]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
- http://vserver.13thfloor.at/Experimental/patch-3.10.9-vs2.3.6.6.diff
[packages/kernel.git] / kernel-vserver-2.3.patch
1 diff -NurpP --minimal linux-3.10.9/Documentation/vserver/debug.txt linux-3.10.9-vs2.3.6.6/Documentation/vserver/debug.txt
2 --- linux-3.10.9/Documentation/vserver/debug.txt        1970-01-01 00:00:00.000000000 +0000
3 +++ linux-3.10.9-vs2.3.6.6/Documentation/vserver/debug.txt      2013-08-22 20:29:59.000000000 +0000
4 @@ -0,0 +1,154 @@
5 +
6 +debug_cvirt:
7 +
8 + 2   4 "vx_map_tgid: %p/%llx: %d -> %d"
9 +       "vx_rmap_tgid: %p/%llx: %d -> %d"
10 +
11 +debug_dlim:
12 +
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"
29 +
30 +debug_misc:
31 +
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«)"
39 +       "temp copy »%s«"
40 + 2   4 "dentry_open(new): %p"
41 +       "dentry_open(old): %p"
42 +       "lookup_create(new): %p"
43 +       "old path »%s«"
44 +       "path_lookup(old): %d"
45 +       "vfs_create(new): %d"
46 +       "vfs_rename: %d"
47 +       "vfs_sendfile: %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]"
54 +
55 +debug_net:
56 +
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"
69 +
70 +debug_nid:
71 +
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])"
94 +
95 +debug_quota:
96 +
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)"
102 +
103 +debug_switch:
104 +
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"
108 +
109 +debug_tag:
110 +
111 + 7  80 "dx_parse_tag(»%s«): %d:#%d"
112 +       "dx_propagate_tag(%p[#%lu.%d]): %d,%d"
113 +
114 +debug_xid:
115 +
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)*"
127 +       "loc_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]"
149 +
150 +
151 +debug_limit:
152 +
153 + n 2^n "vx_acc_cres[%5d,%s,%2d]: %5d%s"
154 +       "vx_cres_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
155 +
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.10.9/arch/alpha/Kconfig linux-3.10.9-vs2.3.6.6/arch/alpha/Kconfig
160 --- linux-3.10.9/arch/alpha/Kconfig     2013-07-14 17:00:13.000000000 +0000
161 +++ linux-3.10.9-vs2.3.6.6/arch/alpha/Kconfig   2013-08-22 20:29:59.000000000 +0000
162 @@ -665,6 +665,8 @@ config DUMMY_CONSOLE
163         depends on VGA_HOSE
164         default y
165  
166 +source "kernel/vserver/Kconfig"
167 +
168  source "security/Kconfig"
169  
170  source "crypto/Kconfig"
171 diff -NurpP --minimal linux-3.10.9/arch/alpha/kernel/systbls.S linux-3.10.9-vs2.3.6.6/arch/alpha/kernel/systbls.S
172 --- linux-3.10.9/arch/alpha/kernel/systbls.S    2013-02-19 13:56:11.000000000 +0000
173 +++ linux-3.10.9-vs2.3.6.6/arch/alpha/kernel/systbls.S  2013-08-22 20:29:59.000000000 +0000
174 @@ -446,7 +446,7 @@ sys_call_table:
175         .quad sys_stat64                        /* 425 */
176         .quad sys_lstat64
177         .quad sys_fstat64
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.10.9/arch/alpha/kernel/traps.c linux-3.10.9-vs2.3.6.6/arch/alpha/kernel/traps.c
184 --- linux-3.10.9/arch/alpha/kernel/traps.c      2013-07-14 17:00:13.000000000 +0000
185 +++ linux-3.10.9-vs2.3.6.6/arch/alpha/kernel/traps.c    2013-08-22 20:29:59.000000000 +0000
186 @@ -177,7 +177,8 @@ die_if_kernel(char * str, struct pt_regs
187  #ifdef CONFIG_SMP
188         printk("CPU %d ", hard_smp_processor_id());
189  #endif
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.10.9/arch/arm/Kconfig linux-3.10.9-vs2.3.6.6/arch/arm/Kconfig
197 --- linux-3.10.9/arch/arm/Kconfig       2013-08-22 19:51:30.000000000 +0000
198 +++ linux-3.10.9-vs2.3.6.6/arch/arm/Kconfig     2013-08-22 20:29:59.000000000 +0000
199 @@ -2238,6 +2238,8 @@ source "fs/Kconfig"
200  
201  source "arch/arm/Kconfig.debug"
202  
203 +source "kernel/vserver/Kconfig"
204 +
205  source "security/Kconfig"
206  
207  source "crypto/Kconfig"
208 diff -NurpP --minimal linux-3.10.9/arch/arm/kernel/calls.S linux-3.10.9-vs2.3.6.6/arch/arm/kernel/calls.S
209 --- linux-3.10.9/arch/arm/kernel/calls.S        2013-05-31 13:44:29.000000000 +0000
210 +++ linux-3.10.9-vs2.3.6.6/arch/arm/kernel/calls.S      2013-08-22 20:29:59.000000000 +0000
211 @@ -322,7 +322,7 @@
212  /* 310 */      CALL(sys_request_key)
213                 CALL(sys_keyctl)
214                 CALL(ABI(sys_semtimedop, sys_oabi_semtimedop))
215 -/* vserver */  CALL(sys_ni_syscall)
216 +               CALL(sys_vserver)
217                 CALL(sys_ioprio_set)
218  /* 315 */      CALL(sys_ioprio_get)
219                 CALL(sys_inotify_init)
220 diff -NurpP --minimal linux-3.10.9/arch/arm/kernel/traps.c linux-3.10.9-vs2.3.6.6/arch/arm/kernel/traps.c
221 --- linux-3.10.9/arch/arm/kernel/traps.c        2013-08-22 19:51:30.000000000 +0000
222 +++ linux-3.10.9-vs2.3.6.6/arch/arm/kernel/traps.c      2013-08-22 20:29:59.000000000 +0000
223 @@ -240,8 +240,8 @@ static int __die(const char *str, int er
224  
225         print_modules();
226         __show_regs(regs);
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));
231  
232         if (!user_mode(regs) || in_interrupt()) {
233                 dump_mem(KERN_EMERG, "Stack: ", regs->ARM_sp,
234 diff -NurpP --minimal linux-3.10.9/arch/cris/Kconfig linux-3.10.9-vs2.3.6.6/arch/cris/Kconfig
235 --- linux-3.10.9/arch/cris/Kconfig      2013-07-14 17:00:25.000000000 +0000
236 +++ linux-3.10.9-vs2.3.6.6/arch/cris/Kconfig    2013-08-22 20:29:59.000000000 +0000
237 @@ -673,6 +673,8 @@ source "drivers/staging/Kconfig"
238  
239  source "arch/cris/Kconfig.debug"
240  
241 +source "kernel/vserver/Kconfig"
242 +
243  source "security/Kconfig"
244  
245  source "crypto/Kconfig"
246 diff -NurpP --minimal linux-3.10.9/arch/h8300/Kconfig linux-3.10.9-vs2.3.6.6/arch/h8300/Kconfig
247 --- linux-3.10.9/arch/h8300/Kconfig     2013-07-14 17:00:25.000000000 +0000
248 +++ linux-3.10.9-vs2.3.6.6/arch/h8300/Kconfig   2013-08-22 20:29:59.000000000 +0000
249 @@ -218,6 +218,8 @@ source "fs/Kconfig"
250  
251  source "arch/h8300/Kconfig.debug"
252  
253 +source "kernel/vserver/Kconfig"
254 +
255  source "security/Kconfig"
256  
257  source "crypto/Kconfig"
258 diff -NurpP --minimal linux-3.10.9/arch/ia64/Kconfig linux-3.10.9-vs2.3.6.6/arch/ia64/Kconfig
259 --- linux-3.10.9/arch/ia64/Kconfig      2013-07-14 17:00:25.000000000 +0000
260 +++ linux-3.10.9-vs2.3.6.6/arch/ia64/Kconfig    2013-08-22 20:29:59.000000000 +0000
261 @@ -643,6 +643,8 @@ source "fs/Kconfig"
262  
263  source "arch/ia64/Kconfig.debug"
264  
265 +source "kernel/vserver/Kconfig"
266 +
267  source "security/Kconfig"
268  
269  source "crypto/Kconfig"
270 diff -NurpP --minimal linux-3.10.9/arch/ia64/kernel/entry.S linux-3.10.9-vs2.3.6.6/arch/ia64/kernel/entry.S
271 --- linux-3.10.9/arch/ia64/kernel/entry.S       2013-05-31 13:44:38.000000000 +0000
272 +++ linux-3.10.9-vs2.3.6.6/arch/ia64/kernel/entry.S     2013-08-22 20:29:59.000000000 +0000
273 @@ -1719,7 +1719,7 @@ sys_call_table:
274         data8 sys_mq_notify
275         data8 sys_mq_getsetattr
276         data8 sys_kexec_load
277 -       data8 sys_ni_syscall                    // reserved for vserver
278 +       data8 sys_vserver
279         data8 sys_waitid                        // 1270
280         data8 sys_add_key
281         data8 sys_request_key
282 diff -NurpP --minimal linux-3.10.9/arch/ia64/kernel/ptrace.c linux-3.10.9-vs2.3.6.6/arch/ia64/kernel/ptrace.c
283 --- linux-3.10.9/arch/ia64/kernel/ptrace.c      2013-02-19 13:56:51.000000000 +0000
284 +++ linux-3.10.9-vs2.3.6.6/arch/ia64/kernel/ptrace.c    2013-08-22 20:29:59.000000000 +0000
285 @@ -21,6 +21,7 @@
286  #include <linux/regset.h>
287  #include <linux/elf.h>
288  #include <linux/tracehook.h>
289 +#include <linux/vs_base.h>
290  
291  #include <asm/pgtable.h>
292  #include <asm/processor.h>
293 diff -NurpP --minimal linux-3.10.9/arch/ia64/kernel/traps.c linux-3.10.9-vs2.3.6.6/arch/ia64/kernel/traps.c
294 --- linux-3.10.9/arch/ia64/kernel/traps.c       2013-05-31 13:44:38.000000000 +0000
295 +++ linux-3.10.9-vs2.3.6.6/arch/ia64/kernel/traps.c     2013-08-22 20:29:59.000000000 +0000
296 @@ -60,8 +60,9 @@ die (const char *str, struct pt_regs *re
297         put_cpu();
298  
299         if (++die.lock_owner_depth < 3) {
300 -               printk("%s[%d]: %s %ld [%d]\n",
301 -               current->comm, task_pid_nr(current), str, err, ++die_counter);
302 +               printk("%s[%d:#%u]: %s %ld [%d]\n",
303 +                       current->comm, task_pid_nr(current), current->xid,
304 +                       str, err, ++die_counter);
305                 if (notify_die(DIE_OOPS, str, regs, err, 255, SIGSEGV)
306                     != NOTIFY_STOP)
307                         show_regs(regs);
308 @@ -324,8 +325,9 @@ handle_fpu_swa (int fp_fault, struct pt_
309                         if ((last.count & 15) < 5 && (ia64_fetchadd(1, &last.count, acq) & 15) < 5) {
310                                 last.time = current_jiffies + 5 * HZ;
311                                 printk(KERN_WARNING
312 -                                       "%s(%d): floating-point assist fault at ip %016lx, isr %016lx\n",
313 -                                       current->comm, task_pid_nr(current), regs->cr_iip + ia64_psr(regs)->ri, isr);
314 +                                       "%s(%d:#%u): floating-point assist fault at ip %016lx, isr %016lx\n",
315 +                                       current->comm, task_pid_nr(current), current->xid,
316 +                                       regs->cr_iip + ia64_psr(regs)->ri, isr);
317                         }
318                 }
319         }
320 diff -NurpP --minimal linux-3.10.9/arch/m32r/kernel/traps.c linux-3.10.9-vs2.3.6.6/arch/m32r/kernel/traps.c
321 --- linux-3.10.9/arch/m32r/kernel/traps.c       2013-07-14 17:00:26.000000000 +0000
322 +++ linux-3.10.9-vs2.3.6.6/arch/m32r/kernel/traps.c     2013-08-22 20:29:59.000000000 +0000
323 @@ -184,8 +184,9 @@ static void show_registers(struct pt_reg
324         } else {
325                 printk("SPI: %08lx\n", sp);
326         }
327 -       printk("Process %s (pid: %d, process nr: %d, stackpage=%08lx)",
328 -               current->comm, task_pid_nr(current), 0xffff & i, 4096+(unsigned long)current);
329 +       printk("Process %s (pid: %d:#%u, process nr: %d, stackpage=%08lx)",
330 +               current->comm, task_pid_nr(current), current->xid,
331 +               0xffff & i, 4096+(unsigned long)current);
332  
333         /*
334          * When in-kernel, we also print out the stack and code at the
335 diff -NurpP --minimal linux-3.10.9/arch/m68k/Kconfig linux-3.10.9-vs2.3.6.6/arch/m68k/Kconfig
336 --- linux-3.10.9/arch/m68k/Kconfig      2013-07-14 17:00:26.000000000 +0000
337 +++ linux-3.10.9-vs2.3.6.6/arch/m68k/Kconfig    2013-08-22 20:29:59.000000000 +0000
338 @@ -134,6 +134,8 @@ source "fs/Kconfig"
339  
340  source "arch/m68k/Kconfig.debug"
341  
342 +source "kernel/vserver/Kconfig"
343 +
344  source "security/Kconfig"
345  
346  source "crypto/Kconfig"
347 diff -NurpP --minimal linux-3.10.9/arch/mips/Kconfig linux-3.10.9-vs2.3.6.6/arch/mips/Kconfig
348 --- linux-3.10.9/arch/mips/Kconfig      2013-08-22 19:51:30.000000000 +0000
349 +++ linux-3.10.9-vs2.3.6.6/arch/mips/Kconfig    2013-08-22 20:29:59.000000000 +0000
350 @@ -2583,6 +2583,8 @@ source "fs/Kconfig"
351  
352  source "arch/mips/Kconfig.debug"
353  
354 +source "kernel/vserver/Kconfig"
355 +
356  source "security/Kconfig"
357  
358  source "crypto/Kconfig"
359 diff -NurpP --minimal linux-3.10.9/arch/mips/kernel/ptrace.c linux-3.10.9-vs2.3.6.6/arch/mips/kernel/ptrace.c
360 --- linux-3.10.9/arch/mips/kernel/ptrace.c      2013-05-31 13:44:42.000000000 +0000
361 +++ linux-3.10.9-vs2.3.6.6/arch/mips/kernel/ptrace.c    2013-08-22 20:29:59.000000000 +0000
362 @@ -25,6 +25,7 @@
363  #include <linux/security.h>
364  #include <linux/audit.h>
365  #include <linux/seccomp.h>
366 +#include <linux/vs_base.h>
367  
368  #include <asm/byteorder.h>
369  #include <asm/cpu.h>
370 @@ -262,6 +263,9 @@ long arch_ptrace(struct task_struct *chi
371         void __user *datavp = (void __user *) data;
372         unsigned long __user *datalp = (void __user *) data;
373  
374 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
375 +               goto out;
376 +
377         switch (request) {
378         /* when I and D space are separate, these will need to be fixed. */
379         case PTRACE_PEEKTEXT: /* read word at location addr. */
380 diff -NurpP --minimal linux-3.10.9/arch/mips/kernel/scall32-o32.S linux-3.10.9-vs2.3.6.6/arch/mips/kernel/scall32-o32.S
381 --- linux-3.10.9/arch/mips/kernel/scall32-o32.S 2013-07-14 17:00:28.000000000 +0000
382 +++ linux-3.10.9-vs2.3.6.6/arch/mips/kernel/scall32-o32.S       2013-08-22 20:29:59.000000000 +0000
383 @@ -521,7 +521,7 @@ einval: li  v0, -ENOSYS
384         sys     sys_mq_timedreceive     5
385         sys     sys_mq_notify           2       /* 4275 */
386         sys     sys_mq_getsetattr       3
387 -       sys     sys_ni_syscall          0       /* sys_vserver */
388 +       sys     sys_vserver             3
389         sys     sys_waitid              5
390         sys     sys_ni_syscall          0       /* available, was setaltroot */
391         sys     sys_add_key             5       /* 4280 */
392 diff -NurpP --minimal linux-3.10.9/arch/mips/kernel/scall64-64.S linux-3.10.9-vs2.3.6.6/arch/mips/kernel/scall64-64.S
393 --- linux-3.10.9/arch/mips/kernel/scall64-64.S  2013-07-14 17:00:28.000000000 +0000
394 +++ linux-3.10.9-vs2.3.6.6/arch/mips/kernel/scall64-64.S        2013-08-22 20:29:59.000000000 +0000
395 @@ -351,7 +351,7 @@ sys_call_table:
396         PTR     sys_mq_timedreceive
397         PTR     sys_mq_notify
398         PTR     sys_mq_getsetattr               /* 5235 */
399 -       PTR     sys_ni_syscall                  /* sys_vserver */
400 +       PTR     sys_vserver
401         PTR     sys_waitid
402         PTR     sys_ni_syscall                  /* available, was setaltroot */
403         PTR     sys_add_key
404 diff -NurpP --minimal linux-3.10.9/arch/mips/kernel/scall64-n32.S linux-3.10.9-vs2.3.6.6/arch/mips/kernel/scall64-n32.S
405 --- linux-3.10.9/arch/mips/kernel/scall64-n32.S 2013-07-14 17:00:28.000000000 +0000
406 +++ linux-3.10.9-vs2.3.6.6/arch/mips/kernel/scall64-n32.S       2013-08-22 20:29:59.000000000 +0000
407 @@ -344,7 +344,7 @@ EXPORT(sysn32_call_table)
408         PTR     compat_sys_mq_timedreceive
409         PTR     compat_sys_mq_notify
410         PTR     compat_sys_mq_getsetattr
411 -       PTR     sys_ni_syscall                  /* 6240, sys_vserver */
412 +       PTR     sys32_vserver                   /* 6240 */
413         PTR     compat_sys_waitid
414         PTR     sys_ni_syscall                  /* available, was setaltroot */
415         PTR     sys_add_key
416 diff -NurpP --minimal linux-3.10.9/arch/mips/kernel/scall64-o32.S linux-3.10.9-vs2.3.6.6/arch/mips/kernel/scall64-o32.S
417 --- linux-3.10.9/arch/mips/kernel/scall64-o32.S 2013-07-14 17:00:28.000000000 +0000
418 +++ linux-3.10.9-vs2.3.6.6/arch/mips/kernel/scall64-o32.S       2013-08-22 20:29:59.000000000 +0000
419 @@ -469,7 +469,7 @@ sys_call_table:
420         PTR     compat_sys_mq_timedreceive
421         PTR     compat_sys_mq_notify            /* 4275 */
422         PTR     compat_sys_mq_getsetattr
423 -       PTR     sys_ni_syscall                  /* sys_vserver */
424 +       PTR     sys32_vserver
425         PTR     compat_sys_waitid
426         PTR     sys_ni_syscall                  /* available, was setaltroot */
427         PTR     sys_add_key                     /* 4280 */
428 diff -NurpP --minimal linux-3.10.9/arch/mips/kernel/traps.c linux-3.10.9-vs2.3.6.6/arch/mips/kernel/traps.c
429 --- linux-3.10.9/arch/mips/kernel/traps.c       2013-07-14 17:00:28.000000000 +0000
430 +++ linux-3.10.9-vs2.3.6.6/arch/mips/kernel/traps.c     2013-08-22 20:29:59.000000000 +0000
431 @@ -331,9 +331,10 @@ void show_registers(struct pt_regs *regs
432  
433         __show_regs(regs);
434         print_modules();
435 -       printk("Process %s (pid: %d, threadinfo=%p, task=%p, tls=%0*lx)\n",
436 -              current->comm, current->pid, current_thread_info(), current,
437 -             field, current_thread_info()->tp_value);
438 +       printk("Process %s (pid: %d:#%u, threadinfo=%p, task=%p, tls=%0*lx)\n",
439 +               current->comm, task_pid_nr(current), current->xid,
440 +               current_thread_info(), current,
441 +               field, current_thread_info()->tp_value);
442         if (cpu_has_userlocal) {
443                 unsigned long tls;
444  
445 diff -NurpP --minimal linux-3.10.9/arch/parisc/Kconfig linux-3.10.9-vs2.3.6.6/arch/parisc/Kconfig
446 --- linux-3.10.9/arch/parisc/Kconfig    2013-07-14 17:00:29.000000000 +0000
447 +++ linux-3.10.9-vs2.3.6.6/arch/parisc/Kconfig  2013-08-22 20:29:59.000000000 +0000
448 @@ -318,6 +318,8 @@ source "fs/Kconfig"
449  
450  source "arch/parisc/Kconfig.debug"
451  
452 +source "kernel/vserver/Kconfig"
453 +
454  source "security/Kconfig"
455  
456  source "crypto/Kconfig"
457 diff -NurpP --minimal linux-3.10.9/arch/parisc/kernel/syscall_table.S linux-3.10.9-vs2.3.6.6/arch/parisc/kernel/syscall_table.S
458 --- linux-3.10.9/arch/parisc/kernel/syscall_table.S     2013-07-14 17:00:31.000000000 +0000
459 +++ linux-3.10.9-vs2.3.6.6/arch/parisc/kernel/syscall_table.S   2013-08-22 20:29:59.000000000 +0000
460 @@ -358,7 +358,7 @@
461         ENTRY_COMP(mbind)               /* 260 */
462         ENTRY_COMP(get_mempolicy)
463         ENTRY_COMP(set_mempolicy)
464 -       ENTRY_SAME(ni_syscall)  /* 263: reserved for vserver */
465 +       ENTRY_DIFF(vserver)
466         ENTRY_SAME(add_key)
467         ENTRY_SAME(request_key)         /* 265 */
468         ENTRY_SAME(keyctl)
469 diff -NurpP --minimal linux-3.10.9/arch/parisc/kernel/traps.c linux-3.10.9-vs2.3.6.6/arch/parisc/kernel/traps.c
470 --- linux-3.10.9/arch/parisc/kernel/traps.c     2013-07-14 17:00:31.000000000 +0000
471 +++ linux-3.10.9-vs2.3.6.6/arch/parisc/kernel/traps.c   2013-08-22 20:29:59.000000000 +0000
472 @@ -229,8 +229,9 @@ void die_if_kernel(char *str, struct pt_
473                 if (err == 0)
474                         return; /* STFU */
475  
476 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld) at " RFMT "\n",
477 -                       current->comm, task_pid_nr(current), str, err, regs->iaoq[0]);
478 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld) at " RFMT "\n",
479 +                       current->comm, task_pid_nr(current), current->xid,
480 +                       str, err, regs->iaoq[0]);
481  #ifdef PRINT_USER_FAULTS
482                 /* XXX for debugging only */
483                 show_regs(regs);
484 @@ -263,8 +264,8 @@ void die_if_kernel(char *str, struct pt_
485                 pdc_console_restart();
486         
487         if (err)
488 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld)\n",
489 -                       current->comm, task_pid_nr(current), str, err);
490 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld)\n",
491 +                       current->comm, task_pid_nr(current), current->xid, str, err);
492  
493         /* Wot's wrong wif bein' racy? */
494         if (current->thread.flags & PARISC_KERNEL_DEATH) {
495 diff -NurpP --minimal linux-3.10.9/arch/parisc/mm/fault.c linux-3.10.9-vs2.3.6.6/arch/parisc/mm/fault.c
496 --- linux-3.10.9/arch/parisc/mm/fault.c 2013-05-31 13:44:44.000000000 +0000
497 +++ linux-3.10.9-vs2.3.6.6/arch/parisc/mm/fault.c       2013-08-22 20:29:59.000000000 +0000
498 @@ -257,8 +257,9 @@ bad_area:
499  
500  #ifdef PRINT_USER_FAULTS
501                 printk(KERN_DEBUG "\n");
502 -               printk(KERN_DEBUG "do_page_fault() pid=%d command='%s' type=%lu address=0x%08lx\n",
503 -                   task_pid_nr(tsk), tsk->comm, code, address);
504 +               printk(KERN_DEBUG "do_page_fault() pid=%d:#%u "
505 +                   "command='%s' type=%lu address=0x%08lx\n",
506 +                   task_pid_nr(tsk), tsk->xid, tsk->comm, code, address);
507                 if (vma) {
508                         printk(KERN_DEBUG "vm_start = 0x%08lx, vm_end = 0x%08lx\n",
509                                         vma->vm_start, vma->vm_end);
510 diff -NurpP --minimal linux-3.10.9/arch/powerpc/Kconfig linux-3.10.9-vs2.3.6.6/arch/powerpc/Kconfig
511 --- linux-3.10.9/arch/powerpc/Kconfig   2013-08-22 19:51:30.000000000 +0000
512 +++ linux-3.10.9-vs2.3.6.6/arch/powerpc/Kconfig 2013-08-22 20:29:59.000000000 +0000
513 @@ -1009,6 +1009,8 @@ source "lib/Kconfig"
514  
515  source "arch/powerpc/Kconfig.debug"
516  
517 +source "kernel/vserver/Kconfig"
518 +
519  source "security/Kconfig"
520  
521  config KEYS_COMPAT
522 diff -NurpP --minimal linux-3.10.9/arch/powerpc/include/uapi/asm/unistd.h linux-3.10.9-vs2.3.6.6/arch/powerpc/include/uapi/asm/unistd.h
523 --- linux-3.10.9/arch/powerpc/include/uapi/asm/unistd.h 2013-05-31 13:44:44.000000000 +0000
524 +++ linux-3.10.9-vs2.3.6.6/arch/powerpc/include/uapi/asm/unistd.h       2013-08-22 20:29:59.000000000 +0000
525 @@ -275,7 +275,7 @@
526  #endif
527  #define __NR_rtas              255
528  #define __NR_sys_debug_setcontext 256
529 -/* Number 257 is reserved for vserver */
530 +#define __NR_vserver           257
531  #define __NR_migrate_pages     258
532  #define __NR_mbind             259
533  #define __NR_get_mempolicy     260
534 diff -NurpP --minimal linux-3.10.9/arch/powerpc/kernel/traps.c linux-3.10.9-vs2.3.6.6/arch/powerpc/kernel/traps.c
535 --- linux-3.10.9/arch/powerpc/kernel/traps.c    2013-08-22 19:51:30.000000000 +0000
536 +++ linux-3.10.9-vs2.3.6.6/arch/powerpc/kernel/traps.c  2013-08-22 20:29:59.000000000 +0000
537 @@ -1231,8 +1231,9 @@ void nonrecoverable_exception(struct pt_
538  
539  void trace_syscall(struct pt_regs *regs)
540  {
541 -       printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
542 -              current, task_pid_nr(current), regs->nip, regs->link, regs->gpr[0],
543 +       printk("Task: %p(%d:#%u), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
544 +              current, task_pid_nr(current), current->xid,
545 +              regs->nip, regs->link, regs->gpr[0],
546                regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted());
547  }
548  
549 diff -NurpP --minimal linux-3.10.9/arch/s390/Kconfig linux-3.10.9-vs2.3.6.6/arch/s390/Kconfig
550 --- linux-3.10.9/arch/s390/Kconfig      2013-08-22 19:51:30.000000000 +0000
551 +++ linux-3.10.9-vs2.3.6.6/arch/s390/Kconfig    2013-08-22 20:29:59.000000000 +0000
552 @@ -579,6 +579,8 @@ source "fs/Kconfig"
553  
554  source "arch/s390/Kconfig.debug"
555  
556 +source "kernel/vserver/Kconfig"
557 +
558  source "security/Kconfig"
559  
560  source "crypto/Kconfig"
561 diff -NurpP --minimal linux-3.10.9/arch/s390/include/asm/tlb.h linux-3.10.9-vs2.3.6.6/arch/s390/include/asm/tlb.h
562 --- linux-3.10.9/arch/s390/include/asm/tlb.h    2013-08-22 19:51:30.000000000 +0000
563 +++ linux-3.10.9-vs2.3.6.6/arch/s390/include/asm/tlb.h  2013-08-22 20:29:59.000000000 +0000
564 @@ -24,6 +24,7 @@
565  #include <linux/mm.h>
566  #include <linux/pagemap.h>
567  #include <linux/swap.h>
568 +
569  #include <asm/processor.h>
570  #include <asm/pgalloc.h>
571  #include <asm/tlbflush.h>
572 diff -NurpP --minimal linux-3.10.9/arch/s390/include/uapi/asm/unistd.h linux-3.10.9-vs2.3.6.6/arch/s390/include/uapi/asm/unistd.h
573 --- linux-3.10.9/arch/s390/include/uapi/asm/unistd.h    2013-02-19 13:57:16.000000000 +0000
574 +++ linux-3.10.9-vs2.3.6.6/arch/s390/include/uapi/asm/unistd.h  2013-08-22 20:29:59.000000000 +0000
575 @@ -200,7 +200,7 @@
576  #define __NR_clock_gettime     (__NR_timer_create+6)
577  #define __NR_clock_getres      (__NR_timer_create+7)
578  #define __NR_clock_nanosleep   (__NR_timer_create+8)
579 -/* Number 263 is reserved for vserver */
580 +#define __NR_vserver           263
581  #define __NR_statfs64          265
582  #define __NR_fstatfs64         266
583  #define __NR_remap_file_pages  267
584 diff -NurpP --minimal linux-3.10.9/arch/s390/kernel/ptrace.c linux-3.10.9-vs2.3.6.6/arch/s390/kernel/ptrace.c
585 --- linux-3.10.9/arch/s390/kernel/ptrace.c      2012-12-11 03:30:57.000000000 +0000
586 +++ linux-3.10.9-vs2.3.6.6/arch/s390/kernel/ptrace.c    2013-08-22 20:29:59.000000000 +0000
587 @@ -21,6 +21,7 @@
588  #include <linux/tracehook.h>
589  #include <linux/seccomp.h>
590  #include <linux/compat.h>
591 +#include <linux/vs_base.h>
592  #include <trace/syscall.h>
593  #include <asm/segment.h>
594  #include <asm/page.h>
595 diff -NurpP --minimal linux-3.10.9/arch/s390/kernel/syscalls.S linux-3.10.9-vs2.3.6.6/arch/s390/kernel/syscalls.S
596 --- linux-3.10.9/arch/s390/kernel/syscalls.S    2013-07-14 17:00:34.000000000 +0000
597 +++ linux-3.10.9-vs2.3.6.6/arch/s390/kernel/syscalls.S  2013-08-22 20:29:59.000000000 +0000
598 @@ -271,7 +271,7 @@ SYSCALL(sys_clock_settime,sys_clock_sett
599  SYSCALL(sys_clock_gettime,sys_clock_gettime,sys32_clock_gettime_wrapper)       /* 260 */
600  SYSCALL(sys_clock_getres,sys_clock_getres,sys32_clock_getres_wrapper)
601  SYSCALL(sys_clock_nanosleep,sys_clock_nanosleep,sys32_clock_nanosleep_wrapper)
602 -NI_SYSCALL                                                     /* reserved for vserver */
603 +SYSCALL(sys_vserver,sys_vserver,sys32_vserver)
604  SYSCALL(sys_s390_fadvise64_64,sys_ni_syscall,sys32_fadvise64_64_wrapper)
605  SYSCALL(sys_statfs64,sys_statfs64,compat_sys_statfs64_wrapper)
606  SYSCALL(sys_fstatfs64,sys_fstatfs64,compat_sys_fstatfs64_wrapper)
607 diff -NurpP --minimal linux-3.10.9/arch/sh/Kconfig linux-3.10.9-vs2.3.6.6/arch/sh/Kconfig
608 --- linux-3.10.9/arch/sh/Kconfig        2013-07-14 17:00:35.000000000 +0000
609 +++ linux-3.10.9-vs2.3.6.6/arch/sh/Kconfig      2013-08-22 20:29:59.000000000 +0000
610 @@ -928,6 +928,8 @@ source "fs/Kconfig"
611  
612  source "arch/sh/Kconfig.debug"
613  
614 +source "kernel/vserver/Kconfig"
615 +
616  source "security/Kconfig"
617  
618  source "crypto/Kconfig"
619 diff -NurpP --minimal linux-3.10.9/arch/sh/kernel/irq.c linux-3.10.9-vs2.3.6.6/arch/sh/kernel/irq.c
620 --- linux-3.10.9/arch/sh/kernel/irq.c   2012-12-11 03:30:57.000000000 +0000
621 +++ linux-3.10.9-vs2.3.6.6/arch/sh/kernel/irq.c 2013-08-22 20:29:59.000000000 +0000
622 @@ -14,6 +14,7 @@
623  #include <linux/ftrace.h>
624  #include <linux/delay.h>
625  #include <linux/ratelimit.h>
626 +// #include <linux/vs_context.h>
627  #include <asm/processor.h>
628  #include <asm/machvec.h>
629  #include <asm/uaccess.h>
630 diff -NurpP --minimal linux-3.10.9/arch/sparc/Kconfig linux-3.10.9-vs2.3.6.6/arch/sparc/Kconfig
631 --- linux-3.10.9/arch/sparc/Kconfig     2013-07-14 17:00:35.000000000 +0000
632 +++ linux-3.10.9-vs2.3.6.6/arch/sparc/Kconfig   2013-08-22 20:29:59.000000000 +0000
633 @@ -550,6 +550,8 @@ source "fs/Kconfig"
634  
635  source "arch/sparc/Kconfig.debug"
636  
637 +source "kernel/vserver/Kconfig"
638 +
639  source "security/Kconfig"
640  
641  source "crypto/Kconfig"
642 diff -NurpP --minimal linux-3.10.9/arch/sparc/include/uapi/asm/unistd.h linux-3.10.9-vs2.3.6.6/arch/sparc/include/uapi/asm/unistd.h
643 --- linux-3.10.9/arch/sparc/include/uapi/asm/unistd.h   2013-02-19 13:57:17.000000000 +0000
644 +++ linux-3.10.9-vs2.3.6.6/arch/sparc/include/uapi/asm/unistd.h 2013-08-22 20:29:59.000000000 +0000
645 @@ -332,7 +332,7 @@
646  #define __NR_timer_getoverrun  264
647  #define __NR_timer_delete      265
648  #define __NR_timer_create      266
649 -/* #define __NR_vserver                267 Reserved for VSERVER */
650 +#define __NR_vserver           267
651  #define __NR_io_setup          268
652  #define __NR_io_destroy                269
653  #define __NR_io_submit         270
654 diff -NurpP --minimal linux-3.10.9/arch/sparc/kernel/systbls_32.S linux-3.10.9-vs2.3.6.6/arch/sparc/kernel/systbls_32.S
655 --- linux-3.10.9/arch/sparc/kernel/systbls_32.S 2013-05-31 13:44:48.000000000 +0000
656 +++ linux-3.10.9-vs2.3.6.6/arch/sparc/kernel/systbls_32.S       2013-08-22 20:29:59.000000000 +0000
657 @@ -70,7 +70,7 @@ sys_call_table:
658  /*250*/        .long sys_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_ni_syscall
659  /*255*/        .long sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
660  /*260*/        .long sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
661 -/*265*/        .long sys_timer_delete, sys_timer_create, sys_nis_syscall, sys_io_setup, sys_io_destroy
662 +/*265*/        .long sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
663  /*270*/        .long sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
664  /*275*/        .long sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
665  /*280*/        .long sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
666 diff -NurpP --minimal linux-3.10.9/arch/sparc/kernel/systbls_64.S linux-3.10.9-vs2.3.6.6/arch/sparc/kernel/systbls_64.S
667 --- linux-3.10.9/arch/sparc/kernel/systbls_64.S 2013-07-14 17:00:35.000000000 +0000
668 +++ linux-3.10.9-vs2.3.6.6/arch/sparc/kernel/systbls_64.S       2013-08-22 20:29:59.000000000 +0000
669 @@ -71,7 +71,7 @@ sys_call_table32:
670  /*250*/        .word sys_mremap, compat_sys_sysctl, sys_getsid, sys_fdatasync, sys_nis_syscall
671         .word sys32_sync_file_range, compat_sys_clock_settime, compat_sys_clock_gettime, compat_sys_clock_getres, sys32_clock_nanosleep
672  /*260*/        .word compat_sys_sched_getaffinity, compat_sys_sched_setaffinity, sys32_timer_settime, compat_sys_timer_gettime, sys_timer_getoverrun
673 -       .word sys_timer_delete, compat_sys_timer_create, sys_ni_syscall, compat_sys_io_setup, sys_io_destroy
674 +       .word sys_timer_delete, compat_sys_timer_create, sys32_vserver, compat_sys_io_setup, sys_io_destroy
675  /*270*/        .word sys32_io_submit, sys_io_cancel, compat_sys_io_getevents, sys32_mq_open, sys_mq_unlink
676         .word compat_sys_mq_timedsend, compat_sys_mq_timedreceive, compat_sys_mq_notify, compat_sys_mq_getsetattr, compat_sys_waitid
677  /*280*/        .word sys_tee, sys_add_key, sys_request_key, compat_sys_keyctl, compat_sys_openat
678 @@ -149,7 +149,7 @@ sys_call_table:
679  /*250*/        .word sys_64_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nis_syscall
680         .word sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
681  /*260*/        .word sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
682 -       .word sys_timer_delete, sys_timer_create, sys_ni_syscall, sys_io_setup, sys_io_destroy
683 +       .word sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
684  /*270*/        .word sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
685         .word sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
686  /*280*/        .word sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
687 diff -NurpP --minimal linux-3.10.9/arch/um/Kconfig.rest linux-3.10.9-vs2.3.6.6/arch/um/Kconfig.rest
688 --- linux-3.10.9/arch/um/Kconfig.rest   2012-12-11 03:30:57.000000000 +0000
689 +++ linux-3.10.9-vs2.3.6.6/arch/um/Kconfig.rest 2013-08-22 20:29:59.000000000 +0000
690 @@ -12,6 +12,8 @@ source "arch/um/Kconfig.net"
691  
692  source "fs/Kconfig"
693  
694 +source "kernel/vserver/Kconfig"
695 +
696  source "security/Kconfig"
697  
698  source "crypto/Kconfig"
699 diff -NurpP --minimal linux-3.10.9/arch/x86/Kconfig linux-3.10.9-vs2.3.6.6/arch/x86/Kconfig
700 --- linux-3.10.9/arch/x86/Kconfig       2013-07-14 17:00:36.000000000 +0000
701 +++ linux-3.10.9-vs2.3.6.6/arch/x86/Kconfig     2013-08-22 20:29:59.000000000 +0000
702 @@ -2339,6 +2339,8 @@ source "fs/Kconfig"
703  
704  source "arch/x86/Kconfig.debug"
705  
706 +source "kernel/vserver/Kconfig"
707 +
708  source "security/Kconfig"
709  
710  source "crypto/Kconfig"
711 diff -NurpP --minimal linux-3.10.9/arch/x86/syscalls/syscall_32.tbl linux-3.10.9-vs2.3.6.6/arch/x86/syscalls/syscall_32.tbl
712 --- linux-3.10.9/arch/x86/syscalls/syscall_32.tbl       2013-07-14 17:00:37.000000000 +0000
713 +++ linux-3.10.9-vs2.3.6.6/arch/x86/syscalls/syscall_32.tbl     2013-08-22 20:29:59.000000000 +0000
714 @@ -279,7 +279,7 @@
715  270    i386    tgkill                  sys_tgkill
716  271    i386    utimes                  sys_utimes                      compat_sys_utimes
717  272    i386    fadvise64_64            sys_fadvise64_64                sys32_fadvise64_64
718 -273    i386    vserver
719 +273    i386    vserver                 sys_vserver                     sys32_vserver
720  274    i386    mbind                   sys_mbind
721  275    i386    get_mempolicy           sys_get_mempolicy               compat_sys_get_mempolicy
722  276    i386    set_mempolicy           sys_set_mempolicy
723 diff -NurpP --minimal linux-3.10.9/arch/x86/syscalls/syscall_64.tbl linux-3.10.9-vs2.3.6.6/arch/x86/syscalls/syscall_64.tbl
724 --- linux-3.10.9/arch/x86/syscalls/syscall_64.tbl       2013-05-31 13:44:50.000000000 +0000
725 +++ linux-3.10.9-vs2.3.6.6/arch/x86/syscalls/syscall_64.tbl     2013-08-22 20:29:59.000000000 +0000
726 @@ -242,7 +242,7 @@
727  233    common  epoll_ctl               sys_epoll_ctl
728  234    common  tgkill                  sys_tgkill
729  235    common  utimes                  sys_utimes
730 -236    64      vserver
731 +236    64      vserver                 sys_vserver
732  237    common  mbind                   sys_mbind
733  238    common  set_mempolicy           sys_set_mempolicy
734  239    common  get_mempolicy           sys_get_mempolicy
735 diff -NurpP --minimal linux-3.10.9/drivers/block/Kconfig linux-3.10.9-vs2.3.6.6/drivers/block/Kconfig
736 --- linux-3.10.9/drivers/block/Kconfig  2013-05-31 13:44:51.000000000 +0000
737 +++ linux-3.10.9-vs2.3.6.6/drivers/block/Kconfig        2013-08-22 20:29:59.000000000 +0000
738 @@ -278,6 +278,13 @@ config BLK_DEV_CRYPTOLOOP
739  
740  source "drivers/block/drbd/Kconfig"
741  
742 +config BLK_DEV_VROOT
743 +       tristate "Virtual Root device support"
744 +       depends on QUOTACTL
745 +       ---help---
746 +         Saying Y here will allow you to use quota/fs ioctls on a shared
747 +         partition within a virtual server without compromising security.
748 +
749  config BLK_DEV_NBD
750         tristate "Network block device support"
751         depends on NET
752 diff -NurpP --minimal linux-3.10.9/drivers/block/Makefile linux-3.10.9-vs2.3.6.6/drivers/block/Makefile
753 --- linux-3.10.9/drivers/block/Makefile 2013-07-14 17:00:41.000000000 +0000
754 +++ linux-3.10.9-vs2.3.6.6/drivers/block/Makefile       2013-08-22 20:29:59.000000000 +0000
755 @@ -33,6 +33,7 @@ obj-$(CONFIG_VIRTIO_BLK)      += virtio_blk.o
756  obj-$(CONFIG_VIODASD)          += viodasd.o
757  obj-$(CONFIG_BLK_DEV_SX8)      += sx8.o
758  obj-$(CONFIG_BLK_DEV_HD)       += hd.o
759 +obj-$(CONFIG_BLK_DEV_VROOT)    += vroot.o
760  
761  obj-$(CONFIG_XEN_BLKDEV_FRONTEND)      += xen-blkfront.o
762  obj-$(CONFIG_XEN_BLKDEV_BACKEND)       += xen-blkback/
763 diff -NurpP --minimal linux-3.10.9/drivers/block/loop.c linux-3.10.9-vs2.3.6.6/drivers/block/loop.c
764 --- linux-3.10.9/drivers/block/loop.c   2013-07-14 17:00:41.000000000 +0000
765 +++ linux-3.10.9-vs2.3.6.6/drivers/block/loop.c 2013-08-22 20:29:59.000000000 +0000
766 @@ -76,6 +76,7 @@
767  #include <linux/sysfs.h>
768  #include <linux/miscdevice.h>
769  #include <linux/falloc.h>
770 +#include <linux/vs_context.h>
771  
772  #include <asm/uaccess.h>
773  
774 @@ -884,6 +885,7 @@ static int loop_set_fd(struct loop_devic
775         lo->lo_blocksize = lo_blocksize;
776         lo->lo_device = bdev;
777         lo->lo_flags = lo_flags;
778 +       lo->lo_xid = vx_current_xid();
779         lo->lo_backing_file = file;
780         lo->transfer = transfer_none;
781         lo->ioctl = NULL;
782 @@ -1035,6 +1037,7 @@ static int loop_clr_fd(struct loop_devic
783         lo->lo_sizelimit = 0;
784         lo->lo_encrypt_key_size = 0;
785         lo->lo_thread = NULL;
786 +       lo->lo_xid = 0;
787         memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
788         memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
789         memset(lo->lo_file_name, 0, LO_NAME_SIZE);
790 @@ -1078,7 +1081,7 @@ loop_set_status(struct loop_device *lo,
791  
792         if (lo->lo_encrypt_key_size &&
793             !uid_eq(lo->lo_key_owner, uid) &&
794 -           !capable(CAP_SYS_ADMIN))
795 +           !vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP))
796                 return -EPERM;
797         if (lo->lo_state != Lo_bound)
798                 return -ENXIO;
799 @@ -1168,7 +1171,8 @@ loop_get_status(struct loop_device *lo,
800         memcpy(info->lo_crypt_name, lo->lo_crypt_name, LO_NAME_SIZE);
801         info->lo_encrypt_type =
802                 lo->lo_encryption ? lo->lo_encryption->number : 0;
803 -       if (lo->lo_encrypt_key_size && capable(CAP_SYS_ADMIN)) {
804 +       if (lo->lo_encrypt_key_size &&
805 +               vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP)) {
806                 info->lo_encrypt_key_size = lo->lo_encrypt_key_size;
807                 memcpy(info->lo_encrypt_key, lo->lo_encrypt_key,
808                        lo->lo_encrypt_key_size);
809 @@ -1510,6 +1514,11 @@ static int lo_open(struct block_device *
810                 goto out;
811         }
812  
813 +       if (!vx_check(lo->lo_xid, VS_IDENT|VS_HOSTID|VS_ADMIN_P)) {
814 +               err = -EACCES;
815 +               goto out;
816 +       }
817 +
818         mutex_lock(&lo->lo_ctl_mutex);
819         lo->lo_refcnt++;
820         mutex_unlock(&lo->lo_ctl_mutex);
821 diff -NurpP --minimal linux-3.10.9/drivers/block/vroot.c linux-3.10.9-vs2.3.6.6/drivers/block/vroot.c
822 --- linux-3.10.9/drivers/block/vroot.c  1970-01-01 00:00:00.000000000 +0000
823 +++ linux-3.10.9-vs2.3.6.6/drivers/block/vroot.c        2013-08-23 00:23:45.000000000 +0000
824 @@ -0,0 +1,290 @@
825 +/*
826 + *  linux/drivers/block/vroot.c
827 + *
828 + *  written by Herbert Pötzl, 9/11/2002
829 + *  ported to 2.6.10 by Herbert Pötzl, 30/12/2004
830 + *
831 + *  based on the loop.c code by Theodore Ts'o.
832 + *
833 + * Copyright (C) 2002-2007 by Herbert Pötzl.
834 + * Redistribution of this file is permitted under the
835 + * GNU General Public License.
836 + *
837 + */
838 +
839 +#include <linux/module.h>
840 +#include <linux/moduleparam.h>
841 +#include <linux/file.h>
842 +#include <linux/major.h>
843 +#include <linux/blkdev.h>
844 +#include <linux/slab.h>
845 +
846 +#include <linux/vroot.h>
847 +#include <linux/vs_context.h>
848 +
849 +
850 +static int max_vroot = 8;
851 +
852 +static struct vroot_device *vroot_dev;
853 +static struct gendisk **disks;
854 +
855 +
856 +static int vroot_set_dev(
857 +       struct vroot_device *vr,
858 +       struct block_device *bdev,
859 +       unsigned int arg)
860 +{
861 +       struct block_device *real_bdev;
862 +       struct file *file;
863 +       struct inode *inode;
864 +       int error;
865 +
866 +       error = -EBUSY;
867 +       if (vr->vr_state != Vr_unbound)
868 +               goto out;
869 +
870 +       error = -EBADF;
871 +       file = fget(arg);
872 +       if (!file)
873 +               goto out;
874 +
875 +       error = -EINVAL;
876 +       inode = file->f_dentry->d_inode;
877 +
878 +
879 +       if (S_ISBLK(inode->i_mode)) {
880 +               real_bdev = inode->i_bdev;
881 +               vr->vr_device = real_bdev;
882 +               __iget(real_bdev->bd_inode);
883 +       } else
884 +               goto out_fput;
885 +
886 +       vxdprintk(VXD_CBIT(misc, 0),
887 +               "vroot[%d]_set_dev: dev=" VXF_DEV,
888 +               vr->vr_number, VXD_DEV(real_bdev));
889 +
890 +       vr->vr_state = Vr_bound;
891 +       error = 0;
892 +
893 + out_fput:
894 +       fput(file);
895 + out:
896 +       return error;
897 +}
898 +
899 +static int vroot_clr_dev(
900 +       struct vroot_device *vr,
901 +       struct block_device *bdev)
902 +{
903 +       struct block_device *real_bdev;
904 +
905 +       if (vr->vr_state != Vr_bound)
906 +               return -ENXIO;
907 +       if (vr->vr_refcnt > 1)  /* we needed one fd for the ioctl */
908 +               return -EBUSY;
909 +
910 +       real_bdev = vr->vr_device;
911 +
912 +       vxdprintk(VXD_CBIT(misc, 0),
913 +               "vroot[%d]_clr_dev: dev=" VXF_DEV,
914 +               vr->vr_number, VXD_DEV(real_bdev));
915 +
916 +       bdput(real_bdev);
917 +       vr->vr_state = Vr_unbound;
918 +       vr->vr_device = NULL;
919 +       return 0;
920 +}
921 +
922 +
923 +static int vr_ioctl(struct block_device *bdev, fmode_t mode,
924 +       unsigned int cmd, unsigned long arg)
925 +{
926 +       struct vroot_device *vr = bdev->bd_disk->private_data;
927 +       int err;
928 +
929 +       down(&vr->vr_ctl_mutex);
930 +       switch (cmd) {
931 +       case VROOT_SET_DEV:
932 +               err = vroot_set_dev(vr, bdev, arg);
933 +               break;
934 +       case VROOT_CLR_DEV:
935 +               err = vroot_clr_dev(vr, bdev);
936 +               break;
937 +       default:
938 +               err = -EINVAL;
939 +               break;
940 +       }
941 +       up(&vr->vr_ctl_mutex);
942 +       return err;
943 +}
944 +
945 +static int vr_open(struct block_device *bdev, fmode_t mode)
946 +{
947 +       struct vroot_device *vr = bdev->bd_disk->private_data;
948 +
949 +       down(&vr->vr_ctl_mutex);
950 +       vr->vr_refcnt++;
951 +       up(&vr->vr_ctl_mutex);
952 +       return 0;
953 +}
954 +
955 +static void vr_release(struct gendisk *disk, fmode_t mode)
956 +{
957 +       struct vroot_device *vr = disk->private_data;
958 +
959 +       down(&vr->vr_ctl_mutex);
960 +       --vr->vr_refcnt;
961 +       up(&vr->vr_ctl_mutex);
962 +}
963 +
964 +static struct block_device_operations vr_fops = {
965 +       .owner =        THIS_MODULE,
966 +       .open =         vr_open,
967 +       .release =      vr_release,
968 +       .ioctl =        vr_ioctl,
969 +};
970 +
971 +static void vroot_make_request(struct request_queue *q, struct bio *bio)
972 +{
973 +       printk("vroot_make_request %p, %p\n", q, bio);
974 +       bio_io_error(bio);
975 +}
976 +
977 +struct block_device *__vroot_get_real_bdev(struct block_device *bdev)
978 +{
979 +       struct inode *inode = bdev->bd_inode;
980 +       struct vroot_device *vr;
981 +       struct block_device *real_bdev;
982 +       int minor = iminor(inode);
983 +
984 +       vr = &vroot_dev[minor];
985 +       real_bdev = vr->vr_device;
986 +
987 +       vxdprintk(VXD_CBIT(misc, 0),
988 +               "vroot[%d]_get_real_bdev: dev=" VXF_DEV,
989 +               vr->vr_number, VXD_DEV(real_bdev));
990 +
991 +       if (vr->vr_state != Vr_bound)
992 +               return ERR_PTR(-ENXIO);
993 +
994 +       __iget(real_bdev->bd_inode);
995 +       return real_bdev;
996 +}
997 +
998 +
999 +
1000 +/*
1001 + * And now the modules code and kernel interface.
1002 + */
1003 +
1004 +module_param(max_vroot, int, 0);
1005 +
1006 +MODULE_PARM_DESC(max_vroot, "Maximum number of vroot devices (1-256)");
1007 +MODULE_LICENSE("GPL");
1008 +MODULE_ALIAS_BLOCKDEV_MAJOR(VROOT_MAJOR);
1009 +
1010 +MODULE_AUTHOR ("Herbert Pötzl");
1011 +MODULE_DESCRIPTION ("Virtual Root Device Mapper");
1012 +
1013 +
1014 +int __init vroot_init(void)
1015 +{
1016 +       int err, i;
1017 +
1018 +       if (max_vroot < 1 || max_vroot > 256) {
1019 +               max_vroot = MAX_VROOT_DEFAULT;
1020 +               printk(KERN_WARNING "vroot: invalid max_vroot "
1021 +                       "(must be between 1 and 256), "
1022 +                       "using default (%d)\n", max_vroot);
1023 +       }
1024 +
1025 +       if (register_blkdev(VROOT_MAJOR, "vroot"))
1026 +               return -EIO;
1027 +
1028 +       err = -ENOMEM;
1029 +       vroot_dev = kmalloc(max_vroot * sizeof(struct vroot_device), GFP_KERNEL);
1030 +       if (!vroot_dev)
1031 +               goto out_mem1;
1032 +       memset(vroot_dev, 0, max_vroot * sizeof(struct vroot_device));
1033 +
1034 +       disks = kmalloc(max_vroot * sizeof(struct gendisk *), GFP_KERNEL);
1035 +       if (!disks)
1036 +               goto out_mem2;
1037 +
1038 +       for (i = 0; i < max_vroot; i++) {
1039 +               disks[i] = alloc_disk(1);
1040 +               if (!disks[i])
1041 +                       goto out_mem3;
1042 +               disks[i]->queue = blk_alloc_queue(GFP_KERNEL);
1043 +               if (!disks[i]->queue)
1044 +                       goto out_mem3;
1045 +               blk_queue_make_request(disks[i]->queue, vroot_make_request);
1046 +       }
1047 +
1048 +       for (i = 0; i < max_vroot; i++) {
1049 +               struct vroot_device *vr = &vroot_dev[i];
1050 +               struct gendisk *disk = disks[i];
1051 +
1052 +               memset(vr, 0, sizeof(*vr));
1053 +               sema_init(&vr->vr_ctl_mutex, 1);
1054 +               vr->vr_number = i;
1055 +               disk->major = VROOT_MAJOR;
1056 +               disk->first_minor = i;
1057 +               disk->fops = &vr_fops;
1058 +               sprintf(disk->disk_name, "vroot%d", i);
1059 +               disk->private_data = vr;
1060 +       }
1061 +
1062 +       err = register_vroot_grb(&__vroot_get_real_bdev);
1063 +       if (err)
1064 +               goto out_mem3;
1065 +
1066 +       for (i = 0; i < max_vroot; i++)
1067 +               add_disk(disks[i]);
1068 +       printk(KERN_INFO "vroot: loaded (max %d devices)\n", max_vroot);
1069 +       return 0;
1070 +
1071 +out_mem3:
1072 +       while (i--)
1073 +               put_disk(disks[i]);
1074 +       kfree(disks);
1075 +out_mem2:
1076 +       kfree(vroot_dev);
1077 +out_mem1:
1078 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1079 +       printk(KERN_ERR "vroot: ran out of memory\n");
1080 +       return err;
1081 +}
1082 +
1083 +void vroot_exit(void)
1084 +{
1085 +       int i;
1086 +
1087 +       if (unregister_vroot_grb(&__vroot_get_real_bdev))
1088 +               printk(KERN_WARNING "vroot: cannot unregister grb\n");
1089 +
1090 +       for (i = 0; i < max_vroot; i++) {
1091 +               del_gendisk(disks[i]);
1092 +               put_disk(disks[i]);
1093 +       }
1094 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1095 +
1096 +       kfree(disks);
1097 +       kfree(vroot_dev);
1098 +}
1099 +
1100 +module_init(vroot_init);
1101 +module_exit(vroot_exit);
1102 +
1103 +#ifndef MODULE
1104 +
1105 +static int __init max_vroot_setup(char *str)
1106 +{
1107 +       max_vroot = simple_strtol(str, NULL, 0);
1108 +       return 1;
1109 +}
1110 +
1111 +__setup("max_vroot=", max_vroot_setup);
1112 +
1113 +#endif
1114 +
1115 diff -NurpP --minimal linux-3.10.9/drivers/infiniband/Kconfig linux-3.10.9-vs2.3.6.6/drivers/infiniband/Kconfig
1116 --- linux-3.10.9/drivers/infiniband/Kconfig     2013-07-14 17:00:49.000000000 +0000
1117 +++ linux-3.10.9-vs2.3.6.6/drivers/infiniband/Kconfig   2013-08-22 20:29:59.000000000 +0000
1118 @@ -39,7 +39,7 @@ config INFINIBAND_USER_MEM
1119  config INFINIBAND_ADDR_TRANS
1120         bool
1121         depends on INET
1122 -       depends on !(INFINIBAND = y && IPV6 = m)
1123 +       depends on !(INFINIBAND = y && IPV6 = y)
1124         default y
1125  
1126  source "drivers/infiniband/hw/mthca/Kconfig"
1127 diff -NurpP --minimal linux-3.10.9/drivers/infiniband/core/addr.c linux-3.10.9-vs2.3.6.6/drivers/infiniband/core/addr.c
1128 --- linux-3.10.9/drivers/infiniband/core/addr.c 2012-12-11 03:30:57.000000000 +0000
1129 +++ linux-3.10.9-vs2.3.6.6/drivers/infiniband/core/addr.c       2013-08-22 20:29:59.000000000 +0000
1130 @@ -261,7 +261,7 @@ static int addr6_resolve(struct sockaddr
1131  
1132         if (ipv6_addr_any(&fl6.saddr)) {
1133                 ret = ipv6_dev_get_saddr(&init_net, ip6_dst_idev(dst)->dev,
1134 -                                        &fl6.daddr, 0, &fl6.saddr);
1135 +                                        &fl6.daddr, 0, &fl6.saddr, NULL);
1136                 if (ret)
1137                         goto put;
1138  
1139 diff -NurpP --minimal linux-3.10.9/drivers/md/dm-ioctl.c linux-3.10.9-vs2.3.6.6/drivers/md/dm-ioctl.c
1140 --- linux-3.10.9/drivers/md/dm-ioctl.c  2013-08-22 19:51:32.000000000 +0000
1141 +++ linux-3.10.9-vs2.3.6.6/drivers/md/dm-ioctl.c        2013-08-22 20:29:59.000000000 +0000
1142 @@ -16,6 +16,7 @@
1143  #include <linux/dm-ioctl.h>
1144  #include <linux/hdreg.h>
1145  #include <linux/compat.h>
1146 +#include <linux/vs_context.h>
1147  
1148  #include <asm/uaccess.h>
1149  
1150 @@ -106,7 +107,8 @@ static struct hash_cell *__get_name_cell
1151         unsigned int h = hash_str(str);
1152  
1153         list_for_each_entry (hc, _name_buckets + h, name_list)
1154 -               if (!strcmp(hc->name, str)) {
1155 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1156 +                       !strcmp(hc->name, str)) {
1157                         dm_get(hc->md);
1158                         return hc;
1159                 }
1160 @@ -120,7 +122,8 @@ static struct hash_cell *__get_uuid_cell
1161         unsigned int h = hash_str(str);
1162  
1163         list_for_each_entry (hc, _uuid_buckets + h, uuid_list)
1164 -               if (!strcmp(hc->uuid, str)) {
1165 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1166 +                       !strcmp(hc->uuid, str)) {
1167                         dm_get(hc->md);
1168                         return hc;
1169                 }
1170 @@ -131,13 +134,15 @@ static struct hash_cell *__get_uuid_cell
1171  static struct hash_cell *__get_dev_cell(uint64_t dev)
1172  {
1173         struct mapped_device *md;
1174 -       struct hash_cell *hc;
1175 +       struct hash_cell *hc = NULL;
1176  
1177         md = dm_get_md(huge_decode_dev(dev));
1178         if (!md)
1179                 return NULL;
1180  
1181 -       hc = dm_get_mdptr(md);
1182 +       if (vx_check(dm_get_xid(md), VS_WATCH_P | VS_IDENT))
1183 +               hc = dm_get_mdptr(md);
1184 +
1185         if (!hc) {
1186                 dm_put(md);
1187                 return NULL;
1188 @@ -445,6 +450,9 @@ typedef int (*ioctl_fn)(struct dm_ioctl
1189  
1190  static int remove_all(struct dm_ioctl *param, size_t param_size)
1191  {
1192 +       if (!vx_check(0, VS_ADMIN))
1193 +               return -EPERM;
1194 +
1195         dm_hash_remove_all(1);
1196         param->data_size = 0;
1197         return 0;
1198 @@ -492,6 +500,8 @@ static int list_devices(struct dm_ioctl
1199          */
1200         for (i = 0; i < NUM_BUCKETS; i++) {
1201                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1202 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1203 +                               continue;
1204                         needed += sizeof(struct dm_name_list);
1205                         needed += strlen(hc->name) + 1;
1206                         needed += ALIGN_MASK;
1207 @@ -515,6 +525,8 @@ static int list_devices(struct dm_ioctl
1208          */
1209         for (i = 0; i < NUM_BUCKETS; i++) {
1210                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1211 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1212 +                               continue;
1213                         if (old_nl)
1214                                 old_nl->next = (uint32_t) ((void *) nl -
1215                                                            (void *) old_nl);
1216 @@ -1725,8 +1737,8 @@ static int ctl_ioctl(uint command, struc
1217         size_t input_param_size;
1218         struct dm_ioctl param_kernel;
1219  
1220 -       /* only root can play with this */
1221 -       if (!capable(CAP_SYS_ADMIN))
1222 +       /* only root and certain contexts can play with this */
1223 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_MAPPER))
1224                 return -EACCES;
1225  
1226         if (_IOC_TYPE(command) != DM_IOCTL)
1227 diff -NurpP --minimal linux-3.10.9/drivers/md/dm.c linux-3.10.9-vs2.3.6.6/drivers/md/dm.c
1228 --- linux-3.10.9/drivers/md/dm.c        2013-08-22 19:51:32.000000000 +0000
1229 +++ linux-3.10.9-vs2.3.6.6/drivers/md/dm.c      2013-08-22 20:29:59.000000000 +0000
1230 @@ -19,6 +19,7 @@
1231  #include <linux/idr.h>
1232  #include <linux/hdreg.h>
1233  #include <linux/delay.h>
1234 +#include <linux/vs_base.h>
1235  
1236  #include <trace/events/block.h>
1237  
1238 @@ -125,6 +126,7 @@ struct mapped_device {
1239         rwlock_t map_lock;
1240         atomic_t holders;
1241         atomic_t open_count;
1242 +       vxid_t xid;
1243  
1244         unsigned long flags;
1245  
1246 @@ -317,6 +319,7 @@ int dm_deleting_md(struct mapped_device
1247  static int dm_blk_open(struct block_device *bdev, fmode_t mode)
1248  {
1249         struct mapped_device *md;
1250 +       int ret = -ENXIO;
1251  
1252         spin_lock(&_minor_lock);
1253  
1254 @@ -325,18 +328,19 @@ static int dm_blk_open(struct block_devi
1255                 goto out;
1256  
1257         if (test_bit(DMF_FREEING, &md->flags) ||
1258 -           dm_deleting_md(md)) {
1259 -               md = NULL;
1260 +           dm_deleting_md(md))
1261 +               goto out;
1262 +
1263 +       ret = -EACCES;
1264 +       if (!vx_check(md->xid, VS_IDENT|VS_HOSTID))
1265                 goto out;
1266 -       }
1267  
1268         dm_get(md);
1269         atomic_inc(&md->open_count);
1270 -
1271 +       ret = 0;
1272  out:
1273         spin_unlock(&_minor_lock);
1274 -
1275 -       return md ? 0 : -ENXIO;
1276 +       return ret;
1277  }
1278  
1279  static void dm_blk_close(struct gendisk *disk, fmode_t mode)
1280 @@ -552,6 +556,14 @@ int dm_set_geometry(struct mapped_device
1281         return 0;
1282  }
1283  
1284 +/*
1285 + * Get the xid associated with a dm device
1286 + */
1287 +vxid_t dm_get_xid(struct mapped_device *md)
1288 +{
1289 +       return md->xid;
1290 +}
1291 +
1292  /*-----------------------------------------------------------------
1293   * CRUD START:
1294   *   A more elegant soln is in the works that uses the queue
1295 @@ -1889,6 +1901,7 @@ static struct mapped_device *alloc_dev(i
1296         INIT_LIST_HEAD(&md->uevent_list);
1297         spin_lock_init(&md->uevent_lock);
1298  
1299 +       md->xid = vx_current_xid();
1300         md->queue = blk_alloc_queue(GFP_KERNEL);
1301         if (!md->queue)
1302                 goto bad_queue;
1303 diff -NurpP --minimal linux-3.10.9/drivers/md/dm.h linux-3.10.9-vs2.3.6.6/drivers/md/dm.h
1304 --- linux-3.10.9/drivers/md/dm.h        2013-02-19 13:57:51.000000000 +0000
1305 +++ linux-3.10.9-vs2.3.6.6/drivers/md/dm.h      2013-08-22 20:29:59.000000000 +0000
1306 @@ -46,6 +46,8 @@ struct dm_dev_internal {
1307  struct dm_table;
1308  struct dm_md_mempools;
1309  
1310 +vxid_t dm_get_xid(struct mapped_device *md);
1311 +
1312  /*-----------------------------------------------------------------
1313   * Internal table functions.
1314   *---------------------------------------------------------------*/
1315 diff -NurpP --minimal linux-3.10.9/drivers/net/tun.c linux-3.10.9-vs2.3.6.6/drivers/net/tun.c
1316 --- linux-3.10.9/drivers/net/tun.c      2013-08-22 19:51:33.000000000 +0000
1317 +++ linux-3.10.9-vs2.3.6.6/drivers/net/tun.c    2013-08-22 20:29:59.000000000 +0000
1318 @@ -64,6 +64,7 @@
1319  #include <linux/nsproxy.h>
1320  #include <linux/virtio_net.h>
1321  #include <linux/rcupdate.h>
1322 +#include <linux/vs_network.h>
1323  #include <net/net_namespace.h>
1324  #include <net/netns/generic.h>
1325  #include <net/rtnetlink.h>
1326 @@ -164,6 +165,7 @@ struct tun_struct {
1327         unsigned int            flags;
1328         kuid_t                  owner;
1329         kgid_t                  group;
1330 +       vnid_t                  nid;
1331  
1332         struct net_device       *dev;
1333         netdev_features_t       set_features;
1334 @@ -380,6 +382,7 @@ static inline bool tun_not_capable(struc
1335         return ((uid_valid(tun->owner) && !uid_eq(cred->euid, tun->owner)) ||
1336                   (gid_valid(tun->group) && !in_egroup_p(tun->group))) &&
1337                 !ns_capable(net->user_ns, CAP_NET_ADMIN);
1338 +               /* !cap_raised(current_cap(), CAP_NET_ADMIN) */
1339  }
1340  
1341  static void tun_set_real_num_queues(struct tun_struct *tun)
1342 @@ -1423,6 +1426,7 @@ static void tun_setup(struct net_device
1343  
1344         tun->owner = INVALID_UID;
1345         tun->group = INVALID_GID;
1346 +       tun->nid = nx_current_nid();
1347  
1348         dev->ethtool_ops = &tun_ethtool_ops;
1349         dev->destructor = tun_free_netdev;
1350 @@ -1614,6 +1618,9 @@ static int tun_set_iff(struct net *net,
1351                 if (err < 0)
1352                         return err;
1353  
1354 +               if (!nx_check(tun->nid, VS_IDENT | VS_HOSTID | VS_ADMIN_P))
1355 +                       return -EPERM;
1356 +
1357                 err = tun_attach(tun, file);
1358                 if (err < 0)
1359                         return err;
1360 @@ -1632,7 +1639,7 @@ static int tun_set_iff(struct net *net,
1361                 int queues = ifr->ifr_flags & IFF_MULTI_QUEUE ?
1362                              MAX_TAP_QUEUES : 1;
1363  
1364 -               if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
1365 +               if (!vx_ns_capable(net->user_ns, CAP_NET_ADMIN, NXC_TUN_CREATE))
1366                         return -EPERM;
1367                 err = security_tun_dev_create();
1368                 if (err < 0)
1369 @@ -1978,6 +1985,16 @@ static long __tun_chr_ioctl(struct file
1370                           from_kgid(&init_user_ns, tun->group));
1371                 break;
1372  
1373 +       case TUNSETNID:
1374 +               if (!capable(CAP_CONTEXT))
1375 +                       return -EPERM;
1376 +
1377 +               /* Set nid owner of the device */
1378 +               tun->nid = (vnid_t) arg;
1379 +
1380 +               tun_debug(KERN_INFO, tun, "nid owner set to %u\n", tun->nid);
1381 +               break;
1382 +
1383         case TUNSETLINK:
1384                 /* Only allow setting the type when the interface is down */
1385                 if (tun->dev->flags & IFF_UP) {
1386 diff -NurpP --minimal linux-3.10.9/drivers/tty/sysrq.c linux-3.10.9-vs2.3.6.6/drivers/tty/sysrq.c
1387 --- linux-3.10.9/drivers/tty/sysrq.c    2013-07-14 17:01:22.000000000 +0000
1388 +++ linux-3.10.9-vs2.3.6.6/drivers/tty/sysrq.c  2013-08-22 20:58:35.000000000 +0000
1389 @@ -44,6 +44,7 @@
1390  #include <linux/uaccess.h>
1391  #include <linux/moduleparam.h>
1392  #include <linux/jiffies.h>
1393 +#include <linux/vserver/debug.h>
1394  
1395  #include <asm/ptrace.h>
1396  #include <asm/irq_regs.h>
1397 @@ -405,6 +406,21 @@ static struct sysrq_key_op sysrq_unrt_op
1398         .enable_mask    = SYSRQ_ENABLE_RTNICE,
1399  };
1400  
1401 +
1402 +#ifdef CONFIG_VSERVER_DEBUG
1403 +static void sysrq_handle_vxinfo(int key)
1404 +{
1405 +       dump_vx_info_inactive((key == 'x') ? 0 : 1);
1406 +}
1407 +
1408 +static struct sysrq_key_op sysrq_showvxinfo_op = {
1409 +       .handler        = sysrq_handle_vxinfo,
1410 +       .help_msg       = "conteXt",
1411 +       .action_msg     = "Show Context Info",
1412 +       .enable_mask    = SYSRQ_ENABLE_DUMP,
1413 +};
1414 +#endif
1415 +
1416  /* Key Operations table and lock */
1417  static DEFINE_SPINLOCK(sysrq_key_table_lock);
1418  
1419 @@ -460,7 +476,11 @@ static struct sysrq_key_op *sysrq_key_ta
1420         &sysrq_showstate_blocked_op,    /* w */
1421         /* x: May be registered on ppc/powerpc for xmon */
1422         /* x: May be registered on sparc64 for global PMU dump */
1423 +#ifdef CONFIG_VSERVER_DEBUG
1424 +       &sysrq_showvxinfo_op,           /* x */
1425 +#else
1426         NULL,                           /* x */
1427 +#endif
1428         /* y: May be registered on sparc64 for global register dump */
1429         NULL,                           /* y */
1430         &sysrq_ftrace_dump_op,          /* z */
1431 @@ -475,6 +495,8 @@ static int sysrq_key_table_key2index(int
1432                 retval = key - '0';
1433         else if ((key >= 'a') && (key <= 'z'))
1434                 retval = key + 10 - 'a';
1435 +       else if ((key >= 'A') && (key <= 'Z'))
1436 +               retval = key + 10 - 'A';
1437         else
1438                 retval = -1;
1439         return retval;
1440 diff -NurpP --minimal linux-3.10.9/drivers/tty/tty_io.c linux-3.10.9-vs2.3.6.6/drivers/tty/tty_io.c
1441 --- linux-3.10.9/drivers/tty/tty_io.c   2013-08-22 19:51:34.000000000 +0000
1442 +++ linux-3.10.9-vs2.3.6.6/drivers/tty/tty_io.c 2013-08-22 20:29:59.000000000 +0000
1443 @@ -104,6 +104,7 @@
1444  
1445  #include <linux/kmod.h>
1446  #include <linux/nsproxy.h>
1447 +#include <linux/vs_pid.h>
1448  
1449  #undef TTY_DEBUG_HANGUP
1450  
1451 @@ -2212,7 +2213,8 @@ static int tiocsti(struct tty_struct *tt
1452         char ch, mbz = 0;
1453         struct tty_ldisc *ld;
1454  
1455 -       if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN))
1456 +       if (((current->signal->tty != tty) &&
1457 +               !vx_capable(CAP_SYS_ADMIN, VXC_TIOCSTI)))
1458                 return -EPERM;
1459         if (get_user(ch, p))
1460                 return -EFAULT;
1461 @@ -2500,6 +2502,7 @@ static int tiocspgrp(struct tty_struct *
1462                 return -ENOTTY;
1463         if (get_user(pgrp_nr, p))
1464                 return -EFAULT;
1465 +       pgrp_nr = vx_rmap_pid(pgrp_nr);
1466         if (pgrp_nr < 0)
1467                 return -EINVAL;
1468         rcu_read_lock();
1469 diff -NurpP --minimal linux-3.10.9/fs/attr.c linux-3.10.9-vs2.3.6.6/fs/attr.c
1470 --- linux-3.10.9/fs/attr.c      2013-02-19 13:58:46.000000000 +0000
1471 +++ linux-3.10.9-vs2.3.6.6/fs/attr.c    2013-08-22 20:29:59.000000000 +0000
1472 @@ -15,6 +15,9 @@
1473  #include <linux/security.h>
1474  #include <linux/evm.h>
1475  #include <linux/ima.h>
1476 +#include <linux/proc_fs.h>
1477 +#include <linux/devpts_fs.h>
1478 +#include <linux/vs_tag.h>
1479  
1480  /**
1481   * inode_change_ok - check if attribute changes to an inode are allowed
1482 @@ -77,6 +80,10 @@ int inode_change_ok(const struct inode *
1483                         return -EPERM;
1484         }
1485  
1486 +       /* check for inode tag permission */
1487 +       if (dx_permission(inode, MAY_WRITE))
1488 +               return -EACCES;
1489 +
1490         return 0;
1491  }
1492  EXPORT_SYMBOL(inode_change_ok);
1493 @@ -147,6 +154,8 @@ void setattr_copy(struct inode *inode, c
1494                 inode->i_uid = attr->ia_uid;
1495         if (ia_valid & ATTR_GID)
1496                 inode->i_gid = attr->ia_gid;
1497 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
1498 +               inode->i_tag = attr->ia_tag;
1499         if (ia_valid & ATTR_ATIME)
1500                 inode->i_atime = timespec_trunc(attr->ia_atime,
1501                                                 inode->i_sb->s_time_gran);
1502 @@ -177,7 +186,8 @@ int notify_change(struct dentry * dentry
1503  
1504         WARN_ON_ONCE(!mutex_is_locked(&inode->i_mutex));
1505  
1506 -       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_TIMES_SET)) {
1507 +       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID |
1508 +               ATTR_TAG | ATTR_TIMES_SET)) {
1509                 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
1510                         return -EPERM;
1511         }
1512 diff -NurpP --minimal linux-3.10.9/fs/block_dev.c linux-3.10.9-vs2.3.6.6/fs/block_dev.c
1513 --- linux-3.10.9/fs/block_dev.c 2013-08-22 19:51:34.000000000 +0000
1514 +++ linux-3.10.9-vs2.3.6.6/fs/block_dev.c       2013-08-22 21:20:35.000000000 +0000
1515 @@ -28,6 +28,7 @@
1516  #include <linux/log2.h>
1517  #include <linux/cleancache.h>
1518  #include <linux/aio.h>
1519 +#include <linux/vs_device.h>
1520  #include <asm/uaccess.h>
1521  #include "internal.h"
1522  
1523 @@ -536,6 +537,7 @@ struct block_device *bdget(dev_t dev)
1524                 bdev->bd_invalidated = 0;
1525                 inode->i_mode = S_IFBLK;
1526                 inode->i_rdev = dev;
1527 +               inode->i_mdev = dev;
1528                 inode->i_bdev = bdev;
1529                 inode->i_data.a_ops = &def_blk_aops;
1530                 mapping_set_gfp_mask(&inode->i_data, GFP_USER);
1531 @@ -583,6 +585,11 @@ EXPORT_SYMBOL(bdput);
1532  static struct block_device *bd_acquire(struct inode *inode)
1533  {
1534         struct block_device *bdev;
1535 +       dev_t mdev;
1536 +
1537 +       if (!vs_map_blkdev(inode->i_rdev, &mdev, DATTR_OPEN))
1538 +               return NULL;
1539 +       inode->i_mdev = mdev;
1540  
1541         spin_lock(&bdev_lock);
1542         bdev = inode->i_bdev;
1543 @@ -593,7 +600,7 @@ static struct block_device *bd_acquire(s
1544         }
1545         spin_unlock(&bdev_lock);
1546  
1547 -       bdev = bdget(inode->i_rdev);
1548 +       bdev = bdget(mdev);
1549         if (bdev) {
1550                 spin_lock(&bdev_lock);
1551                 if (!inode->i_bdev) {
1552 diff -NurpP --minimal linux-3.10.9/fs/btrfs/ctree.h linux-3.10.9-vs2.3.6.6/fs/btrfs/ctree.h
1553 --- linux-3.10.9/fs/btrfs/ctree.h       2013-07-14 17:01:26.000000000 +0000
1554 +++ linux-3.10.9-vs2.3.6.6/fs/btrfs/ctree.h     2013-08-22 20:29:59.000000000 +0000
1555 @@ -707,11 +707,14 @@ struct btrfs_inode_item {
1556         /* modification sequence number for NFS */
1557         __le64 sequence;
1558  
1559 +       __le16 tag;
1560         /*
1561          * a little future expansion, for more than this we can
1562          * just grow the inode item and version it
1563          */
1564 -       __le64 reserved[4];
1565 +       __le16 reserved16;
1566 +       __le32 reserved32;
1567 +       __le64 reserved[3];
1568         struct btrfs_timespec atime;
1569         struct btrfs_timespec ctime;
1570         struct btrfs_timespec mtime;
1571 @@ -1928,6 +1931,8 @@ struct btrfs_ioctl_defrag_range_args {
1572  #define BTRFS_MOUNT_CHECK_INTEGRITY_INCLUDING_EXTENT_DATA (1 << 21)
1573  #define BTRFS_MOUNT_PANIC_ON_FATAL_ERROR       (1 << 22)
1574  
1575 +#define BTRFS_MOUNT_TAGGED             (1 << 24)
1576 +
1577  #define btrfs_clear_opt(o, opt)                ((o) &= ~BTRFS_MOUNT_##opt)
1578  #define btrfs_set_opt(o, opt)          ((o) |= BTRFS_MOUNT_##opt)
1579  #define btrfs_raw_test_opt(o, opt)     ((o) & BTRFS_MOUNT_##opt)
1580 @@ -2197,6 +2202,7 @@ BTRFS_SETGET_FUNCS(inode_block_group, st
1581  BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
1582  BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
1583  BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
1584 +BTRFS_SETGET_FUNCS(inode_tag, struct btrfs_inode_item, tag, 16);
1585  BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
1586  BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
1587  BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
1588 @@ -2250,6 +2256,10 @@ BTRFS_SETGET_FUNCS(extent_flags, struct
1589  
1590  BTRFS_SETGET_FUNCS(extent_refs_v0, struct btrfs_extent_item_v0, refs, 32);
1591  
1592 +#define BTRFS_INODE_IXUNLINK           (1 << 24)
1593 +#define BTRFS_INODE_BARRIER            (1 << 25)
1594 +#define BTRFS_INODE_COW                        (1 << 26)
1595 +
1596  
1597  BTRFS_SETGET_FUNCS(tree_block_level, struct btrfs_tree_block_info, level, 8);
1598  
1599 @@ -3578,6 +3588,7 @@ extern const struct dentry_operations bt
1600  long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
1601  void btrfs_update_iflags(struct inode *inode);
1602  void btrfs_inherit_iflags(struct inode *inode, struct inode *dir);
1603 +int btrfs_sync_flags(struct inode *inode, int, int);
1604  int btrfs_defrag_file(struct inode *inode, struct file *file,
1605                       struct btrfs_ioctl_defrag_range_args *range,
1606                       u64 newer_than, unsigned long max_pages);
1607 diff -NurpP --minimal linux-3.10.9/fs/btrfs/disk-io.c linux-3.10.9-vs2.3.6.6/fs/btrfs/disk-io.c
1608 --- linux-3.10.9/fs/btrfs/disk-io.c     2013-07-14 17:01:26.000000000 +0000
1609 +++ linux-3.10.9-vs2.3.6.6/fs/btrfs/disk-io.c   2013-08-22 20:29:59.000000000 +0000
1610 @@ -2360,6 +2360,9 @@ int open_ctree(struct super_block *sb,
1611                 goto fail_alloc;
1612         }
1613  
1614 +       if (btrfs_test_opt(tree_root, TAGGED))
1615 +               sb->s_flags |= MS_TAGGED;
1616 +
1617         features = btrfs_super_incompat_flags(disk_super) &
1618                 ~BTRFS_FEATURE_INCOMPAT_SUPP;
1619         if (features) {
1620 diff -NurpP --minimal linux-3.10.9/fs/btrfs/inode.c linux-3.10.9-vs2.3.6.6/fs/btrfs/inode.c
1621 --- linux-3.10.9/fs/btrfs/inode.c       2013-07-14 17:01:26.000000000 +0000
1622 +++ linux-3.10.9-vs2.3.6.6/fs/btrfs/inode.c     2013-08-22 20:29:59.000000000 +0000
1623 @@ -42,6 +42,7 @@
1624  #include <linux/mount.h>
1625  #include <linux/btrfs.h>
1626  #include <linux/blkdev.h>
1627 +#include <linux/vs_tag.h>
1628  #include "compat.h"
1629  #include "ctree.h"
1630  #include "disk-io.h"
1631 @@ -3327,6 +3328,9 @@ static void btrfs_read_locked_inode(stru
1632         struct btrfs_key location;
1633         int maybe_acls;
1634         u32 rdev;
1635 +       kuid_t kuid;
1636 +       kgid_t kgid;
1637 +       ktag_t ktag;
1638         int ret;
1639         bool filled = false;
1640  
1641 @@ -3354,8 +3358,14 @@ static void btrfs_read_locked_inode(stru
1642                                     struct btrfs_inode_item);
1643         inode->i_mode = btrfs_inode_mode(leaf, inode_item);
1644         set_nlink(inode, btrfs_inode_nlink(leaf, inode_item));
1645 -       i_uid_write(inode, btrfs_inode_uid(leaf, inode_item));
1646 -       i_gid_write(inode, btrfs_inode_gid(leaf, inode_item));
1647 +
1648 +       kuid = make_kuid(&init_user_ns, btrfs_inode_uid(leaf, inode_item));
1649 +       kgid = make_kgid(&init_user_ns, btrfs_inode_gid(leaf, inode_item));
1650 +       ktag = make_ktag(&init_user_ns, btrfs_inode_tag(leaf, inode_item));
1651 +
1652 +       inode->i_uid = INOTAG_KUID(DX_TAG(inode), kuid, kgid);
1653 +       inode->i_gid = INOTAG_KGID(DX_TAG(inode), kuid, kgid);
1654 +       inode->i_tag = INOTAG_KTAG(DX_TAG(inode), kuid, kgid, ktag);
1655         btrfs_i_size_write(inode, btrfs_inode_size(leaf, inode_item));
1656  
1657         tspec = btrfs_inode_atime(inode_item);
1658 @@ -3446,11 +3456,18 @@ static void fill_inode_item(struct btrfs
1659                             struct inode *inode)
1660  {
1661         struct btrfs_map_token token;
1662 +       uid_t uid = from_kuid(&init_user_ns,
1663 +               TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag));
1664 +       gid_t gid = from_kgid(&init_user_ns,
1665 +               TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag));
1666  
1667         btrfs_init_map_token(&token);
1668  
1669 -       btrfs_set_token_inode_uid(leaf, item, i_uid_read(inode), &token);
1670 -       btrfs_set_token_inode_gid(leaf, item, i_gid_read(inode), &token);
1671 +       btrfs_set_token_inode_uid(leaf, item, uid, &token);
1672 +       btrfs_set_token_inode_gid(leaf, item, gid, &token);
1673 +#ifdef CONFIG_TAGGING_INTERN
1674 +       btrfs_set_token_inode_tag(leaf, item, i_tag_read(inode), &token);
1675 +#endif
1676         btrfs_set_token_inode_size(leaf, item, BTRFS_I(inode)->disk_i_size,
1677                                    &token);
1678         btrfs_set_token_inode_mode(leaf, item, inode->i_mode, &token);
1679 @@ -8720,11 +8737,13 @@ static const struct inode_operations btr
1680         .listxattr      = btrfs_listxattr,
1681         .removexattr    = btrfs_removexattr,
1682         .permission     = btrfs_permission,
1683 +       .sync_flags     = btrfs_sync_flags,
1684         .get_acl        = btrfs_get_acl,
1685  };
1686  static const struct inode_operations btrfs_dir_ro_inode_operations = {
1687         .lookup         = btrfs_lookup,
1688         .permission     = btrfs_permission,
1689 +       .sync_flags     = btrfs_sync_flags,
1690         .get_acl        = btrfs_get_acl,
1691  };
1692  
1693 diff -NurpP --minimal linux-3.10.9/fs/btrfs/ioctl.c linux-3.10.9-vs2.3.6.6/fs/btrfs/ioctl.c
1694 --- linux-3.10.9/fs/btrfs/ioctl.c       2013-07-14 17:01:26.000000000 +0000
1695 +++ linux-3.10.9-vs2.3.6.6/fs/btrfs/ioctl.c     2013-08-22 20:29:59.000000000 +0000
1696 @@ -75,10 +75,13 @@ static unsigned int btrfs_flags_to_ioctl
1697  {
1698         unsigned int iflags = 0;
1699  
1700 -       if (flags & BTRFS_INODE_SYNC)
1701 -               iflags |= FS_SYNC_FL;
1702         if (flags & BTRFS_INODE_IMMUTABLE)
1703                 iflags |= FS_IMMUTABLE_FL;
1704 +       if (flags & BTRFS_INODE_IXUNLINK)
1705 +               iflags |= FS_IXUNLINK_FL;
1706 +
1707 +       if (flags & BTRFS_INODE_SYNC)
1708 +               iflags |= FS_SYNC_FL;
1709         if (flags & BTRFS_INODE_APPEND)
1710                 iflags |= FS_APPEND_FL;
1711         if (flags & BTRFS_INODE_NODUMP)
1712 @@ -95,28 +98,78 @@ static unsigned int btrfs_flags_to_ioctl
1713         else if (flags & BTRFS_INODE_NOCOMPRESS)
1714                 iflags |= FS_NOCOMP_FL;
1715  
1716 +       if (flags & BTRFS_INODE_BARRIER)
1717 +               iflags |= FS_BARRIER_FL;
1718 +       if (flags & BTRFS_INODE_COW)
1719 +               iflags |= FS_COW_FL;
1720         return iflags;
1721  }
1722  
1723  /*
1724 - * Update inode->i_flags based on the btrfs internal flags.
1725 + * Update inode->i_(v)flags based on the btrfs internal flags.
1726   */
1727  void btrfs_update_iflags(struct inode *inode)
1728  {
1729         struct btrfs_inode *ip = BTRFS_I(inode);
1730  
1731 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
1732 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
1733 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
1734  
1735 -       if (ip->flags & BTRFS_INODE_SYNC)
1736 -               inode->i_flags |= S_SYNC;
1737         if (ip->flags & BTRFS_INODE_IMMUTABLE)
1738                 inode->i_flags |= S_IMMUTABLE;
1739 +       if (ip->flags & BTRFS_INODE_IXUNLINK)
1740 +               inode->i_flags |= S_IXUNLINK;
1741 +
1742 +       if (ip->flags & BTRFS_INODE_SYNC)
1743 +               inode->i_flags |= S_SYNC;
1744         if (ip->flags & BTRFS_INODE_APPEND)
1745                 inode->i_flags |= S_APPEND;
1746         if (ip->flags & BTRFS_INODE_NOATIME)
1747                 inode->i_flags |= S_NOATIME;
1748         if (ip->flags & BTRFS_INODE_DIRSYNC)
1749                 inode->i_flags |= S_DIRSYNC;
1750 +
1751 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
1752 +
1753 +       if (ip->flags & BTRFS_INODE_BARRIER)
1754 +               inode->i_vflags |= V_BARRIER;
1755 +       if (ip->flags & BTRFS_INODE_COW)
1756 +               inode->i_vflags |= V_COW;
1757 +}
1758 +
1759 +/*
1760 + * Update btrfs internal flags from inode->i_(v)flags.
1761 + */
1762 +void btrfs_update_flags(struct inode *inode)
1763 +{
1764 +       struct btrfs_inode *ip = BTRFS_I(inode);
1765 +
1766 +       unsigned int flags = inode->i_flags;
1767 +       unsigned int vflags = inode->i_vflags;
1768 +
1769 +       ip->flags &= ~(BTRFS_INODE_SYNC | BTRFS_INODE_APPEND |
1770 +                       BTRFS_INODE_IMMUTABLE | BTRFS_INODE_IXUNLINK |
1771 +                       BTRFS_INODE_NOATIME | BTRFS_INODE_DIRSYNC |
1772 +                       BTRFS_INODE_BARRIER | BTRFS_INODE_COW);
1773 +
1774 +       if (flags & S_IMMUTABLE)
1775 +               ip->flags |= BTRFS_INODE_IMMUTABLE;
1776 +       if (flags & S_IXUNLINK)
1777 +               ip->flags |= BTRFS_INODE_IXUNLINK;
1778 +
1779 +       if (flags & S_SYNC)
1780 +               ip->flags |= BTRFS_INODE_SYNC;
1781 +       if (flags & S_APPEND)
1782 +               ip->flags |= BTRFS_INODE_APPEND;
1783 +       if (flags & S_NOATIME)
1784 +               ip->flags |= BTRFS_INODE_NOATIME;
1785 +       if (flags & S_DIRSYNC)
1786 +               ip->flags |= BTRFS_INODE_DIRSYNC;
1787 +
1788 +       if (vflags & V_BARRIER)
1789 +               ip->flags |= BTRFS_INODE_BARRIER;
1790 +       if (vflags & V_COW)
1791 +               ip->flags |= BTRFS_INODE_COW;
1792  }
1793  
1794  /*
1795 @@ -132,6 +185,7 @@ void btrfs_inherit_iflags(struct inode *
1796                 return;
1797  
1798         flags = BTRFS_I(dir)->flags;
1799 +       flags &= ~BTRFS_INODE_BARRIER;
1800  
1801         if (flags & BTRFS_INODE_NOCOMPRESS) {
1802                 BTRFS_I(inode)->flags &= ~BTRFS_INODE_COMPRESS;
1803 @@ -150,6 +204,30 @@ void btrfs_inherit_iflags(struct inode *
1804         btrfs_update_iflags(inode);
1805  }
1806  
1807 +int btrfs_sync_flags(struct inode *inode, int flags, int vflags)
1808 +{
1809 +       struct btrfs_inode *ip = BTRFS_I(inode);
1810 +       struct btrfs_root *root = ip->root;
1811 +       struct btrfs_trans_handle *trans;
1812 +       int ret;
1813 +
1814 +       trans = btrfs_join_transaction(root);
1815 +       BUG_ON(!trans);
1816 +
1817 +       inode->i_flags = flags;
1818 +       inode->i_vflags = vflags;
1819 +       btrfs_update_flags(inode);
1820 +
1821 +       ret = btrfs_update_inode(trans, root, inode);
1822 +       BUG_ON(ret);
1823 +
1824 +       btrfs_update_iflags(inode);
1825 +       inode->i_ctime = CURRENT_TIME;
1826 +       btrfs_end_transaction(trans, root);
1827 +
1828 +       return 0;
1829 +}
1830 +
1831  static int btrfs_ioctl_getflags(struct file *file, void __user *arg)
1832  {
1833         struct btrfs_inode *ip = BTRFS_I(file_inode(file));
1834 @@ -212,21 +290,27 @@ static int btrfs_ioctl_setflags(struct f
1835  
1836         flags = btrfs_mask_flags(inode->i_mode, flags);
1837         oldflags = btrfs_flags_to_ioctl(ip->flags);
1838 -       if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) {
1839 +       if ((flags ^ oldflags) & (FS_APPEND_FL |
1840 +               FS_IMMUTABLE_FL | FS_IXUNLINK_FL)) {
1841                 if (!capable(CAP_LINUX_IMMUTABLE)) {
1842                         ret = -EPERM;
1843                         goto out_unlock;
1844                 }
1845         }
1846  
1847 -       if (flags & FS_SYNC_FL)
1848 -               ip->flags |= BTRFS_INODE_SYNC;
1849 -       else
1850 -               ip->flags &= ~BTRFS_INODE_SYNC;
1851         if (flags & FS_IMMUTABLE_FL)
1852                 ip->flags |= BTRFS_INODE_IMMUTABLE;
1853         else
1854                 ip->flags &= ~BTRFS_INODE_IMMUTABLE;
1855 +       if (flags & FS_IXUNLINK_FL)
1856 +               ip->flags |= BTRFS_INODE_IXUNLINK;
1857 +       else
1858 +               ip->flags &= ~BTRFS_INODE_IXUNLINK;
1859 +
1860 +       if (flags & FS_SYNC_FL)
1861 +               ip->flags |= BTRFS_INODE_SYNC;
1862 +       else
1863 +               ip->flags &= ~BTRFS_INODE_SYNC;
1864         if (flags & FS_APPEND_FL)
1865                 ip->flags |= BTRFS_INODE_APPEND;
1866         else
1867 diff -NurpP --minimal linux-3.10.9/fs/btrfs/super.c linux-3.10.9-vs2.3.6.6/fs/btrfs/super.c
1868 --- linux-3.10.9/fs/btrfs/super.c       2013-07-14 17:01:26.000000000 +0000
1869 +++ linux-3.10.9-vs2.3.6.6/fs/btrfs/super.c     2013-08-22 20:29:59.000000000 +0000
1870 @@ -319,7 +319,7 @@ enum {
1871         Opt_no_space_cache, Opt_recovery, Opt_skip_balance,
1872         Opt_check_integrity, Opt_check_integrity_including_extent_data,
1873         Opt_check_integrity_print_mask, Opt_fatal_errors,
1874 -       Opt_err,
1875 +       Opt_tag, Opt_notag, Opt_tagid, Opt_err,
1876  };
1877  
1878  static match_table_t tokens = {
1879 @@ -359,6 +359,9 @@ static match_table_t tokens = {
1880         {Opt_check_integrity_including_extent_data, "check_int_data"},
1881         {Opt_check_integrity_print_mask, "check_int_print_mask=%d"},
1882         {Opt_fatal_errors, "fatal_errors=%s"},
1883 +       {Opt_tag, "tag"},
1884 +       {Opt_notag, "notag"},
1885 +       {Opt_tagid, "tagid=%u"},
1886         {Opt_err, NULL},
1887  };
1888  
1889 @@ -624,6 +627,22 @@ int btrfs_parse_options(struct btrfs_roo
1890                                 goto out;
1891                         }
1892                         break;
1893 +#ifndef CONFIG_TAGGING_NONE
1894 +               case Opt_tag:
1895 +                       printk(KERN_INFO "btrfs: use tagging\n");
1896 +                       btrfs_set_opt(info->mount_opt, TAGGED);
1897 +                       break;
1898 +               case Opt_notag:
1899 +                       printk(KERN_INFO "btrfs: disabled tagging\n");
1900 +                       btrfs_clear_opt(info->mount_opt, TAGGED);
1901 +                       break;
1902 +#endif
1903 +#ifdef CONFIG_PROPAGATE
1904 +               case Opt_tagid:
1905 +                       /* use args[0] */
1906 +                       btrfs_set_opt(info->mount_opt, TAGGED);
1907 +                       break;
1908 +#endif
1909                 case Opt_err:
1910                         printk(KERN_INFO "btrfs: unrecognized mount option "
1911                                "'%s'\n", p);
1912 @@ -1251,6 +1270,12 @@ static int btrfs_remount(struct super_bl
1913         btrfs_resize_thread_pool(fs_info,
1914                 fs_info->thread_pool_size, old_thread_pool_size);
1915  
1916 +       if (btrfs_test_opt(root, TAGGED) && !(sb->s_flags & MS_TAGGED)) {
1917 +               printk("btrfs: %s: tagging not permitted on remount.\n",
1918 +                       sb->s_id);
1919 +               return -EINVAL;
1920 +       }
1921 +
1922         if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
1923                 goto out;
1924  
1925 diff -NurpP --minimal linux-3.10.9/fs/char_dev.c linux-3.10.9-vs2.3.6.6/fs/char_dev.c
1926 --- linux-3.10.9/fs/char_dev.c  2012-12-11 03:30:57.000000000 +0000
1927 +++ linux-3.10.9-vs2.3.6.6/fs/char_dev.c        2013-08-22 20:29:59.000000000 +0000
1928 @@ -21,6 +21,8 @@
1929  #include <linux/mutex.h>
1930  #include <linux/backing-dev.h>
1931  #include <linux/tty.h>
1932 +#include <linux/vs_context.h>
1933 +#include <linux/vs_device.h>
1934  
1935  #include "internal.h"
1936  
1937 @@ -371,14 +373,21 @@ static int chrdev_open(struct inode *ino
1938         struct cdev *p;
1939         struct cdev *new = NULL;
1940         int ret = 0;
1941 +       dev_t mdev;
1942 +
1943 +       if (!vs_map_chrdev(inode->i_rdev, &mdev, DATTR_OPEN))
1944 +               return -EPERM;
1945 +       inode->i_mdev = mdev;
1946  
1947         spin_lock(&cdev_lock);
1948         p = inode->i_cdev;
1949         if (!p) {
1950                 struct kobject *kobj;
1951                 int idx;
1952 +
1953                 spin_unlock(&cdev_lock);
1954 -               kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
1955 +
1956 +               kobj = kobj_lookup(cdev_map, mdev, &idx);
1957                 if (!kobj)
1958                         return -ENXIO;
1959                 new = container_of(kobj, struct cdev, kobj);
1960 diff -NurpP --minimal linux-3.10.9/fs/dcache.c linux-3.10.9-vs2.3.6.6/fs/dcache.c
1961 --- linux-3.10.9/fs/dcache.c    2013-07-14 17:01:27.000000000 +0000
1962 +++ linux-3.10.9-vs2.3.6.6/fs/dcache.c  2013-08-22 20:29:59.000000000 +0000
1963 @@ -37,6 +37,7 @@
1964  #include <linux/rculist_bl.h>
1965  #include <linux/prefetch.h>
1966  #include <linux/ratelimit.h>
1967 +#include <linux/vs_limit.h>
1968  #include "internal.h"
1969  #include "mount.h"
1970  
1971 @@ -578,6 +579,8 @@ int d_invalidate(struct dentry * dentry)
1972                 spin_lock(&dentry->d_lock);
1973         }
1974  
1975 +       vx_dentry_dec(dentry);
1976 +
1977         /*
1978          * Somebody else still using it?
1979          *
1980 @@ -607,6 +610,7 @@ EXPORT_SYMBOL(d_invalidate);
1981  static inline void __dget_dlock(struct dentry *dentry)
1982  {
1983         dentry->d_count++;
1984 +       vx_dentry_inc(dentry);
1985  }
1986  
1987  static inline void __dget(struct dentry *dentry)
1988 @@ -1239,6 +1243,9 @@ struct dentry *__d_alloc(struct super_bl
1989         struct dentry *dentry;
1990         char *dname;
1991  
1992 +       if (!vx_dentry_avail(1))
1993 +               return NULL;
1994 +
1995         dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
1996         if (!dentry)
1997                 return NULL;
1998 @@ -1271,6 +1278,7 @@ struct dentry *__d_alloc(struct super_bl
1999  
2000         dentry->d_count = 1;
2001         dentry->d_flags = 0;
2002 +       vx_dentry_inc(dentry);
2003         spin_lock_init(&dentry->d_lock);
2004         seqcount_init(&dentry->d_seq);
2005         dentry->d_inode = NULL;
2006 @@ -1971,6 +1979,7 @@ struct dentry *__d_lookup(const struct d
2007                 }
2008  
2009                 dentry->d_count++;
2010 +               vx_dentry_inc(dentry);
2011                 found = dentry;
2012                 spin_unlock(&dentry->d_lock);
2013                 break;
2014 diff -NurpP --minimal linux-3.10.9/fs/devpts/inode.c linux-3.10.9-vs2.3.6.6/fs/devpts/inode.c
2015 --- linux-3.10.9/fs/devpts/inode.c      2013-05-31 13:45:23.000000000 +0000
2016 +++ linux-3.10.9-vs2.3.6.6/fs/devpts/inode.c    2013-08-22 20:29:59.000000000 +0000
2017 @@ -25,6 +25,7 @@
2018  #include <linux/parser.h>
2019  #include <linux/fsnotify.h>
2020  #include <linux/seq_file.h>
2021 +#include <linux/vs_base.h>
2022  
2023  #define DEVPTS_DEFAULT_MODE 0600
2024  /*
2025 @@ -36,6 +37,21 @@
2026  #define DEVPTS_DEFAULT_PTMX_MODE 0000
2027  #define PTMX_MINOR     2
2028  
2029 +static int devpts_permission(struct inode *inode, int mask)
2030 +{
2031 +       int ret = -EACCES;
2032 +
2033 +       /* devpts is xid tagged */
2034 +       if (vx_check((vxid_t)i_tag_read(inode), VS_WATCH_P | VS_IDENT))
2035 +               ret = generic_permission(inode, mask);
2036 +       return ret;
2037 +}
2038 +
2039 +static struct inode_operations devpts_file_inode_operations = {
2040 +       .permission     = devpts_permission,
2041 +};
2042 +
2043 +
2044  /*
2045   * sysctl support for setting limits on the number of Unix98 ptys allocated.
2046   * Otherwise one can eat up all kernel memory by opening /dev/ptmx repeatedly.
2047 @@ -345,6 +361,34 @@ static int devpts_show_options(struct se
2048         return 0;
2049  }
2050  
2051 +static int devpts_filter(struct dentry *de)
2052 +{
2053 +       vxid_t xid = 0;
2054 +
2055 +       /* devpts is xid tagged */
2056 +       if (de && de->d_inode)
2057 +               xid = (vxid_t)i_tag_read(de->d_inode);
2058 +#ifdef CONFIG_VSERVER_WARN_DEVPTS
2059 +       else
2060 +               vxwprintk_task(1, "devpts " VS_Q("%.*s") " without inode.",
2061 +                       de->d_name.len, de->d_name.name);
2062 +#endif
2063 +       return vx_check(xid, VS_WATCH_P | VS_IDENT);
2064 +}
2065 +
2066 +static int devpts_readdir(struct file * filp, void * dirent, filldir_t filldir)
2067 +{
2068 +       return dcache_readdir_filter(filp, dirent, filldir, devpts_filter);
2069 +}
2070 +
2071 +static struct file_operations devpts_dir_operations = {
2072 +       .open           = dcache_dir_open,
2073 +       .release        = dcache_dir_close,
2074 +       .llseek         = dcache_dir_lseek,
2075 +       .read           = generic_read_dir,
2076 +       .readdir        = devpts_readdir,
2077 +};
2078 +
2079  static const struct super_operations devpts_sops = {
2080         .statfs         = simple_statfs,
2081         .remount_fs     = devpts_remount,
2082 @@ -388,8 +432,10 @@ devpts_fill_super(struct super_block *s,
2083         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2084         inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
2085         inode->i_op = &simple_dir_inode_operations;
2086 -       inode->i_fop = &simple_dir_operations;
2087 +       inode->i_fop = &devpts_dir_operations;
2088         set_nlink(inode, 2);
2089 +       /* devpts is xid tagged */
2090 +       i_tag_write(inode, (vtag_t)vx_current_xid());
2091  
2092         s->s_root = d_make_root(inode);
2093         if (s->s_root)
2094 @@ -592,6 +638,9 @@ struct inode *devpts_pty_new(struct inod
2095         inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
2096         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2097         init_special_inode(inode, S_IFCHR|opts->mode, device);
2098 +       /* devpts is xid tagged */
2099 +       i_tag_write(inode, (vtag_t)vx_current_xid());
2100 +       inode->i_op = &devpts_file_inode_operations;
2101         inode->i_private = priv;
2102  
2103         sprintf(s, "%d", index);
2104 diff -NurpP --minimal linux-3.10.9/fs/ext2/balloc.c linux-3.10.9-vs2.3.6.6/fs/ext2/balloc.c
2105 --- linux-3.10.9/fs/ext2/balloc.c       2013-05-31 13:45:23.000000000 +0000
2106 +++ linux-3.10.9-vs2.3.6.6/fs/ext2/balloc.c     2013-08-22 20:29:59.000000000 +0000
2107 @@ -693,7 +693,6 @@ ext2_try_to_allocate(struct super_block
2108                         start = 0;
2109                 end = EXT2_BLOCKS_PER_GROUP(sb);
2110         }
2111 -
2112         BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
2113  
2114  repeat:
2115 diff -NurpP --minimal linux-3.10.9/fs/ext2/ext2.h linux-3.10.9-vs2.3.6.6/fs/ext2/ext2.h
2116 --- linux-3.10.9/fs/ext2/ext2.h 2012-12-11 03:30:57.000000000 +0000
2117 +++ linux-3.10.9-vs2.3.6.6/fs/ext2/ext2.h       2013-08-22 20:29:59.000000000 +0000
2118 @@ -244,8 +244,12 @@ struct ext2_group_desc
2119  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
2120  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
2121  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
2122 +#define EXT2_IXUNLINK_FL               FS_IXUNLINK_FL  /* Immutable invert on unlink */
2123  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
2124  
2125 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
2126 +#define EXT2_COW_FL                    FS_COW_FL       /* Copy on Write marker */
2127 +
2128  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
2129  #define EXT2_FL_USER_MODIFIABLE                FS_FL_USER_MODIFIABLE   /* User modifiable flags */
2130  
2131 @@ -329,7 +333,8 @@ struct ext2_inode {
2132                         __u16   i_pad1;
2133                         __le16  l_i_uid_high;   /* these 2 fields    */
2134                         __le16  l_i_gid_high;   /* were reserved2[0] */
2135 -                       __u32   l_i_reserved2;
2136 +                       __le16  l_i_tag;        /* Context Tag */
2137 +                       __u16   l_i_reserved2;
2138                 } linux2;
2139                 struct {
2140                         __u8    h_i_frag;       /* Fragment number */
2141 @@ -357,6 +362,7 @@ struct ext2_inode {
2142  #define i_gid_low      i_gid
2143  #define i_uid_high     osd2.linux2.l_i_uid_high
2144  #define i_gid_high     osd2.linux2.l_i_gid_high
2145 +#define i_raw_tag      osd2.linux2.l_i_tag
2146  #define i_reserved2    osd2.linux2.l_i_reserved2
2147  
2148  /*
2149 @@ -384,6 +390,7 @@ struct ext2_inode {
2150  #define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
2151  #define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
2152  #define EXT2_MOUNT_RESERVATION         0x080000  /* Preallocation */
2153 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
2154  
2155  
2156  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
2157 @@ -757,6 +764,7 @@ extern void ext2_set_inode_flags(struct
2158  extern void ext2_get_inode_flags(struct ext2_inode_info *);
2159  extern int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2160                        u64 start, u64 len);
2161 +extern int ext2_sync_flags(struct inode *, int, int);
2162  
2163  /* ioctl.c */
2164  extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
2165 diff -NurpP --minimal linux-3.10.9/fs/ext2/file.c linux-3.10.9-vs2.3.6.6/fs/ext2/file.c
2166 --- linux-3.10.9/fs/ext2/file.c 2012-12-11 03:30:57.000000000 +0000
2167 +++ linux-3.10.9-vs2.3.6.6/fs/ext2/file.c       2013-08-22 20:29:59.000000000 +0000
2168 @@ -104,4 +104,5 @@ const struct inode_operations ext2_file_
2169         .setattr        = ext2_setattr,
2170         .get_acl        = ext2_get_acl,
2171         .fiemap         = ext2_fiemap,
2172 +       .sync_flags     = ext2_sync_flags,
2173  };
2174 diff -NurpP --minimal linux-3.10.9/fs/ext2/ialloc.c linux-3.10.9-vs2.3.6.6/fs/ext2/ialloc.c
2175 --- linux-3.10.9/fs/ext2/ialloc.c       2013-05-31 13:45:23.000000000 +0000
2176 +++ linux-3.10.9-vs2.3.6.6/fs/ext2/ialloc.c     2013-08-22 20:29:59.000000000 +0000
2177 @@ -17,6 +17,7 @@
2178  #include <linux/backing-dev.h>
2179  #include <linux/buffer_head.h>
2180  #include <linux/random.h>
2181 +#include <linux/vs_tag.h>
2182  #include "ext2.h"
2183  #include "xattr.h"
2184  #include "acl.h"
2185 @@ -546,6 +547,7 @@ got:
2186                 inode->i_mode = mode;
2187                 inode->i_uid = current_fsuid();
2188                 inode->i_gid = dir->i_gid;
2189 +               i_tag_write(inode, dx_current_fstag(sb));
2190         } else
2191                 inode_init_owner(inode, dir, mode);
2192  
2193 diff -NurpP --minimal linux-3.10.9/fs/ext2/inode.c linux-3.10.9-vs2.3.6.6/fs/ext2/inode.c
2194 --- linux-3.10.9/fs/ext2/inode.c        2013-07-14 17:01:27.000000000 +0000
2195 +++ linux-3.10.9-vs2.3.6.6/fs/ext2/inode.c      2013-08-22 21:46:54.000000000 +0000
2196 @@ -32,6 +32,7 @@
2197  #include <linux/fiemap.h>
2198  #include <linux/namei.h>
2199  #include <linux/aio.h>
2200 +#include <linux/vs_tag.h>
2201  #include "ext2.h"
2202  #include "acl.h"
2203  #include "xip.h"
2204 @@ -1180,7 +1181,7 @@ static void ext2_truncate_blocks(struct
2205                 return;
2206         if (ext2_inode_is_fast_symlink(inode))
2207                 return;
2208 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2209 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2210                 return;
2211         __ext2_truncate_blocks(inode, offset);
2212  }
2213 @@ -1271,36 +1272,61 @@ void ext2_set_inode_flags(struct inode *
2214  {
2215         unsigned int flags = EXT2_I(inode)->i_flags;
2216  
2217 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2218 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2219 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2220 +
2221 +
2222 +       if (flags & EXT2_IMMUTABLE_FL)
2223 +               inode->i_flags |= S_IMMUTABLE;
2224 +       if (flags & EXT2_IXUNLINK_FL)
2225 +               inode->i_flags |= S_IXUNLINK;
2226 +
2227         if (flags & EXT2_SYNC_FL)
2228                 inode->i_flags |= S_SYNC;
2229         if (flags & EXT2_APPEND_FL)
2230                 inode->i_flags |= S_APPEND;
2231 -       if (flags & EXT2_IMMUTABLE_FL)
2232 -               inode->i_flags |= S_IMMUTABLE;
2233         if (flags & EXT2_NOATIME_FL)
2234                 inode->i_flags |= S_NOATIME;
2235         if (flags & EXT2_DIRSYNC_FL)
2236                 inode->i_flags |= S_DIRSYNC;
2237 +
2238 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2239 +
2240 +       if (flags & EXT2_BARRIER_FL)
2241 +               inode->i_vflags |= V_BARRIER;
2242 +       if (flags & EXT2_COW_FL)
2243 +               inode->i_vflags |= V_COW;
2244  }
2245  
2246  /* Propagate flags from i_flags to EXT2_I(inode)->i_flags */
2247  void ext2_get_inode_flags(struct ext2_inode_info *ei)
2248  {
2249         unsigned int flags = ei->vfs_inode.i_flags;
2250 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2251 +
2252 +       ei->i_flags &= ~(EXT2_SYNC_FL | EXT2_APPEND_FL |
2253 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL |
2254 +                       EXT2_NOATIME_FL | EXT2_DIRSYNC_FL |
2255 +                       EXT2_BARRIER_FL | EXT2_COW_FL);
2256 +
2257 +       if (flags & S_IMMUTABLE)
2258 +               ei->i_flags |= EXT2_IMMUTABLE_FL;
2259 +       if (flags & S_IXUNLINK)
2260 +               ei->i_flags |= EXT2_IXUNLINK_FL;
2261  
2262 -       ei->i_flags &= ~(EXT2_SYNC_FL|EXT2_APPEND_FL|
2263 -                       EXT2_IMMUTABLE_FL|EXT2_NOATIME_FL|EXT2_DIRSYNC_FL);
2264         if (flags & S_SYNC)
2265                 ei->i_flags |= EXT2_SYNC_FL;
2266         if (flags & S_APPEND)
2267                 ei->i_flags |= EXT2_APPEND_FL;
2268 -       if (flags & S_IMMUTABLE)
2269 -               ei->i_flags |= EXT2_IMMUTABLE_FL;
2270         if (flags & S_NOATIME)
2271                 ei->i_flags |= EXT2_NOATIME_FL;
2272         if (flags & S_DIRSYNC)
2273                 ei->i_flags |= EXT2_DIRSYNC_FL;
2274 +
2275 +       if (vflags & V_BARRIER)
2276 +               ei->i_flags |= EXT2_BARRIER_FL;
2277 +       if (vflags & V_COW)
2278 +               ei->i_flags |= EXT2_COW_FL;
2279  }
2280  
2281  struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
2282 @@ -1336,8 +1362,10 @@ struct inode *ext2_iget (struct super_bl
2283                 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2284                 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2285         }
2286 -       i_uid_write(inode, i_uid);
2287 -       i_gid_write(inode, i_gid);
2288 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
2289 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
2290 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
2291 +               le16_to_cpu(raw_inode->i_raw_tag)));
2292         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2293         inode->i_size = le32_to_cpu(raw_inode->i_size);
2294         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2295 @@ -1435,8 +1463,10 @@ static int __ext2_write_inode(struct ino
2296         struct ext2_inode_info *ei = EXT2_I(inode);
2297         struct super_block *sb = inode->i_sb;
2298         ino_t ino = inode->i_ino;
2299 -       uid_t uid = i_uid_read(inode);
2300 -       gid_t gid = i_gid_read(inode);
2301 +       uid_t uid = from_kuid(&init_user_ns,
2302 +               TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag));
2303 +       gid_t gid = from_kgid(&init_user_ns,
2304 +               TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag));
2305         struct buffer_head * bh;
2306         struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2307         int n;
2308 @@ -1472,6 +1502,9 @@ static int __ext2_write_inode(struct ino
2309                 raw_inode->i_uid_high = 0;
2310                 raw_inode->i_gid_high = 0;
2311         }
2312 +#ifdef CONFIG_TAGGING_INTERN
2313 +       raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
2314 +#endif
2315         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2316         raw_inode->i_size = cpu_to_le32(inode->i_size);
2317         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2318 @@ -1552,7 +1585,8 @@ int ext2_setattr(struct dentry *dentry,
2319         if (is_quota_modification(inode, iattr))
2320                 dquot_initialize(inode);
2321         if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
2322 -           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
2323 +           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid)) ||
2324 +           (iattr->ia_valid & ATTR_TAG && !tag_eq(iattr->ia_tag, inode->i_tag))) {
2325                 error = dquot_transfer(inode, iattr);
2326                 if (error)
2327                         return error;
2328 diff -NurpP --minimal linux-3.10.9/fs/ext2/ioctl.c linux-3.10.9-vs2.3.6.6/fs/ext2/ioctl.c
2329 --- linux-3.10.9/fs/ext2/ioctl.c        2013-05-31 13:45:23.000000000 +0000
2330 +++ linux-3.10.9-vs2.3.6.6/fs/ext2/ioctl.c      2013-08-22 20:29:59.000000000 +0000
2331 @@ -17,6 +17,16 @@
2332  #include <asm/uaccess.h>
2333  
2334  
2335 +int ext2_sync_flags(struct inode *inode, int flags, int vflags)
2336 +{
2337 +       inode->i_flags = flags;
2338 +       inode->i_vflags = vflags;
2339 +       ext2_get_inode_flags(EXT2_I(inode));
2340 +       inode->i_ctime = CURRENT_TIME_SEC;
2341 +       mark_inode_dirty(inode);
2342 +       return 0;
2343 +}
2344 +
2345  long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2346  {
2347         struct inode *inode = file_inode(filp);
2348 @@ -51,6 +61,11 @@ long ext2_ioctl(struct file *filp, unsig
2349  
2350                 flags = ext2_mask_flags(inode->i_mode, flags);
2351  
2352 +               if (IS_BARRIER(inode)) {
2353 +                       vxwprintk_task(1, "messing with the barrier.");
2354 +                       return -EACCES;
2355 +               }
2356 +
2357                 mutex_lock(&inode->i_mutex);
2358                 /* Is it quota file? Do not allow user to mess with it */
2359                 if (IS_NOQUOTA(inode)) {
2360 @@ -66,7 +81,9 @@ long ext2_ioctl(struct file *filp, unsig
2361                  *
2362                  * This test looks nicer. Thanks to Pauline Middelink
2363                  */
2364 -               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
2365 +               if ((oldflags & EXT2_IMMUTABLE_FL) ||
2366 +                       ((flags ^ oldflags) & (EXT2_APPEND_FL |
2367 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
2368                         if (!capable(CAP_LINUX_IMMUTABLE)) {
2369                                 mutex_unlock(&inode->i_mutex);
2370                                 ret = -EPERM;
2371 @@ -74,7 +91,7 @@ long ext2_ioctl(struct file *filp, unsig
2372                         }
2373                 }
2374  
2375 -               flags = flags & EXT2_FL_USER_MODIFIABLE;
2376 +               flags &= EXT2_FL_USER_MODIFIABLE;
2377                 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
2378                 ei->i_flags = flags;
2379  
2380 diff -NurpP --minimal linux-3.10.9/fs/ext2/namei.c linux-3.10.9-vs2.3.6.6/fs/ext2/namei.c
2381 --- linux-3.10.9/fs/ext2/namei.c        2012-12-11 03:30:57.000000000 +0000
2382 +++ linux-3.10.9-vs2.3.6.6/fs/ext2/namei.c      2013-08-22 20:29:59.000000000 +0000
2383 @@ -32,6 +32,7 @@
2384  
2385  #include <linux/pagemap.h>
2386  #include <linux/quotaops.h>
2387 +#include <linux/vs_tag.h>
2388  #include "ext2.h"
2389  #include "xattr.h"
2390  #include "acl.h"
2391 @@ -73,6 +74,7 @@ static struct dentry *ext2_lookup(struct
2392                                         (unsigned long) ino);
2393                         return ERR_PTR(-EIO);
2394                 }
2395 +               dx_propagate_tag(nd, inode);
2396         }
2397         return d_splice_alias(inode, dentry);
2398  }
2399 @@ -397,6 +399,7 @@ const struct inode_operations ext2_dir_i
2400         .removexattr    = generic_removexattr,
2401  #endif
2402         .setattr        = ext2_setattr,
2403 +       .sync_flags     = ext2_sync_flags,
2404         .get_acl        = ext2_get_acl,
2405  };
2406  
2407 diff -NurpP --minimal linux-3.10.9/fs/ext2/super.c linux-3.10.9-vs2.3.6.6/fs/ext2/super.c
2408 --- linux-3.10.9/fs/ext2/super.c        2013-05-31 13:45:23.000000000 +0000
2409 +++ linux-3.10.9-vs2.3.6.6/fs/ext2/super.c      2013-08-22 20:29:59.000000000 +0000
2410 @@ -395,7 +395,8 @@ enum {
2411         Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
2412         Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
2413         Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
2414 -       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
2415 +       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
2416 +       Opt_tag, Opt_notag, Opt_tagid
2417  };
2418  
2419  static const match_table_t tokens = {
2420 @@ -423,6 +424,9 @@ static const match_table_t tokens = {
2421         {Opt_acl, "acl"},
2422         {Opt_noacl, "noacl"},
2423         {Opt_xip, "xip"},
2424 +       {Opt_tag, "tag"},
2425 +       {Opt_notag, "notag"},
2426 +       {Opt_tagid, "tagid=%u"},
2427         {Opt_grpquota, "grpquota"},
2428         {Opt_ignore, "noquota"},
2429         {Opt_quota, "quota"},
2430 @@ -506,6 +510,20 @@ static int parse_options(char *options,
2431                 case Opt_nouid32:
2432                         set_opt (sbi->s_mount_opt, NO_UID32);
2433                         break;
2434 +#ifndef CONFIG_TAGGING_NONE
2435 +               case Opt_tag:
2436 +                       set_opt (sbi->s_mount_opt, TAGGED);
2437 +                       break;
2438 +               case Opt_notag:
2439 +                       clear_opt (sbi->s_mount_opt, TAGGED);
2440 +                       break;
2441 +#endif
2442 +#ifdef CONFIG_PROPAGATE
2443 +               case Opt_tagid:
2444 +                       /* use args[0] */
2445 +                       set_opt (sbi->s_mount_opt, TAGGED);
2446 +                       break;
2447 +#endif
2448                 case Opt_nocheck:
2449                         clear_opt (sbi->s_mount_opt, CHECK);
2450                         break;
2451 @@ -864,6 +882,8 @@ static int ext2_fill_super(struct super_
2452         if (!parse_options((char *) data, sb))
2453                 goto failed_mount;
2454  
2455 +       if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
2456 +               sb->s_flags |= MS_TAGGED;
2457         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2458                 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
2459                  MS_POSIXACL : 0);
2460 @@ -1269,6 +1289,14 @@ static int ext2_remount (struct super_bl
2461                 err = -EINVAL;
2462                 goto restore_opts;
2463         }
2464 +
2465 +       if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
2466 +               !(sb->s_flags & MS_TAGGED)) {
2467 +               printk("EXT2-fs: %s: tagging not permitted on remount.\n",
2468 +                      sb->s_id);
2469 +               err = -EINVAL;
2470 +               goto restore_opts;
2471 +       }
2472  
2473         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2474                 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
2475 diff -NurpP --minimal linux-3.10.9/fs/ext3/ext3.h linux-3.10.9-vs2.3.6.6/fs/ext3/ext3.h
2476 --- linux-3.10.9/fs/ext3/ext3.h 2012-12-11 03:30:57.000000000 +0000
2477 +++ linux-3.10.9-vs2.3.6.6/fs/ext3/ext3.h       2013-08-22 20:29:59.000000000 +0000
2478 @@ -151,10 +151,14 @@ struct ext3_group_desc
2479  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
2480  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
2481  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
2482 +#define EXT3_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
2483  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
2484  
2485 -#define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
2486 -#define EXT3_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
2487 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
2488 +#define EXT3_COW_FL                    0x20000000 /* Copy on Write marker */
2489 +
2490 +#define EXT3_FL_USER_VISIBLE           0x0103DFFF /* User visible flags */
2491 +#define EXT3_FL_USER_MODIFIABLE                0x010380FF /* User modifiable flags */
2492  
2493  /* Flags that should be inherited by new inodes from their parent. */
2494  #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
2495 @@ -290,7 +294,8 @@ struct ext3_inode {
2496                         __u16   i_pad1;
2497                         __le16  l_i_uid_high;   /* these 2 fields    */
2498                         __le16  l_i_gid_high;   /* were reserved2[0] */
2499 -                       __u32   l_i_reserved2;
2500 +                       __le16  l_i_tag;        /* Context Tag */
2501 +                       __u16   l_i_reserved2;
2502                 } linux2;
2503                 struct {
2504                         __u8    h_i_frag;       /* Fragment number */
2505 @@ -320,6 +325,7 @@ struct ext3_inode {
2506  #define i_gid_low      i_gid
2507  #define i_uid_high     osd2.linux2.l_i_uid_high
2508  #define i_gid_high     osd2.linux2.l_i_gid_high
2509 +#define i_raw_tag      osd2.linux2.l_i_tag
2510  #define i_reserved2    osd2.linux2.l_i_reserved2
2511  
2512  /*
2513 @@ -364,6 +370,7 @@ struct ext3_inode {
2514  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
2515  #define EXT3_MOUNT_DATA_ERR_ABORT      0x400000 /* Abort on file data write
2516                                                   * error in ordered mode */
2517 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
2518  
2519  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
2520  #ifndef _LINUX_EXT2_FS_H
2521 @@ -1061,6 +1068,7 @@ extern void ext3_get_inode_flags(struct
2522  extern void ext3_set_aops(struct inode *inode);
2523  extern int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2524                        u64 start, u64 len);
2525 +extern int ext3_sync_flags(struct inode *, int, int);
2526  
2527  /* ioctl.c */
2528  extern long ext3_ioctl(struct file *, unsigned int, unsigned long);
2529 diff -NurpP --minimal linux-3.10.9/fs/ext3/file.c linux-3.10.9-vs2.3.6.6/fs/ext3/file.c
2530 --- linux-3.10.9/fs/ext3/file.c 2012-12-11 03:30:57.000000000 +0000
2531 +++ linux-3.10.9-vs2.3.6.6/fs/ext3/file.c       2013-08-22 20:29:59.000000000 +0000
2532 @@ -76,5 +76,6 @@ const struct inode_operations ext3_file_
2533  #endif
2534         .get_acl        = ext3_get_acl,
2535         .fiemap         = ext3_fiemap,
2536 +       .sync_flags     = ext3_sync_flags,
2537  };
2538  
2539 diff -NurpP --minimal linux-3.10.9/fs/ext3/ialloc.c linux-3.10.9-vs2.3.6.6/fs/ext3/ialloc.c
2540 --- linux-3.10.9/fs/ext3/ialloc.c       2012-12-11 03:30:57.000000000 +0000
2541 +++ linux-3.10.9-vs2.3.6.6/fs/ext3/ialloc.c     2013-08-22 20:29:59.000000000 +0000
2542 @@ -14,6 +14,7 @@
2543  
2544  #include <linux/quotaops.h>
2545  #include <linux/random.h>
2546 +#include <linux/vs_tag.h>
2547  
2548  #include "ext3.h"
2549  #include "xattr.h"
2550 @@ -469,6 +470,7 @@ got:
2551                 inode->i_mode = mode;
2552                 inode->i_uid = current_fsuid();
2553                 inode->i_gid = dir->i_gid;
2554 +               i_tag_write(inode, dx_current_fstag(sb));
2555         } else
2556                 inode_init_owner(inode, dir, mode);
2557  
2558 diff -NurpP --minimal linux-3.10.9/fs/ext3/inode.c linux-3.10.9-vs2.3.6.6/fs/ext3/inode.c
2559 --- linux-3.10.9/fs/ext3/inode.c        2013-07-14 17:01:27.000000000 +0000
2560 +++ linux-3.10.9-vs2.3.6.6/fs/ext3/inode.c      2013-08-22 21:21:18.000000000 +0000
2561 @@ -28,6 +28,8 @@
2562  #include <linux/mpage.h>
2563  #include <linux/namei.h>
2564  #include <linux/aio.h>
2565 +#include <linux/vs_tag.h>
2566 +
2567  #include "ext3.h"
2568  #include "xattr.h"
2569  #include "acl.h"
2570 @@ -2853,36 +2855,60 @@ void ext3_set_inode_flags(struct inode *
2571  {
2572         unsigned int flags = EXT3_I(inode)->i_flags;
2573  
2574 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2575 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2576 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2577 +
2578 +       if (flags & EXT3_IMMUTABLE_FL)
2579 +               inode->i_flags |= S_IMMUTABLE;
2580 +       if (flags & EXT3_IXUNLINK_FL)
2581 +               inode->i_flags |= S_IXUNLINK;
2582 +
2583         if (flags & EXT3_SYNC_FL)
2584                 inode->i_flags |= S_SYNC;
2585         if (flags & EXT3_APPEND_FL)
2586                 inode->i_flags |= S_APPEND;
2587 -       if (flags & EXT3_IMMUTABLE_FL)
2588 -               inode->i_flags |= S_IMMUTABLE;
2589         if (flags & EXT3_NOATIME_FL)
2590                 inode->i_flags |= S_NOATIME;
2591         if (flags & EXT3_DIRSYNC_FL)
2592                 inode->i_flags |= S_DIRSYNC;
2593 +
2594 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2595 +
2596 +       if (flags & EXT3_BARRIER_FL)
2597 +               inode->i_vflags |= V_BARRIER;
2598 +       if (flags & EXT3_COW_FL)
2599 +               inode->i_vflags |= V_COW;
2600  }
2601  
2602  /* Propagate flags from i_flags to EXT3_I(inode)->i_flags */
2603  void ext3_get_inode_flags(struct ext3_inode_info *ei)
2604  {
2605         unsigned int flags = ei->vfs_inode.i_flags;
2606 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2607 +
2608 +       ei->i_flags &= ~(EXT3_SYNC_FL | EXT3_APPEND_FL |
2609 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL |
2610 +                       EXT3_NOATIME_FL | EXT3_DIRSYNC_FL |
2611 +                       EXT3_BARRIER_FL | EXT3_COW_FL);
2612 +
2613 +       if (flags & S_IMMUTABLE)
2614 +               ei->i_flags |= EXT3_IMMUTABLE_FL;
2615 +       if (flags & S_IXUNLINK)
2616 +               ei->i_flags |= EXT3_IXUNLINK_FL;
2617  
2618 -       ei->i_flags &= ~(EXT3_SYNC_FL|EXT3_APPEND_FL|
2619 -                       EXT3_IMMUTABLE_FL|EXT3_NOATIME_FL|EXT3_DIRSYNC_FL);
2620         if (flags & S_SYNC)
2621                 ei->i_flags |= EXT3_SYNC_FL;
2622         if (flags & S_APPEND)
2623                 ei->i_flags |= EXT3_APPEND_FL;
2624 -       if (flags & S_IMMUTABLE)
2625 -               ei->i_flags |= EXT3_IMMUTABLE_FL;
2626         if (flags & S_NOATIME)
2627                 ei->i_flags |= EXT3_NOATIME_FL;
2628         if (flags & S_DIRSYNC)
2629                 ei->i_flags |= EXT3_DIRSYNC_FL;
2630 +
2631 +       if (vflags & V_BARRIER)
2632 +               ei->i_flags |= EXT3_BARRIER_FL;
2633 +       if (vflags & V_COW)
2634 +               ei->i_flags |= EXT3_COW_FL;
2635  }
2636  
2637  struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
2638 @@ -2920,8 +2946,10 @@ struct inode *ext3_iget(struct super_blo
2639                 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2640                 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2641         }
2642 -       i_uid_write(inode, i_uid);
2643 -       i_gid_write(inode, i_gid);
2644 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
2645 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
2646 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
2647 +               le16_to_cpu(raw_inode->i_raw_tag)));
2648         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2649         inode->i_size = le32_to_cpu(raw_inode->i_size);
2650         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2651 @@ -3093,8 +3121,10 @@ again:
2652  
2653         ext3_get_inode_flags(ei);
2654         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
2655 -       i_uid = i_uid_read(inode);
2656 -       i_gid = i_gid_read(inode);
2657 +       i_uid = from_kuid(&init_user_ns,
2658 +               TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag));
2659 +       i_gid = from_kgid(&init_user_ns,
2660 +               TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag));
2661         if(!(test_opt(inode->i_sb, NO_UID32))) {
2662                 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(i_uid));
2663                 raw_inode->i_gid_low = cpu_to_le16(low_16_bits(i_gid));
2664 @@ -3119,6 +3149,9 @@ again:
2665                 raw_inode->i_uid_high = 0;
2666                 raw_inode->i_gid_high = 0;
2667         }
2668 +#ifdef CONFIG_TAGGING_INTERN
2669 +       raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
2670 +#endif
2671         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2672         disksize = cpu_to_le32(ei->i_disksize);
2673         if (disksize != raw_inode->i_size) {
2674 @@ -3287,7 +3320,8 @@ int ext3_setattr(struct dentry *dentry,
2675         if (is_quota_modification(inode, attr))
2676                 dquot_initialize(inode);
2677         if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) ||
2678 -           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) {
2679 +           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid)) ||
2680 +           (ia_valid & ATTR_TAG && !tag_eq(attr->ia_tag, inode->i_tag))) {
2681                 handle_t *handle;
2682  
2683                 /* (user+group)*(old+new) structure, inode write (sb,
2684 @@ -3309,6 +3343,8 @@ int ext3_setattr(struct dentry *dentry,
2685                         inode->i_uid = attr->ia_uid;
2686                 if (attr->ia_valid & ATTR_GID)
2687                         inode->i_gid = attr->ia_gid;
2688 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2689 +                       inode->i_tag = attr->ia_tag;
2690                 error = ext3_mark_inode_dirty(handle, inode);
2691                 ext3_journal_stop(handle);
2692         }
2693 diff -NurpP --minimal linux-3.10.9/fs/ext3/ioctl.c linux-3.10.9-vs2.3.6.6/fs/ext3/ioctl.c
2694 --- linux-3.10.9/fs/ext3/ioctl.c        2013-05-31 13:45:23.000000000 +0000
2695 +++ linux-3.10.9-vs2.3.6.6/fs/ext3/ioctl.c      2013-08-22 20:29:59.000000000 +0000
2696 @@ -12,6 +12,34 @@
2697  #include <asm/uaccess.h>
2698  #include "ext3.h"
2699  
2700 +
2701 +int ext3_sync_flags(struct inode *inode, int flags, int vflags)
2702 +{
2703 +       handle_t *handle = NULL;
2704 +       struct ext3_iloc iloc;
2705 +       int err;
2706 +
2707 +       handle = ext3_journal_start(inode, 1);
2708 +       if (IS_ERR(handle))
2709 +               return PTR_ERR(handle);
2710 +
2711 +       if (IS_SYNC(inode))
2712 +               handle->h_sync = 1;
2713 +       err = ext3_reserve_inode_write(handle, inode, &iloc);
2714 +       if (err)
2715 +               goto flags_err;
2716 +
2717 +       inode->i_flags = flags;
2718 +       inode->i_vflags = vflags;
2719 +       ext3_get_inode_flags(EXT3_I(inode));
2720 +       inode->i_ctime = CURRENT_TIME_SEC;
2721 +
2722 +       err = ext3_mark_iloc_dirty(handle, inode, &iloc);
2723 +flags_err:
2724 +       ext3_journal_stop(handle);
2725 +       return err;
2726 +}
2727 +
2728  long ext3_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2729  {
2730         struct inode *inode = file_inode(filp);
2731 @@ -45,6 +73,11 @@ long ext3_ioctl(struct file *filp, unsig
2732  
2733                 flags = ext3_mask_flags(inode->i_mode, flags);
2734  
2735 +               if (IS_BARRIER(inode)) {
2736 +                       vxwprintk_task(1, "messing with the barrier.");
2737 +                       return -EACCES;
2738 +               }
2739 +
2740                 mutex_lock(&inode->i_mutex);
2741  
2742                 /* Is it quota file? Do not allow user to mess with it */
2743 @@ -63,7 +96,9 @@ long ext3_ioctl(struct file *filp, unsig
2744                  *
2745                  * This test looks nicer. Thanks to Pauline Middelink
2746                  */
2747 -               if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
2748 +               if ((oldflags & EXT3_IMMUTABLE_FL) ||
2749 +                       ((flags ^ oldflags) & (EXT3_APPEND_FL |
2750 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL))) {
2751                         if (!capable(CAP_LINUX_IMMUTABLE))
2752                                 goto flags_out;
2753                 }
2754 @@ -88,7 +123,7 @@ long ext3_ioctl(struct file *filp, unsig
2755                 if (err)
2756                         goto flags_err;
2757  
2758 -               flags = flags & EXT3_FL_USER_MODIFIABLE;
2759 +               flags &= EXT3_FL_USER_MODIFIABLE;
2760                 flags |= oldflags & ~EXT3_FL_USER_MODIFIABLE;
2761                 ei->i_flags = flags;
2762  
2763 diff -NurpP --minimal linux-3.10.9/fs/ext3/namei.c linux-3.10.9-vs2.3.6.6/fs/ext3/namei.c
2764 --- linux-3.10.9/fs/ext3/namei.c        2013-08-22 19:51:35.000000000 +0000
2765 +++ linux-3.10.9-vs2.3.6.6/fs/ext3/namei.c      2013-08-22 20:29:59.000000000 +0000
2766 @@ -25,6 +25,8 @@
2767   */
2768  
2769  #include <linux/quotaops.h>
2770 +#include <linux/vs_tag.h>
2771 +
2772  #include "ext3.h"
2773  #include "namei.h"
2774  #include "xattr.h"
2775 @@ -915,6 +917,7 @@ restart:
2776                                         submit_bh(READ | REQ_META | REQ_PRIO,
2777                                                   bh);
2778                                 }
2779 +               dx_propagate_tag(nd, inode);
2780                         }
2781                 }
2782                 if ((bh = bh_use[ra_ptr++]) == NULL)
2783 @@ -2524,6 +2527,7 @@ const struct inode_operations ext3_dir_i
2784         .listxattr      = ext3_listxattr,
2785         .removexattr    = generic_removexattr,
2786  #endif
2787 +       .sync_flags     = ext3_sync_flags,
2788         .get_acl        = ext3_get_acl,
2789  };
2790  
2791 diff -NurpP --minimal linux-3.10.9/fs/ext3/super.c linux-3.10.9-vs2.3.6.6/fs/ext3/super.c
2792 --- linux-3.10.9/fs/ext3/super.c        2013-07-14 17:01:27.000000000 +0000
2793 +++ linux-3.10.9-vs2.3.6.6/fs/ext3/super.c      2013-08-22 20:29:59.000000000 +0000
2794 @@ -813,7 +813,8 @@ enum {
2795         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
2796         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota,
2797         Opt_noquota, Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err,
2798 -       Opt_resize, Opt_usrquota, Opt_grpquota
2799 +       Opt_resize, Opt_usrquota, Opt_grpquota,
2800 +       Opt_tag, Opt_notag, Opt_tagid
2801  };
2802  
2803  static const match_table_t tokens = {
2804 @@ -870,6 +871,9 @@ static const match_table_t tokens = {
2805         {Opt_barrier, "barrier"},
2806         {Opt_nobarrier, "nobarrier"},
2807         {Opt_resize, "resize"},
2808 +       {Opt_tag, "tag"},
2809 +       {Opt_notag, "notag"},
2810 +       {Opt_tagid, "tagid=%u"},
2811         {Opt_err, NULL},
2812  };
2813  
2814 @@ -1037,6 +1041,20 @@ static int parse_options (char *options,
2815                 case Opt_nouid32:
2816                         set_opt (sbi->s_mount_opt, NO_UID32);
2817                         break;
2818 +#ifndef CONFIG_TAGGING_NONE
2819 +               case Opt_tag:
2820 +                       set_opt (sbi->s_mount_opt, TAGGED);
2821 +                       break;
2822 +               case Opt_notag:
2823 +                       clear_opt (sbi->s_mount_opt, TAGGED);
2824 +                       break;
2825 +#endif
2826 +#ifdef CONFIG_PROPAGATE
2827 +               case Opt_tagid:
2828 +                       /* use args[0] */
2829 +                       set_opt (sbi->s_mount_opt, TAGGED);
2830 +                       break;
2831 +#endif
2832                 case Opt_nocheck:
2833                         clear_opt (sbi->s_mount_opt, CHECK);
2834                         break;
2835 @@ -1734,6 +1752,9 @@ static int ext3_fill_super (struct super
2836                             NULL, 0))
2837                 goto failed_mount;
2838  
2839 +       if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
2840 +               sb->s_flags |= MS_TAGGED;
2841 +
2842         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2843                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2844  
2845 @@ -2629,6 +2650,14 @@ static int ext3_remount (struct super_bl
2846         if (test_opt(sb, ABORT))
2847                 ext3_abort(sb, __func__, "Abort forced by user");
2848  
2849 +       if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
2850 +               !(sb->s_flags & MS_TAGGED)) {
2851 +               printk("EXT3-fs: %s: tagging not permitted on remount.\n",
2852 +                       sb->s_id);
2853 +               err = -EINVAL;
2854 +               goto restore_opts;
2855 +       }
2856 +
2857         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2858                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2859  
2860 diff -NurpP --minimal linux-3.10.9/fs/ext4/ext4.h linux-3.10.9-vs2.3.6.6/fs/ext4/ext4.h
2861 --- linux-3.10.9/fs/ext4/ext4.h 2013-07-14 17:01:27.000000000 +0000
2862 +++ linux-3.10.9-vs2.3.6.6/fs/ext4/ext4.h       2013-08-22 20:29:59.000000000 +0000
2863 @@ -387,7 +387,10 @@ struct flex_groups {
2864  #define EXT4_EXTENTS_FL                        0x00080000 /* Inode uses extents */
2865  #define EXT4_EA_INODE_FL               0x00200000 /* Inode used for large EA */
2866  #define EXT4_EOFBLOCKS_FL              0x00400000 /* Blocks allocated beyond EOF */
2867 +#define EXT4_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
2868 +#define EXT4_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
2869  #define EXT4_INLINE_DATA_FL            0x10000000 /* Inode has inline data. */
2870 +#define EXT4_COW_FL                    0x20000000 /* Copy on Write marker */
2871  #define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
2872  
2873  #define EXT4_FL_USER_VISIBLE           0x004BDFFF /* User visible flags */
2874 @@ -663,7 +666,7 @@ struct ext4_inode {
2875                         __le16  l_i_uid_high;   /* these 2 fields */
2876                         __le16  l_i_gid_high;   /* were reserved2[0] */
2877                         __le16  l_i_checksum_lo;/* crc32c(uuid+inum+inode) LE */
2878 -                       __le16  l_i_reserved;
2879 +                       __le16  l_i_tag;        /* Context Tag */
2880                 } linux2;
2881                 struct {
2882                         __le16  h_i_reserved1;  /* Obsoleted fragment number/size which are removed in ext4 */
2883 @@ -781,6 +784,7 @@ do {                                                                               \
2884  #define i_gid_low      i_gid
2885  #define i_uid_high     osd2.linux2.l_i_uid_high
2886  #define i_gid_high     osd2.linux2.l_i_gid_high
2887 +#define i_raw_tag      osd2.linux2.l_i_tag
2888  #define i_checksum_lo  osd2.linux2.l_i_checksum_lo
2889  
2890  #elif defined(__GNU__)
2891 @@ -958,6 +962,7 @@ struct ext4_inode_info {
2892  #define EXT4_MOUNT_POSIX_ACL           0x08000 /* POSIX Access Control Lists */
2893  #define EXT4_MOUNT_NO_AUTO_DA_ALLOC    0x10000 /* No auto delalloc mapping */
2894  #define EXT4_MOUNT_BARRIER             0x20000 /* Use block barriers */
2895 +#define EXT4_MOUNT_TAGGED              0x40000 /* Enable Context Tags */
2896  #define EXT4_MOUNT_QUOTA               0x80000 /* Some quota option set */
2897  #define EXT4_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
2898  #define EXT4_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
2899 @@ -2538,6 +2543,7 @@ extern struct buffer_head *ext4_get_firs
2900  extern int ext4_inline_data_fiemap(struct inode *inode,
2901                                    struct fiemap_extent_info *fieinfo,
2902                                    int *has_inline);
2903 +extern int ext4_sync_flags(struct inode *, int, int);
2904  extern int ext4_try_to_evict_inline_data(handle_t *handle,
2905                                          struct inode *inode,
2906                                          int needed);
2907 diff -NurpP --minimal linux-3.10.9/fs/ext4/file.c linux-3.10.9-vs2.3.6.6/fs/ext4/file.c
2908 --- linux-3.10.9/fs/ext4/file.c 2013-08-22 19:51:35.000000000 +0000
2909 +++ linux-3.10.9-vs2.3.6.6/fs/ext4/file.c       2013-08-22 20:29:59.000000000 +0000
2910 @@ -651,5 +651,6 @@ const struct inode_operations ext4_file_
2911         .removexattr    = generic_removexattr,
2912         .get_acl        = ext4_get_acl,
2913         .fiemap         = ext4_fiemap,
2914 +       .sync_flags     = ext4_sync_flags,
2915  };
2916  
2917 diff -NurpP --minimal linux-3.10.9/fs/ext4/ialloc.c linux-3.10.9-vs2.3.6.6/fs/ext4/ialloc.c
2918 --- linux-3.10.9/fs/ext4/ialloc.c       2013-08-22 19:51:35.000000000 +0000
2919 +++ linux-3.10.9-vs2.3.6.6/fs/ext4/ialloc.c     2013-08-22 20:29:59.000000000 +0000
2920 @@ -22,6 +22,7 @@
2921  #include <linux/random.h>
2922  #include <linux/bitops.h>
2923  #include <linux/blkdev.h>
2924 +#include <linux/vs_tag.h>
2925  #include <asm/byteorder.h>
2926  
2927  #include "ext4.h"
2928 @@ -679,6 +680,7 @@ struct inode *__ext4_new_inode(handle_t
2929                 inode->i_mode = mode;
2930                 inode->i_uid = current_fsuid();
2931                 inode->i_gid = dir->i_gid;
2932 +               i_tag_write(inode, dx_current_fstag(sb));
2933         } else
2934                 inode_init_owner(inode, dir, mode);
2935         dquot_initialize(inode);
2936 diff -NurpP --minimal linux-3.10.9/fs/ext4/inode.c linux-3.10.9-vs2.3.6.6/fs/ext4/inode.c
2937 --- linux-3.10.9/fs/ext4/inode.c        2013-08-22 19:51:35.000000000 +0000
2938 +++ linux-3.10.9-vs2.3.6.6/fs/ext4/inode.c      2013-08-22 22:20:00.000000000 +0000
2939 @@ -38,6 +38,7 @@
2940  #include <linux/slab.h>
2941  #include <linux/ratelimit.h>
2942  #include <linux/aio.h>
2943 +#include <linux/vs_tag.h>
2944  
2945  #include "ext4_jbd2.h"
2946  #include "xattr.h"
2947 @@ -4057,41 +4058,64 @@ void ext4_set_inode_flags(struct inode *
2948  {
2949         unsigned int flags = EXT4_I(inode)->i_flags;
2950  
2951 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2952 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2953 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2954 +
2955 +       if (flags & EXT4_IMMUTABLE_FL)
2956 +               inode->i_flags |= S_IMMUTABLE;
2957 +       if (flags & EXT4_IXUNLINK_FL)
2958 +               inode->i_flags |= S_IXUNLINK;
2959 +
2960         if (flags & EXT4_SYNC_FL)
2961                 inode->i_flags |= S_SYNC;
2962         if (flags & EXT4_APPEND_FL)
2963                 inode->i_flags |= S_APPEND;
2964 -       if (flags & EXT4_IMMUTABLE_FL)
2965 -               inode->i_flags |= S_IMMUTABLE;
2966         if (flags & EXT4_NOATIME_FL)
2967                 inode->i_flags |= S_NOATIME;
2968         if (flags & EXT4_DIRSYNC_FL)
2969                 inode->i_flags |= S_DIRSYNC;
2970 +
2971 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2972 +
2973 +       if (flags & EXT4_BARRIER_FL)
2974 +               inode->i_vflags |= V_BARRIER;
2975 +       if (flags & EXT4_COW_FL)
2976 +               inode->i_vflags |= V_COW;
2977  }
2978  
2979  /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
2980  void ext4_get_inode_flags(struct ext4_inode_info *ei)
2981  {
2982 -       unsigned int vfs_fl;
2983 +       unsigned int vfs_fl, vfs_vf;
2984         unsigned long old_fl, new_fl;
2985  
2986         do {
2987                 vfs_fl = ei->vfs_inode.i_flags;
2988 +               vfs_vf = ei->vfs_inode.i_vflags;
2989                 old_fl = ei->i_flags;
2990                 new_fl = old_fl & ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
2991                                 EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|
2992 -                               EXT4_DIRSYNC_FL);
2993 +                               EXT4_DIRSYNC_FL|EXT4_BARRIER_FL|
2994 +                               EXT4_COW_FL);
2995 +
2996 +               if (vfs_fl & S_IMMUTABLE)
2997 +                       new_fl |= EXT4_IMMUTABLE_FL;
2998 +               if (vfs_fl & S_IXUNLINK)
2999 +                       new_fl |= EXT4_IXUNLINK_FL;
3000 +
3001                 if (vfs_fl & S_SYNC)
3002                         new_fl |= EXT4_SYNC_FL;
3003                 if (vfs_fl & S_APPEND)
3004                         new_fl |= EXT4_APPEND_FL;
3005 -               if (vfs_fl & S_IMMUTABLE)
3006 -                       new_fl |= EXT4_IMMUTABLE_FL;
3007                 if (vfs_fl & S_NOATIME)
3008                         new_fl |= EXT4_NOATIME_FL;
3009                 if (vfs_fl & S_DIRSYNC)
3010                         new_fl |= EXT4_DIRSYNC_FL;
3011 +
3012 +               if (vfs_vf & V_BARRIER)
3013 +                       new_fl |= EXT4_BARRIER_FL;
3014 +               if (vfs_vf & V_COW)
3015 +                       new_fl |= EXT4_COW_FL;
3016         } while (cmpxchg(&ei->i_flags, old_fl, new_fl) != old_fl);
3017  }
3018  
3019 @@ -4196,8 +4220,10 @@ struct inode *ext4_iget(struct super_blo
3020                 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3021                 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3022         }
3023 -       i_uid_write(inode, i_uid);
3024 -       i_gid_write(inode, i_gid);
3025 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
3026 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
3027 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
3028 +               le16_to_cpu(raw_inode->i_raw_tag)));
3029         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
3030  
3031         ext4_clear_state_flags(ei);     /* Only relevant on 32-bit archs */
3032 @@ -4425,8 +4451,10 @@ static int ext4_do_update_inode(handle_t
3033  
3034         ext4_get_inode_flags(ei);
3035         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3036 -       i_uid = i_uid_read(inode);
3037 -       i_gid = i_gid_read(inode);
3038 +       i_uid = from_kuid(&init_user_ns,
3039 +               TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag));
3040 +       i_gid = from_kgid(&init_user_ns,
3041 +               TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag));
3042         if (!(test_opt(inode->i_sb, NO_UID32))) {
3043                 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(i_uid));
3044                 raw_inode->i_gid_low = cpu_to_le16(low_16_bits(i_gid));
3045 @@ -4449,6 +4477,9 @@ static int ext4_do_update_inode(handle_t
3046                 raw_inode->i_uid_high = 0;
3047                 raw_inode->i_gid_high = 0;
3048         }
3049 +#ifdef CONFIG_TAGGING_INTERN
3050 +       raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
3051 +#endif
3052         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3053  
3054         EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
3055 @@ -4679,7 +4710,8 @@ int ext4_setattr(struct dentry *dentry,
3056         if (is_quota_modification(inode, attr))
3057                 dquot_initialize(inode);
3058         if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) ||
3059 -           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) {
3060 +           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid)) ||
3061 +           (ia_valid & ATTR_TAG && !tag_eq(attr->ia_tag, inode->i_tag))) {
3062                 handle_t *handle;
3063  
3064                 /* (user+group)*(old+new) structure, inode write (sb,
3065 @@ -4702,6 +4734,8 @@ int ext4_setattr(struct dentry *dentry,
3066                         inode->i_uid = attr->ia_uid;
3067                 if (attr->ia_valid & ATTR_GID)
3068                         inode->i_gid = attr->ia_gid;
3069 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3070 +                       inode->i_tag = attr->ia_tag;
3071                 error = ext4_mark_inode_dirty(handle, inode);
3072                 ext4_journal_stop(handle);
3073         }
3074 diff -NurpP --minimal linux-3.10.9/fs/ext4/ioctl.c linux-3.10.9-vs2.3.6.6/fs/ext4/ioctl.c
3075 --- linux-3.10.9/fs/ext4/ioctl.c        2013-08-22 19:51:35.000000000 +0000
3076 +++ linux-3.10.9-vs2.3.6.6/fs/ext4/ioctl.c      2013-08-22 22:22:39.000000000 +0000
3077 @@ -14,6 +14,7 @@
3078  #include <linux/compat.h>
3079  #include <linux/mount.h>
3080  #include <linux/file.h>
3081 +#include <linux/vs_tag.h>
3082  #include <asm/uaccess.h>
3083  #include "ext4_jbd2.h"
3084  #include "ext4.h"
3085 @@ -214,6 +215,33 @@ swap_boot_out:
3086         return err;
3087  }
3088  
3089 +int ext4_sync_flags(struct inode *inode, int flags, int vflags)
3090 +{
3091 +       handle_t *handle = NULL;
3092 +       struct ext4_iloc iloc;
3093 +       int err;
3094 +
3095 +       handle = ext4_journal_start(inode, EXT4_HT_INODE, 1);
3096 +       if (IS_ERR(handle))
3097 +               return PTR_ERR(handle);
3098 +
3099 +       if (IS_SYNC(inode))
3100 +               ext4_handle_sync(handle);
3101 +       err = ext4_reserve_inode_write(handle, inode, &iloc);
3102 +       if (err)
3103 +               goto flags_err;
3104 +
3105 +       inode->i_flags = flags;
3106 +       inode->i_vflags = vflags;
3107 +       ext4_get_inode_flags(EXT4_I(inode));
3108 +       inode->i_ctime = ext4_current_time(inode);
3109 +
3110 +       err = ext4_mark_iloc_dirty(handle, inode, &iloc);
3111 +flags_err:
3112 +       ext4_journal_stop(handle);
3113 +       return err;
3114 +}
3115 +
3116  long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3117  {
3118         struct inode *inode = file_inode(filp);
3119 @@ -247,6 +275,11 @@ long ext4_ioctl(struct file *filp, unsig
3120  
3121                 flags = ext4_mask_flags(inode->i_mode, flags);
3122  
3123 +               if (IS_BARRIER(inode)) {
3124 +                       vxwprintk_task(1, "messing with the barrier.");
3125 +                       return -EACCES;
3126 +               }
3127 +
3128                 err = -EPERM;
3129                 mutex_lock(&inode->i_mutex);
3130                 /* Is it quota file? Do not allow user to mess with it */
3131 @@ -264,7 +297,9 @@ long ext4_ioctl(struct file *filp, unsig
3132                  *
3133                  * This test looks nicer. Thanks to Pauline Middelink
3134                  */
3135 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
3136 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
3137 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
3138 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
3139                         if (!capable(CAP_LINUX_IMMUTABLE))
3140                                 goto flags_out;
3141                 }
3142 diff -NurpP --minimal linux-3.10.9/fs/ext4/namei.c linux-3.10.9-vs2.3.6.6/fs/ext4/namei.c
3143 --- linux-3.10.9/fs/ext4/namei.c        2013-08-22 19:51:35.000000000 +0000
3144 +++ linux-3.10.9-vs2.3.6.6/fs/ext4/namei.c      2013-08-22 20:29:59.000000000 +0000
3145 @@ -34,6 +34,7 @@
3146  #include <linux/quotaops.h>
3147  #include <linux/buffer_head.h>
3148  #include <linux/bio.h>
3149 +#include <linux/vs_tag.h>
3150  #include "ext4.h"
3151  #include "ext4_jbd2.h"
3152  
3153 @@ -1299,6 +1300,7 @@ restart:
3154                                         ll_rw_block(READ | REQ_META | REQ_PRIO,
3155                                                     1, &bh);
3156                         }
3157 +               dx_propagate_tag(nd, inode);
3158                 }
3159                 if ((bh = bh_use[ra_ptr++]) == NULL)
3160                         goto next;
3161 @@ -3177,6 +3179,7 @@ const struct inode_operations ext4_dir_i
3162         .removexattr    = generic_removexattr,
3163         .get_acl        = ext4_get_acl,
3164         .fiemap         = ext4_fiemap,
3165 +       .sync_flags     = ext4_sync_flags,
3166  };
3167  
3168  const struct inode_operations ext4_special_inode_operations = {
3169 diff -NurpP --minimal linux-3.10.9/fs/ext4/super.c linux-3.10.9-vs2.3.6.6/fs/ext4/super.c
3170 --- linux-3.10.9/fs/ext4/super.c        2013-08-22 19:51:35.000000000 +0000
3171 +++ linux-3.10.9-vs2.3.6.6/fs/ext4/super.c      2013-08-22 20:29:59.000000000 +0000
3172 @@ -1129,7 +1129,7 @@ enum {
3173         Opt_inode_readahead_blks, Opt_journal_ioprio,
3174         Opt_dioread_nolock, Opt_dioread_lock,
3175         Opt_discard, Opt_nodiscard, Opt_init_itable, Opt_noinit_itable,
3176 -       Opt_max_dir_size_kb,
3177 +       Opt_max_dir_size_kb, Opt_tag, Opt_notag, Opt_tagid
3178  };
3179  
3180  static const match_table_t tokens = {
3181 @@ -1209,6 +1209,9 @@ static const match_table_t tokens = {
3182         {Opt_removed, "reservation"},   /* mount option from ext2/3 */
3183         {Opt_removed, "noreservation"}, /* mount option from ext2/3 */
3184         {Opt_removed, "journal=%u"},    /* mount option from ext2/3 */
3185 +       {Opt_tag, "tag"},
3186 +       {Opt_notag, "notag"},
3187 +       {Opt_tagid, "tagid=%u"},
3188         {Opt_err, NULL},
3189  };
3190  
3191 @@ -1439,6 +1442,20 @@ static int handle_mount_opt(struct super
3192         case Opt_i_version:
3193                 sb->s_flags |= MS_I_VERSION;
3194                 return 1;
3195 +#ifndef CONFIG_TAGGING_NONE
3196 +       case Opt_tag:
3197 +               set_opt(sb, TAGGED);
3198 +               return 1;
3199 +       case Opt_notag:
3200 +               clear_opt(sb, TAGGED);
3201 +               return 1;
3202 +#endif
3203 +#ifdef CONFIG_PROPAGATE
3204 +       case Opt_tagid:
3205 +               /* use args[0] */
3206 +               set_opt(sb, TAGGED);
3207 +               return 1;
3208 +#endif
3209         }
3210  
3211         for (m = ext4_mount_opts; m->token != Opt_err; m++)
3212 @@ -3452,6 +3469,9 @@ static int ext4_fill_super(struct super_
3213                         clear_opt(sb, DELALLOC);
3214         }
3215  
3216 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
3217 +               sb->s_flags |= MS_TAGGED;
3218 +
3219         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3220                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3221  
3222 @@ -4664,6 +4684,14 @@ static int ext4_remount(struct super_blo
3223         if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
3224                 ext4_abort(sb, "Abort forced by user");
3225  
3226 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
3227 +               !(sb->s_flags & MS_TAGGED)) {
3228 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
3229 +                       sb->s_id);
3230 +               err = -EINVAL;
3231 +               goto restore_opts;
3232 +       }
3233 +
3234         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3235                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3236  
3237 diff -NurpP --minimal linux-3.10.9/fs/fcntl.c linux-3.10.9-vs2.3.6.6/fs/fcntl.c
3238 --- linux-3.10.9/fs/fcntl.c     2013-05-31 13:45:23.000000000 +0000
3239 +++ linux-3.10.9-vs2.3.6.6/fs/fcntl.c   2013-08-22 20:29:59.000000000 +0000
3240 @@ -21,6 +21,7 @@
3241  #include <linux/rcupdate.h>
3242  #include <linux/pid_namespace.h>
3243  #include <linux/user_namespace.h>
3244 +#include <linux/vs_limit.h>
3245  
3246  #include <asm/poll.h>
3247  #include <asm/siginfo.h>
3248 @@ -378,6 +379,8 @@ SYSCALL_DEFINE3(fcntl64, unsigned int, f
3249  
3250         if (!f.file)
3251                 goto out;
3252 +       if (!vx_files_avail(1))
3253 +               goto out;
3254  
3255         if (unlikely(f.file->f_mode & FMODE_PATH)) {
3256                 if (!check_fcntl_cmd(cmd))
3257 diff -NurpP --minimal linux-3.10.9/fs/file.c linux-3.10.9-vs2.3.6.6/fs/file.c
3258 --- linux-3.10.9/fs/file.c      2013-07-14 17:01:28.000000000 +0000
3259 +++ linux-3.10.9-vs2.3.6.6/fs/file.c    2013-08-22 20:29:59.000000000 +0000
3260 @@ -22,6 +22,7 @@
3261  #include <linux/spinlock.h>
3262  #include <linux/rcupdate.h>
3263  #include <linux/workqueue.h>
3264 +#include <linux/vs_limit.h>
3265  
3266  int sysctl_nr_open __read_mostly = 1024*1024;
3267  int sysctl_nr_open_min = BITS_PER_LONG;
3268 @@ -311,6 +312,8 @@ struct files_struct *dup_fd(struct files
3269                 struct file *f = *old_fds++;
3270                 if (f) {
3271                         get_file(f);
3272 +                       /* TODO: sum it first for check and performance */
3273 +                       vx_openfd_inc(open_files - i);
3274                 } else {
3275                         /*
3276                          * The fd may be claimed in the fd bitmap but not yet
3277 @@ -376,9 +379,11 @@ static void close_files(struct files_str
3278                                         filp_close(file, files);
3279                                         cond_resched();
3280                                 }
3281 +                               vx_openfd_dec(i);
3282                         }
3283                         i++;
3284                         set >>= 1;
3285 +                       cond_resched();
3286                 }
3287         }
3288  }
3289 @@ -503,6 +508,7 @@ repeat:
3290         else
3291                 __clear_close_on_exec(fd, fdt);
3292         error = fd;
3293 +       vx_openfd_inc(fd);
3294  #if 1
3295         /* Sanity check */
3296         if (rcu_dereference_raw(fdt->fd[fd]) != NULL) {
3297 @@ -533,6 +539,7 @@ static void __put_unused_fd(struct files
3298         __clear_open_fd(fd, fdt);
3299         if (fd < files->next_fd)
3300                 files->next_fd = fd;
3301 +       vx_openfd_dec(fd);
3302  }
3303  
3304  void put_unused_fd(unsigned int fd)
3305 @@ -812,6 +819,8 @@ static int do_dup2(struct files_struct *
3306  
3307         if (tofree)
3308                 filp_close(tofree, files);
3309 +       else
3310 +               vx_openfd_inc(fd);      /* fd was unused */
3311  
3312         return fd;
3313  
3314 diff -NurpP --minimal linux-3.10.9/fs/file_table.c linux-3.10.9-vs2.3.6.6/fs/file_table.c
3315 --- linux-3.10.9/fs/file_table.c        2013-07-14 17:01:28.000000000 +0000
3316 +++ linux-3.10.9-vs2.3.6.6/fs/file_table.c      2013-08-22 20:29:59.000000000 +0000
3317 @@ -26,6 +26,8 @@
3318  #include <linux/hardirq.h>
3319  #include <linux/task_work.h>
3320  #include <linux/ima.h>
3321 +#include <linux/vs_limit.h>
3322 +#include <linux/vs_context.h>
3323  
3324  #include <linux/atomic.h>
3325  
3326 @@ -140,6 +142,8 @@ struct file *get_empty_filp(void)
3327         spin_lock_init(&f->f_lock);
3328         eventpoll_init_file(f);
3329         /* f->f_version: 0 */
3330 +       f->f_xid = vx_current_xid();
3331 +       vx_files_inc(f);
3332         return f;
3333  
3334  over:
3335 @@ -257,6 +261,8 @@ static void __fput(struct file *file)
3336                 i_readcount_dec(inode);
3337         if (file->f_mode & FMODE_WRITE)
3338                 drop_file_write_access(file);
3339 +       vx_files_dec(file);
3340 +       file->f_xid = 0;
3341         file->f_path.dentry = NULL;
3342         file->f_path.mnt = NULL;
3343         file->f_inode = NULL;
3344 @@ -345,6 +351,8 @@ void put_filp(struct file *file)
3345  {
3346         if (atomic_long_dec_and_test(&file->f_count)) {
3347                 security_file_free(file);
3348 +               vx_files_dec(file);
3349 +               file->f_xid = 0;
3350                 file_sb_list_del(file);
3351                 file_free(file);
3352         }
3353 diff -NurpP --minimal linux-3.10.9/fs/fs_struct.c linux-3.10.9-vs2.3.6.6/fs/fs_struct.c
3354 --- linux-3.10.9/fs/fs_struct.c 2013-05-31 13:45:23.000000000 +0000
3355 +++ linux-3.10.9-vs2.3.6.6/fs/fs_struct.c       2013-08-22 20:29:59.000000000 +0000
3356 @@ -4,6 +4,7 @@
3357  #include <linux/path.h>
3358  #include <linux/slab.h>
3359  #include <linux/fs_struct.h>
3360 +#include <linux/vserver/global.h>
3361  #include "internal.h"
3362  
3363  /*
3364 @@ -87,6 +88,7 @@ void free_fs_struct(struct fs_struct *fs
3365  {
3366         path_put(&fs->root);
3367         path_put(&fs->pwd);
3368 +       atomic_dec(&vs_global_fs);
3369         kmem_cache_free(fs_cachep, fs);
3370  }
3371  
3372 @@ -124,6 +126,7 @@ struct fs_struct *copy_fs_struct(struct
3373                 fs->pwd = old->pwd;
3374                 path_get(&fs->pwd);
3375                 spin_unlock(&old->lock);
3376 +               atomic_inc(&vs_global_fs);
3377         }
3378         return fs;
3379  }
3380 diff -NurpP --minimal linux-3.10.9/fs/gfs2/file.c linux-3.10.9-vs2.3.6.6/fs/gfs2/file.c
3381 --- linux-3.10.9/fs/gfs2/file.c 2013-07-14 17:01:28.000000000 +0000
3382 +++ linux-3.10.9-vs2.3.6.6/fs/gfs2/file.c       2013-08-22 20:29:59.000000000 +0000
3383 @@ -144,6 +144,9 @@ static const u32 fsflags_to_gfs2[32] = {
3384         [12] = GFS2_DIF_EXHASH,
3385         [14] = GFS2_DIF_INHERIT_JDATA,
3386         [17] = GFS2_DIF_TOPDIR,
3387 +       [27] = GFS2_DIF_IXUNLINK,
3388 +       [26] = GFS2_DIF_BARRIER,
3389 +       [29] = GFS2_DIF_COW,
3390  };
3391  
3392  static const u32 gfs2_to_fsflags[32] = {
3393 @@ -154,6 +157,9 @@ static const u32 gfs2_to_fsflags[32] = {
3394         [gfs2fl_ExHash] = FS_INDEX_FL,
3395         [gfs2fl_TopLevel] = FS_TOPDIR_FL,
3396         [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL,
3397 +       [gfs2fl_IXUnlink] = FS_IXUNLINK_FL,
3398 +       [gfs2fl_Barrier] = FS_BARRIER_FL,
3399 +       [gfs2fl_Cow] = FS_COW_FL,
3400  };
3401  
3402  static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
3403 @@ -184,12 +190,18 @@ void gfs2_set_inode_flags(struct inode *
3404  {
3405         struct gfs2_inode *ip = GFS2_I(inode);
3406         unsigned int flags = inode->i_flags;
3407 +       unsigned int vflags = inode->i_vflags;
3408 +
3409 +       flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3410 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC | S_NOSEC);
3411  
3412 -       flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC|S_NOSEC);
3413         if ((ip->i_eattr == 0) && !is_sxid(inode->i_mode))
3414                 inode->i_flags |= S_NOSEC;
3415         if (ip->i_diskflags & GFS2_DIF_IMMUTABLE)
3416                 flags |= S_IMMUTABLE;
3417 +       if (ip->i_diskflags & GFS2_DIF_IXUNLINK)
3418 +               flags |= S_IXUNLINK;
3419 +
3420         if (ip->i_diskflags & GFS2_DIF_APPENDONLY)
3421                 flags |= S_APPEND;
3422         if (ip->i_diskflags & GFS2_DIF_NOATIME)
3423 @@ -197,6 +209,43 @@ void gfs2_set_inode_flags(struct inode *
3424         if (ip->i_diskflags & GFS2_DIF_SYNC)
3425                 flags |= S_SYNC;
3426         inode->i_flags = flags;
3427 +
3428 +       vflags &= ~(V_BARRIER | V_COW);
3429 +
3430 +       if (ip->i_diskflags & GFS2_DIF_BARRIER)
3431 +               vflags |= V_BARRIER;
3432 +       if (ip->i_diskflags & GFS2_DIF_COW)
3433 +               vflags |= V_COW;
3434 +       inode->i_vflags = vflags;
3435 +}
3436 +
3437 +void gfs2_get_inode_flags(struct inode *inode)
3438 +{
3439 +       struct gfs2_inode *ip = GFS2_I(inode);
3440 +       unsigned int flags = inode->i_flags;
3441 +       unsigned int vflags = inode->i_vflags;
3442 +
3443 +       ip->i_diskflags &= ~(GFS2_DIF_APPENDONLY |
3444 +                       GFS2_DIF_NOATIME | GFS2_DIF_SYNC |
3445 +                       GFS2_DIF_IMMUTABLE | GFS2_DIF_IXUNLINK |
3446 +                       GFS2_DIF_BARRIER | GFS2_DIF_COW);
3447 +
3448 +       if (flags & S_IMMUTABLE)
3449 +               ip->i_diskflags |= GFS2_DIF_IMMUTABLE;
3450 +       if (flags & S_IXUNLINK)
3451 +               ip->i_diskflags |= GFS2_DIF_IXUNLINK;
3452 +
3453 +       if (flags & S_APPEND)
3454 +               ip->i_diskflags |= GFS2_DIF_APPENDONLY;
3455 +       if (flags & S_NOATIME)
3456 +               ip->i_diskflags |= GFS2_DIF_NOATIME;
3457 +       if (flags & S_SYNC)
3458 +               ip->i_diskflags |= GFS2_DIF_SYNC;
3459 +
3460 +       if (vflags & V_BARRIER)
3461 +               ip->i_diskflags |= GFS2_DIF_BARRIER;
3462 +       if (vflags & V_COW)
3463 +               ip->i_diskflags |= GFS2_DIF_COW;
3464  }
3465  
3466  /* Flags that can be set by user space */
3467 @@ -310,6 +359,37 @@ static int gfs2_set_flags(struct file *f
3468         return do_gfs2_set_flags(filp, gfsflags, ~GFS2_DIF_JDATA);
3469  }
3470  
3471 +int gfs2_sync_flags(struct inode *inode, int flags, int vflags)
3472 +{
3473 +       struct gfs2_inode *ip = GFS2_I(inode);
3474 +       struct gfs2_sbd *sdp = GFS2_SB(inode);
3475 +       struct buffer_head *bh;
3476 +       struct gfs2_holder gh;
3477 +       int error;
3478 +
3479 +       error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
3480 +       if (error)
3481 +               return error;
3482 +       error = gfs2_trans_begin(sdp, RES_DINODE, 0);
3483 +       if (error)
3484 +               goto out;
3485 +       error = gfs2_meta_inode_buffer(ip, &bh);
3486 +       if (error)
3487 +               goto out_trans_end;
3488 +       gfs2_trans_add_meta(ip->i_gl, bh);
3489 +       inode->i_flags = flags;
3490 +       inode->i_vflags = vflags;
3491 +       gfs2_get_inode_flags(inode);
3492 +       gfs2_dinode_out(ip, bh->b_data);
3493 +       brelse(bh);
3494 +       gfs2_set_aops(inode);
3495 +out_trans_end:
3496 +       gfs2_trans_end(sdp);
3497 +out:
3498 +       gfs2_glock_dq_uninit(&gh);
3499 +       return error;
3500 +}
3501 +
3502  static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3503  {
3504         switch(cmd) {
3505 diff -NurpP --minimal linux-3.10.9/fs/gfs2/inode.h linux-3.10.9-vs2.3.6.6/fs/gfs2/inode.h
3506 --- linux-3.10.9/fs/gfs2/inode.h        2012-12-11 03:30:57.000000000 +0000
3507 +++ linux-3.10.9-vs2.3.6.6/fs/gfs2/inode.h      2013-08-22 20:29:59.000000000 +0000
3508 @@ -117,6 +117,7 @@ extern const struct file_operations gfs2
3509  extern const struct file_operations gfs2_dir_fops_nolock;
3510  
3511  extern void gfs2_set_inode_flags(struct inode *inode);
3512 +extern int gfs2_sync_flags(struct inode *inode, int flags, int vflags);
3513   
3514  #ifdef CONFIG_GFS2_FS_LOCKING_DLM
3515  extern const struct file_operations gfs2_file_fops;
3516 diff -NurpP --minimal linux-3.10.9/fs/hostfs/hostfs.h linux-3.10.9-vs2.3.6.6/fs/hostfs/hostfs.h
3517 --- linux-3.10.9/fs/hostfs/hostfs.h     2012-12-11 03:30:57.000000000 +0000
3518 +++ linux-3.10.9-vs2.3.6.6/fs/hostfs/hostfs.h   2013-08-22 20:29:59.000000000 +0000
3519 @@ -42,6 +42,7 @@ struct hostfs_iattr {
3520         unsigned short  ia_mode;
3521         uid_t           ia_uid;
3522         gid_t           ia_gid;
3523 +       vtag_t          ia_tag;
3524         loff_t          ia_size;
3525         struct timespec ia_atime;
3526         struct timespec ia_mtime;
3527 diff -NurpP --minimal linux-3.10.9/fs/inode.c linux-3.10.9-vs2.3.6.6/fs/inode.c
3528 --- linux-3.10.9/fs/inode.c     2013-07-14 17:01:28.000000000 +0000
3529 +++ linux-3.10.9-vs2.3.6.6/fs/inode.c   2013-08-22 20:29:59.000000000 +0000
3530 @@ -17,6 +17,7 @@
3531  #include <linux/prefetch.h>
3532  #include <linux/buffer_head.h> /* for inode_has_buffers */
3533  #include <linux/ratelimit.h>
3534 +#include <linux/vs_tag.h>
3535  #include "internal.h"
3536  
3537  /*
3538 @@ -128,6 +129,8 @@ int inode_init_always(struct super_block
3539         struct address_space *const mapping = &inode->i_data;
3540  
3541         inode->i_sb = sb;
3542 +
3543 +       /* essential because of inode slab reuse */
3544         inode->i_blkbits = sb->s_blocksize_bits;
3545         inode->i_flags = 0;
3546         atomic_set(&inode->i_count, 1);
3547 @@ -137,6 +140,7 @@ int inode_init_always(struct super_block
3548         inode->i_opflags = 0;
3549         i_uid_write(inode, 0);
3550         i_gid_write(inode, 0);
3551 +       i_tag_write(inode, 0);
3552         atomic_set(&inode->i_writecount, 0);
3553         inode->i_size = 0;
3554         inode->i_blocks = 0;
3555 @@ -149,6 +153,7 @@ int inode_init_always(struct super_block
3556         inode->i_bdev = NULL;
3557         inode->i_cdev = NULL;
3558         inode->i_rdev = 0;
3559 +       inode->i_mdev = 0;
3560         inode->dirtied_when = 0;
3561  
3562         if (security_inode_alloc(inode))
3563 @@ -483,6 +488,8 @@ void __insert_inode_hash(struct inode *i
3564  }
3565  EXPORT_SYMBOL(__insert_inode_hash);
3566  
3567 +EXPORT_SYMBOL_GPL(__iget);
3568 +
3569  /**
3570   *     __remove_inode_hash - remove an inode from the hash
3571   *     @inode: inode to unhash
3572 @@ -1799,9 +1806,11 @@ void init_special_inode(struct inode *in
3573         if (S_ISCHR(mode)) {
3574                 inode->i_fop = &def_chr_fops;
3575                 inode->i_rdev = rdev;
3576 +               inode->i_mdev = rdev;
3577         } else if (S_ISBLK(mode)) {
3578                 inode->i_fop = &def_blk_fops;
3579                 inode->i_rdev = rdev;
3580 +               inode->i_mdev = rdev;
3581         } else if (S_ISFIFO(mode))
3582                 inode->i_fop = &pipefifo_fops;
3583         else if (S_ISSOCK(mode))
3584 @@ -1830,6 +1839,7 @@ void inode_init_owner(struct inode *inod
3585         } else
3586                 inode->i_gid = current_fsgid();
3587         inode->i_mode = mode;
3588 +       i_tag_write(inode, dx_current_fstag(inode->i_sb));
3589  }
3590  EXPORT_SYMBOL(inode_init_owner);
3591  
3592 diff -NurpP --minimal linux-3.10.9/fs/ioctl.c linux-3.10.9-vs2.3.6.6/fs/ioctl.c
3593 --- linux-3.10.9/fs/ioctl.c     2013-05-31 13:45:24.000000000 +0000
3594 +++ linux-3.10.9-vs2.3.6.6/fs/ioctl.c   2013-08-22 20:29:59.000000000 +0000
3595 @@ -15,6 +15,9 @@
3596  #include <linux/writeback.h>
3597  #include <linux/buffer_head.h>
3598  #include <linux/falloc.h>
3599 +#include <linux/proc_fs.h>
3600 +#include <linux/vserver/inode.h>
3601 +#include <linux/vs_tag.h>
3602  
3603  #include <asm/ioctls.h>
3604  
3605 diff -NurpP --minimal linux-3.10.9/fs/ioprio.c linux-3.10.9-vs2.3.6.6/fs/ioprio.c
3606 --- linux-3.10.9/fs/ioprio.c    2012-12-11 03:30:57.000000000 +0000
3607 +++ linux-3.10.9-vs2.3.6.6/fs/ioprio.c  2013-08-22 20:29:59.000000000 +0000
3608 @@ -28,6 +28,7 @@
3609  #include <linux/syscalls.h>
3610  #include <linux/security.h>
3611  #include <linux/pid_namespace.h>
3612 +#include <linux/vs_base.h>
3613  
3614  int set_task_ioprio(struct task_struct *task, int ioprio)
3615  {
3616 @@ -105,6 +106,8 @@ SYSCALL_DEFINE3(ioprio_set, int, which,
3617                         else
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))
3621 +                                       continue;
3622                                 ret = set_task_ioprio(p, ioprio);
3623                                 if (ret)
3624                                         break;
3625 @@ -198,6 +201,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which,
3626                         else
3627                                 pgrp = find_vpid(who);
3628                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3629 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3630 +                                       continue;
3631                                 tmpio = get_task_ioprio(p);
3632                                 if (tmpio < 0)
3633                                         continue;
3634 diff -NurpP --minimal linux-3.10.9/fs/jfs/file.c linux-3.10.9-vs2.3.6.6/fs/jfs/file.c
3635 --- linux-3.10.9/fs/jfs/file.c  2013-02-19 13:58:48.000000000 +0000
3636 +++ linux-3.10.9-vs2.3.6.6/fs/jfs/file.c        2013-08-22 20:29:59.000000000 +0000
3637 @@ -109,7 +109,8 @@ int jfs_setattr(struct dentry *dentry, s
3638         if (is_quota_modification(inode, iattr))
3639                 dquot_initialize(inode);
3640         if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
3641 -           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
3642 +           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid)) ||
3643 +           (iattr->ia_valid & ATTR_TAG && !tag_eq(iattr->ia_tag, inode->i_tag))) {
3644                 rc = dquot_transfer(inode, iattr);
3645                 if (rc)
3646                         return rc;
3647 @@ -144,6 +145,7 @@ const struct inode_operations jfs_file_i
3648  #ifdef CONFIG_JFS_POSIX_ACL
3649         .get_acl        = jfs_get_acl,
3650  #endif
3651 +       .sync_flags     = jfs_sync_flags,
3652  };
3653  
3654  const struct file_operations jfs_file_operations = {
3655 diff -NurpP --minimal linux-3.10.9/fs/jfs/ioctl.c linux-3.10.9-vs2.3.6.6/fs/jfs/ioctl.c
3656 --- linux-3.10.9/fs/jfs/ioctl.c 2013-05-31 13:45:24.000000000 +0000
3657 +++ linux-3.10.9-vs2.3.6.6/fs/jfs/ioctl.c       2013-08-22 20:29:59.000000000 +0000
3658 @@ -12,6 +12,7 @@
3659  #include <linux/time.h>
3660  #include <linux/sched.h>
3661  #include <linux/blkdev.h>
3662 +#include <linux/mount.h>
3663  #include <asm/current.h>
3664  #include <asm/uaccess.h>
3665  
3666 @@ -56,6 +57,16 @@ static long jfs_map_ext2(unsigned long f
3667  }
3668  
3669  
3670 +int jfs_sync_flags(struct inode *inode, int flags, int vflags)
3671 +{
3672 +       inode->i_flags = flags;
3673 +       inode->i_vflags = vflags;
3674 +       jfs_get_inode_flags(JFS_IP(inode));
3675 +       inode->i_ctime = CURRENT_TIME_SEC;
3676 +       mark_inode_dirty(inode);
3677 +       return 0;
3678 +}
3679 +
3680  long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3681  {
3682         struct inode *inode = file_inode(filp);
3683 @@ -89,6 +100,11 @@ long jfs_ioctl(struct file *filp, unsign
3684                 if (!S_ISDIR(inode->i_mode))
3685                         flags &= ~JFS_DIRSYNC_FL;
3686  
3687 +               if (IS_BARRIER(inode)) {
3688 +                       vxwprintk_task(1, "messing with the barrier.");
3689 +                       return -EACCES;
3690 +               }
3691 +
3692                 /* Is it quota file? Do not allow user to mess with it */
3693                 if (IS_NOQUOTA(inode)) {
3694                         err = -EPERM;
3695 @@ -106,8 +122,8 @@ long jfs_ioctl(struct file *filp, unsign
3696                  * the relevant capability.
3697                  */
3698                 if ((oldflags & JFS_IMMUTABLE_FL) ||
3699 -                       ((flags ^ oldflags) &
3700 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
3701 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
3702 +                       JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
3703                         if (!capable(CAP_LINUX_IMMUTABLE)) {
3704                                 mutex_unlock(&inode->i_mutex);
3705                                 err = -EPERM;
3706 @@ -115,7 +131,7 @@ long jfs_ioctl(struct file *filp, unsign
3707                         }
3708                 }
3709  
3710 -               flags = flags & JFS_FL_USER_MODIFIABLE;
3711 +               flags &= JFS_FL_USER_MODIFIABLE;
3712                 flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
3713                 jfs_inode->mode2 = flags;
3714  
3715 diff -NurpP --minimal linux-3.10.9/fs/jfs/jfs_dinode.h linux-3.10.9-vs2.3.6.6/fs/jfs/jfs_dinode.h
3716 --- linux-3.10.9/fs/jfs/jfs_dinode.h    2012-12-11 03:30:57.000000000 +0000
3717 +++ linux-3.10.9-vs2.3.6.6/fs/jfs/jfs_dinode.h  2013-08-22 20:29:59.000000000 +0000
3718 @@ -161,9 +161,13 @@ struct dinode {
3719  
3720  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
3721  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
3722 +#define JFS_IXUNLINK_FL                0x08000000 /* Immutable invert on unlink */
3723  
3724 -#define JFS_FL_USER_VISIBLE    0x03F80000
3725 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
3726 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
3727 +#define JFS_COW_FL             0x20000000 /* Copy on Write marker */
3728 +
3729 +#define JFS_FL_USER_VISIBLE    0x07F80000
3730 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
3731  #define JFS_FL_INHERIT         0x03C80000
3732  
3733  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
3734 diff -NurpP --minimal linux-3.10.9/fs/jfs/jfs_filsys.h linux-3.10.9-vs2.3.6.6/fs/jfs/jfs_filsys.h
3735 --- linux-3.10.9/fs/jfs/jfs_filsys.h    2012-12-11 03:30:57.000000000 +0000
3736 +++ linux-3.10.9-vs2.3.6.6/fs/jfs/jfs_filsys.h  2013-08-22 20:29:59.000000000 +0000
3737 @@ -266,6 +266,7 @@
3738  #define JFS_NAME_MAX   255
3739  #define JFS_PATH_MAX   BPSIZE
3740  
3741 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
3742  
3743  /*
3744   *     file system state (superblock state)
3745 diff -NurpP --minimal linux-3.10.9/fs/jfs/jfs_imap.c linux-3.10.9-vs2.3.6.6/fs/jfs/jfs_imap.c
3746 --- linux-3.10.9/fs/jfs/jfs_imap.c      2013-07-14 17:01:28.000000000 +0000
3747 +++ linux-3.10.9-vs2.3.6.6/fs/jfs/jfs_imap.c    2013-08-22 20:29:59.000000000 +0000
3748 @@ -46,6 +46,7 @@
3749  #include <linux/pagemap.h>
3750  #include <linux/quotaops.h>
3751  #include <linux/slab.h>
3752 +#include <linux/vs_tag.h>
3753  
3754  #include "jfs_incore.h"
3755  #include "jfs_inode.h"
3756 @@ -3058,6 +3059,8 @@ static int copy_from_dinode(struct dinod
3757  {
3758         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
3759         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
3760 +       kuid_t kuid;
3761 +       kgid_t kgid;
3762  
3763         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
3764         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
3765 @@ -3078,14 +3081,18 @@ static int copy_from_dinode(struct dinod
3766         }
3767         set_nlink(ip, le32_to_cpu(dip->di_nlink));
3768  
3769 -       jfs_ip->saved_uid = make_kuid(&init_user_ns, le32_to_cpu(dip->di_uid));
3770 +       kuid = make_kuid(&init_user_ns, le32_to_cpu(dip->di_uid));
3771 +       kgid = make_kgid(&init_user_ns, le32_to_cpu(dip->di_gid));
3772 +       ip->i_tag = INOTAG_KTAG(DX_TAG(ip), kuid, kgid, GLOBAL_ROOT_TAG);
3773 +
3774 +       jfs_ip->saved_uid = INOTAG_KUID(DX_TAG(ip), kuid, kgid);
3775         if (!uid_valid(sbi->uid))
3776                 ip->i_uid = jfs_ip->saved_uid;
3777         else {
3778                 ip->i_uid = sbi->uid;
3779         }
3780  
3781 -       jfs_ip->saved_gid = make_kgid(&init_user_ns, le32_to_cpu(dip->di_gid));
3782 +       jfs_ip->saved_gid = INOTAG_KGID(DX_TAG(ip), kuid, kgid);
3783         if (!gid_valid(sbi->gid))
3784                 ip->i_gid = jfs_ip->saved_gid;
3785         else {
3786 @@ -3150,16 +3157,14 @@ static void copy_to_dinode(struct dinode
3787         dip->di_size = cpu_to_le64(ip->i_size);
3788         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
3789         dip->di_nlink = cpu_to_le32(ip->i_nlink);
3790 -       if (!uid_valid(sbi->uid))
3791 -               dip->di_uid = cpu_to_le32(i_uid_read(ip));
3792 -       else
3793 -               dip->di_uid =cpu_to_le32(from_kuid(&init_user_ns,
3794 -                                                  jfs_ip->saved_uid));
3795 -       if (!gid_valid(sbi->gid))
3796 -               dip->di_gid = cpu_to_le32(i_gid_read(ip));
3797 -       else
3798 -               dip->di_gid = cpu_to_le32(from_kgid(&init_user_ns,
3799 -                                                   jfs_ip->saved_gid));
3800 +       dip->di_uid = cpu_to_le32(from_kuid(&init_user_ns,
3801 +               TAGINO_KUID(DX_TAG(ip),
3802 +               !uid_valid(sbi->uid) ? ip->i_uid : jfs_ip->saved_uid,
3803 +               ip->i_tag)));
3804 +       dip->di_gid = cpu_to_le32(from_kgid(&init_user_ns,
3805 +               TAGINO_KGID(DX_TAG(ip),
3806 +               !gid_valid(sbi->gid) ? ip->i_gid : jfs_ip->saved_gid,
3807 +               ip->i_tag)));
3808         jfs_get_inode_flags(jfs_ip);
3809         /*
3810          * mode2 is only needed for storing the higher order bits.
3811 diff -NurpP --minimal linux-3.10.9/fs/jfs/jfs_inode.c linux-3.10.9-vs2.3.6.6/fs/jfs/jfs_inode.c
3812 --- linux-3.10.9/fs/jfs/jfs_inode.c     2012-12-11 03:30:57.000000000 +0000
3813 +++ linux-3.10.9-vs2.3.6.6/fs/jfs/jfs_inode.c   2013-08-22 20:29:59.000000000 +0000
3814 @@ -18,6 +18,7 @@
3815  
3816  #include <linux/fs.h>
3817  #include <linux/quotaops.h>
3818 +#include <linux/vs_tag.h>
3819  #include "jfs_incore.h"
3820  #include "jfs_inode.h"
3821  #include "jfs_filsys.h"
3822 @@ -30,29 +31,46 @@ void jfs_set_inode_flags(struct inode *i
3823  {
3824         unsigned int flags = JFS_IP(inode)->mode2;
3825  
3826 -       inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
3827 -               S_NOATIME | S_DIRSYNC | S_SYNC);
3828 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3829 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3830  
3831         if (flags & JFS_IMMUTABLE_FL)
3832                 inode->i_flags |= S_IMMUTABLE;
3833 +       if (flags & JFS_IXUNLINK_FL)
3834 +               inode->i_flags |= S_IXUNLINK;
3835 +
3836 +       if (flags & JFS_SYNC_FL)
3837 +               inode->i_flags |= S_SYNC;
3838         if (flags & JFS_APPEND_FL)
3839                 inode->i_flags |= S_APPEND;
3840         if (flags & JFS_NOATIME_FL)
3841                 inode->i_flags |= S_NOATIME;
3842         if (flags & JFS_DIRSYNC_FL)
3843                 inode->i_flags |= S_DIRSYNC;
3844 -       if (flags & JFS_SYNC_FL)
3845 -               inode->i_flags |= S_SYNC;
3846 +
3847 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3848 +
3849 +       if (flags & JFS_BARRIER_FL)
3850 +               inode->i_vflags |= V_BARRIER;
3851 +       if (flags & JFS_COW_FL)
3852 +               inode->i_vflags |= V_COW;
3853  }
3854  
3855  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
3856  {
3857         unsigned int flags = jfs_ip->vfs_inode.i_flags;
3858 +       unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
3859 +
3860 +       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
3861 +                          JFS_APPEND_FL | JFS_NOATIME_FL |
3862 +                          JFS_DIRSYNC_FL | JFS_SYNC_FL |
3863 +                          JFS_BARRIER_FL | JFS_COW_FL);
3864  
3865 -       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
3866 -                          JFS_DIRSYNC_FL | JFS_SYNC_FL);
3867         if (flags & S_IMMUTABLE)
3868                 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
3869 +       if (flags & S_IXUNLINK)
3870 +               jfs_ip->mode2 |= JFS_IXUNLINK_FL;
3871 +
3872         if (flags & S_APPEND)
3873                 jfs_ip->mode2 |= JFS_APPEND_FL;
3874         if (flags & S_NOATIME)
3875 @@ -61,6 +79,11 @@ void jfs_get_inode_flags(struct jfs_inod
3876                 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
3877         if (flags & S_SYNC)
3878                 jfs_ip->mode2 |= JFS_SYNC_FL;
3879 +
3880 +       if (vflags & V_BARRIER)
3881 +               jfs_ip->mode2 |= JFS_BARRIER_FL;
3882 +       if (vflags & V_COW)
3883 +               jfs_ip->mode2 |= JFS_COW_FL;
3884  }
3885  
3886  /*
3887 diff -NurpP --minimal linux-3.10.9/fs/jfs/jfs_inode.h linux-3.10.9-vs2.3.6.6/fs/jfs/jfs_inode.h
3888 --- linux-3.10.9/fs/jfs/jfs_inode.h     2012-12-11 03:30:57.000000000 +0000
3889 +++ linux-3.10.9-vs2.3.6.6/fs/jfs/jfs_inode.h   2013-08-22 20:29:59.000000000 +0000
3890 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
3891  extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
3892         int fh_len, int fh_type);
3893  extern void jfs_set_inode_flags(struct inode *);
3894 +extern int jfs_sync_flags(struct inode *, int, int);
3895  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
3896  extern int jfs_setattr(struct dentry *, struct iattr *);
3897  
3898 diff -NurpP --minimal linux-3.10.9/fs/jfs/namei.c linux-3.10.9-vs2.3.6.6/fs/jfs/namei.c
3899 --- linux-3.10.9/fs/jfs/namei.c 2012-12-11 03:30:57.000000000 +0000
3900 +++ linux-3.10.9-vs2.3.6.6/fs/jfs/namei.c       2013-08-22 20:29:59.000000000 +0000
3901 @@ -22,6 +22,7 @@
3902  #include <linux/ctype.h>
3903  #include <linux/quotaops.h>
3904  #include <linux/exportfs.h>
3905 +#include <linux/vs_tag.h>
3906  #include "jfs_incore.h"
3907  #include "jfs_superblock.h"
3908  #include "jfs_inode.h"
3909 @@ -1461,6 +1462,7 @@ static struct dentry *jfs_lookup(struct
3910                         jfs_err("jfs_lookup: iget failed on inum %d", (uint)inum);
3911         }
3912  
3913 +       dx_propagate_tag(nd, ip);
3914         return d_splice_alias(ip, dentry);
3915  }
3916  
3917 @@ -1525,6 +1527,7 @@ const struct inode_operations jfs_dir_in
3918  #ifdef CONFIG_JFS_POSIX_ACL
3919         .get_acl        = jfs_get_acl,
3920  #endif
3921 +       .sync_flags     = jfs_sync_flags,
3922  };
3923  
3924  const struct file_operations jfs_dir_operations = {
3925 diff -NurpP --minimal linux-3.10.9/fs/jfs/super.c linux-3.10.9-vs2.3.6.6/fs/jfs/super.c
3926 --- linux-3.10.9/fs/jfs/super.c 2013-07-14 17:01:28.000000000 +0000
3927 +++ linux-3.10.9-vs2.3.6.6/fs/jfs/super.c       2013-08-22 20:29:59.000000000 +0000
3928 @@ -199,7 +199,8 @@ enum {
3929         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
3930         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
3931         Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
3932 -       Opt_discard, Opt_nodiscard, Opt_discard_minblk
3933 +       Opt_discard, Opt_nodiscard, Opt_discard_minblk,
3934 +       Opt_tag, Opt_notag, Opt_tagid
3935  };
3936  
3937  static const match_table_t tokens = {
3938 @@ -209,6 +210,10 @@ static const match_table_t tokens = {
3939         {Opt_resize, "resize=%u"},
3940         {Opt_resize_nosize, "resize"},
3941         {Opt_errors, "errors=%s"},
3942 +       {Opt_tag, "tag"},
3943 +       {Opt_notag, "notag"},
3944 +       {Opt_tagid, "tagid=%u"},
3945 +       {Opt_tag, "tagxid"},
3946         {Opt_ignore, "noquota"},
3947         {Opt_ignore, "quota"},
3948         {Opt_usrquota, "usrquota"},
3949 @@ -385,7 +390,20 @@ static int parse_options(char *options,
3950                         }
3951                         break;
3952                 }
3953 -
3954 +#ifndef CONFIG_TAGGING_NONE
3955 +               case Opt_tag:
3956 +                       *flag |= JFS_TAGGED;
3957 +                       break;
3958 +               case Opt_notag:
3959 +                       *flag &= JFS_TAGGED;
3960 +                       break;
3961 +#endif
3962 +#ifdef CONFIG_PROPAGATE
3963 +               case Opt_tagid:
3964 +                       /* use args[0] */
3965 +                       *flag |= JFS_TAGGED;
3966 +                       break;
3967 +#endif
3968                 default:
3969                         printk("jfs: Unrecognized mount option \"%s\" "
3970                                         " or missing value\n", p);
3971 @@ -417,6 +435,12 @@ static int jfs_remount(struct super_bloc
3972                 return -EINVAL;
3973         }
3974  
3975 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
3976 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
3977 +                       sb->s_id);
3978 +               return -EINVAL;
3979 +       }
3980 +
3981         if (newLVSize) {
3982                 if (sb->s_flags & MS_RDONLY) {
3983                         pr_err("JFS: resize requires volume" \
3984 @@ -502,6 +526,9 @@ static int jfs_fill_super(struct super_b
3985  #ifdef CONFIG_JFS_POSIX_ACL
3986         sb->s_flags |= MS_POSIXACL;
3987  #endif
3988 +       /* map mount option tagxid */
3989 +       if (sbi->flag & JFS_TAGGED)
3990 +               sb->s_flags |= MS_TAGGED;
3991  
3992         if (newLVSize) {
3993                 pr_err("resize option for remount only\n");
3994 diff -NurpP --minimal linux-3.10.9/fs/libfs.c linux-3.10.9-vs2.3.6.6/fs/libfs.c
3995 --- linux-3.10.9/fs/libfs.c     2013-02-19 13:58:48.000000000 +0000
3996 +++ linux-3.10.9-vs2.3.6.6/fs/libfs.c   2013-08-22 20:29:59.000000000 +0000
3997 @@ -135,7 +135,8 @@ static inline unsigned char dt_type(stru
3998   * both impossible due to the lock on directory.
3999   */
4000  
4001 -int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
4002 +static inline int do_dcache_readdir_filter(struct file *filp,
4003 +       void *dirent, filldir_t filldir, int (*filter)(struct dentry *dentry))
4004  {
4005         struct dentry *dentry = filp->f_path.dentry;
4006         struct dentry *cursor = filp->private_data;
4007 @@ -166,6 +167,8 @@ int dcache_readdir(struct file * filp, v
4008                         for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
4009                                 struct dentry *next;
4010                                 next = list_entry(p, struct dentry, d_u.d_child);
4011 +                               if (filter && !filter(next))
4012 +                                       continue;
4013                                 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
4014                                 if (!simple_positive(next)) {
4015                                         spin_unlock(&next->d_lock);
4016 @@ -192,6 +195,17 @@ int dcache_readdir(struct file * filp, v
4017         return 0;
4018  }
4019  
4020 +int dcache_readdir(struct file *filp, void *dirent, filldir_t filldir)
4021 +{
4022 +       return do_dcache_readdir_filter(filp, dirent, filldir, NULL);
4023 +}
4024 +
4025 +int dcache_readdir_filter(struct file *filp, void *dirent, filldir_t filldir,
4026 +       int (*filter)(struct dentry *))
4027 +{
4028 +       return do_dcache_readdir_filter(filp, dirent, filldir, filter);
4029 +}
4030 +
4031  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
4032  {
4033         return -EISDIR;
4034 @@ -981,6 +995,7 @@ EXPORT_SYMBOL(dcache_dir_close);
4035  EXPORT_SYMBOL(dcache_dir_lseek);
4036  EXPORT_SYMBOL(dcache_dir_open);
4037  EXPORT_SYMBOL(dcache_readdir);
4038 +EXPORT_SYMBOL(dcache_readdir_filter);
4039  EXPORT_SYMBOL(generic_read_dir);
4040  EXPORT_SYMBOL(mount_pseudo);
4041  EXPORT_SYMBOL(simple_write_begin);
4042 diff -NurpP --minimal linux-3.10.9/fs/locks.c linux-3.10.9-vs2.3.6.6/fs/locks.c
4043 --- linux-3.10.9/fs/locks.c     2013-05-31 13:45:24.000000000 +0000
4044 +++ linux-3.10.9-vs2.3.6.6/fs/locks.c   2013-08-22 20:29:59.000000000 +0000
4045 @@ -126,6 +126,8 @@
4046  #include <linux/time.h>
4047  #include <linux/rcupdate.h>
4048  #include <linux/pid_namespace.h>
4049 +#include <linux/vs_base.h>
4050 +#include <linux/vs_limit.h>
4051  
4052  #include <asm/uaccess.h>
4053  
4054 @@ -184,11 +186,17 @@ static void locks_init_lock_heads(struct
4055  /* Allocate an empty lock structure. */
4056  struct file_lock *locks_alloc_lock(void)
4057  {
4058 -       struct file_lock *fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4059 +       struct file_lock *fl;
4060  
4061 -       if (fl)
4062 -               locks_init_lock_heads(fl);
4063 +       if (!vx_locks_avail(1))
4064 +               return NULL;
4065  
4066 +       fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4067 +
4068 +       if (fl) {
4069 +               locks_init_lock_heads(fl);
4070 +               fl->fl_xid = -1;
4071 +       }
4072         return fl;
4073  }
4074  EXPORT_SYMBOL_GPL(locks_alloc_lock);
4075 @@ -212,6 +220,7 @@ void locks_free_lock(struct file_lock *f
4076         BUG_ON(!list_empty(&fl->fl_block));
4077         BUG_ON(!list_empty(&fl->fl_link));
4078  
4079 +       vx_locks_dec(fl);
4080         locks_release_private(fl);
4081         kmem_cache_free(filelock_cache, fl);
4082  }
4083 @@ -221,6 +230,7 @@ void locks_init_lock(struct file_lock *f
4084  {
4085         memset(fl, 0, sizeof(struct file_lock));
4086         locks_init_lock_heads(fl);
4087 +       fl->fl_xid = -1;
4088  }
4089  
4090  EXPORT_SYMBOL(locks_init_lock);
4091 @@ -261,6 +271,7 @@ void locks_copy_lock(struct file_lock *n
4092         new->fl_file = fl->fl_file;
4093         new->fl_ops = fl->fl_ops;
4094         new->fl_lmops = fl->fl_lmops;
4095 +       new->fl_xid = fl->fl_xid;
4096  
4097         locks_copy_private(new, fl);
4098  }
4099 @@ -299,6 +310,11 @@ static int flock_make_lock(struct file *
4100         fl->fl_flags = FL_FLOCK;
4101         fl->fl_type = type;
4102         fl->fl_end = OFFSET_MAX;
4103 +
4104 +       vxd_assert(filp->f_xid == vx_current_xid(),
4105 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4106 +       fl->fl_xid = filp->f_xid;
4107 +       vx_locks_inc(fl);
4108         
4109         *lock = fl;
4110         return 0;
4111 @@ -438,6 +454,7 @@ static int lease_init(struct file *filp,
4112  
4113         fl->fl_owner = current->files;
4114         fl->fl_pid = current->tgid;
4115 +       fl->fl_xid = vx_current_xid();
4116  
4117         fl->fl_file = filp;
4118         fl->fl_flags = FL_LEASE;
4119 @@ -457,6 +474,11 @@ static struct file_lock *lease_alloc(str
4120         if (fl == NULL)
4121                 return ERR_PTR(error);
4122  
4123 +       fl->fl_xid = vx_current_xid();
4124 +       if (filp)
4125 +               vxd_assert(filp->f_xid == fl->fl_xid,
4126 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
4127 +       vx_locks_inc(fl);
4128         error = lease_init(filp, type, fl);
4129         if (error) {
4130                 locks_free_lock(fl);
4131 @@ -753,6 +775,7 @@ static int flock_lock_file(struct file *
4132                 lock_flocks();
4133         }
4134  
4135 +       new_fl->fl_xid = -1;
4136  find_conflict:
4137         for_each_lock(inode, before) {
4138                 struct file_lock *fl = *before;
4139 @@ -773,6 +796,7 @@ find_conflict:
4140                 goto out;
4141         locks_copy_lock(new_fl, request);
4142         locks_insert_lock(before, new_fl);
4143 +       vx_locks_inc(new_fl);
4144         new_fl = NULL;
4145         error = 0;
4146  
4147 @@ -783,7 +807,8 @@ out:
4148         return error;
4149  }
4150  
4151 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
4152 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
4153 +       struct file_lock *conflock, vxid_t xid)
4154  {
4155         struct file_lock *fl;
4156         struct file_lock *new_fl = NULL;
4157 @@ -793,6 +818,8 @@ static int __posix_lock_file(struct inod
4158         struct file_lock **before;
4159         int error, added = 0;
4160  
4161 +       vxd_assert(xid == vx_current_xid(),
4162 +               "xid(%d) == current(%d)", xid, vx_current_xid());
4163         /*
4164          * We may need two file_lock structures for this operation,
4165          * so we get them in advance to avoid races.
4166 @@ -803,7 +830,11 @@ static int __posix_lock_file(struct inod
4167             (request->fl_type != F_UNLCK ||
4168              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
4169                 new_fl = locks_alloc_lock();
4170 +               new_fl->fl_xid = xid;
4171 +               vx_locks_inc(new_fl);
4172                 new_fl2 = locks_alloc_lock();
4173 +               new_fl2->fl_xid = xid;
4174 +               vx_locks_inc(new_fl2);
4175         }
4176  
4177         lock_flocks();
4178 @@ -1002,7 +1033,8 @@ static int __posix_lock_file(struct inod
4179  int posix_lock_file(struct file *filp, struct file_lock *fl,
4180                         struct file_lock *conflock)
4181  {
4182 -       return __posix_lock_file(file_inode(filp), fl, conflock);
4183 +       return __posix_lock_file(file_inode(filp),
4184 +               fl, conflock, filp->f_xid);
4185  }
4186  EXPORT_SYMBOL(posix_lock_file);
4187  
4188 @@ -1092,7 +1124,7 @@ int locks_mandatory_area(int read_write,
4189         fl.fl_end = offset + count - 1;
4190  
4191         for (;;) {
4192 -               error = __posix_lock_file(inode, &fl, NULL);
4193 +               error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
4194                 if (error != FILE_LOCK_DEFERRED)
4195                         break;
4196                 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
4197 @@ -1397,6 +1429,7 @@ int generic_add_lease(struct file *filp,
4198                 goto out;
4199  
4200         locks_insert_lock(before, lease);
4201 +       vx_locks_inc(lease);
4202         return 0;
4203  
4204  out:
4205 @@ -1836,6 +1869,11 @@ int fcntl_setlk(unsigned int fd, struct
4206         if (file_lock == NULL)
4207                 return -ENOLCK;
4208  
4209 +       vxd_assert(filp->f_xid == vx_current_xid(),
4210 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4211 +       file_lock->fl_xid = filp->f_xid;
4212 +       vx_locks_inc(file_lock);
4213 +
4214         /*
4215          * This might block, so we do it before checking the inode.
4216          */
4217 @@ -1954,6 +1992,11 @@ int fcntl_setlk64(unsigned int fd, struc
4218         if (file_lock == NULL)
4219                 return -ENOLCK;
4220  
4221 +       vxd_assert(filp->f_xid == vx_current_xid(),
4222 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4223 +       file_lock->fl_xid = filp->f_xid;
4224 +       vx_locks_inc(file_lock);
4225 +
4226         /*
4227          * This might block, so we do it before checking the inode.
4228          */
4229 @@ -2219,8 +2262,11 @@ static int locks_show(struct seq_file *f
4230  
4231         lock_get_status(f, fl, *((loff_t *)f->private), "");
4232  
4233 -       list_for_each_entry(bfl, &fl->fl_block, fl_block)
4234 +       list_for_each_entry(bfl, &fl->fl_block, fl_block) {
4235 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
4236 +                       continue;
4237                 lock_get_status(f, bfl, *((loff_t *)f->private), " ->");
4238 +       }
4239  
4240         return 0;
4241  }
4242 diff -NurpP --minimal linux-3.10.9/fs/mount.h linux-3.10.9-vs2.3.6.6/fs/mount.h
4243 --- linux-3.10.9/fs/mount.h     2013-07-14 17:01:28.000000000 +0000
4244 +++ linux-3.10.9-vs2.3.6.6/fs/mount.h   2013-08-22 20:29:59.000000000 +0000
4245 @@ -56,6 +56,7 @@ struct mount {
4246         int mnt_expiry_mark;            /* true if marked for expiry */
4247         int mnt_pinned;
4248         int mnt_ghosts;
4249 +       vtag_t mnt_tag;                 /* tagging used for vfsmount */
4250  };
4251  
4252  #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
4253 diff -NurpP --minimal linux-3.10.9/fs/namei.c linux-3.10.9-vs2.3.6.6/fs/namei.c
4254 --- linux-3.10.9/fs/namei.c     2013-07-14 17:01:28.000000000 +0000
4255 +++ linux-3.10.9-vs2.3.6.6/fs/namei.c   2013-08-22 23:36:09.000000000 +0000
4256 @@ -34,9 +34,19 @@
4257  #include <linux/device_cgroup.h>
4258  #include <linux/fs_struct.h>
4259  #include <linux/posix_acl.h>
4260 +#include <linux/proc_fs.h>
4261 +#include <linux/magic.h>
4262 +#include <linux/vserver/inode.h>
4263 +#include <linux/vs_base.h>
4264 +#include <linux/vs_tag.h>
4265 +#include <linux/vs_cowbl.h>
4266 +#include <linux/vs_device.h>
4267 +#include <linux/vs_context.h>
4268 +#include <linux/pid_namespace.h>
4269  #include <asm/uaccess.h>
4270  
4271  #include "internal.h"
4272 +#include "proc/internal.h"
4273  #include "mount.h"
4274  
4275  /* [Feb-1997 T. Schoebel-Theuer]
4276 @@ -266,6 +276,89 @@ static int check_acl(struct inode *inode
4277         return -EAGAIN;
4278  }
4279  
4280 +static inline int dx_barrier(const struct inode *inode)
4281 +{
4282 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
4283 +               vxwprintk_task(1, "did hit the barrier.");
4284 +               return 1;
4285 +       }
4286 +       return 0;
4287 +}
4288 +
4289 +static int __dx_permission(const struct inode *inode, int mask)
4290 +{
4291 +       if (dx_barrier(inode))
4292 +               return -EACCES;
4293 +
4294 +       if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
4295 +               /* devpts is xid tagged */
4296 +               if (S_ISDIR(inode->i_mode) ||
4297 +                   vx_check((vxid_t)i_tag_read(inode), VS_IDENT | VS_WATCH_P))
4298 +                       return 0;
4299 +
4300 +               /* just pretend we didn't find anything */
4301 +               return -ENOENT;
4302 +       }
4303 +       else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
4304 +               struct proc_dir_entry *de = PDE(inode);
4305 +
4306 +               if (de && !vx_hide_check(0, de->vx_flags))
4307 +                       goto out;
4308 +
4309 +               if ((mask & (MAY_WRITE | MAY_APPEND))) {
4310 +                       struct pid *pid;
4311 +                       struct task_struct *tsk;
4312 +
4313 +                       if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
4314 +                           vx_flags(VXF_STATE_SETUP, 0))
4315 +                               return 0;
4316 +
4317 +                       pid = PROC_I(inode)->pid;
4318 +                       if (!pid)
4319 +                               goto out;
4320 +
4321 +                       rcu_read_lock();
4322 +                       tsk = pid_task(pid, PIDTYPE_PID);
4323 +                       vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
4324 +                                 tsk, (tsk ? vx_task_xid(tsk) : 0));
4325 +                       if (tsk &&
4326 +                               vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P)) {
4327 +                               rcu_read_unlock();
4328 +                               return 0;
4329 +                       }
4330 +                       rcu_read_unlock();
4331 +               }
4332 +               else {
4333 +                       /* FIXME: Should we block some entries here? */
4334 +                       return 0;
4335 +               }
4336 +       }
4337 +       else {
4338 +               if (dx_notagcheck(inode->i_sb) ||
4339 +                   dx_check((vxid_t)i_tag_read(inode),
4340 +                       DX_HOSTID | DX_ADMIN | DX_WATCH | DX_IDENT))
4341 +                       return 0;
4342 +       }
4343 +
4344 +out:
4345 +       return -EACCES;
4346 +}
4347 +
4348 +int dx_permission(const struct inode *inode, int mask)
4349 +{
4350 +       int ret = __dx_permission(inode, mask);
4351 +       if (unlikely(ret)) {
4352 +#ifndef        CONFIG_VSERVER_WARN_DEVPTS
4353 +               if (inode->i_sb->s_magic != DEVPTS_SUPER_MAGIC)
4354 +#endif
4355 +                   vxwprintk_task(1,
4356 +                       "denied [0x%x] access to inode %s:%p[#%d,%lu]",
4357 +                       mask, inode->i_sb->s_id, inode,
4358 +                       i_tag_read(inode), inode->i_ino);
4359 +       }
4360 +       return ret;
4361 +}
4362 +
4363  /*
4364   * This does the basic permission checking
4365   */
4366 @@ -388,10 +481,14 @@ int __inode_permission(struct inode *ino
4367                 /*
4368                  * Nobody gets write access to an immutable file.
4369                  */
4370 -               if (IS_IMMUTABLE(inode))
4371 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
4372                         return -EACCES;
4373         }
4374  
4375 +       retval = dx_permission(inode, mask);
4376 +       if (retval)
4377 +               return retval;
4378 +
4379         retval = do_inode_permission(inode, mask);
4380         if (retval)
4381                 return retval;
4382 @@ -1238,7 +1335,8 @@ static void follow_dotdot(struct nameida
4383  
4384                 if (nd->path.dentry == nd->root.dentry &&
4385                     nd->path.mnt == nd->root.mnt) {
4386 -                       break;
4387 +                       /* for sane '/' avoid follow_mount() */
4388 +                       return;
4389                 }
4390                 if (nd->path.dentry != nd->path.mnt->mnt_root) {
4391                         /* rare case of legitimate dget_parent()... */
4392 @@ -1383,6 +1481,9 @@ static int lookup_fast(struct nameidata
4393                                 goto unlazy;
4394                         }
4395                 }
4396 +
4397 +               /* FIXME: check dx permission */
4398 +
4399                 path->mnt = mnt;
4400                 path->dentry = dentry;
4401                 if (unlikely(!__follow_mount_rcu(nd, path, inode)))
4402 @@ -1413,6 +1514,8 @@ unlazy:
4403                 }
4404         }
4405  
4406 +       /* FIXME: check dx permission */
4407 +
4408         path->mnt = mnt;
4409         path->dentry = dentry;
4410         err = follow_managed(path, nd->flags);
4411 @@ -2237,7 +2340,7 @@ static int may_delete(struct inode *dir,
4412         if (IS_APPEND(dir))
4413                 return -EPERM;
4414         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
4415 -           IS_IMMUTABLE(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4416 +               IS_IXORUNLINK(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4417                 return -EPERM;
4418         if (isdir) {
4419                 if (!S_ISDIR(victim->d_inode->i_mode))
4420 @@ -2316,19 +2419,25 @@ int vfs_create(struct inode *dir, struct
4421                 bool want_excl)
4422  {
4423         int error = may_create(dir, dentry);
4424 -       if (error)
4425 +       if (error) {
4426 +               vxdprintk(VXD_CBIT(misc, 3), "may_create failed with %d", error);
4427                 return error;
4428 +       }
4429  
4430         if (!dir->i_op->create)
4431                 return -EACCES; /* shouldn't it be ENOSYS? */
4432         mode &= S_IALLUGO;
4433         mode |= S_IFREG;
4434         error = security_inode_create(dir, dentry, mode);
4435 -       if (error)
4436 +       if (error) {
4437 +               vxdprintk(VXD_CBIT(misc, 3), "security_inode_create failed with %d", error);
4438                 return error;
4439 +       }
4440         error = dir->i_op->create(dir, dentry, mode, want_excl);
4441         if (!error)
4442                 fsnotify_create(dir, dentry);
4443 +       else
4444 +               vxdprintk(VXD_CBIT(misc, 3), "i_op->create failed with %d", error);
4445         return error;
4446  }
4447  
4448 @@ -2363,6 +2472,15 @@ static int may_open(struct path *path, i
4449                 break;
4450         }
4451  
4452 +#ifdef CONFIG_VSERVER_COWBL
4453 +       if (IS_COW(inode) &&
4454 +               ((flag & O_ACCMODE) != O_RDONLY)) {
4455 +               if (IS_COW_LINK(inode))
4456 +                       return -EMLINK;
4457 +               inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
4458 +               mark_inode_dirty(inode);
4459 +       }
4460 +#endif
4461         error = inode_permission(inode, acc_mode);
4462         if (error)
4463                 return error;
4464 @@ -2865,6 +2983,16 @@ finish_open:
4465         }
4466  finish_open_created:
4467         error = may_open(&nd->path, acc_mode, open_flag);
4468 +#ifdef CONFIG_VSERVER_COWBL
4469 +       if (error == -EMLINK) {
4470 +               struct dentry *dentry;
4471 +               dentry = cow_break_link(name->name);
4472 +               if (IS_ERR(dentry))
4473 +                       error = PTR_ERR(dentry);
4474 +               else
4475 +                       dput(dentry);
4476 +       }
4477 +#endif
4478         if (error)
4479                 goto out;
4480         file->f_path.mnt = nd->path.mnt;
4481 @@ -2929,6 +3057,7 @@ static struct file *path_openat(int dfd,
4482         int opened = 0;
4483         int error;
4484  
4485 +restart:
4486         file = get_empty_filp();
4487         if (IS_ERR(file))
4488                 return file;
4489 @@ -2965,6 +3094,16 @@ static struct file *path_openat(int dfd,
4490                 error = do_last(nd, &path, file, op, &opened, pathname);
4491                 put_link(nd, &link, cookie);
4492         }
4493 +
4494 +#ifdef CONFIG_VSERVER_COWBL
4495 +       if (error == -EMLINK) {
4496 +               if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4497 +                       path_put(&nd->root);
4498 +               if (base)
4499 +                       fput(base);
4500 +               goto restart;
4501 +       }
4502 +#endif
4503  out:
4504         if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4505                 path_put(&nd->root);
4506 @@ -3079,6 +3218,11 @@ struct dentry *kern_path_create(int dfd,
4507                 goto fail;
4508         }
4509         *path = nd.path;
4510 +       vxdprintk(VXD_CBIT(misc, 3), "kern_path_create path.dentry = %p (%.*s), dentry = %p (%.*s), d_inode = %p",
4511 +               path->dentry, path->dentry->d_name.len,
4512 +               path->dentry->d_name.name, dentry,
4513 +               dentry->d_name.len, dentry->d_name.name,
4514 +               path->dentry->d_inode);
4515         return dentry;
4516  fail:
4517         dput(dentry);
4518 @@ -3573,7 +3717,7 @@ int vfs_link(struct dentry *old_dentry,
4519         /*
4520          * A link to an append-only or immutable file cannot be created.
4521          */
4522 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
4523 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
4524                 return -EPERM;
4525         if (!dir->i_op->link)
4526                 return -EPERM;
4527 @@ -3976,6 +4120,287 @@ int vfs_follow_link(struct nameidata *nd
4528         return __vfs_follow_link(nd, link);
4529  }
4530  
4531 +
4532 +#ifdef CONFIG_VSERVER_COWBL
4533 +
4534 +static inline
4535 +long do_cow_splice(struct file *in, struct file *out, size_t len)
4536 +{
4537 +       loff_t ppos = 0;
4538 +       loff_t opos = 0;
4539 +
4540 +       return do_splice_direct(in, &ppos, out, &opos, len, 0);
4541 +}
4542 +
4543 +struct dentry *cow_break_link(const char *pathname)
4544 +{
4545 +       int ret, mode, pathlen, redo = 0, drop = 1;
4546 +       struct nameidata old_nd, dir_nd;
4547 +       struct path dir_path, *old_path, *new_path;
4548 +       struct dentry *dir, *old_dentry, *new_dentry = NULL;
4549 +       struct file *old_file;
4550 +       struct file *new_file;
4551 +       char *to, *path, pad='\251';
4552 +       loff_t size;
4553 +
4554 +       vxdprintk(VXD_CBIT(misc, 1),
4555 +               "cow_break_link(" VS_Q("%s") ")", pathname);
4556 +
4557 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
4558 +       ret = -ENOMEM;
4559 +       if (!path)
4560 +               goto out;
4561 +
4562 +       /* old_nd.path will have refs to dentry and mnt */
4563 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4564 +       vxdprintk(VXD_CBIT(misc, 2),
4565 +               "do_path_lookup(old): %d", ret);
4566 +       if (ret < 0)
4567 +               goto out_free_path;
4568 +
4569 +       /* dentry/mnt refs handed over to old_path */
4570 +       old_path = &old_nd.path;
4571 +       /* no explicit reference for old_dentry here */
4572 +       old_dentry = old_path->dentry;
4573 +
4574 +       mode = old_dentry->d_inode->i_mode;
4575 +       to = d_path(old_path, path, PATH_MAX-2);
4576 +       pathlen = strlen(to);
4577 +       vxdprintk(VXD_CBIT(misc, 2),
4578 +               "old path " VS_Q("%s") " [%p:" VS_Q("%.*s") ":%d]", to,
4579 +               old_dentry,
4580 +               old_dentry->d_name.len, old_dentry->d_name.name,
4581 +               old_dentry->d_name.len);
4582 +
4583 +       to[pathlen + 1] = 0;
4584 +retry:
4585 +       new_dentry = NULL;
4586 +       to[pathlen] = pad--;
4587 +       ret = -ELOOP;
4588 +       if (pad <= '\240')
4589 +               goto out_rel_old;
4590 +
4591 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy " VS_Q("%s"), to);
4592 +
4593 +       /* dir_nd.path will have refs to dentry and mnt */
4594 +       ret = do_path_lookup(AT_FDCWD, to,
4595 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
4596 +       vxdprintk(VXD_CBIT(misc, 2), "do_path_lookup(new): %d", ret);
4597 +       if (ret < 0)
4598 +               goto retry;
4599 +
4600 +       /* this puppy downs the dir inode mutex if successful.
4601 +          dir_path will hold refs to dentry and mnt and
4602 +          we'll have write access to the mnt */
4603 +       new_dentry = kern_path_create(AT_FDCWD, to, &dir_path, 0);
4604 +       if (!new_dentry || IS_ERR(new_dentry)) {
4605 +               path_put(&dir_nd.path);
4606 +               vxdprintk(VXD_CBIT(misc, 2),
4607 +                       "kern_path_create(new) failed with %ld",
4608 +                       PTR_ERR(new_dentry));
4609 +               goto retry;
4610 +       }
4611 +       vxdprintk(VXD_CBIT(misc, 2),
4612 +               "kern_path_create(new): %p [" VS_Q("%.*s") ":%d]",
4613 +               new_dentry,
4614 +               new_dentry->d_name.len, new_dentry->d_name.name,
4615 +               new_dentry->d_name.len);
4616 +
4617 +       /* take a reference on new_dentry */
4618 +       dget(new_dentry);
4619 +
4620 +       /* dentry/mnt refs handed over to new_path */
4621 +       new_path = &dir_path;
4622 +
4623 +       /* dentry for old/new dir */
4624 +       dir = dir_nd.path.dentry;
4625 +
4626 +       /* give up reference on dir */
4627 +       dput(new_path->dentry);
4628 +
4629 +       /* new_dentry already has a reference */
4630 +       new_path->dentry = new_dentry;
4631 +
4632 +       ret = vfs_create(dir->d_inode, new_dentry, mode, 1);
4633 +       vxdprintk(VXD_CBIT(misc, 2),
4634 +               "vfs_create(new): %d", ret);
4635 +       if (ret == -EEXIST) {
4636 +               path_put(&dir_nd.path);
4637 +               mutex_unlock(&dir->d_inode->i_mutex);
4638 +               mnt_drop_write(new_path->mnt);
4639 +               path_put(new_path);
4640 +               new_dentry = NULL;
4641 +               goto retry;
4642 +       }
4643 +       else if (ret < 0)
4644 +               goto out_unlock_new;
4645 +
4646 +       /* drop out early, ret passes ENOENT */
4647 +       ret = -ENOENT;
4648 +       if ((redo = d_unhashed(old_dentry)))
4649 +               goto out_unlock_new;
4650 +
4651 +       /* doesn't change refs for old_path */
4652 +       old_file = dentry_open(old_path, O_RDONLY, current_cred());
4653 +       vxdprintk(VXD_CBIT(misc, 2),
4654 +               "dentry_open(old): %p", old_file);
4655 +       if (IS_ERR(old_file)) {
4656 +               ret = PTR_ERR(old_file);
4657 +               goto out_unlock_new;
4658 +       }
4659 +
4660 +       /* doesn't change refs for new_path */
4661 +       new_file = dentry_open(new_path, O_WRONLY, current_cred());
4662 +       vxdprintk(VXD_CBIT(misc, 2),
4663 +               "dentry_open(new): %p", new_file);
4664 +       if (IS_ERR(new_file)) {
4665 +               ret = PTR_ERR(new_file);
4666 +               goto out_fput_old;
4667 +       }
4668 +
4669 +       /* unlock the inode mutex from kern_path_create() */
4670 +       mutex_unlock(&dir->d_inode->i_mutex);
4671 +
4672 +       /* drop write access to mnt */
4673 +       mnt_drop_write(new_path->mnt);
4674 +
4675 +       drop = 0;
4676 +
4677 +       size = i_size_read(old_file->f_dentry->d_inode);
4678 +       ret = do_cow_splice(old_file, new_file, size);
4679 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
4680 +       if (ret < 0) {
4681 +               goto out_fput_both;
4682 +       } else if (ret < size) {
4683 +               ret = -ENOSPC;
4684 +               goto out_fput_both;
4685 +       } else {
4686 +               struct inode *old_inode = old_dentry->d_inode;
4687 +               struct inode *new_inode = new_dentry->d_inode;
4688 +               struct iattr attr = {
4689 +                       .ia_uid = old_inode->i_uid,
4690 +                       .ia_gid = old_inode->i_gid,
4691 +                       .ia_valid = ATTR_UID | ATTR_GID
4692 +                       };
4693 +
4694 +               setattr_copy(new_inode, &attr);
4695 +               mark_inode_dirty(new_inode);
4696 +       }
4697 +
4698 +       /* lock rename mutex */
4699 +       mutex_lock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4700 +
4701 +       /* drop out late */
4702 +       ret = -ENOENT;
4703 +       if ((redo = d_unhashed(old_dentry)))
4704 +               goto out_unlock;
4705 +
4706 +       vxdprintk(VXD_CBIT(misc, 2),
4707 +               "vfs_rename: [" VS_Q("%*s") ":%d] -> [" VS_Q("%*s") ":%d]",
4708 +               new_dentry->d_name.len, new_dentry->d_name.name,
4709 +               new_dentry->d_name.len,
4710 +               old_dentry->d_name.len, old_dentry->d_name.name,
4711 +               old_dentry->d_name.len);
4712 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_dentry,
4713 +               old_dentry->d_parent->d_inode, old_dentry);
4714 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
4715 +
4716 +out_unlock:
4717 +       mutex_unlock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4718 +
4719 +out_fput_both:
4720 +       vxdprintk(VXD_CBIT(misc, 3),
4721 +               "fput(new_file=%p[#%ld])", new_file,
4722 +               atomic_long_read(&new_file->f_count));
4723 +       fput(new_file);
4724 +
4725 +out_fput_old:
4726 +       vxdprintk(VXD_CBIT(misc, 3),
4727 +               "fput(old_file=%p[#%ld])", old_file,
4728 +               atomic_long_read(&old_file->f_count));
4729 +       fput(old_file);
4730 +
4731 +out_unlock_new:
4732 +       /* drop references from dir_nd.path */
4733 +       path_put(&dir_nd.path);
4734 +
4735 +       if (drop) {
4736 +               /* unlock the inode mutex from kern_path_create() */
4737 +               mutex_unlock(&dir->d_inode->i_mutex);
4738 +
4739 +               /* drop write access to mnt */
4740 +               mnt_drop_write(new_path->mnt);
4741 +       }
4742 +
4743 +       if (!ret)
4744 +               goto out_redo;
4745 +
4746 +       /* error path cleanup */
4747 +       vfs_unlink(dir->d_inode, new_dentry);
4748 +
4749 +out_redo:
4750 +       if (!redo)
4751 +               goto out_rel_both;
4752 +
4753 +       /* lookup dentry once again
4754 +          old_nd.path will be freed as old_path in out_rel_old */
4755 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4756 +       if (ret)
4757 +               goto out_rel_both;
4758 +
4759 +       /* drop reference on new_dentry */
4760 +       dput(new_dentry);
4761 +       new_dentry = old_path->dentry;
4762 +       dget(new_dentry);
4763 +       vxdprintk(VXD_CBIT(misc, 2),
4764 +               "do_path_lookup(redo): %p [" VS_Q("%.*s") ":%d]",
4765 +               new_dentry,
4766 +               new_dentry->d_name.len, new_dentry->d_name.name,
4767 +               new_dentry->d_name.len);
4768 +
4769 +out_rel_both:
4770 +       if (new_path)
4771 +               path_put(new_path);
4772 +out_rel_old:
4773 +       path_put(old_path);
4774 +out_free_path:
4775 +       kfree(path);
4776 +out:
4777 +       if (ret) {
4778 +               dput(new_dentry);
4779 +               new_dentry = ERR_PTR(ret);
4780 +       }
4781 +       vxdprintk(VXD_CBIT(misc, 3),
4782 +               "cow_break_link returning with %p", new_dentry);
4783 +       return new_dentry;
4784 +}
4785 +
4786 +#endif
4787 +
4788 +int    vx_info_mnt_namespace(struct mnt_namespace *ns, char *buffer)
4789 +{
4790 +       struct path path;
4791 +       struct vfsmount *vmnt;
4792 +       char *pstr, *root;
4793 +       int length = 0;
4794 +
4795 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
4796 +       if (!pstr)
4797 +               return 0;
4798 +
4799 +       vmnt = &ns->root->mnt;
4800 +       path.mnt = vmnt;
4801 +       path.dentry = vmnt->mnt_root;
4802 +       root = d_path(&path, pstr, PATH_MAX - 2);
4803 +       length = sprintf(buffer + length,
4804 +               "Namespace:\t%p [#%u]\n"
4805 +               "RootPath:\t%s\n",
4806 +               ns, atomic_read(&ns->count),
4807 +               root);
4808 +       kfree(pstr);
4809 +       return length;
4810 +}
4811 +
4812  /* get the link contents into pagecache */
4813  static char *page_getlink(struct dentry * dentry, struct page **ppage)
4814  {
4815 @@ -4099,3 +4524,4 @@ EXPORT_SYMBOL(vfs_symlink);
4816  EXPORT_SYMBOL(vfs_unlink);
4817  EXPORT_SYMBOL(dentry_unhash);
4818  EXPORT_SYMBOL(generic_readlink);
4819 +EXPORT_SYMBOL(vx_info_mnt_namespace);
4820 diff -NurpP --minimal linux-3.10.9/fs/namespace.c linux-3.10.9-vs2.3.6.6/fs/namespace.c
4821 --- linux-3.10.9/fs/namespace.c 2013-07-14 17:01:28.000000000 +0000
4822 +++ linux-3.10.9-vs2.3.6.6/fs/namespace.c       2013-08-22 23:37:02.000000000 +0000
4823 @@ -23,6 +23,11 @@
4824  #include <linux/uaccess.h>
4825  #include <linux/proc_ns.h>
4826  #include <linux/magic.h>
4827 +#include <linux/vs_base.h>
4828 +#include <linux/vs_context.h>
4829 +#include <linux/vs_tag.h>
4830 +#include <linux/vserver/space.h>
4831 +#include <linux/vserver/global.h>
4832  #include "pnode.h"
4833  #include "internal.h"
4834  
4835 @@ -780,6 +785,10 @@ vfs_kern_mount(struct file_system_type *
4836         if (!type)
4837                 return ERR_PTR(-ENODEV);
4838  
4839 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
4840 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
4841 +               return ERR_PTR(-EPERM);
4842 +
4843         mnt = alloc_vfsmnt(name);
4844         if (!mnt)
4845                 return ERR_PTR(-ENOMEM);
4846 @@ -836,6 +845,7 @@ static struct mount *clone_mnt(struct mo
4847         mnt->mnt.mnt_root = dget(root);
4848         mnt->mnt_mountpoint = mnt->mnt.mnt_root;
4849         mnt->mnt_parent = mnt;
4850 +               mnt->mnt_tag = old->mnt_tag;
4851         br_write_lock(&vfsmount_lock);
4852         list_add_tail(&mnt->mnt_instance, &sb->s_mounts);
4853         br_write_unlock(&vfsmount_lock);
4854 @@ -1685,6 +1695,7 @@ static int do_change_type(struct path *p
4855                 if (err)
4856                         goto out_unlock;
4857         }
4858 +       // mnt->mnt_flags = mnt_flags;
4859  
4860         br_write_lock(&vfsmount_lock);
4861         for (m = mnt; m; m = (recurse ? next_mnt(m, mnt) : NULL))
4862 @@ -1700,12 +1711,14 @@ static int do_change_type(struct path *p
4863   * do loopback mount.
4864   */
4865  static int do_loopback(struct path *path, const char *old_name,
4866 -                               int recurse)
4867 +       vtag_t tag, unsigned long flags, int mnt_flags)
4868  {
4869         struct path old_path;
4870         struct mount *mnt = NULL, *old, *parent;
4871         struct mountpoint *mp;
4872 +       int recurse = flags & MS_REC;
4873         int err;
4874 +
4875         if (!old_name || !*old_name)
4876                 return -EINVAL;
4877         err = kern_path(old_name, LOOKUP_FOLLOW|LOOKUP_AUTOMOUNT, &old_path);
4878 @@ -1780,7 +1793,7 @@ static int change_mount_flags(struct vfs
4879   * on it - tough luck.
4880   */
4881  static int do_remount(struct path *path, int flags, int mnt_flags,
4882 -                     void *data)
4883 +       void *data, vxid_t xid)
4884  {
4885         int err;
4886         struct super_block *sb = path->mnt->mnt_sb;
4887 @@ -2264,6 +2277,7 @@ long do_mount(const char *dev_name, cons
4888         struct path path;
4889         int retval = 0;
4890         int mnt_flags = 0;
4891 +       vtag_t tag = 0;
4892  
4893         /* Discard magic */
4894         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
4895 @@ -2293,6 +2307,12 @@ long do_mount(const char *dev_name, cons
4896         if (!(flags & MS_NOATIME))
4897                 mnt_flags |= MNT_RELATIME;
4898  
4899 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
4900 +               /* FIXME: bind and re-mounts get the tag flag? */
4901 +               if (flags & (MS_BIND|MS_REMOUNT))
4902 +                       flags |= MS_TAGID;
4903 +       }
4904 +
4905         /* Separate the per-mountpoint flags */
4906         if (flags & MS_NOSUID)
4907                 mnt_flags |= MNT_NOSUID;
4908 @@ -2309,15 +2329,17 @@ long do_mount(const char *dev_name, cons
4909         if (flags & MS_RDONLY)
4910                 mnt_flags |= MNT_READONLY;
4911  
4912 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_DEV_MOUNT))
4913 +               mnt_flags |= MNT_NODEV;
4914         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_BORN |
4915                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
4916                    MS_STRICTATIME);
4917  
4918         if (flags & MS_REMOUNT)
4919                 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
4920 -                                   data_page);
4921 +                                   data_page, tag);
4922         else if (flags & MS_BIND)
4923 -               retval = do_loopback(&path, dev_name, flags & MS_REC);
4924 +               retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
4925         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
4926                 retval = do_change_type(&path, flags);
4927         else if (flags & MS_MOVE)
4928 @@ -2426,6 +2448,7 @@ static struct mnt_namespace *dup_mnt_ns(
4929                 q = next_mnt(q, new);
4930         }
4931         namespace_unlock();
4932 +       atomic_inc(&vs_global_mnt_ns);
4933  
4934         if (rootmnt)
4935                 mntput(rootmnt);
4936 @@ -2624,9 +2647,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
4937         new_mnt = real_mount(new.mnt);
4938         root_mnt = real_mount(root.mnt);
4939         old_mnt = real_mount(old.mnt);
4940 -       if (IS_MNT_SHARED(old_mnt) ||
4941 +       if ((IS_MNT_SHARED(old_mnt) ||
4942                 IS_MNT_SHARED(new_mnt->mnt_parent) ||
4943 -               IS_MNT_SHARED(root_mnt->mnt_parent))
4944 +               IS_MNT_SHARED(root_mnt->mnt_parent)) &&
4945 +               !vx_flags(VXF_STATE_SETUP, 0))
4946                 goto out4;
4947         if (!check_mnt(root_mnt) || !check_mnt(new_mnt))
4948                 goto out4;
4949 @@ -2752,6 +2776,7 @@ void put_mnt_ns(struct mnt_namespace *ns
4950         umount_tree(ns->root, 0);
4951         br_write_unlock(&vfsmount_lock);
4952         namespace_unlock();
4953 +       atomic_dec(&vs_global_mnt_ns);
4954         free_mnt_ns(ns);
4955  }
4956  
4957 diff -NurpP --minimal linux-3.10.9/fs/nfs/client.c linux-3.10.9-vs2.3.6.6/fs/nfs/client.c
4958 --- linux-3.10.9/fs/nfs/client.c        2013-07-14 17:01:28.000000000 +0000
4959 +++ linux-3.10.9-vs2.3.6.6/fs/nfs/client.c      2013-08-22 20:29:59.000000000 +0000
4960 @@ -684,6 +684,9 @@ int nfs_init_server_rpcclient(struct nfs
4961         if (server->flags & NFS_MOUNT_SOFT)
4962                 server->client->cl_softrtry = 1;
4963  
4964 +       server->client->cl_tag = 0;
4965 +       if (server->flags & NFS_MOUNT_TAGGED)
4966 +               server->client->cl_tag = 1;
4967         return 0;
4968  }
4969  EXPORT_SYMBOL_GPL(nfs_init_server_rpcclient);
4970 @@ -863,6 +866,10 @@ static void nfs_server_set_fsinfo(struct
4971                 server->acdirmin = server->acdirmax = 0;
4972         }
4973  
4974 +       /* FIXME: needs fsinfo
4975 +       if (server->flags & NFS_MOUNT_TAGGED)
4976 +               sb->s_flags |= MS_TAGGED;       */
4977 +
4978         server->maxfilesize = fsinfo->maxfilesize;
4979  
4980         server->time_delta = fsinfo->time_delta;
4981 diff -NurpP --minimal linux-3.10.9/fs/nfs/dir.c linux-3.10.9-vs2.3.6.6/fs/nfs/dir.c
4982 --- linux-3.10.9/fs/nfs/dir.c   2013-07-14 17:01:28.000000000 +0000
4983 +++ linux-3.10.9-vs2.3.6.6/fs/nfs/dir.c 2013-08-22 20:29:59.000000000 +0000
4984 @@ -36,6 +36,7 @@
4985  #include <linux/sched.h>
4986  #include <linux/kmemleak.h>
4987  #include <linux/xattr.h>
4988 +#include <linux/vs_tag.h>
4989  
4990  #include "delegation.h"
4991  #include "iostat.h"
4992 @@ -1300,6 +1301,7 @@ struct dentry *nfs_lookup(struct inode *
4993         /* Success: notify readdir to use READDIRPLUS */
4994         nfs_advise_use_readdirplus(dir);
4995  
4996 +       dx_propagate_tag(nd, inode);
4997  no_entry:
4998         res = d_materialise_unique(dentry, inode);
4999         if (res != NULL) {
5000 diff -NurpP --minimal linux-3.10.9/fs/nfs/inode.c linux-3.10.9-vs2.3.6.6/fs/nfs/inode.c
5001 --- linux-3.10.9/fs/nfs/inode.c 2013-07-14 17:01:28.000000000 +0000
5002 +++ linux-3.10.9-vs2.3.6.6/fs/nfs/inode.c       2013-08-22 20:29:59.000000000 +0000
5003 @@ -39,6 +39,7 @@
5004  #include <linux/compat.h>
5005  #include <linux/freezer.h>
5006  #include <linux/crc32.h>
5007 +#include <linux/vs_tag.h>
5008  
5009  #include <asm/uaccess.h>
5010  
5011 @@ -290,6 +291,8 @@ nfs_fhget(struct super_block *sb, struct
5012         if (inode->i_state & I_NEW) {
5013                 struct nfs_inode *nfsi = NFS_I(inode);
5014                 unsigned long now = jiffies;
5015 +               kuid_t kuid;
5016 +               kgid_t kgid;
5017  
5018                 /* We set i_ino for the few things that still rely on it,
5019                  * such as stat(2) */
5020 @@ -334,8 +337,8 @@ nfs_fhget(struct super_block *sb, struct
5021                 inode->i_version = 0;
5022                 inode->i_size = 0;
5023                 clear_nlink(inode);
5024 -               inode->i_uid = make_kuid(&init_user_ns, -2);
5025 -               inode->i_gid = make_kgid(&init_user_ns, -2);
5026 +               kuid = make_kuid(&init_user_ns, -2);
5027 +               kgid = make_kgid(&init_user_ns, -2);
5028                 inode->i_blocks = 0;
5029                 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
5030                 nfsi->write_io = 0;
5031 @@ -369,11 +372,11 @@ nfs_fhget(struct super_block *sb, struct
5032                 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
5033                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5034                 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
5035 -                       inode->i_uid = fattr->uid;
5036 +                       kuid = fattr->uid;
5037                 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
5038                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5039                 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
5040 -                       inode->i_gid = fattr->gid;
5041 +                       kgid = fattr->gid;
5042                 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
5043                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5044                 if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED)
5045 @@ -384,6 +387,11 @@ nfs_fhget(struct super_block *sb, struct
5046                          */
5047                         inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
5048                 }
5049 +               inode->i_uid = INOTAG_KUID(DX_TAG(inode), kuid, kgid);
5050 +               inode->i_gid = INOTAG_KGID(DX_TAG(inode), kuid, kgid);
5051 +               inode->i_tag = INOTAG_KTAG(DX_TAG(inode), kuid, kgid, GLOBAL_ROOT_TAG);
5052 +                               /* maybe fattr->xid someday */
5053 +
5054                 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
5055                 nfsi->attrtimeo_timestamp = now;
5056                 nfsi->access_cache = RB_ROOT;
5057 @@ -505,6 +513,8 @@ void nfs_setattr_update_inode(struct ino
5058                         inode->i_uid = attr->ia_uid;
5059                 if ((attr->ia_valid & ATTR_GID) != 0)
5060                         inode->i_gid = attr->ia_gid;
5061 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5062 +                       inode->i_tag = attr->ia_tag;
5063                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5064                 spin_unlock(&inode->i_lock);
5065         }
5066 @@ -982,7 +992,9 @@ static int nfs_check_inode_attributes(st
5067         struct nfs_inode *nfsi = NFS_I(inode);
5068         loff_t cur_size, new_isize;
5069         unsigned long invalid = 0;
5070 -
5071 +       kuid_t kuid;
5072 +       kgid_t kgid;
5073 +       ktag_t ktag;
5074  
5075         if (nfs_have_delegated_attributes(inode))
5076                 return 0;
5077 @@ -1007,13 +1019,18 @@ static int nfs_check_inode_attributes(st
5078                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5079         }
5080  
5081 +       kuid = INOTAG_KUID(DX_TAG(inode), fattr->uid, fattr->gid);
5082 +       kgid = INOTAG_KGID(DX_TAG(inode), fattr->uid, fattr->gid);
5083 +       ktag = INOTAG_KTAG(DX_TAG(inode), fattr->uid, fattr->gid, GLOBAL_ROOT_TAG);
5084 +
5085         /* Have any file permissions changed? */
5086         if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
5087                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5088 -       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && !uid_eq(inode->i_uid, fattr->uid))
5089 +       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && !uid_eq(inode->i_uid, kuid))
5090                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5091 -       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && !gid_eq(inode->i_gid, fattr->gid))
5092 +       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && !gid_eq(inode->i_gid, kgid))
5093                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5094 +               /* maybe check for tag too? */
5095  
5096         /* Has the link count changed? */
5097         if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
5098 @@ -1319,6 +1336,9 @@ static int nfs_update_inode(struct inode
5099         unsigned long invalid = 0;
5100         unsigned long now = jiffies;
5101         unsigned long save_cache_validity;
5102 +       kuid_t kuid;
5103 +       kgid_t kgid;
5104 +       ktag_t ktag;
5105  
5106         dfprintk(VFS, "NFS: %s(%s/%ld fh_crc=0x%08x ct=%d info=0x%x)\n",
5107                         __func__, inode->i_sb->s_id, inode->i_ino,
5108 @@ -1420,6 +1440,9 @@ static int nfs_update_inode(struct inode
5109                                 | NFS_INO_REVAL_PAGECACHE
5110                                 | NFS_INO_REVAL_FORCED);
5111  
5112 +       kuid = TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag);
5113 +       kgid = TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag);
5114 +       ktag = TAGINO_KTAG(DX_TAG(inode), inode->i_tag);
5115  
5116         if (fattr->valid & NFS_ATTR_FATTR_ATIME)
5117                 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5118 @@ -1462,6 +1485,10 @@ static int nfs_update_inode(struct inode
5119                                 | NFS_INO_INVALID_ACL
5120                                 | NFS_INO_REVAL_FORCED);
5121  
5122 +       inode->i_uid = INOTAG_KUID(DX_TAG(inode), kuid, kgid);
5123 +       inode->i_gid = INOTAG_KGID(DX_TAG(inode), kuid, kgid);
5124 +       inode->i_tag = INOTAG_KTAG(DX_TAG(inode), kuid, kgid, ktag);
5125 +
5126         if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
5127                 if (inode->i_nlink != fattr->nlink) {
5128                         invalid |= NFS_INO_INVALID_ATTR;
5129 diff -NurpP --minimal linux-3.10.9/fs/nfs/nfs3xdr.c linux-3.10.9-vs2.3.6.6/fs/nfs/nfs3xdr.c
5130 --- linux-3.10.9/fs/nfs/nfs3xdr.c       2013-05-31 13:45:24.000000000 +0000
5131 +++ linux-3.10.9-vs2.3.6.6/fs/nfs/nfs3xdr.c     2013-08-22 20:29:59.000000000 +0000
5132 @@ -20,6 +20,7 @@
5133  #include <linux/nfs3.h>
5134  #include <linux/nfs_fs.h>
5135  #include <linux/nfsacl.h>
5136 +#include <linux/vs_tag.h>
5137  #include "internal.h"
5138  
5139  #define NFSDBG_FACILITY                NFSDBG_XDR
5140 @@ -558,7 +559,8 @@ static __be32 *xdr_decode_nfstime3(__be3
5141   *             set_mtime       mtime;
5142   *     };
5143   */
5144 -static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr)
5145 +static void encode_sattr3(struct xdr_stream *xdr,
5146 +       const struct iattr *attr, int tag)
5147  {
5148         u32 nbytes;
5149         __be32 *p;
5150 @@ -590,15 +592,19 @@ static void encode_sattr3(struct xdr_str
5151         } else
5152                 *p++ = xdr_zero;
5153  
5154 -       if (attr->ia_valid & ATTR_UID) {
5155 +       if (attr->ia_valid & ATTR_UID ||
5156 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5157                 *p++ = xdr_one;
5158 -               *p++ = cpu_to_be32(from_kuid(&init_user_ns, attr->ia_uid));
5159 +               *p++ = cpu_to_be32(from_kuid(&init_user_ns,
5160 +                       TAGINO_KUID(tag, attr->ia_uid, attr->ia_tag)));
5161         } else
5162                 *p++ = xdr_zero;
5163  
5164 -       if (attr->ia_valid & ATTR_GID) {
5165 +       if (attr->ia_valid & ATTR_GID ||
5166 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5167                 *p++ = xdr_one;
5168 -               *p++ = cpu_to_be32(from_kgid(&init_user_ns, attr->ia_gid));
5169 +               *p++ = cpu_to_be32(from_kgid(&init_user_ns,
5170 +                       TAGINO_KGID(tag, attr->ia_gid, attr->ia_tag)));
5171         } else
5172                 *p++ = xdr_zero;
5173  
5174 @@ -887,7 +893,7 @@ static void nfs3_xdr_enc_setattr3args(st
5175                                       const struct nfs3_sattrargs *args)
5176  {
5177         encode_nfs_fh3(xdr, args->fh);
5178 -       encode_sattr3(xdr, args->sattr);
5179 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5180         encode_sattrguard3(xdr, args);
5181  }
5182  
5183 @@ -1037,13 +1043,13 @@ static void nfs3_xdr_enc_write3args(stru
5184   *     };
5185   */
5186  static void encode_createhow3(struct xdr_stream *xdr,
5187 -                             const struct nfs3_createargs *args)
5188 +       const struct nfs3_createargs *args, int tag)
5189  {
5190         encode_uint32(xdr, args->createmode);
5191         switch (args->createmode) {
5192         case NFS3_CREATE_UNCHECKED:
5193         case NFS3_CREATE_GUARDED:
5194 -               encode_sattr3(xdr, args->sattr);
5195 +               encode_sattr3(xdr, args->sattr, tag);
5196                 break;
5197         case NFS3_CREATE_EXCLUSIVE:
5198                 encode_createverf3(xdr, args->verifier);
5199 @@ -1058,7 +1064,7 @@ static void nfs3_xdr_enc_create3args(str
5200                                      const struct nfs3_createargs *args)
5201  {
5202         encode_diropargs3(xdr, args->fh, args->name, args->len);
5203 -       encode_createhow3(xdr, args);
5204 +       encode_createhow3(xdr, args, req->rq_task->tk_client->cl_tag);
5205  }
5206  
5207  /*
5208 @@ -1074,7 +1080,7 @@ static void nfs3_xdr_enc_mkdir3args(stru
5209                                     const struct nfs3_mkdirargs *args)
5210  {
5211         encode_diropargs3(xdr, args->fh, args->name, args->len);
5212 -       encode_sattr3(xdr, args->sattr);
5213 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5214  }
5215  
5216  /*
5217 @@ -1091,9 +1097,9 @@ static void nfs3_xdr_enc_mkdir3args(stru
5218   *     };
5219   */
5220  static void encode_symlinkdata3(struct xdr_stream *xdr,
5221 -                               const struct nfs3_symlinkargs *args)
5222 +       const struct nfs3_symlinkargs *args, int tag)
5223  {
5224 -       encode_sattr3(xdr, args->sattr);
5225 +       encode_sattr3(xdr, args->sattr, tag);
5226         encode_nfspath3(xdr, args->pages, args->pathlen);
5227  }
5228  
5229 @@ -1102,7 +1108,7 @@ static void nfs3_xdr_enc_symlink3args(st
5230                                       const struct nfs3_symlinkargs *args)
5231  {
5232         encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen);
5233 -       encode_symlinkdata3(xdr, args);
5234 +       encode_symlinkdata3(xdr, args, req->rq_task->tk_client->cl_tag);
5235  }
5236  
5237  /*
5238 @@ -1130,24 +1136,24 @@ static void nfs3_xdr_enc_symlink3args(st
5239   *     };
5240   */
5241  static void encode_devicedata3(struct xdr_stream *xdr,
5242 -                              const struct nfs3_mknodargs *args)
5243 +       const struct nfs3_mknodargs *args, int tag)
5244  {
5245 -       encode_sattr3(xdr, args->sattr);
5246 +       encode_sattr3(xdr, args->sattr, tag);
5247         encode_specdata3(xdr, args->rdev);
5248  }
5249  
5250  static void encode_mknoddata3(struct xdr_stream *xdr,
5251 -                             const struct nfs3_mknodargs *args)
5252 +       const struct nfs3_mknodargs *args, int tag)
5253  {
5254         encode_ftype3(xdr, args->type);
5255         switch (args->type) {
5256         case NF3CHR:
5257         case NF3BLK:
5258 -               encode_devicedata3(xdr, args);
5259 +               encode_devicedata3(xdr, args, tag);
5260                 break;
5261         case NF3SOCK:
5262         case NF3FIFO:
5263 -               encode_sattr3(xdr, args->sattr);
5264 +               encode_sattr3(xdr, args->sattr, tag);
5265                 break;
5266         case NF3REG:
5267         case NF3DIR:
5268 @@ -1162,7 +1168,7 @@ static void nfs3_xdr_enc_mknod3args(stru
5269                                     const struct nfs3_mknodargs *args)
5270  {
5271         encode_diropargs3(xdr, args->fh, args->name, args->len);
5272 -       encode_mknoddata3(xdr, args);
5273 +       encode_mknoddata3(xdr, args, req->rq_task->tk_client->cl_tag);
5274  }
5275  
5276  /*
5277 diff -NurpP --minimal linux-3.10.9/fs/nfs/super.c linux-3.10.9-vs2.3.6.6/fs/nfs/super.c
5278 --- linux-3.10.9/fs/nfs/super.c 2013-07-14 17:01:28.000000000 +0000
5279 +++ linux-3.10.9-vs2.3.6.6/fs/nfs/super.c       2013-08-22 20:29:59.000000000 +0000
5280 @@ -55,6 +55,7 @@
5281  #include <linux/parser.h>
5282  #include <linux/nsproxy.h>
5283  #include <linux/rcupdate.h>
5284 +#include <linux/vs_tag.h>
5285  
5286  #include <asm/uaccess.h>
5287  
5288 @@ -103,6 +104,7 @@ enum {
5289         Opt_mountport,
5290         Opt_mountvers,
5291         Opt_minorversion,
5292 +       Opt_tagid,
5293  
5294         /* Mount options that take string arguments */
5295         Opt_nfsvers,
5296 @@ -115,6 +117,9 @@ enum {
5297         /* Special mount options */
5298         Opt_userspace, Opt_deprecated, Opt_sloppy,
5299  
5300 +       /* Linux-VServer tagging options */
5301 +       Opt_tag, Opt_notag,
5302 +
5303         Opt_err
5304  };
5305  
5306 @@ -184,6 +189,10 @@ static const match_table_t nfs_mount_opt
5307         { Opt_fscache_uniq, "fsc=%s" },
5308         { Opt_local_lock, "local_lock=%s" },
5309  
5310 +       { Opt_tag, "tag" },
5311 +       { Opt_notag, "notag" },
5312 +       { Opt_tagid, "tagid=%u" },
5313 +
5314         /* The following needs to be listed after all other options */
5315         { Opt_nfsvers, "v%s" },
5316  
5317 @@ -635,6 +644,7 @@ static void nfs_show_mount_options(struc
5318                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
5319                 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
5320                 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
5321 +               { NFS_MOUNT_TAGGED, ",tag", "" },
5322                 { 0, NULL, NULL }
5323         };
5324         const struct proc_nfs_info *nfs_infop;
5325 @@ -1261,6 +1271,14 @@ static int nfs_parse_mount_options(char
5326                 case Opt_nomigration:
5327                         mnt->options &= NFS_OPTION_MIGRATION;
5328                         break;
5329 +#ifndef CONFIG_TAGGING_NONE
5330 +               case Opt_tag:
5331 +                       mnt->flags |= NFS_MOUNT_TAGGED;
5332 +                       break;
5333 +               case Opt_notag:
5334 +                       mnt->flags &= ~NFS_MOUNT_TAGGED;
5335 +                       break;
5336 +#endif
5337  
5338                 /*
5339                  * options that take numeric values
5340 @@ -1347,6 +1365,12 @@ static int nfs_parse_mount_options(char
5341                                 goto out_invalid_value;
5342                         mnt->minorversion = option;
5343                         break;
5344 +#ifdef CONFIG_PROPAGATE
5345 +               case Opt_tagid:
5346 +                       /* use args[0] */
5347 +                       nfs_data.flags |= NFS_MOUNT_TAGGED;
5348 +                       break;
5349 +#endif
5350  
5351                 /*
5352                  * options that take text values
5353 diff -NurpP --minimal linux-3.10.9/fs/nfsd/auth.c linux-3.10.9-vs2.3.6.6/fs/nfsd/auth.c
5354 --- linux-3.10.9/fs/nfsd/auth.c 2013-05-31 13:45:24.000000000 +0000
5355 +++ linux-3.10.9-vs2.3.6.6/fs/nfsd/auth.c       2013-08-22 20:29:59.000000000 +0000
5356 @@ -2,6 +2,7 @@
5357  
5358  #include <linux/sched.h>
5359  #include <linux/user_namespace.h>
5360 +#include <linux/vs_tag.h>
5361  #include "nfsd.h"
5362  #include "auth.h"
5363  
5364 @@ -37,6 +38,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
5365  
5366         new->fsuid = rqstp->rq_cred.cr_uid;
5367         new->fsgid = rqstp->rq_cred.cr_gid;
5368 +       /* FIXME: this desperately needs a tag :)
5369 +       new->xid = (vxid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
5370 +                       */
5371  
5372         rqgi = rqstp->rq_cred.cr_group_info;
5373  
5374 diff -NurpP --minimal linux-3.10.9/fs/nfsd/nfs3xdr.c linux-3.10.9-vs2.3.6.6/fs/nfsd/nfs3xdr.c
5375 --- linux-3.10.9/fs/nfsd/nfs3xdr.c      2013-05-31 13:45:24.000000000 +0000
5376 +++ linux-3.10.9-vs2.3.6.6/fs/nfsd/nfs3xdr.c    2013-08-22 20:29:59.000000000 +0000
5377 @@ -8,6 +8,7 @@
5378  
5379  #include <linux/namei.h>
5380  #include <linux/sunrpc/svc_xprt.h>
5381 +#include <linux/vs_tag.h>
5382  #include "xdr3.h"
5383  #include "auth.h"
5384  #include "netns.h"
5385 @@ -98,6 +99,8 @@ static __be32 *
5386  decode_sattr3(__be32 *p, struct iattr *iap)
5387  {
5388         u32     tmp;
5389 +       kuid_t  kuid = GLOBAL_ROOT_UID;
5390 +       kgid_t  kgid = GLOBAL_ROOT_GID;
5391  
5392         iap->ia_valid = 0;
5393  
5394 @@ -106,15 +109,18 @@ decode_sattr3(__be32 *p, struct iattr *i
5395                 iap->ia_mode = ntohl(*p++);
5396         }
5397         if (*p++) {
5398 -               iap->ia_uid = make_kuid(&init_user_ns, ntohl(*p++));
5399 +               kuid = make_kuid(&init_user_ns, ntohl(*p++));
5400                 if (uid_valid(iap->ia_uid))
5401                         iap->ia_valid |= ATTR_UID;
5402         }
5403         if (*p++) {
5404 -               iap->ia_gid = make_kgid(&init_user_ns, ntohl(*p++));
5405 +               kgid = make_kgid(&init_user_ns, ntohl(*p++));
5406                 if (gid_valid(iap->ia_gid))
5407                         iap->ia_valid |= ATTR_GID;
5408         }
5409 +       iap->ia_uid = INOTAG_KUID(DX_TAG_NFSD, kuid, kgid);
5410 +       iap->ia_gid = INOTAG_KGID(DX_TAG_NFSD, kuid, kgid);
5411 +       iap->ia_tag = INOTAG_KTAG(DX_TAG_NFSD, kuid, kgid, GLOBAL_ROOT_TAG);
5412         if (*p++) {
5413                 u64     newsize;
5414  
5415 @@ -170,8 +176,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
5416         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
5417         *p++ = htonl((u32) stat->mode);
5418         *p++ = htonl((u32) stat->nlink);
5419 -       *p++ = htonl((u32) from_kuid(&init_user_ns, stat->uid));
5420 -       *p++ = htonl((u32) from_kgid(&init_user_ns, stat->gid));
5421 +       *p++ = htonl((u32) from_kuid(&init_user_ns,
5422 +               TAGINO_KUID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5423 +               stat->uid, stat->tag)));
5424 +       *p++ = htonl((u32) from_kgid(&init_user_ns,
5425 +               TAGINO_KGID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5426 +               stat->gid, stat->tag)));
5427         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
5428                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
5429         } else {
5430 diff -NurpP --minimal linux-3.10.9/fs/nfsd/nfs4xdr.c linux-3.10.9-vs2.3.6.6/fs/nfsd/nfs4xdr.c
5431 --- linux-3.10.9/fs/nfsd/nfs4xdr.c      2013-08-22 19:51:35.000000000 +0000
5432 +++ linux-3.10.9-vs2.3.6.6/fs/nfsd/nfs4xdr.c    2013-08-22 20:29:59.000000000 +0000
5433 @@ -46,6 +46,7 @@
5434  #include <linux/utsname.h>
5435  #include <linux/pagemap.h>
5436  #include <linux/sunrpc/svcauth_gss.h>
5437 +#include <linux/vs_tag.h>
5438  
5439  #include "idmap.h"
5440  #include "acl.h"
5441 @@ -2320,14 +2321,18 @@ out_acl:
5442                 WRITE32(stat.nlink);
5443         }
5444         if (bmval1 & FATTR4_WORD1_OWNER) {
5445 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
5446 +               status = nfsd4_encode_user(rqstp,
5447 +                       TAGINO_KUID(DX_TAG(dentry->d_inode),
5448 +                       stat.uid, stat.tag), &p, &buflen);
5449                 if (status == nfserr_resource)
5450                         goto out_resource;
5451                 if (status)
5452                         goto out;
5453         }
5454         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
5455 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
5456 +               status = nfsd4_encode_group(rqstp,
5457 +                       TAGINO_KGID(DX_TAG(dentry->d_inode),
5458 +                       stat.gid, stat.tag), &p, &buflen);
5459                 if (status == nfserr_resource)
5460                         goto out_resource;
5461                 if (status)
5462 diff -NurpP --minimal linux-3.10.9/fs/nfsd/nfsxdr.c linux-3.10.9-vs2.3.6.6/fs/nfsd/nfsxdr.c
5463 --- linux-3.10.9/fs/nfsd/nfsxdr.c       2013-05-31 13:45:24.000000000 +0000
5464 +++ linux-3.10.9-vs2.3.6.6/fs/nfsd/nfsxdr.c     2013-08-22 20:29:59.000000000 +0000
5465 @@ -7,6 +7,7 @@
5466  #include "vfs.h"
5467  #include "xdr.h"
5468  #include "auth.h"
5469 +#include <linux/vs_tag.h>
5470  
5471  #define NFSDDBG_FACILITY               NFSDDBG_XDR
5472  
5473 @@ -89,6 +90,8 @@ static __be32 *
5474  decode_sattr(__be32 *p, struct iattr *iap)
5475  {
5476         u32     tmp, tmp1;
5477 +       kuid_t  kuid = GLOBAL_ROOT_UID;
5478 +       kgid_t  kgid = GLOBAL_ROOT_GID;
5479  
5480         iap->ia_valid = 0;
5481  
5482 @@ -101,15 +104,18 @@ decode_sattr(__be32 *p, struct iattr *ia
5483                 iap->ia_mode = tmp;
5484         }
5485         if ((tmp = ntohl(*p++)) != (u32)-1) {
5486 -               iap->ia_uid = make_kuid(&init_user_ns, tmp);
5487 +               kuid = make_kuid(&init_user_ns, tmp);
5488                 if (uid_valid(iap->ia_uid))
5489                         iap->ia_valid |= ATTR_UID;
5490         }
5491         if ((tmp = ntohl(*p++)) != (u32)-1) {
5492 -               iap->ia_gid = make_kgid(&init_user_ns, tmp);
5493 +               kgid = make_kgid(&init_user_ns, tmp);
5494                 if (gid_valid(iap->ia_gid))
5495                         iap->ia_valid |= ATTR_GID;
5496         }
5497 +       iap->ia_uid = INOTAG_KUID(DX_TAG_NFSD, kuid, kgid);
5498 +       iap->ia_gid = INOTAG_KGID(DX_TAG_NFSD, kuid, kgid);
5499 +       iap->ia_tag = INOTAG_KTAG(DX_TAG_NFSD, kuid, kgid, GLOBAL_ROOT_TAG);
5500         if ((tmp = ntohl(*p++)) != (u32)-1) {
5501                 iap->ia_valid |= ATTR_SIZE;
5502                 iap->ia_size = tmp;
5503 @@ -154,8 +160,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
5504         *p++ = htonl(nfs_ftypes[type >> 12]);
5505         *p++ = htonl((u32) stat->mode);
5506         *p++ = htonl((u32) stat->nlink);
5507 -       *p++ = htonl((u32) from_kuid(&init_user_ns, stat->uid));
5508 -       *p++ = htonl((u32) from_kgid(&init_user_ns, stat->gid));
5509 +       *p++ = htonl((u32) from_kuid(&init_user_ns,
5510 +               TAGINO_KUID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
5511 +       *p++ = htonl((u32) from_kgid(&init_user_ns,
5512 +               TAGINO_KGID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
5513  
5514         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
5515                 *p++ = htonl(NFS_MAXPATHLEN);
5516 diff -NurpP --minimal linux-3.10.9/fs/ocfs2/dlmglue.c linux-3.10.9-vs2.3.6.6/fs/ocfs2/dlmglue.c
5517 --- linux-3.10.9/fs/ocfs2/dlmglue.c     2013-07-14 17:01:29.000000000 +0000
5518 +++ linux-3.10.9-vs2.3.6.6/fs/ocfs2/dlmglue.c   2013-08-22 20:29:59.000000000 +0000
5519 @@ -2047,6 +2047,7 @@ static void __ocfs2_stuff_meta_lvb(struc
5520         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
5521         lvb->lvb_iuid      = cpu_to_be32(i_uid_read(inode));
5522         lvb->lvb_igid      = cpu_to_be32(i_gid_read(inode));
5523 +       lvb->lvb_itag      = cpu_to_be16(i_tag_read(inode));
5524         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
5525         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
5526         lvb->lvb_iatime_packed  =
5527 @@ -2097,6 +2098,7 @@ static void ocfs2_refresh_inode_from_lvb
5528  
5529         i_uid_write(inode, be32_to_cpu(lvb->lvb_iuid));
5530         i_gid_write(inode, be32_to_cpu(lvb->lvb_igid));
5531 +       i_tag_write(inode, be16_to_cpu(lvb->lvb_itag));
5532         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
5533         set_nlink(inode, be16_to_cpu(lvb->lvb_inlink));
5534         ocfs2_unpack_timespec(&inode->i_atime,
5535 diff -NurpP --minimal linux-3.10.9/fs/ocfs2/dlmglue.h linux-3.10.9-vs2.3.6.6/fs/ocfs2/dlmglue.h
5536 --- linux-3.10.9/fs/ocfs2/dlmglue.h     2012-12-11 03:30:57.000000000 +0000
5537 +++ linux-3.10.9-vs2.3.6.6/fs/ocfs2/dlmglue.h   2013-08-22 20:29:59.000000000 +0000
5538 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
5539         __be16       lvb_inlink;
5540         __be32       lvb_iattr;
5541         __be32       lvb_igeneration;
5542 -       __be32       lvb_reserved2;
5543 +       __be16       lvb_itag;
5544 +       __be16       lvb_reserved2;
5545  };
5546  
5547  #define OCFS2_QINFO_LVB_VERSION 1
5548 diff -NurpP --minimal linux-3.10.9/fs/ocfs2/file.c linux-3.10.9-vs2.3.6.6/fs/ocfs2/file.c
5549 --- linux-3.10.9/fs/ocfs2/file.c        2013-07-14 17:01:29.000000000 +0000
5550 +++ linux-3.10.9-vs2.3.6.6/fs/ocfs2/file.c      2013-08-22 20:29:59.000000000 +0000
5551 @@ -1124,7 +1124,7 @@ int ocfs2_setattr(struct dentry *dentry,
5552                 attr->ia_valid &= ~ATTR_SIZE;
5553  
5554  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
5555 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
5556 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
5557         if (!(attr->ia_valid & OCFS2_VALID_ATTRS))
5558                 return 0;
5559  
5560 diff -NurpP --minimal linux-3.10.9/fs/ocfs2/inode.c linux-3.10.9-vs2.3.6.6/fs/ocfs2/inode.c
5561 --- linux-3.10.9/fs/ocfs2/inode.c       2013-05-31 13:45:24.000000000 +0000
5562 +++ linux-3.10.9-vs2.3.6.6/fs/ocfs2/inode.c     2013-08-22 20:29:59.000000000 +0000
5563 @@ -28,6 +28,7 @@
5564  #include <linux/highmem.h>
5565  #include <linux/pagemap.h>
5566  #include <linux/quotaops.h>
5567 +#include <linux/vs_tag.h>
5568  
5569  #include <asm/byteorder.h>
5570  
5571 @@ -78,11 +79,13 @@ void ocfs2_set_inode_flags(struct inode
5572  {
5573         unsigned int flags = OCFS2_I(inode)->ip_attr;
5574  
5575 -       inode->i_flags &= ~(S_IMMUTABLE |
5576 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
5577                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
5578  
5579         if (flags & OCFS2_IMMUTABLE_FL)
5580                 inode->i_flags |= S_IMMUTABLE;
5581 +       if (flags & OCFS2_IXUNLINK_FL)
5582 +               inode->i_flags |= S_IXUNLINK;
5583  
5584         if (flags & OCFS2_SYNC_FL)
5585                 inode->i_flags |= S_SYNC;
5586 @@ -92,25 +95,44 @@ void ocfs2_set_inode_flags(struct inode
5587                 inode->i_flags |= S_NOATIME;
5588         if (flags & OCFS2_DIRSYNC_FL)
5589                 inode->i_flags |= S_DIRSYNC;
5590 +
5591 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
5592 +
5593 +       if (flags & OCFS2_BARRIER_FL)
5594 +               inode->i_vflags |= V_BARRIER;
5595 +       if (flags & OCFS2_COW_FL)
5596 +               inode->i_vflags |= V_COW;
5597  }
5598  
5599  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
5600  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
5601  {
5602         unsigned int flags = oi->vfs_inode.i_flags;
5603 +       unsigned int vflags = oi->vfs_inode.i_vflags;
5604 +
5605 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
5606 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
5607 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
5608 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
5609 +
5610 +       if (flags & S_IMMUTABLE)
5611 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5612 +       if (flags & S_IXUNLINK)
5613 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
5614  
5615 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
5616 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
5617         if (flags & S_SYNC)
5618                 oi->ip_attr |= OCFS2_SYNC_FL;
5619         if (flags & S_APPEND)
5620                 oi->ip_attr |= OCFS2_APPEND_FL;
5621 -       if (flags & S_IMMUTABLE)
5622 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5623         if (flags & S_NOATIME)
5624                 oi->ip_attr |= OCFS2_NOATIME_FL;
5625         if (flags & S_DIRSYNC)
5626                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
5627 +
5628 +       if (vflags & V_BARRIER)
5629 +               oi->ip_attr |= OCFS2_BARRIER_FL;
5630 +       if (vflags & V_COW)
5631 +               oi->ip_attr |= OCFS2_COW_FL;
5632  }
5633  
5634  struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
5635 @@ -241,6 +263,8 @@ void ocfs2_populate_inode(struct inode *
5636         struct super_block *sb;
5637         struct ocfs2_super *osb;
5638         int use_plocks = 1;
5639 +       uid_t uid;
5640 +       gid_t gid;
5641  
5642         sb = inode->i_sb;
5643         osb = OCFS2_SB(sb);
5644 @@ -269,8 +293,12 @@ void ocfs2_populate_inode(struct inode *
5645         inode->i_generation = le32_to_cpu(fe->i_generation);
5646         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
5647         inode->i_mode = le16_to_cpu(fe->i_mode);
5648 -       i_uid_write(inode, le32_to_cpu(fe->i_uid));
5649 -       i_gid_write(inode, le32_to_cpu(fe->i_gid));
5650 +       uid = le32_to_cpu(fe->i_uid);
5651 +       gid = le32_to_cpu(fe->i_gid);
5652 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), uid, gid));
5653 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), uid, gid));
5654 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), uid, gid,
5655 +               /* le16_to_cpu(raw_inode->i_raw_tag) */ 0));
5656  
5657         /* Fast symlinks will have i_size but no allocated clusters. */
5658         if (S_ISLNK(inode->i_mode) && !fe->i_clusters) {
5659 diff -NurpP --minimal linux-3.10.9/fs/ocfs2/inode.h linux-3.10.9-vs2.3.6.6/fs/ocfs2/inode.h
5660 --- linux-3.10.9/fs/ocfs2/inode.h       2013-07-14 17:01:29.000000000 +0000
5661 +++ linux-3.10.9-vs2.3.6.6/fs/ocfs2/inode.h     2013-08-22 20:29:59.000000000 +0000
5662 @@ -152,6 +152,7 @@ struct buffer_head *ocfs2_bread(struct i
5663  
5664  void ocfs2_set_inode_flags(struct inode *inode);
5665  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
5666 +int ocfs2_sync_flags(struct inode *inode, int, int);
5667  
5668  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
5669  {
5670 diff -NurpP --minimal linux-3.10.9/fs/ocfs2/ioctl.c linux-3.10.9-vs2.3.6.6/fs/ocfs2/ioctl.c
5671 --- linux-3.10.9/fs/ocfs2/ioctl.c       2013-07-14 17:01:29.000000000 +0000
5672 +++ linux-3.10.9-vs2.3.6.6/fs/ocfs2/ioctl.c     2013-08-22 20:29:59.000000000 +0000
5673 @@ -76,7 +76,41 @@ static int ocfs2_get_inode_attr(struct i
5674         return status;
5675  }
5676  
5677 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5678 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
5679 +{
5680 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
5681 +       struct buffer_head *bh = NULL;
5682 +       handle_t *handle = NULL;
5683 +       int status;
5684 +
5685 +       status = ocfs2_inode_lock(inode, &bh, 1);
5686 +       if (status < 0) {
5687 +               mlog_errno(status);
5688 +               return status;
5689 +       }
5690 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5691 +       if (IS_ERR(handle)) {
5692 +               status = PTR_ERR(handle);
5693 +               mlog_errno(status);
5694 +               goto bail_unlock;
5695 +       }
5696 +
5697 +       inode->i_flags = flags;
5698 +       inode->i_vflags = vflags;
5699 +       ocfs2_get_inode_flags(OCFS2_I(inode));
5700 +
5701 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
5702 +       if (status < 0)
5703 +               mlog_errno(status);
5704 +
5705 +       ocfs2_commit_trans(osb, handle);
5706 +bail_unlock:
5707 +       ocfs2_inode_unlock(inode, 1);
5708 +       brelse(bh);
5709 +       return status;
5710 +}
5711 +
5712 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5713                                 unsigned mask)
5714  {
5715         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
5716 @@ -116,6 +150,11 @@ static int ocfs2_set_inode_attr(struct i
5717                         goto bail_unlock;
5718         }
5719  
5720 +       if (IS_BARRIER(inode)) {
5721 +               vxwprintk_task(1, "messing with the barrier.");
5722 +               goto bail_unlock;
5723 +       }
5724 +
5725         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5726         if (IS_ERR(handle)) {
5727                 status = PTR_ERR(handle);
5728 @@ -881,6 +920,7 @@ bail:
5729         return status;
5730  }
5731  
5732 +
5733  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
5734  {
5735         struct inode *inode = file_inode(filp);
5736 diff -NurpP --minimal linux-3.10.9/fs/ocfs2/namei.c linux-3.10.9-vs2.3.6.6/fs/ocfs2/namei.c
5737 --- linux-3.10.9/fs/ocfs2/namei.c       2013-07-14 17:01:29.000000000 +0000
5738 +++ linux-3.10.9-vs2.3.6.6/fs/ocfs2/namei.c     2013-08-22 20:29:59.000000000 +0000
5739 @@ -41,6 +41,7 @@
5740  #include <linux/slab.h>
5741  #include <linux/highmem.h>
5742  #include <linux/quotaops.h>
5743 +#include <linux/vs_tag.h>
5744  
5745  #include <cluster/masklog.h>
5746  
5747 @@ -475,6 +476,7 @@ static int __ocfs2_mknod_locked(struct i
5748         struct ocfs2_dinode *fe = NULL;
5749         struct ocfs2_extent_list *fel;
5750         u16 feat;
5751 +       ktag_t ktag;
5752  
5753         *new_fe_bh = NULL;
5754  
5755 @@ -512,8 +514,13 @@ static int __ocfs2_mknod_locked(struct i
5756         fe->i_suballoc_loc = cpu_to_le64(suballoc_loc);
5757         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
5758         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
5759 -       fe->i_uid = cpu_to_le32(i_uid_read(inode));
5760 -       fe->i_gid = cpu_to_le32(i_gid_read(inode));
5761 +
5762 +       ktag = make_ktag(&init_user_ns, dx_current_fstag(osb->sb));
5763 +       fe->i_uid = cpu_to_le32(from_kuid(&init_user_ns,
5764 +               TAGINO_KUID(DX_TAG(inode), inode->i_uid, ktag)));
5765 +       fe->i_gid = cpu_to_le32(from_kgid(&init_user_ns,
5766 +               TAGINO_KGID(DX_TAG(inode), inode->i_gid, ktag)));
5767 +       inode->i_tag = ktag; /* is this correct? */
5768         fe->i_mode = cpu_to_le16(inode->i_mode);
5769         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
5770                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
5771 diff -NurpP --minimal linux-3.10.9/fs/ocfs2/ocfs2.h linux-3.10.9-vs2.3.6.6/fs/ocfs2/ocfs2.h
5772 --- linux-3.10.9/fs/ocfs2/ocfs2.h       2012-12-11 03:30:57.000000000 +0000
5773 +++ linux-3.10.9-vs2.3.6.6/fs/ocfs2/ocfs2.h     2013-08-22 20:29:59.000000000 +0000
5774 @@ -272,6 +272,7 @@ enum ocfs2_mount_options
5775                                                      writes */
5776         OCFS2_MOUNT_HB_NONE = 1 << 13, /* No heartbeat */
5777         OCFS2_MOUNT_HB_GLOBAL = 1 << 14, /* Global heartbeat */
5778 +       OCFS2_MOUNT_TAGGED = 1 << 15, /* use tagging */
5779  };
5780  
5781  #define OCFS2_OSB_SOFT_RO                      0x0001
5782 diff -NurpP --minimal linux-3.10.9/fs/ocfs2/ocfs2_fs.h linux-3.10.9-vs2.3.6.6/fs/ocfs2/ocfs2_fs.h
5783 --- linux-3.10.9/fs/ocfs2/ocfs2_fs.h    2012-12-11 03:30:57.000000000 +0000
5784 +++ linux-3.10.9-vs2.3.6.6/fs/ocfs2/ocfs2_fs.h  2013-08-22 20:29:59.000000000 +0000
5785 @@ -266,6 +266,11 @@
5786  #define OCFS2_TOPDIR_FL                        FS_TOPDIR_FL    /* Top of directory hierarchies*/
5787  #define OCFS2_RESERVED_FL              FS_RESERVED_FL  /* reserved for ext2 lib */
5788  
5789 +#define OCFS2_IXUNLINK_FL              FS_IXUNLINK_FL  /* Immutable invert on unlink */
5790 +
5791 +#define OCFS2_BARRIER_FL               FS_BARRIER_FL   /* Barrier for chroot() */
5792 +#define OCFS2_COW_FL                   FS_COW_FL       /* Copy on Write marker */
5793 +
5794  #define OCFS2_FL_VISIBLE               FS_FL_USER_VISIBLE      /* User visible flags */
5795  #define OCFS2_FL_MODIFIABLE            FS_FL_USER_MODIFIABLE   /* User modifiable flags */
5796  
5797 diff -NurpP --minimal linux-3.10.9/fs/ocfs2/super.c linux-3.10.9-vs2.3.6.6/fs/ocfs2/super.c
5798 --- linux-3.10.9/fs/ocfs2/super.c       2013-05-31 13:45:25.000000000 +0000
5799 +++ linux-3.10.9-vs2.3.6.6/fs/ocfs2/super.c     2013-08-22 20:29:59.000000000 +0000
5800 @@ -185,6 +185,7 @@ enum {
5801         Opt_coherency_full,
5802         Opt_resv_level,
5803         Opt_dir_resv_level,
5804 +       Opt_tag, Opt_notag, Opt_tagid,
5805         Opt_err,
5806  };
5807  
5808 @@ -216,6 +217,9 @@ static const match_table_t tokens = {
5809         {Opt_coherency_full, "coherency=full"},
5810         {Opt_resv_level, "resv_level=%u"},
5811         {Opt_dir_resv_level, "dir_resv_level=%u"},
5812 +       {Opt_tag, "tag"},
5813 +       {Opt_notag, "notag"},
5814 +       {Opt_tagid, "tagid=%u"},
5815         {Opt_err, NULL}
5816  };
5817  
5818 @@ -662,6 +666,13 @@ static int ocfs2_remount(struct super_bl
5819                 goto out;
5820         }
5821  
5822 +       if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
5823 +           (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
5824 +               ret = -EINVAL;
5825 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
5826 +               goto out;
5827 +       }
5828 +
5829         /* We're going to/from readonly mode. */
5830         if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
5831                 /* Disable quota accounting before remounting RO */
5832 @@ -1177,6 +1188,9 @@ static int ocfs2_fill_super(struct super
5833  
5834         ocfs2_complete_mount_recovery(osb);
5835  
5836 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
5837 +               sb->s_flags |= MS_TAGGED;
5838 +
5839         if (ocfs2_mount_local(osb))
5840                 snprintf(nodestr, sizeof(nodestr), "local");
5841         else
5842 @@ -1504,6 +1518,20 @@ static int ocfs2_parse_options(struct su
5843                             option < OCFS2_MAX_RESV_LEVEL)
5844                                 mopt->dir_resv_level = option;
5845                         break;
5846 +#ifndef CONFIG_TAGGING_NONE
5847 +               case Opt_tag:
5848 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5849 +                       break;
5850 +               case Opt_notag:
5851 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
5852 +                       break;
5853 +#endif
5854 +#ifdef CONFIG_PROPAGATE
5855 +               case Opt_tagid:
5856 +                       /* use args[0] */
5857 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5858 +                       break;
5859 +#endif
5860                 default:
5861                         mlog(ML_ERROR,
5862                              "Unrecognized mount option \"%s\" "
5863 diff -NurpP --minimal linux-3.10.9/fs/open.c linux-3.10.9-vs2.3.6.6/fs/open.c
5864 --- linux-3.10.9/fs/open.c      2013-07-14 17:01:29.000000000 +0000
5865 +++ linux-3.10.9-vs2.3.6.6/fs/open.c    2013-08-22 20:29:59.000000000 +0000
5866 @@ -31,6 +31,11 @@
5867  #include <linux/ima.h>
5868  #include <linux/dnotify.h>
5869  #include <linux/compat.h>
5870 +#include <linux/vs_base.h>
5871 +#include <linux/vs_limit.h>
5872 +#include <linux/vs_tag.h>
5873 +#include <linux/vs_cowbl.h>
5874 +#include <linux/vserver/dlimit.h>
5875  
5876  #include "internal.h"
5877  
5878 @@ -67,6 +72,11 @@ long vfs_truncate(struct path *path, lof
5879         struct inode *inode;
5880         long error;
5881  
5882 +#ifdef CONFIG_VSERVER_COWBL
5883 +       error = cow_check_and_break(path);
5884 +       if (error)
5885 +               goto out;
5886 +#endif
5887         inode = path->dentry->d_inode;
5888  
5889         /* For directories it's -EISDIR, for other non-regulars - -EINVAL */
5890 @@ -504,6 +514,13 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
5891         unsigned int lookup_flags = LOOKUP_FOLLOW;
5892  retry:
5893         error = user_path_at(dfd, filename, lookup_flags, &path);
5894 +#ifdef CONFIG_VSERVER_COWBL
5895 +       if (!error) {
5896 +               error = cow_check_and_break(&path);
5897 +               if (error)
5898 +                       path_put(&path);
5899 +       }
5900 +#endif
5901         if (!error) {
5902                 error = chmod_common(&path, mode);
5903                 path_put(&path);
5904 @@ -536,13 +553,15 @@ static int chown_common(struct path *pat
5905                 if (!uid_valid(uid))
5906                         return -EINVAL;
5907                 newattrs.ia_valid |= ATTR_UID;
5908 -               newattrs.ia_uid = uid;
5909 +               newattrs.ia_uid = make_kuid(&init_user_ns,
5910 +                       dx_map_uid(user));
5911         }
5912         if (group != (gid_t) -1) {
5913                 if (!gid_valid(gid))
5914                         return -EINVAL;
5915                 newattrs.ia_valid |= ATTR_GID;
5916 -               newattrs.ia_gid = gid;
5917 +               newattrs.ia_gid = make_kgid(&init_user_ns,
5918 +                       dx_map_gid(group));
5919         }
5920         if (!S_ISDIR(inode->i_mode))
5921                 newattrs.ia_valid |=
5922 @@ -576,6 +595,18 @@ retry:
5923         error = mnt_want_write(path.mnt);
5924         if (error)
5925                 goto out_release;
5926 +#ifdef CONFIG_VSERVER_COWBL
5927 +       error = cow_check_and_break(&path);
5928 +       if (!error)
5929 +#endif
5930 +#ifdef CONFIG_VSERVER_COWBL
5931 +       error = cow_check_and_break(&path);
5932 +       if (!error)
5933 +#endif
5934 +#ifdef CONFIG_VSERVER_COWBL
5935 +       error = cow_check_and_break(&path);
5936 +       if (!error)
5937 +#endif
5938         error = chown_common(&path, user, group);
5939         mnt_drop_write(path.mnt);
5940  out_release:
5941 diff -NurpP --minimal linux-3.10.9/fs/proc/array.c linux-3.10.9-vs2.3.6.6/fs/proc/array.c
5942 --- linux-3.10.9/fs/proc/array.c        2013-05-31 13:45:25.000000000 +0000
5943 +++ linux-3.10.9-vs2.3.6.6/fs/proc/array.c      2013-08-22 20:29:59.000000000 +0000
5944 @@ -82,6 +82,8 @@
5945  #include <linux/ptrace.h>
5946  #include <linux/tracehook.h>
5947  #include <linux/user_namespace.h>
5948 +#include <linux/vs_context.h>
5949 +#include <linux/vs_network.h>
5950  
5951  #include <asm/pgtable.h>
5952  #include <asm/processor.h>
5953 @@ -173,6 +175,9 @@ static inline void task_state(struct seq
5954         rcu_read_lock();
5955         ppid = pid_alive(p) ?
5956                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
5957 +       if (unlikely(vx_current_initpid(p->pid)))
5958 +               ppid = 0;
5959 +
5960         tpid = 0;
5961         if (pid_alive(p)) {
5962                 struct task_struct *tracer = ptrace_parent(p);
5963 @@ -297,7 +302,7 @@ static inline void task_sig(struct seq_f
5964  }
5965  
5966  static void render_cap_t(struct seq_file *m, const char *header,
5967 -                       kernel_cap_t *a)
5968 +                       struct vx_info *vxi, kernel_cap_t *a)
5969  {
5970         unsigned __capi;
5971  
5972 @@ -331,10 +336,11 @@ static inline void task_cap(struct seq_f
5973         NORM_CAPS(cap_effective);
5974         NORM_CAPS(cap_bset);
5975  
5976 -       render_cap_t(m, "CapInh:\t", &cap_inheritable);
5977 -       render_cap_t(m, "CapPrm:\t", &cap_permitted);
5978 -       render_cap_t(m, "CapEff:\t", &cap_effective);
5979 -       render_cap_t(m, "CapBnd:\t", &cap_bset);
5980 +       /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
5981 +       render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
5982 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
5983 +       render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
5984 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
5985  }
5986  
5987  static inline void task_seccomp(struct seq_file *m, struct task_struct *p)
5988 @@ -363,6 +369,42 @@ static void task_cpus_allowed(struct seq
5989         seq_putc(m, '\n');
5990  }
5991  
5992 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
5993 +                       struct pid *pid, struct task_struct *task)
5994 +{
5995 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
5996 +                       "Count:\t%u\n"
5997 +                       "uts:\t%p(%c)\n"
5998 +                       "ipc:\t%p(%c)\n"
5999 +                       "mnt:\t%p(%c)\n"
6000 +                       "pid:\t%p(%c)\n"
6001 +                       "net:\t%p(%c)\n",
6002 +                       task->nsproxy,
6003 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6004 +                       atomic_read(&task->nsproxy->count),
6005 +                       task->nsproxy->uts_ns,
6006 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6007 +                       task->nsproxy->ipc_ns,
6008 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6009 +                       task->nsproxy->mnt_ns,
6010 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6011 +                       task->nsproxy->pid_ns,
6012 +                       (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
6013 +                       task->nsproxy->net_ns,
6014 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6015 +       return 0;
6016 +}
6017 +
6018 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6019 +{
6020 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6021 +               return;
6022 +
6023 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6024 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6025 +}
6026 +
6027 +
6028  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6029                         struct pid *pid, struct task_struct *task)
6030  {
6031 @@ -380,6 +422,7 @@ int proc_pid_status(struct seq_file *m,
6032         task_seccomp(m, task);
6033         task_cpus_allowed(m, task);
6034         cpuset_task_status_allowed(m, task);
6035 +       task_vs_id(m, task);
6036         task_context_switch_counts(m, task);
6037         return 0;
6038  }
6039 @@ -489,6 +532,17 @@ static int do_task_stat(struct seq_file
6040         /* convert nsec -> ticks */
6041         start_time = nsec_to_clock_t(start_time);
6042  
6043 +       /* fixup start time for virt uptime */
6044 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6045 +               unsigned long long bias =
6046 +                       current->vx_info->cvirt.bias_clock;
6047 +
6048 +               if (start_time > bias)
6049 +                       start_time -= bias;
6050 +               else
6051 +                       start_time = 0;
6052 +       }
6053 +
6054         seq_printf(m, "%d (%s) %c", pid_nr_ns(pid, ns), tcomm, state);
6055         seq_put_decimal_ll(m, ' ', ppid);
6056         seq_put_decimal_ll(m, ' ', pgid);
6057 diff -NurpP --minimal linux-3.10.9/fs/proc/base.c linux-3.10.9-vs2.3.6.6/fs/proc/base.c
6058 --- linux-3.10.9/fs/proc/base.c 2013-07-14 17:01:29.000000000 +0000
6059 +++ linux-3.10.9-vs2.3.6.6/fs/proc/base.c       2013-08-22 22:18:21.000000000 +0000
6060 @@ -87,6 +87,8 @@
6061  #include <linux/slab.h>
6062  #include <linux/flex_array.h>
6063  #include <linux/posix-timers.h>
6064 +#include <linux/vs_context.h>
6065 +#include <linux/vs_network.h>
6066  #ifdef CONFIG_HARDWALL
6067  #include <asm/hardwall.h>
6068  #endif
6069 @@ -976,11 +978,15 @@ static ssize_t oom_adj_write(struct file
6070                 oom_adj = (oom_adj * OOM_SCORE_ADJ_MAX) / -OOM_DISABLE;
6071  
6072         if (oom_adj < task->signal->oom_score_adj &&
6073 -           !capable(CAP_SYS_RESOURCE)) {
6074 +           !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
6075                 err = -EACCES;
6076                 goto err_sighand;
6077         }
6078  
6079 +       /* prevent guest processes from circumventing the oom killer */
6080 +       if (vx_current_xid() && (oom_adj == OOM_DISABLE))
6081 +               oom_adj = OOM_ADJUST_MIN;
6082 +
6083         /*
6084          * /proc/pid/oom_adj is provided for legacy purposes, ask users to use
6085          * /proc/pid/oom_score_adj instead.
6086 @@ -1559,6 +1565,8 @@ struct inode *proc_pid_make_inode(struct
6087                 inode->i_gid = cred->egid;
6088                 rcu_read_unlock();
6089         }
6090 +       /* procfs is xid tagged */
6091 +       i_tag_write(inode, (vtag_t)vx_task_xid(task));
6092         security_task_to_inode(task, inode);
6093  
6094  out:
6095 @@ -1604,6 +1612,8 @@ int pid_getattr(struct vfsmount *mnt, st
6096  
6097  /* dentry stuff */
6098  
6099 +static unsigned name_to_int(struct dentry *dentry);
6100 +
6101  /*
6102   *     Exceptional case: normally we are not allowed to unhash a busy
6103   * directory. In this case, however, we can do it - no aliasing problems
6104 @@ -1632,6 +1642,12 @@ int pid_revalidate(struct dentry *dentry
6105         task = get_proc_task(inode);
6106  
6107         if (task) {
6108 +               unsigned pid = name_to_int(dentry);
6109 +
6110 +               if (pid != ~0U && pid != vx_map_pid(task->pid)) {
6111 +                       put_task_struct(task);
6112 +                       goto drop;
6113 +               }
6114                 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
6115                     task_dumpable(task)) {
6116                         rcu_read_lock();
6117 @@ -1648,6 +1664,7 @@ int pid_revalidate(struct dentry *dentry
6118                 put_task_struct(task);
6119                 return 1;
6120         }
6121 +drop:
6122         d_drop(dentry);
6123         return 0;
6124  }
6125 @@ -2196,6 +2213,13 @@ static struct dentry *proc_pident_lookup
6126         if (!task)
6127                 goto out_no_task;
6128  
6129 +       /* TODO: maybe we can come up with a generic approach? */
6130 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
6131 +               (dentry->d_name.len == 5) &&
6132 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
6133 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
6134 +               goto out;
6135 +
6136         /*
6137          * Yes, it does not scale. And it should not. Don't add
6138          * new entries into /proc/<tgid>/ without very good reasons.
6139 @@ -2630,6 +2654,9 @@ static int proc_pid_personality(struct s
6140  static const struct file_operations proc_task_operations;
6141  static const struct inode_operations proc_task_inode_operations;
6142  
6143 +extern int proc_pid_vx_info(struct task_struct *, char *);
6144 +extern int proc_pid_nx_info(struct task_struct *, char *);
6145 +
6146  static const struct pid_entry tgid_base_stuff[] = {
6147         DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
6148         DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
6149 @@ -2696,6 +2723,8 @@ static const struct pid_entry tgid_base_
6150  #ifdef CONFIG_CGROUPS
6151         REG("cgroup",  S_IRUGO, proc_cgroup_operations),
6152  #endif
6153 +       INF("vinfo",      S_IRUGO, proc_pid_vx_info),
6154 +       INF("ninfo",      S_IRUGO, proc_pid_nx_info),
6155         INF("oom_score",  S_IRUGO, proc_oom_score),
6156         REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adj_operations),
6157         REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations),
6158 @@ -2910,7 +2939,7 @@ retry:
6159         iter.task = NULL;
6160         pid = find_ge_pid(iter.tgid, ns);
6161         if (pid) {
6162 -               iter.tgid = pid_nr_ns(pid, ns);
6163 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
6164                 iter.task = pid_task(pid, PIDTYPE_PID);
6165                 /* What we to know is if the pid we have find is the
6166                  * pid of a thread_group_leader.  Testing for task
6167 @@ -2940,7 +2969,7 @@ static int proc_pid_fill_cache(struct fi
6168         struct tgid_iter iter)
6169  {
6170         char name[PROC_NUMBUF];
6171 -       int len = snprintf(name, sizeof(name), "%d", iter.tgid);
6172 +       int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
6173         return proc_fill_cache(filp, dirent, filldir, name, len,
6174                                 proc_pid_instantiate, iter.task, NULL);
6175  }
6176 @@ -2981,6 +3010,8 @@ int proc_pid_readdir(struct file * filp,
6177                         __filldir = fake_filldir;
6178  
6179                 filp->f_pos = iter.tgid + TGID_OFFSET;
6180 +               if (!vx_proc_task_visible(iter.task))
6181 +                       continue;
6182                 if (proc_pid_fill_cache(filp, dirent, __filldir, iter) < 0) {
6183                         put_task_struct(iter.task);
6184                         goto out;
6185 @@ -3073,6 +3104,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),
6188  #endif
6189 +       ONE("nsproxy",  S_IRUGO, proc_pid_nsproxy),
6190  };
6191  
6192  static int proc_tid_base_readdir(struct file * filp,
6193 @@ -3141,6 +3173,8 @@ static struct dentry *proc_task_lookup(s
6194         tid = name_to_int(dentry);
6195         if (tid == ~0U)
6196                 goto out;
6197 +       if (vx_current_initpid(tid))
6198 +               goto out;
6199  
6200         ns = dentry->d_sb->s_fs_info;
6201         rcu_read_lock();
6202 diff -NurpP --minimal linux-3.10.9/fs/proc/generic.c linux-3.10.9-vs2.3.6.6/fs/proc/generic.c
6203 --- linux-3.10.9/fs/proc/generic.c      2013-07-14 17:01:29.000000000 +0000
6204 +++ linux-3.10.9-vs2.3.6.6/fs/proc/generic.c    2013-08-22 20:29:59.000000000 +0000
6205 @@ -23,6 +23,7 @@
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>
6211  
6212  #include "internal.h"
6213 @@ -203,6 +204,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)
6216                         continue;
6217 +               if (!vx_hide_check(0, de->vx_flags))
6218 +                       continue;
6219                 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
6220                         pde_get(de);
6221                         spin_unlock(&proc_subdir_lock);
6222 @@ -211,6 +214,8 @@ struct dentry *proc_lookup_de(struct pro
6223                                 return ERR_PTR(-ENOMEM);
6224                         d_set_d_op(dentry, &proc_dentry_operations);
6225                         d_add(dentry, inode);
6226 +                       /* generic proc entries belong to the host */
6227 +                       i_tag_write(inode, 0);
6228                         return NULL;
6229                 }
6230         }
6231 @@ -279,6 +284,8 @@ int proc_readdir_de(struct proc_dir_entr
6232  
6233                                 /* filldir passes info to user space */
6234                                 pde_get(de);
6235 +                               if (!vx_hide_check(0, de->vx_flags))
6236 +                                       goto skip;
6237                                 spin_unlock(&proc_subdir_lock);
6238                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
6239                                             de->low_ino, de->mode >> 12) < 0) {
6240 @@ -286,6 +293,7 @@ int proc_readdir_de(struct proc_dir_entr
6241                                         goto out;
6242                                 }
6243                                 spin_lock(&proc_subdir_lock);
6244 +                       skip:
6245                                 filp->f_pos++;
6246                                 next = de->next;
6247                                 pde_put(de);
6248 @@ -395,6 +403,7 @@ static struct proc_dir_entry *__proc_cre
6249         ent->namelen = len;
6250         ent->mode = mode;
6251         ent->nlink = nlink;
6252 +       ent->vx_flags = IATTR_PROC_DEFAULT;
6253         atomic_set(&ent->count, 1);
6254         spin_lock_init(&ent->pde_unload_lock);
6255         INIT_LIST_HEAD(&ent->pde_openers);
6256 @@ -418,7 +427,8 @@ struct proc_dir_entry *proc_symlink(cons
6257                                 kfree(ent->data);
6258                                 kfree(ent);
6259                                 ent = NULL;
6260 -                       }
6261 +                       } else
6262 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
6263                 } else {
6264                         kfree(ent);
6265                         ent = NULL;
6266 diff -NurpP --minimal linux-3.10.9/fs/proc/inode.c linux-3.10.9-vs2.3.6.6/fs/proc/inode.c
6267 --- linux-3.10.9/fs/proc/inode.c        2013-07-14 17:01:29.000000000 +0000
6268 +++ linux-3.10.9-vs2.3.6.6/fs/proc/inode.c      2013-08-22 20:29:59.000000000 +0000
6269 @@ -387,6 +387,8 @@ struct inode *proc_get_inode(struct supe
6270                         inode->i_uid = de->uid;
6271                         inode->i_gid = de->gid;
6272                 }
6273 +               if (de->vx_flags)
6274 +                       PROC_I(inode)->vx_flags = de->vx_flags;
6275                 if (de->size)
6276                         inode->i_size = de->size;
6277                 if (de->nlink)
6278 diff -NurpP --minimal linux-3.10.9/fs/proc/internal.h linux-3.10.9-vs2.3.6.6/fs/proc/internal.h
6279 --- linux-3.10.9/fs/proc/internal.h     2013-07-14 17:01:29.000000000 +0000
6280 +++ linux-3.10.9-vs2.3.6.6/fs/proc/internal.h   2013-08-22 21:52:30.000000000 +0000
6281 @@ -14,6 +14,7 @@
6282  #include <linux/spinlock.h>
6283  #include <linux/atomic.h>
6284  #include <linux/binfmts.h>
6285 +#include <linux/vs_pid.h>
6286  
6287  struct ctl_table_header;
6288  struct mempolicy;
6289 @@ -35,6 +36,7 @@ struct proc_dir_entry {
6290         nlink_t nlink;
6291         kuid_t uid;
6292         kgid_t gid;
6293 +       int vx_flags;
6294         loff_t size;
6295         const struct inode_operations *proc_iops;
6296         const struct file_operations *proc_fops;
6297 @@ -50,16 +52,23 @@ struct proc_dir_entry {
6298         char name[];
6299  };
6300  
6301 +struct vx_info;
6302 +struct nx_info;
6303 +
6304  union proc_op {
6305         int (*proc_get_link)(struct dentry *, struct path *);
6306         int (*proc_read)(struct task_struct *task, char *page);
6307         int (*proc_show)(struct seq_file *m,
6308                 struct pid_namespace *ns, struct pid *pid,
6309                 struct task_struct *task);
6310 +       int (*proc_vs_read)(char *page);
6311 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
6312 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
6313  };
6314  
6315  struct proc_inode {
6316         struct pid *pid;
6317 +       int vx_flags;
6318         int fd;
6319         union proc_op op;
6320         struct proc_dir_entry *pde;
6321 @@ -92,11 +101,16 @@ static inline struct pid *proc_pid(struc
6322         return PROC_I(inode)->pid;
6323  }
6324  
6325 -static inline struct task_struct *get_proc_task(struct inode *inode)
6326 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
6327  {
6328         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
6329  }
6330  
6331 +static inline struct task_struct *get_proc_task(struct inode *inode)
6332 +{
6333 +       return vx_get_proc_task(inode, proc_pid(inode));
6334 +}
6335 +
6336  static inline int task_dumpable(struct task_struct *task)
6337  {
6338         int dumpable = 0;
6339 @@ -155,6 +169,8 @@ extern int proc_pid_status(struct seq_fi
6340                            struct pid *, struct task_struct *);
6341  extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
6342                           struct pid *, struct task_struct *);
6343 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6344 +                           struct pid *pid, struct task_struct *task);
6345  
6346  /*
6347   * base.c
6348 diff -NurpP --minimal linux-3.10.9/fs/proc/loadavg.c linux-3.10.9-vs2.3.6.6/fs/proc/loadavg.c
6349 --- linux-3.10.9/fs/proc/loadavg.c      2012-12-11 03:30:57.000000000 +0000
6350 +++ linux-3.10.9-vs2.3.6.6/fs/proc/loadavg.c    2013-08-22 20:30:00.000000000 +0000
6351 @@ -12,15 +12,27 @@
6352  
6353  static int loadavg_proc_show(struct seq_file *m, void *v)
6354  {
6355 +       unsigned long running;
6356 +       unsigned int threads;
6357         unsigned long avnrun[3];
6358  
6359         get_avenrun(avnrun, FIXED_1/200, 0);
6360  
6361 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
6362 +               struct vx_info *vxi = current_vx_info();
6363 +
6364 +               running = atomic_read(&vxi->cvirt.nr_running);
6365 +               threads = atomic_read(&vxi->cvirt.nr_threads);
6366 +       } else {
6367 +               running = nr_running();
6368 +               threads = nr_threads;
6369 +       }
6370 +
6371         seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
6372                 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
6373                 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
6374                 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
6375 -               nr_running(), nr_threads,
6376 +               running, threads,
6377                 task_active_pid_ns(current)->last_pid);
6378         return 0;
6379  }
6380 diff -NurpP --minimal linux-3.10.9/fs/proc/meminfo.c linux-3.10.9-vs2.3.6.6/fs/proc/meminfo.c
6381 --- linux-3.10.9/fs/proc/meminfo.c      2013-07-14 17:01:29.000000000 +0000
6382 +++ linux-3.10.9-vs2.3.6.6/fs/proc/meminfo.c    2013-08-22 20:30:00.000000000 +0000
6383 @@ -40,7 +40,8 @@ static int meminfo_proc_show(struct seq_
6384         allowed = ((totalram_pages - hugetlb_total_pages())
6385                 * sysctl_overcommit_ratio / 100) + total_swap_pages;
6386  
6387 -       cached = global_page_state(NR_FILE_PAGES) -
6388 +       cached = vx_flags(VXF_VIRT_MEM, 0) ?
6389 +               vx_vsi_cached(&i) : global_page_state(NR_FILE_PAGES) -
6390                         total_swapcache_pages() - i.bufferram;
6391         if (cached < 0)
6392                 cached = 0;
6393 diff -NurpP --minimal linux-3.10.9/fs/proc/root.c linux-3.10.9-vs2.3.6.6/fs/proc/root.c
6394 --- linux-3.10.9/fs/proc/root.c 2013-07-14 17:01:29.000000000 +0000
6395 +++ linux-3.10.9-vs2.3.6.6/fs/proc/root.c       2013-08-22 20:30:00.000000000 +0000
6396 @@ -20,9 +20,14 @@
6397  #include <linux/mount.h>
6398  #include <linux/pid_namespace.h>
6399  #include <linux/parser.h>
6400 +#include <linux/vserver/inode.h>
6401  
6402  #include "internal.h"
6403  
6404 +struct proc_dir_entry *proc_virtual;
6405 +
6406 +extern void proc_vx_init(void);
6407 +
6408  static int proc_test_super(struct super_block *sb, void *data)
6409  {
6410         return sb->s_fs_info == data;
6411 @@ -184,6 +189,7 @@ void __init proc_root_init(void)
6412  #endif
6413         proc_mkdir("bus", NULL);
6414         proc_sys_init();
6415 +       proc_vx_init();
6416  }
6417  
6418  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
6419 @@ -250,6 +256,7 @@ struct proc_dir_entry proc_root = {
6420         .proc_iops      = &proc_root_inode_operations, 
6421         .proc_fops      = &proc_root_operations,
6422         .parent         = &proc_root,
6423 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
6424         .name           = "/proc",
6425  };
6426  
6427 diff -NurpP --minimal linux-3.10.9/fs/proc/self.c linux-3.10.9-vs2.3.6.6/fs/proc/self.c
6428 --- linux-3.10.9/fs/proc/self.c 2013-07-14 17:01:29.000000000 +0000
6429 +++ linux-3.10.9-vs2.3.6.6/fs/proc/self.c       2013-08-23 00:07:45.000000000 +0000
6430 @@ -2,6 +2,7 @@
6431  #include <linux/namei.h>
6432  #include <linux/slab.h>
6433  #include <linux/pid_namespace.h>
6434 +#include <linux/vserver/inode.h>
6435  #include "internal.h"
6436  
6437  /*
6438 @@ -62,6 +63,8 @@ int proc_setup_self(struct super_block *
6439         self = d_alloc_name(s->s_root, "self");
6440         if (self) {
6441                 struct inode *inode = new_inode_pseudo(s);
6442 +
6443 +               // self->vx_flags = IATTR_PROC_SYMLINK;
6444                 if (inode) {
6445                         inode->i_ino = self_inum;
6446                         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
6447 diff -NurpP --minimal linux-3.10.9/fs/proc/stat.c linux-3.10.9-vs2.3.6.6/fs/proc/stat.c
6448 --- linux-3.10.9/fs/proc/stat.c 2013-07-14 17:01:29.000000000 +0000
6449 +++ linux-3.10.9-vs2.3.6.6/fs/proc/stat.c       2013-08-22 20:30:00.000000000 +0000
6450 @@ -9,8 +9,10 @@
6451  #include <linux/slab.h>
6452  #include <linux/time.h>
6453  #include <linux/irqnr.h>
6454 +#include <linux/vserver/cvirt.h>
6455  #include <asm/cputime.h>
6456  #include <linux/tick.h>
6457 +#include <linux/cpuset.h>
6458  
6459  #ifndef arch_irq_stat_cpu
6460  #define arch_irq_stat_cpu(cpu) 0
6461 @@ -87,14 +89,26 @@ static int show_stat(struct seq_file *p,
6462         u64 sum_softirq = 0;
6463         unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
6464         struct timespec boottime;
6465 +       cpumask_var_t cpus_allowed;
6466 +       bool virt_cpu = vx_flags(VXF_VIRT_CPU, 0);
6467  
6468         user = nice = system = idle = iowait =
6469                 irq = softirq = steal = 0;
6470         guest = guest_nice = 0;
6471         getboottime(&boottime);
6472 +
6473 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6474 +               vx_vsi_boottime(&boottime);
6475 +
6476 +       if (virt_cpu)
6477 +               cpuset_cpus_allowed(current, cpus_allowed);
6478 +
6479         jif = boottime.tv_sec;
6480  
6481         for_each_possible_cpu(i) {
6482 +               if (virt_cpu && !cpumask_test_cpu(i, cpus_allowed))
6483 +                       continue;
6484 +
6485                 user += kcpustat_cpu(i).cpustat[CPUTIME_USER];
6486                 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
6487                 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
6488 @@ -131,6 +145,9 @@ static int show_stat(struct seq_file *p,
6489         seq_putc(p, '\n');
6490  
6491         for_each_online_cpu(i) {
6492 +               if (virt_cpu && !cpumask_test_cpu(i, cpus_allowed))
6493 +                       continue;
6494 +
6495                 /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
6496                 user = kcpustat_cpu(i).cpustat[CPUTIME_USER];
6497                 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
6498 diff -NurpP --minimal linux-3.10.9/fs/proc/uptime.c linux-3.10.9-vs2.3.6.6/fs/proc/uptime.c
6499 --- linux-3.10.9/fs/proc/uptime.c       2012-12-11 03:30:57.000000000 +0000
6500 +++ linux-3.10.9-vs2.3.6.6/fs/proc/uptime.c     2013-08-22 20:30:00.000000000 +0000
6501 @@ -5,6 +5,7 @@
6502  #include <linux/seq_file.h>
6503  #include <linux/time.h>
6504  #include <linux/kernel_stat.h>
6505 +#include <linux/vserver/cvirt.h>
6506  #include <asm/cputime.h>
6507  
6508  static int uptime_proc_show(struct seq_file *m, void *v)
6509 @@ -25,6 +26,10 @@ static int uptime_proc_show(struct seq_f
6510         nsec = cputime64_to_jiffies64(idletime) * TICK_NSEC;
6511         idle.tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem);
6512         idle.tv_nsec = rem;
6513 +
6514 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6515 +               vx_vsi_uptime(&uptime, &idle);
6516 +
6517         seq_printf(m, "%lu.%02lu %lu.%02lu\n",
6518                         (unsigned long) uptime.tv_sec,
6519                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
6520 diff -NurpP --minimal linux-3.10.9/fs/proc_namespace.c linux-3.10.9-vs2.3.6.6/fs/proc_namespace.c
6521 --- linux-3.10.9/fs/proc_namespace.c    2012-12-11 03:30:57.000000000 +0000
6522 +++ linux-3.10.9-vs2.3.6.6/fs/proc_namespace.c  2013-08-22 20:30:00.000000000 +0000
6523 @@ -44,6 +44,8 @@ static int show_sb_opts(struct seq_file
6524                 { MS_SYNCHRONOUS, ",sync" },
6525                 { MS_DIRSYNC, ",dirsync" },
6526                 { MS_MANDLOCK, ",mand" },
6527 +               { MS_TAGGED, ",tag" },
6528 +               { MS_NOTAGCHECK, ",notagcheck" },
6529                 { 0, NULL }
6530         };
6531         const struct proc_fs_info *fs_infop;
6532 @@ -80,6 +82,40 @@ static inline void mangle(struct seq_fil
6533         seq_escape(m, s, " \t\n\\");
6534  }
6535  
6536 +#ifdef CONFIG_VSERVER_EXTRA_MNT_CHECK
6537 +
6538 +static int mnt_is_reachable(struct vfsmount *vfsmnt)
6539 +{
6540 +       struct path root;
6541 +       struct dentry *point;
6542 +       struct mount *mnt = real_mount(vfsmnt);
6543 +       struct mount *root_mnt;
6544 +       int ret;
6545 +
6546 +       if (mnt == mnt->mnt_ns->root)
6547 +               return 1;
6548 +
6549 +       br_read_lock(&vfsmount_lock);
6550 +       root = current->fs->root;
6551 +       root_mnt = real_mount(root.mnt);
6552 +       point = root.dentry;
6553 +
6554 +       while ((mnt != mnt->mnt_parent) && (mnt != root_mnt)) {
6555 +               point = mnt->mnt_mountpoint;
6556 +               mnt = mnt->mnt_parent;
6557 +       }
6558 +
6559 +       ret = (mnt == root_mnt) && is_subdir(point, root.dentry);
6560 +
6561 +       br_read_unlock(&vfsmount_lock);
6562 +
6563 +       return ret;
6564 +}
6565 +
6566 +#else
6567 +#define        mnt_is_reachable(v)     (1)
6568 +#endif
6569 +
6570  static void show_type(struct seq_file *m, struct super_block *sb)
6571  {
6572         mangle(m, sb->s_type->name);
6573 @@ -96,6 +132,17 @@ static int show_vfsmnt(struct seq_file *
6574         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
6575         struct super_block *sb = mnt_path.dentry->d_sb;
6576  
6577 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6578 +               return SEQ_SKIP;
6579 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6580 +               return SEQ_SKIP;
6581 +
6582 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6583 +               mnt == current->fs->root.mnt) {
6584 +               seq_puts(m, "/dev/root / ");
6585 +               goto type;
6586 +       }
6587 +
6588         if (sb->s_op->show_devname) {
6589                 err = sb->s_op->show_devname(m, mnt_path.dentry);
6590                 if (err)
6591 @@ -106,6 +153,7 @@ static int show_vfsmnt(struct seq_file *
6592         seq_putc(m, ' ');
6593         seq_path(m, &mnt_path, " \t\n\\");
6594         seq_putc(m, ' ');
6595 +type:
6596         show_type(m, sb);
6597         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
6598         err = show_sb_opts(m, sb);
6599 @@ -128,6 +176,11 @@ static int show_mountinfo(struct seq_fil
6600         struct path root = p->root;
6601         int err = 0;
6602  
6603 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6604 +               return SEQ_SKIP;
6605 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6606 +               return SEQ_SKIP;
6607 +
6608         seq_printf(m, "%i %i %u:%u ", r->mnt_id, r->mnt_parent->mnt_id,
6609                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
6610         if (sb->s_op->show_path)
6611 @@ -187,6 +240,17 @@ static int show_vfsstat(struct seq_file
6612         struct super_block *sb = mnt_path.dentry->d_sb;
6613         int err = 0;
6614  
6615 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6616 +               return SEQ_SKIP;
6617 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6618 +               return SEQ_SKIP;
6619 +
6620 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6621 +               mnt == current->fs->root.mnt) {
6622 +               seq_puts(m, "device /dev/root mounted on / ");
6623 +               goto type;
6624 +       }
6625 +
6626         /* device */
6627         if (sb->s_op->show_devname) {
6628                 seq_puts(m, "device ");
6629 @@ -203,7 +267,7 @@ static int show_vfsstat(struct seq_file
6630         seq_puts(m, " mounted on ");
6631         seq_path(m, &mnt_path, " \t\n\\");
6632         seq_putc(m, ' ');
6633 -
6634 +type:
6635         /* file system type */
6636         seq_puts(m, "with fstype ");
6637         show_type(m, sb);
6638 diff -NurpP --minimal linux-3.10.9/fs/quota/dquot.c linux-3.10.9-vs2.3.6.6/fs/quota/dquot.c
6639 --- linux-3.10.9/fs/quota/dquot.c       2013-05-31 13:45:25.000000000 +0000
6640 +++ linux-3.10.9-vs2.3.6.6/fs/quota/dquot.c     2013-08-22 20:30:00.000000000 +0000
6641 @@ -1585,6 +1585,9 @@ int __dquot_alloc_space(struct inode *in
6642         struct dquot **dquots = inode->i_dquot;
6643         int reserve = flags & DQUOT_SPACE_RESERVE;
6644  
6645 +       if ((ret = dl_alloc_space(inode, number)))
6646 +               return ret;
6647 +
6648         /*
6649          * First test before acquiring mutex - solves deadlocks when we
6650          * re-enter the quota code and are already holding the mutex
6651 @@ -1640,6 +1643,9 @@ int dquot_alloc_inode(const struct inode
6652         struct dquot_warn warn[MAXQUOTAS];
6653         struct dquot * const *dquots = inode->i_dquot;
6654  
6655 +       if ((ret = dl_alloc_inode(inode)))
6656 +               return ret;
6657 +
6658         /* First test before acquiring mutex - solves deadlocks when we
6659           * re-enter the quota code and are already holding the mutex */
6660         if (!dquot_active(inode))
6661 @@ -1711,6 +1717,8 @@ void __dquot_free_space(struct inode *in
6662         struct dquot **dquots = inode->i_dquot;
6663         int reserve = flags & DQUOT_SPACE_RESERVE;
6664  
6665 +       dl_free_space(inode, number);
6666 +
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 @@ -1755,6 +1763,8 @@ void dquot_free_inode(const struct inode
6671         struct dquot_warn warn[MAXQUOTAS];
6672         struct dquot * const *dquots = inode->i_dquot;
6673  
6674 +       dl_free_inode(inode);
6675 +
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 diff -NurpP --minimal linux-3.10.9/fs/quota/quota.c linux-3.10.9-vs2.3.6.6/fs/quota/quota.c
6680 --- linux-3.10.9/fs/quota/quota.c       2013-02-19 13:58:49.000000000 +0000
6681 +++ linux-3.10.9-vs2.3.6.6/fs/quota/quota.c     2013-08-22 20:30:00.000000000 +0000
6682 @@ -8,6 +8,7 @@
6683  #include <linux/fs.h>
6684  #include <linux/namei.h>
6685  #include <linux/slab.h>
6686 +#include <linux/vs_context.h>
6687  #include <asm/current.h>
6688  #include <linux/uaccess.h>
6689  #include <linux/kernel.h>
6690 @@ -37,7 +38,7 @@ static int check_quotactl_permission(str
6691                         break;
6692                 /*FALLTHROUGH*/
6693         default:
6694 -               if (!capable(CAP_SYS_ADMIN))
6695 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
6696                         return -EPERM;
6697         }
6698  
6699 @@ -309,6 +310,46 @@ static int do_quotactl(struct super_bloc
6700  
6701  #ifdef CONFIG_BLOCK
6702  
6703 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6704 +
6705 +#include <linux/vroot.h>
6706 +#include <linux/major.h>
6707 +#include <linux/module.h>
6708 +#include <linux/kallsyms.h>
6709 +#include <linux/vserver/debug.h>
6710 +
6711 +static vroot_grb_func *vroot_get_real_bdev = NULL;
6712 +
6713 +static DEFINE_SPINLOCK(vroot_grb_lock);
6714 +
6715 +int register_vroot_grb(vroot_grb_func *func) {
6716 +       int ret = -EBUSY;
6717 +
6718 +       spin_lock(&vroot_grb_lock);
6719 +       if (!vroot_get_real_bdev) {
6720 +               vroot_get_real_bdev = func;
6721 +               ret = 0;
6722 +       }
6723 +       spin_unlock(&vroot_grb_lock);
6724 +       return ret;
6725 +}
6726 +EXPORT_SYMBOL(register_vroot_grb);
6727 +
6728 +int unregister_vroot_grb(vroot_grb_func *func) {
6729 +       int ret = -EINVAL;
6730 +
6731 +       spin_lock(&vroot_grb_lock);
6732 +       if (vroot_get_real_bdev) {
6733 +               vroot_get_real_bdev = NULL;
6734 +               ret = 0;
6735 +       }
6736 +       spin_unlock(&vroot_grb_lock);
6737 +       return ret;
6738 +}
6739 +EXPORT_SYMBOL(unregister_vroot_grb);
6740 +
6741 +#endif
6742 +
6743  /* Return 1 if 'cmd' will block on frozen filesystem */
6744  static int quotactl_cmd_write(int cmd)
6745  {
6746 @@ -343,6 +384,22 @@ static struct super_block *quotactl_bloc
6747         putname(tmp);
6748         if (IS_ERR(bdev))
6749                 return ERR_CAST(bdev);
6750 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6751 +       if (bdev && bdev->bd_inode &&
6752 +               imajor(bdev->bd_inode) == VROOT_MAJOR) {
6753 +               struct block_device *bdnew = (void *)-EINVAL;
6754 +
6755 +               if (vroot_get_real_bdev)
6756 +                       bdnew = vroot_get_real_bdev(bdev);
6757 +               else
6758 +                       vxdprintk(VXD_CBIT(misc, 0),
6759 +                                       "vroot_get_real_bdev not set");
6760 +               bdput(bdev);
6761 +               if (IS_ERR(bdnew))
6762 +                       return ERR_PTR(PTR_ERR(bdnew));
6763 +               bdev = bdnew;
6764 +       }
6765 +#endif
6766         if (quotactl_cmd_write(cmd))
6767                 sb = get_super_thawed(bdev);
6768         else
6769 diff -NurpP --minimal linux-3.10.9/fs/stat.c linux-3.10.9-vs2.3.6.6/fs/stat.c
6770 --- linux-3.10.9/fs/stat.c      2013-05-31 13:45:25.000000000 +0000
6771 +++ linux-3.10.9-vs2.3.6.6/fs/stat.c    2013-08-22 20:30:00.000000000 +0000
6772 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
6773         stat->nlink = inode->i_nlink;
6774         stat->uid = inode->i_uid;
6775         stat->gid = inode->i_gid;
6776 +       stat->tag = inode->i_tag;
6777         stat->rdev = inode->i_rdev;
6778         stat->size = i_size_read(inode);
6779         stat->atime = inode->i_atime;
6780 diff -NurpP --minimal linux-3.10.9/fs/statfs.c linux-3.10.9-vs2.3.6.6/fs/statfs.c
6781 --- linux-3.10.9/fs/statfs.c    2013-02-19 13:58:49.000000000 +0000
6782 +++ linux-3.10.9-vs2.3.6.6/fs/statfs.c  2013-08-22 20:30:00.000000000 +0000
6783 @@ -7,6 +7,8 @@
6784  #include <linux/statfs.h>
6785  #include <linux/security.h>
6786  #include <linux/uaccess.h>
6787 +#include <linux/vs_base.h>
6788 +#include <linux/vs_dlimit.h>
6789  #include "internal.h"
6790  
6791  static int flags_by_mnt(int mnt_flags)
6792 @@ -60,6 +62,8 @@ static int statfs_by_dentry(struct dentr
6793         retval = dentry->d_sb->s_op->statfs(dentry, buf);
6794         if (retval == 0 && buf->f_frsize == 0)
6795                 buf->f_frsize = buf->f_bsize;
6796 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
6797 +               vx_vsi_statfs(dentry->d_sb, buf);
6798         return retval;
6799  }
6800  
6801 diff -NurpP --minimal linux-3.10.9/fs/super.c linux-3.10.9-vs2.3.6.6/fs/super.c
6802 --- linux-3.10.9/fs/super.c     2013-08-22 19:51:35.000000000 +0000
6803 +++ linux-3.10.9-vs2.3.6.6/fs/super.c   2013-08-22 20:30:00.000000000 +0000
6804 @@ -34,6 +34,8 @@
6805  #include <linux/cleancache.h>
6806  #include <linux/fsnotify.h>
6807  #include <linux/lockdep.h>
6808 +#include <linux/magic.h>
6809 +#include <linux/vs_context.h>
6810  #include "internal.h"
6811  
6812  
6813 @@ -1112,6 +1114,13 @@ mount_fs(struct file_system_type *type,
6814         WARN_ON(sb->s_bdi == &default_backing_dev_info);
6815         sb->s_flags |= MS_BORN;
6816  
6817 +       error = -EPERM;
6818 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) &&
6819 +               !sb->s_bdev &&
6820 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
6821 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
6822 +               goto out_sb;
6823 +
6824         error = security_sb_kern_mount(sb, flags, secdata);
6825         if (error)
6826                 goto out_sb;
6827 diff -NurpP --minimal linux-3.10.9/fs/sysfs/mount.c linux-3.10.9-vs2.3.6.6/fs/sysfs/mount.c
6828 --- linux-3.10.9/fs/sysfs/mount.c       2013-05-31 13:45:25.000000000 +0000
6829 +++ linux-3.10.9-vs2.3.6.6/fs/sysfs/mount.c     2013-08-22 20:30:00.000000000 +0000
6830 @@ -48,7 +48,7 @@ static int sysfs_fill_super(struct super
6831  
6832         sb->s_blocksize = PAGE_CACHE_SIZE;
6833         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
6834 -       sb->s_magic = SYSFS_MAGIC;
6835 +       sb->s_magic = SYSFS_SUPER_MAGIC;
6836         sb->s_op = &sysfs_ops;
6837         sb->s_time_gran = 1;
6838  
6839 diff -NurpP --minimal linux-3.10.9/fs/utimes.c linux-3.10.9-vs2.3.6.6/fs/utimes.c
6840 --- linux-3.10.9/fs/utimes.c    2013-02-19 13:58:49.000000000 +0000
6841 +++ linux-3.10.9-vs2.3.6.6/fs/utimes.c  2013-08-22 20:30:00.000000000 +0000
6842 @@ -8,6 +8,8 @@
6843  #include <linux/stat.h>
6844  #include <linux/utime.h>
6845  #include <linux/syscalls.h>
6846 +#include <linux/mount.h>
6847 +#include <linux/vs_cowbl.h>
6848  #include <asm/uaccess.h>
6849  #include <asm/unistd.h>
6850  
6851 @@ -52,12 +54,18 @@ static int utimes_common(struct path *pa
6852  {
6853         int error;
6854         struct iattr newattrs;
6855 -       struct inode *inode = path->dentry->d_inode;
6856 +       struct inode *inode;
6857 +
6858 +       error = cow_check_and_break(path);
6859 +       if (error)
6860 +               goto out;
6861  
6862         error = mnt_want_write(path->mnt);
6863         if (error)
6864                 goto out;
6865  
6866 +       inode = path->dentry->d_inode;
6867 +
6868         if (times && times[0].tv_nsec == UTIME_NOW &&
6869                      times[1].tv_nsec == UTIME_NOW)
6870                 times = NULL;
6871 diff -NurpP --minimal linux-3.10.9/fs/xattr.c linux-3.10.9-vs2.3.6.6/fs/xattr.c
6872 --- linux-3.10.9/fs/xattr.c     2013-02-19 13:58:49.000000000 +0000
6873 +++ linux-3.10.9-vs2.3.6.6/fs/xattr.c   2013-08-22 20:30:00.000000000 +0000
6874 @@ -21,6 +21,7 @@
6875  #include <linux/audit.h>
6876  #include <linux/vmalloc.h>
6877  #include <linux/posix_acl_xattr.h>
6878 +#include <linux/mount.h>
6879  
6880  #include <asm/uaccess.h>
6881  
6882 @@ -52,7 +53,7 @@ xattr_permission(struct inode *inode, co
6883          * The trusted.* namespace can only be accessed by privileged users.
6884          */
6885         if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN)) {
6886 -               if (!capable(CAP_SYS_ADMIN))
6887 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_FS_TRUSTED))
6888                         return (mask & MAY_WRITE) ? -EPERM : -ENODATA;
6889                 return 0;
6890         }
6891 diff -NurpP --minimal linux-3.10.9/fs/xfs/xfs_dinode.h linux-3.10.9-vs2.3.6.6/fs/xfs/xfs_dinode.h
6892 --- linux-3.10.9/fs/xfs/xfs_dinode.h    2013-07-14 17:01:29.000000000 +0000
6893 +++ linux-3.10.9-vs2.3.6.6/fs/xfs/xfs_dinode.h  2013-08-22 20:30:00.000000000 +0000
6894 @@ -51,7 +51,9 @@ typedef struct xfs_dinode {
6895         __be32          di_nlink;       /* number of links to file */
6896         __be16          di_projid_lo;   /* lower part of owner's project id */
6897         __be16          di_projid_hi;   /* higher part owner's project id */
6898 -       __u8            di_pad[6];      /* unused, zeroed space */
6899 +       __u8            di_pad[2];      /* unused, zeroed space */
6900 +       __be16          di_tag;         /* context tagging */
6901 +       __be16          di_vflags;      /* vserver specific flags */
6902         __be16          di_flushiter;   /* incremented on flush */
6903         xfs_timestamp_t di_atime;       /* time last accessed */
6904         xfs_timestamp_t di_mtime;       /* time last modified */
6905 @@ -209,6 +211,8 @@ static inline void xfs_dinode_put_rdev(s
6906  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
6907  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
6908  #define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
6909 +#define XFS_DIFLAG_IXUNLINK_BIT     15 /* Immutable inver on unlink */
6910 +
6911  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
6912  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
6913  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
6914 @@ -224,6 +228,7 @@ static inline void xfs_dinode_put_rdev(s
6915  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
6916  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
6917  #define XFS_DIFLAG_FILESTREAM    (1 << XFS_DIFLAG_FILESTREAM_BIT)
6918 +#define XFS_DIFLAG_IXUNLINK      (1 << XFS_DIFLAG_IXUNLINK_BIT)
6919  
6920  #ifdef CONFIG_XFS_RT
6921  #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
6922 @@ -236,6 +241,10 @@ static inline void xfs_dinode_put_rdev(s
6923          XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
6924          XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
6925          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
6926 -        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
6927 +        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM | \
6928 +        XFS_DIFLAG_IXUNLINK)
6929 +
6930 +#define XFS_DIVFLAG_BARRIER    0x01
6931 +#define XFS_DIVFLAG_COW                0x02
6932  
6933  #endif /* __XFS_DINODE_H__ */
6934 diff -NurpP --minimal linux-3.10.9/fs/xfs/xfs_fs.h linux-3.10.9-vs2.3.6.6/fs/xfs/xfs_fs.h
6935 --- linux-3.10.9/fs/xfs/xfs_fs.h        2013-07-14 17:01:29.000000000 +0000
6936 +++ linux-3.10.9-vs2.3.6.6/fs/xfs/xfs_fs.h      2013-08-22 20:30:00.000000000 +0000
6937 @@ -67,6 +67,9 @@ struct fsxattr {
6938  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
6939  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
6940  #define XFS_XFLAG_FILESTREAM   0x00004000      /* use filestream allocator */
6941 +#define XFS_XFLAG_IXUNLINK     0x00008000      /* immutable invert on unlink */
6942 +#define XFS_XFLAG_BARRIER      0x10000000      /* chroot() barrier */
6943 +#define XFS_XFLAG_COW          0x20000000      /* copy on write mark */
6944  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
6945  
6946  /*
6947 @@ -304,7 +307,8 @@ typedef struct xfs_bstat {
6948  #define        bs_projid       bs_projid_lo    /* (previously just bs_projid)  */
6949         __u16           bs_forkoff;     /* inode fork offset in bytes   */
6950         __u16           bs_projid_hi;   /* higher part of project id    */
6951 -       unsigned char   bs_pad[10];     /* pad space, unused            */
6952 +       unsigned char   bs_pad[8];      /* pad space, unused            */
6953 +       __u16           bs_tag;         /* context tagging              */
6954         __u32           bs_dmevmask;    /* DMIG event mask              */
6955         __u16           bs_dmstate;     /* DMIG state info              */
6956         __u16           bs_aextents;    /* attribute number of extents  */
6957 diff -NurpP --minimal linux-3.10.9/fs/xfs/xfs_ialloc.c linux-3.10.9-vs2.3.6.6/fs/xfs/xfs_ialloc.c
6958 --- linux-3.10.9/fs/xfs/xfs_ialloc.c    2013-07-14 17:01:29.000000000 +0000
6959 +++ linux-3.10.9-vs2.3.6.6/fs/xfs/xfs_ialloc.c  2013-08-22 20:30:00.000000000 +0000
6960 @@ -39,7 +39,6 @@
6961  #include "xfs_cksum.h"
6962  #include "xfs_buf_item.h"
6963  
6964 -
6965  /*
6966   * Allocation group level functions.
6967   */
6968 diff -NurpP --minimal linux-3.10.9/fs/xfs/xfs_inode.c linux-3.10.9-vs2.3.6.6/fs/xfs/xfs_inode.c
6969 --- linux-3.10.9/fs/xfs/xfs_inode.c     2013-07-14 17:01:29.000000000 +0000
6970 +++ linux-3.10.9-vs2.3.6.6/fs/xfs/xfs_inode.c   2013-08-22 21:50:34.000000000 +0000
6971 @@ -16,6 +16,7 @@
6972   * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
6973   */
6974  #include <linux/log2.h>
6975 +#include <linux/vs_tag.h>
6976  
6977  #include "xfs.h"
6978  #include "xfs_fs.h"
6979 @@ -836,15 +837,25 @@ xfs_iformat_btree(
6980  STATIC void
6981  xfs_dinode_from_disk(
6982         xfs_icdinode_t          *to,
6983 -       xfs_dinode_t            *from)
6984 +       xfs_dinode_t            *from,
6985 +       int                     tagged)
6986  {
6987 +       uint32_t uid, gid, tag;
6988 +
6989         to->di_magic = be16_to_cpu(from->di_magic);
6990         to->di_mode = be16_to_cpu(from->di_mode);
6991         to->di_version = from ->di_version;
6992         to->di_format = from->di_format;
6993         to->di_onlink = be16_to_cpu(from->di_onlink);
6994 -       to->di_uid = be32_to_cpu(from->di_uid);
6995 -       to->di_gid = be32_to_cpu(from->di_gid);
6996 +
6997 +       uid = be32_to_cpu(from->di_uid);
6998 +       gid = be32_to_cpu(from->di_gid);
6999 +       tag = be16_to_cpu(from->di_tag);
7000 +
7001 +       to->di_uid = INOTAG_UID(tagged, uid, gid);
7002 +       to->di_gid = INOTAG_GID(tagged, uid, gid);
7003 +       to->di_tag = INOTAG_TAG(tagged, uid, gid, tag);
7004 +
7005         to->di_nlink = be32_to_cpu(from->di_nlink);
7006         to->di_projid_lo = be16_to_cpu(from->di_projid_lo);
7007         to->di_projid_hi = be16_to_cpu(from->di_projid_hi);
7008 @@ -866,6 +877,7 @@ xfs_dinode_from_disk(
7009         to->di_dmevmask = be32_to_cpu(from->di_dmevmask);
7010         to->di_dmstate  = be16_to_cpu(from->di_dmstate);
7011         to->di_flags    = be16_to_cpu(from->di_flags);
7012 +       to->di_vflags   = be16_to_cpu(from->di_vflags);
7013         to->di_gen      = be32_to_cpu(from->di_gen);
7014  
7015         if (to->di_version == 3) {
7016 @@ -883,15 +895,19 @@ xfs_dinode_from_disk(
7017  void
7018  xfs_dinode_to_disk(
7019         xfs_dinode_t            *to,
7020 -       xfs_icdinode_t          *from)
7021 +       xfs_icdinode_t          *from,
7022 +       int                     tagged)
7023  {
7024         to->di_magic = cpu_to_be16(from->di_magic);
7025         to->di_mode = cpu_to_be16(from->di_mode);
7026         to->di_version = from ->di_version;
7027         to->di_format = from->di_format;
7028         to->di_onlink = cpu_to_be16(from->di_onlink);
7029 -       to->di_uid = cpu_to_be32(from->di_uid);
7030 -       to->di_gid = cpu_to_be32(from->di_gid);
7031 +
7032 +       to->di_uid = cpu_to_be32(TAGINO_UID(tagged, from->di_uid, from->di_tag));
7033 +       to->di_gid = cpu_to_be32(TAGINO_GID(tagged, from->di_gid, from->di_tag));
7034 +       to->di_tag = cpu_to_be16(TAGINO_TAG(tagged, from->di_tag));
7035 +
7036         to->di_nlink = cpu_to_be32(from->di_nlink);
7037         to->di_projid_lo = cpu_to_be16(from->di_projid_lo);
7038         to->di_projid_hi = cpu_to_be16(from->di_projid_hi);
7039 @@ -913,6 +929,7 @@ xfs_dinode_to_disk(
7040         to->di_dmevmask = cpu_to_be32(from->di_dmevmask);
7041         to->di_dmstate = cpu_to_be16(from->di_dmstate);
7042         to->di_flags = cpu_to_be16(from->di_flags);
7043 +       to->di_vflags = cpu_to_be16(from->di_vflags);
7044         to->di_gen = cpu_to_be32(from->di_gen);
7045  
7046         if (from->di_version == 3) {
7047 @@ -929,7 +946,8 @@ xfs_dinode_to_disk(
7048  
7049  STATIC uint
7050  _xfs_dic2xflags(
7051 -       __uint16_t              di_flags)
7052 +       __uint16_t              di_flags,
7053 +       __uint16_t              di_vflags)
7054  {
7055         uint                    flags = 0;
7056  
7057 @@ -940,6 +958,8 @@ _xfs_dic2xflags(
7058                         flags |= XFS_XFLAG_PREALLOC;
7059                 if (di_flags & XFS_DIFLAG_IMMUTABLE)
7060                         flags |= XFS_XFLAG_IMMUTABLE;
7061 +               if (di_flags & XFS_DIFLAG_IXUNLINK)
7062 +                       flags |= XFS_XFLAG_IXUNLINK;
7063                 if (di_flags & XFS_DIFLAG_APPEND)
7064                         flags |= XFS_XFLAG_APPEND;
7065                 if (di_flags & XFS_DIFLAG_SYNC)
7066 @@ -964,6 +984,10 @@ _xfs_dic2xflags(
7067                         flags |= XFS_XFLAG_FILESTREAM;
7068         }
7069  
7070 +       if (di_vflags & XFS_DIVFLAG_BARRIER)
7071 +               flags |= FS_BARRIER_FL;
7072 +       if (di_vflags & XFS_DIVFLAG_COW)
7073 +               flags |= FS_COW_FL;
7074         return flags;
7075  }
7076  
7077 @@ -973,7 +997,7 @@ xfs_ip2xflags(
7078  {
7079         xfs_icdinode_t          *dic = &ip->i_d;
7080  
7081 -       return _xfs_dic2xflags(dic->di_flags) |
7082 +       return _xfs_dic2xflags(dic->di_flags, dic->di_vflags) |
7083                                 (XFS_IFORK_Q(ip) ? XFS_XFLAG_HASATTR : 0);
7084  }
7085  
7086 @@ -981,7 +1005,8 @@ uint
7087  xfs_dic2xflags(
7088         xfs_dinode_t            *dip)
7089  {
7090 -       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags)) |
7091 +       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags),
7092 +                               be16_to_cpu(dip->di_vflags)) |
7093                                 (XFS_DFORK_Q(dip) ? XFS_XFLAG_HASATTR : 0);
7094  }
7095  
7096 @@ -1072,7 +1097,8 @@ xfs_iread(
7097          * Otherwise, just get the truly permanent information.
7098          */
7099         if (dip->di_mode) {
7100 -               xfs_dinode_from_disk(&ip->i_d, dip);
7101 +               xfs_dinode_from_disk(&ip->i_d, dip,
7102 +                       mp->m_flags & XFS_MOUNT_TAGGED);
7103                 error = xfs_iformat(ip, dip);
7104                 if (error)  {
7105  #ifdef DEBUG
7106 @@ -1270,6 +1296,7 @@ xfs_ialloc(
7107         ASSERT(ip->i_d.di_nlink == nlink);
7108         ip->i_d.di_uid = current_fsuid();
7109         ip->i_d.di_gid = current_fsgid();
7110 +       ip->i_d.di_tag = current_fstag(&ip->i_vnode);
7111         xfs_set_projid(ip, prid);
7112         memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
7113  
7114 @@ -1329,6 +1356,7 @@ xfs_ialloc(
7115         ip->i_d.di_dmevmask = 0;
7116         ip->i_d.di_dmstate = 0;
7117         ip->i_d.di_flags = 0;
7118 +       ip->i_d.di_vflags = 0;
7119  
7120         if (ip->i_d.di_version == 3) {
7121                 ASSERT(ip->i_d.di_ino == ino);
7122 @@ -2052,6 +2080,7 @@ xfs_ifree(
7123         }
7124         ip->i_d.di_mode = 0;            /* mark incore inode as free */
7125         ip->i_d.di_flags = 0;
7126 +       ip->i_d.di_vflags = 0;
7127         ip->i_d.di_dmevmask = 0;
7128         ip->i_d.di_forkoff = 0;         /* mark the attr fork not in use */
7129         ip->i_d.di_format = XFS_DINODE_FMT_EXTENTS;
7130 @@ -2219,7 +2248,6 @@ xfs_iroot_realloc(
7131         return;
7132  }
7133  
7134 -
7135  /*
7136   * This is called when the amount of space needed for if_data
7137   * is increased or decreased.  The change in size is indicated by
7138 @@ -2899,7 +2927,8 @@ xfs_iflush_int(
7139          * because if the inode is dirty at all the core must
7140          * be.
7141          */
7142 -       xfs_dinode_to_disk(dip, &ip->i_d);
7143 +       xfs_dinode_to_disk(dip, &ip->i_d,
7144 +               mp->m_flags & XFS_MOUNT_TAGGED);
7145  
7146         /* Wrap, we never let the log put out DI_MAX_FLUSH */
7147         if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
7148 diff -NurpP --minimal linux-3.10.9/fs/xfs/xfs_inode.h linux-3.10.9-vs2.3.6.6/fs/xfs/xfs_inode.h
7149 --- linux-3.10.9/fs/xfs/xfs_inode.h     2013-07-14 17:01:30.000000000 +0000
7150 +++ linux-3.10.9-vs2.3.6.6/fs/xfs/xfs_inode.h   2013-08-22 20:30:00.000000000 +0000
7151 @@ -134,7 +134,9 @@ typedef struct xfs_icdinode {
7152         __uint32_t      di_nlink;       /* number of links to file */
7153         __uint16_t      di_projid_lo;   /* lower part of owner's project id */
7154         __uint16_t      di_projid_hi;   /* higher part of owner's project id */
7155 -       __uint8_t       di_pad[6];      /* unused, zeroed space */
7156 +       __uint8_t       di_pad[2];      /* unused, zeroed space */
7157 +       __uint16_t      di_tag;         /* context tagging */
7158 +       __uint16_t      di_vflags;      /* vserver specific flags */
7159         __uint16_t      di_flushiter;   /* incremented on flush */
7160         xfs_ictimestamp_t di_atime;     /* time last accessed */
7161         xfs_ictimestamp_t di_mtime;     /* time last modified */
7162 @@ -583,7 +585,7 @@ int         xfs_iread(struct xfs_mount *, struc
7163                           struct xfs_inode *, uint);
7164  void           xfs_dinode_calc_crc(struct xfs_mount *, struct xfs_dinode *);
7165  void           xfs_dinode_to_disk(struct xfs_dinode *,
7166 -                                  struct xfs_icdinode *);
7167 +                                  struct xfs_icdinode *, int);
7168  void           xfs_idestroy_fork(struct xfs_inode *, int);
7169  void           xfs_idata_realloc(struct xfs_inode *, int, int);
7170  void           xfs_iroot_realloc(struct xfs_inode *, int, int);
7171 diff -NurpP --minimal linux-3.10.9/fs/xfs/xfs_ioctl.c linux-3.10.9-vs2.3.6.6/fs/xfs/xfs_ioctl.c
7172 --- linux-3.10.9/fs/xfs/xfs_ioctl.c     2013-07-14 17:01:30.000000000 +0000
7173 +++ linux-3.10.9-vs2.3.6.6/fs/xfs/xfs_ioctl.c   2013-08-22 20:30:00.000000000 +0000
7174 @@ -26,7 +26,7 @@
7175  #include "xfs_bmap_btree.h"
7176  #include "xfs_dinode.h"
7177  #include "xfs_inode.h"
7178 -#include "xfs_ioctl.h"
7179 +// #include "xfs_ioctl.h"
7180  #include "xfs_rtalloc.h"
7181  #include "xfs_itable.h"
7182  #include "xfs_error.h"
7183 @@ -769,6 +769,10 @@ xfs_merge_ioc_xflags(
7184                 xflags |= XFS_XFLAG_IMMUTABLE;
7185         else
7186                 xflags &= ~XFS_XFLAG_IMMUTABLE;
7187 +       if (flags & FS_IXUNLINK_FL)
7188 +               xflags |= XFS_XFLAG_IXUNLINK;
7189 +       else
7190 +               xflags &= ~XFS_XFLAG_IXUNLINK;
7191         if (flags & FS_APPEND_FL)
7192                 xflags |= XFS_XFLAG_APPEND;
7193         else
7194 @@ -797,6 +801,8 @@ xfs_di2lxflags(
7195  
7196         if (di_flags & XFS_DIFLAG_IMMUTABLE)
7197                 flags |= FS_IMMUTABLE_FL;
7198 +       if (di_flags & XFS_DIFLAG_IXUNLINK)
7199 +               flags |= FS_IXUNLINK_FL;
7200         if (di_flags & XFS_DIFLAG_APPEND)
7201                 flags |= FS_APPEND_FL;
7202         if (di_flags & XFS_DIFLAG_SYNC)
7203 @@ -857,6 +863,8 @@ xfs_set_diflags(
7204         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
7205         if (xflags & XFS_XFLAG_IMMUTABLE)
7206                 di_flags |= XFS_DIFLAG_IMMUTABLE;
7207 +       if (xflags & XFS_XFLAG_IXUNLINK)
7208 +               di_flags |= XFS_DIFLAG_IXUNLINK;
7209         if (xflags & XFS_XFLAG_APPEND)
7210                 di_flags |= XFS_DIFLAG_APPEND;
7211         if (xflags & XFS_XFLAG_SYNC)
7212 @@ -899,6 +907,10 @@ xfs_diflags_to_linux(
7213                 inode->i_flags |= S_IMMUTABLE;
7214         else
7215                 inode->i_flags &= ~S_IMMUTABLE;
7216 +       if (xflags & XFS_XFLAG_IXUNLINK)
7217 +               inode->i_flags |= S_IXUNLINK;
7218 +       else
7219 +               inode->i_flags &= ~S_IXUNLINK;
7220         if (xflags & XFS_XFLAG_APPEND)
7221                 inode->i_flags |= S_APPEND;
7222         else
7223 @@ -1403,10 +1415,18 @@ xfs_file_ioctl(
7224         case XFS_IOC_FSGETXATTRA:
7225                 return xfs_ioc_fsgetxattr(ip, 1, arg);
7226         case XFS_IOC_FSSETXATTR:
7227 +               if (IS_BARRIER(inode)) {
7228 +                       vxwprintk_task(1, "messing with the barrier.");
7229 +                       return -XFS_ERROR(EACCES);
7230 +               }
7231                 return xfs_ioc_fssetxattr(ip, filp, arg);
7232         case XFS_IOC_GETXFLAGS:
7233                 return xfs_ioc_getxflags(ip, arg);
7234         case XFS_IOC_SETXFLAGS:
7235 +               if (IS_BARRIER(inode)) {
7236 +                       vxwprintk_task(1, "messing with the barrier.");
7237 +                       return -XFS_ERROR(EACCES);
7238 +               }
7239                 return xfs_ioc_setxflags(ip, filp, arg);
7240  
7241         case XFS_IOC_FSSETDM: {
7242 diff -NurpP --minimal linux-3.10.9/fs/xfs/xfs_ioctl.h linux-3.10.9-vs2.3.6.6/fs/xfs/xfs_ioctl.h
7243 --- linux-3.10.9/fs/xfs/xfs_ioctl.h     2012-12-11 03:30:57.000000000 +0000
7244 +++ linux-3.10.9-vs2.3.6.6/fs/xfs/xfs_ioctl.h   2013-08-22 20:30:00.000000000 +0000
7245 @@ -70,6 +70,12 @@ xfs_handle_to_dentry(
7246         void __user             *uhandle,
7247         u32                     hlen);
7248  
7249 +extern int
7250 +xfs_sync_flags(
7251 +       struct inode            *inode,
7252 +       int                     flags,
7253 +       int                     vflags);
7254 +
7255  extern long
7256  xfs_file_ioctl(
7257         struct file             *filp,
7258 diff -NurpP --minimal linux-3.10.9/fs/xfs/xfs_iops.c linux-3.10.9-vs2.3.6.6/fs/xfs/xfs_iops.c
7259 --- linux-3.10.9/fs/xfs/xfs_iops.c      2013-07-14 17:01:30.000000000 +0000
7260 +++ linux-3.10.9-vs2.3.6.6/fs/xfs/xfs_iops.c    2013-08-22 20:30:00.000000000 +0000
7261 @@ -28,6 +28,7 @@
7262  #include "xfs_bmap_btree.h"
7263  #include "xfs_dinode.h"
7264  #include "xfs_inode.h"
7265 +#include "xfs_ioctl.h"
7266  #include "xfs_bmap.h"
7267  #include "xfs_rtalloc.h"
7268  #include "xfs_error.h"
7269 @@ -47,6 +48,7 @@
7270  #include <linux/security.h>
7271  #include <linux/fiemap.h>
7272  #include <linux/slab.h>
7273 +#include <linux/vs_tag.h>
7274  
7275  static int
7276  xfs_initxattrs(
7277 @@ -422,6 +424,7 @@ xfs_vn_getattr(
7278         stat->nlink = ip->i_d.di_nlink;
7279         stat->uid = ip->i_d.di_uid;
7280         stat->gid = ip->i_d.di_gid;
7281 +       stat->tag = ip->i_d.di_tag;
7282         stat->ino = ip->i_ino;
7283         stat->atime = inode->i_atime;
7284         stat->mtime = inode->i_mtime;
7285 @@ -1054,6 +1057,7 @@ static const struct inode_operations xfs
7286         .listxattr              = xfs_vn_listxattr,
7287         .fiemap                 = xfs_vn_fiemap,
7288         .update_time            = xfs_vn_update_time,
7289 +       .sync_flags             = xfs_sync_flags,
7290  };
7291  
7292  static const struct inode_operations xfs_dir_inode_operations = {
7293 @@ -1080,6 +1084,7 @@ static const struct inode_operations xfs
7294         .removexattr            = generic_removexattr,
7295         .listxattr              = xfs_vn_listxattr,
7296         .update_time            = xfs_vn_update_time,
7297 +       .sync_flags             = xfs_sync_flags,
7298  };
7299  
7300  static const struct inode_operations xfs_dir_ci_inode_operations = {
7301 @@ -1131,6 +1136,10 @@ xfs_diflags_to_iflags(
7302                 inode->i_flags |= S_IMMUTABLE;
7303         else
7304                 inode->i_flags &= ~S_IMMUTABLE;
7305 +       if (ip->i_d.di_flags & XFS_DIFLAG_IXUNLINK)
7306 +               inode->i_flags |= S_IXUNLINK;
7307 +       else
7308 +               inode->i_flags &= ~S_IXUNLINK;
7309         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
7310                 inode->i_flags |= S_APPEND;
7311         else
7312 @@ -1143,6 +1152,15 @@ xfs_diflags_to_iflags(
7313                 inode->i_flags |= S_NOATIME;
7314         else
7315                 inode->i_flags &= ~S_NOATIME;
7316 +
7317 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_BARRIER)
7318 +               inode->i_vflags |= V_BARRIER;
7319 +       else
7320 +               inode->i_vflags &= ~V_BARRIER;
7321 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_COW)
7322 +               inode->i_vflags |= V_COW;
7323 +       else
7324 +               inode->i_vflags &= ~V_COW;
7325  }
7326  
7327  /*
7328 @@ -1174,6 +1192,7 @@ xfs_setup_inode(
7329         set_nlink(inode, ip->i_d.di_nlink);
7330         inode->i_uid    = ip->i_d.di_uid;
7331         inode->i_gid    = ip->i_d.di_gid;
7332 +       inode->i_tag    = ip->i_d.di_tag;
7333  
7334         switch (inode->i_mode & S_IFMT) {
7335         case S_IFBLK:
7336 diff -NurpP --minimal linux-3.10.9/fs/xfs/xfs_itable.c linux-3.10.9-vs2.3.6.6/fs/xfs/xfs_itable.c
7337 --- linux-3.10.9/fs/xfs/xfs_itable.c    2013-02-19 13:58:49.000000000 +0000
7338 +++ linux-3.10.9-vs2.3.6.6/fs/xfs/xfs_itable.c  2013-08-22 20:30:00.000000000 +0000
7339 @@ -97,6 +97,7 @@ xfs_bulkstat_one_int(
7340         buf->bs_mode = dic->di_mode;
7341         buf->bs_uid = dic->di_uid;
7342         buf->bs_gid = dic->di_gid;
7343 +       buf->bs_tag = dic->di_tag;
7344         buf->bs_size = dic->di_size;
7345         buf->bs_atime.tv_sec = dic->di_atime.t_sec;
7346         buf->bs_atime.tv_nsec = dic->di_atime.t_nsec;
7347 diff -NurpP --minimal linux-3.10.9/fs/xfs/xfs_linux.h linux-3.10.9-vs2.3.6.6/fs/xfs/xfs_linux.h
7348 --- linux-3.10.9/fs/xfs/xfs_linux.h     2013-07-14 17:01:30.000000000 +0000
7349 +++ linux-3.10.9-vs2.3.6.6/fs/xfs/xfs_linux.h   2013-08-22 20:30:00.000000000 +0000
7350 @@ -124,6 +124,7 @@
7351  
7352  #define current_cpu()          (raw_smp_processor_id())
7353  #define current_pid()          (current->pid)
7354 +#define current_fstag(vp)      (dx_current_fstag((vp)->i_sb))
7355  #define current_test_flags(f)  (current->flags & (f))
7356  #define current_set_flags_nested(sp, f)                \
7357                 (*(sp) = current->flags, current->flags |= (f))
7358 diff -NurpP --minimal linux-3.10.9/fs/xfs/xfs_log_recover.c linux-3.10.9-vs2.3.6.6/fs/xfs/xfs_log_recover.c
7359 --- linux-3.10.9/fs/xfs/xfs_log_recover.c       2013-07-14 17:01:31.000000000 +0000
7360 +++ linux-3.10.9-vs2.3.6.6/fs/xfs/xfs_log_recover.c     2013-08-22 21:48:01.000000000 +0000
7361 @@ -2662,7 +2662,7 @@ xlog_recover_inode_pass2(
7362         }
7363  
7364         /* The core is in in-core format */
7365 -       xfs_dinode_to_disk(dip, dicp);
7366 +       xfs_dinode_to_disk(dip, dicp, mp->m_flags & XFS_MOUNT_TAGGED);
7367  
7368         /* the rest is in on-disk format */
7369         if (item->ri_buf[1].i_len > isize) {
7370 diff -NurpP --minimal linux-3.10.9/fs/xfs/xfs_mount.h linux-3.10.9-vs2.3.6.6/fs/xfs/xfs_mount.h
7371 --- linux-3.10.9/fs/xfs/xfs_mount.h     2013-07-14 17:01:31.000000000 +0000
7372 +++ linux-3.10.9-vs2.3.6.6/fs/xfs/xfs_mount.h   2013-08-22 20:30:00.000000000 +0000
7373 @@ -253,6 +253,7 @@ typedef struct xfs_mount {
7374                                                    allocator */
7375  #define XFS_MOUNT_NOATTR2      (1ULL << 25)    /* disable use of attr2 format */
7376  
7377 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
7378  
7379  /*
7380   * Default minimum read and write sizes.
7381 diff -NurpP --minimal linux-3.10.9/fs/xfs/xfs_super.c linux-3.10.9-vs2.3.6.6/fs/xfs/xfs_super.c
7382 --- linux-3.10.9/fs/xfs/xfs_super.c     2013-07-14 17:01:31.000000000 +0000
7383 +++ linux-3.10.9-vs2.3.6.6/fs/xfs/xfs_super.c   2013-08-22 20:30:00.000000000 +0000
7384 @@ -114,6 +114,9 @@ mempool_t *xfs_ioend_pool;
7385  #define MNTOPT_NODELAYLOG  "nodelaylog"        /* Delayed logging disabled */
7386  #define MNTOPT_DISCARD    "discard"    /* Discard unused blocks */
7387  #define MNTOPT_NODISCARD   "nodiscard" /* Do not discard unused blocks */
7388 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
7389 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
7390 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
7391  
7392  /*
7393   * Table driven mount option parser.
7394 @@ -126,6 +129,8 @@ enum {
7395         Opt_nobarrier,
7396         Opt_inode64,
7397         Opt_inode32,
7398 +       Opt_tag,
7399 +       Opt_notag,
7400         Opt_err
7401  };
7402  
7403 @@ -134,6 +139,9 @@ static const match_table_t tokens = {
7404         {Opt_nobarrier, "nobarrier"},
7405         {Opt_inode64, "inode64"},
7406         {Opt_inode32, "inode32"},
7407 +       {Opt_tag, "tagxid"},
7408 +       {Opt_tag, "tag"},
7409 +       {Opt_notag, "notag"},
7410         {Opt_err, NULL}
7411  };
7412  
7413 @@ -392,6 +400,19 @@ xfs_parseargs(
7414                 } else if (!strcmp(this_char, "irixsgid")) {
7415                         xfs_warn(mp,
7416         "irixsgid is now a sysctl(2) variable, option is deprecated.");
7417 +#ifndef CONFIG_TAGGING_NONE
7418 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7419 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7420 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
7421 +                       mp->m_flags &= ~XFS_MOUNT_TAGGED;
7422 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
7423 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7424 +#endif
7425 +#ifdef CONFIG_PROPAGATE
7426 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7427 +                       /* use value */
7428 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7429 +#endif
7430                 } else {
7431                         xfs_warn(mp, "unknown mount option [%s].", this_char);
7432                         return EINVAL;
7433 @@ -1238,6 +1259,16 @@ xfs_fs_remount(
7434                 case Opt_inode32:
7435                         mp->m_maxagi = xfs_set_inode32(mp);
7436                         break;
7437 +               case Opt_tag:
7438 +                       if (!(sb->s_flags & MS_TAGGED)) {
7439 +                               printk(KERN_INFO
7440 +                                       "XFS: %s: tagging not permitted on remount.\n",
7441 +                                       sb->s_id);
7442 +                               return -EINVAL;
7443 +                       }
7444 +                       break;
7445 +               case Opt_notag:
7446 +                       break;
7447                 default:
7448                         /*
7449                          * Logically we would return an error here to prevent
7450 @@ -1469,6 +1500,9 @@ xfs_fs_fill_super(
7451         if (error)
7452                 goto out_free_sb;
7453  
7454 +       if (mp->m_flags & XFS_MOUNT_TAGGED)
7455 +               sb->s_flags |= MS_TAGGED;
7456 +
7457         /*
7458          * we must configure the block size in the superblock before we run the
7459          * full mount process as the mount process can lookup and cache inodes.
7460 diff -NurpP --minimal linux-3.10.9/fs/xfs/xfs_vnodeops.c linux-3.10.9-vs2.3.6.6/fs/xfs/xfs_vnodeops.c
7461 --- linux-3.10.9/fs/xfs/xfs_vnodeops.c  2013-07-14 17:01:31.000000000 +0000
7462 +++ linux-3.10.9-vs2.3.6.6/fs/xfs/xfs_vnodeops.c        2013-08-22 20:30:00.000000000 +0000
7463 @@ -155,6 +155,77 @@ xfs_free_eofblocks(
7464         return error;
7465  }
7466  
7467 +
7468 +STATIC void
7469 +xfs_get_inode_flags(
7470 +       xfs_inode_t     *ip)
7471 +{
7472 +       struct inode    *inode = VFS_I(ip);
7473 +       unsigned int    flags = inode->i_flags;
7474 +       unsigned int    vflags = inode->i_vflags;
7475 +
7476 +       if (flags & S_IMMUTABLE)
7477 +               ip->i_d.di_flags |= XFS_DIFLAG_IMMUTABLE;
7478 +       else
7479 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IMMUTABLE;
7480 +       if (flags & S_IXUNLINK)
7481 +               ip->i_d.di_flags |= XFS_DIFLAG_IXUNLINK;
7482 +       else
7483 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IXUNLINK;
7484 +
7485 +       if (vflags & V_BARRIER)
7486 +               ip->i_d.di_vflags |= XFS_DIVFLAG_BARRIER;
7487 +       else
7488 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_BARRIER;
7489 +       if (vflags & V_COW)
7490 +               ip->i_d.di_vflags |= XFS_DIVFLAG_COW;
7491 +       else
7492 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_COW;
7493 +}
7494 +
7495 +int
7496 +xfs_sync_flags(
7497 +       struct inode            *inode,
7498 +       int                     flags,
7499 +       int                     vflags)
7500 +{
7501 +       struct xfs_inode        *ip = XFS_I(inode);
7502 +       struct xfs_mount        *mp = ip->i_mount;
7503 +       struct xfs_trans        *tp;
7504 +       unsigned int            lock_flags = 0;
7505 +       int                     code;
7506 +
7507 +       tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
7508 +       code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
7509 +       if (code)
7510 +               goto error_out;
7511 +
7512 +       xfs_ilock(ip, XFS_ILOCK_EXCL);
7513 +       xfs_trans_ijoin(tp, ip, 0);
7514 +
7515 +       inode->i_flags = flags;
7516 +       inode->i_vflags = vflags;
7517 +       xfs_get_inode_flags(ip);
7518 +
7519 +       xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
7520 +       xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG);
7521 +
7522 +       XFS_STATS_INC(xs_ig_attrchg);
7523 +
7524 +       if (mp->m_flags & XFS_MOUNT_WSYNC)
7525 +               xfs_trans_set_sync(tp);
7526 +       code = xfs_trans_commit(tp, 0);
7527 +       xfs_iunlock(ip, XFS_ILOCK_EXCL);
7528 +       return code;
7529 +
7530 +error_out:
7531 +       xfs_trans_cancel(tp, 0);
7532 +       if (lock_flags)
7533 +               xfs_iunlock(ip, XFS_ILOCK_EXCL);
7534 +       return code;
7535 +}
7536 +
7537 +
7538  int
7539  xfs_release(
7540         xfs_inode_t     *ip)
7541 diff -NurpP --minimal linux-3.10.9/include/linux/cred.h linux-3.10.9-vs2.3.6.6/include/linux/cred.h
7542 --- linux-3.10.9/include/linux/cred.h   2013-02-19 13:58:50.000000000 +0000
7543 +++ linux-3.10.9-vs2.3.6.6/include/linux/cred.h 2013-08-22 20:30:00.000000000 +0000
7544 @@ -143,6 +143,7 @@ extern void exit_creds(struct task_struc
7545  extern int copy_creds(struct task_struct *, unsigned long);
7546  extern const struct cred *get_task_cred(struct task_struct *);
7547  extern struct cred *cred_alloc_blank(void);
7548 +extern struct cred *__prepare_creds(const struct cred *);
7549  extern struct cred *prepare_creds(void);
7550  extern struct cred *prepare_exec_creds(void);
7551  extern int commit_creds(struct cred *);
7552 @@ -196,6 +197,31 @@ static inline void validate_process_cred
7553  }
7554  #endif
7555  
7556 +static inline void set_cred_subscribers(struct cred *cred, int n)
7557 +{
7558 +#ifdef CONFIG_DEBUG_CREDENTIALS
7559 +       atomic_set(&cred->subscribers, n);
7560 +#endif
7561 +}
7562 +
7563 +static inline int read_cred_subscribers(const struct cred *cred)
7564 +{
7565 +#ifdef CONFIG_DEBUG_CREDENTIALS
7566 +       return atomic_read(&cred->subscribers);
7567 +#else
7568 +       return 0;
7569 +#endif
7570 +}
7571 +
7572 +static inline void alter_cred_subscribers(const struct cred *_cred, int n)
7573 +{
7574 +#ifdef CONFIG_DEBUG_CREDENTIALS
7575 +       struct cred *cred = (struct cred *) _cred;
7576 +
7577 +       atomic_add(n, &cred->subscribers);
7578 +#endif
7579 +}
7580 +
7581  /**
7582   * get_new_cred - Get a reference on a new set of credentials
7583   * @cred: The new credentials to reference
7584 diff -NurpP --minimal linux-3.10.9/include/linux/devpts_fs.h linux-3.10.9-vs2.3.6.6/include/linux/devpts_fs.h
7585 --- linux-3.10.9/include/linux/devpts_fs.h      2013-02-19 13:58:50.000000000 +0000
7586 +++ linux-3.10.9-vs2.3.6.6/include/linux/devpts_fs.h    2013-08-22 20:30:00.000000000 +0000
7587 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
7588  
7589  #endif
7590  
7591 -
7592  #endif /* _LINUX_DEVPTS_FS_H */
7593 diff -NurpP --minimal linux-3.10.9/include/linux/fs.h linux-3.10.9-vs2.3.6.6/include/linux/fs.h
7594 --- linux-3.10.9/include/linux/fs.h     2013-07-14 17:01:32.000000000 +0000
7595 +++ linux-3.10.9-vs2.3.6.6/include/linux/fs.h   2013-08-22 20:30:00.000000000 +0000
7596 @@ -211,6 +211,7 @@ typedef void (dio_iodone_t)(struct kiocb
7597  #define ATTR_KILL_PRIV (1 << 14)
7598  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
7599  #define ATTR_TIMES_SET (1 << 16)
7600 +#define ATTR_TAG       (1 << 17)
7601  
7602  /*
7603   * This is the Inode Attributes structure, used for notify_change().  It
7604 @@ -226,6 +227,7 @@ struct iattr {
7605         umode_t         ia_mode;
7606         kuid_t          ia_uid;
7607         kgid_t          ia_gid;
7608 +       ktag_t          ia_tag;
7609         loff_t          ia_size;
7610         struct timespec ia_atime;
7611         struct timespec ia_mtime;
7612 @@ -523,7 +525,9 @@ struct inode {
7613         unsigned short          i_opflags;
7614         kuid_t                  i_uid;
7615         kgid_t                  i_gid;
7616 -       unsigned int            i_flags;
7617 +       ktag_t                  i_tag;
7618 +       unsigned short          i_flags;
7619 +       unsigned short          i_vflags;
7620  
7621  #ifdef CONFIG_FS_POSIX_ACL
7622         struct posix_acl        *i_acl;
7623 @@ -552,6 +556,7 @@ struct inode {
7624                 unsigned int __i_nlink;
7625         };
7626         dev_t                   i_rdev;
7627 +       dev_t                   i_mdev;
7628         loff_t                  i_size;
7629         struct timespec         i_atime;
7630         struct timespec         i_mtime;
7631 @@ -704,6 +709,11 @@ static inline gid_t i_gid_read(const str
7632         return from_kgid(&init_user_ns, inode->i_gid);
7633  }
7634  
7635 +static inline vtag_t i_tag_read(const struct inode *inode)
7636 +{
7637 +       return from_ktag(&init_user_ns, inode->i_tag);
7638 +}
7639 +
7640  static inline void i_uid_write(struct inode *inode, uid_t uid)
7641  {
7642         inode->i_uid = make_kuid(&init_user_ns, uid);
7643 @@ -714,14 +724,19 @@ static inline void i_gid_write(struct in
7644         inode->i_gid = make_kgid(&init_user_ns, gid);
7645  }
7646  
7647 +static inline void i_tag_write(struct inode *inode, vtag_t tag)
7648 +{
7649 +       inode->i_tag = make_ktag(&init_user_ns, tag);
7650 +}
7651 +
7652  static inline unsigned iminor(const struct inode *inode)
7653  {
7654 -       return MINOR(inode->i_rdev);
7655 +       return MINOR(inode->i_mdev);
7656  }
7657  
7658  static inline unsigned imajor(const struct inode *inode)
7659  {
7660 -       return MAJOR(inode->i_rdev);
7661 +       return MAJOR(inode->i_mdev);
7662  }
7663  
7664  extern struct block_device *I_BDEV(struct inode *inode);
7665 @@ -788,6 +803,7 @@ struct file {
7666         loff_t                  f_pos;
7667         struct fown_struct      f_owner;
7668         const struct cred       *f_cred;
7669 +       vxid_t                  f_xid;
7670         struct file_ra_state    f_ra;
7671  
7672         u64                     f_version;
7673 @@ -939,6 +955,7 @@ struct file_lock {
7674         struct file *fl_file;
7675         loff_t fl_start;
7676         loff_t fl_end;
7677 +       vxid_t fl_xid;
7678  
7679         struct fasync_struct *  fl_fasync; /* for lease break notifications */
7680         /* for lease breaks: */
7681 @@ -1569,6 +1586,7 @@ struct inode_operations {
7682         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
7683         ssize_t (*listxattr) (struct dentry *, char *, size_t);
7684         int (*removexattr) (struct dentry *, const char *);
7685 +       int (*sync_flags) (struct inode *, int, int);
7686         int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
7687                       u64 len);
7688         int (*update_time)(struct inode *, struct timespec *, int);
7689 @@ -1581,6 +1599,7 @@ ssize_t rw_copy_check_uvector(int type,
7690                               unsigned long nr_segs, unsigned long fast_segs,
7691                               struct iovec *fast_pointer,
7692                               struct iovec **ret_pointer);
7693 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
7694  
7695  extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
7696  extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *);
7697 @@ -1634,6 +1653,14 @@ struct super_operations {
7698  #define S_IMA          1024    /* Inode has an associated IMA struct */
7699  #define S_AUTOMOUNT    2048    /* Automount/referral quasi-directory */
7700  #define S_NOSEC                4096    /* no suid or xattr security attributes */
7701 +#define S_IXUNLINK     8192    /* Immutable Invert on unlink */
7702 +
7703 +/* Linux-VServer related Inode flags */
7704 +
7705 +#define V_VALID                1
7706 +#define V_XATTR                2
7707 +#define V_BARRIER      4       /* Barrier for chroot() */
7708 +#define V_COW          8       /* Copy on Write */
7709  
7710  /*
7711   * Note that nosuid etc flags are inode-specific: setting some file-system
7712 @@ -1658,10 +1685,13 @@ struct super_operations {
7713  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
7714  #define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
7715  #define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
7716 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
7717  
7718  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
7719  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
7720  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
7721 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
7722 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
7723  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
7724  
7725  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
7726 @@ -1672,6 +1702,16 @@ struct super_operations {
7727  #define IS_AUTOMOUNT(inode)    ((inode)->i_flags & S_AUTOMOUNT)
7728  #define IS_NOSEC(inode)                ((inode)->i_flags & S_NOSEC)
7729  
7730 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
7731 +
7732 +#ifdef CONFIG_VSERVER_COWBL
7733 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
7734 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
7735 +#else
7736 +#  define IS_COW(inode)                (0)
7737 +#  define IS_COW_LINK(inode)   (0)
7738 +#endif
7739 +
7740  /*
7741   * Inode state bits.  Protected by inode->i_lock
7742   *
7743 @@ -1900,6 +1940,9 @@ extern int rw_verify_area(int, struct fi
7744  extern int locks_mandatory_locked(struct inode *);
7745  extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t);
7746  
7747 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
7748 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
7749 +
7750  /*
7751   * Candidates for mandatory locking have the setgid bit set
7752   * but no group execute bit -  an otherwise meaningless combination.
7753 @@ -2525,6 +2568,7 @@ extern int dcache_dir_open(struct inode
7754  extern int dcache_dir_close(struct inode *, struct file *);
7755  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
7756  extern int dcache_readdir(struct file *, void *, filldir_t);
7757 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
7758  extern int simple_setattr(struct dentry *, struct iattr *);
7759  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
7760  extern int simple_statfs(struct dentry *, struct kstatfs *);
7761 diff -NurpP --minimal linux-3.10.9/include/linux/init_task.h linux-3.10.9-vs2.3.6.6/include/linux/init_task.h
7762 --- linux-3.10.9/include/linux/init_task.h      2013-05-31 13:45:27.000000000 +0000
7763 +++ linux-3.10.9-vs2.3.6.6/include/linux/init_task.h    2013-08-22 20:30:00.000000000 +0000
7764 @@ -222,6 +222,10 @@ extern struct task_group root_task_group
7765         INIT_TASK_RCU_PREEMPT(tsk)                                      \
7766         INIT_CPUSET_SEQ                                                 \
7767         INIT_VTIME(tsk)                                                 \
7768 +       .xid            = 0,                                            \
7769 +       .vx_info        = NULL,                                         \
7770 +       .nid            = 0,                                            \
7771 +       .nx_info        = NULL,                                         \
7772  }
7773  
7774  
7775 diff -NurpP --minimal linux-3.10.9/include/linux/ipc.h linux-3.10.9-vs2.3.6.6/include/linux/ipc.h
7776 --- linux-3.10.9/include/linux/ipc.h    2012-12-11 03:30:57.000000000 +0000
7777 +++ linux-3.10.9-vs2.3.6.6/include/linux/ipc.h  2013-08-22 20:30:00.000000000 +0000
7778 @@ -16,6 +16,7 @@ struct kern_ipc_perm
7779         key_t           key;
7780         kuid_t          uid;
7781         kgid_t          gid;
7782 +       vxid_t          xid;
7783         kuid_t          cuid;
7784         kgid_t          cgid;
7785         umode_t         mode; 
7786 diff -NurpP --minimal linux-3.10.9/include/linux/loop.h linux-3.10.9-vs2.3.6.6/include/linux/loop.h
7787 --- linux-3.10.9/include/linux/loop.h   2013-02-19 13:58:51.000000000 +0000
7788 +++ linux-3.10.9-vs2.3.6.6/include/linux/loop.h 2013-08-22 20:30:00.000000000 +0000
7789 @@ -41,6 +41,7 @@ struct loop_device {
7790         struct loop_func_table *lo_encryption;
7791         __u32           lo_init[2];
7792         kuid_t          lo_key_owner;   /* Who set the key */
7793 +       vxid_t          lo_xid;
7794         int             (*ioctl)(struct loop_device *, int cmd, 
7795                                  unsigned long arg); 
7796  
7797 diff -NurpP --minimal linux-3.10.9/include/linux/memcontrol.h linux-3.10.9-vs2.3.6.6/include/linux/memcontrol.h
7798 --- linux-3.10.9/include/linux/memcontrol.h     2013-05-31 13:45:28.000000000 +0000
7799 +++ linux-3.10.9-vs2.3.6.6/include/linux/memcontrol.h   2013-08-22 20:30:00.000000000 +0000
7800 @@ -86,6 +86,13 @@ extern struct mem_cgroup *try_get_mem_cg
7801  extern struct mem_cgroup *parent_mem_cgroup(struct mem_cgroup *memcg);
7802  extern struct mem_cgroup *mem_cgroup_from_cont(struct cgroup *cont);
7803  
7804 +extern u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member);
7805 +extern u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member);
7806 +
7807 +extern s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem);
7808 +extern s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem);
7809 +extern s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem);
7810 +
7811  static inline
7812  bool mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *memcg)
7813  {
7814 diff -NurpP --minimal linux-3.10.9/include/linux/mm_types.h linux-3.10.9-vs2.3.6.6/include/linux/mm_types.h
7815 --- linux-3.10.9/include/linux/mm_types.h       2013-05-31 13:45:28.000000000 +0000
7816 +++ linux-3.10.9-vs2.3.6.6/include/linux/mm_types.h     2013-08-22 20:30:00.000000000 +0000
7817 @@ -380,6 +380,7 @@ struct mm_struct {
7818  
7819         /* Architecture-specific MM context */
7820         mm_context_t context;
7821 +       struct vx_info *mm_vx_info;
7822  
7823         unsigned long flags; /* Must use atomic bitops to access the bits */
7824  
7825 diff -NurpP --minimal linux-3.10.9/include/linux/mount.h linux-3.10.9-vs2.3.6.6/include/linux/mount.h
7826 --- linux-3.10.9/include/linux/mount.h  2013-05-31 13:45:28.000000000 +0000
7827 +++ linux-3.10.9-vs2.3.6.6/include/linux/mount.h        2013-08-22 20:30:00.000000000 +0000
7828 @@ -49,6 +49,9 @@ struct mnt_namespace;
7829  
7830  #define MNT_LOCK_READONLY      0x400000
7831  
7832 +#define MNT_TAGID      0x10000
7833 +#define MNT_NOTAG      0x20000
7834 +
7835  struct vfsmount {
7836         struct dentry *mnt_root;        /* root of the mounted tree */
7837         struct super_block *mnt_sb;     /* pointer to superblock */
7838 diff -NurpP --minimal linux-3.10.9/include/linux/net.h linux-3.10.9-vs2.3.6.6/include/linux/net.h
7839 --- linux-3.10.9/include/linux/net.h    2013-07-14 17:01:32.000000000 +0000
7840 +++ linux-3.10.9-vs2.3.6.6/include/linux/net.h  2013-08-22 20:30:00.000000000 +0000
7841 @@ -38,6 +38,7 @@ struct net;
7842  #define SOCK_PASSCRED          3
7843  #define SOCK_PASSSEC           4
7844  #define SOCK_EXTERNALLY_ALLOCATED 5
7845 +#define SOCK_USER_SOCKET       6
7846  
7847  #ifndef ARCH_HAS_SOCKET_TYPES
7848  /**
7849 diff -NurpP --minimal linux-3.10.9/include/linux/netdevice.h linux-3.10.9-vs2.3.6.6/include/linux/netdevice.h
7850 --- linux-3.10.9/include/linux/netdevice.h      2013-07-14 17:01:32.000000000 +0000
7851 +++ linux-3.10.9-vs2.3.6.6/include/linux/netdevice.h    2013-08-22 20:30:00.000000000 +0000
7852 @@ -1694,6 +1694,7 @@ extern int                init_dummy_netdev(struct net
7853  
7854  extern struct net_device       *dev_get_by_index(struct net *net, int ifindex);
7855  extern struct net_device       *__dev_get_by_index(struct net *net, int ifindex);
7856 +extern struct net_device       *dev_get_by_index_real_rcu(struct net *net, int ifindex);
7857  extern struct net_device       *dev_get_by_index_rcu(struct net *net, int ifindex);
7858  extern int             netdev_get_name(struct net *net, char *name, int ifindex);
7859  extern int             dev_restart(struct net_device *dev);
7860 diff -NurpP --minimal linux-3.10.9/include/linux/nsproxy.h linux-3.10.9-vs2.3.6.6/include/linux/nsproxy.h
7861 --- linux-3.10.9/include/linux/nsproxy.h        2013-02-19 13:58:51.000000000 +0000
7862 +++ linux-3.10.9-vs2.3.6.6/include/linux/nsproxy.h      2013-08-22 20:30:00.000000000 +0000
7863 @@ -3,6 +3,7 @@
7864  
7865  #include <linux/spinlock.h>
7866  #include <linux/sched.h>
7867 +#include <linux/vserver/debug.h>
7868  
7869  struct mnt_namespace;
7870  struct uts_namespace;
7871 @@ -63,6 +64,7 @@ static inline struct nsproxy *task_nspro
7872  }
7873  
7874  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
7875 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
7876  void exit_task_namespaces(struct task_struct *tsk);
7877  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
7878  void free_nsproxy(struct nsproxy *ns);
7879 @@ -70,16 +72,26 @@ int unshare_nsproxy_namespaces(unsigned
7880         struct cred *, struct fs_struct *);
7881  int __init nsproxy_cache_init(void);
7882  
7883 -static inline void put_nsproxy(struct nsproxy *ns)
7884 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
7885 +
7886 +static inline void __get_nsproxy(struct nsproxy *ns,
7887 +       const char *_file, int _line)
7888  {
7889 -       if (atomic_dec_and_test(&ns->count)) {
7890 -               free_nsproxy(ns);
7891 -       }
7892 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
7893 +               ns, atomic_read(&ns->count), _file, _line);
7894 +       atomic_inc(&ns->count);
7895  }
7896  
7897 -static inline void get_nsproxy(struct nsproxy *ns)
7898 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
7899 +
7900 +static inline void __put_nsproxy(struct nsproxy *ns,
7901 +       const char *_file, int _line)
7902  {
7903 -       atomic_inc(&ns->count);
7904 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
7905 +               ns, atomic_read(&ns->count), _file, _line);
7906 +       if (atomic_dec_and_test(&ns->count)) {
7907 +               free_nsproxy(ns);
7908 +       }
7909  }
7910  
7911  #endif
7912 diff -NurpP --minimal linux-3.10.9/include/linux/pid.h linux-3.10.9-vs2.3.6.6/include/linux/pid.h
7913 --- linux-3.10.9/include/linux/pid.h    2013-05-31 13:45:28.000000000 +0000
7914 +++ linux-3.10.9-vs2.3.6.6/include/linux/pid.h  2013-08-22 20:30:00.000000000 +0000
7915 @@ -8,7 +8,8 @@ enum pid_type
7916         PIDTYPE_PID,
7917         PIDTYPE_PGID,
7918         PIDTYPE_SID,
7919 -       PIDTYPE_MAX
7920 +       PIDTYPE_MAX,
7921 +       PIDTYPE_REALPID
7922  };
7923  
7924  /*
7925 @@ -172,6 +173,7 @@ static inline pid_t pid_nr(struct pid *p
7926  }
7927  
7928  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
7929 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
7930  pid_t pid_vnr(struct pid *pid);
7931  
7932  #define do_each_pid_task(pid, type, task)                              \
7933 diff -NurpP --minimal linux-3.10.9/include/linux/quotaops.h linux-3.10.9-vs2.3.6.6/include/linux/quotaops.h
7934 --- linux-3.10.9/include/linux/quotaops.h       2012-12-11 03:30:57.000000000 +0000
7935 +++ linux-3.10.9-vs2.3.6.6/include/linux/quotaops.h     2013-08-22 20:30:00.000000000 +0000
7936 @@ -8,6 +8,7 @@
7937  #define _LINUX_QUOTAOPS_
7938  
7939  #include <linux/fs.h>
7940 +#include <linux/vs_dlimit.h>
7941  
7942  #define DQUOT_SPACE_WARN       0x1
7943  #define DQUOT_SPACE_RESERVE    0x2
7944 @@ -205,11 +206,12 @@ static inline void dquot_drop(struct ino
7945  
7946  static inline int dquot_alloc_inode(const struct inode *inode)
7947  {
7948 -       return 0;
7949 +       return dl_alloc_inode(inode);
7950  }
7951  
7952  static inline void dquot_free_inode(const struct inode *inode)
7953  {
7954 +       dl_free_inode(inode);
7955  }
7956  
7957  static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
7958 @@ -220,6 +222,10 @@ static inline int dquot_transfer(struct
7959  static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
7960                 int flags)
7961  {
7962 +       int ret = 0;
7963 +
7964 +       if ((ret = dl_alloc_space(inode, number)))
7965 +               return ret;
7966         if (!(flags & DQUOT_SPACE_RESERVE))
7967                 inode_add_bytes(inode, number);
7968         return 0;
7969 @@ -230,6 +236,7 @@ static inline void __dquot_free_space(st
7970  {
7971         if (!(flags & DQUOT_SPACE_RESERVE))
7972                 inode_sub_bytes(inode, number);
7973 +       dl_free_space(inode, number);
7974  }
7975  
7976  static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
7977 diff -NurpP --minimal linux-3.10.9/include/linux/sched.h linux-3.10.9-vs2.3.6.6/include/linux/sched.h
7978 --- linux-3.10.9/include/linux/sched.h  2013-08-22 19:51:35.000000000 +0000
7979 +++ linux-3.10.9-vs2.3.6.6/include/linux/sched.h        2013-08-22 20:30:00.000000000 +0000
7980 @@ -1234,6 +1234,14 @@ struct task_struct {
7981  #endif
7982         struct seccomp seccomp;
7983  
7984 +/* vserver context data */
7985 +       struct vx_info *vx_info;
7986 +       struct nx_info *nx_info;
7987 +
7988 +       vxid_t xid;
7989 +       vnid_t nid;
7990 +       vtag_t tag;
7991 +
7992  /* Thread group tracking */
7993         u32 parent_exec_id;
7994         u32 self_exec_id;
7995 @@ -1477,6 +1485,11 @@ struct pid_namespace;
7996  pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
7997                         struct pid_namespace *ns);
7998  
7999 +#include <linux/vserver/base.h>
8000 +#include <linux/vserver/context.h>
8001 +#include <linux/vserver/debug.h>
8002 +#include <linux/vserver/pid.h>
8003 +
8004  static inline pid_t task_pid_nr(struct task_struct *tsk)
8005  {
8006         return tsk->pid;
8007 @@ -1490,7 +1503,8 @@ static inline pid_t task_pid_nr_ns(struc
8008  
8009  static inline pid_t task_pid_vnr(struct task_struct *tsk)
8010  {
8011 -       return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
8012 +       // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
8013 +       return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
8014  }
8015  
8016  
8017 @@ -1503,7 +1517,7 @@ pid_t task_tgid_nr_ns(struct task_struct
8018  
8019  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
8020  {
8021 -       return pid_vnr(task_tgid(tsk));
8022 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
8023  }
8024  
8025  
8026 diff -NurpP --minimal linux-3.10.9/include/linux/shmem_fs.h linux-3.10.9-vs2.3.6.6/include/linux/shmem_fs.h
8027 --- linux-3.10.9/include/linux/shmem_fs.h       2012-12-11 03:30:57.000000000 +0000
8028 +++ linux-3.10.9-vs2.3.6.6/include/linux/shmem_fs.h     2013-08-22 20:30:00.000000000 +0000
8029 @@ -9,6 +9,9 @@
8030  
8031  /* inode in-kernel data */
8032  
8033 +#define TMPFS_SUPER_MAGIC      0x01021994
8034 +
8035 +
8036  struct shmem_inode_info {
8037         spinlock_t              lock;
8038         unsigned long           flags;
8039 diff -NurpP --minimal linux-3.10.9/include/linux/stat.h linux-3.10.9-vs2.3.6.6/include/linux/stat.h
8040 --- linux-3.10.9/include/linux/stat.h   2012-12-11 03:30:57.000000000 +0000
8041 +++ linux-3.10.9-vs2.3.6.6/include/linux/stat.h 2013-08-22 20:30:00.000000000 +0000
8042 @@ -25,6 +25,7 @@ struct kstat {
8043         unsigned int    nlink;
8044         kuid_t          uid;
8045         kgid_t          gid;
8046 +       ktag_t          tag;
8047         dev_t           rdev;
8048         loff_t          size;
8049         struct timespec  atime;
8050 diff -NurpP --minimal linux-3.10.9/include/linux/sunrpc/auth.h linux-3.10.9-vs2.3.6.6/include/linux/sunrpc/auth.h
8051 --- linux-3.10.9/include/linux/sunrpc/auth.h    2013-07-14 17:01:33.000000000 +0000
8052 +++ linux-3.10.9-vs2.3.6.6/include/linux/sunrpc/auth.h  2013-08-22 20:30:00.000000000 +0000
8053 @@ -28,6 +28,7 @@ struct rpcsec_gss_info;
8054  struct auth_cred {
8055         kuid_t  uid;
8056         kgid_t  gid;
8057 +       ktag_t  tag;
8058         struct group_info *group_info;
8059         const char *principal;
8060         unsigned char machine_cred : 1;
8061 diff -NurpP --minimal linux-3.10.9/include/linux/sunrpc/clnt.h linux-3.10.9-vs2.3.6.6/include/linux/sunrpc/clnt.h
8062 --- linux-3.10.9/include/linux/sunrpc/clnt.h    2013-07-14 17:01:33.000000000 +0000
8063 +++ linux-3.10.9-vs2.3.6.6/include/linux/sunrpc/clnt.h  2013-08-22 20:30:00.000000000 +0000
8064 @@ -49,7 +49,8 @@ struct rpc_clnt {
8065         unsigned int            cl_softrtry : 1,/* soft timeouts */
8066                                 cl_discrtry : 1,/* disconnect before retry */
8067                                 cl_autobind : 1,/* use getport() */
8068 -                               cl_chatty   : 1;/* be verbose */
8069 +                               cl_chatty   : 1,/* be verbose */
8070 +                               cl_tag      : 1;/* context tagging */
8071  
8072         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
8073         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
8074 diff -NurpP --minimal linux-3.10.9/include/linux/sysfs.h linux-3.10.9-vs2.3.6.6/include/linux/sysfs.h
8075 --- linux-3.10.9/include/linux/sysfs.h  2013-05-31 13:45:28.000000000 +0000
8076 +++ linux-3.10.9-vs2.3.6.6/include/linux/sysfs.h        2013-08-22 20:30:00.000000000 +0000
8077 @@ -19,6 +19,8 @@
8078  #include <linux/kobject_ns.h>
8079  #include <linux/atomic.h>
8080  
8081 +#define SYSFS_SUPER_MAGIC      0x62656572
8082 +
8083  struct kobject;
8084  struct module;
8085  enum kobj_ns_type;
8086 diff -NurpP --minimal linux-3.10.9/include/linux/types.h linux-3.10.9-vs2.3.6.6/include/linux/types.h
8087 --- linux-3.10.9/include/linux/types.h  2013-02-19 13:58:52.000000000 +0000
8088 +++ linux-3.10.9-vs2.3.6.6/include/linux/types.h        2013-08-22 20:30:00.000000000 +0000
8089 @@ -32,6 +32,9 @@ typedef __kernel_uid32_t      uid_t;
8090  typedef __kernel_gid32_t       gid_t;
8091  typedef __kernel_uid16_t        uid16_t;
8092  typedef __kernel_gid16_t        gid16_t;
8093 +typedef unsigned int           vxid_t;
8094 +typedef unsigned int           vnid_t;
8095 +typedef unsigned int           vtag_t;
8096  
8097  typedef unsigned long          uintptr_t;
8098  
8099 diff -NurpP --minimal linux-3.10.9/include/linux/uidgid.h linux-3.10.9-vs2.3.6.6/include/linux/uidgid.h
8100 --- linux-3.10.9/include/linux/uidgid.h 2012-12-11 03:30:57.000000000 +0000
8101 +++ linux-3.10.9-vs2.3.6.6/include/linux/uidgid.h       2013-08-22 20:30:00.000000000 +0000
8102 @@ -23,13 +23,17 @@ typedef struct {
8103         uid_t val;
8104  } kuid_t;
8105  
8106 -
8107  typedef struct {
8108         gid_t val;
8109  } kgid_t;
8110  
8111 +typedef struct {
8112 +       vtag_t val;
8113 +} ktag_t;
8114 +
8115  #define KUIDT_INIT(value) (kuid_t){ value }
8116  #define KGIDT_INIT(value) (kgid_t){ value }
8117 +#define KTAGT_INIT(value) (ktag_t){ value }
8118  
8119  static inline uid_t __kuid_val(kuid_t uid)
8120  {
8121 @@ -41,10 +45,16 @@ static inline gid_t __kgid_val(kgid_t gi
8122         return gid.val;
8123  }
8124  
8125 +static inline vtag_t __ktag_val(ktag_t tag)
8126 +{
8127 +       return tag.val;
8128 +}
8129 +
8130  #else
8131  
8132  typedef uid_t kuid_t;
8133  typedef gid_t kgid_t;
8134 +typedef vtag_t ktag_t;
8135  
8136  static inline uid_t __kuid_val(kuid_t uid)
8137  {
8138 @@ -56,16 +66,24 @@ static inline gid_t __kgid_val(kgid_t gi
8139         return gid;
8140  }
8141  
8142 +static inline vtag_t __ktag_val(ktag_t tag)
8143 +{
8144 +       return tag;
8145 +}
8146 +
8147  #define KUIDT_INIT(value) ((kuid_t) value )
8148  #define KGIDT_INIT(value) ((kgid_t) value )
8149 +#define KTAGT_INIT(value) ((ktag_t) value )
8150  
8151  #endif
8152  
8153  #define GLOBAL_ROOT_UID KUIDT_INIT(0)
8154  #define GLOBAL_ROOT_GID KGIDT_INIT(0)
8155 +#define GLOBAL_ROOT_TAG KTAGT_INIT(0)
8156  
8157  #define INVALID_UID KUIDT_INIT(-1)
8158  #define INVALID_GID KGIDT_INIT(-1)
8159 +#define INVALID_TAG KTAGT_INIT(-1)
8160  
8161  static inline bool uid_eq(kuid_t left, kuid_t right)
8162  {
8163 @@ -77,6 +95,11 @@ static inline bool gid_eq(kgid_t left, k
8164         return __kgid_val(left) == __kgid_val(right);
8165  }
8166  
8167 +static inline bool tag_eq(ktag_t left, ktag_t right)
8168 +{
8169 +       return __ktag_val(left) == __ktag_val(right);
8170 +}
8171 +
8172  static inline bool uid_gt(kuid_t left, kuid_t right)
8173  {
8174         return __kuid_val(left) > __kuid_val(right);
8175 @@ -127,13 +150,21 @@ static inline bool gid_valid(kgid_t gid)
8176         return !gid_eq(gid, INVALID_GID);
8177  }
8178  
8179 +static inline bool tag_valid(ktag_t tag)
8180 +{
8181 +       return !tag_eq(tag, INVALID_TAG);
8182 +}
8183 +
8184  #ifdef CONFIG_USER_NS
8185  
8186  extern kuid_t make_kuid(struct user_namespace *from, uid_t uid);
8187  extern kgid_t make_kgid(struct user_namespace *from, gid_t gid);
8188 +extern krag_t make_ktag(struct user_namespace *from, gid_t gid);
8189  
8190  extern uid_t from_kuid(struct user_namespace *to, kuid_t uid);
8191  extern gid_t from_kgid(struct user_namespace *to, kgid_t gid);
8192 +extern vtag_t from_ktag(struct user_namespace *to, ktag_t tag);
8193 +
8194  extern uid_t from_kuid_munged(struct user_namespace *to, kuid_t uid);
8195  extern gid_t from_kgid_munged(struct user_namespace *to, kgid_t gid);
8196  
8197 @@ -159,6 +190,11 @@ static inline kgid_t make_kgid(struct us
8198         return KGIDT_INIT(gid);
8199  }
8200  
8201 +static inline ktag_t make_ktag(struct user_namespace *from, vtag_t tag)
8202 +{
8203 +       return KTAGT_INIT(tag);
8204 +}
8205 +
8206  static inline uid_t from_kuid(struct user_namespace *to, kuid_t kuid)
8207  {
8208         return __kuid_val(kuid);
8209 @@ -169,6 +205,11 @@ static inline gid_t from_kgid(struct use
8210         return __kgid_val(kgid);
8211  }
8212  
8213 +static inline vtag_t from_ktag(struct user_namespace *to, ktag_t ktag)
8214 +{
8215 +       return __ktag_val(ktag);
8216 +}
8217 +
8218  static inline uid_t from_kuid_munged(struct user_namespace *to, kuid_t kuid)
8219  {
8220         uid_t uid = from_kuid(to, kuid);
8221 diff -NurpP --minimal linux-3.10.9/include/linux/vroot.h linux-3.10.9-vs2.3.6.6/include/linux/vroot.h
8222 --- linux-3.10.9/include/linux/vroot.h  1970-01-01 00:00:00.000000000 +0000
8223 +++ linux-3.10.9-vs2.3.6.6/include/linux/vroot.h        2013-08-22 20:30:00.000000000 +0000
8224 @@ -0,0 +1,51 @@
8225 +
8226 +/*
8227 + * include/linux/vroot.h
8228 + *
8229 + * written by Herbert Pötzl, 9/11/2002
8230 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
8231 + *
8232 + * Copyright (C) 2002-2007 by Herbert Pötzl.
8233 + * Redistribution of this file is permitted under the
8234 + * GNU General Public License.
8235 + */
8236 +
8237 +#ifndef _LINUX_VROOT_H
8238 +#define _LINUX_VROOT_H
8239 +
8240 +
8241 +#ifdef __KERNEL__
8242 +
8243 +/* Possible states of device */
8244 +enum {
8245 +       Vr_unbound,
8246 +       Vr_bound,
8247 +};
8248 +
8249 +struct vroot_device {
8250 +       int             vr_number;
8251 +       int             vr_refcnt;
8252 +
8253 +       struct semaphore        vr_ctl_mutex;
8254 +       struct block_device    *vr_device;
8255 +       int                     vr_state;
8256 +};
8257 +
8258 +
8259 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
8260 +
8261 +extern int register_vroot_grb(vroot_grb_func *);
8262 +extern int unregister_vroot_grb(vroot_grb_func *);
8263 +
8264 +#endif /* __KERNEL__ */
8265 +
8266 +#define MAX_VROOT_DEFAULT      8
8267 +
8268 +/*
8269 + * IOCTL commands --- we will commandeer 0x56 ('V')
8270 + */
8271 +
8272 +#define VROOT_SET_DEV          0x5600
8273 +#define VROOT_CLR_DEV          0x5601
8274 +
8275 +#endif /* _LINUX_VROOT_H */
8276 diff -NurpP --minimal linux-3.10.9/include/linux/vs_base.h linux-3.10.9-vs2.3.6.6/include/linux/vs_base.h
8277 --- linux-3.10.9/include/linux/vs_base.h        1970-01-01 00:00:00.000000000 +0000
8278 +++ linux-3.10.9-vs2.3.6.6/include/linux/vs_base.h      2013-08-22 20:30:00.000000000 +0000
8279 @@ -0,0 +1,10 @@
8280 +#ifndef _VS_BASE_H
8281 +#define _VS_BASE_H
8282 +
8283 +#include "vserver/base.h"
8284 +#include "vserver/check.h"
8285 +#include "vserver/debug.h"
8286 +
8287 +#else
8288 +#warning duplicate inclusion
8289 +#endif
8290 diff -NurpP --minimal linux-3.10.9/include/linux/vs_context.h linux-3.10.9-vs2.3.6.6/include/linux/vs_context.h
8291 --- linux-3.10.9/include/linux/vs_context.h     1970-01-01 00:00:00.000000000 +0000
8292 +++ linux-3.10.9-vs2.3.6.6/include/linux/vs_context.h   2013-08-22 20:30:00.000000000 +0000
8293 @@ -0,0 +1,242 @@
8294 +#ifndef _VS_CONTEXT_H
8295 +#define _VS_CONTEXT_H
8296 +
8297 +#include "vserver/base.h"
8298 +#include "vserver/check.h"
8299 +#include "vserver/context.h"
8300 +#include "vserver/history.h"
8301 +#include "vserver/debug.h"
8302 +
8303 +#include <linux/sched.h>
8304 +
8305 +
8306 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
8307 +
8308 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
8309 +       const char *_file, int _line, void *_here)
8310 +{
8311 +       if (!vxi)
8312 +               return NULL;
8313 +
8314 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
8315 +               vxi, vxi ? vxi->vx_id : 0,
8316 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8317 +               _file, _line);
8318 +       __vxh_get_vx_info(vxi, _here);
8319 +
8320 +       atomic_inc(&vxi->vx_usecnt);
8321 +       return vxi;
8322 +}
8323 +
8324 +
8325 +extern void free_vx_info(struct vx_info *);
8326 +
8327 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
8328 +
8329 +static inline void __put_vx_info(struct vx_info *vxi,
8330 +       const char *_file, int _line, void *_here)
8331 +{
8332 +       if (!vxi)
8333 +               return;
8334 +
8335 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
8336 +               vxi, vxi ? vxi->vx_id : 0,
8337 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8338 +               _file, _line);
8339 +       __vxh_put_vx_info(vxi, _here);
8340 +
8341 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
8342 +               free_vx_info(vxi);
8343 +}
8344 +
8345 +
8346 +#define init_vx_info(p, i) \
8347 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
8348 +
8349 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
8350 +       const char *_file, int _line, void *_here)
8351 +{
8352 +       if (vxi) {
8353 +               vxlprintk(VXD_CBIT(xid, 3),
8354 +                       "init_vx_info(%p[#%d.%d])",
8355 +                       vxi, vxi ? vxi->vx_id : 0,
8356 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8357 +                       _file, _line);
8358 +               __vxh_init_vx_info(vxi, vxp, _here);
8359 +
8360 +               atomic_inc(&vxi->vx_usecnt);
8361 +       }
8362 +       *vxp = vxi;
8363 +}
8364 +
8365 +
8366 +#define set_vx_info(p, i) \
8367 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
8368 +
8369 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
8370 +       const char *_file, int _line, void *_here)
8371 +{
8372 +       struct vx_info *vxo;
8373 +
8374 +       if (!vxi)
8375 +               return;
8376 +
8377 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
8378 +               vxi, vxi ? vxi->vx_id : 0,
8379 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8380 +               _file, _line);
8381 +       __vxh_set_vx_info(vxi, vxp, _here);
8382 +
8383 +       atomic_inc(&vxi->vx_usecnt);
8384 +       vxo = xchg(vxp, vxi);
8385 +       BUG_ON(vxo);
8386 +}
8387 +
8388 +
8389 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
8390 +
8391 +static inline void __clr_vx_info(struct vx_info **vxp,
8392 +       const char *_file, int _line, void *_here)
8393 +{
8394 +       struct vx_info *vxo;
8395 +
8396 +       vxo = xchg(vxp, NULL);
8397 +       if (!vxo)
8398 +               return;
8399 +
8400 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
8401 +               vxo, vxo ? vxo->vx_id : 0,
8402 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
8403 +               _file, _line);
8404 +       __vxh_clr_vx_info(vxo, vxp, _here);
8405 +
8406 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
8407 +               free_vx_info(vxo);
8408 +}
8409 +
8410 +
8411 +#define claim_vx_info(v, p) \
8412 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
8413 +
8414 +static inline void __claim_vx_info(struct vx_info *vxi,
8415 +       struct task_struct *task,
8416 +       const char *_file, int _line, void *_here)
8417 +{
8418 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
8419 +               vxi, vxi ? vxi->vx_id : 0,
8420 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8421 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
8422 +               task, _file, _line);
8423 +       __vxh_claim_vx_info(vxi, task, _here);
8424 +
8425 +       atomic_inc(&vxi->vx_tasks);
8426 +}
8427 +
8428 +
8429 +extern void unhash_vx_info(struct vx_info *);
8430 +
8431 +#define release_vx_info(v, p) \
8432 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
8433 +
8434 +static inline void __release_vx_info(struct vx_info *vxi,
8435 +       struct task_struct *task,
8436 +       const char *_file, int _line, void *_here)
8437 +{
8438 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
8439 +               vxi, vxi ? vxi->vx_id : 0,
8440 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8441 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
8442 +               task, _file, _line);
8443 +       __vxh_release_vx_info(vxi, task, _here);
8444 +
8445 +       might_sleep();
8446 +
8447 +       if (atomic_dec_and_test(&vxi->vx_tasks))
8448 +               unhash_vx_info(vxi);
8449 +}
8450 +
8451 +
8452 +#define task_get_vx_info(p) \
8453 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
8454 +
8455 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
8456 +       const char *_file, int _line, void *_here)
8457 +{
8458 +       struct vx_info *vxi;
8459 +
8460 +       task_lock(p);
8461 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
8462 +               p, _file, _line);
8463 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
8464 +       task_unlock(p);
8465 +       return vxi;
8466 +}
8467 +
8468 +
8469 +static inline void __wakeup_vx_info(struct vx_info *vxi)
8470 +{
8471 +       if (waitqueue_active(&vxi->vx_wait))
8472 +               wake_up_interruptible(&vxi->vx_wait);
8473 +}
8474 +
8475 +
8476 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
8477 +
8478 +static inline void __enter_vx_info(struct vx_info *vxi,
8479 +       struct vx_info_save *vxis, const char *_file, int _line)
8480 +{
8481 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
8482 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
8483 +               current->xid, current->vx_info, _file, _line);
8484 +       vxis->vxi = xchg(&current->vx_info, vxi);
8485 +       vxis->xid = current->xid;
8486 +       current->xid = vxi ? vxi->vx_id : 0;
8487 +}
8488 +
8489 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
8490 +
8491 +static inline void __leave_vx_info(struct vx_info_save *vxis,
8492 +       const char *_file, int _line)
8493 +{
8494 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
8495 +               vxis, vxis->xid, vxis->vxi, current,
8496 +               current->xid, current->vx_info, _file, _line);
8497 +       (void)xchg(&current->vx_info, vxis->vxi);
8498 +       current->xid = vxis->xid;
8499 +}
8500 +
8501 +
8502 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
8503 +{
8504 +       vxis->vxi = xchg(&current->vx_info, NULL);
8505 +       vxis->xid = xchg(&current->xid, (vxid_t)0);
8506 +}
8507 +
8508 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
8509 +{
8510 +       (void)xchg(&current->xid, vxis->xid);
8511 +       (void)xchg(&current->vx_info, vxis->vxi);
8512 +}
8513 +
8514 +#define task_is_init(p) \
8515 +       __task_is_init(p, __FILE__, __LINE__, __HERE__)
8516 +
8517 +static inline int __task_is_init(struct task_struct *p,
8518 +       const char *_file, int _line, void *_here)
8519 +{
8520 +       int is_init = is_global_init(p);
8521 +
8522 +       task_lock(p);
8523 +       if (p->vx_info)
8524 +               is_init = p->vx_info->vx_initpid == p->pid;
8525 +       task_unlock(p);
8526 +       return is_init;
8527 +}
8528 +
8529 +extern void exit_vx_info(struct task_struct *, int);
8530 +extern void exit_vx_info_early(struct task_struct *, int);
8531 +
8532 +
8533 +#else
8534 +#warning duplicate inclusion
8535 +#endif
8536 diff -NurpP --minimal linux-3.10.9/include/linux/vs_cowbl.h linux-3.10.9-vs2.3.6.6/include/linux/vs_cowbl.h
8537 --- linux-3.10.9/include/linux/vs_cowbl.h       1970-01-01 00:00:00.000000000 +0000
8538 +++ linux-3.10.9-vs2.3.6.6/include/linux/vs_cowbl.h     2013-08-22 20:30:00.000000000 +0000
8539 @@ -0,0 +1,48 @@
8540 +#ifndef _VS_COWBL_H
8541 +#define _VS_COWBL_H
8542 +
8543 +#include <linux/fs.h>
8544 +#include <linux/dcache.h>
8545 +#include <linux/namei.h>
8546 +#include <linux/slab.h>
8547 +
8548 +extern struct dentry *cow_break_link(const char *pathname);
8549 +
8550 +static inline int cow_check_and_break(struct path *path)
8551 +{
8552 +       struct inode *inode = path->dentry->d_inode;
8553 +       int error = 0;
8554 +
8555 +       /* do we need this check? */
8556 +       if (IS_RDONLY(inode))
8557 +               return -EROFS;
8558 +
8559 +       if (IS_COW(inode)) {
8560 +               if (IS_COW_LINK(inode)) {
8561 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
8562 +                       char *pp, *buf;
8563 +
8564 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
8565 +                       if (!buf) {
8566 +                               return -ENOMEM;
8567 +                       }
8568 +                       pp = d_path(path, buf, PATH_MAX);
8569 +                       new_dentry = cow_break_link(pp);
8570 +                       kfree(buf);
8571 +                       if (!IS_ERR(new_dentry)) {
8572 +                               path->dentry = new_dentry;
8573 +                               dput(old_dentry);
8574 +                       } else
8575 +                               error = PTR_ERR(new_dentry);
8576 +               } else {
8577 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
8578 +                       inode->i_ctime = CURRENT_TIME;
8579 +                       mark_inode_dirty(inode);
8580 +               }
8581 +       }
8582 +       return error;
8583 +}
8584 +
8585 +#else
8586 +#warning duplicate inclusion
8587 +#endif
8588 diff -NurpP --minimal linux-3.10.9/include/linux/vs_cvirt.h linux-3.10.9-vs2.3.6.6/include/linux/vs_cvirt.h
8589 --- linux-3.10.9/include/linux/vs_cvirt.h       1970-01-01 00:00:00.000000000 +0000
8590 +++ linux-3.10.9-vs2.3.6.6/include/linux/vs_cvirt.h     2013-08-22 20:30:00.000000000 +0000
8591 @@ -0,0 +1,50 @@
8592 +#ifndef _VS_CVIRT_H
8593 +#define _VS_CVIRT_H
8594 +
8595 +#include "vserver/cvirt.h"
8596 +#include "vserver/context.h"
8597 +#include "vserver/base.h"
8598 +#include "vserver/check.h"
8599 +#include "vserver/debug.h"
8600 +
8601 +
8602 +static inline void vx_activate_task(struct task_struct *p)
8603 +{
8604 +       struct vx_info *vxi;
8605 +
8606 +       if ((vxi = p->vx_info)) {
8607 +               vx_update_load(vxi);
8608 +               atomic_inc(&vxi->cvirt.nr_running);
8609 +       }
8610 +}
8611 +
8612 +static inline void vx_deactivate_task(struct task_struct *p)
8613 +{
8614 +       struct vx_info *vxi;
8615 +
8616 +       if ((vxi = p->vx_info)) {
8617 +               vx_update_load(vxi);
8618 +               atomic_dec(&vxi->cvirt.nr_running);
8619 +       }
8620 +}
8621 +
8622 +static inline void vx_uninterruptible_inc(struct task_struct *p)
8623 +{
8624 +       struct vx_info *vxi;
8625 +
8626 +       if ((vxi = p->vx_info))
8627 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
8628 +}
8629 +
8630 +static inline void vx_uninterruptible_dec(struct task_struct *p)
8631 +{
8632 +       struct vx_info *vxi;
8633 +
8634 +       if ((vxi = p->vx_info))
8635 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
8636 +}
8637 +
8638 +
8639 +#else
8640 +#warning duplicate inclusion
8641 +#endif
8642 diff -NurpP --minimal linux-3.10.9/include/linux/vs_device.h linux-3.10.9-vs2.3.6.6/include/linux/vs_device.h
8643 --- linux-3.10.9/include/linux/vs_device.h      1970-01-01 00:00:00.000000000 +0000
8644 +++ linux-3.10.9-vs2.3.6.6/include/linux/vs_device.h    2013-08-22 20:30:00.000000000 +0000
8645 @@ -0,0 +1,45 @@
8646 +#ifndef _VS_DEVICE_H
8647 +#define _VS_DEVICE_H
8648 +
8649 +#include "vserver/base.h"
8650 +#include "vserver/device.h"
8651 +#include "vserver/debug.h"
8652 +
8653 +
8654 +#ifdef CONFIG_VSERVER_DEVICE
8655 +
8656 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
8657 +
8658 +#define vs_device_perm(v, d, m, p) \
8659 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
8660 +
8661 +#else
8662 +
8663 +static inline
8664 +int vs_map_device(struct vx_info *vxi,
8665 +       dev_t device, dev_t *target, umode_t mode)
8666 +{
8667 +       if (target)
8668 +               *target = device;
8669 +       return ~0;
8670 +}
8671 +
8672 +#define vs_device_perm(v, d, m, p) ((p) == (p))
8673 +
8674 +#endif
8675 +
8676 +
8677 +#define vs_map_chrdev(d, t, p) \
8678 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
8679 +#define vs_map_blkdev(d, t, p) \
8680 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
8681 +
8682 +#define vs_chrdev_perm(d, p) \
8683 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
8684 +#define vs_blkdev_perm(d, p) \
8685 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
8686 +
8687 +
8688 +#else
8689 +#warning duplicate inclusion
8690 +#endif
8691 diff -NurpP --minimal linux-3.10.9/include/linux/vs_dlimit.h linux-3.10.9-vs2.3.6.6/include/linux/vs_dlimit.h
8692 --- linux-3.10.9/include/linux/vs_dlimit.h      1970-01-01 00:00:00.000000000 +0000
8693 +++ linux-3.10.9-vs2.3.6.6/include/linux/vs_dlimit.h    2013-08-22 20:30:00.000000000 +0000
8694 @@ -0,0 +1,215 @@
8695 +#ifndef _VS_DLIMIT_H
8696 +#define _VS_DLIMIT_H
8697 +
8698 +#include <linux/fs.h>
8699 +
8700 +#include "vserver/dlimit.h"
8701 +#include "vserver/base.h"
8702 +#include "vserver/debug.h"
8703 +
8704 +
8705 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
8706 +
8707 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
8708 +       const char *_file, int _line)
8709 +{
8710 +       if (!dli)
8711 +               return NULL;
8712 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
8713 +               dli, dli ? dli->dl_tag : 0,
8714 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
8715 +               _file, _line);
8716 +       atomic_inc(&dli->dl_usecnt);
8717 +       return dli;
8718 +}
8719 +
8720 +
8721 +#define free_dl_info(i) \
8722 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
8723 +
8724 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
8725 +
8726 +static inline void __put_dl_info(struct dl_info *dli,
8727 +       const char *_file, int _line)
8728 +{
8729 +       if (!dli)
8730 +               return;
8731 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
8732 +               dli, dli ? dli->dl_tag : 0,
8733 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
8734 +               _file, _line);
8735 +       if (atomic_dec_and_test(&dli->dl_usecnt))
8736 +               free_dl_info(dli);
8737 +}
8738 +
8739 +
8740 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
8741 +
8742 +static inline int __dl_alloc_space(struct super_block *sb,
8743 +       vtag_t tag, dlsize_t nr, const char *file, int line)
8744 +{
8745 +       struct dl_info *dli = NULL;
8746 +       int ret = 0;
8747 +
8748 +       if (nr == 0)
8749 +               goto out;
8750 +       dli = locate_dl_info(sb, tag);
8751 +       if (!dli)
8752 +               goto out;
8753 +
8754 +       spin_lock(&dli->dl_lock);
8755 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
8756 +       if (!ret)
8757 +               dli->dl_space_used += nr;
8758 +       spin_unlock(&dli->dl_lock);
8759 +       put_dl_info(dli);
8760 +out:
8761 +       vxlprintk(VXD_CBIT(dlim, 1),
8762 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
8763 +               sb, tag, __dlimit_char(dli), (long long)nr,
8764 +               ret, file, line);
8765 +       return ret ? -ENOSPC : 0;
8766 +}
8767 +
8768 +static inline void __dl_free_space(struct super_block *sb,
8769 +       vtag_t tag, dlsize_t nr, const char *_file, int _line)
8770 +{
8771 +       struct dl_info *dli = NULL;
8772 +
8773 +       if (nr == 0)
8774 +               goto out;
8775 +       dli = locate_dl_info(sb, tag);
8776 +       if (!dli)
8777 +               goto out;
8778 +
8779 +       spin_lock(&dli->dl_lock);
8780 +       if (dli->dl_space_used > nr)
8781 +               dli->dl_space_used -= nr;
8782 +       else
8783 +               dli->dl_space_used = 0;
8784 +       spin_unlock(&dli->dl_lock);
8785 +       put_dl_info(dli);
8786 +out:
8787 +       vxlprintk(VXD_CBIT(dlim, 1),
8788 +               "FREE  (%p,#%d)%c %lld bytes",
8789 +               sb, tag, __dlimit_char(dli), (long long)nr,
8790 +               _file, _line);
8791 +}
8792 +
8793 +static inline int __dl_alloc_inode(struct super_block *sb,
8794 +       vtag_t tag, const char *_file, int _line)
8795 +{
8796 +       struct dl_info *dli;
8797 +       int ret = 0;
8798 +
8799 +       dli = locate_dl_info(sb, tag);
8800 +       if (!dli)
8801 +               goto out;
8802 +
8803 +       spin_lock(&dli->dl_lock);
8804 +       dli->dl_inodes_used++;
8805 +       ret = (dli->dl_inodes_used > dli->dl_inodes_total);
8806 +       spin_unlock(&dli->dl_lock);
8807 +       put_dl_info(dli);
8808 +out:
8809 +       vxlprintk(VXD_CBIT(dlim, 0),
8810 +               "ALLOC (%p,#%d)%c inode (%d)",
8811 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
8812 +       return ret ? -ENOSPC : 0;
8813 +}
8814 +
8815 +static inline void __dl_free_inode(struct super_block *sb,
8816 +       vtag_t tag, const char *_file, int _line)
8817 +{
8818 +       struct dl_info *dli;
8819 +
8820 +       dli = locate_dl_info(sb, tag);
8821 +       if (!dli)
8822 +               goto out;
8823 +
8824 +       spin_lock(&dli->dl_lock);
8825 +       if (dli->dl_inodes_used > 1)
8826 +               dli->dl_inodes_used--;
8827 +       else
8828 +               dli->dl_inodes_used = 0;
8829 +       spin_unlock(&dli->dl_lock);
8830 +       put_dl_info(dli);
8831 +out:
8832 +       vxlprintk(VXD_CBIT(dlim, 0),
8833 +               "FREE  (%p,#%d)%c inode",
8834 +               sb, tag, __dlimit_char(dli), _file, _line);
8835 +}
8836 +
8837 +static inline void __dl_adjust_block(struct super_block *sb, vtag_t tag,
8838 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
8839 +       const char *_file, int _line)
8840 +{
8841 +       struct dl_info *dli;
8842 +       uint64_t broot, bfree;
8843 +
8844 +       dli = locate_dl_info(sb, tag);
8845 +       if (!dli)
8846 +               return;
8847 +
8848 +       spin_lock(&dli->dl_lock);
8849 +       broot = (dli->dl_space_total -
8850 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
8851 +               >> sb->s_blocksize_bits;
8852 +       bfree = (dli->dl_space_total - dli->dl_space_used)
8853 +                       >> sb->s_blocksize_bits;
8854 +       spin_unlock(&dli->dl_lock);
8855 +
8856 +       vxlprintk(VXD_CBIT(dlim, 2),
8857 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
8858 +               (long long)bfree, (long long)broot,
8859 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
8860 +               _file, _line);
8861 +       if (free_blocks) {
8862 +               if (*free_blocks > bfree)
8863 +                       *free_blocks = bfree;
8864 +       }
8865 +       if (root_blocks) {
8866 +               if (*root_blocks > broot)
8867 +                       *root_blocks = broot;
8868 +       }
8869 +       put_dl_info(dli);
8870 +}
8871 +
8872 +#define dl_prealloc_space(in, bytes) \
8873 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8874 +               __FILE__, __LINE__ )
8875 +
8876 +#define dl_alloc_space(in, bytes) \
8877 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8878 +               __FILE__, __LINE__ )
8879 +
8880 +#define dl_reserve_space(in, bytes) \
8881 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8882 +               __FILE__, __LINE__ )
8883 +
8884 +#define dl_claim_space(in, bytes) (0)
8885 +
8886 +#define dl_release_space(in, bytes) \
8887 +       __dl_free_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8888 +               __FILE__, __LINE__ )
8889 +
8890 +#define dl_free_space(in, bytes) \
8891 +       __dl_free_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8892 +               __FILE__, __LINE__ )
8893 +
8894 +
8895 +
8896 +#define dl_alloc_inode(in) \
8897 +       __dl_alloc_inode((in)->i_sb, i_tag_read(in), __FILE__, __LINE__ )
8898 +
8899 +#define dl_free_inode(in) \
8900 +       __dl_free_inode((in)->i_sb, i_tag_read(in), __FILE__, __LINE__ )
8901 +
8902 +
8903 +#define dl_adjust_block(sb, tag, fb, rb) \
8904 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
8905 +
8906 +
8907 +#else
8908 +#warning duplicate inclusion
8909 +#endif
8910 diff -NurpP --minimal linux-3.10.9/include/linux/vs_inet.h linux-3.10.9-vs2.3.6.6/include/linux/vs_inet.h
8911 --- linux-3.10.9/include/linux/vs_inet.h        1970-01-01 00:00:00.000000000 +0000
8912 +++ linux-3.10.9-vs2.3.6.6/include/linux/vs_inet.h      2013-08-22 20:30:00.000000000 +0000
8913 @@ -0,0 +1,364 @@
8914 +#ifndef _VS_INET_H
8915 +#define _VS_INET_H
8916 +
8917 +#include "vserver/base.h"
8918 +#include "vserver/network.h"
8919 +#include "vserver/debug.h"
8920 +
8921 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
8922 +
8923 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
8924 +                       NIPQUAD((a)->mask), (a)->type
8925 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
8926 +
8927 +#define NIPQUAD(addr) \
8928 +       ((unsigned char *)&addr)[0], \
8929 +       ((unsigned char *)&addr)[1], \
8930 +       ((unsigned char *)&addr)[2], \
8931 +       ((unsigned char *)&addr)[3]
8932 +
8933 +#define NIPQUAD_FMT "%u.%u.%u.%u"
8934 +
8935 +
8936 +static inline
8937 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
8938 +{
8939 +       __be32 ip = nxa->ip[0].s_addr;
8940 +       __be32 mask = nxa->mask.s_addr;
8941 +       __be32 bcast = ip | ~mask;
8942 +       int ret = 0;
8943 +
8944 +       switch (nxa->type & tmask) {
8945 +       case NXA_TYPE_MASK:
8946 +               ret = (ip == (addr & mask));
8947 +               break;
8948 +       case NXA_TYPE_ADDR:
8949 +               ret = 3;
8950 +               if (addr == ip)
8951 +                       break;
8952 +               /* fall through to broadcast */
8953 +       case NXA_MOD_BCAST:
8954 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
8955 +               break;
8956 +       case NXA_TYPE_RANGE:
8957 +               ret = ((nxa->ip[0].s_addr <= addr) &&
8958 +                       (nxa->ip[1].s_addr > addr));
8959 +               break;
8960 +       case NXA_TYPE_ANY:
8961 +               ret = 2;
8962 +               break;
8963 +       }
8964 +
8965 +       vxdprintk(VXD_CBIT(net, 0),
8966 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
8967 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
8968 +       return ret;
8969 +}
8970 +
8971 +static inline
8972 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
8973 +{
8974 +       struct nx_addr_v4 *nxa;
8975 +       unsigned long irqflags;
8976 +       int ret = 1;
8977 +
8978 +       if (!nxi)
8979 +               goto out;
8980 +
8981 +       ret = 2;
8982 +       /* allow 127.0.0.1 when remapping lback */
8983 +       if ((tmask & NXA_LOOPBACK) &&
8984 +               (addr == IPI_LOOPBACK) &&
8985 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
8986 +               goto out;
8987 +       ret = 3;
8988 +       /* check for lback address */
8989 +       if ((tmask & NXA_MOD_LBACK) &&
8990 +               (nxi->v4_lback.s_addr == addr))
8991 +               goto out;
8992 +       ret = 4;
8993 +       /* check for broadcast address */
8994 +       if ((tmask & NXA_MOD_BCAST) &&
8995 +               (nxi->v4_bcast.s_addr == addr))
8996 +               goto out;
8997 +       ret = 5;
8998 +
8999 +       /* check for v4 addresses */
9000 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
9001 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
9002 +               if (v4_addr_match(nxa, addr, tmask))
9003 +                       goto out_unlock;
9004 +       ret = 0;
9005 +out_unlock:
9006 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
9007 +out:
9008 +       vxdprintk(VXD_CBIT(net, 0),
9009 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
9010 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
9011 +       return ret;
9012 +}
9013 +
9014 +static inline
9015 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
9016 +{
9017 +       /* FIXME: needs full range checks */
9018 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
9019 +}
9020 +
9021 +static inline
9022 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
9023 +{
9024 +       struct nx_addr_v4 *ptr;
9025 +       unsigned long irqflags;
9026 +       int ret = 1;
9027 +
9028 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
9029 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
9030 +               if (v4_nx_addr_match(ptr, nxa, mask))
9031 +                       goto out_unlock;
9032 +       ret = 0;
9033 +out_unlock:
9034 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
9035 +       return ret;
9036 +}
9037 +
9038 +#include <net/inet_sock.h>
9039 +
9040 +/*
9041 + *     Check if a given address matches for a socket
9042 + *
9043 + *     nxi:            the socket's nx_info if any
9044 + *     addr:           to be verified address
9045 + */
9046 +static inline
9047 +int v4_sock_addr_match (
9048 +       struct nx_info *nxi,
9049 +       struct inet_sock *inet,
9050 +       __be32 addr)
9051 +{
9052 +       __be32 saddr = inet->inet_rcv_saddr;
9053 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
9054 +
9055 +       if (addr && (saddr == addr || bcast == addr))
9056 +               return 1;
9057 +       if (!saddr)
9058 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
9059 +       return 0;
9060 +}
9061 +
9062 +
9063 +/* inet related checks and helpers */
9064 +
9065 +
9066 +struct in_ifaddr;
9067 +struct net_device;
9068 +struct sock;
9069 +
9070 +#ifdef CONFIG_INET
9071 +
9072 +#include <linux/netdevice.h>
9073 +#include <linux/inetdevice.h>
9074 +#include <net/inet_sock.h>
9075 +#include <net/inet_timewait_sock.h>
9076 +
9077 +
9078 +int dev_in_nx_info(struct net_device *, struct nx_info *);
9079 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
9080 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
9081 +
9082 +
9083 +/*
9084 + *     check if address is covered by socket
9085 + *
9086 + *     sk:     the socket to check against
9087 + *     addr:   the address in question (must be != 0)
9088 + */
9089 +
9090 +static inline
9091 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
9092 +{
9093 +       struct nx_info *nxi = sk->sk_nx_info;
9094 +       __be32 saddr = sk_rcv_saddr(sk);
9095 +
9096 +       vxdprintk(VXD_CBIT(net, 5),
9097 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
9098 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
9099 +               (sk->sk_socket?sk->sk_socket->flags:0));
9100 +
9101 +       if (saddr) {            /* direct address match */
9102 +               return v4_addr_match(nxa, saddr, -1);
9103 +       } else if (nxi) {       /* match against nx_info */
9104 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
9105 +       } else {                /* unrestricted any socket */
9106 +               return 1;
9107 +       }
9108 +}
9109 +
9110 +
9111 +
9112 +static inline
9113 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
9114 +{
9115 +       vxdprintk(VXD_CBIT(net, 1),
9116 +               "nx_dev_visible(%p[#%u],%p " VS_Q("%s") ") %d",
9117 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
9118 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
9119 +
9120 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9121 +               return 1;
9122 +       if (dev_in_nx_info(dev, nxi))
9123 +               return 1;
9124 +       return 0;
9125 +}
9126 +
9127 +
9128 +static inline
9129 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
9130 +{
9131 +       if (!nxi)
9132 +               return 1;
9133 +       if (!ifa)
9134 +               return 0;
9135 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
9136 +}
9137 +
9138 +static inline
9139 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
9140 +{
9141 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
9142 +               nxi, nxi ? nxi->nx_id : 0, ifa,
9143 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
9144 +
9145 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9146 +               return 1;
9147 +       if (v4_ifa_in_nx_info(ifa, nxi))
9148 +               return 1;
9149 +       return 0;
9150 +}
9151 +
9152 +
9153 +struct nx_v4_sock_addr {
9154 +       __be32 saddr;   /* Address used for validation */
9155 +       __be32 baddr;   /* Address used for socket bind */
9156 +};
9157 +
9158 +static inline
9159 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
9160 +       struct nx_v4_sock_addr *nsa)
9161 +{
9162 +       struct sock *sk = &inet->sk;
9163 +       struct nx_info *nxi = sk->sk_nx_info;
9164 +       __be32 saddr = addr->sin_addr.s_addr;
9165 +       __be32 baddr = saddr;
9166 +
9167 +       vxdprintk(VXD_CBIT(net, 3),
9168 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
9169 +               sk, sk->sk_nx_info, sk->sk_socket,
9170 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
9171 +               NIPQUAD(saddr));
9172 +
9173 +       if (nxi) {
9174 +               if (saddr == INADDR_ANY) {
9175 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
9176 +                               baddr = nxi->v4.ip[0].s_addr;
9177 +               } else if (saddr == IPI_LOOPBACK) {
9178 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9179 +                               baddr = nxi->v4_lback.s_addr;
9180 +               } else if (!ipv4_is_multicast(saddr) ||
9181 +                       !nx_info_ncaps(nxi, NXC_MULTICAST)) {
9182 +                       /* normal address bind */
9183 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
9184 +                               return -EADDRNOTAVAIL;
9185 +               }
9186 +       }
9187 +
9188 +       vxdprintk(VXD_CBIT(net, 3),
9189 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
9190 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
9191 +
9192 +       nsa->saddr = saddr;
9193 +       nsa->baddr = baddr;
9194 +       return 0;
9195 +}
9196 +
9197 +static inline
9198 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
9199 +{
9200 +       inet->inet_saddr = nsa->baddr;
9201 +       inet->inet_rcv_saddr = nsa->baddr;
9202 +}
9203 +
9204 +
9205 +/*
9206 + *      helper to simplify inet_lookup_listener
9207 + *
9208 + *      nxi:   the socket's nx_info if any
9209 + *      addr:  to be verified address
9210 + *      saddr: socket address
9211 + */
9212 +static inline int v4_inet_addr_match (
9213 +       struct nx_info *nxi,
9214 +       __be32 addr,
9215 +       __be32 saddr)
9216 +{
9217 +       if (addr && (saddr == addr))
9218 +               return 1;
9219 +       if (!saddr)
9220 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
9221 +       return 0;
9222 +}
9223 +
9224 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
9225 +{
9226 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
9227 +               (addr == nxi->v4_lback.s_addr))
9228 +               return IPI_LOOPBACK;
9229 +       return addr;
9230 +}
9231 +
9232 +static inline
9233 +int nx_info_has_v4(struct nx_info *nxi)
9234 +{
9235 +       if (!nxi)
9236 +               return 1;
9237 +       if (NX_IPV4(nxi))
9238 +               return 1;
9239 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9240 +               return 1;
9241 +       return 0;
9242 +}
9243 +
9244 +#else /* CONFIG_INET */
9245 +
9246 +static inline
9247 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
9248 +{
9249 +       return 1;
9250 +}
9251 +
9252 +static inline
9253 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
9254 +{
9255 +       return 1;
9256 +}
9257 +
9258 +static inline
9259 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
9260 +{
9261 +       return 1;
9262 +}
9263 +
9264 +static inline
9265 +int nx_info_has_v4(struct nx_info *nxi)
9266 +{
9267 +       return 0;
9268 +}
9269 +
9270 +#endif /* CONFIG_INET */
9271 +
9272 +#define current_nx_info_has_v4() \
9273 +       nx_info_has_v4(current_nx_info())
9274 +
9275 +#else
9276 +// #warning duplicate inclusion
9277 +#endif
9278 diff -NurpP --minimal linux-3.10.9/include/linux/vs_inet6.h linux-3.10.9-vs2.3.6.6/include/linux/vs_inet6.h
9279 --- linux-3.10.9/include/linux/vs_inet6.h       1970-01-01 00:00:00.000000000 +0000
9280 +++ linux-3.10.9-vs2.3.6.6/include/linux/vs_inet6.h     2013-08-22 20:30:00.000000000 +0000
9281 @@ -0,0 +1,257 @@
9282 +#ifndef _VS_INET6_H
9283 +#define _VS_INET6_H
9284 +
9285 +#include "vserver/base.h"
9286 +#include "vserver/network.h"
9287 +#include "vserver/debug.h"
9288 +
9289 +#include <net/ipv6.h>
9290 +
9291 +#define NXAV6(a)       &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
9292 +#define NXAV6_FMT      "[%pI6/%pI6/%d:%04x]"
9293 +
9294 +
9295 +#ifdef CONFIG_IPV6
9296 +
9297 +static inline
9298 +int v6_addr_match(struct nx_addr_v6 *nxa,
9299 +       const struct in6_addr *addr, uint16_t mask)
9300 +{
9301 +       int ret = 0;
9302 +
9303 +       switch (nxa->type & mask) {
9304 +       case NXA_TYPE_MASK:
9305 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
9306 +               break;
9307 +       case NXA_TYPE_ADDR:
9308 +               ret = ipv6_addr_equal(&nxa->ip, addr);
9309 +               break;
9310 +       case NXA_TYPE_ANY:
9311 +               ret = 1;
9312 +               break;
9313 +       }
9314 +       vxdprintk(VXD_CBIT(net, 0),
9315 +               "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
9316 +               nxa, NXAV6(nxa), addr, mask, ret);
9317 +       return ret;
9318 +}
9319 +
9320 +static inline
9321 +int v6_addr_in_nx_info(struct nx_info *nxi,
9322 +       const struct in6_addr *addr, uint16_t mask)
9323 +{
9324 +       struct nx_addr_v6 *nxa;
9325 +       unsigned long irqflags;
9326 +       int ret = 1;
9327 +
9328 +       if (!nxi)
9329 +               goto out;
9330 +
9331 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
9332 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
9333 +               if (v6_addr_match(nxa, addr, mask))
9334 +                       goto out_unlock;
9335 +       ret = 0;
9336 +out_unlock:
9337 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
9338 +out:
9339 +       vxdprintk(VXD_CBIT(net, 0),
9340 +               "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
9341 +               nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
9342 +       return ret;
9343 +}
9344 +
9345 +static inline
9346 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
9347 +{
9348 +       /* FIXME: needs full range checks */
9349 +       return v6_addr_match(nxa, &addr->ip, mask);
9350 +}
9351 +
9352 +static inline
9353 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
9354 +{
9355 +       struct nx_addr_v6 *ptr;
9356 +       unsigned long irqflags;
9357 +       int ret = 1;
9358 +
9359 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
9360 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
9361 +               if (v6_nx_addr_match(ptr, nxa, mask))
9362 +                       goto out_unlock;
9363 +       ret = 0;
9364 +out_unlock:
9365 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
9366 +       return ret;
9367 +}
9368 +
9369 +
9370 +/*
9371 + *     Check if a given address matches for a socket
9372 + *
9373 + *     nxi:            the socket's nx_info if any
9374 + *     addr:           to be verified address
9375 + */
9376 +static inline
9377 +int v6_sock_addr_match (
9378 +       struct nx_info *nxi,
9379 +       struct inet_sock *inet,
9380 +       struct in6_addr *addr)
9381 +{
9382 +       struct sock *sk = &inet->sk;
9383 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
9384 +
9385 +       if (!ipv6_addr_any(addr) &&
9386 +               ipv6_addr_equal(saddr, addr))
9387 +               return 1;
9388 +       if (ipv6_addr_any(saddr))
9389 +               return v6_addr_in_nx_info(nxi, addr, -1);
9390 +       return 0;
9391 +}
9392 +
9393 +/*
9394 + *     check if address is covered by socket
9395 + *
9396 + *     sk:     the socket to check against
9397 + *     addr:   the address in question (must be != 0)
9398 + */
9399 +
9400 +static inline
9401 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
9402 +{
9403 +       struct nx_info *nxi = sk->sk_nx_info;
9404 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
9405 +
9406 +       vxdprintk(VXD_CBIT(net, 5),
9407 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
9408 +               sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
9409 +               (sk->sk_socket?sk->sk_socket->flags:0));
9410 +
9411 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
9412 +               return v6_addr_match(nxa, saddr, -1);
9413 +       } else if (nxi) {               /* match against nx_info */
9414 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
9415 +       } else {                        /* unrestricted any socket */
9416 +               return 1;
9417 +       }
9418 +}
9419 +
9420 +
9421 +/* inet related checks and helpers */
9422 +
9423 +
9424 +struct in_ifaddr;
9425 +struct net_device;
9426 +struct sock;
9427 +
9428 +
9429 +#include <linux/netdevice.h>
9430 +#include <linux/inetdevice.h>
9431 +#include <net/inet_timewait_sock.h>
9432 +
9433 +
9434 +int dev_in_nx_info(struct net_device *, struct nx_info *);
9435 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
9436 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
9437 +
9438 +
9439 +
9440 +static inline
9441 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
9442 +{
9443 +       if (!nxi)
9444 +               return 1;
9445 +       if (!ifa)
9446 +               return 0;
9447 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
9448 +}
9449 +
9450 +static inline
9451 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
9452 +{
9453 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
9454 +               nxi, nxi ? nxi->nx_id : 0, ifa,
9455 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
9456 +
9457 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9458 +               return 1;
9459 +       if (v6_ifa_in_nx_info(ifa, nxi))
9460 +               return 1;
9461 +       return 0;
9462 +}
9463 +
9464 +
9465 +struct nx_v6_sock_addr {
9466 +       struct in6_addr saddr;  /* Address used for validation */
9467 +       struct in6_addr baddr;  /* Address used for socket bind */
9468 +};
9469 +
9470 +static inline
9471 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
9472 +       struct nx_v6_sock_addr *nsa)
9473 +{
9474 +       // struct sock *sk = &inet->sk;
9475 +       // struct nx_info *nxi = sk->sk_nx_info;
9476 +       struct in6_addr saddr = addr->sin6_addr;
9477 +       struct in6_addr baddr = saddr;
9478 +
9479 +       nsa->saddr = saddr;
9480 +       nsa->baddr = baddr;
9481 +       return 0;
9482 +}
9483 +
9484 +static inline
9485 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
9486 +{
9487 +       // struct sock *sk = &inet->sk;
9488 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
9489 +
9490 +       // *saddr = nsa->baddr;
9491 +       // inet->inet_saddr = nsa->baddr;
9492 +}
9493 +
9494 +static inline
9495 +int nx_info_has_v6(struct nx_info *nxi)
9496 +{
9497 +       if (!nxi)
9498 +               return 1;
9499 +       if (NX_IPV6(nxi))
9500 +               return 1;
9501 +       return 0;
9502 +}
9503 +
9504 +#else /* CONFIG_IPV6 */
9505 +
9506 +static inline
9507 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
9508 +{
9509 +       return 1;
9510 +}
9511 +
9512 +
9513 +static inline
9514 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
9515 +{
9516 +       return 1;
9517 +}
9518 +
9519 +static inline
9520 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
9521 +{
9522 +       return 1;
9523 +}
9524 +
9525 +static inline
9526 +int nx_info_has_v6(struct nx_info *nxi)
9527 +{
9528 +       return 0;
9529 +}
9530 +
9531 +#endif /* CONFIG_IPV6 */
9532 +
9533 +#define current_nx_info_has_v6() \
9534 +       nx_info_has_v6(current_nx_info())
9535 +
9536 +#else
9537 +#warning duplicate inclusion
9538 +#endif
9539 diff -NurpP --minimal linux-3.10.9/include/linux/vs_limit.h linux-3.10.9-vs2.3.6.6/include/linux/vs_limit.h
9540 --- linux-3.10.9/include/linux/vs_limit.h       1970-01-01 00:00:00.000000000 +0000
9541 +++ linux-3.10.9-vs2.3.6.6/include/linux/vs_limit.h     2013-08-22 20:30:00.000000000 +0000
9542 @@ -0,0 +1,140 @@
9543 +#ifndef _VS_LIMIT_H
9544 +#define _VS_LIMIT_H
9545 +
9546 +#include "vserver/limit.h"
9547 +#include "vserver/base.h"
9548 +#include "vserver/context.h"
9549 +#include "vserver/debug.h"
9550 +#include "vserver/context.h"
9551 +#include "vserver/limit_int.h"
9552 +
9553 +
9554 +#define vx_acc_cres(v, d, p, r) \
9555 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
9556 +
9557 +#define vx_acc_cres_cond(x, d, p, r) \
9558 +       __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
9559 +       r, d, p, __FILE__, __LINE__)
9560 +
9561 +
9562 +#define vx_add_cres(v, a, p, r) \
9563 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
9564 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
9565 +
9566 +#define vx_add_cres_cond(x, a, p, r) \
9567 +       __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
9568 +       r, a, p, __FILE__, __LINE__)
9569 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
9570 +
9571 +
9572 +/* process and file limits */
9573 +
9574 +#define vx_nproc_inc(p) \
9575 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
9576 +
9577 +#define vx_nproc_dec(p) \
9578 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
9579 +
9580 +#define vx_files_inc(f) \
9581 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
9582 +
9583 +#define vx_files_dec(f) \
9584 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
9585 +
9586 +#define vx_locks_inc(l) \
9587 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
9588 +
9589 +#define vx_locks_dec(l) \
9590 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
9591 +
9592 +#define vx_openfd_inc(f) \
9593 +       vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
9594 +
9595 +#define vx_openfd_dec(f) \
9596 +       vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
9597 +
9598 +
9599 +#define vx_cres_avail(v, n, r) \
9600 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
9601 +
9602 +
9603 +#define vx_nproc_avail(n) \
9604 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
9605 +
9606 +#define vx_files_avail(n) \
9607 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
9608 +
9609 +#define vx_locks_avail(n) \
9610 +       vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
9611 +
9612 +#define vx_openfd_avail(n) \
9613 +       vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
9614 +
9615 +
9616 +/* dentry limits */
9617 +
9618 +#define vx_dentry_inc(d) do {                                          \
9619 +       if ((d)->d_count == 1)                                          \
9620 +               vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY);    \
9621 +       } while (0)
9622 +
9623 +#define vx_dentry_dec(d) do {                                          \
9624 +       if ((d)->d_count == 0)                                          \
9625 +               vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY);    \
9626 +       } while (0)
9627 +
9628 +#define vx_dentry_avail(n) \
9629 +       vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
9630 +
9631 +
9632 +/* socket limits */
9633 +
9634 +#define vx_sock_inc(s) \
9635 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
9636 +
9637 +#define vx_sock_dec(s) \
9638 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
9639 +
9640 +#define vx_sock_avail(n) \
9641 +       vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
9642 +
9643 +
9644 +/* ipc resource limits */
9645 +
9646 +#define vx_ipcmsg_add(v, u, a) \
9647 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
9648 +
9649 +#define vx_ipcmsg_sub(v, u, a) \
9650 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
9651 +
9652 +#define vx_ipcmsg_avail(v, a) \
9653 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
9654 +
9655 +
9656 +#define vx_ipcshm_add(v, k, a) \
9657 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
9658 +
9659 +#define vx_ipcshm_sub(v, k, a) \
9660 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
9661 +
9662 +#define vx_ipcshm_avail(v, a) \
9663 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
9664 +
9665 +
9666 +#define vx_semary_inc(a) \
9667 +       vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
9668 +
9669 +#define vx_semary_dec(a) \
9670 +       vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
9671 +
9672 +
9673 +#define vx_nsems_add(a,n) \
9674 +       vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
9675 +
9676 +#define vx_nsems_sub(a,n) \
9677 +       vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
9678 +
9679 +
9680 +#else
9681 +#warning duplicate inclusion
9682 +#endif
9683 diff -NurpP --minimal linux-3.10.9/include/linux/vs_network.h linux-3.10.9-vs2.3.6.6/include/linux/vs_network.h
9684 --- linux-3.10.9/include/linux/vs_network.h     1970-01-01 00:00:00.000000000 +0000
9685 +++ linux-3.10.9-vs2.3.6.6/include/linux/vs_network.h   2013-08-22 20:30:00.000000000 +0000
9686 @@ -0,0 +1,169 @@
9687 +#ifndef _NX_VS_NETWORK_H
9688 +#define _NX_VS_NETWORK_H
9689 +
9690 +#include "vserver/context.h"
9691 +#include "vserver/network.h"
9692 +#include "vserver/base.h"
9693 +#include "vserver/check.h"
9694 +#include "vserver/debug.h"
9695 +
9696 +#include <linux/sched.h>
9697 +
9698 +
9699 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
9700 +
9701 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
9702 +       const char *_file, int _line)
9703 +{
9704 +       if (!nxi)
9705 +               return NULL;
9706 +
9707 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
9708 +               nxi, nxi ? nxi->nx_id : 0,
9709 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9710 +               _file, _line);
9711 +
9712 +       atomic_inc(&nxi->nx_usecnt);
9713 +       return nxi;
9714 +}
9715 +
9716 +
9717 +extern void free_nx_info(struct nx_info *);
9718 +
9719 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
9720 +
9721 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
9722 +{
9723 +       if (!nxi)
9724 +               return;
9725 +
9726 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
9727 +               nxi, nxi ? nxi->nx_id : 0,
9728 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9729 +               _file, _line);
9730 +
9731 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
9732 +               free_nx_info(nxi);
9733 +}
9734 +
9735 +
9736 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
9737 +
9738 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
9739 +               const char *_file, int _line)
9740 +{
9741 +       if (nxi) {
9742 +               vxlprintk(VXD_CBIT(nid, 3),
9743 +                       "init_nx_info(%p[#%d.%d])",
9744 +                       nxi, nxi ? nxi->nx_id : 0,
9745 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9746 +                       _file, _line);
9747 +
9748 +               atomic_inc(&nxi->nx_usecnt);
9749 +       }
9750 +       *nxp = nxi;
9751 +}
9752 +
9753 +
9754 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
9755 +
9756 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
9757 +       const char *_file, int _line)
9758 +{
9759 +       struct nx_info *nxo;
9760 +
9761 +       if (!nxi)
9762 +               return;
9763 +
9764 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
9765 +               nxi, nxi ? nxi->nx_id : 0,
9766 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9767 +               _file, _line);
9768 +
9769 +       atomic_inc(&nxi->nx_usecnt);
9770 +       nxo = xchg(nxp, nxi);
9771 +       BUG_ON(nxo);
9772 +}
9773 +
9774 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
9775 +
9776 +static inline void __clr_nx_info(struct nx_info **nxp,
9777 +       const char *_file, int _line)
9778 +{
9779 +       struct nx_info *nxo;
9780 +
9781 +       nxo = xchg(nxp, NULL);
9782 +       if (!nxo)
9783 +               return;
9784 +
9785 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
9786 +               nxo, nxo ? nxo->nx_id : 0,
9787 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
9788 +               _file, _line);
9789 +
9790 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
9791 +               free_nx_info(nxo);
9792 +}
9793 +
9794 +
9795 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
9796 +
9797 +static inline void __claim_nx_info(struct nx_info *nxi,
9798 +       struct task_struct *task, const char *_file, int _line)
9799 +{
9800 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
9801 +               nxi, nxi ? nxi->nx_id : 0,
9802 +               nxi?atomic_read(&nxi->nx_usecnt):0,
9803 +               nxi?atomic_read(&nxi->nx_tasks):0,
9804 +               task, _file, _line);
9805 +
9806 +       atomic_inc(&nxi->nx_tasks);
9807 +}
9808 +
9809 +
9810 +extern void unhash_nx_info(struct nx_info *);
9811 +
9812 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
9813 +
9814 +static inline void __release_nx_info(struct nx_info *nxi,
9815 +       struct task_struct *task, const char *_file, int _line)
9816 +{
9817 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
9818 +               nxi, nxi ? nxi->nx_id : 0,
9819 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9820 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
9821 +               task, _file, _line);
9822 +
9823 +       might_sleep();
9824 +
9825 +       if (atomic_dec_and_test(&nxi->nx_tasks))
9826 +               unhash_nx_info(nxi);
9827 +}
9828 +
9829 +
9830 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
9831 +
9832 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
9833 +       const char *_file, int _line)
9834 +{
9835 +       struct nx_info *nxi;
9836 +
9837 +       task_lock(p);
9838 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
9839 +               p, _file, _line);
9840 +       nxi = __get_nx_info(p->nx_info, _file, _line);
9841 +       task_unlock(p);
9842 +       return nxi;
9843 +}
9844 +
9845 +
9846 +static inline void exit_nx_info(struct task_struct *p)
9847 +{
9848 +       if (p->nx_info)
9849 +               release_nx_info(p->nx_info, p);
9850 +}
9851 +
9852 +
9853 +#else
9854 +#warning duplicate inclusion
9855 +#endif
9856 diff -NurpP --minimal linux-3.10.9/include/linux/vs_pid.h linux-3.10.9-vs2.3.6.6/include/linux/vs_pid.h
9857 --- linux-3.10.9/include/linux/vs_pid.h 1970-01-01 00:00:00.000000000 +0000
9858 +++ linux-3.10.9-vs2.3.6.6/include/linux/vs_pid.h       2013-08-22 20:30:00.000000000 +0000
9859 @@ -0,0 +1,50 @@
9860 +#ifndef _VS_PID_H
9861 +#define _VS_PID_H
9862 +
9863 +#include "vserver/base.h"
9864 +#include "vserver/check.h"
9865 +#include "vserver/context.h"
9866 +#include "vserver/debug.h"
9867 +#include "vserver/pid.h"
9868 +#include <linux/pid_namespace.h>
9869 +
9870 +
9871 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
9872 +
9873 +static inline
9874 +int vx_proc_task_visible(struct task_struct *task)
9875 +{
9876 +       if ((task->pid == 1) &&
9877 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
9878 +               /* show a blend through init */
9879 +               goto visible;
9880 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
9881 +               goto visible;
9882 +       return 0;
9883 +visible:
9884 +       return 1;
9885 +}
9886 +
9887 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
9888 +
9889 +
9890 +static inline
9891 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
9892 +{
9893 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
9894 +
9895 +       if (task && !vx_proc_task_visible(task)) {
9896 +               vxdprintk(VXD_CBIT(misc, 6),
9897 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
9898 +                       task, task->xid, task->pid,
9899 +                       current, current->xid, current->pid);
9900 +               put_task_struct(task);
9901 +               task = NULL;
9902 +       }
9903 +       return task;
9904 +}
9905 +
9906 +
9907 +#else
9908 +#warning duplicate inclusion
9909 +#endif
9910 diff -NurpP --minimal linux-3.10.9/include/linux/vs_sched.h linux-3.10.9-vs2.3.6.6/include/linux/vs_sched.h
9911 --- linux-3.10.9/include/linux/vs_sched.h       1970-01-01 00:00:00.000000000 +0000
9912 +++ linux-3.10.9-vs2.3.6.6/include/linux/vs_sched.h     2013-08-22 20:30:00.000000000 +0000
9913 @@ -0,0 +1,40 @@
9914 +#ifndef _VS_SCHED_H
9915 +#define _VS_SCHED_H
9916 +
9917 +#include "vserver/base.h"
9918 +#include "vserver/context.h"
9919 +#include "vserver/sched.h"
9920 +
9921 +
9922 +#define MAX_PRIO_BIAS           20
9923 +#define MIN_PRIO_BIAS          -20
9924 +
9925 +static inline
9926 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
9927 +{
9928 +       struct vx_info *vxi = p->vx_info;
9929 +
9930 +       if (vxi)
9931 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
9932 +       return prio;
9933 +}
9934 +
9935 +static inline void vx_account_user(struct vx_info *vxi,
9936 +       cputime_t cputime, int nice)
9937 +{
9938 +       if (!vxi)
9939 +               return;
9940 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
9941 +}
9942 +
9943 +static inline void vx_account_system(struct vx_info *vxi,
9944 +       cputime_t cputime, int idle)
9945 +{
9946 +       if (!vxi)
9947 +               return;
9948 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
9949 +}
9950 +
9951 +#else
9952 +#warning duplicate inclusion
9953 +#endif
9954 diff -NurpP --minimal linux-3.10.9/include/linux/vs_socket.h linux-3.10.9-vs2.3.6.6/include/linux/vs_socket.h
9955 --- linux-3.10.9/include/linux/vs_socket.h      1970-01-01 00:00:00.000000000 +0000
9956 +++ linux-3.10.9-vs2.3.6.6/include/linux/vs_socket.h    2013-08-22 20:30:00.000000000 +0000
9957 @@ -0,0 +1,67 @@
9958 +#ifndef _VS_SOCKET_H
9959 +#define _VS_SOCKET_H
9960 +
9961 +#include "vserver/debug.h"
9962 +#include "vserver/base.h"
9963 +#include "vserver/cacct.h"
9964 +#include "vserver/context.h"
9965 +#include "vserver/tag.h"
9966 +
9967 +
9968 +/* socket accounting */
9969 +
9970 +#include <linux/socket.h>
9971 +
9972 +static inline int vx_sock_type(int family)
9973 +{
9974 +       switch (family) {
9975 +       case PF_UNSPEC:
9976 +               return VXA_SOCK_UNSPEC;
9977 +       case PF_UNIX:
9978 +               return VXA_SOCK_UNIX;
9979 +       case PF_INET:
9980 +               return VXA_SOCK_INET;
9981 +       case PF_INET6:
9982 +               return VXA_SOCK_INET6;
9983 +       case PF_PACKET:
9984 +               return VXA_SOCK_PACKET;
9985 +       default:
9986 +               return VXA_SOCK_OTHER;
9987 +       }
9988 +}
9989 +
9990 +#define vx_acc_sock(v, f, p, s) \
9991 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
9992 +
9993 +static inline void __vx_acc_sock(struct vx_info *vxi,
9994 +       int family, int pos, int size, char *file, int line)
9995 +{
9996 +       if (vxi) {
9997 +               int type = vx_sock_type(family);
9998 +
9999 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
10000 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
10001 +       }
10002 +}
10003 +
10004 +#define vx_sock_recv(sk, s) \
10005 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
10006 +#define vx_sock_send(sk, s) \
10007 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
10008 +#define vx_sock_fail(sk, s) \
10009 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
10010 +
10011 +
10012 +#define sock_vx_init(s) do {           \
10013 +       (s)->sk_xid = 0;                \
10014 +       (s)->sk_vx_info = NULL;         \
10015 +       } while (0)
10016 +
10017 +#define sock_nx_init(s) do {           \
10018 +       (s)->sk_nid = 0;                \
10019 +       (s)->sk_nx_info = NULL;         \
10020 +       } while (0)
10021 +
10022 +#else
10023 +#warning duplicate inclusion
10024 +#endif
10025 diff -NurpP --minimal linux-3.10.9/include/linux/vs_tag.h linux-3.10.9-vs2.3.6.6/include/linux/vs_tag.h
10026 --- linux-3.10.9/include/linux/vs_tag.h 1970-01-01 00:00:00.000000000 +0000
10027 +++ linux-3.10.9-vs2.3.6.6/include/linux/vs_tag.h       2013-08-22 20:30:00.000000000 +0000
10028 @@ -0,0 +1,47 @@
10029 +#ifndef _VS_TAG_H
10030 +#define _VS_TAG_H
10031 +
10032 +#include <linux/vserver/tag.h>
10033 +
10034 +/* check conditions */
10035 +
10036 +#define DX_ADMIN       0x0001
10037 +#define DX_WATCH       0x0002
10038 +#define DX_HOSTID      0x0008
10039 +
10040 +#define DX_IDENT       0x0010
10041 +
10042 +#define DX_ARG_MASK    0x0010
10043 +
10044 +
10045 +#define dx_task_tag(t) ((t)->tag)
10046 +
10047 +#define dx_current_tag() dx_task_tag(current)
10048 +
10049 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
10050 +
10051 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
10052 +
10053 +
10054 +/*
10055 + * check current context for ADMIN/WATCH and
10056 + * optionally against supplied argument
10057 + */
10058 +static inline int __dx_check(vtag_t cid, vtag_t id, unsigned int mode)
10059 +{
10060 +       if (mode & DX_ARG_MASK) {
10061 +               if ((mode & DX_IDENT) && (id == cid))
10062 +                       return 1;
10063 +       }
10064 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
10065 +               ((mode & DX_WATCH) && (cid == 1)) ||
10066 +               ((mode & DX_HOSTID) && (id == 0)));
10067 +}
10068 +
10069 +struct inode;
10070 +int dx_permission(const struct inode *inode, int mask);
10071 +
10072 +
10073 +#else
10074 +#warning duplicate inclusion
10075 +#endif
10076 diff -NurpP --minimal linux-3.10.9/include/linux/vs_time.h linux-3.10.9-vs2.3.6.6/include/linux/vs_time.h
10077 --- linux-3.10.9/include/linux/vs_time.h        1970-01-01 00:00:00.000000000 +0000
10078 +++ linux-3.10.9-vs2.3.6.6/include/linux/vs_time.h      2013-08-22 20:30:00.000000000 +0000
10079 @@ -0,0 +1,19 @@
10080 +#ifndef _VS_TIME_H
10081 +#define _VS_TIME_H
10082 +
10083 +
10084 +/* time faking stuff */
10085 +
10086 +#ifdef CONFIG_VSERVER_VTIME
10087 +
10088 +extern void vx_adjust_timespec(struct timespec *ts);
10089 +extern int vx_settimeofday(const struct timespec *ts);
10090 +
10091 +#else
10092 +#define        vx_adjust_timespec(t)   do { } while (0)
10093 +#define        vx_settimeofday(t)      do_settimeofday(t)
10094 +#endif
10095 +
10096 +#else
10097 +#warning duplicate inclusion
10098 +#endif
10099 diff -NurpP --minimal linux-3.10.9/include/linux/vserver/base.h linux-3.10.9-vs2.3.6.6/include/linux/vserver/base.h
10100 --- linux-3.10.9/include/linux/vserver/base.h   1970-01-01 00:00:00.000000000 +0000
10101 +++ linux-3.10.9-vs2.3.6.6/include/linux/vserver/base.h 2013-08-22 20:30:00.000000000 +0000
10102 @@ -0,0 +1,181 @@
10103 +#ifndef _VSERVER_BASE_H
10104 +#define _VSERVER_BASE_H
10105 +
10106 +
10107 +/* context state changes */
10108 +
10109 +enum {
10110 +       VSC_STARTUP = 1,
10111 +       VSC_SHUTDOWN,
10112 +
10113 +       VSC_NETUP,
10114 +       VSC_NETDOWN,
10115 +};
10116 +
10117 +
10118 +
10119 +#define vx_task_xid(t) ((t)->xid)
10120 +
10121 +#define vx_current_xid() vx_task_xid(current)
10122 +
10123 +#define current_vx_info() (current->vx_info)
10124 +
10125 +
10126 +#define nx_task_nid(t) ((t)->nid)
10127 +
10128 +#define nx_current_nid() nx_task_nid(current)
10129 +
10130 +#define current_nx_info() (current->nx_info)
10131 +
10132 +
10133 +/* generic flag merging */
10134 +
10135 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
10136 +
10137 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
10138 +
10139 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
10140 +
10141 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
10142 +
10143 +
10144 +/* context flags */
10145 +
10146 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
10147 +
10148 +#define vx_current_flags()     __vx_flags(current_vx_info())
10149 +
10150 +#define vx_info_flags(v, m, f) \
10151 +       vs_check_flags(__vx_flags(v), m, f)
10152 +
10153 +#define task_vx_flags(t, m, f) \
10154 +       ((t) && vx_info_flags((t)->vx_info, m, f))
10155 +
10156 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
10157 +
10158 +
10159 +/* context caps */
10160 +
10161 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
10162 +
10163 +#define vx_current_ccaps()     __vx_ccaps(current_vx_info())
10164 +
10165 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
10166 +
10167 +#define vx_ccaps(c)    vx_info_ccaps(current_vx_info(), (c))
10168 +
10169 +
10170 +
10171 +/* network flags */
10172 +
10173 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
10174 +
10175 +#define nx_current_flags()     __nx_flags(current_nx_info())
10176 +
10177 +#define nx_info_flags(n, m, f) \
10178 +       vs_check_flags(__nx_flags(n), m, f)
10179 +
10180 +#define task_nx_flags(t, m, f) \
10181 +       ((t) && nx_info_flags((t)->nx_info, m, f))
10182 +
10183 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
10184 +
10185 +
10186 +/* network caps */
10187 +
10188 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
10189 +
10190 +#define nx_current_ncaps()     __nx_ncaps(current_nx_info())
10191 +
10192 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
10193 +
10194 +#define nx_ncaps(c)    nx_info_ncaps(current_nx_info(), c)
10195 +
10196 +
10197 +/* context mask capabilities */
10198 +
10199 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
10200 +
10201 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
10202 +
10203 +#define vx_mcaps(c)    vx_info_mcaps(current_vx_info(), c)
10204 +
10205 +
10206 +/* context bcap mask */
10207 +
10208 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
10209 +
10210 +#define vx_current_bcaps()     __vx_bcaps(current_vx_info())
10211 +
10212 +
10213 +/* mask given bcaps */
10214 +
10215 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
10216 +
10217 +#define vx_mbcaps(c)           vx_info_mbcaps(current_vx_info(), c)
10218 +
10219 +
10220 +/* masked cap_bset */
10221 +
10222 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
10223 +
10224 +#define vx_current_cap_bset()  vx_info_cap_bset(current_vx_info())
10225 +
10226 +#if 0
10227 +#define vx_info_mbcap(v, b) \
10228 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
10229 +       vx_info_bcaps(v, b) : (b))
10230 +
10231 +#define task_vx_mbcap(t, b) \
10232 +       vx_info_mbcap((t)->vx_info, (t)->b)
10233 +
10234 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
10235 +#endif
10236 +
10237 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
10238 +
10239 +#define vx_capable(b, c) (capable(b) || \
10240 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10241 +
10242 +#define vx_ns_capable(n, b, c) (ns_capable(n, b) || \
10243 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10244 +
10245 +#define nx_capable(b, c) (capable(b) || \
10246 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
10247 +
10248 +#define vx_task_initpid(t, n) \
10249 +       ((t)->vx_info && \
10250 +       ((t)->vx_info->vx_initpid == (n)))
10251 +
10252 +#define vx_current_initpid(n)  vx_task_initpid(current, n)
10253 +
10254 +
10255 +/* context unshare mask */
10256 +
10257 +#define __vx_umask(v)          ((v)->vx_umask)
10258 +
10259 +#define vx_current_umask()     __vx_umask(current_vx_info())
10260 +
10261 +#define vx_can_unshare(b, f) (capable(b) || \
10262 +       (cap_raised(current_cap(), b) && \
10263 +       !((f) & ~vx_current_umask())))
10264 +
10265 +#define vx_ns_can_unshare(n, b, f) (ns_capable(n, b) || \
10266 +       (cap_raised(current_cap(), b) && \
10267 +       !((f) & ~vx_current_umask())))
10268 +
10269 +#define __vx_wmask(v)          ((v)->vx_wmask)
10270 +
10271 +#define vx_current_wmask()     __vx_wmask(current_vx_info())
10272 +
10273 +
10274 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
10275 +
10276 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
10277 +
10278 +
10279 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
10280 +
10281 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
10282 +
10283 +#endif
10284 diff -NurpP --minimal linux-3.10.9/include/linux/vserver/cacct.h linux-3.10.9-vs2.3.6.6/include/linux/vserver/cacct.h
10285 --- linux-3.10.9/include/linux/vserver/cacct.h  1970-01-01 00:00:00.000000000 +0000
10286 +++ linux-3.10.9-vs2.3.6.6/include/linux/vserver/cacct.h        2013-08-22 20:30:00.000000000 +0000
10287 @@ -0,0 +1,15 @@
10288 +#ifndef _VSERVER_CACCT_H
10289 +#define _VSERVER_CACCT_H
10290 +
10291 +
10292 +enum sock_acc_field {
10293 +       VXA_SOCK_UNSPEC = 0,
10294 +       VXA_SOCK_UNIX,
10295 +       VXA_SOCK_INET,
10296 +       VXA_SOCK_INET6,
10297 +       VXA_SOCK_PACKET,
10298 +       VXA_SOCK_OTHER,
10299 +       VXA_SOCK_SIZE   /* array size */
10300 +};
10301 +
10302 +#endif /* _VSERVER_CACCT_H */
10303 diff -NurpP --minimal linux-3.10.9/include/linux/vserver/cacct_cmd.h linux-3.10.9-vs2.3.6.6/include/linux/vserver/cacct_cmd.h
10304 --- linux-3.10.9/include/linux/vserver/cacct_cmd.h      1970-01-01 00:00:00.000000000 +0000
10305 +++ linux-3.10.9-vs2.3.6.6/include/linux/vserver/cacct_cmd.h    2013-08-22 20:30:00.000000000 +0000
10306 @@ -0,0 +1,10 @@
10307 +#ifndef _VSERVER_CACCT_CMD_H
10308 +#define _VSERVER_CACCT_CMD_H
10309 +
10310 +
10311 +#include <linux/compiler.h>
10312 +#include <uapi/vserver/cacct_cmd.h>
10313 +
10314 +extern int vc_sock_stat(struct vx_info *, void __user *);
10315 +
10316 +#endif /* _VSERVER_CACCT_CMD_H */
10317 diff -NurpP --minimal linux-3.10.9/include/linux/vserver/cacct_def.h linux-3.10.9-vs2.3.6.6/include/linux/vserver/cacct_def.h
10318 --- linux-3.10.9/include/linux/vserver/cacct_def.h      1970-01-01 00:00:00.000000000 +0000
10319 +++ linux-3.10.9-vs2.3.6.6/include/linux/vserver/cacct_def.h    2013-08-22 20:30:00.000000000 +0000
10320 @@ -0,0 +1,43 @@
10321 +#ifndef _VSERVER_CACCT_DEF_H
10322 +#define _VSERVER_CACCT_DEF_H
10323 +
10324 +#include <asm/atomic.h>
10325 +#include <linux/vserver/cacct.h>
10326 +
10327 +
10328 +struct _vx_sock_acc {
10329 +       atomic_long_t count;
10330 +       atomic_long_t total;
10331 +};
10332 +
10333 +/* context sub struct */
10334 +
10335 +struct _vx_cacct {
10336 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
10337 +       atomic_t slab[8];
10338 +       atomic_t page[6][8];
10339 +};
10340 +
10341 +#ifdef CONFIG_VSERVER_DEBUG
10342 +
10343 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
10344 +{
10345 +       int i, j;
10346 +
10347 +       printk("\t_vx_cacct:");
10348 +       for (i = 0; i < 6; i++) {
10349 +               struct _vx_sock_acc *ptr = cacct->sock[i];
10350 +
10351 +               printk("\t [%d] =", i);
10352 +               for (j = 0; j < 3; j++) {
10353 +                       printk(" [%d] = %8lu, %8lu", j,
10354 +                               atomic_long_read(&ptr[j].count),
10355 +                               atomic_long_read(&ptr[j].total));
10356 +               }
10357 +               printk("\n");
10358 +       }
10359 +}
10360 +
10361 +#endif
10362 +
10363 +#endif /* _VSERVER_CACCT_DEF_H */
10364 diff -NurpP --minimal linux-3.10.9/include/linux/vserver/cacct_int.h linux-3.10.9-vs2.3.6.6/include/linux/vserver/cacct_int.h
10365 --- linux-3.10.9/include/linux/vserver/cacct_int.h      1970-01-01 00:00:00.000000000 +0000
10366 +++ linux-3.10.9-vs2.3.6.6/include/linux/vserver/cacct_int.h    2013-08-22 20:30:00.000000000 +0000
10367 @@ -0,0 +1,17 @@
10368 +#ifndef _VSERVER_CACCT_INT_H
10369 +#define _VSERVER_CACCT_INT_H
10370 +
10371 +static inline
10372 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
10373 +{
10374 +       return atomic_long_read(&cacct->sock[type][pos].count);
10375 +}
10376 +
10377 +
10378 +static inline
10379 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
10380 +{
10381 +       return atomic_long_read(&cacct->sock[type][pos].total);
10382 +}
10383 +
10384 +#endif /* _VSERVER_CACCT_INT_H */
10385 diff -NurpP --minimal linux-3.10.9/include/linux/vserver/check.h linux-3.10.9-vs2.3.6.6/include/linux/vserver/check.h
10386 --- linux-3.10.9/include/linux/vserver/check.h  1970-01-01 00:00:00.000000000 +0000
10387 +++ linux-3.10.9-vs2.3.6.6/include/linux/vserver/check.h        2013-08-22 20:30:00.000000000 +0000
10388 @@ -0,0 +1,89 @@
10389 +#ifndef _VSERVER_CHECK_H
10390 +#define _VSERVER_CHECK_H
10391 +
10392 +
10393 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
10394 +
10395 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
10396 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
10397 +#else
10398 +#define MIN_D_CONTEXT  65536
10399 +#endif
10400 +
10401 +/* check conditions */
10402 +
10403 +#define VS_ADMIN       0x0001
10404 +#define VS_WATCH       0x0002
10405 +#define VS_HIDE                0x0004
10406 +#define VS_HOSTID      0x0008
10407 +
10408 +#define VS_IDENT       0x0010
10409 +#define VS_EQUIV       0x0020
10410 +#define VS_PARENT      0x0040
10411 +#define VS_CHILD       0x0080
10412 +
10413 +#define VS_ARG_MASK    0x00F0
10414 +
10415 +#define VS_DYNAMIC     0x0100
10416 +#define VS_STATIC      0x0200
10417 +
10418 +#define VS_ATR_MASK    0x0F00
10419 +
10420 +#ifdef CONFIG_VSERVER_PRIVACY
10421 +#define VS_ADMIN_P     (0)
10422 +#define VS_WATCH_P     (0)
10423 +#else
10424 +#define VS_ADMIN_P     VS_ADMIN
10425 +#define VS_WATCH_P     VS_WATCH
10426 +#endif
10427 +
10428 +#define VS_HARDIRQ     0x1000
10429 +#define VS_SOFTIRQ     0x2000
10430 +#define VS_IRQ         0x4000
10431 +
10432 +#define VS_IRQ_MASK    0xF000
10433 +
10434 +#include <linux/hardirq.h>
10435 +
10436 +/*
10437 + * check current context for ADMIN/WATCH and
10438 + * optionally against supplied argument
10439 + */
10440 +static inline int __vs_check(int cid, int id, unsigned int mode)
10441 +{
10442 +       if (mode & VS_ARG_MASK) {
10443 +               if ((mode & VS_IDENT) && (id == cid))
10444 +                       return 1;
10445 +       }
10446 +       if (mode & VS_ATR_MASK) {
10447 +               if ((mode & VS_DYNAMIC) &&
10448 +                       (id >= MIN_D_CONTEXT) &&
10449 +                       (id <= MAX_S_CONTEXT))
10450 +                       return 1;
10451 +               if ((mode & VS_STATIC) &&
10452 +                       (id > 1) && (id < MIN_D_CONTEXT))
10453 +                       return 1;
10454 +       }
10455 +       if (mode & VS_IRQ_MASK) {
10456 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
10457 +                       return 1;
10458 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
10459 +                       return 1;
10460 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
10461 +                       return 1;
10462 +       }
10463 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
10464 +               ((mode & VS_WATCH) && (cid == 1)) ||
10465 +               ((mode & VS_HOSTID) && (id == 0)));
10466 +}
10467 +
10468 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
10469 +
10470 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
10471 +
10472 +
10473 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
10474 +
10475 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
10476 +
10477 +#endif
10478 diff -NurpP --minimal linux-3.10.9/include/linux/vserver/context.h linux-3.10.9-vs2.3.6.6/include/linux/vserver/context.h
10479 --- linux-3.10.9/include/linux/vserver/context.h        1970-01-01 00:00:00.000000000 +0000
10480 +++ linux-3.10.9-vs2.3.6.6/include/linux/vserver/context.h      2013-08-22 20:30:00.000000000 +0000
10481 @@ -0,0 +1,110 @@
10482 +#ifndef _VSERVER_CONTEXT_H
10483 +#define _VSERVER_CONTEXT_H
10484 +
10485 +
10486 +#include <linux/list.h>
10487 +#include <linux/spinlock.h>
10488 +#include <linux/rcupdate.h>
10489 +#include <uapi/vserver/context.h>
10490 +
10491 +#include "limit_def.h"
10492 +#include "sched_def.h"
10493 +#include "cvirt_def.h"
10494 +#include "cacct_def.h"
10495 +#include "device_def.h"
10496 +
10497 +#define VX_SPACES      2
10498 +
10499 +struct _vx_info_pc {
10500 +       struct _vx_sched_pc sched_pc;
10501 +       struct _vx_cvirt_pc cvirt_pc;
10502 +};
10503 +
10504 +struct _vx_space {
10505 +       unsigned long vx_nsmask;                /* assignment mask */
10506 +       struct nsproxy *vx_nsproxy;             /* private namespaces */
10507 +       struct fs_struct *vx_fs;                /* private namespace fs */
10508 +       const struct cred *vx_cred;             /* task credentials */
10509 +};
10510 +
10511 +struct vx_info {
10512 +       struct hlist_node vx_hlist;             /* linked list of contexts */
10513 +       vxid_t vx_id;                           /* context id */
10514 +       atomic_t vx_usecnt;                     /* usage count */
10515 +       atomic_t vx_tasks;                      /* tasks count */
10516 +       struct vx_info *vx_parent;              /* parent context */
10517 +       int vx_state;                           /* context state */
10518 +
10519 +       struct _vx_space space[VX_SPACES];      /* namespace store */
10520 +
10521 +       uint64_t vx_flags;                      /* context flags */
10522 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
10523 +       uint64_t vx_umask;                      /* unshare mask (guest) */
10524 +       uint64_t vx_wmask;                      /* warn mask (guest) */
10525 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
10526 +
10527 +       struct task_struct *vx_reaper;          /* guest reaper process */
10528 +       pid_t vx_initpid;                       /* PID of guest init */
10529 +       int64_t vx_badness_bias;                /* OOM points bias */
10530 +
10531 +       struct _vx_limit limit;                 /* vserver limits */
10532 +       struct _vx_sched sched;                 /* vserver scheduler */
10533 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
10534 +       struct _vx_cacct cacct;                 /* context accounting */
10535 +
10536 +       struct _vx_device dmap;                 /* default device map targets */
10537 +
10538 +#ifndef CONFIG_SMP
10539 +       struct _vx_info_pc info_pc;             /* per cpu data */
10540 +#else
10541 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
10542 +#endif
10543 +
10544 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
10545 +       int reboot_cmd;                         /* last sys_reboot() cmd */
10546 +       int exit_code;                          /* last process exit code */
10547 +
10548 +       char vx_name[65];                       /* vserver name */
10549 +};
10550 +
10551 +#ifndef CONFIG_SMP
10552 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
10553 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
10554 +#else
10555 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
10556 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
10557 +#endif
10558 +
10559 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
10560 +
10561 +
10562 +struct vx_info_save {
10563 +       struct vx_info *vxi;
10564 +       vxid_t xid;
10565 +};
10566 +
10567 +
10568 +/* status flags */
10569 +
10570 +#define VXS_HASHED     0x0001
10571 +#define VXS_PAUSED     0x0010
10572 +#define VXS_SHUTDOWN   0x0100
10573 +#define VXS_HELPER     0x1000
10574 +#define VXS_RELEASED   0x8000
10575 +
10576 +
10577 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
10578 +extern void release_vx_info(struct vx_info *, struct task_struct *);
10579 +
10580 +extern struct vx_info *lookup_vx_info(int);
10581 +extern struct vx_info *lookup_or_create_vx_info(int);
10582 +
10583 +extern int get_xid_list(int, unsigned int *, int);
10584 +extern int xid_is_hashed(vxid_t);
10585 +
10586 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
10587 +
10588 +extern long vs_state_change(struct vx_info *, unsigned int);
10589 +
10590 +
10591 +#endif /* _VSERVER_CONTEXT_H */
10592 diff -NurpP --minimal linux-3.10.9/include/linux/vserver/context_cmd.h linux-3.10.9-vs2.3.6.6/include/linux/vserver/context_cmd.h
10593 --- linux-3.10.9/include/linux/vserver/context_cmd.h    1970-01-01 00:00:00.000000000 +0000
10594 +++ linux-3.10.9-vs2.3.6.6/include/linux/vserver/context_cmd.h  2013-08-22 20:30:00.000000000 +0000
10595 @@ -0,0 +1,33 @@
10596 +#ifndef _VSERVER_CONTEXT_CMD_H
10597 +#define _VSERVER_CONTEXT_CMD_H
10598 +
10599 +#include <uapi/vserver/context_cmd.h>
10600 +
10601 +extern int vc_task_xid(uint32_t);
10602 +
10603 +extern int vc_vx_info(struct vx_info *, void __user *);
10604 +
10605 +extern int vc_ctx_stat(struct vx_info *, void __user *);
10606 +
10607 +extern int vc_ctx_create(uint32_t, void __user *);
10608 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
10609 +
10610 +extern int vc_get_cflags(struct vx_info *, void __user *);
10611 +extern int vc_set_cflags(struct vx_info *, void __user *);
10612 +
10613 +extern int vc_get_ccaps(struct vx_info *, void __user *);
10614 +extern int vc_set_ccaps(struct vx_info *, void __user *);
10615 +
10616 +extern int vc_get_bcaps(struct vx_info *, void __user *);
10617 +extern int vc_set_bcaps(struct vx_info *, void __user *);
10618 +
10619 +extern int vc_get_umask(struct vx_info *, void __user *);
10620 +extern int vc_set_umask(struct vx_info *, void __user *);
10621 +
10622 +extern int vc_get_wmask(struct vx_info *, void __user *);
10623 +extern int vc_set_wmask(struct vx_info *, void __user *);
10624 +
10625 +extern int vc_get_badness(struct vx_info *, void __user *);
10626 +extern int vc_set_badness(struct vx_info *, void __user *);
10627 +
10628 +#endif /* _VSERVER_CONTEXT_CMD_H */
10629 diff -NurpP --minimal linux-3.10.9/include/linux/vserver/cvirt.h linux-3.10.9-vs2.3.6.6/include/linux/vserver/cvirt.h
10630 --- linux-3.10.9/include/linux/vserver/cvirt.h  1970-01-01 00:00:00.000000000 +0000
10631 +++ linux-3.10.9-vs2.3.6.6/include/linux/vserver/cvirt.h        2013-08-22 20:30:00.000000000 +0000
10632 @@ -0,0 +1,18 @@
10633 +#ifndef _VSERVER_CVIRT_H
10634 +#define _VSERVER_CVIRT_H
10635 +
10636 +struct timespec;
10637 +
10638 +void vx_vsi_boottime(struct timespec *);
10639 +
10640 +void vx_vsi_uptime(struct timespec *, struct timespec *);
10641 +
10642 +
10643 +struct vx_info;
10644 +
10645 +void vx_update_load(struct vx_info *);
10646 +
10647 +
10648 +int vx_do_syslog(int, char __user *, int);
10649 +
10650 +#endif /* _VSERVER_CVIRT_H */
10651 diff -NurpP --minimal linux-3.10.9/include/linux/vserver/cvirt_cmd.h linux-3.10.9-vs2.3.6.6/include/linux/vserver/cvirt_cmd.h
10652 --- linux-3.10.9/include/linux/vserver/cvirt_cmd.h      1970-01-01 00:00:00.000000000 +0000
10653 +++ linux-3.10.9-vs2.3.6.6/include/linux/vserver/cvirt_cmd.h    2013-08-22 20:30:00.000000000 +0000
10654 @@ -0,0 +1,13 @@
10655 +#ifndef _VSERVER_CVIRT_CMD_H
10656 +#define _VSERVER_CVIRT_CMD_H
10657 +
10658 +
10659 +#include <linux/compiler.h>
10660 +#include <uapi/vserver/cvirt_cmd.h>
10661 +
10662 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
10663 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
10664 +
10665 +extern int vc_virt_stat(struct vx_info *, void __user *);
10666 +
10667 +#endif /* _VSERVER_CVIRT_CMD_H */
10668 diff -NurpP --minimal linux-3.10.9/include/linux/vserver/cvirt_def.h linux-3.10.9-vs2.3.6.6/include/linux/vserver/cvirt_def.h
10669 --- linux-3.10.9/include/linux/vserver/cvirt_def.h      1970-01-01 00:00:00.000000000 +0000
10670 +++ linux-3.10.9-vs2.3.6.6/include/linux/vserver/cvirt_def.h    2013-08-22 20:30:00.000000000 +0000
10671 @@ -0,0 +1,80 @@
10672 +#ifndef _VSERVER_CVIRT_DEF_H
10673 +#define _VSERVER_CVIRT_DEF_H
10674 +
10675 +#include <linux/jiffies.h>
10676 +#include <linux/spinlock.h>
10677 +#include <linux/wait.h>
10678 +#include <linux/time.h>
10679 +#include <asm/atomic.h>
10680 +
10681 +
10682 +struct _vx_usage_stat {
10683 +       uint64_t user;
10684 +       uint64_t nice;
10685 +       uint64_t system;
10686 +       uint64_t softirq;
10687 +       uint64_t irq;
10688 +       uint64_t idle;
10689 +       uint64_t iowait;
10690 +};
10691 +
10692 +struct _vx_syslog {
10693 +       wait_queue_head_t log_wait;
10694 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
10695 +
10696 +       unsigned long log_start;        /* next char to be read by syslog() */
10697 +       unsigned long con_start;        /* next char to be sent to consoles */
10698 +       unsigned long log_end;  /* most-recently-written-char + 1 */
10699 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
10700 +
10701 +       char log_buf[1024];
10702 +};
10703 +
10704 +
10705 +/* context sub struct */
10706 +
10707 +struct _vx_cvirt {
10708 +       atomic_t nr_threads;            /* number of current threads */
10709 +       atomic_t nr_running;            /* number of running threads */
10710 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
10711 +
10712 +       atomic_t nr_onhold;             /* processes on hold */
10713 +       uint32_t onhold_last;           /* jiffies when put on hold */
10714 +
10715 +       struct timespec bias_ts;        /* time offset to the host */
10716 +       struct timespec bias_idle;
10717 +       struct timespec bias_uptime;    /* context creation point */
10718 +       uint64_t bias_clock;            /* offset in clock_t */
10719 +
10720 +       spinlock_t load_lock;           /* lock for the load averages */
10721 +       atomic_t load_updates;          /* nr of load updates done so far */
10722 +       uint32_t load_last;             /* last time load was calculated */
10723 +       uint32_t load[3];               /* load averages 1,5,15 */
10724 +
10725 +       atomic_t total_forks;           /* number of forks so far */
10726 +
10727 +       struct _vx_syslog syslog;
10728 +};
10729 +
10730 +struct _vx_cvirt_pc {
10731 +       struct _vx_usage_stat cpustat;
10732 +};
10733 +
10734 +
10735 +#ifdef CONFIG_VSERVER_DEBUG
10736 +
10737 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
10738 +{
10739 +       printk("\t_vx_cvirt:\n");
10740 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
10741 +               atomic_read(&cvirt->nr_threads),
10742 +               atomic_read(&cvirt->nr_running),
10743 +               atomic_read(&cvirt->nr_uninterruptible),
10744 +               atomic_read(&cvirt->nr_onhold));
10745 +       /* add rest here */
10746 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
10747 +}
10748 +
10749 +#endif
10750 +
10751 +#endif /* _VSERVER_CVIRT_DEF_H */
10752 diff -NurpP --minimal linux-3.10.9/include/linux/vserver/debug.h linux-3.10.9-vs2.3.6.6/include/linux/vserver/debug.h
10753 --- linux-3.10.9/include/linux/vserver/debug.h  1970-01-01 00:00:00.000000000 +0000
10754 +++ linux-3.10.9-vs2.3.6.6/include/linux/vserver/debug.h        2013-08-22 20:30:00.000000000 +0000
10755 @@ -0,0 +1,146 @@
10756 +#ifndef _VSERVER_DEBUG_H
10757 +#define _VSERVER_DEBUG_H
10758 +
10759 +
10760 +#define VXD_CBIT(n, m) (vs_debug_ ## n & (1 << (m)))
10761 +#define VXD_CMIN(n, m) (vs_debug_ ## n > (m))
10762 +#define VXD_MASK(n, m) (vs_debug_ ## n & (m))
10763 +
10764 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
10765 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
10766 +#define VXF_DEV                "%p[%lu,%d:%d]"
10767 +
10768 +#if    defined(CONFIG_QUOTES_UTF8)
10769 +#define        VS_Q_LQM        "\xc2\xbb"
10770 +#define        VS_Q_RQM        "\xc2\xab"
10771 +#elif  defined(CONFIG_QUOTES_ASCII)
10772 +#define        VS_Q_LQM        "\x27"
10773 +#define        VS_Q_RQM        "\x27"
10774 +#else
10775 +#define        VS_Q_LQM        "\xbb"
10776 +#define        VS_Q_RQM        "\xab"
10777 +#endif
10778 +
10779 +#define        VS_Q(f)         VS_Q_LQM f VS_Q_RQM
10780 +
10781 +
10782 +#define vxd_path(p)                                            \
10783 +       ({ static char _buffer[PATH_MAX];                       \
10784 +          d_path(p, _buffer, sizeof(_buffer)); })
10785 +
10786 +#define vxd_cond_path(n)                                       \
10787 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
10788 +
10789 +
10790 +#ifdef CONFIG_VSERVER_DEBUG
10791 +
10792 +extern unsigned int vs_debug_switch;
10793 +extern unsigned int vs_debug_xid;
10794 +extern unsigned int vs_debug_nid;
10795 +extern unsigned int vs_debug_tag;
10796 +extern unsigned int vs_debug_net;
10797 +extern unsigned int vs_debug_limit;
10798 +extern unsigned int vs_debug_cres;
10799 +extern unsigned int vs_debug_dlim;
10800 +extern unsigned int vs_debug_quota;
10801 +extern unsigned int vs_debug_cvirt;
10802 +extern unsigned int vs_debug_space;
10803 +extern unsigned int vs_debug_perm;
10804 +extern unsigned int vs_debug_misc;
10805 +
10806 +
10807 +#define VX_LOGLEVEL    "vxD: "
10808 +#define VX_PROC_FMT    "%p: "
10809 +#define VX_PROCESS     current
10810 +
10811 +#define vxdprintk(c, f, x...)                                  \
10812 +       do {                                                    \
10813 +               if (c)                                          \
10814 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
10815 +                               VX_PROCESS , ##x);              \
10816 +       } while (0)
10817 +
10818 +#define vxlprintk(c, f, x...)                                  \
10819 +       do {                                                    \
10820 +               if (c)                                          \
10821 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
10822 +       } while (0)
10823 +
10824 +#define vxfprintk(c, f, x...)                                  \
10825 +       do {                                                    \
10826 +               if (c)                                          \
10827 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
10828 +       } while (0)
10829 +
10830 +
10831 +struct vx_info;
10832 +
10833 +void dump_vx_info(struct vx_info *, int);
10834 +void dump_vx_info_inactive(int);
10835 +
10836 +#else  /* CONFIG_VSERVER_DEBUG */
10837 +
10838 +#define vs_debug_switch        0
10839 +#define vs_debug_xid   0
10840 +#define vs_debug_nid   0
10841 +#define vs_debug_tag   0
10842 +#define vs_debug_net   0
10843 +#define vs_debug_limit 0
10844 +#define vs_debug_cres  0
10845 +#define vs_debug_dlim  0
10846 +#define vs_debug_quota 0
10847 +#define vs_debug_cvirt 0
10848 +#define vs_debug_space 0
10849 +#define vs_debug_perm  0
10850 +#define vs_debug_misc  0
10851 +
10852 +#define vxdprintk(x...) do { } while (0)
10853 +#define vxlprintk(x...) do { } while (0)
10854 +#define vxfprintk(x...) do { } while (0)
10855 +
10856 +#endif /* CONFIG_VSERVER_DEBUG */
10857 +
10858 +
10859 +#ifdef CONFIG_VSERVER_WARN
10860 +
10861 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
10862 +#define VX_WARN_TASK   "[" VS_Q("%s") ",%u:#%u|%u|%u] "
10863 +#define VX_WARN_XID    "[xid #%u] "
10864 +#define VX_WARN_NID    "[nid #%u] "
10865 +#define VX_WARN_TAG    "[tag #%u] "
10866 +
10867 +#define vxwprintk(c, f, x...)                                  \
10868 +       do {                                                    \
10869 +               if (c)                                          \
10870 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
10871 +       } while (0)
10872 +
10873 +#else  /* CONFIG_VSERVER_WARN */
10874 +
10875 +#define vxwprintk(x...) do { } while (0)
10876 +
10877 +#endif /* CONFIG_VSERVER_WARN */
10878 +
10879 +#define vxwprintk_task(c, f, x...)                             \
10880 +       vxwprintk(c, VX_WARN_TASK f,                            \
10881 +               current->comm, current->pid,                    \
10882 +               current->xid, current->nid,                     \
10883 +               current->tag, ##x)
10884 +#define vxwprintk_xid(c, f, x...)                              \
10885 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
10886 +#define vxwprintk_nid(c, f, x...)                              \
10887 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
10888 +#define vxwprintk_tag(c, f, x...)                              \
10889 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
10890 +
10891 +#ifdef CONFIG_VSERVER_DEBUG
10892 +#define vxd_assert_lock(l)     assert_spin_locked(l)
10893 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
10894 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
10895 +#else
10896 +#define vxd_assert_lock(l)     do { } while (0)
10897 +#define vxd_assert(c, f, x...) do { } while (0)
10898 +#endif
10899 +
10900 +
10901 +#endif /* _VSERVER_DEBUG_H */
10902 diff -NurpP --minimal linux-3.10.9/include/linux/vserver/debug_cmd.h linux-3.10.9-vs2.3.6.6/include/linux/vserver/debug_cmd.h
10903 --- linux-3.10.9/include/linux/vserver/debug_cmd.h      1970-01-01 00:00:00.000000000 +0000
10904 +++ linux-3.10.9-vs2.3.6.6/include/linux/vserver/debug_cmd.h    2013-08-22 20:30:00.000000000 +0000
10905 @@ -0,0 +1,37 @@
10906 +#ifndef _VSERVER_DEBUG_CMD_H
10907 +#define _VSERVER_DEBUG_CMD_H
10908 +
10909 +#include <uapi/vserver/debug_cmd.h>
10910 +
10911 +
10912 +#ifdef CONFIG_COMPAT
10913 +
10914 +#include <asm/compat.h>
10915 +
10916 +struct vcmd_read_history_v0_x32 {
10917 +       uint32_t index;
10918 +       uint32_t count;
10919 +       compat_uptr_t data_ptr;
10920 +};
10921 +
10922 +struct vcmd_read_monitor_v0_x32 {
10923 +       uint32_t index;
10924 +       uint32_t count;
10925 +       compat_uptr_t data_ptr;
10926 +};
10927 +
10928 +#endif  /* CONFIG_COMPAT */
10929 +
10930 +extern int vc_dump_history(uint32_t);
10931 +
10932 +extern int vc_read_history(uint32_t, void __user *);
10933 +extern int vc_read_monitor(uint32_t, void __user *);
10934 +
10935 +#ifdef CONFIG_COMPAT
10936 +
10937 +extern int vc_read_history_x32(uint32_t, void __user *);
10938 +extern int vc_read_monitor_x32(uint32_t, void __user *);
10939 +
10940 +#endif  /* CONFIG_COMPAT */
10941 +
10942 +#endif /* _VSERVER_DEBUG_CMD_H */
10943 diff -NurpP --minimal linux-3.10.9/include/linux/vserver/device.h linux-3.10.9-vs2.3.6.6/include/linux/vserver/device.h
10944 --- linux-3.10.9/include/linux/vserver/device.h 1970-01-01 00:00:00.000000000 +0000
10945 +++ linux-3.10.9-vs2.3.6.6/include/linux/vserver/device.h       2013-08-22 20:30:00.000000000 +0000
10946 @@ -0,0 +1,9 @@
10947 +#ifndef _VSERVER_DEVICE_H
10948 +#define _VSERVER_DEVICE_H
10949 +
10950 +
10951 +#include <uapi/vserver/device.h>
10952 +
10953 +#else  /* _VSERVER_DEVICE_H */
10954 +#warning duplicate inclusion
10955 +#endif /* _VSERVER_DEVICE_H */
10956 diff -NurpP --minimal linux-3.10.9/include/linux/vserver/device_cmd.h linux-3.10.9-vs2.3.6.6/include/linux/vserver/device_cmd.h
10957 --- linux-3.10.9/include/linux/vserver/device_cmd.h     1970-01-01 00:00:00.000000000 +0000
10958 +++ linux-3.10.9-vs2.3.6.6/include/linux/vserver/device_cmd.h   2013-08-22 20:30:00.000000000 +0000
10959 @@ -0,0 +1,31 @@
10960 +#ifndef _VSERVER_DEVICE_CMD_H
10961 +#define _VSERVER_DEVICE_CMD_H
10962 +
10963 +#include <uapi/vserver/device_cmd.h>
10964 +
10965 +
10966 +#ifdef CONFIG_COMPAT
10967 +
10968 +#include <asm/compat.h>
10969 +
10970 +struct vcmd_set_mapping_v0_x32 {
10971 +       compat_uptr_t device_ptr;
10972 +       compat_uptr_t target_ptr;
10973 +       uint32_t flags;
10974 +};
10975 +
10976 +#endif /* CONFIG_COMPAT */
10977 +
10978 +#include <linux/compiler.h>
10979 +
10980 +extern int vc_set_mapping(struct vx_info *, void __user *);
10981 +extern int vc_unset_mapping(struct vx_info *, void __user *);
10982 +
10983 +#ifdef CONFIG_COMPAT
10984 +
10985 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
10986 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
10987 +
10988 +#endif /* CONFIG_COMPAT */
10989 +
10990 +#endif /* _VSERVER_DEVICE_CMD_H */
10991 diff -NurpP --minimal linux-3.10.9/include/linux/vserver/device_def.h linux-3.10.9-vs2.3.6.6/include/linux/vserver/device_def.h
10992 --- linux-3.10.9/include/linux/vserver/device_def.h     1970-01-01 00:00:00.000000000 +0000
10993 +++ linux-3.10.9-vs2.3.6.6/include/linux/vserver/device_def.h   2013-08-22 20:30:00.000000000 +0000
10994 @@ -0,0 +1,17 @@
10995 +#ifndef _VSERVER_DEVICE_DEF_H
10996 +#define _VSERVER_DEVICE_DEF_H
10997 +
10998 +#include <linux/types.h>
10999 +
11000 +struct vx_dmap_target {
11001 +       dev_t target;
11002 +       uint32_t flags;
11003 +};
11004 +
11005 +struct _vx_device {
11006 +#ifdef CONFIG_VSERVER_DEVICE
11007 +       struct vx_dmap_target targets[2];
11008 +#endif
11009 +};
11010 +
11011 +#endif /* _VSERVER_DEVICE_DEF_H */
11012 diff -NurpP --minimal linux-3.10.9/include/linux/vserver/dlimit.h linux-3.10.9-vs2.3.6.6/include/linux/vserver/dlimit.h
11013 --- linux-3.10.9/include/linux/vserver/dlimit.h 1970-01-01 00:00:00.000000000 +0000
11014 +++ linux-3.10.9-vs2.3.6.6/include/linux/vserver/dlimit.h       2013-08-22 20:30:00.000000000 +0000
11015 @@ -0,0 +1,54 @@
11016 +#ifndef _VSERVER_DLIMIT_H
11017 +#define _VSERVER_DLIMIT_H
11018 +
11019 +#include "switch.h"
11020 +
11021 +
11022 +#ifdef __KERNEL__
11023 +
11024 +/*      keep in sync with CDLIM_INFINITY       */
11025 +
11026 +#define DLIM_INFINITY          (~0ULL)
11027 +
11028 +#include <linux/spinlock.h>
11029 +#include <linux/rcupdate.h>
11030 +
11031 +struct super_block;
11032 +
11033 +struct dl_info {
11034 +       struct hlist_node dl_hlist;             /* linked list of contexts */
11035 +       struct rcu_head dl_rcu;                 /* the rcu head */
11036 +       vtag_t dl_tag;                          /* context tag */
11037 +       atomic_t dl_usecnt;                     /* usage count */
11038 +       atomic_t dl_refcnt;                     /* reference count */
11039 +
11040 +       struct super_block *dl_sb;              /* associated superblock */
11041 +
11042 +       spinlock_t dl_lock;                     /* protect the values */
11043 +
11044 +       unsigned long long dl_space_used;       /* used space in bytes */
11045 +       unsigned long long dl_space_total;      /* maximum space in bytes */
11046 +       unsigned long dl_inodes_used;           /* used inodes */
11047 +       unsigned long dl_inodes_total;          /* maximum inodes */
11048 +
11049 +       unsigned int dl_nrlmult;                /* non root limit mult */
11050 +};
11051 +
11052 +struct rcu_head;
11053 +
11054 +extern void rcu_free_dl_info(struct rcu_head *);
11055 +extern void unhash_dl_info(struct dl_info *);
11056 +
11057 +extern struct dl_info *locate_dl_info(struct super_block *, vtag_t);
11058 +
11059 +
11060 +struct kstatfs;
11061 +
11062 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
11063 +
11064 +typedef uint64_t dlsize_t;
11065 +
11066 +#endif /* __KERNEL__ */
11067 +#else  /* _VSERVER_DLIMIT_H */
11068 +#warning duplicate inclusion
11069 +#endif /* _VSERVER_DLIMIT_H */
11070 diff -NurpP --minimal linux-3.10.9/include/linux/vserver/dlimit_cmd.h linux-3.10.9-vs2.3.6.6/include/linux/vserver/dlimit_cmd.h
11071 --- linux-3.10.9/include/linux/vserver/dlimit_cmd.h     1970-01-01 00:00:00.000000000 +0000
11072 +++ linux-3.10.9-vs2.3.6.6/include/linux/vserver/dlimit_cmd.h   2013-08-22 20:30:00.000000000 +0000
11073 @@ -0,0 +1,46 @@
11074 +#ifndef _VSERVER_DLIMIT_CMD_H
11075 +#define _VSERVER_DLIMIT_CMD_H
11076 +
11077 +#include <uapi/vserver/dlimit_cmd.h>
11078 +
11079 +
11080 +#ifdef CONFIG_COMPAT
11081 +
11082 +#include <asm/compat.h>
11083 +
11084 +struct vcmd_ctx_dlimit_base_v0_x32 {
11085 +       compat_uptr_t name_ptr;
11086 +       uint32_t flags;
11087 +};
11088 +
11089 +struct vcmd_ctx_dlimit_v0_x32 {
11090 +       compat_uptr_t name_ptr;
11091 +       uint32_t space_used;                    /* used space in kbytes */
11092 +       uint32_t space_total;                   /* maximum space in kbytes */
11093 +       uint32_t inodes_used;                   /* used inodes */
11094 +       uint32_t inodes_total;                  /* maximum inodes */
11095 +       uint32_t reserved;                      /* reserved for root in % */
11096 +       uint32_t flags;
11097 +};
11098 +
11099 +#endif /* CONFIG_COMPAT */
11100 +
11101 +#include <linux/compiler.h>
11102 +
11103 +extern int vc_add_dlimit(uint32_t, void __user *);
11104 +extern int vc_rem_dlimit(uint32_t, void __user *);
11105 +
11106 +extern int vc_set_dlimit(uint32_t, void __user *);
11107 +extern int vc_get_dlimit(uint32_t, void __user *);
11108 +
11109 +#ifdef CONFIG_COMPAT
11110 +
11111 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
11112 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
11113 +
11114 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
11115 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
11116 +
11117 +#endif /* CONFIG_COMPAT */
11118 +
11119 +#endif /* _VSERVER_DLIMIT_CMD_H */
11120 diff -NurpP --minimal linux-3.10.9/include/linux/vserver/global.h linux-3.10.9-vs2.3.6.6/include/linux/vserver/global.h
11121 --- linux-3.10.9/include/linux/vserver/global.h 1970-01-01 00:00:00.000000000 +0000
11122 +++ linux-3.10.9-vs2.3.6.6/include/linux/vserver/global.h       2013-08-22 20:30:00.000000000 +0000
11123 @@ -0,0 +1,19 @@
11124 +#ifndef _VSERVER_GLOBAL_H
11125 +#define _VSERVER_GLOBAL_H
11126 +
11127 +
11128 +extern atomic_t vx_global_ctotal;
11129 +extern atomic_t vx_global_cactive;
11130 +
11131 +extern atomic_t nx_global_ctotal;
11132 +extern atomic_t nx_global_cactive;
11133 +
11134 +extern atomic_t vs_global_nsproxy;
11135 +extern atomic_t vs_global_fs;
11136 +extern atomic_t vs_global_mnt_ns;
11137 +extern atomic_t vs_global_uts_ns;
11138 +extern atomic_t vs_global_user_ns;
11139 +extern atomic_t vs_global_pid_ns;
11140 +
11141 +
11142 +#endif /* _VSERVER_GLOBAL_H */
11143 diff -NurpP --minimal linux-3.10.9/include/linux/vserver/history.h linux-3.10.9-vs2.3.6.6/include/linux/vserver/history.h
11144 --- linux-3.10.9/include/linux/vserver/history.h        1970-01-01 00:00:00.000000000 +0000
11145 +++ linux-3.10.9-vs2.3.6.6/include/linux/vserver/history.h      2013-08-22 20:30:00.000000000 +0000
11146 @@ -0,0 +1,197 @@
11147 +#ifndef _VSERVER_HISTORY_H
11148 +#define _VSERVER_HISTORY_H
11149 +
11150 +
11151 +enum {
11152 +       VXH_UNUSED = 0,
11153 +       VXH_THROW_OOPS = 1,
11154 +
11155 +       VXH_GET_VX_INFO,
11156 +       VXH_PUT_VX_INFO,
11157 +       VXH_INIT_VX_INFO,
11158 +       VXH_SET_VX_INFO,
11159 +       VXH_CLR_VX_INFO,
11160 +       VXH_CLAIM_VX_INFO,
11161 +       VXH_RELEASE_VX_INFO,
11162 +       VXH_ALLOC_VX_INFO,
11163 +       VXH_DEALLOC_VX_INFO,
11164 +       VXH_HASH_VX_INFO,
11165 +       VXH_UNHASH_VX_INFO,
11166 +       VXH_LOC_VX_INFO,
11167 +       VXH_LOOKUP_VX_INFO,
11168 +       VXH_CREATE_VX_INFO,
11169 +};
11170 +
11171 +struct _vxhe_vxi {
11172 +       struct vx_info *ptr;
11173 +       unsigned xid;
11174 +       unsigned usecnt;
11175 +       unsigned tasks;
11176 +};
11177 +
11178 +struct _vxhe_set_clr {
11179 +       void *data;
11180 +};
11181 +
11182 +struct _vxhe_loc_lookup {
11183 +       unsigned arg;
11184 +};
11185 +
11186 +struct _vx_hist_entry {
11187 +       void *loc;
11188 +       unsigned short seq;
11189 +       unsigned short type;
11190 +       struct _vxhe_vxi vxi;
11191 +       union {
11192 +               struct _vxhe_set_clr sc;
11193 +               struct _vxhe_loc_lookup ll;
11194 +       };
11195 +};
11196 +
11197 +#ifdef CONFIG_VSERVER_HISTORY
11198 +
11199 +extern unsigned volatile int vxh_active;
11200 +
11201 +struct _vx_hist_entry *vxh_advance(void *loc);
11202 +
11203 +
11204 +static inline
11205 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
11206 +{
11207 +       entry->vxi.ptr = vxi;
11208 +       if (vxi) {
11209 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
11210 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
11211 +               entry->vxi.xid = vxi->vx_id;
11212 +       }
11213 +}
11214 +
11215 +
11216 +#define        __HERE__ current_text_addr()
11217 +
11218 +#define __VXH_BODY(__type, __data, __here)     \
11219 +       struct _vx_hist_entry *entry;           \
11220 +                                               \
11221 +       preempt_disable();                      \
11222 +       entry = vxh_advance(__here);            \
11223 +       __data;                                 \
11224 +       entry->type = __type;                   \
11225 +       preempt_enable();
11226 +
11227 +
11228 +       /* pass vxi only */
11229 +
11230 +#define __VXH_SMPL                             \
11231 +       __vxh_copy_vxi(entry, vxi)
11232 +
11233 +static inline
11234 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
11235 +{
11236 +       __VXH_BODY(__type, __VXH_SMPL, __here)
11237 +}
11238 +
11239 +       /* pass vxi and data (void *) */
11240 +
11241 +#define __VXH_DATA                             \
11242 +       __vxh_copy_vxi(entry, vxi);             \
11243 +       entry->sc.data = data
11244 +
11245 +static inline
11246 +void   __vxh_data(struct vx_info *vxi, void *data,
11247 +                       int __type, void *__here)
11248 +{
11249 +       __VXH_BODY(__type, __VXH_DATA, __here)
11250 +}
11251 +
11252 +       /* pass vxi and arg (long) */
11253 +
11254 +#define __VXH_LONG                             \
11255 +       __vxh_copy_vxi(entry, vxi);             \
11256 +       entry->ll.arg = arg
11257 +
11258 +static inline
11259 +void   __vxh_long(struct vx_info *vxi, long arg,
11260 +                       int __type, void *__here)
11261 +{
11262 +       __VXH_BODY(__type, __VXH_LONG, __here)
11263 +}
11264 +
11265 +
11266 +static inline
11267 +void   __vxh_throw_oops(void *__here)
11268 +{
11269 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
11270 +       /* prevent further acquisition */
11271 +       vxh_active = 0;
11272 +}
11273 +
11274 +
11275 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
11276 +
11277 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
11278 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
11279 +
11280 +#define __vxh_init_vx_info(v, d, h) \
11281 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
11282 +#define __vxh_set_vx_info(v, d, h) \
11283 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
11284 +#define __vxh_clr_vx_info(v, d, h) \
11285 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
11286 +
11287 +#define __vxh_claim_vx_info(v, d, h) \
11288 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
11289 +#define __vxh_release_vx_info(v, d, h) \
11290 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
11291 +
11292 +#define vxh_alloc_vx_info(v) \
11293 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
11294 +#define vxh_dealloc_vx_info(v) \
11295 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
11296 +
11297 +#define vxh_hash_vx_info(v) \
11298 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
11299 +#define vxh_unhash_vx_info(v) \
11300 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
11301 +
11302 +#define vxh_loc_vx_info(v, l) \
11303 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
11304 +#define vxh_lookup_vx_info(v, l) \
11305 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
11306 +#define vxh_create_vx_info(v, l) \
11307 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
11308 +
11309 +extern void vxh_dump_history(void);
11310 +
11311 +
11312 +#else  /* CONFIG_VSERVER_HISTORY */
11313 +
11314 +#define        __HERE__        0
11315 +
11316 +#define vxh_throw_oops()               do { } while (0)
11317 +
11318 +#define __vxh_get_vx_info(v, h)                do { } while (0)
11319 +#define __vxh_put_vx_info(v, h)                do { } while (0)
11320 +
11321 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
11322 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
11323 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
11324 +
11325 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
11326 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
11327 +
11328 +#define vxh_alloc_vx_info(v)           do { } while (0)
11329 +#define vxh_dealloc_vx_info(v)         do { } while (0)
11330 +
11331 +#define vxh_hash_vx_info(v)            do { } while (0)
11332 +#define vxh_unhash_vx_info(v)          do { } while (0)
11333 +
11334 +#define vxh_loc_vx_info(v, l)          do { } while (0)
11335 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
11336 +#define vxh_create_vx_info(v, l)       do { } while (0)
11337 +
11338 +#define vxh_dump_history()             do { } while (0)
11339 +
11340 +
11341 +#endif /* CONFIG_VSERVER_HISTORY */
11342 +
11343 +#endif /* _VSERVER_HISTORY_H */
11344 diff -NurpP --minimal linux-3.10.9/include/linux/vserver/inode.h linux-3.10.9-vs2.3.6.6/include/linux/vserver/inode.h
11345 --- linux-3.10.9/include/linux/vserver/inode.h  1970-01-01 00:00:00.000000000 +0000
11346 +++ linux-3.10.9-vs2.3.6.6/include/linux/vserver/inode.h        2013-08-22 20:30:00.000000000 +0000
11347 @@ -0,0 +1,19 @@
11348 +#ifndef _VSERVER_INODE_H
11349 +#define _VSERVER_INODE_H
11350 +
11351 +#include <uapi/vserver/inode.h>
11352 +
11353 +
11354 +#ifdef CONFIG_VSERVER_PROC_SECURE
11355 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
11356 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11357 +#else
11358 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
11359 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11360 +#endif
11361 +
11362 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
11363 +
11364 +#else  /* _VSERVER_INODE_H */
11365 +#warning duplicate inclusion
11366 +#endif /* _VSERVER_INODE_H */
11367 diff -NurpP --minimal linux-3.10.9/include/linux/vserver/inode_cmd.h linux-3.10.9-vs2.3.6.6/include/linux/vserver/inode_cmd.h
11368 --- linux-3.10.9/include/linux/vserver/inode_cmd.h      1970-01-01 00:00:00.000000000 +0000
11369 +++ linux-3.10.9-vs2.3.6.6/include/linux/vserver/inode_cmd.h    2013-08-22 20:30:00.000000000 +0000
11370 @@ -0,0 +1,36 @@
11371 +#ifndef _VSERVER_INODE_CMD_H
11372 +#define _VSERVER_INODE_CMD_H
11373 +
11374 +#include <uapi/vserver/inode_cmd.h>
11375 +
11376 +
11377 +
11378 +#ifdef CONFIG_COMPAT
11379 +
11380 +#include <asm/compat.h>
11381 +
11382 +struct vcmd_ctx_iattr_v1_x32 {
11383 +       compat_uptr_t name_ptr;
11384 +       uint32_t tag;
11385 +       uint32_t flags;
11386 +       uint32_t mask;
11387 +};
11388 +
11389 +#endif /* CONFIG_COMPAT */
11390 +
11391 +#include <linux/compiler.h>
11392 +
11393 +extern int vc_get_iattr(void __user *);
11394 +extern int vc_set_iattr(void __user *);
11395 +
11396 +extern int vc_fget_iattr(uint32_t, void __user *);
11397 +extern int vc_fset_iattr(uint32_t, void __user *);
11398 +
11399 +#ifdef CONFIG_COMPAT
11400 +
11401 +extern int vc_get_iattr_x32(void __user *);
11402 +extern int vc_set_iattr_x32(void __user *);
11403 +
11404 +#endif /* CONFIG_COMPAT */
11405 +
11406 +#endif /* _VSERVER_INODE_CMD_H */
11407 diff -NurpP --minimal linux-3.10.9/include/linux/vserver/limit.h linux-3.10.9-vs2.3.6.6/include/linux/vserver/limit.h
11408 --- linux-3.10.9/include/linux/vserver/limit.h  1970-01-01 00:00:00.000000000 +0000
11409 +++ linux-3.10.9-vs2.3.6.6/include/linux/vserver/limit.h        2013-08-22 20:30:00.000000000 +0000
11410 @@ -0,0 +1,61 @@
11411 +#ifndef _VSERVER_LIMIT_H
11412 +#define _VSERVER_LIMIT_H
11413 +
11414 +#include <uapi/vserver/limit.h>
11415 +
11416 +
11417 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
11418 +
11419 +/*     keep in sync with CRLIM_INFINITY */
11420 +
11421 +#define        VLIM_INFINITY   (~0ULL)
11422 +
11423 +#include <asm/atomic.h>
11424 +#include <asm/resource.h>
11425 +
11426 +#ifndef RLIM_INFINITY
11427 +#warning RLIM_INFINITY is undefined
11428 +#endif
11429 +
11430 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
11431 +
11432 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
11433 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
11434 +
11435 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
11436 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
11437 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
11438 +
11439 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
11440 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
11441 +
11442 +typedef atomic_long_t rlim_atomic_t;
11443 +typedef unsigned long rlim_t;
11444 +
11445 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
11446 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
11447 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
11448 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
11449 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
11450 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
11451 +
11452 +
11453 +#if    (RLIM_INFINITY == VLIM_INFINITY)
11454 +#define        VX_VLIM(r) ((long long)(long)(r))
11455 +#define        VX_RLIM(v) ((rlim_t)(v))
11456 +#else
11457 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
11458 +               ? VLIM_INFINITY : (long long)(r))
11459 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
11460 +               ? RLIM_INFINITY : (rlim_t)(v))
11461 +#endif
11462 +
11463 +struct sysinfo;
11464 +
11465 +void vx_vsi_meminfo(struct sysinfo *);
11466 +void vx_vsi_swapinfo(struct sysinfo *);
11467 +long vx_vsi_cached(struct sysinfo *);
11468 +
11469 +#define NUM_LIMITS     24
11470 +
11471 +#endif /* _VSERVER_LIMIT_H */
11472 diff -NurpP --minimal linux-3.10.9/include/linux/vserver/limit_cmd.h linux-3.10.9-vs2.3.6.6/include/linux/vserver/limit_cmd.h
11473 --- linux-3.10.9/include/linux/vserver/limit_cmd.h      1970-01-01 00:00:00.000000000 +0000
11474 +++ linux-3.10.9-vs2.3.6.6/include/linux/vserver/limit_cmd.h    2013-08-22 20:30:00.000000000 +0000
11475 @@ -0,0 +1,35 @@
11476 +#ifndef _VSERVER_LIMIT_CMD_H
11477 +#define _VSERVER_LIMIT_CMD_H
11478 +
11479 +#include <uapi/vserver/limit_cmd.h>
11480 +
11481 +
11482 +#ifdef CONFIG_IA32_EMULATION
11483 +
11484 +struct vcmd_ctx_rlimit_v0_x32 {
11485 +       uint32_t id;
11486 +       uint64_t minimum;
11487 +       uint64_t softlimit;
11488 +       uint64_t maximum;
11489 +} __attribute__ ((packed));
11490 +
11491 +#endif /* CONFIG_IA32_EMULATION */
11492 +
11493 +#include <linux/compiler.h>
11494 +
11495 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
11496 +extern int vc_get_rlimit(struct vx_info *, void __user *);
11497 +extern int vc_set_rlimit(struct vx_info *, void __user *);
11498 +extern int vc_reset_hits(struct vx_info *, void __user *);
11499 +extern int vc_reset_minmax(struct vx_info *, void __user *);
11500 +
11501 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
11502 +
11503 +#ifdef CONFIG_IA32_EMULATION
11504 +
11505 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
11506 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
11507 +
11508 +#endif /* CONFIG_IA32_EMULATION */
11509 +
11510 +#endif /* _VSERVER_LIMIT_CMD_H */
11511 diff -NurpP --minimal linux-3.10.9/include/linux/vserver/limit_def.h linux-3.10.9-vs2.3.6.6/include/linux/vserver/limit_def.h
11512 --- linux-3.10.9/include/linux/vserver/limit_def.h      1970-01-01 00:00:00.000000000 +0000
11513 +++ linux-3.10.9-vs2.3.6.6/include/linux/vserver/limit_def.h    2013-08-22 20:30:00.000000000 +0000
11514 @@ -0,0 +1,47 @@
11515 +#ifndef _VSERVER_LIMIT_DEF_H
11516 +#define _VSERVER_LIMIT_DEF_H
11517 +
11518 +#include <asm/atomic.h>
11519 +#include <asm/resource.h>
11520 +
11521 +#include "limit.h"
11522 +
11523 +
11524 +struct _vx_res_limit {
11525 +       rlim_t soft;            /* Context soft limit */
11526 +       rlim_t hard;            /* Context hard limit */
11527 +
11528 +       rlim_atomic_t rcur;     /* Current value */
11529 +       rlim_t rmin;            /* Context minimum */
11530 +       rlim_t rmax;            /* Context maximum */
11531 +
11532 +       atomic_t lhit;          /* Limit hits */
11533 +};
11534 +
11535 +/* context sub struct */
11536 +
11537 +struct _vx_limit {
11538 +       struct _vx_res_limit res[NUM_LIMITS];
11539 +};
11540 +
11541 +#ifdef CONFIG_VSERVER_DEBUG
11542 +
11543 +static inline void __dump_vx_limit(struct _vx_limit *limit)
11544 +{
11545 +       int i;
11546 +
11547 +       printk("\t_vx_limit:");
11548 +       for (i = 0; i < NUM_LIMITS; i++) {
11549 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
11550 +                       i, (unsigned long)__rlim_get(limit, i),
11551 +                       (unsigned long)__rlim_rmin(limit, i),
11552 +                       (unsigned long)__rlim_rmax(limit, i),
11553 +                       (long)__rlim_soft(limit, i),
11554 +                       (long)__rlim_hard(limit, i),
11555 +                       atomic_read(&__rlim_lhit(limit, i)));
11556 +       }
11557 +}
11558 +
11559 +#endif
11560 +
11561 +#endif /* _VSERVER_LIMIT_DEF_H */
11562 diff -NurpP --minimal linux-3.10.9/include/linux/vserver/limit_int.h linux-3.10.9-vs2.3.6.6/include/linux/vserver/limit_int.h
11563 --- linux-3.10.9/include/linux/vserver/limit_int.h      1970-01-01 00:00:00.000000000 +0000
11564 +++ linux-3.10.9-vs2.3.6.6/include/linux/vserver/limit_int.h    2013-08-22 20:30:00.000000000 +0000
11565 @@ -0,0 +1,193 @@
11566 +#ifndef _VSERVER_LIMIT_INT_H
11567 +#define _VSERVER_LIMIT_INT_H
11568 +
11569 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
11570 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
11571 +
11572 +extern const char *vlimit_name[NUM_LIMITS];
11573 +
11574 +static inline void __vx_acc_cres(struct vx_info *vxi,
11575 +       int res, int dir, void *_data, char *_file, int _line)
11576 +{
11577 +       if (VXD_RCRES_COND(res))
11578 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
11579 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11580 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11581 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
11582 +       if (!vxi)
11583 +               return;
11584 +
11585 +       if (dir > 0)
11586 +               __rlim_inc(&vxi->limit, res);
11587 +       else
11588 +               __rlim_dec(&vxi->limit, res);
11589 +}
11590 +
11591 +static inline void __vx_add_cres(struct vx_info *vxi,
11592 +       int res, int amount, void *_data, char *_file, int _line)
11593 +{
11594 +       if (VXD_RCRES_COND(res))
11595 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
11596 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11597 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11598 +                       amount, _data, _file, _line);
11599 +       if (amount == 0)
11600 +               return;
11601 +       if (!vxi)
11602 +               return;
11603 +       __rlim_add(&vxi->limit, res, amount);
11604 +}
11605 +
11606 +static inline
11607 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
11608 +{
11609 +       int cond = (value > __rlim_rmax(limit, res));
11610 +
11611 +       if (cond)
11612 +               __rlim_rmax(limit, res) = value;
11613 +       return cond;
11614 +}
11615 +
11616 +static inline
11617 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
11618 +{
11619 +       int cond = (value < __rlim_rmin(limit, res));
11620 +
11621 +       if (cond)
11622 +               __rlim_rmin(limit, res) = value;
11623 +       return cond;
11624 +}
11625 +
11626 +static inline
11627 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
11628 +{
11629 +       if (!__vx_cres_adjust_max(limit, res, value))
11630 +               __vx_cres_adjust_min(limit, res, value);
11631 +}
11632 +
11633 +
11634 +/*     return values:
11635 +        +1 ... no limit hit
11636 +        -1 ... over soft limit
11637 +         0 ... over hard limit         */
11638 +
11639 +static inline int __vx_cres_avail(struct vx_info *vxi,
11640 +       int res, int num, char *_file, int _line)
11641 +{
11642 +       struct _vx_limit *limit;
11643 +       rlim_t value;
11644 +
11645 +       if (VXD_RLIMIT_COND(res))
11646 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
11647 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11648 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
11649 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
11650 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11651 +                       num, _file, _line);
11652 +       if (!vxi)
11653 +               return 1;
11654 +
11655 +       limit = &vxi->limit;
11656 +       value = __rlim_get(limit, res);
11657 +
11658 +       if (!__vx_cres_adjust_max(limit, res, value))
11659 +               __vx_cres_adjust_min(limit, res, value);
11660 +
11661 +       if (num == 0)
11662 +               return 1;
11663 +
11664 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
11665 +               return -1;
11666 +       if (value + num <= __rlim_soft(limit, res))
11667 +               return -1;
11668 +
11669 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
11670 +               return 1;
11671 +       if (value + num <= __rlim_hard(limit, res))
11672 +               return 1;
11673 +
11674 +       __rlim_hit(limit, res);
11675 +       return 0;
11676 +}
11677 +
11678 +
11679 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
11680 +
11681 +static inline
11682 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
11683 +{
11684 +       rlim_t value, sum = 0;
11685 +       int res;
11686 +
11687 +       while ((res = *array++)) {
11688 +               value = __rlim_get(limit, res);
11689 +               __vx_cres_fixup(limit, res, value);
11690 +               sum += value;
11691 +       }
11692 +       return sum;
11693 +}
11694 +
11695 +static inline
11696 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
11697 +{
11698 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
11699 +       int res = *array;
11700 +
11701 +       if (value == __rlim_get(limit, res))
11702 +               return value;
11703 +
11704 +       __rlim_set(limit, res, value);
11705 +       /* now adjust min/max */
11706 +       if (!__vx_cres_adjust_max(limit, res, value))
11707 +               __vx_cres_adjust_min(limit, res, value);
11708 +
11709 +       return value;
11710 +}
11711 +
11712 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
11713 +       const int *array, int num, char *_file, int _line)
11714 +{
11715 +       struct _vx_limit *limit;
11716 +       rlim_t value = 0;
11717 +       int res;
11718 +
11719 +       if (num == 0)
11720 +               return 1;
11721 +       if (!vxi)
11722 +               return 1;
11723 +
11724 +       limit = &vxi->limit;
11725 +       res = *array;
11726 +       value = __vx_cres_array_sum(limit, array + 1);
11727 +
11728 +       __rlim_set(limit, res, value);
11729 +       __vx_cres_fixup(limit, res, value);
11730 +
11731 +       return __vx_cres_avail(vxi, res, num, _file, _line);
11732 +}
11733 +
11734 +
11735 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
11736 +{
11737 +       rlim_t value;
11738 +       int res;
11739 +
11740 +       /* complex resources first */
11741 +       if ((id < 0) || (id == RLIMIT_RSS))
11742 +               __vx_cres_array_fixup(limit, VLA_RSS);
11743 +
11744 +       for (res = 0; res < NUM_LIMITS; res++) {
11745 +               if ((id > 0) && (res != id))
11746 +                       continue;
11747 +
11748 +               value = __rlim_get(limit, res);
11749 +               __vx_cres_fixup(limit, res, value);
11750 +
11751 +               /* not supposed to happen, maybe warn? */
11752 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
11753 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
11754 +       }
11755 +}
11756 +
11757 +
11758 +#endif /* _VSERVER_LIMIT_INT_H */
11759 diff -NurpP --minimal linux-3.10.9/include/linux/vserver/monitor.h linux-3.10.9-vs2.3.6.6/include/linux/vserver/monitor.h
11760 --- linux-3.10.9/include/linux/vserver/monitor.h        1970-01-01 00:00:00.000000000 +0000
11761 +++ linux-3.10.9-vs2.3.6.6/include/linux/vserver/monitor.h      2013-08-22 20:30:00.000000000 +0000
11762 @@ -0,0 +1,6 @@
11763 +#ifndef _VSERVER_MONITOR_H
11764 +#define _VSERVER_MONITOR_H
11765 +
11766 +#include <uapi/vserver/monitor.h>
11767 +
11768 +#endif /* _VSERVER_MONITOR_H */
11769 diff -NurpP --minimal linux-3.10.9/include/linux/vserver/network.h linux-3.10.9-vs2.3.6.6/include/linux/vserver/network.h
11770 --- linux-3.10.9/include/linux/vserver/network.h        1970-01-01 00:00:00.000000000 +0000
11771 +++ linux-3.10.9-vs2.3.6.6/include/linux/vserver/network.h      2013-08-22 20:30:00.000000000 +0000
11772 @@ -0,0 +1,76 @@
11773 +#ifndef _VSERVER_NETWORK_H
11774 +#define _VSERVER_NETWORK_H
11775 +
11776 +
11777 +#include <linux/list.h>
11778 +#include <linux/spinlock.h>
11779 +#include <linux/rcupdate.h>
11780 +#include <linux/in.h>
11781 +#include <linux/in6.h>
11782 +#include <asm/atomic.h>
11783 +#include <uapi/vserver/network.h>
11784 +
11785 +struct nx_addr_v4 {
11786 +       struct nx_addr_v4 *next;
11787 +       struct in_addr ip[2];
11788 +       struct in_addr mask;
11789 +       uint16_t type;
11790 +       uint16_t flags;
11791 +};
11792 +
11793 +struct nx_addr_v6 {
11794 +       struct nx_addr_v6 *next;
11795 +       struct in6_addr ip;
11796 +       struct in6_addr mask;
11797 +       uint32_t prefix;
11798 +       uint16_t type;
11799 +       uint16_t flags;
11800 +};
11801 +
11802 +struct nx_info {
11803 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
11804 +       vnid_t nx_id;                   /* vnet id */
11805 +       atomic_t nx_usecnt;             /* usage count */
11806 +       atomic_t nx_tasks;              /* tasks count */
11807 +       int nx_state;                   /* context state */
11808 +
11809 +       uint64_t nx_flags;              /* network flag word */
11810 +       uint64_t nx_ncaps;              /* network capabilities */
11811 +
11812 +       spinlock_t addr_lock;           /* protect address changes */
11813 +       struct in_addr v4_lback;        /* Loopback address */
11814 +       struct in_addr v4_bcast;        /* Broadcast address */
11815 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
11816 +#ifdef CONFIG_IPV6
11817 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
11818 +#endif
11819 +       char nx_name[65];               /* network context name */
11820 +};
11821 +
11822 +
11823 +/* status flags */
11824 +
11825 +#define NXS_HASHED      0x0001
11826 +#define NXS_SHUTDOWN    0x0100
11827 +#define NXS_RELEASED    0x8000
11828 +
11829 +extern struct nx_info *lookup_nx_info(int);
11830 +
11831 +extern int get_nid_list(int, unsigned int *, int);
11832 +extern int nid_is_hashed(vnid_t);
11833 +
11834 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
11835 +
11836 +extern long vs_net_change(struct nx_info *, unsigned int);
11837 +
11838 +struct sock;
11839 +
11840 +
11841 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
11842 +#ifdef  CONFIG_IPV6
11843 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
11844 +#else
11845 +#define NX_IPV6(n)     (0)
11846 +#endif
11847 +
11848 +#endif /* _VSERVER_NETWORK_H */
11849 diff -NurpP --minimal linux-3.10.9/include/linux/vserver/network_cmd.h linux-3.10.9-vs2.3.6.6/include/linux/vserver/network_cmd.h
11850 --- linux-3.10.9/include/linux/vserver/network_cmd.h    1970-01-01 00:00:00.000000000 +0000
11851 +++ linux-3.10.9-vs2.3.6.6/include/linux/vserver/network_cmd.h  2013-08-22 20:30:00.000000000 +0000
11852 @@ -0,0 +1,37 @@
11853 +#ifndef _VSERVER_NETWORK_CMD_H
11854 +#define _VSERVER_NETWORK_CMD_H
11855 +
11856 +#include <uapi/vserver/network_cmd.h>
11857 +
11858 +extern int vc_task_nid(uint32_t);
11859 +
11860 +extern int vc_nx_info(struct nx_info *, void __user *);
11861 +
11862 +extern int vc_net_create(uint32_t, void __user *);
11863 +extern int vc_net_migrate(struct nx_info *, void __user *);
11864 +
11865 +extern int vc_net_add(struct nx_info *, void __user *);
11866 +extern int vc_net_remove(struct nx_info *, void __user *);
11867 +
11868 +extern int vc_net_add_ipv4_v1(struct nx_info *, void __user *);
11869 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
11870 +
11871 +extern int vc_net_rem_ipv4_v1(struct nx_info *, void __user *);
11872 +extern int vc_net_rem_ipv4(struct nx_info *, void __user *);
11873 +
11874 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
11875 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
11876 +
11877 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
11878 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
11879 +
11880 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
11881 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
11882 +
11883 +extern int vc_get_nflags(struct nx_info *, void __user *);
11884 +extern int vc_set_nflags(struct nx_info *, void __user *);
11885 +
11886 +extern int vc_get_ncaps(struct nx_info *, void __user *);
11887 +extern int vc_set_ncaps(struct nx_info *, void __user *);
11888 +
11889 +#endif /* _VSERVER_CONTEXT_CMD_H */
11890 diff -NurpP --minimal linux-3.10.9/include/linux/vserver/percpu.h linux-3.10.9-vs2.3.6.6/include/linux/vserver/percpu.h
11891 --- linux-3.10.9/include/linux/vserver/percpu.h 1970-01-01 00:00:00.000000000 +0000
11892 +++ linux-3.10.9-vs2.3.6.6/include/linux/vserver/percpu.h       2013-08-22 20:30:00.000000000 +0000
11893 @@ -0,0 +1,14 @@
11894 +#ifndef _VSERVER_PERCPU_H
11895 +#define _VSERVER_PERCPU_H
11896 +
11897 +#include "cvirt_def.h"
11898 +#include "sched_def.h"
11899 +
11900 +struct _vx_percpu {
11901 +       struct _vx_cvirt_pc cvirt;
11902 +       struct _vx_sched_pc sched;
11903 +};
11904 +
11905 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
11906 +
11907 +#endif /* _VSERVER_PERCPU_H */
11908 diff -NurpP --minimal linux-3.10.9/include/linux/vserver/pid.h linux-3.10.9-vs2.3.6.6/include/linux/vserver/pid.h
11909 --- linux-3.10.9/include/linux/vserver/pid.h    1970-01-01 00:00:00.000000000 +0000
11910 +++ linux-3.10.9-vs2.3.6.6/include/linux/vserver/pid.h  2013-08-22 20:30:00.000000000 +0000
11911 @@ -0,0 +1,51 @@
11912 +#ifndef _VSERVER_PID_H
11913 +#define _VSERVER_PID_H
11914 +
11915 +/* pid faking stuff */
11916 +
11917 +#define vx_info_map_pid(v, p) \
11918 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
11919 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
11920 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
11921 +#define vx_map_tgid(p) vx_map_pid(p)
11922 +
11923 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
11924 +       const char *func, const char *file, int line)
11925 +{
11926 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
11927 +               vxfprintk(VXD_CBIT(cvirt, 2),
11928 +                       "vx_map_tgid: %p/%llx: %d -> %d",
11929 +                       vxi, (long long)vxi->vx_flags, pid,
11930 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
11931 +                       func, file, line);
11932 +               if (pid == 0)
11933 +                       return 0;
11934 +               if (pid == vxi->vx_initpid)
11935 +                       return 1;
11936 +       }
11937 +       return pid;
11938 +}
11939 +
11940 +#define vx_info_rmap_pid(v, p) \
11941 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
11942 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
11943 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
11944 +
11945 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
11946 +       const char *func, const char *file, int line)
11947 +{
11948 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
11949 +               vxfprintk(VXD_CBIT(cvirt, 2),
11950 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
11951 +                       vxi, (long long)vxi->vx_flags, pid,
11952 +                       (pid == 1) ? vxi->vx_initpid : pid,
11953 +                       func, file, line);
11954 +               if ((pid == 1) && vxi->vx_initpid)
11955 +                       return vxi->vx_initpid;
11956 +               if (pid == vxi->vx_initpid)
11957 +                       return ~0U;
11958 +       }
11959 +       return pid;
11960 +}
11961 +
11962 +#endif
11963 diff -NurpP --minimal linux-3.10.9/include/linux/vserver/sched.h linux-3.10.9-vs2.3.6.6/include/linux/vserver/sched.h
11964 --- linux-3.10.9/include/linux/vserver/sched.h  1970-01-01 00:00:00.000000000 +0000
11965 +++ linux-3.10.9-vs2.3.6.6/include/linux/vserver/sched.h        2013-08-22 20:30:00.000000000 +0000
11966 @@ -0,0 +1,23 @@
11967 +#ifndef _VSERVER_SCHED_H
11968 +#define _VSERVER_SCHED_H
11969 +
11970 +
11971 +#ifdef __KERNEL__
11972 +
11973 +struct timespec;
11974 +
11975 +void vx_vsi_uptime(struct timespec *, struct timespec *);
11976 +
11977 +
11978 +struct vx_info;
11979 +
11980 +void vx_update_load(struct vx_info *);
11981 +
11982 +
11983 +void vx_update_sched_param(struct _vx_sched *sched,
11984 +       struct _vx_sched_pc *sched_pc);
11985 +
11986 +#endif /* __KERNEL__ */
11987 +#else  /* _VSERVER_SCHED_H */
11988 +#warning duplicate inclusion
11989 +#endif /* _VSERVER_SCHED_H */
11990 diff -NurpP --minimal linux-3.10.9/include/linux/vserver/sched_cmd.h linux-3.10.9-vs2.3.6.6/include/linux/vserver/sched_cmd.h
11991 --- linux-3.10.9/include/linux/vserver/sched_cmd.h      1970-01-01 00:00:00.000000000 +0000
11992 +++ linux-3.10.9-vs2.3.6.6/include/linux/vserver/sched_cmd.h    2013-08-22 20:30:00.000000000 +0000
11993 @@ -0,0 +1,11 @@
11994 +#ifndef _VSERVER_SCHED_CMD_H
11995 +#define _VSERVER_SCHED_CMD_H
11996 +
11997 +
11998 +#include <linux/compiler.h>
11999 +#include <uapi/vserver/sched_cmd.h>
12000 +
12001 +extern int vc_set_prio_bias(struct vx_info *, void __user *);
12002 +extern int vc_get_prio_bias(struct vx_info *, void __user *);
12003 +
12004 +#endif /* _VSERVER_SCHED_CMD_H */
12005 diff -NurpP --minimal linux-3.10.9/include/linux/vserver/sched_def.h linux-3.10.9-vs2.3.6.6/include/linux/vserver/sched_def.h
12006 --- linux-3.10.9/include/linux/vserver/sched_def.h      1970-01-01 00:00:00.000000000 +0000
12007 +++ linux-3.10.9-vs2.3.6.6/include/linux/vserver/sched_def.h    2013-08-22 20:30:00.000000000 +0000
12008 @@ -0,0 +1,38 @@
12009 +#ifndef _VSERVER_SCHED_DEF_H
12010 +#define _VSERVER_SCHED_DEF_H
12011 +
12012 +#include <linux/spinlock.h>
12013 +#include <linux/jiffies.h>
12014 +#include <linux/cpumask.h>
12015 +#include <asm/atomic.h>
12016 +#include <asm/param.h>
12017 +
12018 +
12019 +/* context sub struct */
12020 +
12021 +struct _vx_sched {
12022 +       int prio_bias;                  /* bias offset for priority */
12023 +
12024 +       cpumask_t update;               /* CPUs which should update */
12025 +};
12026 +
12027 +struct _vx_sched_pc {
12028 +       int prio_bias;                  /* bias offset for priority */
12029 +
12030 +       uint64_t user_ticks;            /* token tick events */
12031 +       uint64_t sys_ticks;             /* token tick events */
12032 +       uint64_t hold_ticks;            /* token ticks paused */
12033 +};
12034 +
12035 +
12036 +#ifdef CONFIG_VSERVER_DEBUG
12037 +
12038 +static inline void __dump_vx_sched(struct _vx_sched *sched)
12039 +{
12040 +       printk("\t_vx_sched:\n");
12041 +       printk("\t priority = %4d\n", sched->prio_bias);
12042 +}
12043 +
12044 +#endif
12045 +
12046 +#endif /* _VSERVER_SCHED_DEF_H */
12047 diff -NurpP --minimal linux-3.10.9/include/linux/vserver/signal.h linux-3.10.9-vs2.3.6.6/include/linux/vserver/signal.h
12048 --- linux-3.10.9/include/linux/vserver/signal.h 1970-01-01 00:00:00.000000000 +0000
12049 +++ linux-3.10.9-vs2.3.6.6/include/linux/vserver/signal.h       2013-08-22 20:30:00.000000000 +0000
12050 @@ -0,0 +1,14 @@
12051 +#ifndef _VSERVER_SIGNAL_H
12052 +#define _VSERVER_SIGNAL_H
12053 +
12054 +
12055 +#ifdef __KERNEL__
12056 +
12057 +struct vx_info;
12058 +
12059 +int vx_info_kill(struct vx_info *, int, int);
12060 +
12061 +#endif /* __KERNEL__ */
12062 +#else  /* _VSERVER_SIGNAL_H */
12063 +#warning duplicate inclusion
12064 +#endif /* _VSERVER_SIGNAL_H */
12065 diff -NurpP --minimal linux-3.10.9/include/linux/vserver/signal_cmd.h linux-3.10.9-vs2.3.6.6/include/linux/vserver/signal_cmd.h
12066 --- linux-3.10.9/include/linux/vserver/signal_cmd.h     1970-01-01 00:00:00.000000000 +0000
12067 +++ linux-3.10.9-vs2.3.6.6/include/linux/vserver/signal_cmd.h   2013-08-22 20:30:00.000000000 +0000
12068 @@ -0,0 +1,14 @@
12069 +#ifndef _VSERVER_SIGNAL_CMD_H
12070 +#define _VSERVER_SIGNAL_CMD_H
12071 +
12072 +#include <uapi/vserver/signal_cmd.h>
12073 +
12074 +
12075 +extern int vc_ctx_kill(struct vx_info *, void __user *);
12076 +extern int vc_wait_exit(struct vx_info *, void __user *);
12077 +
12078 +
12079 +extern int vc_get_pflags(uint32_t pid, void __user *);
12080 +extern int vc_set_pflags(uint32_t pid, void __user *);
12081 +
12082 +#endif /* _VSERVER_SIGNAL_CMD_H */
12083 diff -NurpP --minimal linux-3.10.9/include/linux/vserver/space.h linux-3.10.9-vs2.3.6.6/include/linux/vserver/space.h
12084 --- linux-3.10.9/include/linux/vserver/space.h  1970-01-01 00:00:00.000000000 +0000
12085 +++ linux-3.10.9-vs2.3.6.6/include/linux/vserver/space.h        2013-08-22 20:30:00.000000000 +0000
12086 @@ -0,0 +1,12 @@
12087 +#ifndef _VSERVER_SPACE_H
12088 +#define _VSERVER_SPACE_H
12089 +
12090 +#include <linux/types.h>
12091 +
12092 +struct vx_info;
12093 +
12094 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
12095 +
12096 +#else  /* _VSERVER_SPACE_H */
12097 +#warning duplicate inclusion
12098 +#endif /* _VSERVER_SPACE_H */
12099 diff -NurpP --minimal linux-3.10.9/include/linux/vserver/space_cmd.h linux-3.10.9-vs2.3.6.6/include/linux/vserver/space_cmd.h
12100 --- linux-3.10.9/include/linux/vserver/space_cmd.h      1970-01-01 00:00:00.000000000 +0000
12101 +++ linux-3.10.9-vs2.3.6.6/include/linux/vserver/space_cmd.h    2013-08-22 20:30:00.000000000 +0000
12102 @@ -0,0 +1,13 @@
12103 +#ifndef _VSERVER_SPACE_CMD_H
12104 +#define _VSERVER_SPACE_CMD_H
12105 +
12106 +#include <uapi/vserver/space_cmd.h>
12107 +
12108 +
12109 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
12110 +extern int vc_set_space_v1(struct vx_info *, void __user *);
12111 +extern int vc_enter_space(struct vx_info *, void __user *);
12112 +extern int vc_set_space(struct vx_info *, void __user *);
12113 +extern int vc_get_space_mask(void __user *, int);
12114 +
12115 +#endif /* _VSERVER_SPACE_CMD_H */
12116 diff -NurpP --minimal linux-3.10.9/include/linux/vserver/switch.h linux-3.10.9-vs2.3.6.6/include/linux/vserver/switch.h
12117 --- linux-3.10.9/include/linux/vserver/switch.h 1970-01-01 00:00:00.000000000 +0000
12118 +++ linux-3.10.9-vs2.3.6.6/include/linux/vserver/switch.h       2013-08-22 20:30:00.000000000 +0000
12119 @@ -0,0 +1,8 @@
12120 +#ifndef _VSERVER_SWITCH_H
12121 +#define _VSERVER_SWITCH_H
12122 +
12123 +
12124 +#include <linux/errno.h>
12125 +#include <uapi/vserver/switch.h>
12126 +
12127 +#endif /* _VSERVER_SWITCH_H */
12128 diff -NurpP --minimal linux-3.10.9/include/linux/vserver/tag.h linux-3.10.9-vs2.3.6.6/include/linux/vserver/tag.h
12129 --- linux-3.10.9/include/linux/vserver/tag.h    1970-01-01 00:00:00.000000000 +0000
12130 +++ linux-3.10.9-vs2.3.6.6/include/linux/vserver/tag.h  2013-08-22 20:30:00.000000000 +0000
12131 @@ -0,0 +1,160 @@
12132 +#ifndef _DX_TAG_H
12133 +#define _DX_TAG_H
12134 +
12135 +#include <linux/types.h>
12136 +#include <linux/uidgid.h>
12137 +
12138 +
12139 +#define DX_TAG(in)     (IS_TAGGED(in))
12140 +
12141 +
12142 +#ifdef CONFIG_TAG_NFSD
12143 +#define DX_TAG_NFSD    1
12144 +#else
12145 +#define DX_TAG_NFSD    0
12146 +#endif
12147 +
12148 +
12149 +#ifdef CONFIG_TAGGING_NONE
12150 +
12151 +#define MAX_UID                0xFFFFFFFF
12152 +#define MAX_GID                0xFFFFFFFF
12153 +
12154 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
12155 +
12156 +#define TAGINO_UID(cond, uid, tag)     (uid)
12157 +#define TAGINO_GID(cond, gid, tag)     (gid)
12158 +
12159 +#endif
12160 +
12161 +
12162 +#ifdef CONFIG_TAGGING_GID16
12163 +
12164 +#define MAX_UID                0xFFFFFFFF
12165 +#define MAX_GID                0x0000FFFF
12166 +
12167 +#define INOTAG_TAG(cond, uid, gid, tag)        \
12168 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
12169 +
12170 +#define TAGINO_UID(cond, uid, tag)     (uid)
12171 +#define TAGINO_GID(cond, gid, tag)     \
12172 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
12173 +
12174 +#endif
12175 +
12176 +
12177 +#ifdef CONFIG_TAGGING_ID24
12178 +
12179 +#define MAX_UID                0x00FFFFFF
12180 +#define MAX_GID                0x00FFFFFF
12181 +
12182 +#define INOTAG_TAG(cond, uid, gid, tag)        \
12183 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
12184 +
12185 +#define TAGINO_UID(cond, uid, tag)     \
12186 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
12187 +#define TAGINO_GID(cond, gid, tag)     \
12188 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
12189 +
12190 +#endif
12191 +
12192 +
12193 +#ifdef CONFIG_TAGGING_UID16
12194 +
12195 +#define MAX_UID                0x0000FFFF
12196 +#define MAX_GID                0xFFFFFFFF
12197 +
12198 +#define INOTAG_TAG(cond, uid, gid, tag)        \
12199 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
12200 +
12201 +#define TAGINO_UID(cond, uid, tag)     \
12202 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
12203 +#define TAGINO_GID(cond, gid, tag)     (gid)
12204 +
12205 +#endif
12206 +
12207 +
12208 +#ifdef CONFIG_TAGGING_INTERN
12209 +
12210 +#define MAX_UID                0xFFFFFFFF
12211 +#define MAX_GID                0xFFFFFFFF
12212 +
12213 +#define INOTAG_TAG(cond, uid, gid, tag)        \
12214 +       ((cond) ? (tag) : 0)
12215 +
12216 +#define TAGINO_UID(cond, uid, tag)     (uid)
12217 +#define TAGINO_GID(cond, gid, tag)     (gid)
12218 +
12219 +#endif
12220 +
12221 +
12222 +#ifndef CONFIG_TAGGING_NONE
12223 +#define dx_current_fstag(sb)   \
12224 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
12225 +#else
12226 +#define dx_current_fstag(sb)   (0)
12227 +#endif
12228 +
12229 +#ifndef CONFIG_TAGGING_INTERN
12230 +#define TAGINO_TAG(cond, tag)  (0)
12231 +#else
12232 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
12233 +#endif
12234 +
12235 +#define TAGINO_KUID(cond, kuid, ktag)  \
12236 +       KUIDT_INIT(TAGINO_UID(cond, __kuid_val(kuid), __ktag_val(ktag)))
12237 +#define TAGINO_KGID(cond, kgid, ktag)  \
12238 +       KGIDT_INIT(TAGINO_GID(cond, __kgid_val(kgid), __ktag_val(ktag)))
12239 +#define TAGINO_KTAG(cond, ktag)                \
12240 +       KTAGT_INIT(TAGINO_TAG(cond, __ktag_val(ktag)))
12241 +
12242 +
12243 +#define INOTAG_UID(cond, uid, gid)     \
12244 +       ((cond) ? ((uid) & MAX_UID) : (uid))
12245 +#define INOTAG_GID(cond, uid, gid)     \
12246 +       ((cond) ? ((gid) & MAX_GID) : (gid))
12247 +
12248 +#define INOTAG_KUID(cond, kuid, kgid)  \
12249 +       KUIDT_INIT(INOTAG_UID(cond, __kuid_val(kuid), __kgid_val(kgid)))
12250 +#define INOTAG_KGID(cond, kuid, kgid)  \
12251 +       KGIDT_INIT(INOTAG_GID(cond, __kuid_val(kuid), __kgid_val(kgid)))
12252 +#define INOTAG_KTAG(cond, kuid, kgid, ktag) \
12253 +       KTAGT_INIT(INOTAG_TAG(cond, \
12254 +               __kuid_val(kuid), __kgid_val(kgid), __ktag_val(ktag)))
12255 +
12256 +
12257 +static inline uid_t dx_map_uid(uid_t uid)
12258 +{
12259 +       if ((uid > MAX_UID) && (uid != -1))
12260 +               uid = -2;
12261 +       return (uid & MAX_UID);
12262 +}
12263 +
12264 +static inline gid_t dx_map_gid(gid_t gid)
12265 +{
12266 +       if ((gid > MAX_GID) && (gid != -1))
12267 +               gid = -2;
12268 +       return (gid & MAX_GID);
12269 +}
12270 +
12271 +struct peer_tag {
12272 +       int32_t xid;
12273 +       int32_t nid;
12274 +};
12275 +
12276 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
12277 +
12278 +int dx_parse_tag(char *string, vtag_t *tag, int remove, int *mnt_flags,
12279 +                unsigned long *flags);
12280 +
12281 +#ifdef CONFIG_PROPAGATE
12282 +
12283 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
12284 +
12285 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
12286 +
12287 +#else
12288 +#define dx_propagate_tag(n, i) do { } while (0)
12289 +#endif
12290 +
12291 +#endif /* _DX_TAG_H */
12292 diff -NurpP --minimal linux-3.10.9/include/linux/vserver/tag_cmd.h linux-3.10.9-vs2.3.6.6/include/linux/vserver/tag_cmd.h
12293 --- linux-3.10.9/include/linux/vserver/tag_cmd.h        1970-01-01 00:00:00.000000000 +0000
12294 +++ linux-3.10.9-vs2.3.6.6/include/linux/vserver/tag_cmd.h      2013-08-22 20:30:00.000000000 +0000
12295 @@ -0,0 +1,10 @@
12296 +#ifndef _VSERVER_TAG_CMD_H
12297 +#define _VSERVER_TAG_CMD_H
12298 +
12299 +#include <uapi/vserver/tag_cmd.h>
12300 +
12301 +extern int vc_task_tag(uint32_t);
12302 +
12303 +extern int vc_tag_migrate(uint32_t);
12304 +
12305 +#endif /* _VSERVER_TAG_CMD_H */
12306 diff -NurpP --minimal linux-3.10.9/include/net/addrconf.h linux-3.10.9-vs2.3.6.6/include/net/addrconf.h
12307 --- linux-3.10.9/include/net/addrconf.h 2013-08-22 19:51:35.000000000 +0000
12308 +++ linux-3.10.9-vs2.3.6.6/include/net/addrconf.h       2013-08-22 20:32:06.000000000 +0000
12309 @@ -85,7 +85,8 @@ extern int                    ipv6_dev_get_saddr(struct n
12310                                                const struct net_device *dev,
12311                                                const struct in6_addr *daddr,
12312                                                unsigned int srcprefs,
12313 -                                              struct in6_addr *saddr);
12314 +                                              struct in6_addr *saddr,
12315 +                                              struct nx_info *nxi);
12316  extern int                     __ipv6_get_lladdr(struct inet6_dev *idev,
12317                                                   struct in6_addr *addr,
12318                                                   unsigned char banned_flags);
12319 diff -NurpP --minimal linux-3.10.9/include/net/af_unix.h linux-3.10.9-vs2.3.6.6/include/net/af_unix.h
12320 --- linux-3.10.9/include/net/af_unix.h  2013-07-14 17:01:33.000000000 +0000
12321 +++ linux-3.10.9-vs2.3.6.6/include/net/af_unix.h        2013-08-22 20:30:00.000000000 +0000
12322 @@ -4,6 +4,7 @@
12323  #include <linux/socket.h>
12324  #include <linux/un.h>
12325  #include <linux/mutex.h>
12326 +#include <linux/vs_base.h>
12327  #include <net/sock.h>
12328  
12329  extern void unix_inflight(struct file *fp);
12330 diff -NurpP --minimal linux-3.10.9/include/net/inet_timewait_sock.h linux-3.10.9-vs2.3.6.6/include/net/inet_timewait_sock.h
12331 --- linux-3.10.9/include/net/inet_timewait_sock.h       2013-05-31 13:45:28.000000000 +0000
12332 +++ linux-3.10.9-vs2.3.6.6/include/net/inet_timewait_sock.h     2013-08-22 20:30:00.000000000 +0000
12333 @@ -116,6 +116,10 @@ struct inet_timewait_sock {
12334  #define tw_dport               __tw_common.skc_dport
12335  #define tw_num                 __tw_common.skc_num
12336  #define tw_portpair            __tw_common.skc_portpair
12337 +#define tw_xid                 __tw_common.skc_xid
12338 +#define tw_vx_info             __tw_common.skc_vx_info
12339 +#define tw_nid                 __tw_common.skc_nid
12340 +#define tw_nx_info             __tw_common.skc_nx_info
12341  
12342         int                     tw_timeout;
12343         volatile unsigned char  tw_substate;
12344 diff -NurpP --minimal linux-3.10.9/include/net/ip6_route.h linux-3.10.9-vs2.3.6.6/include/net/ip6_route.h
12345 --- linux-3.10.9/include/net/ip6_route.h        2013-05-31 13:45:28.000000000 +0000
12346 +++ linux-3.10.9-vs2.3.6.6/include/net/ip6_route.h      2013-08-22 20:30:00.000000000 +0000
12347 @@ -95,7 +95,8 @@ extern int                    ip6_route_get_saddr(struct
12348                                                     struct rt6_info *rt,
12349                                                     const struct in6_addr *daddr,
12350                                                     unsigned int prefs,
12351 -                                                   struct in6_addr *saddr);
12352 +                                                   struct in6_addr *saddr,
12353 +                                                   struct nx_info *nxi);
12354  
12355  extern struct rt6_info         *rt6_lookup(struct net *net,
12356                                             const struct in6_addr *daddr,
12357 diff -NurpP --minimal linux-3.10.9/include/net/route.h linux-3.10.9-vs2.3.6.6/include/net/route.h
12358 --- linux-3.10.9/include/net/route.h    2013-02-19 13:58:52.000000000 +0000
12359 +++ linux-3.10.9-vs2.3.6.6/include/net/route.h  2013-08-22 20:30:00.000000000 +0000
12360 @@ -207,6 +207,9 @@ static inline void ip_rt_put(struct rtab
12361         dst_release(&rt->dst);
12362  }
12363  
12364 +#include <linux/vs_base.h>
12365 +#include <linux/vs_inet.h>
12366 +
12367  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
12368  
12369  extern const __u8 ip_tos2prio[16];
12370 @@ -256,6 +259,9 @@ static inline void ip_route_connect_init
12371                            protocol, flow_flags, dst, src, dport, sport);
12372  }
12373  
12374 +extern struct rtable *ip_v4_find_src(struct net *net, struct nx_info *,
12375 +       struct flowi4 *);
12376 +
12377  static inline struct rtable *ip_route_connect(struct flowi4 *fl4,
12378                                               __be32 dst, __be32 src, u32 tos,
12379                                               int oif, u8 protocol,
12380 @@ -264,11 +270,25 @@ static inline struct rtable *ip_route_co
12381  {
12382         struct net *net = sock_net(sk);
12383         struct rtable *rt;
12384 +       struct nx_info *nx_info = current_nx_info();
12385  
12386         ip_route_connect_init(fl4, dst, src, tos, oif, protocol,
12387                               sport, dport, sk, can_sleep);
12388  
12389 -       if (!dst || !src) {
12390 +       if (sk)
12391 +               nx_info = sk->sk_nx_info;
12392 +
12393 +       vxdprintk(VXD_CBIT(net, 4),
12394 +               "ip_route_connect(%p) %p,%p;%lx",
12395 +               sk, nx_info, sk->sk_socket,
12396 +               (sk->sk_socket?sk->sk_socket->flags:0));
12397 +
12398 +       rt = ip_v4_find_src(net, nx_info, fl4);
12399 +       if (IS_ERR(rt))
12400 +               return rt;
12401 +       ip_rt_put(rt);
12402 +
12403 +       if (!fl4->daddr || !fl4->saddr) {
12404                 rt = __ip_route_output_key(net, fl4);
12405                 if (IS_ERR(rt))
12406                         return rt;
12407 diff -NurpP --minimal linux-3.10.9/include/net/sock.h linux-3.10.9-vs2.3.6.6/include/net/sock.h
12408 --- linux-3.10.9/include/net/sock.h     2013-07-14 17:01:33.000000000 +0000
12409 +++ linux-3.10.9-vs2.3.6.6/include/net/sock.h   2013-08-22 20:30:00.000000000 +0000
12410 @@ -191,6 +191,10 @@ struct sock_common {
12411  #ifdef CONFIG_NET_NS
12412         struct net              *skc_net;
12413  #endif
12414 +       vxid_t                  skc_xid;
12415 +       struct vx_info          *skc_vx_info;
12416 +       vnid_t                  skc_nid;
12417 +       struct nx_info          *skc_nx_info;
12418         /*
12419          * fields between dontcopy_begin/dontcopy_end
12420          * are not copied in sock_copy()
12421 @@ -304,6 +308,10 @@ struct sock {
12422  #define sk_bind_node           __sk_common.skc_bind_node
12423  #define sk_prot                        __sk_common.skc_prot
12424  #define sk_net                 __sk_common.skc_net
12425 +#define sk_xid                 __sk_common.skc_xid
12426 +#define sk_vx_info             __sk_common.skc_vx_info
12427 +#define sk_nid                 __sk_common.skc_nid
12428 +#define sk_nx_info             __sk_common.skc_nx_info
12429         socket_lock_t           sk_lock;
12430         struct sk_buff_head     sk_receive_queue;
12431         /*
12432 diff -NurpP --minimal linux-3.10.9/include/uapi/Kbuild linux-3.10.9-vs2.3.6.6/include/uapi/Kbuild
12433 --- linux-3.10.9/include/uapi/Kbuild    2012-12-11 03:30:57.000000000 +0000
12434 +++ linux-3.10.9-vs2.3.6.6/include/uapi/Kbuild  2013-08-22 20:30:00.000000000 +0000
12435 @@ -12,3 +12,4 @@ header-y += video/
12436  header-y += drm/
12437  header-y += xen/
12438  header-y += scsi/
12439 +header-y += vserver/
12440 diff -NurpP --minimal linux-3.10.9/include/uapi/linux/capability.h linux-3.10.9-vs2.3.6.6/include/uapi/linux/capability.h
12441 --- linux-3.10.9/include/uapi/linux/capability.h        2012-12-11 03:30:57.000000000 +0000
12442 +++ linux-3.10.9-vs2.3.6.6/include/uapi/linux/capability.h      2013-08-22 20:30:00.000000000 +0000
12443 @@ -259,6 +259,7 @@ struct vfs_cap_data {
12444     arbitrary SCSI commands */
12445  /* Allow setting encryption key on loopback filesystem */
12446  /* Allow setting zone reclaim policy */
12447 +/* Allow the selection of a security context */
12448  
12449  #define CAP_SYS_ADMIN        21
12450  
12451 @@ -345,7 +346,12 @@ struct vfs_cap_data {
12452  
12453  #define CAP_LAST_CAP         CAP_BLOCK_SUSPEND
12454  
12455 -#define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
12456 +/* Allow context manipulations */
12457 +/* Allow changing context info on files */
12458 +
12459 +#define CAP_CONTEXT         63
12460 +
12461 +#define cap_valid(x) ((x) >= 0 && ((x) <= CAP_LAST_CAP || (x) == CAP_CONTEXT))
12462  
12463  /*
12464   * Bit location of each capability (used by user-space library and kernel)
12465 diff -NurpP --minimal linux-3.10.9/include/uapi/linux/fs.h linux-3.10.9-vs2.3.6.6/include/uapi/linux/fs.h
12466 --- linux-3.10.9/include/uapi/linux/fs.h        2013-07-14 17:01:34.000000000 +0000
12467 +++ linux-3.10.9-vs2.3.6.6/include/uapi/linux/fs.h      2013-08-22 20:30:00.000000000 +0000
12468 @@ -86,6 +86,9 @@ struct inodes_stat_t {
12469  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
12470  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
12471  #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
12472 +#define MS_TAGGED      (1<<8)  /* use generic inode tagging */
12473 +#define MS_NOTAGCHECK  (1<<9)  /* don't check tags */
12474 +#define MS_TAGID       (1<<25) /* use specific tag for this mount */
12475  
12476  /* These sb flags are internal to the kernel */
12477  #define MS_NOSEC       (1<<28)
12478 @@ -191,11 +194,14 @@ struct inodes_stat_t {
12479  #define FS_EXTENT_FL                   0x00080000 /* Extents */
12480  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
12481  #define FS_NOCOW_FL                    0x00800000 /* Do not cow file */
12482 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
12483  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
12484  
12485 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
12486 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
12487 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
12488 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
12489  
12490 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
12491 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
12492  
12493  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
12494  #define SYNC_FILE_RANGE_WRITE          2
12495 diff -NurpP --minimal linux-3.10.9/include/uapi/linux/gfs2_ondisk.h linux-3.10.9-vs2.3.6.6/include/uapi/linux/gfs2_ondisk.h
12496 --- linux-3.10.9/include/uapi/linux/gfs2_ondisk.h       2012-12-11 03:30:57.000000000 +0000
12497 +++ linux-3.10.9-vs2.3.6.6/include/uapi/linux/gfs2_ondisk.h     2013-08-22 20:30:00.000000000 +0000
12498 @@ -225,6 +225,9 @@ enum {
12499         gfs2fl_Sync             = 8,
12500         gfs2fl_System           = 9,
12501         gfs2fl_TopLevel         = 10,
12502 +       gfs2fl_IXUnlink         = 16,
12503 +       gfs2fl_Barrier          = 17,
12504 +       gfs2fl_Cow              = 18,
12505         gfs2fl_TruncInProg      = 29,
12506         gfs2fl_InheritDirectio  = 30,
12507         gfs2fl_InheritJdata     = 31,
12508 @@ -242,6 +245,9 @@ enum {
12509  #define GFS2_DIF_SYNC                  0x00000100
12510  #define GFS2_DIF_SYSTEM                        0x00000200 /* New in gfs2 */
12511  #define GFS2_DIF_TOPDIR                        0x00000400 /* New in gfs2 */
12512 +#define GFS2_DIF_IXUNLINK               0x00010000
12513 +#define GFS2_DIF_BARRIER                0x00020000
12514 +#define GFS2_DIF_COW                    0x00040000
12515  #define GFS2_DIF_TRUNC_IN_PROG         0x20000000 /* New in gfs2 */
12516  #define GFS2_DIF_INHERIT_DIRECTIO      0x40000000 /* only in gfs1 */
12517  #define GFS2_DIF_INHERIT_JDATA         0x80000000
12518 diff -NurpP --minimal linux-3.10.9/include/uapi/linux/if_tun.h linux-3.10.9-vs2.3.6.6/include/uapi/linux/if_tun.h
12519 --- linux-3.10.9/include/uapi/linux/if_tun.h    2013-02-19 13:58:55.000000000 +0000
12520 +++ linux-3.10.9-vs2.3.6.6/include/uapi/linux/if_tun.h  2013-08-22 20:30:00.000000000 +0000
12521 @@ -56,6 +56,7 @@
12522  #define TUNGETVNETHDRSZ _IOR('T', 215, int)
12523  #define TUNSETVNETHDRSZ _IOW('T', 216, int)
12524  #define TUNSETQUEUE  _IOW('T', 217, int)
12525 +#define TUNSETNID     _IOW('T', 218, int)
12526  
12527  /* TUNSETIFF ifr flags */
12528  #define IFF_TUN                0x0001
12529 diff -NurpP --minimal linux-3.10.9/include/uapi/linux/major.h linux-3.10.9-vs2.3.6.6/include/uapi/linux/major.h
12530 --- linux-3.10.9/include/uapi/linux/major.h     2012-12-11 03:30:57.000000000 +0000
12531 +++ linux-3.10.9-vs2.3.6.6/include/uapi/linux/major.h   2013-08-22 20:30:00.000000000 +0000
12532 @@ -15,6 +15,7 @@
12533  #define HD_MAJOR               IDE0_MAJOR
12534  #define PTY_SLAVE_MAJOR                3
12535  #define TTY_MAJOR              4
12536 +#define VROOT_MAJOR            4
12537  #define TTYAUX_MAJOR           5
12538  #define LP_MAJOR               6
12539  #define VCS_MAJOR              7
12540 diff -NurpP --minimal linux-3.10.9/include/uapi/linux/nfs_mount.h linux-3.10.9-vs2.3.6.6/include/uapi/linux/nfs_mount.h
12541 --- linux-3.10.9/include/uapi/linux/nfs_mount.h 2012-12-11 03:30:57.000000000 +0000
12542 +++ linux-3.10.9-vs2.3.6.6/include/uapi/linux/nfs_mount.h       2013-08-22 20:30:00.000000000 +0000
12543 @@ -63,7 +63,8 @@ struct nfs_mount_data {
12544  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
12545  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
12546  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
12547 -#define NFS_MOUNT_FLAGMASK     0xFFFF
12548 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
12549 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
12550  
12551  /* The following are for internal use only */
12552  #define NFS_MOUNT_LOOKUP_CACHE_NONEG   0x10000
12553 diff -NurpP --minimal linux-3.10.9/include/uapi/linux/reboot.h linux-3.10.9-vs2.3.6.6/include/uapi/linux/reboot.h
12554 --- linux-3.10.9/include/uapi/linux/reboot.h    2012-12-11 03:30:57.000000000 +0000
12555 +++ linux-3.10.9-vs2.3.6.6/include/uapi/linux/reboot.h  2013-08-22 20:30:00.000000000 +0000
12556 @@ -33,7 +33,7 @@
12557  #define        LINUX_REBOOT_CMD_RESTART2       0xA1B2C3D4
12558  #define        LINUX_REBOOT_CMD_SW_SUSPEND     0xD000FCE2
12559  #define        LINUX_REBOOT_CMD_KEXEC          0x45584543
12560 -
12561 +#define        LINUX_REBOOT_CMD_OOM            0xDEADBEEF
12562  
12563  
12564  #endif /* _UAPI_LINUX_REBOOT_H */
12565 diff -NurpP --minimal linux-3.10.9/include/uapi/linux/sysctl.h linux-3.10.9-vs2.3.6.6/include/uapi/linux/sysctl.h
12566 --- linux-3.10.9/include/uapi/linux/sysctl.h    2012-12-11 03:30:57.000000000 +0000
12567 +++ linux-3.10.9-vs2.3.6.6/include/uapi/linux/sysctl.h  2013-08-22 20:30:00.000000000 +0000
12568 @@ -60,6 +60,7 @@ enum
12569         CTL_ABI=9,              /* Binary emulation */
12570         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
12571         CTL_ARLAN=254,          /* arlan wireless driver */
12572 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
12573         CTL_S390DBF=5677,       /* s390 debug */
12574         CTL_SUNRPC=7249,        /* sunrpc debug */
12575         CTL_PM=9899,            /* frv power management */
12576 @@ -94,6 +95,7 @@ enum
12577  
12578         KERN_PANIC=15,          /* int: panic timeout */
12579         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
12580 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
12581  
12582         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
12583         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
12584 diff -NurpP --minimal linux-3.10.9/include/uapi/vserver/Kbuild linux-3.10.9-vs2.3.6.6/include/uapi/vserver/Kbuild
12585 --- linux-3.10.9/include/uapi/vserver/Kbuild    1970-01-01 00:00:00.000000000 +0000
12586 +++ linux-3.10.9-vs2.3.6.6/include/uapi/vserver/Kbuild  2013-08-22 20:30:00.000000000 +0000
12587 @@ -0,0 +1,9 @@
12588 +
12589 +header-y += context_cmd.h network_cmd.h space_cmd.h \
12590 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
12591 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
12592 +       debug_cmd.h device_cmd.h
12593 +
12594 +header-y += switch.h context.h network.h monitor.h \
12595 +       limit.h inode.h device.h
12596 +
12597 diff -NurpP --minimal linux-3.10.9/include/uapi/vserver/cacct_cmd.h linux-3.10.9-vs2.3.6.6/include/uapi/vserver/cacct_cmd.h
12598 --- linux-3.10.9/include/uapi/vserver/cacct_cmd.h       1970-01-01 00:00:00.000000000 +0000
12599 +++ linux-3.10.9-vs2.3.6.6/include/uapi/vserver/cacct_cmd.h     2013-08-22 20:30:00.000000000 +0000
12600 @@ -0,0 +1,15 @@
12601 +#ifndef _UAPI_VS_CACCT_CMD_H
12602 +#define _UAPI_VS_CACCT_CMD_H
12603 +
12604 +
12605 +/* virtual host info name commands */
12606 +
12607 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
12608 +
12609 +struct vcmd_sock_stat_v0 {
12610 +       uint32_t field;
12611 +       uint32_t count[3];
12612 +       uint64_t total[3];
12613 +};
12614 +
12615 +#endif /* _UAPI_VS_CACCT_CMD_H */
12616 diff -NurpP --minimal linux-3.10.9/include/uapi/vserver/context.h linux-3.10.9-vs2.3.6.6/include/uapi/vserver/context.h
12617 --- linux-3.10.9/include/uapi/vserver/context.h 1970-01-01 00:00:00.000000000 +0000
12618 +++ linux-3.10.9-vs2.3.6.6/include/uapi/vserver/context.h       2013-08-22 20:30:00.000000000 +0000
12619 @@ -0,0 +1,81 @@
12620 +#ifndef _UAPI_VS_CONTEXT_H
12621 +#define _UAPI_VS_CONTEXT_H
12622 +
12623 +#include <linux/types.h>
12624 +#include <linux/capability.h>
12625 +
12626 +
12627 +/* context flags */
12628 +
12629 +#define VXF_INFO_SCHED         0x00000002
12630 +#define VXF_INFO_NPROC         0x00000004
12631 +#define VXF_INFO_PRIVATE       0x00000008
12632 +
12633 +#define VXF_INFO_INIT          0x00000010
12634 +#define VXF_INFO_HIDE          0x00000020
12635 +#define VXF_INFO_ULIMIT                0x00000040
12636 +#define VXF_INFO_NSPACE                0x00000080
12637 +
12638 +#define VXF_SCHED_HARD         0x00000100
12639 +#define VXF_SCHED_PRIO         0x00000200
12640 +#define VXF_SCHED_PAUSE                0x00000400
12641 +
12642 +#define VXF_VIRT_MEM           0x00010000
12643 +#define VXF_VIRT_UPTIME                0x00020000
12644 +#define VXF_VIRT_CPU           0x00040000
12645 +#define VXF_VIRT_LOAD          0x00080000
12646 +#define VXF_VIRT_TIME          0x00100000
12647 +
12648 +#define VXF_HIDE_MOUNT         0x01000000
12649 +/* was VXF_HIDE_NETIF          0x02000000 */
12650 +#define VXF_HIDE_VINFO         0x04000000
12651 +
12652 +#define VXF_STATE_SETUP                (1ULL << 32)
12653 +#define VXF_STATE_INIT         (1ULL << 33)
12654 +#define VXF_STATE_ADMIN                (1ULL << 34)
12655 +
12656 +#define VXF_SC_HELPER          (1ULL << 36)
12657 +#define VXF_REBOOT_KILL                (1ULL << 37)
12658 +#define VXF_PERSISTENT         (1ULL << 38)
12659 +
12660 +#define VXF_FORK_RSS           (1ULL << 48)
12661 +#define VXF_PROLIFIC           (1ULL << 49)
12662 +
12663 +#define VXF_IGNEG_NICE         (1ULL << 52)
12664 +
12665 +#define VXF_ONE_TIME           (0x0007ULL << 32)
12666 +
12667 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
12668 +
12669 +
12670 +/* context migration */
12671 +
12672 +#define VXM_SET_INIT           0x00000001
12673 +#define VXM_SET_REAPER         0x00000002
12674 +
12675 +/* context caps */
12676 +
12677 +#define VXC_SET_UTSNAME                0x00000001
12678 +#define VXC_SET_RLIMIT         0x00000002
12679 +#define VXC_FS_SECURITY                0x00000004
12680 +#define VXC_FS_TRUSTED         0x00000008
12681 +#define VXC_TIOCSTI            0x00000010
12682 +
12683 +/* was VXC_RAW_ICMP            0x00000100 */
12684 +#define VXC_SYSLOG             0x00001000
12685 +#define VXC_OOM_ADJUST         0x00002000
12686 +#define VXC_AUDIT_CONTROL      0x00004000
12687 +
12688 +/* #define VXC_SECURE_MOUNT    0x00010000
12689 +#define VXC_SECURE_REMOUNT     0x00020000 */
12690 +#define VXC_BINARY_MOUNT       0x00040000
12691 +#define VXC_DEV_MOUNT          0x00080000
12692 +
12693 +#define VXC_QUOTA_CTL          0x00100000
12694 +#define VXC_ADMIN_MAPPER       0x00200000
12695 +#define VXC_ADMIN_CLOOP                0x00400000
12696 +
12697 +#define VXC_KTHREAD            0x01000000
12698 +#define VXC_NAMESPACE          0x02000000
12699 +
12700 +#endif /* _UAPI_VS_CONTEXT_H */
12701 diff -NurpP --minimal linux-3.10.9/include/uapi/vserver/context_cmd.h linux-3.10.9-vs2.3.6.6/include/uapi/vserver/context_cmd.h
12702 --- linux-3.10.9/include/uapi/vserver/context_cmd.h     1970-01-01 00:00:00.000000000 +0000
12703 +++ linux-3.10.9-vs2.3.6.6/include/uapi/vserver/context_cmd.h   2013-08-22 20:30:00.000000000 +0000
12704 @@ -0,0 +1,115 @@
12705 +#ifndef _UAPI_VS_CONTEXT_CMD_H
12706 +#define _UAPI_VS_CONTEXT_CMD_H
12707 +
12708 +
12709 +/* vinfo commands */
12710 +
12711 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
12712 +
12713 +
12714 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
12715 +
12716 +struct vcmd_vx_info_v0 {
12717 +       uint32_t xid;
12718 +       uint32_t initpid;
12719 +       /* more to come */
12720 +};
12721 +
12722 +
12723 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
12724 +
12725 +struct vcmd_ctx_stat_v0 {
12726 +       uint32_t usecnt;
12727 +       uint32_t tasks;
12728 +       /* more to come */
12729 +};
12730 +
12731 +
12732 +/* context commands */
12733 +
12734 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
12735 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
12736 +
12737 +struct vcmd_ctx_create {
12738 +       uint64_t flagword;
12739 +};
12740 +
12741 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
12742 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
12743 +
12744 +struct vcmd_ctx_migrate {
12745 +       uint64_t flagword;
12746 +};
12747 +
12748 +
12749 +
12750 +/* flag commands */
12751 +
12752 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
12753 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
12754 +
12755 +struct vcmd_ctx_flags_v0 {
12756 +       uint64_t flagword;
12757 +       uint64_t mask;
12758 +};
12759 +
12760 +
12761 +
12762 +/* context caps commands */
12763 +
12764 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
12765 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
12766 +
12767 +struct vcmd_ctx_caps_v1 {
12768 +       uint64_t ccaps;
12769 +       uint64_t cmask;
12770 +};
12771 +
12772 +
12773 +
12774 +/* bcaps commands */
12775 +
12776 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
12777 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
12778 +
12779 +struct vcmd_bcaps {
12780 +       uint64_t bcaps;
12781 +       uint64_t bmask;
12782 +};
12783 +
12784 +
12785 +
12786 +/* umask commands */
12787 +
12788 +#define VCMD_get_umask         VC_CMD(FLAGS, 13, 0)
12789 +#define VCMD_set_umask         VC_CMD(FLAGS, 14, 0)
12790 +
12791 +struct vcmd_umask {
12792 +       uint64_t umask;
12793 +       uint64_t mask;
12794 +};
12795 +
12796 +
12797 +
12798 +/* wmask commands */
12799 +
12800 +#define VCMD_get_wmask         VC_CMD(FLAGS, 15, 0)
12801 +#define VCMD_set_wmask         VC_CMD(FLAGS, 16, 0)
12802 +
12803 +struct vcmd_wmask {
12804 +       uint64_t wmask;
12805 +       uint64_t mask;
12806 +};
12807 +
12808 +
12809 +
12810 +/* OOM badness */
12811 +
12812 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
12813 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
12814 +
12815 +struct vcmd_badness_v0 {
12816 +       int64_t bias;
12817 +};
12818 +
12819 +#endif /* _UAPI_VS_CONTEXT_CMD_H */
12820 diff -NurpP --minimal linux-3.10.9/include/uapi/vserver/cvirt_cmd.h linux-3.10.9-vs2.3.6.6/include/uapi/vserver/cvirt_cmd.h
12821 --- linux-3.10.9/include/uapi/vserver/cvirt_cmd.h       1970-01-01 00:00:00.000000000 +0000
12822 +++ linux-3.10.9-vs2.3.6.6/include/uapi/vserver/cvirt_cmd.h     2013-08-22 20:30:00.000000000 +0000
12823 @@ -0,0 +1,41 @@
12824 +#ifndef _UAPI_VS_CVIRT_CMD_H
12825 +#define _UAPI_VS_CVIRT_CMD_H
12826 +
12827 +
12828 +/* virtual host info name commands */
12829 +
12830 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
12831 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
12832 +
12833 +struct vcmd_vhi_name_v0 {
12834 +       uint32_t field;
12835 +       char name[65];
12836 +};
12837 +
12838 +
12839 +enum vhi_name_field {
12840 +       VHIN_CONTEXT = 0,
12841 +       VHIN_SYSNAME,
12842 +       VHIN_NODENAME,
12843 +       VHIN_RELEASE,
12844 +       VHIN_VERSION,
12845 +       VHIN_MACHINE,
12846 +       VHIN_DOMAINNAME,
12847 +};
12848 +
12849 +
12850 +
12851 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
12852 +
12853 +struct vcmd_virt_stat_v0 {
12854 +       uint64_t offset;
12855 +       uint64_t uptime;
12856 +       uint32_t nr_threads;
12857 +       uint32_t nr_running;
12858 +       uint32_t nr_uninterruptible;
12859 +       uint32_t nr_onhold;
12860 +       uint32_t nr_forks;
12861 +       uint32_t load[3];
12862 +};
12863 +
12864 +#endif /* _UAPI_VS_CVIRT_CMD_H */
12865 diff -NurpP --minimal linux-3.10.9/include/uapi/vserver/debug_cmd.h linux-3.10.9-vs2.3.6.6/include/uapi/vserver/debug_cmd.h
12866 --- linux-3.10.9/include/uapi/vserver/debug_cmd.h       1970-01-01 00:00:00.000000000 +0000
12867 +++ linux-3.10.9-vs2.3.6.6/include/uapi/vserver/debug_cmd.h     2013-08-22 20:30:00.000000000 +0000
12868 @@ -0,0 +1,24 @@
12869 +#ifndef _UAPI_VS_DEBUG_CMD_H
12870 +#define _UAPI_VS_DEBUG_CMD_H
12871 +
12872 +
12873 +/* debug commands */
12874 +
12875 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
12876 +
12877 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
12878 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
12879 +
12880 +struct  vcmd_read_history_v0 {
12881 +       uint32_t index;
12882 +       uint32_t count;
12883 +       char __user *data;
12884 +};
12885 +
12886 +struct  vcmd_read_monitor_v0 {
12887 +       uint32_t index;
12888 +       uint32_t count;
12889 +       char __user *data;
12890 +};
12891 +
12892 +#endif /* _UAPI_VS_DEBUG_CMD_H */
12893 diff -NurpP --minimal linux-3.10.9/include/uapi/vserver/device.h linux-3.10.9-vs2.3.6.6/include/uapi/vserver/device.h
12894 --- linux-3.10.9/include/uapi/vserver/device.h  1970-01-01 00:00:00.000000000 +0000
12895 +++ linux-3.10.9-vs2.3.6.6/include/uapi/vserver/device.h        2013-08-22 20:30:00.000000000 +0000
12896 @@ -0,0 +1,12 @@
12897 +#ifndef _UAPI_VS_DEVICE_H
12898 +#define _UAPI_VS_DEVICE_H
12899 +
12900 +
12901 +#define DATTR_CREATE   0x00000001
12902 +#define DATTR_OPEN     0x00000002
12903 +
12904 +#define DATTR_REMAP    0x00000010
12905 +
12906 +#define DATTR_MASK     0x00000013
12907 +
12908 +#endif /* _UAPI_VS_DEVICE_H */
12909 diff -NurpP --minimal linux-3.10.9/include/uapi/vserver/device_cmd.h linux-3.10.9-vs2.3.6.6/include/uapi/vserver/device_cmd.h
12910 --- linux-3.10.9/include/uapi/vserver/device_cmd.h      1970-01-01 00:00:00.000000000 +0000
12911 +++ linux-3.10.9-vs2.3.6.6/include/uapi/vserver/device_cmd.h    2013-08-22 20:30:00.000000000 +0000
12912 @@ -0,0 +1,16 @@
12913 +#ifndef _UAPI_VS_DEVICE_CMD_H
12914 +#define _UAPI_VS_DEVICE_CMD_H
12915 +
12916 +
12917 +/*  device vserver commands */
12918 +
12919 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
12920 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
12921 +
12922 +struct vcmd_set_mapping_v0 {
12923 +       const char __user *device;
12924 +       const char __user *target;
12925 +       uint32_t flags;
12926 +};
12927 +
12928 +#endif /* _UAPI_VS_DEVICE_CMD_H */
12929 diff -NurpP --minimal linux-3.10.9/include/uapi/vserver/dlimit_cmd.h linux-3.10.9-vs2.3.6.6/include/uapi/vserver/dlimit_cmd.h
12930 --- linux-3.10.9/include/uapi/vserver/dlimit_cmd.h      1970-01-01 00:00:00.000000000 +0000
12931 +++ linux-3.10.9-vs2.3.6.6/include/uapi/vserver/dlimit_cmd.h    2013-08-22 20:30:00.000000000 +0000
12932 @@ -0,0 +1,67 @@
12933 +#ifndef _UAPI_VS_DLIMIT_CMD_H
12934 +#define _UAPI_VS_DLIMIT_CMD_H
12935 +
12936 +
12937 +/*  dlimit vserver commands */
12938 +
12939 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
12940 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
12941 +
12942 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
12943 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
12944 +
12945 +struct vcmd_ctx_dlimit_base_v0 {
12946 +       const char __user *name;
12947 +       uint32_t flags;
12948 +};
12949 +
12950 +struct vcmd_ctx_dlimit_v0 {
12951 +       const char __user *name;
12952 +       uint32_t space_used;                    /* used space in kbytes */
12953 +       uint32_t space_total;                   /* maximum space in kbytes */
12954 +       uint32_t inodes_used;                   /* used inodes */
12955 +       uint32_t inodes_total;                  /* maximum inodes */
12956 +       uint32_t reserved;                      /* reserved for root in % */
12957 +       uint32_t flags;
12958 +};
12959 +
12960 +#define CDLIM_UNSET            ((uint32_t)0UL)
12961 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
12962 +#define CDLIM_KEEP             ((uint32_t)~1UL)
12963 +
12964 +#define DLIME_UNIT     0
12965 +#define DLIME_KILO     1
12966 +#define DLIME_MEGA     2
12967 +#define DLIME_GIGA     3
12968 +
12969 +#define DLIMF_SHIFT    0x10
12970 +
12971 +#define DLIMS_USED     0
12972 +#define DLIMS_TOTAL    2
12973 +
12974 +static inline
12975 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
12976 +{
12977 +       int exp = (flags & DLIMF_SHIFT) ?
12978 +               (flags >> shift) & DLIME_GIGA : DLIME_KILO;
12979 +       return ((uint64_t)val) << (10 * exp);
12980 +}
12981 +
12982 +static inline
12983 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
12984 +{
12985 +       int exp = 0;
12986 +
12987 +       if (*flags & DLIMF_SHIFT) {
12988 +               while (val > (1LL << 32) && (exp < 3)) {
12989 +                       val >>= 10;
12990 +                       exp++;
12991 +               }
12992 +               *flags &= ~(DLIME_GIGA << shift);
12993 +               *flags |= exp << shift;
12994 +       } else
12995 +               val >>= 10;
12996 +       return val;
12997 +}
12998 +
12999 +#endif /* _UAPI_VS_DLIMIT_CMD_H */
13000 diff -NurpP --minimal linux-3.10.9/include/uapi/vserver/inode.h linux-3.10.9-vs2.3.6.6/include/uapi/vserver/inode.h
13001 --- linux-3.10.9/include/uapi/vserver/inode.h   1970-01-01 00:00:00.000000000 +0000
13002 +++ linux-3.10.9-vs2.3.6.6/include/uapi/vserver/inode.h 2013-08-22 20:30:00.000000000 +0000
13003 @@ -0,0 +1,23 @@
13004 +#ifndef _UAPI_VS_INODE_H
13005 +#define _UAPI_VS_INODE_H
13006 +
13007 +
13008 +#define IATTR_TAG      0x01000000
13009 +
13010 +#define IATTR_ADMIN    0x00000001
13011 +#define IATTR_WATCH    0x00000002
13012 +#define IATTR_HIDE     0x00000004
13013 +#define IATTR_FLAGS    0x00000007
13014 +
13015 +#define IATTR_BARRIER  0x00010000
13016 +#define IATTR_IXUNLINK 0x00020000
13017 +#define IATTR_IMMUTABLE 0x00040000
13018 +#define IATTR_COW      0x00080000
13019 +
13020 +
13021 +/* inode ioctls */
13022 +
13023 +#define FIOC_GETXFLG   _IOR('x', 5, long)
13024 +#define FIOC_SETXFLG   _IOW('x', 6, long)
13025 +
13026 +#endif /* _UAPI_VS_INODE_H */
13027 diff -NurpP --minimal linux-3.10.9/include/uapi/vserver/inode_cmd.h linux-3.10.9-vs2.3.6.6/include/uapi/vserver/inode_cmd.h
13028 --- linux-3.10.9/include/uapi/vserver/inode_cmd.h       1970-01-01 00:00:00.000000000 +0000
13029 +++ linux-3.10.9-vs2.3.6.6/include/uapi/vserver/inode_cmd.h     2013-08-22 20:30:00.000000000 +0000
13030 @@ -0,0 +1,26 @@
13031 +#ifndef _UAPI_VS_INODE_CMD_H
13032 +#define _UAPI_VS_INODE_CMD_H
13033 +
13034 +
13035 +/*  inode vserver commands */
13036 +
13037 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
13038 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
13039 +
13040 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
13041 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
13042 +
13043 +struct vcmd_ctx_iattr_v1 {
13044 +       const char __user *name;
13045 +       uint32_t tag;
13046 +       uint32_t flags;
13047 +       uint32_t mask;
13048 +};
13049 +
13050 +struct vcmd_ctx_fiattr_v0 {
13051 +       uint32_t tag;
13052 +       uint32_t flags;
13053 +       uint32_t mask;
13054 +};
13055 +
13056 +#endif /* _UAPI_VS_INODE_CMD_H */
13057 diff -NurpP --minimal linux-3.10.9/include/uapi/vserver/limit.h linux-3.10.9-vs2.3.6.6/include/uapi/vserver/limit.h
13058 --- linux-3.10.9/include/uapi/vserver/limit.h   1970-01-01 00:00:00.000000000 +0000
13059 +++ linux-3.10.9-vs2.3.6.6/include/uapi/vserver/limit.h 2013-08-22 20:30:00.000000000 +0000
13060 @@ -0,0 +1,14 @@
13061 +#ifndef _UAPI_VS_LIMIT_H
13062 +#define _UAPI_VS_LIMIT_H
13063 +
13064 +
13065 +#define VLIMIT_NSOCK   16
13066 +#define VLIMIT_OPENFD  17
13067 +#define VLIMIT_ANON    18
13068 +#define VLIMIT_SHMEM   19
13069 +#define VLIMIT_SEMARY  20
13070 +#define VLIMIT_NSEMS   21
13071 +#define VLIMIT_DENTRY  22
13072 +#define VLIMIT_MAPPED  23
13073 +
13074 +#endif /* _UAPI_VS_LIMIT_H */
13075 diff -NurpP --minimal linux-3.10.9/include/uapi/vserver/limit_cmd.h linux-3.10.9-vs2.3.6.6/include/uapi/vserver/limit_cmd.h
13076 --- linux-3.10.9/include/uapi/vserver/limit_cmd.h       1970-01-01 00:00:00.000000000 +0000
13077 +++ linux-3.10.9-vs2.3.6.6/include/uapi/vserver/limit_cmd.h     2013-08-22 20:30:00.000000000 +0000
13078 @@ -0,0 +1,40 @@
13079 +#ifndef _UAPI_VS_LIMIT_CMD_H
13080 +#define _UAPI_VS_LIMIT_CMD_H
13081 +
13082 +
13083 +/*  rlimit vserver commands */
13084 +
13085 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
13086 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
13087 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
13088 +#define VCMD_reset_hits                VC_CMD(RLIMIT, 7, 0)
13089 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
13090 +
13091 +struct vcmd_ctx_rlimit_v0 {
13092 +       uint32_t id;
13093 +       uint64_t minimum;
13094 +       uint64_t softlimit;
13095 +       uint64_t maximum;
13096 +};
13097 +
13098 +struct vcmd_ctx_rlimit_mask_v0 {
13099 +       uint32_t minimum;
13100 +       uint32_t softlimit;
13101 +       uint32_t maximum;
13102 +};
13103 +
13104 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
13105 +
13106 +struct vcmd_rlimit_stat_v0 {
13107 +       uint32_t id;
13108 +       uint32_t hits;
13109 +       uint64_t value;
13110 +       uint64_t minimum;
13111 +       uint64_t maximum;
13112 +};
13113 +
13114 +#define CRLIM_UNSET            (0ULL)
13115 +#define CRLIM_INFINITY         (~0ULL)
13116 +#define CRLIM_KEEP             (~1ULL)
13117 +
13118 +#endif /* _UAPI_VS_LIMIT_CMD_H */
13119 diff -NurpP --minimal linux-3.10.9/include/uapi/vserver/monitor.h linux-3.10.9-vs2.3.6.6/include/uapi/vserver/monitor.h
13120 --- linux-3.10.9/include/uapi/vserver/monitor.h 1970-01-01 00:00:00.000000000 +0000
13121 +++ linux-3.10.9-vs2.3.6.6/include/uapi/vserver/monitor.h       2013-08-22 20:30:00.000000000 +0000
13122 @@ -0,0 +1,96 @@
13123 +#ifndef _UAPI_VS_MONITOR_H
13124 +#define _UAPI_VS_MONITOR_H
13125 +
13126 +#include <linux/types.h>
13127 +
13128 +
13129 +enum {
13130 +       VXM_UNUSED = 0,
13131 +
13132 +       VXM_SYNC = 0x10,
13133 +
13134 +       VXM_UPDATE = 0x20,
13135 +       VXM_UPDATE_1,
13136 +       VXM_UPDATE_2,
13137 +
13138 +       VXM_RQINFO_1 = 0x24,
13139 +       VXM_RQINFO_2,
13140 +
13141 +       VXM_ACTIVATE = 0x40,
13142 +       VXM_DEACTIVATE,
13143 +       VXM_IDLE,
13144 +
13145 +       VXM_HOLD = 0x44,
13146 +       VXM_UNHOLD,
13147 +
13148 +       VXM_MIGRATE = 0x48,
13149 +       VXM_RESCHED,
13150 +
13151 +       /* all other bits are flags */
13152 +       VXM_SCHED = 0x80,
13153 +};
13154 +
13155 +struct _vxm_update_1 {
13156 +       uint32_t tokens_max;
13157 +       uint32_t fill_rate;
13158 +       uint32_t interval;
13159 +};
13160 +
13161 +struct _vxm_update_2 {
13162 +       uint32_t tokens_min;
13163 +       uint32_t fill_rate;
13164 +       uint32_t interval;
13165 +};
13166 +
13167 +struct _vxm_rqinfo_1 {
13168 +       uint16_t running;
13169 +       uint16_t onhold;
13170 +       uint16_t iowait;
13171 +       uint16_t uintr;
13172 +       uint32_t idle_tokens;
13173 +};
13174 +
13175 +struct _vxm_rqinfo_2 {
13176 +       uint32_t norm_time;
13177 +       uint32_t idle_time;
13178 +       uint32_t idle_skip;
13179 +};
13180 +
13181 +struct _vxm_sched {
13182 +       uint32_t tokens;
13183 +       uint32_t norm_time;
13184 +       uint32_t idle_time;
13185 +};
13186 +
13187 +struct _vxm_task {
13188 +       uint16_t pid;
13189 +       uint16_t state;
13190 +};
13191 +
13192 +struct _vxm_event {
13193 +       uint32_t jif;
13194 +       union {
13195 +               uint32_t seq;
13196 +               uint32_t sec;
13197 +       };
13198 +       union {
13199 +               uint32_t tokens;
13200 +               uint32_t nsec;
13201 +               struct _vxm_task tsk;
13202 +       };
13203 +};
13204 +
13205 +struct _vx_mon_entry {
13206 +       uint16_t type;
13207 +       uint16_t xid;
13208 +       union {
13209 +               struct _vxm_event ev;
13210 +               struct _vxm_sched sd;
13211 +               struct _vxm_update_1 u1;
13212 +               struct _vxm_update_2 u2;
13213 +               struct _vxm_rqinfo_1 q1;
13214 +               struct _vxm_rqinfo_2 q2;
13215 +       };
13216 +};
13217 +
13218 +#endif /* _UAPI_VS_MONITOR_H */
13219 diff -NurpP --minimal linux-3.10.9/include/uapi/vserver/network.h linux-3.10.9-vs2.3.6.6/include/uapi/vserver/network.h
13220 --- linux-3.10.9/include/uapi/vserver/network.h 1970-01-01 00:00:00.000000000 +0000
13221 +++ linux-3.10.9-vs2.3.6.6/include/uapi/vserver/network.h       2013-08-22 20:30:00.000000000 +0000
13222 @@ -0,0 +1,76 @@
13223 +#ifndef _UAPI_VS_NETWORK_H
13224 +#define _UAPI_VS_NETWORK_H
13225 +
13226 +#include <linux/types.h>
13227 +
13228 +
13229 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
13230 +
13231 +
13232 +/* network flags */
13233 +
13234 +#define NXF_INFO_PRIVATE       0x00000008
13235 +
13236 +#define NXF_SINGLE_IP          0x00000100
13237 +#define NXF_LBACK_REMAP                0x00000200
13238 +#define NXF_LBACK_ALLOW                0x00000400
13239 +
13240 +#define NXF_HIDE_NETIF         0x02000000
13241 +#define NXF_HIDE_LBACK         0x04000000
13242 +
13243 +#define NXF_STATE_SETUP                (1ULL << 32)
13244 +#define NXF_STATE_ADMIN                (1ULL << 34)
13245 +
13246 +#define NXF_SC_HELPER          (1ULL << 36)
13247 +#define NXF_PERSISTENT         (1ULL << 38)
13248 +
13249 +#define NXF_ONE_TIME           (0x0005ULL << 32)
13250 +
13251 +
13252 +#define        NXF_INIT_SET            (__nxf_init_set())
13253 +
13254 +static inline uint64_t __nxf_init_set(void) {
13255 +       return    NXF_STATE_ADMIN
13256 +#ifdef CONFIG_VSERVER_AUTO_LBACK
13257 +               | NXF_LBACK_REMAP
13258 +               | NXF_HIDE_LBACK
13259 +#endif
13260 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
13261 +               | NXF_SINGLE_IP
13262 +#endif
13263 +               | NXF_HIDE_NETIF;
13264 +}
13265 +
13266 +
13267 +/* network caps */
13268 +
13269 +#define NXC_TUN_CREATE         0x00000001
13270 +
13271 +#define NXC_RAW_ICMP           0x00000100
13272 +
13273 +#define NXC_MULTICAST          0x00001000
13274 +
13275 +
13276 +/* address types */
13277 +
13278 +#define NXA_TYPE_IPV4          0x0001
13279 +#define NXA_TYPE_IPV6          0x0002
13280 +
13281 +#define NXA_TYPE_NONE          0x0000
13282 +#define NXA_TYPE_ANY           0x00FF
13283 +
13284 +#define NXA_TYPE_ADDR          0x0010
13285 +#define NXA_TYPE_MASK          0x0020
13286 +#define NXA_TYPE_RANGE         0x0040
13287 +
13288 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
13289 +
13290 +#define NXA_MOD_BCAST          0x0100
13291 +#define NXA_MOD_LBACK          0x0200
13292 +
13293 +#define NXA_LOOPBACK           0x1000
13294 +
13295 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
13296 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
13297 +
13298 +#endif /* _UAPI_VS_NETWORK_H */
13299 diff -NurpP --minimal linux-3.10.9/include/uapi/vserver/network_cmd.h linux-3.10.9-vs2.3.6.6/include/uapi/vserver/network_cmd.h
13300 --- linux-3.10.9/include/uapi/vserver/network_cmd.h     1970-01-01 00:00:00.000000000 +0000
13301 +++ linux-3.10.9-vs2.3.6.6/include/uapi/vserver/network_cmd.h   2013-08-22 20:30:00.000000000 +0000
13302 @@ -0,0 +1,123 @@
13303 +#ifndef _UAPI_VS_NETWORK_CMD_H
13304 +#define _UAPI_VS_NETWORK_CMD_H
13305 +
13306 +
13307 +/* vinfo commands */
13308 +
13309 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
13310 +
13311 +
13312 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
13313 +
13314 +struct vcmd_nx_info_v0 {
13315 +       uint32_t nid;
13316 +       /* more to come */
13317 +};
13318 +
13319 +
13320 +#include <linux/in.h>
13321 +#include <linux/in6.h>
13322 +
13323 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
13324 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
13325 +
13326 +struct  vcmd_net_create {
13327 +       uint64_t flagword;
13328 +};
13329 +
13330 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
13331 +
13332 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
13333 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
13334 +
13335 +struct vcmd_net_addr_v0 {
13336 +       uint16_t type;
13337 +       uint16_t count;
13338 +       struct in_addr ip[4];
13339 +       struct in_addr mask[4];
13340 +};
13341 +
13342 +#define VCMD_net_add_ipv4_v1   VC_CMD(NETALT, 1, 1)
13343 +#define VCMD_net_rem_ipv4_v1   VC_CMD(NETALT, 2, 1)
13344 +
13345 +struct vcmd_net_addr_ipv4_v1 {
13346 +       uint16_t type;
13347 +       uint16_t flags;
13348 +       struct in_addr ip;
13349 +       struct in_addr mask;
13350 +};
13351 +
13352 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 2)
13353 +#define VCMD_net_rem_ipv4      VC_CMD(NETALT, 2, 2)
13354 +
13355 +struct vcmd_net_addr_ipv4_v2 {
13356 +       uint16_t type;
13357 +       uint16_t flags;
13358 +       struct in_addr ip;
13359 +       struct in_addr ip2;
13360 +       struct in_addr mask;
13361 +};
13362 +
13363 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
13364 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
13365 +
13366 +struct vcmd_net_addr_ipv6_v1 {
13367 +       uint16_t type;
13368 +       uint16_t flags;
13369 +       uint32_t prefix;
13370 +       struct in6_addr ip;
13371 +       struct in6_addr mask;
13372 +};
13373 +
13374 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
13375 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
13376 +
13377 +struct vcmd_match_ipv4_v0 {
13378 +       uint16_t type;
13379 +       uint16_t flags;
13380 +       uint16_t parent;
13381 +       uint16_t prefix;
13382 +       struct in_addr ip;
13383 +       struct in_addr ip2;
13384 +       struct in_addr mask;
13385 +};
13386 +
13387 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
13388 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
13389 +
13390 +struct vcmd_match_ipv6_v0 {
13391 +       uint16_t type;
13392 +       uint16_t flags;
13393 +       uint16_t parent;
13394 +       uint16_t prefix;
13395 +       struct in6_addr ip;
13396 +       struct in6_addr ip2;
13397 +       struct in6_addr mask;
13398 +};
13399 +
13400 +
13401 +
13402 +
13403 +/* flag commands */
13404 +
13405 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
13406 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
13407 +
13408 +struct vcmd_net_flags_v0 {
13409 +       uint64_t flagword;
13410 +       uint64_t mask;
13411 +};
13412 +
13413 +
13414 +
13415 +/* network caps commands */
13416 +
13417 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
13418 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
13419 +
13420 +struct vcmd_net_caps_v0 {
13421 +       uint64_t ncaps;
13422 +       uint64_t cmask;
13423 +};
13424 +
13425 +#endif /* _UAPI_VS_NETWORK_CMD_H */
13426 diff -NurpP --minimal linux-3.10.9/include/uapi/vserver/sched_cmd.h linux-3.10.9-vs2.3.6.6/include/uapi/vserver/sched_cmd.h
13427 --- linux-3.10.9/include/uapi/vserver/sched_cmd.h       1970-01-01 00:00:00.000000000 +0000
13428 +++ linux-3.10.9-vs2.3.6.6/include/uapi/vserver/sched_cmd.h     2013-08-22 20:30:00.000000000 +0000
13429 @@ -0,0 +1,13 @@
13430 +#ifndef _UAPI_VS_SCHED_CMD_H
13431 +#define _UAPI_VS_SCHED_CMD_H
13432 +
13433 +
13434 +struct vcmd_prio_bias {
13435 +       int32_t cpu_id;
13436 +       int32_t prio_bias;
13437 +};
13438 +
13439 +#define VCMD_set_prio_bias     VC_CMD(SCHED, 4, 0)
13440 +#define VCMD_get_prio_bias     VC_CMD(SCHED, 5, 0)
13441 +
13442 +#endif /* _UAPI_VS_SCHED_CMD_H */
13443 diff -NurpP --minimal linux-3.10.9/include/uapi/vserver/signal_cmd.h linux-3.10.9-vs2.3.6.6/include/uapi/vserver/signal_cmd.h
13444 --- linux-3.10.9/include/uapi/vserver/signal_cmd.h      1970-01-01 00:00:00.000000000 +0000
13445 +++ linux-3.10.9-vs2.3.6.6/include/uapi/vserver/signal_cmd.h    2013-08-22 20:30:00.000000000 +0000
13446 @@ -0,0 +1,31 @@
13447 +#ifndef _UAPI_VS_SIGNAL_CMD_H
13448 +#define _UAPI_VS_SIGNAL_CMD_H
13449 +
13450 +
13451 +/*  signalling vserver commands */
13452 +
13453 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
13454 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
13455 +
13456 +struct vcmd_ctx_kill_v0 {
13457 +       int32_t pid;
13458 +       int32_t sig;
13459 +};
13460 +
13461 +struct vcmd_wait_exit_v0 {
13462 +       int32_t reboot_cmd;
13463 +       int32_t exit_code;
13464 +};
13465 +
13466 +
13467 +/*  process alteration commands */
13468 +
13469 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
13470 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
13471 +
13472 +struct vcmd_pflags_v0 {
13473 +       uint32_t flagword;
13474 +       uint32_t mask;
13475 +};
13476 +
13477 +#endif /* _UAPI_VS_SIGNAL_CMD_H */
13478 diff -NurpP --minimal linux-3.10.9/include/uapi/vserver/space_cmd.h linux-3.10.9-vs2.3.6.6/include/uapi/vserver/space_cmd.h
13479 --- linux-3.10.9/include/uapi/vserver/space_cmd.h       1970-01-01 00:00:00.000000000 +0000
13480 +++ linux-3.10.9-vs2.3.6.6/include/uapi/vserver/space_cmd.h     2013-08-22 20:30:00.000000000 +0000
13481 @@ -0,0 +1,28 @@
13482 +#ifndef _UAPI_VS_SPACE_CMD_H
13483 +#define _UAPI_VS_SPACE_CMD_H
13484 +
13485 +
13486 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
13487 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
13488 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
13489 +
13490 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
13491 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
13492 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
13493 +
13494 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
13495 +
13496 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
13497 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
13498 +
13499 +
13500 +struct vcmd_space_mask_v1 {
13501 +       uint64_t mask;
13502 +};
13503 +
13504 +struct vcmd_space_mask_v2 {
13505 +       uint64_t mask;
13506 +       uint32_t index;
13507 +};
13508 +
13509 +#endif /* _UAPI_VS_SPACE_CMD_H */
13510 diff -NurpP --minimal linux-3.10.9/include/uapi/vserver/switch.h linux-3.10.9-vs2.3.6.6/include/uapi/vserver/switch.h
13511 --- linux-3.10.9/include/uapi/vserver/switch.h  1970-01-01 00:00:00.000000000 +0000
13512 +++ linux-3.10.9-vs2.3.6.6/include/uapi/vserver/switch.h        2013-08-22 20:30:00.000000000 +0000
13513 @@ -0,0 +1,90 @@
13514 +#ifndef _UAPI_VS_SWITCH_H
13515 +#define _UAPI_VS_SWITCH_H
13516 +
13517 +#include <linux/types.h>
13518 +
13519 +
13520 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
13521 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
13522 +#define VC_VERSION(c)          ((c) & 0xFFF)
13523 +
13524 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
13525 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
13526 +
13527 +/*
13528 +
13529 +  Syscall Matrix V2.8
13530 +
13531 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
13532 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
13533 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
13534 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13535 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
13536 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
13537 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13538 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
13539 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
13540 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13541 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
13542 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
13543 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13544 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
13545 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
13546 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13547 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
13548 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
13549 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13550 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
13551 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
13552 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
13553 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
13554 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
13555 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13556 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
13557 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
13558 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13559 +
13560 +*/
13561 +
13562 +#define VC_CAT_VERSION         0
13563 +
13564 +#define VC_CAT_VSETUP          1
13565 +#define VC_CAT_VHOST           2
13566 +
13567 +#define VC_CAT_DEVICE          6
13568 +
13569 +#define VC_CAT_VPROC           9
13570 +#define VC_CAT_PROCALT         10
13571 +#define VC_CAT_PROCMIG         11
13572 +#define VC_CAT_PROCTRL         12
13573 +
13574 +#define VC_CAT_SCHED           14
13575 +#define VC_CAT_MEMCTRL         20
13576 +
13577 +#define VC_CAT_VNET            25
13578 +#define VC_CAT_NETALT          26
13579 +#define VC_CAT_NETMIG          27
13580 +#define VC_CAT_NETCTRL         28
13581 +
13582 +#define VC_CAT_TAGMIG          35
13583 +#define VC_CAT_DLIMIT          36
13584 +#define VC_CAT_INODE           38
13585 +
13586 +#define VC_CAT_VSTAT           40
13587 +#define VC_CAT_VINFO           46
13588 +#define VC_CAT_EVENT           48
13589 +
13590 +#define VC_CAT_FLAGS           52
13591 +#define VC_CAT_VSPACE          54
13592 +#define VC_CAT_DEBUG           56
13593 +#define VC_CAT_RLIMIT          60
13594 +
13595 +#define VC_CAT_SYSTEST         61
13596 +#define VC_CAT_COMPAT          63
13597 +
13598 +/*  query version */
13599 +
13600 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
13601 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
13602 +
13603 +#endif /* _UAPI_VS_SWITCH_H */
13604 diff -NurpP --minimal linux-3.10.9/include/uapi/vserver/tag_cmd.h linux-3.10.9-vs2.3.6.6/include/uapi/vserver/tag_cmd.h
13605 --- linux-3.10.9/include/uapi/vserver/tag_cmd.h 1970-01-01 00:00:00.000000000 +0000
13606 +++ linux-3.10.9-vs2.3.6.6/include/uapi/vserver/tag_cmd.h       2013-08-22 20:30:00.000000000 +0000
13607 @@ -0,0 +1,14 @@
13608 +#ifndef _UAPI_VS_TAG_CMD_H
13609 +#define _UAPI_VS_TAG_CMD_H
13610 +
13611 +
13612 +/* vinfo commands */
13613 +
13614 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
13615 +
13616 +
13617 +/* context commands */
13618 +
13619 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
13620 +
13621 +#endif /* _UAPI_VS_TAG_CMD_H */
13622 diff -NurpP --minimal linux-3.10.9/init/Kconfig linux-3.10.9-vs2.3.6.6/init/Kconfig
13623 --- linux-3.10.9/init/Kconfig   2013-07-14 17:01:34.000000000 +0000
13624 +++ linux-3.10.9-vs2.3.6.6/init/Kconfig 2013-08-22 20:30:00.000000000 +0000
13625 @@ -805,6 +805,7 @@ config NUMA_BALANCING
13626  menuconfig CGROUPS
13627         boolean "Control Group support"
13628         depends on EVENTFD
13629 +       default y
13630         help
13631           This option adds support for grouping sets of processes together, for
13632           use with process control subsystems such as Cpusets, CFS, memory
13633 @@ -1067,6 +1068,7 @@ config IPC_NS
13634  config USER_NS
13635         bool "User namespace"
13636         depends on UIDGID_CONVERTED
13637 +       depends on VSERVER_DISABLED
13638         select UIDGID_STRICT_TYPE_CHECKS
13639  
13640         default n
13641 diff -NurpP --minimal linux-3.10.9/init/main.c linux-3.10.9-vs2.3.6.6/init/main.c
13642 --- linux-3.10.9/init/main.c    2013-07-14 17:01:34.000000000 +0000
13643 +++ linux-3.10.9-vs2.3.6.6/init/main.c  2013-08-22 20:30:00.000000000 +0000
13644 @@ -74,6 +74,7 @@
13645  #include <linux/ptrace.h>
13646  #include <linux/blkdev.h>
13647  #include <linux/elevator.h>
13648 +#include <linux/vserver/percpu.h>
13649  
13650  #include <asm/io.h>
13651  #include <asm/bugs.h>
13652 diff -NurpP --minimal linux-3.10.9/ipc/mqueue.c linux-3.10.9-vs2.3.6.6/ipc/mqueue.c
13653 --- linux-3.10.9/ipc/mqueue.c   2013-05-31 13:45:29.000000000 +0000
13654 +++ linux-3.10.9-vs2.3.6.6/ipc/mqueue.c 2013-08-22 20:30:00.000000000 +0000
13655 @@ -35,6 +35,8 @@
13656  #include <linux/ipc_namespace.h>
13657  #include <linux/user_namespace.h>
13658  #include <linux/slab.h>
13659 +#include <linux/vs_context.h>
13660 +#include <linux/vs_limit.h>
13661  
13662  #include <net/sock.h>
13663  #include "util.h"
13664 @@ -76,6 +78,7 @@ struct mqueue_inode_info {
13665         struct pid* notify_owner;
13666         struct user_namespace *notify_user_ns;
13667         struct user_struct *user;       /* user who created, for accounting */
13668 +       struct vx_info *vxi;
13669         struct sock *notify_sock;
13670         struct sk_buff *notify_cookie;
13671  
13672 @@ -234,6 +237,7 @@ static struct inode *mqueue_get_inode(st
13673         if (S_ISREG(mode)) {
13674                 struct mqueue_inode_info *info;
13675                 unsigned long mq_bytes, mq_treesize;
13676 +               struct vx_info *vxi = current_vx_info();
13677  
13678                 inode->i_fop = &mqueue_file_operations;
13679                 inode->i_size = FILENT_SIZE;
13680 @@ -247,6 +251,7 @@ static struct inode *mqueue_get_inode(st
13681                 info->notify_user_ns = NULL;
13682                 info->qsize = 0;
13683                 info->user = NULL;      /* set when all is ok */
13684 +               info->vxi = NULL;
13685                 info->msg_tree = RB_ROOT;
13686                 info->node_cache = NULL;
13687                 memset(&info->attr, 0, sizeof(info->attr));
13688 @@ -280,17 +285,20 @@ static struct inode *mqueue_get_inode(st
13689  
13690                 spin_lock(&mq_lock);
13691                 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
13692 -                   u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
13693 +                   u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE) ||
13694 +                   !vx_ipcmsg_avail(vxi, mq_bytes)) {
13695                         spin_unlock(&mq_lock);
13696                         /* mqueue_evict_inode() releases info->messages */
13697                         ret = -EMFILE;
13698                         goto out_inode;
13699                 }
13700                 u->mq_bytes += mq_bytes;
13701 +               vx_ipcmsg_add(vxi, u, mq_bytes);
13702                 spin_unlock(&mq_lock);
13703  
13704                 /* all is ok */
13705                 info->user = get_uid(u);
13706 +               info->vxi = get_vx_info(vxi);
13707         } else if (S_ISDIR(mode)) {
13708                 inc_nlink(inode);
13709                 /* Some things misbehave if size == 0 on a directory */
13710 @@ -402,8 +410,11 @@ static void mqueue_evict_inode(struct in
13711  
13712         user = info->user;
13713         if (user) {
13714 +               struct vx_info *vxi = info->vxi;
13715 +
13716                 spin_lock(&mq_lock);
13717                 user->mq_bytes -= mq_bytes;
13718 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
13719                 /*
13720                  * get_ns_from_inode() ensures that the
13721                  * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
13722 @@ -413,6 +424,7 @@ static void mqueue_evict_inode(struct in
13723                 if (ipc_ns)
13724                         ipc_ns->mq_queues_count--;
13725                 spin_unlock(&mq_lock);
13726 +               put_vx_info(vxi);
13727                 free_uid(user);
13728         }
13729         if (ipc_ns)
13730 diff -NurpP --minimal linux-3.10.9/ipc/msg.c linux-3.10.9-vs2.3.6.6/ipc/msg.c
13731 --- linux-3.10.9/ipc/msg.c      2013-07-14 17:01:34.000000000 +0000
13732 +++ linux-3.10.9-vs2.3.6.6/ipc/msg.c    2013-08-22 20:30:00.000000000 +0000
13733 @@ -37,6 +37,7 @@
13734  #include <linux/rwsem.h>
13735  #include <linux/nsproxy.h>
13736  #include <linux/ipc_namespace.h>
13737 +#include <linux/vs_base.h>
13738  
13739  #include <asm/current.h>
13740  #include <asm/uaccess.h>
13741 @@ -191,6 +192,7 @@ static int newque(struct ipc_namespace *
13742  
13743         msq->q_perm.mode = msgflg & S_IRWXUGO;
13744         msq->q_perm.key = key;
13745 +       msq->q_perm.xid = vx_current_xid();
13746  
13747         msq->q_perm.security = NULL;
13748         retval = security_msg_queue_alloc(msq);
13749 diff -NurpP --minimal linux-3.10.9/ipc/sem.c linux-3.10.9-vs2.3.6.6/ipc/sem.c
13750 --- linux-3.10.9/ipc/sem.c      2013-07-14 17:01:34.000000000 +0000
13751 +++ linux-3.10.9-vs2.3.6.6/ipc/sem.c    2013-08-22 20:30:00.000000000 +0000
13752 @@ -86,6 +86,8 @@
13753  #include <linux/rwsem.h>
13754  #include <linux/nsproxy.h>
13755  #include <linux/ipc_namespace.h>
13756 +#include <linux/vs_base.h>
13757 +#include <linux/vs_limit.h>
13758  
13759  #include <asm/uaccess.h>
13760  #include "util.h"
13761 @@ -399,6 +401,7 @@ static int newary(struct ipc_namespace *
13762  
13763         sma->sem_perm.mode = (semflg & S_IRWXUGO);
13764         sma->sem_perm.key = key;
13765 +       sma->sem_perm.xid = vx_current_xid();
13766  
13767         sma->sem_perm.security = NULL;
13768         retval = security_sem_alloc(sma);
13769 @@ -414,6 +417,9 @@ static int newary(struct ipc_namespace *
13770                 return id;
13771         }
13772         ns->used_sems += nsems;
13773 +       /* FIXME: obsoleted? */
13774 +       vx_semary_inc(sma);
13775 +       vx_nsems_add(sma, nsems);
13776  
13777         sma->sem_base = (struct sem *) &sma[1];
13778  
13779 @@ -903,6 +909,9 @@ static void freeary(struct ipc_namespace
13780  
13781         wake_up_sem_queue_do(&tasks);
13782         ns->used_sems -= sma->sem_nsems;
13783 +       /* FIXME: obsoleted? */
13784 +       vx_nsems_sub(sma, sma->sem_nsems);
13785 +       vx_semary_dec(sma);
13786         security_sem_free(sma);
13787         ipc_rcu_putref(sma);
13788  }
13789 diff -NurpP --minimal linux-3.10.9/ipc/shm.c linux-3.10.9-vs2.3.6.6/ipc/shm.c
13790 --- linux-3.10.9/ipc/shm.c      2013-07-14 17:01:34.000000000 +0000
13791 +++ linux-3.10.9-vs2.3.6.6/ipc/shm.c    2013-08-22 20:30:00.000000000 +0000
13792 @@ -39,6 +39,8 @@
13793  #include <linux/nsproxy.h>
13794  #include <linux/mount.h>
13795  #include <linux/ipc_namespace.h>
13796 +#include <linux/vs_context.h>
13797 +#include <linux/vs_limit.h>
13798  
13799  #include <asm/uaccess.h>
13800  
13801 @@ -187,7 +189,12 @@ static void shm_open(struct vm_area_stru
13802   */
13803  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
13804  {
13805 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
13806 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
13807 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
13808 +
13809 +       vx_ipcshm_sub(vxi, shp, numpages);
13810 +       ns->shm_tot -= numpages;
13811 +
13812         shm_rmid(ns, shp);
13813         shm_unlock(shp);
13814         if (!is_file_hugepages(shp->shm_file))
13815 @@ -197,6 +204,7 @@ static void shm_destroy(struct ipc_names
13816                                                 shp->mlock_user);
13817         fput (shp->shm_file);
13818         security_shm_free(shp);
13819 +       put_vx_info(vxi);
13820         ipc_rcu_putref(shp);
13821  }
13822  
13823 @@ -474,11 +482,15 @@ static int newseg(struct ipc_namespace *
13824         if (ns->shm_tot + numpages > ns->shm_ctlall)
13825                 return -ENOSPC;
13826  
13827 +       if (!vx_ipcshm_avail(current_vx_info(), numpages))
13828 +               return -ENOSPC;
13829 +
13830         shp = ipc_rcu_alloc(sizeof(*shp));
13831         if (!shp)
13832                 return -ENOMEM;
13833  
13834         shp->shm_perm.key = key;
13835 +       shp->shm_perm.xid = vx_current_xid();
13836         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
13837         shp->mlock_user = NULL;
13838  
13839 @@ -544,6 +556,7 @@ static int newseg(struct ipc_namespace *
13840         ns->shm_tot += numpages;
13841         error = shp->shm_perm.id;
13842         shm_unlock(shp);
13843 +       vx_ipcshm_add(current_vx_info(), key, numpages);
13844         return error;
13845  
13846  no_id:
13847 diff -NurpP --minimal linux-3.10.9/kernel/Makefile linux-3.10.9-vs2.3.6.6/kernel/Makefile
13848 --- linux-3.10.9/kernel/Makefile        2013-07-14 17:01:34.000000000 +0000
13849 +++ linux-3.10.9-vs2.3.6.6/kernel/Makefile      2013-08-22 21:18:32.000000000 +0000
13850 @@ -25,6 +25,7 @@ endif
13851  obj-y += sched/
13852  obj-y += power/
13853  obj-y += cpu/
13854 +obj-y += vserver/
13855  
13856  obj-$(CONFIG_CHECKPOINT_RESTORE) += kcmp.o
13857  obj-$(CONFIG_FREEZER) += freezer.o
13858 diff -NurpP --minimal linux-3.10.9/kernel/auditsc.c linux-3.10.9-vs2.3.6.6/kernel/auditsc.c
13859 --- linux-3.10.9/kernel/auditsc.c       2013-07-14 17:01:34.000000000 +0000
13860 +++ linux-3.10.9-vs2.3.6.6/kernel/auditsc.c     2013-08-22 20:30:00.000000000 +0000
13861 @@ -1976,7 +1976,7 @@ int audit_set_loginuid(kuid_t loginuid)
13862         if (audit_loginuid_set(task))
13863                 return -EPERM;
13864  #else /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
13865 -       if (!capable(CAP_AUDIT_CONTROL))
13866 +       if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
13867                 return -EPERM;
13868  #endif  /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
13869  
13870 diff -NurpP --minimal linux-3.10.9/kernel/capability.c linux-3.10.9-vs2.3.6.6/kernel/capability.c
13871 --- linux-3.10.9/kernel/capability.c    2013-05-31 13:45:29.000000000 +0000
13872 +++ linux-3.10.9-vs2.3.6.6/kernel/capability.c  2013-08-22 20:30:00.000000000 +0000
13873 @@ -15,6 +15,7 @@
13874  #include <linux/syscalls.h>
13875  #include <linux/pid_namespace.h>
13876  #include <linux/user_namespace.h>
13877 +#include <linux/vs_context.h>
13878  #include <asm/uaccess.h>
13879  
13880  /*
13881 @@ -116,6 +117,7 @@ static int cap_validate_magic(cap_user_h
13882         return 0;
13883  }
13884  
13885 +
13886  /*
13887   * The only thing that can change the capabilities of the current
13888   * process is the current process. As such, we can't be in this code
13889 @@ -349,6 +351,8 @@ bool has_ns_capability_noaudit(struct ta
13890         return (ret == 0);
13891  }
13892  
13893 +#include <linux/vserver/base.h>
13894 +
13895  /**
13896   * has_capability_noaudit - Does a task have a capability (unaudited) in the
13897   * initial user ns
13898 diff -NurpP --minimal linux-3.10.9/kernel/compat.c linux-3.10.9-vs2.3.6.6/kernel/compat.c
13899 --- linux-3.10.9/kernel/compat.c        2013-07-14 17:01:34.000000000 +0000
13900 +++ linux-3.10.9-vs2.3.6.6/kernel/compat.c      2013-08-22 20:30:00.000000000 +0000
13901 @@ -27,6 +27,7 @@
13902  #include <linux/times.h>
13903  #include <linux/ptrace.h>
13904  #include <linux/gfp.h>
13905 +#include <linux/vs_time.h>
13906  
13907  #include <asm/uaccess.h>
13908  
13909 @@ -1040,7 +1041,7 @@ asmlinkage long compat_sys_stime(compat_
13910         if (err)
13911                 return err;
13912  
13913 -       do_settimeofday(&tv);
13914 +       vx_settimeofday(&tv);
13915         return 0;
13916  }
13917  
13918 diff -NurpP --minimal linux-3.10.9/kernel/cred.c linux-3.10.9-vs2.3.6.6/kernel/cred.c
13919 --- linux-3.10.9/kernel/cred.c  2013-02-19 13:58:56.000000000 +0000
13920 +++ linux-3.10.9-vs2.3.6.6/kernel/cred.c        2013-08-22 20:30:00.000000000 +0000
13921 @@ -56,31 +56,6 @@ struct cred init_cred = {
13922         .group_info             = &init_groups,
13923  };
13924  
13925 -static inline void set_cred_subscribers(struct cred *cred, int n)
13926 -{
13927 -#ifdef CONFIG_DEBUG_CREDENTIALS
13928 -       atomic_set(&cred->subscribers, n);
13929 -#endif
13930 -}
13931 -
13932 -static inline int read_cred_subscribers(const struct cred *cred)
13933 -{
13934 -#ifdef CONFIG_DEBUG_CREDENTIALS
13935 -       return atomic_read(&cred->subscribers);
13936 -#else
13937 -       return 0;
13938 -#endif
13939 -}
13940 -
13941 -static inline void alter_cred_subscribers(const struct cred *_cred, int n)
13942 -{
13943 -#ifdef CONFIG_DEBUG_CREDENTIALS
13944 -       struct cred *cred = (struct cred *) _cred;
13945 -
13946 -       atomic_add(n, &cred->subscribers);
13947 -#endif
13948 -}
13949 -
13950  /*
13951   * The RCU callback to actually dispose of a set of credentials
13952   */
13953 @@ -232,21 +207,16 @@ error:
13954   *
13955   * Call commit_creds() or abort_creds() to clean up.
13956   */
13957 -struct cred *prepare_creds(void)
13958 +struct cred *__prepare_creds(const struct cred *old)
13959  {
13960 -       struct task_struct *task = current;
13961 -       const struct cred *old;
13962         struct cred *new;
13963  
13964 -       validate_process_creds();
13965 -
13966         new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
13967         if (!new)
13968                 return NULL;
13969  
13970         kdebug("prepare_creds() alloc %p", new);
13971  
13972 -       old = task->cred;
13973         memcpy(new, old, sizeof(struct cred));
13974  
13975         atomic_set(&new->usage, 1);
13976 @@ -275,6 +245,13 @@ error:
13977         abort_creds(new);
13978         return NULL;
13979  }
13980 +
13981 +struct cred *prepare_creds(void)
13982 +{
13983 +       validate_process_creds();
13984 +
13985 +       return __prepare_creds(current->cred);
13986 +}
13987  EXPORT_SYMBOL(prepare_creds);
13988  
13989  /*
13990 diff -NurpP --minimal linux-3.10.9/kernel/exit.c linux-3.10.9-vs2.3.6.6/kernel/exit.c
13991 --- linux-3.10.9/kernel/exit.c  2013-07-14 17:01:35.000000000 +0000
13992 +++ linux-3.10.9-vs2.3.6.6/kernel/exit.c        2013-08-22 20:30:00.000000000 +0000
13993 @@ -48,6 +48,10 @@
13994  #include <linux/fs_struct.h>
13995  #include <linux/init_task.h>
13996  #include <linux/perf_event.h>
13997 +#include <linux/vs_limit.h>
13998 +#include <linux/vs_context.h>
13999 +#include <linux/vs_network.h>
14000 +#include <linux/vs_pid.h>
14001  #include <trace/events/sched.h>
14002  #include <linux/hw_breakpoint.h>
14003  #include <linux/oom.h>
14004 @@ -514,15 +518,25 @@ static struct task_struct *find_new_reap
14005         __acquires(&tasklist_lock)
14006  {
14007         struct pid_namespace *pid_ns = task_active_pid_ns(father);
14008 -       struct task_struct *thread;
14009 +       struct vx_info *vxi = task_get_vx_info(father);
14010 +       struct task_struct *thread = father;
14011 +       struct task_struct *reaper;
14012  
14013 -       thread = father;
14014         while_each_thread(father, thread) {
14015                 if (thread->flags & PF_EXITING)
14016                         continue;
14017                 if (unlikely(pid_ns->child_reaper == father))
14018                         pid_ns->child_reaper = thread;
14019 -               return thread;
14020 +               reaper = thread;
14021 +               goto out_put;
14022 +       }
14023 +
14024 +       reaper = pid_ns->child_reaper;
14025 +       if (vxi) {
14026 +               BUG_ON(!vxi->vx_reaper);
14027 +               if (vxi->vx_reaper != init_pid_ns.child_reaper &&
14028 +                   vxi->vx_reaper != father)
14029 +                       reaper = vxi->vx_reaper;
14030         }
14031  
14032         if (unlikely(pid_ns->child_reaper == father)) {
14033 @@ -560,7 +574,9 @@ static struct task_struct *find_new_reap
14034                 }
14035         }
14036  
14037 -       return pid_ns->child_reaper;
14038 +out_put:
14039 +       put_vx_info(vxi);
14040 +       return reaper;
14041  }
14042  
14043  /*
14044 @@ -611,10 +627,15 @@ static void forget_original_parent(struc
14045         list_for_each_entry_safe(p, n, &father->children, sibling) {
14046                 struct task_struct *t = p;
14047                 do {
14048 -                       t->real_parent = reaper;
14049 +                       struct task_struct *new_parent = reaper;
14050 +
14051 +                       if (unlikely(p == reaper))
14052 +                               new_parent = task_active_pid_ns(p)->child_reaper;
14053 +
14054 +                       t->real_parent = new_parent;
14055                         if (t->parent == father) {
14056                                 BUG_ON(t->ptrace);
14057 -                               t->parent = t->real_parent;
14058 +                               t->parent = new_parent;
14059                         }
14060                         if (t->pdeath_signal)
14061                                 group_send_sig_info(t->pdeath_signal,
14062 @@ -821,6 +842,9 @@ void do_exit(long code)
14063          */
14064         ptrace_put_breakpoints(tsk);
14065  
14066 +       /* needs to stay before exit_notify() */
14067 +       exit_vx_info_early(tsk, code);
14068 +
14069         exit_notify(tsk, group_dead);
14070  #ifdef CONFIG_NUMA
14071         task_lock(tsk);
14072 @@ -874,10 +898,15 @@ void do_exit(long code)
14073         smp_mb();
14074         raw_spin_unlock_wait(&tsk->pi_lock);
14075  
14076 +       /* needs to stay after exit_notify() */
14077 +       exit_vx_info(tsk, code);
14078 +       exit_nx_info(tsk);
14079 +
14080         /* causes final put_task_struct in finish_task_switch(). */
14081         tsk->state = TASK_DEAD;
14082         tsk->flags |= PF_NOFREEZE;      /* tell freezer to ignore us */
14083         schedule();
14084 +       printk("bad task: %p [%lx]\n", current, current->state);
14085         BUG();
14086         /* Avoid "noreturn function does return".  */
14087         for (;;)
14088 diff -NurpP --minimal linux-3.10.9/kernel/fork.c linux-3.10.9-vs2.3.6.6/kernel/fork.c
14089 --- linux-3.10.9/kernel/fork.c  2013-08-22 19:51:35.000000000 +0000
14090 +++ linux-3.10.9-vs2.3.6.6/kernel/fork.c        2013-08-22 21:11:14.000000000 +0000
14091 @@ -71,6 +71,9 @@
14092  #include <linux/signalfd.h>
14093  #include <linux/uprobes.h>
14094  #include <linux/aio.h>
14095 +#include <linux/vs_context.h>
14096 +#include <linux/vs_network.h>
14097 +#include <linux/vs_limit.h>
14098  
14099  #include <asm/pgtable.h>
14100  #include <asm/pgalloc.h>
14101 @@ -211,6 +214,8 @@ void free_task(struct task_struct *tsk)
14102         arch_release_thread_info(tsk->stack);
14103         free_thread_info(tsk->stack);
14104         rt_mutex_debug_task_free(tsk);
14105 +       clr_vx_info(&tsk->vx_info);
14106 +       clr_nx_info(&tsk->nx_info);
14107         ftrace_graph_exit_task(tsk);
14108         put_seccomp_filter(tsk);
14109         arch_release_task_struct(tsk);
14110 @@ -548,6 +553,7 @@ static struct mm_struct *mm_init(struct
14111         if (likely(!mm_alloc_pgd(mm))) {
14112                 mm->def_flags = 0;
14113                 mmu_notifier_mm_init(mm);
14114 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
14115                 return mm;
14116         }
14117  
14118 @@ -600,6 +606,7 @@ void __mmdrop(struct mm_struct *mm)
14119         destroy_context(mm);
14120         mmu_notifier_mm_destroy(mm);
14121         check_mm(mm);
14122 +       clr_vx_info(&mm->mm_vx_info);
14123         free_mm(mm);
14124  }
14125  EXPORT_SYMBOL_GPL(__mmdrop);
14126 @@ -819,6 +826,7 @@ struct mm_struct *dup_mm(struct task_str
14127                 goto fail_nomem;
14128  
14129         memcpy(mm, oldmm, sizeof(*mm));
14130 +       mm->mm_vx_info = NULL;
14131         mm_init_cpumask(mm);
14132  
14133  #ifdef CONFIG_TRANSPARENT_HUGEPAGE
14134 @@ -860,6 +868,7 @@ fail_nocontext:
14135          * If init_new_context() failed, we cannot use mmput() to free the mm
14136          * because it calls destroy_context()
14137          */
14138 +       clr_vx_info(&mm->mm_vx_info);
14139         mm_free_pgd(mm);
14140         free_mm(mm);
14141         return NULL;
14142 @@ -1138,6 +1147,8 @@ static struct task_struct *copy_process(
14143  {
14144         int retval;
14145         struct task_struct *p;
14146 +       struct vx_info *vxi;
14147 +       struct nx_info *nxi;
14148  
14149         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
14150                 return ERR_PTR(-EINVAL);
14151 @@ -1196,7 +1207,12 @@ static struct task_struct *copy_process(
14152         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
14153         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
14154  #endif
14155 +       init_vx_info(&p->vx_info, current_vx_info());
14156 +       init_nx_info(&p->nx_info, current_nx_info());
14157 +
14158         retval = -EAGAIN;
14159 +       if (!vx_nproc_avail(1))
14160 +               goto bad_fork_free;
14161         if (atomic_read(&p->real_cred->user->processes) >=
14162                         task_rlimit(p, RLIMIT_NPROC)) {
14163                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
14164 @@ -1477,6 +1493,18 @@ static struct task_struct *copy_process(
14165  
14166         total_forks++;
14167         spin_unlock(&current->sighand->siglock);
14168 +
14169 +       /* p is copy of current */
14170 +       vxi = p->vx_info;
14171 +       if (vxi) {
14172 +               claim_vx_info(vxi, p);
14173 +               atomic_inc(&vxi->cvirt.nr_threads);
14174 +               atomic_inc(&vxi->cvirt.total_forks);
14175 +               vx_nproc_inc(p);
14176 +       }
14177 +       nxi = p->nx_info;
14178 +       if (nxi)
14179 +               claim_nx_info(nxi, p);
14180         write_unlock_irq(&tasklist_lock);
14181         proc_fork_connector(p);
14182         cgroup_post_fork(p);
14183 diff -NurpP --minimal linux-3.10.9/kernel/kthread.c linux-3.10.9-vs2.3.6.6/kernel/kthread.c
14184 --- linux-3.10.9/kernel/kthread.c       2013-07-14 17:01:35.000000000 +0000
14185 +++ linux-3.10.9-vs2.3.6.6/kernel/kthread.c     2013-08-22 21:14:28.000000000 +0000
14186 @@ -18,6 +18,7 @@
14187  #include <linux/freezer.h>
14188  #include <linux/ptrace.h>
14189  #include <linux/uaccess.h>
14190 +#include <linux/vs_pid.h>
14191  #include <trace/events/sched.h>
14192  
14193  static DEFINE_SPINLOCK(kthread_create_lock);
14194 diff -NurpP --minimal linux-3.10.9/kernel/nsproxy.c linux-3.10.9-vs2.3.6.6/kernel/nsproxy.c
14195 --- linux-3.10.9/kernel/nsproxy.c       2013-07-14 17:01:35.000000000 +0000
14196 +++ linux-3.10.9-vs2.3.6.6/kernel/nsproxy.c     2013-08-22 21:09:55.000000000 +0000
14197 @@ -20,11 +20,14 @@
14198  #include <linux/mnt_namespace.h>
14199  #include <linux/utsname.h>
14200  #include <linux/pid_namespace.h>
14201 +#include <linux/vserver/global.h>
14202 +#include <linux/vserver/debug.h>
14203  #include <net/net_namespace.h>
14204  #include <linux/ipc_namespace.h>
14205  #include <linux/proc_ns.h>
14206  #include <linux/file.h>
14207  #include <linux/syscalls.h>
14208 +#include "../fs/mount.h"
14209  
14210  static struct kmem_cache *nsproxy_cachep;
14211  
14212 @@ -46,8 +49,11 @@ static inline struct nsproxy *create_nsp
14213         struct nsproxy *nsproxy;
14214  
14215         nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
14216 -       if (nsproxy)
14217 +       if (nsproxy) {
14218                 atomic_set(&nsproxy->count, 1);
14219 +               atomic_inc(&vs_global_nsproxy);
14220 +       }
14221 +       vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
14222         return nsproxy;
14223  }
14224  
14225 @@ -56,9 +62,12 @@ static inline struct nsproxy *create_nsp
14226   * Return the newly created nsproxy.  Do not attach this to the task,
14227   * leave it to the caller to do proper locking and attach it to task.
14228   */
14229 -static struct nsproxy *create_new_namespaces(unsigned long flags,
14230 -       struct task_struct *tsk, struct user_namespace *user_ns,
14231 -       struct fs_struct *new_fs)
14232 +static struct nsproxy *unshare_namespaces(
14233 +       unsigned long flags,
14234 +       struct nsproxy *orig,
14235 +       struct fs_struct *new_fs,
14236 +       struct user_namespace *new_user,
14237 +       struct pid_namespace *new_pid)
14238  {
14239         struct nsproxy *new_nsp;
14240         int err;
14241 @@ -67,31 +76,31 @@ static struct nsproxy *create_new_namesp
14242         if (!new_nsp)
14243                 return ERR_PTR(-ENOMEM);
14244  
14245 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, user_ns, new_fs);
14246 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_user, new_fs);
14247         if (IS_ERR(new_nsp->mnt_ns)) {
14248                 err = PTR_ERR(new_nsp->mnt_ns);
14249                 goto out_ns;
14250         }
14251  
14252 -       new_nsp->uts_ns = copy_utsname(flags, user_ns, tsk->nsproxy->uts_ns);
14253 +       new_nsp->uts_ns = copy_utsname(flags, new_user, orig->uts_ns);
14254         if (IS_ERR(new_nsp->uts_ns)) {
14255                 err = PTR_ERR(new_nsp->uts_ns);
14256                 goto out_uts;
14257         }
14258  
14259 -       new_nsp->ipc_ns = copy_ipcs(flags, user_ns, tsk->nsproxy->ipc_ns);
14260 +       new_nsp->ipc_ns = copy_ipcs(flags, new_user, orig->ipc_ns);
14261         if (IS_ERR(new_nsp->ipc_ns)) {
14262                 err = PTR_ERR(new_nsp->ipc_ns);
14263                 goto out_ipc;
14264         }
14265  
14266 -       new_nsp->pid_ns = copy_pid_ns(flags, user_ns, tsk->nsproxy->pid_ns);
14267 +       new_nsp->pid_ns = copy_pid_ns(flags, new_user, new_pid);
14268         if (IS_ERR(new_nsp->pid_ns)) {
14269                 err = PTR_ERR(new_nsp->pid_ns);
14270                 goto out_pid;
14271         }
14272  
14273 -       new_nsp->net_ns = copy_net_ns(flags, user_ns, tsk->nsproxy->net_ns);
14274 +       new_nsp->net_ns = copy_net_ns(flags, new_user, orig->net_ns);
14275         if (IS_ERR(new_nsp->net_ns)) {
14276                 err = PTR_ERR(new_nsp->net_ns);
14277                 goto out_net;
14278 @@ -116,6 +125,41 @@ out_ns:
14279         return ERR_PTR(err);
14280  }
14281  
14282 +static struct nsproxy *create_new_namespaces(unsigned long flags,
14283 +       struct task_struct *tsk, struct user_namespace *user_ns,
14284 +       struct fs_struct *new_fs)
14285 +
14286 +{
14287 +       return unshare_namespaces(flags, tsk->nsproxy,
14288 +               new_fs, user_ns, task_active_pid_ns(tsk));
14289 +}
14290 +
14291 +/*
14292 + * copies the nsproxy, setting refcount to 1, and grabbing a
14293 + * reference to all contained namespaces.
14294 + */
14295 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
14296 +{
14297 +       struct nsproxy *ns = create_nsproxy();
14298 +
14299 +       if (ns) {
14300 +               memcpy(ns, orig, sizeof(struct nsproxy));
14301 +               atomic_set(&ns->count, 1);
14302 +
14303 +               if (ns->mnt_ns)
14304 +                       get_mnt_ns(ns->mnt_ns);
14305 +               if (ns->uts_ns)
14306 +                       get_uts_ns(ns->uts_ns);
14307 +               if (ns->ipc_ns)
14308 +                       get_ipc_ns(ns->ipc_ns);
14309 +               if (ns->pid_ns)
14310 +                       get_pid_ns(ns->pid_ns);
14311 +               if (ns->net_ns)
14312 +                       get_net(ns->net_ns);
14313 +       }
14314 +       return ns;
14315 +}
14316 +
14317  /*
14318   * called from clone.  This now handles copy for nsproxy and all
14319   * namespaces therein.
14320 @@ -124,9 +168,12 @@ int copy_namespaces(unsigned long flags,
14321  {
14322         struct nsproxy *old_ns = tsk->nsproxy;
14323         struct user_namespace *user_ns = task_cred_xxx(tsk, user_ns);
14324 -       struct nsproxy *new_ns;
14325 +       struct nsproxy *new_ns = NULL;
14326         int err = 0;
14327  
14328 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
14329 +               flags, tsk, old_ns);
14330 +
14331         if (!old_ns)
14332                 return 0;
14333  
14334 @@ -136,7 +183,7 @@ int copy_namespaces(unsigned long flags,
14335                                 CLONE_NEWPID | CLONE_NEWNET)))
14336                 return 0;
14337  
14338 -       if (!ns_capable(user_ns, CAP_SYS_ADMIN)) {
14339 +       if (!vx_ns_can_unshare(user_ns, CAP_SYS_ADMIN, flags)) {
14340                 err = -EPERM;
14341                 goto out;
14342         }
14343 @@ -163,6 +210,9 @@ int copy_namespaces(unsigned long flags,
14344  
14345  out:
14346         put_nsproxy(old_ns);
14347 +       vxdprintk(VXD_CBIT(space, 3),
14348 +               "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
14349 +               flags, tsk, old_ns, err, new_ns);
14350         return err;
14351  }
14352  
14353 @@ -176,7 +226,9 @@ void free_nsproxy(struct nsproxy *ns)
14354                 put_ipc_ns(ns->ipc_ns);
14355         if (ns->pid_ns)
14356                 put_pid_ns(ns->pid_ns);
14357 -       put_net(ns->net_ns);
14358 +       if (ns->net_ns)
14359 +               put_net(ns->net_ns);
14360 +       atomic_dec(&vs_global_nsproxy);
14361         kmem_cache_free(nsproxy_cachep, ns);
14362  }
14363  
14364 @@ -190,12 +242,16 @@ int unshare_nsproxy_namespaces(unsigned
14365         struct user_namespace *user_ns;
14366         int err = 0;
14367  
14368 +       vxdprintk(VXD_CBIT(space, 4),
14369 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
14370 +               unshare_flags, current->nsproxy);
14371 +
14372         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
14373                                CLONE_NEWNET | CLONE_NEWPID)))
14374                 return 0;
14375  
14376         user_ns = new_cred ? new_cred->user_ns : current_user_ns();
14377 -       if (!ns_capable(user_ns, CAP_SYS_ADMIN))
14378 +       if (!vx_ns_can_unshare(user_ns, CAP_SYS_ADMIN, unshare_flags))
14379                 return -EPERM;
14380  
14381         *new_nsp = create_new_namespaces(unshare_flags, current, user_ns,
14382 diff -NurpP --minimal linux-3.10.9/kernel/pid.c linux-3.10.9-vs2.3.6.6/kernel/pid.c
14383 --- linux-3.10.9/kernel/pid.c   2013-07-14 17:01:35.000000000 +0000
14384 +++ linux-3.10.9-vs2.3.6.6/kernel/pid.c 2013-08-22 20:30:00.000000000 +0000
14385 @@ -38,6 +38,7 @@
14386  #include <linux/syscalls.h>
14387  #include <linux/proc_ns.h>
14388  #include <linux/proc_fs.h>
14389 +#include <linux/vs_pid.h>
14390  
14391  #define pid_hashfn(nr, ns)     \
14392         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
14393 @@ -366,7 +367,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
14394  
14395  struct pid *find_vpid(int nr)
14396  {
14397 -       return find_pid_ns(nr, task_active_pid_ns(current));
14398 +       return find_pid_ns(vx_rmap_pid(nr), task_active_pid_ns(current));
14399  }
14400  EXPORT_SYMBOL_GPL(find_vpid);
14401  
14402 @@ -426,6 +427,9 @@ void transfer_pid(struct task_struct *ol
14403  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
14404  {
14405         struct task_struct *result = NULL;
14406 +
14407 +       if (type == PIDTYPE_REALPID)
14408 +               type = PIDTYPE_PID;
14409         if (pid) {
14410                 struct hlist_node *first;
14411                 first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]),
14412 @@ -445,7 +449,7 @@ struct task_struct *find_task_by_pid_ns(
14413         rcu_lockdep_assert(rcu_read_lock_held(),
14414                            "find_task_by_pid_ns() needs rcu_read_lock()"
14415                            " protection");
14416 -       return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
14417 +       return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
14418  }
14419  
14420  struct task_struct *find_task_by_vpid(pid_t vnr)
14421 @@ -489,7 +493,7 @@ struct pid *find_get_pid(pid_t nr)
14422  }
14423  EXPORT_SYMBOL_GPL(find_get_pid);
14424  
14425 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
14426 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
14427  {
14428         struct upid *upid;
14429         pid_t nr = 0;
14430 @@ -503,6 +507,11 @@ pid_t pid_nr_ns(struct pid *pid, struct
14431  }
14432  EXPORT_SYMBOL_GPL(pid_nr_ns);
14433  
14434 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
14435 +{
14436 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
14437 +}
14438 +
14439  pid_t pid_vnr(struct pid *pid)
14440  {
14441         return pid_nr_ns(pid, task_active_pid_ns(current));
14442 diff -NurpP --minimal linux-3.10.9/kernel/pid_namespace.c linux-3.10.9-vs2.3.6.6/kernel/pid_namespace.c
14443 --- linux-3.10.9/kernel/pid_namespace.c 2013-07-14 17:01:35.000000000 +0000
14444 +++ linux-3.10.9-vs2.3.6.6/kernel/pid_namespace.c       2013-08-22 20:30:00.000000000 +0000
14445 @@ -18,6 +18,7 @@
14446  #include <linux/proc_ns.h>
14447  #include <linux/reboot.h>
14448  #include <linux/export.h>
14449 +#include <linux/vserver/global.h>
14450  
14451  struct pid_cache {
14452         int nr_ids;
14453 @@ -110,6 +111,7 @@ static struct pid_namespace *create_pid_
14454                 goto out_free_map;
14455  
14456         kref_init(&ns->kref);
14457 +       atomic_inc(&vs_global_pid_ns);
14458         ns->level = level;
14459         ns->parent = get_pid_ns(parent_pid_ns);
14460         ns->user_ns = get_user_ns(user_ns);
14461 @@ -140,6 +142,7 @@ static void destroy_pid_namespace(struct
14462         for (i = 0; i < PIDMAP_ENTRIES; i++)
14463                 kfree(ns->pidmap[i].page);
14464         put_user_ns(ns->user_ns);
14465 +       atomic_dec(&vs_global_pid_ns);
14466         kmem_cache_free(pid_ns_cachep, ns);
14467  }
14468  
14469 diff -NurpP --minimal linux-3.10.9/kernel/posix-timers.c linux-3.10.9-vs2.3.6.6/kernel/posix-timers.c
14470 --- linux-3.10.9/kernel/posix-timers.c  2013-07-14 17:01:35.000000000 +0000
14471 +++ linux-3.10.9-vs2.3.6.6/kernel/posix-timers.c        2013-08-22 21:10:34.000000000 +0000
14472 @@ -48,6 +48,7 @@
14473  #include <linux/workqueue.h>
14474  #include <linux/export.h>
14475  #include <linux/hashtable.h>
14476 +#include <linux/vs_context.h>
14477  
14478  /*
14479   * Management arrays for POSIX timers. Timers are now kept in static hash table
14480 @@ -398,6 +399,7 @@ int posix_timer_event(struct k_itimer *t
14481  {
14482         struct task_struct *task;
14483         int shared, ret = -1;
14484 +
14485         /*
14486          * FIXME: if ->sigq is queued we can race with
14487          * dequeue_signal()->do_schedule_next_timer().
14488 @@ -414,10 +416,18 @@ int posix_timer_event(struct k_itimer *t
14489         rcu_read_lock();
14490         task = pid_task(timr->it_pid, PIDTYPE_PID);
14491         if (task) {
14492 +               struct vx_info_save vxis;
14493 +               struct vx_info *vxi;
14494 +
14495 +               vxi = get_vx_info(task->vx_info);
14496 +               enter_vx_info(vxi, &vxis);
14497                 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
14498                 ret = send_sigqueue(timr->sigq, task, shared);
14499 +               leave_vx_info(&vxis);
14500 +               put_vx_info(vxi);
14501         }
14502         rcu_read_unlock();
14503 +
14504         /* If we failed to send the signal the timer stops. */
14505         return ret > 0;
14506  }
14507 diff -NurpP --minimal linux-3.10.9/kernel/printk.c linux-3.10.9-vs2.3.6.6/kernel/printk.c
14508 --- linux-3.10.9/kernel/printk.c        2013-08-22 19:51:35.000000000 +0000
14509 +++ linux-3.10.9-vs2.3.6.6/kernel/printk.c      2013-08-22 21:14:57.000000000 +0000
14510 @@ -45,6 +45,7 @@
14511  #include <linux/poll.h>
14512  #include <linux/irq_work.h>
14513  #include <linux/utsname.h>
14514 +#include <linux/vs_cvirt.h>
14515  
14516  #include <asm/uaccess.h>
14517  
14518 @@ -391,7 +392,7 @@ static int check_syslog_permissions(int
14519                 return 0;
14520  
14521         if (syslog_action_restricted(type)) {
14522 -               if (capable(CAP_SYSLOG))
14523 +               if (vx_capable(CAP_SYSLOG, VXC_SYSLOG))
14524                         return 0;
14525                 /*
14526                  * For historical reasons, accept CAP_SYS_ADMIN too, with
14527 @@ -1140,12 +1141,9 @@ int do_syslog(int type, char __user *buf
14528         if (error)
14529                 return error;
14530  
14531 -       switch (type) {
14532 -       case SYSLOG_ACTION_CLOSE:       /* Close log */
14533 -               break;
14534 -       case SYSLOG_ACTION_OPEN:        /* Open log */
14535 -               break;
14536 -       case SYSLOG_ACTION_READ:        /* Read from log */
14537 +       if ((type == SYSLOG_ACTION_READ) ||
14538 +           (type == SYSLOG_ACTION_READ_ALL) ||
14539 +           (type == SYSLOG_ACTION_READ_CLEAR)) {
14540                 error = -EINVAL;
14541                 if (!buf || len < 0)
14542                         goto out;
14543 @@ -1156,6 +1154,16 @@ int do_syslog(int type, char __user *buf
14544                         error = -EFAULT;
14545                         goto out;
14546                 }
14547 +       }
14548 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
14549 +               return vx_do_syslog(type, buf, len);
14550 +
14551 +       switch (type) {
14552 +       case SYSLOG_ACTION_CLOSE:       /* Close log */
14553 +               break;
14554 +       case SYSLOG_ACTION_OPEN:        /* Open log */
14555 +               break;
14556 +       case SYSLOG_ACTION_READ:        /* Read from log */
14557                 error = wait_event_interruptible(log_wait,
14558                                                  syslog_seq != log_next_seq);
14559                 if (error)
14560 @@ -1168,16 +1176,6 @@ int do_syslog(int type, char __user *buf
14561                 /* FALL THRU */
14562         /* Read last kernel messages */
14563         case SYSLOG_ACTION_READ_ALL:
14564 -               error = -EINVAL;
14565 -               if (!buf || len < 0)
14566 -                       goto out;
14567 -               error = 0;
14568 -               if (!len)
14569 -                       goto out;
14570 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
14571 -                       error = -EFAULT;
14572 -                       goto out;
14573 -               }
14574                 error = syslog_print_all(buf, len, clear);
14575                 break;
14576         /* Clear ring buffer */
14577 diff -NurpP --minimal linux-3.10.9/kernel/ptrace.c linux-3.10.9-vs2.3.6.6/kernel/ptrace.c
14578 --- linux-3.10.9/kernel/ptrace.c        2013-07-14 17:01:35.000000000 +0000
14579 +++ linux-3.10.9-vs2.3.6.6/kernel/ptrace.c      2013-08-22 20:30:00.000000000 +0000
14580 @@ -23,6 +23,7 @@
14581  #include <linux/syscalls.h>
14582  #include <linux/uaccess.h>
14583  #include <linux/regset.h>
14584 +#include <linux/vs_context.h>
14585  #include <linux/hw_breakpoint.h>
14586  #include <linux/cn_proc.h>
14587  #include <linux/compat.h>
14588 @@ -263,6 +264,11 @@ ok:
14589         }
14590         rcu_read_unlock();
14591  
14592 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_WATCH_P|VS_IDENT))
14593 +               return -EPERM;
14594 +       if (!vx_check(task->xid, VS_IDENT) &&
14595 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
14596 +               return -EACCES;
14597         return security_ptrace_access_check(task, mode);
14598  }
14599  
14600 diff -NurpP --minimal linux-3.10.9/kernel/sched/core.c linux-3.10.9-vs2.3.6.6/kernel/sched/core.c
14601 --- linux-3.10.9/kernel/sched/core.c    2013-07-14 17:01:35.000000000 +0000
14602 +++ linux-3.10.9-vs2.3.6.6/kernel/sched/core.c  2013-08-22 20:30:00.000000000 +0000
14603 @@ -73,6 +73,8 @@
14604  #include <linux/init_task.h>
14605  #include <linux/binfmts.h>
14606  #include <linux/context_tracking.h>
14607 +#include <linux/vs_sched.h>
14608 +#include <linux/vs_cvirt.h>
14609  
14610  #include <asm/switch_to.h>
14611  #include <asm/tlb.h>
14612 @@ -2139,9 +2141,17 @@ EXPORT_SYMBOL(avenrun); /* should be rem
14613   */
14614  void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
14615  {
14616 -       loads[0] = (avenrun[0] + offset) << shift;
14617 -       loads[1] = (avenrun[1] + offset) << shift;
14618 -       loads[2] = (avenrun[2] + offset) << shift;
14619 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
14620 +               struct vx_info *vxi = current_vx_info();
14621 +
14622 +               loads[0] = (vxi->cvirt.load[0] + offset) << shift;
14623 +               loads[1] = (vxi->cvirt.load[1] + offset) << shift;
14624 +               loads[2] = (vxi->cvirt.load[2] + offset) << shift;
14625 +       } else {
14626 +               loads[0] = (avenrun[0] + offset) << shift;
14627 +               loads[1] = (avenrun[1] + offset) << shift;
14628 +               loads[2] = (avenrun[2] + offset) << shift;
14629 +       }
14630  }
14631  
14632  static long calc_load_fold_active(struct rq *this_rq)
14633 @@ -3738,7 +3748,7 @@ SYSCALL_DEFINE1(nice, int, increment)
14634                 nice = 19;
14635  
14636         if (increment < 0 && !can_nice(current, nice))
14637 -               return -EPERM;
14638 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
14639  
14640         retval = security_task_setnice(current, nice);
14641         if (retval)
14642 diff -NurpP --minimal linux-3.10.9/kernel/sched/cputime.c linux-3.10.9-vs2.3.6.6/kernel/sched/cputime.c
14643 --- linux-3.10.9/kernel/sched/cputime.c 2013-07-14 17:01:35.000000000 +0000
14644 +++ linux-3.10.9-vs2.3.6.6/kernel/sched/cputime.c       2013-08-22 20:30:00.000000000 +0000
14645 @@ -4,6 +4,7 @@
14646  #include <linux/kernel_stat.h>
14647  #include <linux/static_key.h>
14648  #include <linux/context_tracking.h>
14649 +#include <linux/vs_sched.h>
14650  #include "sched.h"
14651  
14652  
14653 @@ -135,14 +136,17 @@ static inline void task_group_account_fi
14654  void account_user_time(struct task_struct *p, cputime_t cputime,
14655                        cputime_t cputime_scaled)
14656  {
14657 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
14658 +       int nice = (TASK_NICE(p) > 0);
14659         int index;
14660  
14661         /* Add user time to process. */
14662         p->utime += cputime;
14663         p->utimescaled += cputime_scaled;
14664 +       vx_account_user(vxi, cputime, nice);
14665         account_group_user_time(p, cputime);
14666  
14667 -       index = (TASK_NICE(p) > 0) ? CPUTIME_NICE : CPUTIME_USER;
14668 +       index = (nice) ? CPUTIME_NICE : CPUTIME_USER;
14669  
14670         /* Add user time to cpustat. */
14671         task_group_account_field(p, index, (__force u64) cputime);
14672 @@ -189,9 +193,12 @@ static inline
14673  void __account_system_time(struct task_struct *p, cputime_t cputime,
14674                         cputime_t cputime_scaled, int index)
14675  {
14676 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
14677 +
14678         /* Add system time to process. */
14679         p->stime += cputime;
14680         p->stimescaled += cputime_scaled;
14681 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
14682         account_group_system_time(p, cputime);
14683  
14684         /* Add system time to cpustat. */
14685 diff -NurpP --minimal linux-3.10.9/kernel/sched/fair.c linux-3.10.9-vs2.3.6.6/kernel/sched/fair.c
14686 --- linux-3.10.9/kernel/sched/fair.c    2013-08-22 19:51:35.000000000 +0000
14687 +++ linux-3.10.9-vs2.3.6.6/kernel/sched/fair.c  2013-08-22 20:30:00.000000000 +0000
14688 @@ -29,6 +29,7 @@
14689  #include <linux/mempolicy.h>
14690  #include <linux/migrate.h>
14691  #include <linux/task_work.h>
14692 +#include <linux/vs_cvirt.h>
14693  
14694  #include <trace/events/sched.h>
14695  
14696 @@ -1736,6 +1737,8 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
14697                 __enqueue_entity(cfs_rq, se);
14698         se->on_rq = 1;
14699  
14700 +       if (entity_is_task(se))
14701 +               vx_activate_task(task_of(se));
14702         if (cfs_rq->nr_running == 1) {
14703                 list_add_leaf_cfs_rq(cfs_rq);
14704                 check_enqueue_throttle(cfs_rq);
14705 @@ -1817,6 +1820,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
14706         if (se != cfs_rq->curr)
14707                 __dequeue_entity(cfs_rq, se);
14708         se->on_rq = 0;
14709 +       if (entity_is_task(se))
14710 +               vx_deactivate_task(task_of(se));
14711         account_entity_dequeue(cfs_rq, se);
14712  
14713         /*
14714 diff -NurpP --minimal linux-3.10.9/kernel/signal.c linux-3.10.9-vs2.3.6.6/kernel/signal.c
14715 --- linux-3.10.9/kernel/signal.c        2013-07-14 17:01:35.000000000 +0000
14716 +++ linux-3.10.9-vs2.3.6.6/kernel/signal.c      2013-08-22 21:13:50.000000000 +0000
14717 @@ -33,6 +33,8 @@
14718  #include <linux/uprobes.h>
14719  #include <linux/compat.h>
14720  #include <linux/cn_proc.h>
14721 +#include <linux/vs_context.h>
14722 +#include <linux/vs_pid.h>
14723  #define CREATE_TRACE_POINTS
14724  #include <trace/events/signal.h>
14725  
14726 @@ -790,9 +792,18 @@ static int check_kill_permission(int sig
14727         struct pid *sid;
14728         int error;
14729  
14730 +       vxdprintk(VXD_CBIT(misc, 7),
14731 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
14732 +               sig, info, t, vx_task_xid(t), t->pid);
14733 +
14734         if (!valid_signal(sig))
14735                 return -EINVAL;
14736  
14737 +/*     FIXME: needed? if so, why?
14738 +       if ((info != SEND_SIG_NOINFO) &&
14739 +               (is_si_special(info) || !si_fromuser(info)))
14740 +               goto skip;      */
14741 +
14742         if (!si_fromuser(info))
14743                 return 0;
14744  
14745 @@ -816,6 +827,20 @@ static int check_kill_permission(int sig
14746                 }
14747         }
14748  
14749 +       error = -EPERM;
14750 +       if (t->pid == 1 && current->xid)
14751 +               return error;
14752 +
14753 +       error = -ESRCH;
14754 +       /* FIXME: we shouldn't return ESRCH ever, to avoid
14755 +                 loops, maybe ENOENT or EACCES? */
14756 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
14757 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
14758 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
14759 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
14760 +               return error;
14761 +       }
14762 +/* skip: */
14763         return security_task_kill(t, info, sig, 0);
14764  }
14765  
14766 @@ -1353,7 +1378,7 @@ int kill_pid_info(int sig, struct siginf
14767         rcu_read_lock();
14768  retry:
14769         p = pid_task(pid, PIDTYPE_PID);
14770 -       if (p) {
14771 +       if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
14772                 error = group_send_sig_info(sig, info, p);
14773                 if (unlikely(error == -ESRCH))
14774                         /*
14775 @@ -1401,7 +1426,7 @@ int kill_pid_info_as_cred(int sig, struc
14776  
14777         rcu_read_lock();
14778         p = pid_task(pid, PIDTYPE_PID);
14779 -       if (!p) {
14780 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
14781                 ret = -ESRCH;
14782                 goto out_unlock;
14783         }
14784 @@ -1453,8 +1478,10 @@ static int kill_something_info(int sig,
14785                 struct task_struct * p;
14786  
14787                 for_each_process(p) {
14788 -                       if (task_pid_vnr(p) > 1 &&
14789 -                                       !same_thread_group(p, current)) {
14790 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
14791 +                               task_pid_vnr(p) > 1 &&
14792 +                               !same_thread_group(p, current) &&
14793 +                               !vx_current_initpid(p->pid)) {
14794                                 int err = group_send_sig_info(sig, info, p);
14795                                 ++count;
14796                                 if (err != -EPERM)
14797 @@ -2308,6 +2335,11 @@ relock:
14798                                 !sig_kernel_only(signr))
14799                         continue;
14800  
14801 +               /* virtual init is protected against user signals */
14802 +               if ((info->si_code == SI_USER) &&
14803 +                       vx_current_initpid(current->pid))
14804 +                       continue;
14805 +
14806                 if (sig_kernel_stop(signr)) {
14807                         /*
14808                          * The default action is to stop all threads in
14809 diff -NurpP --minimal linux-3.10.9/kernel/softirq.c linux-3.10.9-vs2.3.6.6/kernel/softirq.c
14810 --- linux-3.10.9/kernel/softirq.c       2013-07-14 17:01:35.000000000 +0000
14811 +++ linux-3.10.9-vs2.3.6.6/kernel/softirq.c     2013-08-22 20:30:00.000000000 +0000
14812 @@ -25,6 +25,7 @@
14813  #include <linux/smp.h>
14814  #include <linux/smpboot.h>
14815  #include <linux/tick.h>
14816 +#include <linux/vs_context.h>
14817  
14818  #define CREATE_TRACE_POINTS
14819  #include <trace/events/irq.h>
14820 diff -NurpP --minimal linux-3.10.9/kernel/sys.c linux-3.10.9-vs2.3.6.6/kernel/sys.c
14821 --- linux-3.10.9/kernel/sys.c   2013-07-14 17:01:35.000000000 +0000
14822 +++ linux-3.10.9-vs2.3.6.6/kernel/sys.c 2013-08-22 20:30:00.000000000 +0000
14823 @@ -55,6 +55,7 @@
14824  #include <linux/cred.h>
14825  
14826  #include <linux/kmsg_dump.h>
14827 +#include <linux/vs_pid.h>
14828  /* Move somewhere else to avoid recompiling? */
14829  #include <generated/utsrelease.h>
14830  
14831 @@ -160,7 +161,10 @@ static int set_one_prio(struct task_stru
14832                 goto out;
14833         }
14834         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
14835 -               error = -EACCES;
14836 +               if (vx_flags(VXF_IGNEG_NICE, 0))
14837 +                       error = 0;
14838 +               else
14839 +                       error = -EACCES;
14840                 goto out;
14841         }
14842         no_nice = security_task_setnice(p, niceval);
14843 @@ -211,6 +215,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
14844                         else
14845                                 pgrp = task_pgrp(current);
14846                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
14847 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
14848 +                                       continue;
14849                                 error = set_one_prio(p, niceval, error);
14850                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
14851                         break;
14852 @@ -276,6 +282,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
14853                         else
14854                                 pgrp = task_pgrp(current);
14855                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
14856 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
14857 +                                       continue;
14858                                 niceval = 20 - task_nice(p);
14859                                 if (niceval > retval)
14860                                         retval = niceval;
14861 @@ -452,6 +460,8 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
14862  
14863  static DEFINE_MUTEX(reboot_mutex);
14864  
14865 +long vs_reboot(unsigned int, void __user *);
14866 +
14867  /*
14868   * Reboot system call: for obvious reasons only root may call it,
14869   * and even root needs to set up some magic numbers in the registers
14870 @@ -494,6 +504,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
14871         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
14872                 cmd = LINUX_REBOOT_CMD_HALT;
14873  
14874 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
14875 +               return vs_reboot(cmd, arg);
14876 +
14877         mutex_lock(&reboot_mutex);
14878         switch (cmd) {
14879         case LINUX_REBOOT_CMD_RESTART:
14880 @@ -1462,7 +1475,8 @@ SYSCALL_DEFINE2(sethostname, char __user
14881         int errno;
14882         char tmp[__NEW_UTS_LEN];
14883  
14884 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
14885 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
14886 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
14887                 return -EPERM;
14888  
14889         if (len < 0 || len > __NEW_UTS_LEN)
14890 @@ -1513,7 +1527,8 @@ SYSCALL_DEFINE2(setdomainname, char __us
14891         int errno;
14892         char tmp[__NEW_UTS_LEN];
14893  
14894 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
14895 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
14896 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
14897                 return -EPERM;
14898         if (len < 0 || len > __NEW_UTS_LEN)
14899                 return -EINVAL;
14900 @@ -1632,7 +1647,7 @@ int do_prlimit(struct task_struct *tsk,
14901                 /* Keep the capable check against init_user_ns until
14902                    cgroups can contain all limits */
14903                 if (new_rlim->rlim_max > rlim->rlim_max &&
14904 -                               !capable(CAP_SYS_RESOURCE))
14905 +                       !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
14906                         retval = -EPERM;
14907                 if (!retval)
14908                         retval = security_task_setrlimit(tsk->group_leader,
14909 @@ -1685,7 +1700,8 @@ static int check_prlimit_permission(stru
14910             gid_eq(cred->gid, tcred->sgid) &&
14911             gid_eq(cred->gid, tcred->gid))
14912                 return 0;
14913 -       if (ns_capable(tcred->user_ns, CAP_SYS_RESOURCE))
14914 +       if (vx_ns_capable(tcred->user_ns,
14915 +               CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
14916                 return 0;
14917  
14918         return -EPERM;
14919 diff -NurpP --minimal linux-3.10.9/kernel/sysctl.c linux-3.10.9-vs2.3.6.6/kernel/sysctl.c
14920 --- linux-3.10.9/kernel/sysctl.c        2013-07-14 17:01:35.000000000 +0000
14921 +++ linux-3.10.9-vs2.3.6.6/kernel/sysctl.c      2013-08-22 20:30:00.000000000 +0000
14922 @@ -83,6 +83,7 @@
14923  #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
14924  #include <linux/lockdep.h>
14925  #endif
14926 +extern char vshelper_path[];
14927  #ifdef CONFIG_CHR_DEV_SG
14928  #include <scsi/sg.h>
14929  #endif
14930 @@ -628,6 +629,13 @@ static struct ctl_table kern_table[] = {
14931                 .mode           = 0644,
14932                 .proc_handler   = proc_dostring,
14933         },
14934 +       {
14935 +               .procname       = "vshelper",
14936 +               .data           = &vshelper_path,
14937 +               .maxlen         = 256,
14938 +               .mode           = 0644,
14939 +               .proc_handler   = &proc_dostring,
14940 +       },
14941  
14942  #ifdef CONFIG_CHR_DEV_SG
14943         {
14944 diff -NurpP --minimal linux-3.10.9/kernel/sysctl_binary.c linux-3.10.9-vs2.3.6.6/kernel/sysctl_binary.c
14945 --- linux-3.10.9/kernel/sysctl_binary.c 2013-07-14 17:01:35.000000000 +0000
14946 +++ linux-3.10.9-vs2.3.6.6/kernel/sysctl_binary.c       2013-08-22 20:30:00.000000000 +0000
14947 @@ -74,6 +74,7 @@ static const struct bin_table bin_kern_t
14948  
14949         { CTL_INT,      KERN_PANIC,                     "panic" },
14950         { CTL_INT,      KERN_REALROOTDEV,               "real-root-dev" },
14951 +       { CTL_STR,      KERN_VSHELPER,                  "vshelper" },
14952  
14953         { CTL_STR,      KERN_SPARC_REBOOT,              "reboot-cmd" },
14954         { CTL_INT,      KERN_CTLALTDEL,                 "ctrl-alt-del" },
14955 diff -NurpP --minimal linux-3.10.9/kernel/time/timekeeping.c linux-3.10.9-vs2.3.6.6/kernel/time/timekeeping.c
14956 --- linux-3.10.9/kernel/time/timekeeping.c      2013-07-14 17:01:35.000000000 +0000
14957 +++ linux-3.10.9-vs2.3.6.6/kernel/time/timekeeping.c    2013-08-22 20:30:00.000000000 +0000
14958 @@ -22,6 +22,7 @@
14959  #include <linux/tick.h>
14960  #include <linux/stop_machine.h>
14961  #include <linux/pvclock_gtod.h>
14962 +#include <linux/vs_time.h>
14963  
14964  #include "tick-internal.h"
14965  #include "ntp_internal.h"
14966 @@ -693,6 +694,7 @@ void getrawmonotonic(struct timespec *ts
14967         } while (read_seqcount_retry(&timekeeper_seq, seq));
14968  
14969         timespec_add_ns(ts, nsecs);
14970 +       vx_adjust_timespec(ts);
14971  }
14972  EXPORT_SYMBOL(getrawmonotonic);
14973  
14974 diff -NurpP --minimal linux-3.10.9/kernel/time.c linux-3.10.9-vs2.3.6.6/kernel/time.c
14975 --- linux-3.10.9/kernel/time.c  2013-07-14 17:01:35.000000000 +0000
14976 +++ linux-3.10.9-vs2.3.6.6/kernel/time.c        2013-08-22 20:30:00.000000000 +0000
14977 @@ -37,6 +37,7 @@
14978  #include <linux/fs.h>
14979  #include <linux/math64.h>
14980  #include <linux/ptrace.h>
14981 +#include <linux/vs_time.h>
14982  
14983  #include <asm/uaccess.h>
14984  #include <asm/unistd.h>
14985 @@ -92,7 +93,7 @@ SYSCALL_DEFINE1(stime, time_t __user *,
14986         if (err)
14987                 return err;
14988  
14989 -       do_settimeofday(&tv);
14990 +       vx_settimeofday(&tv);
14991         return 0;
14992  }
14993  
14994 @@ -181,7 +182,7 @@ int do_sys_settimeofday(const struct tim
14995                 }
14996         }
14997         if (tv)
14998 -               return do_settimeofday(tv);
14999 +               return vx_settimeofday(tv);
15000         return 0;
15001  }
15002  
15003 diff -NurpP --minimal linux-3.10.9/kernel/timer.c linux-3.10.9-vs2.3.6.6/kernel/timer.c
15004 --- linux-3.10.9/kernel/timer.c 2013-08-22 19:51:35.000000000 +0000
15005 +++ linux-3.10.9-vs2.3.6.6/kernel/timer.c       2013-08-22 21:17:56.000000000 +0000
15006 @@ -42,6 +42,10 @@
15007  #include <linux/sched/sysctl.h>
15008  #include <linux/slab.h>
15009  #include <linux/compat.h>
15010 +#include <linux/vs_base.h>
15011 +#include <linux/vs_cvirt.h>
15012 +#include <linux/vs_pid.h>
15013 +#include <linux/vserver/sched.h>
15014  
15015  #include <asm/uaccess.h>
15016  #include <asm/unistd.h>
15017 diff -NurpP --minimal linux-3.10.9/kernel/user_namespace.c linux-3.10.9-vs2.3.6.6/kernel/user_namespace.c
15018 --- linux-3.10.9/kernel/user_namespace.c        2013-08-22 19:51:35.000000000 +0000
15019 +++ linux-3.10.9-vs2.3.6.6/kernel/user_namespace.c      2013-08-22 20:30:00.000000000 +0000
15020 @@ -22,6 +22,7 @@
15021  #include <linux/ctype.h>
15022  #include <linux/projid.h>
15023  #include <linux/fs_struct.h>
15024 +#include <linux/vserver/global.h>
15025  
15026  static struct kmem_cache *user_ns_cachep __read_mostly;
15027  
15028 @@ -94,6 +95,7 @@ int create_user_ns(struct cred *new)
15029  
15030         atomic_set(&ns->count, 1);
15031         /* Leave the new->user_ns reference with the new user namespace. */
15032 +       atomic_inc(&vs_global_user_ns);
15033         ns->parent = parent_ns;
15034         ns->level = parent_ns->level + 1;
15035         ns->owner = owner;
15036 @@ -844,6 +846,8 @@ static void *userns_get(struct task_stru
15037  
15038  static void userns_put(void *ns)
15039  {
15040 +       /* FIXME: maybe move into destroyer? */
15041 +       atomic_dec(&vs_global_user_ns);
15042         put_user_ns(ns);
15043  }
15044  
15045 diff -NurpP --minimal linux-3.10.9/kernel/utsname.c linux-3.10.9-vs2.3.6.6/kernel/utsname.c
15046 --- linux-3.10.9/kernel/utsname.c       2013-07-14 17:01:35.000000000 +0000
15047 +++ linux-3.10.9-vs2.3.6.6/kernel/utsname.c     2013-08-22 21:03:08.000000000 +0000
15048 @@ -16,14 +16,17 @@
15049  #include <linux/slab.h>
15050  #include <linux/user_namespace.h>
15051  #include <linux/proc_ns.h>
15052 +#include <linux/vserver/global.h>
15053  
15054  static struct uts_namespace *create_uts_ns(void)
15055  {
15056         struct uts_namespace *uts_ns;
15057  
15058         uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
15059 -       if (uts_ns)
15060 -               kref_init(&uts_ns->kref);
15061 +       if (uts_ns) {
15062 +               kref_init(&uts_ns->kref);
15063 +               atomic_inc(&vs_global_uts_ns);
15064 +       }
15065         return uts_ns;
15066  }
15067  
15068 @@ -85,6 +88,7 @@ void free_uts_ns(struct kref *kref)
15069         ns = container_of(kref, struct uts_namespace, kref);
15070         put_user_ns(ns->user_ns);
15071         proc_free_inum(ns->proc_inum);
15072 +       atomic_dec(&vs_global_uts_ns);
15073         kfree(ns);
15074  }
15075  
15076 diff -NurpP --minimal linux-3.10.9/kernel/vserver/Kconfig linux-3.10.9-vs2.3.6.6/kernel/vserver/Kconfig
15077 --- linux-3.10.9/kernel/vserver/Kconfig 1970-01-01 00:00:00.000000000 +0000
15078 +++ linux-3.10.9-vs2.3.6.6/kernel/vserver/Kconfig       2013-08-22 20:30:00.000000000 +0000
15079 @@ -0,0 +1,233 @@
15080 +#
15081 +# Linux VServer configuration
15082 +#
15083 +
15084 +menu "Linux VServer"
15085 +
15086 +config VSERVER_AUTO_LBACK
15087 +       bool    "Automatically Assign Loopback IP"
15088 +       default y
15089 +       help
15090 +         Automatically assign a guest specific loopback
15091 +         IP and add it to the kernel network stack on
15092 +         startup.
15093 +
15094 +config VSERVER_AUTO_SINGLE
15095 +       bool    "Automatic Single IP Special Casing"
15096 +       depends on EXPERIMENTAL
15097 +       default y
15098 +       help
15099 +         This allows network contexts with a single IP to
15100 +         automatically remap 0.0.0.0 bindings to that IP,
15101 +         avoiding further network checks and improving
15102 +         performance.
15103 +
15104 +         (note: such guests do not allow to change the ip
15105 +          on the fly and do not show loopback addresses)
15106 +
15107 +config VSERVER_COWBL
15108 +       bool    "Enable COW Immutable Link Breaking"
15109 +       default y
15110 +       help
15111 +         This enables the COW (Copy-On-Write) link break code.
15112 +         It allows you to treat unified files like normal files
15113 +         when writing to them (which will implicitely break the
15114 +         link and create a copy of the unified file)
15115 +
15116 +config VSERVER_VTIME
15117 +       bool    "Enable Virtualized Guest Time"
15118 +       depends on EXPERIMENTAL
15119 +       default n
15120 +       help
15121 +         This enables per guest time offsets to allow for
15122 +         adjusting the system clock individually per guest.
15123 +         this adds some overhead to the time functions and
15124 +         therefore should not be enabled without good reason.
15125 +
15126 +config VSERVER_DEVICE
15127 +       bool    "Enable Guest Device Mapping"
15128 +       depends on EXPERIMENTAL
15129 +       default n
15130 +       help
15131 +         This enables generic device remapping.
15132 +
15133 +config VSERVER_PROC_SECURE
15134 +       bool    "Enable Proc Security"
15135 +       depends on PROC_FS
15136 +       default y
15137 +       help
15138 +         This configures ProcFS security to initially hide
15139 +         non-process entries for all contexts except the main and
15140 +         spectator context (i.e. for all guests), which is a secure
15141 +         default.
15142 +
15143 +         (note: on 1.2x the entries were visible by default)
15144 +
15145 +choice
15146 +       prompt  "Persistent Inode Tagging"
15147 +       default TAGGING_ID24
15148 +       help
15149 +         This adds persistent context information to filesystems
15150 +         mounted with the tagxid option. Tagging is a requirement
15151 +         for per-context disk limits and per-context quota.
15152 +
15153 +
15154 +config TAGGING_NONE
15155 +       bool    "Disabled"
15156 +       help
15157 +         do not store per-context information in inodes.
15158 +
15159 +config TAGGING_UID16
15160 +       bool    "UID16/GID32"
15161 +       help
15162 +         reduces UID to 16 bit, but leaves GID at 32 bit.
15163 +
15164 +config TAGGING_GID16
15165 +       bool    "UID32/GID16"
15166 +       help
15167 +         reduces GID to 16 bit, but leaves UID at 32 bit.
15168 +
15169 +config TAGGING_ID24
15170 +       bool    "UID24/GID24"
15171 +       help
15172 +         uses the upper 8bit from UID and GID for XID tagging
15173 +         which leaves 24bit for UID/GID each, which should be
15174 +         more than sufficient for normal use.
15175 +
15176 +config TAGGING_INTERN
15177 +       bool    "UID32/GID32"
15178 +       help
15179 +         this uses otherwise reserved inode fields in the on
15180 +         disk representation, which limits the use to a few
15181 +         filesystems (currently ext2 and ext3)
15182 +
15183 +endchoice
15184 +
15185 +config TAG_NFSD
15186 +       bool    "Tag NFSD User Auth and Files"
15187 +       default n
15188 +       help
15189 +         Enable this if you do want the in-kernel NFS
15190 +         Server to use the tagging specified above.
15191 +         (will require patched clients too)
15192 +
15193 +config VSERVER_PRIVACY
15194 +       bool    "Honor Privacy Aspects of Guests"
15195 +       default n
15196 +       help
15197 +         When enabled, most context checks will disallow
15198 +         access to structures assigned to a specific context,
15199 +         like ptys or loop devices.
15200 +
15201 +config VSERVER_CONTEXTS
15202 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
15203 +       range 1 65533
15204 +       default "768"   if 64BIT
15205 +       default "256"
15206 +       help
15207 +         This setting will optimize certain data structures
15208 +         and memory allocations according to the expected
15209 +         maximum.
15210 +
15211 +         note: this is not a strict upper limit.
15212 +
15213 +config VSERVER_WARN
15214 +       bool    "VServer Warnings"
15215 +       default y
15216 +       help
15217 +         This enables various runtime warnings, which will
15218 +         notify about potential manipulation attempts or
15219 +         resource shortage. It is generally considered to
15220 +         be a good idea to have that enabled.
15221 +
15222 +config VSERVER_WARN_DEVPTS
15223 +       bool    "VServer DevPTS Warnings"
15224 +       depends on VSERVER_WARN
15225 +       default y
15226 +       help
15227 +         This enables DevPTS related warnings, issued when a
15228 +         process inside a context tries to lookup or access
15229 +         a dynamic pts from the host or a different context.
15230 +
15231 +config VSERVER_DEBUG
15232 +       bool    "VServer Debugging Code"
15233 +       default n
15234 +       help
15235 +         Set this to yes if you want to be able to activate
15236 +         debugging output at runtime. It adds a very small
15237 +         overhead to all vserver related functions and
15238 +         increases the kernel size by about 20k.
15239 +
15240 +config VSERVER_HISTORY
15241 +       bool    "VServer History Tracing"
15242 +       depends on VSERVER_DEBUG
15243 +       default n
15244 +       help
15245 +         Set this to yes if you want to record the history of
15246 +         linux-vserver activities, so they can be replayed in
15247 +         the event of a kernel panic or oops.
15248 +
15249 +config VSERVER_HISTORY_SIZE
15250 +       int     "Per-CPU History Size (32-65536)"
15251 +       depends on VSERVER_HISTORY
15252 +       range 32 65536
15253 +       default 64
15254 +       help
15255 +         This allows you to specify the number of entries in
15256 +         the per-CPU history buffer.
15257 +
15258 +config VSERVER_EXTRA_MNT_CHECK
15259 +       bool    "Extra Checks for Reachability"
15260 +       default n
15261 +       help
15262 +         Set this to yes if you want to do extra checks for
15263 +         vfsmount reachability in the proc filesystem code.
15264 +         This shouldn't be required on any setup utilizing
15265 +         mnt namespaces.
15266 +
15267 +choice
15268 +       prompt  "Quotes used in debug and warn messages"
15269 +       default QUOTES_ISO8859
15270 +
15271 +config QUOTES_ISO8859
15272 +       bool    "Extended ASCII (ISO 8859) angle quotes"
15273 +       help
15274 +         This uses the extended ASCII characters \xbb
15275 +         and \xab for quoting file and process names.
15276 +
15277 +config QUOTES_UTF8
15278 +       bool    "UTF-8 angle quotes"
15279 +       help
15280 +         This uses the the UTF-8 sequences for angle
15281 +         quotes to quote file and process names.
15282 +
15283 +config QUOTES_ASCII
15284 +       bool    "ASCII single quotes"
15285 +       help
15286 +         This uses the ASCII single quote character
15287 +         (\x27) to quote file and process names.
15288 +
15289 +endchoice
15290 +
15291 +endmenu
15292 +
15293 +
15294 +config VSERVER
15295 +       bool
15296 +       default y
15297 +       select NAMESPACES
15298 +       select UTS_NS
15299 +       select IPC_NS
15300 +#      select USER_NS
15301 +       select SYSVIPC
15302 +
15303 +config VSERVER_SECURITY
15304 +       bool
15305 +       depends on SECURITY
15306 +       default y
15307 +       select SECURITY_CAPABILITIES
15308 +
15309 +config VSERVER_DISABLED
15310 +       bool
15311 +       default n
15312 +
15313 diff -NurpP --minimal linux-3.10.9/kernel/vserver/Makefile linux-3.10.9-vs2.3.6.6/kernel/vserver/Makefile
15314 --- linux-3.10.9/kernel/vserver/Makefile        1970-01-01 00:00:00.000000000 +0000
15315 +++ linux-3.10.9-vs2.3.6.6/kernel/vserver/Makefile      2013-08-22 20:30:00.000000000 +0000
15316 @@ -0,0 +1,18 @@
15317 +#
15318 +# Makefile for the Linux vserver routines.
15319 +#
15320 +
15321 +
15322 +obj-y          += vserver.o
15323 +
15324 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
15325 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
15326 +                  dlimit.o tag.o
15327 +
15328 +vserver-$(CONFIG_INET) += inet.o
15329 +vserver-$(CONFIG_PROC_FS) += proc.o
15330 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
15331 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
15332 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
15333 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
15334 +
15335 diff -NurpP --minimal linux-3.10.9/kernel/vserver/cacct.c linux-3.10.9-vs2.3.6.6/kernel/vserver/cacct.c
15336 --- linux-3.10.9/kernel/vserver/cacct.c 1970-01-01 00:00:00.000000000 +0000
15337 +++ linux-3.10.9-vs2.3.6.6/kernel/vserver/cacct.c       2013-08-22 20:30:00.000000000 +0000
15338 @@ -0,0 +1,42 @@
15339 +/*
15340 + *  linux/kernel/vserver/cacct.c
15341 + *
15342 + *  Virtual Server: Context Accounting
15343 + *
15344 + *  Copyright (C) 2006-2007 Herbert Pötzl
15345 + *
15346 + *  V0.01  added accounting stats
15347 + *
15348 + */
15349 +
15350 +#include <linux/types.h>
15351 +#include <linux/vs_context.h>
15352 +#include <linux/vserver/cacct_cmd.h>
15353 +#include <linux/vserver/cacct_int.h>
15354 +
15355 +#include <asm/errno.h>
15356 +#include <asm/uaccess.h>
15357 +
15358 +
15359 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
15360 +{
15361 +       struct vcmd_sock_stat_v0 vc_data;
15362 +       int j, field;
15363 +
15364 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15365 +               return -EFAULT;
15366 +
15367 +       field = vc_data.field;
15368 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
15369 +               return -EINVAL;
15370 +
15371 +       for (j = 0; j < 3; j++) {
15372 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
15373 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
15374 +       }
15375 +
15376 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15377 +               return -EFAULT;
15378 +       return 0;
15379 +}
15380 +
15381 diff -NurpP --minimal linux-3.10.9/kernel/vserver/cacct_init.h linux-3.10.9-vs2.3.6.6/kernel/vserver/cacct_init.h
15382 --- linux-3.10.9/kernel/vserver/cacct_init.h    1970-01-01 00:00:00.000000000 +0000
15383 +++ linux-3.10.9-vs2.3.6.6/kernel/vserver/cacct_init.h  2013-08-22 20:30:00.000000000 +0000
15384 @@ -0,0 +1,25 @@
15385 +
15386 +
15387 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
15388 +{
15389 +       int i, j;
15390 +
15391 +
15392 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
15393 +               for (j = 0; j < 3; j++) {
15394 +                       atomic_long_set(&cacct->sock[i][j].count, 0);
15395 +                       atomic_long_set(&cacct->sock[i][j].total, 0);
15396 +               }
15397 +       }
15398 +       for (i = 0; i < 8; i++)
15399 +               atomic_set(&cacct->slab[i], 0);
15400 +       for (i = 0; i < 5; i++)
15401 +               for (j = 0; j < 4; j++)
15402 +                       atomic_set(&cacct->page[i][j], 0);
15403 +}
15404 +
15405 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
15406 +{
15407 +       return;
15408 +}
15409 +
15410 diff -NurpP --minimal linux-3.10.9/kernel/vserver/cacct_proc.h linux-3.10.9-vs2.3.6.6/kernel/vserver/cacct_proc.h
15411 --- linux-3.10.9/kernel/vserver/cacct_proc.h    1970-01-01 00:00:00.000000000 +0000
15412 +++ linux-3.10.9-vs2.3.6.6/kernel/vserver/cacct_proc.h  2013-08-22 20:30:00.000000000 +0000
15413 @@ -0,0 +1,53 @@
15414 +#ifndef _VX_CACCT_PROC_H
15415 +#define _VX_CACCT_PROC_H
15416 +
15417 +#include <linux/vserver/cacct_int.h>
15418 +
15419 +
15420 +#define VX_SOCKA_TOP   \
15421 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
15422 +
15423 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
15424 +{
15425 +       int i, j, length = 0;
15426 +       static char *type[VXA_SOCK_SIZE] = {
15427 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
15428 +       };
15429 +
15430 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
15431 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
15432 +               length += sprintf(buffer + length, "%s:", type[i]);
15433 +               for (j = 0; j < 3; j++) {
15434 +                       length += sprintf(buffer + length,
15435 +                               "\t%10lu/%-10lu",
15436 +                               vx_sock_count(cacct, i, j),
15437 +                               vx_sock_total(cacct, i, j));
15438 +               }
15439 +               buffer[length++] = '\n';
15440 +       }
15441 +
15442 +       length += sprintf(buffer + length, "\n");
15443 +       length += sprintf(buffer + length,
15444 +               "slab:\t %8u %8u %8u %8u\n",
15445 +               atomic_read(&cacct->slab[1]),
15446 +               atomic_read(&cacct->slab[4]),
15447 +               atomic_read(&cacct->slab[0]),
15448 +               atomic_read(&cacct->slab[2]));
15449 +
15450 +       length += sprintf(buffer + length, "\n");
15451 +       for (i = 0; i < 5; i++) {
15452 +               length += sprintf(buffer + length,
15453 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
15454 +                       atomic_read(&cacct->page[i][0]),
15455 +                       atomic_read(&cacct->page[i][1]),
15456 +                       atomic_read(&cacct->page[i][2]),
15457 +                       atomic_read(&cacct->page[i][3]),
15458 +                       atomic_read(&cacct->page[i][4]),
15459 +                       atomic_read(&cacct->page[i][5]),
15460 +                       atomic_read(&cacct->page[i][6]),
15461 +                       atomic_read(&cacct->page[i][7]));
15462 +       }
15463 +       return length;
15464 +}
15465 +
15466 +#endif /* _VX_CACCT_PROC_H */
15467 diff -NurpP --minimal linux-3.10.9/kernel/vserver/context.c linux-3.10.9-vs2.3.6.6/kernel/vserver/context.c
15468 --- linux-3.10.9/kernel/vserver/context.c       1970-01-01 00:00:00.000000000 +0000
15469 +++ linux-3.10.9-vs2.3.6.6/kernel/vserver/context.c     2013-08-22 20:30:00.000000000 +0000
15470 @@ -0,0 +1,1119 @@
15471 +/*
15472 + *  linux/kernel/vserver/context.c
15473 + *
15474 + *  Virtual Server: Context Support
15475 + *
15476 + *  Copyright (C) 2003-2011  Herbert Pötzl
15477 + *
15478 + *  V0.01  context helper
15479 + *  V0.02  vx_ctx_kill syscall command
15480 + *  V0.03  replaced context_info calls
15481 + *  V0.04  redesign of struct (de)alloc
15482 + *  V0.05  rlimit basic implementation
15483 + *  V0.06  task_xid and info commands
15484 + *  V0.07  context flags and caps
15485 + *  V0.08  switch to RCU based hash
15486 + *  V0.09  revert to non RCU for now
15487 + *  V0.10  and back to working RCU hash
15488 + *  V0.11  and back to locking again
15489 + *  V0.12  referenced context store
15490 + *  V0.13  separate per cpu data
15491 + *  V0.14  changed vcmds to vxi arg
15492 + *  V0.15  added context stat
15493 + *  V0.16  have __create claim() the vxi
15494 + *  V0.17  removed older and legacy stuff
15495 + *  V0.18  added user credentials
15496 + *  V0.19  added warn mask
15497 + *
15498 + */
15499 +
15500 +#include <linux/slab.h>
15501 +#include <linux/types.h>
15502 +#include <linux/security.h>
15503 +#include <linux/pid_namespace.h>
15504 +#include <linux/capability.h>
15505 +
15506 +#include <linux/vserver/context.h>
15507 +#include <linux/vserver/network.h>
15508 +#include <linux/vserver/debug.h>
15509 +#include <linux/vserver/limit.h>
15510 +#include <linux/vserver/limit_int.h>
15511 +#include <linux/vserver/space.h>
15512 +#include <linux/init_task.h>
15513 +#include <linux/fs_struct.h>
15514 +#include <linux/cred.h>
15515 +
15516 +#include <linux/vs_context.h>
15517 +#include <linux/vs_limit.h>
15518 +#include <linux/vs_pid.h>
15519 +#include <linux/vserver/context_cmd.h>
15520 +
15521 +#include "cvirt_init.h"
15522 +#include "cacct_init.h"
15523 +#include "limit_init.h"
15524 +#include "sched_init.h"
15525 +
15526 +
15527 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
15528 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
15529 +
15530 +
15531 +/*     now inactive context structures */
15532 +
15533 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
15534 +
15535 +static DEFINE_SPINLOCK(vx_info_inactive_lock);
15536 +
15537 +
15538 +/*     __alloc_vx_info()
15539 +
15540 +       * allocate an initialized vx_info struct
15541 +       * doesn't make it visible (hash)                        */
15542 +
15543 +static struct vx_info *__alloc_vx_info(vxid_t xid)
15544 +{
15545 +       struct vx_info *new = NULL;
15546 +       int cpu, index;
15547 +
15548 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
15549 +
15550 +       /* would this benefit from a slab cache? */
15551 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
15552 +       if (!new)
15553 +               return 0;
15554 +
15555 +       memset(new, 0, sizeof(struct vx_info));
15556 +#ifdef CONFIG_SMP
15557 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
15558 +       if (!new->ptr_pc)
15559 +               goto error;
15560 +#endif
15561 +       new->vx_id = xid;
15562 +       INIT_HLIST_NODE(&new->vx_hlist);
15563 +       atomic_set(&new->vx_usecnt, 0);
15564 +       atomic_set(&new->vx_tasks, 0);
15565 +       new->vx_parent = NULL;
15566 +       new->vx_state = 0;
15567 +       init_waitqueue_head(&new->vx_wait);
15568 +
15569 +       /* prepare reaper */
15570 +       get_task_struct(init_pid_ns.child_reaper);
15571 +       new->vx_reaper = init_pid_ns.child_reaper;
15572 +       new->vx_badness_bias = 0;
15573 +
15574 +       /* rest of init goes here */
15575 +       vx_info_init_limit(&new->limit);
15576 +       vx_info_init_sched(&new->sched);
15577 +       vx_info_init_cvirt(&new->cvirt);
15578 +       vx_info_init_cacct(&new->cacct);
15579 +
15580 +       /* per cpu data structures */
15581 +       for_each_possible_cpu(cpu) {
15582 +               vx_info_init_sched_pc(
15583 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
15584 +               vx_info_init_cvirt_pc(
15585 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
15586 +       }
15587 +
15588 +       new->vx_flags = VXF_INIT_SET;
15589 +       new->vx_bcaps = CAP_FULL_SET;   // maybe ~CAP_SETPCAP
15590 +       new->vx_ccaps = 0;
15591 +       new->vx_umask = 0;
15592 +       new->vx_wmask = 0;
15593 +
15594 +       new->reboot_cmd = 0;
15595 +       new->exit_code = 0;
15596 +
15597 +       // preconfig spaces
15598 +       for (index = 0; index < VX_SPACES; index++) {
15599 +               struct _vx_space *space = &new->space[index];
15600 +
15601 +               // filesystem
15602 +               spin_lock(&init_fs.lock);
15603 +               init_fs.users++;
15604 +               spin_unlock(&init_fs.lock);
15605 +               space->vx_fs = &init_fs;
15606 +
15607 +               /* FIXME: do we want defaults? */
15608 +               // space->vx_real_cred = 0;
15609 +               // space->vx_cred = 0;
15610 +       }
15611 +
15612 +
15613 +       vxdprintk(VXD_CBIT(xid, 0),
15614 +               "alloc_vx_info(%d) = %p", xid, new);
15615 +       vxh_alloc_vx_info(new);
15616 +       atomic_inc(&vx_global_ctotal);
15617 +       return new;
15618 +#ifdef CONFIG_SMP
15619 +error:
15620 +       kfree(new);
15621 +       return 0;
15622 +#endif
15623 +}
15624 +
15625 +/*     __dealloc_vx_info()
15626 +
15627 +       * final disposal of vx_info                             */
15628 +
15629 +static void __dealloc_vx_info(struct vx_info *vxi)
15630 +{
15631 +#ifdef CONFIG_VSERVER_WARN
15632 +       struct vx_info_save vxis;
15633 +       int cpu;
15634 +#endif
15635 +       vxdprintk(VXD_CBIT(xid, 0),
15636 +               "dealloc_vx_info(%p)", vxi);
15637 +       vxh_dealloc_vx_info(vxi);
15638 +
15639 +#ifdef CONFIG_VSERVER_WARN
15640 +       enter_vx_info(vxi, &vxis);
15641 +       vx_info_exit_limit(&vxi->limit);
15642 +       vx_info_exit_sched(&vxi->sched);
15643 +       vx_info_exit_cvirt(&vxi->cvirt);
15644 +       vx_info_exit_cacct(&vxi->cacct);
15645 +
15646 +       for_each_possible_cpu(cpu) {
15647 +               vx_info_exit_sched_pc(
15648 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
15649 +               vx_info_exit_cvirt_pc(
15650 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
15651 +       }
15652 +       leave_vx_info(&vxis);
15653 +#endif
15654 +
15655 +       vxi->vx_id = -1;
15656 +       vxi->vx_state |= VXS_RELEASED;
15657 +
15658 +#ifdef CONFIG_SMP
15659 +       free_percpu(vxi->ptr_pc);
15660 +#endif
15661 +       kfree(vxi);
15662 +       atomic_dec(&vx_global_ctotal);
15663 +}
15664 +
15665 +static void __shutdown_vx_info(struct vx_info *vxi)
15666 +{
15667 +       struct nsproxy *nsproxy;
15668 +       struct fs_struct *fs;
15669 +       struct cred *cred;
15670 +       int index, kill;
15671 +
15672 +       might_sleep();
15673 +
15674 +       vxi->vx_state |= VXS_SHUTDOWN;
15675 +       vs_state_change(vxi, VSC_SHUTDOWN);
15676 +
15677 +       for (index = 0; index < VX_SPACES; index++) {
15678 +               struct _vx_space *space = &vxi->space[index];
15679 +
15680 +               nsproxy = xchg(&space->vx_nsproxy, NULL);
15681 +               if (nsproxy)
15682 +                       put_nsproxy(nsproxy);
15683 +
15684 +               fs = xchg(&space->vx_fs, NULL);
15685 +               spin_lock(&fs->lock);
15686 +               kill = !--fs->users;
15687 +               spin_unlock(&fs->lock);
15688 +               if (kill)
15689 +                       free_fs_struct(fs);
15690 +
15691 +               cred = (struct cred *)xchg(&space->vx_cred, NULL);
15692 +               if (cred)
15693 +                       abort_creds(cred);
15694 +       }
15695 +}
15696 +
15697 +/* exported stuff */
15698 +
15699 +void free_vx_info(struct vx_info *vxi)
15700 +{
15701 +       unsigned long flags;
15702 +       unsigned index;
15703 +
15704 +       /* check for reference counts first */
15705 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
15706 +       BUG_ON(atomic_read(&vxi->vx_tasks));
15707 +
15708 +       /* context must not be hashed */
15709 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
15710 +
15711 +       /* context shutdown is mandatory */
15712 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
15713 +
15714 +       /* spaces check */
15715 +       for (index = 0; index < VX_SPACES; index++) {
15716 +               struct _vx_space *space = &vxi->space[index];
15717 +
15718 +               BUG_ON(space->vx_nsproxy);
15719 +               BUG_ON(space->vx_fs);
15720 +               // BUG_ON(space->vx_real_cred);
15721 +               // BUG_ON(space->vx_cred);
15722 +       }
15723 +
15724 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
15725 +       hlist_del(&vxi->vx_hlist);
15726 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
15727 +
15728 +       __dealloc_vx_info(vxi);
15729 +}
15730 +
15731 +
15732 +/*     hash table for vx_info hash */
15733 +
15734 +#define VX_HASH_SIZE   13
15735 +
15736 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
15737 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
15738 +
15739 +static DEFINE_SPINLOCK(vx_info_hash_lock);
15740 +
15741 +
15742 +static inline unsigned int __hashval(vxid_t xid)
15743 +{
15744 +       return (xid % VX_HASH_SIZE);
15745 +}
15746 +
15747 +
15748 +
15749 +/*     __hash_vx_info()
15750 +
15751 +       * add the vxi to the global hash table
15752 +       * requires the hash_lock to be held                     */
15753 +
15754 +static inline void __hash_vx_info(struct vx_info *vxi)
15755 +{
15756 +       struct hlist_head *head;
15757 +
15758 +       vxd_assert_lock(&vx_info_hash_lock);
15759 +       vxdprintk(VXD_CBIT(xid, 4),
15760 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
15761 +       vxh_hash_vx_info(vxi);
15762 +
15763 +       /* context must not be hashed */
15764 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
15765 +
15766 +       vxi->vx_state |= VXS_HASHED;
15767 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
15768 +       hlist_add_head(&vxi->vx_hlist, head);
15769 +       atomic_inc(&vx_global_cactive);
15770 +}
15771 +
15772 +/*     __unhash_vx_info()
15773 +
15774 +       * remove the vxi from the global hash table
15775 +       * requires the hash_lock to be held                     */
15776 +
15777 +static inline void __unhash_vx_info(struct vx_info *vxi)
15778 +{
15779 +       unsigned long flags;
15780 +
15781 +       vxd_assert_lock(&vx_info_hash_lock);
15782 +       vxdprintk(VXD_CBIT(xid, 4),
15783 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
15784 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
15785 +       vxh_unhash_vx_info(vxi);
15786 +
15787 +       /* context must be hashed */
15788 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
15789 +       /* but without tasks */
15790 +       BUG_ON(atomic_read(&vxi->vx_tasks));
15791 +
15792 +       vxi->vx_state &= ~VXS_HASHED;
15793 +       hlist_del_init(&vxi->vx_hlist);
15794 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
15795 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
15796 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
15797 +       atomic_dec(&vx_global_cactive);
15798 +}
15799 +
15800 +
15801 +/*     __lookup_vx_info()
15802 +
15803 +       * requires the hash_lock to be held
15804 +       * doesn't increment the vx_refcnt                       */
15805 +
15806 +static inline struct vx_info *__lookup_vx_info(vxid_t xid)
15807 +{
15808 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
15809 +       struct hlist_node *pos;
15810 +       struct vx_info *vxi;
15811 +
15812 +       vxd_assert_lock(&vx_info_hash_lock);
15813 +       hlist_for_each(pos, head) {
15814 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
15815 +
15816 +               if (vxi->vx_id == xid)
15817 +                       goto found;
15818 +       }
15819 +       vxi = NULL;
15820 +found:
15821 +       vxdprintk(VXD_CBIT(xid, 0),
15822 +               "__lookup_vx_info(#%u): %p[#%u]",
15823 +               xid, vxi, vxi ? vxi->vx_id : 0);
15824 +       vxh_lookup_vx_info(vxi, xid);
15825 +       return vxi;
15826 +}
15827 +
15828 +
15829 +/*     __create_vx_info()
15830 +
15831 +       * create the requested context
15832 +       * get(), claim() and hash it                            */
15833 +
15834 +static struct vx_info *__create_vx_info(int id)
15835 +{
15836 +       struct vx_info *new, *vxi = NULL;
15837 +
15838 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
15839 +
15840 +       if (!(new = __alloc_vx_info(id)))
15841 +               return ERR_PTR(-ENOMEM);
15842 +
15843 +       /* required to make dynamic xids unique */
15844 +       spin_lock(&vx_info_hash_lock);
15845 +
15846 +       /* static context requested */
15847 +       if ((vxi = __lookup_vx_info(id))) {
15848 +               vxdprintk(VXD_CBIT(xid, 0),
15849 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
15850 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
15851 +                       vxi = ERR_PTR(-EBUSY);
15852 +               else
15853 +                       vxi = ERR_PTR(-EEXIST);
15854 +               goto out_unlock;
15855 +       }
15856 +       /* new context */
15857 +       vxdprintk(VXD_CBIT(xid, 0),
15858 +               "create_vx_info(%d) = %p (new)", id, new);
15859 +       claim_vx_info(new, NULL);
15860 +       __hash_vx_info(get_vx_info(new));
15861 +       vxi = new, new = NULL;
15862 +
15863 +out_unlock:
15864 +       spin_unlock(&vx_info_hash_lock);
15865 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
15866 +       if (new)
15867 +               __dealloc_vx_info(new);
15868 +       return vxi;
15869 +}
15870 +
15871 +
15872 +/*     exported stuff                                          */
15873 +
15874 +
15875 +void unhash_vx_info(struct vx_info *vxi)
15876 +{
15877 +       spin_lock(&vx_info_hash_lock);
15878 +       __unhash_vx_info(vxi);
15879 +       spin_unlock(&vx_info_hash_lock);
15880 +       __shutdown_vx_info(vxi);
15881 +       __wakeup_vx_info(vxi);
15882 +}
15883 +
15884 +
15885 +/*     lookup_vx_info()
15886 +
15887 +       * search for a vx_info and get() it
15888 +       * negative id means current                             */
15889 +
15890 +struct vx_info *lookup_vx_info(int id)
15891 +{
15892 +       struct vx_info *vxi = NULL;
15893 +
15894 +       if (id < 0) {
15895 +               vxi = get_vx_info(current_vx_info());
15896 +       } else if (id > 1) {
15897 +               spin_lock(&vx_info_hash_lock);
15898 +               vxi = get_vx_info(__lookup_vx_info(id));
15899 +               spin_unlock(&vx_info_hash_lock);
15900 +       }
15901 +       return vxi;
15902 +}
15903 +
15904 +/*     xid_is_hashed()
15905 +
15906 +       * verify that xid is still hashed                       */
15907 +
15908 +int xid_is_hashed(vxid_t xid)
15909 +{
15910 +       int hashed;
15911 +
15912 +       spin_lock(&vx_info_hash_lock);
15913 +       hashed = (__lookup_vx_info(xid) != NULL);
15914 +       spin_unlock(&vx_info_hash_lock);
15915 +       return hashed;
15916 +}
15917 +
15918 +#ifdef CONFIG_PROC_FS
15919 +
15920 +/*     get_xid_list()
15921 +
15922 +       * get a subset of hashed xids for proc
15923 +       * assumes size is at least one                          */
15924 +
15925 +int get_xid_list(int index, unsigned int *xids, int size)
15926 +{
15927 +       int hindex, nr_xids = 0;
15928 +
15929 +       /* only show current and children */
15930 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
15931 +               if (index > 0)
15932 +                       return 0;
15933 +               xids[nr_xids] = vx_current_xid();
15934 +               return 1;
15935 +       }
15936 +
15937 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
15938 +               struct hlist_head *head = &vx_info_hash[hindex];
15939 +               struct hlist_node *pos;
15940 +
15941 +               spin_lock(&vx_info_hash_lock);
15942 +               hlist_for_each(pos, head) {
15943 +                       struct vx_info *vxi;
15944 +
15945 +                       if (--index > 0)
15946 +                               continue;
15947 +
15948 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
15949 +                       xids[nr_xids] = vxi->vx_id;
15950 +                       if (++nr_xids >= size) {
15951 +                               spin_unlock(&vx_info_hash_lock);
15952 +                               goto out;
15953 +                       }
15954 +               }
15955 +               /* keep the lock time short */
15956 +               spin_unlock(&vx_info_hash_lock);
15957 +       }
15958 +out:
15959 +       return nr_xids;
15960 +}
15961 +#endif
15962 +
15963 +#ifdef CONFIG_VSERVER_DEBUG
15964 +
15965 +void   dump_vx_info_inactive(int level)
15966 +{
15967 +       struct hlist_node *entry, *next;
15968 +
15969 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
15970 +               struct vx_info *vxi =
15971 +                       list_entry(entry, struct vx_info, vx_hlist);
15972 +
15973 +               dump_vx_info(vxi, level);
15974 +       }
15975 +}
15976 +
15977 +#endif
15978 +
15979 +#if 0
15980 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
15981 +{
15982 +       struct user_struct *new_user, *old_user;
15983 +
15984 +       if (!p || !vxi)
15985 +               BUG();
15986 +
15987 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
15988 +               return -EACCES;
15989 +
15990 +       new_user = alloc_uid(vxi->vx_id, p->uid);
15991 +       if (!new_user)
15992 +               return -ENOMEM;
15993 +
15994 +       old_user = p->user;
15995 +       if (new_user != old_user) {
15996 +               atomic_inc(&new_user->processes);
15997 +               atomic_dec(&old_user->processes);
15998 +               p->user = new_user;
15999 +       }
16000 +       free_uid(old_user);
16001 +       return 0;
16002 +}
16003 +#endif
16004 +
16005 +#if 0
16006 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
16007 +{
16008 +       // p->cap_effective &= vxi->vx_cap_bset;
16009 +       p->cap_effective =
16010 +               cap_intersect(p->cap_effective, vxi->cap_bset);
16011 +       // p->cap_inheritable &= vxi->vx_cap_bset;
16012 +       p->cap_inheritable =
16013 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
16014 +       // p->cap_permitted &= vxi->vx_cap_bset;
16015 +       p->cap_permitted =
16016 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
16017 +}
16018 +#endif
16019 +
16020 +
16021 +#include <linux/file.h>
16022 +#include <linux/fdtable.h>
16023 +
16024 +static int vx_openfd_task(struct task_struct *tsk)
16025 +{
16026 +       struct files_struct *files = tsk->files;
16027 +       struct fdtable *fdt;
16028 +       const unsigned long *bptr;
16029 +       int count, total;
16030 +
16031 +       /* no rcu_read_lock() because of spin_lock() */
16032 +       spin_lock(&files->file_lock);
16033 +       fdt = files_fdtable(files);
16034 +       bptr = fdt->open_fds;
16035 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
16036 +       for (total = 0; count > 0; count--) {
16037 +               if (*bptr)
16038 +                       total += hweight_long(*bptr);
16039 +               bptr++;
16040 +       }
16041 +       spin_unlock(&files->file_lock);
16042 +       return total;
16043 +}
16044 +
16045 +
16046 +/*     for *space compatibility */
16047 +
16048 +asmlinkage long sys_unshare(unsigned long);
16049 +
16050 +/*
16051 + *     migrate task to new context
16052 + *     gets vxi, puts old_vxi on change
16053 + *     optionally unshares namespaces (hack)
16054 + */
16055 +
16056 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
16057 +{
16058 +       struct vx_info *old_vxi;
16059 +       int ret = 0;
16060 +
16061 +       if (!p || !vxi)
16062 +               BUG();
16063 +
16064 +       vxdprintk(VXD_CBIT(xid, 5),
16065 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
16066 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
16067 +
16068 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
16069 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16070 +               return -EACCES;
16071 +
16072 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
16073 +               return -EFAULT;
16074 +
16075 +       old_vxi = task_get_vx_info(p);
16076 +       if (old_vxi == vxi)
16077 +               goto out;
16078 +
16079 +//     if (!(ret = vx_migrate_user(p, vxi))) {
16080 +       {
16081 +               int openfd;
16082 +
16083 +               task_lock(p);
16084 +               openfd = vx_openfd_task(p);
16085 +
16086 +               if (old_vxi) {
16087 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
16088 +                       atomic_dec(&old_vxi->cvirt.nr_running);
16089 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
16090 +                       /* FIXME: what about the struct files here? */
16091 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
16092 +                       /* account for the executable */
16093 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
16094 +               }
16095 +               atomic_inc(&vxi->cvirt.nr_threads);
16096 +               atomic_inc(&vxi->cvirt.nr_running);
16097 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
16098 +               /* FIXME: what about the struct files here? */
16099 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
16100 +               /* account for the executable */
16101 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
16102 +
16103 +               if (old_vxi) {
16104 +                       release_vx_info(old_vxi, p);
16105 +                       clr_vx_info(&p->vx_info);
16106 +               }
16107 +               claim_vx_info(vxi, p);
16108 +               set_vx_info(&p->vx_info, vxi);
16109 +               p->xid = vxi->vx_id;
16110 +
16111 +               vxdprintk(VXD_CBIT(xid, 5),
16112 +                       "moved task %p into vxi:%p[#%d]",
16113 +                       p, vxi, vxi->vx_id);
16114 +
16115 +               // vx_mask_cap_bset(vxi, p);
16116 +               task_unlock(p);
16117 +
16118 +               /* hack for *spaces to provide compatibility */
16119 +               if (unshare) {
16120 +                       struct nsproxy *old_nsp, *new_nsp;
16121 +
16122 +                       ret = unshare_nsproxy_namespaces(
16123 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
16124 +                               &new_nsp, NULL, NULL);
16125 +                       if (ret)
16126 +                               goto out;
16127 +
16128 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
16129 +                       vx_set_space(vxi,
16130 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
16131 +                       put_nsproxy(old_nsp);
16132 +               }
16133 +       }
16134 +out:
16135 +       put_vx_info(old_vxi);
16136 +       return ret;
16137 +}
16138 +
16139 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
16140 +{
16141 +       struct task_struct *old_reaper;
16142 +       struct vx_info *reaper_vxi;
16143 +
16144 +       if (!vxi)
16145 +               return -EINVAL;
16146 +
16147 +       vxdprintk(VXD_CBIT(xid, 6),
16148 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
16149 +               vxi, vxi->vx_id, p, p->xid, p->pid);
16150 +
16151 +       old_reaper = vxi->vx_reaper;
16152 +       if (old_reaper == p)
16153 +               return 0;
16154 +
16155 +       reaper_vxi = task_get_vx_info(p);
16156 +       if (reaper_vxi && reaper_vxi != vxi) {
16157 +               vxwprintk(1,
16158 +                       "Unsuitable reaper [" VS_Q("%s") ",%u:#%u] "
16159 +                       "for [xid #%u]",
16160 +                       p->comm, p->pid, p->xid, vx_current_xid());
16161 +               goto out;
16162 +       }
16163 +
16164 +       /* set new child reaper */
16165 +       get_task_struct(p);
16166 +       vxi->vx_reaper = p;
16167 +       put_task_struct(old_reaper);
16168 +out:
16169 +       put_vx_info(reaper_vxi);
16170 +       return 0;
16171 +}
16172 +
16173 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
16174 +{
16175 +       if (!vxi)
16176 +               return -EINVAL;
16177 +
16178 +       vxdprintk(VXD_CBIT(xid, 6),
16179 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
16180 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16181 +
16182 +       vxi->vx_flags &= ~VXF_STATE_INIT;
16183 +       // vxi->vx_initpid = p->tgid;
16184 +       vxi->vx_initpid = p->pid;
16185 +       return 0;
16186 +}
16187 +
16188 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
16189 +{
16190 +       vxdprintk(VXD_CBIT(xid, 6),
16191 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
16192 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16193 +
16194 +       vxi->exit_code = code;
16195 +       vxi->vx_initpid = 0;
16196 +}
16197 +
16198 +
16199 +void vx_set_persistent(struct vx_info *vxi)
16200 +{
16201 +       vxdprintk(VXD_CBIT(xid, 6),
16202 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
16203 +
16204 +       get_vx_info(vxi);
16205 +       claim_vx_info(vxi, NULL);
16206 +}
16207 +
16208 +void vx_clear_persistent(struct vx_info *vxi)
16209 +{
16210 +       vxdprintk(VXD_CBIT(xid, 6),
16211 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
16212 +
16213 +       release_vx_info(vxi, NULL);
16214 +       put_vx_info(vxi);
16215 +}
16216 +
16217 +void vx_update_persistent(struct vx_info *vxi)
16218 +{
16219 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
16220 +               vx_set_persistent(vxi);
16221 +       else
16222 +               vx_clear_persistent(vxi);
16223 +}
16224 +
16225 +
16226 +/*     task must be current or locked          */
16227 +
16228 +void   exit_vx_info(struct task_struct *p, int code)
16229 +{
16230 +       struct vx_info *vxi = p->vx_info;
16231 +
16232 +       if (vxi) {
16233 +               atomic_dec(&vxi->cvirt.nr_threads);
16234 +               vx_nproc_dec(p);
16235 +
16236 +               vxi->exit_code = code;
16237 +               release_vx_info(vxi, p);
16238 +       }
16239 +}
16240 +
16241 +void   exit_vx_info_early(struct task_struct *p, int code)
16242 +{
16243 +       struct vx_info *vxi = p->vx_info;
16244 +
16245 +       if (vxi) {
16246 +               if (vxi->vx_initpid == p->pid)
16247 +                       vx_exit_init(vxi, p, code);
16248 +               if (vxi->vx_reaper == p)
16249 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
16250 +       }
16251 +}
16252 +
16253 +
16254 +/* vserver syscall commands below here */
16255 +
16256 +/* taks xid and vx_info functions */
16257 +
16258 +#include <asm/uaccess.h>
16259 +
16260 +
16261 +int vc_task_xid(uint32_t id)
16262 +{
16263 +       vxid_t xid;
16264 +
16265 +       if (id) {
16266 +               struct task_struct *tsk;
16267 +
16268 +               rcu_read_lock();
16269 +               tsk = find_task_by_real_pid(id);
16270 +               xid = (tsk) ? tsk->xid : -ESRCH;
16271 +               rcu_read_unlock();
16272 +       } else
16273 +               xid = vx_current_xid();
16274 +       return xid;
16275 +}
16276 +
16277 +
16278 +int vc_vx_info(struct vx_info *vxi, void __user *data)
16279 +{
16280 +       struct vcmd_vx_info_v0 vc_data;
16281 +
16282 +       vc_data.xid = vxi->vx_id;
16283 +       vc_data.initpid = vxi->vx_initpid;
16284 +
16285 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16286 +               return -EFAULT;
16287 +       return 0;
16288 +}
16289 +
16290 +
16291 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
16292 +{
16293 +       struct vcmd_ctx_stat_v0 vc_data;
16294 +
16295 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
16296 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
16297 +
16298 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16299 +               return -EFAULT;
16300 +       return 0;
16301 +}
16302 +
16303 +
16304 +/* context functions */
16305 +
16306 +int vc_ctx_create(uint32_t xid, void __user *data)
16307 +{
16308 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
16309 +       struct vx_info *new_vxi;
16310 +       int ret;
16311 +
16312 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16313 +               return -EFAULT;
16314 +
16315 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
16316 +               return -EINVAL;
16317 +
16318 +       new_vxi = __create_vx_info(xid);
16319 +       if (IS_ERR(new_vxi))
16320 +               return PTR_ERR(new_vxi);
16321 +
16322 +       /* initial flags */
16323 +       new_vxi->vx_flags = vc_data.flagword;
16324 +
16325 +       ret = -ENOEXEC;
16326 +       if (vs_state_change(new_vxi, VSC_STARTUP))
16327 +               goto out;
16328 +
16329 +       ret = vx_migrate_task(current, new_vxi, (!data));
16330 +       if (ret)
16331 +               goto out;
16332 +
16333 +       /* return context id on success */
16334 +       ret = new_vxi->vx_id;
16335 +
16336 +       /* get a reference for persistent contexts */
16337 +       if ((vc_data.flagword & VXF_PERSISTENT))
16338 +               vx_set_persistent(new_vxi);
16339 +out:
16340 +       release_vx_info(new_vxi, NULL);
16341 +       put_vx_info(new_vxi);
16342 +       return ret;
16343 +}
16344 +
16345 +
16346 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
16347 +{
16348 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
16349 +       int ret;
16350 +
16351 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16352 +               return -EFAULT;
16353 +
16354 +       ret = vx_migrate_task(current, vxi, 0);
16355 +       if (ret)
16356 +               return ret;
16357 +       if (vc_data.flagword & VXM_SET_INIT)
16358 +               ret = vx_set_init(vxi, current);
16359 +       if (ret)
16360 +               return ret;
16361 +       if (vc_data.flagword & VXM_SET_REAPER)
16362 +               ret = vx_set_reaper(vxi, current);
16363 +       return ret;
16364 +}
16365 +
16366 +
16367 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
16368 +{
16369 +       struct vcmd_ctx_flags_v0 vc_data;
16370 +
16371 +       vc_data.flagword = vxi->vx_flags;
16372 +
16373 +       /* special STATE flag handling */
16374 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
16375 +
16376 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16377 +               return -EFAULT;
16378 +       return 0;
16379 +}
16380 +
16381 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
16382 +{
16383 +       struct vcmd_ctx_flags_v0 vc_data;
16384 +       uint64_t mask, trigger;
16385 +
16386 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16387 +               return -EFAULT;
16388 +
16389 +       /* special STATE flag handling */
16390 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
16391 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
16392 +
16393 +       if (vxi == current_vx_info()) {
16394 +               /* if (trigger & VXF_STATE_SETUP)
16395 +                       vx_mask_cap_bset(vxi, current); */
16396 +               if (trigger & VXF_STATE_INIT) {
16397 +                       int ret;
16398 +
16399 +                       ret = vx_set_init(vxi, current);
16400 +                       if (ret)
16401 +                               return ret;
16402 +                       ret = vx_set_reaper(vxi, current);
16403 +                       if (ret)
16404 +                               return ret;
16405 +               }
16406 +       }
16407 +
16408 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
16409 +               vc_data.flagword, mask);
16410 +       if (trigger & VXF_PERSISTENT)
16411 +               vx_update_persistent(vxi);
16412 +
16413 +       return 0;
16414 +}
16415 +
16416 +
16417 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
16418 +{
16419 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
16420 +
16421 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
16422 +       return v;
16423 +}
16424 +
16425 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
16426 +{
16427 +       kernel_cap_t c = __cap_empty_set;
16428 +
16429 +       c.cap[0] = v & 0xFFFFFFFF;
16430 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
16431 +
16432 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
16433 +       return c;
16434 +}
16435 +
16436 +
16437 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
16438 +{
16439 +       if (bcaps)
16440 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
16441 +       if (ccaps)
16442 +               *ccaps = vxi->vx_ccaps;
16443 +
16444 +       return 0;
16445 +}
16446 +
16447 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
16448 +{
16449 +       struct vcmd_ctx_caps_v1 vc_data;
16450 +       int ret;
16451 +
16452 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
16453 +       if (ret)
16454 +               return ret;
16455 +       vc_data.cmask = ~0ULL;
16456 +
16457 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16458 +               return -EFAULT;
16459 +       return 0;
16460 +}
16461 +
16462 +static int do_set_caps(struct vx_info *vxi,
16463 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
16464 +{
16465 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
16466 +
16467 +#if 0
16468 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
16469 +               bcaps, bmask, ccaps, cmask);
16470 +#endif
16471 +       vxi->vx_bcaps = cap_t_from_caps(
16472 +               vs_mask_flags(bcold, bcaps, bmask));
16473 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
16474 +
16475 +       return 0;
16476 +}
16477 +
16478 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
16479 +{
16480 +       struct vcmd_ctx_caps_v1 vc_data;
16481 +
16482 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16483 +               return -EFAULT;
16484 +
16485 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
16486 +}
16487 +
16488 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
16489 +{
16490 +       struct vcmd_bcaps vc_data;
16491 +       int ret;
16492 +
16493 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
16494 +       if (ret)
16495 +               return ret;
16496 +       vc_data.bmask = ~0ULL;
16497 +
16498 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16499 +               return -EFAULT;
16500 +       return 0;
16501 +}
16502 +
16503 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
16504 +{
16505 +       struct vcmd_bcaps vc_data;
16506 +
16507 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16508 +               return -EFAULT;
16509 +
16510 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
16511 +}
16512 +
16513 +
16514 +int vc_get_umask(struct vx_info *vxi, void __user *data)
16515 +{
16516 +       struct vcmd_umask vc_data;
16517 +
16518 +       vc_data.umask = vxi->vx_umask;
16519 +       vc_data.mask = ~0ULL;
16520 +
16521 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16522 +               return -EFAULT;
16523 +       return 0;
16524 +}
16525 +
16526 +int vc_set_umask(struct vx_info *vxi, void __user *data)
16527 +{
16528 +       struct vcmd_umask vc_data;
16529 +
16530 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16531 +               return -EFAULT;
16532 +
16533 +       vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
16534 +               vc_data.umask, vc_data.mask);
16535 +       return 0;
16536 +}
16537 +
16538 +
16539 +int vc_get_wmask(struct vx_info *vxi, void __user *data)
16540 +{
16541 +       struct vcmd_wmask vc_data;
16542 +
16543 +       vc_data.wmask = vxi->vx_wmask;
16544 +       vc_data.mask = ~0ULL;
16545 +
16546 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16547 +               return -EFAULT;
16548 +       return 0;
16549 +}
16550 +
16551 +int vc_set_wmask(struct vx_info *vxi, void __user *data)
16552 +{
16553 +       struct vcmd_wmask vc_data;
16554 +
16555 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16556 +               return -EFAULT;
16557 +
16558 +       vxi->vx_wmask = vs_mask_flags(vxi->vx_wmask,
16559 +               vc_data.wmask, vc_data.mask);
16560 +       return 0;
16561 +}
16562 +
16563 +
16564 +int vc_get_badness(struct vx_info *vxi, void __user *data)
16565 +{
16566 +       struct vcmd_badness_v0 vc_data;
16567 +
16568 +       vc_data.bias = vxi->vx_badness_bias;
16569 +
16570 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16571 +               return -EFAULT;
16572 +       return 0;
16573 +}
16574 +
16575 +int vc_set_badness(struct vx_info *vxi, void __user *data)
16576 +{
16577 +       struct vcmd_badness_v0 vc_data;
16578 +
16579 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16580 +               return -EFAULT;
16581 +
16582 +       vxi->vx_badness_bias = vc_data.bias;
16583 +       return 0;
16584 +}
16585 +
16586 +#include <linux/module.h>
16587 +
16588 +EXPORT_SYMBOL_GPL(free_vx_info);
16589 +
16590 diff -NurpP --minimal linux-3.10.9/kernel/vserver/cvirt.c linux-3.10.9-vs2.3.6.6/kernel/vserver/cvirt.c
16591 --- linux-3.10.9/kernel/vserver/cvirt.c 1970-01-01 00:00:00.000000000 +0000
16592 +++ linux-3.10.9-vs2.3.6.6/kernel/vserver/cvirt.c       2013-08-22 20:30:00.000000000 +0000
16593 @@ -0,0 +1,313 @@
16594 +/*
16595 + *  linux/kernel/vserver/cvirt.c
16596 + *
16597 + *  Virtual Server: Context Virtualization
16598 + *
16599 + *  Copyright (C) 2004-2007  Herbert Pötzl
16600 + *
16601 + *  V0.01  broken out from limit.c
16602 + *  V0.02  added utsname stuff
16603 + *  V0.03  changed vcmds to vxi arg
16604 + *
16605 + */
16606 +
16607 +#include <linux/types.h>
16608 +#include <linux/utsname.h>
16609 +#include <linux/vs_cvirt.h>
16610 +#include <linux/vserver/switch.h>
16611 +#include <linux/vserver/cvirt_cmd.h>
16612 +
16613 +#include <asm/uaccess.h>
16614 +
16615 +
16616 +void vx_vsi_boottime(struct timespec *boottime)
16617 +{
16618 +       struct vx_info *vxi = current_vx_info();
16619 +
16620 +       set_normalized_timespec(boottime,
16621 +               boottime->tv_sec + vxi->cvirt.bias_uptime.tv_sec,
16622 +               boottime->tv_nsec + vxi->cvirt.bias_uptime.tv_nsec);
16623 +       return;
16624 +}
16625 +
16626 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
16627 +{
16628 +       struct vx_info *vxi = current_vx_info();
16629 +
16630 +       set_normalized_timespec(uptime,
16631 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
16632 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
16633 +       if (!idle)
16634 +               return;
16635 +       set_normalized_timespec(idle,
16636 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
16637 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
16638 +       return;
16639 +}
16640 +
16641 +uint64_t vx_idle_jiffies(void)
16642 +{
16643 +       return init_task.utime + init_task.stime;
16644 +}
16645 +
16646 +
16647 +
16648 +static inline uint32_t __update_loadavg(uint32_t load,
16649 +       int wsize, int delta, int n)
16650 +{
16651 +       unsigned long long calc, prev;
16652 +
16653 +       /* just set it to n */
16654 +       if (unlikely(delta >= wsize))
16655 +               return (n << FSHIFT);
16656 +
16657 +       calc = delta * n;
16658 +       calc <<= FSHIFT;
16659 +       prev = (wsize - delta);
16660 +       prev *= load;
16661 +       calc += prev;
16662 +       do_div(calc, wsize);
16663 +       return calc;
16664 +}
16665 +
16666 +
16667 +void vx_update_load(struct vx_info *vxi)
16668 +{
16669 +       uint32_t now, last, delta;
16670 +       unsigned int nr_running, nr_uninterruptible;
16671 +       unsigned int total;
16672 +       unsigned long flags;
16673 +
16674 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
16675 +
16676 +       now = jiffies;
16677 +       last = vxi->cvirt.load_last;
16678 +       delta = now - last;
16679 +
16680 +       if (delta < 5*HZ)
16681 +               goto out;
16682 +
16683 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
16684 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
16685 +       total = nr_running + nr_uninterruptible;
16686 +
16687 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
16688 +               60*HZ, delta, total);
16689 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
16690 +               5*60*HZ, delta, total);
16691 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
16692 +               15*60*HZ, delta, total);
16693 +
16694 +       vxi->cvirt.load_last = now;
16695 +out:
16696 +       atomic_inc(&vxi->cvirt.load_updates);
16697 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
16698 +}
16699 +
16700 +
16701 +/*
16702 + * Commands to do_syslog:
16703 + *
16704 + *      0 -- Close the log.  Currently a NOP.
16705 + *      1 -- Open the log. Currently a NOP.
16706 + *      2 -- Read from the log.
16707 + *      3 -- Read all messages remaining in the ring buffer.
16708 + *      4 -- Read and clear all messages remaining in the ring buffer
16709 + *      5 -- Clear ring buffer.
16710 + *      6 -- Disable printk's to console
16711 + *      7 -- Enable printk's to console
16712 + *      8 -- Set level of messages printed to console
16713 + *      9 -- Return number of unread characters in the log buffer
16714 + *     10 -- Return size of the log buffer
16715 + */
16716 +int vx_do_syslog(int type, char __user *buf, int len)
16717 +{
16718 +       int error = 0;
16719 +       int do_clear = 0;
16720 +       struct vx_info *vxi = current_vx_info();
16721 +       struct _vx_syslog *log;
16722 +
16723 +       if (!vxi)
16724 +               return -EINVAL;
16725 +       log = &vxi->cvirt.syslog;
16726 +
16727 +       switch (type) {
16728 +       case 0:         /* Close log */
16729 +       case 1:         /* Open log */
16730 +               break;
16731 +       case 2:         /* Read from log */
16732 +               error = wait_event_interruptible(log->log_wait,
16733 +                       (log->log_start - log->log_end));
16734 +               if (error)
16735 +                       break;
16736 +               spin_lock_irq(&log->logbuf_lock);
16737 +               spin_unlock_irq(&log->logbuf_lock);
16738 +               break;
16739 +       case 4:         /* Read/clear last kernel messages */
16740 +               do_clear = 1;
16741 +               /* fall through */
16742 +       case 3:         /* Read last kernel messages */
16743 +               return 0;
16744 +
16745 +       case 5:         /* Clear ring buffer */
16746 +               return 0;
16747 +
16748 +       case 6:         /* Disable logging to console */
16749 +       case 7:         /* Enable logging to console */
16750 +       case 8:         /* Set level of messages printed to console */
16751 +               break;
16752 +
16753 +       case 9:         /* Number of chars in the log buffer */
16754 +               return 0;
16755 +       case 10:        /* Size of the log buffer */
16756 +               return 0;
16757 +       default:
16758 +               error = -EINVAL;
16759 +               break;
16760 +       }
16761 +       return error;
16762 +}
16763 +
16764 +
16765 +/* virtual host info names */
16766 +
16767 +static char *vx_vhi_name(struct vx_info *vxi, int id)
16768 +{
16769 +       struct nsproxy *nsproxy;
16770 +       struct uts_namespace *uts;
16771 +
16772 +       if (id == VHIN_CONTEXT)
16773 +               return vxi->vx_name;
16774 +
16775 +       nsproxy = vxi->space[0].vx_nsproxy;
16776 +       if (!nsproxy)
16777 +               return NULL;
16778 +
16779 +       uts = nsproxy->uts_ns;
16780 +       if (!uts)
16781 +               return NULL;
16782 +
16783 +       switch (id) {
16784 +       case VHIN_SYSNAME:
16785 +               return uts->name.sysname;
16786 +       case VHIN_NODENAME:
16787 +               return uts->name.nodename;
16788 +       case VHIN_RELEASE:
16789 +               return uts->name.release;
16790 +       case VHIN_VERSION:
16791 +               return uts->name.version;
16792 +       case VHIN_MACHINE:
16793 +               return uts->name.machine;
16794 +       case VHIN_DOMAINNAME:
16795 +               return uts->name.domainname;
16796 +       default:
16797 +               return NULL;
16798 +       }
16799 +       return NULL;
16800 +}
16801 +
16802 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
16803 +{
16804 +       struct vcmd_vhi_name_v0 vc_data;
16805 +       char *name;
16806 +
16807 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16808 +               return -EFAULT;
16809 +
16810 +       name = vx_vhi_name(vxi, vc_data.field);
16811 +       if (!name)
16812 +               return -EINVAL;
16813 +
16814 +       memcpy(name, vc_data.name, 65);
16815 +       return 0;
16816 +}
16817 +
16818 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
16819 +{
16820 +       struct vcmd_vhi_name_v0 vc_data;
16821 +       char *name;
16822 +
16823 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16824 +               return -EFAULT;
16825 +
16826 +       name = vx_vhi_name(vxi, vc_data.field);
16827 +       if (!name)
16828 +               return -EINVAL;
16829 +
16830 +       memcpy(vc_data.name, name, 65);
16831 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16832 +               return -EFAULT;
16833 +       return 0;
16834 +}
16835 +
16836 +
16837 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
16838 +{
16839 +       struct vcmd_virt_stat_v0 vc_data;
16840 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
16841 +       struct timespec uptime;
16842 +
16843 +       do_posix_clock_monotonic_gettime(&uptime);
16844 +       set_normalized_timespec(&uptime,
16845 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
16846 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
16847 +
16848 +       vc_data.offset = timespec_to_ns(&cvirt->bias_ts);
16849 +       vc_data.uptime = timespec_to_ns(&uptime);
16850 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
16851 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
16852 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
16853 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
16854 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
16855 +       vc_data.load[0] = cvirt->load[0];
16856 +       vc_data.load[1] = cvirt->load[1];
16857 +       vc_data.load[2] = cvirt->load[2];
16858 +
16859 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16860 +               return -EFAULT;
16861 +       return 0;
16862 +}
16863 +
16864 +
16865 +#ifdef CONFIG_VSERVER_VTIME
16866 +
16867 +/* virtualized time base */
16868 +
16869 +void vx_adjust_timespec(struct timespec *ts)
16870 +{
16871 +       struct vx_info *vxi;
16872 +
16873 +       if (!vx_flags(VXF_VIRT_TIME, 0))
16874 +               return;
16875 +
16876 +       vxi = current_vx_info();
16877 +       ts->tv_sec += vxi->cvirt.bias_ts.tv_sec;
16878 +       ts->tv_nsec += vxi->cvirt.bias_ts.tv_nsec;
16879 +
16880 +       if (ts->tv_nsec >= NSEC_PER_SEC) {
16881 +               ts->tv_sec++;
16882 +               ts->tv_nsec -= NSEC_PER_SEC;
16883 +       } else if (ts->tv_nsec < 0) {
16884 +               ts->tv_sec--;
16885 +               ts->tv_nsec += NSEC_PER_SEC;
16886 +       }
16887 +}
16888 +
16889 +int vx_settimeofday(const struct timespec *ts)
16890 +{
16891 +       struct timespec ats, delta;
16892 +       struct vx_info *vxi;
16893 +
16894 +       if (!vx_flags(VXF_VIRT_TIME, 0))
16895 +               return do_settimeofday(ts);
16896 +
16897 +       getnstimeofday(&ats);
16898 +       delta = timespec_sub(*ts, ats);
16899 +
16900 +       vxi = current_vx_info();
16901 +       vxi->cvirt.bias_ts = timespec_add(vxi->cvirt.bias_ts, delta);
16902 +       return 0;
16903 +}
16904 +
16905 +#endif
16906 +
16907 diff -NurpP --minimal linux-3.10.9/kernel/vserver/cvirt_init.h linux-3.10.9-vs2.3.6.6/kernel/vserver/cvirt_init.h
16908 --- linux-3.10.9/kernel/vserver/cvirt_init.h    1970-01-01 00:00:00.000000000 +0000
16909 +++ linux-3.10.9-vs2.3.6.6/kernel/vserver/cvirt_init.h  2013-08-22 20:30:00.000000000 +0000
16910 @@ -0,0 +1,70 @@
16911 +
16912 +
16913 +extern uint64_t vx_idle_jiffies(void);
16914 +
16915 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
16916 +{
16917 +       uint64_t idle_jiffies = vx_idle_jiffies();
16918 +       uint64_t nsuptime;
16919 +
16920 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
16921 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
16922 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
16923 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
16924 +       cvirt->bias_ts.tv_sec = 0;
16925 +       cvirt->bias_ts.tv_nsec = 0;
16926 +
16927 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
16928 +       atomic_set(&cvirt->nr_threads, 0);
16929 +       atomic_set(&cvirt->nr_running, 0);
16930 +       atomic_set(&cvirt->nr_uninterruptible, 0);
16931 +       atomic_set(&cvirt->nr_onhold, 0);
16932 +
16933 +       spin_lock_init(&cvirt->load_lock);
16934 +       cvirt->load_last = jiffies;
16935 +       atomic_set(&cvirt->load_updates, 0);
16936 +       cvirt->load[0] = 0;
16937 +       cvirt->load[1] = 0;
16938 +       cvirt->load[2] = 0;
16939 +       atomic_set(&cvirt->total_forks, 0);
16940 +
16941 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
16942 +       init_waitqueue_head(&cvirt->syslog.log_wait);
16943 +       cvirt->syslog.log_start = 0;
16944 +       cvirt->syslog.log_end = 0;
16945 +       cvirt->syslog.con_start = 0;
16946 +       cvirt->syslog.logged_chars = 0;
16947 +}
16948 +
16949 +static inline
16950 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
16951 +{
16952 +       // cvirt_pc->cpustat = { 0 };
16953 +}
16954 +
16955 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
16956 +{
16957 +#ifdef CONFIG_VSERVER_WARN
16958 +       int value;
16959 +#endif
16960 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
16961 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
16962 +               cvirt, value);
16963 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
16964 +               "!!! cvirt: %p[nr_running] = %d on exit.",
16965 +               cvirt, value);
16966 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
16967 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
16968 +               cvirt, value);
16969 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
16970 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
16971 +               cvirt, value);
16972 +       return;
16973 +}
16974 +
16975 +static inline
16976 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
16977 +{
16978 +       return;
16979 +}
16980 +
16981 diff -NurpP --minimal linux-3.10.9/kernel/vserver/cvirt_proc.h linux-3.10.9-vs2.3.6.6/kernel/vserver/cvirt_proc.h
16982 --- linux-3.10.9/kernel/vserver/cvirt_proc.h    1970-01-01 00:00:00.000000000 +0000
16983 +++ linux-3.10.9-vs2.3.6.6/kernel/vserver/cvirt_proc.h  2013-08-22 20:30:00.000000000 +0000
16984 @@ -0,0 +1,123 @@
16985 +#ifndef _VX_CVIRT_PROC_H
16986 +#define _VX_CVIRT_PROC_H
16987 +
16988 +#include <linux/nsproxy.h>
16989 +#include <linux/mnt_namespace.h>
16990 +#include <linux/ipc_namespace.h>
16991 +#include <linux/utsname.h>
16992 +#include <linux/ipc.h>
16993 +
16994 +extern int vx_info_mnt_namespace(struct mnt_namespace *, char *);
16995 +
16996 +static inline
16997 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
16998 +{
16999 +       struct mnt_namespace *ns;
17000 +       struct uts_namespace *uts;
17001 +       struct ipc_namespace *ipc;
17002 +       int length = 0;
17003 +
17004 +       if (!nsproxy)
17005 +               goto out;
17006 +
17007 +       length += sprintf(buffer + length,
17008 +               "NSProxy:\t%p [%p,%p,%p]\n",
17009 +               nsproxy, nsproxy->mnt_ns,
17010 +               nsproxy->uts_ns, nsproxy->ipc_ns);
17011 +
17012 +       ns = nsproxy->mnt_ns;
17013 +       if (!ns)
17014 +               goto skip_ns;
17015 +
17016 +       length += vx_info_mnt_namespace(ns, buffer + length);
17017 +
17018 +skip_ns:
17019 +
17020 +       uts = nsproxy->uts_ns;
17021 +       if (!uts)
17022 +               goto skip_uts;
17023 +
17024 +       length += sprintf(buffer + length,
17025 +               "SysName:\t%.*s\n"
17026 +               "NodeName:\t%.*s\n"
17027 +               "Release:\t%.*s\n"
17028 +               "Version:\t%.*s\n"
17029 +               "Machine:\t%.*s\n"
17030 +               "DomainName:\t%.*s\n",
17031 +               __NEW_UTS_LEN, uts->name.sysname,
17032 +               __NEW_UTS_LEN, uts->name.nodename,
17033 +               __NEW_UTS_LEN, uts->name.release,
17034 +               __NEW_UTS_LEN, uts->name.version,
17035 +               __NEW_UTS_LEN, uts->name.machine,
17036 +               __NEW_UTS_LEN, uts->name.domainname);
17037 +skip_uts:
17038 +
17039 +       ipc = nsproxy->ipc_ns;
17040 +       if (!ipc)
17041 +               goto skip_ipc;
17042 +
17043 +       length += sprintf(buffer + length,
17044 +               "SEMS:\t\t%d %d %d %d  %d\n"
17045 +               "MSG:\t\t%d %d %d\n"
17046 +               "SHM:\t\t%lu %lu  %d %ld\n",
17047 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
17048 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
17049 +               ipc->used_sems,
17050 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
17051 +               (unsigned long)ipc->shm_ctlmax,
17052 +               (unsigned long)ipc->shm_ctlall,
17053 +               ipc->shm_ctlmni, ipc->shm_tot);
17054 +skip_ipc:
17055 +out:
17056 +       return length;
17057 +}
17058 +
17059 +
17060 +#include <linux/sched.h>
17061 +
17062 +#define LOAD_INT(x) ((x) >> FSHIFT)
17063 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
17064 +
17065 +static inline
17066 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
17067 +{
17068 +       int length = 0;
17069 +       int a, b, c;
17070 +
17071 +       length += sprintf(buffer + length,
17072 +               "BiasUptime:\t%lu.%02lu\n",
17073 +               (unsigned long)cvirt->bias_uptime.tv_sec,
17074 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
17075 +
17076 +       a = cvirt->load[0] + (FIXED_1 / 200);
17077 +       b = cvirt->load[1] + (FIXED_1 / 200);
17078 +       c = cvirt->load[2] + (FIXED_1 / 200);
17079 +       length += sprintf(buffer + length,
17080 +               "nr_threads:\t%d\n"
17081 +               "nr_running:\t%d\n"
17082 +               "nr_unintr:\t%d\n"
17083 +               "nr_onhold:\t%d\n"
17084 +               "load_updates:\t%d\n"
17085 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
17086 +               "total_forks:\t%d\n",
17087 +               atomic_read(&cvirt->nr_threads),
17088 +               atomic_read(&cvirt->nr_running),
17089 +               atomic_read(&cvirt->nr_uninterruptible),
17090 +               atomic_read(&cvirt->nr_onhold),
17091 +               atomic_read(&cvirt->load_updates),
17092 +               LOAD_INT(a), LOAD_FRAC(a),
17093 +               LOAD_INT(b), LOAD_FRAC(b),
17094 +               LOAD_INT(c), LOAD_FRAC(c),
17095 +               atomic_read(&cvirt->total_forks));
17096 +       return length;
17097 +}
17098 +
17099 +static inline
17100 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
17101 +       char *buffer, int cpu)
17102 +{
17103 +       int length = 0;
17104 +       return length;
17105 +}
17106 +
17107 +#endif /* _VX_CVIRT_PROC_H */
17108 diff -NurpP --minimal linux-3.10.9/kernel/vserver/debug.c linux-3.10.9-vs2.3.6.6/kernel/vserver/debug.c
17109 --- linux-3.10.9/kernel/vserver/debug.c 1970-01-01 00:00:00.000000000 +0000
17110 +++ linux-3.10.9-vs2.3.6.6/kernel/vserver/debug.c       2013-08-22 20:30:00.000000000 +0000
17111 @@ -0,0 +1,32 @@
17112 +/*
17113 + *  kernel/vserver/debug.c
17114 + *
17115 + *  Copyright (C) 2005-2007 Herbert Pötzl
17116 + *
17117 + *  V0.01  vx_info dump support
17118 + *
17119 + */
17120 +
17121 +#include <linux/module.h>
17122 +
17123 +#include <linux/vserver/context.h>
17124 +
17125 +
17126 +void   dump_vx_info(struct vx_info *vxi, int level)
17127 +{
17128 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
17129 +               atomic_read(&vxi->vx_usecnt),
17130 +               atomic_read(&vxi->vx_tasks),
17131 +               vxi->vx_state);
17132 +       if (level > 0) {
17133 +               __dump_vx_limit(&vxi->limit);
17134 +               __dump_vx_sched(&vxi->sched);
17135 +               __dump_vx_cvirt(&vxi->cvirt);
17136 +               __dump_vx_cacct(&vxi->cacct);
17137 +       }
17138 +       printk("---\n");
17139 +}
17140 +
17141 +
17142 +EXPORT_SYMBOL_GPL(dump_vx_info);
17143 +
17144 diff -NurpP --minimal linux-3.10.9/kernel/vserver/device.c linux-3.10.9-vs2.3.6.6/kernel/vserver/device.c
17145 --- linux-3.10.9/kernel/vserver/device.c        1970-01-01 00:00:00.000000000 +0000
17146 +++ linux-3.10.9-vs2.3.6.6/kernel/vserver/device.c      2013-08-22 20:30:00.000000000 +0000
17147 @@ -0,0 +1,443 @@
17148 +/*
17149 + *  linux/kernel/vserver/device.c
17150 + *
17151 + *  Linux-VServer: Device Support
17152 + *
17153 + *  Copyright (C) 2006  Herbert Pötzl
17154 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
17155 + *
17156 + *  V0.01  device mapping basics
17157 + *  V0.02  added defaults
17158 + *
17159 + */
17160 +
17161 +#include <linux/slab.h>
17162 +#include <linux/rcupdate.h>
17163 +#include <linux/fs.h>
17164 +#include <linux/namei.h>
17165 +#include <linux/hash.h>
17166 +
17167 +#include <asm/errno.h>
17168 +#include <asm/uaccess.h>
17169 +#include <linux/vserver/base.h>
17170 +#include <linux/vserver/debug.h>
17171 +#include <linux/vserver/context.h>
17172 +#include <linux/vserver/device.h>
17173 +#include <linux/vserver/device_cmd.h>
17174 +
17175 +
17176 +#define DMAP_HASH_BITS 4
17177 +
17178 +
17179 +struct vs_mapping {
17180 +       union {
17181 +               struct hlist_node hlist;
17182 +               struct list_head list;
17183 +       } u;
17184 +#define dm_hlist       u.hlist
17185 +#define dm_list                u.list
17186 +       vxid_t xid;
17187 +       dev_t device;
17188 +       struct vx_dmap_target target;
17189 +};
17190 +
17191 +
17192 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
17193 +
17194 +static DEFINE_SPINLOCK(dmap_main_hash_lock);
17195 +
17196 +static struct vx_dmap_target dmap_defaults[2] = {
17197 +       { .flags = DATTR_OPEN },
17198 +       { .flags = DATTR_OPEN },
17199 +};
17200 +
17201 +
17202 +struct kmem_cache *dmap_cachep __read_mostly;
17203 +
17204 +int __init dmap_cache_init(void)
17205 +{
17206 +       dmap_cachep = kmem_cache_create("dmap_cache",
17207 +               sizeof(struct vs_mapping), 0,
17208 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
17209 +       return 0;
17210 +}
17211 +
17212 +__initcall(dmap_cache_init);
17213 +
17214 +
17215 +static inline unsigned int __hashval(dev_t dev, int bits)
17216 +{
17217 +       return hash_long((unsigned long)dev, bits);
17218 +}
17219 +
17220 +
17221 +/*     __hash_mapping()
17222 + *     add the mapping to the hash table
17223 + */
17224 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
17225 +{
17226 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17227 +       struct hlist_head *head, *hash = dmap_main_hash;
17228 +       int device = vdm->device;
17229 +
17230 +       spin_lock(hash_lock);
17231 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
17232 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
17233 +
17234 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
17235 +       hlist_add_head(&vdm->dm_hlist, head);
17236 +       spin_unlock(hash_lock);
17237 +}
17238 +
17239 +
17240 +static inline int __mode_to_default(umode_t mode)
17241 +{
17242 +       switch (mode) {
17243 +       case S_IFBLK:
17244 +               return 0;
17245 +       case S_IFCHR:
17246 +               return 1;
17247 +       default:
17248 +               BUG();
17249 +       }
17250 +}
17251 +
17252 +
17253 +/*     __set_default()
17254 + *     set a default
17255 + */
17256 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
17257 +       struct vx_dmap_target *vdmt)
17258 +{
17259 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17260 +       spin_lock(hash_lock);
17261 +
17262 +       if (vxi)
17263 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
17264 +       else
17265 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
17266 +
17267 +
17268 +       spin_unlock(hash_lock);
17269 +
17270 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
17271 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
17272 +}
17273 +
17274 +
17275 +/*     __remove_default()
17276 + *     remove a default
17277 + */
17278 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
17279 +{
17280 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17281 +       spin_lock(hash_lock);
17282 +
17283 +       if (vxi)
17284 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
17285 +       else    /* remove == reset */
17286 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
17287 +
17288 +       spin_unlock(hash_lock);
17289 +       return 0;
17290 +}
17291 +
17292 +
17293 +/*     __find_mapping()
17294 + *     find a mapping in the hash table
17295 + *
17296 + *     caller must hold hash_lock
17297 + */
17298 +static inline int __find_mapping(vxid_t xid, dev_t device, umode_t mode,
17299 +       struct vs_mapping **local, struct vs_mapping **global)
17300 +{
17301 +       struct hlist_head *hash = dmap_main_hash;
17302 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
17303 +       struct hlist_node *pos;
17304 +       struct vs_mapping *vdm;
17305 +
17306 +       *local = NULL;
17307 +       if (global)
17308 +               *global = NULL;
17309 +
17310 +       hlist_for_each(pos, head) {
17311 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
17312 +
17313 +               if ((vdm->device == device) &&
17314 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
17315 +                       if (vdm->xid == xid) {
17316 +                               *local = vdm;
17317 +                               return 1;
17318 +                       } else if (global && vdm->xid == 0)
17319 +                               *global = vdm;
17320 +               }
17321 +       }
17322 +
17323 +       if (global && *global)
17324 +               return 0;
17325 +       else
17326 +               return -ENOENT;
17327 +}
17328 +
17329 +
17330 +/*     __lookup_mapping()
17331 + *     find a mapping and store the result in target and flags
17332 + */
17333 +static inline int __lookup_mapping(struct vx_info *vxi,
17334 +       dev_t device, dev_t *target, int *flags, umode_t mode)
17335 +{
17336 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17337 +       struct vs_mapping *vdm, *global;
17338 +       struct vx_dmap_target *vdmt;
17339 +       int ret = 0;
17340 +       vxid_t xid = vxi->vx_id;
17341 +       int index;
17342 +
17343 +       spin_lock(hash_lock);
17344 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
17345 +               ret = 1;
17346 +               vdmt = &vdm->target;
17347 +               goto found;
17348 +       }
17349 +
17350 +       index = __mode_to_default(mode);
17351 +       if (vxi && vxi->dmap.targets[index].flags) {
17352 +               ret = 2;
17353 +               vdmt = &vxi->dmap.targets[index];
17354 +       } else if (global) {
17355 +               ret = 3;
17356 +               vdmt = &global->target;
17357 +               goto found;
17358 +       } else {
17359 +               ret = 4;
17360 +               vdmt = &dmap_defaults[index];
17361 +       }
17362 +
17363 +found:
17364 +       if (target && (vdmt->flags & DATTR_REMAP))
17365 +               *target = vdmt->target;
17366 +       else if (target)
17367 +               *target = device;
17368 +       if (flags)
17369 +               *flags = vdmt->flags;
17370 +
17371 +       spin_unlock(hash_lock);
17372 +
17373 +       return ret;
17374 +}
17375 +
17376 +
17377 +/*     __remove_mapping()
17378 + *     remove a mapping from the hash table
17379 + */
17380 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
17381 +       umode_t mode)
17382 +{
17383 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17384 +       struct vs_mapping *vdm = NULL;
17385 +       int ret = 0;
17386 +
17387 +       spin_lock(hash_lock);
17388 +
17389 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
17390 +               NULL);
17391 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
17392 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
17393 +       if (ret < 0)
17394 +               goto out;
17395 +       hlist_del(&vdm->dm_hlist);
17396 +
17397 +out:
17398 +       spin_unlock(hash_lock);
17399 +       if (vdm)
17400 +               kmem_cache_free(dmap_cachep, vdm);
17401 +       return ret;
17402 +}
17403 +
17404 +
17405 +
17406 +int vs_map_device(struct vx_info *vxi,
17407 +       dev_t device, dev_t *target, umode_t mode)
17408 +{
17409 +       int ret, flags = DATTR_MASK;
17410 +
17411 +       if (!vxi) {
17412 +               if (target)
17413 +                       *target = device;
17414 +               goto out;
17415 +       }
17416 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
17417 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
17418 +               device, target ? *target : 0, flags, mode, ret);
17419 +out:
17420 +       return (flags & DATTR_MASK);
17421 +}
17422 +
17423 +
17424 +
17425 +static int do_set_mapping(struct vx_info *vxi,
17426 +       dev_t device, dev_t target, int flags, umode_t mode)
17427 +{
17428 +       if (device) {
17429 +               struct vs_mapping *new;
17430 +
17431 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
17432 +               if (!new)
17433 +                       return -ENOMEM;
17434 +
17435 +               INIT_HLIST_NODE(&new->dm_hlist);
17436 +               new->device = device;
17437 +               new->target.target = target;
17438 +               new->target.flags = flags | mode;
17439 +               new->xid = (vxi ? vxi->vx_id : 0);
17440 +
17441 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
17442 +               __hash_mapping(vxi, new);
17443 +       } else {
17444 +               struct vx_dmap_target new = {
17445 +                       .target = target,
17446 +                       .flags = flags | mode,
17447 +               };
17448 +               __set_default(vxi, mode, &new);
17449 +       }
17450 +       return 0;
17451 +}
17452 +
17453 +
17454 +static int do_unset_mapping(struct vx_info *vxi,
17455 +       dev_t device, dev_t target, int flags, umode_t mode)
17456 +{
17457 +       int ret = -EINVAL;
17458 +
17459 +       if (device) {
17460 +               ret = __remove_mapping(vxi, device, mode);
17461 +               if (ret < 0)
17462 +                       goto out;
17463 +       } else {
17464 +               ret = __remove_default(vxi, mode);
17465 +               if (ret < 0)
17466 +                       goto out;
17467 +       }
17468 +
17469 +out:
17470 +       return ret;
17471 +}
17472 +
17473 +
17474 +static inline int __user_device(const char __user *name, dev_t *dev,
17475 +       umode_t *mode)
17476 +{
17477 +       struct nameidata nd;
17478 +       int ret;
17479 +
17480 +       if (!name) {
17481 +               *dev = 0;
17482 +               return 0;
17483 +       }
17484 +       ret = user_lpath(name, &nd.path);
17485 +       if (ret)
17486 +               return ret;
17487 +       if (nd.path.dentry->d_inode) {
17488 +               *dev = nd.path.dentry->d_inode->i_rdev;
17489 +               *mode = nd.path.dentry->d_inode->i_mode;
17490 +       }
17491 +       path_put(&nd.path);
17492 +       return 0;
17493 +}
17494 +
17495 +static inline int __mapping_mode(dev_t device, dev_t target,
17496 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
17497 +{
17498 +       if (device)
17499 +               *mode = device_mode & S_IFMT;
17500 +       else if (target)
17501 +               *mode = target_mode & S_IFMT;
17502 +       else
17503 +               return -EINVAL;
17504 +
17505 +       /* if both given, device and target mode have to match */
17506 +       if (device && target &&
17507 +               ((device_mode ^ target_mode) & S_IFMT))
17508 +               return -EINVAL;
17509 +       return 0;
17510 +}
17511 +
17512 +
17513 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
17514 +       const char __user *target_path, int flags, int set)
17515 +{
17516 +       dev_t device = ~0, target = ~0;
17517 +       umode_t device_mode = 0, target_mode = 0, mode;
17518 +       int ret;
17519 +
17520 +       ret = __user_device(device_path, &device, &device_mode);
17521 +       if (ret)
17522 +               return ret;
17523 +       ret = __user_device(target_path, &target, &target_mode);
17524 +       if (ret)
17525 +               return ret;
17526 +
17527 +       ret = __mapping_mode(device, target,
17528 +               device_mode, target_mode, &mode);
17529 +       if (ret)
17530 +               return ret;
17531 +
17532 +       if (set)
17533 +               return do_set_mapping(vxi, device, target,
17534 +                       flags, mode);
17535 +       else
17536 +               return do_unset_mapping(vxi, device, target,
17537 +                       flags, mode);
17538 +}
17539 +
17540 +
17541 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
17542 +{
17543 +       struct vcmd_set_mapping_v0 vc_data;
17544 +
17545 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17546 +               return -EFAULT;
17547 +
17548 +       return do_mapping(vxi, vc_data.device, vc_data.target,
17549 +               vc_data.flags, 1);
17550 +}
17551 +
17552 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
17553 +{
17554 +       struct vcmd_set_mapping_v0 vc_data;
17555 +
17556 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17557 +               return -EFAULT;
17558 +
17559 +       return do_mapping(vxi, vc_data.device, vc_data.target,
17560 +               vc_data.flags, 0);
17561 +}
17562 +
17563 +
17564 +#ifdef CONFIG_COMPAT
17565 +
17566 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
17567 +{
17568 +       struct vcmd_set_mapping_v0_x32 vc_data;
17569 +
17570 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17571 +               return -EFAULT;
17572 +
17573 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
17574 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
17575 +}
17576 +
17577 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
17578 +{
17579 +       struct vcmd_set_mapping_v0_x32 vc_data;
17580 +
17581 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17582 +               return -EFAULT;
17583 +
17584 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
17585 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
17586 +}
17587 +
17588 +#endif /* CONFIG_COMPAT */
17589 +
17590 +
17591 diff -NurpP --minimal linux-3.10.9/kernel/vserver/dlimit.c linux-3.10.9-vs2.3.6.6/kernel/vserver/dlimit.c
17592 --- linux-3.10.9/kernel/vserver/dlimit.c        1970-01-01 00:00:00.000000000 +0000
17593 +++ linux-3.10.9-vs2.3.6.6/kernel/vserver/dlimit.c      2013-08-22 20:30:00.000000000 +0000
17594 @@ -0,0 +1,528 @@
17595 +/*
17596 + *  linux/kernel/vserver/dlimit.c
17597 + *
17598 + *  Virtual Server: Context Disk Limits
17599 + *
17600 + *  Copyright (C) 2004-2009  Herbert Pötzl
17601 + *
17602 + *  V0.01  initial version
17603 + *  V0.02  compat32 splitup
17604 + *  V0.03  extended interface
17605 + *
17606 + */
17607 +
17608 +#include <linux/statfs.h>
17609 +#include <linux/sched.h>
17610 +#include <linux/namei.h>
17611 +#include <linux/vs_tag.h>
17612 +#include <linux/vs_dlimit.h>
17613 +#include <linux/vserver/dlimit_cmd.h>
17614 +#include <linux/slab.h>
17615 +// #include <linux/gfp.h>
17616 +
17617 +#include <asm/uaccess.h>
17618 +
17619 +/*     __alloc_dl_info()
17620 +
17621 +       * allocate an initialized dl_info struct
17622 +       * doesn't make it visible (hash)                        */
17623 +
17624 +static struct dl_info *__alloc_dl_info(struct super_block *sb, vtag_t tag)
17625 +{
17626 +       struct dl_info *new = NULL;
17627 +
17628 +       vxdprintk(VXD_CBIT(dlim, 5),
17629 +               "alloc_dl_info(%p,%d)*", sb, tag);
17630 +
17631 +       /* would this benefit from a slab cache? */
17632 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
17633 +       if (!new)
17634 +               return 0;
17635 +
17636 +       memset(new, 0, sizeof(struct dl_info));
17637 +       new->dl_tag = tag;
17638 +       new->dl_sb = sb;
17639 +       // INIT_RCU_HEAD(&new->dl_rcu);
17640 +       INIT_HLIST_NODE(&new->dl_hlist);
17641 +       spin_lock_init(&new->dl_lock);
17642 +       atomic_set(&new->dl_refcnt, 0);
17643 +       atomic_set(&new->dl_usecnt, 0);
17644 +
17645 +       /* rest of init goes here */
17646 +
17647 +       vxdprintk(VXD_CBIT(dlim, 4),
17648 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
17649 +       return new;
17650 +}
17651 +
17652 +/*     __dealloc_dl_info()
17653 +
17654 +       * final disposal of dl_info                             */
17655 +
17656 +static void __dealloc_dl_info(struct dl_info *dli)
17657 +{
17658 +       vxdprintk(VXD_CBIT(dlim, 4),
17659 +               "dealloc_dl_info(%p)", dli);
17660 +
17661 +       dli->dl_hlist.next = LIST_POISON1;
17662 +       dli->dl_tag = -1;
17663 +       dli->dl_sb = 0;
17664 +
17665 +       BUG_ON(atomic_read(&dli->dl_usecnt));
17666 +       BUG_ON(atomic_read(&dli->dl_refcnt));
17667 +
17668 +       kfree(dli);
17669 +}
17670 +
17671 +
17672 +/*     hash table for dl_info hash */
17673 +
17674 +#define DL_HASH_SIZE   13
17675 +
17676 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
17677 +
17678 +static DEFINE_SPINLOCK(dl_info_hash_lock);
17679 +
17680 +
17681 +static inline unsigned int __hashval(struct super_block *sb, vtag_t tag)
17682 +{
17683 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
17684 +}
17685 +
17686 +
17687 +
17688 +/*     __hash_dl_info()
17689 +
17690 +       * add the dli to the global hash table
17691 +       * requires the hash_lock to be held                     */
17692 +
17693 +static inline void __hash_dl_info(struct dl_info *dli)
17694 +{
17695 +       struct hlist_head *head;
17696 +
17697 +       vxdprintk(VXD_CBIT(dlim, 6),
17698 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
17699 +       get_dl_info(dli);
17700 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
17701 +       hlist_add_head_rcu(&dli->dl_hlist, head);
17702 +}
17703 +
17704 +/*     __unhash_dl_info()
17705 +
17706 +       * remove the dli from the global hash table
17707 +       * requires the hash_lock to be held                     */
17708 +
17709 +static inline void __unhash_dl_info(struct dl_info *dli)
17710 +{
17711 +       vxdprintk(VXD_CBIT(dlim, 6),
17712 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
17713 +       hlist_del_rcu(&dli->dl_hlist);
17714 +       put_dl_info(dli);
17715 +}
17716 +
17717 +
17718 +/*     __lookup_dl_info()
17719 +
17720 +       * requires the rcu_read_lock()
17721 +       * doesn't increment the dl_refcnt                       */
17722 +
17723 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, vtag_t tag)
17724 +{
17725 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
17726 +       struct dl_info *dli;
17727 +
17728 +       hlist_for_each_entry_rcu(dli, head, dl_hlist) {
17729 +               if (dli->dl_tag == tag && dli->dl_sb == sb)
17730 +                       return dli;
17731 +       }
17732 +       return NULL;
17733 +}
17734 +
17735 +
17736 +struct dl_info *locate_dl_info(struct super_block *sb, vtag_t tag)
17737 +{
17738 +       struct dl_info *dli;
17739 +
17740 +       rcu_read_lock();
17741 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
17742 +       vxdprintk(VXD_CBIT(dlim, 7),
17743 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
17744 +       rcu_read_unlock();
17745 +       return dli;
17746 +}
17747 +
17748 +void rcu_free_dl_info(struct rcu_head *head)
17749 +{
17750 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
17751 +       int usecnt, refcnt;
17752 +
17753 +       BUG_ON(!dli || !head);
17754 +
17755 +       usecnt = atomic_read(&dli->dl_usecnt);
17756 +       BUG_ON(usecnt < 0);
17757 +
17758 +       refcnt = atomic_read(&dli->dl_refcnt);
17759 +       BUG_ON(refcnt < 0);
17760 +
17761 +       vxdprintk(VXD_CBIT(dlim, 3),
17762 +               "rcu_free_dl_info(%p)", dli);
17763 +       if (!usecnt)
17764 +               __dealloc_dl_info(dli);
17765 +       else
17766 +               printk("!!! rcu didn't free\n");
17767 +}
17768 +
17769 +
17770 +
17771 +
17772 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
17773 +       uint32_t flags, int add)
17774 +{
17775 +       struct path path;
17776 +       int ret;
17777 +
17778 +       ret = user_lpath(name, &path);
17779 +       if (!ret) {
17780 +               struct super_block *sb;
17781 +               struct dl_info *dli;
17782 +
17783 +               ret = -EINVAL;
17784 +               if (!path.dentry->d_inode)
17785 +                       goto out_release;
17786 +               if (!(sb = path.dentry->d_inode->i_sb))
17787 +                       goto out_release;
17788 +
17789 +               if (add) {
17790 +                       dli = __alloc_dl_info(sb, id);
17791 +                       spin_lock(&dl_info_hash_lock);
17792 +
17793 +                       ret = -EEXIST;
17794 +                       if (__lookup_dl_info(sb, id))
17795 +                               goto out_unlock;
17796 +                       __hash_dl_info(dli);
17797 +                       dli = NULL;
17798 +               } else {
17799 +                       spin_lock(&dl_info_hash_lock);
17800 +                       dli = __lookup_dl_info(sb, id);
17801 +
17802 +                       ret = -ESRCH;
17803 +                       if (!dli)
17804 +                               goto out_unlock;
17805 +                       __unhash_dl_info(dli);
17806 +               }
17807 +               ret = 0;
17808 +       out_unlock:
17809 +               spin_unlock(&dl_info_hash_lock);
17810 +               if (add && dli)
17811 +                       __dealloc_dl_info(dli);
17812 +       out_release:
17813 +               path_put(&path);
17814 +       }
17815 +       return ret;
17816 +}
17817 +
17818 +int vc_add_dlimit(uint32_t id, void __user *data)
17819 +{
17820 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
17821 +
17822 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17823 +               return -EFAULT;
17824 +
17825 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
17826 +}
17827 +
17828 +int vc_rem_dlimit(uint32_t id, void __user *data)
17829 +{
17830 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
17831 +
17832 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17833 +               return -EFAULT;
17834 +
17835 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
17836 +}
17837 +
17838 +#ifdef CONFIG_COMPAT
17839 +
17840 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
17841 +{
17842 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
17843 +
17844 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17845 +               return -EFAULT;
17846 +
17847 +       return do_addrem_dlimit(id,
17848 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
17849 +}
17850 +
17851 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
17852 +{
17853 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
17854 +
17855 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17856 +               return -EFAULT;
17857 +
17858 +       return do_addrem_dlimit(id,
17859 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
17860 +}
17861 +
17862 +#endif /* CONFIG_COMPAT */
17863 +
17864 +
17865 +static inline
17866 +int do_set_dlimit(uint32_t id, const char __user *name,
17867 +       uint32_t space_used, uint32_t space_total,
17868 +       uint32_t inodes_used, uint32_t inodes_total,
17869 +       uint32_t reserved, uint32_t flags)
17870 +{
17871 +       struct path path;
17872 +       int ret;
17873 +
17874 +       ret = user_lpath(name, &path);
17875 +       if (!ret) {
17876 +               struct super_block *sb;
17877 +               struct dl_info *dli;
17878 +
17879 +               ret = -EINVAL;
17880 +               if (!path.dentry->d_inode)
17881 +                       goto out_release;
17882 +               if (!(sb = path.dentry->d_inode->i_sb))
17883 +                       goto out_release;
17884 +
17885 +               /* sanity checks */
17886 +               if ((reserved != CDLIM_KEEP &&
17887 +                       reserved > 100) ||
17888 +                       (inodes_used != CDLIM_KEEP &&
17889 +                       inodes_used > inodes_total) ||
17890 +                       (space_used != CDLIM_KEEP &&
17891 +                       space_used > space_total))
17892 +                       goto out_release;
17893 +
17894 +               ret = -ESRCH;
17895 +               dli = locate_dl_info(sb, id);
17896 +               if (!dli)
17897 +                       goto out_release;
17898 +
17899 +               spin_lock(&dli->dl_lock);
17900 +
17901 +               if (inodes_used != CDLIM_KEEP)
17902 +                       dli->dl_inodes_used = inodes_used;
17903 +               if (inodes_total != CDLIM_KEEP)
17904 +                       dli->dl_inodes_total = inodes_total;
17905 +               if (space_used != CDLIM_KEEP)
17906 +                       dli->dl_space_used = dlimit_space_32to64(
17907 +                               space_used, flags, DLIMS_USED);
17908 +
17909 +               if (space_total == CDLIM_INFINITY)
17910 +                       dli->dl_space_total = DLIM_INFINITY;
17911 +               else if (space_total != CDLIM_KEEP)
17912 +                       dli->dl_space_total = dlimit_space_32to64(
17913 +                               space_total, flags, DLIMS_TOTAL);
17914 +
17915 +               if (reserved != CDLIM_KEEP)
17916 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
17917 +
17918 +               spin_unlock(&dli->dl_lock);
17919 +
17920 +               put_dl_info(dli);
17921 +               ret = 0;
17922 +
17923 +       out_release:
17924 +               path_put(&path);
17925 +       }
17926 +       return ret;
17927 +}
17928 +
17929 +int vc_set_dlimit(uint32_t id, void __user *data)
17930 +{
17931 +       struct vcmd_ctx_dlimit_v0 vc_data;
17932 +
17933 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17934 +               return -EFAULT;
17935 +
17936 +       return do_set_dlimit(id, vc_data.name,
17937 +               vc_data.space_used, vc_data.space_total,
17938 +               vc_data.inodes_used, vc_data.inodes_total,
17939 +               vc_data.reserved, vc_data.flags);
17940 +}
17941 +
17942 +#ifdef CONFIG_COMPAT
17943 +
17944 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
17945 +{
17946 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
17947 +
17948 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17949 +               return -EFAULT;
17950 +
17951 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
17952 +               vc_data.space_used, vc_data.space_total,
17953 +               vc_data.inodes_used, vc_data.inodes_total,
17954 +               vc_data.reserved, vc_data.flags);
17955 +}
17956 +
17957 +#endif /* CONFIG_COMPAT */
17958 +
17959 +
17960 +static inline
17961 +int do_get_dlimit(uint32_t id, const char __user *name,
17962 +       uint32_t *space_used, uint32_t *space_total,
17963 +       uint32_t *inodes_used, uint32_t *inodes_total,
17964 +       uint32_t *reserved, uint32_t *flags)
17965 +{
17966 +       struct path path;
17967 +       int ret;
17968 +
17969 +       ret = user_lpath(name, &path);
17970 +       if (!ret) {
17971 +               struct super_block *sb;
17972 +               struct dl_info *dli;
17973 +
17974 +               ret = -EINVAL;
17975 +               if (!path.dentry->d_inode)
17976 +                       goto out_release;
17977 +               if (!(sb = path.dentry->d_inode->i_sb))
17978 +                       goto out_release;
17979 +
17980 +               ret = -ESRCH;
17981 +               dli = locate_dl_info(sb, id);
17982 +               if (!dli)
17983 +                       goto out_release;
17984 +
17985 +               spin_lock(&dli->dl_lock);
17986 +               *inodes_used = dli->dl_inodes_used;
17987 +               *inodes_total = dli->dl_inodes_total;
17988 +
17989 +               *space_used = dlimit_space_64to32(
17990 +                       dli->dl_space_used, flags, DLIMS_USED);
17991 +
17992 +               if (dli->dl_space_total == DLIM_INFINITY)
17993 +                       *space_total = CDLIM_INFINITY;
17994 +               else
17995 +                       *space_total = dlimit_space_64to32(
17996 +                               dli->dl_space_total, flags, DLIMS_TOTAL);
17997 +
17998 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
17999 +               spin_unlock(&dli->dl_lock);
18000 +
18001 +               put_dl_info(dli);
18002 +               ret = -EFAULT;
18003 +
18004 +               ret = 0;
18005 +       out_release:
18006 +               path_put(&path);
18007 +       }
18008 +       return ret;
18009 +}
18010 +
18011 +
18012 +int vc_get_dlimit(uint32_t id, void __user *data)
18013 +{
18014 +       struct vcmd_ctx_dlimit_v0 vc_data;
18015 +       int ret;
18016 +
18017 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18018 +               return -EFAULT;
18019 +
18020 +       ret = do_get_dlimit(id, vc_data.name,
18021 +               &vc_data.space_used, &vc_data.space_total,
18022 +               &vc_data.inodes_used, &vc_data.inodes_total,
18023 +               &vc_data.reserved, &vc_data.flags);
18024 +       if (ret)
18025 +               return ret;
18026 +
18027 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18028 +               return -EFAULT;
18029 +       return 0;
18030 +}
18031 +
18032 +#ifdef CONFIG_COMPAT
18033 +
18034 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
18035 +{
18036 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18037 +       int ret;
18038 +
18039 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18040 +               return -EFAULT;
18041 +
18042 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
18043 +               &vc_data.space_used, &vc_data.space_total,
18044 +               &vc_data.inodes_used, &vc_data.inodes_total,
18045 +               &vc_data.reserved, &vc_data.flags);
18046 +       if (ret)
18047 +               return ret;
18048 +
18049 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18050 +               return -EFAULT;
18051 +       return 0;
18052 +}
18053 +
18054 +#endif /* CONFIG_COMPAT */
18055 +
18056 +
18057 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
18058 +{
18059 +       struct dl_info *dli;
18060 +       __u64 blimit, bfree, bavail;
18061 +       __u32 ifree;
18062 +
18063 +       dli = locate_dl_info(sb, dx_current_tag());
18064 +       if (!dli)
18065 +               return;
18066 +
18067 +       spin_lock(&dli->dl_lock);
18068 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
18069 +               goto no_ilim;
18070 +
18071 +       /* reduce max inodes available to limit */
18072 +       if (buf->f_files > dli->dl_inodes_total)
18073 +               buf->f_files = dli->dl_inodes_total;
18074 +
18075 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
18076 +       /* reduce free inodes to min */
18077 +       if (ifree < buf->f_ffree)
18078 +               buf->f_ffree = ifree;
18079 +
18080 +no_ilim:
18081 +       if (dli->dl_space_total == DLIM_INFINITY)
18082 +               goto no_blim;
18083 +
18084 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
18085 +
18086 +       if (dli->dl_space_total < dli->dl_space_used)
18087 +               bfree = 0;
18088 +       else
18089 +               bfree = (dli->dl_space_total - dli->dl_space_used)
18090 +                       >> sb->s_blocksize_bits;
18091 +
18092 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
18093 +       if (bavail < dli->dl_space_used)
18094 +               bavail = 0;
18095 +       else
18096 +               bavail = (bavail - dli->dl_space_used)
18097 +                       >> sb->s_blocksize_bits;
18098 +
18099 +       /* reduce max space available to limit */
18100 +       if (buf->f_blocks > blimit)
18101 +               buf->f_blocks = blimit;
18102 +
18103 +       /* reduce free space to min */
18104 +       if (bfree < buf->f_bfree)
18105 +               buf->f_bfree = bfree;
18106 +
18107 +       /* reduce avail space to min */
18108 +       if (bavail < buf->f_bavail)
18109 +               buf->f_bavail = bavail;
18110 +
18111 +no_blim:
18112 +       spin_unlock(&dli->dl_lock);
18113 +       put_dl_info(dli);
18114 +
18115 +       return;
18116 +}
18117 +
18118 +#include <linux/module.h>
18119 +
18120 +EXPORT_SYMBOL_GPL(locate_dl_info);
18121 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
18122 +
18123 diff -NurpP --minimal linux-3.10.9/kernel/vserver/helper.c linux-3.10.9-vs2.3.6.6/kernel/vserver/helper.c
18124 --- linux-3.10.9/kernel/vserver/helper.c        1970-01-01 00:00:00.000000000 +0000
18125 +++ linux-3.10.9-vs2.3.6.6/kernel/vserver/helper.c      2013-08-23 00:55:48.000000000 +0000
18126 @@ -0,0 +1,242 @@
18127 +/*
18128 + *  linux/kernel/vserver/helper.c
18129 + *
18130 + *  Virtual Context Support
18131 + *
18132 + *  Copyright (C) 2004-2007  Herbert Pötzl
18133 + *
18134 + *  V0.01  basic helper
18135 + *
18136 + */
18137 +
18138 +#include <linux/kmod.h>
18139 +#include <linux/reboot.h>
18140 +#include <linux/vs_context.h>
18141 +#include <linux/vs_network.h>
18142 +#include <linux/vserver/signal.h>
18143 +
18144 +
18145 +char vshelper_path[255] = "/sbin/vshelper";
18146 +
18147 +static int vshelper_init(struct subprocess_info *info, struct cred *new_cred)
18148 +{
18149 +       current->flags &= ~PF_NO_SETAFFINITY;
18150 +       return 0;
18151 +}
18152 +
18153 +static int vs_call_usermodehelper(char *path, char **argv, char **envp, int wait)
18154 +{
18155 +       struct subprocess_info *info;
18156 +       gfp_t gfp_mask = (wait == UMH_NO_WAIT) ? GFP_ATOMIC : GFP_KERNEL;
18157 +
18158 +       info = call_usermodehelper_setup(path, argv, envp, gfp_mask,
18159 +                                        vshelper_init, NULL, NULL);
18160 +       if (info == NULL)
18161 +               return -ENOMEM;
18162 +
18163 +       return call_usermodehelper_exec(info, wait);
18164 +}
18165 +
18166 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
18167 +{
18168 +       int ret;
18169 +
18170 +       if ((ret = vs_call_usermodehelper(name, argv, envp,
18171 +               sync ? UMH_WAIT_PROC : UMH_WAIT_EXEC))) {
18172 +               printk(KERN_WARNING "%s: (%s %s) returned %s with %d\n",
18173 +                       name, argv[1], argv[2],
18174 +                       sync ? "sync" : "async", ret);
18175 +       }
18176 +       vxdprintk(VXD_CBIT(switch, 4),
18177 +               "%s: (%s %s) returned %s with %d",
18178 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
18179 +       return ret;
18180 +}
18181 +
18182 +/*
18183 + *      vshelper path is set via /proc/sys
18184 + *      invoked by vserver sys_reboot(), with
18185 + *      the following arguments
18186 + *
18187 + *      argv [0] = vshelper_path;
18188 + *      argv [1] = action: "restart", "halt", "poweroff", ...
18189 + *      argv [2] = context identifier
18190 + *
18191 + *      envp [*] = type-specific parameters
18192 + */
18193 +
18194 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
18195 +{
18196 +       char id_buf[8], cmd_buf[16];
18197 +       char uid_buf[16], pid_buf[16];
18198 +       int ret;
18199 +
18200 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18201 +       char *envp[] = {"HOME=/", "TERM=linux",
18202 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
18203 +                       uid_buf, pid_buf, cmd_buf, 0};
18204 +
18205 +       if (vx_info_state(vxi, VXS_HELPER))
18206 +               return -EAGAIN;
18207 +       vxi->vx_state |= VXS_HELPER;
18208 +
18209 +       snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
18210 +
18211 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18212 +       snprintf(uid_buf, sizeof(uid_buf), "VS_UID=%d",
18213 +               from_kuid(&init_user_ns, current_uid()));
18214 +       snprintf(pid_buf, sizeof(pid_buf), "VS_PID=%d", current->pid);
18215 +
18216 +       switch (cmd) {
18217 +       case LINUX_REBOOT_CMD_RESTART:
18218 +               argv[1] = "restart";
18219 +               break;
18220 +
18221 +       case LINUX_REBOOT_CMD_HALT:
18222 +               argv[1] = "halt";
18223 +               break;
18224 +
18225 +       case LINUX_REBOOT_CMD_POWER_OFF:
18226 +               argv[1] = "poweroff";
18227 +               break;
18228 +
18229 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
18230 +               argv[1] = "swsusp";
18231 +               break;
18232 +
18233 +       case LINUX_REBOOT_CMD_OOM:
18234 +               argv[1] = "oom";
18235 +               break;
18236 +
18237 +       default:
18238 +               vxi->vx_state &= ~VXS_HELPER;
18239 +               return 0;
18240 +       }
18241 +
18242 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
18243 +       vxi->vx_state &= ~VXS_HELPER;
18244 +       __wakeup_vx_info(vxi);
18245 +       return (ret) ? -EPERM : 0;
18246 +}
18247 +
18248 +
18249 +long vs_reboot(unsigned int cmd, void __user *arg)
18250 +{
18251 +       struct vx_info *vxi = current_vx_info();
18252 +       long ret = 0;
18253 +
18254 +       vxdprintk(VXD_CBIT(misc, 5),
18255 +               "vs_reboot(%p[#%d],%u)",
18256 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18257 +
18258 +       ret = vs_reboot_helper(vxi, cmd, arg);
18259 +       if (ret)
18260 +               return ret;
18261 +
18262 +       vxi->reboot_cmd = cmd;
18263 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18264 +               switch (cmd) {
18265 +               case LINUX_REBOOT_CMD_RESTART:
18266 +               case LINUX_REBOOT_CMD_HALT:
18267 +               case LINUX_REBOOT_CMD_POWER_OFF:
18268 +                       vx_info_kill(vxi, 0, SIGKILL);
18269 +                       vx_info_kill(vxi, 1, SIGKILL);
18270 +               default:
18271 +                       break;
18272 +               }
18273 +       }
18274 +       return 0;
18275 +}
18276 +
18277 +long vs_oom_action(unsigned int cmd)
18278 +{
18279 +       struct vx_info *vxi = current_vx_info();
18280 +       long ret = 0;
18281 +
18282 +       vxdprintk(VXD_CBIT(misc, 5),
18283 +               "vs_oom_action(%p[#%d],%u)",
18284 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18285 +
18286 +       ret = vs_reboot_helper(vxi, cmd, NULL);
18287 +       if (ret)
18288 +               return ret;
18289 +
18290 +       vxi->reboot_cmd = cmd;
18291 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18292 +               vx_info_kill(vxi, 0, SIGKILL);
18293 +               vx_info_kill(vxi, 1, SIGKILL);
18294 +       }
18295 +       return 0;
18296 +}
18297 +
18298 +/*
18299 + *      argv [0] = vshelper_path;
18300 + *      argv [1] = action: "startup", "shutdown"
18301 + *      argv [2] = context identifier
18302 + *
18303 + *      envp [*] = type-specific parameters
18304 + */
18305 +
18306 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
18307 +{
18308 +       char id_buf[8], cmd_buf[16];
18309 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18310 +       char *envp[] = {"HOME=/", "TERM=linux",
18311 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18312 +
18313 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
18314 +               return 0;
18315 +
18316 +       snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
18317 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18318 +
18319 +       switch (cmd) {
18320 +       case VSC_STARTUP:
18321 +               argv[1] = "startup";
18322 +               break;
18323 +       case VSC_SHUTDOWN:
18324 +               argv[1] = "shutdown";
18325 +               break;
18326 +       default:
18327 +               return 0;
18328 +       }
18329 +
18330 +       return do_vshelper(vshelper_path, argv, envp, 1);
18331 +}
18332 +
18333 +
18334 +/*
18335 + *      argv [0] = vshelper_path;
18336 + *      argv [1] = action: "netup", "netdown"
18337 + *      argv [2] = context identifier
18338 + *
18339 + *      envp [*] = type-specific parameters
18340 + */
18341 +
18342 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
18343 +{
18344 +       char id_buf[8], cmd_buf[16];
18345 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18346 +       char *envp[] = {"HOME=/", "TERM=linux",
18347 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18348 +
18349 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
18350 +               return 0;
18351 +
18352 +       snprintf(id_buf, sizeof(id_buf), "%d", nxi->nx_id);
18353 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18354 +
18355 +       switch (cmd) {
18356 +       case VSC_NETUP:
18357 +               argv[1] = "netup";
18358 +               break;
18359 +       case VSC_NETDOWN:
18360 +               argv[1] = "netdown";
18361 +               break;
18362 +       default:
18363 +               return 0;
18364 +       }
18365 +
18366 +       return do_vshelper(vshelper_path, argv, envp, 1);
18367 +}
18368 +
18369 diff -NurpP --minimal linux-3.10.9/kernel/vserver/history.c linux-3.10.9-vs2.3.6.6/kernel/vserver/history.c
18370 --- linux-3.10.9/kernel/vserver/history.c       1970-01-01 00:00:00.000000000 +0000
18371 +++ linux-3.10.9-vs2.3.6.6/kernel/vserver/history.c     2013-08-22 20:30:00.000000000 +0000
18372 @@ -0,0 +1,258 @@
18373 +/*
18374 + *  kernel/vserver/history.c
18375 + *
18376 + *  Virtual Context History Backtrace
18377 + *
18378 + *  Copyright (C) 2004-2007  Herbert Pötzl
18379 + *
18380 + *  V0.01  basic structure
18381 + *  V0.02  hash/unhash and trace
18382 + *  V0.03  preemption fixes
18383 + *
18384 + */
18385 +
18386 +#include <linux/module.h>
18387 +#include <asm/uaccess.h>
18388 +
18389 +#include <linux/vserver/context.h>
18390 +#include <linux/vserver/debug.h>
18391 +#include <linux/vserver/debug_cmd.h>
18392 +#include <linux/vserver/history.h>
18393 +
18394 +
18395 +#ifdef CONFIG_VSERVER_HISTORY
18396 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
18397 +#else
18398 +#define VXH_SIZE       64
18399 +#endif
18400 +
18401 +struct _vx_history {
18402 +       unsigned int counter;
18403 +
18404 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
18405 +};
18406 +
18407 +
18408 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
18409 +
18410 +unsigned volatile int vxh_active = 1;
18411 +
18412 +static atomic_t sequence = ATOMIC_INIT(0);
18413 +
18414 +
18415 +/*     vxh_advance()
18416 +
18417 +       * requires disabled preemption                          */
18418 +
18419 +struct _vx_hist_entry *vxh_advance(void *loc)
18420 +{
18421 +       unsigned int cpu = smp_processor_id();
18422 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
18423 +       struct _vx_hist_entry *entry;
18424 +       unsigned int index;
18425 +
18426 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
18427 +       entry = &hist->entry[index];
18428 +
18429 +       entry->seq = atomic_inc_return(&sequence);
18430 +       entry->loc = loc;
18431 +       return entry;
18432 +}
18433 +
18434 +EXPORT_SYMBOL_GPL(vxh_advance);
18435 +
18436 +
18437 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
18438 +
18439 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
18440 +
18441 +
18442 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
18443 +
18444 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
18445 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
18446 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
18447 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
18448 +
18449 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
18450 +{
18451 +       switch (e->type) {
18452 +       case VXH_THROW_OOPS:
18453 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
18454 +               break;
18455 +
18456 +       case VXH_GET_VX_INFO:
18457 +       case VXH_PUT_VX_INFO:
18458 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
18459 +                       VXH_LOC_ARGS(e),
18460 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
18461 +                       VXH_VXI_ARGS(e));
18462 +               break;
18463 +
18464 +       case VXH_INIT_VX_INFO:
18465 +       case VXH_SET_VX_INFO:
18466 +       case VXH_CLR_VX_INFO:
18467 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
18468 +                       VXH_LOC_ARGS(e),
18469 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
18470 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
18471 +                       VXH_VXI_ARGS(e), e->sc.data);
18472 +               break;
18473 +
18474 +       case VXH_CLAIM_VX_INFO:
18475 +       case VXH_RELEASE_VX_INFO:
18476 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
18477 +                       VXH_LOC_ARGS(e),
18478 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
18479 +                       VXH_VXI_ARGS(e), e->sc.data);
18480 +               break;
18481 +
18482 +       case VXH_ALLOC_VX_INFO:
18483 +       case VXH_DEALLOC_VX_INFO:
18484 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
18485 +                       VXH_LOC_ARGS(e),
18486 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
18487 +                       VXH_VXI_ARGS(e));
18488 +               break;
18489 +
18490 +       case VXH_HASH_VX_INFO:
18491 +       case VXH_UNHASH_VX_INFO:
18492 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
18493 +                       VXH_LOC_ARGS(e),
18494 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
18495 +                       VXH_VXI_ARGS(e));
18496 +               break;
18497 +
18498 +       case VXH_LOC_VX_INFO:
18499 +       case VXH_LOOKUP_VX_INFO:
18500 +       case VXH_CREATE_VX_INFO:
18501 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
18502 +                       VXH_LOC_ARGS(e),
18503 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
18504 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
18505 +                       e->ll.arg, VXH_VXI_ARGS(e));
18506 +               break;
18507 +       }
18508 +}
18509 +
18510 +static void __vxh_dump_history(void)
18511 +{
18512 +       unsigned int i, cpu;
18513 +
18514 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
18515 +               atomic_read(&sequence), NR_CPUS);
18516 +
18517 +       for (i = 0; i < VXH_SIZE; i++) {
18518 +               for_each_online_cpu(cpu) {
18519 +                       struct _vx_history *hist =
18520 +                               &per_cpu(vx_history_buffer, cpu);
18521 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
18522 +                       struct _vx_hist_entry *entry = &hist->entry[index];
18523 +
18524 +                       vxh_dump_entry(entry, cpu);
18525 +               }
18526 +       }
18527 +}
18528 +
18529 +void   vxh_dump_history(void)
18530 +{
18531 +       vxh_active = 0;
18532 +#ifdef CONFIG_SMP
18533 +       local_irq_enable();
18534 +       smp_send_stop();
18535 +       local_irq_disable();
18536 +#endif
18537 +       __vxh_dump_history();
18538 +}
18539 +
18540 +
18541 +/* vserver syscall commands below here */
18542 +
18543 +
18544 +int vc_dump_history(uint32_t id)
18545 +{
18546 +       vxh_active = 0;
18547 +       __vxh_dump_history();
18548 +       vxh_active = 1;
18549 +
18550 +       return 0;
18551 +}
18552 +
18553 +
18554 +int do_read_history(struct __user _vx_hist_entry *data,
18555 +       int cpu, uint32_t *index, uint32_t *count)
18556 +{
18557 +       int pos, ret = 0;
18558 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
18559 +       int end = hist->counter;
18560 +       int start = end - VXH_SIZE + 2;
18561 +       int idx = *index;
18562 +
18563 +       /* special case: get current pos */
18564 +       if (!*count) {
18565 +               *index = end;
18566 +               return 0;
18567 +       }
18568 +
18569 +       /* have we lost some data? */
18570 +       if (idx < start)
18571 +               idx = start;
18572 +
18573 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
18574 +               struct _vx_hist_entry *entry =
18575 +                       &hist->entry[idx % VXH_SIZE];
18576 +
18577 +               /* send entry to userspace */
18578 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
18579 +               if (ret)
18580 +                       break;
18581 +       }
18582 +       /* save new index and count */
18583 +       *index = idx;
18584 +       *count = pos;
18585 +       return ret ? ret : (*index < end);
18586 +}
18587 +
18588 +int vc_read_history(uint32_t id, void __user *data)
18589 +{
18590 +       struct vcmd_read_history_v0 vc_data;
18591 +       int ret;
18592 +
18593 +       if (id >= NR_CPUS)
18594 +               return -EINVAL;
18595 +
18596 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18597 +               return -EFAULT;
18598 +
18599 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
18600 +               id, &vc_data.index, &vc_data.count);
18601 +
18602 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18603 +               return -EFAULT;
18604 +       return ret;
18605 +}
18606 +
18607 +#ifdef CONFIG_COMPAT
18608 +
18609 +int vc_read_history_x32(uint32_t id, void __user *data)
18610 +{
18611 +       struct vcmd_read_history_v0_x32 vc_data;
18612 +       int ret;
18613 +
18614 +       if (id >= NR_CPUS)
18615 +               return -EINVAL;
18616 +
18617 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18618 +               return -EFAULT;
18619 +
18620 +       ret = do_read_history((struct __user _vx_hist_entry *)
18621 +               compat_ptr(vc_data.data_ptr),
18622 +               id, &vc_data.index, &vc_data.count);
18623 +
18624 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18625 +               return -EFAULT;
18626 +       return ret;
18627 +}
18628 +
18629 +#endif /* CONFIG_COMPAT */
18630 +
18631 diff -NurpP --minimal linux-3.10.9/kernel/vserver/inet.c linux-3.10.9-vs2.3.6.6/kernel/vserver/inet.c
18632 --- linux-3.10.9/kernel/vserver/inet.c  1970-01-01 00:00:00.000000000 +0000
18633 +++ linux-3.10.9-vs2.3.6.6/kernel/vserver/inet.c        2013-08-22 20:30:00.000000000 +0000
18634 @@ -0,0 +1,236 @@
18635 +
18636 +#include <linux/in.h>
18637 +#include <linux/inetdevice.h>
18638 +#include <linux/export.h>
18639 +#include <linux/vs_inet.h>
18640 +#include <linux/vs_inet6.h>
18641 +#include <linux/vserver/debug.h>
18642 +#include <net/route.h>
18643 +#include <net/addrconf.h>
18644 +
18645 +
18646 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
18647 +{
18648 +       int ret = 0;
18649 +
18650 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
18651 +               ret = 1;
18652 +       else {
18653 +               struct nx_addr_v4 *ptr;
18654 +               unsigned long irqflags;
18655 +
18656 +               spin_lock_irqsave(&nxi1->addr_lock, irqflags);
18657 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
18658 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
18659 +                               ret = 1;
18660 +                               break;
18661 +                       }
18662 +               }
18663 +               spin_unlock_irqrestore(&nxi1->addr_lock, irqflags);
18664 +       }
18665 +
18666 +       vxdprintk(VXD_CBIT(net, 2),
18667 +               "nx_v4_addr_conflict(%p,%p): %d",
18668 +               nxi1, nxi2, ret);
18669 +
18670 +       return ret;
18671 +}
18672 +
18673 +
18674 +#ifdef CONFIG_IPV6
18675 +
18676 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
18677 +{
18678 +       int ret = 0;
18679 +
18680 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
18681 +               ret = 1;
18682 +       else {
18683 +               struct nx_addr_v6 *ptr;
18684 +               unsigned long irqflags;
18685 +
18686 +               spin_lock_irqsave(&nxi1->addr_lock, irqflags);
18687 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
18688 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
18689 +                               ret = 1;
18690 +                               break;
18691 +                       }
18692 +               }
18693 +               spin_unlock_irqrestore(&nxi1->addr_lock, irqflags);
18694 +       }
18695 +
18696 +       vxdprintk(VXD_CBIT(net, 2),
18697 +               "nx_v6_addr_conflict(%p,%p): %d",
18698 +               nxi1, nxi2, ret);
18699 +
18700 +       return ret;
18701 +}
18702 +
18703 +#endif
18704 +
18705 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18706 +{
18707 +       struct in_device *in_dev;
18708 +       struct in_ifaddr **ifap;
18709 +       struct in_ifaddr *ifa;
18710 +       int ret = 0;
18711 +
18712 +       if (!dev)
18713 +               goto out;
18714 +       in_dev = in_dev_get(dev);
18715 +       if (!in_dev)
18716 +               goto out;
18717 +
18718 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
18719 +               ifap = &ifa->ifa_next) {
18720 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
18721 +                       ret = 1;
18722 +                       break;
18723 +               }
18724 +       }
18725 +       in_dev_put(in_dev);
18726 +out:
18727 +       return ret;
18728 +}
18729 +
18730 +
18731 +#ifdef CONFIG_IPV6
18732 +
18733 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18734 +{
18735 +       struct inet6_dev *in_dev;
18736 +       struct inet6_ifaddr *ifa;
18737 +       int ret = 0;
18738 +
18739 +       if (!dev)
18740 +               goto out;
18741 +       in_dev = in6_dev_get(dev);
18742 +       if (!in_dev)
18743 +               goto out;
18744 +
18745 +       // for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
18746 +       list_for_each_entry(ifa, &in_dev->addr_list, if_list) {
18747 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
18748 +                       ret = 1;
18749 +                       break;
18750 +               }
18751 +       }
18752 +       in6_dev_put(in_dev);
18753 +out:
18754 +       return ret;
18755 +}
18756 +
18757 +#endif
18758 +
18759 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18760 +{
18761 +       int ret = 1;
18762 +
18763 +       if (!nxi)
18764 +               goto out;
18765 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
18766 +               goto out;
18767 +#ifdef CONFIG_IPV6
18768 +       ret = 2;
18769 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
18770 +               goto out;
18771 +#endif
18772 +       ret = 0;
18773 +out:
18774 +       vxdprintk(VXD_CBIT(net, 3),
18775 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
18776 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
18777 +       return ret;
18778 +}
18779 +
18780 +struct rtable *ip_v4_find_src(struct net *net, struct nx_info *nxi,
18781 +       struct flowi4 *fl4)
18782 +{
18783 +       struct rtable *rt;
18784 +
18785 +       if (!nxi)
18786 +               return NULL;
18787 +
18788 +       /* FIXME: handle lback only case */
18789 +       if (!NX_IPV4(nxi))
18790 +               return ERR_PTR(-EPERM);
18791 +
18792 +       vxdprintk(VXD_CBIT(net, 4),
18793 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
18794 +               nxi, nxi ? nxi->nx_id : 0,
18795 +               NIPQUAD(fl4->saddr), NIPQUAD(fl4->daddr));
18796 +
18797 +       /* single IP is unconditional */
18798 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
18799 +               (fl4->saddr == INADDR_ANY))
18800 +               fl4->saddr = nxi->v4.ip[0].s_addr;
18801 +
18802 +       if (fl4->saddr == INADDR_ANY) {
18803 +               struct nx_addr_v4 *ptr;
18804 +               __be32 found = 0;
18805 +
18806 +               rt = __ip_route_output_key(net, fl4);
18807 +               if (!IS_ERR(rt)) {
18808 +                       found = fl4->saddr;
18809 +                       ip_rt_put(rt);
18810 +                       vxdprintk(VXD_CBIT(net, 4),
18811 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
18812 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(found));
18813 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
18814 +                               goto found;
18815 +               }
18816 +
18817 +               WARN_ON_ONCE(in_irq());
18818 +               spin_lock_bh(&nxi->addr_lock);
18819 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
18820 +                       __be32 primary = ptr->ip[0].s_addr;
18821 +                       __be32 mask = ptr->mask.s_addr;
18822 +                       __be32 neta = primary & mask;
18823 +
18824 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
18825 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
18826 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
18827 +                               NIPQUAD(mask), NIPQUAD(neta));
18828 +                       if ((found & mask) != neta)
18829 +                               continue;
18830 +
18831 +                       fl4->saddr = primary;
18832 +                       rt = __ip_route_output_key(net, fl4);
18833 +                       vxdprintk(VXD_CBIT(net, 4),
18834 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
18835 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(primary));
18836 +                       if (!IS_ERR(rt)) {
18837 +                               found = fl4->saddr;
18838 +                               ip_rt_put(rt);
18839 +                               if (found == primary)
18840 +                                       goto found_unlock;
18841 +                       }
18842 +               }
18843 +               /* still no source ip? */
18844 +               found = ipv4_is_loopback(fl4->daddr)
18845 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
18846 +       found_unlock:
18847 +               spin_unlock_bh(&nxi->addr_lock);
18848 +       found:
18849 +               /* assign src ip to flow */
18850 +               fl4->saddr = found;
18851 +
18852 +       } else {
18853 +               if (!v4_addr_in_nx_info(nxi, fl4->saddr, NXA_MASK_BIND))
18854 +                       return ERR_PTR(-EPERM);
18855 +       }
18856 +
18857 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
18858 +               if (ipv4_is_loopback(fl4->daddr))
18859 +                       fl4->daddr = nxi->v4_lback.s_addr;
18860 +               if (ipv4_is_loopback(fl4->saddr))
18861 +                       fl4->saddr = nxi->v4_lback.s_addr;
18862 +       } else if (ipv4_is_loopback(fl4->daddr) &&
18863 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
18864 +               return ERR_PTR(-EPERM);
18865 +
18866 +       return NULL;
18867 +}
18868 +
18869 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
18870 +
18871 diff -NurpP --minimal linux-3.10.9/kernel/vserver/init.c linux-3.10.9-vs2.3.6.6/kernel/vserver/init.c
18872 --- linux-3.10.9/kernel/vserver/init.c  1970-01-01 00:00:00.000000000 +0000
18873 +++ linux-3.10.9-vs2.3.6.6/kernel/vserver/init.c        2013-08-22 20:30:00.000000000 +0000
18874 @@ -0,0 +1,45 @@
18875 +/*
18876 + *  linux/kernel/init.c
18877 + *
18878 + *  Virtual Server Init
18879 + *
18880 + *  Copyright (C) 2004-2007  Herbert Pötzl
18881 + *
18882 + *  V0.01  basic structure
18883 + *
18884 + */
18885 +
18886 +#include <linux/init.h>
18887 +
18888 +int    vserver_register_sysctl(void);
18889 +void   vserver_unregister_sysctl(void);
18890 +
18891 +
18892 +static int __init init_vserver(void)
18893 +{
18894 +       int ret = 0;
18895 +
18896 +#ifdef CONFIG_VSERVER_DEBUG
18897 +       vserver_register_sysctl();
18898 +#endif
18899 +       return ret;
18900 +}
18901 +
18902 +
18903 +static void __exit exit_vserver(void)
18904 +{
18905 +
18906 +#ifdef CONFIG_VSERVER_DEBUG
18907 +       vserver_unregister_sysctl();
18908 +#endif
18909 +       return;
18910 +}
18911 +
18912 +/* FIXME: GFP_ZONETYPES gone
18913 +long vx_slab[GFP_ZONETYPES]; */
18914 +long vx_area;
18915 +
18916 +
18917 +module_init(init_vserver);
18918 +module_exit(exit_vserver);
18919 +
18920 diff -NurpP --minimal linux-3.10.9/kernel/vserver/inode.c linux-3.10.9-vs2.3.6.6/kernel/vserver/inode.c
18921 --- linux-3.10.9/kernel/vserver/inode.c 1970-01-01 00:00:00.000000000 +0000
18922 +++ linux-3.10.9-vs2.3.6.6/kernel/vserver/inode.c       2013-08-22 23:14:01.000000000 +0000
18923 @@ -0,0 +1,440 @@
18924 +/*
18925 + *  linux/kernel/vserver/inode.c
18926 + *
18927 + *  Virtual Server: File System Support
18928 + *
18929 + *  Copyright (C) 2004-2007  Herbert Pötzl
18930 + *
18931 + *  V0.01  separated from vcontext V0.05
18932 + *  V0.02  moved to tag (instead of xid)
18933 + *
18934 + */
18935 +
18936 +#include <linux/tty.h>
18937 +#include <linux/proc_fs.h>
18938 +#include <linux/devpts_fs.h>
18939 +#include <linux/fs.h>
18940 +#include <linux/file.h>
18941 +#include <linux/mount.h>
18942 +#include <linux/parser.h>
18943 +#include <linux/namei.h>
18944 +#include <linux/magic.h>
18945 +#include <linux/slab.h>
18946 +#include <linux/vserver/inode.h>
18947 +#include <linux/vserver/inode_cmd.h>
18948 +#include <linux/vs_base.h>
18949 +#include <linux/vs_tag.h>
18950 +
18951 +#include <asm/uaccess.h>
18952 +#include <../../fs/proc/internal.h>
18953 +
18954 +
18955 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
18956 +{
18957 +       struct proc_dir_entry *entry;
18958 +
18959 +       if (!in || !in->i_sb)
18960 +               return -ESRCH;
18961 +
18962 +       *flags = IATTR_TAG
18963 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
18964 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
18965 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
18966 +               | (IS_COW(in) ? IATTR_COW : 0);
18967 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
18968 +
18969 +       if (S_ISDIR(in->i_mode))
18970 +               *mask |= IATTR_BARRIER;
18971 +
18972 +       if (IS_TAGGED(in)) {
18973 +               *tag = i_tag_read(in);
18974 +               *mask |= IATTR_TAG;
18975 +       }
18976 +
18977 +       switch (in->i_sb->s_magic) {
18978 +       case PROC_SUPER_MAGIC:
18979 +               entry = PROC_I(in)->pde;
18980 +
18981 +               /* check for specific inodes? */
18982 +               if (entry)
18983 +                       *mask |= IATTR_FLAGS;
18984 +               if (entry)
18985 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
18986 +               else
18987 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
18988 +               break;
18989 +
18990 +       case DEVPTS_SUPER_MAGIC:
18991 +               *tag = i_tag_read(in);
18992 +               *mask |= IATTR_TAG;
18993 +               break;
18994 +
18995 +       default:
18996 +               break;
18997 +       }
18998 +       return 0;
18999 +}
19000 +
19001 +int vc_get_iattr(void __user *data)
19002 +{
19003 +       struct path path;
19004 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
19005 +       int ret;
19006 +
19007 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19008 +               return -EFAULT;
19009 +
19010 +       ret = user_lpath(vc_data.name, &path);
19011 +       if (!ret) {
19012 +               ret = __vc_get_iattr(path.dentry->d_inode,
19013 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19014 +               path_put(&path);
19015 +       }
19016 +       if (ret)
19017 +               return ret;
19018 +
19019 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19020 +               ret = -EFAULT;
19021 +       return ret;
19022 +}
19023 +
19024 +#ifdef CONFIG_COMPAT
19025 +
19026 +int vc_get_iattr_x32(void __user *data)
19027 +{
19028 +       struct path path;
19029 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
19030 +       int ret;
19031 +
19032 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19033 +               return -EFAULT;
19034 +
19035 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19036 +       if (!ret) {
19037 +               ret = __vc_get_iattr(path.dentry->d_inode,
19038 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19039 +               path_put(&path);
19040 +       }
19041 +       if (ret)
19042 +               return ret;
19043 +
19044 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19045 +               ret = -EFAULT;
19046 +       return ret;
19047 +}
19048 +
19049 +#endif /* CONFIG_COMPAT */
19050 +
19051 +
19052 +int vc_fget_iattr(uint32_t fd, void __user *data)
19053 +{
19054 +       struct file *filp;
19055 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
19056 +       int ret;
19057 +
19058 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19059 +               return -EFAULT;
19060 +
19061 +       filp = fget(fd);
19062 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19063 +               return -EBADF;
19064 +
19065 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
19066 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
19067 +
19068 +       fput(filp);
19069 +
19070 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19071 +               ret = -EFAULT;
19072 +       return ret;
19073 +}
19074 +
19075 +
19076 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19077 +{
19078 +       struct inode *in = de->d_inode;
19079 +       int error = 0, is_proc = 0, has_tag = 0;
19080 +       struct iattr attr = { 0 };
19081 +
19082 +       if (!in || !in->i_sb)
19083 +               return -ESRCH;
19084 +
19085 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
19086 +       if ((*mask & IATTR_FLAGS) && !is_proc)
19087 +               return -EINVAL;
19088 +
19089 +       has_tag = IS_TAGGED(in) ||
19090 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
19091 +       if ((*mask & IATTR_TAG) && !has_tag)
19092 +               return -EINVAL;
19093 +
19094 +       mutex_lock(&in->i_mutex);
19095 +       if (*mask & IATTR_TAG) {
19096 +               attr.ia_tag = make_ktag(&init_user_ns, *tag);
19097 +               attr.ia_valid |= ATTR_TAG;
19098 +       }
19099 +
19100 +       if (*mask & IATTR_FLAGS) {
19101 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
19102 +               unsigned int iflags = PROC_I(in)->vx_flags;
19103 +
19104 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
19105 +                       | (*flags & IATTR_FLAGS);
19106 +               PROC_I(in)->vx_flags = iflags;
19107 +               if (entry)
19108 +                       entry->vx_flags = iflags;
19109 +       }
19110 +
19111 +       if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
19112 +               IATTR_BARRIER | IATTR_COW)) {
19113 +               int iflags = in->i_flags;
19114 +               int vflags = in->i_vflags;
19115 +
19116 +               if (*mask & IATTR_IMMUTABLE) {
19117 +                       if (*flags & IATTR_IMMUTABLE)
19118 +                               iflags |= S_IMMUTABLE;
19119 +                       else
19120 +                               iflags &= ~S_IMMUTABLE;
19121 +               }
19122 +               if (*mask & IATTR_IXUNLINK) {
19123 +                       if (*flags & IATTR_IXUNLINK)
19124 +                               iflags |= S_IXUNLINK;
19125 +                       else
19126 +                               iflags &= ~S_IXUNLINK;
19127 +               }
19128 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
19129 +                       if (*flags & IATTR_BARRIER)
19130 +                               vflags |= V_BARRIER;
19131 +                       else
19132 +                               vflags &= ~V_BARRIER;
19133 +               }
19134 +               if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
19135 +                       if (*flags & IATTR_COW)
19136 +                               vflags |= V_COW;
19137 +                       else
19138 +                               vflags &= ~V_COW;
19139 +               }
19140 +               if (in->i_op && in->i_op->sync_flags) {
19141 +                       error = in->i_op->sync_flags(in, iflags, vflags);
19142 +                       if (error)
19143 +                               goto out;
19144 +               }
19145 +       }
19146 +
19147 +       if (attr.ia_valid) {
19148 +               if (in->i_op && in->i_op->setattr)
19149 +                       error = in->i_op->setattr(de, &attr);
19150 +               else {
19151 +                       error = inode_change_ok(in, &attr);
19152 +                       if (!error) {
19153 +                               setattr_copy(in, &attr);
19154 +                               mark_inode_dirty(in);
19155 +                       }
19156 +               }
19157 +       }
19158 +
19159 +out:
19160 +       mutex_unlock(&in->i_mutex);
19161 +       return error;
19162 +}
19163 +
19164 +int vc_set_iattr(void __user *data)
19165 +{
19166 +       struct path path;
19167 +       struct vcmd_ctx_iattr_v1 vc_data;
19168 +       int ret;
19169 +
19170 +       if (!capable(CAP_LINUX_IMMUTABLE))
19171 +               return -EPERM;
19172 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19173 +               return -EFAULT;
19174 +
19175 +       ret = user_lpath(vc_data.name, &path);
19176 +       if (!ret) {
19177 +               ret = __vc_set_iattr(path.dentry,
19178 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19179 +               path_put(&path);
19180 +       }
19181 +
19182 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19183 +               ret = -EFAULT;
19184 +       return ret;
19185 +}
19186 +
19187 +#ifdef CONFIG_COMPAT
19188 +
19189 +int vc_set_iattr_x32(void __user *data)
19190 +{
19191 +       struct path path;
19192 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
19193 +       int ret;
19194 +
19195 +       if (!capable(CAP_LINUX_IMMUTABLE))
19196 +               return -EPERM;
19197 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19198 +               return -EFAULT;
19199 +
19200 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19201 +       if (!ret) {
19202 +               ret = __vc_set_iattr(path.dentry,
19203 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19204 +               path_put(&path);
19205 +       }
19206 +
19207 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19208 +               ret = -EFAULT;
19209 +       return ret;
19210 +}
19211 +
19212 +#endif /* CONFIG_COMPAT */
19213 +
19214 +int vc_fset_iattr(uint32_t fd, void __user *data)
19215 +{
19216 +       struct file *filp;
19217 +       struct vcmd_ctx_fiattr_v0 vc_data;
19218 +       int ret;
19219 +
19220 +       if (!capable(CAP_LINUX_IMMUTABLE))
19221 +               return -EPERM;
19222 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19223 +               return -EFAULT;
19224 +
19225 +       filp = fget(fd);
19226 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19227 +               return -EBADF;
19228 +
19229 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
19230 +               &vc_data.flags, &vc_data.mask);
19231 +
19232 +       fput(filp);
19233 +
19234 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19235 +               return -EFAULT;
19236 +       return ret;
19237 +}
19238 +
19239 +
19240 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
19241 +
19242 +static match_table_t tokens = {
19243 +       {Opt_notagcheck, "notagcheck"},
19244 +#ifdef CONFIG_PROPAGATE
19245 +       {Opt_notag, "notag"},
19246 +       {Opt_tag, "tag"},
19247 +       {Opt_tagid, "tagid=%u"},
19248 +#endif
19249 +       {Opt_err, NULL}
19250 +};
19251 +
19252 +
19253 +static void __dx_parse_remove(char *string, char *opt)
19254 +{
19255 +       char *p = strstr(string, opt);
19256 +       char *q = p;
19257 +
19258 +       if (p) {
19259 +               while (*q != '\0' && *q != ',')
19260 +                       q++;
19261 +               while (*q)
19262 +                       *p++ = *q++;
19263 +               while (*p)
19264 +                       *p++ = '\0';
19265 +       }
19266 +}
19267 +
19268 +int dx_parse_tag(char *string, vtag_t *tag, int remove, int *mnt_flags,
19269 +                unsigned long *flags)
19270 +{
19271 +       int set = 0;
19272 +       substring_t args[MAX_OPT_ARGS];
19273 +       int token;
19274 +       char *s, *p, *opts;
19275 +#if defined(CONFIG_PROPAGATE) || defined(CONFIG_VSERVER_DEBUG)
19276 +       int option = 0;
19277 +#endif
19278 +
19279 +       if (!string)
19280 +               return 0;
19281 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
19282 +       if (!s)
19283 +               return 0;
19284 +
19285 +       opts = s;
19286 +       while ((p = strsep(&opts, ",")) != NULL) {
19287 +               token = match_token(p, tokens, args);
19288 +
19289 +               switch (token) {
19290 +#ifdef CONFIG_PROPAGATE
19291 +               case Opt_tag:
19292 +                       if (tag)
19293 +                               *tag = 0;
19294 +                       if (remove)
19295 +                               __dx_parse_remove(s, "tag");
19296 +                       *mnt_flags |= MNT_TAGID;
19297 +                       set |= MNT_TAGID;
19298 +                       break;
19299 +               case Opt_notag:
19300 +                       if (remove)
19301 +                               __dx_parse_remove(s, "notag");
19302 +                       *mnt_flags |= MNT_NOTAG;
19303 +                       set |= MNT_NOTAG;
19304 +                       break;
19305 +               case Opt_tagid:
19306 +                       if (tag && !match_int(args, &option))
19307 +                               *tag = option;
19308 +                       if (remove)
19309 +                               __dx_parse_remove(s, "tagid");
19310 +                       *mnt_flags |= MNT_TAGID;
19311 +                       set |= MNT_TAGID;
19312 +                       break;
19313 +#endif /* CONFIG_PROPAGATE */
19314 +               case Opt_notagcheck:
19315 +                       if (remove)
19316 +                               __dx_parse_remove(s, "notagcheck");
19317 +                       *flags |= MS_NOTAGCHECK;
19318 +                       set |= MS_NOTAGCHECK;
19319 +                       break;
19320 +               }
19321 +               vxdprintk(VXD_CBIT(tag, 7),
19322 +                       "dx_parse_tag(" VS_Q("%s") "): %d:#%d",
19323 +                       p, token, option);
19324 +       }
19325 +       if (set)
19326 +               strcpy(string, s);
19327 +       kfree(s);
19328 +       return set;
19329 +}
19330 +
19331 +#ifdef CONFIG_PROPAGATE
19332 +
19333 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
19334 +{
19335 +       vtag_t new_tag = 0;
19336 +       struct vfsmount *mnt;
19337 +       int propagate;
19338 +
19339 +       if (!nd)
19340 +               return;
19341 +       mnt = nd->path.mnt;
19342 +       if (!mnt)
19343 +               return;
19344 +
19345 +       propagate = (mnt->mnt_flags & MNT_TAGID);
19346 +       if (propagate)
19347 +               new_tag = mnt->mnt_tag;
19348 +
19349 +       vxdprintk(VXD_CBIT(tag, 7),
19350 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
19351 +               inode, inode->i_ino, inode->i_tag,
19352 +               new_tag, (propagate) ? 1 : 0);
19353 +
19354 +       if (propagate)
19355 +               i_tag_write(inode, new_tag);
19356 +}
19357 +
19358 +#include <linux/module.h>
19359 +
19360 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
19361 +
19362 +#endif /* CONFIG_PROPAGATE */
19363 +
19364 diff -NurpP --minimal linux-3.10.9/kernel/vserver/limit.c linux-3.10.9-vs2.3.6.6/kernel/vserver/limit.c
19365 --- linux-3.10.9/kernel/vserver/limit.c 1970-01-01 00:00:00.000000000 +0000
19366 +++ linux-3.10.9-vs2.3.6.6/kernel/vserver/limit.c       2013-08-22 20:30:00.000000000 +0000
19367 @@ -0,0 +1,345 @@
19368 +/*
19369 + *  linux/kernel/vserver/limit.c
19370 + *
19371 + *  Virtual Server: Context Limits
19372 + *
19373 + *  Copyright (C) 2004-2010  Herbert Pötzl
19374 + *
19375 + *  V0.01  broken out from vcontext V0.05
19376 + *  V0.02  changed vcmds to vxi arg
19377 + *  V0.03  added memory cgroup support
19378 + *
19379 + */
19380 +
19381 +#include <linux/sched.h>
19382 +#include <linux/module.h>
19383 +#include <linux/memcontrol.h>
19384 +#include <linux/res_counter.h>
19385 +#include <linux/vs_limit.h>
19386 +#include <linux/vserver/limit.h>
19387 +#include <linux/vserver/limit_cmd.h>
19388 +
19389 +#include <asm/uaccess.h>
19390 +
19391 +
19392 +const char *vlimit_name[NUM_LIMITS] = {
19393 +       [RLIMIT_CPU]            = "CPU",
19394 +       [RLIMIT_NPROC]          = "NPROC",
19395 +       [RLIMIT_NOFILE]         = "NOFILE",
19396 +       [RLIMIT_LOCKS]          = "LOCKS",
19397 +       [RLIMIT_SIGPENDING]     = "SIGP",
19398 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
19399 +
19400 +       [VLIMIT_NSOCK]          = "NSOCK",
19401 +       [VLIMIT_OPENFD]         = "OPENFD",
19402 +       [VLIMIT_SHMEM]          = "SHMEM",
19403 +       [VLIMIT_DENTRY]         = "DENTRY",
19404 +};
19405 +
19406 +EXPORT_SYMBOL_GPL(vlimit_name);
19407 +
19408 +#define MASK_ENTRY(x)  (1 << (x))
19409 +
19410 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
19411 +               /* minimum */
19412 +       0
19413 +       ,       /* softlimit */
19414 +       0
19415 +       ,       /* maximum */
19416 +       MASK_ENTRY( RLIMIT_NPROC        ) |
19417 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
19418 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
19419 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
19420 +
19421 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
19422 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
19423 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
19424 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
19425 +       0
19426 +};
19427 +               /* accounting only */
19428 +uint32_t account_mask =
19429 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
19430 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
19431 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
19432 +       0;
19433 +
19434 +
19435 +static int is_valid_vlimit(int id)
19436 +{
19437 +       uint32_t mask = vlimit_mask.minimum |
19438 +               vlimit_mask.softlimit | vlimit_mask.maximum;
19439 +       return mask & (1 << id);
19440 +}
19441 +
19442 +static int is_accounted_vlimit(int id)
19443 +{
19444 +       if (is_valid_vlimit(id))
19445 +               return 1;
19446 +       return account_mask & (1 << id);
19447 +}
19448 +
19449 +
19450 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
19451 +{
19452 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
19453 +       return VX_VLIM(limit);
19454 +}
19455 +
19456 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
19457 +{
19458 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
19459 +       return VX_VLIM(limit);
19460 +}
19461 +
19462 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
19463 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
19464 +{
19465 +       if (!is_valid_vlimit(id))
19466 +               return -EINVAL;
19467 +
19468 +       if (minimum)
19469 +               *minimum = CRLIM_UNSET;
19470 +       if (softlimit)
19471 +               *softlimit = vc_get_soft(vxi, id);
19472 +       if (maximum)
19473 +               *maximum = vc_get_hard(vxi, id);
19474 +       return 0;
19475 +}
19476 +
19477 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
19478 +{
19479 +       struct vcmd_ctx_rlimit_v0 vc_data;
19480 +       int ret;
19481 +
19482 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19483 +               return -EFAULT;
19484 +
19485 +       ret = do_get_rlimit(vxi, vc_data.id,
19486 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
19487 +       if (ret)
19488 +               return ret;
19489 +
19490 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19491 +               return -EFAULT;
19492 +       return 0;
19493 +}
19494 +
19495 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
19496 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
19497 +{
19498 +       if (!is_valid_vlimit(id))
19499 +               return -EINVAL;
19500 +
19501 +       if (maximum != CRLIM_KEEP)
19502 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
19503 +       if (softlimit != CRLIM_KEEP)
19504 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
19505 +
19506 +       /* clamp soft limit */
19507 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
19508 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
19509 +
19510 +       return 0;
19511 +}
19512 +
19513 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
19514 +{
19515 +       struct vcmd_ctx_rlimit_v0 vc_data;
19516 +
19517 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19518 +               return -EFAULT;
19519 +
19520 +       return do_set_rlimit(vxi, vc_data.id,
19521 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
19522 +}
19523 +
19524 +#ifdef CONFIG_IA32_EMULATION
19525 +
19526 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
19527 +{
19528 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
19529 +
19530 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19531 +               return -EFAULT;
19532 +
19533 +       return do_set_rlimit(vxi, vc_data.id,
19534 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
19535 +}
19536 +
19537 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
19538 +{
19539 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
19540 +       int ret;
19541 +
19542 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19543 +               return -EFAULT;
19544 +
19545 +       ret = do_get_rlimit(vxi, vc_data.id,
19546 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
19547 +       if (ret)
19548 +               return ret;
19549 +
19550 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19551 +               return -EFAULT;
19552 +       return 0;
19553 +}
19554 +
19555 +#endif /* CONFIG_IA32_EMULATION */
19556 +
19557 +
19558 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
19559 +{
19560 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
19561 +               return -EFAULT;
19562 +       return 0;
19563 +}
19564 +
19565 +
19566 +static inline void vx_reset_hits(struct _vx_limit *limit)
19567 +{
19568 +       int lim;
19569 +
19570 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19571 +               atomic_set(&__rlim_lhit(limit, lim), 0);
19572 +       }
19573 +}
19574 +
19575 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
19576 +{
19577 +       vx_reset_hits(&vxi->limit);
19578 +       return 0;
19579 +}
19580 +
19581 +static inline void vx_reset_minmax(struct _vx_limit *limit)
19582 +{
19583 +       rlim_t value;
19584 +       int lim;
19585 +
19586 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19587 +               value = __rlim_get(limit, lim);
19588 +               __rlim_rmax(limit, lim) = value;
19589 +               __rlim_rmin(limit, lim) = value;
19590 +       }
19591 +}
19592 +
19593 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
19594 +{
19595 +       vx_reset_minmax(&vxi->limit);
19596 +       return 0;
19597 +}
19598 +
19599 +
19600 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
19601 +{
19602 +       struct vcmd_rlimit_stat_v0 vc_data;
19603 +       struct _vx_limit *limit = &vxi->limit;
19604 +       int id;
19605 +
19606 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19607 +               return -EFAULT;
19608 +
19609 +       id = vc_data.id;
19610 +       if (!is_accounted_vlimit(id))
19611 +               return -EINVAL;
19612 +
19613 +       vx_limit_fixup(limit, id);
19614 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
19615 +       vc_data.value = __rlim_get(limit, id);
19616 +       vc_data.minimum = __rlim_rmin(limit, id);
19617 +       vc_data.maximum = __rlim_rmax(limit, id);
19618 +
19619 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19620 +               return -EFAULT;
19621 +       return 0;
19622 +}
19623 +
19624 +
19625 +void vx_vsi_meminfo(struct sysinfo *val)
19626 +{
19627 +#ifdef CONFIG_MEMCG
19628 +       struct mem_cgroup *mcg;
19629 +       u64 res_limit, res_usage;
19630 +
19631 +       rcu_read_lock();
19632 +       mcg = mem_cgroup_from_task(current);
19633 +       rcu_read_unlock();
19634 +       if (!mcg)
19635 +               goto out;
19636 +
19637 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
19638 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
19639 +
19640 +       if (res_limit != RESOURCE_MAX)
19641 +               val->totalram = (res_limit >> PAGE_SHIFT);
19642 +       val->freeram = val->totalram - (res_usage >> PAGE_SHIFT);
19643 +       val->bufferram = 0;
19644 +       val->totalhigh = 0;
19645 +       val->freehigh = 0;
19646 +out:
19647 +#endif /* CONFIG_MEMCG */
19648 +       return;
19649 +}
19650 +
19651 +void vx_vsi_swapinfo(struct sysinfo *val)
19652 +{
19653 +#ifdef CONFIG_MEMCG
19654 +#ifdef CONFIG_MEMCG_SWAP
19655 +       struct mem_cgroup *mcg;
19656 +       u64 res_limit, res_usage, memsw_limit, memsw_usage;
19657 +       s64 swap_limit, swap_usage;
19658 +
19659 +       rcu_read_lock();
19660 +       mcg = mem_cgroup_from_task(current);
19661 +       rcu_read_unlock();
19662 +       if (!mcg)
19663 +               goto out;
19664 +
19665 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
19666 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
19667 +       memsw_limit = mem_cgroup_memsw_read_u64(mcg, RES_LIMIT);
19668 +       memsw_usage = mem_cgroup_memsw_read_u64(mcg, RES_USAGE);
19669 +
19670 +       /* memory unlimited */
19671 +       if (res_limit == RESOURCE_MAX)
19672 +               goto out;
19673 +
19674 +       swap_limit = memsw_limit - res_limit;
19675 +       /* we have a swap limit? */
19676 +       if (memsw_limit != RESOURCE_MAX)
19677 +               val->totalswap = swap_limit >> PAGE_SHIFT;
19678 +
19679 +       /* calculate swap part */
19680 +       swap_usage = (memsw_usage > res_usage) ?
19681 +               memsw_usage - res_usage : 0;
19682 +
19683 +       /* total shown minus usage gives free swap */
19684 +       val->freeswap = (swap_usage < swap_limit) ?
19685 +               val->totalswap - (swap_usage >> PAGE_SHIFT) : 0;
19686 +out:
19687 +#else  /* !CONFIG_MEMCG_SWAP */
19688 +       val->totalswap = 0;
19689 +       val->freeswap = 0;
19690 +#endif /* !CONFIG_MEMCG_SWAP */
19691 +#endif /* CONFIG_MEMCG */
19692 +       return;
19693 +}
19694 +
19695 +long vx_vsi_cached(struct sysinfo *val)
19696 +{
19697 +       long cache = 0;
19698 +#ifdef CONFIG_MEMCG
19699 +       struct mem_cgroup *mcg;
19700 +
19701 +       rcu_read_lock();
19702 +       mcg = mem_cgroup_from_task(current);
19703 +       rcu_read_unlock();
19704 +       if (!mcg)
19705 +               goto out;
19706 +
19707 +       cache = mem_cgroup_stat_read_cache(mcg);
19708 +out:
19709 +#endif
19710 +       return cache;
19711 +}
19712 +
19713 diff -NurpP --minimal linux-3.10.9/kernel/vserver/limit_init.h linux-3.10.9-vs2.3.6.6/kernel/vserver/limit_init.h
19714 --- linux-3.10.9/kernel/vserver/limit_init.h    1970-01-01 00:00:00.000000000 +0000
19715 +++ linux-3.10.9-vs2.3.6.6/kernel/vserver/limit_init.h  2013-08-22 20:30:00.000000000 +0000
19716 @@ -0,0 +1,31 @@
19717 +
19718 +
19719 +static inline void vx_info_init_limit(struct _vx_limit *limit)
19720 +{
19721 +       int lim;
19722 +
19723 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19724 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
19725 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
19726 +               __rlim_set(limit, lim, 0);
19727 +               atomic_set(&__rlim_lhit(limit, lim), 0);
19728 +               __rlim_rmin(limit, lim) = 0;
19729 +               __rlim_rmax(limit, lim) = 0;
19730 +       }
19731 +}
19732 +
19733 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
19734 +{
19735 +       rlim_t value;
19736 +       int lim;
19737 +
19738 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19739 +               if ((1 << lim) & VLIM_NOCHECK)
19740 +                       continue;
19741 +               value = __rlim_get(limit, lim);
19742 +               vxwprintk_xid(value,
19743 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
19744 +                       limit, vlimit_name[lim], lim, (long)value);
19745 +       }
19746 +}
19747 +
19748 diff -NurpP --minimal linux-3.10.9/kernel/vserver/limit_proc.h linux-3.10.9-vs2.3.6.6/kernel/vserver/limit_proc.h
19749 --- linux-3.10.9/kernel/vserver/limit_proc.h    1970-01-01 00:00:00.000000000 +0000
19750 +++ linux-3.10.9-vs2.3.6.6/kernel/vserver/limit_proc.h  2013-08-22 20:30:00.000000000 +0000
19751 @@ -0,0 +1,57 @@
19752 +#ifndef _VX_LIMIT_PROC_H
19753 +#define _VX_LIMIT_PROC_H
19754 +
19755 +#include <linux/vserver/limit_int.h>
19756 +
19757 +
19758 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
19759 +#define VX_LIMIT_TOP   \
19760 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
19761 +
19762 +#define VX_LIMIT_ARG(r)                                \
19763 +       (unsigned long)__rlim_get(limit, r),    \
19764 +       (unsigned long)__rlim_rmin(limit, r),   \
19765 +       (unsigned long)__rlim_rmax(limit, r),   \
19766 +       VX_VLIM(__rlim_soft(limit, r)),         \
19767 +       VX_VLIM(__rlim_hard(limit, r)),         \
19768 +       atomic_read(&__rlim_lhit(limit, r))
19769 +
19770 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
19771 +{
19772 +       vx_limit_fixup(limit, -1);
19773 +       return sprintf(buffer, VX_LIMIT_TOP
19774 +               "PROC"  VX_LIMIT_FMT
19775 +               "VM"    VX_LIMIT_FMT
19776 +               "VML"   VX_LIMIT_FMT
19777 +               "RSS"   VX_LIMIT_FMT
19778 +               "ANON"  VX_LIMIT_FMT
19779 +               "RMAP"  VX_LIMIT_FMT
19780 +               "FILES" VX_LIMIT_FMT
19781 +               "OFD"   VX_LIMIT_FMT
19782 +               "LOCKS" VX_LIMIT_FMT
19783 +               "SOCK"  VX_LIMIT_FMT
19784 +               "MSGQ"  VX_LIMIT_FMT
19785 +               "SHM"   VX_LIMIT_FMT
19786 +               "SEMA"  VX_LIMIT_FMT
19787 +               "SEMS"  VX_LIMIT_FMT
19788 +               "DENT"  VX_LIMIT_FMT,
19789 +               VX_LIMIT_ARG(RLIMIT_NPROC),
19790 +               VX_LIMIT_ARG(RLIMIT_AS),
19791 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
19792 +               VX_LIMIT_ARG(RLIMIT_RSS),
19793 +               VX_LIMIT_ARG(VLIMIT_ANON),
19794 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
19795 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
19796 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
19797 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
19798 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
19799 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
19800 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
19801 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
19802 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
19803 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
19804 +}
19805 +
19806 +#endif /* _VX_LIMIT_PROC_H */
19807 +
19808 +
19809 diff -NurpP --minimal linux-3.10.9/kernel/vserver/network.c linux-3.10.9-vs2.3.6.6/kernel/vserver/network.c
19810 --- linux-3.10.9/kernel/vserver/network.c       1970-01-01 00:00:00.000000000 +0000
19811 +++ linux-3.10.9-vs2.3.6.6/kernel/vserver/network.c     2013-08-22 20:30:00.000000000 +0000
19812 @@ -0,0 +1,1053 @@
19813 +/*
19814 + *  linux/kernel/vserver/network.c
19815 + *
19816 + *  Virtual Server: Network Support
19817 + *
19818 + *  Copyright (C) 2003-2007  Herbert Pötzl
19819 + *
19820 + *  V0.01  broken out from vcontext V0.05
19821 + *  V0.02  cleaned up implementation
19822 + *  V0.03  added equiv nx commands
19823 + *  V0.04  switch to RCU based hash
19824 + *  V0.05  and back to locking again
19825 + *  V0.06  changed vcmds to nxi arg
19826 + *  V0.07  have __create claim() the nxi
19827 + *
19828 + */
19829 +
19830 +#include <linux/err.h>
19831 +#include <linux/slab.h>
19832 +#include <linux/rcupdate.h>
19833 +#include <net/ipv6.h>
19834 +
19835 +#include <linux/vs_network.h>
19836 +#include <linux/vs_pid.h>
19837 +#include <linux/vserver/network_cmd.h>
19838 +
19839 +
19840 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
19841 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
19842 +
19843 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
19844 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
19845 +
19846 +
19847 +static int __init init_network(void)
19848 +{
19849 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
19850 +               sizeof(struct nx_addr_v4), 0,
19851 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19852 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
19853 +               sizeof(struct nx_addr_v6), 0,
19854 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19855 +       return 0;
19856 +}
19857 +
19858 +
19859 +/*     __alloc_nx_addr_v4()                                    */
19860 +
19861 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
19862 +{
19863 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
19864 +               nx_addr_v4_cachep, GFP_KERNEL);
19865 +
19866 +       if (!IS_ERR(nxa))
19867 +               memset(nxa, 0, sizeof(*nxa));
19868 +       return nxa;
19869 +}
19870 +
19871 +/*     __dealloc_nx_addr_v4()                                  */
19872 +
19873 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
19874 +{
19875 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
19876 +}
19877 +
19878 +/*     __dealloc_nx_addr_v4_all()                              */
19879 +
19880 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
19881 +{
19882 +       while (nxa) {
19883 +               struct nx_addr_v4 *next = nxa->next;
19884 +
19885 +               __dealloc_nx_addr_v4(nxa);
19886 +               nxa = next;
19887 +       }
19888 +}
19889 +
19890 +
19891 +#ifdef CONFIG_IPV6
19892 +
19893 +/*     __alloc_nx_addr_v6()                                    */
19894 +
19895 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
19896 +{
19897 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
19898 +               nx_addr_v6_cachep, GFP_KERNEL);
19899 +
19900 +       if (!IS_ERR(nxa))
19901 +               memset(nxa, 0, sizeof(*nxa));
19902 +       return nxa;
19903 +}
19904 +
19905 +/*     __dealloc_nx_addr_v6()                                  */
19906 +
19907 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
19908 +{
19909 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
19910 +}
19911 +
19912 +/*     __dealloc_nx_addr_v6_all()                              */
19913 +
19914 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
19915 +{
19916 +       while (nxa) {
19917 +               struct nx_addr_v6 *next = nxa->next;
19918 +
19919 +               __dealloc_nx_addr_v6(nxa);
19920 +               nxa = next;
19921 +       }
19922 +}
19923 +
19924 +#endif /* CONFIG_IPV6 */
19925 +
19926 +/*     __alloc_nx_info()
19927 +
19928 +       * allocate an initialized nx_info struct
19929 +       * doesn't make it visible (hash)                        */
19930 +
19931 +static struct nx_info *__alloc_nx_info(vnid_t nid)
19932 +{
19933 +       struct nx_info *new = NULL;
19934 +
19935 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
19936 +
19937 +       /* would this benefit from a slab cache? */
19938 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
19939 +       if (!new)
19940 +               return 0;
19941 +
19942 +       memset(new, 0, sizeof(struct nx_info));
19943 +       new->nx_id = nid;
19944 +       INIT_HLIST_NODE(&new->nx_hlist);
19945 +       atomic_set(&new->nx_usecnt, 0);
19946 +       atomic_set(&new->nx_tasks, 0);
19947 +       spin_lock_init(&new->addr_lock);
19948 +       new->nx_state = 0;
19949 +
19950 +       new->nx_flags = NXF_INIT_SET;
19951 +
19952 +       /* rest of init goes here */
19953 +
19954 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
19955 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
19956 +
19957 +       vxdprintk(VXD_CBIT(nid, 0),
19958 +               "alloc_nx_info(%d) = %p", nid, new);
19959 +       atomic_inc(&nx_global_ctotal);
19960 +       return new;
19961 +}
19962 +
19963 +/*     __dealloc_nx_info()
19964 +
19965 +       * final disposal of nx_info                             */
19966 +
19967 +static void __dealloc_nx_info(struct nx_info *nxi)
19968 +{
19969 +       vxdprintk(VXD_CBIT(nid, 0),
19970 +               "dealloc_nx_info(%p)", nxi);
19971 +
19972 +       nxi->nx_hlist.next = LIST_POISON1;
19973 +       nxi->nx_id = -1;
19974 +
19975 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
19976 +       BUG_ON(atomic_read(&nxi->nx_tasks));
19977 +
19978 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
19979 +#ifdef CONFIG_IPV6
19980 +       __dealloc_nx_addr_v6_all(nxi->v6.next);
19981 +#endif
19982 +
19983 +       nxi->nx_state |= NXS_RELEASED;
19984 +       kfree(nxi);
19985 +       atomic_dec(&nx_global_ctotal);
19986 +}
19987 +
19988 +static void __shutdown_nx_info(struct nx_info *nxi)
19989 +{
19990 +       nxi->nx_state |= NXS_SHUTDOWN;
19991 +       vs_net_change(nxi, VSC_NETDOWN);
19992 +}
19993 +
19994 +/*     exported stuff                                          */
19995 +
19996 +void free_nx_info(struct nx_info *nxi)
19997 +{
19998 +       /* context shutdown is mandatory */
19999 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
20000 +
20001 +       /* context must not be hashed */
20002 +       BUG_ON(nxi->nx_state & NXS_HASHED);
20003 +
20004 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20005 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20006 +
20007 +       __dealloc_nx_info(nxi);
20008 +}
20009 +
20010 +
20011 +void __nx_set_lback(struct nx_info *nxi)
20012 +{
20013 +       int nid = nxi->nx_id;
20014 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
20015 +
20016 +       nxi->v4_lback.s_addr = lback;
20017 +}
20018 +
20019 +extern int __nx_inet_add_lback(__be32 addr);
20020 +extern int __nx_inet_del_lback(__be32 addr);
20021 +
20022 +
20023 +/*     hash table for nx_info hash */
20024 +
20025 +#define NX_HASH_SIZE   13
20026 +
20027 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
20028 +
20029 +static DEFINE_SPINLOCK(nx_info_hash_lock);
20030 +
20031 +
20032 +static inline unsigned int __hashval(vnid_t nid)
20033 +{
20034 +       return (nid % NX_HASH_SIZE);
20035 +}
20036 +
20037 +
20038 +
20039 +/*     __hash_nx_info()
20040 +
20041 +       * add the nxi to the global hash table
20042 +       * requires the hash_lock to be held                     */
20043 +
20044 +static inline void __hash_nx_info(struct nx_info *nxi)
20045 +{
20046 +       struct hlist_head *head;
20047 +
20048 +       vxd_assert_lock(&nx_info_hash_lock);
20049 +       vxdprintk(VXD_CBIT(nid, 4),
20050 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
20051 +
20052 +       /* context must not be hashed */
20053 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
20054 +
20055 +       nxi->nx_state |= NXS_HASHED;
20056 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
20057 +       hlist_add_head(&nxi->nx_hlist, head);
20058 +       atomic_inc(&nx_global_cactive);
20059 +}
20060 +
20061 +/*     __unhash_nx_info()
20062 +
20063 +       * remove the nxi from the global hash table
20064 +       * requires the hash_lock to be held                     */
20065 +
20066 +static inline void __unhash_nx_info(struct nx_info *nxi)
20067 +{
20068 +       vxd_assert_lock(&nx_info_hash_lock);
20069 +       vxdprintk(VXD_CBIT(nid, 4),
20070 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
20071 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
20072 +
20073 +       /* context must be hashed */
20074 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
20075 +       /* but without tasks */
20076 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20077 +
20078 +       nxi->nx_state &= ~NXS_HASHED;
20079 +       hlist_del(&nxi->nx_hlist);
20080 +       atomic_dec(&nx_global_cactive);
20081 +}
20082 +
20083 +
20084 +/*     __lookup_nx_info()
20085 +
20086 +       * requires the hash_lock to be held
20087 +       * doesn't increment the nx_refcnt                       */
20088 +
20089 +static inline struct nx_info *__lookup_nx_info(vnid_t nid)
20090 +{
20091 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
20092 +       struct hlist_node *pos;
20093 +       struct nx_info *nxi;
20094 +
20095 +       vxd_assert_lock(&nx_info_hash_lock);
20096 +       hlist_for_each(pos, head) {
20097 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20098 +
20099 +               if (nxi->nx_id == nid)
20100 +                       goto found;
20101 +       }
20102 +       nxi = NULL;
20103 +found:
20104 +       vxdprintk(VXD_CBIT(nid, 0),
20105 +               "__lookup_nx_info(#%u): %p[#%u]",
20106 +               nid, nxi, nxi ? nxi->nx_id : 0);
20107 +       return nxi;
20108 +}
20109 +
20110 +
20111 +/*     __create_nx_info()
20112 +
20113 +       * create the requested context
20114 +       * get(), claim() and hash it                            */
20115 +
20116 +static struct nx_info *__create_nx_info(int id)
20117 +{
20118 +       struct nx_info *new, *nxi = NULL;
20119 +
20120 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
20121 +
20122 +       if (!(new = __alloc_nx_info(id)))
20123 +               return ERR_PTR(-ENOMEM);
20124 +
20125 +       /* required to make dynamic xids unique */
20126 +       spin_lock(&nx_info_hash_lock);
20127 +
20128 +       /* static context requested */
20129 +       if ((nxi = __lookup_nx_info(id))) {
20130 +               vxdprintk(VXD_CBIT(nid, 0),
20131 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
20132 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20133 +                       nxi = ERR_PTR(-EBUSY);
20134 +               else
20135 +                       nxi = ERR_PTR(-EEXIST);
20136 +               goto out_unlock;
20137 +       }
20138 +       /* new context */
20139 +       vxdprintk(VXD_CBIT(nid, 0),
20140 +               "create_nx_info(%d) = %p (new)", id, new);
20141 +       claim_nx_info(new, NULL);
20142 +       __nx_set_lback(new);
20143 +       __hash_nx_info(get_nx_info(new));
20144 +       nxi = new, new = NULL;
20145 +
20146 +out_unlock:
20147 +       spin_unlock(&nx_info_hash_lock);
20148 +       if (new)
20149 +               __dealloc_nx_info(new);
20150 +       return nxi;
20151 +}
20152 +
20153 +
20154 +
20155 +/*     exported stuff                                          */
20156 +
20157 +
20158 +void unhash_nx_info(struct nx_info *nxi)
20159 +{
20160 +       __shutdown_nx_info(nxi);
20161 +       spin_lock(&nx_info_hash_lock);
20162 +       __unhash_nx_info(nxi);
20163 +       spin_unlock(&nx_info_hash_lock);
20164 +}
20165 +
20166 +/*     lookup_nx_info()
20167 +
20168 +       * search for a nx_info and get() it
20169 +       * negative id means current                             */
20170 +
20171 +struct nx_info *lookup_nx_info(int id)
20172 +{
20173 +       struct nx_info *nxi = NULL;
20174 +
20175 +       if (id < 0) {
20176 +               nxi = get_nx_info(current_nx_info());
20177 +       } else if (id > 1) {
20178 +               spin_lock(&nx_info_hash_lock);
20179 +               nxi = get_nx_info(__lookup_nx_info(id));
20180 +               spin_unlock(&nx_info_hash_lock);
20181 +       }
20182 +       return nxi;
20183 +}
20184 +
20185 +/*     nid_is_hashed()
20186 +
20187 +       * verify that nid is still hashed                       */
20188 +
20189 +int nid_is_hashed(vnid_t nid)
20190 +{
20191 +       int hashed;
20192 +
20193 +       spin_lock(&nx_info_hash_lock);
20194 +       hashed = (__lookup_nx_info(nid) != NULL);
20195 +       spin_unlock(&nx_info_hash_lock);
20196 +       return hashed;
20197 +}
20198 +
20199 +
20200 +#ifdef CONFIG_PROC_FS
20201 +
20202 +/*     get_nid_list()
20203 +
20204 +       * get a subset of hashed nids for proc
20205 +       * assumes size is at least one                          */
20206 +
20207 +int get_nid_list(int index, unsigned int *nids, int size)
20208 +{
20209 +       int hindex, nr_nids = 0;
20210 +
20211 +       /* only show current and children */
20212 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
20213 +               if (index > 0)
20214 +                       return 0;
20215 +               nids[nr_nids] = nx_current_nid();
20216 +               return 1;
20217 +       }
20218 +
20219 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
20220 +               struct hlist_head *head = &nx_info_hash[hindex];
20221 +               struct hlist_node *pos;
20222 +
20223 +               spin_lock(&nx_info_hash_lock);
20224 +               hlist_for_each(pos, head) {
20225 +                       struct nx_info *nxi;
20226 +
20227 +                       if (--index > 0)
20228 +                               continue;
20229 +
20230 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20231 +                       nids[nr_nids] = nxi->nx_id;
20232 +                       if (++nr_nids >= size) {
20233 +                               spin_unlock(&nx_info_hash_lock);
20234 +                               goto out;
20235 +                       }
20236 +               }
20237 +               /* keep the lock time short */
20238 +               spin_unlock(&nx_info_hash_lock);
20239 +       }
20240 +out:
20241 +       return nr_nids;
20242 +}
20243 +#endif
20244 +
20245 +
20246 +/*
20247 + *     migrate task to new network
20248 + *     gets nxi, puts old_nxi on change
20249 + */
20250 +
20251 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
20252 +{
20253 +       struct nx_info *old_nxi;
20254 +       int ret = 0;
20255 +
20256 +       if (!p || !nxi)
20257 +               BUG();
20258 +
20259 +       vxdprintk(VXD_CBIT(nid, 5),
20260 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
20261 +               p, nxi, nxi->nx_id,
20262 +               atomic_read(&nxi->nx_usecnt),
20263 +               atomic_read(&nxi->nx_tasks));
20264 +
20265 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
20266 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20267 +               return -EACCES;
20268 +
20269 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
20270 +               return -EFAULT;
20271 +
20272 +       /* maybe disallow this completely? */
20273 +       old_nxi = task_get_nx_info(p);
20274 +       if (old_nxi == nxi)
20275 +               goto out;
20276 +
20277 +       task_lock(p);
20278 +       if (old_nxi)
20279 +               clr_nx_info(&p->nx_info);
20280 +       claim_nx_info(nxi, p);
20281 +       set_nx_info(&p->nx_info, nxi);
20282 +       p->nid = nxi->nx_id;
20283 +       task_unlock(p);
20284 +
20285 +       vxdprintk(VXD_CBIT(nid, 5),
20286 +               "moved task %p into nxi:%p[#%d]",
20287 +               p, nxi, nxi->nx_id);
20288 +
20289 +       if (old_nxi)
20290 +               release_nx_info(old_nxi, p);
20291 +       ret = 0;
20292 +out:
20293 +       put_nx_info(old_nxi);
20294 +       return ret;
20295 +}
20296 +
20297 +
20298 +void nx_set_persistent(struct nx_info *nxi)
20299 +{
20300 +       vxdprintk(VXD_CBIT(nid, 6),
20301 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
20302 +
20303 +       get_nx_info(nxi);
20304 +       claim_nx_info(nxi, NULL);
20305 +}
20306 +
20307 +void nx_clear_persistent(struct nx_info *nxi)
20308 +{
20309 +       vxdprintk(VXD_CBIT(nid, 6),
20310 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
20311 +
20312 +       release_nx_info(nxi, NULL);
20313 +       put_nx_info(nxi);
20314 +}
20315 +
20316 +void nx_update_persistent(struct nx_info *nxi)
20317 +{
20318 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
20319 +               nx_set_persistent(nxi);
20320 +       else
20321 +               nx_clear_persistent(nxi);
20322 +}
20323 +
20324 +/* vserver syscall commands below here */
20325 +
20326 +/* taks nid and nx_info functions */
20327 +
20328 +#include <asm/uaccess.h>
20329 +
20330 +
20331 +int vc_task_nid(uint32_t id)
20332 +{
20333 +       vnid_t nid;
20334 +
20335 +       if (id) {
20336 +               struct task_struct *tsk;
20337 +
20338 +               rcu_read_lock();
20339 +               tsk = find_task_by_real_pid(id);
20340 +               nid = (tsk) ? tsk->nid : -ESRCH;
20341 +               rcu_read_unlock();
20342 +       } else
20343 +               nid = nx_current_nid();
20344 +       return nid;
20345 +}
20346 +
20347 +
20348 +int vc_nx_info(struct nx_info *nxi, void __user *data)
20349 +{
20350 +       struct vcmd_nx_info_v0 vc_data;
20351 +
20352 +       vc_data.nid = nxi->nx_id;
20353 +
20354 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20355 +               return -EFAULT;
20356 +       return 0;
20357 +}
20358 +
20359 +
20360 +/* network functions */
20361 +
20362 +int vc_net_create(uint32_t nid, void __user *data)
20363 +{
20364 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
20365 +       struct nx_info *new_nxi;
20366 +       int ret;
20367 +
20368 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20369 +               return -EFAULT;
20370 +
20371 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
20372 +               return -EINVAL;
20373 +
20374 +       new_nxi = __create_nx_info(nid);
20375 +       if (IS_ERR(new_nxi))
20376 +               return PTR_ERR(new_nxi);
20377 +
20378 +       /* initial flags */
20379 +       new_nxi->nx_flags = vc_data.flagword;
20380 +
20381 +       ret = -ENOEXEC;
20382 +       if (vs_net_change(new_nxi, VSC_NETUP))
20383 +               goto out;
20384 +
20385 +       ret = nx_migrate_task(current, new_nxi);
20386 +       if (ret)
20387 +               goto out;
20388 +
20389 +       /* return context id on success */
20390 +       ret = new_nxi->nx_id;
20391 +
20392 +       /* get a reference for persistent contexts */
20393 +       if ((vc_data.flagword & NXF_PERSISTENT))
20394 +               nx_set_persistent(new_nxi);
20395 +out:
20396 +       release_nx_info(new_nxi, NULL);
20397 +       put_nx_info(new_nxi);
20398 +       return ret;
20399 +}
20400 +
20401 +
20402 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
20403 +{
20404 +       return nx_migrate_task(current, nxi);
20405 +}
20406 +
20407 +
20408 +static inline
20409 +struct nx_addr_v4 *__find_v4_addr(struct nx_info *nxi,
20410 +       __be32 ip, __be32 ip2, __be32 mask, uint16_t type, uint16_t flags,
20411 +       struct nx_addr_v4 **prev)
20412 +{
20413 +       struct nx_addr_v4 *nxa = &nxi->v4;
20414 +
20415 +       for (; nxa; nxa = nxa->next) {
20416 +               if ((nxa->ip[0].s_addr == ip) &&
20417 +                   (nxa->ip[1].s_addr == ip2) &&
20418 +                   (nxa->mask.s_addr == mask) &&
20419 +                   (nxa->type == type) &&
20420 +                   (nxa->flags == flags))
20421 +                   return nxa;
20422 +
20423 +               /* save previous entry */
20424 +               if (prev)
20425 +                       *prev = nxa;
20426 +       }
20427 +       return NULL;
20428 +}
20429 +
20430 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
20431 +       uint16_t type, uint16_t flags)
20432 +{
20433 +       struct nx_addr_v4 *nxa = NULL;
20434 +       struct nx_addr_v4 *new = __alloc_nx_addr_v4();
20435 +       unsigned long irqflags;
20436 +       int ret = -EEXIST;
20437 +
20438 +       if (IS_ERR(new))
20439 +               return PTR_ERR(new);
20440 +
20441 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
20442 +       if (__find_v4_addr(nxi, ip, ip2, mask, type, flags, &nxa))
20443 +               goto out_unlock;
20444 +
20445 +       if (NX_IPV4(nxi)) {
20446 +               nxa->next = new;
20447 +               nxa = new;
20448 +               new = NULL;
20449 +
20450 +               /* remove single ip for ip list */
20451 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
20452 +       }
20453 +
20454 +       nxa->ip[0].s_addr = ip;
20455 +       nxa->ip[1].s_addr = ip2;
20456 +       nxa->mask.s_addr = mask;
20457 +       nxa->type = type;
20458 +       nxa->flags = flags;
20459 +       ret = 0;
20460 +out_unlock:
20461 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20462 +       if (new)
20463 +               __dealloc_nx_addr_v4(new);
20464 +       return ret;
20465 +}
20466 +
20467 +int do_remove_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
20468 +       uint16_t type, uint16_t flags)
20469 +{
20470 +       struct nx_addr_v4 *nxa = NULL;
20471 +       struct nx_addr_v4 *old = NULL;
20472 +       unsigned long irqflags;
20473 +       int ret = 0;
20474 +
20475 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
20476 +       switch (type) {
20477 +       case NXA_TYPE_ADDR:
20478 +               old = __find_v4_addr(nxi, ip, ip2, mask, type, flags, &nxa);
20479 +               if (old) {
20480 +                       if (nxa) {
20481 +                               nxa->next = old->next;
20482 +                               old->next = NULL;
20483 +                       } else {
20484 +                               if (old->next) {
20485 +                                       nxa = old;
20486 +                                       old = old->next;
20487 +                                       *nxa = *old;
20488 +                                       old->next = NULL;
20489 +                               } else {
20490 +                                       memset(old, 0, sizeof(*old));
20491 +                                       old = NULL;
20492 +                               }
20493 +                       }
20494 +               } else
20495 +                       ret = -ESRCH;
20496 +               break;
20497 +
20498 +       case NXA_TYPE_ANY:
20499 +               nxa = &nxi->v4;
20500 +               old = nxa->next;
20501 +               memset(nxa, 0, sizeof(*nxa));
20502 +               break;
20503 +
20504 +       default:
20505 +               ret = -EINVAL;
20506 +       }
20507 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20508 +       __dealloc_nx_addr_v4_all(old);
20509 +       return ret;
20510 +}
20511 +
20512 +
20513 +int vc_net_add(struct nx_info *nxi, void __user *data)
20514 +{
20515 +       struct vcmd_net_addr_v0 vc_data;
20516 +       int index, ret = 0;
20517 +
20518 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20519 +               return -EFAULT;
20520 +
20521 +       switch (vc_data.type) {
20522 +       case NXA_TYPE_IPV4:
20523 +               if ((vc_data.count < 1) || (vc_data.count > 4))
20524 +                       return -EINVAL;
20525 +
20526 +               index = 0;
20527 +               while (index < vc_data.count) {
20528 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
20529 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
20530 +                       if (ret)
20531 +                               return ret;
20532 +                       index++;
20533 +               }
20534 +               ret = index;
20535 +               break;
20536 +
20537 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
20538 +               nxi->v4_bcast = vc_data.ip[0];
20539 +               ret = 1;
20540 +               break;
20541 +
20542 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
20543 +               nxi->v4_lback = vc_data.ip[0];
20544 +               ret = 1;
20545 +               break;
20546 +
20547 +       default:
20548 +               ret = -EINVAL;
20549 +               break;
20550 +       }
20551 +       return ret;
20552 +}
20553 +
20554 +int vc_net_remove(struct nx_info *nxi, void __user *data)
20555 +{
20556 +       struct vcmd_net_addr_v0 vc_data;
20557 +
20558 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20559 +               return -EFAULT;
20560 +
20561 +       switch (vc_data.type) {
20562 +       case NXA_TYPE_ANY:
20563 +               return do_remove_v4_addr(nxi, 0, 0, 0, vc_data.type, 0);
20564 +       default:
20565 +               return -EINVAL;
20566 +       }
20567 +       return 0;
20568 +}
20569 +
20570 +
20571 +int vc_net_add_ipv4_v1(struct nx_info *nxi, void __user *data)
20572 +{
20573 +       struct vcmd_net_addr_ipv4_v1 vc_data;
20574 +
20575 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20576 +               return -EFAULT;
20577 +
20578 +       switch (vc_data.type) {
20579 +       case NXA_TYPE_ADDR:
20580 +       case NXA_TYPE_MASK:
20581 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
20582 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20583 +
20584 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
20585 +               nxi->v4_bcast = vc_data.ip;
20586 +               break;
20587 +
20588 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
20589 +               nxi->v4_lback = vc_data.ip;
20590 +               break;
20591 +
20592 +       default:
20593 +               return -EINVAL;
20594 +       }
20595 +       return 0;
20596 +}
20597 +
20598 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
20599 +{
20600 +       struct vcmd_net_addr_ipv4_v2 vc_data;
20601 +
20602 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20603 +               return -EFAULT;
20604 +
20605 +       switch (vc_data.type) {
20606 +       case NXA_TYPE_ADDR:
20607 +       case NXA_TYPE_MASK:
20608 +       case NXA_TYPE_RANGE:
20609 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
20610 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20611 +
20612 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
20613 +               nxi->v4_bcast = vc_data.ip;
20614 +               break;
20615 +
20616 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
20617 +               nxi->v4_lback = vc_data.ip;
20618 +               break;
20619 +
20620 +       default:
20621 +               return -EINVAL;
20622 +       }
20623 +       return 0;
20624 +}
20625 +
20626 +int vc_net_rem_ipv4_v1(struct nx_info *nxi, void __user *data)
20627 +{
20628 +       struct vcmd_net_addr_ipv4_v1 vc_data;
20629 +
20630 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20631 +               return -EFAULT;
20632 +
20633 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, 0,
20634 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20635 +}
20636 +
20637 +int vc_net_rem_ipv4(struct nx_info *nxi, void __user *data)
20638 +{
20639 +       struct vcmd_net_addr_ipv4_v2 vc_data;
20640 +
20641 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20642 +               return -EFAULT;
20643 +
20644 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
20645 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20646 +}
20647 +
20648 +#ifdef CONFIG_IPV6
20649 +
20650 +static inline
20651 +struct nx_addr_v6 *__find_v6_addr(struct nx_info *nxi,
20652 +       struct in6_addr *ip, struct in6_addr *mask,
20653 +       uint32_t prefix, uint16_t type, uint16_t flags,
20654 +       struct nx_addr_v6 **prev)
20655 +{
20656 +       struct nx_addr_v6 *nxa = &nxi->v6;
20657 +
20658 +       for (; nxa; nxa = nxa->next) {
20659 +               if (ipv6_addr_equal(&nxa->ip, ip) &&
20660 +                   ipv6_addr_equal(&nxa->mask, mask) &&
20661 +                   (nxa->prefix == prefix) &&
20662 +                   (nxa->type == type) &&
20663 +                   (nxa->flags == flags))
20664 +                   return nxa;
20665 +
20666 +               /* save previous entry */
20667 +               if (prev)
20668 +                       *prev = nxa;
20669 +       }
20670 +       return NULL;
20671 +}
20672 +
20673 +
20674 +int do_add_v6_addr(struct nx_info *nxi,
20675 +       struct in6_addr *ip, struct in6_addr *mask,
20676 +       uint32_t prefix, uint16_t type, uint16_t flags)
20677 +{
20678 +       struct nx_addr_v6 *nxa = NULL;
20679 +       struct nx_addr_v6 *new = __alloc_nx_addr_v6();
20680 +       unsigned long irqflags;
20681 +       int ret = -EEXIST;
20682 +
20683 +       if (IS_ERR(new))
20684 +               return PTR_ERR(new);
20685 +
20686 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
20687 +       if (__find_v6_addr(nxi, ip, mask, prefix, type, flags, &nxa))
20688 +               goto out_unlock;
20689 +
20690 +       if (NX_IPV6(nxi)) {
20691 +               nxa->next = new;
20692 +               nxa = new;
20693 +               new = NULL;
20694 +       }
20695 +
20696 +       nxa->ip = *ip;
20697 +       nxa->mask = *mask;
20698 +       nxa->prefix = prefix;
20699 +       nxa->type = type;
20700 +       nxa->flags = flags;
20701 +       ret = 0;
20702 +out_unlock:
20703 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20704 +       if (new)
20705 +               __dealloc_nx_addr_v6(new);
20706 +       return ret;
20707 +}
20708 +
20709 +int do_remove_v6_addr(struct nx_info *nxi,
20710 +       struct in6_addr *ip, struct in6_addr *mask,
20711 +       uint32_t prefix, uint16_t type, uint16_t flags)
20712 +{
20713 +       struct nx_addr_v6 *nxa = NULL;
20714 +       struct nx_addr_v6 *old = NULL;
20715 +       unsigned long irqflags;
20716 +       int ret = 0;
20717 +
20718 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
20719 +       switch (type) {
20720 +       case NXA_TYPE_ADDR:
20721 +               old = __find_v6_addr(nxi, ip, mask, prefix, type, flags, &nxa);
20722 +               if (old) {
20723 +                       if (nxa) {
20724 +                               nxa->next = old->next;
20725 +                               old->next = NULL;
20726 +                       } else {
20727 +                               if (old->next) {
20728 +                                       nxa = old;
20729 +                                       old = old->next;
20730 +                                       *nxa = *old;
20731 +                                       old->next = NULL;
20732 +                               } else {
20733 +                                       memset(old, 0, sizeof(*old));
20734 +                                       old = NULL;
20735 +                               }
20736 +                       }
20737 +               } else
20738 +                       ret = -ESRCH;
20739 +               break;
20740 +
20741 +       case NXA_TYPE_ANY:
20742 +               nxa = &nxi->v6;
20743 +               old = nxa->next;
20744 +               memset(nxa, 0, sizeof(*nxa));
20745 +               break;
20746 +
20747 +       default:
20748 +               ret = -EINVAL;
20749 +       }
20750 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20751 +       __dealloc_nx_addr_v6_all(old);
20752 +       return ret;
20753 +}
20754 +
20755 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
20756 +{
20757 +       struct vcmd_net_addr_ipv6_v1 vc_data;
20758 +
20759 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20760 +               return -EFAULT;
20761 +
20762 +       switch (vc_data.type) {
20763 +       case NXA_TYPE_ADDR:
20764 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
20765 +               /* fallthrough */
20766 +       case NXA_TYPE_MASK:
20767 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
20768 +                       vc_data.prefix, vc_data.type, vc_data.flags);
20769 +       default:
20770 +               return -EINVAL;
20771 +       }
20772 +       return 0;
20773 +}
20774 +
20775 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
20776 +{
20777 +       struct vcmd_net_addr_ipv6_v1 vc_data;
20778 +
20779 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20780 +               return -EFAULT;
20781 +
20782 +       switch (vc_data.type) {
20783 +       case NXA_TYPE_ADDR:
20784 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
20785 +               /* fallthrough */
20786 +       case NXA_TYPE_MASK:
20787 +               return do_remove_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
20788 +                       vc_data.prefix, vc_data.type, vc_data.flags);
20789 +       case NXA_TYPE_ANY:
20790 +               return do_remove_v6_addr(nxi, NULL, NULL, 0, vc_data.type, 0);
20791 +       default:
20792 +               return -EINVAL;
20793 +       }
20794 +       return 0;
20795 +}
20796 +
20797 +#endif /* CONFIG_IPV6 */
20798 +
20799 +
20800 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
20801 +{
20802 +       struct vcmd_net_flags_v0 vc_data;
20803 +
20804 +       vc_data.flagword = nxi->nx_flags;
20805 +
20806 +       /* special STATE flag handling */
20807 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
20808 +
20809 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20810 +               return -EFAULT;
20811 +       return 0;
20812 +}
20813 +
20814 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
20815 +{
20816 +       struct vcmd_net_flags_v0 vc_data;
20817 +       uint64_t mask, trigger;
20818 +
20819 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20820 +               return -EFAULT;
20821 +
20822 +       /* special STATE flag handling */
20823 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
20824 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
20825 +
20826 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
20827 +               vc_data.flagword, mask);
20828 +       if (trigger & NXF_PERSISTENT)
20829 +               nx_update_persistent(nxi);
20830 +
20831 +       return 0;
20832 +}
20833 +
20834 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
20835 +{
20836 +       struct vcmd_net_caps_v0 vc_data;
20837 +
20838 +       vc_data.ncaps = nxi->nx_ncaps;
20839 +       vc_data.cmask = ~0ULL;
20840 +
20841 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20842 +               return -EFAULT;
20843 +       return 0;
20844 +}
20845 +
20846 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
20847 +{
20848 +       struct vcmd_net_caps_v0 vc_data;
20849 +
20850 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20851 +               return -EFAULT;
20852 +
20853 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
20854 +               vc_data.ncaps, vc_data.cmask);
20855 +       return 0;
20856 +}
20857 +
20858 +
20859 +#include <linux/module.h>
20860 +
20861 +module_init(init_network);
20862 +
20863 +EXPORT_SYMBOL_GPL(free_nx_info);
20864 +EXPORT_SYMBOL_GPL(unhash_nx_info);
20865 +
20866 diff -NurpP --minimal linux-3.10.9/kernel/vserver/proc.c linux-3.10.9-vs2.3.6.6/kernel/vserver/proc.c
20867 --- linux-3.10.9/kernel/vserver/proc.c  1970-01-01 00:00:00.000000000 +0000
20868 +++ linux-3.10.9-vs2.3.6.6/kernel/vserver/proc.c        2013-08-22 23:31:37.000000000 +0000
20869 @@ -0,0 +1,1113 @@
20870 +/*
20871 + *  linux/kernel/vserver/proc.c
20872 + *
20873 + *  Virtual Context Support
20874 + *
20875 + *  Copyright (C) 2003-2011  Herbert Pötzl
20876 + *
20877 + *  V0.01  basic structure
20878 + *  V0.02  adaptation vs1.3.0
20879 + *  V0.03  proc permissions
20880 + *  V0.04  locking/generic
20881 + *  V0.05  next generation procfs
20882 + *  V0.06  inode validation
20883 + *  V0.07  generic rewrite vid
20884 + *  V0.08  remove inode type
20885 + *  V0.09  added u/wmask info
20886 + *
20887 + */
20888 +
20889 +#include <linux/proc_fs.h>
20890 +#include <linux/fs_struct.h>
20891 +#include <linux/mount.h>
20892 +#include <linux/namei.h>
20893 +#include <asm/unistd.h>
20894 +
20895 +#include <linux/vs_context.h>
20896 +#include <linux/vs_network.h>
20897 +#include <linux/vs_cvirt.h>
20898 +
20899 +#include <linux/in.h>
20900 +#include <linux/inetdevice.h>
20901 +#include <linux/vs_inet.h>
20902 +#include <linux/vs_inet6.h>
20903 +
20904 +#include <linux/vserver/global.h>
20905 +
20906 +#include "cvirt_proc.h"
20907 +#include "cacct_proc.h"
20908 +#include "limit_proc.h"
20909 +#include "sched_proc.h"
20910 +#include "vci_config.h"
20911 +
20912 +#include <../../fs/proc/internal.h>
20913 +
20914 +
20915 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
20916 +{
20917 +       unsigned __capi;
20918 +
20919 +       CAP_FOR_EACH_U32(__capi) {
20920 +               buffer += sprintf(buffer, "%08x",
20921 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
20922 +       }
20923 +       return buffer;
20924 +}
20925 +
20926 +
20927 +static struct proc_dir_entry *proc_virtual;
20928 +
20929 +static struct proc_dir_entry *proc_virtnet;
20930 +
20931 +
20932 +/* first the actual feeds */
20933 +
20934 +
20935 +static int proc_vci(char *buffer)
20936 +{
20937 +       return sprintf(buffer,
20938 +               "VCIVersion:\t%04x:%04x\n"
20939 +               "VCISyscall:\t%d\n"
20940 +               "VCIKernel:\t%08x\n",
20941 +               VCI_VERSION >> 16,
20942 +               VCI_VERSION & 0xFFFF,
20943 +               __NR_vserver,
20944 +               vci_kernel_config());
20945 +}
20946 +
20947 +static int proc_virtual_info(char *buffer)
20948 +{
20949 +       return proc_vci(buffer);
20950 +}
20951 +
20952 +static int proc_virtual_status(char *buffer)
20953 +{
20954 +       return sprintf(buffer,
20955 +               "#CTotal:\t%d\n"
20956 +               "#CActive:\t%d\n"
20957 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
20958 +               "#InitTask:\t%d\t%d %d\n",
20959 +               atomic_read(&vx_global_ctotal),
20960 +               atomic_read(&vx_global_cactive),
20961 +               atomic_read(&vs_global_nsproxy),
20962 +               atomic_read(&vs_global_fs),
20963 +               atomic_read(&vs_global_mnt_ns),
20964 +               atomic_read(&vs_global_uts_ns),
20965 +               atomic_read(&nr_ipc_ns),
20966 +               atomic_read(&vs_global_user_ns),
20967 +               atomic_read(&vs_global_pid_ns),
20968 +               atomic_read(&init_task.usage),
20969 +               atomic_read(&init_task.nsproxy->count),
20970 +               init_task.fs->users);
20971 +}
20972 +
20973 +
20974 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
20975 +{
20976 +       int length;
20977 +
20978 +       length = sprintf(buffer,
20979 +               "ID:\t%d\n"
20980 +               "Info:\t%p\n"
20981 +               "Init:\t%d\n"
20982 +               "OOM:\t%lld\n",
20983 +               vxi->vx_id,
20984 +               vxi,
20985 +               vxi->vx_initpid,
20986 +               vxi->vx_badness_bias);
20987 +       return length;
20988 +}
20989 +
20990 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
20991 +{
20992 +       char *orig = buffer;
20993 +
20994 +       buffer += sprintf(buffer,
20995 +               "UseCnt:\t%d\n"
20996 +               "Tasks:\t%d\n"
20997 +               "Flags:\t%016llx\n",
20998 +               atomic_read(&vxi->vx_usecnt),
20999 +               atomic_read(&vxi->vx_tasks),
21000 +               (unsigned long long)vxi->vx_flags);
21001 +
21002 +       buffer += sprintf(buffer, "BCaps:\t");
21003 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
21004 +       buffer += sprintf(buffer, "\n");
21005 +
21006 +       buffer += sprintf(buffer,
21007 +               "CCaps:\t%016llx\n"
21008 +               "Umask:\t%16llx\n"
21009 +               "Wmask:\t%16llx\n"
21010 +               "Spaces:\t%08lx %08lx\n",
21011 +               (unsigned long long)vxi->vx_ccaps,
21012 +               (unsigned long long)vxi->vx_umask,
21013 +               (unsigned long long)vxi->vx_wmask,
21014 +               vxi->space[0].vx_nsmask, vxi->space[1].vx_nsmask);
21015 +       return buffer - orig;
21016 +}
21017 +
21018 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
21019 +{
21020 +       return vx_info_proc_limit(&vxi->limit, buffer);
21021 +}
21022 +
21023 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
21024 +{
21025 +       int cpu, length;
21026 +
21027 +       length = vx_info_proc_sched(&vxi->sched, buffer);
21028 +       for_each_online_cpu(cpu) {
21029 +               length += vx_info_proc_sched_pc(
21030 +                       &vx_per_cpu(vxi, sched_pc, cpu),
21031 +                       buffer + length, cpu);
21032 +       }
21033 +       return length;
21034 +}
21035 +
21036 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
21037 +{
21038 +       return vx_info_proc_nsproxy(vxi->space[0].vx_nsproxy, buffer);
21039 +}
21040 +
21041 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
21042 +{
21043 +       return vx_info_proc_nsproxy(vxi->space[1].vx_nsproxy, buffer);
21044 +}
21045 +
21046 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
21047 +{
21048 +       int cpu, length;
21049 +
21050 +       vx_update_load(vxi);
21051 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
21052 +       for_each_online_cpu(cpu) {
21053 +               length += vx_info_proc_cvirt_pc(
21054 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
21055 +                       buffer + length, cpu);
21056 +       }
21057 +       return length;
21058 +}
21059 +
21060 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
21061 +{
21062 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
21063 +}
21064 +
21065 +
21066 +static int proc_virtnet_info(char *buffer)
21067 +{
21068 +       return proc_vci(buffer);
21069 +}
21070 +
21071 +static int proc_virtnet_status(char *buffer)
21072 +{
21073 +       return sprintf(buffer,
21074 +               "#CTotal:\t%d\n"
21075 +               "#CActive:\t%d\n",
21076 +               atomic_read(&nx_global_ctotal),
21077 +               atomic_read(&nx_global_cactive));
21078 +}
21079 +
21080 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
21081 +{
21082 +       struct nx_addr_v4 *v4a;
21083 +#ifdef CONFIG_IPV6
21084 +       struct nx_addr_v6 *v6a;
21085 +#endif
21086 +       int length, i;
21087 +
21088 +       length = sprintf(buffer,
21089 +               "ID:\t%d\n"
21090 +               "Info:\t%p\n"
21091 +               "Bcast:\t" NIPQUAD_FMT "\n"
21092 +               "Lback:\t" NIPQUAD_FMT "\n",
21093 +               nxi->nx_id,
21094 +               nxi,
21095 +               NIPQUAD(nxi->v4_bcast.s_addr),
21096 +               NIPQUAD(nxi->v4_lback.s_addr));
21097 +
21098 +       if (!NX_IPV4(nxi))
21099 +               goto skip_v4;
21100 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
21101 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
21102 +                       i, NXAV4(v4a));
21103 +skip_v4:
21104 +#ifdef CONFIG_IPV6
21105 +       if (!NX_IPV6(nxi))
21106 +               goto skip_v6;
21107 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
21108 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
21109 +                       i, NXAV6(v6a));
21110 +skip_v6:
21111 +#endif
21112 +       return length;
21113 +}
21114 +
21115 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
21116 +{
21117 +       int length;
21118 +
21119 +       length = sprintf(buffer,
21120 +               "UseCnt:\t%d\n"
21121 +               "Tasks:\t%d\n"
21122 +               "Flags:\t%016llx\n"
21123 +               "NCaps:\t%016llx\n",
21124 +               atomic_read(&nxi->nx_usecnt),
21125 +               atomic_read(&nxi->nx_tasks),
21126 +               (unsigned long long)nxi->nx_flags,
21127 +               (unsigned long long)nxi->nx_ncaps);
21128 +       return length;
21129 +}
21130 +
21131 +
21132 +
21133 +/* here the inode helpers */
21134 +
21135 +struct vs_entry {
21136 +       int len;
21137 +       char *name;
21138 +       mode_t mode;
21139 +       struct inode_operations *iop;
21140 +       struct file_operations *fop;
21141 +       union proc_op op;
21142 +};
21143 +
21144 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
21145 +{
21146 +       struct inode *inode = new_inode(sb);
21147 +
21148 +       if (!inode)
21149 +               goto out;
21150 +
21151 +       inode->i_mode = p->mode;
21152 +       if (p->iop)
21153 +               inode->i_op = p->iop;
21154 +       if (p->fop)
21155 +               inode->i_fop = p->fop;
21156 +
21157 +       set_nlink(inode, (p->mode & S_IFDIR) ? 2 : 1);
21158 +       inode->i_flags |= S_IMMUTABLE;
21159 +
21160 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
21161 +
21162 +       i_uid_write(inode, 0);
21163 +       i_gid_write(inode, 0);
21164 +       i_tag_write(inode, 0);
21165 +out:
21166 +       return inode;
21167 +}
21168 +
21169 +static struct dentry *vs_proc_instantiate(struct inode *dir,
21170 +       struct dentry *dentry, int id, void *ptr)
21171 +{
21172 +       struct vs_entry *p = ptr;
21173 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
21174 +       struct dentry *error = ERR_PTR(-EINVAL);
21175 +
21176 +       if (!inode)
21177 +               goto out;
21178 +
21179 +       PROC_I(inode)->op = p->op;
21180 +       PROC_I(inode)->fd = id;
21181 +       d_add(dentry, inode);
21182 +       error = NULL;
21183 +out:
21184 +       return error;
21185 +}
21186 +
21187 +/* Lookups */
21188 +
21189 +typedef struct dentry *vx_instantiate_t(struct inode *, struct dentry *, int, void *);
21190 +
21191 +
21192 +/*
21193 + * Fill a directory entry.
21194 + *
21195 + * If possible create the dcache entry and derive our inode number and
21196 + * file type from dcache entry.
21197 + *
21198 + * Since all of the proc inode numbers are dynamically generated, the inode
21199 + * numbers do not exist until the inode is cache.  This means creating the
21200 + * the dcache entry in readdir is necessary to keep the inode numbers
21201 + * reported by readdir in sync with the inode numbers reported
21202 + * by stat.
21203 + */
21204 +static int vx_proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
21205 +       char *name, int len, vx_instantiate_t instantiate, int id, void *ptr)
21206 +{
21207 +       struct dentry *child, *dir = filp->f_dentry;
21208 +       struct inode *inode;
21209 +       struct qstr qname;
21210 +       ino_t ino = 0;
21211 +       unsigned type = DT_UNKNOWN;
21212 +
21213 +       qname.name = name;
21214 +       qname.len  = len;
21215 +       qname.hash = full_name_hash(name, len);
21216 +
21217 +       child = d_lookup(dir, &qname);
21218 +       if (!child) {
21219 +               struct dentry *new;
21220 +               new = d_alloc(dir, &qname);
21221 +               if (new) {
21222 +                       child = instantiate(dir->d_inode, new, id, ptr);
21223 +                       if (child)
21224 +                               dput(new);
21225 +                       else
21226 +                               child = new;
21227 +               }
21228 +       }
21229 +       if (!child || IS_ERR(child) || !child->d_inode)
21230 +               goto end_instantiate;
21231 +       inode = child->d_inode;
21232 +       if (inode) {
21233 +               ino = inode->i_ino;
21234 +               type = inode->i_mode >> 12;
21235 +       }
21236 +       dput(child);
21237 +end_instantiate:
21238 +       if (!ino)
21239 +               ino = find_inode_number(dir, &qname);
21240 +       if (!ino)
21241 +               ino = 1;
21242 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
21243 +}
21244 +
21245 +
21246 +
21247 +/* get and revalidate vx_info/xid */
21248 +
21249 +static inline
21250 +struct vx_info *get_proc_vx_info(struct inode *inode)
21251 +{
21252 +       return lookup_vx_info(PROC_I(inode)->fd);
21253 +}
21254 +
21255 +static int proc_xid_revalidate(struct dentry *dentry, unsigned int flags)
21256 +{
21257 +       struct inode *inode = dentry->d_inode;
21258 +       vxid_t xid = PROC_I(inode)->fd;
21259 +
21260 +       if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
21261 +               return -ECHILD;
21262 +
21263 +       if (!xid || xid_is_hashed(xid))
21264 +               return 1;
21265 +       d_drop(dentry);
21266 +       return 0;
21267 +}
21268 +
21269 +
21270 +/* get and revalidate nx_info/nid */
21271 +
21272 +static int proc_nid_revalidate(struct dentry *dentry, unsigned int flags)
21273 +{
21274 +       struct inode *inode = dentry->d_inode;
21275 +       vnid_t nid = PROC_I(inode)->fd;
21276 +
21277 +       if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
21278 +               return -ECHILD;
21279 +
21280 +       if (!nid || nid_is_hashed(nid))
21281 +               return 1;
21282 +       d_drop(dentry);
21283 +       return 0;
21284 +}
21285 +
21286 +
21287 +
21288 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
21289 +
21290 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
21291 +                         size_t count, loff_t *ppos)
21292 +{
21293 +       struct inode *inode = file->f_dentry->d_inode;
21294 +       unsigned long page;
21295 +       ssize_t length = 0;
21296 +
21297 +       if (count > PROC_BLOCK_SIZE)
21298 +               count = PROC_BLOCK_SIZE;
21299 +
21300 +       /* fade that out as soon as stable */
21301 +       WARN_ON(PROC_I(inode)->fd);
21302 +
21303 +       if (!(page = __get_free_page(GFP_KERNEL)))
21304 +               return -ENOMEM;
21305 +
21306 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
21307 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
21308 +
21309 +       if (length >= 0)
21310 +               length = simple_read_from_buffer(buf, count, ppos,
21311 +                       (char *)page, length);
21312 +
21313 +       free_page(page);
21314 +       return length;
21315 +}
21316 +
21317 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
21318 +                         size_t count, loff_t *ppos)
21319 +{
21320 +       struct inode *inode = file->f_dentry->d_inode;
21321 +       struct vx_info *vxi = NULL;
21322 +       vxid_t xid = PROC_I(inode)->fd;
21323 +       unsigned long page;
21324 +       ssize_t length = 0;
21325 +
21326 +       if (count > PROC_BLOCK_SIZE)
21327 +               count = PROC_BLOCK_SIZE;
21328 +
21329 +       /* fade that out as soon as stable */
21330 +       WARN_ON(!xid);
21331 +       vxi = lookup_vx_info(xid);
21332 +       if (!vxi)
21333 +               goto out;
21334 +
21335 +       length = -ENOMEM;
21336 +       if (!(page = __get_free_page(GFP_KERNEL)))
21337 +               goto out_put;
21338 +
21339 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
21340 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
21341 +
21342 +       if (length >= 0)
21343 +               length = simple_read_from_buffer(buf, count, ppos,
21344 +                       (char *)page, length);
21345 +
21346 +       free_page(page);
21347 +out_put:
21348 +       put_vx_info(vxi);
21349 +out:
21350 +       return length;
21351 +}
21352 +
21353 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
21354 +                         size_t count, loff_t *ppos)
21355 +{
21356 +       struct inode *inode = file->f_dentry->d_inode;
21357 +       struct nx_info *nxi = NULL;
21358 +       vnid_t nid = PROC_I(inode)->fd;
21359 +       unsigned long page;
21360 +       ssize_t length = 0;
21361 +
21362 +       if (count > PROC_BLOCK_SIZE)
21363 +               count = PROC_BLOCK_SIZE;
21364 +
21365 +       /* fade that out as soon as stable */
21366 +       WARN_ON(!nid);
21367 +       nxi = lookup_nx_info(nid);
21368 +       if (!nxi)
21369 +               goto out;
21370 +
21371 +       length = -ENOMEM;
21372 +       if (!(page = __get_free_page(GFP_KERNEL)))
21373 +               goto out_put;
21374 +
21375 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
21376 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
21377 +
21378 +       if (length >= 0)
21379 +               length = simple_read_from_buffer(buf, count, ppos,
21380 +                       (char *)page, length);
21381 +
21382 +       free_page(page);
21383 +out_put:
21384 +       put_nx_info(nxi);
21385 +out:
21386 +       return length;
21387 +}
21388 +
21389 +
21390 +
21391 +/* here comes the lower level */
21392 +
21393 +
21394 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
21395 +       .len  = sizeof(NAME) - 1,       \
21396 +       .name = (NAME),                 \
21397 +       .mode = MODE,                   \
21398 +       .iop  = IOP,                    \
21399 +       .fop  = FOP,                    \
21400 +       .op   = OP,                     \
21401 +}
21402 +
21403 +
21404 +#define DIR(NAME, MODE, OTYPE)                         \
21405 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
21406 +               &proc_ ## OTYPE ## _inode_operations,   \
21407 +               &proc_ ## OTYPE ## _file_operations, { } )
21408 +
21409 +#define INF(NAME, MODE, OTYPE)                         \
21410 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21411 +               &proc_vs_info_file_operations,          \
21412 +               { .proc_vs_read = &proc_##OTYPE } )
21413 +
21414 +#define VINF(NAME, MODE, OTYPE)                                \
21415 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21416 +               &proc_vx_info_file_operations,          \
21417 +               { .proc_vxi_read = &proc_##OTYPE } )
21418 +
21419 +#define NINF(NAME, MODE, OTYPE)                                \
21420 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21421 +               &proc_nx_info_file_operations,          \
21422 +               { .proc_nxi_read = &proc_##OTYPE } )
21423 +
21424 +
21425 +static struct file_operations proc_vs_info_file_operations = {
21426 +       .read =         proc_vs_info_read,
21427 +};
21428 +
21429 +static struct file_operations proc_vx_info_file_operations = {
21430 +       .read =         proc_vx_info_read,
21431 +};
21432 +
21433 +static struct dentry_operations proc_xid_dentry_operations = {
21434 +       .d_revalidate = proc_xid_revalidate,
21435 +};
21436 +
21437 +static struct vs_entry vx_base_stuff[] = {
21438 +       VINF("info",    S_IRUGO, vxi_info),
21439 +       VINF("status",  S_IRUGO, vxi_status),
21440 +       VINF("limit",   S_IRUGO, vxi_limit),
21441 +       VINF("sched",   S_IRUGO, vxi_sched),
21442 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
21443 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
21444 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
21445 +       VINF("cacct",   S_IRUGO, vxi_cacct),
21446 +       {}
21447 +};
21448 +
21449 +
21450 +
21451 +
21452 +static struct dentry *proc_xid_instantiate(struct inode *dir,
21453 +       struct dentry *dentry, int id, void *ptr)
21454 +{
21455 +       dentry->d_op = &proc_xid_dentry_operations;
21456 +       return vs_proc_instantiate(dir, dentry, id, ptr);
21457 +}
21458 +
21459 +static struct dentry *proc_xid_lookup(struct inode *dir,
21460 +       struct dentry *dentry, unsigned int flags)
21461 +{
21462 +       struct vs_entry *p = vx_base_stuff;
21463 +       struct dentry *error = ERR_PTR(-ENOENT);
21464 +
21465 +       for (; p->name; p++) {
21466 +               if (p->len != dentry->d_name.len)
21467 +                       continue;
21468 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21469 +                       break;
21470 +       }
21471 +       if (!p->name)
21472 +               goto out;
21473 +
21474 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
21475 +out:
21476 +       return error;
21477 +}
21478 +
21479 +static int proc_xid_readdir(struct file *filp,
21480 +       void *dirent, filldir_t filldir)
21481 +{
21482 +       struct dentry *dentry = filp->f_dentry;
21483 +       struct inode *inode = dentry->d_inode;
21484 +       struct vs_entry *p = vx_base_stuff;
21485 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
21486 +       int pos, index;
21487 +       u64 ino;
21488 +
21489 +       pos = filp->f_pos;
21490 +       switch (pos) {
21491 +       case 0:
21492 +               ino = inode->i_ino;
21493 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21494 +                       goto out;
21495 +               pos++;
21496 +               /* fall through */
21497 +       case 1:
21498 +               ino = parent_ino(dentry);
21499 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21500 +                       goto out;
21501 +               pos++;
21502 +               /* fall through */
21503 +       default:
21504 +               index = pos - 2;
21505 +               if (index >= size)
21506 +                       goto out;
21507 +               for (p += index; p->name; p++) {
21508 +                       if (vx_proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21509 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
21510 +                               goto out;
21511 +                       pos++;
21512 +               }
21513 +       }
21514 +out:
21515 +       filp->f_pos = pos;
21516 +       return 1;
21517 +}
21518 +
21519 +
21520 +
21521 +static struct file_operations proc_nx_info_file_operations = {
21522 +       .read =         proc_nx_info_read,
21523 +};
21524 +
21525 +static struct dentry_operations proc_nid_dentry_operations = {
21526 +       .d_revalidate = proc_nid_revalidate,
21527 +};
21528 +
21529 +static struct vs_entry nx_base_stuff[] = {
21530 +       NINF("info",    S_IRUGO, nxi_info),
21531 +       NINF("status",  S_IRUGO, nxi_status),
21532 +       {}
21533 +};
21534 +
21535 +
21536 +static struct dentry *proc_nid_instantiate(struct inode *dir,
21537 +       struct dentry *dentry, int id, void *ptr)
21538 +{
21539 +       dentry->d_op = &proc_nid_dentry_operations;
21540 +       return vs_proc_instantiate(dir, dentry, id, ptr);
21541 +}
21542 +
21543 +static struct dentry *proc_nid_lookup(struct inode *dir,
21544 +       struct dentry *dentry, unsigned int flags)
21545 +{
21546 +       struct vs_entry *p = nx_base_stuff;
21547 +       struct dentry *error = ERR_PTR(-ENOENT);
21548 +
21549 +       for (; p->name; p++) {
21550 +               if (p->len != dentry->d_name.len)
21551 +                       continue;
21552 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21553 +                       break;
21554 +       }
21555 +       if (!p->name)
21556 +               goto out;
21557 +
21558 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
21559 +out:
21560 +       return error;
21561 +}
21562 +
21563 +static int proc_nid_readdir(struct file *filp,
21564 +       void *dirent, filldir_t filldir)
21565 +{
21566 +       struct dentry *dentry = filp->f_dentry;
21567 +       struct inode *inode = dentry->d_inode;
21568 +       struct vs_entry *p = nx_base_stuff;
21569 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
21570 +       int pos, index;
21571 +       u64 ino;
21572 +
21573 +       pos = filp->f_pos;
21574 +       switch (pos) {
21575 +       case 0:
21576 +               ino = inode->i_ino;
21577 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21578 +                       goto out;
21579 +               pos++;
21580 +               /* fall through */
21581 +       case 1:
21582 +               ino = parent_ino(dentry);
21583 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21584 +                       goto out;
21585 +               pos++;
21586 +               /* fall through */
21587 +       default:
21588 +               index = pos - 2;
21589 +               if (index >= size)
21590 +                       goto out;
21591 +               for (p += index; p->name; p++) {
21592 +                       if (vx_proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21593 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
21594 +                               goto out;
21595 +                       pos++;
21596 +               }
21597 +       }
21598 +out:
21599 +       filp->f_pos = pos;
21600 +       return 1;
21601 +}
21602 +
21603 +
21604 +#define MAX_MULBY10    ((~0U - 9) / 10)
21605 +
21606 +static inline int atovid(const char *str, int len)
21607 +{
21608 +       int vid, c;
21609 +
21610 +       vid = 0;
21611 +       while (len-- > 0) {
21612 +               c = *str - '0';
21613 +               str++;
21614 +               if (c > 9)
21615 +                       return -1;
21616 +               if (vid >= MAX_MULBY10)
21617 +                       return -1;
21618 +               vid *= 10;
21619 +               vid += c;
21620 +               if (!vid)
21621 +                       return -1;
21622 +       }
21623 +       return vid;
21624 +}
21625 +
21626 +/* now the upper level (virtual) */
21627 +
21628 +
21629 +static struct file_operations proc_xid_file_operations = {
21630 +       .read =         generic_read_dir,
21631 +       .readdir =      proc_xid_readdir,
21632 +};
21633 +
21634 +static struct inode_operations proc_xid_inode_operations = {
21635 +       .lookup =       proc_xid_lookup,
21636 +};
21637 +
21638 +static struct vs_entry vx_virtual_stuff[] = {
21639 +       INF("info",     S_IRUGO, virtual_info),
21640 +       INF("status",   S_IRUGO, virtual_status),
21641 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
21642 +};
21643 +
21644 +
21645 +static struct dentry *proc_virtual_lookup(struct inode *dir,
21646 +       struct dentry *dentry, unsigned int flags)
21647 +{
21648 +       struct vs_entry *p = vx_virtual_stuff;
21649 +       struct dentry *error = ERR_PTR(-ENOENT);
21650 +       int id = 0;
21651 +
21652 +       for (; p->name; p++) {
21653 +               if (p->len != dentry->d_name.len)
21654 +                       continue;
21655 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21656 +                       break;
21657 +       }
21658 +       if (p->name)
21659 +               goto instantiate;
21660 +
21661 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
21662 +       if ((id < 0) || !xid_is_hashed(id))
21663 +               goto out;
21664 +
21665 +instantiate:
21666 +       error = proc_xid_instantiate(dir, dentry, id, p);
21667 +out:
21668 +       return error;
21669 +}
21670 +
21671 +static struct file_operations proc_nid_file_operations = {
21672 +       .read =         generic_read_dir,
21673 +       .readdir =      proc_nid_readdir,
21674 +};
21675 +
21676 +static struct inode_operations proc_nid_inode_operations = {
21677 +       .lookup =       proc_nid_lookup,
21678 +};
21679 +
21680 +static struct vs_entry nx_virtnet_stuff[] = {
21681 +       INF("info",     S_IRUGO, virtnet_info),
21682 +       INF("status",   S_IRUGO, virtnet_status),
21683 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
21684 +};
21685 +
21686 +
21687 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
21688 +       struct dentry *dentry, unsigned int flags)
21689 +{
21690 +       struct vs_entry *p = nx_virtnet_stuff;
21691 +       struct dentry *error = ERR_PTR(-ENOENT);
21692 +       int id = 0;
21693 +
21694 +       for (; p->name; p++) {
21695 +               if (p->len != dentry->d_name.len)
21696 +                       continue;
21697 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21698 +                       break;
21699 +       }
21700 +       if (p->name)
21701 +               goto instantiate;
21702 +
21703 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
21704 +       if ((id < 0) || !nid_is_hashed(id))
21705 +               goto out;
21706 +
21707 +instantiate:
21708 +       error = proc_nid_instantiate(dir, dentry, id, p);
21709 +out:
21710 +       return error;
21711 +}
21712 +
21713 +
21714 +#define PROC_MAXVIDS 32
21715 +
21716 +int proc_virtual_readdir(struct file *filp,
21717 +       void *dirent, filldir_t filldir)
21718 +{
21719 +       struct dentry *dentry = filp->f_dentry;
21720 +       struct inode *inode = dentry->d_inode;
21721 +       struct vs_entry *p = vx_virtual_stuff;
21722 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
21723 +       int pos, index;
21724 +       unsigned int xid_array[PROC_MAXVIDS];
21725 +       char buf[PROC_NUMBUF];
21726 +       unsigned int nr_xids, i;
21727 +       u64 ino;
21728 +
21729 +       pos = filp->f_pos;
21730 +       switch (pos) {
21731 +       case 0:
21732 +               ino = inode->i_ino;
21733 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21734 +                       goto out;
21735 +               pos++;
21736 +               /* fall through */
21737 +       case 1:
21738 +               ino = parent_ino(dentry);
21739 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21740 +                       goto out;
21741 +               pos++;
21742 +               /* fall through */
21743 +       default:
21744 +               index = pos - 2;
21745 +               if (index >= size)
21746 +                       goto entries;
21747 +               for (p += index; p->name; p++) {
21748 +                       if (vx_proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21749 +                               vs_proc_instantiate, 0, p))
21750 +                               goto out;
21751 +                       pos++;
21752 +               }
21753 +       entries:
21754 +               index = pos - size;
21755 +               p = &vx_virtual_stuff[size - 1];
21756 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
21757 +               for (i = 0; i < nr_xids; i++) {
21758 +                       int n, xid = xid_array[i];
21759 +                       unsigned int j = PROC_NUMBUF;
21760 +
21761 +                       n = xid;
21762 +                       do
21763 +                               buf[--j] = '0' + (n % 10);
21764 +                       while (n /= 10);
21765 +
21766 +                       if (vx_proc_fill_cache(filp, dirent, filldir,
21767 +                               buf + j, PROC_NUMBUF - j,
21768 +                               vs_proc_instantiate, xid, p))
21769 +                               goto out;
21770 +                       pos++;
21771 +               }
21772 +       }
21773 +out:
21774 +       filp->f_pos = pos;
21775 +       return 0;
21776 +}
21777 +
21778 +static int proc_virtual_getattr(struct vfsmount *mnt,
21779 +       struct dentry *dentry, struct kstat *stat)
21780 +{
21781 +       struct inode *inode = dentry->d_inode;
21782 +
21783 +       generic_fillattr(inode, stat);
21784 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
21785 +       return 0;
21786 +}
21787 +
21788 +static struct file_operations proc_virtual_dir_operations = {
21789 +       .read =         generic_read_dir,
21790 +       .readdir =      proc_virtual_readdir,
21791 +};
21792 +
21793 +static struct inode_operations proc_virtual_dir_inode_operations = {
21794 +       .getattr =      proc_virtual_getattr,
21795 +       .lookup =       proc_virtual_lookup,
21796 +};
21797 +
21798 +
21799 +
21800 +
21801 +
21802 +int proc_virtnet_readdir(struct file *filp,
21803 +       void *dirent, filldir_t filldir)
21804 +{
21805 +       struct dentry *dentry = filp->f_dentry;
21806 +       struct inode *inode = dentry->d_inode;
21807 +       struct vs_entry *p = nx_virtnet_stuff;
21808 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
21809 +       int pos, index;
21810 +       unsigned int nid_array[PROC_MAXVIDS];
21811 +       char buf[PROC_NUMBUF];
21812 +       unsigned int nr_nids, i;
21813 +       u64 ino;
21814 +
21815 +       pos = filp->f_pos;
21816 +       switch (pos) {
21817 +       case 0:
21818 +               ino = inode->i_ino;
21819 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21820 +                       goto out;
21821 +               pos++;
21822 +               /* fall through */
21823 +       case 1:
21824 +               ino = parent_ino(dentry);
21825 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21826 +                       goto out;
21827 +               pos++;
21828 +               /* fall through */
21829 +       default:
21830 +               index = pos - 2;
21831 +               if (index >= size)
21832 +                       goto entries;
21833 +               for (p += index; p->name; p++) {
21834 +                       if (vx_proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21835 +                               vs_proc_instantiate, 0, p))
21836 +                               goto out;
21837 +                       pos++;
21838 +               }
21839 +       entries:
21840 +               index = pos - size;
21841 +               p = &nx_virtnet_stuff[size - 1];
21842 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
21843 +               for (i = 0; i < nr_nids; i++) {
21844 +                       int n, nid = nid_array[i];
21845 +                       unsigned int j = PROC_NUMBUF;
21846 +
21847 +                       n = nid;
21848 +                       do
21849 +                               buf[--j] = '0' + (n % 10);
21850 +                       while (n /= 10);
21851 +
21852 +                       if (vx_proc_fill_cache(filp, dirent, filldir,
21853 +                               buf + j, PROC_NUMBUF - j,
21854 +                               vs_proc_instantiate, nid, p))
21855 +                               goto out;
21856 +                       pos++;
21857 +               }
21858 +       }
21859 +out:
21860 +       filp->f_pos = pos;
21861 +       return 0;
21862 +}
21863 +
21864 +static int proc_virtnet_getattr(struct vfsmount *mnt,
21865 +       struct dentry *dentry, struct kstat *stat)
21866 +{
21867 +       struct inode *inode = dentry->d_inode;
21868 +
21869 +       generic_fillattr(inode, stat);
21870 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
21871 +       return 0;
21872 +}
21873 +
21874 +static struct file_operations proc_virtnet_dir_operations = {
21875 +       .read =         generic_read_dir,
21876 +       .readdir =      proc_virtnet_readdir,
21877 +};
21878 +
21879 +static struct inode_operations proc_virtnet_dir_inode_operations = {
21880 +       .getattr =      proc_virtnet_getattr,
21881 +       .lookup =       proc_virtnet_lookup,
21882 +};
21883 +
21884 +
21885 +
21886 +void proc_vx_init(void)
21887 +{
21888 +       struct proc_dir_entry *ent;
21889 +
21890 +       ent = proc_mkdir("virtual", 0);
21891 +       if (ent) {
21892 +               ent->proc_fops = &proc_virtual_dir_operations;
21893 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
21894 +       }
21895 +       proc_virtual = ent;
21896 +
21897 +       ent = proc_mkdir("virtnet", 0);
21898 +       if (ent) {
21899 +               ent->proc_fops = &proc_virtnet_dir_operations;
21900 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
21901 +       }
21902 +       proc_virtnet = ent;
21903 +}
21904 +
21905 +
21906 +
21907 +
21908 +/* per pid info */
21909 +
21910 +
21911 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
21912 +{
21913 +       struct vx_info *vxi;
21914 +       char *orig = buffer;
21915 +
21916 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
21917 +
21918 +       vxi = task_get_vx_info(p);
21919 +       if (!vxi)
21920 +               goto out;
21921 +
21922 +       buffer += sprintf(buffer, "BCaps:\t");
21923 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
21924 +       buffer += sprintf(buffer, "\n");
21925 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
21926 +               (unsigned long long)vxi->vx_ccaps);
21927 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
21928 +               (unsigned long long)vxi->vx_flags);
21929 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
21930 +
21931 +       put_vx_info(vxi);
21932 +out:
21933 +       return buffer - orig;
21934 +}
21935 +
21936 +
21937 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
21938 +{
21939 +       struct nx_info *nxi;
21940 +       struct nx_addr_v4 *v4a;
21941 +#ifdef CONFIG_IPV6
21942 +       struct nx_addr_v6 *v6a;
21943 +#endif
21944 +       char *orig = buffer;
21945 +       int i;
21946 +
21947 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
21948 +
21949 +       nxi = task_get_nx_info(p);
21950 +       if (!nxi)
21951 +               goto out;
21952 +
21953 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
21954 +               (unsigned long long)nxi->nx_ncaps);
21955 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
21956 +               (unsigned long long)nxi->nx_flags);
21957 +
21958 +       buffer += sprintf(buffer,
21959 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
21960 +               NIPQUAD(nxi->v4_bcast.s_addr));
21961 +       buffer += sprintf (buffer,
21962 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
21963 +               NIPQUAD(nxi->v4_lback.s_addr));
21964 +       if (!NX_IPV4(nxi))
21965 +               goto skip_v4;
21966 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
21967 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
21968 +                       i, NXAV4(v4a));
21969 +skip_v4:
21970 +#ifdef CONFIG_IPV6
21971 +       if (!NX_IPV6(nxi))
21972 +               goto skip_v6;
21973 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
21974 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
21975 +                       i, NXAV6(v6a));
21976 +skip_v6:
21977 +#endif
21978 +       put_nx_info(nxi);
21979 +out:
21980 +       return buffer - orig;
21981 +}
21982 +
21983 diff -NurpP --minimal linux-3.10.9/kernel/vserver/sched.c linux-3.10.9-vs2.3.6.6/kernel/vserver/sched.c
21984 --- linux-3.10.9/kernel/vserver/sched.c 1970-01-01 00:00:00.000000000 +0000
21985 +++ linux-3.10.9-vs2.3.6.6/kernel/vserver/sched.c       2013-08-22 20:30:00.000000000 +0000
21986 @@ -0,0 +1,83 @@
21987 +/*
21988 + *  linux/kernel/vserver/sched.c
21989 + *
21990 + *  Virtual Server: Scheduler Support
21991 + *
21992 + *  Copyright (C) 2004-2010  Herbert Pötzl
21993 + *
21994 + *  V0.01  adapted Sam Vilains version to 2.6.3
21995 + *  V0.02  removed legacy interface
21996 + *  V0.03  changed vcmds to vxi arg
21997 + *  V0.04  removed older and legacy interfaces
21998 + *  V0.05  removed scheduler code/commands
21999 + *
22000 + */
22001 +
22002 +#include <linux/vs_context.h>
22003 +#include <linux/vs_sched.h>
22004 +#include <linux/cpumask.h>
22005 +#include <linux/vserver/sched_cmd.h>
22006 +
22007 +#include <asm/uaccess.h>
22008 +
22009 +
22010 +void vx_update_sched_param(struct _vx_sched *sched,
22011 +       struct _vx_sched_pc *sched_pc)
22012 +{
22013 +       sched_pc->prio_bias = sched->prio_bias;
22014 +}
22015 +
22016 +static int do_set_prio_bias(struct vx_info *vxi, struct vcmd_prio_bias *data)
22017 +{
22018 +       int cpu;
22019 +
22020 +       if (data->prio_bias > MAX_PRIO_BIAS)
22021 +               data->prio_bias = MAX_PRIO_BIAS;
22022 +       if (data->prio_bias < MIN_PRIO_BIAS)
22023 +               data->prio_bias = MIN_PRIO_BIAS;
22024 +
22025 +       if (data->cpu_id != ~0) {
22026 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
22027 +               cpumask_and(&vxi->sched.update, &vxi->sched.update,
22028 +                       cpu_online_mask);
22029 +       } else
22030 +               cpumask_copy(&vxi->sched.update, cpu_online_mask);
22031 +
22032 +       for_each_cpu_mask(cpu, vxi->sched.update)
22033 +               vx_update_sched_param(&vxi->sched,
22034 +                       &vx_per_cpu(vxi, sched_pc, cpu));
22035 +       return 0;
22036 +}
22037 +
22038 +int vc_set_prio_bias(struct vx_info *vxi, void __user *data)
22039 +{
22040 +       struct vcmd_prio_bias vc_data;
22041 +
22042 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22043 +               return -EFAULT;
22044 +
22045 +       return do_set_prio_bias(vxi, &vc_data);
22046 +}
22047 +
22048 +int vc_get_prio_bias(struct vx_info *vxi, void __user *data)
22049 +{
22050 +       struct vcmd_prio_bias vc_data;
22051 +       struct _vx_sched_pc *pcd;
22052 +       int cpu;
22053 +
22054 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22055 +               return -EFAULT;
22056 +
22057 +       cpu = vc_data.cpu_id;
22058 +
22059 +       if (!cpu_possible(cpu))
22060 +               return -EINVAL;
22061 +
22062 +       pcd = &vx_per_cpu(vxi, sched_pc, cpu);
22063 +       vc_data.prio_bias = pcd->prio_bias;
22064 +
22065 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22066 +               return -EFAULT;
22067 +       return 0;
22068 +}
22069 +
22070 diff -NurpP --minimal linux-3.10.9/kernel/vserver/sched_init.h linux-3.10.9-vs2.3.6.6/kernel/vserver/sched_init.h
22071 --- linux-3.10.9/kernel/vserver/sched_init.h    1970-01-01 00:00:00.000000000 +0000
22072 +++ linux-3.10.9-vs2.3.6.6/kernel/vserver/sched_init.h  2013-08-22 20:30:00.000000000 +0000
22073 @@ -0,0 +1,27 @@
22074 +
22075 +static inline void vx_info_init_sched(struct _vx_sched *sched)
22076 +{
22077 +       /* scheduling; hard code starting values as constants */
22078 +       sched->prio_bias = 0;
22079 +}
22080 +
22081 +static inline
22082 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22083 +{
22084 +       sched_pc->prio_bias = 0;
22085 +
22086 +       sched_pc->user_ticks = 0;
22087 +       sched_pc->sys_ticks = 0;
22088 +       sched_pc->hold_ticks = 0;
22089 +}
22090 +
22091 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
22092 +{
22093 +       return;
22094 +}
22095 +
22096 +static inline
22097 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22098 +{
22099 +       return;
22100 +}
22101 diff -NurpP --minimal linux-3.10.9/kernel/vserver/sched_proc.h linux-3.10.9-vs2.3.6.6/kernel/vserver/sched_proc.h
22102 --- linux-3.10.9/kernel/vserver/sched_proc.h    1970-01-01 00:00:00.000000000 +0000
22103 +++ linux-3.10.9-vs2.3.6.6/kernel/vserver/sched_proc.h  2013-08-22 20:30:00.000000000 +0000
22104 @@ -0,0 +1,32 @@
22105 +#ifndef _VX_SCHED_PROC_H
22106 +#define _VX_SCHED_PROC_H
22107 +
22108 +
22109 +static inline
22110 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
22111 +{
22112 +       int length = 0;
22113 +
22114 +       length += sprintf(buffer,
22115 +               "PrioBias:\t%8d\n",
22116 +               sched->prio_bias);
22117 +       return length;
22118 +}
22119 +
22120 +static inline
22121 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
22122 +       char *buffer, int cpu)
22123 +{
22124 +       int length = 0;
22125 +
22126 +       length += sprintf(buffer + length,
22127 +               "cpu %d: %lld %lld %lld", cpu,
22128 +               (unsigned long long)sched_pc->user_ticks,
22129 +               (unsigned long long)sched_pc->sys_ticks,
22130 +               (unsigned long long)sched_pc->hold_ticks);
22131 +       length += sprintf(buffer + length,
22132 +               " %d\n", sched_pc->prio_bias);
22133 +       return length;
22134 +}
22135 +
22136 +#endif /* _VX_SCHED_PROC_H */
22137 diff -NurpP --minimal linux-3.10.9/kernel/vserver/signal.c linux-3.10.9-vs2.3.6.6/kernel/vserver/signal.c
22138 --- linux-3.10.9/kernel/vserver/signal.c        1970-01-01 00:00:00.000000000 +0000
22139 +++ linux-3.10.9-vs2.3.6.6/kernel/vserver/signal.c      2013-08-22 20:30:00.000000000 +0000
22140 @@ -0,0 +1,134 @@
22141 +/*
22142 + *  linux/kernel/vserver/signal.c
22143 + *
22144 + *  Virtual Server: Signal Support
22145 + *
22146 + *  Copyright (C) 2003-2007  Herbert Pötzl
22147 + *
22148 + *  V0.01  broken out from vcontext V0.05
22149 + *  V0.02  changed vcmds to vxi arg
22150 + *  V0.03  adjusted siginfo for kill
22151 + *
22152 + */
22153 +
22154 +#include <asm/uaccess.h>
22155 +
22156 +#include <linux/vs_context.h>
22157 +#include <linux/vs_pid.h>
22158 +#include <linux/vserver/signal_cmd.h>
22159 +
22160 +
22161 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
22162 +{
22163 +       int retval, count = 0;
22164 +       struct task_struct *p;
22165 +       struct siginfo *sip = SEND_SIG_PRIV;
22166 +
22167 +       retval = -ESRCH;
22168 +       vxdprintk(VXD_CBIT(misc, 4),
22169 +               "vx_info_kill(%p[#%d],%d,%d)*",
22170 +               vxi, vxi->vx_id, pid, sig);
22171 +       read_lock(&tasklist_lock);
22172 +       switch (pid) {
22173 +       case  0:
22174 +       case -1:
22175 +               for_each_process(p) {
22176 +                       int err = 0;
22177 +
22178 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
22179 +                               (pid && vxi->vx_initpid == p->pid))
22180 +                               continue;
22181 +
22182 +                       err = group_send_sig_info(sig, sip, p);
22183 +                       ++count;
22184 +                       if (err != -EPERM)
22185 +                               retval = err;
22186 +               }
22187 +               break;
22188 +
22189 +       case 1:
22190 +               if (vxi->vx_initpid) {
22191 +                       pid = vxi->vx_initpid;
22192 +                       /* for now, only SIGINT to private init ... */
22193 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22194 +                               /* ... as long as there are tasks left */
22195 +                               (atomic_read(&vxi->vx_tasks) > 1))
22196 +                               sig = SIGINT;
22197 +               }
22198 +               /* fallthrough */
22199 +       default:
22200 +               rcu_read_lock();
22201 +               p = find_task_by_real_pid(pid);
22202 +               rcu_read_unlock();
22203 +               if (p) {
22204 +                       if (vx_task_xid(p) == vxi->vx_id)
22205 +                               retval = group_send_sig_info(sig, sip, p);
22206 +               }
22207 +               break;
22208 +       }
22209 +       read_unlock(&tasklist_lock);
22210 +       vxdprintk(VXD_CBIT(misc, 4),
22211 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
22212 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
22213 +       return retval;
22214 +}
22215 +
22216 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
22217 +{
22218 +       struct vcmd_ctx_kill_v0 vc_data;
22219 +
22220 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22221 +               return -EFAULT;
22222 +
22223 +       /* special check to allow guest shutdown */
22224 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22225 +               /* forbid killall pid=0 when init is present */
22226 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
22227 +               (vc_data.pid > 1)))
22228 +               return -EACCES;
22229 +
22230 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
22231 +}
22232 +
22233 +
22234 +static int __wait_exit(struct vx_info *vxi)
22235 +{
22236 +       DECLARE_WAITQUEUE(wait, current);
22237 +       int ret = 0;
22238 +
22239 +       add_wait_queue(&vxi->vx_wait, &wait);
22240 +       set_current_state(TASK_INTERRUPTIBLE);
22241 +
22242 +wait:
22243 +       if (vx_info_state(vxi,
22244 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
22245 +               goto out;
22246 +       if (signal_pending(current)) {
22247 +               ret = -ERESTARTSYS;
22248 +               goto out;
22249 +       }
22250 +       schedule();
22251 +       goto wait;
22252 +
22253 +out:
22254 +       set_current_state(TASK_RUNNING);
22255 +       remove_wait_queue(&vxi->vx_wait, &wait);
22256 +       return ret;
22257 +}
22258 +
22259 +
22260 +
22261 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
22262 +{
22263 +       struct vcmd_wait_exit_v0 vc_data;
22264 +       int ret;
22265 +
22266 +       ret = __wait_exit(vxi);
22267 +       vc_data.reboot_cmd = vxi->reboot_cmd;
22268 +       vc_data.exit_code = vxi->exit_code;
22269 +
22270 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22271 +               ret = -EFAULT;
22272 +       return ret;
22273 +}
22274 +
22275 diff -NurpP --minimal linux-3.10.9/kernel/vserver/space.c linux-3.10.9-vs2.3.6.6/kernel/vserver/space.c
22276 --- linux-3.10.9/kernel/vserver/space.c 1970-01-01 00:00:00.000000000 +0000
22277 +++ linux-3.10.9-vs2.3.6.6/kernel/vserver/space.c       2013-08-22 20:30:00.000000000 +0000
22278 @@ -0,0 +1,436 @@
22279 +/*
22280 + *  linux/kernel/vserver/space.c
22281 + *
22282 + *  Virtual Server: Context Space Support
22283 + *
22284 + *  Copyright (C) 2003-2010  Herbert Pötzl
22285 + *
22286 + *  V0.01  broken out from context.c 0.07
22287 + *  V0.02  added task locking for namespace
22288 + *  V0.03  broken out vx_enter_namespace
22289 + *  V0.04  added *space support and commands
22290 + *  V0.05  added credential support
22291 + *
22292 + */
22293 +
22294 +#include <linux/utsname.h>
22295 +#include <linux/nsproxy.h>
22296 +#include <linux/err.h>
22297 +#include <linux/fs_struct.h>
22298 +#include <linux/cred.h>
22299 +#include <asm/uaccess.h>
22300 +
22301 +#include <linux/vs_context.h>
22302 +#include <linux/vserver/space.h>
22303 +#include <linux/vserver/space_cmd.h>
22304 +
22305 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
22306 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
22307 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
22308 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
22309 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
22310 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
22311 +
22312 +
22313 +/* namespace functions */
22314 +
22315 +#include <linux/mnt_namespace.h>
22316 +#include <linux/user_namespace.h>
22317 +#include <linux/pid_namespace.h>
22318 +#include <linux/ipc_namespace.h>
22319 +#include <net/net_namespace.h>
22320 +#include "../fs/mount.h"
22321 +
22322 +
22323 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
22324 +       .mask = CLONE_FS |
22325 +               CLONE_NEWNS |
22326 +#ifdef CONFIG_UTS_NS
22327 +               CLONE_NEWUTS |
22328 +#endif
22329 +#ifdef CONFIG_IPC_NS
22330 +               CLONE_NEWIPC |
22331 +#endif
22332 +#ifdef CONFIG_USER_NS
22333 +               CLONE_NEWUSER |
22334 +#endif
22335 +               0
22336 +};
22337 +
22338 +static const struct vcmd_space_mask_v1 space_mask = {
22339 +       .mask = CLONE_FS |
22340 +               CLONE_NEWNS |
22341 +#ifdef CONFIG_UTS_NS
22342 +               CLONE_NEWUTS |
22343 +#endif
22344 +#ifdef CONFIG_IPC_NS
22345 +               CLONE_NEWIPC |
22346 +#endif
22347 +#ifdef CONFIG_USER_NS
22348 +               CLONE_NEWUSER |
22349 +#endif
22350 +#ifdef CONFIG_PID_NS
22351 +               CLONE_NEWPID |
22352 +#endif
22353 +#ifdef CONFIG_NET_NS
22354 +               CLONE_NEWNET |
22355 +#endif
22356 +               0
22357 +};
22358 +
22359 +static const struct vcmd_space_mask_v1 default_space_mask = {
22360 +       .mask = CLONE_FS |
22361 +               CLONE_NEWNS |
22362 +#ifdef CONFIG_UTS_NS
22363 +               CLONE_NEWUTS |
22364 +#endif
22365 +#ifdef CONFIG_IPC_NS
22366 +               CLONE_NEWIPC |
22367 +#endif
22368 +#ifdef CONFIG_USER_NS
22369 +               CLONE_NEWUSER |
22370 +#endif
22371 +#ifdef CONFIG_PID_NS
22372 +//             CLONE_NEWPID |
22373 +#endif
22374 +               0
22375 +};
22376 +
22377 +/*
22378 + *     build a new nsproxy mix
22379 + *      assumes that both proxies are 'const'
22380 + *     does not touch nsproxy refcounts
22381 + *     will hold a reference on the result.
22382 + */
22383 +
22384 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
22385 +       struct nsproxy *new_nsproxy, unsigned long mask)
22386 +{
22387 +       struct mnt_namespace *old_ns;
22388 +       struct uts_namespace *old_uts;
22389 +       struct ipc_namespace *old_ipc;
22390 +#ifdef CONFIG_PID_NS
22391 +       struct pid_namespace *old_pid;
22392 +#endif
22393 +#ifdef CONFIG_NET_NS
22394 +       struct net *old_net;
22395 +#endif
22396 +       struct nsproxy *nsproxy;
22397 +
22398 +       nsproxy = copy_nsproxy(old_nsproxy);
22399 +       if (!nsproxy)
22400 +               goto out;
22401 +
22402 +       if (mask & CLONE_NEWNS) {
22403 +               old_ns = nsproxy->mnt_ns;
22404 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
22405 +               if (nsproxy->mnt_ns)
22406 +                       get_mnt_ns(nsproxy->mnt_ns);
22407 +       } else
22408 +               old_ns = NULL;
22409 +
22410 +       if (mask & CLONE_NEWUTS) {
22411 +               old_uts = nsproxy->uts_ns;
22412 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
22413 +               if (nsproxy->uts_ns)
22414 +                       get_uts_ns(nsproxy->uts_ns);
22415 +       } else
22416 +               old_uts = NULL;
22417 +
22418 +       if (mask & CLONE_NEWIPC) {
22419 +               old_ipc = nsproxy->ipc_ns;
22420 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
22421 +               if (nsproxy->ipc_ns)
22422 +                       get_ipc_ns(nsproxy->ipc_ns);
22423 +       } else
22424 +               old_ipc = NULL;
22425 +
22426 +#ifdef CONFIG_PID_NS
22427 +       if (mask & CLONE_NEWPID) {
22428 +               old_pid = nsproxy->pid_ns;
22429 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
22430 +               if (nsproxy->pid_ns)
22431 +                       get_pid_ns(nsproxy->pid_ns);
22432 +       } else
22433 +               old_pid = NULL;
22434 +#endif
22435 +#ifdef CONFIG_NET_NS
22436 +       if (mask & CLONE_NEWNET) {
22437 +               old_net = nsproxy->net_ns;
22438 +               nsproxy->net_ns = new_nsproxy->net_ns;
22439 +               if (nsproxy->net_ns)
22440 +                       get_net(nsproxy->net_ns);
22441 +       } else
22442 +               old_net = NULL;
22443 +#endif
22444 +       if (old_ns)
22445 +               put_mnt_ns(old_ns);
22446 +       if (old_uts)
22447 +               put_uts_ns(old_uts);
22448 +       if (old_ipc)
22449 +               put_ipc_ns(old_ipc);
22450 +#ifdef CONFIG_PID_NS
22451 +       if (old_pid)
22452 +               put_pid_ns(old_pid);
22453 +#endif
22454 +#ifdef CONFIG_NET_NS
22455 +       if (old_net)
22456 +               put_net(old_net);
22457 +#endif
22458 +out:
22459 +       return nsproxy;
22460 +}
22461 +
22462 +
22463 +/*
22464 + *     merge two nsproxy structs into a new one.
22465 + *     will hold a reference on the result.
22466 + */
22467 +
22468 +static inline
22469 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
22470 +       struct nsproxy *proxy, unsigned long mask)
22471 +{
22472 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
22473 +
22474 +       if (!proxy)
22475 +               return NULL;
22476 +
22477 +       if (mask) {
22478 +               /* vs_mix_nsproxy returns with reference */
22479 +               return vs_mix_nsproxy(old ? old : &null_proxy,
22480 +                       proxy, mask);
22481 +       }
22482 +       get_nsproxy(proxy);
22483 +       return proxy;
22484 +}
22485 +
22486 +
22487 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
22488 +{
22489 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
22490 +       struct fs_struct *fs_cur, *fs = NULL;
22491 +       struct _vx_space *space;
22492 +       int ret, kill = 0;
22493 +
22494 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
22495 +               vxi, vxi->vx_id, mask, index);
22496 +
22497 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
22498 +               return -EACCES;
22499 +
22500 +       if (index >= VX_SPACES)
22501 +               return -EINVAL;
22502 +
22503 +       space = &vxi->space[index];
22504 +
22505 +       if (!mask)
22506 +               mask = space->vx_nsmask;
22507 +
22508 +       if ((mask & space->vx_nsmask) != mask)
22509 +               return -EINVAL;
22510 +
22511 +       if (mask & CLONE_FS) {
22512 +               fs = copy_fs_struct(space->vx_fs);
22513 +               if (!fs)
22514 +                       return -ENOMEM;
22515 +       }
22516 +       proxy = space->vx_nsproxy;
22517 +
22518 +       vxdprintk(VXD_CBIT(space, 9),
22519 +               "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
22520 +               vxi, vxi->vx_id, mask, index, proxy, fs);
22521 +
22522 +       task_lock(current);
22523 +       fs_cur = current->fs;
22524 +
22525 +       if (mask & CLONE_FS) {
22526 +               spin_lock(&fs_cur->lock);
22527 +               current->fs = fs;
22528 +               kill = !--fs_cur->users;
22529 +               spin_unlock(&fs_cur->lock);
22530 +       }
22531 +
22532 +       proxy_cur = current->nsproxy;
22533 +       get_nsproxy(proxy_cur);
22534 +       task_unlock(current);
22535 +
22536 +       if (kill)
22537 +               free_fs_struct(fs_cur);
22538 +
22539 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
22540 +       if (IS_ERR(proxy_new)) {
22541 +               ret = PTR_ERR(proxy_new);
22542 +               goto out_put;
22543 +       }
22544 +
22545 +       proxy_new = xchg(&current->nsproxy, proxy_new);
22546 +
22547 +       if (mask & CLONE_NEWUSER) {
22548 +               struct cred *cred;
22549 +
22550 +               vxdprintk(VXD_CBIT(space, 10),
22551 +                       "vx_enter_space(%p[#%u],%p) cred (%p,%p)",
22552 +                       vxi, vxi->vx_id, space->vx_cred,
22553 +                       current->real_cred, current->cred);
22554 +
22555 +               if (space->vx_cred) {
22556 +                       cred = __prepare_creds(space->vx_cred);
22557 +                       if (cred)
22558 +                               commit_creds(cred);
22559 +               }
22560 +       }
22561 +
22562 +       ret = 0;
22563 +
22564 +       if (proxy_new)
22565 +               put_nsproxy(proxy_new);
22566 +out_put:
22567 +       if (proxy_cur)
22568 +               put_nsproxy(proxy_cur);
22569 +       return ret;
22570 +}
22571 +
22572 +
22573 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
22574 +{
22575 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
22576 +       struct fs_struct *fs_vxi, *fs = NULL;
22577 +       struct _vx_space *space;
22578 +       int ret, kill = 0;
22579 +
22580 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
22581 +               vxi, vxi->vx_id, mask, index);
22582 +
22583 +       if ((mask & space_mask.mask) != mask)
22584 +               return -EINVAL;
22585 +
22586 +       if (index >= VX_SPACES)
22587 +               return -EINVAL;
22588 +
22589 +       space = &vxi->space[index];
22590 +
22591 +       proxy_vxi = space->vx_nsproxy;
22592 +       fs_vxi = space->vx_fs;
22593 +
22594 +       if (mask & CLONE_FS) {
22595 +               fs = copy_fs_struct(current->fs);
22596 +               if (!fs)
22597 +                       return -ENOMEM;
22598 +       }
22599 +
22600 +       task_lock(current);
22601 +
22602 +       if (mask & CLONE_FS) {
22603 +               spin_lock(&fs_vxi->lock);
22604 +               space->vx_fs = fs;
22605 +               kill = !--fs_vxi->users;
22606 +               spin_unlock(&fs_vxi->lock);
22607 +       }
22608 +
22609 +       proxy_cur = current->nsproxy;
22610 +       get_nsproxy(proxy_cur);
22611 +       task_unlock(current);
22612 +
22613 +       if (kill)
22614 +               free_fs_struct(fs_vxi);
22615 +
22616 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
22617 +       if (IS_ERR(proxy_new)) {
22618 +               ret = PTR_ERR(proxy_new);
22619 +               goto out_put;
22620 +       }
22621 +
22622 +       proxy_new = xchg(&space->vx_nsproxy, proxy_new);
22623 +       space->vx_nsmask |= mask;
22624 +
22625 +       if (mask & CLONE_NEWUSER) {
22626 +               struct cred *cred;
22627 +
22628 +               vxdprintk(VXD_CBIT(space, 10),
22629 +                       "vx_set_space(%p[#%u],%p) cred (%p,%p)",
22630 +                       vxi, vxi->vx_id, space->vx_cred,
22631 +                       current->real_cred, current->cred);
22632 +
22633 +               cred = prepare_creds();
22634 +               cred = (struct cred *)xchg(&space->vx_cred, cred);
22635 +               if (cred)
22636 +                       abort_creds(cred);
22637 +       }
22638 +
22639 +       ret = 0;
22640 +
22641 +       if (proxy_new)
22642 +               put_nsproxy(proxy_new);
22643 +out_put:
22644 +       if (proxy_cur)
22645 +               put_nsproxy(proxy_cur);
22646 +       return ret;
22647 +}
22648 +
22649 +
22650 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
22651 +{
22652 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22653 +
22654 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22655 +               return -EFAULT;
22656 +
22657 +       return vx_enter_space(vxi, vc_data.mask, 0);
22658 +}
22659 +
22660 +int vc_enter_space(struct vx_info *vxi, void __user *data)
22661 +{
22662 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22663 +
22664 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22665 +               return -EFAULT;
22666 +
22667 +       if (vc_data.index >= VX_SPACES)
22668 +               return -EINVAL;
22669 +
22670 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
22671 +}
22672 +
22673 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
22674 +{
22675 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22676 +
22677 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22678 +               return -EFAULT;
22679 +
22680 +       return vx_set_space(vxi, vc_data.mask, 0);
22681 +}
22682 +
22683 +int vc_set_space(struct vx_info *vxi, void __user *data)
22684 +{
22685 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22686 +
22687 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22688 +               return -EFAULT;
22689 +
22690 +       if (vc_data.index >= VX_SPACES)
22691 +               return -EINVAL;
22692 +
22693 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
22694 +}
22695 +
22696 +int vc_get_space_mask(void __user *data, int type)
22697 +{
22698 +       const struct vcmd_space_mask_v1 *mask;
22699 +
22700 +       if (type == 0)
22701 +               mask = &space_mask_v0;
22702 +       else if (type == 1)
22703 +               mask = &space_mask;
22704 +       else
22705 +               mask = &default_space_mask;
22706 +
22707 +       vxdprintk(VXD_CBIT(space, 10),
22708 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
22709 +
22710 +       if (copy_to_user(data, mask, sizeof(*mask)))
22711 +               return -EFAULT;
22712 +       return 0;
22713 +}
22714 +
22715 diff -NurpP --minimal linux-3.10.9/kernel/vserver/switch.c linux-3.10.9-vs2.3.6.6/kernel/vserver/switch.c
22716 --- linux-3.10.9/kernel/vserver/switch.c        1970-01-01 00:00:00.000000000 +0000
22717 +++ linux-3.10.9-vs2.3.6.6/kernel/vserver/switch.c      2013-08-22 20:30:00.000000000 +0000
22718 @@ -0,0 +1,556 @@
22719 +/*
22720 + *  linux/kernel/vserver/switch.c
22721 + *
22722 + *  Virtual Server: Syscall Switch
22723 + *
22724 + *  Copyright (C) 2003-2011  Herbert Pötzl
22725 + *
22726 + *  V0.01  syscall switch
22727 + *  V0.02  added signal to context
22728 + *  V0.03  added rlimit functions
22729 + *  V0.04  added iattr, task/xid functions
22730 + *  V0.05  added debug/history stuff
22731 + *  V0.06  added compat32 layer
22732 + *  V0.07  vcmd args and perms
22733 + *  V0.08  added status commands
22734 + *  V0.09  added tag commands
22735 + *  V0.10  added oom bias
22736 + *  V0.11  added device commands
22737 + *  V0.12  added warn mask
22738 + *
22739 + */
22740 +
22741 +#include <linux/vs_context.h>
22742 +#include <linux/vs_network.h>
22743 +#include <linux/vserver/switch.h>
22744 +
22745 +#include "vci_config.h"
22746 +
22747 +
22748 +static inline
22749 +int vc_get_version(uint32_t id)
22750 +{
22751 +       return VCI_VERSION;
22752 +}
22753 +
22754 +static inline
22755 +int vc_get_vci(uint32_t id)
22756 +{
22757 +       return vci_kernel_config();
22758 +}
22759 +
22760 +#include <linux/vserver/context_cmd.h>
22761 +#include <linux/vserver/cvirt_cmd.h>
22762 +#include <linux/vserver/cacct_cmd.h>
22763 +#include <linux/vserver/limit_cmd.h>
22764 +#include <linux/vserver/network_cmd.h>
22765 +#include <linux/vserver/sched_cmd.h>
22766 +#include <linux/vserver/debug_cmd.h>
22767 +#include <linux/vserver/inode_cmd.h>
22768 +#include <linux/vserver/dlimit_cmd.h>
22769 +#include <linux/vserver/signal_cmd.h>
22770 +#include <linux/vserver/space_cmd.h>
22771 +#include <linux/vserver/tag_cmd.h>
22772 +#include <linux/vserver/device_cmd.h>
22773 +
22774 +#include <linux/vserver/inode.h>
22775 +#include <linux/vserver/dlimit.h>
22776 +
22777 +
22778 +#ifdef CONFIG_COMPAT
22779 +#define __COMPAT(name, id, data, compat)       \
22780 +       (compat) ? name ## _x32(id, data) : name(id, data)
22781 +#define __COMPAT_NO_ID(name, data, compat)     \
22782 +       (compat) ? name ## _x32(data) : name(data)
22783 +#else
22784 +#define __COMPAT(name, id, data, compat)       \
22785 +       name(id, data)
22786 +#define __COMPAT_NO_ID(name, data, compat)     \
22787 +       name(data)
22788 +#endif
22789 +
22790 +
22791 +static inline
22792 +long do_vcmd(uint32_t cmd, uint32_t id,
22793 +       struct vx_info *vxi, struct nx_info *nxi,
22794 +       void __user *data, int compat)
22795 +{
22796 +       switch (cmd) {
22797 +
22798 +       case VCMD_get_version:
22799 +               return vc_get_version(id);
22800 +       case VCMD_get_vci:
22801 +               return vc_get_vci(id);
22802 +
22803 +       case VCMD_task_xid:
22804 +               return vc_task_xid(id);
22805 +       case VCMD_vx_info:
22806 +               return vc_vx_info(vxi, data);
22807 +
22808 +       case VCMD_task_nid:
22809 +               return vc_task_nid(id);
22810 +       case VCMD_nx_info:
22811 +               return vc_nx_info(nxi, data);
22812 +
22813 +       case VCMD_task_tag:
22814 +               return vc_task_tag(id);
22815 +
22816 +       case VCMD_set_space_v1:
22817 +               return vc_set_space_v1(vxi, data);
22818 +       /* this is version 2 */
22819 +       case VCMD_set_space:
22820 +               return vc_set_space(vxi, data);
22821 +
22822 +       case VCMD_get_space_mask_v0:
22823 +               return vc_get_space_mask(data, 0);
22824 +       /* this is version 1 */
22825 +       case VCMD_get_space_mask:
22826 +               return vc_get_space_mask(data, 1);
22827 +
22828 +       case VCMD_get_space_default:
22829 +               return vc_get_space_mask(data, -1);
22830 +
22831 +       case VCMD_set_umask:
22832 +               return vc_set_umask(vxi, data);
22833 +
22834 +       case VCMD_get_umask:
22835 +               return vc_get_umask(vxi, data);
22836 +
22837 +       case VCMD_set_wmask:
22838 +               return vc_set_wmask(vxi, data);
22839 +
22840 +       case VCMD_get_wmask:
22841 +               return vc_get_wmask(vxi, data);
22842 +#ifdef CONFIG_IA32_EMULATION
22843 +       case VCMD_get_rlimit:
22844 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
22845 +       case VCMD_set_rlimit:
22846 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
22847 +#else
22848 +       case VCMD_get_rlimit:
22849 +               return vc_get_rlimit(vxi, data);
22850 +       case VCMD_set_rlimit:
22851 +               return vc_set_rlimit(vxi, data);
22852 +#endif
22853 +       case VCMD_get_rlimit_mask:
22854 +               return vc_get_rlimit_mask(id, data);
22855 +       case VCMD_reset_hits:
22856 +               return vc_reset_hits(vxi, data);
22857 +       case VCMD_reset_minmax:
22858 +               return vc_reset_minmax(vxi, data);
22859 +
22860 +       case VCMD_get_vhi_name:
22861 +               return vc_get_vhi_name(vxi, data);
22862 +       case VCMD_set_vhi_name:
22863 +               return vc_set_vhi_name(vxi, data);
22864 +
22865 +       case VCMD_ctx_stat:
22866 +               return vc_ctx_stat(vxi, data);
22867 +       case VCMD_virt_stat:
22868 +               return vc_virt_stat(vxi, data);
22869 +       case VCMD_sock_stat:
22870 +               return vc_sock_stat(vxi, data);
22871 +       case VCMD_rlimit_stat:
22872 +               return vc_rlimit_stat(vxi, data);
22873 +
22874 +       case VCMD_set_cflags:
22875 +               return vc_set_cflags(vxi, data);
22876 +       case VCMD_get_cflags:
22877 +               return vc_get_cflags(vxi, data);
22878 +
22879 +       /* this is version 1 */
22880 +       case VCMD_set_ccaps:
22881 +               return vc_set_ccaps(vxi, data);
22882 +       /* this is version 1 */
22883 +       case VCMD_get_ccaps:
22884 +               return vc_get_ccaps(vxi, data);
22885 +       case VCMD_set_bcaps:
22886 +               return vc_set_bcaps(vxi, data);
22887 +       case VCMD_get_bcaps:
22888 +               return vc_get_bcaps(vxi, data);
22889 +
22890 +       case VCMD_set_badness:
22891 +               return vc_set_badness(vxi, data);
22892 +       case VCMD_get_badness:
22893 +               return vc_get_badness(vxi, data);
22894 +
22895 +       case VCMD_set_nflags:
22896 +               return vc_set_nflags(nxi, data);
22897 +       case VCMD_get_nflags:
22898 +               return vc_get_nflags(nxi, data);
22899 +
22900 +       case VCMD_set_ncaps:
22901 +               return vc_set_ncaps(nxi, data);
22902 +       case VCMD_get_ncaps:
22903 +               return vc_get_ncaps(nxi, data);
22904 +
22905 +       case VCMD_set_prio_bias:
22906 +               return vc_set_prio_bias(vxi, data);
22907 +       case VCMD_get_prio_bias:
22908 +               return vc_get_prio_bias(vxi, data);
22909 +       case VCMD_add_dlimit:
22910 +               return __COMPAT(vc_add_dlimit, id, data, compat);
22911 +       case VCMD_rem_dlimit:
22912 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
22913 +       case VCMD_set_dlimit:
22914 +               return __COMPAT(vc_set_dlimit, id, data, compat);
22915 +       case VCMD_get_dlimit:
22916 +               return __COMPAT(vc_get_dlimit, id, data, compat);
22917 +
22918 +       case VCMD_ctx_kill:
22919 +               return vc_ctx_kill(vxi, data);
22920 +
22921 +       case VCMD_wait_exit:
22922 +               return vc_wait_exit(vxi, data);
22923 +
22924 +       case VCMD_get_iattr:
22925 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
22926 +       case VCMD_set_iattr:
22927 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
22928 +
22929 +       case VCMD_fget_iattr:
22930 +               return vc_fget_iattr(id, data);
22931 +       case VCMD_fset_iattr:
22932 +               return vc_fset_iattr(id, data);
22933 +
22934 +       case VCMD_enter_space_v0:
22935 +               return vc_enter_space_v1(vxi, NULL);
22936 +       case VCMD_enter_space_v1:
22937 +               return vc_enter_space_v1(vxi, data);
22938 +       /* this is version 2 */
22939 +       case VCMD_enter_space:
22940 +               return vc_enter_space(vxi, data);
22941 +
22942 +       case VCMD_ctx_create_v0:
22943 +               return vc_ctx_create(id, NULL);
22944 +       case VCMD_ctx_create:
22945 +               return vc_ctx_create(id, data);
22946 +       case VCMD_ctx_migrate_v0:
22947 +               return vc_ctx_migrate(vxi, NULL);
22948 +       case VCMD_ctx_migrate:
22949 +               return vc_ctx_migrate(vxi, data);
22950 +
22951 +       case VCMD_net_create_v0:
22952 +               return vc_net_create(id, NULL);
22953 +       case VCMD_net_create:
22954 +               return vc_net_create(id, data);
22955 +       case VCMD_net_migrate:
22956 +               return vc_net_migrate(nxi, data);
22957 +
22958 +       case VCMD_tag_migrate:
22959 +               return vc_tag_migrate(id);
22960 +
22961 +       case VCMD_net_add:
22962 +               return vc_net_add(nxi, data);
22963 +       case VCMD_net_remove:
22964 +               return vc_net_remove(nxi, data);
22965 +
22966 +       case VCMD_net_add_ipv4_v1:
22967 +               return vc_net_add_ipv4_v1(nxi, data);
22968 +       /* this is version 2 */
22969 +       case VCMD_net_add_ipv4:
22970 +               return vc_net_add_ipv4(nxi, data);
22971 +
22972 +       case VCMD_net_rem_ipv4_v1:
22973 +               return vc_net_rem_ipv4_v1(nxi, data);
22974 +       /* this is version 2 */
22975 +       case VCMD_net_rem_ipv4:
22976 +               return vc_net_rem_ipv4(nxi, data);
22977 +#ifdef CONFIG_IPV6
22978 +       case VCMD_net_add_ipv6:
22979 +               return vc_net_add_ipv6(nxi, data);
22980 +       case VCMD_net_remove_ipv6:
22981 +               return vc_net_remove_ipv6(nxi, data);
22982 +#endif
22983 +/*     case VCMD_add_match_ipv4:
22984 +               return vc_add_match_ipv4(nxi, data);
22985 +       case VCMD_get_match_ipv4:
22986 +               return vc_get_match_ipv4(nxi, data);
22987 +#ifdef CONFIG_IPV6
22988 +       case VCMD_add_match_ipv6:
22989 +               return vc_add_match_ipv6(nxi, data);
22990 +       case VCMD_get_match_ipv6:
22991 +               return vc_get_match_ipv6(nxi, data);
22992 +#endif */
22993 +
22994 +#ifdef CONFIG_VSERVER_DEVICE
22995 +       case VCMD_set_mapping:
22996 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
22997 +       case VCMD_unset_mapping:
22998 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
22999 +#endif
23000 +#ifdef CONFIG_VSERVER_HISTORY
23001 +       case VCMD_dump_history:
23002 +               return vc_dump_history(id);
23003 +       case VCMD_read_history:
23004 +               return __COMPAT(vc_read_history, id, data, compat);
23005 +#endif
23006 +       default:
23007 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
23008 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
23009 +       }
23010 +       return -ENOSYS;
23011 +}
23012 +
23013 +
23014 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
23015 +       case VCMD_ ## vcmd: perm = _perm;               \
23016 +               args = _args; flags = _flags; break
23017 +
23018 +
23019 +#define VCA_NONE       0x00
23020 +#define VCA_VXI                0x01
23021 +#define VCA_NXI                0x02
23022 +
23023 +#define VCF_NONE       0x00
23024 +#define VCF_INFO       0x01
23025 +#define VCF_ADMIN      0x02
23026 +#define VCF_ARES       0x06    /* includes admin */
23027 +#define VCF_SETUP      0x08
23028 +
23029 +#define VCF_ZIDOK      0x10    /* zero id okay */
23030 +
23031 +
23032 +static inline
23033 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
23034 +{
23035 +       long ret;
23036 +       int permit = -1, state = 0;
23037 +       int perm = -1, args = 0, flags = 0;
23038 +       struct vx_info *vxi = NULL;
23039 +       struct nx_info *nxi = NULL;
23040 +
23041 +       switch (cmd) {
23042 +       /* unpriviledged commands */
23043 +       __VCMD(get_version,      0, VCA_NONE,   0);
23044 +       __VCMD(get_vci,          0, VCA_NONE,   0);
23045 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
23046 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
23047 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
23048 +       __VCMD(get_space_default,0, VCA_NONE,   0);
23049 +
23050 +       /* info commands */
23051 +       __VCMD(task_xid,         2, VCA_NONE,   0);
23052 +       __VCMD(reset_hits,       2, VCA_VXI,    0);
23053 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
23054 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
23055 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
23056 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
23057 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
23058 +       __VCMD(get_umask,        3, VCA_VXI,    VCF_INFO);
23059 +       __VCMD(get_wmask,        3, VCA_VXI,    VCF_INFO);
23060 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
23061 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
23062 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
23063 +
23064 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
23065 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
23066 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
23067 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
23068 +
23069 +       __VCMD(task_nid,         2, VCA_NONE,   0);
23070 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
23071 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
23072 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
23073 +
23074 +       __VCMD(task_tag,         2, VCA_NONE,   0);
23075 +
23076 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
23077 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
23078 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
23079 +       __VCMD(get_prio_bias,    3, VCA_VXI,    VCF_INFO);
23080 +
23081 +       /* lower admin commands */
23082 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
23083 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
23084 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
23085 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
23086 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
23087 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
23088 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
23089 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
23090 +
23091 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
23092 +       __VCMD(net_create,       5, VCA_NONE,   0);
23093 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
23094 +
23095 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
23096 +
23097 +       /* higher admin commands */
23098 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
23099 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23100 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23101 +
23102 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23103 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23104 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23105 +       __VCMD(set_umask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23106 +       __VCMD(set_wmask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23107 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23108 +
23109 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23110 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23111 +       __VCMD(set_prio_bias,    7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23112 +
23113 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23114 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23115 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23116 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23117 +       __VCMD(net_add_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23118 +       __VCMD(net_rem_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23119 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23120 +       __VCMD(net_rem_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23121 +#ifdef CONFIG_IPV6
23122 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23123 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23124 +#endif
23125 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
23126 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
23127 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
23128 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
23129 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
23130 +
23131 +#ifdef CONFIG_VSERVER_DEVICE
23132 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23133 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23134 +#endif
23135 +       /* debug level admin commands */
23136 +#ifdef CONFIG_VSERVER_HISTORY
23137 +       __VCMD(dump_history,     9, VCA_NONE,   0);
23138 +       __VCMD(read_history,     9, VCA_NONE,   0);
23139 +#endif
23140 +
23141 +       default:
23142 +               perm = -1;
23143 +       }
23144 +
23145 +       vxdprintk(VXD_CBIT(switch, 0),
23146 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
23147 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23148 +               VC_VERSION(cmd), id, data, compat,
23149 +               perm, args, flags);
23150 +
23151 +       ret = -ENOSYS;
23152 +       if (perm < 0)
23153 +               goto out;
23154 +
23155 +       state = 1;
23156 +       if (!capable(CAP_CONTEXT))
23157 +               goto out;
23158 +
23159 +       state = 2;
23160 +       /* moved here from the individual commands */
23161 +       ret = -EPERM;
23162 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
23163 +               goto out;
23164 +
23165 +       state = 3;
23166 +       /* vcmd involves resource management  */
23167 +       ret = -EPERM;
23168 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
23169 +               goto out;
23170 +
23171 +       state = 4;
23172 +       /* various legacy exceptions */
23173 +       switch (cmd) {
23174 +       /* will go away when spectator is a cap */
23175 +       case VCMD_ctx_migrate_v0:
23176 +       case VCMD_ctx_migrate:
23177 +               if (id == 1) {
23178 +                       current->xid = 1;
23179 +                       ret = 1;
23180 +                       goto out;
23181 +               }
23182 +               break;
23183 +
23184 +       /* will go away when spectator is a cap */
23185 +       case VCMD_net_migrate:
23186 +               if (id == 1) {
23187 +                       current->nid = 1;
23188 +                       ret = 1;
23189 +                       goto out;
23190 +               }
23191 +               break;
23192 +       }
23193 +
23194 +       /* vcmds are fine by default */
23195 +       permit = 1;
23196 +
23197 +       /* admin type vcmds require admin ... */
23198 +       if (flags & VCF_ADMIN)
23199 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
23200 +
23201 +       /* ... but setup type vcmds override that */
23202 +       if (!permit && (flags & VCF_SETUP))
23203 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
23204 +
23205 +       state = 5;
23206 +       ret = -EPERM;
23207 +       if (!permit)
23208 +               goto out;
23209 +
23210 +       state = 6;
23211 +       if (!id && (flags & VCF_ZIDOK))
23212 +               goto skip_id;
23213 +
23214 +       ret = -ESRCH;
23215 +       if (args & VCA_VXI) {
23216 +               vxi = lookup_vx_info(id);
23217 +               if (!vxi)
23218 +                       goto out;
23219 +
23220 +               if ((flags & VCF_ADMIN) &&
23221 +                       /* special case kill for shutdown */
23222 +                       (cmd != VCMD_ctx_kill) &&
23223 +                       /* can context be administrated? */
23224 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
23225 +                       ret = -EACCES;
23226 +                       goto out_vxi;
23227 +               }
23228 +       }
23229 +       state = 7;
23230 +       if (args & VCA_NXI) {
23231 +               nxi = lookup_nx_info(id);
23232 +               if (!nxi)
23233 +                       goto out_vxi;
23234 +
23235 +               if ((flags & VCF_ADMIN) &&
23236 +                       /* can context be administrated? */
23237 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
23238 +                       ret = -EACCES;
23239 +                       goto out_nxi;
23240 +               }
23241 +       }
23242 +skip_id:
23243 +       state = 8;
23244 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
23245 +
23246 +out_nxi:
23247 +       if ((args & VCA_NXI) && nxi)
23248 +               put_nx_info(nxi);
23249 +out_vxi:
23250 +       if ((args & VCA_VXI) && vxi)
23251 +               put_vx_info(vxi);
23252 +out:
23253 +       vxdprintk(VXD_CBIT(switch, 1),
23254 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
23255 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23256 +               VC_VERSION(cmd), ret, ret, state, permit);
23257 +       return ret;
23258 +}
23259 +
23260 +asmlinkage long
23261 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
23262 +{
23263 +       return do_vserver(cmd, id, data, 0);
23264 +}
23265 +
23266 +#ifdef CONFIG_COMPAT
23267 +
23268 +asmlinkage long
23269 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
23270 +{
23271 +       return do_vserver(cmd, id, data, 1);
23272 +}
23273 +
23274 +#endif /* CONFIG_COMPAT */
23275 diff -NurpP --minimal linux-3.10.9/kernel/vserver/sysctl.c linux-3.10.9-vs2.3.6.6/kernel/vserver/sysctl.c
23276 --- linux-3.10.9/kernel/vserver/sysctl.c        1970-01-01 00:00:00.000000000 +0000
23277 +++ linux-3.10.9-vs2.3.6.6/kernel/vserver/sysctl.c      2013-08-22 20:30:00.000000000 +0000
23278 @@ -0,0 +1,247 @@
23279 +/*
23280 + *  kernel/vserver/sysctl.c
23281 + *
23282 + *  Virtual Context Support
23283 + *
23284 + *  Copyright (C) 2004-2007  Herbert Pötzl
23285 + *
23286 + *  V0.01  basic structure
23287 + *
23288 + */
23289 +
23290 +#include <linux/module.h>
23291 +#include <linux/ctype.h>
23292 +#include <linux/sysctl.h>
23293 +#include <linux/parser.h>
23294 +#include <asm/uaccess.h>
23295 +
23296 +enum {
23297 +       CTL_DEBUG_ERROR         = 0,
23298 +       CTL_DEBUG_SWITCH        = 1,
23299 +       CTL_DEBUG_XID,
23300 +       CTL_DEBUG_NID,
23301 +       CTL_DEBUG_TAG,
23302 +       CTL_DEBUG_NET,
23303 +       CTL_DEBUG_LIMIT,
23304 +       CTL_DEBUG_CRES,
23305 +       CTL_DEBUG_DLIM,
23306 +       CTL_DEBUG_QUOTA,
23307 +       CTL_DEBUG_CVIRT,
23308 +       CTL_DEBUG_SPACE,
23309 +       CTL_DEBUG_PERM,
23310 +       CTL_DEBUG_MISC,
23311 +};
23312 +
23313 +
23314 +unsigned int vs_debug_switch   = 0;
23315 +unsigned int vs_debug_xid      = 0;
23316 +unsigned int vs_debug_nid      = 0;
23317 +unsigned int vs_debug_tag      = 0;
23318 +unsigned int vs_debug_net      = 0;
23319 +unsigned int vs_debug_limit    = 0;
23320 +unsigned int vs_debug_cres     = 0;
23321 +unsigned int vs_debug_dlim     = 0;
23322 +unsigned int vs_debug_quota    = 0;
23323 +unsigned int vs_debug_cvirt    = 0;
23324 +unsigned int vs_debug_space    = 0;
23325 +unsigned int vs_debug_perm     = 0;
23326 +unsigned int vs_debug_misc     = 0;
23327 +
23328 +
23329 +static struct ctl_table_header *vserver_table_header;
23330 +static ctl_table vserver_root_table[];
23331 +
23332 +
23333 +void vserver_register_sysctl(void)
23334 +{
23335 +       if (!vserver_table_header) {
23336 +               vserver_table_header = register_sysctl_table(vserver_root_table);
23337 +       }
23338 +
23339 +}
23340 +
23341 +void vserver_unregister_sysctl(void)
23342 +{
23343 +       if (vserver_table_header) {
23344 +               unregister_sysctl_table(vserver_table_header);
23345 +               vserver_table_header = NULL;
23346 +       }
23347 +}
23348 +
23349 +
23350 +static int proc_dodebug(ctl_table *table, int write,
23351 +       void __user *buffer, size_t *lenp, loff_t *ppos)
23352 +{
23353 +       char            tmpbuf[20], *p, c;
23354 +       unsigned int    value;
23355 +       size_t          left, len;
23356 +
23357 +       if ((*ppos && !write) || !*lenp) {
23358 +               *lenp = 0;
23359 +               return 0;
23360 +       }
23361 +
23362 +       left = *lenp;
23363 +
23364 +       if (write) {
23365 +               if (!access_ok(VERIFY_READ, buffer, left))
23366 +                       return -EFAULT;
23367 +               p = (char *)buffer;
23368 +               while (left && __get_user(c, p) >= 0 && isspace(c))
23369 +                       left--, p++;
23370 +               if (!left)
23371 +                       goto done;
23372 +
23373 +               if (left > sizeof(tmpbuf) - 1)
23374 +                       return -EINVAL;
23375 +               if (copy_from_user(tmpbuf, p, left))
23376 +                       return -EFAULT;
23377 +               tmpbuf[left] = '\0';
23378 +
23379 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
23380 +                       value = 10 * value + (*p - '0');
23381 +               if (*p && !isspace(*p))
23382 +                       return -EINVAL;
23383 +               while (left && isspace(*p))
23384 +                       left--, p++;
23385 +               *(unsigned int *)table->data = value;
23386 +       } else {
23387 +               if (!access_ok(VERIFY_WRITE, buffer, left))
23388 +                       return -EFAULT;
23389 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
23390 +               if (len > left)
23391 +                       len = left;
23392 +               if (__copy_to_user(buffer, tmpbuf, len))
23393 +                       return -EFAULT;
23394 +               if ((left -= len) > 0) {
23395 +                       if (put_user('\n', (char *)buffer + len))
23396 +                               return -EFAULT;
23397 +                       left--;
23398 +               }
23399 +       }
23400 +
23401 +done:
23402 +       *lenp -= left;
23403 +       *ppos += *lenp;
23404 +       return 0;
23405 +}
23406 +
23407 +static int zero;
23408 +
23409 +#define        CTL_ENTRY(ctl, name)                            \
23410 +       {                                               \
23411 +               .procname       = #name,                \
23412 +               .data           = &vs_ ## name,         \
23413 +               .maxlen         = sizeof(int),          \
23414 +               .mode           = 0644,                 \
23415 +               .proc_handler   = &proc_dodebug,        \
23416 +               .extra1         = &zero,                \
23417 +               .extra2         = &zero,                \
23418 +       }
23419 +
23420 +static ctl_table vserver_debug_table[] = {
23421 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
23422 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
23423 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
23424 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
23425 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
23426 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
23427 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
23428 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
23429 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
23430 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
23431 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
23432 +       CTL_ENTRY(CTL_DEBUG_PERM,       debug_perm),
23433 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
23434 +       { 0 }
23435 +};
23436 +
23437 +static ctl_table vserver_root_table[] = {
23438 +       {
23439 +               .procname       = "vserver",
23440 +               .mode           = 0555,
23441 +               .child          = vserver_debug_table
23442 +       },
23443 +       { 0 }
23444 +};
23445 +
23446 +
23447 +static match_table_t tokens = {
23448 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
23449 +       { CTL_DEBUG_XID,        "xid=%x"        },
23450 +       { CTL_DEBUG_NID,        "nid=%x"        },
23451 +       { CTL_DEBUG_TAG,        "tag=%x"        },
23452 +       { CTL_DEBUG_NET,        "net=%x"        },
23453 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
23454 +       { CTL_DEBUG_CRES,       "cres=%x"       },
23455 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
23456 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
23457 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
23458 +       { CTL_DEBUG_SPACE,      "space=%x"      },
23459 +       { CTL_DEBUG_PERM,       "perm=%x"       },
23460 +       { CTL_DEBUG_MISC,       "misc=%x"       },
23461 +       { CTL_DEBUG_ERROR,      NULL            }
23462 +};
23463 +
23464 +#define        HANDLE_CASE(id, name, val)                              \
23465 +       case CTL_DEBUG_ ## id:                                  \
23466 +               vs_debug_ ## name = val;                        \
23467 +               printk("vs_debug_" #name "=0x%x\n", val);       \
23468 +               break
23469 +
23470 +
23471 +static int __init vs_debug_setup(char *str)
23472 +{
23473 +       char *p;
23474 +       int token;
23475 +
23476 +       printk("vs_debug_setup(%s)\n", str);
23477 +       while ((p = strsep(&str, ",")) != NULL) {
23478 +               substring_t args[MAX_OPT_ARGS];
23479 +               unsigned int value;
23480 +
23481 +               if (!*p)
23482 +                       continue;
23483 +
23484 +               token = match_token(p, tokens, args);
23485 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
23486 +
23487 +               switch (token) {
23488 +               HANDLE_CASE(SWITCH, switch, value);
23489 +               HANDLE_CASE(XID,    xid,    value);
23490 +               HANDLE_CASE(NID,    nid,    value);
23491 +               HANDLE_CASE(TAG,    tag,    value);
23492 +               HANDLE_CASE(NET,    net,    value);
23493 +               HANDLE_CASE(LIMIT,  limit,  value);
23494 +               HANDLE_CASE(CRES,   cres,   value);
23495 +               HANDLE_CASE(DLIM,   dlim,   value);
23496 +               HANDLE_CASE(QUOTA,  quota,  value);
23497 +               HANDLE_CASE(CVIRT,  cvirt,  value);
23498 +               HANDLE_CASE(SPACE,  space,  value);
23499 +               HANDLE_CASE(PERM,   perm,   value);
23500 +               HANDLE_CASE(MISC,   misc,   value);
23501 +               default:
23502 +                       return -EINVAL;
23503 +                       break;
23504 +               }
23505 +       }
23506 +       return 1;
23507 +}
23508 +
23509 +__setup("vsdebug=", vs_debug_setup);
23510 +
23511 +
23512 +
23513 +EXPORT_SYMBOL_GPL(vs_debug_switch);
23514 +EXPORT_SYMBOL_GPL(vs_debug_xid);
23515 +EXPORT_SYMBOL_GPL(vs_debug_nid);
23516 +EXPORT_SYMBOL_GPL(vs_debug_net);
23517 +EXPORT_SYMBOL_GPL(vs_debug_limit);
23518 +EXPORT_SYMBOL_GPL(vs_debug_cres);
23519 +EXPORT_SYMBOL_GPL(vs_debug_dlim);
23520 +EXPORT_SYMBOL_GPL(vs_debug_quota);
23521 +EXPORT_SYMBOL_GPL(vs_debug_cvirt);
23522 +EXPORT_SYMBOL_GPL(vs_debug_space);
23523 +EXPORT_SYMBOL_GPL(vs_debug_perm);
23524 +EXPORT_SYMBOL_GPL(vs_debug_misc);
23525 +
23526 diff -NurpP --minimal linux-3.10.9/kernel/vserver/tag.c linux-3.10.9-vs2.3.6.6/kernel/vserver/tag.c
23527 --- linux-3.10.9/kernel/vserver/tag.c   1970-01-01 00:00:00.000000000 +0000
23528 +++ linux-3.10.9-vs2.3.6.6/kernel/vserver/tag.c 2013-08-22 20:30:00.000000000 +0000
23529 @@ -0,0 +1,63 @@
23530 +/*
23531 + *  linux/kernel/vserver/tag.c
23532 + *
23533 + *  Virtual Server: Shallow Tag Space
23534 + *
23535 + *  Copyright (C) 2007  Herbert Pötzl
23536 + *
23537 + *  V0.01  basic implementation
23538 + *
23539 + */
23540 +
23541 +#include <linux/sched.h>
23542 +#include <linux/vserver/debug.h>
23543 +#include <linux/vs_pid.h>
23544 +#include <linux/vs_tag.h>
23545 +
23546 +#include <linux/vserver/tag_cmd.h>
23547 +
23548 +
23549 +int dx_migrate_task(struct task_struct *p, vtag_t tag)
23550 +{
23551 +       if (!p)
23552 +               BUG();
23553 +
23554 +       vxdprintk(VXD_CBIT(tag, 5),
23555 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
23556 +
23557 +       task_lock(p);
23558 +       p->tag = tag;
23559 +       task_unlock(p);
23560 +
23561 +       vxdprintk(VXD_CBIT(tag, 5),
23562 +               "moved task %p into [#%d]", p, tag);
23563 +       return 0;
23564 +}
23565 +
23566 +/* vserver syscall commands below here */
23567 +
23568 +/* taks xid and vx_info functions */
23569 +
23570 +
23571 +int vc_task_tag(uint32_t id)
23572 +{
23573 +       vtag_t tag;
23574 +
23575 +       if (id) {
23576 +               struct task_struct *tsk;
23577 +               rcu_read_lock();
23578 +               tsk = find_task_by_real_pid(id);
23579 +               tag = (tsk) ? tsk->tag : -ESRCH;
23580 +               rcu_read_unlock();
23581 +       } else
23582 +               tag = dx_current_tag();
23583 +       return tag;
23584 +}
23585 +
23586 +
23587 +int vc_tag_migrate(uint32_t tag)
23588 +{
23589 +       return dx_migrate_task(current, tag & 0xFFFF);
23590 +}
23591 +
23592 +
23593 diff -NurpP --minimal linux-3.10.9/kernel/vserver/vci_config.h linux-3.10.9-vs2.3.6.6/kernel/vserver/vci_config.h
23594 --- linux-3.10.9/kernel/vserver/vci_config.h    1970-01-01 00:00:00.000000000 +0000
23595 +++ linux-3.10.9-vs2.3.6.6/kernel/vserver/vci_config.h  2013-08-22 20:30:00.000000000 +0000
23596 @@ -0,0 +1,80 @@
23597 +
23598 +/*  interface version */
23599 +
23600 +#define VCI_VERSION            0x00020308
23601 +
23602 +
23603 +enum {
23604 +       VCI_KCBIT_NO_DYNAMIC = 0,
23605 +
23606 +       VCI_KCBIT_PROC_SECURE = 4,
23607 +       /* VCI_KCBIT_HARDCPU = 5, */
23608 +       /* VCI_KCBIT_IDLELIMIT = 6, */
23609 +       /* VCI_KCBIT_IDLETIME = 7, */
23610 +
23611 +       VCI_KCBIT_COWBL = 8,
23612 +       VCI_KCBIT_FULLCOWBL = 9,
23613 +       VCI_KCBIT_SPACES = 10,
23614 +       VCI_KCBIT_NETV2 = 11,
23615 +       VCI_KCBIT_MEMCG = 12,
23616 +       VCI_KCBIT_MEMCG_SWAP = 13,
23617 +
23618 +       VCI_KCBIT_DEBUG = 16,
23619 +       VCI_KCBIT_HISTORY = 20,
23620 +       VCI_KCBIT_TAGGED = 24,
23621 +       VCI_KCBIT_PPTAG = 28,
23622 +
23623 +       VCI_KCBIT_MORE = 31,
23624 +};
23625 +
23626 +
23627 +static inline uint32_t vci_kernel_config(void)
23628 +{
23629 +       return
23630 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
23631 +
23632 +       /* configured features */
23633 +#ifdef CONFIG_VSERVER_PROC_SECURE
23634 +       (1 << VCI_KCBIT_PROC_SECURE) |
23635 +#endif
23636 +#ifdef CONFIG_VSERVER_COWBL
23637 +       (1 << VCI_KCBIT_COWBL) |
23638 +       (1 << VCI_KCBIT_FULLCOWBL) |
23639 +#endif
23640 +       (1 << VCI_KCBIT_SPACES) |
23641 +       (1 << VCI_KCBIT_NETV2) |
23642 +#ifdef CONFIG_MEMCG
23643 +       (1 << VCI_KCBIT_MEMCG) |
23644 +#endif
23645 +#ifdef CONFIG_MEMCG_SWAP
23646 +       (1 << VCI_KCBIT_MEMCG_SWAP) |
23647 +#endif
23648 +
23649 +       /* debug options */
23650 +#ifdef CONFIG_VSERVER_DEBUG
23651 +       (1 << VCI_KCBIT_DEBUG) |
23652 +#endif
23653 +#ifdef CONFIG_VSERVER_HISTORY
23654 +       (1 << VCI_KCBIT_HISTORY) |
23655 +#endif
23656 +
23657 +       /* inode context tagging */
23658 +#if    defined(CONFIG_TAGGING_NONE)
23659 +       (0 << VCI_KCBIT_TAGGED) |
23660 +#elif  defined(CONFIG_TAGGING_UID16)
23661 +       (1 << VCI_KCBIT_TAGGED) |
23662 +#elif  defined(CONFIG_TAGGING_GID16)
23663 +       (2 << VCI_KCBIT_TAGGED) |
23664 +#elif  defined(CONFIG_TAGGING_ID24)
23665 +       (3 << VCI_KCBIT_TAGGED) |
23666 +#elif  defined(CONFIG_TAGGING_INTERN)
23667 +       (4 << VCI_KCBIT_TAGGED) |
23668 +#elif  defined(CONFIG_TAGGING_RUNTIME)
23669 +       (5 << VCI_KCBIT_TAGGED) |
23670 +#else
23671 +       (7 << VCI_KCBIT_TAGGED) |
23672 +#endif
23673 +       (1 << VCI_KCBIT_PPTAG) |
23674 +       0;
23675 +}
23676 +
23677 diff -NurpP --minimal linux-3.10.9/mm/memcontrol.c linux-3.10.9-vs2.3.6.6/mm/memcontrol.c
23678 --- linux-3.10.9/mm/memcontrol.c        2013-08-22 19:51:35.000000000 +0000
23679 +++ linux-3.10.9-vs2.3.6.6/mm/memcontrol.c      2013-08-22 20:30:00.000000000 +0000
23680 @@ -1082,6 +1082,31 @@ struct mem_cgroup *mem_cgroup_from_task(
23681         return mem_cgroup_from_css(task_subsys_state(p, mem_cgroup_subsys_id));
23682  }
23683  
23684 +u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member)
23685 +{
23686 +       return res_counter_read_u64(&mem->res, member);
23687 +}
23688 +
23689 +u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member)
23690 +{
23691 +       return res_counter_read_u64(&mem->memsw, member);
23692 +}
23693 +
23694 +s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem)
23695 +{
23696 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_CACHE);
23697 +}
23698 +
23699 +s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem)
23700 +{
23701 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_RSS);
23702 +}
23703 +
23704 +s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem)
23705 +{
23706 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_FILE_MAPPED);
23707 +}
23708 +
23709  struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
23710  {
23711         struct mem_cgroup *memcg = NULL;
23712 diff -NurpP --minimal linux-3.10.9/mm/oom_kill.c linux-3.10.9-vs2.3.6.6/mm/oom_kill.c
23713 --- linux-3.10.9/mm/oom_kill.c  2013-05-31 13:45:31.000000000 +0000
23714 +++ linux-3.10.9-vs2.3.6.6/mm/oom_kill.c        2013-08-22 20:30:00.000000000 +0000
23715 @@ -35,6 +35,8 @@
23716  #include <linux/freezer.h>
23717  #include <linux/ftrace.h>
23718  #include <linux/ratelimit.h>
23719 +#include <linux/reboot.h>
23720 +#include <linux/vs_context.h>
23721  
23722  #define CREATE_TRACE_POINTS
23723  #include <trace/events/oom.h>
23724 @@ -113,11 +115,18 @@ struct task_struct *find_lock_task_mm(st
23725  static bool oom_unkillable_task(struct task_struct *p,
23726                 const struct mem_cgroup *memcg, const nodemask_t *nodemask)
23727  {
23728 -       if (is_global_init(p))
23729 +       unsigned xid = vx_current_xid();
23730 +
23731 +       /* skip the init task, global and per guest */
23732 +       if (task_is_init(p))
23733                 return true;
23734         if (p->flags & PF_KTHREAD)
23735                 return true;
23736  
23737 +       /* skip other guest and host processes if oom in guest */
23738 +       if (xid && vx_task_xid(p) != xid)
23739 +               return true;
23740 +
23741         /* When mem_cgroup_out_of_memory() and p is not member of the group */
23742         if (memcg && !task_in_mem_cgroup(p, memcg))
23743                 return true;
23744 @@ -426,8 +435,8 @@ void oom_kill_process(struct task_struct
23745                 dump_header(p, gfp_mask, order, memcg, nodemask);
23746  
23747         task_lock(p);
23748 -       pr_err("%s: Kill process %d (%s) score %d or sacrifice child\n",
23749 -               message, task_pid_nr(p), p->comm, points);
23750 +       pr_err("%s: Kill process %d:#%u (%s) score %d or sacrifice child\n",
23751 +               message, task_pid_nr(p), p->xid, p->comm, points);
23752         task_unlock(p);
23753  
23754         /*
23755 @@ -472,8 +481,8 @@ void oom_kill_process(struct task_struct
23756  
23757         /* mm cannot safely be dereferenced after task_unlock(victim) */
23758         mm = victim->mm;
23759 -       pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23760 -               task_pid_nr(victim), victim->comm, K(victim->mm->total_vm),
23761 +       pr_err("Killed process %d:#%u (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23762 +               task_pid_nr(victim), victim->xid, victim->comm, K(victim->mm->total_vm),
23763                 K(get_mm_counter(victim->mm, MM_ANONPAGES)),
23764                 K(get_mm_counter(victim->mm, MM_FILEPAGES)));
23765         task_unlock(victim);
23766 @@ -543,6 +552,8 @@ int unregister_oom_notifier(struct notif
23767  }
23768  EXPORT_SYMBOL_GPL(unregister_oom_notifier);
23769  
23770 +long vs_oom_action(unsigned int);
23771 +
23772  /*
23773   * Try to acquire the OOM killer lock for the zones in zonelist.  Returns zero
23774   * if a parallel OOM killing is already taking place that includes a zone in
23775 @@ -655,7 +666,12 @@ void out_of_memory(struct zonelist *zone
23776         /* Found nothing?!?! Either we hang forever, or we panic. */
23777         if (!p) {
23778                 dump_header(NULL, gfp_mask, order, NULL, mpol_mask);
23779 -               panic("Out of memory and no killable processes...\n");
23780 +
23781 +               /* avoid panic for guest OOM */
23782 +               if (vx_current_xid())
23783 +                       vs_oom_action(LINUX_REBOOT_CMD_OOM);
23784 +               else
23785 +                       panic("Out of memory and no killable processes...\n");
23786         }
23787         if (PTR_ERR(p) != -1UL) {
23788                 oom_kill_process(p, gfp_mask, order, points, totalpages, NULL,
23789 diff -NurpP --minimal linux-3.10.9/mm/page_alloc.c linux-3.10.9-vs2.3.6.6/mm/page_alloc.c
23790 --- linux-3.10.9/mm/page_alloc.c        2013-08-22 19:51:36.000000000 +0000
23791 +++ linux-3.10.9-vs2.3.6.6/mm/page_alloc.c      2013-08-22 20:30:00.000000000 +0000
23792 @@ -60,6 +60,8 @@
23793  #include <linux/page-debug-flags.h>
23794  #include <linux/hugetlb.h>
23795  #include <linux/sched/rt.h>
23796 +#include <linux/vs_base.h>
23797 +#include <linux/vs_limit.h>
23798  
23799  #include <asm/tlbflush.h>
23800  #include <asm/div64.h>
23801 @@ -2899,6 +2901,9 @@ void si_meminfo(struct sysinfo *val)
23802         val->totalhigh = totalhigh_pages;
23803         val->freehigh = nr_free_highpages();
23804         val->mem_unit = PAGE_SIZE;
23805 +
23806 +       if (vx_flags(VXF_VIRT_MEM, 0))
23807 +               vx_vsi_meminfo(val);
23808  }
23809  
23810  EXPORT_SYMBOL(si_meminfo);
23811 @@ -2919,6 +2924,9 @@ void si_meminfo_node(struct sysinfo *val
23812         val->freehigh = 0;
23813  #endif
23814         val->mem_unit = PAGE_SIZE;
23815 +
23816 +       if (vx_flags(VXF_VIRT_MEM, 0))
23817 +               vx_vsi_meminfo(val);
23818  }
23819  #endif
23820  
23821 diff -NurpP --minimal linux-3.10.9/mm/pgtable-generic.c linux-3.10.9-vs2.3.6.6/mm/pgtable-generic.c
23822 --- linux-3.10.9/mm/pgtable-generic.c   2013-02-19 13:58:57.000000000 +0000
23823 +++ linux-3.10.9-vs2.3.6.6/mm/pgtable-generic.c 2013-08-22 20:30:00.000000000 +0000
23824 @@ -6,6 +6,8 @@
23825   *  Copyright (C) 2010  Linus Torvalds
23826   */
23827  
23828 +#include <linux/mm.h>
23829 +
23830  #include <linux/pagemap.h>
23831  #include <asm/tlb.h>
23832  #include <asm-generic/pgtable.h>
23833 diff -NurpP --minimal linux-3.10.9/mm/shmem.c linux-3.10.9-vs2.3.6.6/mm/shmem.c
23834 --- linux-3.10.9/mm/shmem.c     2013-07-14 17:01:36.000000000 +0000
23835 +++ linux-3.10.9-vs2.3.6.6/mm/shmem.c   2013-08-22 20:30:00.000000000 +0000
23836 @@ -1911,7 +1911,7 @@ static int shmem_statfs(struct dentry *d
23837  {
23838         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
23839  
23840 -       buf->f_type = TMPFS_MAGIC;
23841 +       buf->f_type = TMPFS_SUPER_MAGIC;
23842         buf->f_bsize = PAGE_CACHE_SIZE;
23843         buf->f_namelen = NAME_MAX;
23844         if (sbinfo->max_blocks) {
23845 @@ -2608,7 +2608,7 @@ int shmem_fill_super(struct super_block
23846         sb->s_maxbytes = MAX_LFS_FILESIZE;
23847         sb->s_blocksize = PAGE_CACHE_SIZE;
23848         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
23849 -       sb->s_magic = TMPFS_MAGIC;
23850 +       sb->s_magic = TMPFS_SUPER_MAGIC;
23851         sb->s_op = &shmem_ops;
23852         sb->s_time_gran = 1;
23853  #ifdef CONFIG_TMPFS_XATTR
23854 diff -NurpP --minimal linux-3.10.9/mm/slab.c linux-3.10.9-vs2.3.6.6/mm/slab.c
23855 --- linux-3.10.9/mm/slab.c      2013-08-22 19:51:36.000000000 +0000
23856 +++ linux-3.10.9-vs2.3.6.6/mm/slab.c    2013-08-22 21:01:54.000000000 +0000
23857 @@ -388,6 +388,8 @@ static void kmem_cache_node_init(struct
23858  #define STATS_INC_FREEMISS(x)  do { } while (0)
23859  #endif
23860  
23861 +#include "slab_vs.h"
23862 +
23863  #if DEBUG
23864  
23865  /*
23866 @@ -3314,6 +3316,7 @@ retry:
23867  
23868         obj = slab_get_obj(cachep, slabp, nodeid);
23869         check_slabp(cachep, slabp);
23870 +       vx_slab_alloc(cachep, flags);
23871         n->free_objects--;
23872         /* move slabp to correct slabp list: */
23873         list_del(&slabp->list);
23874 @@ -3393,6 +3396,7 @@ slab_alloc_node(struct kmem_cache *cache
23875         /* ___cache_alloc_node can fall back to other nodes */
23876         ptr = ____cache_alloc_node(cachep, flags, nodeid);
23877    out:
23878 +       vx_slab_alloc(cachep, flags);
23879         local_irq_restore(save_flags);
23880         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
23881         kmemleak_alloc_recursive(ptr, cachep->object_size, 1, cachep->flags,
23882 @@ -3585,6 +3589,7 @@ static inline void __cache_free(struct k
23883         check_irq_off();
23884         kmemleak_free_recursive(objp, cachep->flags);
23885         objp = cache_free_debugcheck(cachep, objp, caller);
23886 +       vx_slab_free(cachep);
23887  
23888         kmemcheck_slab_free(cachep, objp, cachep->object_size);
23889  
23890 diff -NurpP --minimal linux-3.10.9/mm/slab_vs.h linux-3.10.9-vs2.3.6.6/mm/slab_vs.h
23891 --- linux-3.10.9/mm/slab_vs.h   1970-01-01 00:00:00.000000000 +0000
23892 +++ linux-3.10.9-vs2.3.6.6/mm/slab_vs.h 2013-08-22 20:30:00.000000000 +0000
23893 @@ -0,0 +1,29 @@
23894 +
23895 +#include <linux/vserver/context.h>
23896 +
23897 +#include <linux/vs_context.h>
23898 +
23899 +static inline
23900 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
23901 +{
23902 +       int what = gfp_zone(cachep->allocflags);
23903 +       struct vx_info *vxi = current_vx_info();
23904 +
23905 +       if (!vxi)
23906 +               return;
23907 +
23908 +       atomic_add(cachep->size, &vxi->cacct.slab[what]);
23909 +}
23910 +
23911 +static inline
23912 +void vx_slab_free(struct kmem_cache *cachep)
23913 +{
23914 +       int what = gfp_zone(cachep->allocflags);
23915 +       struct vx_info *vxi = current_vx_info();
23916 +
23917 +       if (!vxi)
23918 +               return;
23919 +
23920 +       atomic_sub(cachep->size, &vxi->cacct.slab[what]);
23921 +}
23922 +
23923 diff -NurpP --minimal linux-3.10.9/mm/swapfile.c linux-3.10.9-vs2.3.6.6/mm/swapfile.c
23924 --- linux-3.10.9/mm/swapfile.c  2013-07-14 17:01:36.000000000 +0000
23925 +++ linux-3.10.9-vs2.3.6.6/mm/swapfile.c        2013-08-22 20:30:00.000000000 +0000
23926 @@ -39,6 +39,7 @@
23927  #include <asm/tlbflush.h>
23928  #include <linux/swapops.h>
23929  #include <linux/page_cgroup.h>
23930 +#include <linux/vs_base.h>
23931  
23932  static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
23933                                  unsigned char);
23934 @@ -1768,6 +1769,16 @@ static int swap_show(struct seq_file *sw
23935  
23936         if (si == SEQ_START_TOKEN) {
23937                 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
23938 +               if (vx_flags(VXF_VIRT_MEM, 0)) {
23939 +                       struct sysinfo si;
23940 +
23941 +                       vx_vsi_swapinfo(&si);
23942 +                       if (si.totalswap < (1 << 10))
23943 +                               return 0;
23944 +                       seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
23945 +                               "hdv0", "partition", si.totalswap >> 10,
23946 +                               (si.totalswap - si.freeswap) >> 10, -1);
23947 +               }
23948                 return 0;
23949         }
23950  
23951 @@ -2196,6 +2207,8 @@ void si_swapinfo(struct sysinfo *val)
23952         val->freeswap = atomic_long_read(&nr_swap_pages) + nr_to_be_unused;
23953         val->totalswap = total_swap_pages + nr_to_be_unused;
23954         spin_unlock(&swap_lock);
23955 +       if (vx_flags(VXF_VIRT_MEM, 0))
23956 +               vx_vsi_swapinfo(val);
23957  }
23958  
23959  /*
23960 diff -NurpP --minimal linux-3.10.9/net/bridge/br_multicast.c linux-3.10.9-vs2.3.6.6/net/bridge/br_multicast.c
23961 --- linux-3.10.9/net/bridge/br_multicast.c      2013-07-14 17:01:37.000000000 +0000
23962 +++ linux-3.10.9-vs2.3.6.6/net/bridge/br_multicast.c    2013-08-22 20:30:00.000000000 +0000
23963 @@ -443,7 +443,7 @@ static struct sk_buff *br_ip6_multicast_
23964         ip6h->hop_limit = 1;
23965         ipv6_addr_set(&ip6h->daddr, htonl(0xff020000), 0, 0, htonl(1));
23966         if (ipv6_dev_get_saddr(dev_net(br->dev), br->dev, &ip6h->daddr, 0,
23967 -                              &ip6h->saddr)) {
23968 +                              &ip6h->saddr, NULL)) {
23969                 kfree_skb(skb);
23970                 return NULL;
23971         }
23972 diff -NurpP --minimal linux-3.10.9/net/core/dev.c linux-3.10.9-vs2.3.6.6/net/core/dev.c
23973 --- linux-3.10.9/net/core/dev.c 2013-08-22 19:51:36.000000000 +0000
23974 +++ linux-3.10.9-vs2.3.6.6/net/core/dev.c       2013-08-22 20:30:00.000000000 +0000
23975 @@ -122,6 +122,7 @@
23976  #include <linux/in.h>
23977  #include <linux/jhash.h>
23978  #include <linux/random.h>
23979 +#include <linux/vs_inet.h>
23980  #include <trace/events/napi.h>
23981  #include <trace/events/net.h>
23982  #include <trace/events/skb.h>
23983 @@ -660,7 +661,8 @@ struct net_device *__dev_get_by_name(str
23984         struct hlist_head *head = dev_name_hash(net, name);
23985  
23986         hlist_for_each_entry(dev, head, name_hlist)
23987 -               if (!strncmp(dev->name, name, IFNAMSIZ))
23988 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
23989 +                   nx_dev_visible(current_nx_info(), dev))
23990                         return dev;
23991  
23992         return NULL;
23993 @@ -685,7 +687,8 @@ struct net_device *dev_get_by_name_rcu(s
23994         struct hlist_head *head = dev_name_hash(net, name);
23995  
23996         hlist_for_each_entry_rcu(dev, head, name_hlist)
23997 -               if (!strncmp(dev->name, name, IFNAMSIZ))
23998 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
23999 +                   nx_dev_visible(current_nx_info(), dev))
24000                         return dev;
24001  
24002         return NULL;
24003 @@ -735,7 +738,8 @@ struct net_device *__dev_get_by_index(st
24004         struct hlist_head *head = dev_index_hash(net, ifindex);
24005  
24006         hlist_for_each_entry(dev, head, index_hlist)
24007 -               if (dev->ifindex == ifindex)
24008 +               if ((dev->ifindex == ifindex) &&
24009 +                   nx_dev_visible(current_nx_info(), dev))
24010                         return dev;
24011  
24012         return NULL;
24013 @@ -753,7 +757,7 @@ EXPORT_SYMBOL(__dev_get_by_index);
24014   *     about locking. The caller must hold RCU lock.
24015   */
24016  
24017 -struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
24018 +struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex)
24019  {
24020         struct net_device *dev;
24021         struct hlist_head *head = dev_index_hash(net, ifindex);
24022 @@ -764,6 +768,16 @@ struct net_device *dev_get_by_index_rcu(
24023  
24024         return NULL;
24025  }
24026 +EXPORT_SYMBOL(dev_get_by_index_real_rcu);
24027 +
24028 +struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
24029 +{
24030 +       struct net_device *dev = dev_get_by_index_real_rcu(net, ifindex);
24031 +
24032 +       if (nx_dev_visible(current_nx_info(), dev))
24033 +               return dev;
24034 +       return NULL;
24035 +}
24036  EXPORT_SYMBOL(dev_get_by_index_rcu);
24037  
24038  
24039 @@ -846,7 +860,8 @@ struct net_device *dev_getbyhwaddr_rcu(s
24040  
24041         for_each_netdev_rcu(net, dev)
24042                 if (dev->type == type &&
24043 -                   !memcmp(dev->dev_addr, ha, dev->addr_len))
24044 +                   !memcmp(dev->dev_addr, ha, dev->addr_len) &&
24045 +                   nx_dev_visible(current_nx_info(), dev))
24046                         return dev;
24047  
24048         return NULL;
24049 @@ -858,9 +873,11 @@ struct net_device *__dev_getfirstbyhwtyp
24050         struct net_device *dev;
24051  
24052         ASSERT_RTNL();
24053 -       for_each_netdev(net, dev)
24054 -               if (dev->type == type)
24055 +       for_each_netdev(net, dev) {
24056 +               if ((dev->type == type) &&
24057 +                   nx_dev_visible(current_nx_info(), dev))
24058                         return dev;
24059 +       }
24060  
24061         return NULL;
24062  }
24063 @@ -872,7 +889,8 @@ struct net_device *dev_getfirstbyhwtype(
24064  
24065         rcu_read_lock();
24066         for_each_netdev_rcu(net, dev)
24067 -               if (dev->type == type) {
24068 +               if ((dev->type == type) &&
24069 +                   nx_dev_visible(current_nx_info(), dev)) {
24070                         dev_hold(dev);
24071                         ret = dev;
24072                         break;
24073 @@ -900,7 +918,8 @@ struct net_device *dev_get_by_flags_rcu(
24074  
24075         ret = NULL;
24076         for_each_netdev_rcu(net, dev) {
24077 -               if (((dev->flags ^ if_flags) & mask) == 0) {
24078 +               if ((((dev->flags ^ if_flags) & mask) == 0) &&
24079 +                       nx_dev_visible(current_nx_info(), dev)) {
24080                         ret = dev;
24081                         break;
24082                 }
24083 @@ -978,6 +997,8 @@ static int __dev_alloc_name(struct net *
24084                                 continue;
24085                         if (i < 0 || i >= max_netdevices)
24086                                 continue;
24087 +                       if (!nx_dev_visible(current_nx_info(), d))
24088 +                               continue;
24089  
24090                         /*  avoid cases where sscanf is not exact inverse of printf */
24091                         snprintf(buf, IFNAMSIZ, name, i);
24092 diff -NurpP --minimal linux-3.10.9/net/core/net-procfs.c linux-3.10.9-vs2.3.6.6/net/core/net-procfs.c
24093 --- linux-3.10.9/net/core/net-procfs.c  2013-07-14 17:01:37.000000000 +0000
24094 +++ linux-3.10.9-vs2.3.6.6/net/core/net-procfs.c        2013-08-22 20:30:00.000000000 +0000
24095 @@ -1,6 +1,7 @@
24096  #include <linux/netdevice.h>
24097  #include <linux/proc_fs.h>
24098  #include <linux/seq_file.h>
24099 +#include <linux/vs_inet.h>
24100  #include <net/wext.h>
24101  
24102  #define BUCKET_SPACE (32 - NETDEV_HASHBITS - 1)
24103 @@ -77,8 +78,13 @@ static void dev_seq_stop(struct seq_file
24104  static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
24105  {
24106         struct rtnl_link_stats64 temp;
24107 -       const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
24108 +       const struct rtnl_link_stats64 *stats;
24109 +
24110 +       /* device visible inside network context? */
24111 +       if (!nx_dev_visible(current_nx_info(), dev))
24112 +               return;
24113  
24114 +       stats = dev_get_stats(dev, &temp);
24115         seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
24116                    "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
24117                    dev->name, stats->rx_bytes, stats->rx_packets,
24118 diff -NurpP --minimal linux-3.10.9/net/core/rtnetlink.c linux-3.10.9-vs2.3.6.6/net/core/rtnetlink.c
24119 --- linux-3.10.9/net/core/rtnetlink.c   2013-07-14 17:01:37.000000000 +0000
24120 +++ linux-3.10.9-vs2.3.6.6/net/core/rtnetlink.c 2013-08-22 20:30:00.000000000 +0000
24121 @@ -1059,6 +1059,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
24122                 hlist_for_each_entry_rcu(dev, head, index_hlist) {
24123                         if (idx < s_idx)
24124                                 goto cont;
24125 +                       if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
24126 +                               continue;
24127                         if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
24128                                              NETLINK_CB(cb->skb).portid,
24129                                              cb->nlh->nlmsg_seq, 0,
24130 @@ -1951,6 +1953,9 @@ void rtmsg_ifinfo(int type, struct net_d
24131         int err = -ENOBUFS;
24132         size_t if_info_size;
24133  
24134 +       if (!nx_dev_visible(current_nx_info(), dev))
24135 +               return;
24136 +
24137         skb = nlmsg_new((if_info_size = if_nlmsg_size(dev, 0)), GFP_KERNEL);
24138         if (skb == NULL)
24139                 goto errout;
24140 diff -NurpP --minimal linux-3.10.9/net/core/sock.c linux-3.10.9-vs2.3.6.6/net/core/sock.c
24141 --- linux-3.10.9/net/core/sock.c        2013-07-14 17:01:37.000000000 +0000
24142 +++ linux-3.10.9-vs2.3.6.6/net/core/sock.c      2013-08-22 20:30:00.000000000 +0000
24143 @@ -132,6 +132,10 @@
24144  #include <net/netprio_cgroup.h>
24145  
24146  #include <linux/filter.h>
24147 +#include <linux/vs_socket.h>
24148 +#include <linux/vs_limit.h>
24149 +#include <linux/vs_context.h>
24150 +#include <linux/vs_network.h>
24151  
24152  #include <trace/events/sock.h>
24153  
24154 @@ -1252,6 +1256,8 @@ static struct sock *sk_prot_alloc(struct
24155                         goto out_free_sec;
24156                 sk_tx_queue_clear(sk);
24157         }
24158 +               sock_vx_init(sk);
24159 +               sock_nx_init(sk);
24160  
24161         return sk;
24162  
24163 @@ -1360,6 +1366,11 @@ static void __sk_free(struct sock *sk)
24164                 put_cred(sk->sk_peer_cred);
24165         put_pid(sk->sk_peer_pid);
24166         put_net(sock_net(sk));
24167 +       vx_sock_dec(sk);
24168 +       clr_vx_info(&sk->sk_vx_info);
24169 +       sk->sk_xid = -1;
24170 +       clr_nx_info(&sk->sk_nx_info);
24171 +       sk->sk_nid = -1;
24172         sk_prot_free(sk->sk_prot_creator, sk);
24173  }
24174  
24175 @@ -1420,6 +1431,8 @@ struct sock *sk_clone_lock(const struct
24176  
24177                 /* SANITY */
24178                 get_net(sock_net(newsk));
24179 +               sock_vx_init(newsk);
24180 +               sock_nx_init(newsk);
24181                 sk_node_init(&newsk->sk_node);
24182                 sock_lock_init(newsk);
24183                 bh_lock_sock(newsk);
24184 @@ -1476,6 +1489,12 @@ struct sock *sk_clone_lock(const struct
24185                 smp_wmb();
24186                 atomic_set(&newsk->sk_refcnt, 2);
24187  
24188 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
24189 +               newsk->sk_xid = sk->sk_xid;
24190 +               vx_sock_inc(newsk);
24191 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
24192 +               newsk->sk_nid = sk->sk_nid;
24193 +
24194                 /*
24195                  * Increment the counter in the same struct proto as the master
24196                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
24197 @@ -2271,6 +2290,12 @@ void sock_init_data(struct socket *sock,
24198  
24199         sk->sk_stamp = ktime_set(-1L, 0);
24200  
24201 +       set_vx_info(&sk->sk_vx_info, current_vx_info());
24202 +       sk->sk_xid = vx_current_xid();
24203 +       vx_sock_inc(sk);
24204 +       set_nx_info(&sk->sk_nx_info, current_nx_info());
24205 +       sk->sk_nid = nx_current_nid();
24206 +
24207         /*
24208          * Before updating sk_refcnt, we must commit prior changes to memory
24209          * (Documentation/RCU/rculist_nulls.txt for details)
24210 diff -NurpP --minimal linux-3.10.9/net/ipv4/af_inet.c linux-3.10.9-vs2.3.6.6/net/ipv4/af_inet.c
24211 --- linux-3.10.9/net/ipv4/af_inet.c     2013-07-14 17:01:37.000000000 +0000
24212 +++ linux-3.10.9-vs2.3.6.6/net/ipv4/af_inet.c   2013-08-22 20:30:00.000000000 +0000
24213 @@ -118,6 +118,7 @@
24214  #ifdef CONFIG_IP_MROUTE
24215  #include <linux/mroute.h>
24216  #endif
24217 +#include <linux/vs_limit.h>
24218  
24219  
24220  /* The inetsw table contains everything that inet_create needs to
24221 @@ -338,10 +339,13 @@ lookup_protocol:
24222         }
24223  
24224         err = -EPERM;
24225 +       if ((protocol == IPPROTO_ICMP) &&
24226 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
24227 +               goto override;
24228         if (sock->type == SOCK_RAW && !kern &&
24229             !ns_capable(net->user_ns, CAP_NET_RAW))
24230                 goto out_rcu_unlock;
24231 -
24232 +override:
24233         sock->ops = answer->ops;
24234         answer_prot = answer->prot;
24235         answer_no_check = answer->no_check;
24236 @@ -462,6 +466,7 @@ int inet_bind(struct socket *sock, struc
24237         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
24238         struct sock *sk = sock->sk;
24239         struct inet_sock *inet = inet_sk(sk);
24240 +       struct nx_v4_sock_addr nsa;
24241         struct net *net = sock_net(sk);
24242         unsigned short snum;
24243         int chk_addr_ret;
24244 @@ -486,7 +491,11 @@ int inet_bind(struct socket *sock, struc
24245                         goto out;
24246         }
24247  
24248 -       chk_addr_ret = inet_addr_type(net, addr->sin_addr.s_addr);
24249 +       err = v4_map_sock_addr(inet, addr, &nsa);
24250 +       if (err)
24251 +               goto out;
24252 +
24253 +       chk_addr_ret = inet_addr_type(net, nsa.saddr);
24254  
24255         /* Not specified by any standard per-se, however it breaks too
24256          * many applications when removed.  It is unfortunate since
24257 @@ -498,7 +507,7 @@ int inet_bind(struct socket *sock, struc
24258         err = -EADDRNOTAVAIL;
24259         if (!sysctl_ip_nonlocal_bind &&
24260             !(inet->freebind || inet->transparent) &&
24261 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
24262 +           nsa.saddr != htonl(INADDR_ANY) &&
24263             chk_addr_ret != RTN_LOCAL &&
24264             chk_addr_ret != RTN_MULTICAST &&
24265             chk_addr_ret != RTN_BROADCAST)
24266 @@ -524,7 +533,7 @@ int inet_bind(struct socket *sock, struc
24267         if (sk->sk_state != TCP_CLOSE || inet->inet_num)
24268                 goto out_release_sock;
24269  
24270 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24271 +       v4_set_sock_addr(inet, &nsa);
24272         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24273                 inet->inet_saddr = 0;  /* Use device */
24274  
24275 @@ -743,11 +752,13 @@ int inet_getname(struct socket *sock, st
24276                      peer == 1))
24277                         return -ENOTCONN;
24278                 sin->sin_port = inet->inet_dport;
24279 -               sin->sin_addr.s_addr = inet->inet_daddr;
24280 +               sin->sin_addr.s_addr =
24281 +                       nx_map_sock_lback(sk->sk_nx_info, inet->inet_daddr);
24282         } else {
24283                 __be32 addr = inet->inet_rcv_saddr;
24284                 if (!addr)
24285                         addr = inet->inet_saddr;
24286 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
24287                 sin->sin_port = inet->inet_sport;
24288                 sin->sin_addr.s_addr = addr;
24289         }
24290 diff -NurpP --minimal linux-3.10.9/net/ipv4/arp.c linux-3.10.9-vs2.3.6.6/net/ipv4/arp.c
24291 --- linux-3.10.9/net/ipv4/arp.c 2013-07-14 17:01:37.000000000 +0000
24292 +++ linux-3.10.9-vs2.3.6.6/net/ipv4/arp.c       2013-08-22 20:30:00.000000000 +0000
24293 @@ -1332,6 +1332,7 @@ static void arp_format_neigh_entry(struc
24294         struct net_device *dev = n->dev;
24295         int hatype = dev->type;
24296  
24297 +       /* FIXME: check for network context */
24298         read_lock(&n->lock);
24299         /* Convert hardware address to XX:XX:XX:XX ... form. */
24300  #if IS_ENABLED(CONFIG_AX25)
24301 @@ -1363,6 +1364,7 @@ static void arp_format_pneigh_entry(stru
24302         int hatype = dev ? dev->type : 0;
24303         char tbuf[16];
24304  
24305 +       /* FIXME: check for network context */
24306         sprintf(tbuf, "%pI4", n->key);
24307         seq_printf(seq, "%-16s 0x%-10x0x%-10x%s     *        %s\n",
24308                    tbuf, hatype, ATF_PUBL | ATF_PERM, "00:00:00:00:00:00",
24309 diff -NurpP --minimal linux-3.10.9/net/ipv4/devinet.c linux-3.10.9-vs2.3.6.6/net/ipv4/devinet.c
24310 --- linux-3.10.9/net/ipv4/devinet.c     2013-07-14 17:01:37.000000000 +0000
24311 +++ linux-3.10.9-vs2.3.6.6/net/ipv4/devinet.c   2013-08-22 20:30:00.000000000 +0000
24312 @@ -522,6 +522,7 @@ struct in_device *inetdev_by_index(struc
24313  }
24314  EXPORT_SYMBOL(inetdev_by_index);
24315  
24316 +
24317  /* Called only from RTNL semaphored context. No locks. */
24318  
24319  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
24320 @@ -940,6 +941,8 @@ int devinet_ioctl(struct net *net, unsig
24321  
24322         in_dev = __in_dev_get_rtnl(dev);
24323         if (in_dev) {
24324 +               struct nx_info *nxi = current_nx_info();
24325 +
24326                 if (tryaddrmatch) {
24327                         /* Matthias Andree */
24328                         /* compare label and address (4.4BSD style) */
24329 @@ -948,6 +951,8 @@ int devinet_ioctl(struct net *net, unsig
24330                            This is checked above. */
24331                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24332                              ifap = &ifa->ifa_next) {
24333 +                               if (!nx_v4_ifa_visible(nxi, ifa))
24334 +                                       continue;
24335                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
24336                                     sin_orig.sin_addr.s_addr ==
24337                                                         ifa->ifa_local) {
24338 @@ -960,9 +965,12 @@ int devinet_ioctl(struct net *net, unsig
24339                    comparing just the label */
24340                 if (!ifa) {
24341                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24342 -                            ifap = &ifa->ifa_next)
24343 +                            ifap = &ifa->ifa_next) {
24344 +                               if (!nx_v4_ifa_visible(nxi, ifa))
24345 +                                       continue;
24346                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
24347                                         break;
24348 +                       }
24349                 }
24350         }
24351  
24352 @@ -1116,6 +1124,8 @@ static int inet_gifconf(struct net_devic
24353                 goto out;
24354  
24355         for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
24356 +               if (!nx_v4_ifa_visible(current_nx_info(), ifa))
24357 +                       continue;
24358                 if (!buf) {
24359                         done += sizeof(ifr);
24360                         continue;
24361 @@ -1519,6 +1529,7 @@ static int inet_dump_ifaddr(struct sk_bu
24362         struct net_device *dev;
24363         struct in_device *in_dev;
24364         struct in_ifaddr *ifa;
24365 +       struct sock *sk = skb->sk;
24366         struct hlist_head *head;
24367  
24368         s_h = cb->args[0];
24369 @@ -1542,6 +1553,8 @@ static int inet_dump_ifaddr(struct sk_bu
24370  
24371                         for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
24372                              ifa = ifa->ifa_next, ip_idx++) {
24373 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
24374 +                               continue;
24375                                 if (ip_idx < s_ip_idx)
24376                                         continue;
24377                                 if (inet_fill_ifaddr(skb, ifa,
24378 diff -NurpP --minimal linux-3.10.9/net/ipv4/fib_trie.c linux-3.10.9-vs2.3.6.6/net/ipv4/fib_trie.c
24379 --- linux-3.10.9/net/ipv4/fib_trie.c    2013-07-14 17:01:37.000000000 +0000
24380 +++ linux-3.10.9-vs2.3.6.6/net/ipv4/fib_trie.c  2013-08-22 20:30:00.000000000 +0000
24381 @@ -2539,6 +2539,7 @@ static int fib_route_seq_show(struct seq
24382                             || fa->fa_type == RTN_MULTICAST)
24383                                 continue;
24384  
24385 +                       /* FIXME: check for network context? */
24386                         if (fi)
24387                                 seq_printf(seq,
24388                                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t"
24389 diff -NurpP --minimal linux-3.10.9/net/ipv4/inet_connection_sock.c linux-3.10.9-vs2.3.6.6/net/ipv4/inet_connection_sock.c
24390 --- linux-3.10.9/net/ipv4/inet_connection_sock.c        2013-07-14 17:01:37.000000000 +0000
24391 +++ linux-3.10.9-vs2.3.6.6/net/ipv4/inet_connection_sock.c      2013-08-22 20:30:00.000000000 +0000
24392 @@ -53,6 +53,37 @@ void inet_get_local_port_range(int *low,
24393  }
24394  EXPORT_SYMBOL(inet_get_local_port_range);
24395  
24396 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24397 +{
24398 +       __be32  sk1_rcv_saddr = sk_rcv_saddr(sk1),
24399 +               sk2_rcv_saddr = sk_rcv_saddr(sk2);
24400 +
24401 +       if (inet_v6_ipv6only(sk2))
24402 +               return 0;
24403 +
24404 +       if (sk1_rcv_saddr &&
24405 +           sk2_rcv_saddr &&
24406 +           sk1_rcv_saddr == sk2_rcv_saddr)
24407 +               return 1;
24408 +
24409 +       if (sk1_rcv_saddr &&
24410 +           !sk2_rcv_saddr &&
24411 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
24412 +               return 1;
24413 +
24414 +       if (sk2_rcv_saddr &&
24415 +           !sk1_rcv_saddr &&
24416 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
24417 +               return 1;
24418 +
24419 +       if (!sk1_rcv_saddr &&
24420 +           !sk2_rcv_saddr &&
24421 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
24422 +               return 1;
24423 +
24424 +       return 0;
24425 +}
24426 +
24427  int inet_csk_bind_conflict(const struct sock *sk,
24428                            const struct inet_bind_bucket *tb, bool relax)
24429  {
24430 @@ -79,17 +110,12 @@ int inet_csk_bind_conflict(const struct
24431                             (!reuseport || !sk2->sk_reuseport ||
24432                             (sk2->sk_state != TCP_TIME_WAIT &&
24433                              !uid_eq(uid, sock_i_uid(sk2))))) {
24434 -                               const __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
24435 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr(sk) ||
24436 -                                   sk2_rcv_saddr == sk_rcv_saddr(sk))
24437 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
24438                                         break;
24439                         }
24440                         if (!relax && reuse && sk2->sk_reuse &&
24441                             sk2->sk_state != TCP_LISTEN) {
24442 -                               const __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
24443 -
24444 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr(sk) ||
24445 -                                   sk2_rcv_saddr == sk_rcv_saddr(sk))
24446 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
24447                                         break;
24448                         }
24449                 }
24450 diff -NurpP --minimal linux-3.10.9/net/ipv4/inet_diag.c linux-3.10.9-vs2.3.6.6/net/ipv4/inet_diag.c
24451 --- linux-3.10.9/net/ipv4/inet_diag.c   2013-07-14 17:01:37.000000000 +0000
24452 +++ linux-3.10.9-vs2.3.6.6/net/ipv4/inet_diag.c 2013-08-22 20:30:00.000000000 +0000
24453 @@ -31,6 +31,8 @@
24454  
24455  #include <linux/inet.h>
24456  #include <linux/stddef.h>
24457 +#include <linux/vs_network.h>
24458 +#include <linux/vs_inet.h>
24459  
24460  #include <linux/inet_diag.h>
24461  #include <linux/sock_diag.h>
24462 @@ -106,8 +108,10 @@ int inet_sk_diag_fill(struct sock *sk, s
24463  
24464         r->id.idiag_sport = inet->inet_sport;
24465         r->id.idiag_dport = inet->inet_dport;
24466 -       r->id.idiag_src[0] = inet->inet_rcv_saddr;
24467 -       r->id.idiag_dst[0] = inet->inet_daddr;
24468 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info,
24469 +               inet->inet_rcv_saddr);
24470 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info,
24471 +               inet->inet_daddr);
24472  
24473         if (nla_put_u8(skb, INET_DIAG_SHUTDOWN, sk->sk_shutdown))
24474                 goto errout;
24475 @@ -244,8 +248,8 @@ static int inet_twsk_diag_fill(struct in
24476         sock_diag_save_cookie(tw, r->id.idiag_cookie);
24477         r->id.idiag_sport     = tw->tw_sport;
24478         r->id.idiag_dport     = tw->tw_dport;
24479 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
24480 -       r->id.idiag_dst[0]    = tw->tw_daddr;
24481 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
24482 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
24483         r->idiag_state        = tw->tw_substate;
24484         r->idiag_timer        = 3;
24485         r->idiag_expires      = DIV_ROUND_UP(tmo * 1000, HZ);
24486 @@ -289,12 +293,14 @@ int inet_diag_dump_one_icsk(struct inet_
24487  
24488         err = -EINVAL;
24489         if (req->sdiag_family == AF_INET) {
24490 +               /* TODO: lback */
24491                 sk = inet_lookup(net, hashinfo, req->id.idiag_dst[0],
24492                                  req->id.idiag_dport, req->id.idiag_src[0],
24493                                  req->id.idiag_sport, req->id.idiag_if);
24494         }
24495  #if IS_ENABLED(CONFIG_IPV6)
24496         else if (req->sdiag_family == AF_INET6) {
24497 +               /* TODO: lback */
24498                 sk = inet6_lookup(net, hashinfo,
24499                                   (struct in6_addr *)req->id.idiag_dst,
24500                                   req->id.idiag_dport,
24501 @@ -496,6 +502,7 @@ int inet_diag_bc_sk(const struct nlattr
24502         } else
24503  #endif
24504         {
24505 +                       /* TODO: lback */
24506                 entry.saddr = &inet->inet_rcv_saddr;
24507                 entry.daddr = &inet->inet_daddr;
24508         }
24509 @@ -654,6 +661,7 @@ static int inet_twsk_diag_dump(struct in
24510                 } else
24511  #endif
24512                 {
24513 +                       /* TODO: lback */
24514                         entry.saddr = &tw->tw_rcv_saddr;
24515                         entry.daddr = &tw->tw_daddr;
24516                 }
24517 @@ -732,8 +740,8 @@ static int inet_diag_fill_req(struct sk_
24518  
24519         r->id.idiag_sport = inet->inet_sport;
24520         r->id.idiag_dport = ireq->rmt_port;
24521 -       r->id.idiag_src[0] = ireq->loc_addr;
24522 -       r->id.idiag_dst[0] = ireq->rmt_addr;
24523 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
24524 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
24525         r->idiag_expires = jiffies_to_msecs(tmo);
24526         r->idiag_rqueue = 0;
24527         r->idiag_wqueue = 0;
24528 @@ -796,6 +804,7 @@ static int inet_diag_dump_reqs(struct sk
24529                             r->id.idiag_dport)
24530                                 continue;
24531  
24532 +                       /* TODO: lback */
24533                         if (bc) {
24534                                 inet_diag_req_addrs(sk, req, &entry);
24535                                 entry.dport = ntohs(ireq->rmt_port);
24536 @@ -852,6 +861,8 @@ void inet_diag_dump_icsk(struct inet_has
24537                                 if (!net_eq(sock_net(sk), net))
24538                                         continue;
24539  
24540 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24541 +                                       continue;
24542                                 if (num < s_num) {
24543                                         num++;
24544                                         continue;
24545 @@ -924,6 +935,8 @@ skip_listen_ht:
24546  
24547                         if (!net_eq(sock_net(sk), net))
24548                                 continue;
24549 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24550 +                               continue;
24551                         if (num < s_num)
24552                                 goto next_normal;
24553                         if (!(r->idiag_states & (1 << sk->sk_state)))
24554 @@ -952,7 +965,8 @@ next_normal:
24555                                     &head->twchain) {
24556                                 if (!net_eq(twsk_net(tw), net))
24557                                         continue;
24558 -
24559 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
24560 +                                       continue;
24561                                 if (num < s_num)
24562                                         goto next_dying;
24563                                 if (r->sdiag_family != AF_UNSPEC &&
24564 diff -NurpP --minimal linux-3.10.9/net/ipv4/inet_hashtables.c linux-3.10.9-vs2.3.6.6/net/ipv4/inet_hashtables.c
24565 --- linux-3.10.9/net/ipv4/inet_hashtables.c     2013-05-31 13:45:32.000000000 +0000
24566 +++ linux-3.10.9-vs2.3.6.6/net/ipv4/inet_hashtables.c   2013-08-22 20:30:00.000000000 +0000
24567 @@ -22,6 +22,7 @@
24568  #include <net/inet_connection_sock.h>
24569  #include <net/inet_hashtables.h>
24570  #include <net/secure_seq.h>
24571 +#include <net/route.h>
24572  #include <net/ip.h>
24573  
24574  /*
24575 @@ -156,6 +157,11 @@ static inline int compute_score(struct s
24576                         if (rcv_saddr != daddr)
24577                                 return -1;
24578                         score += 4;
24579 +               } else {
24580 +                       /* block non nx_info ips */
24581 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
24582 +                               daddr, NXA_MASK_BIND))
24583 +                               return -1;
24584                 }
24585                 if (sk->sk_bound_dev_if) {
24586                         if (sk->sk_bound_dev_if != dif)
24587 @@ -173,7 +179,6 @@ static inline int compute_score(struct s
24588   * wildcarded during the search since they can never be otherwise.
24589   */
24590  
24591 -
24592  struct sock *__inet_lookup_listener(struct net *net,
24593                                     struct inet_hashinfo *hashinfo,
24594                                     const __be32 saddr, __be16 sport,
24595 @@ -209,6 +214,7 @@ begin:
24596                         phash = next_pseudo_random32(phash);
24597                 }
24598         }
24599 +
24600         /*
24601          * if the nulls value we got at the end of this lookup is
24602          * not the expected one, we must restart lookup.
24603 diff -NurpP --minimal linux-3.10.9/net/ipv4/netfilter.c linux-3.10.9-vs2.3.6.6/net/ipv4/netfilter.c
24604 --- linux-3.10.9/net/ipv4/netfilter.c   2013-07-14 17:01:37.000000000 +0000
24605 +++ linux-3.10.9-vs2.3.6.6/net/ipv4/netfilter.c 2013-08-22 20:30:00.000000000 +0000
24606 @@ -11,7 +11,7 @@
24607  #include <linux/skbuff.h>
24608  #include <linux/gfp.h>
24609  #include <linux/export.h>
24610 -#include <net/route.h>
24611 +// #include <net/route.h>
24612  #include <net/xfrm.h>
24613  #include <net/ip.h>
24614  #include <net/netfilter/nf_queue.h>
24615 diff -NurpP --minimal linux-3.10.9/net/ipv4/raw.c linux-3.10.9-vs2.3.6.6/net/ipv4/raw.c
24616 --- linux-3.10.9/net/ipv4/raw.c 2013-05-31 13:45:32.000000000 +0000
24617 +++ linux-3.10.9-vs2.3.6.6/net/ipv4/raw.c       2013-08-22 20:30:00.000000000 +0000
24618 @@ -116,7 +116,7 @@ static struct sock *__raw_v4_lookup(stru
24619  
24620                 if (net_eq(sock_net(sk), net) && inet->inet_num == num  &&
24621                     !(inet->inet_daddr && inet->inet_daddr != raddr)    &&
24622 -                   !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
24623 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
24624                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
24625                         goto found; /* gotcha */
24626         }
24627 @@ -395,6 +395,12 @@ static int raw_send_hdrinc(struct sock *
24628                 icmp_out_count(net, ((struct icmphdr *)
24629                         skb_transport_header(skb))->type);
24630  
24631 +       err = -EPERM;
24632 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
24633 +               sk->sk_nx_info &&
24634 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
24635 +               goto error_free;
24636 +
24637         err = NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT, skb, NULL,
24638                       rt->dst.dev, dst_output);
24639         if (err > 0)
24640 @@ -580,6 +586,16 @@ static int raw_sendmsg(struct kiocb *ioc
24641                         goto done;
24642         }
24643  
24644 +       if (sk->sk_nx_info) {
24645 +               rt = ip_v4_find_src(sock_net(sk), sk->sk_nx_info, &fl4);
24646 +               if (IS_ERR(rt)) {
24647 +                       err = PTR_ERR(rt);
24648 +                       rt = NULL;
24649 +                       goto done;
24650 +               }
24651 +               ip_rt_put(rt);
24652 +       }
24653 +
24654         security_sk_classify_flow(sk, flowi4_to_flowi(&fl4));
24655         rt = ip_route_output_flow(sock_net(sk), &fl4, sk);
24656         if (IS_ERR(rt)) {
24657 @@ -656,17 +672,19 @@ static int raw_bind(struct sock *sk, str
24658  {
24659         struct inet_sock *inet = inet_sk(sk);
24660         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
24661 +       struct nx_v4_sock_addr nsa = { 0 };
24662         int ret = -EINVAL;
24663         int chk_addr_ret;
24664  
24665         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
24666                 goto out;
24667 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
24668 +       v4_map_sock_addr(inet, addr, &nsa);
24669 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
24670         ret = -EADDRNOTAVAIL;
24671 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
24672 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
24673             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
24674                 goto out;
24675 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24676 +       v4_set_sock_addr(inet, &nsa);
24677         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24678                 inet->inet_saddr = 0;  /* Use device */
24679         sk_dst_reset(sk);
24680 @@ -718,7 +736,8 @@ static int raw_recvmsg(struct kiocb *ioc
24681         /* Copy the address. */
24682         if (sin) {
24683                 sin->sin_family = AF_INET;
24684 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
24685 +               sin->sin_addr.s_addr =
24686 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
24687                 sin->sin_port = 0;
24688                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
24689         }
24690 @@ -913,7 +932,8 @@ static struct sock *raw_get_first(struct
24691         for (state->bucket = 0; state->bucket < RAW_HTABLE_SIZE;
24692                         ++state->bucket) {
24693                 sk_for_each(sk, &state->h->ht[state->bucket])
24694 -                       if (sock_net(sk) == seq_file_net(seq))
24695 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
24696 +                           nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24697                                 goto found;
24698         }
24699         sk = NULL;
24700 @@ -929,7 +949,8 @@ static struct sock *raw_get_next(struct
24701                 sk = sk_next(sk);
24702  try_again:
24703                 ;
24704 -       } while (sk && sock_net(sk) != seq_file_net(seq));
24705 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
24706 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
24707  
24708         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
24709                 sk = sk_head(&state->h->ht[state->bucket]);
24710 diff -NurpP --minimal linux-3.10.9/net/ipv4/route.c linux-3.10.9-vs2.3.6.6/net/ipv4/route.c
24711 --- linux-3.10.9/net/ipv4/route.c       2013-07-14 17:01:37.000000000 +0000
24712 +++ linux-3.10.9-vs2.3.6.6/net/ipv4/route.c     2013-08-22 20:30:00.000000000 +0000
24713 @@ -2003,7 +2003,7 @@ struct rtable *__ip_route_output_key(str
24714  
24715  
24716         if (fl4->flowi4_oif) {
24717 -               dev_out = dev_get_by_index_rcu(net, fl4->flowi4_oif);
24718 +               dev_out = dev_get_by_index_real_rcu(net, fl4->flowi4_oif);
24719                 rth = ERR_PTR(-ENODEV);
24720                 if (dev_out == NULL)
24721                         goto out;
24722 diff -NurpP --minimal linux-3.10.9/net/ipv4/tcp.c linux-3.10.9-vs2.3.6.6/net/ipv4/tcp.c
24723 --- linux-3.10.9/net/ipv4/tcp.c 2013-07-14 17:01:37.000000000 +0000
24724 +++ linux-3.10.9-vs2.3.6.6/net/ipv4/tcp.c       2013-08-22 20:30:00.000000000 +0000
24725 @@ -268,6 +268,7 @@
24726  #include <linux/crypto.h>
24727  #include <linux/time.h>
24728  #include <linux/slab.h>
24729 +#include <linux/in.h>
24730  
24731  #include <net/icmp.h>
24732  #include <net/inet_common.h>
24733 diff -NurpP --minimal linux-3.10.9/net/ipv4/tcp_ipv4.c linux-3.10.9-vs2.3.6.6/net/ipv4/tcp_ipv4.c
24734 --- linux-3.10.9/net/ipv4/tcp_ipv4.c    2013-07-14 17:01:37.000000000 +0000
24735 +++ linux-3.10.9-vs2.3.6.6/net/ipv4/tcp_ipv4.c  2013-08-22 20:30:00.000000000 +0000
24736 @@ -2263,6 +2263,12 @@ static void *listening_get_next(struct s
24737                 req = req->dl_next;
24738                 while (1) {
24739                         while (req) {
24740 +                               vxdprintk(VXD_CBIT(net, 6),
24741 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
24742 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
24743 +                               if (req->sk &&
24744 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
24745 +                                       continue;
24746                                 if (req->rsk_ops->family == st->family) {
24747                                         cur = req;
24748                                         goto out;
24749 @@ -2287,6 +2293,10 @@ get_req:
24750         }
24751  get_sk:
24752         sk_nulls_for_each_from(sk, node) {
24753 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
24754 +                       sk, sk->sk_nid, nx_current_nid());
24755 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24756 +                       continue;
24757                 if (!net_eq(sock_net(sk), net))
24758                         continue;
24759                 if (sk->sk_family == st->family) {
24760 @@ -2363,6 +2373,11 @@ static void *established_get_first(struc
24761  
24762                 spin_lock_bh(lock);
24763                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
24764 +                       vxdprintk(VXD_CBIT(net, 6),
24765 +                               "sk,egf: %p [#%d] (from %d)",
24766 +                               sk, sk->sk_nid, nx_current_nid());
24767 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24768 +                               continue;
24769                         if (sk->sk_family != st->family ||
24770                             !net_eq(sock_net(sk), net)) {
24771                                 continue;
24772 @@ -2373,6 +2388,11 @@ static void *established_get_first(struc
24773                 st->state = TCP_SEQ_STATE_TIME_WAIT;
24774                 inet_twsk_for_each(tw, node,
24775                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
24776 +                       vxdprintk(VXD_CBIT(net, 6),
24777 +                               "tw: %p [#%d] (from %d)",
24778 +                               tw, tw->tw_nid, nx_current_nid());
24779 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
24780 +                               continue;
24781                         if (tw->tw_family != st->family ||
24782                             !net_eq(twsk_net(tw), net)) {
24783                                 continue;
24784 @@ -2402,7 +2422,9 @@ static void *established_get_next(struct
24785                 tw = cur;
24786                 tw = tw_next(tw);
24787  get_tw:
24788 -               while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
24789 +               while (tw && (tw->tw_family != st->family ||
24790 +                       !net_eq(twsk_net(tw), net) ||
24791 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
24792                         tw = tw_next(tw);
24793                 }
24794                 if (tw) {
24795 @@ -2426,6 +2448,11 @@ get_tw:
24796                 sk = sk_nulls_next(sk);
24797  
24798         sk_nulls_for_each_from(sk, node) {
24799 +               vxdprintk(VXD_CBIT(net, 6),
24800 +                       "sk,egn: %p [#%d] (from %d)",
24801 +                       sk, sk->sk_nid, nx_current_nid());
24802 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24803 +                       continue;
24804                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
24805                         goto found;
24806         }
24807 @@ -2631,9 +2658,9 @@ static void get_openreq4(const struct so
24808         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
24809                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %pK%n",
24810                 i,
24811 -               ireq->loc_addr,
24812 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
24813                 ntohs(inet_sk(sk)->inet_sport),
24814 -               ireq->rmt_addr,
24815 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
24816                 ntohs(ireq->rmt_port),
24817                 TCP_SYN_RECV,
24818                 0, 0, /* could print option size, but that is af dependent. */
24819 @@ -2656,8 +2683,8 @@ static void get_tcp4_sock(struct sock *s
24820         const struct inet_connection_sock *icsk = inet_csk(sk);
24821         const struct inet_sock *inet = inet_sk(sk);
24822         struct fastopen_queue *fastopenq = icsk->icsk_accept_queue.fastopenq;
24823 -       __be32 dest = inet->inet_daddr;
24824 -       __be32 src = inet->inet_rcv_saddr;
24825 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
24826 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
24827         __u16 destp = ntohs(inet->inet_dport);
24828         __u16 srcp = ntohs(inet->inet_sport);
24829         int rx_queue;
24830 @@ -2715,8 +2742,8 @@ static void get_timewait4_sock(const str
24831         __u16 destp, srcp;
24832         long delta = tw->tw_ttd - jiffies;
24833  
24834 -       dest  = tw->tw_daddr;
24835 -       src   = tw->tw_rcv_saddr;
24836 +       dest  = nx_map_sock_lback(current_nx_info(), tw->tw_daddr);
24837 +       src   = nx_map_sock_lback(current_nx_info(), tw->tw_rcv_saddr);
24838         destp = ntohs(tw->tw_dport);
24839         srcp  = ntohs(tw->tw_sport);
24840  
24841 diff -NurpP --minimal linux-3.10.9/net/ipv4/tcp_minisocks.c linux-3.10.9-vs2.3.6.6/net/ipv4/tcp_minisocks.c
24842 --- linux-3.10.9/net/ipv4/tcp_minisocks.c       2013-07-14 17:01:37.000000000 +0000
24843 +++ linux-3.10.9-vs2.3.6.6/net/ipv4/tcp_minisocks.c     2013-08-22 20:30:00.000000000 +0000
24844 @@ -23,6 +23,9 @@
24845  #include <linux/slab.h>
24846  #include <linux/sysctl.h>
24847  #include <linux/workqueue.h>
24848 +#include <linux/vs_limit.h>
24849 +#include <linux/vs_socket.h>
24850 +#include <linux/vs_context.h>
24851  #include <net/tcp.h>
24852  #include <net/inet_common.h>
24853  #include <net/xfrm.h>
24854 @@ -290,6 +293,11 @@ void tcp_time_wait(struct sock *sk, int
24855                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
24856                 tcptw->tw_ts_offset     = tp->tsoffset;
24857  
24858 +               tw->tw_xid              = sk->sk_xid;
24859 +               tw->tw_vx_info          = NULL;
24860 +               tw->tw_nid              = sk->sk_nid;
24861 +               tw->tw_nx_info          = NULL;
24862 +
24863  #if IS_ENABLED(CONFIG_IPV6)
24864                 if (tw->tw_family == PF_INET6) {
24865                         struct ipv6_pinfo *np = inet6_sk(sk);
24866 diff -NurpP --minimal linux-3.10.9/net/ipv4/udp.c linux-3.10.9-vs2.3.6.6/net/ipv4/udp.c
24867 --- linux-3.10.9/net/ipv4/udp.c 2013-08-22 19:51:36.000000000 +0000
24868 +++ linux-3.10.9-vs2.3.6.6/net/ipv4/udp.c       2013-08-22 20:30:00.000000000 +0000
24869 @@ -306,14 +306,7 @@ fail:
24870  }
24871  EXPORT_SYMBOL(udp_lib_get_port);
24872  
24873 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24874 -{
24875 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
24876 -
24877 -       return  (!ipv6_only_sock(sk2)  &&
24878 -                (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr ||
24879 -                  inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
24880 -}
24881 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
24882  
24883  static unsigned int udp4_portaddr_hash(struct net *net, __be32 saddr,
24884                                        unsigned int port)
24885 @@ -348,6 +341,11 @@ static inline int compute_score(struct s
24886                         if (inet->inet_rcv_saddr != daddr)
24887                                 return -1;
24888                         score += 4;
24889 +               } else {
24890 +                       /* block non nx_info ips */
24891 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
24892 +                               daddr, NXA_MASK_BIND))
24893 +                               return -1;
24894                 }
24895                 if (inet->inet_daddr) {
24896                         if (inet->inet_daddr != saddr)
24897 @@ -458,6 +456,7 @@ begin:
24898         return result;
24899  }
24900  
24901 +
24902  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
24903   * harder than this. -DaveM
24904   */
24905 @@ -504,6 +503,11 @@ begin:
24906         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
24907                 score = compute_score(sk, net, saddr, hnum, sport,
24908                                       daddr, dport, dif);
24909 +               /* FIXME: disabled?
24910 +               if (score == 9) {
24911 +                       result = sk;
24912 +                       break;
24913 +               } else */
24914                 if (score > badness) {
24915                         result = sk;
24916                         badness = score;
24917 @@ -528,6 +532,7 @@ begin:
24918         if (get_nulls_value(node) != slot)
24919                 goto begin;
24920  
24921 +
24922         if (result) {
24923                 if (unlikely(!atomic_inc_not_zero_hint(&result->sk_refcnt, 2)))
24924                         result = NULL;
24925 @@ -537,6 +542,7 @@ begin:
24926                         goto begin;
24927                 }
24928         }
24929 +
24930         rcu_read_unlock();
24931         return result;
24932  }
24933 @@ -580,8 +586,7 @@ static inline struct sock *udp_v4_mcast_
24934                     udp_sk(s)->udp_port_hash != hnum ||
24935                     (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
24936                     (inet->inet_dport != rmt_port && inet->inet_dport) ||
24937 -                   (inet->inet_rcv_saddr &&
24938 -                    inet->inet_rcv_saddr != loc_addr) ||
24939 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
24940                     ipv6_only_sock(s) ||
24941                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
24942                         continue;
24943 @@ -965,6 +970,16 @@ int udp_sendmsg(struct kiocb *iocb, stru
24944                                    inet_sk_flowi_flags(sk)|FLOWI_FLAG_CAN_SLEEP,
24945                                    faddr, saddr, dport, inet->inet_sport);
24946  
24947 +               if (sk->sk_nx_info) {
24948 +                       rt = ip_v4_find_src(net, sk->sk_nx_info, fl4);
24949 +                       if (IS_ERR(rt)) {
24950 +                               err = PTR_ERR(rt);
24951 +                               rt = NULL;
24952 +                               goto out;
24953 +                       }
24954 +                       ip_rt_put(rt);
24955 +               }
24956 +
24957                 security_sk_classify_flow(sk, flowi4_to_flowi(fl4));
24958                 rt = ip_route_output_flow(net, fl4, sk);
24959                 if (IS_ERR(rt)) {
24960 @@ -1272,7 +1287,8 @@ try_again:
24961         if (sin) {
24962                 sin->sin_family = AF_INET;
24963                 sin->sin_port = udp_hdr(skb)->source;
24964 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
24965 +               sin->sin_addr.s_addr = nx_map_sock_lback(
24966 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
24967                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
24968         }
24969         if (inet->cmsg_flags)
24970 @@ -2033,6 +2049,8 @@ static struct sock *udp_get_first(struct
24971                 sk_nulls_for_each(sk, node, &hslot->head) {
24972                         if (!net_eq(sock_net(sk), net))
24973                                 continue;
24974 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24975 +                               continue;
24976                         if (sk->sk_family == state->family)
24977                                 goto found;
24978                 }
24979 @@ -2050,7 +2068,9 @@ static struct sock *udp_get_next(struct
24980  
24981         do {
24982                 sk = sk_nulls_next(sk);
24983 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
24984 +       } while (sk && (!net_eq(sock_net(sk), net) ||
24985 +               sk->sk_family != state->family ||
24986 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
24987  
24988         if (!sk) {
24989                 if (state->bucket <= state->udp_table->mask)
24990 @@ -2146,8 +2166,8 @@ static void udp4_format_sock(struct sock
24991                 int bucket, int *len)
24992  {
24993         struct inet_sock *inet = inet_sk(sp);
24994 -       __be32 dest = inet->inet_daddr;
24995 -       __be32 src  = inet->inet_rcv_saddr;
24996 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
24997 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
24998         __u16 destp       = ntohs(inet->inet_dport);
24999         __u16 srcp        = ntohs(inet->inet_sport);
25000  
25001 diff -NurpP --minimal linux-3.10.9/net/ipv6/Kconfig linux-3.10.9-vs2.3.6.6/net/ipv6/Kconfig
25002 --- linux-3.10.9/net/ipv6/Kconfig       2013-07-14 17:01:38.000000000 +0000
25003 +++ linux-3.10.9-vs2.3.6.6/net/ipv6/Kconfig     2013-08-22 20:30:00.000000000 +0000
25004 @@ -4,8 +4,8 @@
25005  
25006  #   IPv6 as module will cause a CRASH if you try to unload it
25007  menuconfig IPV6
25008 -       tristate "The IPv6 protocol"
25009 -       default m
25010 +       bool "The IPv6 protocol"
25011 +       default n
25012         ---help---
25013           This is complemental support for the IP version 6.
25014           You will still be able to do traditional IPv4 networking as well.
25015 diff -NurpP --minimal linux-3.10.9/net/ipv6/addrconf.c linux-3.10.9-vs2.3.6.6/net/ipv6/addrconf.c
25016 --- linux-3.10.9/net/ipv6/addrconf.c    2013-08-22 19:51:36.000000000 +0000
25017 +++ linux-3.10.9-vs2.3.6.6/net/ipv6/addrconf.c  2013-08-22 20:30:00.000000000 +0000
25018 @@ -94,6 +94,8 @@
25019  #include <linux/proc_fs.h>
25020  #include <linux/seq_file.h>
25021  #include <linux/export.h>
25022 +#include <linux/vs_network.h>
25023 +#include <linux/vs_inet6.h>
25024  
25025  /* Set to 3 to get tracing... */
25026  #define ACONF_DEBUG 2
25027 @@ -1323,7 +1325,7 @@ out:
25028  
25029  int ipv6_dev_get_saddr(struct net *net, const struct net_device *dst_dev,
25030                        const struct in6_addr *daddr, unsigned int prefs,
25031 -                      struct in6_addr *saddr)
25032 +                      struct in6_addr *saddr, struct nx_info *nxi)
25033  {
25034         struct ipv6_saddr_score scores[2],
25035                                 *score = &scores[0], *hiscore = &scores[1];
25036 @@ -1395,6 +1397,8 @@ int ipv6_dev_get_saddr(struct net *net,
25037                                                dev->name);
25038                                 continue;
25039                         }
25040 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
25041 +                               continue;
25042  
25043                         score->rule = -1;
25044                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
25045 @@ -3423,7 +3427,10 @@ static void if6_seq_stop(struct seq_file
25046  static int if6_seq_show(struct seq_file *seq, void *v)
25047  {
25048         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
25049 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25050 +
25051 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
25052 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
25053 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25054                    &ifp->addr,
25055                    ifp->idev->dev->ifindex,
25056                    ifp->prefix_len,
25057 @@ -3927,6 +3934,11 @@ static int in6_dump_addrs(struct inet6_d
25058         struct ifacaddr6 *ifaca;
25059         int err = 1;
25060         int ip_idx = *p_ip_idx;
25061 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25062 +
25063 +       /* disable ipv6 on non v6 guests */
25064 +       if (nxi && !nx_info_has_v6(nxi))
25065 +               return skb->len;
25066  
25067         read_lock_bh(&idev->lock);
25068         switch (type) {
25069 @@ -3937,6 +3949,8 @@ static int in6_dump_addrs(struct inet6_d
25070                 list_for_each_entry(ifa, &idev->addr_list, if_list) {
25071                         if (++ip_idx < s_ip_idx)
25072                                 continue;
25073 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
25074 +                                       continue;
25075                         err = inet6_fill_ifaddr(skb, ifa,
25076                                                 NETLINK_CB(cb->skb).portid,
25077                                                 cb->nlh->nlmsg_seq,
25078 @@ -3954,6 +3968,8 @@ static int in6_dump_addrs(struct inet6_d
25079                      ifmca = ifmca->next, ip_idx++) {
25080                         if (ip_idx < s_ip_idx)
25081                                 continue;
25082 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
25083 +                                       continue;
25084                         err = inet6_fill_ifmcaddr(skb, ifmca,
25085                                                   NETLINK_CB(cb->skb).portid,
25086                                                   cb->nlh->nlmsg_seq,
25087 @@ -3969,6 +3985,8 @@ static int in6_dump_addrs(struct inet6_d
25088                      ifaca = ifaca->aca_next, ip_idx++) {
25089                         if (ip_idx < s_ip_idx)
25090                                 continue;
25091 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
25092 +                                       continue;
25093                         err = inet6_fill_ifacaddr(skb, ifaca,
25094                                                   NETLINK_CB(cb->skb).portid,
25095                                                   cb->nlh->nlmsg_seq,
25096 @@ -3997,6 +4015,10 @@ static int inet6_dump_addr(struct sk_buf
25097         struct inet6_dev *idev;
25098         struct hlist_head *head;
25099  
25100 +       /* FIXME: maybe disable ipv6 on non v6 guests?
25101 +       if (skb->sk && skb->sk->sk_vx_info)
25102 +               return skb->len; */
25103 +
25104         s_h = cb->args[0];
25105         s_idx = idx = cb->args[1];
25106         s_ip_idx = ip_idx = cb->args[2];
25107 @@ -4432,6 +4454,7 @@ static int inet6_dump_ifinfo(struct sk_b
25108         struct net_device *dev;
25109         struct inet6_dev *idev;
25110         struct hlist_head *head;
25111 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25112  
25113         s_h = cb->args[0];
25114         s_idx = cb->args[1];
25115 @@ -4443,6 +4466,8 @@ static int inet6_dump_ifinfo(struct sk_b
25116                 hlist_for_each_entry_rcu(dev, head, index_hlist) {
25117                         if (idx < s_idx)
25118                                 goto cont;
25119 +                       if (!v6_dev_in_nx_info(dev, nxi))
25120 +                               goto cont;
25121                         idev = __in6_dev_get(dev);
25122                         if (!idev)
25123                                 goto cont;
25124 diff -NurpP --minimal linux-3.10.9/net/ipv6/af_inet6.c linux-3.10.9-vs2.3.6.6/net/ipv6/af_inet6.c
25125 --- linux-3.10.9/net/ipv6/af_inet6.c    2013-07-14 17:01:38.000000000 +0000
25126 +++ linux-3.10.9-vs2.3.6.6/net/ipv6/af_inet6.c  2013-08-22 20:30:00.000000000 +0000
25127 @@ -43,6 +43,8 @@
25128  #include <linux/netdevice.h>
25129  #include <linux/icmpv6.h>
25130  #include <linux/netfilter_ipv6.h>
25131 +#include <linux/vs_inet.h>
25132 +#include <linux/vs_inet6.h>
25133  
25134  #include <net/ip.h>
25135  #include <net/ipv6.h>
25136 @@ -159,10 +161,13 @@ lookup_protocol:
25137         }
25138  
25139         err = -EPERM;
25140 +       if ((protocol == IPPROTO_ICMPV6) &&
25141 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
25142 +               goto override;
25143         if (sock->type == SOCK_RAW && !kern &&
25144             !ns_capable(net->user_ns, CAP_NET_RAW))
25145                 goto out_rcu_unlock;
25146 -
25147 +override:
25148         sock->ops = answer->ops;
25149         answer_prot = answer->prot;
25150         answer_no_check = answer->no_check;
25151 @@ -262,6 +267,7 @@ int inet6_bind(struct socket *sock, stru
25152         struct inet_sock *inet = inet_sk(sk);
25153         struct ipv6_pinfo *np = inet6_sk(sk);
25154         struct net *net = sock_net(sk);
25155 +       struct nx_v6_sock_addr nsa;
25156         __be32 v4addr = 0;
25157         unsigned short snum;
25158         int addr_type = 0;
25159 @@ -277,6 +283,10 @@ int inet6_bind(struct socket *sock, stru
25160         if (addr->sin6_family != AF_INET6)
25161                 return -EAFNOSUPPORT;
25162  
25163 +       err = v6_map_sock_addr(inet, addr, &nsa);
25164 +       if (err)
25165 +               return err;
25166 +
25167         addr_type = ipv6_addr_type(&addr->sin6_addr);
25168         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
25169                 return -EINVAL;
25170 @@ -308,6 +318,7 @@ int inet6_bind(struct socket *sock, stru
25171                 /* Reproduce AF_INET checks to make the bindings consistent */
25172                 v4addr = addr->sin6_addr.s6_addr32[3];
25173                 chk_addr_ret = inet_addr_type(net, v4addr);
25174 +
25175                 if (!sysctl_ip_nonlocal_bind &&
25176                     !(inet->freebind || inet->transparent) &&
25177                     v4addr != htonl(INADDR_ANY) &&
25178 @@ -317,6 +328,10 @@ int inet6_bind(struct socket *sock, stru
25179                         err = -EADDRNOTAVAIL;
25180                         goto out;
25181                 }
25182 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
25183 +                       err = -EADDRNOTAVAIL;
25184 +                       goto out;
25185 +               }
25186         } else {
25187                 if (addr_type != IPV6_ADDR_ANY) {
25188                         struct net_device *dev = NULL;
25189 @@ -343,6 +358,11 @@ int inet6_bind(struct socket *sock, stru
25190                                 }
25191                         }
25192  
25193 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25194 +                               err = -EADDRNOTAVAIL;
25195 +                               goto out_unlock;
25196 +                       }
25197 +
25198                         /* ipv4 addr of the socket is invalid.  Only the
25199                          * unspecified and mapped address have a v4 equivalent.
25200                          */
25201 @@ -359,6 +379,9 @@ int inet6_bind(struct socket *sock, stru
25202                 }
25203         }
25204  
25205 +       /* what's that for? */
25206 +       v6_set_sock_addr(inet, &nsa);
25207 +
25208         inet->inet_rcv_saddr = v4addr;
25209         inet->inet_saddr = v4addr;
25210  
25211 @@ -460,9 +483,11 @@ int inet6_getname(struct socket *sock, s
25212                         return -ENOTCONN;
25213                 sin->sin6_port = inet->inet_dport;
25214                 sin->sin6_addr = np->daddr;
25215 +               /* FIXME: remap lback? */
25216                 if (np->sndflow)
25217                         sin->sin6_flowinfo = np->flow_label;
25218         } else {
25219 +               /* FIXME: remap lback? */
25220                 if (ipv6_addr_any(&np->rcv_saddr))
25221                         sin->sin6_addr = np->saddr;
25222                 else
25223 diff -NurpP --minimal linux-3.10.9/net/ipv6/datagram.c linux-3.10.9-vs2.3.6.6/net/ipv6/datagram.c
25224 --- linux-3.10.9/net/ipv6/datagram.c    2013-07-14 17:01:38.000000000 +0000
25225 +++ linux-3.10.9-vs2.3.6.6/net/ipv6/datagram.c  2013-08-22 20:30:00.000000000 +0000
25226 @@ -652,7 +652,7 @@ int ip6_datagram_send_ctl(struct net *ne
25227  
25228                         rcu_read_lock();
25229                         if (fl6->flowi6_oif) {
25230 -                               dev = dev_get_by_index_rcu(net, fl6->flowi6_oif);
25231 +                               dev = dev_get_by_index_real_rcu(net, fl6->flowi6_oif);
25232                                 if (!dev) {
25233                                         rcu_read_unlock();
25234                                         return -ENODEV;
25235 diff -NurpP --minimal linux-3.10.9/net/ipv6/fib6_rules.c linux-3.10.9-vs2.3.6.6/net/ipv6/fib6_rules.c
25236 --- linux-3.10.9/net/ipv6/fib6_rules.c  2013-02-19 13:58:58.000000000 +0000
25237 +++ linux-3.10.9-vs2.3.6.6/net/ipv6/fib6_rules.c        2013-08-22 20:30:00.000000000 +0000
25238 @@ -90,7 +90,7 @@ static int fib6_rule_action(struct fib_r
25239                                                ip6_dst_idev(&rt->dst)->dev,
25240                                                &flp6->daddr,
25241                                                rt6_flags2srcprefs(flags),
25242 -                                              &saddr))
25243 +                                              &saddr, NULL))
25244                                 goto again;
25245                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
25246                                                r->src.plen))
25247 diff -NurpP --minimal linux-3.10.9/net/ipv6/inet6_hashtables.c linux-3.10.9-vs2.3.6.6/net/ipv6/inet6_hashtables.c
25248 --- linux-3.10.9/net/ipv6/inet6_hashtables.c    2013-05-31 13:45:32.000000000 +0000
25249 +++ linux-3.10.9-vs2.3.6.6/net/ipv6/inet6_hashtables.c  2013-08-22 20:30:00.000000000 +0000
25250 @@ -16,6 +16,7 @@
25251  
25252  #include <linux/module.h>
25253  #include <linux/random.h>
25254 +#include <linux/vs_inet6.h>
25255  
25256  #include <net/inet_connection_sock.h>
25257  #include <net/inet_hashtables.h>
25258 @@ -83,7 +84,6 @@ struct sock *__inet6_lookup_established(
25259         unsigned int slot = hash & hashinfo->ehash_mask;
25260         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
25261  
25262 -
25263         rcu_read_lock();
25264  begin:
25265         sk_nulls_for_each_rcu(sk, node, &head->chain) {
25266 @@ -97,7 +97,7 @@ begin:
25267                                 sock_put(sk);
25268                                 goto begin;
25269                         }
25270 -               goto out;
25271 +                       goto out;
25272                 }
25273         }
25274         if (get_nulls_value(node) != slot)
25275 @@ -147,6 +147,9 @@ static inline int compute_score(struct s
25276                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25277                                 return -1;
25278                         score++;
25279 +               } else {
25280 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25281 +                               return -1;
25282                 }
25283                 if (sk->sk_bound_dev_if) {
25284                         if (sk->sk_bound_dev_if != dif)
25285 diff -NurpP --minimal linux-3.10.9/net/ipv6/ip6_output.c linux-3.10.9-vs2.3.6.6/net/ipv6/ip6_output.c
25286 --- linux-3.10.9/net/ipv6/ip6_output.c  2013-08-22 19:51:36.000000000 +0000
25287 +++ linux-3.10.9-vs2.3.6.6/net/ipv6/ip6_output.c        2013-08-22 20:30:00.000000000 +0000
25288 @@ -882,7 +882,8 @@ static int ip6_dst_lookup_tail(struct so
25289                 struct rt6_info *rt = (struct rt6_info *) *dst;
25290                 err = ip6_route_get_saddr(net, rt, &fl6->daddr,
25291                                           sk ? inet6_sk(sk)->srcprefs : 0,
25292 -                                         &fl6->saddr);
25293 +                                         &fl6->saddr,
25294 +                                         sk ? sk->sk_nx_info : NULL);
25295                 if (err)
25296                         goto out_err_release;
25297         }
25298 diff -NurpP --minimal linux-3.10.9/net/ipv6/ndisc.c linux-3.10.9-vs2.3.6.6/net/ipv6/ndisc.c
25299 --- linux-3.10.9/net/ipv6/ndisc.c       2013-07-14 17:01:38.000000000 +0000
25300 +++ linux-3.10.9-vs2.3.6.6/net/ipv6/ndisc.c     2013-08-22 20:30:00.000000000 +0000
25301 @@ -485,7 +485,7 @@ static void ndisc_send_na(struct net_dev
25302         } else {
25303                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
25304                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
25305 -                                      &tmpaddr))
25306 +                                      &tmpaddr, NULL))
25307                         return;
25308                 src_addr = &tmpaddr;
25309         }
25310 diff -NurpP --minimal linux-3.10.9/net/ipv6/netfilter/ip6t_MASQUERADE.c linux-3.10.9-vs2.3.6.6/net/ipv6/netfilter/ip6t_MASQUERADE.c
25311 --- linux-3.10.9/net/ipv6/netfilter/ip6t_MASQUERADE.c   2012-12-11 03:30:57.000000000 +0000
25312 +++ linux-3.10.9-vs2.3.6.6/net/ipv6/netfilter/ip6t_MASQUERADE.c 2013-08-22 20:30:00.000000000 +0000
25313 @@ -34,7 +34,7 @@ masquerade_tg6(struct sk_buff *skb, cons
25314                             ctinfo == IP_CT_RELATED_REPLY));
25315  
25316         if (ipv6_dev_get_saddr(dev_net(par->out), par->out,
25317 -                              &ipv6_hdr(skb)->daddr, 0, &src) < 0)
25318 +                              &ipv6_hdr(skb)->daddr, 0, &src, NULL) < 0)
25319                 return NF_DROP;
25320  
25321         nfct_nat(ct)->masq_index = par->out->ifindex;
25322 diff -NurpP --minimal linux-3.10.9/net/ipv6/raw.c linux-3.10.9-vs2.3.6.6/net/ipv6/raw.c
25323 --- linux-3.10.9/net/ipv6/raw.c 2013-07-14 17:01:38.000000000 +0000
25324 +++ linux-3.10.9-vs2.3.6.6/net/ipv6/raw.c       2013-08-22 20:30:00.000000000 +0000
25325 @@ -30,6 +30,7 @@
25326  #include <linux/icmpv6.h>
25327  #include <linux/netfilter.h>
25328  #include <linux/netfilter_ipv6.h>
25329 +#include <linux/vs_inet6.h>
25330  #include <linux/skbuff.h>
25331  #include <linux/compat.h>
25332  #include <asm/uaccess.h>
25333 @@ -283,6 +284,13 @@ static int rawv6_bind(struct sock *sk, s
25334                                 goto out_unlock;
25335                 }
25336  
25337 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25338 +                       err = -EADDRNOTAVAIL;
25339 +                       if (dev)
25340 +                               dev_put(dev);
25341 +                       goto out;
25342 +               }
25343 +
25344                 /* ipv4 addr of the socket is invalid.  Only the
25345                  * unspecified and mapped address have a v4 equivalent.
25346                  */
25347 diff -NurpP --minimal linux-3.10.9/net/ipv6/route.c linux-3.10.9-vs2.3.6.6/net/ipv6/route.c
25348 --- linux-3.10.9/net/ipv6/route.c       2013-08-22 19:51:36.000000000 +0000
25349 +++ linux-3.10.9-vs2.3.6.6/net/ipv6/route.c     2013-08-22 20:30:00.000000000 +0000
25350 @@ -58,6 +58,7 @@
25351  #include <net/netevent.h>
25352  #include <net/netlink.h>
25353  #include <net/nexthop.h>
25354 +#include <linux/vs_inet6.h>
25355  
25356  #include <asm/uaccess.h>
25357  
25358 @@ -2101,15 +2102,17 @@ int ip6_route_get_saddr(struct net *net,
25359                         struct rt6_info *rt,
25360                         const struct in6_addr *daddr,
25361                         unsigned int prefs,
25362 -                       struct in6_addr *saddr)
25363 +                       struct in6_addr *saddr,
25364 +                       struct nx_info *nxi)
25365  {
25366         struct inet6_dev *idev = ip6_dst_idev((struct dst_entry*)rt);
25367         int err = 0;
25368 -       if (rt->rt6i_prefsrc.plen)
25369 +       if (rt->rt6i_prefsrc.plen && (!nxi ||
25370 +           v6_addr_in_nx_info(nxi, &rt->rt6i_prefsrc.addr, NXA_TYPE_ADDR)))
25371                 *saddr = rt->rt6i_prefsrc.addr;
25372         else
25373                 err = ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
25374 -                                        daddr, prefs, saddr);
25375 +                                        daddr, prefs, saddr, nxi);
25376         return err;
25377  }
25378  
25379 @@ -2529,7 +2532,8 @@ static int rt6_fill_node(struct net *net
25380                                 goto nla_put_failure;
25381         } else if (dst) {
25382                 struct in6_addr saddr_buf;
25383 -               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf) == 0 &&
25384 +               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf,
25385 +                   (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0 &&
25386                     nla_put(skb, RTA_PREFSRC, 16, &saddr_buf))
25387                         goto nla_put_failure;
25388         }
25389 @@ -2741,6 +2745,7 @@ static int rt6_info_route(struct rt6_inf
25390  {
25391         struct seq_file *m = p_arg;
25392  
25393 +       /* FIXME: check for network context? */
25394         seq_printf(m, "%pi6 %02x ", &rt->rt6i_dst.addr, rt->rt6i_dst.plen);
25395  
25396  #ifdef CONFIG_IPV6_SUBTREES
25397 diff -NurpP --minimal linux-3.10.9/net/ipv6/tcp_ipv6.c linux-3.10.9-vs2.3.6.6/net/ipv6/tcp_ipv6.c
25398 --- linux-3.10.9/net/ipv6/tcp_ipv6.c    2013-07-14 17:01:38.000000000 +0000
25399 +++ linux-3.10.9-vs2.3.6.6/net/ipv6/tcp_ipv6.c  2013-08-22 20:30:00.000000000 +0000
25400 @@ -71,6 +71,7 @@
25401  
25402  #include <linux/crypto.h>
25403  #include <linux/scatterlist.h>
25404 +#include <linux/vs_inet6.h>
25405  
25406  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
25407  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
25408 @@ -164,8 +165,15 @@ static int tcp_v6_connect(struct sock *s
25409          *      connect() to INADDR_ANY means loopback (BSD'ism).
25410          */
25411  
25412 -       if(ipv6_addr_any(&usin->sin6_addr))
25413 -               usin->sin6_addr.s6_addr[15] = 0x1;
25414 +       if(ipv6_addr_any(&usin->sin6_addr)) {
25415 +               struct nx_info *nxi =  sk->sk_nx_info;
25416 +
25417 +               if (nxi && nx_info_has_v6(nxi))
25418 +                       /* FIXME: remap lback? */
25419 +                       usin->sin6_addr = nxi->v6.ip;
25420 +               else
25421 +                       usin->sin6_addr.s6_addr[15] = 0x1;
25422 +       }
25423  
25424         addr_type = ipv6_addr_type(&usin->sin6_addr);
25425  
25426 diff -NurpP --minimal linux-3.10.9/net/ipv6/udp.c linux-3.10.9-vs2.3.6.6/net/ipv6/udp.c
25427 --- linux-3.10.9/net/ipv6/udp.c 2013-08-22 19:51:36.000000000 +0000
25428 +++ linux-3.10.9-vs2.3.6.6/net/ipv6/udp.c       2013-08-22 20:30:00.000000000 +0000
25429 @@ -46,42 +46,68 @@
25430  #include <net/ip6_checksum.h>
25431  #include <net/xfrm.h>
25432  #include <net/inet6_hashtables.h>
25433 +#include <linux/vs_inet6.h>
25434  
25435  #include <linux/proc_fs.h>
25436  #include <linux/seq_file.h>
25437  #include <trace/events/skb.h>
25438  #include "udp_impl.h"
25439  
25440 -int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
25441 +int ipv6_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25442  {
25443 -       const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
25444 +       const struct in6_addr *sk1_rcv_saddr6 = &inet6_sk(sk1)->rcv_saddr;
25445         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
25446 -       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk);
25447 +       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk1);
25448         __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
25449 -       int sk_ipv6only = ipv6_only_sock(sk);
25450 +       int sk1_ipv6only = ipv6_only_sock(sk1);
25451         int sk2_ipv6only = inet_v6_ipv6only(sk2);
25452 -       int addr_type = ipv6_addr_type(sk_rcv_saddr6);
25453 +       int addr_type = ipv6_addr_type(sk1_rcv_saddr6);
25454         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
25455  
25456         /* if both are mapped, treat as IPv4 */
25457 -       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
25458 -               return (!sk2_ipv6only &&
25459 +       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
25460 +               if (!sk2_ipv6only &&
25461                         (!sk1_rcv_saddr || !sk2_rcv_saddr ||
25462 -                         sk1_rcv_saddr == sk2_rcv_saddr));
25463 +                         sk1_rcv_saddr == sk2_rcv_saddr))
25464 +                       goto vs_v4;
25465 +               else
25466 +                       return 0;
25467 +       }
25468  
25469         if (addr_type2 == IPV6_ADDR_ANY &&
25470             !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
25471 -               return 1;
25472 +               goto vs;
25473  
25474         if (addr_type == IPV6_ADDR_ANY &&
25475 -           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
25476 -               return 1;
25477 +           !(sk1_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
25478 +               goto vs;
25479  
25480         if (sk2_rcv_saddr6 &&
25481 -           ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
25482 -               return 1;
25483 +           ipv6_addr_equal(sk1_rcv_saddr6, sk2_rcv_saddr6))
25484 +               goto vs;
25485  
25486         return 0;
25487 +
25488 +vs_v4:
25489 +       if (!sk1_rcv_saddr && !sk2_rcv_saddr)
25490 +               return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25491 +       if (!sk2_rcv_saddr)
25492 +               return v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, -1);
25493 +       if (!sk1_rcv_saddr)
25494 +               return v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, -1);
25495 +       return 1;
25496 +vs:
25497 +       if (addr_type2 == IPV6_ADDR_ANY && addr_type == IPV6_ADDR_ANY)
25498 +               return nx_v6_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25499 +       else if (addr_type2 == IPV6_ADDR_ANY)
25500 +               return v6_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr6, -1);
25501 +       else if (addr_type == IPV6_ADDR_ANY) {
25502 +               if (addr_type2 == IPV6_ADDR_MAPPED)
25503 +                       return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25504 +               else
25505 +                       return v6_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr6, -1);
25506 +       }
25507 +       return 1;
25508  }
25509  
25510  static unsigned int udp6_portaddr_hash(struct net *net,
25511 @@ -145,6 +171,10 @@ static inline int compute_score(struct s
25512                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25513                                 return -1;
25514                         score++;
25515 +               } else {
25516 +                       /* block non nx_info ips */
25517 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25518 +                               return -1;
25519                 }
25520                 if (!ipv6_addr_any(&np->daddr)) {
25521                         if (!ipv6_addr_equal(&np->daddr, saddr))
25522 diff -NurpP --minimal linux-3.10.9/net/ipv6/xfrm6_policy.c linux-3.10.9-vs2.3.6.6/net/ipv6/xfrm6_policy.c
25523 --- linux-3.10.9/net/ipv6/xfrm6_policy.c        2013-07-14 17:01:38.000000000 +0000
25524 +++ linux-3.10.9-vs2.3.6.6/net/ipv6/xfrm6_policy.c      2013-08-22 20:30:00.000000000 +0000
25525 @@ -63,7 +63,7 @@ static int xfrm6_get_saddr(struct net *n
25526         dev = ip6_dst_idev(dst)->dev;
25527         ipv6_dev_get_saddr(dev_net(dev), dev,
25528                            (struct in6_addr *)&daddr->a6, 0,
25529 -                          (struct in6_addr *)&saddr->a6);
25530 +                          (struct in6_addr *)&saddr->a6, NULL);
25531         dst_release(dst);
25532         return 0;
25533  }
25534 diff -NurpP --minimal linux-3.10.9/net/netfilter/ipvs/ip_vs_xmit.c linux-3.10.9-vs2.3.6.6/net/netfilter/ipvs/ip_vs_xmit.c
25535 --- linux-3.10.9/net/netfilter/ipvs/ip_vs_xmit.c        2013-07-14 17:01:38.000000000 +0000
25536 +++ linux-3.10.9-vs2.3.6.6/net/netfilter/ipvs/ip_vs_xmit.c      2013-08-22 20:30:00.000000000 +0000
25537 @@ -316,7 +316,7 @@ __ip_vs_route_output_v6(struct net *net,
25538                 return dst;
25539         if (ipv6_addr_any(&fl6.saddr) &&
25540             ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
25541 -                              &fl6.daddr, 0, &fl6.saddr) < 0)
25542 +                              &fl6.daddr, 0, &fl6.saddr, NULL) < 0)
25543                 goto out_err;
25544         if (do_xfrm) {
25545                 dst = xfrm_lookup(net, dst, flowi6_to_flowi(&fl6), NULL, 0);
25546 diff -NurpP --minimal linux-3.10.9/net/netlink/af_netlink.c linux-3.10.9-vs2.3.6.6/net/netlink/af_netlink.c
25547 --- linux-3.10.9/net/netlink/af_netlink.c       2013-07-14 17:01:39.000000000 +0000
25548 +++ linux-3.10.9-vs2.3.6.6/net/netlink/af_netlink.c     2013-08-22 21:19:02.000000000 +0000
25549 @@ -57,6 +57,9 @@
25550  #include <linux/audit.h>
25551  #include <linux/mutex.h>
25552  #include <linux/vmalloc.h>
25553 +#include <linux/vs_context.h>
25554 +#include <linux/vs_network.h>
25555 +#include <linux/vs_limit.h>
25556  #include <asm/cacheflush.h>
25557  
25558  #include <net/net_namespace.h>
25559 @@ -2684,6 +2687,8 @@ static struct sock *netlink_seq_socket_i
25560                         sk_for_each(s, &hash->table[j]) {
25561                                 if (sock_net(s) != seq_file_net(seq))
25562                                         continue;
25563 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25564 +                                       continue;
25565                                 if (off == pos) {
25566                                         iter->link = i;
25567                                         iter->hash_idx = j;
25568 @@ -2718,7 +2723,8 @@ static void *netlink_seq_next(struct seq
25569         s = v;
25570         do {
25571                 s = sk_next(s);
25572 -       } while (s && sock_net(s) != seq_file_net(seq));
25573 +       } while (s && (sock_net(s) != seq_file_net(seq) ||
25574 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
25575         if (s)
25576                 return s;
25577  
25578 @@ -2730,7 +2736,8 @@ static void *netlink_seq_next(struct seq
25579  
25580                 for (; j <= hash->mask; j++) {
25581                         s = sk_head(&hash->table[j]);
25582 -                       while (s && sock_net(s) != seq_file_net(seq))
25583 +                       while (s && (sock_net(s) != seq_file_net(seq) ||
25584 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
25585                                 s = sk_next(s);
25586                         if (s) {
25587                                 iter->link = i;
25588 diff -NurpP --minimal linux-3.10.9/net/socket.c linux-3.10.9-vs2.3.6.6/net/socket.c
25589 --- linux-3.10.9/net/socket.c   2013-07-14 17:01:39.000000000 +0000
25590 +++ linux-3.10.9-vs2.3.6.6/net/socket.c 2013-08-22 20:30:00.000000000 +0000
25591 @@ -98,6 +98,10 @@
25592  
25593  #include <net/sock.h>
25594  #include <linux/netfilter.h>
25595 +#include <linux/vs_base.h>
25596 +#include <linux/vs_socket.h>
25597 +#include <linux/vs_inet.h>
25598 +#include <linux/vs_inet6.h>
25599  
25600  #include <linux/if_tun.h>
25601  #include <linux/ipv6_route.h>
25602 @@ -616,13 +620,29 @@ static inline int __sock_sendmsg_nosec(s
25603                                        struct msghdr *msg, size_t size)
25604  {
25605         struct sock_iocb *si = kiocb_to_siocb(iocb);
25606 +       size_t len;
25607  
25608         si->sock = sock;
25609         si->scm = NULL;
25610         si->msg = msg;
25611         si->size = size;
25612  
25613 -       return sock->ops->sendmsg(iocb, sock, msg, size);
25614 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
25615 +       if (sock->sk) {
25616 +               if (len == size)
25617 +                       vx_sock_send(sock->sk, size);
25618 +               else
25619 +                       vx_sock_fail(sock->sk, size);
25620 +       }
25621 +       vxdprintk(VXD_CBIT(net, 7),
25622 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%zu",
25623 +               sock, sock->sk,
25624 +               (sock->sk)?sock->sk->sk_nx_info:0,
25625 +               (sock->sk)?sock->sk->sk_vx_info:0,
25626 +               (sock->sk)?sock->sk->sk_xid:0,
25627 +               (sock->sk)?sock->sk->sk_nid:0,
25628 +               (unsigned int)size, len);
25629 +       return len;
25630  }
25631  
25632  static inline int __sock_sendmsg(struct kiocb *iocb, struct socket *sock,
25633 @@ -766,6 +786,7 @@ static inline int __sock_recvmsg_nosec(s
25634                                        struct msghdr *msg, size_t size, int flags)
25635  {
25636         struct sock_iocb *si = kiocb_to_siocb(iocb);
25637 +       int len;
25638  
25639         si->sock = sock;
25640         si->scm = NULL;
25641 @@ -773,7 +794,18 @@ static inline int __sock_recvmsg_nosec(s
25642         si->size = size;
25643         si->flags = flags;
25644  
25645 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
25646 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
25647 +       if ((len >= 0) && sock->sk)
25648 +               vx_sock_recv(sock->sk, len);
25649 +       vxdprintk(VXD_CBIT(net, 7),
25650 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
25651 +               sock, sock->sk,
25652 +               (sock->sk)?sock->sk->sk_nx_info:0,
25653 +               (sock->sk)?sock->sk->sk_vx_info:0,
25654 +               (sock->sk)?sock->sk->sk_xid:0,
25655 +               (sock->sk)?sock->sk->sk_nid:0,
25656 +               (unsigned int)size, len);
25657 +       return len;
25658  }
25659  
25660  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
25661 @@ -1247,6 +1279,13 @@ int __sock_create(struct net *net, int f
25662         if (type < 0 || type >= SOCK_MAX)
25663                 return -EINVAL;
25664  
25665 +       if (!nx_check(0, VS_ADMIN)) {
25666 +               if (family == PF_INET && !current_nx_info_has_v4())
25667 +                       return -EAFNOSUPPORT;
25668 +               if (family == PF_INET6 && !current_nx_info_has_v6())
25669 +                       return -EAFNOSUPPORT;
25670 +       }
25671 +
25672         /* Compatibility.
25673  
25674            This uglymoron is moved from INET layer to here to avoid
25675 @@ -1381,6 +1420,7 @@ SYSCALL_DEFINE3(socket, int, family, int
25676         if (retval < 0)
25677                 goto out;
25678  
25679 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
25680         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
25681         if (retval < 0)
25682                 goto out_release;
25683 @@ -1422,10 +1462,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
25684         err = sock_create(family, type, protocol, &sock1);
25685         if (err < 0)
25686                 goto out;
25687 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
25688  
25689         err = sock_create(family, type, protocol, &sock2);
25690         if (err < 0)
25691                 goto out_release_1;
25692 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
25693  
25694         err = sock1->ops->socketpair(sock1, sock2);
25695         if (err < 0)
25696 diff -NurpP --minimal linux-3.10.9/net/sunrpc/auth.c linux-3.10.9-vs2.3.6.6/net/sunrpc/auth.c
25697 --- linux-3.10.9/net/sunrpc/auth.c      2013-07-14 17:01:39.000000000 +0000
25698 +++ linux-3.10.9-vs2.3.6.6/net/sunrpc/auth.c    2013-08-22 20:30:00.000000000 +0000
25699 @@ -15,6 +15,7 @@
25700  #include <linux/sunrpc/clnt.h>
25701  #include <linux/sunrpc/gss_api.h>
25702  #include <linux/spinlock.h>
25703 +#include <linux/vs_tag.h>
25704  
25705  #ifdef RPC_DEBUG
25706  # define RPCDBG_FACILITY       RPCDBG_AUTH
25707 @@ -553,6 +554,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
25708         memset(&acred, 0, sizeof(acred));
25709         acred.uid = cred->fsuid;
25710         acred.gid = cred->fsgid;
25711 +       acred.tag = make_ktag(&init_user_ns, dx_current_tag());
25712         acred.group_info = get_group_info(((struct cred *)cred)->group_info);
25713  
25714         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
25715 @@ -593,6 +595,7 @@ rpcauth_bind_root_cred(struct rpc_task *
25716         struct auth_cred acred = {
25717                 .uid = GLOBAL_ROOT_UID,
25718                 .gid = GLOBAL_ROOT_GID,
25719 +               .tag = KTAGT_INIT(dx_current_tag()),
25720         };
25721  
25722         dprintk("RPC: %5u looking up %s cred\n",
25723 diff -NurpP --minimal linux-3.10.9/net/sunrpc/auth_unix.c linux-3.10.9-vs2.3.6.6/net/sunrpc/auth_unix.c
25724 --- linux-3.10.9/net/sunrpc/auth_unix.c 2013-05-31 13:45:33.000000000 +0000
25725 +++ linux-3.10.9-vs2.3.6.6/net/sunrpc/auth_unix.c       2013-08-22 20:30:00.000000000 +0000
25726 @@ -13,11 +13,13 @@
25727  #include <linux/sunrpc/clnt.h>
25728  #include <linux/sunrpc/auth.h>
25729  #include <linux/user_namespace.h>
25730 +#include <linux/vs_tag.h>
25731  
25732  #define NFS_NGROUPS    16
25733  
25734  struct unx_cred {
25735         struct rpc_cred         uc_base;
25736 +       ktag_t                  uc_tag;
25737         kgid_t                  uc_gid;
25738         kgid_t                  uc_gids[NFS_NGROUPS];
25739  };
25740 @@ -80,6 +82,7 @@ unx_create_cred(struct rpc_auth *auth, s
25741                 groups = NFS_NGROUPS;
25742  
25743         cred->uc_gid = acred->gid;
25744 +       cred->uc_tag = acred->tag;
25745         for (i = 0; i < groups; i++)
25746                 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
25747         if (i < NFS_NGROUPS)
25748 @@ -121,7 +124,9 @@ unx_match(struct auth_cred *acred, struc
25749         unsigned int i;
25750  
25751  
25752 -       if (!uid_eq(cred->uc_uid, acred->uid) || !gid_eq(cred->uc_gid, acred->gid))
25753 +       if (!uid_eq(cred->uc_uid, acred->uid) ||
25754 +           !gid_eq(cred->uc_gid, acred->gid) ||
25755 +           !tag_eq(cred->uc_tag, acred->tag))
25756                 return 0;
25757  
25758         if (acred->group_info != NULL)
25759 @@ -146,7 +151,7 @@ unx_marshal(struct rpc_task *task, __be3
25760         struct rpc_clnt *clnt = task->tk_client;
25761         struct unx_cred *cred = container_of(task->tk_rqstp->rq_cred, struct unx_cred, uc_base);
25762         __be32          *base, *hold;
25763 -       int             i;
25764 +       int             i, tag;
25765  
25766         *p++ = htonl(RPC_AUTH_UNIX);
25767         base = p++;
25768 @@ -157,8 +162,11 @@ unx_marshal(struct rpc_task *task, __be3
25769          */
25770         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
25771  
25772 -       *p++ = htonl((u32) from_kuid(&init_user_ns, cred->uc_uid));
25773 -       *p++ = htonl((u32) from_kgid(&init_user_ns, cred->uc_gid));
25774 +       tag = task->tk_client->cl_tag;
25775 +       *p++ = htonl((u32) from_kuid(&init_user_ns,
25776 +               TAGINO_KUID(tag, cred->uc_uid, cred->uc_tag)));
25777 +       *p++ = htonl((u32) from_kgid(&init_user_ns,
25778 +               TAGINO_KGID(tag, cred->uc_gid, cred->uc_tag)));
25779         hold = p++;
25780         for (i = 0; i < 16 && gid_valid(cred->uc_gids[i]); i++)
25781                 *p++ = htonl((u32) from_kgid(&init_user_ns, cred->uc_gids[i]));
25782 diff -NurpP --minimal linux-3.10.9/net/sunrpc/clnt.c linux-3.10.9-vs2.3.6.6/net/sunrpc/clnt.c
25783 --- linux-3.10.9/net/sunrpc/clnt.c      2013-08-22 19:51:36.000000000 +0000
25784 +++ linux-3.10.9-vs2.3.6.6/net/sunrpc/clnt.c    2013-08-22 20:30:00.000000000 +0000
25785 @@ -31,6 +31,7 @@
25786  #include <linux/in6.h>
25787  #include <linux/un.h>
25788  #include <linux/rcupdate.h>
25789 +#include <linux/vs_cvirt.h>
25790  
25791  #include <linux/sunrpc/clnt.h>
25792  #include <linux/sunrpc/addr.h>
25793 @@ -486,6 +487,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
25794         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
25795                 clnt->cl_chatty = 1;
25796  
25797 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
25798 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
25799 +               clnt->cl_tag = 1; */
25800         return clnt;
25801  }
25802  EXPORT_SYMBOL_GPL(rpc_create);
25803 diff -NurpP --minimal linux-3.10.9/net/unix/af_unix.c linux-3.10.9-vs2.3.6.6/net/unix/af_unix.c
25804 --- linux-3.10.9/net/unix/af_unix.c     2013-07-14 17:01:39.000000000 +0000
25805 +++ linux-3.10.9-vs2.3.6.6/net/unix/af_unix.c   2013-08-22 20:30:00.000000000 +0000
25806 @@ -114,6 +114,8 @@
25807  #include <linux/mount.h>
25808  #include <net/checksum.h>
25809  #include <linux/security.h>
25810 +#include <linux/vs_context.h>
25811 +#include <linux/vs_limit.h>
25812  
25813  struct hlist_head unix_socket_table[2 * UNIX_HASH_SIZE];
25814  EXPORT_SYMBOL_GPL(unix_socket_table);
25815 @@ -270,6 +272,8 @@ static struct sock *__unix_find_socket_b
25816                 if (!net_eq(sock_net(s), net))
25817                         continue;
25818  
25819 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25820 +                       continue;
25821                 if (u->addr->len == len &&
25822                     !memcmp(u->addr->name, sunname, len))
25823                         goto found;
25824 @@ -2257,6 +2261,8 @@ static struct sock *unix_from_bucket(str
25825         for (sk = sk_head(&unix_socket_table[bucket]); sk; sk = sk_next(sk)) {
25826                 if (sock_net(sk) != seq_file_net(seq))
25827                         continue;
25828 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25829 +                       continue;
25830                 if (++count == offset)
25831                         break;
25832         }
25833 @@ -2274,6 +2280,8 @@ static struct sock *unix_next_socket(str
25834                 sk = sk_next(sk);
25835                 if (!sk)
25836                         goto next_bucket;
25837 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25838 +                       continue;
25839                 if (sock_net(sk) == seq_file_net(seq))
25840                         return sk;
25841         }
25842 diff -NurpP --minimal linux-3.10.9/scripts/checksyscalls.sh linux-3.10.9-vs2.3.6.6/scripts/checksyscalls.sh
25843 --- linux-3.10.9/scripts/checksyscalls.sh       2012-12-11 03:30:57.000000000 +0000
25844 +++ linux-3.10.9-vs2.3.6.6/scripts/checksyscalls.sh     2013-08-22 20:30:00.000000000 +0000
25845 @@ -193,7 +193,6 @@ cat << EOF
25846  #define __IGNORE_afs_syscall
25847  #define __IGNORE_getpmsg
25848  #define __IGNORE_putpmsg
25849 -#define __IGNORE_vserver
25850  EOF
25851  }
25852  
25853 diff -NurpP --minimal linux-3.10.9/security/commoncap.c linux-3.10.9-vs2.3.6.6/security/commoncap.c
25854 --- linux-3.10.9/security/commoncap.c   2013-05-31 13:45:34.000000000 +0000
25855 +++ linux-3.10.9-vs2.3.6.6/security/commoncap.c 2013-08-22 20:30:00.000000000 +0000
25856 @@ -76,6 +76,7 @@ int cap_netlink_send(struct sock *sk, st
25857  int cap_capable(const struct cred *cred, struct user_namespace *targ_ns,
25858                 int cap, int audit)
25859  {
25860 +       struct vx_info *vxi = current_vx_info(); /* FIXME: get vxi from cred? */
25861         struct user_namespace *ns = targ_ns;
25862  
25863         /* See if cred has the capability in the target user namespace
25864 @@ -84,8 +85,12 @@ int cap_capable(const struct cred *cred,
25865          */
25866         for (;;) {
25867                 /* Do we have the necessary capabilities? */
25868 -               if (ns == cred->user_ns)
25869 -                       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
25870 +               if (ns == cred->user_ns) {
25871 +                       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
25872 +                           cap_raised(cred->cap_effective, cap))
25873 +                               return 0;
25874 +                       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
25875 +               }
25876  
25877                 /* Have we tried all of the parent namespaces? */
25878                 if (ns == &init_user_ns)
25879 @@ -628,7 +633,7 @@ int cap_inode_setxattr(struct dentry *de
25880  
25881         if (!strncmp(name, XATTR_SECURITY_PREFIX,
25882                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
25883 -           !capable(CAP_SYS_ADMIN))
25884 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
25885                 return -EPERM;
25886         return 0;
25887  }
25888 @@ -654,7 +659,7 @@ int cap_inode_removexattr(struct dentry
25889  
25890         if (!strncmp(name, XATTR_SECURITY_PREFIX,
25891                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
25892 -           !capable(CAP_SYS_ADMIN))
25893 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
25894                 return -EPERM;
25895         return 0;
25896  }
25897 diff -NurpP --minimal linux-3.10.9/security/selinux/hooks.c linux-3.10.9-vs2.3.6.6/security/selinux/hooks.c
25898 --- linux-3.10.9/security/selinux/hooks.c       2013-07-14 17:01:42.000000000 +0000
25899 +++ linux-3.10.9-vs2.3.6.6/security/selinux/hooks.c     2013-08-22 20:30:00.000000000 +0000
25900 @@ -67,7 +67,6 @@
25901  #include <linux/dccp.h>
25902  #include <linux/quota.h>
25903  #include <linux/un.h>          /* for Unix socket types */
25904 -#include <net/af_unix.h>       /* for Unix socket types */
25905  #include <linux/parser.h>
25906  #include <linux/nfs_mount.h>
25907  #include <net/ipv6.h>
This page took 2.306807 seconds and 4 git commands to generate.