]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
86281e2d0bd2bd52436f8f587451d5e13870b321
[packages/kernel.git] / kernel-vserver-2.3.patch
1 diff -NurpP --minimal linux-3.10.33/Documentation/vserver/debug.txt linux-3.10.33-vs2.3.6.8/Documentation/vserver/debug.txt
2 --- linux-3.10.33/Documentation/vserver/debug.txt       1970-01-01 00:00:00.000000000 +0000
3 +++ linux-3.10.33-vs2.3.6.8/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.33/arch/alpha/Kconfig linux-3.10.33-vs2.3.6.8/arch/alpha/Kconfig
160 --- linux-3.10.33/arch/alpha/Kconfig    2013-07-14 17:00:13.000000000 +0000
161 +++ linux-3.10.33-vs2.3.6.8/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.33/arch/alpha/kernel/systbls.S linux-3.10.33-vs2.3.6.8/arch/alpha/kernel/systbls.S
172 --- linux-3.10.33/arch/alpha/kernel/systbls.S   2013-02-19 13:56:11.000000000 +0000
173 +++ linux-3.10.33-vs2.3.6.8/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.33/arch/alpha/kernel/traps.c linux-3.10.33-vs2.3.6.8/arch/alpha/kernel/traps.c
184 --- linux-3.10.33/arch/alpha/kernel/traps.c     2013-07-14 17:00:13.000000000 +0000
185 +++ linux-3.10.33-vs2.3.6.8/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.33/arch/arm/Kconfig linux-3.10.33-vs2.3.6.8/arch/arm/Kconfig
197 --- linux-3.10.33/arch/arm/Kconfig      2014-03-12 13:15:53.000000000 +0000
198 +++ linux-3.10.33-vs2.3.6.8/arch/arm/Kconfig    2013-11-13 17:17:15.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.33/arch/arm/kernel/calls.S linux-3.10.33-vs2.3.6.8/arch/arm/kernel/calls.S
209 --- linux-3.10.33/arch/arm/kernel/calls.S       2013-05-31 13:44:29.000000000 +0000
210 +++ linux-3.10.33-vs2.3.6.8/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.33/arch/arm/kernel/traps.c linux-3.10.33-vs2.3.6.8/arch/arm/kernel/traps.c
221 --- linux-3.10.33/arch/arm/kernel/traps.c       2014-03-12 13:15:53.000000000 +0000
222 +++ linux-3.10.33-vs2.3.6.8/arch/arm/kernel/traps.c     2014-01-22 19:00:34.000000000 +0000
223 @@ -246,8 +246,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.33/arch/cris/Kconfig linux-3.10.33-vs2.3.6.8/arch/cris/Kconfig
235 --- linux-3.10.33/arch/cris/Kconfig     2013-07-14 17:00:25.000000000 +0000
236 +++ linux-3.10.33-vs2.3.6.8/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.33/arch/h8300/Kconfig linux-3.10.33-vs2.3.6.8/arch/h8300/Kconfig
247 --- linux-3.10.33/arch/h8300/Kconfig    2013-07-14 17:00:25.000000000 +0000
248 +++ linux-3.10.33-vs2.3.6.8/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.33/arch/ia64/Kconfig linux-3.10.33-vs2.3.6.8/arch/ia64/Kconfig
259 --- linux-3.10.33/arch/ia64/Kconfig     2013-07-14 17:00:25.000000000 +0000
260 +++ linux-3.10.33-vs2.3.6.8/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.33/arch/ia64/kernel/entry.S linux-3.10.33-vs2.3.6.8/arch/ia64/kernel/entry.S
271 --- linux-3.10.33/arch/ia64/kernel/entry.S      2013-05-31 13:44:38.000000000 +0000
272 +++ linux-3.10.33-vs2.3.6.8/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.33/arch/ia64/kernel/ptrace.c linux-3.10.33-vs2.3.6.8/arch/ia64/kernel/ptrace.c
283 --- linux-3.10.33/arch/ia64/kernel/ptrace.c     2013-02-19 13:56:51.000000000 +0000
284 +++ linux-3.10.33-vs2.3.6.8/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.33/arch/ia64/kernel/traps.c linux-3.10.33-vs2.3.6.8/arch/ia64/kernel/traps.c
294 --- linux-3.10.33/arch/ia64/kernel/traps.c      2013-05-31 13:44:38.000000000 +0000
295 +++ linux-3.10.33-vs2.3.6.8/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.33/arch/m32r/kernel/traps.c linux-3.10.33-vs2.3.6.8/arch/m32r/kernel/traps.c
321 --- linux-3.10.33/arch/m32r/kernel/traps.c      2013-07-14 17:00:26.000000000 +0000
322 +++ linux-3.10.33-vs2.3.6.8/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.33/arch/m68k/Kconfig linux-3.10.33-vs2.3.6.8/arch/m68k/Kconfig
336 --- linux-3.10.33/arch/m68k/Kconfig     2013-07-14 17:00:26.000000000 +0000
337 +++ linux-3.10.33-vs2.3.6.8/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.33/arch/mips/Kconfig linux-3.10.33-vs2.3.6.8/arch/mips/Kconfig
348 --- linux-3.10.33/arch/mips/Kconfig     2014-03-12 13:15:54.000000000 +0000
349 +++ linux-3.10.33-vs2.3.6.8/arch/mips/Kconfig   2013-11-13 17:17:15.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.33/arch/mips/kernel/ptrace.c linux-3.10.33-vs2.3.6.8/arch/mips/kernel/ptrace.c
360 --- linux-3.10.33/arch/mips/kernel/ptrace.c     2013-05-31 13:44:42.000000000 +0000
361 +++ linux-3.10.33-vs2.3.6.8/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.33/arch/mips/kernel/scall32-o32.S linux-3.10.33-vs2.3.6.8/arch/mips/kernel/scall32-o32.S
381 --- linux-3.10.33/arch/mips/kernel/scall32-o32.S        2013-07-14 17:00:28.000000000 +0000
382 +++ linux-3.10.33-vs2.3.6.8/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.33/arch/mips/kernel/scall64-64.S linux-3.10.33-vs2.3.6.8/arch/mips/kernel/scall64-64.S
393 --- linux-3.10.33/arch/mips/kernel/scall64-64.S 2013-07-14 17:00:28.000000000 +0000
394 +++ linux-3.10.33-vs2.3.6.8/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.33/arch/mips/kernel/scall64-n32.S linux-3.10.33-vs2.3.6.8/arch/mips/kernel/scall64-n32.S
405 --- linux-3.10.33/arch/mips/kernel/scall64-n32.S        2013-07-14 17:00:28.000000000 +0000
406 +++ linux-3.10.33-vs2.3.6.8/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.33/arch/mips/kernel/scall64-o32.S linux-3.10.33-vs2.3.6.8/arch/mips/kernel/scall64-o32.S
417 --- linux-3.10.33/arch/mips/kernel/scall64-o32.S        2013-07-14 17:00:28.000000000 +0000
418 +++ linux-3.10.33-vs2.3.6.8/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.33/arch/mips/kernel/traps.c linux-3.10.33-vs2.3.6.8/arch/mips/kernel/traps.c
429 --- linux-3.10.33/arch/mips/kernel/traps.c      2013-07-14 17:00:28.000000000 +0000
430 +++ linux-3.10.33-vs2.3.6.8/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.33/arch/parisc/Kconfig linux-3.10.33-vs2.3.6.8/arch/parisc/Kconfig
446 --- linux-3.10.33/arch/parisc/Kconfig   2013-07-14 17:00:29.000000000 +0000
447 +++ linux-3.10.33-vs2.3.6.8/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.33/arch/parisc/kernel/syscall_table.S linux-3.10.33-vs2.3.6.8/arch/parisc/kernel/syscall_table.S
458 --- linux-3.10.33/arch/parisc/kernel/syscall_table.S    2013-07-14 17:00:31.000000000 +0000
459 +++ linux-3.10.33-vs2.3.6.8/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.33/arch/parisc/kernel/traps.c linux-3.10.33-vs2.3.6.8/arch/parisc/kernel/traps.c
470 --- linux-3.10.33/arch/parisc/kernel/traps.c    2014-03-12 13:15:54.000000000 +0000
471 +++ linux-3.10.33-vs2.3.6.8/arch/parisc/kernel/traps.c  2013-11-13 17:17:15.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.33/arch/parisc/mm/fault.c linux-3.10.33-vs2.3.6.8/arch/parisc/mm/fault.c
496 --- linux-3.10.33/arch/parisc/mm/fault.c        2013-05-31 13:44:44.000000000 +0000
497 +++ linux-3.10.33-vs2.3.6.8/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.33/arch/powerpc/Kconfig linux-3.10.33-vs2.3.6.8/arch/powerpc/Kconfig
511 --- linux-3.10.33/arch/powerpc/Kconfig  2014-03-12 13:15:54.000000000 +0000
512 +++ linux-3.10.33-vs2.3.6.8/arch/powerpc/Kconfig        2013-11-13 17:17:15.000000000 +0000
513 @@ -1010,6 +1010,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.33/arch/powerpc/include/uapi/asm/unistd.h linux-3.10.33-vs2.3.6.8/arch/powerpc/include/uapi/asm/unistd.h
523 --- linux-3.10.33/arch/powerpc/include/uapi/asm/unistd.h        2013-05-31 13:44:44.000000000 +0000
524 +++ linux-3.10.33-vs2.3.6.8/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.33/arch/powerpc/kernel/traps.c linux-3.10.33-vs2.3.6.8/arch/powerpc/kernel/traps.c
535 --- linux-3.10.33/arch/powerpc/kernel/traps.c   2014-03-12 13:15:54.000000000 +0000
536 +++ linux-3.10.33-vs2.3.6.8/arch/powerpc/kernel/traps.c 2013-11-13 17:17:15.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.33/arch/s390/Kconfig linux-3.10.33-vs2.3.6.8/arch/s390/Kconfig
550 --- linux-3.10.33/arch/s390/Kconfig     2014-03-12 13:15:55.000000000 +0000
551 +++ linux-3.10.33-vs2.3.6.8/arch/s390/Kconfig   2013-11-13 17:17:15.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.33/arch/s390/include/asm/tlb.h linux-3.10.33-vs2.3.6.8/arch/s390/include/asm/tlb.h
562 --- linux-3.10.33/arch/s390/include/asm/tlb.h   2014-03-12 13:15:55.000000000 +0000
563 +++ linux-3.10.33-vs2.3.6.8/arch/s390/include/asm/tlb.h 2013-11-13 17:17:15.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.33/arch/s390/include/uapi/asm/unistd.h linux-3.10.33-vs2.3.6.8/arch/s390/include/uapi/asm/unistd.h
573 --- linux-3.10.33/arch/s390/include/uapi/asm/unistd.h   2013-02-19 13:57:16.000000000 +0000
574 +++ linux-3.10.33-vs2.3.6.8/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.33/arch/s390/kernel/ptrace.c linux-3.10.33-vs2.3.6.8/arch/s390/kernel/ptrace.c
585 --- linux-3.10.33/arch/s390/kernel/ptrace.c     2012-12-11 03:30:57.000000000 +0000
586 +++ linux-3.10.33-vs2.3.6.8/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.33/arch/s390/kernel/syscalls.S linux-3.10.33-vs2.3.6.8/arch/s390/kernel/syscalls.S
596 --- linux-3.10.33/arch/s390/kernel/syscalls.S   2013-07-14 17:00:34.000000000 +0000
597 +++ linux-3.10.33-vs2.3.6.8/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.33/arch/sh/Kconfig linux-3.10.33-vs2.3.6.8/arch/sh/Kconfig
608 --- linux-3.10.33/arch/sh/Kconfig       2013-07-14 17:00:35.000000000 +0000
609 +++ linux-3.10.33-vs2.3.6.8/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.33/arch/sh/kernel/irq.c linux-3.10.33-vs2.3.6.8/arch/sh/kernel/irq.c
620 --- linux-3.10.33/arch/sh/kernel/irq.c  2012-12-11 03:30:57.000000000 +0000
621 +++ linux-3.10.33-vs2.3.6.8/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.33/arch/sparc/Kconfig linux-3.10.33-vs2.3.6.8/arch/sparc/Kconfig
631 --- linux-3.10.33/arch/sparc/Kconfig    2013-07-14 17:00:35.000000000 +0000
632 +++ linux-3.10.33-vs2.3.6.8/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.33/arch/sparc/include/uapi/asm/unistd.h linux-3.10.33-vs2.3.6.8/arch/sparc/include/uapi/asm/unistd.h
643 --- linux-3.10.33/arch/sparc/include/uapi/asm/unistd.h  2013-02-19 13:57:17.000000000 +0000
644 +++ linux-3.10.33-vs2.3.6.8/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.33/arch/sparc/kernel/systbls_32.S linux-3.10.33-vs2.3.6.8/arch/sparc/kernel/systbls_32.S
655 --- linux-3.10.33/arch/sparc/kernel/systbls_32.S        2013-05-31 13:44:48.000000000 +0000
656 +++ linux-3.10.33-vs2.3.6.8/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.33/arch/sparc/kernel/systbls_64.S linux-3.10.33-vs2.3.6.8/arch/sparc/kernel/systbls_64.S
667 --- linux-3.10.33/arch/sparc/kernel/systbls_64.S        2013-07-14 17:00:35.000000000 +0000
668 +++ linux-3.10.33-vs2.3.6.8/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.33/arch/um/Kconfig.rest linux-3.10.33-vs2.3.6.8/arch/um/Kconfig.rest
688 --- linux-3.10.33/arch/um/Kconfig.rest  2012-12-11 03:30:57.000000000 +0000
689 +++ linux-3.10.33-vs2.3.6.8/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.33/arch/x86/Kconfig linux-3.10.33-vs2.3.6.8/arch/x86/Kconfig
700 --- linux-3.10.33/arch/x86/Kconfig      2013-07-14 17:00:36.000000000 +0000
701 +++ linux-3.10.33-vs2.3.6.8/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.33/arch/x86/syscalls/syscall_32.tbl linux-3.10.33-vs2.3.6.8/arch/x86/syscalls/syscall_32.tbl
712 --- linux-3.10.33/arch/x86/syscalls/syscall_32.tbl      2013-07-14 17:00:37.000000000 +0000
713 +++ linux-3.10.33-vs2.3.6.8/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.33/arch/x86/syscalls/syscall_64.tbl linux-3.10.33-vs2.3.6.8/arch/x86/syscalls/syscall_64.tbl
724 --- linux-3.10.33/arch/x86/syscalls/syscall_64.tbl      2013-05-31 13:44:50.000000000 +0000
725 +++ linux-3.10.33-vs2.3.6.8/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.33/drivers/block/Kconfig linux-3.10.33-vs2.3.6.8/drivers/block/Kconfig
736 --- linux-3.10.33/drivers/block/Kconfig 2013-05-31 13:44:51.000000000 +0000
737 +++ linux-3.10.33-vs2.3.6.8/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.33/drivers/block/Makefile linux-3.10.33-vs2.3.6.8/drivers/block/Makefile
753 --- linux-3.10.33/drivers/block/Makefile        2013-07-14 17:00:41.000000000 +0000
754 +++ linux-3.10.33-vs2.3.6.8/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.33/drivers/block/loop.c linux-3.10.33-vs2.3.6.8/drivers/block/loop.c
764 --- linux-3.10.33/drivers/block/loop.c  2014-03-12 13:15:56.000000000 +0000
765 +++ linux-3.10.33-vs2.3.6.8/drivers/block/loop.c        2013-12-23 17:42:39.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 @@ -1028,6 +1030,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 @@ -1071,7 +1074,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 @@ -1161,7 +1164,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 @@ -1503,6 +1507,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.33/drivers/block/vroot.c linux-3.10.33-vs2.3.6.8/drivers/block/vroot.c
822 --- linux-3.10.33/drivers/block/vroot.c 1970-01-01 00:00:00.000000000 +0000
823 +++ linux-3.10.33-vs2.3.6.8/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.33/drivers/infiniband/Kconfig linux-3.10.33-vs2.3.6.8/drivers/infiniband/Kconfig
1116 --- linux-3.10.33/drivers/infiniband/Kconfig    2013-07-14 17:00:49.000000000 +0000
1117 +++ linux-3.10.33-vs2.3.6.8/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.33/drivers/infiniband/core/addr.c linux-3.10.33-vs2.3.6.8/drivers/infiniband/core/addr.c
1128 --- linux-3.10.33/drivers/infiniband/core/addr.c        2012-12-11 03:30:57.000000000 +0000
1129 +++ linux-3.10.33-vs2.3.6.8/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.33/drivers/md/dm-ioctl.c linux-3.10.33-vs2.3.6.8/drivers/md/dm-ioctl.c
1140 --- linux-3.10.33/drivers/md/dm-ioctl.c 2014-03-12 13:16:01.000000000 +0000
1141 +++ linux-3.10.33-vs2.3.6.8/drivers/md/dm-ioctl.c       2013-11-13 17:17:15.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.33/drivers/md/dm.c linux-3.10.33-vs2.3.6.8/drivers/md/dm.c
1228 --- linux-3.10.33/drivers/md/dm.c       2014-03-12 13:16:01.000000000 +0000
1229 +++ linux-3.10.33-vs2.3.6.8/drivers/md/dm.c     2014-03-12 13:18:23.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.33/drivers/md/dm.h linux-3.10.33-vs2.3.6.8/drivers/md/dm.h
1304 --- linux-3.10.33/drivers/md/dm.h       2014-03-12 13:16:01.000000000 +0000
1305 +++ linux-3.10.33-vs2.3.6.8/drivers/md/dm.h     2014-03-12 13:18:23.000000000 +0000
1306 @@ -48,6 +48,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.33/drivers/net/tun.c linux-3.10.33-vs2.3.6.8/drivers/net/tun.c
1316 --- linux-3.10.33/drivers/net/tun.c     2014-03-12 13:16:01.000000000 +0000
1317 +++ linux-3.10.33-vs2.3.6.8/drivers/net/tun.c   2014-01-22 19:00:34.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 @@ -1435,6 +1438,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 @@ -1626,6 +1630,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 @@ -1644,7 +1651,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 (!nx_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 @@ -1995,6 +2002,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.33/drivers/tty/sysrq.c linux-3.10.33-vs2.3.6.8/drivers/tty/sysrq.c
1387 --- linux-3.10.33/drivers/tty/sysrq.c   2013-07-14 17:01:22.000000000 +0000
1388 +++ linux-3.10.33-vs2.3.6.8/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.33/drivers/tty/tty_io.c linux-3.10.33-vs2.3.6.8/drivers/tty/tty_io.c
1441 --- linux-3.10.33/drivers/tty/tty_io.c  2014-03-12 13:16:02.000000000 +0000
1442 +++ linux-3.10.33-vs2.3.6.8/drivers/tty/tty_io.c        2013-11-13 17:17:15.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 @@ -2213,7 +2214,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 @@ -2501,6 +2503,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.33/fs/attr.c linux-3.10.33-vs2.3.6.8/fs/attr.c
1470 --- linux-3.10.33/fs/attr.c     2014-03-12 13:16:02.000000000 +0000
1471 +++ linux-3.10.33-vs2.3.6.8/fs/attr.c   2014-03-12 13:18:32.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.33/fs/block_dev.c linux-3.10.33-vs2.3.6.8/fs/block_dev.c
1513 --- linux-3.10.33/fs/block_dev.c        2014-03-12 13:16:02.000000000 +0000
1514 +++ linux-3.10.33-vs2.3.6.8/fs/block_dev.c      2013-11-13 17:17:15.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.33/fs/btrfs/ctree.h linux-3.10.33-vs2.3.6.8/fs/btrfs/ctree.h
1553 --- linux-3.10.33/fs/btrfs/ctree.h      2013-07-14 17:01:26.000000000 +0000
1554 +++ linux-3.10.33-vs2.3.6.8/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.33/fs/btrfs/disk-io.c linux-3.10.33-vs2.3.6.8/fs/btrfs/disk-io.c
1608 --- linux-3.10.33/fs/btrfs/disk-io.c    2013-07-14 17:01:26.000000000 +0000
1609 +++ linux-3.10.33-vs2.3.6.8/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.33/fs/btrfs/inode.c linux-3.10.33-vs2.3.6.8/fs/btrfs/inode.c
1621 --- linux-3.10.33/fs/btrfs/inode.c      2014-03-12 13:16:02.000000000 +0000
1622 +++ linux-3.10.33-vs2.3.6.8/fs/btrfs/inode.c    2014-03-12 13:18:32.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 @@ -3336,6 +3337,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 @@ -3363,8 +3367,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 @@ -3455,11 +3465,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 @@ -8733,11 +8750,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.33/fs/btrfs/ioctl.c linux-3.10.33-vs2.3.6.8/fs/btrfs/ioctl.c
1694 --- linux-3.10.33/fs/btrfs/ioctl.c      2014-03-12 13:16:02.000000000 +0000
1695 +++ linux-3.10.33-vs2.3.6.8/fs/btrfs/ioctl.c    2014-03-12 13:18:23.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.33/fs/btrfs/super.c linux-3.10.33-vs2.3.6.8/fs/btrfs/super.c
1868 --- linux-3.10.33/fs/btrfs/super.c      2013-07-14 17:01:26.000000000 +0000
1869 +++ linux-3.10.33-vs2.3.6.8/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.33/fs/char_dev.c linux-3.10.33-vs2.3.6.8/fs/char_dev.c
1926 --- linux-3.10.33/fs/char_dev.c 2012-12-11 03:30:57.000000000 +0000
1927 +++ linux-3.10.33-vs2.3.6.8/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.33/fs/dcache.c linux-3.10.33-vs2.3.6.8/fs/dcache.c
1961 --- linux-3.10.33/fs/dcache.c   2014-03-12 13:16:02.000000000 +0000
1962 +++ linux-3.10.33-vs2.3.6.8/fs/dcache.c 2014-03-12 13:18:23.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.33/fs/devpts/inode.c linux-3.10.33-vs2.3.6.8/fs/devpts/inode.c
2015 --- linux-3.10.33/fs/devpts/inode.c     2014-03-12 13:16:02.000000000 +0000
2016 +++ linux-3.10.33-vs2.3.6.8/fs/devpts/inode.c   2013-12-23 17:42:40.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 @@ -593,6 +639,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.33/fs/ext2/balloc.c linux-3.10.33-vs2.3.6.8/fs/ext2/balloc.c
2105 --- linux-3.10.33/fs/ext2/balloc.c      2013-05-31 13:45:23.000000000 +0000
2106 +++ linux-3.10.33-vs2.3.6.8/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.33/fs/ext2/ext2.h linux-3.10.33-vs2.3.6.8/fs/ext2/ext2.h
2116 --- linux-3.10.33/fs/ext2/ext2.h        2012-12-11 03:30:57.000000000 +0000
2117 +++ linux-3.10.33-vs2.3.6.8/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.33/fs/ext2/file.c linux-3.10.33-vs2.3.6.8/fs/ext2/file.c
2166 --- linux-3.10.33/fs/ext2/file.c        2012-12-11 03:30:57.000000000 +0000
2167 +++ linux-3.10.33-vs2.3.6.8/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.33/fs/ext2/ialloc.c linux-3.10.33-vs2.3.6.8/fs/ext2/ialloc.c
2175 --- linux-3.10.33/fs/ext2/ialloc.c      2013-05-31 13:45:23.000000000 +0000
2176 +++ linux-3.10.33-vs2.3.6.8/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.33/fs/ext2/inode.c linux-3.10.33-vs2.3.6.8/fs/ext2/inode.c
2194 --- linux-3.10.33/fs/ext2/inode.c       2013-07-14 17:01:27.000000000 +0000
2195 +++ linux-3.10.33-vs2.3.6.8/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.33/fs/ext2/ioctl.c linux-3.10.33-vs2.3.6.8/fs/ext2/ioctl.c
2329 --- linux-3.10.33/fs/ext2/ioctl.c       2013-05-31 13:45:23.000000000 +0000
2330 +++ linux-3.10.33-vs2.3.6.8/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.33/fs/ext2/namei.c linux-3.10.33-vs2.3.6.8/fs/ext2/namei.c
2381 --- linux-3.10.33/fs/ext2/namei.c       2012-12-11 03:30:57.000000000 +0000
2382 +++ linux-3.10.33-vs2.3.6.8/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.33/fs/ext2/super.c linux-3.10.33-vs2.3.6.8/fs/ext2/super.c
2408 --- linux-3.10.33/fs/ext2/super.c       2013-05-31 13:45:23.000000000 +0000
2409 +++ linux-3.10.33-vs2.3.6.8/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.33/fs/ext3/ext3.h linux-3.10.33-vs2.3.6.8/fs/ext3/ext3.h
2476 --- linux-3.10.33/fs/ext3/ext3.h        2012-12-11 03:30:57.000000000 +0000
2477 +++ linux-3.10.33-vs2.3.6.8/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.33/fs/ext3/file.c linux-3.10.33-vs2.3.6.8/fs/ext3/file.c
2530 --- linux-3.10.33/fs/ext3/file.c        2012-12-11 03:30:57.000000000 +0000
2531 +++ linux-3.10.33-vs2.3.6.8/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.33/fs/ext3/ialloc.c linux-3.10.33-vs2.3.6.8/fs/ext3/ialloc.c
2540 --- linux-3.10.33/fs/ext3/ialloc.c      2012-12-11 03:30:57.000000000 +0000
2541 +++ linux-3.10.33-vs2.3.6.8/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.33/fs/ext3/inode.c linux-3.10.33-vs2.3.6.8/fs/ext3/inode.c
2559 --- linux-3.10.33/fs/ext3/inode.c       2013-07-14 17:01:27.000000000 +0000
2560 +++ linux-3.10.33-vs2.3.6.8/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.33/fs/ext3/ioctl.c linux-3.10.33-vs2.3.6.8/fs/ext3/ioctl.c
2694 --- linux-3.10.33/fs/ext3/ioctl.c       2013-05-31 13:45:23.000000000 +0000
2695 +++ linux-3.10.33-vs2.3.6.8/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.33/fs/ext3/namei.c linux-3.10.33-vs2.3.6.8/fs/ext3/namei.c
2764 --- linux-3.10.33/fs/ext3/namei.c       2014-03-12 13:16:02.000000000 +0000
2765 +++ linux-3.10.33-vs2.3.6.8/fs/ext3/namei.c     2013-11-13 17:17:16.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.33/fs/ext3/super.c linux-3.10.33-vs2.3.6.8/fs/ext3/super.c
2792 --- linux-3.10.33/fs/ext3/super.c       2013-07-14 17:01:27.000000000 +0000
2793 +++ linux-3.10.33-vs2.3.6.8/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.33/fs/ext4/ext4.h linux-3.10.33-vs2.3.6.8/fs/ext4/ext4.h
2861 --- linux-3.10.33/fs/ext4/ext4.h        2014-03-12 13:16:02.000000000 +0000
2862 +++ linux-3.10.33-vs2.3.6.8/fs/ext4/ext4.h      2014-03-12 13:18:32.000000000 +0000
2863 @@ -397,7 +397,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 @@ -673,7 +676,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 @@ -793,6 +796,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 @@ -970,6 +974,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 @@ -2550,6 +2555,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.33/fs/ext4/file.c linux-3.10.33-vs2.3.6.8/fs/ext4/file.c
2908 --- linux-3.10.33/fs/ext4/file.c        2014-03-12 13:16:02.000000000 +0000
2909 +++ linux-3.10.33-vs2.3.6.8/fs/ext4/file.c      2013-11-13 17:17:16.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.33/fs/ext4/ialloc.c linux-3.10.33-vs2.3.6.8/fs/ext4/ialloc.c
2918 --- linux-3.10.33/fs/ext4/ialloc.c      2014-03-12 13:16:02.000000000 +0000
2919 +++ linux-3.10.33-vs2.3.6.8/fs/ext4/ialloc.c    2013-11-13 17:17:16.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.33/fs/ext4/inode.c linux-3.10.33-vs2.3.6.8/fs/ext4/inode.c
2937 --- linux-3.10.33/fs/ext4/inode.c       2014-03-12 13:16:02.000000000 +0000
2938 +++ linux-3.10.33-vs2.3.6.8/fs/ext4/inode.c     2014-03-12 13:18:32.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 @@ -4045,41 +4046,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 @@ -4184,8 +4208,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 @@ -4413,8 +4439,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 @@ -4437,6 +4465,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 @@ -4667,7 +4698,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 @@ -4690,6 +4722,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.33/fs/ext4/ioctl.c linux-3.10.33-vs2.3.6.8/fs/ext4/ioctl.c
3075 --- linux-3.10.33/fs/ext4/ioctl.c       2014-03-12 13:16:02.000000000 +0000
3076 +++ linux-3.10.33-vs2.3.6.8/fs/ext4/ioctl.c     2014-03-12 13:18:32.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 @@ -215,6 +216,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 @@ -248,6 +276,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 @@ -265,7 +298,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.33/fs/ext4/namei.c linux-3.10.33-vs2.3.6.8/fs/ext4/namei.c
3143 --- linux-3.10.33/fs/ext4/namei.c       2014-03-12 13:16:02.000000000 +0000
3144 +++ linux-3.10.33-vs2.3.6.8/fs/ext4/namei.c     2013-11-13 17:17:16.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.33/fs/ext4/super.c linux-3.10.33-vs2.3.6.8/fs/ext4/super.c
3170 --- linux-3.10.33/fs/ext4/super.c       2014-03-12 13:16:02.000000000 +0000
3171 +++ linux-3.10.33-vs2.3.6.8/fs/ext4/super.c     2014-03-12 13:18:32.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 @@ -3461,6 +3478,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 @@ -4679,6 +4699,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.33/fs/fcntl.c linux-3.10.33-vs2.3.6.8/fs/fcntl.c
3238 --- linux-3.10.33/fs/fcntl.c    2013-05-31 13:45:23.000000000 +0000
3239 +++ linux-3.10.33-vs2.3.6.8/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.33/fs/file.c linux-3.10.33-vs2.3.6.8/fs/file.c
3258 --- linux-3.10.33/fs/file.c     2014-03-12 13:16:02.000000000 +0000
3259 +++ linux-3.10.33-vs2.3.6.8/fs/file.c   2014-03-12 13:18:23.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.33/fs/file_table.c linux-3.10.33-vs2.3.6.8/fs/file_table.c
3315 --- linux-3.10.33/fs/file_table.c       2013-07-14 17:01:28.000000000 +0000
3316 +++ linux-3.10.33-vs2.3.6.8/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.33/fs/fs_struct.c linux-3.10.33-vs2.3.6.8/fs/fs_struct.c
3354 --- linux-3.10.33/fs/fs_struct.c        2013-05-31 13:45:23.000000000 +0000
3355 +++ linux-3.10.33-vs2.3.6.8/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.33/fs/gfs2/file.c linux-3.10.33-vs2.3.6.8/fs/gfs2/file.c
3381 --- linux-3.10.33/fs/gfs2/file.c        2013-07-14 17:01:28.000000000 +0000
3382 +++ linux-3.10.33-vs2.3.6.8/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.33/fs/gfs2/inode.h linux-3.10.33-vs2.3.6.8/fs/gfs2/inode.h
3506 --- linux-3.10.33/fs/gfs2/inode.h       2012-12-11 03:30:57.000000000 +0000
3507 +++ linux-3.10.33-vs2.3.6.8/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.33/fs/hostfs/hostfs.h linux-3.10.33-vs2.3.6.8/fs/hostfs/hostfs.h
3517 --- linux-3.10.33/fs/hostfs/hostfs.h    2012-12-11 03:30:57.000000000 +0000
3518 +++ linux-3.10.33-vs2.3.6.8/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.33/fs/inode.c linux-3.10.33-vs2.3.6.8/fs/inode.c
3528 --- linux-3.10.33/fs/inode.c    2013-07-14 17:01:28.000000000 +0000
3529 +++ linux-3.10.33-vs2.3.6.8/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.33/fs/ioctl.c linux-3.10.33-vs2.3.6.8/fs/ioctl.c
3593 --- linux-3.10.33/fs/ioctl.c    2013-05-31 13:45:24.000000000 +0000
3594 +++ linux-3.10.33-vs2.3.6.8/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.33/fs/ioprio.c linux-3.10.33-vs2.3.6.8/fs/ioprio.c
3606 --- linux-3.10.33/fs/ioprio.c   2012-12-11 03:30:57.000000000 +0000
3607 +++ linux-3.10.33-vs2.3.6.8/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.33/fs/jfs/file.c linux-3.10.33-vs2.3.6.8/fs/jfs/file.c
3635 --- linux-3.10.33/fs/jfs/file.c 2013-02-19 13:58:48.000000000 +0000
3636 +++ linux-3.10.33-vs2.3.6.8/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.33/fs/jfs/ioctl.c linux-3.10.33-vs2.3.6.8/fs/jfs/ioctl.c
3656 --- linux-3.10.33/fs/jfs/ioctl.c        2013-05-31 13:45:24.000000000 +0000
3657 +++ linux-3.10.33-vs2.3.6.8/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.33/fs/jfs/jfs_dinode.h linux-3.10.33-vs2.3.6.8/fs/jfs/jfs_dinode.h
3716 --- linux-3.10.33/fs/jfs/jfs_dinode.h   2012-12-11 03:30:57.000000000 +0000
3717 +++ linux-3.10.33-vs2.3.6.8/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.33/fs/jfs/jfs_filsys.h linux-3.10.33-vs2.3.6.8/fs/jfs/jfs_filsys.h
3735 --- linux-3.10.33/fs/jfs/jfs_filsys.h   2012-12-11 03:30:57.000000000 +0000
3736 +++ linux-3.10.33-vs2.3.6.8/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.33/fs/jfs/jfs_imap.c linux-3.10.33-vs2.3.6.8/fs/jfs/jfs_imap.c
3746 --- linux-3.10.33/fs/jfs/jfs_imap.c     2013-07-14 17:01:28.000000000 +0000
3747 +++ linux-3.10.33-vs2.3.6.8/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.33/fs/jfs/jfs_inode.c linux-3.10.33-vs2.3.6.8/fs/jfs/jfs_inode.c
3812 --- linux-3.10.33/fs/jfs/jfs_inode.c    2014-03-12 13:16:02.000000000 +0000
3813 +++ linux-3.10.33-vs2.3.6.8/fs/jfs/jfs_inode.c  2013-11-13 17:22:25.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.33/fs/jfs/jfs_inode.h linux-3.10.33-vs2.3.6.8/fs/jfs/jfs_inode.h
3888 --- linux-3.10.33/fs/jfs/jfs_inode.h    2012-12-11 03:30:57.000000000 +0000
3889 +++ linux-3.10.33-vs2.3.6.8/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.33/fs/jfs/namei.c linux-3.10.33-vs2.3.6.8/fs/jfs/namei.c
3899 --- linux-3.10.33/fs/jfs/namei.c        2012-12-11 03:30:57.000000000 +0000
3900 +++ linux-3.10.33-vs2.3.6.8/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.33/fs/jfs/super.c linux-3.10.33-vs2.3.6.8/fs/jfs/super.c
3926 --- linux-3.10.33/fs/jfs/super.c        2013-07-14 17:01:28.000000000 +0000
3927 +++ linux-3.10.33-vs2.3.6.8/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.33/fs/libfs.c linux-3.10.33-vs2.3.6.8/fs/libfs.c
3995 --- linux-3.10.33/fs/libfs.c    2013-02-19 13:58:48.000000000 +0000
3996 +++ linux-3.10.33-vs2.3.6.8/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.33/fs/locks.c linux-3.10.33-vs2.3.6.8/fs/locks.c
4043 --- linux-3.10.33/fs/locks.c    2013-05-31 13:45:24.000000000 +0000
4044 +++ linux-3.10.33-vs2.3.6.8/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.33/fs/mount.h linux-3.10.33-vs2.3.6.8/fs/mount.h
4243 --- linux-3.10.33/fs/mount.h    2014-03-12 13:16:02.000000000 +0000
4244 +++ linux-3.10.33-vs2.3.6.8/fs/mount.h  2014-03-12 13:18:23.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.33/fs/namei.c linux-3.10.33-vs2.3.6.8/fs/namei.c
4254 --- linux-3.10.33/fs/namei.c    2014-03-12 13:16:02.000000000 +0000
4255 +++ linux-3.10.33-vs2.3.6.8/fs/namei.c  2013-12-23 17:42:40.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 @@ -2317,19 +2420,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 @@ -2364,6 +2473,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 @@ -2866,6 +2984,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 @@ -2930,6 +3058,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 @@ -2966,6 +3095,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 @@ -3080,6 +3219,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 @@ -3574,7 +3718,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 @@ -3977,6 +4121,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 @@ -4100,3 +4525,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.33/fs/namespace.c linux-3.10.33-vs2.3.6.8/fs/namespace.c
4821 --- linux-3.10.33/fs/namespace.c        2014-03-12 13:16:02.000000000 +0000
4822 +++ linux-3.10.33-vs2.3.6.8/fs/namespace.c      2013-11-13 17:17:16.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 @@ -1291,7 +1301,8 @@ static int do_umount(struct mount *mnt,
4855   */
4856  static inline bool may_mount(void)
4857  {
4858 -       return ns_capable(current->nsproxy->mnt_ns->user_ns, CAP_SYS_ADMIN);
4859 +       return vx_ns_capable(current->nsproxy->mnt_ns->user_ns,
4860 +               CAP_SYS_ADMIN, VXC_SECURE_MOUNT);
4861  }
4862  
4863  /*
4864 @@ -1685,6 +1696,7 @@ static int do_change_type(struct path *p
4865                 if (err)
4866                         goto out_unlock;
4867         }
4868 +       // mnt->mnt_flags = mnt_flags;
4869  
4870         br_write_lock(&vfsmount_lock);
4871         for (m = mnt; m; m = (recurse ? next_mnt(m, mnt) : NULL))
4872 @@ -1700,12 +1712,14 @@ static int do_change_type(struct path *p
4873   * do loopback mount.
4874   */
4875  static int do_loopback(struct path *path, const char *old_name,
4876 -                               int recurse)
4877 +       vtag_t tag, unsigned long flags, int mnt_flags)
4878  {
4879         struct path old_path;
4880         struct mount *mnt = NULL, *old, *parent;
4881         struct mountpoint *mp;
4882 +       int recurse = flags & MS_REC;
4883         int err;
4884 +
4885         if (!old_name || !*old_name)
4886                 return -EINVAL;
4887         err = kern_path(old_name, LOOKUP_FOLLOW|LOOKUP_AUTOMOUNT, &old_path);
4888 @@ -1780,7 +1794,7 @@ static int change_mount_flags(struct vfs
4889   * on it - tough luck.
4890   */
4891  static int do_remount(struct path *path, int flags, int mnt_flags,
4892 -                     void *data)
4893 +       void *data, vxid_t xid)
4894  {
4895         int err;
4896         struct super_block *sb = path->mnt->mnt_sb;
4897 @@ -2264,6 +2278,7 @@ long do_mount(const char *dev_name, cons
4898         struct path path;
4899         int retval = 0;
4900         int mnt_flags = 0;
4901 +       vtag_t tag = 0;
4902  
4903         /* Discard magic */
4904         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
4905 @@ -2293,6 +2308,12 @@ long do_mount(const char *dev_name, cons
4906         if (!(flags & MS_NOATIME))
4907                 mnt_flags |= MNT_RELATIME;
4908  
4909 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
4910 +               /* FIXME: bind and re-mounts get the tag flag? */
4911 +               if (flags & (MS_BIND|MS_REMOUNT))
4912 +                       flags |= MS_TAGID;
4913 +       }
4914 +
4915         /* Separate the per-mountpoint flags */
4916         if (flags & MS_NOSUID)
4917                 mnt_flags |= MNT_NOSUID;
4918 @@ -2309,15 +2330,17 @@ long do_mount(const char *dev_name, cons
4919         if (flags & MS_RDONLY)
4920                 mnt_flags |= MNT_READONLY;
4921  
4922 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_DEV_MOUNT))
4923 +               mnt_flags |= MNT_NODEV;
4924         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_BORN |
4925                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
4926                    MS_STRICTATIME);
4927  
4928         if (flags & MS_REMOUNT)
4929                 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
4930 -                                   data_page);
4931 +                                   data_page, tag);
4932         else if (flags & MS_BIND)
4933 -               retval = do_loopback(&path, dev_name, flags & MS_REC);
4934 +               retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
4935         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
4936                 retval = do_change_type(&path, flags);
4937         else if (flags & MS_MOVE)
4938 @@ -2426,6 +2449,7 @@ static struct mnt_namespace *dup_mnt_ns(
4939                 q = next_mnt(q, new);
4940         }
4941         namespace_unlock();
4942 +       atomic_inc(&vs_global_mnt_ns);
4943  
4944         if (rootmnt)
4945                 mntput(rootmnt);
4946 @@ -2624,9 +2648,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
4947         new_mnt = real_mount(new.mnt);
4948         root_mnt = real_mount(root.mnt);
4949         old_mnt = real_mount(old.mnt);
4950 -       if (IS_MNT_SHARED(old_mnt) ||
4951 +       if ((IS_MNT_SHARED(old_mnt) ||
4952                 IS_MNT_SHARED(new_mnt->mnt_parent) ||
4953 -               IS_MNT_SHARED(root_mnt->mnt_parent))
4954 +               IS_MNT_SHARED(root_mnt->mnt_parent)) &&
4955 +               !vx_flags(VXF_STATE_SETUP, 0))
4956                 goto out4;
4957         if (!check_mnt(root_mnt) || !check_mnt(new_mnt))
4958                 goto out4;
4959 @@ -2752,6 +2777,7 @@ void put_mnt_ns(struct mnt_namespace *ns
4960         umount_tree(ns->root, 0);
4961         br_write_unlock(&vfsmount_lock);
4962         namespace_unlock();
4963 +       atomic_dec(&vs_global_mnt_ns);
4964         free_mnt_ns(ns);
4965  }
4966  
4967 diff -NurpP --minimal linux-3.10.33/fs/nfs/client.c linux-3.10.33-vs2.3.6.8/fs/nfs/client.c
4968 --- linux-3.10.33/fs/nfs/client.c       2013-07-14 17:01:28.000000000 +0000
4969 +++ linux-3.10.33-vs2.3.6.8/fs/nfs/client.c     2013-08-22 20:29:59.000000000 +0000
4970 @@ -684,6 +684,9 @@ int nfs_init_server_rpcclient(struct nfs
4971         if (server->flags & NFS_MOUNT_SOFT)
4972                 server->client->cl_softrtry = 1;
4973  
4974 +       server->client->cl_tag = 0;
4975 +       if (server->flags & NFS_MOUNT_TAGGED)
4976 +               server->client->cl_tag = 1;
4977         return 0;
4978  }
4979  EXPORT_SYMBOL_GPL(nfs_init_server_rpcclient);
4980 @@ -863,6 +866,10 @@ static void nfs_server_set_fsinfo(struct
4981                 server->acdirmin = server->acdirmax = 0;
4982         }
4983  
4984 +       /* FIXME: needs fsinfo
4985 +       if (server->flags & NFS_MOUNT_TAGGED)
4986 +               sb->s_flags |= MS_TAGGED;       */
4987 +
4988         server->maxfilesize = fsinfo->maxfilesize;
4989  
4990         server->time_delta = fsinfo->time_delta;
4991 diff -NurpP --minimal linux-3.10.33/fs/nfs/dir.c linux-3.10.33-vs2.3.6.8/fs/nfs/dir.c
4992 --- linux-3.10.33/fs/nfs/dir.c  2013-07-14 17:01:28.000000000 +0000
4993 +++ linux-3.10.33-vs2.3.6.8/fs/nfs/dir.c        2013-08-22 20:29:59.000000000 +0000
4994 @@ -36,6 +36,7 @@
4995  #include <linux/sched.h>
4996  #include <linux/kmemleak.h>
4997  #include <linux/xattr.h>
4998 +#include <linux/vs_tag.h>
4999  
5000  #include "delegation.h"
5001  #include "iostat.h"
5002 @@ -1300,6 +1301,7 @@ struct dentry *nfs_lookup(struct inode *
5003         /* Success: notify readdir to use READDIRPLUS */
5004         nfs_advise_use_readdirplus(dir);
5005  
5006 +       dx_propagate_tag(nd, inode);
5007  no_entry:
5008         res = d_materialise_unique(dentry, inode);
5009         if (res != NULL) {
5010 diff -NurpP --minimal linux-3.10.33/fs/nfs/inode.c linux-3.10.33-vs2.3.6.8/fs/nfs/inode.c
5011 --- linux-3.10.33/fs/nfs/inode.c        2013-07-14 17:01:28.000000000 +0000
5012 +++ linux-3.10.33-vs2.3.6.8/fs/nfs/inode.c      2013-08-22 20:29:59.000000000 +0000
5013 @@ -39,6 +39,7 @@
5014  #include <linux/compat.h>
5015  #include <linux/freezer.h>
5016  #include <linux/crc32.h>
5017 +#include <linux/vs_tag.h>
5018  
5019  #include <asm/uaccess.h>
5020  
5021 @@ -290,6 +291,8 @@ nfs_fhget(struct super_block *sb, struct
5022         if (inode->i_state & I_NEW) {
5023                 struct nfs_inode *nfsi = NFS_I(inode);
5024                 unsigned long now = jiffies;
5025 +               kuid_t kuid;
5026 +               kgid_t kgid;
5027  
5028                 /* We set i_ino for the few things that still rely on it,
5029                  * such as stat(2) */
5030 @@ -334,8 +337,8 @@ nfs_fhget(struct super_block *sb, struct
5031                 inode->i_version = 0;
5032                 inode->i_size = 0;
5033                 clear_nlink(inode);
5034 -               inode->i_uid = make_kuid(&init_user_ns, -2);
5035 -               inode->i_gid = make_kgid(&init_user_ns, -2);
5036 +               kuid = make_kuid(&init_user_ns, -2);
5037 +               kgid = make_kgid(&init_user_ns, -2);
5038                 inode->i_blocks = 0;
5039                 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
5040                 nfsi->write_io = 0;
5041 @@ -369,11 +372,11 @@ nfs_fhget(struct super_block *sb, struct
5042                 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
5043                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5044                 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
5045 -                       inode->i_uid = fattr->uid;
5046 +                       kuid = fattr->uid;
5047                 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
5048                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5049                 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
5050 -                       inode->i_gid = fattr->gid;
5051 +                       kgid = fattr->gid;
5052                 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
5053                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5054                 if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED)
5055 @@ -384,6 +387,11 @@ nfs_fhget(struct super_block *sb, struct
5056                          */
5057                         inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
5058                 }
5059 +               inode->i_uid = INOTAG_KUID(DX_TAG(inode), kuid, kgid);
5060 +               inode->i_gid = INOTAG_KGID(DX_TAG(inode), kuid, kgid);
5061 +               inode->i_tag = INOTAG_KTAG(DX_TAG(inode), kuid, kgid, GLOBAL_ROOT_TAG);
5062 +                               /* maybe fattr->xid someday */
5063 +
5064                 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
5065                 nfsi->attrtimeo_timestamp = now;
5066                 nfsi->access_cache = RB_ROOT;
5067 @@ -505,6 +513,8 @@ void nfs_setattr_update_inode(struct ino
5068                         inode->i_uid = attr->ia_uid;
5069                 if ((attr->ia_valid & ATTR_GID) != 0)
5070                         inode->i_gid = attr->ia_gid;
5071 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5072 +                       inode->i_tag = attr->ia_tag;
5073                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5074                 spin_unlock(&inode->i_lock);
5075         }
5076 @@ -982,7 +992,9 @@ static int nfs_check_inode_attributes(st
5077         struct nfs_inode *nfsi = NFS_I(inode);
5078         loff_t cur_size, new_isize;
5079         unsigned long invalid = 0;
5080 -
5081 +       kuid_t kuid;
5082 +       kgid_t kgid;
5083 +       ktag_t ktag;
5084  
5085         if (nfs_have_delegated_attributes(inode))
5086                 return 0;
5087 @@ -1007,13 +1019,18 @@ static int nfs_check_inode_attributes(st
5088                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5089         }
5090  
5091 +       kuid = INOTAG_KUID(DX_TAG(inode), fattr->uid, fattr->gid);
5092 +       kgid = INOTAG_KGID(DX_TAG(inode), fattr->uid, fattr->gid);
5093 +       ktag = INOTAG_KTAG(DX_TAG(inode), fattr->uid, fattr->gid, GLOBAL_ROOT_TAG);
5094 +
5095         /* Have any file permissions changed? */
5096         if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
5097                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5098 -       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && !uid_eq(inode->i_uid, fattr->uid))
5099 +       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && !uid_eq(inode->i_uid, kuid))
5100                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5101 -       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && !gid_eq(inode->i_gid, fattr->gid))
5102 +       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && !gid_eq(inode->i_gid, kgid))
5103                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5104 +               /* maybe check for tag too? */
5105  
5106         /* Has the link count changed? */
5107         if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
5108 @@ -1319,6 +1336,9 @@ static int nfs_update_inode(struct inode
5109         unsigned long invalid = 0;
5110         unsigned long now = jiffies;
5111         unsigned long save_cache_validity;
5112 +       kuid_t kuid;
5113 +       kgid_t kgid;
5114 +       ktag_t ktag;
5115  
5116         dfprintk(VFS, "NFS: %s(%s/%ld fh_crc=0x%08x ct=%d info=0x%x)\n",
5117                         __func__, inode->i_sb->s_id, inode->i_ino,
5118 @@ -1420,6 +1440,9 @@ static int nfs_update_inode(struct inode
5119                                 | NFS_INO_REVAL_PAGECACHE
5120                                 | NFS_INO_REVAL_FORCED);
5121  
5122 +       kuid = TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag);
5123 +       kgid = TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag);
5124 +       ktag = TAGINO_KTAG(DX_TAG(inode), inode->i_tag);
5125  
5126         if (fattr->valid & NFS_ATTR_FATTR_ATIME)
5127                 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5128 @@ -1462,6 +1485,10 @@ static int nfs_update_inode(struct inode
5129                                 | NFS_INO_INVALID_ACL
5130                                 | NFS_INO_REVAL_FORCED);
5131  
5132 +       inode->i_uid = INOTAG_KUID(DX_TAG(inode), kuid, kgid);
5133 +       inode->i_gid = INOTAG_KGID(DX_TAG(inode), kuid, kgid);
5134 +       inode->i_tag = INOTAG_KTAG(DX_TAG(inode), kuid, kgid, ktag);
5135 +
5136         if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
5137                 if (inode->i_nlink != fattr->nlink) {
5138                         invalid |= NFS_INO_INVALID_ATTR;
5139 diff -NurpP --minimal linux-3.10.33/fs/nfs/nfs3xdr.c linux-3.10.33-vs2.3.6.8/fs/nfs/nfs3xdr.c
5140 --- linux-3.10.33/fs/nfs/nfs3xdr.c      2013-05-31 13:45:24.000000000 +0000
5141 +++ linux-3.10.33-vs2.3.6.8/fs/nfs/nfs3xdr.c    2013-08-22 20:29:59.000000000 +0000
5142 @@ -20,6 +20,7 @@
5143  #include <linux/nfs3.h>
5144  #include <linux/nfs_fs.h>
5145  #include <linux/nfsacl.h>
5146 +#include <linux/vs_tag.h>
5147  #include "internal.h"
5148  
5149  #define NFSDBG_FACILITY                NFSDBG_XDR
5150 @@ -558,7 +559,8 @@ static __be32 *xdr_decode_nfstime3(__be3
5151   *             set_mtime       mtime;
5152   *     };
5153   */
5154 -static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr)
5155 +static void encode_sattr3(struct xdr_stream *xdr,
5156 +       const struct iattr *attr, int tag)
5157  {
5158         u32 nbytes;
5159         __be32 *p;
5160 @@ -590,15 +592,19 @@ static void encode_sattr3(struct xdr_str
5161         } else
5162                 *p++ = xdr_zero;
5163  
5164 -       if (attr->ia_valid & ATTR_UID) {
5165 +       if (attr->ia_valid & ATTR_UID ||
5166 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5167                 *p++ = xdr_one;
5168 -               *p++ = cpu_to_be32(from_kuid(&init_user_ns, attr->ia_uid));
5169 +               *p++ = cpu_to_be32(from_kuid(&init_user_ns,
5170 +                       TAGINO_KUID(tag, attr->ia_uid, attr->ia_tag)));
5171         } else
5172                 *p++ = xdr_zero;
5173  
5174 -       if (attr->ia_valid & ATTR_GID) {
5175 +       if (attr->ia_valid & ATTR_GID ||
5176 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5177                 *p++ = xdr_one;
5178 -               *p++ = cpu_to_be32(from_kgid(&init_user_ns, attr->ia_gid));
5179 +               *p++ = cpu_to_be32(from_kgid(&init_user_ns,
5180 +                       TAGINO_KGID(tag, attr->ia_gid, attr->ia_tag)));
5181         } else
5182                 *p++ = xdr_zero;
5183  
5184 @@ -887,7 +893,7 @@ static void nfs3_xdr_enc_setattr3args(st
5185                                       const struct nfs3_sattrargs *args)
5186  {
5187         encode_nfs_fh3(xdr, args->fh);
5188 -       encode_sattr3(xdr, args->sattr);
5189 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5190         encode_sattrguard3(xdr, args);
5191  }
5192  
5193 @@ -1037,13 +1043,13 @@ static void nfs3_xdr_enc_write3args(stru
5194   *     };
5195   */
5196  static void encode_createhow3(struct xdr_stream *xdr,
5197 -                             const struct nfs3_createargs *args)
5198 +       const struct nfs3_createargs *args, int tag)
5199  {
5200         encode_uint32(xdr, args->createmode);
5201         switch (args->createmode) {
5202         case NFS3_CREATE_UNCHECKED:
5203         case NFS3_CREATE_GUARDED:
5204 -               encode_sattr3(xdr, args->sattr);
5205 +               encode_sattr3(xdr, args->sattr, tag);
5206                 break;
5207         case NFS3_CREATE_EXCLUSIVE:
5208                 encode_createverf3(xdr, args->verifier);
5209 @@ -1058,7 +1064,7 @@ static void nfs3_xdr_enc_create3args(str
5210                                      const struct nfs3_createargs *args)
5211  {
5212         encode_diropargs3(xdr, args->fh, args->name, args->len);
5213 -       encode_createhow3(xdr, args);
5214 +       encode_createhow3(xdr, args, req->rq_task->tk_client->cl_tag);
5215  }
5216  
5217  /*
5218 @@ -1074,7 +1080,7 @@ static void nfs3_xdr_enc_mkdir3args(stru
5219                                     const struct nfs3_mkdirargs *args)
5220  {
5221         encode_diropargs3(xdr, args->fh, args->name, args->len);
5222 -       encode_sattr3(xdr, args->sattr);
5223 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5224  }
5225  
5226  /*
5227 @@ -1091,9 +1097,9 @@ static void nfs3_xdr_enc_mkdir3args(stru
5228   *     };
5229   */
5230  static void encode_symlinkdata3(struct xdr_stream *xdr,
5231 -                               const struct nfs3_symlinkargs *args)
5232 +       const struct nfs3_symlinkargs *args, int tag)
5233  {
5234 -       encode_sattr3(xdr, args->sattr);
5235 +       encode_sattr3(xdr, args->sattr, tag);
5236         encode_nfspath3(xdr, args->pages, args->pathlen);
5237  }
5238  
5239 @@ -1102,7 +1108,7 @@ static void nfs3_xdr_enc_symlink3args(st
5240                                       const struct nfs3_symlinkargs *args)
5241  {
5242         encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen);
5243 -       encode_symlinkdata3(xdr, args);
5244 +       encode_symlinkdata3(xdr, args, req->rq_task->tk_client->cl_tag);
5245  }
5246  
5247  /*
5248 @@ -1130,24 +1136,24 @@ static void nfs3_xdr_enc_symlink3args(st
5249   *     };
5250   */
5251  static void encode_devicedata3(struct xdr_stream *xdr,
5252 -                              const struct nfs3_mknodargs *args)
5253 +       const struct nfs3_mknodargs *args, int tag)
5254  {
5255 -       encode_sattr3(xdr, args->sattr);
5256 +       encode_sattr3(xdr, args->sattr, tag);
5257         encode_specdata3(xdr, args->rdev);
5258  }
5259  
5260  static void encode_mknoddata3(struct xdr_stream *xdr,
5261 -                             const struct nfs3_mknodargs *args)
5262 +       const struct nfs3_mknodargs *args, int tag)
5263  {
5264         encode_ftype3(xdr, args->type);
5265         switch (args->type) {
5266         case NF3CHR:
5267         case NF3BLK:
5268 -               encode_devicedata3(xdr, args);
5269 +               encode_devicedata3(xdr, args, tag);
5270                 break;
5271         case NF3SOCK:
5272         case NF3FIFO:
5273 -               encode_sattr3(xdr, args->sattr);
5274 +               encode_sattr3(xdr, args->sattr, tag);
5275                 break;
5276         case NF3REG:
5277         case NF3DIR:
5278 @@ -1162,7 +1168,7 @@ static void nfs3_xdr_enc_mknod3args(stru
5279                                     const struct nfs3_mknodargs *args)
5280  {
5281         encode_diropargs3(xdr, args->fh, args->name, args->len);
5282 -       encode_mknoddata3(xdr, args);
5283 +       encode_mknoddata3(xdr, args, req->rq_task->tk_client->cl_tag);
5284  }
5285  
5286  /*
5287 diff -NurpP --minimal linux-3.10.33/fs/nfs/super.c linux-3.10.33-vs2.3.6.8/fs/nfs/super.c
5288 --- linux-3.10.33/fs/nfs/super.c        2013-07-14 17:01:28.000000000 +0000
5289 +++ linux-3.10.33-vs2.3.6.8/fs/nfs/super.c      2013-08-22 20:29:59.000000000 +0000
5290 @@ -55,6 +55,7 @@
5291  #include <linux/parser.h>
5292  #include <linux/nsproxy.h>
5293  #include <linux/rcupdate.h>
5294 +#include <linux/vs_tag.h>
5295  
5296  #include <asm/uaccess.h>
5297  
5298 @@ -103,6 +104,7 @@ enum {
5299         Opt_mountport,
5300         Opt_mountvers,
5301         Opt_minorversion,
5302 +       Opt_tagid,
5303  
5304         /* Mount options that take string arguments */
5305         Opt_nfsvers,
5306 @@ -115,6 +117,9 @@ enum {
5307         /* Special mount options */
5308         Opt_userspace, Opt_deprecated, Opt_sloppy,
5309  
5310 +       /* Linux-VServer tagging options */
5311 +       Opt_tag, Opt_notag,
5312 +
5313         Opt_err
5314  };
5315  
5316 @@ -184,6 +189,10 @@ static const match_table_t nfs_mount_opt
5317         { Opt_fscache_uniq, "fsc=%s" },
5318         { Opt_local_lock, "local_lock=%s" },
5319  
5320 +       { Opt_tag, "tag" },
5321 +       { Opt_notag, "notag" },
5322 +       { Opt_tagid, "tagid=%u" },
5323 +
5324         /* The following needs to be listed after all other options */
5325         { Opt_nfsvers, "v%s" },
5326  
5327 @@ -635,6 +644,7 @@ static void nfs_show_mount_options(struc
5328                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
5329                 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
5330                 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
5331 +               { NFS_MOUNT_TAGGED, ",tag", "" },
5332                 { 0, NULL, NULL }
5333         };
5334         const struct proc_nfs_info *nfs_infop;
5335 @@ -1261,6 +1271,14 @@ static int nfs_parse_mount_options(char
5336                 case Opt_nomigration:
5337                         mnt->options &= NFS_OPTION_MIGRATION;
5338                         break;
5339 +#ifndef CONFIG_TAGGING_NONE
5340 +               case Opt_tag:
5341 +                       mnt->flags |= NFS_MOUNT_TAGGED;
5342 +                       break;
5343 +               case Opt_notag:
5344 +                       mnt->flags &= ~NFS_MOUNT_TAGGED;
5345 +                       break;
5346 +#endif
5347  
5348                 /*
5349                  * options that take numeric values
5350 @@ -1347,6 +1365,12 @@ static int nfs_parse_mount_options(char
5351                                 goto out_invalid_value;
5352                         mnt->minorversion = option;
5353                         break;
5354 +#ifdef CONFIG_PROPAGATE
5355 +               case Opt_tagid:
5356 +                       /* use args[0] */
5357 +                       nfs_data.flags |= NFS_MOUNT_TAGGED;
5358 +                       break;
5359 +#endif
5360  
5361                 /*
5362                  * options that take text values
5363 diff -NurpP --minimal linux-3.10.33/fs/nfsd/auth.c linux-3.10.33-vs2.3.6.8/fs/nfsd/auth.c
5364 --- linux-3.10.33/fs/nfsd/auth.c        2013-05-31 13:45:24.000000000 +0000
5365 +++ linux-3.10.33-vs2.3.6.8/fs/nfsd/auth.c      2013-08-22 20:29:59.000000000 +0000
5366 @@ -2,6 +2,7 @@
5367  
5368  #include <linux/sched.h>
5369  #include <linux/user_namespace.h>
5370 +#include <linux/vs_tag.h>
5371  #include "nfsd.h"
5372  #include "auth.h"
5373  
5374 @@ -37,6 +38,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
5375  
5376         new->fsuid = rqstp->rq_cred.cr_uid;
5377         new->fsgid = rqstp->rq_cred.cr_gid;
5378 +       /* FIXME: this desperately needs a tag :)
5379 +       new->xid = (vxid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
5380 +                       */
5381  
5382         rqgi = rqstp->rq_cred.cr_group_info;
5383  
5384 diff -NurpP --minimal linux-3.10.33/fs/nfsd/nfs3xdr.c linux-3.10.33-vs2.3.6.8/fs/nfsd/nfs3xdr.c
5385 --- linux-3.10.33/fs/nfsd/nfs3xdr.c     2013-05-31 13:45:24.000000000 +0000
5386 +++ linux-3.10.33-vs2.3.6.8/fs/nfsd/nfs3xdr.c   2013-08-22 20:29:59.000000000 +0000
5387 @@ -8,6 +8,7 @@
5388  
5389  #include <linux/namei.h>
5390  #include <linux/sunrpc/svc_xprt.h>
5391 +#include <linux/vs_tag.h>
5392  #include "xdr3.h"
5393  #include "auth.h"
5394  #include "netns.h"
5395 @@ -98,6 +99,8 @@ static __be32 *
5396  decode_sattr3(__be32 *p, struct iattr *iap)
5397  {
5398         u32     tmp;
5399 +       kuid_t  kuid = GLOBAL_ROOT_UID;
5400 +       kgid_t  kgid = GLOBAL_ROOT_GID;
5401  
5402         iap->ia_valid = 0;
5403  
5404 @@ -106,15 +109,18 @@ decode_sattr3(__be32 *p, struct iattr *i
5405                 iap->ia_mode = ntohl(*p++);
5406         }
5407         if (*p++) {
5408 -               iap->ia_uid = make_kuid(&init_user_ns, ntohl(*p++));
5409 +               kuid = make_kuid(&init_user_ns, ntohl(*p++));
5410                 if (uid_valid(iap->ia_uid))
5411                         iap->ia_valid |= ATTR_UID;
5412         }
5413         if (*p++) {
5414 -               iap->ia_gid = make_kgid(&init_user_ns, ntohl(*p++));
5415 +               kgid = make_kgid(&init_user_ns, ntohl(*p++));
5416                 if (gid_valid(iap->ia_gid))
5417                         iap->ia_valid |= ATTR_GID;
5418         }
5419 +       iap->ia_uid = INOTAG_KUID(DX_TAG_NFSD, kuid, kgid);
5420 +       iap->ia_gid = INOTAG_KGID(DX_TAG_NFSD, kuid, kgid);
5421 +       iap->ia_tag = INOTAG_KTAG(DX_TAG_NFSD, kuid, kgid, GLOBAL_ROOT_TAG);
5422         if (*p++) {
5423                 u64     newsize;
5424  
5425 @@ -170,8 +176,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
5426         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
5427         *p++ = htonl((u32) stat->mode);
5428         *p++ = htonl((u32) stat->nlink);
5429 -       *p++ = htonl((u32) from_kuid(&init_user_ns, stat->uid));
5430 -       *p++ = htonl((u32) from_kgid(&init_user_ns, stat->gid));
5431 +       *p++ = htonl((u32) from_kuid(&init_user_ns,
5432 +               TAGINO_KUID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5433 +               stat->uid, stat->tag)));
5434 +       *p++ = htonl((u32) from_kgid(&init_user_ns,
5435 +               TAGINO_KGID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5436 +               stat->gid, stat->tag)));
5437         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
5438                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
5439         } else {
5440 diff -NurpP --minimal linux-3.10.33/fs/nfsd/nfs4xdr.c linux-3.10.33-vs2.3.6.8/fs/nfsd/nfs4xdr.c
5441 --- linux-3.10.33/fs/nfsd/nfs4xdr.c     2014-03-12 13:16:02.000000000 +0000
5442 +++ linux-3.10.33-vs2.3.6.8/fs/nfsd/nfs4xdr.c   2013-11-13 17:17:16.000000000 +0000
5443 @@ -46,6 +46,7 @@
5444  #include <linux/utsname.h>
5445  #include <linux/pagemap.h>
5446  #include <linux/sunrpc/svcauth_gss.h>
5447 +#include <linux/vs_tag.h>
5448  
5449  #include "idmap.h"
5450  #include "acl.h"
5451 @@ -2320,14 +2321,18 @@ out_acl:
5452                 WRITE32(stat.nlink);
5453         }
5454         if (bmval1 & FATTR4_WORD1_OWNER) {
5455 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
5456 +               status = nfsd4_encode_user(rqstp,
5457 +                       TAGINO_KUID(DX_TAG(dentry->d_inode),
5458 +                       stat.uid, stat.tag), &p, &buflen);
5459                 if (status == nfserr_resource)
5460                         goto out_resource;
5461                 if (status)
5462                         goto out;
5463         }
5464         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
5465 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
5466 +               status = nfsd4_encode_group(rqstp,
5467 +                       TAGINO_KGID(DX_TAG(dentry->d_inode),
5468 +                       stat.gid, stat.tag), &p, &buflen);
5469                 if (status == nfserr_resource)
5470                         goto out_resource;
5471                 if (status)
5472 diff -NurpP --minimal linux-3.10.33/fs/nfsd/nfsxdr.c linux-3.10.33-vs2.3.6.8/fs/nfsd/nfsxdr.c
5473 --- linux-3.10.33/fs/nfsd/nfsxdr.c      2013-05-31 13:45:24.000000000 +0000
5474 +++ linux-3.10.33-vs2.3.6.8/fs/nfsd/nfsxdr.c    2013-08-22 20:29:59.000000000 +0000
5475 @@ -7,6 +7,7 @@
5476  #include "vfs.h"
5477  #include "xdr.h"
5478  #include "auth.h"
5479 +#include <linux/vs_tag.h>
5480  
5481  #define NFSDDBG_FACILITY               NFSDDBG_XDR
5482  
5483 @@ -89,6 +90,8 @@ static __be32 *
5484  decode_sattr(__be32 *p, struct iattr *iap)
5485  {
5486         u32     tmp, tmp1;
5487 +       kuid_t  kuid = GLOBAL_ROOT_UID;
5488 +       kgid_t  kgid = GLOBAL_ROOT_GID;
5489  
5490         iap->ia_valid = 0;
5491  
5492 @@ -101,15 +104,18 @@ decode_sattr(__be32 *p, struct iattr *ia
5493                 iap->ia_mode = tmp;
5494         }
5495         if ((tmp = ntohl(*p++)) != (u32)-1) {
5496 -               iap->ia_uid = make_kuid(&init_user_ns, tmp);
5497 +               kuid = make_kuid(&init_user_ns, tmp);
5498                 if (uid_valid(iap->ia_uid))
5499                         iap->ia_valid |= ATTR_UID;
5500         }
5501         if ((tmp = ntohl(*p++)) != (u32)-1) {
5502 -               iap->ia_gid = make_kgid(&init_user_ns, tmp);
5503 +               kgid = make_kgid(&init_user_ns, tmp);
5504                 if (gid_valid(iap->ia_gid))
5505                         iap->ia_valid |= ATTR_GID;
5506         }
5507 +       iap->ia_uid = INOTAG_KUID(DX_TAG_NFSD, kuid, kgid);
5508 +       iap->ia_gid = INOTAG_KGID(DX_TAG_NFSD, kuid, kgid);
5509 +       iap->ia_tag = INOTAG_KTAG(DX_TAG_NFSD, kuid, kgid, GLOBAL_ROOT_TAG);
5510         if ((tmp = ntohl(*p++)) != (u32)-1) {
5511                 iap->ia_valid |= ATTR_SIZE;
5512                 iap->ia_size = tmp;
5513 @@ -154,8 +160,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
5514         *p++ = htonl(nfs_ftypes[type >> 12]);
5515         *p++ = htonl((u32) stat->mode);
5516         *p++ = htonl((u32) stat->nlink);
5517 -       *p++ = htonl((u32) from_kuid(&init_user_ns, stat->uid));
5518 -       *p++ = htonl((u32) from_kgid(&init_user_ns, stat->gid));
5519 +       *p++ = htonl((u32) from_kuid(&init_user_ns,
5520 +               TAGINO_KUID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
5521 +       *p++ = htonl((u32) from_kgid(&init_user_ns,
5522 +               TAGINO_KGID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
5523  
5524         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
5525                 *p++ = htonl(NFS_MAXPATHLEN);
5526 diff -NurpP --minimal linux-3.10.33/fs/ocfs2/dlmglue.c linux-3.10.33-vs2.3.6.8/fs/ocfs2/dlmglue.c
5527 --- linux-3.10.33/fs/ocfs2/dlmglue.c    2013-07-14 17:01:29.000000000 +0000
5528 +++ linux-3.10.33-vs2.3.6.8/fs/ocfs2/dlmglue.c  2013-08-22 20:29:59.000000000 +0000
5529 @@ -2047,6 +2047,7 @@ static void __ocfs2_stuff_meta_lvb(struc
5530         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
5531         lvb->lvb_iuid      = cpu_to_be32(i_uid_read(inode));
5532         lvb->lvb_igid      = cpu_to_be32(i_gid_read(inode));
5533 +       lvb->lvb_itag      = cpu_to_be16(i_tag_read(inode));
5534         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
5535         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
5536         lvb->lvb_iatime_packed  =
5537 @@ -2097,6 +2098,7 @@ static void ocfs2_refresh_inode_from_lvb
5538  
5539         i_uid_write(inode, be32_to_cpu(lvb->lvb_iuid));
5540         i_gid_write(inode, be32_to_cpu(lvb->lvb_igid));
5541 +       i_tag_write(inode, be16_to_cpu(lvb->lvb_itag));
5542         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
5543         set_nlink(inode, be16_to_cpu(lvb->lvb_inlink));
5544         ocfs2_unpack_timespec(&inode->i_atime,
5545 diff -NurpP --minimal linux-3.10.33/fs/ocfs2/dlmglue.h linux-3.10.33-vs2.3.6.8/fs/ocfs2/dlmglue.h
5546 --- linux-3.10.33/fs/ocfs2/dlmglue.h    2012-12-11 03:30:57.000000000 +0000
5547 +++ linux-3.10.33-vs2.3.6.8/fs/ocfs2/dlmglue.h  2013-08-22 20:29:59.000000000 +0000
5548 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
5549         __be16       lvb_inlink;
5550         __be32       lvb_iattr;
5551         __be32       lvb_igeneration;
5552 -       __be32       lvb_reserved2;
5553 +       __be16       lvb_itag;
5554 +       __be16       lvb_reserved2;
5555  };
5556  
5557  #define OCFS2_QINFO_LVB_VERSION 1
5558 diff -NurpP --minimal linux-3.10.33/fs/ocfs2/file.c linux-3.10.33-vs2.3.6.8/fs/ocfs2/file.c
5559 --- linux-3.10.33/fs/ocfs2/file.c       2013-07-14 17:01:29.000000000 +0000
5560 +++ linux-3.10.33-vs2.3.6.8/fs/ocfs2/file.c     2013-08-22 20:29:59.000000000 +0000
5561 @@ -1124,7 +1124,7 @@ int ocfs2_setattr(struct dentry *dentry,
5562                 attr->ia_valid &= ~ATTR_SIZE;
5563  
5564  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
5565 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
5566 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
5567         if (!(attr->ia_valid & OCFS2_VALID_ATTRS))
5568                 return 0;
5569  
5570 diff -NurpP --minimal linux-3.10.33/fs/ocfs2/inode.c linux-3.10.33-vs2.3.6.8/fs/ocfs2/inode.c
5571 --- linux-3.10.33/fs/ocfs2/inode.c      2013-05-31 13:45:24.000000000 +0000
5572 +++ linux-3.10.33-vs2.3.6.8/fs/ocfs2/inode.c    2013-08-22 20:29:59.000000000 +0000
5573 @@ -28,6 +28,7 @@
5574  #include <linux/highmem.h>
5575  #include <linux/pagemap.h>
5576  #include <linux/quotaops.h>
5577 +#include <linux/vs_tag.h>
5578  
5579  #include <asm/byteorder.h>
5580  
5581 @@ -78,11 +79,13 @@ void ocfs2_set_inode_flags(struct inode
5582  {
5583         unsigned int flags = OCFS2_I(inode)->ip_attr;
5584  
5585 -       inode->i_flags &= ~(S_IMMUTABLE |
5586 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
5587                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
5588  
5589         if (flags & OCFS2_IMMUTABLE_FL)
5590                 inode->i_flags |= S_IMMUTABLE;
5591 +       if (flags & OCFS2_IXUNLINK_FL)
5592 +               inode->i_flags |= S_IXUNLINK;
5593  
5594         if (flags & OCFS2_SYNC_FL)
5595                 inode->i_flags |= S_SYNC;
5596 @@ -92,25 +95,44 @@ void ocfs2_set_inode_flags(struct inode
5597                 inode->i_flags |= S_NOATIME;
5598         if (flags & OCFS2_DIRSYNC_FL)
5599                 inode->i_flags |= S_DIRSYNC;
5600 +
5601 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
5602 +
5603 +       if (flags & OCFS2_BARRIER_FL)
5604 +               inode->i_vflags |= V_BARRIER;
5605 +       if (flags & OCFS2_COW_FL)
5606 +               inode->i_vflags |= V_COW;
5607  }
5608  
5609  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
5610  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
5611  {
5612         unsigned int flags = oi->vfs_inode.i_flags;
5613 +       unsigned int vflags = oi->vfs_inode.i_vflags;
5614 +
5615 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
5616 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
5617 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
5618 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
5619 +
5620 +       if (flags & S_IMMUTABLE)
5621 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5622 +       if (flags & S_IXUNLINK)
5623 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
5624  
5625 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
5626 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
5627         if (flags & S_SYNC)
5628                 oi->ip_attr |= OCFS2_SYNC_FL;
5629         if (flags & S_APPEND)
5630                 oi->ip_attr |= OCFS2_APPEND_FL;
5631 -       if (flags & S_IMMUTABLE)
5632 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5633         if (flags & S_NOATIME)
5634                 oi->ip_attr |= OCFS2_NOATIME_FL;
5635         if (flags & S_DIRSYNC)
5636                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
5637 +
5638 +       if (vflags & V_BARRIER)
5639 +               oi->ip_attr |= OCFS2_BARRIER_FL;
5640 +       if (vflags & V_COW)
5641 +               oi->ip_attr |= OCFS2_COW_FL;
5642  }
5643  
5644  struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
5645 @@ -241,6 +263,8 @@ void ocfs2_populate_inode(struct inode *
5646         struct super_block *sb;
5647         struct ocfs2_super *osb;
5648         int use_plocks = 1;
5649 +       uid_t uid;
5650 +       gid_t gid;
5651  
5652         sb = inode->i_sb;
5653         osb = OCFS2_SB(sb);
5654 @@ -269,8 +293,12 @@ void ocfs2_populate_inode(struct inode *
5655         inode->i_generation = le32_to_cpu(fe->i_generation);
5656         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
5657         inode->i_mode = le16_to_cpu(fe->i_mode);
5658 -       i_uid_write(inode, le32_to_cpu(fe->i_uid));
5659 -       i_gid_write(inode, le32_to_cpu(fe->i_gid));
5660 +       uid = le32_to_cpu(fe->i_uid);
5661 +       gid = le32_to_cpu(fe->i_gid);
5662 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), uid, gid));
5663 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), uid, gid));
5664 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), uid, gid,
5665 +               /* le16_to_cpu(raw_inode->i_raw_tag) */ 0));
5666  
5667         /* Fast symlinks will have i_size but no allocated clusters. */
5668         if (S_ISLNK(inode->i_mode) && !fe->i_clusters) {
5669 diff -NurpP --minimal linux-3.10.33/fs/ocfs2/inode.h linux-3.10.33-vs2.3.6.8/fs/ocfs2/inode.h
5670 --- linux-3.10.33/fs/ocfs2/inode.h      2013-07-14 17:01:29.000000000 +0000
5671 +++ linux-3.10.33-vs2.3.6.8/fs/ocfs2/inode.h    2013-08-22 20:29:59.000000000 +0000
5672 @@ -152,6 +152,7 @@ struct buffer_head *ocfs2_bread(struct i
5673  
5674  void ocfs2_set_inode_flags(struct inode *inode);
5675  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
5676 +int ocfs2_sync_flags(struct inode *inode, int, int);
5677  
5678  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
5679  {
5680 diff -NurpP --minimal linux-3.10.33/fs/ocfs2/ioctl.c linux-3.10.33-vs2.3.6.8/fs/ocfs2/ioctl.c
5681 --- linux-3.10.33/fs/ocfs2/ioctl.c      2013-07-14 17:01:29.000000000 +0000
5682 +++ linux-3.10.33-vs2.3.6.8/fs/ocfs2/ioctl.c    2013-08-22 20:29:59.000000000 +0000
5683 @@ -76,7 +76,41 @@ static int ocfs2_get_inode_attr(struct i
5684         return status;
5685  }
5686  
5687 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5688 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
5689 +{
5690 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
5691 +       struct buffer_head *bh = NULL;
5692 +       handle_t *handle = NULL;
5693 +       int status;
5694 +
5695 +       status = ocfs2_inode_lock(inode, &bh, 1);
5696 +       if (status < 0) {
5697 +               mlog_errno(status);
5698 +               return status;
5699 +       }
5700 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5701 +       if (IS_ERR(handle)) {
5702 +               status = PTR_ERR(handle);
5703 +               mlog_errno(status);
5704 +               goto bail_unlock;
5705 +       }
5706 +
5707 +       inode->i_flags = flags;
5708 +       inode->i_vflags = vflags;
5709 +       ocfs2_get_inode_flags(OCFS2_I(inode));
5710 +
5711 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
5712 +       if (status < 0)
5713 +               mlog_errno(status);
5714 +
5715 +       ocfs2_commit_trans(osb, handle);
5716 +bail_unlock:
5717 +       ocfs2_inode_unlock(inode, 1);
5718 +       brelse(bh);
5719 +       return status;
5720 +}
5721 +
5722 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5723                                 unsigned mask)
5724  {
5725         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
5726 @@ -116,6 +150,11 @@ static int ocfs2_set_inode_attr(struct i
5727                         goto bail_unlock;
5728         }
5729  
5730 +       if (IS_BARRIER(inode)) {
5731 +               vxwprintk_task(1, "messing with the barrier.");
5732 +               goto bail_unlock;
5733 +       }
5734 +
5735         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5736         if (IS_ERR(handle)) {
5737                 status = PTR_ERR(handle);
5738 @@ -881,6 +920,7 @@ bail:
5739         return status;
5740  }
5741  
5742 +
5743  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
5744  {
5745         struct inode *inode = file_inode(filp);
5746 diff -NurpP --minimal linux-3.10.33/fs/ocfs2/namei.c linux-3.10.33-vs2.3.6.8/fs/ocfs2/namei.c
5747 --- linux-3.10.33/fs/ocfs2/namei.c      2013-07-14 17:01:29.000000000 +0000
5748 +++ linux-3.10.33-vs2.3.6.8/fs/ocfs2/namei.c    2013-08-22 20:29:59.000000000 +0000
5749 @@ -41,6 +41,7 @@
5750  #include <linux/slab.h>
5751  #include <linux/highmem.h>
5752  #include <linux/quotaops.h>
5753 +#include <linux/vs_tag.h>
5754  
5755  #include <cluster/masklog.h>
5756  
5757 @@ -475,6 +476,7 @@ static int __ocfs2_mknod_locked(struct i
5758         struct ocfs2_dinode *fe = NULL;
5759         struct ocfs2_extent_list *fel;
5760         u16 feat;
5761 +       ktag_t ktag;
5762  
5763         *new_fe_bh = NULL;
5764  
5765 @@ -512,8 +514,13 @@ static int __ocfs2_mknod_locked(struct i
5766         fe->i_suballoc_loc = cpu_to_le64(suballoc_loc);
5767         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
5768         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
5769 -       fe->i_uid = cpu_to_le32(i_uid_read(inode));
5770 -       fe->i_gid = cpu_to_le32(i_gid_read(inode));
5771 +
5772 +       ktag = make_ktag(&init_user_ns, dx_current_fstag(osb->sb));
5773 +       fe->i_uid = cpu_to_le32(from_kuid(&init_user_ns,
5774 +               TAGINO_KUID(DX_TAG(inode), inode->i_uid, ktag)));
5775 +       fe->i_gid = cpu_to_le32(from_kgid(&init_user_ns,
5776 +               TAGINO_KGID(DX_TAG(inode), inode->i_gid, ktag)));
5777 +       inode->i_tag = ktag; /* is this correct? */
5778         fe->i_mode = cpu_to_le16(inode->i_mode);
5779         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
5780                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
5781 diff -NurpP --minimal linux-3.10.33/fs/ocfs2/ocfs2.h linux-3.10.33-vs2.3.6.8/fs/ocfs2/ocfs2.h
5782 --- linux-3.10.33/fs/ocfs2/ocfs2.h      2012-12-11 03:30:57.000000000 +0000
5783 +++ linux-3.10.33-vs2.3.6.8/fs/ocfs2/ocfs2.h    2013-08-22 20:29:59.000000000 +0000
5784 @@ -272,6 +272,7 @@ enum ocfs2_mount_options
5785                                                      writes */
5786         OCFS2_MOUNT_HB_NONE = 1 << 13, /* No heartbeat */
5787         OCFS2_MOUNT_HB_GLOBAL = 1 << 14, /* Global heartbeat */
5788 +       OCFS2_MOUNT_TAGGED = 1 << 15, /* use tagging */
5789  };
5790  
5791  #define OCFS2_OSB_SOFT_RO                      0x0001
5792 diff -NurpP --minimal linux-3.10.33/fs/ocfs2/ocfs2_fs.h linux-3.10.33-vs2.3.6.8/fs/ocfs2/ocfs2_fs.h
5793 --- linux-3.10.33/fs/ocfs2/ocfs2_fs.h   2012-12-11 03:30:57.000000000 +0000
5794 +++ linux-3.10.33-vs2.3.6.8/fs/ocfs2/ocfs2_fs.h 2013-08-22 20:29:59.000000000 +0000
5795 @@ -266,6 +266,11 @@
5796  #define OCFS2_TOPDIR_FL                        FS_TOPDIR_FL    /* Top of directory hierarchies*/
5797  #define OCFS2_RESERVED_FL              FS_RESERVED_FL  /* reserved for ext2 lib */
5798  
5799 +#define OCFS2_IXUNLINK_FL              FS_IXUNLINK_FL  /* Immutable invert on unlink */
5800 +
5801 +#define OCFS2_BARRIER_FL               FS_BARRIER_FL   /* Barrier for chroot() */
5802 +#define OCFS2_COW_FL                   FS_COW_FL       /* Copy on Write marker */
5803 +
5804  #define OCFS2_FL_VISIBLE               FS_FL_USER_VISIBLE      /* User visible flags */
5805  #define OCFS2_FL_MODIFIABLE            FS_FL_USER_MODIFIABLE   /* User modifiable flags */
5806  
5807 diff -NurpP --minimal linux-3.10.33/fs/ocfs2/super.c linux-3.10.33-vs2.3.6.8/fs/ocfs2/super.c
5808 --- linux-3.10.33/fs/ocfs2/super.c      2013-05-31 13:45:25.000000000 +0000
5809 +++ linux-3.10.33-vs2.3.6.8/fs/ocfs2/super.c    2013-08-22 20:29:59.000000000 +0000
5810 @@ -185,6 +185,7 @@ enum {
5811         Opt_coherency_full,
5812         Opt_resv_level,
5813         Opt_dir_resv_level,
5814 +       Opt_tag, Opt_notag, Opt_tagid,
5815         Opt_err,
5816  };
5817  
5818 @@ -216,6 +217,9 @@ static const match_table_t tokens = {
5819         {Opt_coherency_full, "coherency=full"},
5820         {Opt_resv_level, "resv_level=%u"},
5821         {Opt_dir_resv_level, "dir_resv_level=%u"},
5822 +       {Opt_tag, "tag"},
5823 +       {Opt_notag, "notag"},
5824 +       {Opt_tagid, "tagid=%u"},
5825         {Opt_err, NULL}
5826  };
5827  
5828 @@ -662,6 +666,13 @@ static int ocfs2_remount(struct super_bl
5829                 goto out;
5830         }
5831  
5832 +       if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
5833 +           (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
5834 +               ret = -EINVAL;
5835 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
5836 +               goto out;
5837 +       }
5838 +
5839         /* We're going to/from readonly mode. */
5840         if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
5841                 /* Disable quota accounting before remounting RO */
5842 @@ -1177,6 +1188,9 @@ static int ocfs2_fill_super(struct super
5843  
5844         ocfs2_complete_mount_recovery(osb);
5845  
5846 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
5847 +               sb->s_flags |= MS_TAGGED;
5848 +
5849         if (ocfs2_mount_local(osb))
5850                 snprintf(nodestr, sizeof(nodestr), "local");
5851         else
5852 @@ -1504,6 +1518,20 @@ static int ocfs2_parse_options(struct su
5853                             option < OCFS2_MAX_RESV_LEVEL)
5854                                 mopt->dir_resv_level = option;
5855                         break;
5856 +#ifndef CONFIG_TAGGING_NONE
5857 +               case Opt_tag:
5858 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5859 +                       break;
5860 +               case Opt_notag:
5861 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
5862 +                       break;
5863 +#endif
5864 +#ifdef CONFIG_PROPAGATE
5865 +               case Opt_tagid:
5866 +                       /* use args[0] */
5867 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5868 +                       break;
5869 +#endif
5870                 default:
5871                         mlog(ML_ERROR,
5872                              "Unrecognized mount option \"%s\" "
5873 diff -NurpP --minimal linux-3.10.33/fs/open.c linux-3.10.33-vs2.3.6.8/fs/open.c
5874 --- linux-3.10.33/fs/open.c     2013-07-14 17:01:29.000000000 +0000
5875 +++ linux-3.10.33-vs2.3.6.8/fs/open.c   2013-08-22 20:29:59.000000000 +0000
5876 @@ -31,6 +31,11 @@
5877  #include <linux/ima.h>
5878  #include <linux/dnotify.h>
5879  #include <linux/compat.h>
5880 +#include <linux/vs_base.h>
5881 +#include <linux/vs_limit.h>
5882 +#include <linux/vs_tag.h>
5883 +#include <linux/vs_cowbl.h>
5884 +#include <linux/vserver/dlimit.h>
5885  
5886  #include "internal.h"
5887  
5888 @@ -67,6 +72,11 @@ long vfs_truncate(struct path *path, lof
5889         struct inode *inode;
5890         long error;
5891  
5892 +#ifdef CONFIG_VSERVER_COWBL
5893 +       error = cow_check_and_break(path);
5894 +       if (error)
5895 +               goto out;
5896 +#endif
5897         inode = path->dentry->d_inode;
5898  
5899         /* For directories it's -EISDIR, for other non-regulars - -EINVAL */
5900 @@ -504,6 +514,13 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
5901         unsigned int lookup_flags = LOOKUP_FOLLOW;
5902  retry:
5903         error = user_path_at(dfd, filename, lookup_flags, &path);
5904 +#ifdef CONFIG_VSERVER_COWBL
5905 +       if (!error) {
5906 +               error = cow_check_and_break(&path);
5907 +               if (error)
5908 +                       path_put(&path);
5909 +       }
5910 +#endif
5911         if (!error) {
5912                 error = chmod_common(&path, mode);
5913                 path_put(&path);
5914 @@ -536,13 +553,15 @@ static int chown_common(struct path *pat
5915                 if (!uid_valid(uid))
5916                         return -EINVAL;
5917                 newattrs.ia_valid |= ATTR_UID;
5918 -               newattrs.ia_uid = uid;
5919 +               newattrs.ia_uid = make_kuid(&init_user_ns,
5920 +                       dx_map_uid(user));
5921         }
5922         if (group != (gid_t) -1) {
5923                 if (!gid_valid(gid))
5924                         return -EINVAL;
5925                 newattrs.ia_valid |= ATTR_GID;
5926 -               newattrs.ia_gid = gid;
5927 +               newattrs.ia_gid = make_kgid(&init_user_ns,
5928 +                       dx_map_gid(group));
5929         }
5930         if (!S_ISDIR(inode->i_mode))
5931                 newattrs.ia_valid |=
5932 @@ -576,6 +595,18 @@ retry:
5933         error = mnt_want_write(path.mnt);
5934         if (error)
5935                 goto out_release;
5936 +#ifdef CONFIG_VSERVER_COWBL
5937 +       error = cow_check_and_break(&path);
5938 +       if (!error)
5939 +#endif
5940 +#ifdef CONFIG_VSERVER_COWBL
5941 +       error = cow_check_and_break(&path);
5942 +       if (!error)
5943 +#endif
5944 +#ifdef CONFIG_VSERVER_COWBL
5945 +       error = cow_check_and_break(&path);
5946 +       if (!error)
5947 +#endif
5948         error = chown_common(&path, user, group);
5949         mnt_drop_write(path.mnt);
5950  out_release:
5951 diff -NurpP --minimal linux-3.10.33/fs/proc/array.c linux-3.10.33-vs2.3.6.8/fs/proc/array.c
5952 --- linux-3.10.33/fs/proc/array.c       2013-05-31 13:45:25.000000000 +0000
5953 +++ linux-3.10.33-vs2.3.6.8/fs/proc/array.c     2013-08-22 20:29:59.000000000 +0000
5954 @@ -82,6 +82,8 @@
5955  #include <linux/ptrace.h>
5956  #include <linux/tracehook.h>
5957  #include <linux/user_namespace.h>
5958 +#include <linux/vs_context.h>
5959 +#include <linux/vs_network.h>
5960  
5961  #include <asm/pgtable.h>
5962  #include <asm/processor.h>
5963 @@ -173,6 +175,9 @@ static inline void task_state(struct seq
5964         rcu_read_lock();
5965         ppid = pid_alive(p) ?
5966                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
5967 +       if (unlikely(vx_current_initpid(p->pid)))
5968 +               ppid = 0;
5969 +
5970         tpid = 0;
5971         if (pid_alive(p)) {
5972                 struct task_struct *tracer = ptrace_parent(p);
5973 @@ -297,7 +302,7 @@ static inline void task_sig(struct seq_f
5974  }
5975  
5976  static void render_cap_t(struct seq_file *m, const char *header,
5977 -                       kernel_cap_t *a)
5978 +                       struct vx_info *vxi, kernel_cap_t *a)
5979  {
5980         unsigned __capi;
5981  
5982 @@ -331,10 +336,11 @@ static inline void task_cap(struct seq_f
5983         NORM_CAPS(cap_effective);
5984         NORM_CAPS(cap_bset);
5985  
5986 -       render_cap_t(m, "CapInh:\t", &cap_inheritable);
5987 -       render_cap_t(m, "CapPrm:\t", &cap_permitted);
5988 -       render_cap_t(m, "CapEff:\t", &cap_effective);
5989 -       render_cap_t(m, "CapBnd:\t", &cap_bset);
5990 +       /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
5991 +       render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
5992 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
5993 +       render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
5994 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
5995  }
5996  
5997  static inline void task_seccomp(struct seq_file *m, struct task_struct *p)
5998 @@ -363,6 +369,42 @@ static void task_cpus_allowed(struct seq
5999         seq_putc(m, '\n');
6000  }
6001  
6002 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6003 +                       struct pid *pid, struct task_struct *task)
6004 +{
6005 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
6006 +                       "Count:\t%u\n"
6007 +                       "uts:\t%p(%c)\n"
6008 +                       "ipc:\t%p(%c)\n"
6009 +                       "mnt:\t%p(%c)\n"
6010 +                       "pid:\t%p(%c)\n"
6011 +                       "net:\t%p(%c)\n",
6012 +                       task->nsproxy,
6013 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6014 +                       atomic_read(&task->nsproxy->count),
6015 +                       task->nsproxy->uts_ns,
6016 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6017 +                       task->nsproxy->ipc_ns,
6018 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6019 +                       task->nsproxy->mnt_ns,
6020 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6021 +                       task->nsproxy->pid_ns,
6022 +                       (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
6023 +                       task->nsproxy->net_ns,
6024 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6025 +       return 0;
6026 +}
6027 +
6028 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6029 +{
6030 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6031 +               return;
6032 +
6033 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6034 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6035 +}
6036 +
6037 +
6038  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6039                         struct pid *pid, struct task_struct *task)
6040  {
6041 @@ -380,6 +422,7 @@ int proc_pid_status(struct seq_file *m,
6042         task_seccomp(m, task);
6043         task_cpus_allowed(m, task);
6044         cpuset_task_status_allowed(m, task);
6045 +       task_vs_id(m, task);
6046         task_context_switch_counts(m, task);
6047         return 0;
6048  }
6049 @@ -489,6 +532,17 @@ static int do_task_stat(struct seq_file
6050         /* convert nsec -> ticks */
6051         start_time = nsec_to_clock_t(start_time);
6052  
6053 +       /* fixup start time for virt uptime */
6054 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6055 +               unsigned long long bias =
6056 +                       current->vx_info->cvirt.bias_clock;
6057 +
6058 +               if (start_time > bias)
6059 +                       start_time -= bias;
6060 +               else
6061 +                       start_time = 0;
6062 +       }
6063 +
6064         seq_printf(m, "%d (%s) %c", pid_nr_ns(pid, ns), tcomm, state);
6065         seq_put_decimal_ll(m, ' ', ppid);
6066         seq_put_decimal_ll(m, ' ', pgid);
6067 diff -NurpP --minimal linux-3.10.33/fs/proc/base.c linux-3.10.33-vs2.3.6.8/fs/proc/base.c
6068 --- linux-3.10.33/fs/proc/base.c        2013-07-14 17:01:29.000000000 +0000
6069 +++ linux-3.10.33-vs2.3.6.8/fs/proc/base.c      2013-08-22 22:18:21.000000000 +0000
6070 @@ -87,6 +87,8 @@
6071  #include <linux/slab.h>
6072  #include <linux/flex_array.h>
6073  #include <linux/posix-timers.h>
6074 +#include <linux/vs_context.h>
6075 +#include <linux/vs_network.h>
6076  #ifdef CONFIG_HARDWALL
6077  #include <asm/hardwall.h>
6078  #endif
6079 @@ -976,11 +978,15 @@ static ssize_t oom_adj_write(struct file
6080                 oom_adj = (oom_adj * OOM_SCORE_ADJ_MAX) / -OOM_DISABLE;
6081  
6082         if (oom_adj < task->signal->oom_score_adj &&
6083 -           !capable(CAP_SYS_RESOURCE)) {
6084 +           !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
6085                 err = -EACCES;
6086                 goto err_sighand;
6087         }
6088  
6089 +       /* prevent guest processes from circumventing the oom killer */
6090 +       if (vx_current_xid() && (oom_adj == OOM_DISABLE))
6091 +               oom_adj = OOM_ADJUST_MIN;
6092 +
6093         /*
6094          * /proc/pid/oom_adj is provided for legacy purposes, ask users to use
6095          * /proc/pid/oom_score_adj instead.
6096 @@ -1559,6 +1565,8 @@ struct inode *proc_pid_make_inode(struct
6097                 inode->i_gid = cred->egid;
6098                 rcu_read_unlock();
6099         }
6100 +       /* procfs is xid tagged */
6101 +       i_tag_write(inode, (vtag_t)vx_task_xid(task));
6102         security_task_to_inode(task, inode);
6103  
6104  out:
6105 @@ -1604,6 +1612,8 @@ int pid_getattr(struct vfsmount *mnt, st
6106  
6107  /* dentry stuff */
6108  
6109 +static unsigned name_to_int(struct dentry *dentry);
6110 +
6111  /*
6112   *     Exceptional case: normally we are not allowed to unhash a busy
6113   * directory. In this case, however, we can do it - no aliasing problems
6114 @@ -1632,6 +1642,12 @@ int pid_revalidate(struct dentry *dentry
6115         task = get_proc_task(inode);
6116  
6117         if (task) {
6118 +               unsigned pid = name_to_int(dentry);
6119 +
6120 +               if (pid != ~0U && pid != vx_map_pid(task->pid)) {
6121 +                       put_task_struct(task);
6122 +                       goto drop;
6123 +               }
6124                 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
6125                     task_dumpable(task)) {
6126                         rcu_read_lock();
6127 @@ -1648,6 +1664,7 @@ int pid_revalidate(struct dentry *dentry
6128                 put_task_struct(task);
6129                 return 1;
6130         }
6131 +drop:
6132         d_drop(dentry);
6133         return 0;
6134  }
6135 @@ -2196,6 +2213,13 @@ static struct dentry *proc_pident_lookup
6136         if (!task)
6137                 goto out_no_task;
6138  
6139 +       /* TODO: maybe we can come up with a generic approach? */
6140 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
6141 +               (dentry->d_name.len == 5) &&
6142 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
6143 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
6144 +               goto out;
6145 +
6146         /*
6147          * Yes, it does not scale. And it should not. Don't add
6148          * new entries into /proc/<tgid>/ without very good reasons.
6149 @@ -2630,6 +2654,9 @@ static int proc_pid_personality(struct s
6150  static const struct file_operations proc_task_operations;
6151  static const struct inode_operations proc_task_inode_operations;
6152  
6153 +extern int proc_pid_vx_info(struct task_struct *, char *);
6154 +extern int proc_pid_nx_info(struct task_struct *, char *);
6155 +
6156  static const struct pid_entry tgid_base_stuff[] = {
6157         DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
6158         DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
6159 @@ -2696,6 +2723,8 @@ static const struct pid_entry tgid_base_
6160  #ifdef CONFIG_CGROUPS
6161         REG("cgroup",  S_IRUGO, proc_cgroup_operations),
6162  #endif
6163 +       INF("vinfo",      S_IRUGO, proc_pid_vx_info),
6164 +       INF("ninfo",      S_IRUGO, proc_pid_nx_info),
6165         INF("oom_score",  S_IRUGO, proc_oom_score),
6166         REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adj_operations),
6167         REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations),
6168 @@ -2910,7 +2939,7 @@ retry:
6169         iter.task = NULL;
6170         pid = find_ge_pid(iter.tgid, ns);
6171         if (pid) {
6172 -               iter.tgid = pid_nr_ns(pid, ns);
6173 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
6174                 iter.task = pid_task(pid, PIDTYPE_PID);
6175                 /* What we to know is if the pid we have find is the
6176                  * pid of a thread_group_leader.  Testing for task
6177 @@ -2940,7 +2969,7 @@ static int proc_pid_fill_cache(struct fi
6178         struct tgid_iter iter)
6179  {
6180         char name[PROC_NUMBUF];
6181 -       int len = snprintf(name, sizeof(name), "%d", iter.tgid);
6182 +       int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
6183         return proc_fill_cache(filp, dirent, filldir, name, len,
6184                                 proc_pid_instantiate, iter.task, NULL);
6185  }
6186 @@ -2981,6 +3010,8 @@ int proc_pid_readdir(struct file * filp,
6187                         __filldir = fake_filldir;
6188  
6189                 filp->f_pos = iter.tgid + TGID_OFFSET;
6190 +               if (!vx_proc_task_visible(iter.task))
6191 +                       continue;
6192                 if (proc_pid_fill_cache(filp, dirent, __filldir, iter) < 0) {
6193                         put_task_struct(iter.task);
6194                         goto out;
6195 @@ -3073,6 +3104,7 @@ static const struct pid_entry tid_base_s
6196         REG("gid_map",    S_IRUGO|S_IWUSR, proc_gid_map_operations),
6197         REG("projid_map", S_IRUGO|S_IWUSR, proc_projid_map_operations),
6198  #endif
6199 +       ONE("nsproxy",  S_IRUGO, proc_pid_nsproxy),
6200  };
6201  
6202  static int proc_tid_base_readdir(struct file * filp,
6203 @@ -3141,6 +3173,8 @@ static struct dentry *proc_task_lookup(s
6204         tid = name_to_int(dentry);
6205         if (tid == ~0U)
6206                 goto out;
6207 +       if (vx_current_initpid(tid))
6208 +               goto out;
6209  
6210         ns = dentry->d_sb->s_fs_info;
6211         rcu_read_lock();
6212 diff -NurpP --minimal linux-3.10.33/fs/proc/generic.c linux-3.10.33-vs2.3.6.8/fs/proc/generic.c
6213 --- linux-3.10.33/fs/proc/generic.c     2013-07-14 17:01:29.000000000 +0000
6214 +++ linux-3.10.33-vs2.3.6.8/fs/proc/generic.c   2013-08-22 20:29:59.000000000 +0000
6215 @@ -23,6 +23,7 @@
6216  #include <linux/bitops.h>
6217  #include <linux/spinlock.h>
6218  #include <linux/completion.h>
6219 +#include <linux/vserver/inode.h>
6220  #include <asm/uaccess.h>
6221  
6222  #include "internal.h"
6223 @@ -203,6 +204,8 @@ struct dentry *proc_lookup_de(struct pro
6224         for (de = de->subdir; de ; de = de->next) {
6225                 if (de->namelen != dentry->d_name.len)
6226                         continue;
6227 +               if (!vx_hide_check(0, de->vx_flags))
6228 +                       continue;
6229                 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
6230                         pde_get(de);
6231                         spin_unlock(&proc_subdir_lock);
6232 @@ -211,6 +214,8 @@ struct dentry *proc_lookup_de(struct pro
6233                                 return ERR_PTR(-ENOMEM);
6234                         d_set_d_op(dentry, &proc_dentry_operations);
6235                         d_add(dentry, inode);
6236 +                       /* generic proc entries belong to the host */
6237 +                       i_tag_write(inode, 0);
6238                         return NULL;
6239                 }
6240         }
6241 @@ -279,6 +284,8 @@ int proc_readdir_de(struct proc_dir_entr
6242  
6243                                 /* filldir passes info to user space */
6244                                 pde_get(de);
6245 +                               if (!vx_hide_check(0, de->vx_flags))
6246 +                                       goto skip;
6247                                 spin_unlock(&proc_subdir_lock);
6248                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
6249                                             de->low_ino, de->mode >> 12) < 0) {
6250 @@ -286,6 +293,7 @@ int proc_readdir_de(struct proc_dir_entr
6251                                         goto out;
6252                                 }
6253                                 spin_lock(&proc_subdir_lock);
6254 +                       skip:
6255                                 filp->f_pos++;
6256                                 next = de->next;
6257                                 pde_put(de);
6258 @@ -395,6 +403,7 @@ static struct proc_dir_entry *__proc_cre
6259         ent->namelen = len;
6260         ent->mode = mode;
6261         ent->nlink = nlink;
6262 +       ent->vx_flags = IATTR_PROC_DEFAULT;
6263         atomic_set(&ent->count, 1);
6264         spin_lock_init(&ent->pde_unload_lock);
6265         INIT_LIST_HEAD(&ent->pde_openers);
6266 @@ -418,7 +427,8 @@ struct proc_dir_entry *proc_symlink(cons
6267                                 kfree(ent->data);
6268                                 kfree(ent);
6269                                 ent = NULL;
6270 -                       }
6271 +                       } else
6272 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
6273                 } else {
6274                         kfree(ent);
6275                         ent = NULL;
6276 diff -NurpP --minimal linux-3.10.33/fs/proc/inode.c linux-3.10.33-vs2.3.6.8/fs/proc/inode.c
6277 --- linux-3.10.33/fs/proc/inode.c       2013-07-14 17:01:29.000000000 +0000
6278 +++ linux-3.10.33-vs2.3.6.8/fs/proc/inode.c     2013-08-22 20:29:59.000000000 +0000
6279 @@ -387,6 +387,8 @@ struct inode *proc_get_inode(struct supe
6280                         inode->i_uid = de->uid;
6281                         inode->i_gid = de->gid;
6282                 }
6283 +               if (de->vx_flags)
6284 +                       PROC_I(inode)->vx_flags = de->vx_flags;
6285                 if (de->size)
6286                         inode->i_size = de->size;
6287                 if (de->nlink)
6288 diff -NurpP --minimal linux-3.10.33/fs/proc/internal.h linux-3.10.33-vs2.3.6.8/fs/proc/internal.h
6289 --- linux-3.10.33/fs/proc/internal.h    2013-07-14 17:01:29.000000000 +0000
6290 +++ linux-3.10.33-vs2.3.6.8/fs/proc/internal.h  2013-08-22 21:52:30.000000000 +0000
6291 @@ -14,6 +14,7 @@
6292  #include <linux/spinlock.h>
6293  #include <linux/atomic.h>
6294  #include <linux/binfmts.h>
6295 +#include <linux/vs_pid.h>
6296  
6297  struct ctl_table_header;
6298  struct mempolicy;
6299 @@ -35,6 +36,7 @@ struct proc_dir_entry {
6300         nlink_t nlink;
6301         kuid_t uid;
6302         kgid_t gid;
6303 +       int vx_flags;
6304         loff_t size;
6305         const struct inode_operations *proc_iops;
6306         const struct file_operations *proc_fops;
6307 @@ -50,16 +52,23 @@ struct proc_dir_entry {
6308         char name[];
6309  };
6310  
6311 +struct vx_info;
6312 +struct nx_info;
6313 +
6314  union proc_op {
6315         int (*proc_get_link)(struct dentry *, struct path *);
6316         int (*proc_read)(struct task_struct *task, char *page);
6317         int (*proc_show)(struct seq_file *m,
6318                 struct pid_namespace *ns, struct pid *pid,
6319                 struct task_struct *task);
6320 +       int (*proc_vs_read)(char *page);
6321 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
6322 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
6323  };
6324  
6325  struct proc_inode {
6326         struct pid *pid;
6327 +       int vx_flags;
6328         int fd;
6329         union proc_op op;
6330         struct proc_dir_entry *pde;
6331 @@ -92,11 +101,16 @@ static inline struct pid *proc_pid(struc
6332         return PROC_I(inode)->pid;
6333  }
6334  
6335 -static inline struct task_struct *get_proc_task(struct inode *inode)
6336 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
6337  {
6338         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
6339  }
6340  
6341 +static inline struct task_struct *get_proc_task(struct inode *inode)
6342 +{
6343 +       return vx_get_proc_task(inode, proc_pid(inode));
6344 +}
6345 +
6346  static inline int task_dumpable(struct task_struct *task)
6347  {
6348         int dumpable = 0;
6349 @@ -155,6 +169,8 @@ extern int proc_pid_status(struct seq_fi
6350                            struct pid *, struct task_struct *);
6351  extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
6352                           struct pid *, struct task_struct *);
6353 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6354 +                           struct pid *pid, struct task_struct *task);
6355  
6356  /*
6357   * base.c
6358 diff -NurpP --minimal linux-3.10.33/fs/proc/loadavg.c linux-3.10.33-vs2.3.6.8/fs/proc/loadavg.c
6359 --- linux-3.10.33/fs/proc/loadavg.c     2012-12-11 03:30:57.000000000 +0000
6360 +++ linux-3.10.33-vs2.3.6.8/fs/proc/loadavg.c   2013-08-22 20:30:00.000000000 +0000
6361 @@ -12,15 +12,27 @@
6362  
6363  static int loadavg_proc_show(struct seq_file *m, void *v)
6364  {
6365 +       unsigned long running;
6366 +       unsigned int threads;
6367         unsigned long avnrun[3];
6368  
6369         get_avenrun(avnrun, FIXED_1/200, 0);
6370  
6371 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
6372 +               struct vx_info *vxi = current_vx_info();
6373 +
6374 +               running = atomic_read(&vxi->cvirt.nr_running);
6375 +               threads = atomic_read(&vxi->cvirt.nr_threads);
6376 +       } else {
6377 +               running = nr_running();
6378 +               threads = nr_threads;
6379 +       }
6380 +
6381         seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
6382                 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
6383                 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
6384                 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
6385 -               nr_running(), nr_threads,
6386 +               running, threads,
6387                 task_active_pid_ns(current)->last_pid);
6388         return 0;
6389  }
6390 diff -NurpP --minimal linux-3.10.33/fs/proc/meminfo.c linux-3.10.33-vs2.3.6.8/fs/proc/meminfo.c
6391 --- linux-3.10.33/fs/proc/meminfo.c     2013-07-14 17:01:29.000000000 +0000
6392 +++ linux-3.10.33-vs2.3.6.8/fs/proc/meminfo.c   2013-08-22 20:30:00.000000000 +0000
6393 @@ -40,7 +40,8 @@ static int meminfo_proc_show(struct seq_
6394         allowed = ((totalram_pages - hugetlb_total_pages())
6395                 * sysctl_overcommit_ratio / 100) + total_swap_pages;
6396  
6397 -       cached = global_page_state(NR_FILE_PAGES) -
6398 +       cached = vx_flags(VXF_VIRT_MEM, 0) ?
6399 +               vx_vsi_cached(&i) : global_page_state(NR_FILE_PAGES) -
6400                         total_swapcache_pages() - i.bufferram;
6401         if (cached < 0)
6402                 cached = 0;
6403 diff -NurpP --minimal linux-3.10.33/fs/proc/root.c linux-3.10.33-vs2.3.6.8/fs/proc/root.c
6404 --- linux-3.10.33/fs/proc/root.c        2014-03-12 13:16:02.000000000 +0000
6405 +++ linux-3.10.33-vs2.3.6.8/fs/proc/root.c      2013-11-13 17:19:37.000000000 +0000
6406 @@ -20,9 +20,14 @@
6407  #include <linux/mount.h>
6408  #include <linux/pid_namespace.h>
6409  #include <linux/parser.h>
6410 +#include <linux/vserver/inode.h>
6411  
6412  #include "internal.h"
6413  
6414 +struct proc_dir_entry *proc_virtual;
6415 +
6416 +extern void proc_vx_init(void);
6417 +
6418  static int proc_test_super(struct super_block *sb, void *data)
6419  {
6420         return sb->s_fs_info == data;
6421 @@ -111,7 +116,8 @@ static struct dentry *proc_mount(struct
6422                 options = data;
6423  
6424                 if (!current_user_ns()->may_mount_proc ||
6425 -                   !ns_capable(ns->user_ns, CAP_SYS_ADMIN))
6426 +                   !vx_ns_capable(ns->user_ns,
6427 +                       CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
6428                         return ERR_PTR(-EPERM);
6429         }
6430  
6431 @@ -185,6 +191,7 @@ void __init proc_root_init(void)
6432  #endif
6433         proc_mkdir("bus", NULL);
6434         proc_sys_init();
6435 +       proc_vx_init();
6436  }
6437  
6438  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
6439 @@ -251,6 +258,7 @@ struct proc_dir_entry proc_root = {
6440         .proc_iops      = &proc_root_inode_operations, 
6441         .proc_fops      = &proc_root_operations,
6442         .parent         = &proc_root,
6443 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
6444         .name           = "/proc",
6445  };
6446  
6447 diff -NurpP --minimal linux-3.10.33/fs/proc/self.c linux-3.10.33-vs2.3.6.8/fs/proc/self.c
6448 --- linux-3.10.33/fs/proc/self.c        2013-07-14 17:01:29.000000000 +0000
6449 +++ linux-3.10.33-vs2.3.6.8/fs/proc/self.c      2013-08-23 00:07:45.000000000 +0000
6450 @@ -2,6 +2,7 @@
6451  #include <linux/namei.h>
6452  #include <linux/slab.h>
6453  #include <linux/pid_namespace.h>
6454 +#include <linux/vserver/inode.h>
6455  #include "internal.h"
6456  
6457  /*
6458 @@ -62,6 +63,8 @@ int proc_setup_self(struct super_block *
6459         self = d_alloc_name(s->s_root, "self");
6460         if (self) {
6461                 struct inode *inode = new_inode_pseudo(s);
6462 +
6463 +               // self->vx_flags = IATTR_PROC_SYMLINK;
6464                 if (inode) {
6465                         inode->i_ino = self_inum;
6466                         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
6467 diff -NurpP --minimal linux-3.10.33/fs/proc/stat.c linux-3.10.33-vs2.3.6.8/fs/proc/stat.c
6468 --- linux-3.10.33/fs/proc/stat.c        2013-07-14 17:01:29.000000000 +0000
6469 +++ linux-3.10.33-vs2.3.6.8/fs/proc/stat.c      2013-08-22 20:30:00.000000000 +0000
6470 @@ -9,8 +9,10 @@
6471  #include <linux/slab.h>
6472  #include <linux/time.h>
6473  #include <linux/irqnr.h>
6474 +#include <linux/vserver/cvirt.h>
6475  #include <asm/cputime.h>
6476  #include <linux/tick.h>
6477 +#include <linux/cpuset.h>
6478  
6479  #ifndef arch_irq_stat_cpu
6480  #define arch_irq_stat_cpu(cpu) 0
6481 @@ -87,14 +89,26 @@ static int show_stat(struct seq_file *p,
6482         u64 sum_softirq = 0;
6483         unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
6484         struct timespec boottime;
6485 +       cpumask_var_t cpus_allowed;
6486 +       bool virt_cpu = vx_flags(VXF_VIRT_CPU, 0);
6487  
6488         user = nice = system = idle = iowait =
6489                 irq = softirq = steal = 0;
6490         guest = guest_nice = 0;
6491         getboottime(&boottime);
6492 +
6493 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6494 +               vx_vsi_boottime(&boottime);
6495 +
6496 +       if (virt_cpu)
6497 +               cpuset_cpus_allowed(current, cpus_allowed);
6498 +
6499         jif = boottime.tv_sec;
6500  
6501         for_each_possible_cpu(i) {
6502 +               if (virt_cpu && !cpumask_test_cpu(i, cpus_allowed))
6503 +                       continue;
6504 +
6505                 user += kcpustat_cpu(i).cpustat[CPUTIME_USER];
6506                 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
6507                 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
6508 @@ -131,6 +145,9 @@ static int show_stat(struct seq_file *p,
6509         seq_putc(p, '\n');
6510  
6511         for_each_online_cpu(i) {
6512 +               if (virt_cpu && !cpumask_test_cpu(i, cpus_allowed))
6513 +                       continue;
6514 +
6515                 /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
6516                 user = kcpustat_cpu(i).cpustat[CPUTIME_USER];
6517                 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
6518 diff -NurpP --minimal linux-3.10.33/fs/proc/uptime.c linux-3.10.33-vs2.3.6.8/fs/proc/uptime.c
6519 --- linux-3.10.33/fs/proc/uptime.c      2012-12-11 03:30:57.000000000 +0000
6520 +++ linux-3.10.33-vs2.3.6.8/fs/proc/uptime.c    2013-08-22 20:30:00.000000000 +0000
6521 @@ -5,6 +5,7 @@
6522  #include <linux/seq_file.h>
6523  #include <linux/time.h>
6524  #include <linux/kernel_stat.h>
6525 +#include <linux/vserver/cvirt.h>
6526  #include <asm/cputime.h>
6527  
6528  static int uptime_proc_show(struct seq_file *m, void *v)
6529 @@ -25,6 +26,10 @@ static int uptime_proc_show(struct seq_f
6530         nsec = cputime64_to_jiffies64(idletime) * TICK_NSEC;
6531         idle.tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem);
6532         idle.tv_nsec = rem;
6533 +
6534 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6535 +               vx_vsi_uptime(&uptime, &idle);
6536 +
6537         seq_printf(m, "%lu.%02lu %lu.%02lu\n",
6538                         (unsigned long) uptime.tv_sec,
6539                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
6540 diff -NurpP --minimal linux-3.10.33/fs/proc_namespace.c linux-3.10.33-vs2.3.6.8/fs/proc_namespace.c
6541 --- linux-3.10.33/fs/proc_namespace.c   2012-12-11 03:30:57.000000000 +0000
6542 +++ linux-3.10.33-vs2.3.6.8/fs/proc_namespace.c 2013-08-22 20:30:00.000000000 +0000
6543 @@ -44,6 +44,8 @@ static int show_sb_opts(struct seq_file
6544                 { MS_SYNCHRONOUS, ",sync" },
6545                 { MS_DIRSYNC, ",dirsync" },
6546                 { MS_MANDLOCK, ",mand" },
6547 +               { MS_TAGGED, ",tag" },
6548 +               { MS_NOTAGCHECK, ",notagcheck" },
6549                 { 0, NULL }
6550         };
6551         const struct proc_fs_info *fs_infop;
6552 @@ -80,6 +82,40 @@ static inline void mangle(struct seq_fil
6553         seq_escape(m, s, " \t\n\\");
6554  }
6555  
6556 +#ifdef CONFIG_VSERVER_EXTRA_MNT_CHECK
6557 +
6558 +static int mnt_is_reachable(struct vfsmount *vfsmnt)
6559 +{
6560 +       struct path root;
6561 +       struct dentry *point;
6562 +       struct mount *mnt = real_mount(vfsmnt);
6563 +       struct mount *root_mnt;
6564 +       int ret;
6565 +
6566 +       if (mnt == mnt->mnt_ns->root)
6567 +               return 1;
6568 +
6569 +       br_read_lock(&vfsmount_lock);
6570 +       root = current->fs->root;
6571 +       root_mnt = real_mount(root.mnt);
6572 +       point = root.dentry;
6573 +
6574 +       while ((mnt != mnt->mnt_parent) && (mnt != root_mnt)) {
6575 +               point = mnt->mnt_mountpoint;
6576 +               mnt = mnt->mnt_parent;
6577 +       }
6578 +
6579 +       ret = (mnt == root_mnt) && is_subdir(point, root.dentry);
6580 +
6581 +       br_read_unlock(&vfsmount_lock);
6582 +
6583 +       return ret;
6584 +}
6585 +
6586 +#else
6587 +#define        mnt_is_reachable(v)     (1)
6588 +#endif
6589 +
6590  static void show_type(struct seq_file *m, struct super_block *sb)
6591  {
6592         mangle(m, sb->s_type->name);
6593 @@ -96,6 +132,17 @@ static int show_vfsmnt(struct seq_file *
6594         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
6595         struct super_block *sb = mnt_path.dentry->d_sb;
6596  
6597 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6598 +               return SEQ_SKIP;
6599 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6600 +               return SEQ_SKIP;
6601 +
6602 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6603 +               mnt == current->fs->root.mnt) {
6604 +               seq_puts(m, "/dev/root / ");
6605 +               goto type;
6606 +       }
6607 +
6608         if (sb->s_op->show_devname) {
6609                 err = sb->s_op->show_devname(m, mnt_path.dentry);
6610                 if (err)
6611 @@ -106,6 +153,7 @@ static int show_vfsmnt(struct seq_file *
6612         seq_putc(m, ' ');
6613         seq_path(m, &mnt_path, " \t\n\\");
6614         seq_putc(m, ' ');
6615 +type:
6616         show_type(m, sb);
6617         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
6618         err = show_sb_opts(m, sb);
6619 @@ -128,6 +176,11 @@ static int show_mountinfo(struct seq_fil
6620         struct path root = p->root;
6621         int err = 0;
6622  
6623 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6624 +               return SEQ_SKIP;
6625 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6626 +               return SEQ_SKIP;
6627 +
6628         seq_printf(m, "%i %i %u:%u ", r->mnt_id, r->mnt_parent->mnt_id,
6629                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
6630         if (sb->s_op->show_path)
6631 @@ -187,6 +240,17 @@ static int show_vfsstat(struct seq_file
6632         struct super_block *sb = mnt_path.dentry->d_sb;
6633         int err = 0;
6634  
6635 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6636 +               return SEQ_SKIP;
6637 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6638 +               return SEQ_SKIP;
6639 +
6640 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6641 +               mnt == current->fs->root.mnt) {
6642 +               seq_puts(m, "device /dev/root mounted on / ");
6643 +               goto type;
6644 +       }
6645 +
6646         /* device */
6647         if (sb->s_op->show_devname) {
6648                 seq_puts(m, "device ");
6649 @@ -203,7 +267,7 @@ static int show_vfsstat(struct seq_file
6650         seq_puts(m, " mounted on ");
6651         seq_path(m, &mnt_path, " \t\n\\");
6652         seq_putc(m, ' ');
6653 -
6654 +type:
6655         /* file system type */
6656         seq_puts(m, "with fstype ");
6657         show_type(m, sb);
6658 diff -NurpP --minimal linux-3.10.33/fs/quota/dquot.c linux-3.10.33-vs2.3.6.8/fs/quota/dquot.c
6659 --- linux-3.10.33/fs/quota/dquot.c      2014-03-12 13:16:02.000000000 +0000
6660 +++ linux-3.10.33-vs2.3.6.8/fs/quota/dquot.c    2014-03-12 13:18:32.000000000 +0000
6661 @@ -1593,6 +1593,9 @@ int __dquot_alloc_space(struct inode *in
6662         struct dquot **dquots = inode->i_dquot;
6663         int reserve = flags & DQUOT_SPACE_RESERVE;
6664  
6665 +       if ((ret = dl_alloc_space(inode, number)))
6666 +               return ret;
6667 +
6668         /*
6669          * First test before acquiring mutex - solves deadlocks when we
6670          * re-enter the quota code and are already holding the mutex
6671 @@ -1648,6 +1651,9 @@ int dquot_alloc_inode(const struct inode
6672         struct dquot_warn warn[MAXQUOTAS];
6673         struct dquot * const *dquots = inode->i_dquot;
6674  
6675 +       if ((ret = dl_alloc_inode(inode)))
6676 +               return ret;
6677 +
6678         /* First test before acquiring mutex - solves deadlocks when we
6679           * re-enter the quota code and are already holding the mutex */
6680         if (!dquot_active(inode))
6681 @@ -1719,6 +1725,8 @@ void __dquot_free_space(struct inode *in
6682         struct dquot **dquots = inode->i_dquot;
6683         int reserve = flags & DQUOT_SPACE_RESERVE;
6684  
6685 +       dl_free_space(inode, number);
6686 +
6687         /* First test before acquiring mutex - solves deadlocks when we
6688           * re-enter the quota code and are already holding the mutex */
6689         if (!dquot_active(inode)) {
6690 @@ -1763,6 +1771,8 @@ void dquot_free_inode(const struct inode
6691         struct dquot_warn warn[MAXQUOTAS];
6692         struct dquot * const *dquots = inode->i_dquot;
6693  
6694 +       dl_free_inode(inode);
6695 +
6696         /* First test before acquiring mutex - solves deadlocks when we
6697           * re-enter the quota code and are already holding the mutex */
6698         if (!dquot_active(inode))
6699 diff -NurpP --minimal linux-3.10.33/fs/quota/quota.c linux-3.10.33-vs2.3.6.8/fs/quota/quota.c
6700 --- linux-3.10.33/fs/quota/quota.c      2013-02-19 13:58:49.000000000 +0000
6701 +++ linux-3.10.33-vs2.3.6.8/fs/quota/quota.c    2013-08-22 20:30:00.000000000 +0000
6702 @@ -8,6 +8,7 @@
6703  #include <linux/fs.h>
6704  #include <linux/namei.h>
6705  #include <linux/slab.h>
6706 +#include <linux/vs_context.h>
6707  #include <asm/current.h>
6708  #include <linux/uaccess.h>
6709  #include <linux/kernel.h>
6710 @@ -37,7 +38,7 @@ static int check_quotactl_permission(str
6711                         break;
6712                 /*FALLTHROUGH*/
6713         default:
6714 -               if (!capable(CAP_SYS_ADMIN))
6715 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
6716                         return -EPERM;
6717         }
6718  
6719 @@ -309,6 +310,46 @@ static int do_quotactl(struct super_bloc
6720  
6721  #ifdef CONFIG_BLOCK
6722  
6723 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6724 +
6725 +#include <linux/vroot.h>
6726 +#include <linux/major.h>
6727 +#include <linux/module.h>
6728 +#include <linux/kallsyms.h>
6729 +#include <linux/vserver/debug.h>
6730 +
6731 +static vroot_grb_func *vroot_get_real_bdev = NULL;
6732 +
6733 +static DEFINE_SPINLOCK(vroot_grb_lock);
6734 +
6735 +int register_vroot_grb(vroot_grb_func *func) {
6736 +       int ret = -EBUSY;
6737 +
6738 +       spin_lock(&vroot_grb_lock);
6739 +       if (!vroot_get_real_bdev) {
6740 +               vroot_get_real_bdev = func;
6741 +               ret = 0;
6742 +       }
6743 +       spin_unlock(&vroot_grb_lock);
6744 +       return ret;
6745 +}
6746 +EXPORT_SYMBOL(register_vroot_grb);
6747 +
6748 +int unregister_vroot_grb(vroot_grb_func *func) {
6749 +       int ret = -EINVAL;
6750 +
6751 +       spin_lock(&vroot_grb_lock);
6752 +       if (vroot_get_real_bdev) {
6753 +               vroot_get_real_bdev = NULL;
6754 +               ret = 0;
6755 +       }
6756 +       spin_unlock(&vroot_grb_lock);
6757 +       return ret;
6758 +}
6759 +EXPORT_SYMBOL(unregister_vroot_grb);
6760 +
6761 +#endif
6762 +
6763  /* Return 1 if 'cmd' will block on frozen filesystem */
6764  static int quotactl_cmd_write(int cmd)
6765  {
6766 @@ -343,6 +384,22 @@ static struct super_block *quotactl_bloc
6767         putname(tmp);
6768         if (IS_ERR(bdev))
6769                 return ERR_CAST(bdev);
6770 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6771 +       if (bdev && bdev->bd_inode &&
6772 +               imajor(bdev->bd_inode) == VROOT_MAJOR) {
6773 +               struct block_device *bdnew = (void *)-EINVAL;
6774 +
6775 +               if (vroot_get_real_bdev)
6776 +                       bdnew = vroot_get_real_bdev(bdev);
6777 +               else
6778 +                       vxdprintk(VXD_CBIT(misc, 0),
6779 +                                       "vroot_get_real_bdev not set");
6780 +               bdput(bdev);
6781 +               if (IS_ERR(bdnew))
6782 +                       return ERR_PTR(PTR_ERR(bdnew));
6783 +               bdev = bdnew;
6784 +       }
6785 +#endif
6786         if (quotactl_cmd_write(cmd))
6787                 sb = get_super_thawed(bdev);
6788         else
6789 diff -NurpP --minimal linux-3.10.33/fs/stat.c linux-3.10.33-vs2.3.6.8/fs/stat.c
6790 --- linux-3.10.33/fs/stat.c     2013-05-31 13:45:25.000000000 +0000
6791 +++ linux-3.10.33-vs2.3.6.8/fs/stat.c   2013-08-22 20:30:00.000000000 +0000
6792 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
6793         stat->nlink = inode->i_nlink;
6794         stat->uid = inode->i_uid;
6795         stat->gid = inode->i_gid;
6796 +       stat->tag = inode->i_tag;
6797         stat->rdev = inode->i_rdev;
6798         stat->size = i_size_read(inode);
6799         stat->atime = inode->i_atime;
6800 diff -NurpP --minimal linux-3.10.33/fs/statfs.c linux-3.10.33-vs2.3.6.8/fs/statfs.c
6801 --- linux-3.10.33/fs/statfs.c   2014-03-12 13:16:02.000000000 +0000
6802 +++ linux-3.10.33-vs2.3.6.8/fs/statfs.c 2013-11-13 17:17:16.000000000 +0000
6803 @@ -7,6 +7,8 @@
6804  #include <linux/statfs.h>
6805  #include <linux/security.h>
6806  #include <linux/uaccess.h>
6807 +#include <linux/vs_base.h>
6808 +#include <linux/vs_dlimit.h>
6809  #include "internal.h"
6810  
6811  static int flags_by_mnt(int mnt_flags)
6812 @@ -60,6 +62,8 @@ static int statfs_by_dentry(struct dentr
6813         retval = dentry->d_sb->s_op->statfs(dentry, buf);
6814         if (retval == 0 && buf->f_frsize == 0)
6815                 buf->f_frsize = buf->f_bsize;
6816 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
6817 +               vx_vsi_statfs(dentry->d_sb, buf);
6818         return retval;
6819  }
6820  
6821 diff -NurpP --minimal linux-3.10.33/fs/super.c linux-3.10.33-vs2.3.6.8/fs/super.c
6822 --- linux-3.10.33/fs/super.c    2014-03-12 13:16:02.000000000 +0000
6823 +++ linux-3.10.33-vs2.3.6.8/fs/super.c  2013-11-13 17:17:16.000000000 +0000
6824 @@ -34,6 +34,8 @@
6825  #include <linux/cleancache.h>
6826  #include <linux/fsnotify.h>
6827  #include <linux/lockdep.h>
6828 +#include <linux/magic.h>
6829 +#include <linux/vs_context.h>
6830  #include "internal.h"
6831  
6832  
6833 @@ -1112,6 +1114,13 @@ mount_fs(struct file_system_type *type,
6834         WARN_ON(sb->s_bdi == &default_backing_dev_info);
6835         sb->s_flags |= MS_BORN;
6836  
6837 +       error = -EPERM;
6838 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) &&
6839 +               !sb->s_bdev &&
6840 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
6841 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
6842 +               goto out_sb;
6843 +
6844         error = security_sb_kern_mount(sb, flags, secdata);
6845         if (error)
6846                 goto out_sb;
6847 diff -NurpP --minimal linux-3.10.33/fs/sysfs/mount.c linux-3.10.33-vs2.3.6.8/fs/sysfs/mount.c
6848 --- linux-3.10.33/fs/sysfs/mount.c      2013-05-31 13:45:25.000000000 +0000
6849 +++ linux-3.10.33-vs2.3.6.8/fs/sysfs/mount.c    2013-08-22 20:30:00.000000000 +0000
6850 @@ -48,7 +48,7 @@ static int sysfs_fill_super(struct super
6851  
6852         sb->s_blocksize = PAGE_CACHE_SIZE;
6853         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
6854 -       sb->s_magic = SYSFS_MAGIC;
6855 +       sb->s_magic = SYSFS_SUPER_MAGIC;
6856         sb->s_op = &sysfs_ops;
6857         sb->s_time_gran = 1;
6858  
6859 diff -NurpP --minimal linux-3.10.33/fs/utimes.c linux-3.10.33-vs2.3.6.8/fs/utimes.c
6860 --- linux-3.10.33/fs/utimes.c   2013-02-19 13:58:49.000000000 +0000
6861 +++ linux-3.10.33-vs2.3.6.8/fs/utimes.c 2013-08-22 20:30:00.000000000 +0000
6862 @@ -8,6 +8,8 @@
6863  #include <linux/stat.h>
6864  #include <linux/utime.h>
6865  #include <linux/syscalls.h>
6866 +#include <linux/mount.h>
6867 +#include <linux/vs_cowbl.h>
6868  #include <asm/uaccess.h>
6869  #include <asm/unistd.h>
6870  
6871 @@ -52,12 +54,18 @@ static int utimes_common(struct path *pa
6872  {
6873         int error;
6874         struct iattr newattrs;
6875 -       struct inode *inode = path->dentry->d_inode;
6876 +       struct inode *inode;
6877 +
6878 +       error = cow_check_and_break(path);
6879 +       if (error)
6880 +               goto out;
6881  
6882         error = mnt_want_write(path->mnt);
6883         if (error)
6884                 goto out;
6885  
6886 +       inode = path->dentry->d_inode;
6887 +
6888         if (times && times[0].tv_nsec == UTIME_NOW &&
6889                      times[1].tv_nsec == UTIME_NOW)
6890                 times = NULL;
6891 diff -NurpP --minimal linux-3.10.33/fs/xattr.c linux-3.10.33-vs2.3.6.8/fs/xattr.c
6892 --- linux-3.10.33/fs/xattr.c    2013-02-19 13:58:49.000000000 +0000
6893 +++ linux-3.10.33-vs2.3.6.8/fs/xattr.c  2013-08-22 20:30:00.000000000 +0000
6894 @@ -21,6 +21,7 @@
6895  #include <linux/audit.h>
6896  #include <linux/vmalloc.h>
6897  #include <linux/posix_acl_xattr.h>
6898 +#include <linux/mount.h>
6899  
6900  #include <asm/uaccess.h>
6901  
6902 @@ -52,7 +53,7 @@ xattr_permission(struct inode *inode, co
6903          * The trusted.* namespace can only be accessed by privileged users.
6904          */
6905         if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN)) {
6906 -               if (!capable(CAP_SYS_ADMIN))
6907 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_FS_TRUSTED))
6908                         return (mask & MAY_WRITE) ? -EPERM : -ENODATA;
6909                 return 0;
6910         }
6911 diff -NurpP --minimal linux-3.10.33/fs/xfs/xfs_dinode.h linux-3.10.33-vs2.3.6.8/fs/xfs/xfs_dinode.h
6912 --- linux-3.10.33/fs/xfs/xfs_dinode.h   2013-07-14 17:01:29.000000000 +0000
6913 +++ linux-3.10.33-vs2.3.6.8/fs/xfs/xfs_dinode.h 2013-08-22 20:30:00.000000000 +0000
6914 @@ -51,7 +51,9 @@ typedef struct xfs_dinode {
6915         __be32          di_nlink;       /* number of links to file */
6916         __be16          di_projid_lo;   /* lower part of owner's project id */
6917         __be16          di_projid_hi;   /* higher part owner's project id */
6918 -       __u8            di_pad[6];      /* unused, zeroed space */
6919 +       __u8            di_pad[2];      /* unused, zeroed space */
6920 +       __be16          di_tag;         /* context tagging */
6921 +       __be16          di_vflags;      /* vserver specific flags */
6922         __be16          di_flushiter;   /* incremented on flush */
6923         xfs_timestamp_t di_atime;       /* time last accessed */
6924         xfs_timestamp_t di_mtime;       /* time last modified */
6925 @@ -209,6 +211,8 @@ static inline void xfs_dinode_put_rdev(s
6926  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
6927  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
6928  #define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
6929 +#define XFS_DIFLAG_IXUNLINK_BIT     15 /* Immutable inver on unlink */
6930 +
6931  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
6932  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
6933  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
6934 @@ -224,6 +228,7 @@ static inline void xfs_dinode_put_rdev(s
6935  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
6936  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
6937  #define XFS_DIFLAG_FILESTREAM    (1 << XFS_DIFLAG_FILESTREAM_BIT)
6938 +#define XFS_DIFLAG_IXUNLINK      (1 << XFS_DIFLAG_IXUNLINK_BIT)
6939  
6940  #ifdef CONFIG_XFS_RT
6941  #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
6942 @@ -236,6 +241,10 @@ static inline void xfs_dinode_put_rdev(s
6943          XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
6944          XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
6945          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
6946 -        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
6947 +        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM | \
6948 +        XFS_DIFLAG_IXUNLINK)
6949 +
6950 +#define XFS_DIVFLAG_BARRIER    0x01
6951 +#define XFS_DIVFLAG_COW                0x02
6952  
6953  #endif /* __XFS_DINODE_H__ */
6954 diff -NurpP --minimal linux-3.10.33/fs/xfs/xfs_fs.h linux-3.10.33-vs2.3.6.8/fs/xfs/xfs_fs.h
6955 --- linux-3.10.33/fs/xfs/xfs_fs.h       2013-07-14 17:01:29.000000000 +0000
6956 +++ linux-3.10.33-vs2.3.6.8/fs/xfs/xfs_fs.h     2013-08-22 20:30:00.000000000 +0000
6957 @@ -67,6 +67,9 @@ struct fsxattr {
6958  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
6959  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
6960  #define XFS_XFLAG_FILESTREAM   0x00004000      /* use filestream allocator */
6961 +#define XFS_XFLAG_IXUNLINK     0x00008000      /* immutable invert on unlink */
6962 +#define XFS_XFLAG_BARRIER      0x10000000      /* chroot() barrier */
6963 +#define XFS_XFLAG_COW          0x20000000      /* copy on write mark */
6964  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
6965  
6966  /*
6967 @@ -304,7 +307,8 @@ typedef struct xfs_bstat {
6968  #define        bs_projid       bs_projid_lo    /* (previously just bs_projid)  */
6969         __u16           bs_forkoff;     /* inode fork offset in bytes   */
6970         __u16           bs_projid_hi;   /* higher part of project id    */
6971 -       unsigned char   bs_pad[10];     /* pad space, unused            */
6972 +       unsigned char   bs_pad[8];      /* pad space, unused            */
6973 +       __u16           bs_tag;         /* context tagging              */
6974         __u32           bs_dmevmask;    /* DMIG event mask              */
6975         __u16           bs_dmstate;     /* DMIG state info              */
6976         __u16           bs_aextents;    /* attribute number of extents  */
6977 diff -NurpP --minimal linux-3.10.33/fs/xfs/xfs_ialloc.c linux-3.10.33-vs2.3.6.8/fs/xfs/xfs_ialloc.c
6978 --- linux-3.10.33/fs/xfs/xfs_ialloc.c   2013-07-14 17:01:29.000000000 +0000
6979 +++ linux-3.10.33-vs2.3.6.8/fs/xfs/xfs_ialloc.c 2013-08-22 20:30:00.000000000 +0000
6980 @@ -39,7 +39,6 @@
6981  #include "xfs_cksum.h"
6982  #include "xfs_buf_item.h"
6983  
6984 -
6985  /*
6986   * Allocation group level functions.
6987   */
6988 diff -NurpP --minimal linux-3.10.33/fs/xfs/xfs_inode.c linux-3.10.33-vs2.3.6.8/fs/xfs/xfs_inode.c
6989 --- linux-3.10.33/fs/xfs/xfs_inode.c    2013-07-14 17:01:29.000000000 +0000
6990 +++ linux-3.10.33-vs2.3.6.8/fs/xfs/xfs_inode.c  2013-08-22 21:50:34.000000000 +0000
6991 @@ -16,6 +16,7 @@
6992   * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
6993   */
6994  #include <linux/log2.h>
6995 +#include <linux/vs_tag.h>
6996  
6997  #include "xfs.h"
6998  #include "xfs_fs.h"
6999 @@ -836,15 +837,25 @@ xfs_iformat_btree(
7000  STATIC void
7001  xfs_dinode_from_disk(
7002         xfs_icdinode_t          *to,
7003 -       xfs_dinode_t            *from)
7004 +       xfs_dinode_t            *from,
7005 +       int                     tagged)
7006  {
7007 +       uint32_t uid, gid, tag;
7008 +
7009         to->di_magic = be16_to_cpu(from->di_magic);
7010         to->di_mode = be16_to_cpu(from->di_mode);
7011         to->di_version = from ->di_version;
7012         to->di_format = from->di_format;
7013         to->di_onlink = be16_to_cpu(from->di_onlink);
7014 -       to->di_uid = be32_to_cpu(from->di_uid);
7015 -       to->di_gid = be32_to_cpu(from->di_gid);
7016 +
7017 +       uid = be32_to_cpu(from->di_uid);
7018 +       gid = be32_to_cpu(from->di_gid);
7019 +       tag = be16_to_cpu(from->di_tag);
7020 +
7021 +       to->di_uid = INOTAG_UID(tagged, uid, gid);
7022 +       to->di_gid = INOTAG_GID(tagged, uid, gid);
7023 +       to->di_tag = INOTAG_TAG(tagged, uid, gid, tag);
7024 +
7025         to->di_nlink = be32_to_cpu(from->di_nlink);
7026         to->di_projid_lo = be16_to_cpu(from->di_projid_lo);
7027         to->di_projid_hi = be16_to_cpu(from->di_projid_hi);
7028 @@ -866,6 +877,7 @@ xfs_dinode_from_disk(
7029         to->di_dmevmask = be32_to_cpu(from->di_dmevmask);
7030         to->di_dmstate  = be16_to_cpu(from->di_dmstate);
7031         to->di_flags    = be16_to_cpu(from->di_flags);
7032 +       to->di_vflags   = be16_to_cpu(from->di_vflags);
7033         to->di_gen      = be32_to_cpu(from->di_gen);
7034  
7035         if (to->di_version == 3) {
7036 @@ -883,15 +895,19 @@ xfs_dinode_from_disk(
7037  void
7038  xfs_dinode_to_disk(
7039         xfs_dinode_t            *to,
7040 -       xfs_icdinode_t          *from)
7041 +       xfs_icdinode_t          *from,
7042 +       int                     tagged)
7043  {
7044         to->di_magic = cpu_to_be16(from->di_magic);
7045         to->di_mode = cpu_to_be16(from->di_mode);
7046         to->di_version = from ->di_version;
7047         to->di_format = from->di_format;
7048         to->di_onlink = cpu_to_be16(from->di_onlink);
7049 -       to->di_uid = cpu_to_be32(from->di_uid);
7050 -       to->di_gid = cpu_to_be32(from->di_gid);
7051 +
7052 +       to->di_uid = cpu_to_be32(TAGINO_UID(tagged, from->di_uid, from->di_tag));
7053 +       to->di_gid = cpu_to_be32(TAGINO_GID(tagged, from->di_gid, from->di_tag));
7054 +       to->di_tag = cpu_to_be16(TAGINO_TAG(tagged, from->di_tag));
7055 +
7056         to->di_nlink = cpu_to_be32(from->di_nlink);
7057         to->di_projid_lo = cpu_to_be16(from->di_projid_lo);
7058         to->di_projid_hi = cpu_to_be16(from->di_projid_hi);
7059 @@ -913,6 +929,7 @@ xfs_dinode_to_disk(
7060         to->di_dmevmask = cpu_to_be32(from->di_dmevmask);
7061         to->di_dmstate = cpu_to_be16(from->di_dmstate);
7062         to->di_flags = cpu_to_be16(from->di_flags);
7063 +       to->di_vflags = cpu_to_be16(from->di_vflags);
7064         to->di_gen = cpu_to_be32(from->di_gen);
7065  
7066         if (from->di_version == 3) {
7067 @@ -929,7 +946,8 @@ xfs_dinode_to_disk(
7068  
7069  STATIC uint
7070  _xfs_dic2xflags(
7071 -       __uint16_t              di_flags)
7072 +       __uint16_t              di_flags,
7073 +       __uint16_t              di_vflags)
7074  {
7075         uint                    flags = 0;
7076  
7077 @@ -940,6 +958,8 @@ _xfs_dic2xflags(
7078                         flags |= XFS_XFLAG_PREALLOC;
7079                 if (di_flags & XFS_DIFLAG_IMMUTABLE)
7080                         flags |= XFS_XFLAG_IMMUTABLE;
7081 +               if (di_flags & XFS_DIFLAG_IXUNLINK)
7082 +                       flags |= XFS_XFLAG_IXUNLINK;
7083                 if (di_flags & XFS_DIFLAG_APPEND)
7084                         flags |= XFS_XFLAG_APPEND;
7085                 if (di_flags & XFS_DIFLAG_SYNC)
7086 @@ -964,6 +984,10 @@ _xfs_dic2xflags(
7087                         flags |= XFS_XFLAG_FILESTREAM;
7088         }
7089  
7090 +       if (di_vflags & XFS_DIVFLAG_BARRIER)
7091 +               flags |= FS_BARRIER_FL;
7092 +       if (di_vflags & XFS_DIVFLAG_COW)
7093 +               flags |= FS_COW_FL;
7094         return flags;
7095  }
7096  
7097 @@ -973,7 +997,7 @@ xfs_ip2xflags(
7098  {
7099         xfs_icdinode_t          *dic = &ip->i_d;
7100  
7101 -       return _xfs_dic2xflags(dic->di_flags) |
7102 +       return _xfs_dic2xflags(dic->di_flags, dic->di_vflags) |
7103                                 (XFS_IFORK_Q(ip) ? XFS_XFLAG_HASATTR : 0);
7104  }
7105  
7106 @@ -981,7 +1005,8 @@ uint
7107  xfs_dic2xflags(
7108         xfs_dinode_t            *dip)
7109  {
7110 -       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags)) |
7111 +       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags),
7112 +                               be16_to_cpu(dip->di_vflags)) |
7113                                 (XFS_DFORK_Q(dip) ? XFS_XFLAG_HASATTR : 0);
7114  }
7115  
7116 @@ -1072,7 +1097,8 @@ xfs_iread(
7117          * Otherwise, just get the truly permanent information.
7118          */
7119         if (dip->di_mode) {
7120 -               xfs_dinode_from_disk(&ip->i_d, dip);
7121 +               xfs_dinode_from_disk(&ip->i_d, dip,
7122 +                       mp->m_flags & XFS_MOUNT_TAGGED);
7123                 error = xfs_iformat(ip, dip);
7124                 if (error)  {
7125  #ifdef DEBUG
7126 @@ -1270,6 +1296,7 @@ xfs_ialloc(
7127         ASSERT(ip->i_d.di_nlink == nlink);
7128         ip->i_d.di_uid = current_fsuid();
7129         ip->i_d.di_gid = current_fsgid();
7130 +       ip->i_d.di_tag = current_fstag(&ip->i_vnode);
7131         xfs_set_projid(ip, prid);
7132         memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
7133  
7134 @@ -1329,6 +1356,7 @@ xfs_ialloc(
7135         ip->i_d.di_dmevmask = 0;
7136         ip->i_d.di_dmstate = 0;
7137         ip->i_d.di_flags = 0;
7138 +       ip->i_d.di_vflags = 0;
7139  
7140         if (ip->i_d.di_version == 3) {
7141                 ASSERT(ip->i_d.di_ino == ino);
7142 @@ -2052,6 +2080,7 @@ xfs_ifree(
7143         }
7144         ip->i_d.di_mode = 0;            /* mark incore inode as free */
7145         ip->i_d.di_flags = 0;
7146 +       ip->i_d.di_vflags = 0;
7147         ip->i_d.di_dmevmask = 0;
7148         ip->i_d.di_forkoff = 0;         /* mark the attr fork not in use */
7149         ip->i_d.di_format = XFS_DINODE_FMT_EXTENTS;
7150 @@ -2219,7 +2248,6 @@ xfs_iroot_realloc(
7151         return;
7152  }
7153  
7154 -
7155  /*
7156   * This is called when the amount of space needed for if_data
7157   * is increased or decreased.  The change in size is indicated by
7158 @@ -2899,7 +2927,8 @@ xfs_iflush_int(
7159          * because if the inode is dirty at all the core must
7160          * be.
7161          */
7162 -       xfs_dinode_to_disk(dip, &ip->i_d);
7163 +       xfs_dinode_to_disk(dip, &ip->i_d,
7164 +               mp->m_flags & XFS_MOUNT_TAGGED);
7165  
7166         /* Wrap, we never let the log put out DI_MAX_FLUSH */
7167         if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
7168 diff -NurpP --minimal linux-3.10.33/fs/xfs/xfs_inode.h linux-3.10.33-vs2.3.6.8/fs/xfs/xfs_inode.h
7169 --- linux-3.10.33/fs/xfs/xfs_inode.h    2013-07-14 17:01:30.000000000 +0000
7170 +++ linux-3.10.33-vs2.3.6.8/fs/xfs/xfs_inode.h  2013-08-22 20:30:00.000000000 +0000
7171 @@ -134,7 +134,9 @@ typedef struct xfs_icdinode {
7172         __uint32_t      di_nlink;       /* number of links to file */
7173         __uint16_t      di_projid_lo;   /* lower part of owner's project id */
7174         __uint16_t      di_projid_hi;   /* higher part of owner's project id */
7175 -       __uint8_t       di_pad[6];      /* unused, zeroed space */
7176 +       __uint8_t       di_pad[2];      /* unused, zeroed space */
7177 +       __uint16_t      di_tag;         /* context tagging */
7178 +       __uint16_t      di_vflags;      /* vserver specific flags */
7179         __uint16_t      di_flushiter;   /* incremented on flush */
7180         xfs_ictimestamp_t di_atime;     /* time last accessed */
7181         xfs_ictimestamp_t di_mtime;     /* time last modified */
7182 @@ -583,7 +585,7 @@ int         xfs_iread(struct xfs_mount *, struc
7183                           struct xfs_inode *, uint);
7184  void           xfs_dinode_calc_crc(struct xfs_mount *, struct xfs_dinode *);
7185  void           xfs_dinode_to_disk(struct xfs_dinode *,
7186 -                                  struct xfs_icdinode *);
7187 +                                  struct xfs_icdinode *, int);
7188  void           xfs_idestroy_fork(struct xfs_inode *, int);
7189  void           xfs_idata_realloc(struct xfs_inode *, int, int);
7190  void           xfs_iroot_realloc(struct xfs_inode *, int, int);
7191 diff -NurpP --minimal linux-3.10.33/fs/xfs/xfs_ioctl.c linux-3.10.33-vs2.3.6.8/fs/xfs/xfs_ioctl.c
7192 --- linux-3.10.33/fs/xfs/xfs_ioctl.c    2014-03-12 13:16:02.000000000 +0000
7193 +++ linux-3.10.33-vs2.3.6.8/fs/xfs/xfs_ioctl.c  2013-12-23 17:42:40.000000000 +0000
7194 @@ -26,7 +26,7 @@
7195  #include "xfs_bmap_btree.h"
7196  #include "xfs_dinode.h"
7197  #include "xfs_inode.h"
7198 -#include "xfs_ioctl.h"
7199 +// #include "xfs_ioctl.h"
7200  #include "xfs_rtalloc.h"
7201  #include "xfs_itable.h"
7202  #include "xfs_error.h"
7203 @@ -770,6 +770,10 @@ xfs_merge_ioc_xflags(
7204                 xflags |= XFS_XFLAG_IMMUTABLE;
7205         else
7206                 xflags &= ~XFS_XFLAG_IMMUTABLE;
7207 +       if (flags & FS_IXUNLINK_FL)
7208 +               xflags |= XFS_XFLAG_IXUNLINK;
7209 +       else
7210 +               xflags &= ~XFS_XFLAG_IXUNLINK;
7211         if (flags & FS_APPEND_FL)
7212                 xflags |= XFS_XFLAG_APPEND;
7213         else
7214 @@ -798,6 +802,8 @@ xfs_di2lxflags(
7215  
7216         if (di_flags & XFS_DIFLAG_IMMUTABLE)
7217                 flags |= FS_IMMUTABLE_FL;
7218 +       if (di_flags & XFS_DIFLAG_IXUNLINK)
7219 +               flags |= FS_IXUNLINK_FL;
7220         if (di_flags & XFS_DIFLAG_APPEND)
7221                 flags |= FS_APPEND_FL;
7222         if (di_flags & XFS_DIFLAG_SYNC)
7223 @@ -858,6 +864,8 @@ xfs_set_diflags(
7224         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
7225         if (xflags & XFS_XFLAG_IMMUTABLE)
7226                 di_flags |= XFS_DIFLAG_IMMUTABLE;
7227 +       if (xflags & XFS_XFLAG_IXUNLINK)
7228 +               di_flags |= XFS_DIFLAG_IXUNLINK;
7229         if (xflags & XFS_XFLAG_APPEND)
7230                 di_flags |= XFS_DIFLAG_APPEND;
7231         if (xflags & XFS_XFLAG_SYNC)
7232 @@ -900,6 +908,10 @@ xfs_diflags_to_linux(
7233                 inode->i_flags |= S_IMMUTABLE;
7234         else
7235                 inode->i_flags &= ~S_IMMUTABLE;
7236 +       if (xflags & XFS_XFLAG_IXUNLINK)
7237 +               inode->i_flags |= S_IXUNLINK;
7238 +       else
7239 +               inode->i_flags &= ~S_IXUNLINK;
7240         if (xflags & XFS_XFLAG_APPEND)
7241                 inode->i_flags |= S_APPEND;
7242         else
7243 @@ -1404,10 +1416,18 @@ xfs_file_ioctl(
7244         case XFS_IOC_FSGETXATTRA:
7245                 return xfs_ioc_fsgetxattr(ip, 1, arg);
7246         case XFS_IOC_FSSETXATTR:
7247 +               if (IS_BARRIER(inode)) {
7248 +                       vxwprintk_task(1, "messing with the barrier.");
7249 +                       return -XFS_ERROR(EACCES);
7250 +               }
7251                 return xfs_ioc_fssetxattr(ip, filp, arg);
7252         case XFS_IOC_GETXFLAGS:
7253                 return xfs_ioc_getxflags(ip, arg);
7254         case XFS_IOC_SETXFLAGS:
7255 +               if (IS_BARRIER(inode)) {
7256 +                       vxwprintk_task(1, "messing with the barrier.");
7257 +                       return -XFS_ERROR(EACCES);
7258 +               }
7259                 return xfs_ioc_setxflags(ip, filp, arg);
7260  
7261         case XFS_IOC_FSSETDM: {
7262 diff -NurpP --minimal linux-3.10.33/fs/xfs/xfs_ioctl.h linux-3.10.33-vs2.3.6.8/fs/xfs/xfs_ioctl.h
7263 --- linux-3.10.33/fs/xfs/xfs_ioctl.h    2012-12-11 03:30:57.000000000 +0000
7264 +++ linux-3.10.33-vs2.3.6.8/fs/xfs/xfs_ioctl.h  2013-08-22 20:30:00.000000000 +0000
7265 @@ -70,6 +70,12 @@ xfs_handle_to_dentry(
7266         void __user             *uhandle,
7267         u32                     hlen);
7268  
7269 +extern int
7270 +xfs_sync_flags(
7271 +       struct inode            *inode,
7272 +       int                     flags,
7273 +       int                     vflags);
7274 +
7275  extern long
7276  xfs_file_ioctl(
7277         struct file             *filp,
7278 diff -NurpP --minimal linux-3.10.33/fs/xfs/xfs_iops.c linux-3.10.33-vs2.3.6.8/fs/xfs/xfs_iops.c
7279 --- linux-3.10.33/fs/xfs/xfs_iops.c     2013-07-14 17:01:30.000000000 +0000
7280 +++ linux-3.10.33-vs2.3.6.8/fs/xfs/xfs_iops.c   2013-08-22 20:30:00.000000000 +0000
7281 @@ -28,6 +28,7 @@
7282  #include "xfs_bmap_btree.h"
7283  #include "xfs_dinode.h"
7284  #include "xfs_inode.h"
7285 +#include "xfs_ioctl.h"
7286  #include "xfs_bmap.h"
7287  #include "xfs_rtalloc.h"
7288  #include "xfs_error.h"
7289 @@ -47,6 +48,7 @@
7290  #include <linux/security.h>
7291  #include <linux/fiemap.h>
7292  #include <linux/slab.h>
7293 +#include <linux/vs_tag.h>
7294  
7295  static int
7296  xfs_initxattrs(
7297 @@ -422,6 +424,7 @@ xfs_vn_getattr(
7298         stat->nlink = ip->i_d.di_nlink;
7299         stat->uid = ip->i_d.di_uid;
7300         stat->gid = ip->i_d.di_gid;
7301 +       stat->tag = ip->i_d.di_tag;
7302         stat->ino = ip->i_ino;
7303         stat->atime = inode->i_atime;
7304         stat->mtime = inode->i_mtime;
7305 @@ -1054,6 +1057,7 @@ static const struct inode_operations xfs
7306         .listxattr              = xfs_vn_listxattr,
7307         .fiemap                 = xfs_vn_fiemap,
7308         .update_time            = xfs_vn_update_time,
7309 +       .sync_flags             = xfs_sync_flags,
7310  };
7311  
7312  static const struct inode_operations xfs_dir_inode_operations = {
7313 @@ -1080,6 +1084,7 @@ static const struct inode_operations xfs
7314         .removexattr            = generic_removexattr,
7315         .listxattr              = xfs_vn_listxattr,
7316         .update_time            = xfs_vn_update_time,
7317 +       .sync_flags             = xfs_sync_flags,
7318  };
7319  
7320  static const struct inode_operations xfs_dir_ci_inode_operations = {
7321 @@ -1131,6 +1136,10 @@ xfs_diflags_to_iflags(
7322                 inode->i_flags |= S_IMMUTABLE;
7323         else
7324                 inode->i_flags &= ~S_IMMUTABLE;
7325 +       if (ip->i_d.di_flags & XFS_DIFLAG_IXUNLINK)
7326 +               inode->i_flags |= S_IXUNLINK;
7327 +       else
7328 +               inode->i_flags &= ~S_IXUNLINK;
7329         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
7330                 inode->i_flags |= S_APPEND;
7331         else
7332 @@ -1143,6 +1152,15 @@ xfs_diflags_to_iflags(
7333                 inode->i_flags |= S_NOATIME;
7334         else
7335                 inode->i_flags &= ~S_NOATIME;
7336 +
7337 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_BARRIER)
7338 +               inode->i_vflags |= V_BARRIER;
7339 +       else
7340 +               inode->i_vflags &= ~V_BARRIER;
7341 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_COW)
7342 +               inode->i_vflags |= V_COW;
7343 +       else
7344 +               inode->i_vflags &= ~V_COW;
7345  }
7346  
7347  /*
7348 @@ -1174,6 +1192,7 @@ xfs_setup_inode(
7349         set_nlink(inode, ip->i_d.di_nlink);
7350         inode->i_uid    = ip->i_d.di_uid;
7351         inode->i_gid    = ip->i_d.di_gid;
7352 +       inode->i_tag    = ip->i_d.di_tag;
7353  
7354         switch (inode->i_mode & S_IFMT) {
7355         case S_IFBLK:
7356 diff -NurpP --minimal linux-3.10.33/fs/xfs/xfs_itable.c linux-3.10.33-vs2.3.6.8/fs/xfs/xfs_itable.c
7357 --- linux-3.10.33/fs/xfs/xfs_itable.c   2013-02-19 13:58:49.000000000 +0000
7358 +++ linux-3.10.33-vs2.3.6.8/fs/xfs/xfs_itable.c 2013-08-22 20:30:00.000000000 +0000
7359 @@ -97,6 +97,7 @@ xfs_bulkstat_one_int(
7360         buf->bs_mode = dic->di_mode;
7361         buf->bs_uid = dic->di_uid;
7362         buf->bs_gid = dic->di_gid;
7363 +       buf->bs_tag = dic->di_tag;
7364         buf->bs_size = dic->di_size;
7365         buf->bs_atime.tv_sec = dic->di_atime.t_sec;
7366         buf->bs_atime.tv_nsec = dic->di_atime.t_nsec;
7367 diff -NurpP --minimal linux-3.10.33/fs/xfs/xfs_linux.h linux-3.10.33-vs2.3.6.8/fs/xfs/xfs_linux.h
7368 --- linux-3.10.33/fs/xfs/xfs_linux.h    2013-07-14 17:01:30.000000000 +0000
7369 +++ linux-3.10.33-vs2.3.6.8/fs/xfs/xfs_linux.h  2013-08-22 20:30:00.000000000 +0000
7370 @@ -124,6 +124,7 @@
7371  
7372  #define current_cpu()          (raw_smp_processor_id())
7373  #define current_pid()          (current->pid)
7374 +#define current_fstag(vp)      (dx_current_fstag((vp)->i_sb))
7375  #define current_test_flags(f)  (current->flags & (f))
7376  #define current_set_flags_nested(sp, f)                \
7377                 (*(sp) = current->flags, current->flags |= (f))
7378 diff -NurpP --minimal linux-3.10.33/fs/xfs/xfs_log_recover.c linux-3.10.33-vs2.3.6.8/fs/xfs/xfs_log_recover.c
7379 --- linux-3.10.33/fs/xfs/xfs_log_recover.c      2013-07-14 17:01:31.000000000 +0000
7380 +++ linux-3.10.33-vs2.3.6.8/fs/xfs/xfs_log_recover.c    2013-08-22 21:48:01.000000000 +0000
7381 @@ -2662,7 +2662,7 @@ xlog_recover_inode_pass2(
7382         }
7383  
7384         /* The core is in in-core format */
7385 -       xfs_dinode_to_disk(dip, dicp);
7386 +       xfs_dinode_to_disk(dip, dicp, mp->m_flags & XFS_MOUNT_TAGGED);
7387  
7388         /* the rest is in on-disk format */
7389         if (item->ri_buf[1].i_len > isize) {
7390 diff -NurpP --minimal linux-3.10.33/fs/xfs/xfs_mount.h linux-3.10.33-vs2.3.6.8/fs/xfs/xfs_mount.h
7391 --- linux-3.10.33/fs/xfs/xfs_mount.h    2013-07-14 17:01:31.000000000 +0000
7392 +++ linux-3.10.33-vs2.3.6.8/fs/xfs/xfs_mount.h  2013-08-22 20:30:00.000000000 +0000
7393 @@ -253,6 +253,7 @@ typedef struct xfs_mount {
7394                                                    allocator */
7395  #define XFS_MOUNT_NOATTR2      (1ULL << 25)    /* disable use of attr2 format */
7396  
7397 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
7398  
7399  /*
7400   * Default minimum read and write sizes.
7401 diff -NurpP --minimal linux-3.10.33/fs/xfs/xfs_super.c linux-3.10.33-vs2.3.6.8/fs/xfs/xfs_super.c
7402 --- linux-3.10.33/fs/xfs/xfs_super.c    2013-07-14 17:01:31.000000000 +0000
7403 +++ linux-3.10.33-vs2.3.6.8/fs/xfs/xfs_super.c  2013-08-22 20:30:00.000000000 +0000
7404 @@ -114,6 +114,9 @@ mempool_t *xfs_ioend_pool;
7405  #define MNTOPT_NODELAYLOG  "nodelaylog"        /* Delayed logging disabled */
7406  #define MNTOPT_DISCARD    "discard"    /* Discard unused blocks */
7407  #define MNTOPT_NODISCARD   "nodiscard" /* Do not discard unused blocks */
7408 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
7409 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
7410 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
7411  
7412  /*
7413   * Table driven mount option parser.
7414 @@ -126,6 +129,8 @@ enum {
7415         Opt_nobarrier,
7416         Opt_inode64,
7417         Opt_inode32,
7418 +       Opt_tag,
7419 +       Opt_notag,
7420         Opt_err
7421  };
7422  
7423 @@ -134,6 +139,9 @@ static const match_table_t tokens = {
7424         {Opt_nobarrier, "nobarrier"},
7425         {Opt_inode64, "inode64"},
7426         {Opt_inode32, "inode32"},
7427 +       {Opt_tag, "tagxid"},
7428 +       {Opt_tag, "tag"},
7429 +       {Opt_notag, "notag"},
7430         {Opt_err, NULL}
7431  };
7432  
7433 @@ -392,6 +400,19 @@ xfs_parseargs(
7434                 } else if (!strcmp(this_char, "irixsgid")) {
7435                         xfs_warn(mp,
7436         "irixsgid is now a sysctl(2) variable, option is deprecated.");
7437 +#ifndef CONFIG_TAGGING_NONE
7438 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7439 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7440 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
7441 +                       mp->m_flags &= ~XFS_MOUNT_TAGGED;
7442 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
7443 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7444 +#endif
7445 +#ifdef CONFIG_PROPAGATE
7446 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7447 +                       /* use value */
7448 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7449 +#endif
7450                 } else {
7451                         xfs_warn(mp, "unknown mount option [%s].", this_char);
7452                         return EINVAL;
7453 @@ -1238,6 +1259,16 @@ xfs_fs_remount(
7454                 case Opt_inode32:
7455                         mp->m_maxagi = xfs_set_inode32(mp);
7456                         break;
7457 +               case Opt_tag:
7458 +                       if (!(sb->s_flags & MS_TAGGED)) {
7459 +                               printk(KERN_INFO
7460 +                                       "XFS: %s: tagging not permitted on remount.\n",
7461 +                                       sb->s_id);
7462 +                               return -EINVAL;
7463 +                       }
7464 +                       break;
7465 +               case Opt_notag:
7466 +                       break;
7467                 default:
7468                         /*
7469                          * Logically we would return an error here to prevent
7470 @@ -1469,6 +1500,9 @@ xfs_fs_fill_super(
7471         if (error)
7472                 goto out_free_sb;
7473  
7474 +       if (mp->m_flags & XFS_MOUNT_TAGGED)
7475 +               sb->s_flags |= MS_TAGGED;
7476 +
7477         /*
7478          * we must configure the block size in the superblock before we run the
7479          * full mount process as the mount process can lookup and cache inodes.
7480 diff -NurpP --minimal linux-3.10.33/fs/xfs/xfs_vnodeops.c linux-3.10.33-vs2.3.6.8/fs/xfs/xfs_vnodeops.c
7481 --- linux-3.10.33/fs/xfs/xfs_vnodeops.c 2013-07-14 17:01:31.000000000 +0000
7482 +++ linux-3.10.33-vs2.3.6.8/fs/xfs/xfs_vnodeops.c       2013-08-22 20:30:00.000000000 +0000
7483 @@ -155,6 +155,77 @@ xfs_free_eofblocks(
7484         return error;
7485  }
7486  
7487 +
7488 +STATIC void
7489 +xfs_get_inode_flags(
7490 +       xfs_inode_t     *ip)
7491 +{
7492 +       struct inode    *inode = VFS_I(ip);
7493 +       unsigned int    flags = inode->i_flags;
7494 +       unsigned int    vflags = inode->i_vflags;
7495 +
7496 +       if (flags & S_IMMUTABLE)
7497 +               ip->i_d.di_flags |= XFS_DIFLAG_IMMUTABLE;
7498 +       else
7499 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IMMUTABLE;
7500 +       if (flags & S_IXUNLINK)
7501 +               ip->i_d.di_flags |= XFS_DIFLAG_IXUNLINK;
7502 +       else
7503 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IXUNLINK;
7504 +
7505 +       if (vflags & V_BARRIER)
7506 +               ip->i_d.di_vflags |= XFS_DIVFLAG_BARRIER;
7507 +       else
7508 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_BARRIER;
7509 +       if (vflags & V_COW)
7510 +               ip->i_d.di_vflags |= XFS_DIVFLAG_COW;
7511 +       else
7512 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_COW;
7513 +}
7514 +
7515 +int
7516 +xfs_sync_flags(
7517 +       struct inode            *inode,
7518 +       int                     flags,
7519 +       int                     vflags)
7520 +{
7521 +       struct xfs_inode        *ip = XFS_I(inode);
7522 +       struct xfs_mount        *mp = ip->i_mount;
7523 +       struct xfs_trans        *tp;
7524 +       unsigned int            lock_flags = 0;
7525 +       int                     code;
7526 +
7527 +       tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
7528 +       code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
7529 +       if (code)
7530 +               goto error_out;
7531 +
7532 +       xfs_ilock(ip, XFS_ILOCK_EXCL);
7533 +       xfs_trans_ijoin(tp, ip, 0);
7534 +
7535 +       inode->i_flags = flags;
7536 +       inode->i_vflags = vflags;
7537 +       xfs_get_inode_flags(ip);
7538 +
7539 +       xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
7540 +       xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG);
7541 +
7542 +       XFS_STATS_INC(xs_ig_attrchg);
7543 +
7544 +       if (mp->m_flags & XFS_MOUNT_WSYNC)
7545 +               xfs_trans_set_sync(tp);
7546 +       code = xfs_trans_commit(tp, 0);
7547 +       xfs_iunlock(ip, XFS_ILOCK_EXCL);
7548 +       return code;
7549 +
7550 +error_out:
7551 +       xfs_trans_cancel(tp, 0);
7552 +       if (lock_flags)
7553 +               xfs_iunlock(ip, XFS_ILOCK_EXCL);
7554 +       return code;
7555 +}
7556 +
7557 +
7558  int
7559  xfs_release(
7560         xfs_inode_t     *ip)
7561 diff -NurpP --minimal linux-3.10.33/include/linux/cred.h linux-3.10.33-vs2.3.6.8/include/linux/cred.h
7562 --- linux-3.10.33/include/linux/cred.h  2013-02-19 13:58:50.000000000 +0000
7563 +++ linux-3.10.33-vs2.3.6.8/include/linux/cred.h        2013-08-22 20:30:00.000000000 +0000
7564 @@ -143,6 +143,7 @@ extern void exit_creds(struct task_struc
7565  extern int copy_creds(struct task_struct *, unsigned long);
7566  extern const struct cred *get_task_cred(struct task_struct *);
7567  extern struct cred *cred_alloc_blank(void);
7568 +extern struct cred *__prepare_creds(const struct cred *);
7569  extern struct cred *prepare_creds(void);
7570  extern struct cred *prepare_exec_creds(void);
7571  extern int commit_creds(struct cred *);
7572 @@ -196,6 +197,31 @@ static inline void validate_process_cred
7573  }
7574  #endif
7575  
7576 +static inline void set_cred_subscribers(struct cred *cred, int n)
7577 +{
7578 +#ifdef CONFIG_DEBUG_CREDENTIALS
7579 +       atomic_set(&cred->subscribers, n);
7580 +#endif
7581 +}
7582 +
7583 +static inline int read_cred_subscribers(const struct cred *cred)
7584 +{
7585 +#ifdef CONFIG_DEBUG_CREDENTIALS
7586 +       return atomic_read(&cred->subscribers);
7587 +#else
7588 +       return 0;
7589 +#endif
7590 +}
7591 +
7592 +static inline void alter_cred_subscribers(const struct cred *_cred, int n)
7593 +{
7594 +#ifdef CONFIG_DEBUG_CREDENTIALS
7595 +       struct cred *cred = (struct cred *) _cred;
7596 +
7597 +       atomic_add(n, &cred->subscribers);
7598 +#endif
7599 +}
7600 +
7601  /**
7602   * get_new_cred - Get a reference on a new set of credentials
7603   * @cred: The new credentials to reference
7604 diff -NurpP --minimal linux-3.10.33/include/linux/devpts_fs.h linux-3.10.33-vs2.3.6.8/include/linux/devpts_fs.h
7605 --- linux-3.10.33/include/linux/devpts_fs.h     2013-02-19 13:58:50.000000000 +0000
7606 +++ linux-3.10.33-vs2.3.6.8/include/linux/devpts_fs.h   2013-08-22 20:30:00.000000000 +0000
7607 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
7608  
7609  #endif
7610  
7611 -
7612  #endif /* _LINUX_DEVPTS_FS_H */
7613 diff -NurpP --minimal linux-3.10.33/include/linux/fs.h linux-3.10.33-vs2.3.6.8/include/linux/fs.h
7614 --- linux-3.10.33/include/linux/fs.h    2013-07-14 17:01:32.000000000 +0000
7615 +++ linux-3.10.33-vs2.3.6.8/include/linux/fs.h  2013-08-22 20:30:00.000000000 +0000
7616 @@ -211,6 +211,7 @@ typedef void (dio_iodone_t)(struct kiocb
7617  #define ATTR_KILL_PRIV (1 << 14)
7618  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
7619  #define ATTR_TIMES_SET (1 << 16)
7620 +#define ATTR_TAG       (1 << 17)
7621  
7622  /*
7623   * This is the Inode Attributes structure, used for notify_change().  It
7624 @@ -226,6 +227,7 @@ struct iattr {
7625         umode_t         ia_mode;
7626         kuid_t          ia_uid;
7627         kgid_t          ia_gid;
7628 +       ktag_t          ia_tag;
7629         loff_t          ia_size;
7630         struct timespec ia_atime;
7631         struct timespec ia_mtime;
7632 @@ -523,7 +525,9 @@ struct inode {
7633         unsigned short          i_opflags;
7634         kuid_t                  i_uid;
7635         kgid_t                  i_gid;
7636 -       unsigned int            i_flags;
7637 +       ktag_t                  i_tag;
7638 +       unsigned short          i_flags;
7639 +       unsigned short          i_vflags;
7640  
7641  #ifdef CONFIG_FS_POSIX_ACL
7642         struct posix_acl        *i_acl;
7643 @@ -552,6 +556,7 @@ struct inode {
7644                 unsigned int __i_nlink;
7645         };
7646         dev_t                   i_rdev;
7647 +       dev_t                   i_mdev;
7648         loff_t                  i_size;
7649         struct timespec         i_atime;
7650         struct timespec         i_mtime;
7651 @@ -704,6 +709,11 @@ static inline gid_t i_gid_read(const str
7652         return from_kgid(&init_user_ns, inode->i_gid);
7653  }
7654  
7655 +static inline vtag_t i_tag_read(const struct inode *inode)
7656 +{
7657 +       return from_ktag(&init_user_ns, inode->i_tag);
7658 +}
7659 +
7660  static inline void i_uid_write(struct inode *inode, uid_t uid)
7661  {
7662         inode->i_uid = make_kuid(&init_user_ns, uid);
7663 @@ -714,14 +724,19 @@ static inline void i_gid_write(struct in
7664         inode->i_gid = make_kgid(&init_user_ns, gid);
7665  }
7666  
7667 +static inline void i_tag_write(struct inode *inode, vtag_t tag)
7668 +{
7669 +       inode->i_tag = make_ktag(&init_user_ns, tag);
7670 +}
7671 +
7672  static inline unsigned iminor(const struct inode *inode)
7673  {
7674 -       return MINOR(inode->i_rdev);
7675 +       return MINOR(inode->i_mdev);
7676  }
7677  
7678  static inline unsigned imajor(const struct inode *inode)
7679  {
7680 -       return MAJOR(inode->i_rdev);
7681 +       return MAJOR(inode->i_mdev);
7682  }
7683  
7684  extern struct block_device *I_BDEV(struct inode *inode);
7685 @@ -788,6 +803,7 @@ struct file {
7686         loff_t                  f_pos;
7687         struct fown_struct      f_owner;
7688         const struct cred       *f_cred;
7689 +       vxid_t                  f_xid;
7690         struct file_ra_state    f_ra;
7691  
7692         u64                     f_version;
7693 @@ -939,6 +955,7 @@ struct file_lock {
7694         struct file *fl_file;
7695         loff_t fl_start;
7696         loff_t fl_end;
7697 +       vxid_t fl_xid;
7698  
7699         struct fasync_struct *  fl_fasync; /* for lease break notifications */
7700         /* for lease breaks: */
7701 @@ -1569,6 +1586,7 @@ struct inode_operations {
7702         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
7703         ssize_t (*listxattr) (struct dentry *, char *, size_t);
7704         int (*removexattr) (struct dentry *, const char *);
7705 +       int (*sync_flags) (struct inode *, int, int);
7706         int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
7707                       u64 len);
7708         int (*update_time)(struct inode *, struct timespec *, int);
7709 @@ -1581,6 +1599,7 @@ ssize_t rw_copy_check_uvector(int type,
7710                               unsigned long nr_segs, unsigned long fast_segs,
7711                               struct iovec *fast_pointer,
7712                               struct iovec **ret_pointer);
7713 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
7714  
7715  extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
7716  extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *);
7717 @@ -1634,6 +1653,14 @@ struct super_operations {
7718  #define S_IMA          1024    /* Inode has an associated IMA struct */
7719  #define S_AUTOMOUNT    2048    /* Automount/referral quasi-directory */
7720  #define S_NOSEC                4096    /* no suid or xattr security attributes */
7721 +#define S_IXUNLINK     8192    /* Immutable Invert on unlink */
7722 +
7723 +/* Linux-VServer related Inode flags */
7724 +
7725 +#define V_VALID                1
7726 +#define V_XATTR                2
7727 +#define V_BARRIER      4       /* Barrier for chroot() */
7728 +#define V_COW          8       /* Copy on Write */
7729  
7730  /*
7731   * Note that nosuid etc flags are inode-specific: setting some file-system
7732 @@ -1658,10 +1685,13 @@ struct super_operations {
7733  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
7734  #define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
7735  #define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
7736 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
7737  
7738  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
7739  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
7740  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
7741 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
7742 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
7743  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
7744  
7745  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
7746 @@ -1672,6 +1702,16 @@ struct super_operations {
7747  #define IS_AUTOMOUNT(inode)    ((inode)->i_flags & S_AUTOMOUNT)
7748  #define IS_NOSEC(inode)                ((inode)->i_flags & S_NOSEC)
7749  
7750 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
7751 +
7752 +#ifdef CONFIG_VSERVER_COWBL
7753 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
7754 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
7755 +#else
7756 +#  define IS_COW(inode)                (0)
7757 +#  define IS_COW_LINK(inode)   (0)
7758 +#endif
7759 +
7760  /*
7761   * Inode state bits.  Protected by inode->i_lock
7762   *
7763 @@ -1900,6 +1940,9 @@ extern int rw_verify_area(int, struct fi
7764  extern int locks_mandatory_locked(struct inode *);
7765  extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t);
7766  
7767 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
7768 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
7769 +
7770  /*
7771   * Candidates for mandatory locking have the setgid bit set
7772   * but no group execute bit -  an otherwise meaningless combination.
7773 @@ -2525,6 +2568,7 @@ extern int dcache_dir_open(struct inode
7774  extern int dcache_dir_close(struct inode *, struct file *);
7775  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
7776  extern int dcache_readdir(struct file *, void *, filldir_t);
7777 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
7778  extern int simple_setattr(struct dentry *, struct iattr *);
7779  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
7780  extern int simple_statfs(struct dentry *, struct kstatfs *);
7781 diff -NurpP --minimal linux-3.10.33/include/linux/init_task.h linux-3.10.33-vs2.3.6.8/include/linux/init_task.h
7782 --- linux-3.10.33/include/linux/init_task.h     2013-05-31 13:45:27.000000000 +0000
7783 +++ linux-3.10.33-vs2.3.6.8/include/linux/init_task.h   2013-08-22 20:30:00.000000000 +0000
7784 @@ -222,6 +222,10 @@ extern struct task_group root_task_group
7785         INIT_TASK_RCU_PREEMPT(tsk)                                      \
7786         INIT_CPUSET_SEQ                                                 \
7787         INIT_VTIME(tsk)                                                 \
7788 +       .xid            = 0,                                            \
7789 +       .vx_info        = NULL,                                         \
7790 +       .nid            = 0,                                            \
7791 +       .nx_info        = NULL,                                         \
7792  }
7793  
7794  
7795 diff -NurpP --minimal linux-3.10.33/include/linux/ipc.h linux-3.10.33-vs2.3.6.8/include/linux/ipc.h
7796 --- linux-3.10.33/include/linux/ipc.h   2012-12-11 03:30:57.000000000 +0000
7797 +++ linux-3.10.33-vs2.3.6.8/include/linux/ipc.h 2013-08-22 20:30:00.000000000 +0000
7798 @@ -16,6 +16,7 @@ struct kern_ipc_perm
7799         key_t           key;
7800         kuid_t          uid;
7801         kgid_t          gid;
7802 +       vxid_t          xid;
7803         kuid_t          cuid;
7804         kgid_t          cgid;
7805         umode_t         mode; 
7806 diff -NurpP --minimal linux-3.10.33/include/linux/loop.h linux-3.10.33-vs2.3.6.8/include/linux/loop.h
7807 --- linux-3.10.33/include/linux/loop.h  2013-02-19 13:58:51.000000000 +0000
7808 +++ linux-3.10.33-vs2.3.6.8/include/linux/loop.h        2013-08-22 20:30:00.000000000 +0000
7809 @@ -41,6 +41,7 @@ struct loop_device {
7810         struct loop_func_table *lo_encryption;
7811         __u32           lo_init[2];
7812         kuid_t          lo_key_owner;   /* Who set the key */
7813 +       vxid_t          lo_xid;
7814         int             (*ioctl)(struct loop_device *, int cmd, 
7815                                  unsigned long arg); 
7816  
7817 diff -NurpP --minimal linux-3.10.33/include/linux/memcontrol.h linux-3.10.33-vs2.3.6.8/include/linux/memcontrol.h
7818 --- linux-3.10.33/include/linux/memcontrol.h    2013-05-31 13:45:28.000000000 +0000
7819 +++ linux-3.10.33-vs2.3.6.8/include/linux/memcontrol.h  2013-08-22 20:30:00.000000000 +0000
7820 @@ -86,6 +86,13 @@ extern struct mem_cgroup *try_get_mem_cg
7821  extern struct mem_cgroup *parent_mem_cgroup(struct mem_cgroup *memcg);
7822  extern struct mem_cgroup *mem_cgroup_from_cont(struct cgroup *cont);
7823  
7824 +extern u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member);
7825 +extern u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member);
7826 +
7827 +extern s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem);
7828 +extern s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem);
7829 +extern s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem);
7830 +
7831  static inline
7832  bool mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *memcg)
7833  {
7834 diff -NurpP --minimal linux-3.10.33/include/linux/mm_types.h linux-3.10.33-vs2.3.6.8/include/linux/mm_types.h
7835 --- linux-3.10.33/include/linux/mm_types.h      2014-03-12 13:16:02.000000000 +0000
7836 +++ linux-3.10.33-vs2.3.6.8/include/linux/mm_types.h    2014-01-22 19:00:34.000000000 +0000
7837 @@ -381,6 +381,7 @@ struct mm_struct {
7838  
7839         /* Architecture-specific MM context */
7840         mm_context_t context;
7841 +       struct vx_info *mm_vx_info;
7842  
7843         unsigned long flags; /* Must use atomic bitops to access the bits */
7844  
7845 diff -NurpP --minimal linux-3.10.33/include/linux/mount.h linux-3.10.33-vs2.3.6.8/include/linux/mount.h
7846 --- linux-3.10.33/include/linux/mount.h 2013-05-31 13:45:28.000000000 +0000
7847 +++ linux-3.10.33-vs2.3.6.8/include/linux/mount.h       2013-08-22 20:30:00.000000000 +0000
7848 @@ -49,6 +49,9 @@ struct mnt_namespace;
7849  
7850  #define MNT_LOCK_READONLY      0x400000
7851  
7852 +#define MNT_TAGID      0x10000
7853 +#define MNT_NOTAG      0x20000
7854 +
7855  struct vfsmount {
7856         struct dentry *mnt_root;        /* root of the mounted tree */
7857         struct super_block *mnt_sb;     /* pointer to superblock */
7858 diff -NurpP --minimal linux-3.10.33/include/linux/net.h linux-3.10.33-vs2.3.6.8/include/linux/net.h
7859 --- linux-3.10.33/include/linux/net.h   2014-03-12 13:16:02.000000000 +0000
7860 +++ linux-3.10.33-vs2.3.6.8/include/linux/net.h 2014-01-22 19:00:34.000000000 +0000
7861 @@ -38,6 +38,7 @@ struct net;
7862  #define SOCK_PASSCRED          3
7863  #define SOCK_PASSSEC           4
7864  #define SOCK_EXTERNALLY_ALLOCATED 5
7865 +#define SOCK_USER_SOCKET       6
7866  
7867  #ifndef ARCH_HAS_SOCKET_TYPES
7868  /**
7869 diff -NurpP --minimal linux-3.10.33/include/linux/netdevice.h linux-3.10.33-vs2.3.6.8/include/linux/netdevice.h
7870 --- linux-3.10.33/include/linux/netdevice.h     2014-03-12 13:16:02.000000000 +0000
7871 +++ linux-3.10.33-vs2.3.6.8/include/linux/netdevice.h   2014-03-12 13:18:32.000000000 +0000
7872 @@ -1694,6 +1694,7 @@ extern int                init_dummy_netdev(struct net
7873  
7874  extern struct net_device       *dev_get_by_index(struct net *net, int ifindex);
7875  extern struct net_device       *__dev_get_by_index(struct net *net, int ifindex);
7876 +extern struct net_device       *dev_get_by_index_real_rcu(struct net *net, int ifindex);
7877  extern struct net_device       *dev_get_by_index_rcu(struct net *net, int ifindex);
7878  extern int             netdev_get_name(struct net *net, char *name, int ifindex);
7879  extern int             dev_restart(struct net_device *dev);
7880 diff -NurpP --minimal linux-3.10.33/include/linux/nsproxy.h linux-3.10.33-vs2.3.6.8/include/linux/nsproxy.h
7881 --- linux-3.10.33/include/linux/nsproxy.h       2013-02-19 13:58:51.000000000 +0000
7882 +++ linux-3.10.33-vs2.3.6.8/include/linux/nsproxy.h     2013-08-22 20:30:00.000000000 +0000
7883 @@ -3,6 +3,7 @@
7884  
7885  #include <linux/spinlock.h>
7886  #include <linux/sched.h>
7887 +#include <linux/vserver/debug.h>
7888  
7889  struct mnt_namespace;
7890  struct uts_namespace;
7891 @@ -63,6 +64,7 @@ static inline struct nsproxy *task_nspro
7892  }
7893  
7894  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
7895 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
7896  void exit_task_namespaces(struct task_struct *tsk);
7897  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
7898  void free_nsproxy(struct nsproxy *ns);
7899 @@ -70,16 +72,26 @@ int unshare_nsproxy_namespaces(unsigned
7900         struct cred *, struct fs_struct *);
7901  int __init nsproxy_cache_init(void);
7902  
7903 -static inline void put_nsproxy(struct nsproxy *ns)
7904 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
7905 +
7906 +static inline void __get_nsproxy(struct nsproxy *ns,
7907 +       const char *_file, int _line)
7908  {
7909 -       if (atomic_dec_and_test(&ns->count)) {
7910 -               free_nsproxy(ns);
7911 -       }
7912 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
7913 +               ns, atomic_read(&ns->count), _file, _line);
7914 +       atomic_inc(&ns->count);
7915  }
7916  
7917 -static inline void get_nsproxy(struct nsproxy *ns)
7918 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
7919 +
7920 +static inline void __put_nsproxy(struct nsproxy *ns,
7921 +       const char *_file, int _line)
7922  {
7923 -       atomic_inc(&ns->count);
7924 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
7925 +               ns, atomic_read(&ns->count), _file, _line);
7926 +       if (atomic_dec_and_test(&ns->count)) {
7927 +               free_nsproxy(ns);
7928 +       }
7929  }
7930  
7931  #endif
7932 diff -NurpP --minimal linux-3.10.33/include/linux/pid.h linux-3.10.33-vs2.3.6.8/include/linux/pid.h
7933 --- linux-3.10.33/include/linux/pid.h   2013-05-31 13:45:28.000000000 +0000
7934 +++ linux-3.10.33-vs2.3.6.8/include/linux/pid.h 2013-08-22 20:30:00.000000000 +0000
7935 @@ -8,7 +8,8 @@ enum pid_type
7936         PIDTYPE_PID,
7937         PIDTYPE_PGID,
7938         PIDTYPE_SID,
7939 -       PIDTYPE_MAX
7940 +       PIDTYPE_MAX,
7941 +       PIDTYPE_REALPID
7942  };
7943  
7944  /*
7945 @@ -172,6 +173,7 @@ static inline pid_t pid_nr(struct pid *p
7946  }
7947  
7948  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
7949 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
7950  pid_t pid_vnr(struct pid *pid);
7951  
7952  #define do_each_pid_task(pid, type, task)                              \
7953 diff -NurpP --minimal linux-3.10.33/include/linux/quotaops.h linux-3.10.33-vs2.3.6.8/include/linux/quotaops.h
7954 --- linux-3.10.33/include/linux/quotaops.h      2012-12-11 03:30:57.000000000 +0000
7955 +++ linux-3.10.33-vs2.3.6.8/include/linux/quotaops.h    2013-08-22 20:30:00.000000000 +0000
7956 @@ -8,6 +8,7 @@
7957  #define _LINUX_QUOTAOPS_
7958  
7959  #include <linux/fs.h>
7960 +#include <linux/vs_dlimit.h>
7961  
7962  #define DQUOT_SPACE_WARN       0x1
7963  #define DQUOT_SPACE_RESERVE    0x2
7964 @@ -205,11 +206,12 @@ static inline void dquot_drop(struct ino
7965  
7966  static inline int dquot_alloc_inode(const struct inode *inode)
7967  {
7968 -       return 0;
7969 +       return dl_alloc_inode(inode);
7970  }
7971  
7972  static inline void dquot_free_inode(const struct inode *inode)
7973  {
7974 +       dl_free_inode(inode);
7975  }
7976  
7977  static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
7978 @@ -220,6 +222,10 @@ static inline int dquot_transfer(struct
7979  static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
7980                 int flags)
7981  {
7982 +       int ret = 0;
7983 +
7984 +       if ((ret = dl_alloc_space(inode, number)))
7985 +               return ret;
7986         if (!(flags & DQUOT_SPACE_RESERVE))
7987                 inode_add_bytes(inode, number);
7988         return 0;
7989 @@ -230,6 +236,7 @@ static inline void __dquot_free_space(st
7990  {
7991         if (!(flags & DQUOT_SPACE_RESERVE))
7992                 inode_sub_bytes(inode, number);
7993 +       dl_free_space(inode, number);
7994  }
7995  
7996  static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
7997 diff -NurpP --minimal linux-3.10.33/include/linux/sched.h linux-3.10.33-vs2.3.6.8/include/linux/sched.h
7998 --- linux-3.10.33/include/linux/sched.h 2014-03-12 13:16:02.000000000 +0000
7999 +++ linux-3.10.33-vs2.3.6.8/include/linux/sched.h       2013-11-30 07:53:00.000000000 +0000
8000 @@ -1237,6 +1237,14 @@ struct task_struct {
8001  #endif
8002         struct seccomp seccomp;
8003  
8004 +/* vserver context data */
8005 +       struct vx_info *vx_info;
8006 +       struct nx_info *nx_info;
8007 +
8008 +       vxid_t xid;
8009 +       vnid_t nid;
8010 +       vtag_t tag;
8011 +
8012  /* Thread group tracking */
8013         u32 parent_exec_id;
8014         u32 self_exec_id;
8015 @@ -1480,6 +1488,11 @@ struct pid_namespace;
8016  pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
8017                         struct pid_namespace *ns);
8018  
8019 +#include <linux/vserver/base.h>
8020 +#include <linux/vserver/context.h>
8021 +#include <linux/vserver/debug.h>
8022 +#include <linux/vserver/pid.h>
8023 +
8024  static inline pid_t task_pid_nr(struct task_struct *tsk)
8025  {
8026         return tsk->pid;
8027 @@ -1493,7 +1506,8 @@ static inline pid_t task_pid_nr_ns(struc
8028  
8029  static inline pid_t task_pid_vnr(struct task_struct *tsk)
8030  {
8031 -       return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
8032 +       // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
8033 +       return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
8034  }
8035  
8036  
8037 @@ -1506,7 +1520,7 @@ pid_t task_tgid_nr_ns(struct task_struct
8038  
8039  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
8040  {
8041 -       return pid_vnr(task_tgid(tsk));
8042 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
8043  }
8044  
8045  
8046 diff -NurpP --minimal linux-3.10.33/include/linux/shmem_fs.h linux-3.10.33-vs2.3.6.8/include/linux/shmem_fs.h
8047 --- linux-3.10.33/include/linux/shmem_fs.h      2012-12-11 03:30:57.000000000 +0000
8048 +++ linux-3.10.33-vs2.3.6.8/include/linux/shmem_fs.h    2013-08-22 20:30:00.000000000 +0000
8049 @@ -9,6 +9,9 @@
8050  
8051  /* inode in-kernel data */
8052  
8053 +#define TMPFS_SUPER_MAGIC      0x01021994
8054 +
8055 +
8056  struct shmem_inode_info {
8057         spinlock_t              lock;
8058         unsigned long           flags;
8059 diff -NurpP --minimal linux-3.10.33/include/linux/stat.h linux-3.10.33-vs2.3.6.8/include/linux/stat.h
8060 --- linux-3.10.33/include/linux/stat.h  2012-12-11 03:30:57.000000000 +0000
8061 +++ linux-3.10.33-vs2.3.6.8/include/linux/stat.h        2013-08-22 20:30:00.000000000 +0000
8062 @@ -25,6 +25,7 @@ struct kstat {
8063         unsigned int    nlink;
8064         kuid_t          uid;
8065         kgid_t          gid;
8066 +       ktag_t          tag;
8067         dev_t           rdev;
8068         loff_t          size;
8069         struct timespec  atime;
8070 diff -NurpP --minimal linux-3.10.33/include/linux/sunrpc/auth.h linux-3.10.33-vs2.3.6.8/include/linux/sunrpc/auth.h
8071 --- linux-3.10.33/include/linux/sunrpc/auth.h   2013-07-14 17:01:33.000000000 +0000
8072 +++ linux-3.10.33-vs2.3.6.8/include/linux/sunrpc/auth.h 2013-08-22 20:30:00.000000000 +0000
8073 @@ -28,6 +28,7 @@ struct rpcsec_gss_info;
8074  struct auth_cred {
8075         kuid_t  uid;
8076         kgid_t  gid;
8077 +       ktag_t  tag;
8078         struct group_info *group_info;
8079         const char *principal;
8080         unsigned char machine_cred : 1;
8081 diff -NurpP --minimal linux-3.10.33/include/linux/sunrpc/clnt.h linux-3.10.33-vs2.3.6.8/include/linux/sunrpc/clnt.h
8082 --- linux-3.10.33/include/linux/sunrpc/clnt.h   2013-07-14 17:01:33.000000000 +0000
8083 +++ linux-3.10.33-vs2.3.6.8/include/linux/sunrpc/clnt.h 2013-08-22 20:30:00.000000000 +0000
8084 @@ -49,7 +49,8 @@ struct rpc_clnt {
8085         unsigned int            cl_softrtry : 1,/* soft timeouts */
8086                                 cl_discrtry : 1,/* disconnect before retry */
8087                                 cl_autobind : 1,/* use getport() */
8088 -                               cl_chatty   : 1;/* be verbose */
8089 +                               cl_chatty   : 1,/* be verbose */
8090 +                               cl_tag      : 1;/* context tagging */
8091  
8092         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
8093         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
8094 diff -NurpP --minimal linux-3.10.33/include/linux/sysfs.h linux-3.10.33-vs2.3.6.8/include/linux/sysfs.h
8095 --- linux-3.10.33/include/linux/sysfs.h 2013-05-31 13:45:28.000000000 +0000
8096 +++ linux-3.10.33-vs2.3.6.8/include/linux/sysfs.h       2013-08-22 20:30:00.000000000 +0000
8097 @@ -19,6 +19,8 @@
8098  #include <linux/kobject_ns.h>
8099  #include <linux/atomic.h>
8100  
8101 +#define SYSFS_SUPER_MAGIC      0x62656572
8102 +
8103  struct kobject;
8104  struct module;
8105  enum kobj_ns_type;
8106 diff -NurpP --minimal linux-3.10.33/include/linux/types.h linux-3.10.33-vs2.3.6.8/include/linux/types.h
8107 --- linux-3.10.33/include/linux/types.h 2013-02-19 13:58:52.000000000 +0000
8108 +++ linux-3.10.33-vs2.3.6.8/include/linux/types.h       2013-08-22 20:30:00.000000000 +0000
8109 @@ -32,6 +32,9 @@ typedef __kernel_uid32_t      uid_t;
8110  typedef __kernel_gid32_t       gid_t;
8111  typedef __kernel_uid16_t        uid16_t;
8112  typedef __kernel_gid16_t        gid16_t;
8113 +typedef unsigned int           vxid_t;
8114 +typedef unsigned int           vnid_t;
8115 +typedef unsigned int           vtag_t;
8116  
8117  typedef unsigned long          uintptr_t;
8118  
8119 diff -NurpP --minimal linux-3.10.33/include/linux/uidgid.h linux-3.10.33-vs2.3.6.8/include/linux/uidgid.h
8120 --- linux-3.10.33/include/linux/uidgid.h        2012-12-11 03:30:57.000000000 +0000
8121 +++ linux-3.10.33-vs2.3.6.8/include/linux/uidgid.h      2013-08-22 20:30:00.000000000 +0000
8122 @@ -23,13 +23,17 @@ typedef struct {
8123         uid_t val;
8124  } kuid_t;
8125  
8126 -
8127  typedef struct {
8128         gid_t val;
8129  } kgid_t;
8130  
8131 +typedef struct {
8132 +       vtag_t val;
8133 +} ktag_t;
8134 +
8135  #define KUIDT_INIT(value) (kuid_t){ value }
8136  #define KGIDT_INIT(value) (kgid_t){ value }
8137 +#define KTAGT_INIT(value) (ktag_t){ value }
8138  
8139  static inline uid_t __kuid_val(kuid_t uid)
8140  {
8141 @@ -41,10 +45,16 @@ static inline gid_t __kgid_val(kgid_t gi
8142         return gid.val;
8143  }
8144  
8145 +static inline vtag_t __ktag_val(ktag_t tag)
8146 +{
8147 +       return tag.val;
8148 +}
8149 +
8150  #else
8151  
8152  typedef uid_t kuid_t;
8153  typedef gid_t kgid_t;
8154 +typedef vtag_t ktag_t;
8155  
8156  static inline uid_t __kuid_val(kuid_t uid)
8157  {
8158 @@ -56,16 +66,24 @@ static inline gid_t __kgid_val(kgid_t gi
8159         return gid;
8160  }
8161  
8162 +static inline vtag_t __ktag_val(ktag_t tag)
8163 +{
8164 +       return tag;
8165 +}
8166 +
8167  #define KUIDT_INIT(value) ((kuid_t) value )
8168  #define KGIDT_INIT(value) ((kgid_t) value )
8169 +#define KTAGT_INIT(value) ((ktag_t) value )
8170  
8171  #endif
8172  
8173  #define GLOBAL_ROOT_UID KUIDT_INIT(0)
8174  #define GLOBAL_ROOT_GID KGIDT_INIT(0)
8175 +#define GLOBAL_ROOT_TAG KTAGT_INIT(0)
8176  
8177  #define INVALID_UID KUIDT_INIT(-1)
8178  #define INVALID_GID KGIDT_INIT(-1)
8179 +#define INVALID_TAG KTAGT_INIT(-1)
8180  
8181  static inline bool uid_eq(kuid_t left, kuid_t right)
8182  {
8183 @@ -77,6 +95,11 @@ static inline bool gid_eq(kgid_t left, k
8184         return __kgid_val(left) == __kgid_val(right);
8185  }
8186  
8187 +static inline bool tag_eq(ktag_t left, ktag_t right)
8188 +{
8189 +       return __ktag_val(left) == __ktag_val(right);
8190 +}
8191 +
8192  static inline bool uid_gt(kuid_t left, kuid_t right)
8193  {
8194         return __kuid_val(left) > __kuid_val(right);
8195 @@ -127,13 +150,21 @@ static inline bool gid_valid(kgid_t gid)
8196         return !gid_eq(gid, INVALID_GID);
8197  }
8198  
8199 +static inline bool tag_valid(ktag_t tag)
8200 +{
8201 +       return !tag_eq(tag, INVALID_TAG);
8202 +}
8203 +
8204  #ifdef CONFIG_USER_NS
8205  
8206  extern kuid_t make_kuid(struct user_namespace *from, uid_t uid);
8207  extern kgid_t make_kgid(struct user_namespace *from, gid_t gid);
8208 +extern krag_t make_ktag(struct user_namespace *from, gid_t gid);
8209  
8210  extern uid_t from_kuid(struct user_namespace *to, kuid_t uid);
8211  extern gid_t from_kgid(struct user_namespace *to, kgid_t gid);
8212 +extern vtag_t from_ktag(struct user_namespace *to, ktag_t tag);
8213 +
8214  extern uid_t from_kuid_munged(struct user_namespace *to, kuid_t uid);
8215  extern gid_t from_kgid_munged(struct user_namespace *to, kgid_t gid);
8216  
8217 @@ -159,6 +190,11 @@ static inline kgid_t make_kgid(struct us
8218         return KGIDT_INIT(gid);
8219  }
8220  
8221 +static inline ktag_t make_ktag(struct user_namespace *from, vtag_t tag)
8222 +{
8223 +       return KTAGT_INIT(tag);
8224 +}
8225 +
8226  static inline uid_t from_kuid(struct user_namespace *to, kuid_t kuid)
8227  {
8228         return __kuid_val(kuid);
8229 @@ -169,6 +205,11 @@ static inline gid_t from_kgid(struct use
8230         return __kgid_val(kgid);
8231  }
8232  
8233 +static inline vtag_t from_ktag(struct user_namespace *to, ktag_t ktag)
8234 +{
8235 +       return __ktag_val(ktag);
8236 +}
8237 +
8238  static inline uid_t from_kuid_munged(struct user_namespace *to, kuid_t kuid)
8239  {
8240         uid_t uid = from_kuid(to, kuid);
8241 diff -NurpP --minimal linux-3.10.33/include/linux/vroot.h linux-3.10.33-vs2.3.6.8/include/linux/vroot.h
8242 --- linux-3.10.33/include/linux/vroot.h 1970-01-01 00:00:00.000000000 +0000
8243 +++ linux-3.10.33-vs2.3.6.8/include/linux/vroot.h       2013-08-22 20:30:00.000000000 +0000
8244 @@ -0,0 +1,51 @@
8245 +
8246 +/*
8247 + * include/linux/vroot.h
8248 + *
8249 + * written by Herbert Pötzl, 9/11/2002
8250 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
8251 + *
8252 + * Copyright (C) 2002-2007 by Herbert Pötzl.
8253 + * Redistribution of this file is permitted under the
8254 + * GNU General Public License.
8255 + */
8256 +
8257 +#ifndef _LINUX_VROOT_H
8258 +#define _LINUX_VROOT_H
8259 +
8260 +
8261 +#ifdef __KERNEL__
8262 +
8263 +/* Possible states of device */
8264 +enum {
8265 +       Vr_unbound,
8266 +       Vr_bound,
8267 +};
8268 +
8269 +struct vroot_device {
8270 +       int             vr_number;
8271 +       int             vr_refcnt;
8272 +
8273 +       struct semaphore        vr_ctl_mutex;
8274 +       struct block_device    *vr_device;
8275 +       int                     vr_state;
8276 +};
8277 +
8278 +
8279 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
8280 +
8281 +extern int register_vroot_grb(vroot_grb_func *);
8282 +extern int unregister_vroot_grb(vroot_grb_func *);
8283 +
8284 +#endif /* __KERNEL__ */
8285 +
8286 +#define MAX_VROOT_DEFAULT      8
8287 +
8288 +/*
8289 + * IOCTL commands --- we will commandeer 0x56 ('V')
8290 + */
8291 +
8292 +#define VROOT_SET_DEV          0x5600
8293 +#define VROOT_CLR_DEV          0x5601
8294 +
8295 +#endif /* _LINUX_VROOT_H */
8296 diff -NurpP --minimal linux-3.10.33/include/linux/vs_base.h linux-3.10.33-vs2.3.6.8/include/linux/vs_base.h
8297 --- linux-3.10.33/include/linux/vs_base.h       1970-01-01 00:00:00.000000000 +0000
8298 +++ linux-3.10.33-vs2.3.6.8/include/linux/vs_base.h     2013-08-22 20:30:00.000000000 +0000
8299 @@ -0,0 +1,10 @@
8300 +#ifndef _VS_BASE_H
8301 +#define _VS_BASE_H
8302 +
8303 +#include "vserver/base.h"
8304 +#include "vserver/check.h"
8305 +#include "vserver/debug.h"
8306 +
8307 +#else
8308 +#warning duplicate inclusion
8309 +#endif
8310 diff -NurpP --minimal linux-3.10.33/include/linux/vs_context.h linux-3.10.33-vs2.3.6.8/include/linux/vs_context.h
8311 --- linux-3.10.33/include/linux/vs_context.h    1970-01-01 00:00:00.000000000 +0000
8312 +++ linux-3.10.33-vs2.3.6.8/include/linux/vs_context.h  2013-08-22 20:30:00.000000000 +0000
8313 @@ -0,0 +1,242 @@
8314 +#ifndef _VS_CONTEXT_H
8315 +#define _VS_CONTEXT_H
8316 +
8317 +#include "vserver/base.h"
8318 +#include "vserver/check.h"
8319 +#include "vserver/context.h"
8320 +#include "vserver/history.h"
8321 +#include "vserver/debug.h"
8322 +
8323 +#include <linux/sched.h>
8324 +
8325 +
8326 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
8327 +
8328 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
8329 +       const char *_file, int _line, void *_here)
8330 +{
8331 +       if (!vxi)
8332 +               return NULL;
8333 +
8334 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
8335 +               vxi, vxi ? vxi->vx_id : 0,
8336 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8337 +               _file, _line);
8338 +       __vxh_get_vx_info(vxi, _here);
8339 +
8340 +       atomic_inc(&vxi->vx_usecnt);
8341 +       return vxi;
8342 +}
8343 +
8344 +
8345 +extern void free_vx_info(struct vx_info *);
8346 +
8347 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
8348 +
8349 +static inline void __put_vx_info(struct vx_info *vxi,
8350 +       const char *_file, int _line, void *_here)
8351 +{
8352 +       if (!vxi)
8353 +               return;
8354 +
8355 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
8356 +               vxi, vxi ? vxi->vx_id : 0,
8357 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8358 +               _file, _line);
8359 +       __vxh_put_vx_info(vxi, _here);
8360 +
8361 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
8362 +               free_vx_info(vxi);
8363 +}
8364 +
8365 +
8366 +#define init_vx_info(p, i) \
8367 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
8368 +
8369 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
8370 +       const char *_file, int _line, void *_here)
8371 +{
8372 +       if (vxi) {
8373 +               vxlprintk(VXD_CBIT(xid, 3),
8374 +                       "init_vx_info(%p[#%d.%d])",
8375 +                       vxi, vxi ? vxi->vx_id : 0,
8376 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8377 +                       _file, _line);
8378 +               __vxh_init_vx_info(vxi, vxp, _here);
8379 +
8380 +               atomic_inc(&vxi->vx_usecnt);
8381 +       }
8382 +       *vxp = vxi;
8383 +}
8384 +
8385 +
8386 +#define set_vx_info(p, i) \
8387 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
8388 +
8389 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
8390 +       const char *_file, int _line, void *_here)
8391 +{
8392 +       struct vx_info *vxo;
8393 +
8394 +       if (!vxi)
8395 +               return;
8396 +
8397 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
8398 +               vxi, vxi ? vxi->vx_id : 0,
8399 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8400 +               _file, _line);
8401 +       __vxh_set_vx_info(vxi, vxp, _here);
8402 +
8403 +       atomic_inc(&vxi->vx_usecnt);
8404 +       vxo = xchg(vxp, vxi);
8405 +       BUG_ON(vxo);
8406 +}
8407 +
8408 +
8409 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
8410 +
8411 +static inline void __clr_vx_info(struct vx_info **vxp,
8412 +       const char *_file, int _line, void *_here)
8413 +{
8414 +       struct vx_info *vxo;
8415 +
8416 +       vxo = xchg(vxp, NULL);
8417 +       if (!vxo)
8418 +               return;
8419 +
8420 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
8421 +               vxo, vxo ? vxo->vx_id : 0,
8422 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
8423 +               _file, _line);
8424 +       __vxh_clr_vx_info(vxo, vxp, _here);
8425 +
8426 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
8427 +               free_vx_info(vxo);
8428 +}
8429 +
8430 +
8431 +#define claim_vx_info(v, p) \
8432 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
8433 +
8434 +static inline void __claim_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), "claim_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_claim_vx_info(vxi, task, _here);
8444 +
8445 +       atomic_inc(&vxi->vx_tasks);
8446 +}
8447 +
8448 +
8449 +extern void unhash_vx_info(struct vx_info *);
8450 +
8451 +#define release_vx_info(v, p) \
8452 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
8453 +
8454 +static inline void __release_vx_info(struct vx_info *vxi,
8455 +       struct task_struct *task,
8456 +       const char *_file, int _line, void *_here)
8457 +{
8458 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
8459 +               vxi, vxi ? vxi->vx_id : 0,
8460 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8461 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
8462 +               task, _file, _line);
8463 +       __vxh_release_vx_info(vxi, task, _here);
8464 +
8465 +       might_sleep();
8466 +
8467 +       if (atomic_dec_and_test(&vxi->vx_tasks))
8468 +               unhash_vx_info(vxi);
8469 +}
8470 +
8471 +
8472 +#define task_get_vx_info(p) \
8473 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
8474 +
8475 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
8476 +       const char *_file, int _line, void *_here)
8477 +{
8478 +       struct vx_info *vxi;
8479 +
8480 +       task_lock(p);
8481 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
8482 +               p, _file, _line);
8483 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
8484 +       task_unlock(p);
8485 +       return vxi;
8486 +}
8487 +
8488 +
8489 +static inline void __wakeup_vx_info(struct vx_info *vxi)
8490 +{
8491 +       if (waitqueue_active(&vxi->vx_wait))
8492 +               wake_up_interruptible(&vxi->vx_wait);
8493 +}
8494 +
8495 +
8496 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
8497 +
8498 +static inline void __enter_vx_info(struct vx_info *vxi,
8499 +       struct vx_info_save *vxis, const char *_file, int _line)
8500 +{
8501 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
8502 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
8503 +               current->xid, current->vx_info, _file, _line);
8504 +       vxis->vxi = xchg(&current->vx_info, vxi);
8505 +       vxis->xid = current->xid;
8506 +       current->xid = vxi ? vxi->vx_id : 0;
8507 +}
8508 +
8509 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
8510 +
8511 +static inline void __leave_vx_info(struct vx_info_save *vxis,
8512 +       const char *_file, int _line)
8513 +{
8514 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
8515 +               vxis, vxis->xid, vxis->vxi, current,
8516 +               current->xid, current->vx_info, _file, _line);
8517 +       (void)xchg(&current->vx_info, vxis->vxi);
8518 +       current->xid = vxis->xid;
8519 +}
8520 +
8521 +
8522 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
8523 +{
8524 +       vxis->vxi = xchg(&current->vx_info, NULL);
8525 +       vxis->xid = xchg(&current->xid, (vxid_t)0);
8526 +}
8527 +
8528 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
8529 +{
8530 +       (void)xchg(&current->xid, vxis->xid);
8531 +       (void)xchg(&current->vx_info, vxis->vxi);
8532 +}
8533 +
8534 +#define task_is_init(p) \
8535 +       __task_is_init(p, __FILE__, __LINE__, __HERE__)
8536 +
8537 +static inline int __task_is_init(struct task_struct *p,
8538 +       const char *_file, int _line, void *_here)
8539 +{
8540 +       int is_init = is_global_init(p);
8541 +
8542 +       task_lock(p);
8543 +       if (p->vx_info)
8544 +               is_init = p->vx_info->vx_initpid == p->pid;
8545 +       task_unlock(p);
8546 +       return is_init;
8547 +}
8548 +
8549 +extern void exit_vx_info(struct task_struct *, int);
8550 +extern void exit_vx_info_early(struct task_struct *, int);
8551 +
8552 +
8553 +#else
8554 +#warning duplicate inclusion
8555 +#endif
8556 diff -NurpP --minimal linux-3.10.33/include/linux/vs_cowbl.h linux-3.10.33-vs2.3.6.8/include/linux/vs_cowbl.h
8557 --- linux-3.10.33/include/linux/vs_cowbl.h      1970-01-01 00:00:00.000000000 +0000
8558 +++ linux-3.10.33-vs2.3.6.8/include/linux/vs_cowbl.h    2013-08-22 20:30:00.000000000 +0000
8559 @@ -0,0 +1,48 @@
8560 +#ifndef _VS_COWBL_H
8561 +#define _VS_COWBL_H
8562 +
8563 +#include <linux/fs.h>
8564 +#include <linux/dcache.h>
8565 +#include <linux/namei.h>
8566 +#include <linux/slab.h>
8567 +
8568 +extern struct dentry *cow_break_link(const char *pathname);
8569 +
8570 +static inline int cow_check_and_break(struct path *path)
8571 +{
8572 +       struct inode *inode = path->dentry->d_inode;
8573 +       int error = 0;
8574 +
8575 +       /* do we need this check? */
8576 +       if (IS_RDONLY(inode))
8577 +               return -EROFS;
8578 +
8579 +       if (IS_COW(inode)) {
8580 +               if (IS_COW_LINK(inode)) {
8581 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
8582 +                       char *pp, *buf;
8583 +
8584 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
8585 +                       if (!buf) {
8586 +                               return -ENOMEM;
8587 +                       }
8588 +                       pp = d_path(path, buf, PATH_MAX);
8589 +                       new_dentry = cow_break_link(pp);
8590 +                       kfree(buf);
8591 +                       if (!IS_ERR(new_dentry)) {
8592 +                               path->dentry = new_dentry;
8593 +                               dput(old_dentry);
8594 +                       } else
8595 +                               error = PTR_ERR(new_dentry);
8596 +               } else {
8597 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
8598 +                       inode->i_ctime = CURRENT_TIME;
8599 +                       mark_inode_dirty(inode);
8600 +               }
8601 +       }
8602 +       return error;
8603 +}
8604 +
8605 +#else
8606 +#warning duplicate inclusion
8607 +#endif
8608 diff -NurpP --minimal linux-3.10.33/include/linux/vs_cvirt.h linux-3.10.33-vs2.3.6.8/include/linux/vs_cvirt.h
8609 --- linux-3.10.33/include/linux/vs_cvirt.h      1970-01-01 00:00:00.000000000 +0000
8610 +++ linux-3.10.33-vs2.3.6.8/include/linux/vs_cvirt.h    2013-08-22 20:30:00.000000000 +0000
8611 @@ -0,0 +1,50 @@
8612 +#ifndef _VS_CVIRT_H
8613 +#define _VS_CVIRT_H
8614 +
8615 +#include "vserver/cvirt.h"
8616 +#include "vserver/context.h"
8617 +#include "vserver/base.h"
8618 +#include "vserver/check.h"
8619 +#include "vserver/debug.h"
8620 +
8621 +
8622 +static inline void vx_activate_task(struct task_struct *p)
8623 +{
8624 +       struct vx_info *vxi;
8625 +
8626 +       if ((vxi = p->vx_info)) {
8627 +               vx_update_load(vxi);
8628 +               atomic_inc(&vxi->cvirt.nr_running);
8629 +       }
8630 +}
8631 +
8632 +static inline void vx_deactivate_task(struct task_struct *p)
8633 +{
8634 +       struct vx_info *vxi;
8635 +
8636 +       if ((vxi = p->vx_info)) {
8637 +               vx_update_load(vxi);
8638 +               atomic_dec(&vxi->cvirt.nr_running);
8639 +       }
8640 +}
8641 +
8642 +static inline void vx_uninterruptible_inc(struct task_struct *p)
8643 +{
8644 +       struct vx_info *vxi;
8645 +
8646 +       if ((vxi = p->vx_info))
8647 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
8648 +}
8649 +
8650 +static inline void vx_uninterruptible_dec(struct task_struct *p)
8651 +{
8652 +       struct vx_info *vxi;
8653 +
8654 +       if ((vxi = p->vx_info))
8655 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
8656 +}
8657 +
8658 +
8659 +#else
8660 +#warning duplicate inclusion
8661 +#endif
8662 diff -NurpP --minimal linux-3.10.33/include/linux/vs_device.h linux-3.10.33-vs2.3.6.8/include/linux/vs_device.h
8663 --- linux-3.10.33/include/linux/vs_device.h     1970-01-01 00:00:00.000000000 +0000
8664 +++ linux-3.10.33-vs2.3.6.8/include/linux/vs_device.h   2013-08-22 20:30:00.000000000 +0000
8665 @@ -0,0 +1,45 @@
8666 +#ifndef _VS_DEVICE_H
8667 +#define _VS_DEVICE_H
8668 +
8669 +#include "vserver/base.h"
8670 +#include "vserver/device.h"
8671 +#include "vserver/debug.h"
8672 +
8673 +
8674 +#ifdef CONFIG_VSERVER_DEVICE
8675 +
8676 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
8677 +
8678 +#define vs_device_perm(v, d, m, p) \
8679 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
8680 +
8681 +#else
8682 +
8683 +static inline
8684 +int vs_map_device(struct vx_info *vxi,
8685 +       dev_t device, dev_t *target, umode_t mode)
8686 +{
8687 +       if (target)
8688 +               *target = device;
8689 +       return ~0;
8690 +}
8691 +
8692 +#define vs_device_perm(v, d, m, p) ((p) == (p))
8693 +
8694 +#endif
8695 +
8696 +
8697 +#define vs_map_chrdev(d, t, p) \
8698 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
8699 +#define vs_map_blkdev(d, t, p) \
8700 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
8701 +
8702 +#define vs_chrdev_perm(d, p) \
8703 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
8704 +#define vs_blkdev_perm(d, p) \
8705 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
8706 +
8707 +
8708 +#else
8709 +#warning duplicate inclusion
8710 +#endif
8711 diff -NurpP --minimal linux-3.10.33/include/linux/vs_dlimit.h linux-3.10.33-vs2.3.6.8/include/linux/vs_dlimit.h
8712 --- linux-3.10.33/include/linux/vs_dlimit.h     1970-01-01 00:00:00.000000000 +0000
8713 +++ linux-3.10.33-vs2.3.6.8/include/linux/vs_dlimit.h   2013-08-22 20:30:00.000000000 +0000
8714 @@ -0,0 +1,215 @@
8715 +#ifndef _VS_DLIMIT_H
8716 +#define _VS_DLIMIT_H
8717 +
8718 +#include <linux/fs.h>
8719 +
8720 +#include "vserver/dlimit.h"
8721 +#include "vserver/base.h"
8722 +#include "vserver/debug.h"
8723 +
8724 +
8725 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
8726 +
8727 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
8728 +       const char *_file, int _line)
8729 +{
8730 +       if (!dli)
8731 +               return NULL;
8732 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
8733 +               dli, dli ? dli->dl_tag : 0,
8734 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
8735 +               _file, _line);
8736 +       atomic_inc(&dli->dl_usecnt);
8737 +       return dli;
8738 +}
8739 +
8740 +
8741 +#define free_dl_info(i) \
8742 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
8743 +
8744 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
8745 +
8746 +static inline void __put_dl_info(struct dl_info *dli,
8747 +       const char *_file, int _line)
8748 +{
8749 +       if (!dli)
8750 +               return;
8751 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
8752 +               dli, dli ? dli->dl_tag : 0,
8753 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
8754 +               _file, _line);
8755 +       if (atomic_dec_and_test(&dli->dl_usecnt))
8756 +               free_dl_info(dli);
8757 +}
8758 +
8759 +
8760 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
8761 +
8762 +static inline int __dl_alloc_space(struct super_block *sb,
8763 +       vtag_t tag, dlsize_t nr, const char *file, int line)
8764 +{
8765 +       struct dl_info *dli = NULL;
8766 +       int ret = 0;
8767 +
8768 +       if (nr == 0)
8769 +               goto out;
8770 +       dli = locate_dl_info(sb, tag);
8771 +       if (!dli)
8772 +               goto out;
8773 +
8774 +       spin_lock(&dli->dl_lock);
8775 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
8776 +       if (!ret)
8777 +               dli->dl_space_used += nr;
8778 +       spin_unlock(&dli->dl_lock);
8779 +       put_dl_info(dli);
8780 +out:
8781 +       vxlprintk(VXD_CBIT(dlim, 1),
8782 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
8783 +               sb, tag, __dlimit_char(dli), (long long)nr,
8784 +               ret, file, line);
8785 +       return ret ? -ENOSPC : 0;
8786 +}
8787 +
8788 +static inline void __dl_free_space(struct super_block *sb,
8789 +       vtag_t tag, dlsize_t nr, const char *_file, int _line)
8790 +{
8791 +       struct dl_info *dli = NULL;
8792 +
8793 +       if (nr == 0)
8794 +               goto out;
8795 +       dli = locate_dl_info(sb, tag);
8796 +       if (!dli)
8797 +               goto out;
8798 +
8799 +       spin_lock(&dli->dl_lock);
8800 +       if (dli->dl_space_used > nr)
8801 +               dli->dl_space_used -= nr;
8802 +       else
8803 +               dli->dl_space_used = 0;
8804 +       spin_unlock(&dli->dl_lock);
8805 +       put_dl_info(dli);
8806 +out:
8807 +       vxlprintk(VXD_CBIT(dlim, 1),
8808 +               "FREE  (%p,#%d)%c %lld bytes",
8809 +               sb, tag, __dlimit_char(dli), (long long)nr,
8810 +               _file, _line);
8811 +}
8812 +
8813 +static inline int __dl_alloc_inode(struct super_block *sb,
8814 +       vtag_t tag, const char *_file, int _line)
8815 +{
8816 +       struct dl_info *dli;
8817 +       int ret = 0;
8818 +
8819 +       dli = locate_dl_info(sb, tag);
8820 +       if (!dli)
8821 +               goto out;
8822 +
8823 +       spin_lock(&dli->dl_lock);
8824 +       dli->dl_inodes_used++;
8825 +       ret = (dli->dl_inodes_used > dli->dl_inodes_total);
8826 +       spin_unlock(&dli->dl_lock);
8827 +       put_dl_info(dli);
8828 +out:
8829 +       vxlprintk(VXD_CBIT(dlim, 0),
8830 +               "ALLOC (%p,#%d)%c inode (%d)",
8831 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
8832 +       return ret ? -ENOSPC : 0;
8833 +}
8834 +
8835 +static inline void __dl_free_inode(struct super_block *sb,
8836 +       vtag_t tag, const char *_file, int _line)
8837 +{
8838 +       struct dl_info *dli;
8839 +
8840 +       dli = locate_dl_info(sb, tag);
8841 +       if (!dli)
8842 +               goto out;
8843 +
8844 +       spin_lock(&dli->dl_lock);
8845 +       if (dli->dl_inodes_used > 1)
8846 +               dli->dl_inodes_used--;
8847 +       else
8848 +               dli->dl_inodes_used = 0;
8849 +       spin_unlock(&dli->dl_lock);
8850 +       put_dl_info(dli);
8851 +out:
8852 +       vxlprintk(VXD_CBIT(dlim, 0),
8853 +               "FREE  (%p,#%d)%c inode",
8854 +               sb, tag, __dlimit_char(dli), _file, _line);
8855 +}
8856 +
8857 +static inline void __dl_adjust_block(struct super_block *sb, vtag_t tag,
8858 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
8859 +       const char *_file, int _line)
8860 +{
8861 +       struct dl_info *dli;
8862 +       uint64_t broot, bfree;
8863 +
8864 +       dli = locate_dl_info(sb, tag);
8865 +       if (!dli)
8866 +               return;
8867 +
8868 +       spin_lock(&dli->dl_lock);
8869 +       broot = (dli->dl_space_total -
8870 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
8871 +               >> sb->s_blocksize_bits;
8872 +       bfree = (dli->dl_space_total - dli->dl_space_used)
8873 +                       >> sb->s_blocksize_bits;
8874 +       spin_unlock(&dli->dl_lock);
8875 +
8876 +       vxlprintk(VXD_CBIT(dlim, 2),
8877 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
8878 +               (long long)bfree, (long long)broot,
8879 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
8880 +               _file, _line);
8881 +       if (free_blocks) {
8882 +               if (*free_blocks > bfree)
8883 +                       *free_blocks = bfree;
8884 +       }
8885 +       if (root_blocks) {
8886 +               if (*root_blocks > broot)
8887 +                       *root_blocks = broot;
8888 +       }
8889 +       put_dl_info(dli);
8890 +}
8891 +
8892 +#define dl_prealloc_space(in, bytes) \
8893 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8894 +               __FILE__, __LINE__ )
8895 +
8896 +#define dl_alloc_space(in, bytes) \
8897 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8898 +               __FILE__, __LINE__ )
8899 +
8900 +#define dl_reserve_space(in, bytes) \
8901 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8902 +               __FILE__, __LINE__ )
8903 +
8904 +#define dl_claim_space(in, bytes) (0)
8905 +
8906 +#define dl_release_space(in, bytes) \
8907 +       __dl_free_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8908 +               __FILE__, __LINE__ )
8909 +
8910 +#define dl_free_space(in, bytes) \
8911 +       __dl_free_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8912 +               __FILE__, __LINE__ )
8913 +
8914 +
8915 +
8916 +#define dl_alloc_inode(in) \
8917 +       __dl_alloc_inode((in)->i_sb, i_tag_read(in), __FILE__, __LINE__ )
8918 +
8919 +#define dl_free_inode(in) \
8920 +       __dl_free_inode((in)->i_sb, i_tag_read(in), __FILE__, __LINE__ )
8921 +
8922 +
8923 +#define dl_adjust_block(sb, tag, fb, rb) \
8924 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
8925 +
8926 +
8927 +#else
8928 +#warning duplicate inclusion
8929 +#endif
8930 diff -NurpP --minimal linux-3.10.33/include/linux/vs_inet.h linux-3.10.33-vs2.3.6.8/include/linux/vs_inet.h
8931 --- linux-3.10.33/include/linux/vs_inet.h       1970-01-01 00:00:00.000000000 +0000
8932 +++ linux-3.10.33-vs2.3.6.8/include/linux/vs_inet.h     2013-08-22 20:30:00.000000000 +0000
8933 @@ -0,0 +1,364 @@
8934 +#ifndef _VS_INET_H
8935 +#define _VS_INET_H
8936 +
8937 +#include "vserver/base.h"
8938 +#include "vserver/network.h"
8939 +#include "vserver/debug.h"
8940 +
8941 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
8942 +
8943 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
8944 +                       NIPQUAD((a)->mask), (a)->type
8945 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
8946 +
8947 +#define NIPQUAD(addr) \
8948 +       ((unsigned char *)&addr)[0], \
8949 +       ((unsigned char *)&addr)[1], \
8950 +       ((unsigned char *)&addr)[2], \
8951 +       ((unsigned char *)&addr)[3]
8952 +
8953 +#define NIPQUAD_FMT "%u.%u.%u.%u"
8954 +
8955 +
8956 +static inline
8957 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
8958 +{
8959 +       __be32 ip = nxa->ip[0].s_addr;
8960 +       __be32 mask = nxa->mask.s_addr;
8961 +       __be32 bcast = ip | ~mask;
8962 +       int ret = 0;
8963 +
8964 +       switch (nxa->type & tmask) {
8965 +       case NXA_TYPE_MASK:
8966 +               ret = (ip == (addr & mask));
8967 +               break;
8968 +       case NXA_TYPE_ADDR:
8969 +               ret = 3;
8970 +               if (addr == ip)
8971 +                       break;
8972 +               /* fall through to broadcast */
8973 +       case NXA_MOD_BCAST:
8974 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
8975 +               break;
8976 +       case NXA_TYPE_RANGE:
8977 +               ret = ((nxa->ip[0].s_addr <= addr) &&
8978 +                       (nxa->ip[1].s_addr > addr));
8979 +               break;
8980 +       case NXA_TYPE_ANY:
8981 +               ret = 2;
8982 +               break;
8983 +       }
8984 +
8985 +       vxdprintk(VXD_CBIT(net, 0),
8986 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
8987 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
8988 +       return ret;
8989 +}
8990 +
8991 +static inline
8992 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
8993 +{
8994 +       struct nx_addr_v4 *nxa;
8995 +       unsigned long irqflags;
8996 +       int ret = 1;
8997 +
8998 +       if (!nxi)
8999 +               goto out;
9000 +
9001 +       ret = 2;
9002 +       /* allow 127.0.0.1 when remapping lback */
9003 +       if ((tmask & NXA_LOOPBACK) &&
9004 +               (addr == IPI_LOOPBACK) &&
9005 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9006 +               goto out;
9007 +       ret = 3;
9008 +       /* check for lback address */
9009 +       if ((tmask & NXA_MOD_LBACK) &&
9010 +               (nxi->v4_lback.s_addr == addr))
9011 +               goto out;
9012 +       ret = 4;
9013 +       /* check for broadcast address */
9014 +       if ((tmask & NXA_MOD_BCAST) &&
9015 +               (nxi->v4_bcast.s_addr == addr))
9016 +               goto out;
9017 +       ret = 5;
9018 +
9019 +       /* check for v4 addresses */
9020 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
9021 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
9022 +               if (v4_addr_match(nxa, addr, tmask))
9023 +                       goto out_unlock;
9024 +       ret = 0;
9025 +out_unlock:
9026 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
9027 +out:
9028 +       vxdprintk(VXD_CBIT(net, 0),
9029 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
9030 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
9031 +       return ret;
9032 +}
9033 +
9034 +static inline
9035 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
9036 +{
9037 +       /* FIXME: needs full range checks */
9038 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
9039 +}
9040 +
9041 +static inline
9042 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
9043 +{
9044 +       struct nx_addr_v4 *ptr;
9045 +       unsigned long irqflags;
9046 +       int ret = 1;
9047 +
9048 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
9049 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
9050 +               if (v4_nx_addr_match(ptr, nxa, mask))
9051 +                       goto out_unlock;
9052 +       ret = 0;
9053 +out_unlock:
9054 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
9055 +       return ret;
9056 +}
9057 +
9058 +#include <net/inet_sock.h>
9059 +
9060 +/*
9061 + *     Check if a given address matches for a socket
9062 + *
9063 + *     nxi:            the socket's nx_info if any
9064 + *     addr:           to be verified address
9065 + */
9066 +static inline
9067 +int v4_sock_addr_match (
9068 +       struct nx_info *nxi,
9069 +       struct inet_sock *inet,
9070 +       __be32 addr)
9071 +{
9072 +       __be32 saddr = inet->inet_rcv_saddr;
9073 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
9074 +
9075 +       if (addr && (saddr == addr || bcast == addr))
9076 +               return 1;
9077 +       if (!saddr)
9078 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
9079 +       return 0;
9080 +}
9081 +
9082 +
9083 +/* inet related checks and helpers */
9084 +
9085 +
9086 +struct in_ifaddr;
9087 +struct net_device;
9088 +struct sock;
9089 +
9090 +#ifdef CONFIG_INET
9091 +
9092 +#include <linux/netdevice.h>
9093 +#include <linux/inetdevice.h>
9094 +#include <net/inet_sock.h>
9095 +#include <net/inet_timewait_sock.h>
9096 +
9097 +
9098 +int dev_in_nx_info(struct net_device *, struct nx_info *);
9099 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
9100 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
9101 +
9102 +
9103 +/*
9104 + *     check if address is covered by socket
9105 + *
9106 + *     sk:     the socket to check against
9107 + *     addr:   the address in question (must be != 0)
9108 + */
9109 +
9110 +static inline
9111 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
9112 +{
9113 +       struct nx_info *nxi = sk->sk_nx_info;
9114 +       __be32 saddr = sk_rcv_saddr(sk);
9115 +
9116 +       vxdprintk(VXD_CBIT(net, 5),
9117 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
9118 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
9119 +               (sk->sk_socket?sk->sk_socket->flags:0));
9120 +
9121 +       if (saddr) {            /* direct address match */
9122 +               return v4_addr_match(nxa, saddr, -1);
9123 +       } else if (nxi) {       /* match against nx_info */
9124 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
9125 +       } else {                /* unrestricted any socket */
9126 +               return 1;
9127 +       }
9128 +}
9129 +
9130 +
9131 +
9132 +static inline
9133 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
9134 +{
9135 +       vxdprintk(VXD_CBIT(net, 1),
9136 +               "nx_dev_visible(%p[#%u],%p " VS_Q("%s") ") %d",
9137 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
9138 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
9139 +
9140 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9141 +               return 1;
9142 +       if (dev_in_nx_info(dev, nxi))
9143 +               return 1;
9144 +       return 0;
9145 +}
9146 +
9147 +
9148 +static inline
9149 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
9150 +{
9151 +       if (!nxi)
9152 +               return 1;
9153 +       if (!ifa)
9154 +               return 0;
9155 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
9156 +}
9157 +
9158 +static inline
9159 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
9160 +{
9161 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
9162 +               nxi, nxi ? nxi->nx_id : 0, ifa,
9163 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
9164 +
9165 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9166 +               return 1;
9167 +       if (v4_ifa_in_nx_info(ifa, nxi))
9168 +               return 1;
9169 +       return 0;
9170 +}
9171 +
9172 +
9173 +struct nx_v4_sock_addr {
9174 +       __be32 saddr;   /* Address used for validation */
9175 +       __be32 baddr;   /* Address used for socket bind */
9176 +};
9177 +
9178 +static inline
9179 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
9180 +       struct nx_v4_sock_addr *nsa)
9181 +{
9182 +       struct sock *sk = &inet->sk;
9183 +       struct nx_info *nxi = sk->sk_nx_info;
9184 +       __be32 saddr = addr->sin_addr.s_addr;
9185 +       __be32 baddr = saddr;
9186 +
9187 +       vxdprintk(VXD_CBIT(net, 3),
9188 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
9189 +               sk, sk->sk_nx_info, sk->sk_socket,
9190 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
9191 +               NIPQUAD(saddr));
9192 +
9193 +       if (nxi) {
9194 +               if (saddr == INADDR_ANY) {
9195 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
9196 +                               baddr = nxi->v4.ip[0].s_addr;
9197 +               } else if (saddr == IPI_LOOPBACK) {
9198 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9199 +                               baddr = nxi->v4_lback.s_addr;
9200 +               } else if (!ipv4_is_multicast(saddr) ||
9201 +                       !nx_info_ncaps(nxi, NXC_MULTICAST)) {
9202 +                       /* normal address bind */
9203 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
9204 +                               return -EADDRNOTAVAIL;
9205 +               }
9206 +       }
9207 +
9208 +       vxdprintk(VXD_CBIT(net, 3),
9209 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
9210 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
9211 +
9212 +       nsa->saddr = saddr;
9213 +       nsa->baddr = baddr;
9214 +       return 0;
9215 +}
9216 +
9217 +static inline
9218 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
9219 +{
9220 +       inet->inet_saddr = nsa->baddr;
9221 +       inet->inet_rcv_saddr = nsa->baddr;
9222 +}
9223 +
9224 +
9225 +/*
9226 + *      helper to simplify inet_lookup_listener
9227 + *
9228 + *      nxi:   the socket's nx_info if any
9229 + *      addr:  to be verified address
9230 + *      saddr: socket address
9231 + */
9232 +static inline int v4_inet_addr_match (
9233 +       struct nx_info *nxi,
9234 +       __be32 addr,
9235 +       __be32 saddr)
9236 +{
9237 +       if (addr && (saddr == addr))
9238 +               return 1;
9239 +       if (!saddr)
9240 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
9241 +       return 0;
9242 +}
9243 +
9244 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
9245 +{
9246 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
9247 +               (addr == nxi->v4_lback.s_addr))
9248 +               return IPI_LOOPBACK;
9249 +       return addr;
9250 +}
9251 +
9252 +static inline
9253 +int nx_info_has_v4(struct nx_info *nxi)
9254 +{
9255 +       if (!nxi)
9256 +               return 1;
9257 +       if (NX_IPV4(nxi))
9258 +               return 1;
9259 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9260 +               return 1;
9261 +       return 0;
9262 +}
9263 +
9264 +#else /* CONFIG_INET */
9265 +
9266 +static inline
9267 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
9268 +{
9269 +       return 1;
9270 +}
9271 +
9272 +static inline
9273 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
9274 +{
9275 +       return 1;
9276 +}
9277 +
9278 +static inline
9279 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
9280 +{
9281 +       return 1;
9282 +}
9283 +
9284 +static inline
9285 +int nx_info_has_v4(struct nx_info *nxi)
9286 +{
9287 +       return 0;
9288 +}
9289 +
9290 +#endif /* CONFIG_INET */
9291 +
9292 +#define current_nx_info_has_v4() \
9293 +       nx_info_has_v4(current_nx_info())
9294 +
9295 +#else
9296 +// #warning duplicate inclusion
9297 +#endif
9298 diff -NurpP --minimal linux-3.10.33/include/linux/vs_inet6.h linux-3.10.33-vs2.3.6.8/include/linux/vs_inet6.h
9299 --- linux-3.10.33/include/linux/vs_inet6.h      1970-01-01 00:00:00.000000000 +0000
9300 +++ linux-3.10.33-vs2.3.6.8/include/linux/vs_inet6.h    2013-08-22 20:30:00.000000000 +0000
9301 @@ -0,0 +1,257 @@
9302 +#ifndef _VS_INET6_H
9303 +#define _VS_INET6_H
9304 +
9305 +#include "vserver/base.h"
9306 +#include "vserver/network.h"
9307 +#include "vserver/debug.h"
9308 +
9309 +#include <net/ipv6.h>
9310 +
9311 +#define NXAV6(a)       &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
9312 +#define NXAV6_FMT      "[%pI6/%pI6/%d:%04x]"
9313 +
9314 +
9315 +#ifdef CONFIG_IPV6
9316 +
9317 +static inline
9318 +int v6_addr_match(struct nx_addr_v6 *nxa,
9319 +       const struct in6_addr *addr, uint16_t mask)
9320 +{
9321 +       int ret = 0;
9322 +
9323 +       switch (nxa->type & mask) {
9324 +       case NXA_TYPE_MASK:
9325 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
9326 +               break;
9327 +       case NXA_TYPE_ADDR:
9328 +               ret = ipv6_addr_equal(&nxa->ip, addr);
9329 +               break;
9330 +       case NXA_TYPE_ANY:
9331 +               ret = 1;
9332 +               break;
9333 +       }
9334 +       vxdprintk(VXD_CBIT(net, 0),
9335 +               "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
9336 +               nxa, NXAV6(nxa), addr, mask, ret);
9337 +       return ret;
9338 +}
9339 +
9340 +static inline
9341 +int v6_addr_in_nx_info(struct nx_info *nxi,
9342 +       const struct in6_addr *addr, uint16_t mask)
9343 +{
9344 +       struct nx_addr_v6 *nxa;
9345 +       unsigned long irqflags;
9346 +       int ret = 1;
9347 +
9348 +       if (!nxi)
9349 +               goto out;
9350 +
9351 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
9352 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
9353 +               if (v6_addr_match(nxa, addr, mask))
9354 +                       goto out_unlock;
9355 +       ret = 0;
9356 +out_unlock:
9357 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
9358 +out:
9359 +       vxdprintk(VXD_CBIT(net, 0),
9360 +               "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
9361 +               nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
9362 +       return ret;
9363 +}
9364 +
9365 +static inline
9366 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
9367 +{
9368 +       /* FIXME: needs full range checks */
9369 +       return v6_addr_match(nxa, &addr->ip, mask);
9370 +}
9371 +
9372 +static inline
9373 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
9374 +{
9375 +       struct nx_addr_v6 *ptr;
9376 +       unsigned long irqflags;
9377 +       int ret = 1;
9378 +
9379 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
9380 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
9381 +               if (v6_nx_addr_match(ptr, nxa, mask))
9382 +                       goto out_unlock;
9383 +       ret = 0;
9384 +out_unlock:
9385 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
9386 +       return ret;
9387 +}
9388 +
9389 +
9390 +/*
9391 + *     Check if a given address matches for a socket
9392 + *
9393 + *     nxi:            the socket's nx_info if any
9394 + *     addr:           to be verified address
9395 + */
9396 +static inline
9397 +int v6_sock_addr_match (
9398 +       struct nx_info *nxi,
9399 +       struct inet_sock *inet,
9400 +       struct in6_addr *addr)
9401 +{
9402 +       struct sock *sk = &inet->sk;
9403 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
9404 +
9405 +       if (!ipv6_addr_any(addr) &&
9406 +               ipv6_addr_equal(saddr, addr))
9407 +               return 1;
9408 +       if (ipv6_addr_any(saddr))
9409 +               return v6_addr_in_nx_info(nxi, addr, -1);
9410 +       return 0;
9411 +}
9412 +
9413 +/*
9414 + *     check if address is covered by socket
9415 + *
9416 + *     sk:     the socket to check against
9417 + *     addr:   the address in question (must be != 0)
9418 + */
9419 +
9420 +static inline
9421 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
9422 +{
9423 +       struct nx_info *nxi = sk->sk_nx_info;
9424 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
9425 +
9426 +       vxdprintk(VXD_CBIT(net, 5),
9427 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
9428 +               sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
9429 +               (sk->sk_socket?sk->sk_socket->flags:0));
9430 +
9431 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
9432 +               return v6_addr_match(nxa, saddr, -1);
9433 +       } else if (nxi) {               /* match against nx_info */
9434 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
9435 +       } else {                        /* unrestricted any socket */
9436 +               return 1;
9437 +       }
9438 +}
9439 +
9440 +
9441 +/* inet related checks and helpers */
9442 +
9443 +
9444 +struct in_ifaddr;
9445 +struct net_device;
9446 +struct sock;
9447 +
9448 +
9449 +#include <linux/netdevice.h>
9450 +#include <linux/inetdevice.h>
9451 +#include <net/inet_timewait_sock.h>
9452 +
9453 +
9454 +int dev_in_nx_info(struct net_device *, struct nx_info *);
9455 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
9456 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
9457 +
9458 +
9459 +
9460 +static inline
9461 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
9462 +{
9463 +       if (!nxi)
9464 +               return 1;
9465 +       if (!ifa)
9466 +               return 0;
9467 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
9468 +}
9469 +
9470 +static inline
9471 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
9472 +{
9473 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
9474 +               nxi, nxi ? nxi->nx_id : 0, ifa,
9475 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
9476 +
9477 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9478 +               return 1;
9479 +       if (v6_ifa_in_nx_info(ifa, nxi))
9480 +               return 1;
9481 +       return 0;
9482 +}
9483 +
9484 +
9485 +struct nx_v6_sock_addr {
9486 +       struct in6_addr saddr;  /* Address used for validation */
9487 +       struct in6_addr baddr;  /* Address used for socket bind */
9488 +};
9489 +
9490 +static inline
9491 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
9492 +       struct nx_v6_sock_addr *nsa)
9493 +{
9494 +       // struct sock *sk = &inet->sk;
9495 +       // struct nx_info *nxi = sk->sk_nx_info;
9496 +       struct in6_addr saddr = addr->sin6_addr;
9497 +       struct in6_addr baddr = saddr;
9498 +
9499 +       nsa->saddr = saddr;
9500 +       nsa->baddr = baddr;
9501 +       return 0;
9502 +}
9503 +
9504 +static inline
9505 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
9506 +{
9507 +       // struct sock *sk = &inet->sk;
9508 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
9509 +
9510 +       // *saddr = nsa->baddr;
9511 +       // inet->inet_saddr = nsa->baddr;
9512 +}
9513 +
9514 +static inline
9515 +int nx_info_has_v6(struct nx_info *nxi)
9516 +{
9517 +       if (!nxi)
9518 +               return 1;
9519 +       if (NX_IPV6(nxi))
9520 +               return 1;
9521 +       return 0;
9522 +}
9523 +
9524 +#else /* CONFIG_IPV6 */
9525 +
9526 +static inline
9527 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
9528 +{
9529 +       return 1;
9530 +}
9531 +
9532 +
9533 +static inline
9534 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
9535 +{
9536 +       return 1;
9537 +}
9538 +
9539 +static inline
9540 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
9541 +{
9542 +       return 1;
9543 +}
9544 +
9545 +static inline
9546 +int nx_info_has_v6(struct nx_info *nxi)
9547 +{
9548 +       return 0;
9549 +}
9550 +
9551 +#endif /* CONFIG_IPV6 */
9552 +
9553 +#define current_nx_info_has_v6() \
9554 +       nx_info_has_v6(current_nx_info())
9555 +
9556 +#else
9557 +#warning duplicate inclusion
9558 +#endif
9559 diff -NurpP --minimal linux-3.10.33/include/linux/vs_limit.h linux-3.10.33-vs2.3.6.8/include/linux/vs_limit.h
9560 --- linux-3.10.33/include/linux/vs_limit.h      1970-01-01 00:00:00.000000000 +0000
9561 +++ linux-3.10.33-vs2.3.6.8/include/linux/vs_limit.h    2013-08-22 20:30:00.000000000 +0000
9562 @@ -0,0 +1,140 @@
9563 +#ifndef _VS_LIMIT_H
9564 +#define _VS_LIMIT_H
9565 +
9566 +#include "vserver/limit.h"
9567 +#include "vserver/base.h"
9568 +#include "vserver/context.h"
9569 +#include "vserver/debug.h"
9570 +#include "vserver/context.h"
9571 +#include "vserver/limit_int.h"
9572 +
9573 +
9574 +#define vx_acc_cres(v, d, p, r) \
9575 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
9576 +
9577 +#define vx_acc_cres_cond(x, d, p, r) \
9578 +       __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
9579 +       r, d, p, __FILE__, __LINE__)
9580 +
9581 +
9582 +#define vx_add_cres(v, a, p, r) \
9583 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
9584 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
9585 +
9586 +#define vx_add_cres_cond(x, a, p, r) \
9587 +       __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
9588 +       r, a, p, __FILE__, __LINE__)
9589 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
9590 +
9591 +
9592 +/* process and file limits */
9593 +
9594 +#define vx_nproc_inc(p) \
9595 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
9596 +
9597 +#define vx_nproc_dec(p) \
9598 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
9599 +
9600 +#define vx_files_inc(f) \
9601 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
9602 +
9603 +#define vx_files_dec(f) \
9604 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
9605 +
9606 +#define vx_locks_inc(l) \
9607 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
9608 +
9609 +#define vx_locks_dec(l) \
9610 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
9611 +
9612 +#define vx_openfd_inc(f) \
9613 +       vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
9614 +
9615 +#define vx_openfd_dec(f) \
9616 +       vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
9617 +
9618 +
9619 +#define vx_cres_avail(v, n, r) \
9620 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
9621 +
9622 +
9623 +#define vx_nproc_avail(n) \
9624 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
9625 +
9626 +#define vx_files_avail(n) \
9627 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
9628 +
9629 +#define vx_locks_avail(n) \
9630 +       vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
9631 +
9632 +#define vx_openfd_avail(n) \
9633 +       vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
9634 +
9635 +
9636 +/* dentry limits */
9637 +
9638 +#define vx_dentry_inc(d) do {                                          \
9639 +       if ((d)->d_count == 1)                                          \
9640 +               vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY);    \
9641 +       } while (0)
9642 +
9643 +#define vx_dentry_dec(d) do {                                          \
9644 +       if ((d)->d_count == 0)                                          \
9645 +               vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY);    \
9646 +       } while (0)
9647 +
9648 +#define vx_dentry_avail(n) \
9649 +       vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
9650 +
9651 +
9652 +/* socket limits */
9653 +
9654 +#define vx_sock_inc(s) \
9655 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
9656 +
9657 +#define vx_sock_dec(s) \
9658 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
9659 +
9660 +#define vx_sock_avail(n) \
9661 +       vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
9662 +
9663 +
9664 +/* ipc resource limits */
9665 +
9666 +#define vx_ipcmsg_add(v, u, a) \
9667 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
9668 +
9669 +#define vx_ipcmsg_sub(v, u, a) \
9670 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
9671 +
9672 +#define vx_ipcmsg_avail(v, a) \
9673 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
9674 +
9675 +
9676 +#define vx_ipcshm_add(v, k, a) \
9677 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
9678 +
9679 +#define vx_ipcshm_sub(v, k, a) \
9680 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
9681 +
9682 +#define vx_ipcshm_avail(v, a) \
9683 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
9684 +
9685 +
9686 +#define vx_semary_inc(a) \
9687 +       vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
9688 +
9689 +#define vx_semary_dec(a) \
9690 +       vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
9691 +
9692 +
9693 +#define vx_nsems_add(a,n) \
9694 +       vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
9695 +
9696 +#define vx_nsems_sub(a,n) \
9697 +       vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
9698 +
9699 +
9700 +#else
9701 +#warning duplicate inclusion
9702 +#endif
9703 diff -NurpP --minimal linux-3.10.33/include/linux/vs_network.h linux-3.10.33-vs2.3.6.8/include/linux/vs_network.h
9704 --- linux-3.10.33/include/linux/vs_network.h    1970-01-01 00:00:00.000000000 +0000
9705 +++ linux-3.10.33-vs2.3.6.8/include/linux/vs_network.h  2013-08-22 20:30:00.000000000 +0000
9706 @@ -0,0 +1,169 @@
9707 +#ifndef _NX_VS_NETWORK_H
9708 +#define _NX_VS_NETWORK_H
9709 +
9710 +#include "vserver/context.h"
9711 +#include "vserver/network.h"
9712 +#include "vserver/base.h"
9713 +#include "vserver/check.h"
9714 +#include "vserver/debug.h"
9715 +
9716 +#include <linux/sched.h>
9717 +
9718 +
9719 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
9720 +
9721 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
9722 +       const char *_file, int _line)
9723 +{
9724 +       if (!nxi)
9725 +               return NULL;
9726 +
9727 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
9728 +               nxi, nxi ? nxi->nx_id : 0,
9729 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9730 +               _file, _line);
9731 +
9732 +       atomic_inc(&nxi->nx_usecnt);
9733 +       return nxi;
9734 +}
9735 +
9736 +
9737 +extern void free_nx_info(struct nx_info *);
9738 +
9739 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
9740 +
9741 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
9742 +{
9743 +       if (!nxi)
9744 +               return;
9745 +
9746 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
9747 +               nxi, nxi ? nxi->nx_id : 0,
9748 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9749 +               _file, _line);
9750 +
9751 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
9752 +               free_nx_info(nxi);
9753 +}
9754 +
9755 +
9756 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
9757 +
9758 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
9759 +               const char *_file, int _line)
9760 +{
9761 +       if (nxi) {
9762 +               vxlprintk(VXD_CBIT(nid, 3),
9763 +                       "init_nx_info(%p[#%d.%d])",
9764 +                       nxi, nxi ? nxi->nx_id : 0,
9765 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9766 +                       _file, _line);
9767 +
9768 +               atomic_inc(&nxi->nx_usecnt);
9769 +       }
9770 +       *nxp = nxi;
9771 +}
9772 +
9773 +
9774 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
9775 +
9776 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
9777 +       const char *_file, int _line)
9778 +{
9779 +       struct nx_info *nxo;
9780 +
9781 +       if (!nxi)
9782 +               return;
9783 +
9784 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
9785 +               nxi, nxi ? nxi->nx_id : 0,
9786 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9787 +               _file, _line);
9788 +
9789 +       atomic_inc(&nxi->nx_usecnt);
9790 +       nxo = xchg(nxp, nxi);
9791 +       BUG_ON(nxo);
9792 +}
9793 +
9794 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
9795 +
9796 +static inline void __clr_nx_info(struct nx_info **nxp,
9797 +       const char *_file, int _line)
9798 +{
9799 +       struct nx_info *nxo;
9800 +
9801 +       nxo = xchg(nxp, NULL);
9802 +       if (!nxo)
9803 +               return;
9804 +
9805 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
9806 +               nxo, nxo ? nxo->nx_id : 0,
9807 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
9808 +               _file, _line);
9809 +
9810 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
9811 +               free_nx_info(nxo);
9812 +}
9813 +
9814 +
9815 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
9816 +
9817 +static inline void __claim_nx_info(struct nx_info *nxi,
9818 +       struct task_struct *task, const char *_file, int _line)
9819 +{
9820 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
9821 +               nxi, nxi ? nxi->nx_id : 0,
9822 +               nxi?atomic_read(&nxi->nx_usecnt):0,
9823 +               nxi?atomic_read(&nxi->nx_tasks):0,
9824 +               task, _file, _line);
9825 +
9826 +       atomic_inc(&nxi->nx_tasks);
9827 +}
9828 +
9829 +
9830 +extern void unhash_nx_info(struct nx_info *);
9831 +
9832 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
9833 +
9834 +static inline void __release_nx_info(struct nx_info *nxi,
9835 +       struct task_struct *task, const char *_file, int _line)
9836 +{
9837 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
9838 +               nxi, nxi ? nxi->nx_id : 0,
9839 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9840 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
9841 +               task, _file, _line);
9842 +
9843 +       might_sleep();
9844 +
9845 +       if (atomic_dec_and_test(&nxi->nx_tasks))
9846 +               unhash_nx_info(nxi);
9847 +}
9848 +
9849 +
9850 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
9851 +
9852 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
9853 +       const char *_file, int _line)
9854 +{
9855 +       struct nx_info *nxi;
9856 +
9857 +       task_lock(p);
9858 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
9859 +               p, _file, _line);
9860 +       nxi = __get_nx_info(p->nx_info, _file, _line);
9861 +       task_unlock(p);
9862 +       return nxi;
9863 +}
9864 +
9865 +
9866 +static inline void exit_nx_info(struct task_struct *p)
9867 +{
9868 +       if (p->nx_info)
9869 +               release_nx_info(p->nx_info, p);
9870 +}
9871 +
9872 +
9873 +#else
9874 +#warning duplicate inclusion
9875 +#endif
9876 diff -NurpP --minimal linux-3.10.33/include/linux/vs_pid.h linux-3.10.33-vs2.3.6.8/include/linux/vs_pid.h
9877 --- linux-3.10.33/include/linux/vs_pid.h        1970-01-01 00:00:00.000000000 +0000
9878 +++ linux-3.10.33-vs2.3.6.8/include/linux/vs_pid.h      2013-08-22 20:30:00.000000000 +0000
9879 @@ -0,0 +1,50 @@
9880 +#ifndef _VS_PID_H
9881 +#define _VS_PID_H
9882 +
9883 +#include "vserver/base.h"
9884 +#include "vserver/check.h"
9885 +#include "vserver/context.h"
9886 +#include "vserver/debug.h"
9887 +#include "vserver/pid.h"
9888 +#include <linux/pid_namespace.h>
9889 +
9890 +
9891 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
9892 +
9893 +static inline
9894 +int vx_proc_task_visible(struct task_struct *task)
9895 +{
9896 +       if ((task->pid == 1) &&
9897 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
9898 +               /* show a blend through init */
9899 +               goto visible;
9900 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
9901 +               goto visible;
9902 +       return 0;
9903 +visible:
9904 +       return 1;
9905 +}
9906 +
9907 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
9908 +
9909 +
9910 +static inline
9911 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
9912 +{
9913 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
9914 +
9915 +       if (task && !vx_proc_task_visible(task)) {
9916 +               vxdprintk(VXD_CBIT(misc, 6),
9917 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
9918 +                       task, task->xid, task->pid,
9919 +                       current, current->xid, current->pid);
9920 +               put_task_struct(task);
9921 +               task = NULL;
9922 +       }
9923 +       return task;
9924 +}
9925 +
9926 +
9927 +#else
9928 +#warning duplicate inclusion
9929 +#endif
9930 diff -NurpP --minimal linux-3.10.33/include/linux/vs_sched.h linux-3.10.33-vs2.3.6.8/include/linux/vs_sched.h
9931 --- linux-3.10.33/include/linux/vs_sched.h      1970-01-01 00:00:00.000000000 +0000
9932 +++ linux-3.10.33-vs2.3.6.8/include/linux/vs_sched.h    2013-08-22 20:30:00.000000000 +0000
9933 @@ -0,0 +1,40 @@
9934 +#ifndef _VS_SCHED_H
9935 +#define _VS_SCHED_H
9936 +
9937 +#include "vserver/base.h"
9938 +#include "vserver/context.h"
9939 +#include "vserver/sched.h"
9940 +
9941 +
9942 +#define MAX_PRIO_BIAS           20
9943 +#define MIN_PRIO_BIAS          -20
9944 +
9945 +static inline
9946 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
9947 +{
9948 +       struct vx_info *vxi = p->vx_info;
9949 +
9950 +       if (vxi)
9951 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
9952 +       return prio;
9953 +}
9954 +
9955 +static inline void vx_account_user(struct vx_info *vxi,
9956 +       cputime_t cputime, int nice)
9957 +{
9958 +       if (!vxi)
9959 +               return;
9960 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
9961 +}
9962 +
9963 +static inline void vx_account_system(struct vx_info *vxi,
9964 +       cputime_t cputime, int idle)
9965 +{
9966 +       if (!vxi)
9967 +               return;
9968 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
9969 +}
9970 +
9971 +#else
9972 +#warning duplicate inclusion
9973 +#endif
9974 diff -NurpP --minimal linux-3.10.33/include/linux/vs_socket.h linux-3.10.33-vs2.3.6.8/include/linux/vs_socket.h
9975 --- linux-3.10.33/include/linux/vs_socket.h     1970-01-01 00:00:00.000000000 +0000
9976 +++ linux-3.10.33-vs2.3.6.8/include/linux/vs_socket.h   2013-08-22 20:30:00.000000000 +0000
9977 @@ -0,0 +1,67 @@
9978 +#ifndef _VS_SOCKET_H
9979 +#define _VS_SOCKET_H
9980 +
9981 +#include "vserver/debug.h"
9982 +#include "vserver/base.h"
9983 +#include "vserver/cacct.h"
9984 +#include "vserver/context.h"
9985 +#include "vserver/tag.h"
9986 +
9987 +
9988 +/* socket accounting */
9989 +
9990 +#include <linux/socket.h>
9991 +
9992 +static inline int vx_sock_type(int family)
9993 +{
9994 +       switch (family) {
9995 +       case PF_UNSPEC:
9996 +               return VXA_SOCK_UNSPEC;
9997 +       case PF_UNIX:
9998 +               return VXA_SOCK_UNIX;
9999 +       case PF_INET:
10000 +               return VXA_SOCK_INET;
10001 +       case PF_INET6:
10002 +               return VXA_SOCK_INET6;
10003 +       case PF_PACKET:
10004 +               return VXA_SOCK_PACKET;
10005 +       default:
10006 +               return VXA_SOCK_OTHER;
10007 +       }
10008 +}
10009 +
10010 +#define vx_acc_sock(v, f, p, s) \
10011 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
10012 +
10013 +static inline void __vx_acc_sock(struct vx_info *vxi,
10014 +       int family, int pos, int size, char *file, int line)
10015 +{
10016 +       if (vxi) {
10017 +               int type = vx_sock_type(family);
10018 +
10019 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
10020 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
10021 +       }
10022 +}
10023 +
10024 +#define vx_sock_recv(sk, s) \
10025 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
10026 +#define vx_sock_send(sk, s) \
10027 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
10028 +#define vx_sock_fail(sk, s) \
10029 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
10030 +
10031 +
10032 +#define sock_vx_init(s) do {           \
10033 +       (s)->sk_xid = 0;                \
10034 +       (s)->sk_vx_info = NULL;         \
10035 +       } while (0)
10036 +
10037 +#define sock_nx_init(s) do {           \
10038 +       (s)->sk_nid = 0;                \
10039 +       (s)->sk_nx_info = NULL;         \
10040 +       } while (0)
10041 +
10042 +#else
10043 +#warning duplicate inclusion
10044 +#endif
10045 diff -NurpP --minimal linux-3.10.33/include/linux/vs_tag.h linux-3.10.33-vs2.3.6.8/include/linux/vs_tag.h
10046 --- linux-3.10.33/include/linux/vs_tag.h        1970-01-01 00:00:00.000000000 +0000
10047 +++ linux-3.10.33-vs2.3.6.8/include/linux/vs_tag.h      2013-08-22 20:30:00.000000000 +0000
10048 @@ -0,0 +1,47 @@
10049 +#ifndef _VS_TAG_H
10050 +#define _VS_TAG_H
10051 +
10052 +#include <linux/vserver/tag.h>
10053 +
10054 +/* check conditions */
10055 +
10056 +#define DX_ADMIN       0x0001
10057 +#define DX_WATCH       0x0002
10058 +#define DX_HOSTID      0x0008
10059 +
10060 +#define DX_IDENT       0x0010
10061 +
10062 +#define DX_ARG_MASK    0x0010
10063 +
10064 +
10065 +#define dx_task_tag(t) ((t)->tag)
10066 +
10067 +#define dx_current_tag() dx_task_tag(current)
10068 +
10069 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
10070 +
10071 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
10072 +
10073 +
10074 +/*
10075 + * check current context for ADMIN/WATCH and
10076 + * optionally against supplied argument
10077 + */
10078 +static inline int __dx_check(vtag_t cid, vtag_t id, unsigned int mode)
10079 +{
10080 +       if (mode & DX_ARG_MASK) {
10081 +               if ((mode & DX_IDENT) && (id == cid))
10082 +                       return 1;
10083 +       }
10084 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
10085 +               ((mode & DX_WATCH) && (cid == 1)) ||
10086 +               ((mode & DX_HOSTID) && (id == 0)));
10087 +}
10088 +
10089 +struct inode;
10090 +int dx_permission(const struct inode *inode, int mask);
10091 +
10092 +
10093 +#else
10094 +#warning duplicate inclusion
10095 +#endif
10096 diff -NurpP --minimal linux-3.10.33/include/linux/vs_time.h linux-3.10.33-vs2.3.6.8/include/linux/vs_time.h
10097 --- linux-3.10.33/include/linux/vs_time.h       1970-01-01 00:00:00.000000000 +0000
10098 +++ linux-3.10.33-vs2.3.6.8/include/linux/vs_time.h     2013-08-22 20:30:00.000000000 +0000
10099 @@ -0,0 +1,19 @@
10100 +#ifndef _VS_TIME_H
10101 +#define _VS_TIME_H
10102 +
10103 +
10104 +/* time faking stuff */
10105 +
10106 +#ifdef CONFIG_VSERVER_VTIME
10107 +
10108 +extern void vx_adjust_timespec(struct timespec *ts);
10109 +extern int vx_settimeofday(const struct timespec *ts);
10110 +
10111 +#else
10112 +#define        vx_adjust_timespec(t)   do { } while (0)
10113 +#define        vx_settimeofday(t)      do_settimeofday(t)
10114 +#endif
10115 +
10116 +#else
10117 +#warning duplicate inclusion
10118 +#endif
10119 diff -NurpP --minimal linux-3.10.33/include/linux/vserver/base.h linux-3.10.33-vs2.3.6.8/include/linux/vserver/base.h
10120 --- linux-3.10.33/include/linux/vserver/base.h  1970-01-01 00:00:00.000000000 +0000
10121 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/base.h        2013-10-27 03:40:46.000000000 +0000
10122 @@ -0,0 +1,184 @@
10123 +#ifndef _VSERVER_BASE_H
10124 +#define _VSERVER_BASE_H
10125 +
10126 +
10127 +/* context state changes */
10128 +
10129 +enum {
10130 +       VSC_STARTUP = 1,
10131 +       VSC_SHUTDOWN,
10132 +
10133 +       VSC_NETUP,
10134 +       VSC_NETDOWN,
10135 +};
10136 +
10137 +
10138 +
10139 +#define vx_task_xid(t) ((t)->xid)
10140 +
10141 +#define vx_current_xid() vx_task_xid(current)
10142 +
10143 +#define current_vx_info() (current->vx_info)
10144 +
10145 +
10146 +#define nx_task_nid(t) ((t)->nid)
10147 +
10148 +#define nx_current_nid() nx_task_nid(current)
10149 +
10150 +#define current_nx_info() (current->nx_info)
10151 +
10152 +
10153 +/* generic flag merging */
10154 +
10155 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
10156 +
10157 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
10158 +
10159 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
10160 +
10161 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
10162 +
10163 +
10164 +/* context flags */
10165 +
10166 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
10167 +
10168 +#define vx_current_flags()     __vx_flags(current_vx_info())
10169 +
10170 +#define vx_info_flags(v, m, f) \
10171 +       vs_check_flags(__vx_flags(v), m, f)
10172 +
10173 +#define task_vx_flags(t, m, f) \
10174 +       ((t) && vx_info_flags((t)->vx_info, m, f))
10175 +
10176 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
10177 +
10178 +
10179 +/* context caps */
10180 +
10181 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
10182 +
10183 +#define vx_current_ccaps()     __vx_ccaps(current_vx_info())
10184 +
10185 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
10186 +
10187 +#define vx_ccaps(c)    vx_info_ccaps(current_vx_info(), (c))
10188 +
10189 +
10190 +
10191 +/* network flags */
10192 +
10193 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
10194 +
10195 +#define nx_current_flags()     __nx_flags(current_nx_info())
10196 +
10197 +#define nx_info_flags(n, m, f) \
10198 +       vs_check_flags(__nx_flags(n), m, f)
10199 +
10200 +#define task_nx_flags(t, m, f) \
10201 +       ((t) && nx_info_flags((t)->nx_info, m, f))
10202 +
10203 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
10204 +
10205 +
10206 +/* network caps */
10207 +
10208 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
10209 +
10210 +#define nx_current_ncaps()     __nx_ncaps(current_nx_info())
10211 +
10212 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
10213 +
10214 +#define nx_ncaps(c)    nx_info_ncaps(current_nx_info(), c)
10215 +
10216 +
10217 +/* context mask capabilities */
10218 +
10219 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
10220 +
10221 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
10222 +
10223 +#define vx_mcaps(c)    vx_info_mcaps(current_vx_info(), c)
10224 +
10225 +
10226 +/* context bcap mask */
10227 +
10228 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
10229 +
10230 +#define vx_current_bcaps()     __vx_bcaps(current_vx_info())
10231 +
10232 +
10233 +/* mask given bcaps */
10234 +
10235 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
10236 +
10237 +#define vx_mbcaps(c)           vx_info_mbcaps(current_vx_info(), c)
10238 +
10239 +
10240 +/* masked cap_bset */
10241 +
10242 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
10243 +
10244 +#define vx_current_cap_bset()  vx_info_cap_bset(current_vx_info())
10245 +
10246 +#if 0
10247 +#define vx_info_mbcap(v, b) \
10248 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
10249 +       vx_info_bcaps(v, b) : (b))
10250 +
10251 +#define task_vx_mbcap(t, b) \
10252 +       vx_info_mbcap((t)->vx_info, (t)->b)
10253 +
10254 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
10255 +#endif
10256 +
10257 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
10258 +
10259 +#define vx_capable(b, c) (capable(b) || \
10260 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10261 +
10262 +#define vx_ns_capable(n, b, c) (ns_capable(n, b) || \
10263 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10264 +
10265 +#define nx_capable(b, c) (capable(b) || \
10266 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
10267 +
10268 +#define nx_ns_capable(n, b, c) (ns_capable(n, b) || \
10269 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
10270 +
10271 +#define vx_task_initpid(t, n) \
10272 +       ((t)->vx_info && \
10273 +       ((t)->vx_info->vx_initpid == (n)))
10274 +
10275 +#define vx_current_initpid(n)  vx_task_initpid(current, n)
10276 +
10277 +
10278 +/* context unshare mask */
10279 +
10280 +#define __vx_umask(v)          ((v)->vx_umask)
10281 +
10282 +#define vx_current_umask()     __vx_umask(current_vx_info())
10283 +
10284 +#define vx_can_unshare(b, f) (capable(b) || \
10285 +       (cap_raised(current_cap(), b) && \
10286 +       !((f) & ~vx_current_umask())))
10287 +
10288 +#define vx_ns_can_unshare(n, b, f) (ns_capable(n, b) || \
10289 +       (cap_raised(current_cap(), b) && \
10290 +       !((f) & ~vx_current_umask())))
10291 +
10292 +#define __vx_wmask(v)          ((v)->vx_wmask)
10293 +
10294 +#define vx_current_wmask()     __vx_wmask(current_vx_info())
10295 +
10296 +
10297 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
10298 +
10299 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
10300 +
10301 +
10302 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
10303 +
10304 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
10305 +
10306 +#endif
10307 diff -NurpP --minimal linux-3.10.33/include/linux/vserver/cacct.h linux-3.10.33-vs2.3.6.8/include/linux/vserver/cacct.h
10308 --- linux-3.10.33/include/linux/vserver/cacct.h 1970-01-01 00:00:00.000000000 +0000
10309 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/cacct.h       2013-08-22 20:30:00.000000000 +0000
10310 @@ -0,0 +1,15 @@
10311 +#ifndef _VSERVER_CACCT_H
10312 +#define _VSERVER_CACCT_H
10313 +
10314 +
10315 +enum sock_acc_field {
10316 +       VXA_SOCK_UNSPEC = 0,
10317 +       VXA_SOCK_UNIX,
10318 +       VXA_SOCK_INET,
10319 +       VXA_SOCK_INET6,
10320 +       VXA_SOCK_PACKET,
10321 +       VXA_SOCK_OTHER,
10322 +       VXA_SOCK_SIZE   /* array size */
10323 +};
10324 +
10325 +#endif /* _VSERVER_CACCT_H */
10326 diff -NurpP --minimal linux-3.10.33/include/linux/vserver/cacct_cmd.h linux-3.10.33-vs2.3.6.8/include/linux/vserver/cacct_cmd.h
10327 --- linux-3.10.33/include/linux/vserver/cacct_cmd.h     1970-01-01 00:00:00.000000000 +0000
10328 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/cacct_cmd.h   2013-08-22 20:30:00.000000000 +0000
10329 @@ -0,0 +1,10 @@
10330 +#ifndef _VSERVER_CACCT_CMD_H
10331 +#define _VSERVER_CACCT_CMD_H
10332 +
10333 +
10334 +#include <linux/compiler.h>
10335 +#include <uapi/vserver/cacct_cmd.h>
10336 +
10337 +extern int vc_sock_stat(struct vx_info *, void __user *);
10338 +
10339 +#endif /* _VSERVER_CACCT_CMD_H */
10340 diff -NurpP --minimal linux-3.10.33/include/linux/vserver/cacct_def.h linux-3.10.33-vs2.3.6.8/include/linux/vserver/cacct_def.h
10341 --- linux-3.10.33/include/linux/vserver/cacct_def.h     1970-01-01 00:00:00.000000000 +0000
10342 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/cacct_def.h   2013-08-22 20:30:00.000000000 +0000
10343 @@ -0,0 +1,43 @@
10344 +#ifndef _VSERVER_CACCT_DEF_H
10345 +#define _VSERVER_CACCT_DEF_H
10346 +
10347 +#include <asm/atomic.h>
10348 +#include <linux/vserver/cacct.h>
10349 +
10350 +
10351 +struct _vx_sock_acc {
10352 +       atomic_long_t count;
10353 +       atomic_long_t total;
10354 +};
10355 +
10356 +/* context sub struct */
10357 +
10358 +struct _vx_cacct {
10359 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
10360 +       atomic_t slab[8];
10361 +       atomic_t page[6][8];
10362 +};
10363 +
10364 +#ifdef CONFIG_VSERVER_DEBUG
10365 +
10366 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
10367 +{
10368 +       int i, j;
10369 +
10370 +       printk("\t_vx_cacct:");
10371 +       for (i = 0; i < 6; i++) {
10372 +               struct _vx_sock_acc *ptr = cacct->sock[i];
10373 +
10374 +               printk("\t [%d] =", i);
10375 +               for (j = 0; j < 3; j++) {
10376 +                       printk(" [%d] = %8lu, %8lu", j,
10377 +                               atomic_long_read(&ptr[j].count),
10378 +                               atomic_long_read(&ptr[j].total));
10379 +               }
10380 +               printk("\n");
10381 +       }
10382 +}
10383 +
10384 +#endif
10385 +
10386 +#endif /* _VSERVER_CACCT_DEF_H */
10387 diff -NurpP --minimal linux-3.10.33/include/linux/vserver/cacct_int.h linux-3.10.33-vs2.3.6.8/include/linux/vserver/cacct_int.h
10388 --- linux-3.10.33/include/linux/vserver/cacct_int.h     1970-01-01 00:00:00.000000000 +0000
10389 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/cacct_int.h   2013-08-22 20:30:00.000000000 +0000
10390 @@ -0,0 +1,17 @@
10391 +#ifndef _VSERVER_CACCT_INT_H
10392 +#define _VSERVER_CACCT_INT_H
10393 +
10394 +static inline
10395 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
10396 +{
10397 +       return atomic_long_read(&cacct->sock[type][pos].count);
10398 +}
10399 +
10400 +
10401 +static inline
10402 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
10403 +{
10404 +       return atomic_long_read(&cacct->sock[type][pos].total);
10405 +}
10406 +
10407 +#endif /* _VSERVER_CACCT_INT_H */
10408 diff -NurpP --minimal linux-3.10.33/include/linux/vserver/check.h linux-3.10.33-vs2.3.6.8/include/linux/vserver/check.h
10409 --- linux-3.10.33/include/linux/vserver/check.h 1970-01-01 00:00:00.000000000 +0000
10410 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/check.h       2013-08-22 20:30:00.000000000 +0000
10411 @@ -0,0 +1,89 @@
10412 +#ifndef _VSERVER_CHECK_H
10413 +#define _VSERVER_CHECK_H
10414 +
10415 +
10416 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
10417 +
10418 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
10419 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
10420 +#else
10421 +#define MIN_D_CONTEXT  65536
10422 +#endif
10423 +
10424 +/* check conditions */
10425 +
10426 +#define VS_ADMIN       0x0001
10427 +#define VS_WATCH       0x0002
10428 +#define VS_HIDE                0x0004
10429 +#define VS_HOSTID      0x0008
10430 +
10431 +#define VS_IDENT       0x0010
10432 +#define VS_EQUIV       0x0020
10433 +#define VS_PARENT      0x0040
10434 +#define VS_CHILD       0x0080
10435 +
10436 +#define VS_ARG_MASK    0x00F0
10437 +
10438 +#define VS_DYNAMIC     0x0100
10439 +#define VS_STATIC      0x0200
10440 +
10441 +#define VS_ATR_MASK    0x0F00
10442 +
10443 +#ifdef CONFIG_VSERVER_PRIVACY
10444 +#define VS_ADMIN_P     (0)
10445 +#define VS_WATCH_P     (0)
10446 +#else
10447 +#define VS_ADMIN_P     VS_ADMIN
10448 +#define VS_WATCH_P     VS_WATCH
10449 +#endif
10450 +
10451 +#define VS_HARDIRQ     0x1000
10452 +#define VS_SOFTIRQ     0x2000
10453 +#define VS_IRQ         0x4000
10454 +
10455 +#define VS_IRQ_MASK    0xF000
10456 +
10457 +#include <linux/hardirq.h>
10458 +
10459 +/*
10460 + * check current context for ADMIN/WATCH and
10461 + * optionally against supplied argument
10462 + */
10463 +static inline int __vs_check(int cid, int id, unsigned int mode)
10464 +{
10465 +       if (mode & VS_ARG_MASK) {
10466 +               if ((mode & VS_IDENT) && (id == cid))
10467 +                       return 1;
10468 +       }
10469 +       if (mode & VS_ATR_MASK) {
10470 +               if ((mode & VS_DYNAMIC) &&
10471 +                       (id >= MIN_D_CONTEXT) &&
10472 +                       (id <= MAX_S_CONTEXT))
10473 +                       return 1;
10474 +               if ((mode & VS_STATIC) &&
10475 +                       (id > 1) && (id < MIN_D_CONTEXT))
10476 +                       return 1;
10477 +       }
10478 +       if (mode & VS_IRQ_MASK) {
10479 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
10480 +                       return 1;
10481 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
10482 +                       return 1;
10483 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
10484 +                       return 1;
10485 +       }
10486 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
10487 +               ((mode & VS_WATCH) && (cid == 1)) ||
10488 +               ((mode & VS_HOSTID) && (id == 0)));
10489 +}
10490 +
10491 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
10492 +
10493 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
10494 +
10495 +
10496 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
10497 +
10498 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
10499 +
10500 +#endif
10501 diff -NurpP --minimal linux-3.10.33/include/linux/vserver/context.h linux-3.10.33-vs2.3.6.8/include/linux/vserver/context.h
10502 --- linux-3.10.33/include/linux/vserver/context.h       1970-01-01 00:00:00.000000000 +0000
10503 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/context.h     2013-08-22 20:30:00.000000000 +0000
10504 @@ -0,0 +1,110 @@
10505 +#ifndef _VSERVER_CONTEXT_H
10506 +#define _VSERVER_CONTEXT_H
10507 +
10508 +
10509 +#include <linux/list.h>
10510 +#include <linux/spinlock.h>
10511 +#include <linux/rcupdate.h>
10512 +#include <uapi/vserver/context.h>
10513 +
10514 +#include "limit_def.h"
10515 +#include "sched_def.h"
10516 +#include "cvirt_def.h"
10517 +#include "cacct_def.h"
10518 +#include "device_def.h"
10519 +
10520 +#define VX_SPACES      2
10521 +
10522 +struct _vx_info_pc {
10523 +       struct _vx_sched_pc sched_pc;
10524 +       struct _vx_cvirt_pc cvirt_pc;
10525 +};
10526 +
10527 +struct _vx_space {
10528 +       unsigned long vx_nsmask;                /* assignment mask */
10529 +       struct nsproxy *vx_nsproxy;             /* private namespaces */
10530 +       struct fs_struct *vx_fs;                /* private namespace fs */
10531 +       const struct cred *vx_cred;             /* task credentials */
10532 +};
10533 +
10534 +struct vx_info {
10535 +       struct hlist_node vx_hlist;             /* linked list of contexts */
10536 +       vxid_t vx_id;                           /* context id */
10537 +       atomic_t vx_usecnt;                     /* usage count */
10538 +       atomic_t vx_tasks;                      /* tasks count */
10539 +       struct vx_info *vx_parent;              /* parent context */
10540 +       int vx_state;                           /* context state */
10541 +
10542 +       struct _vx_space space[VX_SPACES];      /* namespace store */
10543 +
10544 +       uint64_t vx_flags;                      /* context flags */
10545 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
10546 +       uint64_t vx_umask;                      /* unshare mask (guest) */
10547 +       uint64_t vx_wmask;                      /* warn mask (guest) */
10548 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
10549 +
10550 +       struct task_struct *vx_reaper;          /* guest reaper process */
10551 +       pid_t vx_initpid;                       /* PID of guest init */
10552 +       int64_t vx_badness_bias;                /* OOM points bias */
10553 +
10554 +       struct _vx_limit limit;                 /* vserver limits */
10555 +       struct _vx_sched sched;                 /* vserver scheduler */
10556 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
10557 +       struct _vx_cacct cacct;                 /* context accounting */
10558 +
10559 +       struct _vx_device dmap;                 /* default device map targets */
10560 +
10561 +#ifndef CONFIG_SMP
10562 +       struct _vx_info_pc info_pc;             /* per cpu data */
10563 +#else
10564 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
10565 +#endif
10566 +
10567 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
10568 +       int reboot_cmd;                         /* last sys_reboot() cmd */
10569 +       int exit_code;                          /* last process exit code */
10570 +
10571 +       char vx_name[65];                       /* vserver name */
10572 +};
10573 +
10574 +#ifndef CONFIG_SMP
10575 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
10576 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
10577 +#else
10578 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
10579 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
10580 +#endif
10581 +
10582 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
10583 +
10584 +
10585 +struct vx_info_save {
10586 +       struct vx_info *vxi;
10587 +       vxid_t xid;
10588 +};
10589 +
10590 +
10591 +/* status flags */
10592 +
10593 +#define VXS_HASHED     0x0001
10594 +#define VXS_PAUSED     0x0010
10595 +#define VXS_SHUTDOWN   0x0100
10596 +#define VXS_HELPER     0x1000
10597 +#define VXS_RELEASED   0x8000
10598 +
10599 +
10600 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
10601 +extern void release_vx_info(struct vx_info *, struct task_struct *);
10602 +
10603 +extern struct vx_info *lookup_vx_info(int);
10604 +extern struct vx_info *lookup_or_create_vx_info(int);
10605 +
10606 +extern int get_xid_list(int, unsigned int *, int);
10607 +extern int xid_is_hashed(vxid_t);
10608 +
10609 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
10610 +
10611 +extern long vs_state_change(struct vx_info *, unsigned int);
10612 +
10613 +
10614 +#endif /* _VSERVER_CONTEXT_H */
10615 diff -NurpP --minimal linux-3.10.33/include/linux/vserver/context_cmd.h linux-3.10.33-vs2.3.6.8/include/linux/vserver/context_cmd.h
10616 --- linux-3.10.33/include/linux/vserver/context_cmd.h   1970-01-01 00:00:00.000000000 +0000
10617 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/context_cmd.h 2013-08-22 20:30:00.000000000 +0000
10618 @@ -0,0 +1,33 @@
10619 +#ifndef _VSERVER_CONTEXT_CMD_H
10620 +#define _VSERVER_CONTEXT_CMD_H
10621 +
10622 +#include <uapi/vserver/context_cmd.h>
10623 +
10624 +extern int vc_task_xid(uint32_t);
10625 +
10626 +extern int vc_vx_info(struct vx_info *, void __user *);
10627 +
10628 +extern int vc_ctx_stat(struct vx_info *, void __user *);
10629 +
10630 +extern int vc_ctx_create(uint32_t, void __user *);
10631 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
10632 +
10633 +extern int vc_get_cflags(struct vx_info *, void __user *);
10634 +extern int vc_set_cflags(struct vx_info *, void __user *);
10635 +
10636 +extern int vc_get_ccaps(struct vx_info *, void __user *);
10637 +extern int vc_set_ccaps(struct vx_info *, void __user *);
10638 +
10639 +extern int vc_get_bcaps(struct vx_info *, void __user *);
10640 +extern int vc_set_bcaps(struct vx_info *, void __user *);
10641 +
10642 +extern int vc_get_umask(struct vx_info *, void __user *);
10643 +extern int vc_set_umask(struct vx_info *, void __user *);
10644 +
10645 +extern int vc_get_wmask(struct vx_info *, void __user *);
10646 +extern int vc_set_wmask(struct vx_info *, void __user *);
10647 +
10648 +extern int vc_get_badness(struct vx_info *, void __user *);
10649 +extern int vc_set_badness(struct vx_info *, void __user *);
10650 +
10651 +#endif /* _VSERVER_CONTEXT_CMD_H */
10652 diff -NurpP --minimal linux-3.10.33/include/linux/vserver/cvirt.h linux-3.10.33-vs2.3.6.8/include/linux/vserver/cvirt.h
10653 --- linux-3.10.33/include/linux/vserver/cvirt.h 1970-01-01 00:00:00.000000000 +0000
10654 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/cvirt.h       2013-08-22 20:30:00.000000000 +0000
10655 @@ -0,0 +1,18 @@
10656 +#ifndef _VSERVER_CVIRT_H
10657 +#define _VSERVER_CVIRT_H
10658 +
10659 +struct timespec;
10660 +
10661 +void vx_vsi_boottime(struct timespec *);
10662 +
10663 +void vx_vsi_uptime(struct timespec *, struct timespec *);
10664 +
10665 +
10666 +struct vx_info;
10667 +
10668 +void vx_update_load(struct vx_info *);
10669 +
10670 +
10671 +int vx_do_syslog(int, char __user *, int);
10672 +
10673 +#endif /* _VSERVER_CVIRT_H */
10674 diff -NurpP --minimal linux-3.10.33/include/linux/vserver/cvirt_cmd.h linux-3.10.33-vs2.3.6.8/include/linux/vserver/cvirt_cmd.h
10675 --- linux-3.10.33/include/linux/vserver/cvirt_cmd.h     1970-01-01 00:00:00.000000000 +0000
10676 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/cvirt_cmd.h   2013-08-22 20:30:00.000000000 +0000
10677 @@ -0,0 +1,13 @@
10678 +#ifndef _VSERVER_CVIRT_CMD_H
10679 +#define _VSERVER_CVIRT_CMD_H
10680 +
10681 +
10682 +#include <linux/compiler.h>
10683 +#include <uapi/vserver/cvirt_cmd.h>
10684 +
10685 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
10686 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
10687 +
10688 +extern int vc_virt_stat(struct vx_info *, void __user *);
10689 +
10690 +#endif /* _VSERVER_CVIRT_CMD_H */
10691 diff -NurpP --minimal linux-3.10.33/include/linux/vserver/cvirt_def.h linux-3.10.33-vs2.3.6.8/include/linux/vserver/cvirt_def.h
10692 --- linux-3.10.33/include/linux/vserver/cvirt_def.h     1970-01-01 00:00:00.000000000 +0000
10693 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/cvirt_def.h   2013-08-22 20:30:00.000000000 +0000
10694 @@ -0,0 +1,80 @@
10695 +#ifndef _VSERVER_CVIRT_DEF_H
10696 +#define _VSERVER_CVIRT_DEF_H
10697 +
10698 +#include <linux/jiffies.h>
10699 +#include <linux/spinlock.h>
10700 +#include <linux/wait.h>
10701 +#include <linux/time.h>
10702 +#include <asm/atomic.h>
10703 +
10704 +
10705 +struct _vx_usage_stat {
10706 +       uint64_t user;
10707 +       uint64_t nice;
10708 +       uint64_t system;
10709 +       uint64_t softirq;
10710 +       uint64_t irq;
10711 +       uint64_t idle;
10712 +       uint64_t iowait;
10713 +};
10714 +
10715 +struct _vx_syslog {
10716 +       wait_queue_head_t log_wait;
10717 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
10718 +
10719 +       unsigned long log_start;        /* next char to be read by syslog() */
10720 +       unsigned long con_start;        /* next char to be sent to consoles */
10721 +       unsigned long log_end;  /* most-recently-written-char + 1 */
10722 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
10723 +
10724 +       char log_buf[1024];
10725 +};
10726 +
10727 +
10728 +/* context sub struct */
10729 +
10730 +struct _vx_cvirt {
10731 +       atomic_t nr_threads;            /* number of current threads */
10732 +       atomic_t nr_running;            /* number of running threads */
10733 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
10734 +
10735 +       atomic_t nr_onhold;             /* processes on hold */
10736 +       uint32_t onhold_last;           /* jiffies when put on hold */
10737 +
10738 +       struct timespec bias_ts;        /* time offset to the host */
10739 +       struct timespec bias_idle;
10740 +       struct timespec bias_uptime;    /* context creation point */
10741 +       uint64_t bias_clock;            /* offset in clock_t */
10742 +
10743 +       spinlock_t load_lock;           /* lock for the load averages */
10744 +       atomic_t load_updates;          /* nr of load updates done so far */
10745 +       uint32_t load_last;             /* last time load was calculated */
10746 +       uint32_t load[3];               /* load averages 1,5,15 */
10747 +
10748 +       atomic_t total_forks;           /* number of forks so far */
10749 +
10750 +       struct _vx_syslog syslog;
10751 +};
10752 +
10753 +struct _vx_cvirt_pc {
10754 +       struct _vx_usage_stat cpustat;
10755 +};
10756 +
10757 +
10758 +#ifdef CONFIG_VSERVER_DEBUG
10759 +
10760 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
10761 +{
10762 +       printk("\t_vx_cvirt:\n");
10763 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
10764 +               atomic_read(&cvirt->nr_threads),
10765 +               atomic_read(&cvirt->nr_running),
10766 +               atomic_read(&cvirt->nr_uninterruptible),
10767 +               atomic_read(&cvirt->nr_onhold));
10768 +       /* add rest here */
10769 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
10770 +}
10771 +
10772 +#endif
10773 +
10774 +#endif /* _VSERVER_CVIRT_DEF_H */
10775 diff -NurpP --minimal linux-3.10.33/include/linux/vserver/debug.h linux-3.10.33-vs2.3.6.8/include/linux/vserver/debug.h
10776 --- linux-3.10.33/include/linux/vserver/debug.h 1970-01-01 00:00:00.000000000 +0000
10777 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/debug.h       2013-08-22 20:30:00.000000000 +0000
10778 @@ -0,0 +1,146 @@
10779 +#ifndef _VSERVER_DEBUG_H
10780 +#define _VSERVER_DEBUG_H
10781 +
10782 +
10783 +#define VXD_CBIT(n, m) (vs_debug_ ## n & (1 << (m)))
10784 +#define VXD_CMIN(n, m) (vs_debug_ ## n > (m))
10785 +#define VXD_MASK(n, m) (vs_debug_ ## n & (m))
10786 +
10787 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
10788 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
10789 +#define VXF_DEV                "%p[%lu,%d:%d]"
10790 +
10791 +#if    defined(CONFIG_QUOTES_UTF8)
10792 +#define        VS_Q_LQM        "\xc2\xbb"
10793 +#define        VS_Q_RQM        "\xc2\xab"
10794 +#elif  defined(CONFIG_QUOTES_ASCII)
10795 +#define        VS_Q_LQM        "\x27"
10796 +#define        VS_Q_RQM        "\x27"
10797 +#else
10798 +#define        VS_Q_LQM        "\xbb"
10799 +#define        VS_Q_RQM        "\xab"
10800 +#endif
10801 +
10802 +#define        VS_Q(f)         VS_Q_LQM f VS_Q_RQM
10803 +
10804 +
10805 +#define vxd_path(p)                                            \
10806 +       ({ static char _buffer[PATH_MAX];                       \
10807 +          d_path(p, _buffer, sizeof(_buffer)); })
10808 +
10809 +#define vxd_cond_path(n)                                       \
10810 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
10811 +
10812 +
10813 +#ifdef CONFIG_VSERVER_DEBUG
10814 +
10815 +extern unsigned int vs_debug_switch;
10816 +extern unsigned int vs_debug_xid;
10817 +extern unsigned int vs_debug_nid;
10818 +extern unsigned int vs_debug_tag;
10819 +extern unsigned int vs_debug_net;
10820 +extern unsigned int vs_debug_limit;
10821 +extern unsigned int vs_debug_cres;
10822 +extern unsigned int vs_debug_dlim;
10823 +extern unsigned int vs_debug_quota;
10824 +extern unsigned int vs_debug_cvirt;
10825 +extern unsigned int vs_debug_space;
10826 +extern unsigned int vs_debug_perm;
10827 +extern unsigned int vs_debug_misc;
10828 +
10829 +
10830 +#define VX_LOGLEVEL    "vxD: "
10831 +#define VX_PROC_FMT    "%p: "
10832 +#define VX_PROCESS     current
10833 +
10834 +#define vxdprintk(c, f, x...)                                  \
10835 +       do {                                                    \
10836 +               if (c)                                          \
10837 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
10838 +                               VX_PROCESS , ##x);              \
10839 +       } while (0)
10840 +
10841 +#define vxlprintk(c, f, x...)                                  \
10842 +       do {                                                    \
10843 +               if (c)                                          \
10844 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
10845 +       } while (0)
10846 +
10847 +#define vxfprintk(c, f, x...)                                  \
10848 +       do {                                                    \
10849 +               if (c)                                          \
10850 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
10851 +       } while (0)
10852 +
10853 +
10854 +struct vx_info;
10855 +
10856 +void dump_vx_info(struct vx_info *, int);
10857 +void dump_vx_info_inactive(int);
10858 +
10859 +#else  /* CONFIG_VSERVER_DEBUG */
10860 +
10861 +#define vs_debug_switch        0
10862 +#define vs_debug_xid   0
10863 +#define vs_debug_nid   0
10864 +#define vs_debug_tag   0
10865 +#define vs_debug_net   0
10866 +#define vs_debug_limit 0
10867 +#define vs_debug_cres  0
10868 +#define vs_debug_dlim  0
10869 +#define vs_debug_quota 0
10870 +#define vs_debug_cvirt 0
10871 +#define vs_debug_space 0
10872 +#define vs_debug_perm  0
10873 +#define vs_debug_misc  0
10874 +
10875 +#define vxdprintk(x...) do { } while (0)
10876 +#define vxlprintk(x...) do { } while (0)
10877 +#define vxfprintk(x...) do { } while (0)
10878 +
10879 +#endif /* CONFIG_VSERVER_DEBUG */
10880 +
10881 +
10882 +#ifdef CONFIG_VSERVER_WARN
10883 +
10884 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
10885 +#define VX_WARN_TASK   "[" VS_Q("%s") ",%u:#%u|%u|%u] "
10886 +#define VX_WARN_XID    "[xid #%u] "
10887 +#define VX_WARN_NID    "[nid #%u] "
10888 +#define VX_WARN_TAG    "[tag #%u] "
10889 +
10890 +#define vxwprintk(c, f, x...)                                  \
10891 +       do {                                                    \
10892 +               if (c)                                          \
10893 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
10894 +       } while (0)
10895 +
10896 +#else  /* CONFIG_VSERVER_WARN */
10897 +
10898 +#define vxwprintk(x...) do { } while (0)
10899 +
10900 +#endif /* CONFIG_VSERVER_WARN */
10901 +
10902 +#define vxwprintk_task(c, f, x...)                             \
10903 +       vxwprintk(c, VX_WARN_TASK f,                            \
10904 +               current->comm, current->pid,                    \
10905 +               current->xid, current->nid,                     \
10906 +               current->tag, ##x)
10907 +#define vxwprintk_xid(c, f, x...)                              \
10908 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
10909 +#define vxwprintk_nid(c, f, x...)                              \
10910 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
10911 +#define vxwprintk_tag(c, f, x...)                              \
10912 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
10913 +
10914 +#ifdef CONFIG_VSERVER_DEBUG
10915 +#define vxd_assert_lock(l)     assert_spin_locked(l)
10916 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
10917 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
10918 +#else
10919 +#define vxd_assert_lock(l)     do { } while (0)
10920 +#define vxd_assert(c, f, x...) do { } while (0)
10921 +#endif
10922 +
10923 +
10924 +#endif /* _VSERVER_DEBUG_H */
10925 diff -NurpP --minimal linux-3.10.33/include/linux/vserver/debug_cmd.h linux-3.10.33-vs2.3.6.8/include/linux/vserver/debug_cmd.h
10926 --- linux-3.10.33/include/linux/vserver/debug_cmd.h     1970-01-01 00:00:00.000000000 +0000
10927 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/debug_cmd.h   2013-08-22 20:30:00.000000000 +0000
10928 @@ -0,0 +1,37 @@
10929 +#ifndef _VSERVER_DEBUG_CMD_H
10930 +#define _VSERVER_DEBUG_CMD_H
10931 +
10932 +#include <uapi/vserver/debug_cmd.h>
10933 +
10934 +
10935 +#ifdef CONFIG_COMPAT
10936 +
10937 +#include <asm/compat.h>
10938 +
10939 +struct vcmd_read_history_v0_x32 {
10940 +       uint32_t index;
10941 +       uint32_t count;
10942 +       compat_uptr_t data_ptr;
10943 +};
10944 +
10945 +struct vcmd_read_monitor_v0_x32 {
10946 +       uint32_t index;
10947 +       uint32_t count;
10948 +       compat_uptr_t data_ptr;
10949 +};
10950 +
10951 +#endif  /* CONFIG_COMPAT */
10952 +
10953 +extern int vc_dump_history(uint32_t);
10954 +
10955 +extern int vc_read_history(uint32_t, void __user *);
10956 +extern int vc_read_monitor(uint32_t, void __user *);
10957 +
10958 +#ifdef CONFIG_COMPAT
10959 +
10960 +extern int vc_read_history_x32(uint32_t, void __user *);
10961 +extern int vc_read_monitor_x32(uint32_t, void __user *);
10962 +
10963 +#endif  /* CONFIG_COMPAT */
10964 +
10965 +#endif /* _VSERVER_DEBUG_CMD_H */
10966 diff -NurpP --minimal linux-3.10.33/include/linux/vserver/device.h linux-3.10.33-vs2.3.6.8/include/linux/vserver/device.h
10967 --- linux-3.10.33/include/linux/vserver/device.h        1970-01-01 00:00:00.000000000 +0000
10968 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/device.h      2013-08-22 20:30:00.000000000 +0000
10969 @@ -0,0 +1,9 @@
10970 +#ifndef _VSERVER_DEVICE_H
10971 +#define _VSERVER_DEVICE_H
10972 +
10973 +
10974 +#include <uapi/vserver/device.h>
10975 +
10976 +#else  /* _VSERVER_DEVICE_H */
10977 +#warning duplicate inclusion
10978 +#endif /* _VSERVER_DEVICE_H */
10979 diff -NurpP --minimal linux-3.10.33/include/linux/vserver/device_cmd.h linux-3.10.33-vs2.3.6.8/include/linux/vserver/device_cmd.h
10980 --- linux-3.10.33/include/linux/vserver/device_cmd.h    1970-01-01 00:00:00.000000000 +0000
10981 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/device_cmd.h  2013-08-22 20:30:00.000000000 +0000
10982 @@ -0,0 +1,31 @@
10983 +#ifndef _VSERVER_DEVICE_CMD_H
10984 +#define _VSERVER_DEVICE_CMD_H
10985 +
10986 +#include <uapi/vserver/device_cmd.h>
10987 +
10988 +
10989 +#ifdef CONFIG_COMPAT
10990 +
10991 +#include <asm/compat.h>
10992 +
10993 +struct vcmd_set_mapping_v0_x32 {
10994 +       compat_uptr_t device_ptr;
10995 +       compat_uptr_t target_ptr;
10996 +       uint32_t flags;
10997 +};
10998 +
10999 +#endif /* CONFIG_COMPAT */
11000 +
11001 +#include <linux/compiler.h>
11002 +
11003 +extern int vc_set_mapping(struct vx_info *, void __user *);
11004 +extern int vc_unset_mapping(struct vx_info *, void __user *);
11005 +
11006 +#ifdef CONFIG_COMPAT
11007 +
11008 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
11009 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
11010 +
11011 +#endif /* CONFIG_COMPAT */
11012 +
11013 +#endif /* _VSERVER_DEVICE_CMD_H */
11014 diff -NurpP --minimal linux-3.10.33/include/linux/vserver/device_def.h linux-3.10.33-vs2.3.6.8/include/linux/vserver/device_def.h
11015 --- linux-3.10.33/include/linux/vserver/device_def.h    1970-01-01 00:00:00.000000000 +0000
11016 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/device_def.h  2013-08-22 20:30:00.000000000 +0000
11017 @@ -0,0 +1,17 @@
11018 +#ifndef _VSERVER_DEVICE_DEF_H
11019 +#define _VSERVER_DEVICE_DEF_H
11020 +
11021 +#include <linux/types.h>
11022 +
11023 +struct vx_dmap_target {
11024 +       dev_t target;
11025 +       uint32_t flags;
11026 +};
11027 +
11028 +struct _vx_device {
11029 +#ifdef CONFIG_VSERVER_DEVICE
11030 +       struct vx_dmap_target targets[2];
11031 +#endif
11032 +};
11033 +
11034 +#endif /* _VSERVER_DEVICE_DEF_H */
11035 diff -NurpP --minimal linux-3.10.33/include/linux/vserver/dlimit.h linux-3.10.33-vs2.3.6.8/include/linux/vserver/dlimit.h
11036 --- linux-3.10.33/include/linux/vserver/dlimit.h        1970-01-01 00:00:00.000000000 +0000
11037 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/dlimit.h      2013-08-22 20:30:00.000000000 +0000
11038 @@ -0,0 +1,54 @@
11039 +#ifndef _VSERVER_DLIMIT_H
11040 +#define _VSERVER_DLIMIT_H
11041 +
11042 +#include "switch.h"
11043 +
11044 +
11045 +#ifdef __KERNEL__
11046 +
11047 +/*      keep in sync with CDLIM_INFINITY       */
11048 +
11049 +#define DLIM_INFINITY          (~0ULL)
11050 +
11051 +#include <linux/spinlock.h>
11052 +#include <linux/rcupdate.h>
11053 +
11054 +struct super_block;
11055 +
11056 +struct dl_info {
11057 +       struct hlist_node dl_hlist;             /* linked list of contexts */
11058 +       struct rcu_head dl_rcu;                 /* the rcu head */
11059 +       vtag_t dl_tag;                          /* context tag */
11060 +       atomic_t dl_usecnt;                     /* usage count */
11061 +       atomic_t dl_refcnt;                     /* reference count */
11062 +
11063 +       struct super_block *dl_sb;              /* associated superblock */
11064 +
11065 +       spinlock_t dl_lock;                     /* protect the values */
11066 +
11067 +       unsigned long long dl_space_used;       /* used space in bytes */
11068 +       unsigned long long dl_space_total;      /* maximum space in bytes */
11069 +       unsigned long dl_inodes_used;           /* used inodes */
11070 +       unsigned long dl_inodes_total;          /* maximum inodes */
11071 +
11072 +       unsigned int dl_nrlmult;                /* non root limit mult */
11073 +};
11074 +
11075 +struct rcu_head;
11076 +
11077 +extern void rcu_free_dl_info(struct rcu_head *);
11078 +extern void unhash_dl_info(struct dl_info *);
11079 +
11080 +extern struct dl_info *locate_dl_info(struct super_block *, vtag_t);
11081 +
11082 +
11083 +struct kstatfs;
11084 +
11085 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
11086 +
11087 +typedef uint64_t dlsize_t;
11088 +
11089 +#endif /* __KERNEL__ */
11090 +#else  /* _VSERVER_DLIMIT_H */
11091 +#warning duplicate inclusion
11092 +#endif /* _VSERVER_DLIMIT_H */
11093 diff -NurpP --minimal linux-3.10.33/include/linux/vserver/dlimit_cmd.h linux-3.10.33-vs2.3.6.8/include/linux/vserver/dlimit_cmd.h
11094 --- linux-3.10.33/include/linux/vserver/dlimit_cmd.h    1970-01-01 00:00:00.000000000 +0000
11095 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/dlimit_cmd.h  2013-08-22 20:30:00.000000000 +0000
11096 @@ -0,0 +1,46 @@
11097 +#ifndef _VSERVER_DLIMIT_CMD_H
11098 +#define _VSERVER_DLIMIT_CMD_H
11099 +
11100 +#include <uapi/vserver/dlimit_cmd.h>
11101 +
11102 +
11103 +#ifdef CONFIG_COMPAT
11104 +
11105 +#include <asm/compat.h>
11106 +
11107 +struct vcmd_ctx_dlimit_base_v0_x32 {
11108 +       compat_uptr_t name_ptr;
11109 +       uint32_t flags;
11110 +};
11111 +
11112 +struct vcmd_ctx_dlimit_v0_x32 {
11113 +       compat_uptr_t name_ptr;
11114 +       uint32_t space_used;                    /* used space in kbytes */
11115 +       uint32_t space_total;                   /* maximum space in kbytes */
11116 +       uint32_t inodes_used;                   /* used inodes */
11117 +       uint32_t inodes_total;                  /* maximum inodes */
11118 +       uint32_t reserved;                      /* reserved for root in % */
11119 +       uint32_t flags;
11120 +};
11121 +
11122 +#endif /* CONFIG_COMPAT */
11123 +
11124 +#include <linux/compiler.h>
11125 +
11126 +extern int vc_add_dlimit(uint32_t, void __user *);
11127 +extern int vc_rem_dlimit(uint32_t, void __user *);
11128 +
11129 +extern int vc_set_dlimit(uint32_t, void __user *);
11130 +extern int vc_get_dlimit(uint32_t, void __user *);
11131 +
11132 +#ifdef CONFIG_COMPAT
11133 +
11134 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
11135 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
11136 +
11137 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
11138 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
11139 +
11140 +#endif /* CONFIG_COMPAT */
11141 +
11142 +#endif /* _VSERVER_DLIMIT_CMD_H */
11143 diff -NurpP --minimal linux-3.10.33/include/linux/vserver/global.h linux-3.10.33-vs2.3.6.8/include/linux/vserver/global.h
11144 --- linux-3.10.33/include/linux/vserver/global.h        1970-01-01 00:00:00.000000000 +0000
11145 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/global.h      2013-08-22 20:30:00.000000000 +0000
11146 @@ -0,0 +1,19 @@
11147 +#ifndef _VSERVER_GLOBAL_H
11148 +#define _VSERVER_GLOBAL_H
11149 +
11150 +
11151 +extern atomic_t vx_global_ctotal;
11152 +extern atomic_t vx_global_cactive;
11153 +
11154 +extern atomic_t nx_global_ctotal;
11155 +extern atomic_t nx_global_cactive;
11156 +
11157 +extern atomic_t vs_global_nsproxy;
11158 +extern atomic_t vs_global_fs;
11159 +extern atomic_t vs_global_mnt_ns;
11160 +extern atomic_t vs_global_uts_ns;
11161 +extern atomic_t vs_global_user_ns;
11162 +extern atomic_t vs_global_pid_ns;
11163 +
11164 +
11165 +#endif /* _VSERVER_GLOBAL_H */
11166 diff -NurpP --minimal linux-3.10.33/include/linux/vserver/history.h linux-3.10.33-vs2.3.6.8/include/linux/vserver/history.h
11167 --- linux-3.10.33/include/linux/vserver/history.h       1970-01-01 00:00:00.000000000 +0000
11168 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/history.h     2013-08-22 20:30:00.000000000 +0000
11169 @@ -0,0 +1,197 @@
11170 +#ifndef _VSERVER_HISTORY_H
11171 +#define _VSERVER_HISTORY_H
11172 +
11173 +
11174 +enum {
11175 +       VXH_UNUSED = 0,
11176 +       VXH_THROW_OOPS = 1,
11177 +
11178 +       VXH_GET_VX_INFO,
11179 +       VXH_PUT_VX_INFO,
11180 +       VXH_INIT_VX_INFO,
11181 +       VXH_SET_VX_INFO,
11182 +       VXH_CLR_VX_INFO,
11183 +       VXH_CLAIM_VX_INFO,
11184 +       VXH_RELEASE_VX_INFO,
11185 +       VXH_ALLOC_VX_INFO,
11186 +       VXH_DEALLOC_VX_INFO,
11187 +       VXH_HASH_VX_INFO,
11188 +       VXH_UNHASH_VX_INFO,
11189 +       VXH_LOC_VX_INFO,
11190 +       VXH_LOOKUP_VX_INFO,
11191 +       VXH_CREATE_VX_INFO,
11192 +};
11193 +
11194 +struct _vxhe_vxi {
11195 +       struct vx_info *ptr;
11196 +       unsigned xid;
11197 +       unsigned usecnt;
11198 +       unsigned tasks;
11199 +};
11200 +
11201 +struct _vxhe_set_clr {
11202 +       void *data;
11203 +};
11204 +
11205 +struct _vxhe_loc_lookup {
11206 +       unsigned arg;
11207 +};
11208 +
11209 +struct _vx_hist_entry {
11210 +       void *loc;
11211 +       unsigned short seq;
11212 +       unsigned short type;
11213 +       struct _vxhe_vxi vxi;
11214 +       union {
11215 +               struct _vxhe_set_clr sc;
11216 +               struct _vxhe_loc_lookup ll;
11217 +       };
11218 +};
11219 +
11220 +#ifdef CONFIG_VSERVER_HISTORY
11221 +
11222 +extern unsigned volatile int vxh_active;
11223 +
11224 +struct _vx_hist_entry *vxh_advance(void *loc);
11225 +
11226 +
11227 +static inline
11228 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
11229 +{
11230 +       entry->vxi.ptr = vxi;
11231 +       if (vxi) {
11232 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
11233 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
11234 +               entry->vxi.xid = vxi->vx_id;
11235 +       }
11236 +}
11237 +
11238 +
11239 +#define        __HERE__ current_text_addr()
11240 +
11241 +#define __VXH_BODY(__type, __data, __here)     \
11242 +       struct _vx_hist_entry *entry;           \
11243 +                                               \
11244 +       preempt_disable();                      \
11245 +       entry = vxh_advance(__here);            \
11246 +       __data;                                 \
11247 +       entry->type = __type;                   \
11248 +       preempt_enable();
11249 +
11250 +
11251 +       /* pass vxi only */
11252 +
11253 +#define __VXH_SMPL                             \
11254 +       __vxh_copy_vxi(entry, vxi)
11255 +
11256 +static inline
11257 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
11258 +{
11259 +       __VXH_BODY(__type, __VXH_SMPL, __here)
11260 +}
11261 +
11262 +       /* pass vxi and data (void *) */
11263 +
11264 +#define __VXH_DATA                             \
11265 +       __vxh_copy_vxi(entry, vxi);             \
11266 +       entry->sc.data = data
11267 +
11268 +static inline
11269 +void   __vxh_data(struct vx_info *vxi, void *data,
11270 +                       int __type, void *__here)
11271 +{
11272 +       __VXH_BODY(__type, __VXH_DATA, __here)
11273 +}
11274 +
11275 +       /* pass vxi and arg (long) */
11276 +
11277 +#define __VXH_LONG                             \
11278 +       __vxh_copy_vxi(entry, vxi);             \
11279 +       entry->ll.arg = arg
11280 +
11281 +static inline
11282 +void   __vxh_long(struct vx_info *vxi, long arg,
11283 +                       int __type, void *__here)
11284 +{
11285 +       __VXH_BODY(__type, __VXH_LONG, __here)
11286 +}
11287 +
11288 +
11289 +static inline
11290 +void   __vxh_throw_oops(void *__here)
11291 +{
11292 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
11293 +       /* prevent further acquisition */
11294 +       vxh_active = 0;
11295 +}
11296 +
11297 +
11298 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
11299 +
11300 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
11301 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
11302 +
11303 +#define __vxh_init_vx_info(v, d, h) \
11304 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
11305 +#define __vxh_set_vx_info(v, d, h) \
11306 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
11307 +#define __vxh_clr_vx_info(v, d, h) \
11308 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
11309 +
11310 +#define __vxh_claim_vx_info(v, d, h) \
11311 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
11312 +#define __vxh_release_vx_info(v, d, h) \
11313 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
11314 +
11315 +#define vxh_alloc_vx_info(v) \
11316 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
11317 +#define vxh_dealloc_vx_info(v) \
11318 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
11319 +
11320 +#define vxh_hash_vx_info(v) \
11321 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
11322 +#define vxh_unhash_vx_info(v) \
11323 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
11324 +
11325 +#define vxh_loc_vx_info(v, l) \
11326 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
11327 +#define vxh_lookup_vx_info(v, l) \
11328 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
11329 +#define vxh_create_vx_info(v, l) \
11330 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
11331 +
11332 +extern void vxh_dump_history(void);
11333 +
11334 +
11335 +#else  /* CONFIG_VSERVER_HISTORY */
11336 +
11337 +#define        __HERE__        0
11338 +
11339 +#define vxh_throw_oops()               do { } while (0)
11340 +
11341 +#define __vxh_get_vx_info(v, h)                do { } while (0)
11342 +#define __vxh_put_vx_info(v, h)                do { } while (0)
11343 +
11344 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
11345 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
11346 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
11347 +
11348 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
11349 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
11350 +
11351 +#define vxh_alloc_vx_info(v)           do { } while (0)
11352 +#define vxh_dealloc_vx_info(v)         do { } while (0)
11353 +
11354 +#define vxh_hash_vx_info(v)            do { } while (0)
11355 +#define vxh_unhash_vx_info(v)          do { } while (0)
11356 +
11357 +#define vxh_loc_vx_info(v, l)          do { } while (0)
11358 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
11359 +#define vxh_create_vx_info(v, l)       do { } while (0)
11360 +
11361 +#define vxh_dump_history()             do { } while (0)
11362 +
11363 +
11364 +#endif /* CONFIG_VSERVER_HISTORY */
11365 +
11366 +#endif /* _VSERVER_HISTORY_H */
11367 diff -NurpP --minimal linux-3.10.33/include/linux/vserver/inode.h linux-3.10.33-vs2.3.6.8/include/linux/vserver/inode.h
11368 --- linux-3.10.33/include/linux/vserver/inode.h 1970-01-01 00:00:00.000000000 +0000
11369 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/inode.h       2013-08-22 20:30:00.000000000 +0000
11370 @@ -0,0 +1,19 @@
11371 +#ifndef _VSERVER_INODE_H
11372 +#define _VSERVER_INODE_H
11373 +
11374 +#include <uapi/vserver/inode.h>
11375 +
11376 +
11377 +#ifdef CONFIG_VSERVER_PROC_SECURE
11378 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
11379 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11380 +#else
11381 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
11382 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11383 +#endif
11384 +
11385 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
11386 +
11387 +#else  /* _VSERVER_INODE_H */
11388 +#warning duplicate inclusion
11389 +#endif /* _VSERVER_INODE_H */
11390 diff -NurpP --minimal linux-3.10.33/include/linux/vserver/inode_cmd.h linux-3.10.33-vs2.3.6.8/include/linux/vserver/inode_cmd.h
11391 --- linux-3.10.33/include/linux/vserver/inode_cmd.h     1970-01-01 00:00:00.000000000 +0000
11392 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/inode_cmd.h   2013-08-22 20:30:00.000000000 +0000
11393 @@ -0,0 +1,36 @@
11394 +#ifndef _VSERVER_INODE_CMD_H
11395 +#define _VSERVER_INODE_CMD_H
11396 +
11397 +#include <uapi/vserver/inode_cmd.h>
11398 +
11399 +
11400 +
11401 +#ifdef CONFIG_COMPAT
11402 +
11403 +#include <asm/compat.h>
11404 +
11405 +struct vcmd_ctx_iattr_v1_x32 {
11406 +       compat_uptr_t name_ptr;
11407 +       uint32_t tag;
11408 +       uint32_t flags;
11409 +       uint32_t mask;
11410 +};
11411 +
11412 +#endif /* CONFIG_COMPAT */
11413 +
11414 +#include <linux/compiler.h>
11415 +
11416 +extern int vc_get_iattr(void __user *);
11417 +extern int vc_set_iattr(void __user *);
11418 +
11419 +extern int vc_fget_iattr(uint32_t, void __user *);
11420 +extern int vc_fset_iattr(uint32_t, void __user *);
11421 +
11422 +#ifdef CONFIG_COMPAT
11423 +
11424 +extern int vc_get_iattr_x32(void __user *);
11425 +extern int vc_set_iattr_x32(void __user *);
11426 +
11427 +#endif /* CONFIG_COMPAT */
11428 +
11429 +#endif /* _VSERVER_INODE_CMD_H */
11430 diff -NurpP --minimal linux-3.10.33/include/linux/vserver/limit.h linux-3.10.33-vs2.3.6.8/include/linux/vserver/limit.h
11431 --- linux-3.10.33/include/linux/vserver/limit.h 1970-01-01 00:00:00.000000000 +0000
11432 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/limit.h       2013-08-22 20:30:00.000000000 +0000
11433 @@ -0,0 +1,61 @@
11434 +#ifndef _VSERVER_LIMIT_H
11435 +#define _VSERVER_LIMIT_H
11436 +
11437 +#include <uapi/vserver/limit.h>
11438 +
11439 +
11440 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
11441 +
11442 +/*     keep in sync with CRLIM_INFINITY */
11443 +
11444 +#define        VLIM_INFINITY   (~0ULL)
11445 +
11446 +#include <asm/atomic.h>
11447 +#include <asm/resource.h>
11448 +
11449 +#ifndef RLIM_INFINITY
11450 +#warning RLIM_INFINITY is undefined
11451 +#endif
11452 +
11453 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
11454 +
11455 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
11456 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
11457 +
11458 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
11459 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
11460 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
11461 +
11462 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
11463 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
11464 +
11465 +typedef atomic_long_t rlim_atomic_t;
11466 +typedef unsigned long rlim_t;
11467 +
11468 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
11469 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
11470 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
11471 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
11472 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
11473 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
11474 +
11475 +
11476 +#if    (RLIM_INFINITY == VLIM_INFINITY)
11477 +#define        VX_VLIM(r) ((long long)(long)(r))
11478 +#define        VX_RLIM(v) ((rlim_t)(v))
11479 +#else
11480 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
11481 +               ? VLIM_INFINITY : (long long)(r))
11482 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
11483 +               ? RLIM_INFINITY : (rlim_t)(v))
11484 +#endif
11485 +
11486 +struct sysinfo;
11487 +
11488 +void vx_vsi_meminfo(struct sysinfo *);
11489 +void vx_vsi_swapinfo(struct sysinfo *);
11490 +long vx_vsi_cached(struct sysinfo *);
11491 +
11492 +#define NUM_LIMITS     24
11493 +
11494 +#endif /* _VSERVER_LIMIT_H */
11495 diff -NurpP --minimal linux-3.10.33/include/linux/vserver/limit_cmd.h linux-3.10.33-vs2.3.6.8/include/linux/vserver/limit_cmd.h
11496 --- linux-3.10.33/include/linux/vserver/limit_cmd.h     1970-01-01 00:00:00.000000000 +0000
11497 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/limit_cmd.h   2013-08-22 20:30:00.000000000 +0000
11498 @@ -0,0 +1,35 @@
11499 +#ifndef _VSERVER_LIMIT_CMD_H
11500 +#define _VSERVER_LIMIT_CMD_H
11501 +
11502 +#include <uapi/vserver/limit_cmd.h>
11503 +
11504 +
11505 +#ifdef CONFIG_IA32_EMULATION
11506 +
11507 +struct vcmd_ctx_rlimit_v0_x32 {
11508 +       uint32_t id;
11509 +       uint64_t minimum;
11510 +       uint64_t softlimit;
11511 +       uint64_t maximum;
11512 +} __attribute__ ((packed));
11513 +
11514 +#endif /* CONFIG_IA32_EMULATION */
11515 +
11516 +#include <linux/compiler.h>
11517 +
11518 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
11519 +extern int vc_get_rlimit(struct vx_info *, void __user *);
11520 +extern int vc_set_rlimit(struct vx_info *, void __user *);
11521 +extern int vc_reset_hits(struct vx_info *, void __user *);
11522 +extern int vc_reset_minmax(struct vx_info *, void __user *);
11523 +
11524 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
11525 +
11526 +#ifdef CONFIG_IA32_EMULATION
11527 +
11528 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
11529 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
11530 +
11531 +#endif /* CONFIG_IA32_EMULATION */
11532 +
11533 +#endif /* _VSERVER_LIMIT_CMD_H */
11534 diff -NurpP --minimal linux-3.10.33/include/linux/vserver/limit_def.h linux-3.10.33-vs2.3.6.8/include/linux/vserver/limit_def.h
11535 --- linux-3.10.33/include/linux/vserver/limit_def.h     1970-01-01 00:00:00.000000000 +0000
11536 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/limit_def.h   2013-08-22 20:30:00.000000000 +0000
11537 @@ -0,0 +1,47 @@
11538 +#ifndef _VSERVER_LIMIT_DEF_H
11539 +#define _VSERVER_LIMIT_DEF_H
11540 +
11541 +#include <asm/atomic.h>
11542 +#include <asm/resource.h>
11543 +
11544 +#include "limit.h"
11545 +
11546 +
11547 +struct _vx_res_limit {
11548 +       rlim_t soft;            /* Context soft limit */
11549 +       rlim_t hard;            /* Context hard limit */
11550 +
11551 +       rlim_atomic_t rcur;     /* Current value */
11552 +       rlim_t rmin;            /* Context minimum */
11553 +       rlim_t rmax;            /* Context maximum */
11554 +
11555 +       atomic_t lhit;          /* Limit hits */
11556 +};
11557 +
11558 +/* context sub struct */
11559 +
11560 +struct _vx_limit {
11561 +       struct _vx_res_limit res[NUM_LIMITS];
11562 +};
11563 +
11564 +#ifdef CONFIG_VSERVER_DEBUG
11565 +
11566 +static inline void __dump_vx_limit(struct _vx_limit *limit)
11567 +{
11568 +       int i;
11569 +
11570 +       printk("\t_vx_limit:");
11571 +       for (i = 0; i < NUM_LIMITS; i++) {
11572 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
11573 +                       i, (unsigned long)__rlim_get(limit, i),
11574 +                       (unsigned long)__rlim_rmin(limit, i),
11575 +                       (unsigned long)__rlim_rmax(limit, i),
11576 +                       (long)__rlim_soft(limit, i),
11577 +                       (long)__rlim_hard(limit, i),
11578 +                       atomic_read(&__rlim_lhit(limit, i)));
11579 +       }
11580 +}
11581 +
11582 +#endif
11583 +
11584 +#endif /* _VSERVER_LIMIT_DEF_H */
11585 diff -NurpP --minimal linux-3.10.33/include/linux/vserver/limit_int.h linux-3.10.33-vs2.3.6.8/include/linux/vserver/limit_int.h
11586 --- linux-3.10.33/include/linux/vserver/limit_int.h     1970-01-01 00:00:00.000000000 +0000
11587 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/limit_int.h   2013-08-22 20:30:00.000000000 +0000
11588 @@ -0,0 +1,193 @@
11589 +#ifndef _VSERVER_LIMIT_INT_H
11590 +#define _VSERVER_LIMIT_INT_H
11591 +
11592 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
11593 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
11594 +
11595 +extern const char *vlimit_name[NUM_LIMITS];
11596 +
11597 +static inline void __vx_acc_cres(struct vx_info *vxi,
11598 +       int res, int dir, void *_data, char *_file, int _line)
11599 +{
11600 +       if (VXD_RCRES_COND(res))
11601 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
11602 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11603 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11604 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
11605 +       if (!vxi)
11606 +               return;
11607 +
11608 +       if (dir > 0)
11609 +               __rlim_inc(&vxi->limit, res);
11610 +       else
11611 +               __rlim_dec(&vxi->limit, res);
11612 +}
11613 +
11614 +static inline void __vx_add_cres(struct vx_info *vxi,
11615 +       int res, int amount, void *_data, char *_file, int _line)
11616 +{
11617 +       if (VXD_RCRES_COND(res))
11618 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
11619 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11620 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11621 +                       amount, _data, _file, _line);
11622 +       if (amount == 0)
11623 +               return;
11624 +       if (!vxi)
11625 +               return;
11626 +       __rlim_add(&vxi->limit, res, amount);
11627 +}
11628 +
11629 +static inline
11630 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
11631 +{
11632 +       int cond = (value > __rlim_rmax(limit, res));
11633 +
11634 +       if (cond)
11635 +               __rlim_rmax(limit, res) = value;
11636 +       return cond;
11637 +}
11638 +
11639 +static inline
11640 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
11641 +{
11642 +       int cond = (value < __rlim_rmin(limit, res));
11643 +
11644 +       if (cond)
11645 +               __rlim_rmin(limit, res) = value;
11646 +       return cond;
11647 +}
11648 +
11649 +static inline
11650 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
11651 +{
11652 +       if (!__vx_cres_adjust_max(limit, res, value))
11653 +               __vx_cres_adjust_min(limit, res, value);
11654 +}
11655 +
11656 +
11657 +/*     return values:
11658 +        +1 ... no limit hit
11659 +        -1 ... over soft limit
11660 +         0 ... over hard limit         */
11661 +
11662 +static inline int __vx_cres_avail(struct vx_info *vxi,
11663 +       int res, int num, char *_file, int _line)
11664 +{
11665 +       struct _vx_limit *limit;
11666 +       rlim_t value;
11667 +
11668 +       if (VXD_RLIMIT_COND(res))
11669 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
11670 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11671 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
11672 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
11673 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11674 +                       num, _file, _line);
11675 +       if (!vxi)
11676 +               return 1;
11677 +
11678 +       limit = &vxi->limit;
11679 +       value = __rlim_get(limit, res);
11680 +
11681 +       if (!__vx_cres_adjust_max(limit, res, value))
11682 +               __vx_cres_adjust_min(limit, res, value);
11683 +
11684 +       if (num == 0)
11685 +               return 1;
11686 +
11687 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
11688 +               return -1;
11689 +       if (value + num <= __rlim_soft(limit, res))
11690 +               return -1;
11691 +
11692 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
11693 +               return 1;
11694 +       if (value + num <= __rlim_hard(limit, res))
11695 +               return 1;
11696 +
11697 +       __rlim_hit(limit, res);
11698 +       return 0;
11699 +}
11700 +
11701 +
11702 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
11703 +
11704 +static inline
11705 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
11706 +{
11707 +       rlim_t value, sum = 0;
11708 +       int res;
11709 +
11710 +       while ((res = *array++)) {
11711 +               value = __rlim_get(limit, res);
11712 +               __vx_cres_fixup(limit, res, value);
11713 +               sum += value;
11714 +       }
11715 +       return sum;
11716 +}
11717 +
11718 +static inline
11719 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
11720 +{
11721 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
11722 +       int res = *array;
11723 +
11724 +       if (value == __rlim_get(limit, res))
11725 +               return value;
11726 +
11727 +       __rlim_set(limit, res, value);
11728 +       /* now adjust min/max */
11729 +       if (!__vx_cres_adjust_max(limit, res, value))
11730 +               __vx_cres_adjust_min(limit, res, value);
11731 +
11732 +       return value;
11733 +}
11734 +
11735 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
11736 +       const int *array, int num, char *_file, int _line)
11737 +{
11738 +       struct _vx_limit *limit;
11739 +       rlim_t value = 0;
11740 +       int res;
11741 +
11742 +       if (num == 0)
11743 +               return 1;
11744 +       if (!vxi)
11745 +               return 1;
11746 +
11747 +       limit = &vxi->limit;
11748 +       res = *array;
11749 +       value = __vx_cres_array_sum(limit, array + 1);
11750 +
11751 +       __rlim_set(limit, res, value);
11752 +       __vx_cres_fixup(limit, res, value);
11753 +
11754 +       return __vx_cres_avail(vxi, res, num, _file, _line);
11755 +}
11756 +
11757 +
11758 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
11759 +{
11760 +       rlim_t value;
11761 +       int res;
11762 +
11763 +       /* complex resources first */
11764 +       if ((id < 0) || (id == RLIMIT_RSS))
11765 +               __vx_cres_array_fixup(limit, VLA_RSS);
11766 +
11767 +       for (res = 0; res < NUM_LIMITS; res++) {
11768 +               if ((id > 0) && (res != id))
11769 +                       continue;
11770 +
11771 +               value = __rlim_get(limit, res);
11772 +               __vx_cres_fixup(limit, res, value);
11773 +
11774 +               /* not supposed to happen, maybe warn? */
11775 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
11776 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
11777 +       }
11778 +}
11779 +
11780 +
11781 +#endif /* _VSERVER_LIMIT_INT_H */
11782 diff -NurpP --minimal linux-3.10.33/include/linux/vserver/monitor.h linux-3.10.33-vs2.3.6.8/include/linux/vserver/monitor.h
11783 --- linux-3.10.33/include/linux/vserver/monitor.h       1970-01-01 00:00:00.000000000 +0000
11784 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/monitor.h     2013-08-22 20:30:00.000000000 +0000
11785 @@ -0,0 +1,6 @@
11786 +#ifndef _VSERVER_MONITOR_H
11787 +#define _VSERVER_MONITOR_H
11788 +
11789 +#include <uapi/vserver/monitor.h>
11790 +
11791 +#endif /* _VSERVER_MONITOR_H */
11792 diff -NurpP --minimal linux-3.10.33/include/linux/vserver/network.h linux-3.10.33-vs2.3.6.8/include/linux/vserver/network.h
11793 --- linux-3.10.33/include/linux/vserver/network.h       1970-01-01 00:00:00.000000000 +0000
11794 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/network.h     2013-08-22 20:30:00.000000000 +0000
11795 @@ -0,0 +1,76 @@
11796 +#ifndef _VSERVER_NETWORK_H
11797 +#define _VSERVER_NETWORK_H
11798 +
11799 +
11800 +#include <linux/list.h>
11801 +#include <linux/spinlock.h>
11802 +#include <linux/rcupdate.h>
11803 +#include <linux/in.h>
11804 +#include <linux/in6.h>
11805 +#include <asm/atomic.h>
11806 +#include <uapi/vserver/network.h>
11807 +
11808 +struct nx_addr_v4 {
11809 +       struct nx_addr_v4 *next;
11810 +       struct in_addr ip[2];
11811 +       struct in_addr mask;
11812 +       uint16_t type;
11813 +       uint16_t flags;
11814 +};
11815 +
11816 +struct nx_addr_v6 {
11817 +       struct nx_addr_v6 *next;
11818 +       struct in6_addr ip;
11819 +       struct in6_addr mask;
11820 +       uint32_t prefix;
11821 +       uint16_t type;
11822 +       uint16_t flags;
11823 +};
11824 +
11825 +struct nx_info {
11826 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
11827 +       vnid_t nx_id;                   /* vnet id */
11828 +       atomic_t nx_usecnt;             /* usage count */
11829 +       atomic_t nx_tasks;              /* tasks count */
11830 +       int nx_state;                   /* context state */
11831 +
11832 +       uint64_t nx_flags;              /* network flag word */
11833 +       uint64_t nx_ncaps;              /* network capabilities */
11834 +
11835 +       spinlock_t addr_lock;           /* protect address changes */
11836 +       struct in_addr v4_lback;        /* Loopback address */
11837 +       struct in_addr v4_bcast;        /* Broadcast address */
11838 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
11839 +#ifdef CONFIG_IPV6
11840 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
11841 +#endif
11842 +       char nx_name[65];               /* network context name */
11843 +};
11844 +
11845 +
11846 +/* status flags */
11847 +
11848 +#define NXS_HASHED      0x0001
11849 +#define NXS_SHUTDOWN    0x0100
11850 +#define NXS_RELEASED    0x8000
11851 +
11852 +extern struct nx_info *lookup_nx_info(int);
11853 +
11854 +extern int get_nid_list(int, unsigned int *, int);
11855 +extern int nid_is_hashed(vnid_t);
11856 +
11857 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
11858 +
11859 +extern long vs_net_change(struct nx_info *, unsigned int);
11860 +
11861 +struct sock;
11862 +
11863 +
11864 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
11865 +#ifdef  CONFIG_IPV6
11866 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
11867 +#else
11868 +#define NX_IPV6(n)     (0)
11869 +#endif
11870 +
11871 +#endif /* _VSERVER_NETWORK_H */
11872 diff -NurpP --minimal linux-3.10.33/include/linux/vserver/network_cmd.h linux-3.10.33-vs2.3.6.8/include/linux/vserver/network_cmd.h
11873 --- linux-3.10.33/include/linux/vserver/network_cmd.h   1970-01-01 00:00:00.000000000 +0000
11874 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/network_cmd.h 2013-08-22 20:30:00.000000000 +0000
11875 @@ -0,0 +1,37 @@
11876 +#ifndef _VSERVER_NETWORK_CMD_H
11877 +#define _VSERVER_NETWORK_CMD_H
11878 +
11879 +#include <uapi/vserver/network_cmd.h>
11880 +
11881 +extern int vc_task_nid(uint32_t);
11882 +
11883 +extern int vc_nx_info(struct nx_info *, void __user *);
11884 +
11885 +extern int vc_net_create(uint32_t, void __user *);
11886 +extern int vc_net_migrate(struct nx_info *, void __user *);
11887 +
11888 +extern int vc_net_add(struct nx_info *, void __user *);
11889 +extern int vc_net_remove(struct nx_info *, void __user *);
11890 +
11891 +extern int vc_net_add_ipv4_v1(struct nx_info *, void __user *);
11892 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
11893 +
11894 +extern int vc_net_rem_ipv4_v1(struct nx_info *, void __user *);
11895 +extern int vc_net_rem_ipv4(struct nx_info *, void __user *);
11896 +
11897 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
11898 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
11899 +
11900 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
11901 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
11902 +
11903 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
11904 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
11905 +
11906 +extern int vc_get_nflags(struct nx_info *, void __user *);
11907 +extern int vc_set_nflags(struct nx_info *, void __user *);
11908 +
11909 +extern int vc_get_ncaps(struct nx_info *, void __user *);
11910 +extern int vc_set_ncaps(struct nx_info *, void __user *);
11911 +
11912 +#endif /* _VSERVER_CONTEXT_CMD_H */
11913 diff -NurpP --minimal linux-3.10.33/include/linux/vserver/percpu.h linux-3.10.33-vs2.3.6.8/include/linux/vserver/percpu.h
11914 --- linux-3.10.33/include/linux/vserver/percpu.h        1970-01-01 00:00:00.000000000 +0000
11915 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/percpu.h      2013-08-22 20:30:00.000000000 +0000
11916 @@ -0,0 +1,14 @@
11917 +#ifndef _VSERVER_PERCPU_H
11918 +#define _VSERVER_PERCPU_H
11919 +
11920 +#include "cvirt_def.h"
11921 +#include "sched_def.h"
11922 +
11923 +struct _vx_percpu {
11924 +       struct _vx_cvirt_pc cvirt;
11925 +       struct _vx_sched_pc sched;
11926 +};
11927 +
11928 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
11929 +
11930 +#endif /* _VSERVER_PERCPU_H */
11931 diff -NurpP --minimal linux-3.10.33/include/linux/vserver/pid.h linux-3.10.33-vs2.3.6.8/include/linux/vserver/pid.h
11932 --- linux-3.10.33/include/linux/vserver/pid.h   1970-01-01 00:00:00.000000000 +0000
11933 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/pid.h 2013-08-22 20:30:00.000000000 +0000
11934 @@ -0,0 +1,51 @@
11935 +#ifndef _VSERVER_PID_H
11936 +#define _VSERVER_PID_H
11937 +
11938 +/* pid faking stuff */
11939 +
11940 +#define vx_info_map_pid(v, p) \
11941 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
11942 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
11943 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
11944 +#define vx_map_tgid(p) vx_map_pid(p)
11945 +
11946 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
11947 +       const char *func, const char *file, int line)
11948 +{
11949 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
11950 +               vxfprintk(VXD_CBIT(cvirt, 2),
11951 +                       "vx_map_tgid: %p/%llx: %d -> %d",
11952 +                       vxi, (long long)vxi->vx_flags, pid,
11953 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
11954 +                       func, file, line);
11955 +               if (pid == 0)
11956 +                       return 0;
11957 +               if (pid == vxi->vx_initpid)
11958 +                       return 1;
11959 +       }
11960 +       return pid;
11961 +}
11962 +
11963 +#define vx_info_rmap_pid(v, p) \
11964 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
11965 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
11966 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
11967 +
11968 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
11969 +       const char *func, const char *file, int line)
11970 +{
11971 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
11972 +               vxfprintk(VXD_CBIT(cvirt, 2),
11973 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
11974 +                       vxi, (long long)vxi->vx_flags, pid,
11975 +                       (pid == 1) ? vxi->vx_initpid : pid,
11976 +                       func, file, line);
11977 +               if ((pid == 1) && vxi->vx_initpid)
11978 +                       return vxi->vx_initpid;
11979 +               if (pid == vxi->vx_initpid)
11980 +                       return ~0U;
11981 +       }
11982 +       return pid;
11983 +}
11984 +
11985 +#endif
11986 diff -NurpP --minimal linux-3.10.33/include/linux/vserver/sched.h linux-3.10.33-vs2.3.6.8/include/linux/vserver/sched.h
11987 --- linux-3.10.33/include/linux/vserver/sched.h 1970-01-01 00:00:00.000000000 +0000
11988 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/sched.h       2013-08-22 20:30:00.000000000 +0000
11989 @@ -0,0 +1,23 @@
11990 +#ifndef _VSERVER_SCHED_H
11991 +#define _VSERVER_SCHED_H
11992 +
11993 +
11994 +#ifdef __KERNEL__
11995 +
11996 +struct timespec;
11997 +
11998 +void vx_vsi_uptime(struct timespec *, struct timespec *);
11999 +
12000 +
12001 +struct vx_info;
12002 +
12003 +void vx_update_load(struct vx_info *);
12004 +
12005 +
12006 +void vx_update_sched_param(struct _vx_sched *sched,
12007 +       struct _vx_sched_pc *sched_pc);
12008 +
12009 +#endif /* __KERNEL__ */
12010 +#else  /* _VSERVER_SCHED_H */
12011 +#warning duplicate inclusion
12012 +#endif /* _VSERVER_SCHED_H */
12013 diff -NurpP --minimal linux-3.10.33/include/linux/vserver/sched_cmd.h linux-3.10.33-vs2.3.6.8/include/linux/vserver/sched_cmd.h
12014 --- linux-3.10.33/include/linux/vserver/sched_cmd.h     1970-01-01 00:00:00.000000000 +0000
12015 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/sched_cmd.h   2013-08-22 20:30:00.000000000 +0000
12016 @@ -0,0 +1,11 @@
12017 +#ifndef _VSERVER_SCHED_CMD_H
12018 +#define _VSERVER_SCHED_CMD_H
12019 +
12020 +
12021 +#include <linux/compiler.h>
12022 +#include <uapi/vserver/sched_cmd.h>
12023 +
12024 +extern int vc_set_prio_bias(struct vx_info *, void __user *);
12025 +extern int vc_get_prio_bias(struct vx_info *, void __user *);
12026 +
12027 +#endif /* _VSERVER_SCHED_CMD_H */
12028 diff -NurpP --minimal linux-3.10.33/include/linux/vserver/sched_def.h linux-3.10.33-vs2.3.6.8/include/linux/vserver/sched_def.h
12029 --- linux-3.10.33/include/linux/vserver/sched_def.h     1970-01-01 00:00:00.000000000 +0000
12030 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/sched_def.h   2013-08-22 20:30:00.000000000 +0000
12031 @@ -0,0 +1,38 @@
12032 +#ifndef _VSERVER_SCHED_DEF_H
12033 +#define _VSERVER_SCHED_DEF_H
12034 +
12035 +#include <linux/spinlock.h>
12036 +#include <linux/jiffies.h>
12037 +#include <linux/cpumask.h>
12038 +#include <asm/atomic.h>
12039 +#include <asm/param.h>
12040 +
12041 +
12042 +/* context sub struct */
12043 +
12044 +struct _vx_sched {
12045 +       int prio_bias;                  /* bias offset for priority */
12046 +
12047 +       cpumask_t update;               /* CPUs which should update */
12048 +};
12049 +
12050 +struct _vx_sched_pc {
12051 +       int prio_bias;                  /* bias offset for priority */
12052 +
12053 +       uint64_t user_ticks;            /* token tick events */
12054 +       uint64_t sys_ticks;             /* token tick events */
12055 +       uint64_t hold_ticks;            /* token ticks paused */
12056 +};
12057 +
12058 +
12059 +#ifdef CONFIG_VSERVER_DEBUG
12060 +
12061 +static inline void __dump_vx_sched(struct _vx_sched *sched)
12062 +{
12063 +       printk("\t_vx_sched:\n");
12064 +       printk("\t priority = %4d\n", sched->prio_bias);
12065 +}
12066 +
12067 +#endif
12068 +
12069 +#endif /* _VSERVER_SCHED_DEF_H */
12070 diff -NurpP --minimal linux-3.10.33/include/linux/vserver/signal.h linux-3.10.33-vs2.3.6.8/include/linux/vserver/signal.h
12071 --- linux-3.10.33/include/linux/vserver/signal.h        1970-01-01 00:00:00.000000000 +0000
12072 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/signal.h      2013-08-22 20:30:00.000000000 +0000
12073 @@ -0,0 +1,14 @@
12074 +#ifndef _VSERVER_SIGNAL_H
12075 +#define _VSERVER_SIGNAL_H
12076 +
12077 +
12078 +#ifdef __KERNEL__
12079 +
12080 +struct vx_info;
12081 +
12082 +int vx_info_kill(struct vx_info *, int, int);
12083 +
12084 +#endif /* __KERNEL__ */
12085 +#else  /* _VSERVER_SIGNAL_H */
12086 +#warning duplicate inclusion
12087 +#endif /* _VSERVER_SIGNAL_H */
12088 diff -NurpP --minimal linux-3.10.33/include/linux/vserver/signal_cmd.h linux-3.10.33-vs2.3.6.8/include/linux/vserver/signal_cmd.h
12089 --- linux-3.10.33/include/linux/vserver/signal_cmd.h    1970-01-01 00:00:00.000000000 +0000
12090 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/signal_cmd.h  2013-08-22 20:30:00.000000000 +0000
12091 @@ -0,0 +1,14 @@
12092 +#ifndef _VSERVER_SIGNAL_CMD_H
12093 +#define _VSERVER_SIGNAL_CMD_H
12094 +
12095 +#include <uapi/vserver/signal_cmd.h>
12096 +
12097 +
12098 +extern int vc_ctx_kill(struct vx_info *, void __user *);
12099 +extern int vc_wait_exit(struct vx_info *, void __user *);
12100 +
12101 +
12102 +extern int vc_get_pflags(uint32_t pid, void __user *);
12103 +extern int vc_set_pflags(uint32_t pid, void __user *);
12104 +
12105 +#endif /* _VSERVER_SIGNAL_CMD_H */
12106 diff -NurpP --minimal linux-3.10.33/include/linux/vserver/space.h linux-3.10.33-vs2.3.6.8/include/linux/vserver/space.h
12107 --- linux-3.10.33/include/linux/vserver/space.h 1970-01-01 00:00:00.000000000 +0000
12108 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/space.h       2013-08-22 20:30:00.000000000 +0000
12109 @@ -0,0 +1,12 @@
12110 +#ifndef _VSERVER_SPACE_H
12111 +#define _VSERVER_SPACE_H
12112 +
12113 +#include <linux/types.h>
12114 +
12115 +struct vx_info;
12116 +
12117 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
12118 +
12119 +#else  /* _VSERVER_SPACE_H */
12120 +#warning duplicate inclusion
12121 +#endif /* _VSERVER_SPACE_H */
12122 diff -NurpP --minimal linux-3.10.33/include/linux/vserver/space_cmd.h linux-3.10.33-vs2.3.6.8/include/linux/vserver/space_cmd.h
12123 --- linux-3.10.33/include/linux/vserver/space_cmd.h     1970-01-01 00:00:00.000000000 +0000
12124 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/space_cmd.h   2013-08-22 20:30:00.000000000 +0000
12125 @@ -0,0 +1,13 @@
12126 +#ifndef _VSERVER_SPACE_CMD_H
12127 +#define _VSERVER_SPACE_CMD_H
12128 +
12129 +#include <uapi/vserver/space_cmd.h>
12130 +
12131 +
12132 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
12133 +extern int vc_set_space_v1(struct vx_info *, void __user *);
12134 +extern int vc_enter_space(struct vx_info *, void __user *);
12135 +extern int vc_set_space(struct vx_info *, void __user *);
12136 +extern int vc_get_space_mask(void __user *, int);
12137 +
12138 +#endif /* _VSERVER_SPACE_CMD_H */
12139 diff -NurpP --minimal linux-3.10.33/include/linux/vserver/switch.h linux-3.10.33-vs2.3.6.8/include/linux/vserver/switch.h
12140 --- linux-3.10.33/include/linux/vserver/switch.h        1970-01-01 00:00:00.000000000 +0000
12141 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/switch.h      2013-08-22 20:30:00.000000000 +0000
12142 @@ -0,0 +1,8 @@
12143 +#ifndef _VSERVER_SWITCH_H
12144 +#define _VSERVER_SWITCH_H
12145 +
12146 +
12147 +#include <linux/errno.h>
12148 +#include <uapi/vserver/switch.h>
12149 +
12150 +#endif /* _VSERVER_SWITCH_H */
12151 diff -NurpP --minimal linux-3.10.33/include/linux/vserver/tag.h linux-3.10.33-vs2.3.6.8/include/linux/vserver/tag.h
12152 --- linux-3.10.33/include/linux/vserver/tag.h   1970-01-01 00:00:00.000000000 +0000
12153 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/tag.h 2013-08-22 20:30:00.000000000 +0000
12154 @@ -0,0 +1,160 @@
12155 +#ifndef _DX_TAG_H
12156 +#define _DX_TAG_H
12157 +
12158 +#include <linux/types.h>
12159 +#include <linux/uidgid.h>
12160 +
12161 +
12162 +#define DX_TAG(in)     (IS_TAGGED(in))
12163 +
12164 +
12165 +#ifdef CONFIG_TAG_NFSD
12166 +#define DX_TAG_NFSD    1
12167 +#else
12168 +#define DX_TAG_NFSD    0
12169 +#endif
12170 +
12171 +
12172 +#ifdef CONFIG_TAGGING_NONE
12173 +
12174 +#define MAX_UID                0xFFFFFFFF
12175 +#define MAX_GID                0xFFFFFFFF
12176 +
12177 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
12178 +
12179 +#define TAGINO_UID(cond, uid, tag)     (uid)
12180 +#define TAGINO_GID(cond, gid, tag)     (gid)
12181 +
12182 +#endif
12183 +
12184 +
12185 +#ifdef CONFIG_TAGGING_GID16
12186 +
12187 +#define MAX_UID                0xFFFFFFFF
12188 +#define MAX_GID                0x0000FFFF
12189 +
12190 +#define INOTAG_TAG(cond, uid, gid, tag)        \
12191 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
12192 +
12193 +#define TAGINO_UID(cond, uid, tag)     (uid)
12194 +#define TAGINO_GID(cond, gid, tag)     \
12195 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
12196 +
12197 +#endif
12198 +
12199 +
12200 +#ifdef CONFIG_TAGGING_ID24
12201 +
12202 +#define MAX_UID                0x00FFFFFF
12203 +#define MAX_GID                0x00FFFFFF
12204 +
12205 +#define INOTAG_TAG(cond, uid, gid, tag)        \
12206 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
12207 +
12208 +#define TAGINO_UID(cond, uid, tag)     \
12209 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
12210 +#define TAGINO_GID(cond, gid, tag)     \
12211 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
12212 +
12213 +#endif
12214 +
12215 +
12216 +#ifdef CONFIG_TAGGING_UID16
12217 +
12218 +#define MAX_UID                0x0000FFFF
12219 +#define MAX_GID                0xFFFFFFFF
12220 +
12221 +#define INOTAG_TAG(cond, uid, gid, tag)        \
12222 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
12223 +
12224 +#define TAGINO_UID(cond, uid, tag)     \
12225 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
12226 +#define TAGINO_GID(cond, gid, tag)     (gid)
12227 +
12228 +#endif
12229 +
12230 +
12231 +#ifdef CONFIG_TAGGING_INTERN
12232 +
12233 +#define MAX_UID                0xFFFFFFFF
12234 +#define MAX_GID                0xFFFFFFFF
12235 +
12236 +#define INOTAG_TAG(cond, uid, gid, tag)        \
12237 +       ((cond) ? (tag) : 0)
12238 +
12239 +#define TAGINO_UID(cond, uid, tag)     (uid)
12240 +#define TAGINO_GID(cond, gid, tag)     (gid)
12241 +
12242 +#endif
12243 +
12244 +
12245 +#ifndef CONFIG_TAGGING_NONE
12246 +#define dx_current_fstag(sb)   \
12247 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
12248 +#else
12249 +#define dx_current_fstag(sb)   (0)
12250 +#endif
12251 +
12252 +#ifndef CONFIG_TAGGING_INTERN
12253 +#define TAGINO_TAG(cond, tag)  (0)
12254 +#else
12255 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
12256 +#endif
12257 +
12258 +#define TAGINO_KUID(cond, kuid, ktag)  \
12259 +       KUIDT_INIT(TAGINO_UID(cond, __kuid_val(kuid), __ktag_val(ktag)))
12260 +#define TAGINO_KGID(cond, kgid, ktag)  \
12261 +       KGIDT_INIT(TAGINO_GID(cond, __kgid_val(kgid), __ktag_val(ktag)))
12262 +#define TAGINO_KTAG(cond, ktag)                \
12263 +       KTAGT_INIT(TAGINO_TAG(cond, __ktag_val(ktag)))
12264 +
12265 +
12266 +#define INOTAG_UID(cond, uid, gid)     \
12267 +       ((cond) ? ((uid) & MAX_UID) : (uid))
12268 +#define INOTAG_GID(cond, uid, gid)     \
12269 +       ((cond) ? ((gid) & MAX_GID) : (gid))
12270 +
12271 +#define INOTAG_KUID(cond, kuid, kgid)  \
12272 +       KUIDT_INIT(INOTAG_UID(cond, __kuid_val(kuid), __kgid_val(kgid)))
12273 +#define INOTAG_KGID(cond, kuid, kgid)  \
12274 +       KGIDT_INIT(INOTAG_GID(cond, __kuid_val(kuid), __kgid_val(kgid)))
12275 +#define INOTAG_KTAG(cond, kuid, kgid, ktag) \
12276 +       KTAGT_INIT(INOTAG_TAG(cond, \
12277 +               __kuid_val(kuid), __kgid_val(kgid), __ktag_val(ktag)))
12278 +
12279 +
12280 +static inline uid_t dx_map_uid(uid_t uid)
12281 +{
12282 +       if ((uid > MAX_UID) && (uid != -1))
12283 +               uid = -2;
12284 +       return (uid & MAX_UID);
12285 +}
12286 +
12287 +static inline gid_t dx_map_gid(gid_t gid)
12288 +{
12289 +       if ((gid > MAX_GID) && (gid != -1))
12290 +               gid = -2;
12291 +       return (gid & MAX_GID);
12292 +}
12293 +
12294 +struct peer_tag {
12295 +       int32_t xid;
12296 +       int32_t nid;
12297 +};
12298 +
12299 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
12300 +
12301 +int dx_parse_tag(char *string, vtag_t *tag, int remove, int *mnt_flags,
12302 +                unsigned long *flags);
12303 +
12304 +#ifdef CONFIG_PROPAGATE
12305 +
12306 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
12307 +
12308 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
12309 +
12310 +#else
12311 +#define dx_propagate_tag(n, i) do { } while (0)
12312 +#endif
12313 +
12314 +#endif /* _DX_TAG_H */
12315 diff -NurpP --minimal linux-3.10.33/include/linux/vserver/tag_cmd.h linux-3.10.33-vs2.3.6.8/include/linux/vserver/tag_cmd.h
12316 --- linux-3.10.33/include/linux/vserver/tag_cmd.h       1970-01-01 00:00:00.000000000 +0000
12317 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/tag_cmd.h     2013-08-22 20:30:00.000000000 +0000
12318 @@ -0,0 +1,10 @@
12319 +#ifndef _VSERVER_TAG_CMD_H
12320 +#define _VSERVER_TAG_CMD_H
12321 +
12322 +#include <uapi/vserver/tag_cmd.h>
12323 +
12324 +extern int vc_task_tag(uint32_t);
12325 +
12326 +extern int vc_tag_migrate(uint32_t);
12327 +
12328 +#endif /* _VSERVER_TAG_CMD_H */
12329 diff -NurpP --minimal linux-3.10.33/include/net/addrconf.h linux-3.10.33-vs2.3.6.8/include/net/addrconf.h
12330 --- linux-3.10.33/include/net/addrconf.h        2014-03-12 13:16:02.000000000 +0000
12331 +++ linux-3.10.33-vs2.3.6.8/include/net/addrconf.h      2013-11-13 17:19:37.000000000 +0000
12332 @@ -89,7 +89,8 @@ extern int                    ipv6_dev_get_saddr(struct n
12333                                                const struct net_device *dev,
12334                                                const struct in6_addr *daddr,
12335                                                unsigned int srcprefs,
12336 -                                              struct in6_addr *saddr);
12337 +                                              struct in6_addr *saddr,
12338 +                                              struct nx_info *nxi);
12339  extern int                     __ipv6_get_lladdr(struct inet6_dev *idev,
12340                                                   struct in6_addr *addr,
12341                                                   unsigned char banned_flags);
12342 diff -NurpP --minimal linux-3.10.33/include/net/af_unix.h linux-3.10.33-vs2.3.6.8/include/net/af_unix.h
12343 --- linux-3.10.33/include/net/af_unix.h 2013-07-14 17:01:33.000000000 +0000
12344 +++ linux-3.10.33-vs2.3.6.8/include/net/af_unix.h       2013-08-22 20:30:00.000000000 +0000
12345 @@ -4,6 +4,7 @@
12346  #include <linux/socket.h>
12347  #include <linux/un.h>
12348  #include <linux/mutex.h>
12349 +#include <linux/vs_base.h>
12350  #include <net/sock.h>
12351  
12352  extern void unix_inflight(struct file *fp);
12353 diff -NurpP --minimal linux-3.10.33/include/net/inet_timewait_sock.h linux-3.10.33-vs2.3.6.8/include/net/inet_timewait_sock.h
12354 --- linux-3.10.33/include/net/inet_timewait_sock.h      2013-05-31 13:45:28.000000000 +0000
12355 +++ linux-3.10.33-vs2.3.6.8/include/net/inet_timewait_sock.h    2013-08-22 20:30:00.000000000 +0000
12356 @@ -116,6 +116,10 @@ struct inet_timewait_sock {
12357  #define tw_dport               __tw_common.skc_dport
12358  #define tw_num                 __tw_common.skc_num
12359  #define tw_portpair            __tw_common.skc_portpair
12360 +#define tw_xid                 __tw_common.skc_xid
12361 +#define tw_vx_info             __tw_common.skc_vx_info
12362 +#define tw_nid                 __tw_common.skc_nid
12363 +#define tw_nx_info             __tw_common.skc_nx_info
12364  
12365         int                     tw_timeout;
12366         volatile unsigned char  tw_substate;
12367 diff -NurpP --minimal linux-3.10.33/include/net/ip6_route.h linux-3.10.33-vs2.3.6.8/include/net/ip6_route.h
12368 --- linux-3.10.33/include/net/ip6_route.h       2014-03-12 13:16:02.000000000 +0000
12369 +++ linux-3.10.33-vs2.3.6.8/include/net/ip6_route.h     2013-11-13 17:22:25.000000000 +0000
12370 @@ -95,7 +95,8 @@ extern int                    ip6_route_get_saddr(struct
12371                                                     struct rt6_info *rt,
12372                                                     const struct in6_addr *daddr,
12373                                                     unsigned int prefs,
12374 -                                                   struct in6_addr *saddr);
12375 +                                                   struct in6_addr *saddr,
12376 +                                                   struct nx_info *nxi);
12377  
12378  extern struct rt6_info         *rt6_lookup(struct net *net,
12379                                             const struct in6_addr *daddr,
12380 diff -NurpP --minimal linux-3.10.33/include/net/route.h linux-3.10.33-vs2.3.6.8/include/net/route.h
12381 --- linux-3.10.33/include/net/route.h   2013-02-19 13:58:52.000000000 +0000
12382 +++ linux-3.10.33-vs2.3.6.8/include/net/route.h 2013-08-22 20:30:00.000000000 +0000
12383 @@ -207,6 +207,9 @@ static inline void ip_rt_put(struct rtab
12384         dst_release(&rt->dst);
12385  }
12386  
12387 +#include <linux/vs_base.h>
12388 +#include <linux/vs_inet.h>
12389 +
12390  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
12391  
12392  extern const __u8 ip_tos2prio[16];
12393 @@ -256,6 +259,9 @@ static inline void ip_route_connect_init
12394                            protocol, flow_flags, dst, src, dport, sport);
12395  }
12396  
12397 +extern struct rtable *ip_v4_find_src(struct net *net, struct nx_info *,
12398 +       struct flowi4 *);
12399 +
12400  static inline struct rtable *ip_route_connect(struct flowi4 *fl4,
12401                                               __be32 dst, __be32 src, u32 tos,
12402                                               int oif, u8 protocol,
12403 @@ -264,11 +270,25 @@ static inline struct rtable *ip_route_co
12404  {
12405         struct net *net = sock_net(sk);
12406         struct rtable *rt;
12407 +       struct nx_info *nx_info = current_nx_info();
12408  
12409         ip_route_connect_init(fl4, dst, src, tos, oif, protocol,
12410                               sport, dport, sk, can_sleep);
12411  
12412 -       if (!dst || !src) {
12413 +       if (sk)
12414 +               nx_info = sk->sk_nx_info;
12415 +
12416 +       vxdprintk(VXD_CBIT(net, 4),
12417 +               "ip_route_connect(%p) %p,%p;%lx",
12418 +               sk, nx_info, sk->sk_socket,
12419 +               (sk->sk_socket?sk->sk_socket->flags:0));
12420 +
12421 +       rt = ip_v4_find_src(net, nx_info, fl4);
12422 +       if (IS_ERR(rt))
12423 +               return rt;
12424 +       ip_rt_put(rt);
12425 +
12426 +       if (!fl4->daddr || !fl4->saddr) {
12427                 rt = __ip_route_output_key(net, fl4);
12428                 if (IS_ERR(rt))
12429                         return rt;
12430 diff -NurpP --minimal linux-3.10.33/include/net/sock.h linux-3.10.33-vs2.3.6.8/include/net/sock.h
12431 --- linux-3.10.33/include/net/sock.h    2014-03-12 13:16:02.000000000 +0000
12432 +++ linux-3.10.33-vs2.3.6.8/include/net/sock.h  2013-11-13 17:22:25.000000000 +0000
12433 @@ -191,6 +191,10 @@ struct sock_common {
12434  #ifdef CONFIG_NET_NS
12435         struct net              *skc_net;
12436  #endif
12437 +       vxid_t                  skc_xid;
12438 +       struct vx_info          *skc_vx_info;
12439 +       vnid_t                  skc_nid;
12440 +       struct nx_info          *skc_nx_info;
12441         /*
12442          * fields between dontcopy_begin/dontcopy_end
12443          * are not copied in sock_copy()
12444 @@ -305,6 +309,10 @@ struct sock {
12445  #define sk_bind_node           __sk_common.skc_bind_node
12446  #define sk_prot                        __sk_common.skc_prot
12447  #define sk_net                 __sk_common.skc_net
12448 +#define sk_xid                 __sk_common.skc_xid
12449 +#define sk_vx_info             __sk_common.skc_vx_info
12450 +#define sk_nid                 __sk_common.skc_nid
12451 +#define sk_nx_info             __sk_common.skc_nx_info
12452         socket_lock_t           sk_lock;
12453         struct sk_buff_head     sk_receive_queue;
12454         /*
12455 diff -NurpP --minimal linux-3.10.33/include/uapi/Kbuild linux-3.10.33-vs2.3.6.8/include/uapi/Kbuild
12456 --- linux-3.10.33/include/uapi/Kbuild   2012-12-11 03:30:57.000000000 +0000
12457 +++ linux-3.10.33-vs2.3.6.8/include/uapi/Kbuild 2013-08-22 20:30:00.000000000 +0000
12458 @@ -12,3 +12,4 @@ header-y += video/
12459  header-y += drm/
12460  header-y += xen/
12461  header-y += scsi/
12462 +header-y += vserver/
12463 diff -NurpP --minimal linux-3.10.33/include/uapi/linux/capability.h linux-3.10.33-vs2.3.6.8/include/uapi/linux/capability.h
12464 --- linux-3.10.33/include/uapi/linux/capability.h       2012-12-11 03:30:57.000000000 +0000
12465 +++ linux-3.10.33-vs2.3.6.8/include/uapi/linux/capability.h     2013-08-22 20:30:00.000000000 +0000
12466 @@ -259,6 +259,7 @@ struct vfs_cap_data {
12467     arbitrary SCSI commands */
12468  /* Allow setting encryption key on loopback filesystem */
12469  /* Allow setting zone reclaim policy */
12470 +/* Allow the selection of a security context */
12471  
12472  #define CAP_SYS_ADMIN        21
12473  
12474 @@ -345,7 +346,12 @@ struct vfs_cap_data {
12475  
12476  #define CAP_LAST_CAP         CAP_BLOCK_SUSPEND
12477  
12478 -#define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
12479 +/* Allow context manipulations */
12480 +/* Allow changing context info on files */
12481 +
12482 +#define CAP_CONTEXT         63
12483 +
12484 +#define cap_valid(x) ((x) >= 0 && ((x) <= CAP_LAST_CAP || (x) == CAP_CONTEXT))
12485  
12486  /*
12487   * Bit location of each capability (used by user-space library and kernel)
12488 diff -NurpP --minimal linux-3.10.33/include/uapi/linux/fs.h linux-3.10.33-vs2.3.6.8/include/uapi/linux/fs.h
12489 --- linux-3.10.33/include/uapi/linux/fs.h       2013-07-14 17:01:34.000000000 +0000
12490 +++ linux-3.10.33-vs2.3.6.8/include/uapi/linux/fs.h     2013-08-22 20:30:00.000000000 +0000
12491 @@ -86,6 +86,9 @@ struct inodes_stat_t {
12492  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
12493  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
12494  #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
12495 +#define MS_TAGGED      (1<<8)  /* use generic inode tagging */
12496 +#define MS_NOTAGCHECK  (1<<9)  /* don't check tags */
12497 +#define MS_TAGID       (1<<25) /* use specific tag for this mount */
12498  
12499  /* These sb flags are internal to the kernel */
12500  #define MS_NOSEC       (1<<28)
12501 @@ -191,11 +194,14 @@ struct inodes_stat_t {
12502  #define FS_EXTENT_FL                   0x00080000 /* Extents */
12503  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
12504  #define FS_NOCOW_FL                    0x00800000 /* Do not cow file */
12505 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
12506  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
12507  
12508 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
12509 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
12510 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
12511 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
12512  
12513 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
12514 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
12515  
12516  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
12517  #define SYNC_FILE_RANGE_WRITE          2
12518 diff -NurpP --minimal linux-3.10.33/include/uapi/linux/gfs2_ondisk.h linux-3.10.33-vs2.3.6.8/include/uapi/linux/gfs2_ondisk.h
12519 --- linux-3.10.33/include/uapi/linux/gfs2_ondisk.h      2012-12-11 03:30:57.000000000 +0000
12520 +++ linux-3.10.33-vs2.3.6.8/include/uapi/linux/gfs2_ondisk.h    2013-08-22 20:30:00.000000000 +0000
12521 @@ -225,6 +225,9 @@ enum {
12522         gfs2fl_Sync             = 8,
12523         gfs2fl_System           = 9,
12524         gfs2fl_TopLevel         = 10,
12525 +       gfs2fl_IXUnlink         = 16,
12526 +       gfs2fl_Barrier          = 17,
12527 +       gfs2fl_Cow              = 18,
12528         gfs2fl_TruncInProg      = 29,
12529         gfs2fl_InheritDirectio  = 30,
12530         gfs2fl_InheritJdata     = 31,
12531 @@ -242,6 +245,9 @@ enum {
12532  #define GFS2_DIF_SYNC                  0x00000100
12533  #define GFS2_DIF_SYSTEM                        0x00000200 /* New in gfs2 */
12534  #define GFS2_DIF_TOPDIR                        0x00000400 /* New in gfs2 */
12535 +#define GFS2_DIF_IXUNLINK               0x00010000
12536 +#define GFS2_DIF_BARRIER                0x00020000
12537 +#define GFS2_DIF_COW                    0x00040000
12538  #define GFS2_DIF_TRUNC_IN_PROG         0x20000000 /* New in gfs2 */
12539  #define GFS2_DIF_INHERIT_DIRECTIO      0x40000000 /* only in gfs1 */
12540  #define GFS2_DIF_INHERIT_JDATA         0x80000000
12541 diff -NurpP --minimal linux-3.10.33/include/uapi/linux/if_tun.h linux-3.10.33-vs2.3.6.8/include/uapi/linux/if_tun.h
12542 --- linux-3.10.33/include/uapi/linux/if_tun.h   2013-02-19 13:58:55.000000000 +0000
12543 +++ linux-3.10.33-vs2.3.6.8/include/uapi/linux/if_tun.h 2013-08-22 20:30:00.000000000 +0000
12544 @@ -56,6 +56,7 @@
12545  #define TUNGETVNETHDRSZ _IOR('T', 215, int)
12546  #define TUNSETVNETHDRSZ _IOW('T', 216, int)
12547  #define TUNSETQUEUE  _IOW('T', 217, int)
12548 +#define TUNSETNID     _IOW('T', 218, int)
12549  
12550  /* TUNSETIFF ifr flags */
12551  #define IFF_TUN                0x0001
12552 diff -NurpP --minimal linux-3.10.33/include/uapi/linux/major.h linux-3.10.33-vs2.3.6.8/include/uapi/linux/major.h
12553 --- linux-3.10.33/include/uapi/linux/major.h    2012-12-11 03:30:57.000000000 +0000
12554 +++ linux-3.10.33-vs2.3.6.8/include/uapi/linux/major.h  2013-08-22 20:30:00.000000000 +0000
12555 @@ -15,6 +15,7 @@
12556  #define HD_MAJOR               IDE0_MAJOR
12557  #define PTY_SLAVE_MAJOR                3
12558  #define TTY_MAJOR              4
12559 +#define VROOT_MAJOR            4
12560  #define TTYAUX_MAJOR           5
12561  #define LP_MAJOR               6
12562  #define VCS_MAJOR              7
12563 diff -NurpP --minimal linux-3.10.33/include/uapi/linux/nfs_mount.h linux-3.10.33-vs2.3.6.8/include/uapi/linux/nfs_mount.h
12564 --- linux-3.10.33/include/uapi/linux/nfs_mount.h        2012-12-11 03:30:57.000000000 +0000
12565 +++ linux-3.10.33-vs2.3.6.8/include/uapi/linux/nfs_mount.h      2013-08-22 20:30:00.000000000 +0000
12566 @@ -63,7 +63,8 @@ struct nfs_mount_data {
12567  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
12568  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
12569  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
12570 -#define NFS_MOUNT_FLAGMASK     0xFFFF
12571 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
12572 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
12573  
12574  /* The following are for internal use only */
12575  #define NFS_MOUNT_LOOKUP_CACHE_NONEG   0x10000
12576 diff -NurpP --minimal linux-3.10.33/include/uapi/linux/reboot.h linux-3.10.33-vs2.3.6.8/include/uapi/linux/reboot.h
12577 --- linux-3.10.33/include/uapi/linux/reboot.h   2012-12-11 03:30:57.000000000 +0000
12578 +++ linux-3.10.33-vs2.3.6.8/include/uapi/linux/reboot.h 2013-08-22 20:30:00.000000000 +0000
12579 @@ -33,7 +33,7 @@
12580  #define        LINUX_REBOOT_CMD_RESTART2       0xA1B2C3D4
12581  #define        LINUX_REBOOT_CMD_SW_SUSPEND     0xD000FCE2
12582  #define        LINUX_REBOOT_CMD_KEXEC          0x45584543
12583 -
12584 +#define        LINUX_REBOOT_CMD_OOM            0xDEADBEEF
12585  
12586  
12587  #endif /* _UAPI_LINUX_REBOOT_H */
12588 diff -NurpP --minimal linux-3.10.33/include/uapi/linux/sysctl.h linux-3.10.33-vs2.3.6.8/include/uapi/linux/sysctl.h
12589 --- linux-3.10.33/include/uapi/linux/sysctl.h   2012-12-11 03:30:57.000000000 +0000
12590 +++ linux-3.10.33-vs2.3.6.8/include/uapi/linux/sysctl.h 2013-08-22 20:30:00.000000000 +0000
12591 @@ -60,6 +60,7 @@ enum
12592         CTL_ABI=9,              /* Binary emulation */
12593         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
12594         CTL_ARLAN=254,          /* arlan wireless driver */
12595 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
12596         CTL_S390DBF=5677,       /* s390 debug */
12597         CTL_SUNRPC=7249,        /* sunrpc debug */
12598         CTL_PM=9899,            /* frv power management */
12599 @@ -94,6 +95,7 @@ enum
12600  
12601         KERN_PANIC=15,          /* int: panic timeout */
12602         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
12603 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
12604  
12605         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
12606         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
12607 diff -NurpP --minimal linux-3.10.33/include/uapi/vserver/Kbuild linux-3.10.33-vs2.3.6.8/include/uapi/vserver/Kbuild
12608 --- linux-3.10.33/include/uapi/vserver/Kbuild   1970-01-01 00:00:00.000000000 +0000
12609 +++ linux-3.10.33-vs2.3.6.8/include/uapi/vserver/Kbuild 2013-08-22 20:30:00.000000000 +0000
12610 @@ -0,0 +1,9 @@
12611 +
12612 +header-y += context_cmd.h network_cmd.h space_cmd.h \
12613 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
12614 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
12615 +       debug_cmd.h device_cmd.h
12616 +
12617 +header-y += switch.h context.h network.h monitor.h \
12618 +       limit.h inode.h device.h
12619 +
12620 diff -NurpP --minimal linux-3.10.33/include/uapi/vserver/cacct_cmd.h linux-3.10.33-vs2.3.6.8/include/uapi/vserver/cacct_cmd.h
12621 --- linux-3.10.33/include/uapi/vserver/cacct_cmd.h      1970-01-01 00:00:00.000000000 +0000
12622 +++ linux-3.10.33-vs2.3.6.8/include/uapi/vserver/cacct_cmd.h    2013-08-22 20:30:00.000000000 +0000
12623 @@ -0,0 +1,15 @@
12624 +#ifndef _UAPI_VS_CACCT_CMD_H
12625 +#define _UAPI_VS_CACCT_CMD_H
12626 +
12627 +
12628 +/* virtual host info name commands */
12629 +
12630 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
12631 +
12632 +struct vcmd_sock_stat_v0 {
12633 +       uint32_t field;
12634 +       uint32_t count[3];
12635 +       uint64_t total[3];
12636 +};
12637 +
12638 +#endif /* _UAPI_VS_CACCT_CMD_H */
12639 diff -NurpP --minimal linux-3.10.33/include/uapi/vserver/context.h linux-3.10.33-vs2.3.6.8/include/uapi/vserver/context.h
12640 --- linux-3.10.33/include/uapi/vserver/context.h        1970-01-01 00:00:00.000000000 +0000
12641 +++ linux-3.10.33-vs2.3.6.8/include/uapi/vserver/context.h      2013-10-27 03:43:35.000000000 +0000
12642 @@ -0,0 +1,81 @@
12643 +#ifndef _UAPI_VS_CONTEXT_H
12644 +#define _UAPI_VS_CONTEXT_H
12645 +
12646 +#include <linux/types.h>
12647 +#include <linux/capability.h>
12648 +
12649 +
12650 +/* context flags */
12651 +
12652 +#define VXF_INFO_SCHED         0x00000002
12653 +#define VXF_INFO_NPROC         0x00000004
12654 +#define VXF_INFO_PRIVATE       0x00000008
12655 +
12656 +#define VXF_INFO_INIT          0x00000010
12657 +#define VXF_INFO_HIDE          0x00000020
12658 +#define VXF_INFO_ULIMIT                0x00000040
12659 +#define VXF_INFO_NSPACE                0x00000080
12660 +
12661 +#define VXF_SCHED_HARD         0x00000100
12662 +#define VXF_SCHED_PRIO         0x00000200
12663 +#define VXF_SCHED_PAUSE                0x00000400
12664 +
12665 +#define VXF_VIRT_MEM           0x00010000
12666 +#define VXF_VIRT_UPTIME                0x00020000
12667 +#define VXF_VIRT_CPU           0x00040000
12668 +#define VXF_VIRT_LOAD          0x00080000
12669 +#define VXF_VIRT_TIME          0x00100000
12670 +
12671 +#define VXF_HIDE_MOUNT         0x01000000
12672 +/* was VXF_HIDE_NETIF          0x02000000 */
12673 +#define VXF_HIDE_VINFO         0x04000000
12674 +
12675 +#define VXF_STATE_SETUP                (1ULL << 32)
12676 +#define VXF_STATE_INIT         (1ULL << 33)
12677 +#define VXF_STATE_ADMIN                (1ULL << 34)
12678 +
12679 +#define VXF_SC_HELPER          (1ULL << 36)
12680 +#define VXF_REBOOT_KILL                (1ULL << 37)
12681 +#define VXF_PERSISTENT         (1ULL << 38)
12682 +
12683 +#define VXF_FORK_RSS           (1ULL << 48)
12684 +#define VXF_PROLIFIC           (1ULL << 49)
12685 +
12686 +#define VXF_IGNEG_NICE         (1ULL << 52)
12687 +
12688 +#define VXF_ONE_TIME           (0x0007ULL << 32)
12689 +
12690 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
12691 +
12692 +
12693 +/* context migration */
12694 +
12695 +#define VXM_SET_INIT           0x00000001
12696 +#define VXM_SET_REAPER         0x00000002
12697 +
12698 +/* context caps */
12699 +
12700 +#define VXC_SET_UTSNAME                0x00000001
12701 +#define VXC_SET_RLIMIT         0x00000002
12702 +#define VXC_FS_SECURITY                0x00000004
12703 +#define VXC_FS_TRUSTED         0x00000008
12704 +#define VXC_TIOCSTI            0x00000010
12705 +
12706 +/* was VXC_RAW_ICMP            0x00000100 */
12707 +#define VXC_SYSLOG             0x00001000
12708 +#define VXC_OOM_ADJUST         0x00002000
12709 +#define VXC_AUDIT_CONTROL      0x00004000
12710 +
12711 +#define VXC_SECURE_MOUNT       0x00010000
12712 +/* #define VXC_SECURE_REMOUNT  0x00020000 */
12713 +#define VXC_BINARY_MOUNT       0x00040000
12714 +#define VXC_DEV_MOUNT          0x00080000
12715 +
12716 +#define VXC_QUOTA_CTL          0x00100000
12717 +#define VXC_ADMIN_MAPPER       0x00200000
12718 +#define VXC_ADMIN_CLOOP                0x00400000
12719 +
12720 +#define VXC_KTHREAD            0x01000000
12721 +#define VXC_NAMESPACE          0x02000000
12722 +
12723 +#endif /* _UAPI_VS_CONTEXT_H */
12724 diff -NurpP --minimal linux-3.10.33/include/uapi/vserver/context_cmd.h linux-3.10.33-vs2.3.6.8/include/uapi/vserver/context_cmd.h
12725 --- linux-3.10.33/include/uapi/vserver/context_cmd.h    1970-01-01 00:00:00.000000000 +0000
12726 +++ linux-3.10.33-vs2.3.6.8/include/uapi/vserver/context_cmd.h  2013-08-22 20:30:00.000000000 +0000
12727 @@ -0,0 +1,115 @@
12728 +#ifndef _UAPI_VS_CONTEXT_CMD_H
12729 +#define _UAPI_VS_CONTEXT_CMD_H
12730 +
12731 +
12732 +/* vinfo commands */
12733 +
12734 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
12735 +
12736 +
12737 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
12738 +
12739 +struct vcmd_vx_info_v0 {
12740 +       uint32_t xid;
12741 +       uint32_t initpid;
12742 +       /* more to come */
12743 +};
12744 +
12745 +
12746 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
12747 +
12748 +struct vcmd_ctx_stat_v0 {
12749 +       uint32_t usecnt;
12750 +       uint32_t tasks;
12751 +       /* more to come */
12752 +};
12753 +
12754 +
12755 +/* context commands */
12756 +
12757 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
12758 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
12759 +
12760 +struct vcmd_ctx_create {
12761 +       uint64_t flagword;
12762 +};
12763 +
12764 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
12765 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
12766 +
12767 +struct vcmd_ctx_migrate {
12768 +       uint64_t flagword;
12769 +};
12770 +
12771 +
12772 +
12773 +/* flag commands */
12774 +
12775 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
12776 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
12777 +
12778 +struct vcmd_ctx_flags_v0 {
12779 +       uint64_t flagword;
12780 +       uint64_t mask;
12781 +};
12782 +
12783 +
12784 +
12785 +/* context caps commands */
12786 +
12787 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
12788 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
12789 +
12790 +struct vcmd_ctx_caps_v1 {
12791 +       uint64_t ccaps;
12792 +       uint64_t cmask;
12793 +};
12794 +
12795 +
12796 +
12797 +/* bcaps commands */
12798 +
12799 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
12800 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
12801 +
12802 +struct vcmd_bcaps {
12803 +       uint64_t bcaps;
12804 +       uint64_t bmask;
12805 +};
12806 +
12807 +
12808 +
12809 +/* umask commands */
12810 +
12811 +#define VCMD_get_umask         VC_CMD(FLAGS, 13, 0)
12812 +#define VCMD_set_umask         VC_CMD(FLAGS, 14, 0)
12813 +
12814 +struct vcmd_umask {
12815 +       uint64_t umask;
12816 +       uint64_t mask;
12817 +};
12818 +
12819 +
12820 +
12821 +/* wmask commands */
12822 +
12823 +#define VCMD_get_wmask         VC_CMD(FLAGS, 15, 0)
12824 +#define VCMD_set_wmask         VC_CMD(FLAGS, 16, 0)
12825 +
12826 +struct vcmd_wmask {
12827 +       uint64_t wmask;
12828 +       uint64_t mask;
12829 +};
12830 +
12831 +
12832 +
12833 +/* OOM badness */
12834 +
12835 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
12836 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
12837 +
12838 +struct vcmd_badness_v0 {
12839 +       int64_t bias;
12840 +};
12841 +
12842 +#endif /* _UAPI_VS_CONTEXT_CMD_H */
12843 diff -NurpP --minimal linux-3.10.33/include/uapi/vserver/cvirt_cmd.h linux-3.10.33-vs2.3.6.8/include/uapi/vserver/cvirt_cmd.h
12844 --- linux-3.10.33/include/uapi/vserver/cvirt_cmd.h      1970-01-01 00:00:00.000000000 +0000
12845 +++ linux-3.10.33-vs2.3.6.8/include/uapi/vserver/cvirt_cmd.h    2013-08-22 20:30:00.000000000 +0000
12846 @@ -0,0 +1,41 @@
12847 +#ifndef _UAPI_VS_CVIRT_CMD_H
12848 +#define _UAPI_VS_CVIRT_CMD_H
12849 +
12850 +
12851 +/* virtual host info name commands */
12852 +
12853 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
12854 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
12855 +
12856 +struct vcmd_vhi_name_v0 {
12857 +       uint32_t field;
12858 +       char name[65];
12859 +};
12860 +
12861 +
12862 +enum vhi_name_field {
12863 +       VHIN_CONTEXT = 0,
12864 +       VHIN_SYSNAME,
12865 +       VHIN_NODENAME,
12866 +       VHIN_RELEASE,
12867 +       VHIN_VERSION,
12868 +       VHIN_MACHINE,
12869 +       VHIN_DOMAINNAME,
12870 +};
12871 +
12872 +
12873 +
12874 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
12875 +
12876 +struct vcmd_virt_stat_v0 {
12877 +       uint64_t offset;
12878 +       uint64_t uptime;
12879 +       uint32_t nr_threads;
12880 +       uint32_t nr_running;
12881 +       uint32_t nr_uninterruptible;
12882 +       uint32_t nr_onhold;
12883 +       uint32_t nr_forks;
12884 +       uint32_t load[3];
12885 +};
12886 +
12887 +#endif /* _UAPI_VS_CVIRT_CMD_H */
12888 diff -NurpP --minimal linux-3.10.33/include/uapi/vserver/debug_cmd.h linux-3.10.33-vs2.3.6.8/include/uapi/vserver/debug_cmd.h
12889 --- linux-3.10.33/include/uapi/vserver/debug_cmd.h      1970-01-01 00:00:00.000000000 +0000
12890 +++ linux-3.10.33-vs2.3.6.8/include/uapi/vserver/debug_cmd.h    2013-08-22 20:30:00.000000000 +0000
12891 @@ -0,0 +1,24 @@
12892 +#ifndef _UAPI_VS_DEBUG_CMD_H
12893 +#define _UAPI_VS_DEBUG_CMD_H
12894 +
12895 +
12896 +/* debug commands */
12897 +
12898 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
12899 +
12900 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
12901 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
12902 +
12903 +struct  vcmd_read_history_v0 {
12904 +       uint32_t index;
12905 +       uint32_t count;
12906 +       char __user *data;
12907 +};
12908 +
12909 +struct  vcmd_read_monitor_v0 {
12910 +       uint32_t index;
12911 +       uint32_t count;
12912 +       char __user *data;
12913 +};
12914 +
12915 +#endif /* _UAPI_VS_DEBUG_CMD_H */
12916 diff -NurpP --minimal linux-3.10.33/include/uapi/vserver/device.h linux-3.10.33-vs2.3.6.8/include/uapi/vserver/device.h
12917 --- linux-3.10.33/include/uapi/vserver/device.h 1970-01-01 00:00:00.000000000 +0000
12918 +++ linux-3.10.33-vs2.3.6.8/include/uapi/vserver/device.h       2013-08-22 20:30:00.000000000 +0000
12919 @@ -0,0 +1,12 @@
12920 +#ifndef _UAPI_VS_DEVICE_H
12921 +#define _UAPI_VS_DEVICE_H
12922 +
12923 +
12924 +#define DATTR_CREATE   0x00000001
12925 +#define DATTR_OPEN     0x00000002
12926 +
12927 +#define DATTR_REMAP    0x00000010
12928 +
12929 +#define DATTR_MASK     0x00000013
12930 +
12931 +#endif /* _UAPI_VS_DEVICE_H */
12932 diff -NurpP --minimal linux-3.10.33/include/uapi/vserver/device_cmd.h linux-3.10.33-vs2.3.6.8/include/uapi/vserver/device_cmd.h
12933 --- linux-3.10.33/include/uapi/vserver/device_cmd.h     1970-01-01 00:00:00.000000000 +0000
12934 +++ linux-3.10.33-vs2.3.6.8/include/uapi/vserver/device_cmd.h   2013-08-22 20:30:00.000000000 +0000
12935 @@ -0,0 +1,16 @@
12936 +#ifndef _UAPI_VS_DEVICE_CMD_H
12937 +#define _UAPI_VS_DEVICE_CMD_H
12938 +
12939 +
12940 +/*  device vserver commands */
12941 +
12942 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
12943 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
12944 +
12945 +struct vcmd_set_mapping_v0 {
12946 +       const char __user *device;
12947 +       const char __user *target;
12948 +       uint32_t flags;
12949 +};
12950 +
12951 +#endif /* _UAPI_VS_DEVICE_CMD_H */
12952 diff -NurpP --minimal linux-3.10.33/include/uapi/vserver/dlimit_cmd.h linux-3.10.33-vs2.3.6.8/include/uapi/vserver/dlimit_cmd.h
12953 --- linux-3.10.33/include/uapi/vserver/dlimit_cmd.h     1970-01-01 00:00:00.000000000 +0000
12954 +++ linux-3.10.33-vs2.3.6.8/include/uapi/vserver/dlimit_cmd.h   2013-08-22 20:30:00.000000000 +0000
12955 @@ -0,0 +1,67 @@
12956 +#ifndef _UAPI_VS_DLIMIT_CMD_H
12957 +#define _UAPI_VS_DLIMIT_CMD_H
12958 +
12959 +
12960 +/*  dlimit vserver commands */
12961 +
12962 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
12963 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
12964 +
12965 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
12966 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
12967 +
12968 +struct vcmd_ctx_dlimit_base_v0 {
12969 +       const char __user *name;
12970 +       uint32_t flags;
12971 +};
12972 +
12973 +struct vcmd_ctx_dlimit_v0 {
12974 +       const char __user *name;
12975 +       uint32_t space_used;                    /* used space in kbytes */
12976 +       uint32_t space_total;                   /* maximum space in kbytes */
12977 +       uint32_t inodes_used;                   /* used inodes */
12978 +       uint32_t inodes_total;                  /* maximum inodes */
12979 +       uint32_t reserved;                      /* reserved for root in % */
12980 +       uint32_t flags;
12981 +};
12982 +
12983 +#define CDLIM_UNSET            ((uint32_t)0UL)
12984 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
12985 +#define CDLIM_KEEP             ((uint32_t)~1UL)
12986 +
12987 +#define DLIME_UNIT     0
12988 +#define DLIME_KILO     1
12989 +#define DLIME_MEGA     2
12990 +#define DLIME_GIGA     3
12991 +
12992 +#define DLIMF_SHIFT    0x10
12993 +
12994 +#define DLIMS_USED     0
12995 +#define DLIMS_TOTAL    2
12996 +
12997 +static inline
12998 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
12999 +{
13000 +       int exp = (flags & DLIMF_SHIFT) ?
13001 +               (flags >> shift) & DLIME_GIGA : DLIME_KILO;
13002 +       return ((uint64_t)val) << (10 * exp);
13003 +}
13004 +
13005 +static inline
13006 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
13007 +{
13008 +       int exp = 0;
13009 +
13010 +       if (*flags & DLIMF_SHIFT) {
13011 +               while (val > (1LL << 32) && (exp < 3)) {
13012 +                       val >>= 10;
13013 +                       exp++;
13014 +               }
13015 +               *flags &= ~(DLIME_GIGA << shift);
13016 +               *flags |= exp << shift;
13017 +       } else
13018 +               val >>= 10;
13019 +       return val;
13020 +}
13021 +
13022 +#endif /* _UAPI_VS_DLIMIT_CMD_H */
13023 diff -NurpP --minimal linux-3.10.33/include/uapi/vserver/inode.h linux-3.10.33-vs2.3.6.8/include/uapi/vserver/inode.h
13024 --- linux-3.10.33/include/uapi/vserver/inode.h  1970-01-01 00:00:00.000000000 +0000
13025 +++ linux-3.10.33-vs2.3.6.8/include/uapi/vserver/inode.h        2013-08-22 20:30:00.000000000 +0000
13026 @@ -0,0 +1,23 @@
13027 +#ifndef _UAPI_VS_INODE_H
13028 +#define _UAPI_VS_INODE_H
13029 +
13030 +
13031 +#define IATTR_TAG      0x01000000
13032 +
13033 +#define IATTR_ADMIN    0x00000001
13034 +#define IATTR_WATCH    0x00000002
13035 +#define IATTR_HIDE     0x00000004
13036 +#define IATTR_FLAGS    0x00000007
13037 +
13038 +#define IATTR_BARRIER  0x00010000
13039 +#define IATTR_IXUNLINK 0x00020000
13040 +#define IATTR_IMMUTABLE 0x00040000
13041 +#define IATTR_COW      0x00080000
13042 +
13043 +
13044 +/* inode ioctls */
13045 +
13046 +#define FIOC_GETXFLG   _IOR('x', 5, long)
13047 +#define FIOC_SETXFLG   _IOW('x', 6, long)
13048 +
13049 +#endif /* _UAPI_VS_INODE_H */
13050 diff -NurpP --minimal linux-3.10.33/include/uapi/vserver/inode_cmd.h linux-3.10.33-vs2.3.6.8/include/uapi/vserver/inode_cmd.h
13051 --- linux-3.10.33/include/uapi/vserver/inode_cmd.h      1970-01-01 00:00:00.000000000 +0000
13052 +++ linux-3.10.33-vs2.3.6.8/include/uapi/vserver/inode_cmd.h    2013-08-22 20:30:00.000000000 +0000
13053 @@ -0,0 +1,26 @@
13054 +#ifndef _UAPI_VS_INODE_CMD_H
13055 +#define _UAPI_VS_INODE_CMD_H
13056 +
13057 +
13058 +/*  inode vserver commands */
13059 +
13060 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
13061 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
13062 +
13063 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
13064 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
13065 +
13066 +struct vcmd_ctx_iattr_v1 {
13067 +       const char __user *name;
13068 +       uint32_t tag;
13069 +       uint32_t flags;
13070 +       uint32_t mask;
13071 +};
13072 +
13073 +struct vcmd_ctx_fiattr_v0 {
13074 +       uint32_t tag;
13075 +       uint32_t flags;
13076 +       uint32_t mask;
13077 +};
13078 +
13079 +#endif /* _UAPI_VS_INODE_CMD_H */
13080 diff -NurpP --minimal linux-3.10.33/include/uapi/vserver/limit.h linux-3.10.33-vs2.3.6.8/include/uapi/vserver/limit.h
13081 --- linux-3.10.33/include/uapi/vserver/limit.h  1970-01-01 00:00:00.000000000 +0000
13082 +++ linux-3.10.33-vs2.3.6.8/include/uapi/vserver/limit.h        2013-08-22 20:30:00.000000000 +0000
13083 @@ -0,0 +1,14 @@
13084 +#ifndef _UAPI_VS_LIMIT_H
13085 +#define _UAPI_VS_LIMIT_H
13086 +
13087 +
13088 +#define VLIMIT_NSOCK   16
13089 +#define VLIMIT_OPENFD  17
13090 +#define VLIMIT_ANON    18
13091 +#define VLIMIT_SHMEM   19
13092 +#define VLIMIT_SEMARY  20
13093 +#define VLIMIT_NSEMS   21
13094 +#define VLIMIT_DENTRY  22
13095 +#define VLIMIT_MAPPED  23
13096 +
13097 +#endif /* _UAPI_VS_LIMIT_H */
13098 diff -NurpP --minimal linux-3.10.33/include/uapi/vserver/limit_cmd.h linux-3.10.33-vs2.3.6.8/include/uapi/vserver/limit_cmd.h
13099 --- linux-3.10.33/include/uapi/vserver/limit_cmd.h      1970-01-01 00:00:00.000000000 +0000
13100 +++ linux-3.10.33-vs2.3.6.8/include/uapi/vserver/limit_cmd.h    2013-08-22 20:30:00.000000000 +0000
13101 @@ -0,0 +1,40 @@
13102 +#ifndef _UAPI_VS_LIMIT_CMD_H
13103 +#define _UAPI_VS_LIMIT_CMD_H
13104 +
13105 +
13106 +/*  rlimit vserver commands */
13107 +
13108 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
13109 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
13110 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
13111 +#define VCMD_reset_hits                VC_CMD(RLIMIT, 7, 0)
13112 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
13113 +
13114 +struct vcmd_ctx_rlimit_v0 {
13115 +       uint32_t id;
13116 +       uint64_t minimum;
13117 +       uint64_t softlimit;
13118 +       uint64_t maximum;
13119 +};
13120 +
13121 +struct vcmd_ctx_rlimit_mask_v0 {
13122 +       uint32_t minimum;
13123 +       uint32_t softlimit;
13124 +       uint32_t maximum;
13125 +};
13126 +
13127 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
13128 +
13129 +struct vcmd_rlimit_stat_v0 {
13130 +       uint32_t id;
13131 +       uint32_t hits;
13132 +       uint64_t value;
13133 +       uint64_t minimum;
13134 +       uint64_t maximum;
13135 +};
13136 +
13137 +#define CRLIM_UNSET            (0ULL)
13138 +#define CRLIM_INFINITY         (~0ULL)
13139 +#define CRLIM_KEEP             (~1ULL)
13140 +
13141 +#endif /* _UAPI_VS_LIMIT_CMD_H */
13142 diff -NurpP --minimal linux-3.10.33/include/uapi/vserver/monitor.h linux-3.10.33-vs2.3.6.8/include/uapi/vserver/monitor.h
13143 --- linux-3.10.33/include/uapi/vserver/monitor.h        1970-01-01 00:00:00.000000000 +0000
13144 +++ linux-3.10.33-vs2.3.6.8/include/uapi/vserver/monitor.h      2013-08-22 20:30:00.000000000 +0000
13145 @@ -0,0 +1,96 @@
13146 +#ifndef _UAPI_VS_MONITOR_H
13147 +#define _UAPI_VS_MONITOR_H
13148 +
13149 +#include <linux/types.h>
13150 +
13151 +
13152 +enum {
13153 +       VXM_UNUSED = 0,
13154 +
13155 +       VXM_SYNC = 0x10,
13156 +
13157 +       VXM_UPDATE = 0x20,
13158 +       VXM_UPDATE_1,
13159 +       VXM_UPDATE_2,
13160 +
13161 +       VXM_RQINFO_1 = 0x24,
13162 +       VXM_RQINFO_2,
13163 +
13164 +       VXM_ACTIVATE = 0x40,
13165 +       VXM_DEACTIVATE,
13166 +       VXM_IDLE,
13167 +
13168 +       VXM_HOLD = 0x44,
13169 +       VXM_UNHOLD,
13170 +
13171 +       VXM_MIGRATE = 0x48,
13172 +       VXM_RESCHED,
13173 +
13174 +       /* all other bits are flags */
13175 +       VXM_SCHED = 0x80,
13176 +};
13177 +
13178 +struct _vxm_update_1 {
13179 +       uint32_t tokens_max;
13180 +       uint32_t fill_rate;
13181 +       uint32_t interval;
13182 +};
13183 +
13184 +struct _vxm_update_2 {
13185 +       uint32_t tokens_min;
13186 +       uint32_t fill_rate;
13187 +       uint32_t interval;
13188 +};
13189 +
13190 +struct _vxm_rqinfo_1 {
13191 +       uint16_t running;
13192 +       uint16_t onhold;
13193 +       uint16_t iowait;
13194 +       uint16_t uintr;
13195 +       uint32_t idle_tokens;
13196 +};
13197 +
13198 +struct _vxm_rqinfo_2 {
13199 +       uint32_t norm_time;
13200 +       uint32_t idle_time;
13201 +       uint32_t idle_skip;
13202 +};
13203 +
13204 +struct _vxm_sched {
13205 +       uint32_t tokens;
13206 +       uint32_t norm_time;
13207 +       uint32_t idle_time;
13208 +};
13209 +
13210 +struct _vxm_task {
13211 +       uint16_t pid;
13212 +       uint16_t state;
13213 +};
13214 +
13215 +struct _vxm_event {
13216 +       uint32_t jif;
13217 +       union {
13218 +               uint32_t seq;
13219 +               uint32_t sec;
13220 +       };
13221 +       union {
13222 +               uint32_t tokens;
13223 +               uint32_t nsec;
13224 +               struct _vxm_task tsk;
13225 +       };
13226 +};
13227 +
13228 +struct _vx_mon_entry {
13229 +       uint16_t type;
13230 +       uint16_t xid;
13231 +       union {
13232 +               struct _vxm_event ev;
13233 +               struct _vxm_sched sd;
13234 +               struct _vxm_update_1 u1;
13235 +               struct _vxm_update_2 u2;
13236 +               struct _vxm_rqinfo_1 q1;
13237 +               struct _vxm_rqinfo_2 q2;
13238 +       };
13239 +};
13240 +
13241 +#endif /* _UAPI_VS_MONITOR_H */
13242 diff -NurpP --minimal linux-3.10.33/include/uapi/vserver/network.h linux-3.10.33-vs2.3.6.8/include/uapi/vserver/network.h
13243 --- linux-3.10.33/include/uapi/vserver/network.h        1970-01-01 00:00:00.000000000 +0000
13244 +++ linux-3.10.33-vs2.3.6.8/include/uapi/vserver/network.h      2013-08-22 20:30:00.000000000 +0000
13245 @@ -0,0 +1,76 @@
13246 +#ifndef _UAPI_VS_NETWORK_H
13247 +#define _UAPI_VS_NETWORK_H
13248 +
13249 +#include <linux/types.h>
13250 +
13251 +
13252 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
13253 +
13254 +
13255 +/* network flags */
13256 +
13257 +#define NXF_INFO_PRIVATE       0x00000008
13258 +
13259 +#define NXF_SINGLE_IP          0x00000100
13260 +#define NXF_LBACK_REMAP                0x00000200
13261 +#define NXF_LBACK_ALLOW                0x00000400
13262 +
13263 +#define NXF_HIDE_NETIF         0x02000000
13264 +#define NXF_HIDE_LBACK         0x04000000
13265 +
13266 +#define NXF_STATE_SETUP                (1ULL << 32)
13267 +#define NXF_STATE_ADMIN                (1ULL << 34)
13268 +
13269 +#define NXF_SC_HELPER          (1ULL << 36)
13270 +#define NXF_PERSISTENT         (1ULL << 38)
13271 +
13272 +#define NXF_ONE_TIME           (0x0005ULL << 32)
13273 +
13274 +
13275 +#define        NXF_INIT_SET            (__nxf_init_set())
13276 +
13277 +static inline uint64_t __nxf_init_set(void) {
13278 +       return    NXF_STATE_ADMIN
13279 +#ifdef CONFIG_VSERVER_AUTO_LBACK
13280 +               | NXF_LBACK_REMAP
13281 +               | NXF_HIDE_LBACK
13282 +#endif
13283 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
13284 +               | NXF_SINGLE_IP
13285 +#endif
13286 +               | NXF_HIDE_NETIF;
13287 +}
13288 +
13289 +
13290 +/* network caps */
13291 +
13292 +#define NXC_TUN_CREATE         0x00000001
13293 +
13294 +#define NXC_RAW_ICMP           0x00000100
13295 +
13296 +#define NXC_MULTICAST          0x00001000
13297 +
13298 +
13299 +/* address types */
13300 +
13301 +#define NXA_TYPE_IPV4          0x0001
13302 +#define NXA_TYPE_IPV6          0x0002
13303 +
13304 +#define NXA_TYPE_NONE          0x0000
13305 +#define NXA_TYPE_ANY           0x00FF
13306 +
13307 +#define NXA_TYPE_ADDR          0x0010
13308 +#define NXA_TYPE_MASK          0x0020
13309 +#define NXA_TYPE_RANGE         0x0040
13310 +
13311 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
13312 +
13313 +#define NXA_MOD_BCAST          0x0100
13314 +#define NXA_MOD_LBACK          0x0200
13315 +
13316 +#define NXA_LOOPBACK           0x1000
13317 +
13318 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
13319 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
13320 +
13321 +#endif /* _UAPI_VS_NETWORK_H */
13322 diff -NurpP --minimal linux-3.10.33/include/uapi/vserver/network_cmd.h linux-3.10.33-vs2.3.6.8/include/uapi/vserver/network_cmd.h
13323 --- linux-3.10.33/include/uapi/vserver/network_cmd.h    1970-01-01 00:00:00.000000000 +0000
13324 +++ linux-3.10.33-vs2.3.6.8/include/uapi/vserver/network_cmd.h  2013-08-22 20:30:00.000000000 +0000
13325 @@ -0,0 +1,123 @@
13326 +#ifndef _UAPI_VS_NETWORK_CMD_H
13327 +#define _UAPI_VS_NETWORK_CMD_H
13328 +
13329 +
13330 +/* vinfo commands */
13331 +
13332 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
13333 +
13334 +
13335 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
13336 +
13337 +struct vcmd_nx_info_v0 {
13338 +       uint32_t nid;
13339 +       /* more to come */
13340 +};
13341 +
13342 +
13343 +#include <linux/in.h>
13344 +#include <linux/in6.h>
13345 +
13346 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
13347 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
13348 +
13349 +struct  vcmd_net_create {
13350 +       uint64_t flagword;
13351 +};
13352 +
13353 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
13354 +
13355 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
13356 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
13357 +
13358 +struct vcmd_net_addr_v0 {
13359 +       uint16_t type;
13360 +       uint16_t count;
13361 +       struct in_addr ip[4];
13362 +       struct in_addr mask[4];
13363 +};
13364 +
13365 +#define VCMD_net_add_ipv4_v1   VC_CMD(NETALT, 1, 1)
13366 +#define VCMD_net_rem_ipv4_v1   VC_CMD(NETALT, 2, 1)
13367 +
13368 +struct vcmd_net_addr_ipv4_v1 {
13369 +       uint16_t type;
13370 +       uint16_t flags;
13371 +       struct in_addr ip;
13372 +       struct in_addr mask;
13373 +};
13374 +
13375 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 2)
13376 +#define VCMD_net_rem_ipv4      VC_CMD(NETALT, 2, 2)
13377 +
13378 +struct vcmd_net_addr_ipv4_v2 {
13379 +       uint16_t type;
13380 +       uint16_t flags;
13381 +       struct in_addr ip;
13382 +       struct in_addr ip2;
13383 +       struct in_addr mask;
13384 +};
13385 +
13386 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
13387 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
13388 +
13389 +struct vcmd_net_addr_ipv6_v1 {
13390 +       uint16_t type;
13391 +       uint16_t flags;
13392 +       uint32_t prefix;
13393 +       struct in6_addr ip;
13394 +       struct in6_addr mask;
13395 +};
13396 +
13397 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
13398 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
13399 +
13400 +struct vcmd_match_ipv4_v0 {
13401 +       uint16_t type;
13402 +       uint16_t flags;
13403 +       uint16_t parent;
13404 +       uint16_t prefix;
13405 +       struct in_addr ip;
13406 +       struct in_addr ip2;
13407 +       struct in_addr mask;
13408 +};
13409 +
13410 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
13411 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
13412 +
13413 +struct vcmd_match_ipv6_v0 {
13414 +       uint16_t type;
13415 +       uint16_t flags;
13416 +       uint16_t parent;
13417 +       uint16_t prefix;
13418 +       struct in6_addr ip;
13419 +       struct in6_addr ip2;
13420 +       struct in6_addr mask;
13421 +};
13422 +
13423 +
13424 +
13425 +
13426 +/* flag commands */
13427 +
13428 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
13429 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
13430 +
13431 +struct vcmd_net_flags_v0 {
13432 +       uint64_t flagword;
13433 +       uint64_t mask;
13434 +};
13435 +
13436 +
13437 +
13438 +/* network caps commands */
13439 +
13440 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
13441 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
13442 +
13443 +struct vcmd_net_caps_v0 {
13444 +       uint64_t ncaps;
13445 +       uint64_t cmask;
13446 +};
13447 +
13448 +#endif /* _UAPI_VS_NETWORK_CMD_H */
13449 diff -NurpP --minimal linux-3.10.33/include/uapi/vserver/sched_cmd.h linux-3.10.33-vs2.3.6.8/include/uapi/vserver/sched_cmd.h
13450 --- linux-3.10.33/include/uapi/vserver/sched_cmd.h      1970-01-01 00:00:00.000000000 +0000
13451 +++ linux-3.10.33-vs2.3.6.8/include/uapi/vserver/sched_cmd.h    2013-08-22 20:30:00.000000000 +0000
13452 @@ -0,0 +1,13 @@
13453 +#ifndef _UAPI_VS_SCHED_CMD_H
13454 +#define _UAPI_VS_SCHED_CMD_H
13455 +
13456 +
13457 +struct vcmd_prio_bias {
13458 +       int32_t cpu_id;
13459 +       int32_t prio_bias;
13460 +};
13461 +
13462 +#define VCMD_set_prio_bias     VC_CMD(SCHED, 4, 0)
13463 +#define VCMD_get_prio_bias     VC_CMD(SCHED, 5, 0)
13464 +
13465 +#endif /* _UAPI_VS_SCHED_CMD_H */
13466 diff -NurpP --minimal linux-3.10.33/include/uapi/vserver/signal_cmd.h linux-3.10.33-vs2.3.6.8/include/uapi/vserver/signal_cmd.h
13467 --- linux-3.10.33/include/uapi/vserver/signal_cmd.h     1970-01-01 00:00:00.000000000 +0000
13468 +++ linux-3.10.33-vs2.3.6.8/include/uapi/vserver/signal_cmd.h   2013-08-22 20:30:00.000000000 +0000
13469 @@ -0,0 +1,31 @@
13470 +#ifndef _UAPI_VS_SIGNAL_CMD_H
13471 +#define _UAPI_VS_SIGNAL_CMD_H
13472 +
13473 +
13474 +/*  signalling vserver commands */
13475 +
13476 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
13477 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
13478 +
13479 +struct vcmd_ctx_kill_v0 {
13480 +       int32_t pid;
13481 +       int32_t sig;
13482 +};
13483 +
13484 +struct vcmd_wait_exit_v0 {
13485 +       int32_t reboot_cmd;
13486 +       int32_t exit_code;
13487 +};
13488 +
13489 +
13490 +/*  process alteration commands */
13491 +
13492 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
13493 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
13494 +
13495 +struct vcmd_pflags_v0 {
13496 +       uint32_t flagword;
13497 +       uint32_t mask;
13498 +};
13499 +
13500 +#endif /* _UAPI_VS_SIGNAL_CMD_H */
13501 diff -NurpP --minimal linux-3.10.33/include/uapi/vserver/space_cmd.h linux-3.10.33-vs2.3.6.8/include/uapi/vserver/space_cmd.h
13502 --- linux-3.10.33/include/uapi/vserver/space_cmd.h      1970-01-01 00:00:00.000000000 +0000
13503 +++ linux-3.10.33-vs2.3.6.8/include/uapi/vserver/space_cmd.h    2013-08-22 20:30:00.000000000 +0000
13504 @@ -0,0 +1,28 @@
13505 +#ifndef _UAPI_VS_SPACE_CMD_H
13506 +#define _UAPI_VS_SPACE_CMD_H
13507 +
13508 +
13509 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
13510 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
13511 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
13512 +
13513 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
13514 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
13515 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
13516 +
13517 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
13518 +
13519 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
13520 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
13521 +
13522 +
13523 +struct vcmd_space_mask_v1 {
13524 +       uint64_t mask;
13525 +};
13526 +
13527 +struct vcmd_space_mask_v2 {
13528 +       uint64_t mask;
13529 +       uint32_t index;
13530 +};
13531 +
13532 +#endif /* _UAPI_VS_SPACE_CMD_H */
13533 diff -NurpP --minimal linux-3.10.33/include/uapi/vserver/switch.h linux-3.10.33-vs2.3.6.8/include/uapi/vserver/switch.h
13534 --- linux-3.10.33/include/uapi/vserver/switch.h 1970-01-01 00:00:00.000000000 +0000
13535 +++ linux-3.10.33-vs2.3.6.8/include/uapi/vserver/switch.h       2013-08-22 20:30:00.000000000 +0000
13536 @@ -0,0 +1,90 @@
13537 +#ifndef _UAPI_VS_SWITCH_H
13538 +#define _UAPI_VS_SWITCH_H
13539 +
13540 +#include <linux/types.h>
13541 +
13542 +
13543 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
13544 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
13545 +#define VC_VERSION(c)          ((c) & 0xFFF)
13546 +
13547 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
13548 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
13549 +
13550 +/*
13551 +
13552 +  Syscall Matrix V2.8
13553 +
13554 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
13555 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
13556 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
13557 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13558 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
13559 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
13560 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13561 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
13562 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
13563 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13564 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
13565 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
13566 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13567 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
13568 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
13569 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13570 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
13571 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
13572 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13573 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
13574 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
13575 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
13576 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
13577 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
13578 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13579 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
13580 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
13581 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13582 +
13583 +*/
13584 +
13585 +#define VC_CAT_VERSION         0
13586 +
13587 +#define VC_CAT_VSETUP          1
13588 +#define VC_CAT_VHOST           2
13589 +
13590 +#define VC_CAT_DEVICE          6
13591 +
13592 +#define VC_CAT_VPROC           9
13593 +#define VC_CAT_PROCALT         10
13594 +#define VC_CAT_PROCMIG         11
13595 +#define VC_CAT_PROCTRL         12
13596 +
13597 +#define VC_CAT_SCHED           14
13598 +#define VC_CAT_MEMCTRL         20
13599 +
13600 +#define VC_CAT_VNET            25
13601 +#define VC_CAT_NETALT          26
13602 +#define VC_CAT_NETMIG          27
13603 +#define VC_CAT_NETCTRL         28
13604 +
13605 +#define VC_CAT_TAGMIG          35
13606 +#define VC_CAT_DLIMIT          36
13607 +#define VC_CAT_INODE           38
13608 +
13609 +#define VC_CAT_VSTAT           40
13610 +#define VC_CAT_VINFO           46
13611 +#define VC_CAT_EVENT           48
13612 +
13613 +#define VC_CAT_FLAGS           52
13614 +#define VC_CAT_VSPACE          54
13615 +#define VC_CAT_DEBUG           56
13616 +#define VC_CAT_RLIMIT          60
13617 +
13618 +#define VC_CAT_SYSTEST         61
13619 +#define VC_CAT_COMPAT          63
13620 +
13621 +/*  query version */
13622 +
13623 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
13624 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
13625 +
13626 +#endif /* _UAPI_VS_SWITCH_H */
13627 diff -NurpP --minimal linux-3.10.33/include/uapi/vserver/tag_cmd.h linux-3.10.33-vs2.3.6.8/include/uapi/vserver/tag_cmd.h
13628 --- linux-3.10.33/include/uapi/vserver/tag_cmd.h        1970-01-01 00:00:00.000000000 +0000
13629 +++ linux-3.10.33-vs2.3.6.8/include/uapi/vserver/tag_cmd.h      2013-08-22 20:30:00.000000000 +0000
13630 @@ -0,0 +1,14 @@
13631 +#ifndef _UAPI_VS_TAG_CMD_H
13632 +#define _UAPI_VS_TAG_CMD_H
13633 +
13634 +
13635 +/* vinfo commands */
13636 +
13637 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
13638 +
13639 +
13640 +/* context commands */
13641 +
13642 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
13643 +
13644 +#endif /* _UAPI_VS_TAG_CMD_H */
13645 diff -NurpP --minimal linux-3.10.33/init/Kconfig linux-3.10.33-vs2.3.6.8/init/Kconfig
13646 --- linux-3.10.33/init/Kconfig  2013-07-14 17:01:34.000000000 +0000
13647 +++ linux-3.10.33-vs2.3.6.8/init/Kconfig        2013-08-22 20:30:00.000000000 +0000
13648 @@ -805,6 +805,7 @@ config NUMA_BALANCING
13649  menuconfig CGROUPS
13650         boolean "Control Group support"
13651         depends on EVENTFD
13652 +       default y
13653         help
13654           This option adds support for grouping sets of processes together, for
13655           use with process control subsystems such as Cpusets, CFS, memory
13656 @@ -1067,6 +1068,7 @@ config IPC_NS
13657  config USER_NS
13658         bool "User namespace"
13659         depends on UIDGID_CONVERTED
13660 +       depends on VSERVER_DISABLED
13661         select UIDGID_STRICT_TYPE_CHECKS
13662  
13663         default n
13664 diff -NurpP --minimal linux-3.10.33/init/main.c linux-3.10.33-vs2.3.6.8/init/main.c
13665 --- linux-3.10.33/init/main.c   2014-03-12 13:16:02.000000000 +0000
13666 +++ linux-3.10.33-vs2.3.6.8/init/main.c 2013-11-13 17:19:37.000000000 +0000
13667 @@ -75,6 +75,7 @@
13668  #include <linux/blkdev.h>
13669  #include <linux/elevator.h>
13670  #include <linux/random.h>
13671 +#include <linux/vserver/percpu.h>
13672  
13673  #include <asm/io.h>
13674  #include <asm/bugs.h>
13675 diff -NurpP --minimal linux-3.10.33/ipc/mqueue.c linux-3.10.33-vs2.3.6.8/ipc/mqueue.c
13676 --- linux-3.10.33/ipc/mqueue.c  2014-03-12 13:16:02.000000000 +0000
13677 +++ linux-3.10.33-vs2.3.6.8/ipc/mqueue.c        2014-03-12 13:18:33.000000000 +0000
13678 @@ -35,6 +35,8 @@
13679  #include <linux/ipc_namespace.h>
13680  #include <linux/user_namespace.h>
13681  #include <linux/slab.h>
13682 +#include <linux/vs_context.h>
13683 +#include <linux/vs_limit.h>
13684  
13685  #include <net/sock.h>
13686  #include "util.h"
13687 @@ -76,6 +78,7 @@ struct mqueue_inode_info {
13688         struct pid* notify_owner;
13689         struct user_namespace *notify_user_ns;
13690         struct user_struct *user;       /* user who created, for accounting */
13691 +       struct vx_info *vxi;
13692         struct sock *notify_sock;
13693         struct sk_buff *notify_cookie;
13694  
13695 @@ -234,6 +237,7 @@ static struct inode *mqueue_get_inode(st
13696         if (S_ISREG(mode)) {
13697                 struct mqueue_inode_info *info;
13698                 unsigned long mq_bytes, mq_treesize;
13699 +               struct vx_info *vxi = current_vx_info();
13700  
13701                 inode->i_fop = &mqueue_file_operations;
13702                 inode->i_size = FILENT_SIZE;
13703 @@ -247,6 +251,7 @@ static struct inode *mqueue_get_inode(st
13704                 info->notify_user_ns = NULL;
13705                 info->qsize = 0;
13706                 info->user = NULL;      /* set when all is ok */
13707 +               info->vxi = NULL;
13708                 info->msg_tree = RB_ROOT;
13709                 info->node_cache = NULL;
13710                 memset(&info->attr, 0, sizeof(info->attr));
13711 @@ -280,17 +285,20 @@ static struct inode *mqueue_get_inode(st
13712  
13713                 spin_lock(&mq_lock);
13714                 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
13715 -                   u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
13716 +                   u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE) ||
13717 +                   !vx_ipcmsg_avail(vxi, mq_bytes)) {
13718                         spin_unlock(&mq_lock);
13719                         /* mqueue_evict_inode() releases info->messages */
13720                         ret = -EMFILE;
13721                         goto out_inode;
13722                 }
13723                 u->mq_bytes += mq_bytes;
13724 +               vx_ipcmsg_add(vxi, u, mq_bytes);
13725                 spin_unlock(&mq_lock);
13726  
13727                 /* all is ok */
13728                 info->user = get_uid(u);
13729 +               info->vxi = get_vx_info(vxi);
13730         } else if (S_ISDIR(mode)) {
13731                 inc_nlink(inode);
13732                 /* Some things misbehave if size == 0 on a directory */
13733 @@ -402,8 +410,11 @@ static void mqueue_evict_inode(struct in
13734  
13735         user = info->user;
13736         if (user) {
13737 +               struct vx_info *vxi = info->vxi;
13738 +
13739                 spin_lock(&mq_lock);
13740                 user->mq_bytes -= mq_bytes;
13741 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
13742                 /*
13743                  * get_ns_from_inode() ensures that the
13744                  * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
13745 @@ -413,6 +424,7 @@ static void mqueue_evict_inode(struct in
13746                 if (ipc_ns)
13747                         ipc_ns->mq_queues_count--;
13748                 spin_unlock(&mq_lock);
13749 +               put_vx_info(vxi);
13750                 free_uid(user);
13751         }
13752         if (ipc_ns)
13753 diff -NurpP --minimal linux-3.10.33/ipc/msg.c linux-3.10.33-vs2.3.6.8/ipc/msg.c
13754 --- linux-3.10.33/ipc/msg.c     2014-03-12 13:16:02.000000000 +0000
13755 +++ linux-3.10.33-vs2.3.6.8/ipc/msg.c   2013-11-13 17:17:16.000000000 +0000
13756 @@ -37,6 +37,7 @@
13757  #include <linux/rwsem.h>
13758  #include <linux/nsproxy.h>
13759  #include <linux/ipc_namespace.h>
13760 +#include <linux/vs_base.h>
13761  
13762  #include <asm/current.h>
13763  #include <asm/uaccess.h>
13764 @@ -194,6 +195,7 @@ static int newque(struct ipc_namespace *
13765  
13766         msq->q_perm.mode = msgflg & S_IRWXUGO;
13767         msq->q_perm.key = key;
13768 +       msq->q_perm.xid = vx_current_xid();
13769  
13770         msq->q_perm.security = NULL;
13771         retval = security_msg_queue_alloc(msq);
13772 diff -NurpP --minimal linux-3.10.33/ipc/sem.c linux-3.10.33-vs2.3.6.8/ipc/sem.c
13773 --- linux-3.10.33/ipc/sem.c     2014-03-12 13:16:02.000000000 +0000
13774 +++ linux-3.10.33-vs2.3.6.8/ipc/sem.c   2013-12-23 17:42:40.000000000 +0000
13775 @@ -86,6 +86,8 @@
13776  #include <linux/rwsem.h>
13777  #include <linux/nsproxy.h>
13778  #include <linux/ipc_namespace.h>
13779 +#include <linux/vs_base.h>
13780 +#include <linux/vs_limit.h>
13781  
13782  #include <asm/uaccess.h>
13783  #include "util.h"
13784 @@ -500,6 +502,7 @@ static int newary(struct ipc_namespace *
13785  
13786         sma->sem_perm.mode = (semflg & S_IRWXUGO);
13787         sma->sem_perm.key = key;
13788 +       sma->sem_perm.xid = vx_current_xid();
13789  
13790         sma->sem_perm.security = NULL;
13791         retval = security_sem_alloc(sma);
13792 @@ -514,6 +517,9 @@ static int newary(struct ipc_namespace *
13793                 return id;
13794         }
13795         ns->used_sems += nsems;
13796 +       /* FIXME: obsoleted? */
13797 +       vx_semary_inc(sma);
13798 +       vx_nsems_add(sma, nsems);
13799  
13800         sma->sem_base = (struct sem *) &sma[1];
13801  
13802 @@ -1103,6 +1109,9 @@ static void freeary(struct ipc_namespace
13803  
13804         wake_up_sem_queue_do(&tasks);
13805         ns->used_sems -= sma->sem_nsems;
13806 +       /* FIXME: obsoleted? */
13807 +       vx_nsems_sub(sma, sma->sem_nsems);
13808 +       vx_semary_dec(sma);
13809         ipc_rcu_putref(sma, sem_rcu_free);
13810  }
13811  
13812 diff -NurpP --minimal linux-3.10.33/ipc/shm.c linux-3.10.33-vs2.3.6.8/ipc/shm.c
13813 --- linux-3.10.33/ipc/shm.c     2014-03-12 13:16:02.000000000 +0000
13814 +++ linux-3.10.33-vs2.3.6.8/ipc/shm.c   2013-11-30 07:55:52.000000000 +0000
13815 @@ -42,6 +42,8 @@
13816  #include <linux/nsproxy.h>
13817  #include <linux/mount.h>
13818  #include <linux/ipc_namespace.h>
13819 +#include <linux/vs_context.h>
13820 +#include <linux/vs_limit.h>
13821  
13822  #include <asm/uaccess.h>
13823  
13824 @@ -209,10 +211,14 @@ static void shm_open(struct vm_area_stru
13825  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
13826  {
13827         struct file *shm_file;
13828 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
13829 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
13830  
13831         shm_file = shp->shm_file;
13832         shp->shm_file = NULL;
13833 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
13834 +       vx_ipcshm_sub(vxi, shp, numpages);
13835 +       ns->shm_tot -= numpages;
13836 +
13837         shm_rmid(ns, shp);
13838         shm_unlock(shp);
13839         if (!is_file_hugepages(shm_file))
13840 @@ -220,6 +226,7 @@ static void shm_destroy(struct ipc_names
13841         else if (shp->mlock_user)
13842                 user_shm_unlock(file_inode(shm_file)->i_size, shp->mlock_user);
13843         fput(shm_file);
13844 +       put_vx_info(vxi);
13845         ipc_rcu_putref(shp, shm_rcu_free);
13846  }
13847  
13848 @@ -497,11 +504,15 @@ static int newseg(struct ipc_namespace *
13849         if (ns->shm_tot + numpages > ns->shm_ctlall)
13850                 return -ENOSPC;
13851  
13852 +       if (!vx_ipcshm_avail(current_vx_info(), numpages))
13853 +               return -ENOSPC;
13854 +
13855         shp = ipc_rcu_alloc(sizeof(*shp));
13856         if (!shp)
13857                 return -ENOMEM;
13858  
13859         shp->shm_perm.key = key;
13860 +       shp->shm_perm.xid = vx_current_xid();
13861         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
13862         shp->mlock_user = NULL;
13863  
13864 @@ -570,6 +581,7 @@ static int newseg(struct ipc_namespace *
13865  
13866         ipc_unlock_object(&shp->shm_perm);
13867         rcu_read_unlock();
13868 +       vx_ipcshm_add(current_vx_info(), key, numpages);
13869         return error;
13870  
13871  no_id:
13872 diff -NurpP --minimal linux-3.10.33/kernel/Makefile linux-3.10.33-vs2.3.6.8/kernel/Makefile
13873 --- linux-3.10.33/kernel/Makefile       2013-07-14 17:01:34.000000000 +0000
13874 +++ linux-3.10.33-vs2.3.6.8/kernel/Makefile     2013-08-22 21:18:32.000000000 +0000
13875 @@ -25,6 +25,7 @@ endif
13876  obj-y += sched/
13877  obj-y += power/
13878  obj-y += cpu/
13879 +obj-y += vserver/
13880  
13881  obj-$(CONFIG_CHECKPOINT_RESTORE) += kcmp.o
13882  obj-$(CONFIG_FREEZER) += freezer.o
13883 diff -NurpP --minimal linux-3.10.33/kernel/auditsc.c linux-3.10.33-vs2.3.6.8/kernel/auditsc.c
13884 --- linux-3.10.33/kernel/auditsc.c      2014-03-12 13:16:02.000000000 +0000
13885 +++ linux-3.10.33-vs2.3.6.8/kernel/auditsc.c    2013-12-23 17:42:40.000000000 +0000
13886 @@ -1982,7 +1982,7 @@ int audit_set_loginuid(kuid_t loginuid)
13887         if (audit_loginuid_set(task))
13888                 return -EPERM;
13889  #else /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
13890 -       if (!capable(CAP_AUDIT_CONTROL))
13891 +       if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
13892                 return -EPERM;
13893  #endif  /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
13894  
13895 diff -NurpP --minimal linux-3.10.33/kernel/capability.c linux-3.10.33-vs2.3.6.8/kernel/capability.c
13896 --- linux-3.10.33/kernel/capability.c   2013-05-31 13:45:29.000000000 +0000
13897 +++ linux-3.10.33-vs2.3.6.8/kernel/capability.c 2013-08-22 20:30:00.000000000 +0000
13898 @@ -15,6 +15,7 @@
13899  #include <linux/syscalls.h>
13900  #include <linux/pid_namespace.h>
13901  #include <linux/user_namespace.h>
13902 +#include <linux/vs_context.h>
13903  #include <asm/uaccess.h>
13904  
13905  /*
13906 @@ -116,6 +117,7 @@ static int cap_validate_magic(cap_user_h
13907         return 0;
13908  }
13909  
13910 +
13911  /*
13912   * The only thing that can change the capabilities of the current
13913   * process is the current process. As such, we can't be in this code
13914 @@ -349,6 +351,8 @@ bool has_ns_capability_noaudit(struct ta
13915         return (ret == 0);
13916  }
13917  
13918 +#include <linux/vserver/base.h>
13919 +
13920  /**
13921   * has_capability_noaudit - Does a task have a capability (unaudited) in the
13922   * initial user ns
13923 diff -NurpP --minimal linux-3.10.33/kernel/compat.c linux-3.10.33-vs2.3.6.8/kernel/compat.c
13924 --- linux-3.10.33/kernel/compat.c       2013-07-14 17:01:34.000000000 +0000
13925 +++ linux-3.10.33-vs2.3.6.8/kernel/compat.c     2013-08-22 20:30:00.000000000 +0000
13926 @@ -27,6 +27,7 @@
13927  #include <linux/times.h>
13928  #include <linux/ptrace.h>
13929  #include <linux/gfp.h>
13930 +#include <linux/vs_time.h>
13931  
13932  #include <asm/uaccess.h>
13933  
13934 @@ -1040,7 +1041,7 @@ asmlinkage long compat_sys_stime(compat_
13935         if (err)
13936                 return err;
13937  
13938 -       do_settimeofday(&tv);
13939 +       vx_settimeofday(&tv);
13940         return 0;
13941  }
13942  
13943 diff -NurpP --minimal linux-3.10.33/kernel/cred.c linux-3.10.33-vs2.3.6.8/kernel/cred.c
13944 --- linux-3.10.33/kernel/cred.c 2013-02-19 13:58:56.000000000 +0000
13945 +++ linux-3.10.33-vs2.3.6.8/kernel/cred.c       2013-08-22 20:30:00.000000000 +0000
13946 @@ -56,31 +56,6 @@ struct cred init_cred = {
13947         .group_info             = &init_groups,
13948  };
13949  
13950 -static inline void set_cred_subscribers(struct cred *cred, int n)
13951 -{
13952 -#ifdef CONFIG_DEBUG_CREDENTIALS
13953 -       atomic_set(&cred->subscribers, n);
13954 -#endif
13955 -}
13956 -
13957 -static inline int read_cred_subscribers(const struct cred *cred)
13958 -{
13959 -#ifdef CONFIG_DEBUG_CREDENTIALS
13960 -       return atomic_read(&cred->subscribers);
13961 -#else
13962 -       return 0;
13963 -#endif
13964 -}
13965 -
13966 -static inline void alter_cred_subscribers(const struct cred *_cred, int n)
13967 -{
13968 -#ifdef CONFIG_DEBUG_CREDENTIALS
13969 -       struct cred *cred = (struct cred *) _cred;
13970 -
13971 -       atomic_add(n, &cred->subscribers);
13972 -#endif
13973 -}
13974 -
13975  /*
13976   * The RCU callback to actually dispose of a set of credentials
13977   */
13978 @@ -232,21 +207,16 @@ error:
13979   *
13980   * Call commit_creds() or abort_creds() to clean up.
13981   */
13982 -struct cred *prepare_creds(void)
13983 +struct cred *__prepare_creds(const struct cred *old)
13984  {
13985 -       struct task_struct *task = current;
13986 -       const struct cred *old;
13987         struct cred *new;
13988  
13989 -       validate_process_creds();
13990 -
13991         new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
13992         if (!new)
13993                 return NULL;
13994  
13995         kdebug("prepare_creds() alloc %p", new);
13996  
13997 -       old = task->cred;
13998         memcpy(new, old, sizeof(struct cred));
13999  
14000         atomic_set(&new->usage, 1);
14001 @@ -275,6 +245,13 @@ error:
14002         abort_creds(new);
14003         return NULL;
14004  }
14005 +
14006 +struct cred *prepare_creds(void)
14007 +{
14008 +       validate_process_creds();
14009 +
14010 +       return __prepare_creds(current->cred);
14011 +}
14012  EXPORT_SYMBOL(prepare_creds);
14013  
14014  /*
14015 diff -NurpP --minimal linux-3.10.33/kernel/exit.c linux-3.10.33-vs2.3.6.8/kernel/exit.c
14016 --- linux-3.10.33/kernel/exit.c 2013-07-14 17:01:35.000000000 +0000
14017 +++ linux-3.10.33-vs2.3.6.8/kernel/exit.c       2013-08-22 20:30:00.000000000 +0000
14018 @@ -48,6 +48,10 @@
14019  #include <linux/fs_struct.h>
14020  #include <linux/init_task.h>
14021  #include <linux/perf_event.h>
14022 +#include <linux/vs_limit.h>
14023 +#include <linux/vs_context.h>
14024 +#include <linux/vs_network.h>
14025 +#include <linux/vs_pid.h>
14026  #include <trace/events/sched.h>
14027  #include <linux/hw_breakpoint.h>
14028  #include <linux/oom.h>
14029 @@ -514,15 +518,25 @@ static struct task_struct *find_new_reap
14030         __acquires(&tasklist_lock)
14031  {
14032         struct pid_namespace *pid_ns = task_active_pid_ns(father);
14033 -       struct task_struct *thread;
14034 +       struct vx_info *vxi = task_get_vx_info(father);
14035 +       struct task_struct *thread = father;
14036 +       struct task_struct *reaper;
14037  
14038 -       thread = father;
14039         while_each_thread(father, thread) {
14040                 if (thread->flags & PF_EXITING)
14041                         continue;
14042                 if (unlikely(pid_ns->child_reaper == father))
14043                         pid_ns->child_reaper = thread;
14044 -               return thread;
14045 +               reaper = thread;
14046 +               goto out_put;
14047 +       }
14048 +
14049 +       reaper = pid_ns->child_reaper;
14050 +       if (vxi) {
14051 +               BUG_ON(!vxi->vx_reaper);
14052 +               if (vxi->vx_reaper != init_pid_ns.child_reaper &&
14053 +                   vxi->vx_reaper != father)
14054 +                       reaper = vxi->vx_reaper;
14055         }
14056  
14057         if (unlikely(pid_ns->child_reaper == father)) {
14058 @@ -560,7 +574,9 @@ static struct task_struct *find_new_reap
14059                 }
14060         }
14061  
14062 -       return pid_ns->child_reaper;
14063 +out_put:
14064 +       put_vx_info(vxi);
14065 +       return reaper;
14066  }
14067  
14068  /*
14069 @@ -611,10 +627,15 @@ static void forget_original_parent(struc
14070         list_for_each_entry_safe(p, n, &father->children, sibling) {
14071                 struct task_struct *t = p;
14072                 do {
14073 -                       t->real_parent = reaper;
14074 +                       struct task_struct *new_parent = reaper;
14075 +
14076 +                       if (unlikely(p == reaper))
14077 +                               new_parent = task_active_pid_ns(p)->child_reaper;
14078 +
14079 +                       t->real_parent = new_parent;
14080                         if (t->parent == father) {
14081                                 BUG_ON(t->ptrace);
14082 -                               t->parent = t->real_parent;
14083 +                               t->parent = new_parent;
14084                         }
14085                         if (t->pdeath_signal)
14086                                 group_send_sig_info(t->pdeath_signal,
14087 @@ -821,6 +842,9 @@ void do_exit(long code)
14088          */
14089         ptrace_put_breakpoints(tsk);
14090  
14091 +       /* needs to stay before exit_notify() */
14092 +       exit_vx_info_early(tsk, code);
14093 +
14094         exit_notify(tsk, group_dead);
14095  #ifdef CONFIG_NUMA
14096         task_lock(tsk);
14097 @@ -874,10 +898,15 @@ void do_exit(long code)
14098         smp_mb();
14099         raw_spin_unlock_wait(&tsk->pi_lock);
14100  
14101 +       /* needs to stay after exit_notify() */
14102 +       exit_vx_info(tsk, code);
14103 +       exit_nx_info(tsk);
14104 +
14105         /* causes final put_task_struct in finish_task_switch(). */
14106         tsk->state = TASK_DEAD;
14107         tsk->flags |= PF_NOFREEZE;      /* tell freezer to ignore us */
14108         schedule();
14109 +       printk("bad task: %p [%lx]\n", current, current->state);
14110         BUG();
14111         /* Avoid "noreturn function does return".  */
14112         for (;;)
14113 diff -NurpP --minimal linux-3.10.33/kernel/fork.c linux-3.10.33-vs2.3.6.8/kernel/fork.c
14114 --- linux-3.10.33/kernel/fork.c 2014-03-12 13:16:02.000000000 +0000
14115 +++ linux-3.10.33-vs2.3.6.8/kernel/fork.c       2014-01-22 19:00:34.000000000 +0000
14116 @@ -71,6 +71,9 @@
14117  #include <linux/signalfd.h>
14118  #include <linux/uprobes.h>
14119  #include <linux/aio.h>
14120 +#include <linux/vs_context.h>
14121 +#include <linux/vs_network.h>
14122 +#include <linux/vs_limit.h>
14123  
14124  #include <asm/pgtable.h>
14125  #include <asm/pgalloc.h>
14126 @@ -211,6 +214,8 @@ void free_task(struct task_struct *tsk)
14127         arch_release_thread_info(tsk->stack);
14128         free_thread_info(tsk->stack);
14129         rt_mutex_debug_task_free(tsk);
14130 +       clr_vx_info(&tsk->vx_info);
14131 +       clr_nx_info(&tsk->nx_info);
14132         ftrace_graph_exit_task(tsk);
14133         put_seccomp_filter(tsk);
14134         arch_release_task_struct(tsk);
14135 @@ -549,6 +554,7 @@ static struct mm_struct *mm_init(struct
14136         if (likely(!mm_alloc_pgd(mm))) {
14137                 mm->def_flags = 0;
14138                 mmu_notifier_mm_init(mm);
14139 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
14140                 return mm;
14141         }
14142  
14143 @@ -601,6 +607,7 @@ void __mmdrop(struct mm_struct *mm)
14144         destroy_context(mm);
14145         mmu_notifier_mm_destroy(mm);
14146         check_mm(mm);
14147 +       clr_vx_info(&mm->mm_vx_info);
14148         free_mm(mm);
14149  }
14150  EXPORT_SYMBOL_GPL(__mmdrop);
14151 @@ -820,6 +827,7 @@ struct mm_struct *dup_mm(struct task_str
14152                 goto fail_nomem;
14153  
14154         memcpy(mm, oldmm, sizeof(*mm));
14155 +       mm->mm_vx_info = NULL;
14156         mm_init_cpumask(mm);
14157  
14158  #ifdef CONFIG_TRANSPARENT_HUGEPAGE
14159 @@ -861,6 +869,7 @@ fail_nocontext:
14160          * If init_new_context() failed, we cannot use mmput() to free the mm
14161          * because it calls destroy_context()
14162          */
14163 +       clr_vx_info(&mm->mm_vx_info);
14164         mm_free_pgd(mm);
14165         free_mm(mm);
14166         return NULL;
14167 @@ -1139,6 +1148,8 @@ static struct task_struct *copy_process(
14168  {
14169         int retval;
14170         struct task_struct *p;
14171 +       struct vx_info *vxi;
14172 +       struct nx_info *nxi;
14173  
14174         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
14175                 return ERR_PTR(-EINVAL);
14176 @@ -1198,7 +1209,12 @@ static struct task_struct *copy_process(
14177         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
14178         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
14179  #endif
14180 +       init_vx_info(&p->vx_info, current_vx_info());
14181 +       init_nx_info(&p->nx_info, current_nx_info());
14182 +
14183         retval = -EAGAIN;
14184 +       if (!vx_nproc_avail(1))
14185 +               goto bad_fork_free;
14186         if (atomic_read(&p->real_cred->user->processes) >=
14187                         task_rlimit(p, RLIMIT_NPROC)) {
14188                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
14189 @@ -1479,6 +1495,18 @@ static struct task_struct *copy_process(
14190  
14191         total_forks++;
14192         spin_unlock(&current->sighand->siglock);
14193 +
14194 +       /* p is copy of current */
14195 +       vxi = p->vx_info;
14196 +       if (vxi) {
14197 +               claim_vx_info(vxi, p);
14198 +               atomic_inc(&vxi->cvirt.nr_threads);
14199 +               atomic_inc(&vxi->cvirt.total_forks);
14200 +               vx_nproc_inc(p);
14201 +       }
14202 +       nxi = p->nx_info;
14203 +       if (nxi)
14204 +               claim_nx_info(nxi, p);
14205         write_unlock_irq(&tasklist_lock);
14206         proc_fork_connector(p);
14207         cgroup_post_fork(p);
14208 diff -NurpP --minimal linux-3.10.33/kernel/kthread.c linux-3.10.33-vs2.3.6.8/kernel/kthread.c
14209 --- linux-3.10.33/kernel/kthread.c      2013-07-14 17:01:35.000000000 +0000
14210 +++ linux-3.10.33-vs2.3.6.8/kernel/kthread.c    2013-08-22 21:14:28.000000000 +0000
14211 @@ -18,6 +18,7 @@
14212  #include <linux/freezer.h>
14213  #include <linux/ptrace.h>
14214  #include <linux/uaccess.h>
14215 +#include <linux/vs_pid.h>
14216  #include <trace/events/sched.h>
14217  
14218  static DEFINE_SPINLOCK(kthread_create_lock);
14219 diff -NurpP --minimal linux-3.10.33/kernel/nsproxy.c linux-3.10.33-vs2.3.6.8/kernel/nsproxy.c
14220 --- linux-3.10.33/kernel/nsproxy.c      2013-07-14 17:01:35.000000000 +0000
14221 +++ linux-3.10.33-vs2.3.6.8/kernel/nsproxy.c    2013-08-22 21:09:55.000000000 +0000
14222 @@ -20,11 +20,14 @@
14223  #include <linux/mnt_namespace.h>
14224  #include <linux/utsname.h>
14225  #include <linux/pid_namespace.h>
14226 +#include <linux/vserver/global.h>
14227 +#include <linux/vserver/debug.h>
14228  #include <net/net_namespace.h>
14229  #include <linux/ipc_namespace.h>
14230  #include <linux/proc_ns.h>
14231  #include <linux/file.h>
14232  #include <linux/syscalls.h>
14233 +#include "../fs/mount.h"
14234  
14235  static struct kmem_cache *nsproxy_cachep;
14236  
14237 @@ -46,8 +49,11 @@ static inline struct nsproxy *create_nsp
14238         struct nsproxy *nsproxy;
14239  
14240         nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
14241 -       if (nsproxy)
14242 +       if (nsproxy) {
14243                 atomic_set(&nsproxy->count, 1);
14244 +               atomic_inc(&vs_global_nsproxy);
14245 +       }
14246 +       vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
14247         return nsproxy;
14248  }
14249  
14250 @@ -56,9 +62,12 @@ static inline struct nsproxy *create_nsp
14251   * Return the newly created nsproxy.  Do not attach this to the task,
14252   * leave it to the caller to do proper locking and attach it to task.
14253   */
14254 -static struct nsproxy *create_new_namespaces(unsigned long flags,
14255 -       struct task_struct *tsk, struct user_namespace *user_ns,
14256 -       struct fs_struct *new_fs)
14257 +static struct nsproxy *unshare_namespaces(
14258 +       unsigned long flags,
14259 +       struct nsproxy *orig,
14260 +       struct fs_struct *new_fs,
14261 +       struct user_namespace *new_user,
14262 +       struct pid_namespace *new_pid)
14263  {
14264         struct nsproxy *new_nsp;
14265         int err;
14266 @@ -67,31 +76,31 @@ static struct nsproxy *create_new_namesp
14267         if (!new_nsp)
14268                 return ERR_PTR(-ENOMEM);
14269  
14270 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, user_ns, new_fs);
14271 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_user, new_fs);
14272         if (IS_ERR(new_nsp->mnt_ns)) {
14273                 err = PTR_ERR(new_nsp->mnt_ns);
14274                 goto out_ns;
14275         }
14276  
14277 -       new_nsp->uts_ns = copy_utsname(flags, user_ns, tsk->nsproxy->uts_ns);
14278 +       new_nsp->uts_ns = copy_utsname(flags, new_user, orig->uts_ns);
14279         if (IS_ERR(new_nsp->uts_ns)) {
14280                 err = PTR_ERR(new_nsp->uts_ns);
14281                 goto out_uts;
14282         }
14283  
14284 -       new_nsp->ipc_ns = copy_ipcs(flags, user_ns, tsk->nsproxy->ipc_ns);
14285 +       new_nsp->ipc_ns = copy_ipcs(flags, new_user, orig->ipc_ns);
14286         if (IS_ERR(new_nsp->ipc_ns)) {
14287                 err = PTR_ERR(new_nsp->ipc_ns);
14288                 goto out_ipc;
14289         }
14290  
14291 -       new_nsp->pid_ns = copy_pid_ns(flags, user_ns, tsk->nsproxy->pid_ns);
14292 +       new_nsp->pid_ns = copy_pid_ns(flags, new_user, new_pid);
14293         if (IS_ERR(new_nsp->pid_ns)) {
14294                 err = PTR_ERR(new_nsp->pid_ns);
14295                 goto out_pid;
14296         }
14297  
14298 -       new_nsp->net_ns = copy_net_ns(flags, user_ns, tsk->nsproxy->net_ns);
14299 +       new_nsp->net_ns = copy_net_ns(flags, new_user, orig->net_ns);
14300         if (IS_ERR(new_nsp->net_ns)) {
14301                 err = PTR_ERR(new_nsp->net_ns);
14302                 goto out_net;
14303 @@ -116,6 +125,41 @@ out_ns:
14304         return ERR_PTR(err);
14305  }
14306  
14307 +static struct nsproxy *create_new_namespaces(unsigned long flags,
14308 +       struct task_struct *tsk, struct user_namespace *user_ns,
14309 +       struct fs_struct *new_fs)
14310 +
14311 +{
14312 +       return unshare_namespaces(flags, tsk->nsproxy,
14313 +               new_fs, user_ns, task_active_pid_ns(tsk));
14314 +}
14315 +
14316 +/*
14317 + * copies the nsproxy, setting refcount to 1, and grabbing a
14318 + * reference to all contained namespaces.
14319 + */
14320 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
14321 +{
14322 +       struct nsproxy *ns = create_nsproxy();
14323 +
14324 +       if (ns) {
14325 +               memcpy(ns, orig, sizeof(struct nsproxy));
14326 +               atomic_set(&ns->count, 1);
14327 +
14328 +               if (ns->mnt_ns)
14329 +                       get_mnt_ns(ns->mnt_ns);
14330 +               if (ns->uts_ns)
14331 +                       get_uts_ns(ns->uts_ns);
14332 +               if (ns->ipc_ns)
14333 +                       get_ipc_ns(ns->ipc_ns);
14334 +               if (ns->pid_ns)
14335 +                       get_pid_ns(ns->pid_ns);
14336 +               if (ns->net_ns)
14337 +                       get_net(ns->net_ns);
14338 +       }
14339 +       return ns;
14340 +}
14341 +
14342  /*
14343   * called from clone.  This now handles copy for nsproxy and all
14344   * namespaces therein.
14345 @@ -124,9 +168,12 @@ int copy_namespaces(unsigned long flags,
14346  {
14347         struct nsproxy *old_ns = tsk->nsproxy;
14348         struct user_namespace *user_ns = task_cred_xxx(tsk, user_ns);
14349 -       struct nsproxy *new_ns;
14350 +       struct nsproxy *new_ns = NULL;
14351         int err = 0;
14352  
14353 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
14354 +               flags, tsk, old_ns);
14355 +
14356         if (!old_ns)
14357                 return 0;
14358  
14359 @@ -136,7 +183,7 @@ int copy_namespaces(unsigned long flags,
14360                                 CLONE_NEWPID | CLONE_NEWNET)))
14361                 return 0;
14362  
14363 -       if (!ns_capable(user_ns, CAP_SYS_ADMIN)) {
14364 +       if (!vx_ns_can_unshare(user_ns, CAP_SYS_ADMIN, flags)) {
14365                 err = -EPERM;
14366                 goto out;
14367         }
14368 @@ -163,6 +210,9 @@ int copy_namespaces(unsigned long flags,
14369  
14370  out:
14371         put_nsproxy(old_ns);
14372 +       vxdprintk(VXD_CBIT(space, 3),
14373 +               "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
14374 +               flags, tsk, old_ns, err, new_ns);
14375         return err;
14376  }
14377  
14378 @@ -176,7 +226,9 @@ void free_nsproxy(struct nsproxy *ns)
14379                 put_ipc_ns(ns->ipc_ns);
14380         if (ns->pid_ns)
14381                 put_pid_ns(ns->pid_ns);
14382 -       put_net(ns->net_ns);
14383 +       if (ns->net_ns)
14384 +               put_net(ns->net_ns);
14385 +       atomic_dec(&vs_global_nsproxy);
14386         kmem_cache_free(nsproxy_cachep, ns);
14387  }
14388  
14389 @@ -190,12 +242,16 @@ int unshare_nsproxy_namespaces(unsigned
14390         struct user_namespace *user_ns;
14391         int err = 0;
14392  
14393 +       vxdprintk(VXD_CBIT(space, 4),
14394 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
14395 +               unshare_flags, current->nsproxy);
14396 +
14397         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
14398                                CLONE_NEWNET | CLONE_NEWPID)))
14399                 return 0;
14400  
14401         user_ns = new_cred ? new_cred->user_ns : current_user_ns();
14402 -       if (!ns_capable(user_ns, CAP_SYS_ADMIN))
14403 +       if (!vx_ns_can_unshare(user_ns, CAP_SYS_ADMIN, unshare_flags))
14404                 return -EPERM;
14405  
14406         *new_nsp = create_new_namespaces(unshare_flags, current, user_ns,
14407 diff -NurpP --minimal linux-3.10.33/kernel/pid.c linux-3.10.33-vs2.3.6.8/kernel/pid.c
14408 --- linux-3.10.33/kernel/pid.c  2014-03-12 13:16:02.000000000 +0000
14409 +++ linux-3.10.33-vs2.3.6.8/kernel/pid.c        2013-11-13 17:17:16.000000000 +0000
14410 @@ -38,6 +38,7 @@
14411  #include <linux/syscalls.h>
14412  #include <linux/proc_ns.h>
14413  #include <linux/proc_fs.h>
14414 +#include <linux/vs_pid.h>
14415  
14416  #define pid_hashfn(nr, ns)     \
14417         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
14418 @@ -367,7 +368,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
14419  
14420  struct pid *find_vpid(int nr)
14421  {
14422 -       return find_pid_ns(nr, task_active_pid_ns(current));
14423 +       return find_pid_ns(vx_rmap_pid(nr), task_active_pid_ns(current));
14424  }
14425  EXPORT_SYMBOL_GPL(find_vpid);
14426  
14427 @@ -427,6 +428,9 @@ void transfer_pid(struct task_struct *ol
14428  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
14429  {
14430         struct task_struct *result = NULL;
14431 +
14432 +       if (type == PIDTYPE_REALPID)
14433 +               type = PIDTYPE_PID;
14434         if (pid) {
14435                 struct hlist_node *first;
14436                 first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]),
14437 @@ -446,7 +450,7 @@ struct task_struct *find_task_by_pid_ns(
14438         rcu_lockdep_assert(rcu_read_lock_held(),
14439                            "find_task_by_pid_ns() needs rcu_read_lock()"
14440                            " protection");
14441 -       return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
14442 +       return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
14443  }
14444  
14445  struct task_struct *find_task_by_vpid(pid_t vnr)
14446 @@ -490,7 +494,7 @@ struct pid *find_get_pid(pid_t nr)
14447  }
14448  EXPORT_SYMBOL_GPL(find_get_pid);
14449  
14450 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
14451 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
14452  {
14453         struct upid *upid;
14454         pid_t nr = 0;
14455 @@ -504,6 +508,11 @@ pid_t pid_nr_ns(struct pid *pid, struct
14456  }
14457  EXPORT_SYMBOL_GPL(pid_nr_ns);
14458  
14459 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
14460 +{
14461 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
14462 +}
14463 +
14464  pid_t pid_vnr(struct pid *pid)
14465  {
14466         return pid_nr_ns(pid, task_active_pid_ns(current));
14467 diff -NurpP --minimal linux-3.10.33/kernel/pid_namespace.c linux-3.10.33-vs2.3.6.8/kernel/pid_namespace.c
14468 --- linux-3.10.33/kernel/pid_namespace.c        2013-07-14 17:01:35.000000000 +0000
14469 +++ linux-3.10.33-vs2.3.6.8/kernel/pid_namespace.c      2013-08-22 20:30:00.000000000 +0000
14470 @@ -18,6 +18,7 @@
14471  #include <linux/proc_ns.h>
14472  #include <linux/reboot.h>
14473  #include <linux/export.h>
14474 +#include <linux/vserver/global.h>
14475  
14476  struct pid_cache {
14477         int nr_ids;
14478 @@ -110,6 +111,7 @@ static struct pid_namespace *create_pid_
14479                 goto out_free_map;
14480  
14481         kref_init(&ns->kref);
14482 +       atomic_inc(&vs_global_pid_ns);
14483         ns->level = level;
14484         ns->parent = get_pid_ns(parent_pid_ns);
14485         ns->user_ns = get_user_ns(user_ns);
14486 @@ -140,6 +142,7 @@ static void destroy_pid_namespace(struct
14487         for (i = 0; i < PIDMAP_ENTRIES; i++)
14488                 kfree(ns->pidmap[i].page);
14489         put_user_ns(ns->user_ns);
14490 +       atomic_dec(&vs_global_pid_ns);
14491         kmem_cache_free(pid_ns_cachep, ns);
14492  }
14493  
14494 diff -NurpP --minimal linux-3.10.33/kernel/posix-timers.c linux-3.10.33-vs2.3.6.8/kernel/posix-timers.c
14495 --- linux-3.10.33/kernel/posix-timers.c 2013-07-14 17:01:35.000000000 +0000
14496 +++ linux-3.10.33-vs2.3.6.8/kernel/posix-timers.c       2013-08-22 21:10:34.000000000 +0000
14497 @@ -48,6 +48,7 @@
14498  #include <linux/workqueue.h>
14499  #include <linux/export.h>
14500  #include <linux/hashtable.h>
14501 +#include <linux/vs_context.h>
14502  
14503  /*
14504   * Management arrays for POSIX timers. Timers are now kept in static hash table
14505 @@ -398,6 +399,7 @@ int posix_timer_event(struct k_itimer *t
14506  {
14507         struct task_struct *task;
14508         int shared, ret = -1;
14509 +
14510         /*
14511          * FIXME: if ->sigq is queued we can race with
14512          * dequeue_signal()->do_schedule_next_timer().
14513 @@ -414,10 +416,18 @@ int posix_timer_event(struct k_itimer *t
14514         rcu_read_lock();
14515         task = pid_task(timr->it_pid, PIDTYPE_PID);
14516         if (task) {
14517 +               struct vx_info_save vxis;
14518 +               struct vx_info *vxi;
14519 +
14520 +               vxi = get_vx_info(task->vx_info);
14521 +               enter_vx_info(vxi, &vxis);
14522                 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
14523                 ret = send_sigqueue(timr->sigq, task, shared);
14524 +               leave_vx_info(&vxis);
14525 +               put_vx_info(vxi);
14526         }
14527         rcu_read_unlock();
14528 +
14529         /* If we failed to send the signal the timer stops. */
14530         return ret > 0;
14531  }
14532 diff -NurpP --minimal linux-3.10.33/kernel/printk.c linux-3.10.33-vs2.3.6.8/kernel/printk.c
14533 --- linux-3.10.33/kernel/printk.c       2014-03-12 13:16:02.000000000 +0000
14534 +++ linux-3.10.33-vs2.3.6.8/kernel/printk.c     2013-11-13 17:17:16.000000000 +0000
14535 @@ -45,6 +45,7 @@
14536  #include <linux/poll.h>
14537  #include <linux/irq_work.h>
14538  #include <linux/utsname.h>
14539 +#include <linux/vs_cvirt.h>
14540  
14541  #include <asm/uaccess.h>
14542  
14543 @@ -391,7 +392,7 @@ static int check_syslog_permissions(int
14544                 return 0;
14545  
14546         if (syslog_action_restricted(type)) {
14547 -               if (capable(CAP_SYSLOG))
14548 +               if (vx_capable(CAP_SYSLOG, VXC_SYSLOG))
14549                         return 0;
14550                 /*
14551                  * For historical reasons, accept CAP_SYS_ADMIN too, with
14552 @@ -1140,12 +1141,9 @@ int do_syslog(int type, char __user *buf
14553         if (error)
14554                 return error;
14555  
14556 -       switch (type) {
14557 -       case SYSLOG_ACTION_CLOSE:       /* Close log */
14558 -               break;
14559 -       case SYSLOG_ACTION_OPEN:        /* Open log */
14560 -               break;
14561 -       case SYSLOG_ACTION_READ:        /* Read from log */
14562 +       if ((type == SYSLOG_ACTION_READ) ||
14563 +           (type == SYSLOG_ACTION_READ_ALL) ||
14564 +           (type == SYSLOG_ACTION_READ_CLEAR)) {
14565                 error = -EINVAL;
14566                 if (!buf || len < 0)
14567                         goto out;
14568 @@ -1156,6 +1154,16 @@ int do_syslog(int type, char __user *buf
14569                         error = -EFAULT;
14570                         goto out;
14571                 }
14572 +       }
14573 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
14574 +               return vx_do_syslog(type, buf, len);
14575 +
14576 +       switch (type) {
14577 +       case SYSLOG_ACTION_CLOSE:       /* Close log */
14578 +               break;
14579 +       case SYSLOG_ACTION_OPEN:        /* Open log */
14580 +               break;
14581 +       case SYSLOG_ACTION_READ:        /* Read from log */
14582                 error = wait_event_interruptible(log_wait,
14583                                                  syslog_seq != log_next_seq);
14584                 if (error)
14585 @@ -1168,16 +1176,6 @@ int do_syslog(int type, char __user *buf
14586                 /* FALL THRU */
14587         /* Read last kernel messages */
14588         case SYSLOG_ACTION_READ_ALL:
14589 -               error = -EINVAL;
14590 -               if (!buf || len < 0)
14591 -                       goto out;
14592 -               error = 0;
14593 -               if (!len)
14594 -                       goto out;
14595 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
14596 -                       error = -EFAULT;
14597 -                       goto out;
14598 -               }
14599                 error = syslog_print_all(buf, len, clear);
14600                 break;
14601         /* Clear ring buffer */
14602 diff -NurpP --minimal linux-3.10.33/kernel/ptrace.c linux-3.10.33-vs2.3.6.8/kernel/ptrace.c
14603 --- linux-3.10.33/kernel/ptrace.c       2014-03-12 13:16:02.000000000 +0000
14604 +++ linux-3.10.33-vs2.3.6.8/kernel/ptrace.c     2013-11-30 07:53:00.000000000 +0000
14605 @@ -23,6 +23,7 @@
14606  #include <linux/syscalls.h>
14607  #include <linux/uaccess.h>
14608  #include <linux/regset.h>
14609 +#include <linux/vs_context.h>
14610  #include <linux/hw_breakpoint.h>
14611  #include <linux/cn_proc.h>
14612  #include <linux/compat.h>
14613 @@ -264,6 +265,11 @@ ok:
14614         }
14615         rcu_read_unlock();
14616  
14617 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_WATCH_P|VS_IDENT))
14618 +               return -EPERM;
14619 +       if (!vx_check(task->xid, VS_IDENT) &&
14620 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
14621 +               return -EACCES;
14622         return security_ptrace_access_check(task, mode);
14623  }
14624  
14625 diff -NurpP --minimal linux-3.10.33/kernel/sched/core.c linux-3.10.33-vs2.3.6.8/kernel/sched/core.c
14626 --- linux-3.10.33/kernel/sched/core.c   2014-03-12 13:16:02.000000000 +0000
14627 +++ linux-3.10.33-vs2.3.6.8/kernel/sched/core.c 2014-01-22 19:00:34.000000000 +0000
14628 @@ -73,6 +73,8 @@
14629  #include <linux/init_task.h>
14630  #include <linux/binfmts.h>
14631  #include <linux/context_tracking.h>
14632 +#include <linux/vs_sched.h>
14633 +#include <linux/vs_cvirt.h>
14634  
14635  #include <asm/switch_to.h>
14636  #include <asm/tlb.h>
14637 @@ -2145,9 +2147,17 @@ EXPORT_SYMBOL(avenrun); /* should be rem
14638   */
14639  void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
14640  {
14641 -       loads[0] = (avenrun[0] + offset) << shift;
14642 -       loads[1] = (avenrun[1] + offset) << shift;
14643 -       loads[2] = (avenrun[2] + offset) << shift;
14644 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
14645 +               struct vx_info *vxi = current_vx_info();
14646 +
14647 +               loads[0] = (vxi->cvirt.load[0] + offset) << shift;
14648 +               loads[1] = (vxi->cvirt.load[1] + offset) << shift;
14649 +               loads[2] = (vxi->cvirt.load[2] + offset) << shift;
14650 +       } else {
14651 +               loads[0] = (avenrun[0] + offset) << shift;
14652 +               loads[1] = (avenrun[1] + offset) << shift;
14653 +               loads[2] = (avenrun[2] + offset) << shift;
14654 +       }
14655  }
14656  
14657  static long calc_load_fold_active(struct rq *this_rq)
14658 @@ -3750,7 +3760,7 @@ SYSCALL_DEFINE1(nice, int, increment)
14659                 nice = 19;
14660  
14661         if (increment < 0 && !can_nice(current, nice))
14662 -               return -EPERM;
14663 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
14664  
14665         retval = security_task_setnice(current, nice);
14666         if (retval)
14667 diff -NurpP --minimal linux-3.10.33/kernel/sched/cputime.c linux-3.10.33-vs2.3.6.8/kernel/sched/cputime.c
14668 --- linux-3.10.33/kernel/sched/cputime.c        2014-03-12 13:16:02.000000000 +0000
14669 +++ linux-3.10.33-vs2.3.6.8/kernel/sched/cputime.c      2013-11-13 17:17:16.000000000 +0000
14670 @@ -4,6 +4,7 @@
14671  #include <linux/kernel_stat.h>
14672  #include <linux/static_key.h>
14673  #include <linux/context_tracking.h>
14674 +#include <linux/vs_sched.h>
14675  #include "sched.h"
14676  
14677  
14678 @@ -135,14 +136,17 @@ static inline void task_group_account_fi
14679  void account_user_time(struct task_struct *p, cputime_t cputime,
14680                        cputime_t cputime_scaled)
14681  {
14682 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
14683 +       int nice = (TASK_NICE(p) > 0);
14684         int index;
14685  
14686         /* Add user time to process. */
14687         p->utime += cputime;
14688         p->utimescaled += cputime_scaled;
14689 +       vx_account_user(vxi, cputime, nice);
14690         account_group_user_time(p, cputime);
14691  
14692 -       index = (TASK_NICE(p) > 0) ? CPUTIME_NICE : CPUTIME_USER;
14693 +       index = (nice) ? CPUTIME_NICE : CPUTIME_USER;
14694  
14695         /* Add user time to cpustat. */
14696         task_group_account_field(p, index, (__force u64) cputime);
14697 @@ -189,9 +193,12 @@ static inline
14698  void __account_system_time(struct task_struct *p, cputime_t cputime,
14699                         cputime_t cputime_scaled, int index)
14700  {
14701 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
14702 +
14703         /* Add system time to process. */
14704         p->stime += cputime;
14705         p->stimescaled += cputime_scaled;
14706 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
14707         account_group_system_time(p, cputime);
14708  
14709         /* Add system time to cpustat. */
14710 diff -NurpP --minimal linux-3.10.33/kernel/sched/fair.c linux-3.10.33-vs2.3.6.8/kernel/sched/fair.c
14711 --- linux-3.10.33/kernel/sched/fair.c   2014-03-12 13:16:02.000000000 +0000
14712 +++ linux-3.10.33-vs2.3.6.8/kernel/sched/fair.c 2014-01-22 19:00:34.000000000 +0000
14713 @@ -29,6 +29,7 @@
14714  #include <linux/mempolicy.h>
14715  #include <linux/migrate.h>
14716  #include <linux/task_work.h>
14717 +#include <linux/vs_cvirt.h>
14718  
14719  #include <trace/events/sched.h>
14720  
14721 @@ -1743,6 +1744,8 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
14722                 __enqueue_entity(cfs_rq, se);
14723         se->on_rq = 1;
14724  
14725 +       if (entity_is_task(se))
14726 +               vx_activate_task(task_of(se));
14727         if (cfs_rq->nr_running == 1) {
14728                 list_add_leaf_cfs_rq(cfs_rq);
14729                 check_enqueue_throttle(cfs_rq);
14730 @@ -1824,6 +1827,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
14731         if (se != cfs_rq->curr)
14732                 __dequeue_entity(cfs_rq, se);
14733         se->on_rq = 0;
14734 +       if (entity_is_task(se))
14735 +               vx_deactivate_task(task_of(se));
14736         account_entity_dequeue(cfs_rq, se);
14737  
14738         /*
14739 diff -NurpP --minimal linux-3.10.33/kernel/signal.c linux-3.10.33-vs2.3.6.8/kernel/signal.c
14740 --- linux-3.10.33/kernel/signal.c       2013-07-14 17:01:35.000000000 +0000
14741 +++ linux-3.10.33-vs2.3.6.8/kernel/signal.c     2013-08-22 21:13:50.000000000 +0000
14742 @@ -33,6 +33,8 @@
14743  #include <linux/uprobes.h>
14744  #include <linux/compat.h>
14745  #include <linux/cn_proc.h>
14746 +#include <linux/vs_context.h>
14747 +#include <linux/vs_pid.h>
14748  #define CREATE_TRACE_POINTS
14749  #include <trace/events/signal.h>
14750  
14751 @@ -790,9 +792,18 @@ static int check_kill_permission(int sig
14752         struct pid *sid;
14753         int error;
14754  
14755 +       vxdprintk(VXD_CBIT(misc, 7),
14756 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
14757 +               sig, info, t, vx_task_xid(t), t->pid);
14758 +
14759         if (!valid_signal(sig))
14760                 return -EINVAL;
14761  
14762 +/*     FIXME: needed? if so, why?
14763 +       if ((info != SEND_SIG_NOINFO) &&
14764 +               (is_si_special(info) || !si_fromuser(info)))
14765 +               goto skip;      */
14766 +
14767         if (!si_fromuser(info))
14768                 return 0;
14769  
14770 @@ -816,6 +827,20 @@ static int check_kill_permission(int sig
14771                 }
14772         }
14773  
14774 +       error = -EPERM;
14775 +       if (t->pid == 1 && current->xid)
14776 +               return error;
14777 +
14778 +       error = -ESRCH;
14779 +       /* FIXME: we shouldn't return ESRCH ever, to avoid
14780 +                 loops, maybe ENOENT or EACCES? */
14781 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
14782 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
14783 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
14784 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
14785 +               return error;
14786 +       }
14787 +/* skip: */
14788         return security_task_kill(t, info, sig, 0);
14789  }
14790  
14791 @@ -1353,7 +1378,7 @@ int kill_pid_info(int sig, struct siginf
14792         rcu_read_lock();
14793  retry:
14794         p = pid_task(pid, PIDTYPE_PID);
14795 -       if (p) {
14796 +       if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
14797                 error = group_send_sig_info(sig, info, p);
14798                 if (unlikely(error == -ESRCH))
14799                         /*
14800 @@ -1401,7 +1426,7 @@ int kill_pid_info_as_cred(int sig, struc
14801  
14802         rcu_read_lock();
14803         p = pid_task(pid, PIDTYPE_PID);
14804 -       if (!p) {
14805 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
14806                 ret = -ESRCH;
14807                 goto out_unlock;
14808         }
14809 @@ -1453,8 +1478,10 @@ static int kill_something_info(int sig,
14810                 struct task_struct * p;
14811  
14812                 for_each_process(p) {
14813 -                       if (task_pid_vnr(p) > 1 &&
14814 -                                       !same_thread_group(p, current)) {
14815 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
14816 +                               task_pid_vnr(p) > 1 &&
14817 +                               !same_thread_group(p, current) &&
14818 +                               !vx_current_initpid(p->pid)) {
14819                                 int err = group_send_sig_info(sig, info, p);
14820                                 ++count;
14821                                 if (err != -EPERM)
14822 @@ -2308,6 +2335,11 @@ relock:
14823                                 !sig_kernel_only(signr))
14824                         continue;
14825  
14826 +               /* virtual init is protected against user signals */
14827 +               if ((info->si_code == SI_USER) &&
14828 +                       vx_current_initpid(current->pid))
14829 +                       continue;
14830 +
14831                 if (sig_kernel_stop(signr)) {
14832                         /*
14833                          * The default action is to stop all threads in
14834 diff -NurpP --minimal linux-3.10.33/kernel/softirq.c linux-3.10.33-vs2.3.6.8/kernel/softirq.c
14835 --- linux-3.10.33/kernel/softirq.c      2014-03-12 13:16:02.000000000 +0000
14836 +++ linux-3.10.33-vs2.3.6.8/kernel/softirq.c    2013-11-13 17:17:16.000000000 +0000
14837 @@ -25,6 +25,7 @@
14838  #include <linux/smp.h>
14839  #include <linux/smpboot.h>
14840  #include <linux/tick.h>
14841 +#include <linux/vs_context.h>
14842  
14843  #define CREATE_TRACE_POINTS
14844  #include <trace/events/irq.h>
14845 diff -NurpP --minimal linux-3.10.33/kernel/sys.c linux-3.10.33-vs2.3.6.8/kernel/sys.c
14846 --- linux-3.10.33/kernel/sys.c  2013-07-14 17:01:35.000000000 +0000
14847 +++ linux-3.10.33-vs2.3.6.8/kernel/sys.c        2013-08-22 20:30:00.000000000 +0000
14848 @@ -55,6 +55,7 @@
14849  #include <linux/cred.h>
14850  
14851  #include <linux/kmsg_dump.h>
14852 +#include <linux/vs_pid.h>
14853  /* Move somewhere else to avoid recompiling? */
14854  #include <generated/utsrelease.h>
14855  
14856 @@ -160,7 +161,10 @@ static int set_one_prio(struct task_stru
14857                 goto out;
14858         }
14859         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
14860 -               error = -EACCES;
14861 +               if (vx_flags(VXF_IGNEG_NICE, 0))
14862 +                       error = 0;
14863 +               else
14864 +                       error = -EACCES;
14865                 goto out;
14866         }
14867         no_nice = security_task_setnice(p, niceval);
14868 @@ -211,6 +215,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
14869                         else
14870                                 pgrp = task_pgrp(current);
14871                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
14872 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
14873 +                                       continue;
14874                                 error = set_one_prio(p, niceval, error);
14875                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
14876                         break;
14877 @@ -276,6 +282,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
14878                         else
14879                                 pgrp = task_pgrp(current);
14880                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
14881 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
14882 +                                       continue;
14883                                 niceval = 20 - task_nice(p);
14884                                 if (niceval > retval)
14885                                         retval = niceval;
14886 @@ -452,6 +460,8 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
14887  
14888  static DEFINE_MUTEX(reboot_mutex);
14889  
14890 +long vs_reboot(unsigned int, void __user *);
14891 +
14892  /*
14893   * Reboot system call: for obvious reasons only root may call it,
14894   * and even root needs to set up some magic numbers in the registers
14895 @@ -494,6 +504,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
14896         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
14897                 cmd = LINUX_REBOOT_CMD_HALT;
14898  
14899 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
14900 +               return vs_reboot(cmd, arg);
14901 +
14902         mutex_lock(&reboot_mutex);
14903         switch (cmd) {
14904         case LINUX_REBOOT_CMD_RESTART:
14905 @@ -1462,7 +1475,8 @@ SYSCALL_DEFINE2(sethostname, char __user
14906         int errno;
14907         char tmp[__NEW_UTS_LEN];
14908  
14909 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
14910 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
14911 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
14912                 return -EPERM;
14913  
14914         if (len < 0 || len > __NEW_UTS_LEN)
14915 @@ -1513,7 +1527,8 @@ SYSCALL_DEFINE2(setdomainname, char __us
14916         int errno;
14917         char tmp[__NEW_UTS_LEN];
14918  
14919 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
14920 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
14921 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
14922                 return -EPERM;
14923         if (len < 0 || len > __NEW_UTS_LEN)
14924                 return -EINVAL;
14925 @@ -1632,7 +1647,7 @@ int do_prlimit(struct task_struct *tsk,
14926                 /* Keep the capable check against init_user_ns until
14927                    cgroups can contain all limits */
14928                 if (new_rlim->rlim_max > rlim->rlim_max &&
14929 -                               !capable(CAP_SYS_RESOURCE))
14930 +                       !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
14931                         retval = -EPERM;
14932                 if (!retval)
14933                         retval = security_task_setrlimit(tsk->group_leader,
14934 @@ -1685,7 +1700,8 @@ static int check_prlimit_permission(stru
14935             gid_eq(cred->gid, tcred->sgid) &&
14936             gid_eq(cred->gid, tcred->gid))
14937                 return 0;
14938 -       if (ns_capable(tcred->user_ns, CAP_SYS_RESOURCE))
14939 +       if (vx_ns_capable(tcred->user_ns,
14940 +               CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
14941                 return 0;
14942  
14943         return -EPERM;
14944 diff -NurpP --minimal linux-3.10.33/kernel/sysctl.c linux-3.10.33-vs2.3.6.8/kernel/sysctl.c
14945 --- linux-3.10.33/kernel/sysctl.c       2013-07-14 17:01:35.000000000 +0000
14946 +++ linux-3.10.33-vs2.3.6.8/kernel/sysctl.c     2013-08-22 20:30:00.000000000 +0000
14947 @@ -83,6 +83,7 @@
14948  #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
14949  #include <linux/lockdep.h>
14950  #endif
14951 +extern char vshelper_path[];
14952  #ifdef CONFIG_CHR_DEV_SG
14953  #include <scsi/sg.h>
14954  #endif
14955 @@ -628,6 +629,13 @@ static struct ctl_table kern_table[] = {
14956                 .mode           = 0644,
14957                 .proc_handler   = proc_dostring,
14958         },
14959 +       {
14960 +               .procname       = "vshelper",
14961 +               .data           = &vshelper_path,
14962 +               .maxlen         = 256,
14963 +               .mode           = 0644,
14964 +               .proc_handler   = &proc_dostring,
14965 +       },
14966  
14967  #ifdef CONFIG_CHR_DEV_SG
14968         {
14969 diff -NurpP --minimal linux-3.10.33/kernel/sysctl_binary.c linux-3.10.33-vs2.3.6.8/kernel/sysctl_binary.c
14970 --- linux-3.10.33/kernel/sysctl_binary.c        2013-07-14 17:01:35.000000000 +0000
14971 +++ linux-3.10.33-vs2.3.6.8/kernel/sysctl_binary.c      2013-08-22 20:30:00.000000000 +0000
14972 @@ -74,6 +74,7 @@ static const struct bin_table bin_kern_t
14973  
14974         { CTL_INT,      KERN_PANIC,                     "panic" },
14975         { CTL_INT,      KERN_REALROOTDEV,               "real-root-dev" },
14976 +       { CTL_STR,      KERN_VSHELPER,                  "vshelper" },
14977  
14978         { CTL_STR,      KERN_SPARC_REBOOT,              "reboot-cmd" },
14979         { CTL_INT,      KERN_CTLALTDEL,                 "ctrl-alt-del" },
14980 diff -NurpP --minimal linux-3.10.33/kernel/time/timekeeping.c linux-3.10.33-vs2.3.6.8/kernel/time/timekeeping.c
14981 --- linux-3.10.33/kernel/time/timekeeping.c     2014-03-12 13:16:02.000000000 +0000
14982 +++ linux-3.10.33-vs2.3.6.8/kernel/time/timekeeping.c   2014-03-12 13:18:23.000000000 +0000
14983 @@ -22,6 +22,7 @@
14984  #include <linux/tick.h>
14985  #include <linux/stop_machine.h>
14986  #include <linux/pvclock_gtod.h>
14987 +#include <linux/vs_time.h>
14988  
14989  #include "tick-internal.h"
14990  #include "ntp_internal.h"
14991 @@ -694,6 +695,7 @@ void getrawmonotonic(struct timespec *ts
14992         } while (read_seqcount_retry(&timekeeper_seq, seq));
14993  
14994         timespec_add_ns(ts, nsecs);
14995 +       vx_adjust_timespec(ts);
14996  }
14997  EXPORT_SYMBOL(getrawmonotonic);
14998  
14999 diff -NurpP --minimal linux-3.10.33/kernel/time.c linux-3.10.33-vs2.3.6.8/kernel/time.c
15000 --- linux-3.10.33/kernel/time.c 2013-07-14 17:01:35.000000000 +0000
15001 +++ linux-3.10.33-vs2.3.6.8/kernel/time.c       2013-08-22 20:30:00.000000000 +0000
15002 @@ -37,6 +37,7 @@
15003  #include <linux/fs.h>
15004  #include <linux/math64.h>
15005  #include <linux/ptrace.h>
15006 +#include <linux/vs_time.h>
15007  
15008  #include <asm/uaccess.h>
15009  #include <asm/unistd.h>
15010 @@ -92,7 +93,7 @@ SYSCALL_DEFINE1(stime, time_t __user *,
15011         if (err)
15012                 return err;
15013  
15014 -       do_settimeofday(&tv);
15015 +       vx_settimeofday(&tv);
15016         return 0;
15017  }
15018  
15019 @@ -181,7 +182,7 @@ int do_sys_settimeofday(const struct tim
15020                 }
15021         }
15022         if (tv)
15023 -               return do_settimeofday(tv);
15024 +               return vx_settimeofday(tv);
15025         return 0;
15026  }
15027  
15028 diff -NurpP --minimal linux-3.10.33/kernel/timer.c linux-3.10.33-vs2.3.6.8/kernel/timer.c
15029 --- linux-3.10.33/kernel/timer.c        2014-03-12 13:16:02.000000000 +0000
15030 +++ linux-3.10.33-vs2.3.6.8/kernel/timer.c      2013-11-13 17:17:16.000000000 +0000
15031 @@ -42,6 +42,10 @@
15032  #include <linux/sched/sysctl.h>
15033  #include <linux/slab.h>
15034  #include <linux/compat.h>
15035 +#include <linux/vs_base.h>
15036 +#include <linux/vs_cvirt.h>
15037 +#include <linux/vs_pid.h>
15038 +#include <linux/vserver/sched.h>
15039  
15040  #include <asm/uaccess.h>
15041  #include <asm/unistd.h>
15042 diff -NurpP --minimal linux-3.10.33/kernel/user_namespace.c linux-3.10.33-vs2.3.6.8/kernel/user_namespace.c
15043 --- linux-3.10.33/kernel/user_namespace.c       2014-03-12 13:16:02.000000000 +0000
15044 +++ linux-3.10.33-vs2.3.6.8/kernel/user_namespace.c     2013-11-13 17:17:16.000000000 +0000
15045 @@ -22,6 +22,7 @@
15046  #include <linux/ctype.h>
15047  #include <linux/projid.h>
15048  #include <linux/fs_struct.h>
15049 +#include <linux/vserver/global.h>
15050  
15051  static struct kmem_cache *user_ns_cachep __read_mostly;
15052  
15053 @@ -94,6 +95,7 @@ int create_user_ns(struct cred *new)
15054  
15055         atomic_set(&ns->count, 1);
15056         /* Leave the new->user_ns reference with the new user namespace. */
15057 +       atomic_inc(&vs_global_user_ns);
15058         ns->parent = parent_ns;
15059         ns->level = parent_ns->level + 1;
15060         ns->owner = owner;
15061 @@ -844,6 +846,8 @@ static void *userns_get(struct task_stru
15062  
15063  static void userns_put(void *ns)
15064  {
15065 +       /* FIXME: maybe move into destroyer? */
15066 +       atomic_dec(&vs_global_user_ns);
15067         put_user_ns(ns);
15068  }
15069  
15070 diff -NurpP --minimal linux-3.10.33/kernel/utsname.c linux-3.10.33-vs2.3.6.8/kernel/utsname.c
15071 --- linux-3.10.33/kernel/utsname.c      2013-07-14 17:01:35.000000000 +0000
15072 +++ linux-3.10.33-vs2.3.6.8/kernel/utsname.c    2013-08-22 21:03:08.000000000 +0000
15073 @@ -16,14 +16,17 @@
15074  #include <linux/slab.h>
15075  #include <linux/user_namespace.h>
15076  #include <linux/proc_ns.h>
15077 +#include <linux/vserver/global.h>
15078  
15079  static struct uts_namespace *create_uts_ns(void)
15080  {
15081         struct uts_namespace *uts_ns;
15082  
15083         uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
15084 -       if (uts_ns)
15085 -               kref_init(&uts_ns->kref);
15086 +       if (uts_ns) {
15087 +               kref_init(&uts_ns->kref);
15088 +               atomic_inc(&vs_global_uts_ns);
15089 +       }
15090         return uts_ns;
15091  }
15092  
15093 @@ -85,6 +88,7 @@ void free_uts_ns(struct kref *kref)
15094         ns = container_of(kref, struct uts_namespace, kref);
15095         put_user_ns(ns->user_ns);
15096         proc_free_inum(ns->proc_inum);
15097 +       atomic_dec(&vs_global_uts_ns);
15098         kfree(ns);
15099  }
15100  
15101 diff -NurpP --minimal linux-3.10.33/kernel/vserver/Kconfig linux-3.10.33-vs2.3.6.8/kernel/vserver/Kconfig
15102 --- linux-3.10.33/kernel/vserver/Kconfig        1970-01-01 00:00:00.000000000 +0000
15103 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/Kconfig      2013-11-14 04:29:47.000000000 +0000
15104 @@ -0,0 +1,230 @@
15105 +#
15106 +# Linux VServer configuration
15107 +#
15108 +
15109 +menu "Linux VServer"
15110 +
15111 +config VSERVER_AUTO_LBACK
15112 +       bool    "Automatically Assign Loopback IP"
15113 +       default y
15114 +       help
15115 +         Automatically assign a guest specific loopback
15116 +         IP and add it to the kernel network stack on
15117 +         startup.
15118 +
15119 +config VSERVER_AUTO_SINGLE
15120 +       bool    "Automatic Single IP Special Casing"
15121 +       default n
15122 +       help
15123 +         This allows network contexts with a single IP to
15124 +         automatically remap 0.0.0.0 bindings to that IP,
15125 +         avoiding further network checks and improving
15126 +         performance.
15127 +
15128 +         (note: such guests do not allow to change the ip
15129 +          on the fly and do not show loopback addresses)
15130 +
15131 +config VSERVER_COWBL
15132 +       bool    "Enable COW Immutable Link Breaking"
15133 +       default y
15134 +       help
15135 +         This enables the COW (Copy-On-Write) link break code.
15136 +         It allows you to treat unified files like normal files
15137 +         when writing to them (which will implicitely break the
15138 +         link and create a copy of the unified file)
15139 +
15140 +config VSERVER_VTIME
15141 +       bool    "Enable Virtualized Guest Time (EXPERIMENTAL)"
15142 +       default n
15143 +       help
15144 +         This enables per guest time offsets to allow for
15145 +         adjusting the system clock individually per guest.
15146 +         this adds some overhead to the time functions and
15147 +         therefore should not be enabled without good reason.
15148 +
15149 +config VSERVER_DEVICE
15150 +       bool    "Enable Guest Device Mapping (EXPERIMENTAL)"
15151 +       default n
15152 +       help
15153 +         This enables generic device remapping.
15154 +
15155 +config VSERVER_PROC_SECURE
15156 +       bool    "Enable Proc Security"
15157 +       depends on PROC_FS
15158 +       default y
15159 +       help
15160 +         This configures ProcFS security to initially hide
15161 +         non-process entries for all contexts except the main and
15162 +         spectator context (i.e. for all guests), which is a secure
15163 +         default.
15164 +
15165 +         (note: on 1.2x the entries were visible by default)
15166 +
15167 +choice
15168 +       prompt  "Persistent Inode Tagging"
15169 +       default TAGGING_ID24
15170 +       help
15171 +         This adds persistent context information to filesystems
15172 +         mounted with the tagxid option. Tagging is a requirement
15173 +         for per-context disk limits and per-context quota.
15174 +
15175 +
15176 +config TAGGING_NONE
15177 +       bool    "Disabled"
15178 +       help
15179 +         do not store per-context information in inodes.
15180 +
15181 +config TAGGING_UID16
15182 +       bool    "UID16/GID32"
15183 +       help
15184 +         reduces UID to 16 bit, but leaves GID at 32 bit.
15185 +
15186 +config TAGGING_GID16
15187 +       bool    "UID32/GID16"
15188 +       help
15189 +         reduces GID to 16 bit, but leaves UID at 32 bit.
15190 +
15191 +config TAGGING_ID24
15192 +       bool    "UID24/GID24"
15193 +       help
15194 +         uses the upper 8bit from UID and GID for XID tagging
15195 +         which leaves 24bit for UID/GID each, which should be
15196 +         more than sufficient for normal use.
15197 +
15198 +config TAGGING_INTERN
15199 +       bool    "UID32/GID32"
15200 +       help
15201 +         this uses otherwise reserved inode fields in the on
15202 +         disk representation, which limits the use to a few
15203 +         filesystems (currently ext2 and ext3)
15204 +
15205 +endchoice
15206 +
15207 +config TAG_NFSD
15208 +       bool    "Tag NFSD User Auth and Files"
15209 +       default n
15210 +       help
15211 +         Enable this if you do want the in-kernel NFS
15212 +         Server to use the tagging specified above.
15213 +         (will require patched clients too)
15214 +
15215 +config VSERVER_PRIVACY
15216 +       bool    "Honor Privacy Aspects of Guests"
15217 +       default n
15218 +       help
15219 +         When enabled, most context checks will disallow
15220 +         access to structures assigned to a specific context,
15221 +         like ptys or loop devices.
15222 +
15223 +config VSERVER_CONTEXTS
15224 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
15225 +       range 1 65533
15226 +       default "768"   if 64BIT
15227 +       default "256"
15228 +       help
15229 +         This setting will optimize certain data structures
15230 +         and memory allocations according to the expected
15231 +         maximum.
15232 +
15233 +         note: this is not a strict upper limit.
15234 +
15235 +config VSERVER_WARN
15236 +       bool    "VServer Warnings"
15237 +       default y
15238 +       help
15239 +         This enables various runtime warnings, which will
15240 +         notify about potential manipulation attempts or
15241 +         resource shortage. It is generally considered to
15242 +         be a good idea to have that enabled.
15243 +
15244 +config VSERVER_WARN_DEVPTS
15245 +       bool    "VServer DevPTS Warnings"
15246 +       depends on VSERVER_WARN
15247 +       default y
15248 +       help
15249 +         This enables DevPTS related warnings, issued when a
15250 +         process inside a context tries to lookup or access
15251 +         a dynamic pts from the host or a different context.
15252 +
15253 +config VSERVER_DEBUG
15254 +       bool    "VServer Debugging Code"
15255 +       default n
15256 +       help
15257 +         Set this to yes if you want to be able to activate
15258 +         debugging output at runtime. It adds a very small
15259 +         overhead to all vserver related functions and
15260 +         increases the kernel size by about 20k.
15261 +
15262 +config VSERVER_HISTORY
15263 +       bool    "VServer History Tracing"
15264 +       depends on VSERVER_DEBUG
15265 +       default n
15266 +       help
15267 +         Set this to yes if you want to record the history of
15268 +         linux-vserver activities, so they can be replayed in
15269 +         the event of a kernel panic or oops.
15270 +
15271 +config VSERVER_HISTORY_SIZE
15272 +       int     "Per-CPU History Size (32-65536)"
15273 +       depends on VSERVER_HISTORY
15274 +       range 32 65536
15275 +       default 64
15276 +       help
15277 +         This allows you to specify the number of entries in
15278 +         the per-CPU history buffer.
15279 +
15280 +config VSERVER_EXTRA_MNT_CHECK
15281 +       bool    "Extra Checks for Reachability"
15282 +       default n
15283 +       help
15284 +         Set this to yes if you want to do extra checks for
15285 +         vfsmount reachability in the proc filesystem code.
15286 +         This shouldn't be required on any setup utilizing
15287 +         mnt namespaces.
15288 +
15289 +choice
15290 +       prompt  "Quotes used in debug and warn messages"
15291 +       default QUOTES_ISO8859
15292 +
15293 +config QUOTES_ISO8859
15294 +       bool    "Extended ASCII (ISO 8859) angle quotes"
15295 +       help
15296 +         This uses the extended ASCII characters \xbb
15297 +         and \xab for quoting file and process names.
15298 +
15299 +config QUOTES_UTF8
15300 +       bool    "UTF-8 angle quotes"
15301 +       help
15302 +         This uses the the UTF-8 sequences for angle
15303 +         quotes to quote file and process names.
15304 +
15305 +config QUOTES_ASCII
15306 +       bool    "ASCII single quotes"
15307 +       help
15308 +         This uses the ASCII single quote character
15309 +         (\x27) to quote file and process names.
15310 +
15311 +endchoice
15312 +
15313 +endmenu
15314 +
15315 +
15316 +config VSERVER
15317 +       bool
15318 +       default y
15319 +       select NAMESPACES
15320 +       select UTS_NS
15321 +       select IPC_NS
15322 +#      select USER_NS
15323 +       select SYSVIPC
15324 +
15325 +config VSERVER_SECURITY
15326 +       bool
15327 +       depends on SECURITY
15328 +       default y
15329 +       select SECURITY_CAPABILITIES
15330 +
15331 +config VSERVER_DISABLED
15332 +       bool
15333 +       default n
15334 +
15335 diff -NurpP --minimal linux-3.10.33/kernel/vserver/Makefile linux-3.10.33-vs2.3.6.8/kernel/vserver/Makefile
15336 --- linux-3.10.33/kernel/vserver/Makefile       1970-01-01 00:00:00.000000000 +0000
15337 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/Makefile     2013-08-22 20:30:00.000000000 +0000
15338 @@ -0,0 +1,18 @@
15339 +#
15340 +# Makefile for the Linux vserver routines.
15341 +#
15342 +
15343 +
15344 +obj-y          += vserver.o
15345 +
15346 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
15347 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
15348 +                  dlimit.o tag.o
15349 +
15350 +vserver-$(CONFIG_INET) += inet.o
15351 +vserver-$(CONFIG_PROC_FS) += proc.o
15352 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
15353 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
15354 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
15355 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
15356 +
15357 diff -NurpP --minimal linux-3.10.33/kernel/vserver/cacct.c linux-3.10.33-vs2.3.6.8/kernel/vserver/cacct.c
15358 --- linux-3.10.33/kernel/vserver/cacct.c        1970-01-01 00:00:00.000000000 +0000
15359 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/cacct.c      2013-08-22 20:30:00.000000000 +0000
15360 @@ -0,0 +1,42 @@
15361 +/*
15362 + *  linux/kernel/vserver/cacct.c
15363 + *
15364 + *  Virtual Server: Context Accounting
15365 + *
15366 + *  Copyright (C) 2006-2007 Herbert Pötzl
15367 + *
15368 + *  V0.01  added accounting stats
15369 + *
15370 + */
15371 +
15372 +#include <linux/types.h>
15373 +#include <linux/vs_context.h>
15374 +#include <linux/vserver/cacct_cmd.h>
15375 +#include <linux/vserver/cacct_int.h>
15376 +
15377 +#include <asm/errno.h>
15378 +#include <asm/uaccess.h>
15379 +
15380 +
15381 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
15382 +{
15383 +       struct vcmd_sock_stat_v0 vc_data;
15384 +       int j, field;
15385 +
15386 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15387 +               return -EFAULT;
15388 +
15389 +       field = vc_data.field;
15390 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
15391 +               return -EINVAL;
15392 +
15393 +       for (j = 0; j < 3; j++) {
15394 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
15395 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
15396 +       }
15397 +
15398 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15399 +               return -EFAULT;
15400 +       return 0;
15401 +}
15402 +
15403 diff -NurpP --minimal linux-3.10.33/kernel/vserver/cacct_init.h linux-3.10.33-vs2.3.6.8/kernel/vserver/cacct_init.h
15404 --- linux-3.10.33/kernel/vserver/cacct_init.h   1970-01-01 00:00:00.000000000 +0000
15405 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/cacct_init.h 2013-08-22 20:30:00.000000000 +0000
15406 @@ -0,0 +1,25 @@
15407 +
15408 +
15409 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
15410 +{
15411 +       int i, j;
15412 +
15413 +
15414 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
15415 +               for (j = 0; j < 3; j++) {
15416 +                       atomic_long_set(&cacct->sock[i][j].count, 0);
15417 +                       atomic_long_set(&cacct->sock[i][j].total, 0);
15418 +               }
15419 +       }
15420 +       for (i = 0; i < 8; i++)
15421 +               atomic_set(&cacct->slab[i], 0);
15422 +       for (i = 0; i < 5; i++)
15423 +               for (j = 0; j < 4; j++)
15424 +                       atomic_set(&cacct->page[i][j], 0);
15425 +}
15426 +
15427 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
15428 +{
15429 +       return;
15430 +}
15431 +
15432 diff -NurpP --minimal linux-3.10.33/kernel/vserver/cacct_proc.h linux-3.10.33-vs2.3.6.8/kernel/vserver/cacct_proc.h
15433 --- linux-3.10.33/kernel/vserver/cacct_proc.h   1970-01-01 00:00:00.000000000 +0000
15434 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/cacct_proc.h 2013-08-22 20:30:00.000000000 +0000
15435 @@ -0,0 +1,53 @@
15436 +#ifndef _VX_CACCT_PROC_H
15437 +#define _VX_CACCT_PROC_H
15438 +
15439 +#include <linux/vserver/cacct_int.h>
15440 +
15441 +
15442 +#define VX_SOCKA_TOP   \
15443 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
15444 +
15445 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
15446 +{
15447 +       int i, j, length = 0;
15448 +       static char *type[VXA_SOCK_SIZE] = {
15449 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
15450 +       };
15451 +
15452 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
15453 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
15454 +               length += sprintf(buffer + length, "%s:", type[i]);
15455 +               for (j = 0; j < 3; j++) {
15456 +                       length += sprintf(buffer + length,
15457 +                               "\t%10lu/%-10lu",
15458 +                               vx_sock_count(cacct, i, j),
15459 +                               vx_sock_total(cacct, i, j));
15460 +               }
15461 +               buffer[length++] = '\n';
15462 +       }
15463 +
15464 +       length += sprintf(buffer + length, "\n");
15465 +       length += sprintf(buffer + length,
15466 +               "slab:\t %8u %8u %8u %8u\n",
15467 +               atomic_read(&cacct->slab[1]),
15468 +               atomic_read(&cacct->slab[4]),
15469 +               atomic_read(&cacct->slab[0]),
15470 +               atomic_read(&cacct->slab[2]));
15471 +
15472 +       length += sprintf(buffer + length, "\n");
15473 +       for (i = 0; i < 5; i++) {
15474 +               length += sprintf(buffer + length,
15475 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
15476 +                       atomic_read(&cacct->page[i][0]),
15477 +                       atomic_read(&cacct->page[i][1]),
15478 +                       atomic_read(&cacct->page[i][2]),
15479 +                       atomic_read(&cacct->page[i][3]),
15480 +                       atomic_read(&cacct->page[i][4]),
15481 +                       atomic_read(&cacct->page[i][5]),
15482 +                       atomic_read(&cacct->page[i][6]),
15483 +                       atomic_read(&cacct->page[i][7]));
15484 +       }
15485 +       return length;
15486 +}
15487 +
15488 +#endif /* _VX_CACCT_PROC_H */
15489 diff -NurpP --minimal linux-3.10.33/kernel/vserver/context.c linux-3.10.33-vs2.3.6.8/kernel/vserver/context.c
15490 --- linux-3.10.33/kernel/vserver/context.c      1970-01-01 00:00:00.000000000 +0000
15491 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/context.c    2013-08-22 20:30:00.000000000 +0000
15492 @@ -0,0 +1,1119 @@
15493 +/*
15494 + *  linux/kernel/vserver/context.c
15495 + *
15496 + *  Virtual Server: Context Support
15497 + *
15498 + *  Copyright (C) 2003-2011  Herbert Pötzl
15499 + *
15500 + *  V0.01  context helper
15501 + *  V0.02  vx_ctx_kill syscall command
15502 + *  V0.03  replaced context_info calls
15503 + *  V0.04  redesign of struct (de)alloc
15504 + *  V0.05  rlimit basic implementation
15505 + *  V0.06  task_xid and info commands
15506 + *  V0.07  context flags and caps
15507 + *  V0.08  switch to RCU based hash
15508 + *  V0.09  revert to non RCU for now
15509 + *  V0.10  and back to working RCU hash
15510 + *  V0.11  and back to locking again
15511 + *  V0.12  referenced context store
15512 + *  V0.13  separate per cpu data
15513 + *  V0.14  changed vcmds to vxi arg
15514 + *  V0.15  added context stat
15515 + *  V0.16  have __create claim() the vxi
15516 + *  V0.17  removed older and legacy stuff
15517 + *  V0.18  added user credentials
15518 + *  V0.19  added warn mask
15519 + *
15520 + */
15521 +
15522 +#include <linux/slab.h>
15523 +#include <linux/types.h>
15524 +#include <linux/security.h>
15525 +#include <linux/pid_namespace.h>
15526 +#include <linux/capability.h>
15527 +
15528 +#include <linux/vserver/context.h>
15529 +#include <linux/vserver/network.h>
15530 +#include <linux/vserver/debug.h>
15531 +#include <linux/vserver/limit.h>
15532 +#include <linux/vserver/limit_int.h>
15533 +#include <linux/vserver/space.h>
15534 +#include <linux/init_task.h>
15535 +#include <linux/fs_struct.h>
15536 +#include <linux/cred.h>
15537 +
15538 +#include <linux/vs_context.h>
15539 +#include <linux/vs_limit.h>
15540 +#include <linux/vs_pid.h>
15541 +#include <linux/vserver/context_cmd.h>
15542 +
15543 +#include "cvirt_init.h"
15544 +#include "cacct_init.h"
15545 +#include "limit_init.h"
15546 +#include "sched_init.h"
15547 +
15548 +
15549 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
15550 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
15551 +
15552 +
15553 +/*     now inactive context structures */
15554 +
15555 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
15556 +
15557 +static DEFINE_SPINLOCK(vx_info_inactive_lock);
15558 +
15559 +
15560 +/*     __alloc_vx_info()
15561 +
15562 +       * allocate an initialized vx_info struct
15563 +       * doesn't make it visible (hash)                        */
15564 +
15565 +static struct vx_info *__alloc_vx_info(vxid_t xid)
15566 +{
15567 +       struct vx_info *new = NULL;
15568 +       int cpu, index;
15569 +
15570 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
15571 +
15572 +       /* would this benefit from a slab cache? */
15573 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
15574 +       if (!new)
15575 +               return 0;
15576 +
15577 +       memset(new, 0, sizeof(struct vx_info));
15578 +#ifdef CONFIG_SMP
15579 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
15580 +       if (!new->ptr_pc)
15581 +               goto error;
15582 +#endif
15583 +       new->vx_id = xid;
15584 +       INIT_HLIST_NODE(&new->vx_hlist);
15585 +       atomic_set(&new->vx_usecnt, 0);
15586 +       atomic_set(&new->vx_tasks, 0);
15587 +       new->vx_parent = NULL;
15588 +       new->vx_state = 0;
15589 +       init_waitqueue_head(&new->vx_wait);
15590 +
15591 +       /* prepare reaper */
15592 +       get_task_struct(init_pid_ns.child_reaper);
15593 +       new->vx_reaper = init_pid_ns.child_reaper;
15594 +       new->vx_badness_bias = 0;
15595 +
15596 +       /* rest of init goes here */
15597 +       vx_info_init_limit(&new->limit);
15598 +       vx_info_init_sched(&new->sched);
15599 +       vx_info_init_cvirt(&new->cvirt);
15600 +       vx_info_init_cacct(&new->cacct);
15601 +
15602 +       /* per cpu data structures */
15603 +       for_each_possible_cpu(cpu) {
15604 +               vx_info_init_sched_pc(
15605 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
15606 +               vx_info_init_cvirt_pc(
15607 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
15608 +       }
15609 +
15610 +       new->vx_flags = VXF_INIT_SET;
15611 +       new->vx_bcaps = CAP_FULL_SET;   // maybe ~CAP_SETPCAP
15612 +       new->vx_ccaps = 0;
15613 +       new->vx_umask = 0;
15614 +       new->vx_wmask = 0;
15615 +
15616 +       new->reboot_cmd = 0;
15617 +       new->exit_code = 0;
15618 +
15619 +       // preconfig spaces
15620 +       for (index = 0; index < VX_SPACES; index++) {
15621 +               struct _vx_space *space = &new->space[index];
15622 +
15623 +               // filesystem
15624 +               spin_lock(&init_fs.lock);
15625 +               init_fs.users++;
15626 +               spin_unlock(&init_fs.lock);
15627 +               space->vx_fs = &init_fs;
15628 +
15629 +               /* FIXME: do we want defaults? */
15630 +               // space->vx_real_cred = 0;
15631 +               // space->vx_cred = 0;
15632 +       }
15633 +
15634 +
15635 +       vxdprintk(VXD_CBIT(xid, 0),
15636 +               "alloc_vx_info(%d) = %p", xid, new);
15637 +       vxh_alloc_vx_info(new);
15638 +       atomic_inc(&vx_global_ctotal);
15639 +       return new;
15640 +#ifdef CONFIG_SMP
15641 +error:
15642 +       kfree(new);
15643 +       return 0;
15644 +#endif
15645 +}
15646 +
15647 +/*     __dealloc_vx_info()
15648 +
15649 +       * final disposal of vx_info                             */
15650 +
15651 +static void __dealloc_vx_info(struct vx_info *vxi)
15652 +{
15653 +#ifdef CONFIG_VSERVER_WARN
15654 +       struct vx_info_save vxis;
15655 +       int cpu;
15656 +#endif
15657 +       vxdprintk(VXD_CBIT(xid, 0),
15658 +               "dealloc_vx_info(%p)", vxi);
15659 +       vxh_dealloc_vx_info(vxi);
15660 +
15661 +#ifdef CONFIG_VSERVER_WARN
15662 +       enter_vx_info(vxi, &vxis);
15663 +       vx_info_exit_limit(&vxi->limit);
15664 +       vx_info_exit_sched(&vxi->sched);
15665 +       vx_info_exit_cvirt(&vxi->cvirt);
15666 +       vx_info_exit_cacct(&vxi->cacct);
15667 +
15668 +       for_each_possible_cpu(cpu) {
15669 +               vx_info_exit_sched_pc(
15670 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
15671 +               vx_info_exit_cvirt_pc(
15672 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
15673 +       }
15674 +       leave_vx_info(&vxis);
15675 +#endif
15676 +
15677 +       vxi->vx_id = -1;
15678 +       vxi->vx_state |= VXS_RELEASED;
15679 +
15680 +#ifdef CONFIG_SMP
15681 +       free_percpu(vxi->ptr_pc);
15682 +#endif
15683 +       kfree(vxi);
15684 +       atomic_dec(&vx_global_ctotal);
15685 +}
15686 +
15687 +static void __shutdown_vx_info(struct vx_info *vxi)
15688 +{
15689 +       struct nsproxy *nsproxy;
15690 +       struct fs_struct *fs;
15691 +       struct cred *cred;
15692 +       int index, kill;
15693 +
15694 +       might_sleep();
15695 +
15696 +       vxi->vx_state |= VXS_SHUTDOWN;
15697 +       vs_state_change(vxi, VSC_SHUTDOWN);
15698 +
15699 +       for (index = 0; index < VX_SPACES; index++) {
15700 +               struct _vx_space *space = &vxi->space[index];
15701 +
15702 +               nsproxy = xchg(&space->vx_nsproxy, NULL);
15703 +               if (nsproxy)
15704 +                       put_nsproxy(nsproxy);
15705 +
15706 +               fs = xchg(&space->vx_fs, NULL);
15707 +               spin_lock(&fs->lock);
15708 +               kill = !--fs->users;
15709 +               spin_unlock(&fs->lock);
15710 +               if (kill)
15711 +                       free_fs_struct(fs);
15712 +
15713 +               cred = (struct cred *)xchg(&space->vx_cred, NULL);
15714 +               if (cred)
15715 +                       abort_creds(cred);
15716 +       }
15717 +}
15718 +
15719 +/* exported stuff */
15720 +
15721 +void free_vx_info(struct vx_info *vxi)
15722 +{
15723 +       unsigned long flags;
15724 +       unsigned index;
15725 +
15726 +       /* check for reference counts first */
15727 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
15728 +       BUG_ON(atomic_read(&vxi->vx_tasks));
15729 +
15730 +       /* context must not be hashed */
15731 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
15732 +
15733 +       /* context shutdown is mandatory */
15734 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
15735 +
15736 +       /* spaces check */
15737 +       for (index = 0; index < VX_SPACES; index++) {
15738 +               struct _vx_space *space = &vxi->space[index];
15739 +
15740 +               BUG_ON(space->vx_nsproxy);
15741 +               BUG_ON(space->vx_fs);
15742 +               // BUG_ON(space->vx_real_cred);
15743 +               // BUG_ON(space->vx_cred);
15744 +       }
15745 +
15746 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
15747 +       hlist_del(&vxi->vx_hlist);
15748 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
15749 +
15750 +       __dealloc_vx_info(vxi);
15751 +}
15752 +
15753 +
15754 +/*     hash table for vx_info hash */
15755 +
15756 +#define VX_HASH_SIZE   13
15757 +
15758 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
15759 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
15760 +
15761 +static DEFINE_SPINLOCK(vx_info_hash_lock);
15762 +
15763 +
15764 +static inline unsigned int __hashval(vxid_t xid)
15765 +{
15766 +       return (xid % VX_HASH_SIZE);
15767 +}
15768 +
15769 +
15770 +
15771 +/*     __hash_vx_info()
15772 +
15773 +       * add the vxi to the global hash table
15774 +       * requires the hash_lock to be held                     */
15775 +
15776 +static inline void __hash_vx_info(struct vx_info *vxi)
15777 +{
15778 +       struct hlist_head *head;
15779 +
15780 +       vxd_assert_lock(&vx_info_hash_lock);
15781 +       vxdprintk(VXD_CBIT(xid, 4),
15782 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
15783 +       vxh_hash_vx_info(vxi);
15784 +
15785 +       /* context must not be hashed */
15786 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
15787 +
15788 +       vxi->vx_state |= VXS_HASHED;
15789 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
15790 +       hlist_add_head(&vxi->vx_hlist, head);
15791 +       atomic_inc(&vx_global_cactive);
15792 +}
15793 +
15794 +/*     __unhash_vx_info()
15795 +
15796 +       * remove the vxi from the global hash table
15797 +       * requires the hash_lock to be held                     */
15798 +
15799 +static inline void __unhash_vx_info(struct vx_info *vxi)
15800 +{
15801 +       unsigned long flags;
15802 +
15803 +       vxd_assert_lock(&vx_info_hash_lock);
15804 +       vxdprintk(VXD_CBIT(xid, 4),
15805 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
15806 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
15807 +       vxh_unhash_vx_info(vxi);
15808 +
15809 +       /* context must be hashed */
15810 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
15811 +       /* but without tasks */
15812 +       BUG_ON(atomic_read(&vxi->vx_tasks));
15813 +
15814 +       vxi->vx_state &= ~VXS_HASHED;
15815 +       hlist_del_init(&vxi->vx_hlist);
15816 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
15817 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
15818 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
15819 +       atomic_dec(&vx_global_cactive);
15820 +}
15821 +
15822 +
15823 +/*     __lookup_vx_info()
15824 +
15825 +       * requires the hash_lock to be held
15826 +       * doesn't increment the vx_refcnt                       */
15827 +
15828 +static inline struct vx_info *__lookup_vx_info(vxid_t xid)
15829 +{
15830 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
15831 +       struct hlist_node *pos;
15832 +       struct vx_info *vxi;
15833 +
15834 +       vxd_assert_lock(&vx_info_hash_lock);
15835 +       hlist_for_each(pos, head) {
15836 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
15837 +
15838 +               if (vxi->vx_id == xid)
15839 +                       goto found;
15840 +       }
15841 +       vxi = NULL;
15842 +found:
15843 +       vxdprintk(VXD_CBIT(xid, 0),
15844 +               "__lookup_vx_info(#%u): %p[#%u]",
15845 +               xid, vxi, vxi ? vxi->vx_id : 0);
15846 +       vxh_lookup_vx_info(vxi, xid);
15847 +       return vxi;
15848 +}
15849 +
15850 +
15851 +/*     __create_vx_info()
15852 +
15853 +       * create the requested context
15854 +       * get(), claim() and hash it                            */
15855 +
15856 +static struct vx_info *__create_vx_info(int id)
15857 +{
15858 +       struct vx_info *new, *vxi = NULL;
15859 +
15860 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
15861 +
15862 +       if (!(new = __alloc_vx_info(id)))
15863 +               return ERR_PTR(-ENOMEM);
15864 +
15865 +       /* required to make dynamic xids unique */
15866 +       spin_lock(&vx_info_hash_lock);
15867 +
15868 +       /* static context requested */
15869 +       if ((vxi = __lookup_vx_info(id))) {
15870 +               vxdprintk(VXD_CBIT(xid, 0),
15871 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
15872 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
15873 +                       vxi = ERR_PTR(-EBUSY);
15874 +               else
15875 +                       vxi = ERR_PTR(-EEXIST);
15876 +               goto out_unlock;
15877 +       }
15878 +       /* new context */
15879 +       vxdprintk(VXD_CBIT(xid, 0),
15880 +               "create_vx_info(%d) = %p (new)", id, new);
15881 +       claim_vx_info(new, NULL);
15882 +       __hash_vx_info(get_vx_info(new));
15883 +       vxi = new, new = NULL;
15884 +
15885 +out_unlock:
15886 +       spin_unlock(&vx_info_hash_lock);
15887 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
15888 +       if (new)
15889 +               __dealloc_vx_info(new);
15890 +       return vxi;
15891 +}
15892 +
15893 +
15894 +/*     exported stuff                                          */
15895 +
15896 +
15897 +void unhash_vx_info(struct vx_info *vxi)
15898 +{
15899 +       spin_lock(&vx_info_hash_lock);
15900 +       __unhash_vx_info(vxi);
15901 +       spin_unlock(&vx_info_hash_lock);
15902 +       __shutdown_vx_info(vxi);
15903 +       __wakeup_vx_info(vxi);
15904 +}
15905 +
15906 +
15907 +/*     lookup_vx_info()
15908 +
15909 +       * search for a vx_info and get() it
15910 +       * negative id means current                             */
15911 +
15912 +struct vx_info *lookup_vx_info(int id)
15913 +{
15914 +       struct vx_info *vxi = NULL;
15915 +
15916 +       if (id < 0) {
15917 +               vxi = get_vx_info(current_vx_info());
15918 +       } else if (id > 1) {
15919 +               spin_lock(&vx_info_hash_lock);
15920 +               vxi = get_vx_info(__lookup_vx_info(id));
15921 +               spin_unlock(&vx_info_hash_lock);
15922 +       }
15923 +       return vxi;
15924 +}
15925 +
15926 +/*     xid_is_hashed()
15927 +
15928 +       * verify that xid is still hashed                       */
15929 +
15930 +int xid_is_hashed(vxid_t xid)
15931 +{
15932 +       int hashed;
15933 +
15934 +       spin_lock(&vx_info_hash_lock);
15935 +       hashed = (__lookup_vx_info(xid) != NULL);
15936 +       spin_unlock(&vx_info_hash_lock);
15937 +       return hashed;
15938 +}
15939 +
15940 +#ifdef CONFIG_PROC_FS
15941 +
15942 +/*     get_xid_list()
15943 +
15944 +       * get a subset of hashed xids for proc
15945 +       * assumes size is at least one                          */
15946 +
15947 +int get_xid_list(int index, unsigned int *xids, int size)
15948 +{
15949 +       int hindex, nr_xids = 0;
15950 +
15951 +       /* only show current and children */
15952 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
15953 +               if (index > 0)
15954 +                       return 0;
15955 +               xids[nr_xids] = vx_current_xid();
15956 +               return 1;
15957 +       }
15958 +
15959 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
15960 +               struct hlist_head *head = &vx_info_hash[hindex];
15961 +               struct hlist_node *pos;
15962 +
15963 +               spin_lock(&vx_info_hash_lock);
15964 +               hlist_for_each(pos, head) {
15965 +                       struct vx_info *vxi;
15966 +
15967 +                       if (--index > 0)
15968 +                               continue;
15969 +
15970 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
15971 +                       xids[nr_xids] = vxi->vx_id;
15972 +                       if (++nr_xids >= size) {
15973 +                               spin_unlock(&vx_info_hash_lock);
15974 +                               goto out;
15975 +                       }
15976 +               }
15977 +               /* keep the lock time short */
15978 +               spin_unlock(&vx_info_hash_lock);
15979 +       }
15980 +out:
15981 +       return nr_xids;
15982 +}
15983 +#endif
15984 +
15985 +#ifdef CONFIG_VSERVER_DEBUG
15986 +
15987 +void   dump_vx_info_inactive(int level)
15988 +{
15989 +       struct hlist_node *entry, *next;
15990 +
15991 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
15992 +               struct vx_info *vxi =
15993 +                       list_entry(entry, struct vx_info, vx_hlist);
15994 +
15995 +               dump_vx_info(vxi, level);
15996 +       }
15997 +}
15998 +
15999 +#endif
16000 +
16001 +#if 0
16002 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
16003 +{
16004 +       struct user_struct *new_user, *old_user;
16005 +
16006 +       if (!p || !vxi)
16007 +               BUG();
16008 +
16009 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
16010 +               return -EACCES;
16011 +
16012 +       new_user = alloc_uid(vxi->vx_id, p->uid);
16013 +       if (!new_user)
16014 +               return -ENOMEM;
16015 +
16016 +       old_user = p->user;
16017 +       if (new_user != old_user) {
16018 +               atomic_inc(&new_user->processes);
16019 +               atomic_dec(&old_user->processes);
16020 +               p->user = new_user;
16021 +       }
16022 +       free_uid(old_user);
16023 +       return 0;
16024 +}
16025 +#endif
16026 +
16027 +#if 0
16028 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
16029 +{
16030 +       // p->cap_effective &= vxi->vx_cap_bset;
16031 +       p->cap_effective =
16032 +               cap_intersect(p->cap_effective, vxi->cap_bset);
16033 +       // p->cap_inheritable &= vxi->vx_cap_bset;
16034 +       p->cap_inheritable =
16035 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
16036 +       // p->cap_permitted &= vxi->vx_cap_bset;
16037 +       p->cap_permitted =
16038 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
16039 +}
16040 +#endif
16041 +
16042 +
16043 +#include <linux/file.h>
16044 +#include <linux/fdtable.h>
16045 +
16046 +static int vx_openfd_task(struct task_struct *tsk)
16047 +{
16048 +       struct files_struct *files = tsk->files;
16049 +       struct fdtable *fdt;
16050 +       const unsigned long *bptr;
16051 +       int count, total;
16052 +
16053 +       /* no rcu_read_lock() because of spin_lock() */
16054 +       spin_lock(&files->file_lock);
16055 +       fdt = files_fdtable(files);
16056 +       bptr = fdt->open_fds;
16057 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
16058 +       for (total = 0; count > 0; count--) {
16059 +               if (*bptr)
16060 +                       total += hweight_long(*bptr);
16061 +               bptr++;
16062 +       }
16063 +       spin_unlock(&files->file_lock);
16064 +       return total;
16065 +}
16066 +
16067 +
16068 +/*     for *space compatibility */
16069 +
16070 +asmlinkage long sys_unshare(unsigned long);
16071 +
16072 +/*
16073 + *     migrate task to new context
16074 + *     gets vxi, puts old_vxi on change
16075 + *     optionally unshares namespaces (hack)
16076 + */
16077 +
16078 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
16079 +{
16080 +       struct vx_info *old_vxi;
16081 +       int ret = 0;
16082 +
16083 +       if (!p || !vxi)
16084 +               BUG();
16085 +
16086 +       vxdprintk(VXD_CBIT(xid, 5),
16087 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
16088 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
16089 +
16090 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
16091 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16092 +               return -EACCES;
16093 +
16094 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
16095 +               return -EFAULT;
16096 +
16097 +       old_vxi = task_get_vx_info(p);
16098 +       if (old_vxi == vxi)
16099 +               goto out;
16100 +
16101 +//     if (!(ret = vx_migrate_user(p, vxi))) {
16102 +       {
16103 +               int openfd;
16104 +
16105 +               task_lock(p);
16106 +               openfd = vx_openfd_task(p);
16107 +
16108 +               if (old_vxi) {
16109 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
16110 +                       atomic_dec(&old_vxi->cvirt.nr_running);
16111 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
16112 +                       /* FIXME: what about the struct files here? */
16113 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
16114 +                       /* account for the executable */
16115 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
16116 +               }
16117 +               atomic_inc(&vxi->cvirt.nr_threads);
16118 +               atomic_inc(&vxi->cvirt.nr_running);
16119 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
16120 +               /* FIXME: what about the struct files here? */
16121 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
16122 +               /* account for the executable */
16123 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
16124 +
16125 +               if (old_vxi) {
16126 +                       release_vx_info(old_vxi, p);
16127 +                       clr_vx_info(&p->vx_info);
16128 +               }
16129 +               claim_vx_info(vxi, p);
16130 +               set_vx_info(&p->vx_info, vxi);
16131 +               p->xid = vxi->vx_id;
16132 +
16133 +               vxdprintk(VXD_CBIT(xid, 5),
16134 +                       "moved task %p into vxi:%p[#%d]",
16135 +                       p, vxi, vxi->vx_id);
16136 +
16137 +               // vx_mask_cap_bset(vxi, p);
16138 +               task_unlock(p);
16139 +
16140 +               /* hack for *spaces to provide compatibility */
16141 +               if (unshare) {
16142 +                       struct nsproxy *old_nsp, *new_nsp;
16143 +
16144 +                       ret = unshare_nsproxy_namespaces(
16145 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
16146 +                               &new_nsp, NULL, NULL);
16147 +                       if (ret)
16148 +                               goto out;
16149 +
16150 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
16151 +                       vx_set_space(vxi,
16152 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
16153 +                       put_nsproxy(old_nsp);
16154 +               }
16155 +       }
16156 +out:
16157 +       put_vx_info(old_vxi);
16158 +       return ret;
16159 +}
16160 +
16161 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
16162 +{
16163 +       struct task_struct *old_reaper;
16164 +       struct vx_info *reaper_vxi;
16165 +
16166 +       if (!vxi)
16167 +               return -EINVAL;
16168 +
16169 +       vxdprintk(VXD_CBIT(xid, 6),
16170 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
16171 +               vxi, vxi->vx_id, p, p->xid, p->pid);
16172 +
16173 +       old_reaper = vxi->vx_reaper;
16174 +       if (old_reaper == p)
16175 +               return 0;
16176 +
16177 +       reaper_vxi = task_get_vx_info(p);
16178 +       if (reaper_vxi && reaper_vxi != vxi) {
16179 +               vxwprintk(1,
16180 +                       "Unsuitable reaper [" VS_Q("%s") ",%u:#%u] "
16181 +                       "for [xid #%u]",
16182 +                       p->comm, p->pid, p->xid, vx_current_xid());
16183 +               goto out;
16184 +       }
16185 +
16186 +       /* set new child reaper */
16187 +       get_task_struct(p);
16188 +       vxi->vx_reaper = p;
16189 +       put_task_struct(old_reaper);
16190 +out:
16191 +       put_vx_info(reaper_vxi);
16192 +       return 0;
16193 +}
16194 +
16195 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
16196 +{
16197 +       if (!vxi)
16198 +               return -EINVAL;
16199 +
16200 +       vxdprintk(VXD_CBIT(xid, 6),
16201 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
16202 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16203 +
16204 +       vxi->vx_flags &= ~VXF_STATE_INIT;
16205 +       // vxi->vx_initpid = p->tgid;
16206 +       vxi->vx_initpid = p->pid;
16207 +       return 0;
16208 +}
16209 +
16210 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
16211 +{
16212 +       vxdprintk(VXD_CBIT(xid, 6),
16213 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
16214 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16215 +
16216 +       vxi->exit_code = code;
16217 +       vxi->vx_initpid = 0;
16218 +}
16219 +
16220 +
16221 +void vx_set_persistent(struct vx_info *vxi)
16222 +{
16223 +       vxdprintk(VXD_CBIT(xid, 6),
16224 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
16225 +
16226 +       get_vx_info(vxi);
16227 +       claim_vx_info(vxi, NULL);
16228 +}
16229 +
16230 +void vx_clear_persistent(struct vx_info *vxi)
16231 +{
16232 +       vxdprintk(VXD_CBIT(xid, 6),
16233 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
16234 +
16235 +       release_vx_info(vxi, NULL);
16236 +       put_vx_info(vxi);
16237 +}
16238 +
16239 +void vx_update_persistent(struct vx_info *vxi)
16240 +{
16241 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
16242 +               vx_set_persistent(vxi);
16243 +       else
16244 +               vx_clear_persistent(vxi);
16245 +}
16246 +
16247 +
16248 +/*     task must be current or locked          */
16249 +
16250 +void   exit_vx_info(struct task_struct *p, int code)
16251 +{
16252 +       struct vx_info *vxi = p->vx_info;
16253 +
16254 +       if (vxi) {
16255 +               atomic_dec(&vxi->cvirt.nr_threads);
16256 +               vx_nproc_dec(p);
16257 +
16258 +               vxi->exit_code = code;
16259 +               release_vx_info(vxi, p);
16260 +       }
16261 +}
16262 +
16263 +void   exit_vx_info_early(struct task_struct *p, int code)
16264 +{
16265 +       struct vx_info *vxi = p->vx_info;
16266 +
16267 +       if (vxi) {
16268 +               if (vxi->vx_initpid == p->pid)
16269 +                       vx_exit_init(vxi, p, code);
16270 +               if (vxi->vx_reaper == p)
16271 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
16272 +       }
16273 +}
16274 +
16275 +
16276 +/* vserver syscall commands below here */
16277 +
16278 +/* taks xid and vx_info functions */
16279 +
16280 +#include <asm/uaccess.h>
16281 +
16282 +
16283 +int vc_task_xid(uint32_t id)
16284 +{
16285 +       vxid_t xid;
16286 +
16287 +       if (id) {
16288 +               struct task_struct *tsk;
16289 +
16290 +               rcu_read_lock();
16291 +               tsk = find_task_by_real_pid(id);
16292 +               xid = (tsk) ? tsk->xid : -ESRCH;
16293 +               rcu_read_unlock();
16294 +       } else
16295 +               xid = vx_current_xid();
16296 +       return xid;
16297 +}
16298 +
16299 +
16300 +int vc_vx_info(struct vx_info *vxi, void __user *data)
16301 +{
16302 +       struct vcmd_vx_info_v0 vc_data;
16303 +
16304 +       vc_data.xid = vxi->vx_id;
16305 +       vc_data.initpid = vxi->vx_initpid;
16306 +
16307 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16308 +               return -EFAULT;
16309 +       return 0;
16310 +}
16311 +
16312 +
16313 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
16314 +{
16315 +       struct vcmd_ctx_stat_v0 vc_data;
16316 +
16317 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
16318 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
16319 +
16320 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16321 +               return -EFAULT;
16322 +       return 0;
16323 +}
16324 +
16325 +
16326 +/* context functions */
16327 +
16328 +int vc_ctx_create(uint32_t xid, void __user *data)
16329 +{
16330 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
16331 +       struct vx_info *new_vxi;
16332 +       int ret;
16333 +
16334 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16335 +               return -EFAULT;
16336 +
16337 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
16338 +               return -EINVAL;
16339 +
16340 +       new_vxi = __create_vx_info(xid);
16341 +       if (IS_ERR(new_vxi))
16342 +               return PTR_ERR(new_vxi);
16343 +
16344 +       /* initial flags */
16345 +       new_vxi->vx_flags = vc_data.flagword;
16346 +
16347 +       ret = -ENOEXEC;
16348 +       if (vs_state_change(new_vxi, VSC_STARTUP))
16349 +               goto out;
16350 +
16351 +       ret = vx_migrate_task(current, new_vxi, (!data));
16352 +       if (ret)
16353 +               goto out;
16354 +
16355 +       /* return context id on success */
16356 +       ret = new_vxi->vx_id;
16357 +
16358 +       /* get a reference for persistent contexts */
16359 +       if ((vc_data.flagword & VXF_PERSISTENT))
16360 +               vx_set_persistent(new_vxi);
16361 +out:
16362 +       release_vx_info(new_vxi, NULL);
16363 +       put_vx_info(new_vxi);
16364 +       return ret;
16365 +}
16366 +
16367 +
16368 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
16369 +{
16370 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
16371 +       int ret;
16372 +
16373 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16374 +               return -EFAULT;
16375 +
16376 +       ret = vx_migrate_task(current, vxi, 0);
16377 +       if (ret)
16378 +               return ret;
16379 +       if (vc_data.flagword & VXM_SET_INIT)
16380 +               ret = vx_set_init(vxi, current);
16381 +       if (ret)
16382 +               return ret;
16383 +       if (vc_data.flagword & VXM_SET_REAPER)
16384 +               ret = vx_set_reaper(vxi, current);
16385 +       return ret;
16386 +}
16387 +
16388 +
16389 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
16390 +{
16391 +       struct vcmd_ctx_flags_v0 vc_data;
16392 +
16393 +       vc_data.flagword = vxi->vx_flags;
16394 +
16395 +       /* special STATE flag handling */
16396 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
16397 +
16398 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16399 +               return -EFAULT;
16400 +       return 0;
16401 +}
16402 +
16403 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
16404 +{
16405 +       struct vcmd_ctx_flags_v0 vc_data;
16406 +       uint64_t mask, trigger;
16407 +
16408 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16409 +               return -EFAULT;
16410 +
16411 +       /* special STATE flag handling */
16412 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
16413 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
16414 +
16415 +       if (vxi == current_vx_info()) {
16416 +               /* if (trigger & VXF_STATE_SETUP)
16417 +                       vx_mask_cap_bset(vxi, current); */
16418 +               if (trigger & VXF_STATE_INIT) {
16419 +                       int ret;
16420 +
16421 +                       ret = vx_set_init(vxi, current);
16422 +                       if (ret)
16423 +                               return ret;
16424 +                       ret = vx_set_reaper(vxi, current);
16425 +                       if (ret)
16426 +                               return ret;
16427 +               }
16428 +       }
16429 +
16430 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
16431 +               vc_data.flagword, mask);
16432 +       if (trigger & VXF_PERSISTENT)
16433 +               vx_update_persistent(vxi);
16434 +
16435 +       return 0;
16436 +}
16437 +
16438 +
16439 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
16440 +{
16441 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
16442 +
16443 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
16444 +       return v;
16445 +}
16446 +
16447 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
16448 +{
16449 +       kernel_cap_t c = __cap_empty_set;
16450 +
16451 +       c.cap[0] = v & 0xFFFFFFFF;
16452 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
16453 +
16454 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
16455 +       return c;
16456 +}
16457 +
16458 +
16459 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
16460 +{
16461 +       if (bcaps)
16462 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
16463 +       if (ccaps)
16464 +               *ccaps = vxi->vx_ccaps;
16465 +
16466 +       return 0;
16467 +}
16468 +
16469 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
16470 +{
16471 +       struct vcmd_ctx_caps_v1 vc_data;
16472 +       int ret;
16473 +
16474 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
16475 +       if (ret)
16476 +               return ret;
16477 +       vc_data.cmask = ~0ULL;
16478 +
16479 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16480 +               return -EFAULT;
16481 +       return 0;
16482 +}
16483 +
16484 +static int do_set_caps(struct vx_info *vxi,
16485 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
16486 +{
16487 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
16488 +
16489 +#if 0
16490 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
16491 +               bcaps, bmask, ccaps, cmask);
16492 +#endif
16493 +       vxi->vx_bcaps = cap_t_from_caps(
16494 +               vs_mask_flags(bcold, bcaps, bmask));
16495 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
16496 +
16497 +       return 0;
16498 +}
16499 +
16500 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
16501 +{
16502 +       struct vcmd_ctx_caps_v1 vc_data;
16503 +
16504 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16505 +               return -EFAULT;
16506 +
16507 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
16508 +}
16509 +
16510 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
16511 +{
16512 +       struct vcmd_bcaps vc_data;
16513 +       int ret;
16514 +
16515 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
16516 +       if (ret)
16517 +               return ret;
16518 +       vc_data.bmask = ~0ULL;
16519 +
16520 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16521 +               return -EFAULT;
16522 +       return 0;
16523 +}
16524 +
16525 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
16526 +{
16527 +       struct vcmd_bcaps vc_data;
16528 +
16529 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16530 +               return -EFAULT;
16531 +
16532 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
16533 +}
16534 +
16535 +
16536 +int vc_get_umask(struct vx_info *vxi, void __user *data)
16537 +{
16538 +       struct vcmd_umask vc_data;
16539 +
16540 +       vc_data.umask = vxi->vx_umask;
16541 +       vc_data.mask = ~0ULL;
16542 +
16543 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16544 +               return -EFAULT;
16545 +       return 0;
16546 +}
16547 +
16548 +int vc_set_umask(struct vx_info *vxi, void __user *data)
16549 +{
16550 +       struct vcmd_umask vc_data;
16551 +
16552 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16553 +               return -EFAULT;
16554 +
16555 +       vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
16556 +               vc_data.umask, vc_data.mask);
16557 +       return 0;
16558 +}
16559 +
16560 +
16561 +int vc_get_wmask(struct vx_info *vxi, void __user *data)
16562 +{
16563 +       struct vcmd_wmask vc_data;
16564 +
16565 +       vc_data.wmask = vxi->vx_wmask;
16566 +       vc_data.mask = ~0ULL;
16567 +
16568 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16569 +               return -EFAULT;
16570 +       return 0;
16571 +}
16572 +
16573 +int vc_set_wmask(struct vx_info *vxi, void __user *data)
16574 +{
16575 +       struct vcmd_wmask vc_data;
16576 +
16577 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16578 +               return -EFAULT;
16579 +
16580 +       vxi->vx_wmask = vs_mask_flags(vxi->vx_wmask,
16581 +               vc_data.wmask, vc_data.mask);
16582 +       return 0;
16583 +}
16584 +
16585 +
16586 +int vc_get_badness(struct vx_info *vxi, void __user *data)
16587 +{
16588 +       struct vcmd_badness_v0 vc_data;
16589 +
16590 +       vc_data.bias = vxi->vx_badness_bias;
16591 +
16592 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16593 +               return -EFAULT;
16594 +       return 0;
16595 +}
16596 +
16597 +int vc_set_badness(struct vx_info *vxi, void __user *data)
16598 +{
16599 +       struct vcmd_badness_v0 vc_data;
16600 +
16601 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16602 +               return -EFAULT;
16603 +
16604 +       vxi->vx_badness_bias = vc_data.bias;
16605 +       return 0;
16606 +}
16607 +
16608 +#include <linux/module.h>
16609 +
16610 +EXPORT_SYMBOL_GPL(free_vx_info);
16611 +
16612 diff -NurpP --minimal linux-3.10.33/kernel/vserver/cvirt.c linux-3.10.33-vs2.3.6.8/kernel/vserver/cvirt.c
16613 --- linux-3.10.33/kernel/vserver/cvirt.c        1970-01-01 00:00:00.000000000 +0000
16614 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/cvirt.c      2013-08-22 20:30:00.000000000 +0000
16615 @@ -0,0 +1,313 @@
16616 +/*
16617 + *  linux/kernel/vserver/cvirt.c
16618 + *
16619 + *  Virtual Server: Context Virtualization
16620 + *
16621 + *  Copyright (C) 2004-2007  Herbert Pötzl
16622 + *
16623 + *  V0.01  broken out from limit.c
16624 + *  V0.02  added utsname stuff
16625 + *  V0.03  changed vcmds to vxi arg
16626 + *
16627 + */
16628 +
16629 +#include <linux/types.h>
16630 +#include <linux/utsname.h>
16631 +#include <linux/vs_cvirt.h>
16632 +#include <linux/vserver/switch.h>
16633 +#include <linux/vserver/cvirt_cmd.h>
16634 +
16635 +#include <asm/uaccess.h>
16636 +
16637 +
16638 +void vx_vsi_boottime(struct timespec *boottime)
16639 +{
16640 +       struct vx_info *vxi = current_vx_info();
16641 +
16642 +       set_normalized_timespec(boottime,
16643 +               boottime->tv_sec + vxi->cvirt.bias_uptime.tv_sec,
16644 +               boottime->tv_nsec + vxi->cvirt.bias_uptime.tv_nsec);
16645 +       return;
16646 +}
16647 +
16648 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
16649 +{
16650 +       struct vx_info *vxi = current_vx_info();
16651 +
16652 +       set_normalized_timespec(uptime,
16653 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
16654 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
16655 +       if (!idle)
16656 +               return;
16657 +       set_normalized_timespec(idle,
16658 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
16659 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
16660 +       return;
16661 +}
16662 +
16663 +uint64_t vx_idle_jiffies(void)
16664 +{
16665 +       return init_task.utime + init_task.stime;
16666 +}
16667 +
16668 +
16669 +
16670 +static inline uint32_t __update_loadavg(uint32_t load,
16671 +       int wsize, int delta, int n)
16672 +{
16673 +       unsigned long long calc, prev;
16674 +
16675 +       /* just set it to n */
16676 +       if (unlikely(delta >= wsize))
16677 +               return (n << FSHIFT);
16678 +
16679 +       calc = delta * n;
16680 +       calc <<= FSHIFT;
16681 +       prev = (wsize - delta);
16682 +       prev *= load;
16683 +       calc += prev;
16684 +       do_div(calc, wsize);
16685 +       return calc;
16686 +}
16687 +
16688 +
16689 +void vx_update_load(struct vx_info *vxi)
16690 +{
16691 +       uint32_t now, last, delta;
16692 +       unsigned int nr_running, nr_uninterruptible;
16693 +       unsigned int total;
16694 +       unsigned long flags;
16695 +
16696 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
16697 +
16698 +       now = jiffies;
16699 +       last = vxi->cvirt.load_last;
16700 +       delta = now - last;
16701 +
16702 +       if (delta < 5*HZ)
16703 +               goto out;
16704 +
16705 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
16706 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
16707 +       total = nr_running + nr_uninterruptible;
16708 +
16709 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
16710 +               60*HZ, delta, total);
16711 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
16712 +               5*60*HZ, delta, total);
16713 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
16714 +               15*60*HZ, delta, total);
16715 +
16716 +       vxi->cvirt.load_last = now;
16717 +out:
16718 +       atomic_inc(&vxi->cvirt.load_updates);
16719 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
16720 +}
16721 +
16722 +
16723 +/*
16724 + * Commands to do_syslog:
16725 + *
16726 + *      0 -- Close the log.  Currently a NOP.
16727 + *      1 -- Open the log. Currently a NOP.
16728 + *      2 -- Read from the log.
16729 + *      3 -- Read all messages remaining in the ring buffer.
16730 + *      4 -- Read and clear all messages remaining in the ring buffer
16731 + *      5 -- Clear ring buffer.
16732 + *      6 -- Disable printk's to console
16733 + *      7 -- Enable printk's to console
16734 + *      8 -- Set level of messages printed to console
16735 + *      9 -- Return number of unread characters in the log buffer
16736 + *     10 -- Return size of the log buffer
16737 + */
16738 +int vx_do_syslog(int type, char __user *buf, int len)
16739 +{
16740 +       int error = 0;
16741 +       int do_clear = 0;
16742 +       struct vx_info *vxi = current_vx_info();
16743 +       struct _vx_syslog *log;
16744 +
16745 +       if (!vxi)
16746 +               return -EINVAL;
16747 +       log = &vxi->cvirt.syslog;
16748 +
16749 +       switch (type) {
16750 +       case 0:         /* Close log */
16751 +       case 1:         /* Open log */
16752 +               break;
16753 +       case 2:         /* Read from log */
16754 +               error = wait_event_interruptible(log->log_wait,
16755 +                       (log->log_start - log->log_end));
16756 +               if (error)
16757 +                       break;
16758 +               spin_lock_irq(&log->logbuf_lock);
16759 +               spin_unlock_irq(&log->logbuf_lock);
16760 +               break;
16761 +       case 4:         /* Read/clear last kernel messages */
16762 +               do_clear = 1;
16763 +               /* fall through */
16764 +       case 3:         /* Read last kernel messages */
16765 +               return 0;
16766 +
16767 +       case 5:         /* Clear ring buffer */
16768 +               return 0;
16769 +
16770 +       case 6:         /* Disable logging to console */
16771 +       case 7:         /* Enable logging to console */
16772 +       case 8:         /* Set level of messages printed to console */
16773 +               break;
16774 +
16775 +       case 9:         /* Number of chars in the log buffer */
16776 +               return 0;
16777 +       case 10:        /* Size of the log buffer */
16778 +               return 0;
16779 +       default:
16780 +               error = -EINVAL;
16781 +               break;
16782 +       }
16783 +       return error;
16784 +}
16785 +
16786 +
16787 +/* virtual host info names */
16788 +
16789 +static char *vx_vhi_name(struct vx_info *vxi, int id)
16790 +{
16791 +       struct nsproxy *nsproxy;
16792 +       struct uts_namespace *uts;
16793 +
16794 +       if (id == VHIN_CONTEXT)
16795 +               return vxi->vx_name;
16796 +
16797 +       nsproxy = vxi->space[0].vx_nsproxy;
16798 +       if (!nsproxy)
16799 +               return NULL;
16800 +
16801 +       uts = nsproxy->uts_ns;
16802 +       if (!uts)
16803 +               return NULL;
16804 +
16805 +       switch (id) {
16806 +       case VHIN_SYSNAME:
16807 +               return uts->name.sysname;
16808 +       case VHIN_NODENAME:
16809 +               return uts->name.nodename;
16810 +       case VHIN_RELEASE:
16811 +               return uts->name.release;
16812 +       case VHIN_VERSION:
16813 +               return uts->name.version;
16814 +       case VHIN_MACHINE:
16815 +               return uts->name.machine;
16816 +       case VHIN_DOMAINNAME:
16817 +               return uts->name.domainname;
16818 +       default:
16819 +               return NULL;
16820 +       }
16821 +       return NULL;
16822 +}
16823 +
16824 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
16825 +{
16826 +       struct vcmd_vhi_name_v0 vc_data;
16827 +       char *name;
16828 +
16829 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16830 +               return -EFAULT;
16831 +
16832 +       name = vx_vhi_name(vxi, vc_data.field);
16833 +       if (!name)
16834 +               return -EINVAL;
16835 +
16836 +       memcpy(name, vc_data.name, 65);
16837 +       return 0;
16838 +}
16839 +
16840 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
16841 +{
16842 +       struct vcmd_vhi_name_v0 vc_data;
16843 +       char *name;
16844 +
16845 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16846 +               return -EFAULT;
16847 +
16848 +       name = vx_vhi_name(vxi, vc_data.field);
16849 +       if (!name)
16850 +               return -EINVAL;
16851 +
16852 +       memcpy(vc_data.name, name, 65);
16853 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16854 +               return -EFAULT;
16855 +       return 0;
16856 +}
16857 +
16858 +
16859 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
16860 +{
16861 +       struct vcmd_virt_stat_v0 vc_data;
16862 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
16863 +       struct timespec uptime;
16864 +
16865 +       do_posix_clock_monotonic_gettime(&uptime);
16866 +       set_normalized_timespec(&uptime,
16867 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
16868 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
16869 +
16870 +       vc_data.offset = timespec_to_ns(&cvirt->bias_ts);
16871 +       vc_data.uptime = timespec_to_ns(&uptime);
16872 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
16873 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
16874 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
16875 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
16876 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
16877 +       vc_data.load[0] = cvirt->load[0];
16878 +       vc_data.load[1] = cvirt->load[1];
16879 +       vc_data.load[2] = cvirt->load[2];
16880 +
16881 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16882 +               return -EFAULT;
16883 +       return 0;
16884 +}
16885 +
16886 +
16887 +#ifdef CONFIG_VSERVER_VTIME
16888 +
16889 +/* virtualized time base */
16890 +
16891 +void vx_adjust_timespec(struct timespec *ts)
16892 +{
16893 +       struct vx_info *vxi;
16894 +
16895 +       if (!vx_flags(VXF_VIRT_TIME, 0))
16896 +               return;
16897 +
16898 +       vxi = current_vx_info();
16899 +       ts->tv_sec += vxi->cvirt.bias_ts.tv_sec;
16900 +       ts->tv_nsec += vxi->cvirt.bias_ts.tv_nsec;
16901 +
16902 +       if (ts->tv_nsec >= NSEC_PER_SEC) {
16903 +               ts->tv_sec++;
16904 +               ts->tv_nsec -= NSEC_PER_SEC;
16905 +       } else if (ts->tv_nsec < 0) {
16906 +               ts->tv_sec--;
16907 +               ts->tv_nsec += NSEC_PER_SEC;
16908 +       }
16909 +}
16910 +
16911 +int vx_settimeofday(const struct timespec *ts)
16912 +{
16913 +       struct timespec ats, delta;
16914 +       struct vx_info *vxi;
16915 +
16916 +       if (!vx_flags(VXF_VIRT_TIME, 0))
16917 +               return do_settimeofday(ts);
16918 +
16919 +       getnstimeofday(&ats);
16920 +       delta = timespec_sub(*ts, ats);
16921 +
16922 +       vxi = current_vx_info();
16923 +       vxi->cvirt.bias_ts = timespec_add(vxi->cvirt.bias_ts, delta);
16924 +       return 0;
16925 +}
16926 +
16927 +#endif
16928 +
16929 diff -NurpP --minimal linux-3.10.33/kernel/vserver/cvirt_init.h linux-3.10.33-vs2.3.6.8/kernel/vserver/cvirt_init.h
16930 --- linux-3.10.33/kernel/vserver/cvirt_init.h   1970-01-01 00:00:00.000000000 +0000
16931 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/cvirt_init.h 2013-08-22 20:30:00.000000000 +0000
16932 @@ -0,0 +1,70 @@
16933 +
16934 +
16935 +extern uint64_t vx_idle_jiffies(void);
16936 +
16937 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
16938 +{
16939 +       uint64_t idle_jiffies = vx_idle_jiffies();
16940 +       uint64_t nsuptime;
16941 +
16942 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
16943 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
16944 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
16945 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
16946 +       cvirt->bias_ts.tv_sec = 0;
16947 +       cvirt->bias_ts.tv_nsec = 0;
16948 +
16949 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
16950 +       atomic_set(&cvirt->nr_threads, 0);
16951 +       atomic_set(&cvirt->nr_running, 0);
16952 +       atomic_set(&cvirt->nr_uninterruptible, 0);
16953 +       atomic_set(&cvirt->nr_onhold, 0);
16954 +
16955 +       spin_lock_init(&cvirt->load_lock);
16956 +       cvirt->load_last = jiffies;
16957 +       atomic_set(&cvirt->load_updates, 0);
16958 +       cvirt->load[0] = 0;
16959 +       cvirt->load[1] = 0;
16960 +       cvirt->load[2] = 0;
16961 +       atomic_set(&cvirt->total_forks, 0);
16962 +
16963 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
16964 +       init_waitqueue_head(&cvirt->syslog.log_wait);
16965 +       cvirt->syslog.log_start = 0;
16966 +       cvirt->syslog.log_end = 0;
16967 +       cvirt->syslog.con_start = 0;
16968 +       cvirt->syslog.logged_chars = 0;
16969 +}
16970 +
16971 +static inline
16972 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
16973 +{
16974 +       // cvirt_pc->cpustat = { 0 };
16975 +}
16976 +
16977 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
16978 +{
16979 +#ifdef CONFIG_VSERVER_WARN
16980 +       int value;
16981 +#endif
16982 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
16983 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
16984 +               cvirt, value);
16985 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
16986 +               "!!! cvirt: %p[nr_running] = %d on exit.",
16987 +               cvirt, value);
16988 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
16989 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
16990 +               cvirt, value);
16991 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
16992 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
16993 +               cvirt, value);
16994 +       return;
16995 +}
16996 +
16997 +static inline
16998 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
16999 +{
17000 +       return;
17001 +}
17002 +
17003 diff -NurpP --minimal linux-3.10.33/kernel/vserver/cvirt_proc.h linux-3.10.33-vs2.3.6.8/kernel/vserver/cvirt_proc.h
17004 --- linux-3.10.33/kernel/vserver/cvirt_proc.h   1970-01-01 00:00:00.000000000 +0000
17005 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/cvirt_proc.h 2013-08-22 20:30:00.000000000 +0000
17006 @@ -0,0 +1,123 @@
17007 +#ifndef _VX_CVIRT_PROC_H
17008 +#define _VX_CVIRT_PROC_H
17009 +
17010 +#include <linux/nsproxy.h>
17011 +#include <linux/mnt_namespace.h>
17012 +#include <linux/ipc_namespace.h>
17013 +#include <linux/utsname.h>
17014 +#include <linux/ipc.h>
17015 +
17016 +extern int vx_info_mnt_namespace(struct mnt_namespace *, char *);
17017 +
17018 +static inline
17019 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
17020 +{
17021 +       struct mnt_namespace *ns;
17022 +       struct uts_namespace *uts;
17023 +       struct ipc_namespace *ipc;
17024 +       int length = 0;
17025 +
17026 +       if (!nsproxy)
17027 +               goto out;
17028 +
17029 +       length += sprintf(buffer + length,
17030 +               "NSProxy:\t%p [%p,%p,%p]\n",
17031 +               nsproxy, nsproxy->mnt_ns,
17032 +               nsproxy->uts_ns, nsproxy->ipc_ns);
17033 +
17034 +       ns = nsproxy->mnt_ns;
17035 +       if (!ns)
17036 +               goto skip_ns;
17037 +
17038 +       length += vx_info_mnt_namespace(ns, buffer + length);
17039 +
17040 +skip_ns:
17041 +
17042 +       uts = nsproxy->uts_ns;
17043 +       if (!uts)
17044 +               goto skip_uts;
17045 +
17046 +       length += sprintf(buffer + length,
17047 +               "SysName:\t%.*s\n"
17048 +               "NodeName:\t%.*s\n"
17049 +               "Release:\t%.*s\n"
17050 +               "Version:\t%.*s\n"
17051 +               "Machine:\t%.*s\n"
17052 +               "DomainName:\t%.*s\n",
17053 +               __NEW_UTS_LEN, uts->name.sysname,
17054 +               __NEW_UTS_LEN, uts->name.nodename,
17055 +               __NEW_UTS_LEN, uts->name.release,
17056 +               __NEW_UTS_LEN, uts->name.version,
17057 +               __NEW_UTS_LEN, uts->name.machine,
17058 +               __NEW_UTS_LEN, uts->name.domainname);
17059 +skip_uts:
17060 +
17061 +       ipc = nsproxy->ipc_ns;
17062 +       if (!ipc)
17063 +               goto skip_ipc;
17064 +
17065 +       length += sprintf(buffer + length,
17066 +               "SEMS:\t\t%d %d %d %d  %d\n"
17067 +               "MSG:\t\t%d %d %d\n"
17068 +               "SHM:\t\t%lu %lu  %d %ld\n",
17069 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
17070 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
17071 +               ipc->used_sems,
17072 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
17073 +               (unsigned long)ipc->shm_ctlmax,
17074 +               (unsigned long)ipc->shm_ctlall,
17075 +               ipc->shm_ctlmni, ipc->shm_tot);
17076 +skip_ipc:
17077 +out:
17078 +       return length;
17079 +}
17080 +
17081 +
17082 +#include <linux/sched.h>
17083 +
17084 +#define LOAD_INT(x) ((x) >> FSHIFT)
17085 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
17086 +
17087 +static inline
17088 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
17089 +{
17090 +       int length = 0;
17091 +       int a, b, c;
17092 +
17093 +       length += sprintf(buffer + length,
17094 +               "BiasUptime:\t%lu.%02lu\n",
17095 +               (unsigned long)cvirt->bias_uptime.tv_sec,
17096 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
17097 +
17098 +       a = cvirt->load[0] + (FIXED_1 / 200);
17099 +       b = cvirt->load[1] + (FIXED_1 / 200);
17100 +       c = cvirt->load[2] + (FIXED_1 / 200);
17101 +       length += sprintf(buffer + length,
17102 +               "nr_threads:\t%d\n"
17103 +               "nr_running:\t%d\n"
17104 +               "nr_unintr:\t%d\n"
17105 +               "nr_onhold:\t%d\n"
17106 +               "load_updates:\t%d\n"
17107 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
17108 +               "total_forks:\t%d\n",
17109 +               atomic_read(&cvirt->nr_threads),
17110 +               atomic_read(&cvirt->nr_running),
17111 +               atomic_read(&cvirt->nr_uninterruptible),
17112 +               atomic_read(&cvirt->nr_onhold),
17113 +               atomic_read(&cvirt->load_updates),
17114 +               LOAD_INT(a), LOAD_FRAC(a),
17115 +               LOAD_INT(b), LOAD_FRAC(b),
17116 +               LOAD_INT(c), LOAD_FRAC(c),
17117 +               atomic_read(&cvirt->total_forks));
17118 +       return length;
17119 +}
17120 +
17121 +static inline
17122 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
17123 +       char *buffer, int cpu)
17124 +{
17125 +       int length = 0;
17126 +       return length;
17127 +}
17128 +
17129 +#endif /* _VX_CVIRT_PROC_H */
17130 diff -NurpP --minimal linux-3.10.33/kernel/vserver/debug.c linux-3.10.33-vs2.3.6.8/kernel/vserver/debug.c
17131 --- linux-3.10.33/kernel/vserver/debug.c        1970-01-01 00:00:00.000000000 +0000
17132 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/debug.c      2013-08-22 20:30:00.000000000 +0000
17133 @@ -0,0 +1,32 @@
17134 +/*
17135 + *  kernel/vserver/debug.c
17136 + *
17137 + *  Copyright (C) 2005-2007 Herbert Pötzl
17138 + *
17139 + *  V0.01  vx_info dump support
17140 + *
17141 + */
17142 +
17143 +#include <linux/module.h>
17144 +
17145 +#include <linux/vserver/context.h>
17146 +
17147 +
17148 +void   dump_vx_info(struct vx_info *vxi, int level)
17149 +{
17150 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
17151 +               atomic_read(&vxi->vx_usecnt),
17152 +               atomic_read(&vxi->vx_tasks),
17153 +               vxi->vx_state);
17154 +       if (level > 0) {
17155 +               __dump_vx_limit(&vxi->limit);
17156 +               __dump_vx_sched(&vxi->sched);
17157 +               __dump_vx_cvirt(&vxi->cvirt);
17158 +               __dump_vx_cacct(&vxi->cacct);
17159 +       }
17160 +       printk("---\n");
17161 +}
17162 +
17163 +
17164 +EXPORT_SYMBOL_GPL(dump_vx_info);
17165 +
17166 diff -NurpP --minimal linux-3.10.33/kernel/vserver/device.c linux-3.10.33-vs2.3.6.8/kernel/vserver/device.c
17167 --- linux-3.10.33/kernel/vserver/device.c       1970-01-01 00:00:00.000000000 +0000
17168 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/device.c     2013-08-22 20:30:00.000000000 +0000
17169 @@ -0,0 +1,443 @@
17170 +/*
17171 + *  linux/kernel/vserver/device.c
17172 + *
17173 + *  Linux-VServer: Device Support
17174 + *
17175 + *  Copyright (C) 2006  Herbert Pötzl
17176 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
17177 + *
17178 + *  V0.01  device mapping basics
17179 + *  V0.02  added defaults
17180 + *
17181 + */
17182 +
17183 +#include <linux/slab.h>
17184 +#include <linux/rcupdate.h>
17185 +#include <linux/fs.h>
17186 +#include <linux/namei.h>
17187 +#include <linux/hash.h>
17188 +
17189 +#include <asm/errno.h>
17190 +#include <asm/uaccess.h>
17191 +#include <linux/vserver/base.h>
17192 +#include <linux/vserver/debug.h>
17193 +#include <linux/vserver/context.h>
17194 +#include <linux/vserver/device.h>
17195 +#include <linux/vserver/device_cmd.h>
17196 +
17197 +
17198 +#define DMAP_HASH_BITS 4
17199 +
17200 +
17201 +struct vs_mapping {
17202 +       union {
17203 +               struct hlist_node hlist;
17204 +               struct list_head list;
17205 +       } u;
17206 +#define dm_hlist       u.hlist
17207 +#define dm_list                u.list
17208 +       vxid_t xid;
17209 +       dev_t device;
17210 +       struct vx_dmap_target target;
17211 +};
17212 +
17213 +
17214 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
17215 +
17216 +static DEFINE_SPINLOCK(dmap_main_hash_lock);
17217 +
17218 +static struct vx_dmap_target dmap_defaults[2] = {
17219 +       { .flags = DATTR_OPEN },
17220 +       { .flags = DATTR_OPEN },
17221 +};
17222 +
17223 +
17224 +struct kmem_cache *dmap_cachep __read_mostly;
17225 +
17226 +int __init dmap_cache_init(void)
17227 +{
17228 +       dmap_cachep = kmem_cache_create("dmap_cache",
17229 +               sizeof(struct vs_mapping), 0,
17230 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
17231 +       return 0;
17232 +}
17233 +
17234 +__initcall(dmap_cache_init);
17235 +
17236 +
17237 +static inline unsigned int __hashval(dev_t dev, int bits)
17238 +{
17239 +       return hash_long((unsigned long)dev, bits);
17240 +}
17241 +
17242 +
17243 +/*     __hash_mapping()
17244 + *     add the mapping to the hash table
17245 + */
17246 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
17247 +{
17248 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17249 +       struct hlist_head *head, *hash = dmap_main_hash;
17250 +       int device = vdm->device;
17251 +
17252 +       spin_lock(hash_lock);
17253 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
17254 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
17255 +
17256 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
17257 +       hlist_add_head(&vdm->dm_hlist, head);
17258 +       spin_unlock(hash_lock);
17259 +}
17260 +
17261 +
17262 +static inline int __mode_to_default(umode_t mode)
17263 +{
17264 +       switch (mode) {
17265 +       case S_IFBLK:
17266 +               return 0;
17267 +       case S_IFCHR:
17268 +               return 1;
17269 +       default:
17270 +               BUG();
17271 +       }
17272 +}
17273 +
17274 +
17275 +/*     __set_default()
17276 + *     set a default
17277 + */
17278 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
17279 +       struct vx_dmap_target *vdmt)
17280 +{
17281 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17282 +       spin_lock(hash_lock);
17283 +
17284 +       if (vxi)
17285 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
17286 +       else
17287 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
17288 +
17289 +
17290 +       spin_unlock(hash_lock);
17291 +
17292 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
17293 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
17294 +}
17295 +
17296 +
17297 +/*     __remove_default()
17298 + *     remove a default
17299 + */
17300 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
17301 +{
17302 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17303 +       spin_lock(hash_lock);
17304 +
17305 +       if (vxi)
17306 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
17307 +       else    /* remove == reset */
17308 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
17309 +
17310 +       spin_unlock(hash_lock);
17311 +       return 0;
17312 +}
17313 +
17314 +
17315 +/*     __find_mapping()
17316 + *     find a mapping in the hash table
17317 + *
17318 + *     caller must hold hash_lock
17319 + */
17320 +static inline int __find_mapping(vxid_t xid, dev_t device, umode_t mode,
17321 +       struct vs_mapping **local, struct vs_mapping **global)
17322 +{
17323 +       struct hlist_head *hash = dmap_main_hash;
17324 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
17325 +       struct hlist_node *pos;
17326 +       struct vs_mapping *vdm;
17327 +
17328 +       *local = NULL;
17329 +       if (global)
17330 +               *global = NULL;
17331 +
17332 +       hlist_for_each(pos, head) {
17333 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
17334 +
17335 +               if ((vdm->device == device) &&
17336 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
17337 +                       if (vdm->xid == xid) {
17338 +                               *local = vdm;
17339 +                               return 1;
17340 +                       } else if (global && vdm->xid == 0)
17341 +                               *global = vdm;
17342 +               }
17343 +       }
17344 +
17345 +       if (global && *global)
17346 +               return 0;
17347 +       else
17348 +               return -ENOENT;
17349 +}
17350 +
17351 +
17352 +/*     __lookup_mapping()
17353 + *     find a mapping and store the result in target and flags
17354 + */
17355 +static inline int __lookup_mapping(struct vx_info *vxi,
17356 +       dev_t device, dev_t *target, int *flags, umode_t mode)
17357 +{
17358 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17359 +       struct vs_mapping *vdm, *global;
17360 +       struct vx_dmap_target *vdmt;
17361 +       int ret = 0;
17362 +       vxid_t xid = vxi->vx_id;
17363 +       int index;
17364 +
17365 +       spin_lock(hash_lock);
17366 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
17367 +               ret = 1;
17368 +               vdmt = &vdm->target;
17369 +               goto found;
17370 +       }
17371 +
17372 +       index = __mode_to_default(mode);
17373 +       if (vxi && vxi->dmap.targets[index].flags) {
17374 +               ret = 2;
17375 +               vdmt = &vxi->dmap.targets[index];
17376 +       } else if (global) {
17377 +               ret = 3;
17378 +               vdmt = &global->target;
17379 +               goto found;
17380 +       } else {
17381 +               ret = 4;
17382 +               vdmt = &dmap_defaults[index];
17383 +       }
17384 +
17385 +found:
17386 +       if (target && (vdmt->flags & DATTR_REMAP))
17387 +               *target = vdmt->target;
17388 +       else if (target)
17389 +               *target = device;
17390 +       if (flags)
17391 +               *flags = vdmt->flags;
17392 +
17393 +       spin_unlock(hash_lock);
17394 +
17395 +       return ret;
17396 +}
17397 +
17398 +
17399 +/*     __remove_mapping()
17400 + *     remove a mapping from the hash table
17401 + */
17402 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
17403 +       umode_t mode)
17404 +{
17405 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17406 +       struct vs_mapping *vdm = NULL;
17407 +       int ret = 0;
17408 +
17409 +       spin_lock(hash_lock);
17410 +
17411 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
17412 +               NULL);
17413 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
17414 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
17415 +       if (ret < 0)
17416 +               goto out;
17417 +       hlist_del(&vdm->dm_hlist);
17418 +
17419 +out:
17420 +       spin_unlock(hash_lock);
17421 +       if (vdm)
17422 +               kmem_cache_free(dmap_cachep, vdm);
17423 +       return ret;
17424 +}
17425 +
17426 +
17427 +
17428 +int vs_map_device(struct vx_info *vxi,
17429 +       dev_t device, dev_t *target, umode_t mode)
17430 +{
17431 +       int ret, flags = DATTR_MASK;
17432 +
17433 +       if (!vxi) {
17434 +               if (target)
17435 +                       *target = device;
17436 +               goto out;
17437 +       }
17438 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
17439 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
17440 +               device, target ? *target : 0, flags, mode, ret);
17441 +out:
17442 +       return (flags & DATTR_MASK);
17443 +}
17444 +
17445 +
17446 +
17447 +static int do_set_mapping(struct vx_info *vxi,
17448 +       dev_t device, dev_t target, int flags, umode_t mode)
17449 +{
17450 +       if (device) {
17451 +               struct vs_mapping *new;
17452 +
17453 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
17454 +               if (!new)
17455 +                       return -ENOMEM;
17456 +
17457 +               INIT_HLIST_NODE(&new->dm_hlist);
17458 +               new->device = device;
17459 +               new->target.target = target;
17460 +               new->target.flags = flags | mode;
17461 +               new->xid = (vxi ? vxi->vx_id : 0);
17462 +
17463 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
17464 +               __hash_mapping(vxi, new);
17465 +       } else {
17466 +               struct vx_dmap_target new = {
17467 +                       .target = target,
17468 +                       .flags = flags | mode,
17469 +               };
17470 +               __set_default(vxi, mode, &new);
17471 +       }
17472 +       return 0;
17473 +}
17474 +
17475 +
17476 +static int do_unset_mapping(struct vx_info *vxi,
17477 +       dev_t device, dev_t target, int flags, umode_t mode)
17478 +{
17479 +       int ret = -EINVAL;
17480 +
17481 +       if (device) {
17482 +               ret = __remove_mapping(vxi, device, mode);
17483 +               if (ret < 0)
17484 +                       goto out;
17485 +       } else {
17486 +               ret = __remove_default(vxi, mode);
17487 +               if (ret < 0)
17488 +                       goto out;
17489 +       }
17490 +
17491 +out:
17492 +       return ret;
17493 +}
17494 +
17495 +
17496 +static inline int __user_device(const char __user *name, dev_t *dev,
17497 +       umode_t *mode)
17498 +{
17499 +       struct nameidata nd;
17500 +       int ret;
17501 +
17502 +       if (!name) {
17503 +               *dev = 0;
17504 +               return 0;
17505 +       }
17506 +       ret = user_lpath(name, &nd.path);
17507 +       if (ret)
17508 +               return ret;
17509 +       if (nd.path.dentry->d_inode) {
17510 +               *dev = nd.path.dentry->d_inode->i_rdev;
17511 +               *mode = nd.path.dentry->d_inode->i_mode;
17512 +       }
17513 +       path_put(&nd.path);
17514 +       return 0;
17515 +}
17516 +
17517 +static inline int __mapping_mode(dev_t device, dev_t target,
17518 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
17519 +{
17520 +       if (device)
17521 +               *mode = device_mode & S_IFMT;
17522 +       else if (target)
17523 +               *mode = target_mode & S_IFMT;
17524 +       else
17525 +               return -EINVAL;
17526 +
17527 +       /* if both given, device and target mode have to match */
17528 +       if (device && target &&
17529 +               ((device_mode ^ target_mode) & S_IFMT))
17530 +               return -EINVAL;
17531 +       return 0;
17532 +}
17533 +
17534 +
17535 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
17536 +       const char __user *target_path, int flags, int set)
17537 +{
17538 +       dev_t device = ~0, target = ~0;
17539 +       umode_t device_mode = 0, target_mode = 0, mode;
17540 +       int ret;
17541 +
17542 +       ret = __user_device(device_path, &device, &device_mode);
17543 +       if (ret)
17544 +               return ret;
17545 +       ret = __user_device(target_path, &target, &target_mode);
17546 +       if (ret)
17547 +               return ret;
17548 +
17549 +       ret = __mapping_mode(device, target,
17550 +               device_mode, target_mode, &mode);
17551 +       if (ret)
17552 +               return ret;
17553 +
17554 +       if (set)
17555 +               return do_set_mapping(vxi, device, target,
17556 +                       flags, mode);
17557 +       else
17558 +               return do_unset_mapping(vxi, device, target,
17559 +                       flags, mode);
17560 +}
17561 +
17562 +
17563 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
17564 +{
17565 +       struct vcmd_set_mapping_v0 vc_data;
17566 +
17567 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17568 +               return -EFAULT;
17569 +
17570 +       return do_mapping(vxi, vc_data.device, vc_data.target,
17571 +               vc_data.flags, 1);
17572 +}
17573 +
17574 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
17575 +{
17576 +       struct vcmd_set_mapping_v0 vc_data;
17577 +
17578 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17579 +               return -EFAULT;
17580 +
17581 +       return do_mapping(vxi, vc_data.device, vc_data.target,
17582 +               vc_data.flags, 0);
17583 +}
17584 +
17585 +
17586 +#ifdef CONFIG_COMPAT
17587 +
17588 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
17589 +{
17590 +       struct vcmd_set_mapping_v0_x32 vc_data;
17591 +
17592 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17593 +               return -EFAULT;
17594 +
17595 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
17596 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
17597 +}
17598 +
17599 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
17600 +{
17601 +       struct vcmd_set_mapping_v0_x32 vc_data;
17602 +
17603 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17604 +               return -EFAULT;
17605 +
17606 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
17607 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
17608 +}
17609 +
17610 +#endif /* CONFIG_COMPAT */
17611 +
17612 +
17613 diff -NurpP --minimal linux-3.10.33/kernel/vserver/dlimit.c linux-3.10.33-vs2.3.6.8/kernel/vserver/dlimit.c
17614 --- linux-3.10.33/kernel/vserver/dlimit.c       1970-01-01 00:00:00.000000000 +0000
17615 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/dlimit.c     2013-08-22 20:30:00.000000000 +0000
17616 @@ -0,0 +1,528 @@
17617 +/*
17618 + *  linux/kernel/vserver/dlimit.c
17619 + *
17620 + *  Virtual Server: Context Disk Limits
17621 + *
17622 + *  Copyright (C) 2004-2009  Herbert Pötzl
17623 + *
17624 + *  V0.01  initial version
17625 + *  V0.02  compat32 splitup
17626 + *  V0.03  extended interface
17627 + *
17628 + */
17629 +
17630 +#include <linux/statfs.h>
17631 +#include <linux/sched.h>
17632 +#include <linux/namei.h>
17633 +#include <linux/vs_tag.h>
17634 +#include <linux/vs_dlimit.h>
17635 +#include <linux/vserver/dlimit_cmd.h>
17636 +#include <linux/slab.h>
17637 +// #include <linux/gfp.h>
17638 +
17639 +#include <asm/uaccess.h>
17640 +
17641 +/*     __alloc_dl_info()
17642 +
17643 +       * allocate an initialized dl_info struct
17644 +       * doesn't make it visible (hash)                        */
17645 +
17646 +static struct dl_info *__alloc_dl_info(struct super_block *sb, vtag_t tag)
17647 +{
17648 +       struct dl_info *new = NULL;
17649 +
17650 +       vxdprintk(VXD_CBIT(dlim, 5),
17651 +               "alloc_dl_info(%p,%d)*", sb, tag);
17652 +
17653 +       /* would this benefit from a slab cache? */
17654 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
17655 +       if (!new)
17656 +               return 0;
17657 +
17658 +       memset(new, 0, sizeof(struct dl_info));
17659 +       new->dl_tag = tag;
17660 +       new->dl_sb = sb;
17661 +       // INIT_RCU_HEAD(&new->dl_rcu);
17662 +       INIT_HLIST_NODE(&new->dl_hlist);
17663 +       spin_lock_init(&new->dl_lock);
17664 +       atomic_set(&new->dl_refcnt, 0);
17665 +       atomic_set(&new->dl_usecnt, 0);
17666 +
17667 +       /* rest of init goes here */
17668 +
17669 +       vxdprintk(VXD_CBIT(dlim, 4),
17670 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
17671 +       return new;
17672 +}
17673 +
17674 +/*     __dealloc_dl_info()
17675 +
17676 +       * final disposal of dl_info                             */
17677 +
17678 +static void __dealloc_dl_info(struct dl_info *dli)
17679 +{
17680 +       vxdprintk(VXD_CBIT(dlim, 4),
17681 +               "dealloc_dl_info(%p)", dli);
17682 +
17683 +       dli->dl_hlist.next = LIST_POISON1;
17684 +       dli->dl_tag = -1;
17685 +       dli->dl_sb = 0;
17686 +
17687 +       BUG_ON(atomic_read(&dli->dl_usecnt));
17688 +       BUG_ON(atomic_read(&dli->dl_refcnt));
17689 +
17690 +       kfree(dli);
17691 +}
17692 +
17693 +
17694 +/*     hash table for dl_info hash */
17695 +
17696 +#define DL_HASH_SIZE   13
17697 +
17698 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
17699 +
17700 +static DEFINE_SPINLOCK(dl_info_hash_lock);
17701 +
17702 +
17703 +static inline unsigned int __hashval(struct super_block *sb, vtag_t tag)
17704 +{
17705 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
17706 +}
17707 +
17708 +
17709 +
17710 +/*     __hash_dl_info()
17711 +
17712 +       * add the dli to the global hash table
17713 +       * requires the hash_lock to be held                     */
17714 +
17715 +static inline void __hash_dl_info(struct dl_info *dli)
17716 +{
17717 +       struct hlist_head *head;
17718 +
17719 +       vxdprintk(VXD_CBIT(dlim, 6),
17720 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
17721 +       get_dl_info(dli);
17722 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
17723 +       hlist_add_head_rcu(&dli->dl_hlist, head);
17724 +}
17725 +
17726 +/*     __unhash_dl_info()
17727 +
17728 +       * remove the dli from the global hash table
17729 +       * requires the hash_lock to be held                     */
17730 +
17731 +static inline void __unhash_dl_info(struct dl_info *dli)
17732 +{
17733 +       vxdprintk(VXD_CBIT(dlim, 6),
17734 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
17735 +       hlist_del_rcu(&dli->dl_hlist);
17736 +       put_dl_info(dli);
17737 +}
17738 +
17739 +
17740 +/*     __lookup_dl_info()
17741 +
17742 +       * requires the rcu_read_lock()
17743 +       * doesn't increment the dl_refcnt                       */
17744 +
17745 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, vtag_t tag)
17746 +{
17747 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
17748 +       struct dl_info *dli;
17749 +
17750 +       hlist_for_each_entry_rcu(dli, head, dl_hlist) {
17751 +               if (dli->dl_tag == tag && dli->dl_sb == sb)
17752 +                       return dli;
17753 +       }
17754 +       return NULL;
17755 +}
17756 +
17757 +
17758 +struct dl_info *locate_dl_info(struct super_block *sb, vtag_t tag)
17759 +{
17760 +       struct dl_info *dli;
17761 +
17762 +       rcu_read_lock();
17763 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
17764 +       vxdprintk(VXD_CBIT(dlim, 7),
17765 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
17766 +       rcu_read_unlock();
17767 +       return dli;
17768 +}
17769 +
17770 +void rcu_free_dl_info(struct rcu_head *head)
17771 +{
17772 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
17773 +       int usecnt, refcnt;
17774 +
17775 +       BUG_ON(!dli || !head);
17776 +
17777 +       usecnt = atomic_read(&dli->dl_usecnt);
17778 +       BUG_ON(usecnt < 0);
17779 +
17780 +       refcnt = atomic_read(&dli->dl_refcnt);
17781 +       BUG_ON(refcnt < 0);
17782 +
17783 +       vxdprintk(VXD_CBIT(dlim, 3),
17784 +               "rcu_free_dl_info(%p)", dli);
17785 +       if (!usecnt)
17786 +               __dealloc_dl_info(dli);
17787 +       else
17788 +               printk("!!! rcu didn't free\n");
17789 +}
17790 +
17791 +
17792 +
17793 +
17794 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
17795 +       uint32_t flags, int add)
17796 +{
17797 +       struct path path;
17798 +       int ret;
17799 +
17800 +       ret = user_lpath(name, &path);
17801 +       if (!ret) {
17802 +               struct super_block *sb;
17803 +               struct dl_info *dli;
17804 +
17805 +               ret = -EINVAL;
17806 +               if (!path.dentry->d_inode)
17807 +                       goto out_release;
17808 +               if (!(sb = path.dentry->d_inode->i_sb))
17809 +                       goto out_release;
17810 +
17811 +               if (add) {
17812 +                       dli = __alloc_dl_info(sb, id);
17813 +                       spin_lock(&dl_info_hash_lock);
17814 +
17815 +                       ret = -EEXIST;
17816 +                       if (__lookup_dl_info(sb, id))
17817 +                               goto out_unlock;
17818 +                       __hash_dl_info(dli);
17819 +                       dli = NULL;
17820 +               } else {
17821 +                       spin_lock(&dl_info_hash_lock);
17822 +                       dli = __lookup_dl_info(sb, id);
17823 +
17824 +                       ret = -ESRCH;
17825 +                       if (!dli)
17826 +                               goto out_unlock;
17827 +                       __unhash_dl_info(dli);
17828 +               }
17829 +               ret = 0;
17830 +       out_unlock:
17831 +               spin_unlock(&dl_info_hash_lock);
17832 +               if (add && dli)
17833 +                       __dealloc_dl_info(dli);
17834 +       out_release:
17835 +               path_put(&path);
17836 +       }
17837 +       return ret;
17838 +}
17839 +
17840 +int vc_add_dlimit(uint32_t id, void __user *data)
17841 +{
17842 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
17843 +
17844 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17845 +               return -EFAULT;
17846 +
17847 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
17848 +}
17849 +
17850 +int vc_rem_dlimit(uint32_t id, void __user *data)
17851 +{
17852 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
17853 +
17854 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17855 +               return -EFAULT;
17856 +
17857 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
17858 +}
17859 +
17860 +#ifdef CONFIG_COMPAT
17861 +
17862 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
17863 +{
17864 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
17865 +
17866 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17867 +               return -EFAULT;
17868 +
17869 +       return do_addrem_dlimit(id,
17870 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
17871 +}
17872 +
17873 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
17874 +{
17875 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
17876 +
17877 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17878 +               return -EFAULT;
17879 +
17880 +       return do_addrem_dlimit(id,
17881 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
17882 +}
17883 +
17884 +#endif /* CONFIG_COMPAT */
17885 +
17886 +
17887 +static inline
17888 +int do_set_dlimit(uint32_t id, const char __user *name,
17889 +       uint32_t space_used, uint32_t space_total,
17890 +       uint32_t inodes_used, uint32_t inodes_total,
17891 +       uint32_t reserved, uint32_t flags)
17892 +{
17893 +       struct path path;
17894 +       int ret;
17895 +
17896 +       ret = user_lpath(name, &path);
17897 +       if (!ret) {
17898 +               struct super_block *sb;
17899 +               struct dl_info *dli;
17900 +
17901 +               ret = -EINVAL;
17902 +               if (!path.dentry->d_inode)
17903 +                       goto out_release;
17904 +               if (!(sb = path.dentry->d_inode->i_sb))
17905 +                       goto out_release;
17906 +
17907 +               /* sanity checks */
17908 +               if ((reserved != CDLIM_KEEP &&
17909 +                       reserved > 100) ||
17910 +                       (inodes_used != CDLIM_KEEP &&
17911 +                       inodes_used > inodes_total) ||
17912 +                       (space_used != CDLIM_KEEP &&
17913 +                       space_used > space_total))
17914 +                       goto out_release;
17915 +
17916 +               ret = -ESRCH;
17917 +               dli = locate_dl_info(sb, id);
17918 +               if (!dli)
17919 +                       goto out_release;
17920 +
17921 +               spin_lock(&dli->dl_lock);
17922 +
17923 +               if (inodes_used != CDLIM_KEEP)
17924 +                       dli->dl_inodes_used = inodes_used;
17925 +               if (inodes_total != CDLIM_KEEP)
17926 +                       dli->dl_inodes_total = inodes_total;
17927 +               if (space_used != CDLIM_KEEP)
17928 +                       dli->dl_space_used = dlimit_space_32to64(
17929 +                               space_used, flags, DLIMS_USED);
17930 +
17931 +               if (space_total == CDLIM_INFINITY)
17932 +                       dli->dl_space_total = DLIM_INFINITY;
17933 +               else if (space_total != CDLIM_KEEP)
17934 +                       dli->dl_space_total = dlimit_space_32to64(
17935 +                               space_total, flags, DLIMS_TOTAL);
17936 +
17937 +               if (reserved != CDLIM_KEEP)
17938 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
17939 +
17940 +               spin_unlock(&dli->dl_lock);
17941 +
17942 +               put_dl_info(dli);
17943 +               ret = 0;
17944 +
17945 +       out_release:
17946 +               path_put(&path);
17947 +       }
17948 +       return ret;
17949 +}
17950 +
17951 +int vc_set_dlimit(uint32_t id, void __user *data)
17952 +{
17953 +       struct vcmd_ctx_dlimit_v0 vc_data;
17954 +
17955 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17956 +               return -EFAULT;
17957 +
17958 +       return do_set_dlimit(id, vc_data.name,
17959 +               vc_data.space_used, vc_data.space_total,
17960 +               vc_data.inodes_used, vc_data.inodes_total,
17961 +               vc_data.reserved, vc_data.flags);
17962 +}
17963 +
17964 +#ifdef CONFIG_COMPAT
17965 +
17966 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
17967 +{
17968 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
17969 +
17970 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17971 +               return -EFAULT;
17972 +
17973 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
17974 +               vc_data.space_used, vc_data.space_total,
17975 +               vc_data.inodes_used, vc_data.inodes_total,
17976 +               vc_data.reserved, vc_data.flags);
17977 +}
17978 +
17979 +#endif /* CONFIG_COMPAT */
17980 +
17981 +
17982 +static inline
17983 +int do_get_dlimit(uint32_t id, const char __user *name,
17984 +       uint32_t *space_used, uint32_t *space_total,
17985 +       uint32_t *inodes_used, uint32_t *inodes_total,
17986 +       uint32_t *reserved, uint32_t *flags)
17987 +{
17988 +       struct path path;
17989 +       int ret;
17990 +
17991 +       ret = user_lpath(name, &path);
17992 +       if (!ret) {
17993 +               struct super_block *sb;
17994 +               struct dl_info *dli;
17995 +
17996 +               ret = -EINVAL;
17997 +               if (!path.dentry->d_inode)
17998 +                       goto out_release;
17999 +               if (!(sb = path.dentry->d_inode->i_sb))
18000 +                       goto out_release;
18001 +
18002 +               ret = -ESRCH;
18003 +               dli = locate_dl_info(sb, id);
18004 +               if (!dli)
18005 +                       goto out_release;
18006 +
18007 +               spin_lock(&dli->dl_lock);
18008 +               *inodes_used = dli->dl_inodes_used;
18009 +               *inodes_total = dli->dl_inodes_total;
18010 +
18011 +               *space_used = dlimit_space_64to32(
18012 +                       dli->dl_space_used, flags, DLIMS_USED);
18013 +
18014 +               if (dli->dl_space_total == DLIM_INFINITY)
18015 +                       *space_total = CDLIM_INFINITY;
18016 +               else
18017 +                       *space_total = dlimit_space_64to32(
18018 +                               dli->dl_space_total, flags, DLIMS_TOTAL);
18019 +
18020 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
18021 +               spin_unlock(&dli->dl_lock);
18022 +
18023 +               put_dl_info(dli);
18024 +               ret = -EFAULT;
18025 +
18026 +               ret = 0;
18027 +       out_release:
18028 +               path_put(&path);
18029 +       }
18030 +       return ret;
18031 +}
18032 +
18033 +
18034 +int vc_get_dlimit(uint32_t id, void __user *data)
18035 +{
18036 +       struct vcmd_ctx_dlimit_v0 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, vc_data.name,
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 +#ifdef CONFIG_COMPAT
18055 +
18056 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
18057 +{
18058 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18059 +       int ret;
18060 +
18061 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18062 +               return -EFAULT;
18063 +
18064 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
18065 +               &vc_data.space_used, &vc_data.space_total,
18066 +               &vc_data.inodes_used, &vc_data.inodes_total,
18067 +               &vc_data.reserved, &vc_data.flags);
18068 +       if (ret)
18069 +               return ret;
18070 +
18071 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18072 +               return -EFAULT;
18073 +       return 0;
18074 +}
18075 +
18076 +#endif /* CONFIG_COMPAT */
18077 +
18078 +
18079 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
18080 +{
18081 +       struct dl_info *dli;
18082 +       __u64 blimit, bfree, bavail;
18083 +       __u32 ifree;
18084 +
18085 +       dli = locate_dl_info(sb, dx_current_tag());
18086 +       if (!dli)
18087 +               return;
18088 +
18089 +       spin_lock(&dli->dl_lock);
18090 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
18091 +               goto no_ilim;
18092 +
18093 +       /* reduce max inodes available to limit */
18094 +       if (buf->f_files > dli->dl_inodes_total)
18095 +               buf->f_files = dli->dl_inodes_total;
18096 +
18097 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
18098 +       /* reduce free inodes to min */
18099 +       if (ifree < buf->f_ffree)
18100 +               buf->f_ffree = ifree;
18101 +
18102 +no_ilim:
18103 +       if (dli->dl_space_total == DLIM_INFINITY)
18104 +               goto no_blim;
18105 +
18106 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
18107 +
18108 +       if (dli->dl_space_total < dli->dl_space_used)
18109 +               bfree = 0;
18110 +       else
18111 +               bfree = (dli->dl_space_total - dli->dl_space_used)
18112 +                       >> sb->s_blocksize_bits;
18113 +
18114 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
18115 +       if (bavail < dli->dl_space_used)
18116 +               bavail = 0;
18117 +       else
18118 +               bavail = (bavail - dli->dl_space_used)
18119 +                       >> sb->s_blocksize_bits;
18120 +
18121 +       /* reduce max space available to limit */
18122 +       if (buf->f_blocks > blimit)
18123 +               buf->f_blocks = blimit;
18124 +
18125 +       /* reduce free space to min */
18126 +       if (bfree < buf->f_bfree)
18127 +               buf->f_bfree = bfree;
18128 +
18129 +       /* reduce avail space to min */
18130 +       if (bavail < buf->f_bavail)
18131 +               buf->f_bavail = bavail;
18132 +
18133 +no_blim:
18134 +       spin_unlock(&dli->dl_lock);
18135 +       put_dl_info(dli);
18136 +
18137 +       return;
18138 +}
18139 +
18140 +#include <linux/module.h>
18141 +
18142 +EXPORT_SYMBOL_GPL(locate_dl_info);
18143 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
18144 +
18145 diff -NurpP --minimal linux-3.10.33/kernel/vserver/helper.c linux-3.10.33-vs2.3.6.8/kernel/vserver/helper.c
18146 --- linux-3.10.33/kernel/vserver/helper.c       1970-01-01 00:00:00.000000000 +0000
18147 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/helper.c     2013-08-23 00:55:48.000000000 +0000
18148 @@ -0,0 +1,242 @@
18149 +/*
18150 + *  linux/kernel/vserver/helper.c
18151 + *
18152 + *  Virtual Context Support
18153 + *
18154 + *  Copyright (C) 2004-2007  Herbert Pötzl
18155 + *
18156 + *  V0.01  basic helper
18157 + *
18158 + */
18159 +
18160 +#include <linux/kmod.h>
18161 +#include <linux/reboot.h>
18162 +#include <linux/vs_context.h>
18163 +#include <linux/vs_network.h>
18164 +#include <linux/vserver/signal.h>
18165 +
18166 +
18167 +char vshelper_path[255] = "/sbin/vshelper";
18168 +
18169 +static int vshelper_init(struct subprocess_info *info, struct cred *new_cred)
18170 +{
18171 +       current->flags &= ~PF_NO_SETAFFINITY;
18172 +       return 0;
18173 +}
18174 +
18175 +static int vs_call_usermodehelper(char *path, char **argv, char **envp, int wait)
18176 +{
18177 +       struct subprocess_info *info;
18178 +       gfp_t gfp_mask = (wait == UMH_NO_WAIT) ? GFP_ATOMIC : GFP_KERNEL;
18179 +
18180 +       info = call_usermodehelper_setup(path, argv, envp, gfp_mask,
18181 +                                        vshelper_init, NULL, NULL);
18182 +       if (info == NULL)
18183 +               return -ENOMEM;
18184 +
18185 +       return call_usermodehelper_exec(info, wait);
18186 +}
18187 +
18188 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
18189 +{
18190 +       int ret;
18191 +
18192 +       if ((ret = vs_call_usermodehelper(name, argv, envp,
18193 +               sync ? UMH_WAIT_PROC : UMH_WAIT_EXEC))) {
18194 +               printk(KERN_WARNING "%s: (%s %s) returned %s with %d\n",
18195 +                       name, argv[1], argv[2],
18196 +                       sync ? "sync" : "async", ret);
18197 +       }
18198 +       vxdprintk(VXD_CBIT(switch, 4),
18199 +               "%s: (%s %s) returned %s with %d",
18200 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
18201 +       return ret;
18202 +}
18203 +
18204 +/*
18205 + *      vshelper path is set via /proc/sys
18206 + *      invoked by vserver sys_reboot(), with
18207 + *      the following arguments
18208 + *
18209 + *      argv [0] = vshelper_path;
18210 + *      argv [1] = action: "restart", "halt", "poweroff", ...
18211 + *      argv [2] = context identifier
18212 + *
18213 + *      envp [*] = type-specific parameters
18214 + */
18215 +
18216 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
18217 +{
18218 +       char id_buf[8], cmd_buf[16];
18219 +       char uid_buf[16], pid_buf[16];
18220 +       int ret;
18221 +
18222 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18223 +       char *envp[] = {"HOME=/", "TERM=linux",
18224 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
18225 +                       uid_buf, pid_buf, cmd_buf, 0};
18226 +
18227 +       if (vx_info_state(vxi, VXS_HELPER))
18228 +               return -EAGAIN;
18229 +       vxi->vx_state |= VXS_HELPER;
18230 +
18231 +       snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
18232 +
18233 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18234 +       snprintf(uid_buf, sizeof(uid_buf), "VS_UID=%d",
18235 +               from_kuid(&init_user_ns, current_uid()));
18236 +       snprintf(pid_buf, sizeof(pid_buf), "VS_PID=%d", current->pid);
18237 +
18238 +       switch (cmd) {
18239 +       case LINUX_REBOOT_CMD_RESTART:
18240 +               argv[1] = "restart";
18241 +               break;
18242 +
18243 +       case LINUX_REBOOT_CMD_HALT:
18244 +               argv[1] = "halt";
18245 +               break;
18246 +
18247 +       case LINUX_REBOOT_CMD_POWER_OFF:
18248 +               argv[1] = "poweroff";
18249 +               break;
18250 +
18251 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
18252 +               argv[1] = "swsusp";
18253 +               break;
18254 +
18255 +       case LINUX_REBOOT_CMD_OOM:
18256 +               argv[1] = "oom";
18257 +               break;
18258 +
18259 +       default:
18260 +               vxi->vx_state &= ~VXS_HELPER;
18261 +               return 0;
18262 +       }
18263 +
18264 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
18265 +       vxi->vx_state &= ~VXS_HELPER;
18266 +       __wakeup_vx_info(vxi);
18267 +       return (ret) ? -EPERM : 0;
18268 +}
18269 +
18270 +
18271 +long vs_reboot(unsigned int cmd, void __user *arg)
18272 +{
18273 +       struct vx_info *vxi = current_vx_info();
18274 +       long ret = 0;
18275 +
18276 +       vxdprintk(VXD_CBIT(misc, 5),
18277 +               "vs_reboot(%p[#%d],%u)",
18278 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18279 +
18280 +       ret = vs_reboot_helper(vxi, cmd, arg);
18281 +       if (ret)
18282 +               return ret;
18283 +
18284 +       vxi->reboot_cmd = cmd;
18285 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18286 +               switch (cmd) {
18287 +               case LINUX_REBOOT_CMD_RESTART:
18288 +               case LINUX_REBOOT_CMD_HALT:
18289 +               case LINUX_REBOOT_CMD_POWER_OFF:
18290 +                       vx_info_kill(vxi, 0, SIGKILL);
18291 +                       vx_info_kill(vxi, 1, SIGKILL);
18292 +               default:
18293 +                       break;
18294 +               }
18295 +       }
18296 +       return 0;
18297 +}
18298 +
18299 +long vs_oom_action(unsigned int cmd)
18300 +{
18301 +       struct vx_info *vxi = current_vx_info();
18302 +       long ret = 0;
18303 +
18304 +       vxdprintk(VXD_CBIT(misc, 5),
18305 +               "vs_oom_action(%p[#%d],%u)",
18306 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18307 +
18308 +       ret = vs_reboot_helper(vxi, cmd, NULL);
18309 +       if (ret)
18310 +               return ret;
18311 +
18312 +       vxi->reboot_cmd = cmd;
18313 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18314 +               vx_info_kill(vxi, 0, SIGKILL);
18315 +               vx_info_kill(vxi, 1, SIGKILL);
18316 +       }
18317 +       return 0;
18318 +}
18319 +
18320 +/*
18321 + *      argv [0] = vshelper_path;
18322 + *      argv [1] = action: "startup", "shutdown"
18323 + *      argv [2] = context identifier
18324 + *
18325 + *      envp [*] = type-specific parameters
18326 + */
18327 +
18328 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
18329 +{
18330 +       char id_buf[8], cmd_buf[16];
18331 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18332 +       char *envp[] = {"HOME=/", "TERM=linux",
18333 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18334 +
18335 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
18336 +               return 0;
18337 +
18338 +       snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
18339 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18340 +
18341 +       switch (cmd) {
18342 +       case VSC_STARTUP:
18343 +               argv[1] = "startup";
18344 +               break;
18345 +       case VSC_SHUTDOWN:
18346 +               argv[1] = "shutdown";
18347 +               break;
18348 +       default:
18349 +               return 0;
18350 +       }
18351 +
18352 +       return do_vshelper(vshelper_path, argv, envp, 1);
18353 +}
18354 +
18355 +
18356 +/*
18357 + *      argv [0] = vshelper_path;
18358 + *      argv [1] = action: "netup", "netdown"
18359 + *      argv [2] = context identifier
18360 + *
18361 + *      envp [*] = type-specific parameters
18362 + */
18363 +
18364 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
18365 +{
18366 +       char id_buf[8], cmd_buf[16];
18367 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18368 +       char *envp[] = {"HOME=/", "TERM=linux",
18369 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18370 +
18371 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
18372 +               return 0;
18373 +
18374 +       snprintf(id_buf, sizeof(id_buf), "%d", nxi->nx_id);
18375 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18376 +
18377 +       switch (cmd) {
18378 +       case VSC_NETUP:
18379 +               argv[1] = "netup";
18380 +               break;
18381 +       case VSC_NETDOWN:
18382 +               argv[1] = "netdown";
18383 +               break;
18384 +       default:
18385 +               return 0;
18386 +       }
18387 +
18388 +       return do_vshelper(vshelper_path, argv, envp, 1);
18389 +}
18390 +
18391 diff -NurpP --minimal linux-3.10.33/kernel/vserver/history.c linux-3.10.33-vs2.3.6.8/kernel/vserver/history.c
18392 --- linux-3.10.33/kernel/vserver/history.c      1970-01-01 00:00:00.000000000 +0000
18393 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/history.c    2013-08-22 20:30:00.000000000 +0000
18394 @@ -0,0 +1,258 @@
18395 +/*
18396 + *  kernel/vserver/history.c
18397 + *
18398 + *  Virtual Context History Backtrace
18399 + *
18400 + *  Copyright (C) 2004-2007  Herbert Pötzl
18401 + *
18402 + *  V0.01  basic structure
18403 + *  V0.02  hash/unhash and trace
18404 + *  V0.03  preemption fixes
18405 + *
18406 + */
18407 +
18408 +#include <linux/module.h>
18409 +#include <asm/uaccess.h>
18410 +
18411 +#include <linux/vserver/context.h>
18412 +#include <linux/vserver/debug.h>
18413 +#include <linux/vserver/debug_cmd.h>
18414 +#include <linux/vserver/history.h>
18415 +
18416 +
18417 +#ifdef CONFIG_VSERVER_HISTORY
18418 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
18419 +#else
18420 +#define VXH_SIZE       64
18421 +#endif
18422 +
18423 +struct _vx_history {
18424 +       unsigned int counter;
18425 +
18426 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
18427 +};
18428 +
18429 +
18430 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
18431 +
18432 +unsigned volatile int vxh_active = 1;
18433 +
18434 +static atomic_t sequence = ATOMIC_INIT(0);
18435 +
18436 +
18437 +/*     vxh_advance()
18438 +
18439 +       * requires disabled preemption                          */
18440 +
18441 +struct _vx_hist_entry *vxh_advance(void *loc)
18442 +{
18443 +       unsigned int cpu = smp_processor_id();
18444 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
18445 +       struct _vx_hist_entry *entry;
18446 +       unsigned int index;
18447 +
18448 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
18449 +       entry = &hist->entry[index];
18450 +
18451 +       entry->seq = atomic_inc_return(&sequence);
18452 +       entry->loc = loc;
18453 +       return entry;
18454 +}
18455 +
18456 +EXPORT_SYMBOL_GPL(vxh_advance);
18457 +
18458 +
18459 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
18460 +
18461 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
18462 +
18463 +
18464 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
18465 +
18466 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
18467 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
18468 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
18469 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
18470 +
18471 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
18472 +{
18473 +       switch (e->type) {
18474 +       case VXH_THROW_OOPS:
18475 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
18476 +               break;
18477 +
18478 +       case VXH_GET_VX_INFO:
18479 +       case VXH_PUT_VX_INFO:
18480 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
18481 +                       VXH_LOC_ARGS(e),
18482 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
18483 +                       VXH_VXI_ARGS(e));
18484 +               break;
18485 +
18486 +       case VXH_INIT_VX_INFO:
18487 +       case VXH_SET_VX_INFO:
18488 +       case VXH_CLR_VX_INFO:
18489 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
18490 +                       VXH_LOC_ARGS(e),
18491 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
18492 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
18493 +                       VXH_VXI_ARGS(e), e->sc.data);
18494 +               break;
18495 +
18496 +       case VXH_CLAIM_VX_INFO:
18497 +       case VXH_RELEASE_VX_INFO:
18498 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
18499 +                       VXH_LOC_ARGS(e),
18500 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
18501 +                       VXH_VXI_ARGS(e), e->sc.data);
18502 +               break;
18503 +
18504 +       case VXH_ALLOC_VX_INFO:
18505 +       case VXH_DEALLOC_VX_INFO:
18506 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
18507 +                       VXH_LOC_ARGS(e),
18508 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
18509 +                       VXH_VXI_ARGS(e));
18510 +               break;
18511 +
18512 +       case VXH_HASH_VX_INFO:
18513 +       case VXH_UNHASH_VX_INFO:
18514 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
18515 +                       VXH_LOC_ARGS(e),
18516 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
18517 +                       VXH_VXI_ARGS(e));
18518 +               break;
18519 +
18520 +       case VXH_LOC_VX_INFO:
18521 +       case VXH_LOOKUP_VX_INFO:
18522 +       case VXH_CREATE_VX_INFO:
18523 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
18524 +                       VXH_LOC_ARGS(e),
18525 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
18526 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
18527 +                       e->ll.arg, VXH_VXI_ARGS(e));
18528 +               break;
18529 +       }
18530 +}
18531 +
18532 +static void __vxh_dump_history(void)
18533 +{
18534 +       unsigned int i, cpu;
18535 +
18536 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
18537 +               atomic_read(&sequence), NR_CPUS);
18538 +
18539 +       for (i = 0; i < VXH_SIZE; i++) {
18540 +               for_each_online_cpu(cpu) {
18541 +                       struct _vx_history *hist =
18542 +                               &per_cpu(vx_history_buffer, cpu);
18543 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
18544 +                       struct _vx_hist_entry *entry = &hist->entry[index];
18545 +
18546 +                       vxh_dump_entry(entry, cpu);
18547 +               }
18548 +       }
18549 +}
18550 +
18551 +void   vxh_dump_history(void)
18552 +{
18553 +       vxh_active = 0;
18554 +#ifdef CONFIG_SMP
18555 +       local_irq_enable();
18556 +       smp_send_stop();
18557 +       local_irq_disable();
18558 +#endif
18559 +       __vxh_dump_history();
18560 +}
18561 +
18562 +
18563 +/* vserver syscall commands below here */
18564 +
18565 +
18566 +int vc_dump_history(uint32_t id)
18567 +{
18568 +       vxh_active = 0;
18569 +       __vxh_dump_history();
18570 +       vxh_active = 1;
18571 +
18572 +       return 0;
18573 +}
18574 +
18575 +
18576 +int do_read_history(struct __user _vx_hist_entry *data,
18577 +       int cpu, uint32_t *index, uint32_t *count)
18578 +{
18579 +       int pos, ret = 0;
18580 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
18581 +       int end = hist->counter;
18582 +       int start = end - VXH_SIZE + 2;
18583 +       int idx = *index;
18584 +
18585 +       /* special case: get current pos */
18586 +       if (!*count) {
18587 +               *index = end;
18588 +               return 0;
18589 +       }
18590 +
18591 +       /* have we lost some data? */
18592 +       if (idx < start)
18593 +               idx = start;
18594 +
18595 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
18596 +               struct _vx_hist_entry *entry =
18597 +                       &hist->entry[idx % VXH_SIZE];
18598 +
18599 +               /* send entry to userspace */
18600 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
18601 +               if (ret)
18602 +                       break;
18603 +       }
18604 +       /* save new index and count */
18605 +       *index = idx;
18606 +       *count = pos;
18607 +       return ret ? ret : (*index < end);
18608 +}
18609 +
18610 +int vc_read_history(uint32_t id, void __user *data)
18611 +{
18612 +       struct vcmd_read_history_v0 vc_data;
18613 +       int ret;
18614 +
18615 +       if (id >= NR_CPUS)
18616 +               return -EINVAL;
18617 +
18618 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18619 +               return -EFAULT;
18620 +
18621 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
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 +#ifdef CONFIG_COMPAT
18630 +
18631 +int vc_read_history_x32(uint32_t id, void __user *data)
18632 +{
18633 +       struct vcmd_read_history_v0_x32 vc_data;
18634 +       int ret;
18635 +
18636 +       if (id >= NR_CPUS)
18637 +               return -EINVAL;
18638 +
18639 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18640 +               return -EFAULT;
18641 +
18642 +       ret = do_read_history((struct __user _vx_hist_entry *)
18643 +               compat_ptr(vc_data.data_ptr),
18644 +               id, &vc_data.index, &vc_data.count);
18645 +
18646 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18647 +               return -EFAULT;
18648 +       return ret;
18649 +}
18650 +
18651 +#endif /* CONFIG_COMPAT */
18652 +
18653 diff -NurpP --minimal linux-3.10.33/kernel/vserver/inet.c linux-3.10.33-vs2.3.6.8/kernel/vserver/inet.c
18654 --- linux-3.10.33/kernel/vserver/inet.c 1970-01-01 00:00:00.000000000 +0000
18655 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/inet.c       2013-08-22 20:30:00.000000000 +0000
18656 @@ -0,0 +1,236 @@
18657 +
18658 +#include <linux/in.h>
18659 +#include <linux/inetdevice.h>
18660 +#include <linux/export.h>
18661 +#include <linux/vs_inet.h>
18662 +#include <linux/vs_inet6.h>
18663 +#include <linux/vserver/debug.h>
18664 +#include <net/route.h>
18665 +#include <net/addrconf.h>
18666 +
18667 +
18668 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
18669 +{
18670 +       int ret = 0;
18671 +
18672 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
18673 +               ret = 1;
18674 +       else {
18675 +               struct nx_addr_v4 *ptr;
18676 +               unsigned long irqflags;
18677 +
18678 +               spin_lock_irqsave(&nxi1->addr_lock, irqflags);
18679 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
18680 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
18681 +                               ret = 1;
18682 +                               break;
18683 +                       }
18684 +               }
18685 +               spin_unlock_irqrestore(&nxi1->addr_lock, irqflags);
18686 +       }
18687 +
18688 +       vxdprintk(VXD_CBIT(net, 2),
18689 +               "nx_v4_addr_conflict(%p,%p): %d",
18690 +               nxi1, nxi2, ret);
18691 +
18692 +       return ret;
18693 +}
18694 +
18695 +
18696 +#ifdef CONFIG_IPV6
18697 +
18698 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
18699 +{
18700 +       int ret = 0;
18701 +
18702 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
18703 +               ret = 1;
18704 +       else {
18705 +               struct nx_addr_v6 *ptr;
18706 +               unsigned long irqflags;
18707 +
18708 +               spin_lock_irqsave(&nxi1->addr_lock, irqflags);
18709 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
18710 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
18711 +                               ret = 1;
18712 +                               break;
18713 +                       }
18714 +               }
18715 +               spin_unlock_irqrestore(&nxi1->addr_lock, irqflags);
18716 +       }
18717 +
18718 +       vxdprintk(VXD_CBIT(net, 2),
18719 +               "nx_v6_addr_conflict(%p,%p): %d",
18720 +               nxi1, nxi2, ret);
18721 +
18722 +       return ret;
18723 +}
18724 +
18725 +#endif
18726 +
18727 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18728 +{
18729 +       struct in_device *in_dev;
18730 +       struct in_ifaddr **ifap;
18731 +       struct in_ifaddr *ifa;
18732 +       int ret = 0;
18733 +
18734 +       if (!dev)
18735 +               goto out;
18736 +       in_dev = in_dev_get(dev);
18737 +       if (!in_dev)
18738 +               goto out;
18739 +
18740 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
18741 +               ifap = &ifa->ifa_next) {
18742 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
18743 +                       ret = 1;
18744 +                       break;
18745 +               }
18746 +       }
18747 +       in_dev_put(in_dev);
18748 +out:
18749 +       return ret;
18750 +}
18751 +
18752 +
18753 +#ifdef CONFIG_IPV6
18754 +
18755 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18756 +{
18757 +       struct inet6_dev *in_dev;
18758 +       struct inet6_ifaddr *ifa;
18759 +       int ret = 0;
18760 +
18761 +       if (!dev)
18762 +               goto out;
18763 +       in_dev = in6_dev_get(dev);
18764 +       if (!in_dev)
18765 +               goto out;
18766 +
18767 +       // for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
18768 +       list_for_each_entry(ifa, &in_dev->addr_list, if_list) {
18769 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
18770 +                       ret = 1;
18771 +                       break;
18772 +               }
18773 +       }
18774 +       in6_dev_put(in_dev);
18775 +out:
18776 +       return ret;
18777 +}
18778 +
18779 +#endif
18780 +
18781 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18782 +{
18783 +       int ret = 1;
18784 +
18785 +       if (!nxi)
18786 +               goto out;
18787 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
18788 +               goto out;
18789 +#ifdef CONFIG_IPV6
18790 +       ret = 2;
18791 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
18792 +               goto out;
18793 +#endif
18794 +       ret = 0;
18795 +out:
18796 +       vxdprintk(VXD_CBIT(net, 3),
18797 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
18798 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
18799 +       return ret;
18800 +}
18801 +
18802 +struct rtable *ip_v4_find_src(struct net *net, struct nx_info *nxi,
18803 +       struct flowi4 *fl4)
18804 +{
18805 +       struct rtable *rt;
18806 +
18807 +       if (!nxi)
18808 +               return NULL;
18809 +
18810 +       /* FIXME: handle lback only case */
18811 +       if (!NX_IPV4(nxi))
18812 +               return ERR_PTR(-EPERM);
18813 +
18814 +       vxdprintk(VXD_CBIT(net, 4),
18815 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
18816 +               nxi, nxi ? nxi->nx_id : 0,
18817 +               NIPQUAD(fl4->saddr), NIPQUAD(fl4->daddr));
18818 +
18819 +       /* single IP is unconditional */
18820 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
18821 +               (fl4->saddr == INADDR_ANY))
18822 +               fl4->saddr = nxi->v4.ip[0].s_addr;
18823 +
18824 +       if (fl4->saddr == INADDR_ANY) {
18825 +               struct nx_addr_v4 *ptr;
18826 +               __be32 found = 0;
18827 +
18828 +               rt = __ip_route_output_key(net, fl4);
18829 +               if (!IS_ERR(rt)) {
18830 +                       found = fl4->saddr;
18831 +                       ip_rt_put(rt);
18832 +                       vxdprintk(VXD_CBIT(net, 4),
18833 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
18834 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(found));
18835 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
18836 +                               goto found;
18837 +               }
18838 +
18839 +               WARN_ON_ONCE(in_irq());
18840 +               spin_lock_bh(&nxi->addr_lock);
18841 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
18842 +                       __be32 primary = ptr->ip[0].s_addr;
18843 +                       __be32 mask = ptr->mask.s_addr;
18844 +                       __be32 neta = primary & mask;
18845 +
18846 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
18847 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
18848 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
18849 +                               NIPQUAD(mask), NIPQUAD(neta));
18850 +                       if ((found & mask) != neta)
18851 +                               continue;
18852 +
18853 +                       fl4->saddr = primary;
18854 +                       rt = __ip_route_output_key(net, fl4);
18855 +                       vxdprintk(VXD_CBIT(net, 4),
18856 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
18857 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(primary));
18858 +                       if (!IS_ERR(rt)) {
18859 +                               found = fl4->saddr;
18860 +                               ip_rt_put(rt);
18861 +                               if (found == primary)
18862 +                                       goto found_unlock;
18863 +                       }
18864 +               }
18865 +               /* still no source ip? */
18866 +               found = ipv4_is_loopback(fl4->daddr)
18867 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
18868 +       found_unlock:
18869 +               spin_unlock_bh(&nxi->addr_lock);
18870 +       found:
18871 +               /* assign src ip to flow */
18872 +               fl4->saddr = found;
18873 +
18874 +       } else {
18875 +               if (!v4_addr_in_nx_info(nxi, fl4->saddr, NXA_MASK_BIND))
18876 +                       return ERR_PTR(-EPERM);
18877 +       }
18878 +
18879 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
18880 +               if (ipv4_is_loopback(fl4->daddr))
18881 +                       fl4->daddr = nxi->v4_lback.s_addr;
18882 +               if (ipv4_is_loopback(fl4->saddr))
18883 +                       fl4->saddr = nxi->v4_lback.s_addr;
18884 +       } else if (ipv4_is_loopback(fl4->daddr) &&
18885 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
18886 +               return ERR_PTR(-EPERM);
18887 +
18888 +       return NULL;
18889 +}
18890 +
18891 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
18892 +
18893 diff -NurpP --minimal linux-3.10.33/kernel/vserver/init.c linux-3.10.33-vs2.3.6.8/kernel/vserver/init.c
18894 --- linux-3.10.33/kernel/vserver/init.c 1970-01-01 00:00:00.000000000 +0000
18895 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/init.c       2013-08-22 20:30:00.000000000 +0000
18896 @@ -0,0 +1,45 @@
18897 +/*
18898 + *  linux/kernel/init.c
18899 + *
18900 + *  Virtual Server Init
18901 + *
18902 + *  Copyright (C) 2004-2007  Herbert Pötzl
18903 + *
18904 + *  V0.01  basic structure
18905 + *
18906 + */
18907 +
18908 +#include <linux/init.h>
18909 +
18910 +int    vserver_register_sysctl(void);
18911 +void   vserver_unregister_sysctl(void);
18912 +
18913 +
18914 +static int __init init_vserver(void)
18915 +{
18916 +       int ret = 0;
18917 +
18918 +#ifdef CONFIG_VSERVER_DEBUG
18919 +       vserver_register_sysctl();
18920 +#endif
18921 +       return ret;
18922 +}
18923 +
18924 +
18925 +static void __exit exit_vserver(void)
18926 +{
18927 +
18928 +#ifdef CONFIG_VSERVER_DEBUG
18929 +       vserver_unregister_sysctl();
18930 +#endif
18931 +       return;
18932 +}
18933 +
18934 +/* FIXME: GFP_ZONETYPES gone
18935 +long vx_slab[GFP_ZONETYPES]; */
18936 +long vx_area;
18937 +
18938 +
18939 +module_init(init_vserver);
18940 +module_exit(exit_vserver);
18941 +
18942 diff -NurpP --minimal linux-3.10.33/kernel/vserver/inode.c linux-3.10.33-vs2.3.6.8/kernel/vserver/inode.c
18943 --- linux-3.10.33/kernel/vserver/inode.c        1970-01-01 00:00:00.000000000 +0000
18944 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/inode.c      2013-08-22 23:14:01.000000000 +0000
18945 @@ -0,0 +1,440 @@
18946 +/*
18947 + *  linux/kernel/vserver/inode.c
18948 + *
18949 + *  Virtual Server: File System Support
18950 + *
18951 + *  Copyright (C) 2004-2007  Herbert Pötzl
18952 + *
18953 + *  V0.01  separated from vcontext V0.05
18954 + *  V0.02  moved to tag (instead of xid)
18955 + *
18956 + */
18957 +
18958 +#include <linux/tty.h>
18959 +#include <linux/proc_fs.h>
18960 +#include <linux/devpts_fs.h>
18961 +#include <linux/fs.h>
18962 +#include <linux/file.h>
18963 +#include <linux/mount.h>
18964 +#include <linux/parser.h>
18965 +#include <linux/namei.h>
18966 +#include <linux/magic.h>
18967 +#include <linux/slab.h>
18968 +#include <linux/vserver/inode.h>
18969 +#include <linux/vserver/inode_cmd.h>
18970 +#include <linux/vs_base.h>
18971 +#include <linux/vs_tag.h>
18972 +
18973 +#include <asm/uaccess.h>
18974 +#include <../../fs/proc/internal.h>
18975 +
18976 +
18977 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
18978 +{
18979 +       struct proc_dir_entry *entry;
18980 +
18981 +       if (!in || !in->i_sb)
18982 +               return -ESRCH;
18983 +
18984 +       *flags = IATTR_TAG
18985 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
18986 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
18987 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
18988 +               | (IS_COW(in) ? IATTR_COW : 0);
18989 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
18990 +
18991 +       if (S_ISDIR(in->i_mode))
18992 +               *mask |= IATTR_BARRIER;
18993 +
18994 +       if (IS_TAGGED(in)) {
18995 +               *tag = i_tag_read(in);
18996 +               *mask |= IATTR_TAG;
18997 +       }
18998 +
18999 +       switch (in->i_sb->s_magic) {
19000 +       case PROC_SUPER_MAGIC:
19001 +               entry = PROC_I(in)->pde;
19002 +
19003 +               /* check for specific inodes? */
19004 +               if (entry)
19005 +                       *mask |= IATTR_FLAGS;
19006 +               if (entry)
19007 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
19008 +               else
19009 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
19010 +               break;
19011 +
19012 +       case DEVPTS_SUPER_MAGIC:
19013 +               *tag = i_tag_read(in);
19014 +               *mask |= IATTR_TAG;
19015 +               break;
19016 +
19017 +       default:
19018 +               break;
19019 +       }
19020 +       return 0;
19021 +}
19022 +
19023 +int vc_get_iattr(void __user *data)
19024 +{
19025 +       struct path path;
19026 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
19027 +       int ret;
19028 +
19029 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19030 +               return -EFAULT;
19031 +
19032 +       ret = user_lpath(vc_data.name, &path);
19033 +       if (!ret) {
19034 +               ret = __vc_get_iattr(path.dentry->d_inode,
19035 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19036 +               path_put(&path);
19037 +       }
19038 +       if (ret)
19039 +               return ret;
19040 +
19041 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19042 +               ret = -EFAULT;
19043 +       return ret;
19044 +}
19045 +
19046 +#ifdef CONFIG_COMPAT
19047 +
19048 +int vc_get_iattr_x32(void __user *data)
19049 +{
19050 +       struct path path;
19051 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
19052 +       int ret;
19053 +
19054 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19055 +               return -EFAULT;
19056 +
19057 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19058 +       if (!ret) {
19059 +               ret = __vc_get_iattr(path.dentry->d_inode,
19060 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19061 +               path_put(&path);
19062 +       }
19063 +       if (ret)
19064 +               return ret;
19065 +
19066 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19067 +               ret = -EFAULT;
19068 +       return ret;
19069 +}
19070 +
19071 +#endif /* CONFIG_COMPAT */
19072 +
19073 +
19074 +int vc_fget_iattr(uint32_t fd, void __user *data)
19075 +{
19076 +       struct file *filp;
19077 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
19078 +       int ret;
19079 +
19080 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19081 +               return -EFAULT;
19082 +
19083 +       filp = fget(fd);
19084 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19085 +               return -EBADF;
19086 +
19087 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
19088 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
19089 +
19090 +       fput(filp);
19091 +
19092 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19093 +               ret = -EFAULT;
19094 +       return ret;
19095 +}
19096 +
19097 +
19098 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19099 +{
19100 +       struct inode *in = de->d_inode;
19101 +       int error = 0, is_proc = 0, has_tag = 0;
19102 +       struct iattr attr = { 0 };
19103 +
19104 +       if (!in || !in->i_sb)
19105 +               return -ESRCH;
19106 +
19107 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
19108 +       if ((*mask & IATTR_FLAGS) && !is_proc)
19109 +               return -EINVAL;
19110 +
19111 +       has_tag = IS_TAGGED(in) ||
19112 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
19113 +       if ((*mask & IATTR_TAG) && !has_tag)
19114 +               return -EINVAL;
19115 +
19116 +       mutex_lock(&in->i_mutex);
19117 +       if (*mask & IATTR_TAG) {
19118 +               attr.ia_tag = make_ktag(&init_user_ns, *tag);
19119 +               attr.ia_valid |= ATTR_TAG;
19120 +       }
19121 +
19122 +       if (*mask & IATTR_FLAGS) {
19123 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
19124 +               unsigned int iflags = PROC_I(in)->vx_flags;
19125 +
19126 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
19127 +                       | (*flags & IATTR_FLAGS);
19128 +               PROC_I(in)->vx_flags = iflags;
19129 +               if (entry)
19130 +                       entry->vx_flags = iflags;
19131 +       }
19132 +
19133 +       if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
19134 +               IATTR_BARRIER | IATTR_COW)) {
19135 +               int iflags = in->i_flags;
19136 +               int vflags = in->i_vflags;
19137 +
19138 +               if (*mask & IATTR_IMMUTABLE) {
19139 +                       if (*flags & IATTR_IMMUTABLE)
19140 +                               iflags |= S_IMMUTABLE;
19141 +                       else
19142 +                               iflags &= ~S_IMMUTABLE;
19143 +               }
19144 +               if (*mask & IATTR_IXUNLINK) {
19145 +                       if (*flags & IATTR_IXUNLINK)
19146 +                               iflags |= S_IXUNLINK;
19147 +                       else
19148 +                               iflags &= ~S_IXUNLINK;
19149 +               }
19150 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
19151 +                       if (*flags & IATTR_BARRIER)
19152 +                               vflags |= V_BARRIER;
19153 +                       else
19154 +                               vflags &= ~V_BARRIER;
19155 +               }
19156 +               if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
19157 +                       if (*flags & IATTR_COW)
19158 +                               vflags |= V_COW;
19159 +                       else
19160 +                               vflags &= ~V_COW;
19161 +               }
19162 +               if (in->i_op && in->i_op->sync_flags) {
19163 +                       error = in->i_op->sync_flags(in, iflags, vflags);
19164 +                       if (error)
19165 +                               goto out;
19166 +               }
19167 +       }
19168 +
19169 +       if (attr.ia_valid) {
19170 +               if (in->i_op && in->i_op->setattr)
19171 +                       error = in->i_op->setattr(de, &attr);
19172 +               else {
19173 +                       error = inode_change_ok(in, &attr);
19174 +                       if (!error) {
19175 +                               setattr_copy(in, &attr);
19176 +                               mark_inode_dirty(in);
19177 +                       }
19178 +               }
19179 +       }
19180 +
19181 +out:
19182 +       mutex_unlock(&in->i_mutex);
19183 +       return error;
19184 +}
19185 +
19186 +int vc_set_iattr(void __user *data)
19187 +{
19188 +       struct path path;
19189 +       struct vcmd_ctx_iattr_v1 vc_data;
19190 +       int ret;
19191 +
19192 +       if (!capable(CAP_LINUX_IMMUTABLE))
19193 +               return -EPERM;
19194 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19195 +               return -EFAULT;
19196 +
19197 +       ret = user_lpath(vc_data.name, &path);
19198 +       if (!ret) {
19199 +               ret = __vc_set_iattr(path.dentry,
19200 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19201 +               path_put(&path);
19202 +       }
19203 +
19204 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19205 +               ret = -EFAULT;
19206 +       return ret;
19207 +}
19208 +
19209 +#ifdef CONFIG_COMPAT
19210 +
19211 +int vc_set_iattr_x32(void __user *data)
19212 +{
19213 +       struct path path;
19214 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
19215 +       int ret;
19216 +
19217 +       if (!capable(CAP_LINUX_IMMUTABLE))
19218 +               return -EPERM;
19219 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19220 +               return -EFAULT;
19221 +
19222 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19223 +       if (!ret) {
19224 +               ret = __vc_set_iattr(path.dentry,
19225 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19226 +               path_put(&path);
19227 +       }
19228 +
19229 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19230 +               ret = -EFAULT;
19231 +       return ret;
19232 +}
19233 +
19234 +#endif /* CONFIG_COMPAT */
19235 +
19236 +int vc_fset_iattr(uint32_t fd, void __user *data)
19237 +{
19238 +       struct file *filp;
19239 +       struct vcmd_ctx_fiattr_v0 vc_data;
19240 +       int ret;
19241 +
19242 +       if (!capable(CAP_LINUX_IMMUTABLE))
19243 +               return -EPERM;
19244 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19245 +               return -EFAULT;
19246 +
19247 +       filp = fget(fd);
19248 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19249 +               return -EBADF;
19250 +
19251 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
19252 +               &vc_data.flags, &vc_data.mask);
19253 +
19254 +       fput(filp);
19255 +
19256 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19257 +               return -EFAULT;
19258 +       return ret;
19259 +}
19260 +
19261 +
19262 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
19263 +
19264 +static match_table_t tokens = {
19265 +       {Opt_notagcheck, "notagcheck"},
19266 +#ifdef CONFIG_PROPAGATE
19267 +       {Opt_notag, "notag"},
19268 +       {Opt_tag, "tag"},
19269 +       {Opt_tagid, "tagid=%u"},
19270 +#endif
19271 +       {Opt_err, NULL}
19272 +};
19273 +
19274 +
19275 +static void __dx_parse_remove(char *string, char *opt)
19276 +{
19277 +       char *p = strstr(string, opt);
19278 +       char *q = p;
19279 +
19280 +       if (p) {
19281 +               while (*q != '\0' && *q != ',')
19282 +                       q++;
19283 +               while (*q)
19284 +                       *p++ = *q++;
19285 +               while (*p)
19286 +                       *p++ = '\0';
19287 +       }
19288 +}
19289 +
19290 +int dx_parse_tag(char *string, vtag_t *tag, int remove, int *mnt_flags,
19291 +                unsigned long *flags)
19292 +{
19293 +       int set = 0;
19294 +       substring_t args[MAX_OPT_ARGS];
19295 +       int token;
19296 +       char *s, *p, *opts;
19297 +#if defined(CONFIG_PROPAGATE) || defined(CONFIG_VSERVER_DEBUG)
19298 +       int option = 0;
19299 +#endif
19300 +
19301 +       if (!string)
19302 +               return 0;
19303 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
19304 +       if (!s)
19305 +               return 0;
19306 +
19307 +       opts = s;
19308 +       while ((p = strsep(&opts, ",")) != NULL) {
19309 +               token = match_token(p, tokens, args);
19310 +
19311 +               switch (token) {
19312 +#ifdef CONFIG_PROPAGATE
19313 +               case Opt_tag:
19314 +                       if (tag)
19315 +                               *tag = 0;
19316 +                       if (remove)
19317 +                               __dx_parse_remove(s, "tag");
19318 +                       *mnt_flags |= MNT_TAGID;
19319 +                       set |= MNT_TAGID;
19320 +                       break;
19321 +               case Opt_notag:
19322 +                       if (remove)
19323 +                               __dx_parse_remove(s, "notag");
19324 +                       *mnt_flags |= MNT_NOTAG;
19325 +                       set |= MNT_NOTAG;
19326 +                       break;
19327 +               case Opt_tagid:
19328 +                       if (tag && !match_int(args, &option))
19329 +                               *tag = option;
19330 +                       if (remove)
19331 +                               __dx_parse_remove(s, "tagid");
19332 +                       *mnt_flags |= MNT_TAGID;
19333 +                       set |= MNT_TAGID;
19334 +                       break;
19335 +#endif /* CONFIG_PROPAGATE */
19336 +               case Opt_notagcheck:
19337 +                       if (remove)
19338 +                               __dx_parse_remove(s, "notagcheck");
19339 +                       *flags |= MS_NOTAGCHECK;
19340 +                       set |= MS_NOTAGCHECK;
19341 +                       break;
19342 +               }
19343 +               vxdprintk(VXD_CBIT(tag, 7),
19344 +                       "dx_parse_tag(" VS_Q("%s") "): %d:#%d",
19345 +                       p, token, option);
19346 +       }
19347 +       if (set)
19348 +               strcpy(string, s);
19349 +       kfree(s);
19350 +       return set;
19351 +}
19352 +
19353 +#ifdef CONFIG_PROPAGATE
19354 +
19355 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
19356 +{
19357 +       vtag_t new_tag = 0;
19358 +       struct vfsmount *mnt;
19359 +       int propagate;
19360 +
19361 +       if (!nd)
19362 +               return;
19363 +       mnt = nd->path.mnt;
19364 +       if (!mnt)
19365 +               return;
19366 +
19367 +       propagate = (mnt->mnt_flags & MNT_TAGID);
19368 +       if (propagate)
19369 +               new_tag = mnt->mnt_tag;
19370 +
19371 +       vxdprintk(VXD_CBIT(tag, 7),
19372 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
19373 +               inode, inode->i_ino, inode->i_tag,
19374 +               new_tag, (propagate) ? 1 : 0);
19375 +
19376 +       if (propagate)
19377 +               i_tag_write(inode, new_tag);
19378 +}
19379 +
19380 +#include <linux/module.h>
19381 +
19382 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
19383 +
19384 +#endif /* CONFIG_PROPAGATE */
19385 +
19386 diff -NurpP --minimal linux-3.10.33/kernel/vserver/limit.c linux-3.10.33-vs2.3.6.8/kernel/vserver/limit.c
19387 --- linux-3.10.33/kernel/vserver/limit.c        1970-01-01 00:00:00.000000000 +0000
19388 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/limit.c      2013-08-22 20:30:00.000000000 +0000
19389 @@ -0,0 +1,345 @@
19390 +/*
19391 + *  linux/kernel/vserver/limit.c
19392 + *
19393 + *  Virtual Server: Context Limits
19394 + *
19395 + *  Copyright (C) 2004-2010  Herbert Pötzl
19396 + *
19397 + *  V0.01  broken out from vcontext V0.05
19398 + *  V0.02  changed vcmds to vxi arg
19399 + *  V0.03  added memory cgroup support
19400 + *
19401 + */
19402 +
19403 +#include <linux/sched.h>
19404 +#include <linux/module.h>
19405 +#include <linux/memcontrol.h>
19406 +#include <linux/res_counter.h>
19407 +#include <linux/vs_limit.h>
19408 +#include <linux/vserver/limit.h>
19409 +#include <linux/vserver/limit_cmd.h>
19410 +
19411 +#include <asm/uaccess.h>
19412 +
19413 +
19414 +const char *vlimit_name[NUM_LIMITS] = {
19415 +       [RLIMIT_CPU]            = "CPU",
19416 +       [RLIMIT_NPROC]          = "NPROC",
19417 +       [RLIMIT_NOFILE]         = "NOFILE",
19418 +       [RLIMIT_LOCKS]          = "LOCKS",
19419 +       [RLIMIT_SIGPENDING]     = "SIGP",
19420 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
19421 +
19422 +       [VLIMIT_NSOCK]          = "NSOCK",
19423 +       [VLIMIT_OPENFD]         = "OPENFD",
19424 +       [VLIMIT_SHMEM]          = "SHMEM",
19425 +       [VLIMIT_DENTRY]         = "DENTRY",
19426 +};
19427 +
19428 +EXPORT_SYMBOL_GPL(vlimit_name);
19429 +
19430 +#define MASK_ENTRY(x)  (1 << (x))
19431 +
19432 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
19433 +               /* minimum */
19434 +       0
19435 +       ,       /* softlimit */
19436 +       0
19437 +       ,       /* maximum */
19438 +       MASK_ENTRY( RLIMIT_NPROC        ) |
19439 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
19440 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
19441 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
19442 +
19443 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
19444 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
19445 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
19446 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
19447 +       0
19448 +};
19449 +               /* accounting only */
19450 +uint32_t account_mask =
19451 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
19452 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
19453 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
19454 +       0;
19455 +
19456 +
19457 +static int is_valid_vlimit(int id)
19458 +{
19459 +       uint32_t mask = vlimit_mask.minimum |
19460 +               vlimit_mask.softlimit | vlimit_mask.maximum;
19461 +       return mask & (1 << id);
19462 +}
19463 +
19464 +static int is_accounted_vlimit(int id)
19465 +{
19466 +       if (is_valid_vlimit(id))
19467 +               return 1;
19468 +       return account_mask & (1 << id);
19469 +}
19470 +
19471 +
19472 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
19473 +{
19474 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
19475 +       return VX_VLIM(limit);
19476 +}
19477 +
19478 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
19479 +{
19480 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
19481 +       return VX_VLIM(limit);
19482 +}
19483 +
19484 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
19485 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
19486 +{
19487 +       if (!is_valid_vlimit(id))
19488 +               return -EINVAL;
19489 +
19490 +       if (minimum)
19491 +               *minimum = CRLIM_UNSET;
19492 +       if (softlimit)
19493 +               *softlimit = vc_get_soft(vxi, id);
19494 +       if (maximum)
19495 +               *maximum = vc_get_hard(vxi, id);
19496 +       return 0;
19497 +}
19498 +
19499 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
19500 +{
19501 +       struct vcmd_ctx_rlimit_v0 vc_data;
19502 +       int ret;
19503 +
19504 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19505 +               return -EFAULT;
19506 +
19507 +       ret = do_get_rlimit(vxi, vc_data.id,
19508 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
19509 +       if (ret)
19510 +               return ret;
19511 +
19512 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19513 +               return -EFAULT;
19514 +       return 0;
19515 +}
19516 +
19517 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
19518 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
19519 +{
19520 +       if (!is_valid_vlimit(id))
19521 +               return -EINVAL;
19522 +
19523 +       if (maximum != CRLIM_KEEP)
19524 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
19525 +       if (softlimit != CRLIM_KEEP)
19526 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
19527 +
19528 +       /* clamp soft limit */
19529 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
19530 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
19531 +
19532 +       return 0;
19533 +}
19534 +
19535 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
19536 +{
19537 +       struct vcmd_ctx_rlimit_v0 vc_data;
19538 +
19539 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19540 +               return -EFAULT;
19541 +
19542 +       return do_set_rlimit(vxi, vc_data.id,
19543 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
19544 +}
19545 +
19546 +#ifdef CONFIG_IA32_EMULATION
19547 +
19548 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
19549 +{
19550 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
19551 +
19552 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19553 +               return -EFAULT;
19554 +
19555 +       return do_set_rlimit(vxi, vc_data.id,
19556 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
19557 +}
19558 +
19559 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
19560 +{
19561 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
19562 +       int ret;
19563 +
19564 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19565 +               return -EFAULT;
19566 +
19567 +       ret = do_get_rlimit(vxi, vc_data.id,
19568 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
19569 +       if (ret)
19570 +               return ret;
19571 +
19572 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19573 +               return -EFAULT;
19574 +       return 0;
19575 +}
19576 +
19577 +#endif /* CONFIG_IA32_EMULATION */
19578 +
19579 +
19580 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
19581 +{
19582 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
19583 +               return -EFAULT;
19584 +       return 0;
19585 +}
19586 +
19587 +
19588 +static inline void vx_reset_hits(struct _vx_limit *limit)
19589 +{
19590 +       int lim;
19591 +
19592 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19593 +               atomic_set(&__rlim_lhit(limit, lim), 0);
19594 +       }
19595 +}
19596 +
19597 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
19598 +{
19599 +       vx_reset_hits(&vxi->limit);
19600 +       return 0;
19601 +}
19602 +
19603 +static inline void vx_reset_minmax(struct _vx_limit *limit)
19604 +{
19605 +       rlim_t value;
19606 +       int lim;
19607 +
19608 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19609 +               value = __rlim_get(limit, lim);
19610 +               __rlim_rmax(limit, lim) = value;
19611 +               __rlim_rmin(limit, lim) = value;
19612 +       }
19613 +}
19614 +
19615 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
19616 +{
19617 +       vx_reset_minmax(&vxi->limit);
19618 +       return 0;
19619 +}
19620 +
19621 +
19622 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
19623 +{
19624 +       struct vcmd_rlimit_stat_v0 vc_data;
19625 +       struct _vx_limit *limit = &vxi->limit;
19626 +       int id;
19627 +
19628 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19629 +               return -EFAULT;
19630 +
19631 +       id = vc_data.id;
19632 +       if (!is_accounted_vlimit(id))
19633 +               return -EINVAL;
19634 +
19635 +       vx_limit_fixup(limit, id);
19636 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
19637 +       vc_data.value = __rlim_get(limit, id);
19638 +       vc_data.minimum = __rlim_rmin(limit, id);
19639 +       vc_data.maximum = __rlim_rmax(limit, id);
19640 +
19641 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19642 +               return -EFAULT;
19643 +       return 0;
19644 +}
19645 +
19646 +
19647 +void vx_vsi_meminfo(struct sysinfo *val)
19648 +{
19649 +#ifdef CONFIG_MEMCG
19650 +       struct mem_cgroup *mcg;
19651 +       u64 res_limit, res_usage;
19652 +
19653 +       rcu_read_lock();
19654 +       mcg = mem_cgroup_from_task(current);
19655 +       rcu_read_unlock();
19656 +       if (!mcg)
19657 +               goto out;
19658 +
19659 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
19660 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
19661 +
19662 +       if (res_limit != RESOURCE_MAX)
19663 +               val->totalram = (res_limit >> PAGE_SHIFT);
19664 +       val->freeram = val->totalram - (res_usage >> PAGE_SHIFT);
19665 +       val->bufferram = 0;
19666 +       val->totalhigh = 0;
19667 +       val->freehigh = 0;
19668 +out:
19669 +#endif /* CONFIG_MEMCG */
19670 +       return;
19671 +}
19672 +
19673 +void vx_vsi_swapinfo(struct sysinfo *val)
19674 +{
19675 +#ifdef CONFIG_MEMCG
19676 +#ifdef CONFIG_MEMCG_SWAP
19677 +       struct mem_cgroup *mcg;
19678 +       u64 res_limit, res_usage, memsw_limit, memsw_usage;
19679 +       s64 swap_limit, swap_usage;
19680 +
19681 +       rcu_read_lock();
19682 +       mcg = mem_cgroup_from_task(current);
19683 +       rcu_read_unlock();
19684 +       if (!mcg)
19685 +               goto out;
19686 +
19687 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
19688 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
19689 +       memsw_limit = mem_cgroup_memsw_read_u64(mcg, RES_LIMIT);
19690 +       memsw_usage = mem_cgroup_memsw_read_u64(mcg, RES_USAGE);
19691 +
19692 +       /* memory unlimited */
19693 +       if (res_limit == RESOURCE_MAX)
19694 +               goto out;
19695 +
19696 +       swap_limit = memsw_limit - res_limit;
19697 +       /* we have a swap limit? */
19698 +       if (memsw_limit != RESOURCE_MAX)
19699 +               val->totalswap = swap_limit >> PAGE_SHIFT;
19700 +
19701 +       /* calculate swap part */
19702 +       swap_usage = (memsw_usage > res_usage) ?
19703 +               memsw_usage - res_usage : 0;
19704 +
19705 +       /* total shown minus usage gives free swap */
19706 +       val->freeswap = (swap_usage < swap_limit) ?
19707 +               val->totalswap - (swap_usage >> PAGE_SHIFT) : 0;
19708 +out:
19709 +#else  /* !CONFIG_MEMCG_SWAP */
19710 +       val->totalswap = 0;
19711 +       val->freeswap = 0;
19712 +#endif /* !CONFIG_MEMCG_SWAP */
19713 +#endif /* CONFIG_MEMCG */
19714 +       return;
19715 +}
19716 +
19717 +long vx_vsi_cached(struct sysinfo *val)
19718 +{
19719 +       long cache = 0;
19720 +#ifdef CONFIG_MEMCG
19721 +       struct mem_cgroup *mcg;
19722 +
19723 +       rcu_read_lock();
19724 +       mcg = mem_cgroup_from_task(current);
19725 +       rcu_read_unlock();
19726 +       if (!mcg)
19727 +               goto out;
19728 +
19729 +       cache = mem_cgroup_stat_read_cache(mcg);
19730 +out:
19731 +#endif
19732 +       return cache;
19733 +}
19734 +
19735 diff -NurpP --minimal linux-3.10.33/kernel/vserver/limit_init.h linux-3.10.33-vs2.3.6.8/kernel/vserver/limit_init.h
19736 --- linux-3.10.33/kernel/vserver/limit_init.h   1970-01-01 00:00:00.000000000 +0000
19737 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/limit_init.h 2013-08-22 20:30:00.000000000 +0000
19738 @@ -0,0 +1,31 @@
19739 +
19740 +
19741 +static inline void vx_info_init_limit(struct _vx_limit *limit)
19742 +{
19743 +       int lim;
19744 +
19745 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19746 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
19747 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
19748 +               __rlim_set(limit, lim, 0);
19749 +               atomic_set(&__rlim_lhit(limit, lim), 0);
19750 +               __rlim_rmin(limit, lim) = 0;
19751 +               __rlim_rmax(limit, lim) = 0;
19752 +       }
19753 +}
19754 +
19755 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
19756 +{
19757 +       rlim_t value;
19758 +       int lim;
19759 +
19760 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19761 +               if ((1 << lim) & VLIM_NOCHECK)
19762 +                       continue;
19763 +               value = __rlim_get(limit, lim);
19764 +               vxwprintk_xid(value,
19765 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
19766 +                       limit, vlimit_name[lim], lim, (long)value);
19767 +       }
19768 +}
19769 +
19770 diff -NurpP --minimal linux-3.10.33/kernel/vserver/limit_proc.h linux-3.10.33-vs2.3.6.8/kernel/vserver/limit_proc.h
19771 --- linux-3.10.33/kernel/vserver/limit_proc.h   1970-01-01 00:00:00.000000000 +0000
19772 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/limit_proc.h 2013-08-22 20:30:00.000000000 +0000
19773 @@ -0,0 +1,57 @@
19774 +#ifndef _VX_LIMIT_PROC_H
19775 +#define _VX_LIMIT_PROC_H
19776 +
19777 +#include <linux/vserver/limit_int.h>
19778 +
19779 +
19780 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
19781 +#define VX_LIMIT_TOP   \
19782 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
19783 +
19784 +#define VX_LIMIT_ARG(r)                                \
19785 +       (unsigned long)__rlim_get(limit, r),    \
19786 +       (unsigned long)__rlim_rmin(limit, r),   \
19787 +       (unsigned long)__rlim_rmax(limit, r),   \
19788 +       VX_VLIM(__rlim_soft(limit, r)),         \
19789 +       VX_VLIM(__rlim_hard(limit, r)),         \
19790 +       atomic_read(&__rlim_lhit(limit, r))
19791 +
19792 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
19793 +{
19794 +       vx_limit_fixup(limit, -1);
19795 +       return sprintf(buffer, VX_LIMIT_TOP
19796 +               "PROC"  VX_LIMIT_FMT
19797 +               "VM"    VX_LIMIT_FMT
19798 +               "VML"   VX_LIMIT_FMT
19799 +               "RSS"   VX_LIMIT_FMT
19800 +               "ANON"  VX_LIMIT_FMT
19801 +               "RMAP"  VX_LIMIT_FMT
19802 +               "FILES" VX_LIMIT_FMT
19803 +               "OFD"   VX_LIMIT_FMT
19804 +               "LOCKS" VX_LIMIT_FMT
19805 +               "SOCK"  VX_LIMIT_FMT
19806 +               "MSGQ"  VX_LIMIT_FMT
19807 +               "SHM"   VX_LIMIT_FMT
19808 +               "SEMA"  VX_LIMIT_FMT
19809 +               "SEMS"  VX_LIMIT_FMT
19810 +               "DENT"  VX_LIMIT_FMT,
19811 +               VX_LIMIT_ARG(RLIMIT_NPROC),
19812 +               VX_LIMIT_ARG(RLIMIT_AS),
19813 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
19814 +               VX_LIMIT_ARG(RLIMIT_RSS),
19815 +               VX_LIMIT_ARG(VLIMIT_ANON),
19816 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
19817 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
19818 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
19819 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
19820 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
19821 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
19822 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
19823 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
19824 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
19825 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
19826 +}
19827 +
19828 +#endif /* _VX_LIMIT_PROC_H */
19829 +
19830 +
19831 diff -NurpP --minimal linux-3.10.33/kernel/vserver/network.c linux-3.10.33-vs2.3.6.8/kernel/vserver/network.c
19832 --- linux-3.10.33/kernel/vserver/network.c      1970-01-01 00:00:00.000000000 +0000
19833 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/network.c    2013-08-22 20:30:00.000000000 +0000
19834 @@ -0,0 +1,1053 @@
19835 +/*
19836 + *  linux/kernel/vserver/network.c
19837 + *
19838 + *  Virtual Server: Network Support
19839 + *
19840 + *  Copyright (C) 2003-2007  Herbert Pötzl
19841 + *
19842 + *  V0.01  broken out from vcontext V0.05
19843 + *  V0.02  cleaned up implementation
19844 + *  V0.03  added equiv nx commands
19845 + *  V0.04  switch to RCU based hash
19846 + *  V0.05  and back to locking again
19847 + *  V0.06  changed vcmds to nxi arg
19848 + *  V0.07  have __create claim() the nxi
19849 + *
19850 + */
19851 +
19852 +#include <linux/err.h>
19853 +#include <linux/slab.h>
19854 +#include <linux/rcupdate.h>
19855 +#include <net/ipv6.h>
19856 +
19857 +#include <linux/vs_network.h>
19858 +#include <linux/vs_pid.h>
19859 +#include <linux/vserver/network_cmd.h>
19860 +
19861 +
19862 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
19863 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
19864 +
19865 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
19866 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
19867 +
19868 +
19869 +static int __init init_network(void)
19870 +{
19871 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
19872 +               sizeof(struct nx_addr_v4), 0,
19873 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19874 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
19875 +               sizeof(struct nx_addr_v6), 0,
19876 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19877 +       return 0;
19878 +}
19879 +
19880 +
19881 +/*     __alloc_nx_addr_v4()                                    */
19882 +
19883 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
19884 +{
19885 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
19886 +               nx_addr_v4_cachep, GFP_KERNEL);
19887 +
19888 +       if (!IS_ERR(nxa))
19889 +               memset(nxa, 0, sizeof(*nxa));
19890 +       return nxa;
19891 +}
19892 +
19893 +/*     __dealloc_nx_addr_v4()                                  */
19894 +
19895 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
19896 +{
19897 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
19898 +}
19899 +
19900 +/*     __dealloc_nx_addr_v4_all()                              */
19901 +
19902 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
19903 +{
19904 +       while (nxa) {
19905 +               struct nx_addr_v4 *next = nxa->next;
19906 +
19907 +               __dealloc_nx_addr_v4(nxa);
19908 +               nxa = next;
19909 +       }
19910 +}
19911 +
19912 +
19913 +#ifdef CONFIG_IPV6
19914 +
19915 +/*     __alloc_nx_addr_v6()                                    */
19916 +
19917 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
19918 +{
19919 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
19920 +               nx_addr_v6_cachep, GFP_KERNEL);
19921 +
19922 +       if (!IS_ERR(nxa))
19923 +               memset(nxa, 0, sizeof(*nxa));
19924 +       return nxa;
19925 +}
19926 +
19927 +/*     __dealloc_nx_addr_v6()                                  */
19928 +
19929 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
19930 +{
19931 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
19932 +}
19933 +
19934 +/*     __dealloc_nx_addr_v6_all()                              */
19935 +
19936 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
19937 +{
19938 +       while (nxa) {
19939 +               struct nx_addr_v6 *next = nxa->next;
19940 +
19941 +               __dealloc_nx_addr_v6(nxa);
19942 +               nxa = next;
19943 +       }
19944 +}
19945 +
19946 +#endif /* CONFIG_IPV6 */
19947 +
19948 +/*     __alloc_nx_info()
19949 +
19950 +       * allocate an initialized nx_info struct
19951 +       * doesn't make it visible (hash)                        */
19952 +
19953 +static struct nx_info *__alloc_nx_info(vnid_t nid)
19954 +{
19955 +       struct nx_info *new = NULL;
19956 +
19957 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
19958 +
19959 +       /* would this benefit from a slab cache? */
19960 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
19961 +       if (!new)
19962 +               return 0;
19963 +
19964 +       memset(new, 0, sizeof(struct nx_info));
19965 +       new->nx_id = nid;
19966 +       INIT_HLIST_NODE(&new->nx_hlist);
19967 +       atomic_set(&new->nx_usecnt, 0);
19968 +       atomic_set(&new->nx_tasks, 0);
19969 +       spin_lock_init(&new->addr_lock);
19970 +       new->nx_state = 0;
19971 +
19972 +       new->nx_flags = NXF_INIT_SET;
19973 +
19974 +       /* rest of init goes here */
19975 +
19976 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
19977 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
19978 +
19979 +       vxdprintk(VXD_CBIT(nid, 0),
19980 +               "alloc_nx_info(%d) = %p", nid, new);
19981 +       atomic_inc(&nx_global_ctotal);
19982 +       return new;
19983 +}
19984 +
19985 +/*     __dealloc_nx_info()
19986 +
19987 +       * final disposal of nx_info                             */
19988 +
19989 +static void __dealloc_nx_info(struct nx_info *nxi)
19990 +{
19991 +       vxdprintk(VXD_CBIT(nid, 0),
19992 +               "dealloc_nx_info(%p)", nxi);
19993 +
19994 +       nxi->nx_hlist.next = LIST_POISON1;
19995 +       nxi->nx_id = -1;
19996 +
19997 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
19998 +       BUG_ON(atomic_read(&nxi->nx_tasks));
19999 +
20000 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
20001 +#ifdef CONFIG_IPV6
20002 +       __dealloc_nx_addr_v6_all(nxi->v6.next);
20003 +#endif
20004 +
20005 +       nxi->nx_state |= NXS_RELEASED;
20006 +       kfree(nxi);
20007 +       atomic_dec(&nx_global_ctotal);
20008 +}
20009 +
20010 +static void __shutdown_nx_info(struct nx_info *nxi)
20011 +{
20012 +       nxi->nx_state |= NXS_SHUTDOWN;
20013 +       vs_net_change(nxi, VSC_NETDOWN);
20014 +}
20015 +
20016 +/*     exported stuff                                          */
20017 +
20018 +void free_nx_info(struct nx_info *nxi)
20019 +{
20020 +       /* context shutdown is mandatory */
20021 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
20022 +
20023 +       /* context must not be hashed */
20024 +       BUG_ON(nxi->nx_state & NXS_HASHED);
20025 +
20026 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20027 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20028 +
20029 +       __dealloc_nx_info(nxi);
20030 +}
20031 +
20032 +
20033 +void __nx_set_lback(struct nx_info *nxi)
20034 +{
20035 +       int nid = nxi->nx_id;
20036 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
20037 +
20038 +       nxi->v4_lback.s_addr = lback;
20039 +}
20040 +
20041 +extern int __nx_inet_add_lback(__be32 addr);
20042 +extern int __nx_inet_del_lback(__be32 addr);
20043 +
20044 +
20045 +/*     hash table for nx_info hash */
20046 +
20047 +#define NX_HASH_SIZE   13
20048 +
20049 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
20050 +
20051 +static DEFINE_SPINLOCK(nx_info_hash_lock);
20052 +
20053 +
20054 +static inline unsigned int __hashval(vnid_t nid)
20055 +{
20056 +       return (nid % NX_HASH_SIZE);
20057 +}
20058 +
20059 +
20060 +
20061 +/*     __hash_nx_info()
20062 +
20063 +       * add the nxi to the global hash table
20064 +       * requires the hash_lock to be held                     */
20065 +
20066 +static inline void __hash_nx_info(struct nx_info *nxi)
20067 +{
20068 +       struct hlist_head *head;
20069 +
20070 +       vxd_assert_lock(&nx_info_hash_lock);
20071 +       vxdprintk(VXD_CBIT(nid, 4),
20072 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
20073 +
20074 +       /* context must not be hashed */
20075 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
20076 +
20077 +       nxi->nx_state |= NXS_HASHED;
20078 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
20079 +       hlist_add_head(&nxi->nx_hlist, head);
20080 +       atomic_inc(&nx_global_cactive);
20081 +}
20082 +
20083 +/*     __unhash_nx_info()
20084 +
20085 +       * remove the nxi from the global hash table
20086 +       * requires the hash_lock to be held                     */
20087 +
20088 +static inline void __unhash_nx_info(struct nx_info *nxi)
20089 +{
20090 +       vxd_assert_lock(&nx_info_hash_lock);
20091 +       vxdprintk(VXD_CBIT(nid, 4),
20092 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
20093 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
20094 +
20095 +       /* context must be hashed */
20096 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
20097 +       /* but without tasks */
20098 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20099 +
20100 +       nxi->nx_state &= ~NXS_HASHED;
20101 +       hlist_del(&nxi->nx_hlist);
20102 +       atomic_dec(&nx_global_cactive);
20103 +}
20104 +
20105 +
20106 +/*     __lookup_nx_info()
20107 +
20108 +       * requires the hash_lock to be held
20109 +       * doesn't increment the nx_refcnt                       */
20110 +
20111 +static inline struct nx_info *__lookup_nx_info(vnid_t nid)
20112 +{
20113 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
20114 +       struct hlist_node *pos;
20115 +       struct nx_info *nxi;
20116 +
20117 +       vxd_assert_lock(&nx_info_hash_lock);
20118 +       hlist_for_each(pos, head) {
20119 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20120 +
20121 +               if (nxi->nx_id == nid)
20122 +                       goto found;
20123 +       }
20124 +       nxi = NULL;
20125 +found:
20126 +       vxdprintk(VXD_CBIT(nid, 0),
20127 +               "__lookup_nx_info(#%u): %p[#%u]",
20128 +               nid, nxi, nxi ? nxi->nx_id : 0);
20129 +       return nxi;
20130 +}
20131 +
20132 +
20133 +/*     __create_nx_info()
20134 +
20135 +       * create the requested context
20136 +       * get(), claim() and hash it                            */
20137 +
20138 +static struct nx_info *__create_nx_info(int id)
20139 +{
20140 +       struct nx_info *new, *nxi = NULL;
20141 +
20142 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
20143 +
20144 +       if (!(new = __alloc_nx_info(id)))
20145 +               return ERR_PTR(-ENOMEM);
20146 +
20147 +       /* required to make dynamic xids unique */
20148 +       spin_lock(&nx_info_hash_lock);
20149 +
20150 +       /* static context requested */
20151 +       if ((nxi = __lookup_nx_info(id))) {
20152 +               vxdprintk(VXD_CBIT(nid, 0),
20153 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
20154 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20155 +                       nxi = ERR_PTR(-EBUSY);
20156 +               else
20157 +                       nxi = ERR_PTR(-EEXIST);
20158 +               goto out_unlock;
20159 +       }
20160 +       /* new context */
20161 +       vxdprintk(VXD_CBIT(nid, 0),
20162 +               "create_nx_info(%d) = %p (new)", id, new);
20163 +       claim_nx_info(new, NULL);
20164 +       __nx_set_lback(new);
20165 +       __hash_nx_info(get_nx_info(new));
20166 +       nxi = new, new = NULL;
20167 +
20168 +out_unlock:
20169 +       spin_unlock(&nx_info_hash_lock);
20170 +       if (new)
20171 +               __dealloc_nx_info(new);
20172 +       return nxi;
20173 +}
20174 +
20175 +
20176 +
20177 +/*     exported stuff                                          */
20178 +
20179 +
20180 +void unhash_nx_info(struct nx_info *nxi)
20181 +{
20182 +       __shutdown_nx_info(nxi);
20183 +       spin_lock(&nx_info_hash_lock);
20184 +       __unhash_nx_info(nxi);
20185 +       spin_unlock(&nx_info_hash_lock);
20186 +}
20187 +
20188 +/*     lookup_nx_info()
20189 +
20190 +       * search for a nx_info and get() it
20191 +       * negative id means current                             */
20192 +
20193 +struct nx_info *lookup_nx_info(int id)
20194 +{
20195 +       struct nx_info *nxi = NULL;
20196 +
20197 +       if (id < 0) {
20198 +               nxi = get_nx_info(current_nx_info());
20199 +       } else if (id > 1) {
20200 +               spin_lock(&nx_info_hash_lock);
20201 +               nxi = get_nx_info(__lookup_nx_info(id));
20202 +               spin_unlock(&nx_info_hash_lock);
20203 +       }
20204 +       return nxi;
20205 +}
20206 +
20207 +/*     nid_is_hashed()
20208 +
20209 +       * verify that nid is still hashed                       */
20210 +
20211 +int nid_is_hashed(vnid_t nid)
20212 +{
20213 +       int hashed;
20214 +
20215 +       spin_lock(&nx_info_hash_lock);
20216 +       hashed = (__lookup_nx_info(nid) != NULL);
20217 +       spin_unlock(&nx_info_hash_lock);
20218 +       return hashed;
20219 +}
20220 +
20221 +
20222 +#ifdef CONFIG_PROC_FS
20223 +
20224 +/*     get_nid_list()
20225 +
20226 +       * get a subset of hashed nids for proc
20227 +       * assumes size is at least one                          */
20228 +
20229 +int get_nid_list(int index, unsigned int *nids, int size)
20230 +{
20231 +       int hindex, nr_nids = 0;
20232 +
20233 +       /* only show current and children */
20234 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
20235 +               if (index > 0)
20236 +                       return 0;
20237 +               nids[nr_nids] = nx_current_nid();
20238 +               return 1;
20239 +       }
20240 +
20241 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
20242 +               struct hlist_head *head = &nx_info_hash[hindex];
20243 +               struct hlist_node *pos;
20244 +
20245 +               spin_lock(&nx_info_hash_lock);
20246 +               hlist_for_each(pos, head) {
20247 +                       struct nx_info *nxi;
20248 +
20249 +                       if (--index > 0)
20250 +                               continue;
20251 +
20252 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20253 +                       nids[nr_nids] = nxi->nx_id;
20254 +                       if (++nr_nids >= size) {
20255 +                               spin_unlock(&nx_info_hash_lock);
20256 +                               goto out;
20257 +                       }
20258 +               }
20259 +               /* keep the lock time short */
20260 +               spin_unlock(&nx_info_hash_lock);
20261 +       }
20262 +out:
20263 +       return nr_nids;
20264 +}
20265 +#endif
20266 +
20267 +
20268 +/*
20269 + *     migrate task to new network
20270 + *     gets nxi, puts old_nxi on change
20271 + */
20272 +
20273 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
20274 +{
20275 +       struct nx_info *old_nxi;
20276 +       int ret = 0;
20277 +
20278 +       if (!p || !nxi)
20279 +               BUG();
20280 +
20281 +       vxdprintk(VXD_CBIT(nid, 5),
20282 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
20283 +               p, nxi, nxi->nx_id,
20284 +               atomic_read(&nxi->nx_usecnt),
20285 +               atomic_read(&nxi->nx_tasks));
20286 +
20287 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
20288 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20289 +               return -EACCES;
20290 +
20291 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
20292 +               return -EFAULT;
20293 +
20294 +       /* maybe disallow this completely? */
20295 +       old_nxi = task_get_nx_info(p);
20296 +       if (old_nxi == nxi)
20297 +               goto out;
20298 +
20299 +       task_lock(p);
20300 +       if (old_nxi)
20301 +               clr_nx_info(&p->nx_info);
20302 +       claim_nx_info(nxi, p);
20303 +       set_nx_info(&p->nx_info, nxi);
20304 +       p->nid = nxi->nx_id;
20305 +       task_unlock(p);
20306 +
20307 +       vxdprintk(VXD_CBIT(nid, 5),
20308 +               "moved task %p into nxi:%p[#%d]",
20309 +               p, nxi, nxi->nx_id);
20310 +
20311 +       if (old_nxi)
20312 +               release_nx_info(old_nxi, p);
20313 +       ret = 0;
20314 +out:
20315 +       put_nx_info(old_nxi);
20316 +       return ret;
20317 +}
20318 +
20319 +
20320 +void nx_set_persistent(struct nx_info *nxi)
20321 +{
20322 +       vxdprintk(VXD_CBIT(nid, 6),
20323 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
20324 +
20325 +       get_nx_info(nxi);
20326 +       claim_nx_info(nxi, NULL);
20327 +}
20328 +
20329 +void nx_clear_persistent(struct nx_info *nxi)
20330 +{
20331 +       vxdprintk(VXD_CBIT(nid, 6),
20332 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
20333 +
20334 +       release_nx_info(nxi, NULL);
20335 +       put_nx_info(nxi);
20336 +}
20337 +
20338 +void nx_update_persistent(struct nx_info *nxi)
20339 +{
20340 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
20341 +               nx_set_persistent(nxi);
20342 +       else
20343 +               nx_clear_persistent(nxi);
20344 +}
20345 +
20346 +/* vserver syscall commands below here */
20347 +
20348 +/* taks nid and nx_info functions */
20349 +
20350 +#include <asm/uaccess.h>
20351 +
20352 +
20353 +int vc_task_nid(uint32_t id)
20354 +{
20355 +       vnid_t nid;
20356 +
20357 +       if (id) {
20358 +               struct task_struct *tsk;
20359 +
20360 +               rcu_read_lock();
20361 +               tsk = find_task_by_real_pid(id);
20362 +               nid = (tsk) ? tsk->nid : -ESRCH;
20363 +               rcu_read_unlock();
20364 +       } else
20365 +               nid = nx_current_nid();
20366 +       return nid;
20367 +}
20368 +
20369 +
20370 +int vc_nx_info(struct nx_info *nxi, void __user *data)
20371 +{
20372 +       struct vcmd_nx_info_v0 vc_data;
20373 +
20374 +       vc_data.nid = nxi->nx_id;
20375 +
20376 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20377 +               return -EFAULT;
20378 +       return 0;
20379 +}
20380 +
20381 +
20382 +/* network functions */
20383 +
20384 +int vc_net_create(uint32_t nid, void __user *data)
20385 +{
20386 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
20387 +       struct nx_info *new_nxi;
20388 +       int ret;
20389 +
20390 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20391 +               return -EFAULT;
20392 +
20393 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
20394 +               return -EINVAL;
20395 +
20396 +       new_nxi = __create_nx_info(nid);
20397 +       if (IS_ERR(new_nxi))
20398 +               return PTR_ERR(new_nxi);
20399 +
20400 +       /* initial flags */
20401 +       new_nxi->nx_flags = vc_data.flagword;
20402 +
20403 +       ret = -ENOEXEC;
20404 +       if (vs_net_change(new_nxi, VSC_NETUP))
20405 +               goto out;
20406 +
20407 +       ret = nx_migrate_task(current, new_nxi);
20408 +       if (ret)
20409 +               goto out;
20410 +
20411 +       /* return context id on success */
20412 +       ret = new_nxi->nx_id;
20413 +
20414 +       /* get a reference for persistent contexts */
20415 +       if ((vc_data.flagword & NXF_PERSISTENT))
20416 +               nx_set_persistent(new_nxi);
20417 +out:
20418 +       release_nx_info(new_nxi, NULL);
20419 +       put_nx_info(new_nxi);
20420 +       return ret;
20421 +}
20422 +
20423 +
20424 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
20425 +{
20426 +       return nx_migrate_task(current, nxi);
20427 +}
20428 +
20429 +
20430 +static inline
20431 +struct nx_addr_v4 *__find_v4_addr(struct nx_info *nxi,
20432 +       __be32 ip, __be32 ip2, __be32 mask, uint16_t type, uint16_t flags,
20433 +       struct nx_addr_v4 **prev)
20434 +{
20435 +       struct nx_addr_v4 *nxa = &nxi->v4;
20436 +
20437 +       for (; nxa; nxa = nxa->next) {
20438 +               if ((nxa->ip[0].s_addr == ip) &&
20439 +                   (nxa->ip[1].s_addr == ip2) &&
20440 +                   (nxa->mask.s_addr == mask) &&
20441 +                   (nxa->type == type) &&
20442 +                   (nxa->flags == flags))
20443 +                   return nxa;
20444 +
20445 +               /* save previous entry */
20446 +               if (prev)
20447 +                       *prev = nxa;
20448 +       }
20449 +       return NULL;
20450 +}
20451 +
20452 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
20453 +       uint16_t type, uint16_t flags)
20454 +{
20455 +       struct nx_addr_v4 *nxa = NULL;
20456 +       struct nx_addr_v4 *new = __alloc_nx_addr_v4();
20457 +       unsigned long irqflags;
20458 +       int ret = -EEXIST;
20459 +
20460 +       if (IS_ERR(new))
20461 +               return PTR_ERR(new);
20462 +
20463 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
20464 +       if (__find_v4_addr(nxi, ip, ip2, mask, type, flags, &nxa))
20465 +               goto out_unlock;
20466 +
20467 +       if (NX_IPV4(nxi)) {
20468 +               nxa->next = new;
20469 +               nxa = new;
20470 +               new = NULL;
20471 +
20472 +               /* remove single ip for ip list */
20473 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
20474 +       }
20475 +
20476 +       nxa->ip[0].s_addr = ip;
20477 +       nxa->ip[1].s_addr = ip2;
20478 +       nxa->mask.s_addr = mask;
20479 +       nxa->type = type;
20480 +       nxa->flags = flags;
20481 +       ret = 0;
20482 +out_unlock:
20483 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20484 +       if (new)
20485 +               __dealloc_nx_addr_v4(new);
20486 +       return ret;
20487 +}
20488 +
20489 +int do_remove_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
20490 +       uint16_t type, uint16_t flags)
20491 +{
20492 +       struct nx_addr_v4 *nxa = NULL;
20493 +       struct nx_addr_v4 *old = NULL;
20494 +       unsigned long irqflags;
20495 +       int ret = 0;
20496 +
20497 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
20498 +       switch (type) {
20499 +       case NXA_TYPE_ADDR:
20500 +               old = __find_v4_addr(nxi, ip, ip2, mask, type, flags, &nxa);
20501 +               if (old) {
20502 +                       if (nxa) {
20503 +                               nxa->next = old->next;
20504 +                               old->next = NULL;
20505 +                       } else {
20506 +                               if (old->next) {
20507 +                                       nxa = old;
20508 +                                       old = old->next;
20509 +                                       *nxa = *old;
20510 +                                       old->next = NULL;
20511 +                               } else {
20512 +                                       memset(old, 0, sizeof(*old));
20513 +                                       old = NULL;
20514 +                               }
20515 +                       }
20516 +               } else
20517 +                       ret = -ESRCH;
20518 +               break;
20519 +
20520 +       case NXA_TYPE_ANY:
20521 +               nxa = &nxi->v4;
20522 +               old = nxa->next;
20523 +               memset(nxa, 0, sizeof(*nxa));
20524 +               break;
20525 +
20526 +       default:
20527 +               ret = -EINVAL;
20528 +       }
20529 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20530 +       __dealloc_nx_addr_v4_all(old);
20531 +       return ret;
20532 +}
20533 +
20534 +
20535 +int vc_net_add(struct nx_info *nxi, void __user *data)
20536 +{
20537 +       struct vcmd_net_addr_v0 vc_data;
20538 +       int index, ret = 0;
20539 +
20540 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20541 +               return -EFAULT;
20542 +
20543 +       switch (vc_data.type) {
20544 +       case NXA_TYPE_IPV4:
20545 +               if ((vc_data.count < 1) || (vc_data.count > 4))
20546 +                       return -EINVAL;
20547 +
20548 +               index = 0;
20549 +               while (index < vc_data.count) {
20550 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
20551 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
20552 +                       if (ret)
20553 +                               return ret;
20554 +                       index++;
20555 +               }
20556 +               ret = index;
20557 +               break;
20558 +
20559 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
20560 +               nxi->v4_bcast = vc_data.ip[0];
20561 +               ret = 1;
20562 +               break;
20563 +
20564 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
20565 +               nxi->v4_lback = vc_data.ip[0];
20566 +               ret = 1;
20567 +               break;
20568 +
20569 +       default:
20570 +               ret = -EINVAL;
20571 +               break;
20572 +       }
20573 +       return ret;
20574 +}
20575 +
20576 +int vc_net_remove(struct nx_info *nxi, void __user *data)
20577 +{
20578 +       struct vcmd_net_addr_v0 vc_data;
20579 +
20580 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20581 +               return -EFAULT;
20582 +
20583 +       switch (vc_data.type) {
20584 +       case NXA_TYPE_ANY:
20585 +               return do_remove_v4_addr(nxi, 0, 0, 0, vc_data.type, 0);
20586 +       default:
20587 +               return -EINVAL;
20588 +       }
20589 +       return 0;
20590 +}
20591 +
20592 +
20593 +int vc_net_add_ipv4_v1(struct nx_info *nxi, void __user *data)
20594 +{
20595 +       struct vcmd_net_addr_ipv4_v1 vc_data;
20596 +
20597 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20598 +               return -EFAULT;
20599 +
20600 +       switch (vc_data.type) {
20601 +       case NXA_TYPE_ADDR:
20602 +       case NXA_TYPE_MASK:
20603 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
20604 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20605 +
20606 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
20607 +               nxi->v4_bcast = vc_data.ip;
20608 +               break;
20609 +
20610 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
20611 +               nxi->v4_lback = vc_data.ip;
20612 +               break;
20613 +
20614 +       default:
20615 +               return -EINVAL;
20616 +       }
20617 +       return 0;
20618 +}
20619 +
20620 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
20621 +{
20622 +       struct vcmd_net_addr_ipv4_v2 vc_data;
20623 +
20624 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20625 +               return -EFAULT;
20626 +
20627 +       switch (vc_data.type) {
20628 +       case NXA_TYPE_ADDR:
20629 +       case NXA_TYPE_MASK:
20630 +       case NXA_TYPE_RANGE:
20631 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
20632 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20633 +
20634 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
20635 +               nxi->v4_bcast = vc_data.ip;
20636 +               break;
20637 +
20638 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
20639 +               nxi->v4_lback = vc_data.ip;
20640 +               break;
20641 +
20642 +       default:
20643 +               return -EINVAL;
20644 +       }
20645 +       return 0;
20646 +}
20647 +
20648 +int vc_net_rem_ipv4_v1(struct nx_info *nxi, void __user *data)
20649 +{
20650 +       struct vcmd_net_addr_ipv4_v1 vc_data;
20651 +
20652 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20653 +               return -EFAULT;
20654 +
20655 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, 0,
20656 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20657 +}
20658 +
20659 +int vc_net_rem_ipv4(struct nx_info *nxi, void __user *data)
20660 +{
20661 +       struct vcmd_net_addr_ipv4_v2 vc_data;
20662 +
20663 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20664 +               return -EFAULT;
20665 +
20666 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
20667 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20668 +}
20669 +
20670 +#ifdef CONFIG_IPV6
20671 +
20672 +static inline
20673 +struct nx_addr_v6 *__find_v6_addr(struct nx_info *nxi,
20674 +       struct in6_addr *ip, struct in6_addr *mask,
20675 +       uint32_t prefix, uint16_t type, uint16_t flags,
20676 +       struct nx_addr_v6 **prev)
20677 +{
20678 +       struct nx_addr_v6 *nxa = &nxi->v6;
20679 +
20680 +       for (; nxa; nxa = nxa->next) {
20681 +               if (ipv6_addr_equal(&nxa->ip, ip) &&
20682 +                   ipv6_addr_equal(&nxa->mask, mask) &&
20683 +                   (nxa->prefix == prefix) &&
20684 +                   (nxa->type == type) &&
20685 +                   (nxa->flags == flags))
20686 +                   return nxa;
20687 +
20688 +               /* save previous entry */
20689 +               if (prev)
20690 +                       *prev = nxa;
20691 +       }
20692 +       return NULL;
20693 +}
20694 +
20695 +
20696 +int do_add_v6_addr(struct nx_info *nxi,
20697 +       struct in6_addr *ip, struct in6_addr *mask,
20698 +       uint32_t prefix, uint16_t type, uint16_t flags)
20699 +{
20700 +       struct nx_addr_v6 *nxa = NULL;
20701 +       struct nx_addr_v6 *new = __alloc_nx_addr_v6();
20702 +       unsigned long irqflags;
20703 +       int ret = -EEXIST;
20704 +
20705 +       if (IS_ERR(new))
20706 +               return PTR_ERR(new);
20707 +
20708 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
20709 +       if (__find_v6_addr(nxi, ip, mask, prefix, type, flags, &nxa))
20710 +               goto out_unlock;
20711 +
20712 +       if (NX_IPV6(nxi)) {
20713 +               nxa->next = new;
20714 +               nxa = new;
20715 +               new = NULL;
20716 +       }
20717 +
20718 +       nxa->ip = *ip;
20719 +       nxa->mask = *mask;
20720 +       nxa->prefix = prefix;
20721 +       nxa->type = type;
20722 +       nxa->flags = flags;
20723 +       ret = 0;
20724 +out_unlock:
20725 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20726 +       if (new)
20727 +               __dealloc_nx_addr_v6(new);
20728 +       return ret;
20729 +}
20730 +
20731 +int do_remove_v6_addr(struct nx_info *nxi,
20732 +       struct in6_addr *ip, struct in6_addr *mask,
20733 +       uint32_t prefix, uint16_t type, uint16_t flags)
20734 +{
20735 +       struct nx_addr_v6 *nxa = NULL;
20736 +       struct nx_addr_v6 *old = NULL;
20737 +       unsigned long irqflags;
20738 +       int ret = 0;
20739 +
20740 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
20741 +       switch (type) {
20742 +       case NXA_TYPE_ADDR:
20743 +               old = __find_v6_addr(nxi, ip, mask, prefix, type, flags, &nxa);
20744 +               if (old) {
20745 +                       if (nxa) {
20746 +                               nxa->next = old->next;
20747 +                               old->next = NULL;
20748 +                       } else {
20749 +                               if (old->next) {
20750 +                                       nxa = old;
20751 +                                       old = old->next;
20752 +                                       *nxa = *old;
20753 +                                       old->next = NULL;
20754 +                               } else {
20755 +                                       memset(old, 0, sizeof(*old));
20756 +                                       old = NULL;
20757 +                               }
20758 +                       }
20759 +               } else
20760 +                       ret = -ESRCH;
20761 +               break;
20762 +
20763 +       case NXA_TYPE_ANY:
20764 +               nxa = &nxi->v6;
20765 +               old = nxa->next;
20766 +               memset(nxa, 0, sizeof(*nxa));
20767 +               break;
20768 +
20769 +       default:
20770 +               ret = -EINVAL;
20771 +       }
20772 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20773 +       __dealloc_nx_addr_v6_all(old);
20774 +       return ret;
20775 +}
20776 +
20777 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
20778 +{
20779 +       struct vcmd_net_addr_ipv6_v1 vc_data;
20780 +
20781 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20782 +               return -EFAULT;
20783 +
20784 +       switch (vc_data.type) {
20785 +       case NXA_TYPE_ADDR:
20786 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
20787 +               /* fallthrough */
20788 +       case NXA_TYPE_MASK:
20789 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
20790 +                       vc_data.prefix, vc_data.type, vc_data.flags);
20791 +       default:
20792 +               return -EINVAL;
20793 +       }
20794 +       return 0;
20795 +}
20796 +
20797 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
20798 +{
20799 +       struct vcmd_net_addr_ipv6_v1 vc_data;
20800 +
20801 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20802 +               return -EFAULT;
20803 +
20804 +       switch (vc_data.type) {
20805 +       case NXA_TYPE_ADDR:
20806 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
20807 +               /* fallthrough */
20808 +       case NXA_TYPE_MASK:
20809 +               return do_remove_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
20810 +                       vc_data.prefix, vc_data.type, vc_data.flags);
20811 +       case NXA_TYPE_ANY:
20812 +               return do_remove_v6_addr(nxi, NULL, NULL, 0, vc_data.type, 0);
20813 +       default:
20814 +               return -EINVAL;
20815 +       }
20816 +       return 0;
20817 +}
20818 +
20819 +#endif /* CONFIG_IPV6 */
20820 +
20821 +
20822 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
20823 +{
20824 +       struct vcmd_net_flags_v0 vc_data;
20825 +
20826 +       vc_data.flagword = nxi->nx_flags;
20827 +
20828 +       /* special STATE flag handling */
20829 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
20830 +
20831 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20832 +               return -EFAULT;
20833 +       return 0;
20834 +}
20835 +
20836 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
20837 +{
20838 +       struct vcmd_net_flags_v0 vc_data;
20839 +       uint64_t mask, trigger;
20840 +
20841 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20842 +               return -EFAULT;
20843 +
20844 +       /* special STATE flag handling */
20845 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
20846 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
20847 +
20848 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
20849 +               vc_data.flagword, mask);
20850 +       if (trigger & NXF_PERSISTENT)
20851 +               nx_update_persistent(nxi);
20852 +
20853 +       return 0;
20854 +}
20855 +
20856 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
20857 +{
20858 +       struct vcmd_net_caps_v0 vc_data;
20859 +
20860 +       vc_data.ncaps = nxi->nx_ncaps;
20861 +       vc_data.cmask = ~0ULL;
20862 +
20863 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20864 +               return -EFAULT;
20865 +       return 0;
20866 +}
20867 +
20868 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
20869 +{
20870 +       struct vcmd_net_caps_v0 vc_data;
20871 +
20872 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20873 +               return -EFAULT;
20874 +
20875 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
20876 +               vc_data.ncaps, vc_data.cmask);
20877 +       return 0;
20878 +}
20879 +
20880 +
20881 +#include <linux/module.h>
20882 +
20883 +module_init(init_network);
20884 +
20885 +EXPORT_SYMBOL_GPL(free_nx_info);
20886 +EXPORT_SYMBOL_GPL(unhash_nx_info);
20887 +
20888 diff -NurpP --minimal linux-3.10.33/kernel/vserver/proc.c linux-3.10.33-vs2.3.6.8/kernel/vserver/proc.c
20889 --- linux-3.10.33/kernel/vserver/proc.c 1970-01-01 00:00:00.000000000 +0000
20890 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/proc.c       2013-08-22 23:31:37.000000000 +0000
20891 @@ -0,0 +1,1113 @@
20892 +/*
20893 + *  linux/kernel/vserver/proc.c
20894 + *
20895 + *  Virtual Context Support
20896 + *
20897 + *  Copyright (C) 2003-2011  Herbert Pötzl
20898 + *
20899 + *  V0.01  basic structure
20900 + *  V0.02  adaptation vs1.3.0
20901 + *  V0.03  proc permissions
20902 + *  V0.04  locking/generic
20903 + *  V0.05  next generation procfs
20904 + *  V0.06  inode validation
20905 + *  V0.07  generic rewrite vid
20906 + *  V0.08  remove inode type
20907 + *  V0.09  added u/wmask info
20908 + *
20909 + */
20910 +
20911 +#include <linux/proc_fs.h>
20912 +#include <linux/fs_struct.h>
20913 +#include <linux/mount.h>
20914 +#include <linux/namei.h>
20915 +#include <asm/unistd.h>
20916 +
20917 +#include <linux/vs_context.h>
20918 +#include <linux/vs_network.h>
20919 +#include <linux/vs_cvirt.h>
20920 +
20921 +#include <linux/in.h>
20922 +#include <linux/inetdevice.h>
20923 +#include <linux/vs_inet.h>
20924 +#include <linux/vs_inet6.h>
20925 +
20926 +#include <linux/vserver/global.h>
20927 +
20928 +#include "cvirt_proc.h"
20929 +#include "cacct_proc.h"
20930 +#include "limit_proc.h"
20931 +#include "sched_proc.h"
20932 +#include "vci_config.h"
20933 +
20934 +#include <../../fs/proc/internal.h>
20935 +
20936 +
20937 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
20938 +{
20939 +       unsigned __capi;
20940 +
20941 +       CAP_FOR_EACH_U32(__capi) {
20942 +               buffer += sprintf(buffer, "%08x",
20943 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
20944 +       }
20945 +       return buffer;
20946 +}
20947 +
20948 +
20949 +static struct proc_dir_entry *proc_virtual;
20950 +
20951 +static struct proc_dir_entry *proc_virtnet;
20952 +
20953 +
20954 +/* first the actual feeds */
20955 +
20956 +
20957 +static int proc_vci(char *buffer)
20958 +{
20959 +       return sprintf(buffer,
20960 +               "VCIVersion:\t%04x:%04x\n"
20961 +               "VCISyscall:\t%d\n"
20962 +               "VCIKernel:\t%08x\n",
20963 +               VCI_VERSION >> 16,
20964 +               VCI_VERSION & 0xFFFF,
20965 +               __NR_vserver,
20966 +               vci_kernel_config());
20967 +}
20968 +
20969 +static int proc_virtual_info(char *buffer)
20970 +{
20971 +       return proc_vci(buffer);
20972 +}
20973 +
20974 +static int proc_virtual_status(char *buffer)
20975 +{
20976 +       return sprintf(buffer,
20977 +               "#CTotal:\t%d\n"
20978 +               "#CActive:\t%d\n"
20979 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
20980 +               "#InitTask:\t%d\t%d %d\n",
20981 +               atomic_read(&vx_global_ctotal),
20982 +               atomic_read(&vx_global_cactive),
20983 +               atomic_read(&vs_global_nsproxy),
20984 +               atomic_read(&vs_global_fs),
20985 +               atomic_read(&vs_global_mnt_ns),
20986 +               atomic_read(&vs_global_uts_ns),
20987 +               atomic_read(&nr_ipc_ns),
20988 +               atomic_read(&vs_global_user_ns),
20989 +               atomic_read(&vs_global_pid_ns),
20990 +               atomic_read(&init_task.usage),
20991 +               atomic_read(&init_task.nsproxy->count),
20992 +               init_task.fs->users);
20993 +}
20994 +
20995 +
20996 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
20997 +{
20998 +       int length;
20999 +
21000 +       length = sprintf(buffer,
21001 +               "ID:\t%d\n"
21002 +               "Info:\t%p\n"
21003 +               "Init:\t%d\n"
21004 +               "OOM:\t%lld\n",
21005 +               vxi->vx_id,
21006 +               vxi,
21007 +               vxi->vx_initpid,
21008 +               vxi->vx_badness_bias);
21009 +       return length;
21010 +}
21011 +
21012 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
21013 +{
21014 +       char *orig = buffer;
21015 +
21016 +       buffer += sprintf(buffer,
21017 +               "UseCnt:\t%d\n"
21018 +               "Tasks:\t%d\n"
21019 +               "Flags:\t%016llx\n",
21020 +               atomic_read(&vxi->vx_usecnt),
21021 +               atomic_read(&vxi->vx_tasks),
21022 +               (unsigned long long)vxi->vx_flags);
21023 +
21024 +       buffer += sprintf(buffer, "BCaps:\t");
21025 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
21026 +       buffer += sprintf(buffer, "\n");
21027 +
21028 +       buffer += sprintf(buffer,
21029 +               "CCaps:\t%016llx\n"
21030 +               "Umask:\t%16llx\n"
21031 +               "Wmask:\t%16llx\n"
21032 +               "Spaces:\t%08lx %08lx\n",
21033 +               (unsigned long long)vxi->vx_ccaps,
21034 +               (unsigned long long)vxi->vx_umask,
21035 +               (unsigned long long)vxi->vx_wmask,
21036 +               vxi->space[0].vx_nsmask, vxi->space[1].vx_nsmask);
21037 +       return buffer - orig;
21038 +}
21039 +
21040 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
21041 +{
21042 +       return vx_info_proc_limit(&vxi->limit, buffer);
21043 +}
21044 +
21045 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
21046 +{
21047 +       int cpu, length;
21048 +
21049 +       length = vx_info_proc_sched(&vxi->sched, buffer);
21050 +       for_each_online_cpu(cpu) {
21051 +               length += vx_info_proc_sched_pc(
21052 +                       &vx_per_cpu(vxi, sched_pc, cpu),
21053 +                       buffer + length, cpu);
21054 +       }
21055 +       return length;
21056 +}
21057 +
21058 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
21059 +{
21060 +       return vx_info_proc_nsproxy(vxi->space[0].vx_nsproxy, buffer);
21061 +}
21062 +
21063 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
21064 +{
21065 +       return vx_info_proc_nsproxy(vxi->space[1].vx_nsproxy, buffer);
21066 +}
21067 +
21068 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
21069 +{
21070 +       int cpu, length;
21071 +
21072 +       vx_update_load(vxi);
21073 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
21074 +       for_each_online_cpu(cpu) {
21075 +               length += vx_info_proc_cvirt_pc(
21076 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
21077 +                       buffer + length, cpu);
21078 +       }
21079 +       return length;
21080 +}
21081 +
21082 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
21083 +{
21084 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
21085 +}
21086 +
21087 +
21088 +static int proc_virtnet_info(char *buffer)
21089 +{
21090 +       return proc_vci(buffer);
21091 +}
21092 +
21093 +static int proc_virtnet_status(char *buffer)
21094 +{
21095 +       return sprintf(buffer,
21096 +               "#CTotal:\t%d\n"
21097 +               "#CActive:\t%d\n",
21098 +               atomic_read(&nx_global_ctotal),
21099 +               atomic_read(&nx_global_cactive));
21100 +}
21101 +
21102 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
21103 +{
21104 +       struct nx_addr_v4 *v4a;
21105 +#ifdef CONFIG_IPV6
21106 +       struct nx_addr_v6 *v6a;
21107 +#endif
21108 +       int length, i;
21109 +
21110 +       length = sprintf(buffer,
21111 +               "ID:\t%d\n"
21112 +               "Info:\t%p\n"
21113 +               "Bcast:\t" NIPQUAD_FMT "\n"
21114 +               "Lback:\t" NIPQUAD_FMT "\n",
21115 +               nxi->nx_id,
21116 +               nxi,
21117 +               NIPQUAD(nxi->v4_bcast.s_addr),
21118 +               NIPQUAD(nxi->v4_lback.s_addr));
21119 +
21120 +       if (!NX_IPV4(nxi))
21121 +               goto skip_v4;
21122 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
21123 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
21124 +                       i, NXAV4(v4a));
21125 +skip_v4:
21126 +#ifdef CONFIG_IPV6
21127 +       if (!NX_IPV6(nxi))
21128 +               goto skip_v6;
21129 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
21130 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
21131 +                       i, NXAV6(v6a));
21132 +skip_v6:
21133 +#endif
21134 +       return length;
21135 +}
21136 +
21137 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
21138 +{
21139 +       int length;
21140 +
21141 +       length = sprintf(buffer,
21142 +               "UseCnt:\t%d\n"
21143 +               "Tasks:\t%d\n"
21144 +               "Flags:\t%016llx\n"
21145 +               "NCaps:\t%016llx\n",
21146 +               atomic_read(&nxi->nx_usecnt),
21147 +               atomic_read(&nxi->nx_tasks),
21148 +               (unsigned long long)nxi->nx_flags,
21149 +               (unsigned long long)nxi->nx_ncaps);
21150 +       return length;
21151 +}
21152 +
21153 +
21154 +
21155 +/* here the inode helpers */
21156 +
21157 +struct vs_entry {
21158 +       int len;
21159 +       char *name;
21160 +       mode_t mode;
21161 +       struct inode_operations *iop;
21162 +       struct file_operations *fop;
21163 +       union proc_op op;
21164 +};
21165 +
21166 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
21167 +{
21168 +       struct inode *inode = new_inode(sb);
21169 +
21170 +       if (!inode)
21171 +               goto out;
21172 +
21173 +       inode->i_mode = p->mode;
21174 +       if (p->iop)
21175 +               inode->i_op = p->iop;
21176 +       if (p->fop)
21177 +               inode->i_fop = p->fop;
21178 +
21179 +       set_nlink(inode, (p->mode & S_IFDIR) ? 2 : 1);
21180 +       inode->i_flags |= S_IMMUTABLE;
21181 +
21182 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
21183 +
21184 +       i_uid_write(inode, 0);
21185 +       i_gid_write(inode, 0);
21186 +       i_tag_write(inode, 0);
21187 +out:
21188 +       return inode;
21189 +}
21190 +
21191 +static struct dentry *vs_proc_instantiate(struct inode *dir,
21192 +       struct dentry *dentry, int id, void *ptr)
21193 +{
21194 +       struct vs_entry *p = ptr;
21195 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
21196 +       struct dentry *error = ERR_PTR(-EINVAL);
21197 +
21198 +       if (!inode)
21199 +               goto out;
21200 +
21201 +       PROC_I(inode)->op = p->op;
21202 +       PROC_I(inode)->fd = id;
21203 +       d_add(dentry, inode);
21204 +       error = NULL;
21205 +out:
21206 +       return error;
21207 +}
21208 +
21209 +/* Lookups */
21210 +
21211 +typedef struct dentry *vx_instantiate_t(struct inode *, struct dentry *, int, void *);
21212 +
21213 +
21214 +/*
21215 + * Fill a directory entry.
21216 + *
21217 + * If possible create the dcache entry and derive our inode number and
21218 + * file type from dcache entry.
21219 + *
21220 + * Since all of the proc inode numbers are dynamically generated, the inode
21221 + * numbers do not exist until the inode is cache.  This means creating the
21222 + * the dcache entry in readdir is necessary to keep the inode numbers
21223 + * reported by readdir in sync with the inode numbers reported
21224 + * by stat.
21225 + */
21226 +static int vx_proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
21227 +       char *name, int len, vx_instantiate_t instantiate, int id, void *ptr)
21228 +{
21229 +       struct dentry *child, *dir = filp->f_dentry;
21230 +       struct inode *inode;
21231 +       struct qstr qname;
21232 +       ino_t ino = 0;
21233 +       unsigned type = DT_UNKNOWN;
21234 +
21235 +       qname.name = name;
21236 +       qname.len  = len;
21237 +       qname.hash = full_name_hash(name, len);
21238 +
21239 +       child = d_lookup(dir, &qname);
21240 +       if (!child) {
21241 +               struct dentry *new;
21242 +               new = d_alloc(dir, &qname);
21243 +               if (new) {
21244 +                       child = instantiate(dir->d_inode, new, id, ptr);
21245 +                       if (child)
21246 +                               dput(new);
21247 +                       else
21248 +                               child = new;
21249 +               }
21250 +       }
21251 +       if (!child || IS_ERR(child) || !child->d_inode)
21252 +               goto end_instantiate;
21253 +       inode = child->d_inode;
21254 +       if (inode) {
21255 +               ino = inode->i_ino;
21256 +               type = inode->i_mode >> 12;
21257 +       }
21258 +       dput(child);
21259 +end_instantiate:
21260 +       if (!ino)
21261 +               ino = find_inode_number(dir, &qname);
21262 +       if (!ino)
21263 +               ino = 1;
21264 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
21265 +}
21266 +
21267 +
21268 +
21269 +/* get and revalidate vx_info/xid */
21270 +
21271 +static inline
21272 +struct vx_info *get_proc_vx_info(struct inode *inode)
21273 +{
21274 +       return lookup_vx_info(PROC_I(inode)->fd);
21275 +}
21276 +
21277 +static int proc_xid_revalidate(struct dentry *dentry, unsigned int flags)
21278 +{
21279 +       struct inode *inode = dentry->d_inode;
21280 +       vxid_t xid = PROC_I(inode)->fd;
21281 +
21282 +       if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
21283 +               return -ECHILD;
21284 +
21285 +       if (!xid || xid_is_hashed(xid))
21286 +               return 1;
21287 +       d_drop(dentry);
21288 +       return 0;
21289 +}
21290 +
21291 +
21292 +/* get and revalidate nx_info/nid */
21293 +
21294 +static int proc_nid_revalidate(struct dentry *dentry, unsigned int flags)
21295 +{
21296 +       struct inode *inode = dentry->d_inode;
21297 +       vnid_t nid = PROC_I(inode)->fd;
21298 +
21299 +       if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
21300 +               return -ECHILD;
21301 +
21302 +       if (!nid || nid_is_hashed(nid))
21303 +               return 1;
21304 +       d_drop(dentry);
21305 +       return 0;
21306 +}
21307 +
21308 +
21309 +
21310 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
21311 +
21312 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
21313 +                         size_t count, loff_t *ppos)
21314 +{
21315 +       struct inode *inode = file->f_dentry->d_inode;
21316 +       unsigned long page;
21317 +       ssize_t length = 0;
21318 +
21319 +       if (count > PROC_BLOCK_SIZE)
21320 +               count = PROC_BLOCK_SIZE;
21321 +
21322 +       /* fade that out as soon as stable */
21323 +       WARN_ON(PROC_I(inode)->fd);
21324 +
21325 +       if (!(page = __get_free_page(GFP_KERNEL)))
21326 +               return -ENOMEM;
21327 +
21328 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
21329 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
21330 +
21331 +       if (length >= 0)
21332 +               length = simple_read_from_buffer(buf, count, ppos,
21333 +                       (char *)page, length);
21334 +
21335 +       free_page(page);
21336 +       return length;
21337 +}
21338 +
21339 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
21340 +                         size_t count, loff_t *ppos)
21341 +{
21342 +       struct inode *inode = file->f_dentry->d_inode;
21343 +       struct vx_info *vxi = NULL;
21344 +       vxid_t xid = PROC_I(inode)->fd;
21345 +       unsigned long page;
21346 +       ssize_t length = 0;
21347 +
21348 +       if (count > PROC_BLOCK_SIZE)
21349 +               count = PROC_BLOCK_SIZE;
21350 +
21351 +       /* fade that out as soon as stable */
21352 +       WARN_ON(!xid);
21353 +       vxi = lookup_vx_info(xid);
21354 +       if (!vxi)
21355 +               goto out;
21356 +
21357 +       length = -ENOMEM;
21358 +       if (!(page = __get_free_page(GFP_KERNEL)))
21359 +               goto out_put;
21360 +
21361 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
21362 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
21363 +
21364 +       if (length >= 0)
21365 +               length = simple_read_from_buffer(buf, count, ppos,
21366 +                       (char *)page, length);
21367 +
21368 +       free_page(page);
21369 +out_put:
21370 +       put_vx_info(vxi);
21371 +out:
21372 +       return length;
21373 +}
21374 +
21375 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
21376 +                         size_t count, loff_t *ppos)
21377 +{
21378 +       struct inode *inode = file->f_dentry->d_inode;
21379 +       struct nx_info *nxi = NULL;
21380 +       vnid_t nid = PROC_I(inode)->fd;
21381 +       unsigned long page;
21382 +       ssize_t length = 0;
21383 +
21384 +       if (count > PROC_BLOCK_SIZE)
21385 +               count = PROC_BLOCK_SIZE;
21386 +
21387 +       /* fade that out as soon as stable */
21388 +       WARN_ON(!nid);
21389 +       nxi = lookup_nx_info(nid);
21390 +       if (!nxi)
21391 +               goto out;
21392 +
21393 +       length = -ENOMEM;
21394 +       if (!(page = __get_free_page(GFP_KERNEL)))
21395 +               goto out_put;
21396 +
21397 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
21398 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
21399 +
21400 +       if (length >= 0)
21401 +               length = simple_read_from_buffer(buf, count, ppos,
21402 +                       (char *)page, length);
21403 +
21404 +       free_page(page);
21405 +out_put:
21406 +       put_nx_info(nxi);
21407 +out:
21408 +       return length;
21409 +}
21410 +
21411 +
21412 +
21413 +/* here comes the lower level */
21414 +
21415 +
21416 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
21417 +       .len  = sizeof(NAME) - 1,       \
21418 +       .name = (NAME),                 \
21419 +       .mode = MODE,                   \
21420 +       .iop  = IOP,                    \
21421 +       .fop  = FOP,                    \
21422 +       .op   = OP,                     \
21423 +}
21424 +
21425 +
21426 +#define DIR(NAME, MODE, OTYPE)                         \
21427 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
21428 +               &proc_ ## OTYPE ## _inode_operations,   \
21429 +               &proc_ ## OTYPE ## _file_operations, { } )
21430 +
21431 +#define INF(NAME, MODE, OTYPE)                         \
21432 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21433 +               &proc_vs_info_file_operations,          \
21434 +               { .proc_vs_read = &proc_##OTYPE } )
21435 +
21436 +#define VINF(NAME, MODE, OTYPE)                                \
21437 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21438 +               &proc_vx_info_file_operations,          \
21439 +               { .proc_vxi_read = &proc_##OTYPE } )
21440 +
21441 +#define NINF(NAME, MODE, OTYPE)                                \
21442 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21443 +               &proc_nx_info_file_operations,          \
21444 +               { .proc_nxi_read = &proc_##OTYPE } )
21445 +
21446 +
21447 +static struct file_operations proc_vs_info_file_operations = {
21448 +       .read =         proc_vs_info_read,
21449 +};
21450 +
21451 +static struct file_operations proc_vx_info_file_operations = {
21452 +       .read =         proc_vx_info_read,
21453 +};
21454 +
21455 +static struct dentry_operations proc_xid_dentry_operations = {
21456 +       .d_revalidate = proc_xid_revalidate,
21457 +};
21458 +
21459 +static struct vs_entry vx_base_stuff[] = {
21460 +       VINF("info",    S_IRUGO, vxi_info),
21461 +       VINF("status",  S_IRUGO, vxi_status),
21462 +       VINF("limit",   S_IRUGO, vxi_limit),
21463 +       VINF("sched",   S_IRUGO, vxi_sched),
21464 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
21465 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
21466 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
21467 +       VINF("cacct",   S_IRUGO, vxi_cacct),
21468 +       {}
21469 +};
21470 +
21471 +
21472 +
21473 +
21474 +static struct dentry *proc_xid_instantiate(struct inode *dir,
21475 +       struct dentry *dentry, int id, void *ptr)
21476 +{
21477 +       dentry->d_op = &proc_xid_dentry_operations;
21478 +       return vs_proc_instantiate(dir, dentry, id, ptr);
21479 +}
21480 +
21481 +static struct dentry *proc_xid_lookup(struct inode *dir,
21482 +       struct dentry *dentry, unsigned int flags)
21483 +{
21484 +       struct vs_entry *p = vx_base_stuff;
21485 +       struct dentry *error = ERR_PTR(-ENOENT);
21486 +
21487 +       for (; p->name; p++) {
21488 +               if (p->len != dentry->d_name.len)
21489 +                       continue;
21490 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21491 +                       break;
21492 +       }
21493 +       if (!p->name)
21494 +               goto out;
21495 +
21496 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
21497 +out:
21498 +       return error;
21499 +}
21500 +
21501 +static int proc_xid_readdir(struct file *filp,
21502 +       void *dirent, filldir_t filldir)
21503 +{
21504 +       struct dentry *dentry = filp->f_dentry;
21505 +       struct inode *inode = dentry->d_inode;
21506 +       struct vs_entry *p = vx_base_stuff;
21507 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
21508 +       int pos, index;
21509 +       u64 ino;
21510 +
21511 +       pos = filp->f_pos;
21512 +       switch (pos) {
21513 +       case 0:
21514 +               ino = inode->i_ino;
21515 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21516 +                       goto out;
21517 +               pos++;
21518 +               /* fall through */
21519 +       case 1:
21520 +               ino = parent_ino(dentry);
21521 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21522 +                       goto out;
21523 +               pos++;
21524 +               /* fall through */
21525 +       default:
21526 +               index = pos - 2;
21527 +               if (index >= size)
21528 +                       goto out;
21529 +               for (p += index; p->name; p++) {
21530 +                       if (vx_proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21531 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
21532 +                               goto out;
21533 +                       pos++;
21534 +               }
21535 +       }
21536 +out:
21537 +       filp->f_pos = pos;
21538 +       return 1;
21539 +}
21540 +
21541 +
21542 +
21543 +static struct file_operations proc_nx_info_file_operations = {
21544 +       .read =         proc_nx_info_read,
21545 +};
21546 +
21547 +static struct dentry_operations proc_nid_dentry_operations = {
21548 +       .d_revalidate = proc_nid_revalidate,
21549 +};
21550 +
21551 +static struct vs_entry nx_base_stuff[] = {
21552 +       NINF("info",    S_IRUGO, nxi_info),
21553 +       NINF("status",  S_IRUGO, nxi_status),
21554 +       {}
21555 +};
21556 +
21557 +
21558 +static struct dentry *proc_nid_instantiate(struct inode *dir,
21559 +       struct dentry *dentry, int id, void *ptr)
21560 +{
21561 +       dentry->d_op = &proc_nid_dentry_operations;
21562 +       return vs_proc_instantiate(dir, dentry, id, ptr);
21563 +}
21564 +
21565 +static struct dentry *proc_nid_lookup(struct inode *dir,
21566 +       struct dentry *dentry, unsigned int flags)
21567 +{
21568 +       struct vs_entry *p = nx_base_stuff;
21569 +       struct dentry *error = ERR_PTR(-ENOENT);
21570 +
21571 +       for (; p->name; p++) {
21572 +               if (p->len != dentry->d_name.len)
21573 +                       continue;
21574 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21575 +                       break;
21576 +       }
21577 +       if (!p->name)
21578 +               goto out;
21579 +
21580 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
21581 +out:
21582 +       return error;
21583 +}
21584 +
21585 +static int proc_nid_readdir(struct file *filp,
21586 +       void *dirent, filldir_t filldir)
21587 +{
21588 +       struct dentry *dentry = filp->f_dentry;
21589 +       struct inode *inode = dentry->d_inode;
21590 +       struct vs_entry *p = nx_base_stuff;
21591 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
21592 +       int pos, index;
21593 +       u64 ino;
21594 +
21595 +       pos = filp->f_pos;
21596 +       switch (pos) {
21597 +       case 0:
21598 +               ino = inode->i_ino;
21599 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21600 +                       goto out;
21601 +               pos++;
21602 +               /* fall through */
21603 +       case 1:
21604 +               ino = parent_ino(dentry);
21605 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21606 +                       goto out;
21607 +               pos++;
21608 +               /* fall through */
21609 +       default:
21610 +               index = pos - 2;
21611 +               if (index >= size)
21612 +                       goto out;
21613 +               for (p += index; p->name; p++) {
21614 +                       if (vx_proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21615 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
21616 +                               goto out;
21617 +                       pos++;
21618 +               }
21619 +       }
21620 +out:
21621 +       filp->f_pos = pos;
21622 +       return 1;
21623 +}
21624 +
21625 +
21626 +#define MAX_MULBY10    ((~0U - 9) / 10)
21627 +
21628 +static inline int atovid(const char *str, int len)
21629 +{
21630 +       int vid, c;
21631 +
21632 +       vid = 0;
21633 +       while (len-- > 0) {
21634 +               c = *str - '0';
21635 +               str++;
21636 +               if (c > 9)
21637 +                       return -1;
21638 +               if (vid >= MAX_MULBY10)
21639 +                       return -1;
21640 +               vid *= 10;
21641 +               vid += c;
21642 +               if (!vid)
21643 +                       return -1;
21644 +       }
21645 +       return vid;
21646 +}
21647 +
21648 +/* now the upper level (virtual) */
21649 +
21650 +
21651 +static struct file_operations proc_xid_file_operations = {
21652 +       .read =         generic_read_dir,
21653 +       .readdir =      proc_xid_readdir,
21654 +};
21655 +
21656 +static struct inode_operations proc_xid_inode_operations = {
21657 +       .lookup =       proc_xid_lookup,
21658 +};
21659 +
21660 +static struct vs_entry vx_virtual_stuff[] = {
21661 +       INF("info",     S_IRUGO, virtual_info),
21662 +       INF("status",   S_IRUGO, virtual_status),
21663 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
21664 +};
21665 +
21666 +
21667 +static struct dentry *proc_virtual_lookup(struct inode *dir,
21668 +       struct dentry *dentry, unsigned int flags)
21669 +{
21670 +       struct vs_entry *p = vx_virtual_stuff;
21671 +       struct dentry *error = ERR_PTR(-ENOENT);
21672 +       int id = 0;
21673 +
21674 +       for (; p->name; p++) {
21675 +               if (p->len != dentry->d_name.len)
21676 +                       continue;
21677 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21678 +                       break;
21679 +       }
21680 +       if (p->name)
21681 +               goto instantiate;
21682 +
21683 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
21684 +       if ((id < 0) || !xid_is_hashed(id))
21685 +               goto out;
21686 +
21687 +instantiate:
21688 +       error = proc_xid_instantiate(dir, dentry, id, p);
21689 +out:
21690 +       return error;
21691 +}
21692 +
21693 +static struct file_operations proc_nid_file_operations = {
21694 +       .read =         generic_read_dir,
21695 +       .readdir =      proc_nid_readdir,
21696 +};
21697 +
21698 +static struct inode_operations proc_nid_inode_operations = {
21699 +       .lookup =       proc_nid_lookup,
21700 +};
21701 +
21702 +static struct vs_entry nx_virtnet_stuff[] = {
21703 +       INF("info",     S_IRUGO, virtnet_info),
21704 +       INF("status",   S_IRUGO, virtnet_status),
21705 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
21706 +};
21707 +
21708 +
21709 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
21710 +       struct dentry *dentry, unsigned int flags)
21711 +{
21712 +       struct vs_entry *p = nx_virtnet_stuff;
21713 +       struct dentry *error = ERR_PTR(-ENOENT);
21714 +       int id = 0;
21715 +
21716 +       for (; p->name; p++) {
21717 +               if (p->len != dentry->d_name.len)
21718 +                       continue;
21719 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21720 +                       break;
21721 +       }
21722 +       if (p->name)
21723 +               goto instantiate;
21724 +
21725 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
21726 +       if ((id < 0) || !nid_is_hashed(id))
21727 +               goto out;
21728 +
21729 +instantiate:
21730 +       error = proc_nid_instantiate(dir, dentry, id, p);
21731 +out:
21732 +       return error;
21733 +}
21734 +
21735 +
21736 +#define PROC_MAXVIDS 32
21737 +
21738 +int proc_virtual_readdir(struct file *filp,
21739 +       void *dirent, filldir_t filldir)
21740 +{
21741 +       struct dentry *dentry = filp->f_dentry;
21742 +       struct inode *inode = dentry->d_inode;
21743 +       struct vs_entry *p = vx_virtual_stuff;
21744 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
21745 +       int pos, index;
21746 +       unsigned int xid_array[PROC_MAXVIDS];
21747 +       char buf[PROC_NUMBUF];
21748 +       unsigned int nr_xids, i;
21749 +       u64 ino;
21750 +
21751 +       pos = filp->f_pos;
21752 +       switch (pos) {
21753 +       case 0:
21754 +               ino = inode->i_ino;
21755 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21756 +                       goto out;
21757 +               pos++;
21758 +               /* fall through */
21759 +       case 1:
21760 +               ino = parent_ino(dentry);
21761 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21762 +                       goto out;
21763 +               pos++;
21764 +               /* fall through */
21765 +       default:
21766 +               index = pos - 2;
21767 +               if (index >= size)
21768 +                       goto entries;
21769 +               for (p += index; p->name; p++) {
21770 +                       if (vx_proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21771 +                               vs_proc_instantiate, 0, p))
21772 +                               goto out;
21773 +                       pos++;
21774 +               }
21775 +       entries:
21776 +               index = pos - size;
21777 +               p = &vx_virtual_stuff[size - 1];
21778 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
21779 +               for (i = 0; i < nr_xids; i++) {
21780 +                       int n, xid = xid_array[i];
21781 +                       unsigned int j = PROC_NUMBUF;
21782 +
21783 +                       n = xid;
21784 +                       do
21785 +                               buf[--j] = '0' + (n % 10);
21786 +                       while (n /= 10);
21787 +
21788 +                       if (vx_proc_fill_cache(filp, dirent, filldir,
21789 +                               buf + j, PROC_NUMBUF - j,
21790 +                               vs_proc_instantiate, xid, p))
21791 +                               goto out;
21792 +                       pos++;
21793 +               }
21794 +       }
21795 +out:
21796 +       filp->f_pos = pos;
21797 +       return 0;
21798 +}
21799 +
21800 +static int proc_virtual_getattr(struct vfsmount *mnt,
21801 +       struct dentry *dentry, struct kstat *stat)
21802 +{
21803 +       struct inode *inode = dentry->d_inode;
21804 +
21805 +       generic_fillattr(inode, stat);
21806 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
21807 +       return 0;
21808 +}
21809 +
21810 +static struct file_operations proc_virtual_dir_operations = {
21811 +       .read =         generic_read_dir,
21812 +       .readdir =      proc_virtual_readdir,
21813 +};
21814 +
21815 +static struct inode_operations proc_virtual_dir_inode_operations = {
21816 +       .getattr =      proc_virtual_getattr,
21817 +       .lookup =       proc_virtual_lookup,
21818 +};
21819 +
21820 +
21821 +
21822 +
21823 +
21824 +int proc_virtnet_readdir(struct file *filp,
21825 +       void *dirent, filldir_t filldir)
21826 +{
21827 +       struct dentry *dentry = filp->f_dentry;
21828 +       struct inode *inode = dentry->d_inode;
21829 +       struct vs_entry *p = nx_virtnet_stuff;
21830 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
21831 +       int pos, index;
21832 +       unsigned int nid_array[PROC_MAXVIDS];
21833 +       char buf[PROC_NUMBUF];
21834 +       unsigned int nr_nids, i;
21835 +       u64 ino;
21836 +
21837 +       pos = filp->f_pos;
21838 +       switch (pos) {
21839 +       case 0:
21840 +               ino = inode->i_ino;
21841 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21842 +                       goto out;
21843 +               pos++;
21844 +               /* fall through */
21845 +       case 1:
21846 +               ino = parent_ino(dentry);
21847 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21848 +                       goto out;
21849 +               pos++;
21850 +               /* fall through */
21851 +       default:
21852 +               index = pos - 2;
21853 +               if (index >= size)
21854 +                       goto entries;
21855 +               for (p += index; p->name; p++) {
21856 +                       if (vx_proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21857 +                               vs_proc_instantiate, 0, p))
21858 +                               goto out;
21859 +                       pos++;
21860 +               }
21861 +       entries:
21862 +               index = pos - size;
21863 +               p = &nx_virtnet_stuff[size - 1];
21864 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
21865 +               for (i = 0; i < nr_nids; i++) {
21866 +                       int n, nid = nid_array[i];
21867 +                       unsigned int j = PROC_NUMBUF;
21868 +
21869 +                       n = nid;
21870 +                       do
21871 +                               buf[--j] = '0' + (n % 10);
21872 +                       while (n /= 10);
21873 +
21874 +                       if (vx_proc_fill_cache(filp, dirent, filldir,
21875 +                               buf + j, PROC_NUMBUF - j,
21876 +                               vs_proc_instantiate, nid, p))
21877 +                               goto out;
21878 +                       pos++;
21879 +               }
21880 +       }
21881 +out:
21882 +       filp->f_pos = pos;
21883 +       return 0;
21884 +}
21885 +
21886 +static int proc_virtnet_getattr(struct vfsmount *mnt,
21887 +       struct dentry *dentry, struct kstat *stat)
21888 +{
21889 +       struct inode *inode = dentry->d_inode;
21890 +
21891 +       generic_fillattr(inode, stat);
21892 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
21893 +       return 0;
21894 +}
21895 +
21896 +static struct file_operations proc_virtnet_dir_operations = {
21897 +       .read =         generic_read_dir,
21898 +       .readdir =      proc_virtnet_readdir,
21899 +};
21900 +
21901 +static struct inode_operations proc_virtnet_dir_inode_operations = {
21902 +       .getattr =      proc_virtnet_getattr,
21903 +       .lookup =       proc_virtnet_lookup,
21904 +};
21905 +
21906 +
21907 +
21908 +void proc_vx_init(void)
21909 +{
21910 +       struct proc_dir_entry *ent;
21911 +
21912 +       ent = proc_mkdir("virtual", 0);
21913 +       if (ent) {
21914 +               ent->proc_fops = &proc_virtual_dir_operations;
21915 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
21916 +       }
21917 +       proc_virtual = ent;
21918 +
21919 +       ent = proc_mkdir("virtnet", 0);
21920 +       if (ent) {
21921 +               ent->proc_fops = &proc_virtnet_dir_operations;
21922 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
21923 +       }
21924 +       proc_virtnet = ent;
21925 +}
21926 +
21927 +
21928 +
21929 +
21930 +/* per pid info */
21931 +
21932 +
21933 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
21934 +{
21935 +       struct vx_info *vxi;
21936 +       char *orig = buffer;
21937 +
21938 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
21939 +
21940 +       vxi = task_get_vx_info(p);
21941 +       if (!vxi)
21942 +               goto out;
21943 +
21944 +       buffer += sprintf(buffer, "BCaps:\t");
21945 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
21946 +       buffer += sprintf(buffer, "\n");
21947 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
21948 +               (unsigned long long)vxi->vx_ccaps);
21949 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
21950 +               (unsigned long long)vxi->vx_flags);
21951 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
21952 +
21953 +       put_vx_info(vxi);
21954 +out:
21955 +       return buffer - orig;
21956 +}
21957 +
21958 +
21959 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
21960 +{
21961 +       struct nx_info *nxi;
21962 +       struct nx_addr_v4 *v4a;
21963 +#ifdef CONFIG_IPV6
21964 +       struct nx_addr_v6 *v6a;
21965 +#endif
21966 +       char *orig = buffer;
21967 +       int i;
21968 +
21969 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
21970 +
21971 +       nxi = task_get_nx_info(p);
21972 +       if (!nxi)
21973 +               goto out;
21974 +
21975 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
21976 +               (unsigned long long)nxi->nx_ncaps);
21977 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
21978 +               (unsigned long long)nxi->nx_flags);
21979 +
21980 +       buffer += sprintf(buffer,
21981 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
21982 +               NIPQUAD(nxi->v4_bcast.s_addr));
21983 +       buffer += sprintf (buffer,
21984 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
21985 +               NIPQUAD(nxi->v4_lback.s_addr));
21986 +       if (!NX_IPV4(nxi))
21987 +               goto skip_v4;
21988 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
21989 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
21990 +                       i, NXAV4(v4a));
21991 +skip_v4:
21992 +#ifdef CONFIG_IPV6
21993 +       if (!NX_IPV6(nxi))
21994 +               goto skip_v6;
21995 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
21996 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
21997 +                       i, NXAV6(v6a));
21998 +skip_v6:
21999 +#endif
22000 +       put_nx_info(nxi);
22001 +out:
22002 +       return buffer - orig;
22003 +}
22004 +
22005 diff -NurpP --minimal linux-3.10.33/kernel/vserver/sched.c linux-3.10.33-vs2.3.6.8/kernel/vserver/sched.c
22006 --- linux-3.10.33/kernel/vserver/sched.c        1970-01-01 00:00:00.000000000 +0000
22007 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/sched.c      2013-08-22 20:30:00.000000000 +0000
22008 @@ -0,0 +1,83 @@
22009 +/*
22010 + *  linux/kernel/vserver/sched.c
22011 + *
22012 + *  Virtual Server: Scheduler Support
22013 + *
22014 + *  Copyright (C) 2004-2010  Herbert Pötzl
22015 + *
22016 + *  V0.01  adapted Sam Vilains version to 2.6.3
22017 + *  V0.02  removed legacy interface
22018 + *  V0.03  changed vcmds to vxi arg
22019 + *  V0.04  removed older and legacy interfaces
22020 + *  V0.05  removed scheduler code/commands
22021 + *
22022 + */
22023 +
22024 +#include <linux/vs_context.h>
22025 +#include <linux/vs_sched.h>
22026 +#include <linux/cpumask.h>
22027 +#include <linux/vserver/sched_cmd.h>
22028 +
22029 +#include <asm/uaccess.h>
22030 +
22031 +
22032 +void vx_update_sched_param(struct _vx_sched *sched,
22033 +       struct _vx_sched_pc *sched_pc)
22034 +{
22035 +       sched_pc->prio_bias = sched->prio_bias;
22036 +}
22037 +
22038 +static int do_set_prio_bias(struct vx_info *vxi, struct vcmd_prio_bias *data)
22039 +{
22040 +       int cpu;
22041 +
22042 +       if (data->prio_bias > MAX_PRIO_BIAS)
22043 +               data->prio_bias = MAX_PRIO_BIAS;
22044 +       if (data->prio_bias < MIN_PRIO_BIAS)
22045 +               data->prio_bias = MIN_PRIO_BIAS;
22046 +
22047 +       if (data->cpu_id != ~0) {
22048 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
22049 +               cpumask_and(&vxi->sched.update, &vxi->sched.update,
22050 +                       cpu_online_mask);
22051 +       } else
22052 +               cpumask_copy(&vxi->sched.update, cpu_online_mask);
22053 +
22054 +       for_each_cpu_mask(cpu, vxi->sched.update)
22055 +               vx_update_sched_param(&vxi->sched,
22056 +                       &vx_per_cpu(vxi, sched_pc, cpu));
22057 +       return 0;
22058 +}
22059 +
22060 +int vc_set_prio_bias(struct vx_info *vxi, void __user *data)
22061 +{
22062 +       struct vcmd_prio_bias vc_data;
22063 +
22064 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22065 +               return -EFAULT;
22066 +
22067 +       return do_set_prio_bias(vxi, &vc_data);
22068 +}
22069 +
22070 +int vc_get_prio_bias(struct vx_info *vxi, void __user *data)
22071 +{
22072 +       struct vcmd_prio_bias vc_data;
22073 +       struct _vx_sched_pc *pcd;
22074 +       int cpu;
22075 +
22076 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22077 +               return -EFAULT;
22078 +
22079 +       cpu = vc_data.cpu_id;
22080 +
22081 +       if (!cpu_possible(cpu))
22082 +               return -EINVAL;
22083 +
22084 +       pcd = &vx_per_cpu(vxi, sched_pc, cpu);
22085 +       vc_data.prio_bias = pcd->prio_bias;
22086 +
22087 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22088 +               return -EFAULT;
22089 +       return 0;
22090 +}
22091 +
22092 diff -NurpP --minimal linux-3.10.33/kernel/vserver/sched_init.h linux-3.10.33-vs2.3.6.8/kernel/vserver/sched_init.h
22093 --- linux-3.10.33/kernel/vserver/sched_init.h   1970-01-01 00:00:00.000000000 +0000
22094 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/sched_init.h 2013-08-22 20:30:00.000000000 +0000
22095 @@ -0,0 +1,27 @@
22096 +
22097 +static inline void vx_info_init_sched(struct _vx_sched *sched)
22098 +{
22099 +       /* scheduling; hard code starting values as constants */
22100 +       sched->prio_bias = 0;
22101 +}
22102 +
22103 +static inline
22104 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22105 +{
22106 +       sched_pc->prio_bias = 0;
22107 +
22108 +       sched_pc->user_ticks = 0;
22109 +       sched_pc->sys_ticks = 0;
22110 +       sched_pc->hold_ticks = 0;
22111 +}
22112 +
22113 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
22114 +{
22115 +       return;
22116 +}
22117 +
22118 +static inline
22119 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22120 +{
22121 +       return;
22122 +}
22123 diff -NurpP --minimal linux-3.10.33/kernel/vserver/sched_proc.h linux-3.10.33-vs2.3.6.8/kernel/vserver/sched_proc.h
22124 --- linux-3.10.33/kernel/vserver/sched_proc.h   1970-01-01 00:00:00.000000000 +0000
22125 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/sched_proc.h 2013-08-22 20:30:00.000000000 +0000
22126 @@ -0,0 +1,32 @@
22127 +#ifndef _VX_SCHED_PROC_H
22128 +#define _VX_SCHED_PROC_H
22129 +
22130 +
22131 +static inline
22132 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
22133 +{
22134 +       int length = 0;
22135 +
22136 +       length += sprintf(buffer,
22137 +               "PrioBias:\t%8d\n",
22138 +               sched->prio_bias);
22139 +       return length;
22140 +}
22141 +
22142 +static inline
22143 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
22144 +       char *buffer, int cpu)
22145 +{
22146 +       int length = 0;
22147 +
22148 +       length += sprintf(buffer + length,
22149 +               "cpu %d: %lld %lld %lld", cpu,
22150 +               (unsigned long long)sched_pc->user_ticks,
22151 +               (unsigned long long)sched_pc->sys_ticks,
22152 +               (unsigned long long)sched_pc->hold_ticks);
22153 +       length += sprintf(buffer + length,
22154 +               " %d\n", sched_pc->prio_bias);
22155 +       return length;
22156 +}
22157 +
22158 +#endif /* _VX_SCHED_PROC_H */
22159 diff -NurpP --minimal linux-3.10.33/kernel/vserver/signal.c linux-3.10.33-vs2.3.6.8/kernel/vserver/signal.c
22160 --- linux-3.10.33/kernel/vserver/signal.c       1970-01-01 00:00:00.000000000 +0000
22161 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/signal.c     2013-08-22 20:30:00.000000000 +0000
22162 @@ -0,0 +1,134 @@
22163 +/*
22164 + *  linux/kernel/vserver/signal.c
22165 + *
22166 + *  Virtual Server: Signal Support
22167 + *
22168 + *  Copyright (C) 2003-2007  Herbert Pötzl
22169 + *
22170 + *  V0.01  broken out from vcontext V0.05
22171 + *  V0.02  changed vcmds to vxi arg
22172 + *  V0.03  adjusted siginfo for kill
22173 + *
22174 + */
22175 +
22176 +#include <asm/uaccess.h>
22177 +
22178 +#include <linux/vs_context.h>
22179 +#include <linux/vs_pid.h>
22180 +#include <linux/vserver/signal_cmd.h>
22181 +
22182 +
22183 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
22184 +{
22185 +       int retval, count = 0;
22186 +       struct task_struct *p;
22187 +       struct siginfo *sip = SEND_SIG_PRIV;
22188 +
22189 +       retval = -ESRCH;
22190 +       vxdprintk(VXD_CBIT(misc, 4),
22191 +               "vx_info_kill(%p[#%d],%d,%d)*",
22192 +               vxi, vxi->vx_id, pid, sig);
22193 +       read_lock(&tasklist_lock);
22194 +       switch (pid) {
22195 +       case  0:
22196 +       case -1:
22197 +               for_each_process(p) {
22198 +                       int err = 0;
22199 +
22200 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
22201 +                               (pid && vxi->vx_initpid == p->pid))
22202 +                               continue;
22203 +
22204 +                       err = group_send_sig_info(sig, sip, p);
22205 +                       ++count;
22206 +                       if (err != -EPERM)
22207 +                               retval = err;
22208 +               }
22209 +               break;
22210 +
22211 +       case 1:
22212 +               if (vxi->vx_initpid) {
22213 +                       pid = vxi->vx_initpid;
22214 +                       /* for now, only SIGINT to private init ... */
22215 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22216 +                               /* ... as long as there are tasks left */
22217 +                               (atomic_read(&vxi->vx_tasks) > 1))
22218 +                               sig = SIGINT;
22219 +               }
22220 +               /* fallthrough */
22221 +       default:
22222 +               rcu_read_lock();
22223 +               p = find_task_by_real_pid(pid);
22224 +               rcu_read_unlock();
22225 +               if (p) {
22226 +                       if (vx_task_xid(p) == vxi->vx_id)
22227 +                               retval = group_send_sig_info(sig, sip, p);
22228 +               }
22229 +               break;
22230 +       }
22231 +       read_unlock(&tasklist_lock);
22232 +       vxdprintk(VXD_CBIT(misc, 4),
22233 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
22234 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
22235 +       return retval;
22236 +}
22237 +
22238 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
22239 +{
22240 +       struct vcmd_ctx_kill_v0 vc_data;
22241 +
22242 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22243 +               return -EFAULT;
22244 +
22245 +       /* special check to allow guest shutdown */
22246 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22247 +               /* forbid killall pid=0 when init is present */
22248 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
22249 +               (vc_data.pid > 1)))
22250 +               return -EACCES;
22251 +
22252 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
22253 +}
22254 +
22255 +
22256 +static int __wait_exit(struct vx_info *vxi)
22257 +{
22258 +       DECLARE_WAITQUEUE(wait, current);
22259 +       int ret = 0;
22260 +
22261 +       add_wait_queue(&vxi->vx_wait, &wait);
22262 +       set_current_state(TASK_INTERRUPTIBLE);
22263 +
22264 +wait:
22265 +       if (vx_info_state(vxi,
22266 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
22267 +               goto out;
22268 +       if (signal_pending(current)) {
22269 +               ret = -ERESTARTSYS;
22270 +               goto out;
22271 +       }
22272 +       schedule();
22273 +       goto wait;
22274 +
22275 +out:
22276 +       set_current_state(TASK_RUNNING);
22277 +       remove_wait_queue(&vxi->vx_wait, &wait);
22278 +       return ret;
22279 +}
22280 +
22281 +
22282 +
22283 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
22284 +{
22285 +       struct vcmd_wait_exit_v0 vc_data;
22286 +       int ret;
22287 +
22288 +       ret = __wait_exit(vxi);
22289 +       vc_data.reboot_cmd = vxi->reboot_cmd;
22290 +       vc_data.exit_code = vxi->exit_code;
22291 +
22292 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22293 +               ret = -EFAULT;
22294 +       return ret;
22295 +}
22296 +
22297 diff -NurpP --minimal linux-3.10.33/kernel/vserver/space.c linux-3.10.33-vs2.3.6.8/kernel/vserver/space.c
22298 --- linux-3.10.33/kernel/vserver/space.c        1970-01-01 00:00:00.000000000 +0000
22299 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/space.c      2013-08-22 20:30:00.000000000 +0000
22300 @@ -0,0 +1,436 @@
22301 +/*
22302 + *  linux/kernel/vserver/space.c
22303 + *
22304 + *  Virtual Server: Context Space Support
22305 + *
22306 + *  Copyright (C) 2003-2010  Herbert Pötzl
22307 + *
22308 + *  V0.01  broken out from context.c 0.07
22309 + *  V0.02  added task locking for namespace
22310 + *  V0.03  broken out vx_enter_namespace
22311 + *  V0.04  added *space support and commands
22312 + *  V0.05  added credential support
22313 + *
22314 + */
22315 +
22316 +#include <linux/utsname.h>
22317 +#include <linux/nsproxy.h>
22318 +#include <linux/err.h>
22319 +#include <linux/fs_struct.h>
22320 +#include <linux/cred.h>
22321 +#include <asm/uaccess.h>
22322 +
22323 +#include <linux/vs_context.h>
22324 +#include <linux/vserver/space.h>
22325 +#include <linux/vserver/space_cmd.h>
22326 +
22327 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
22328 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
22329 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
22330 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
22331 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
22332 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
22333 +
22334 +
22335 +/* namespace functions */
22336 +
22337 +#include <linux/mnt_namespace.h>
22338 +#include <linux/user_namespace.h>
22339 +#include <linux/pid_namespace.h>
22340 +#include <linux/ipc_namespace.h>
22341 +#include <net/net_namespace.h>
22342 +#include "../fs/mount.h"
22343 +
22344 +
22345 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
22346 +       .mask = CLONE_FS |
22347 +               CLONE_NEWNS |
22348 +#ifdef CONFIG_UTS_NS
22349 +               CLONE_NEWUTS |
22350 +#endif
22351 +#ifdef CONFIG_IPC_NS
22352 +               CLONE_NEWIPC |
22353 +#endif
22354 +#ifdef CONFIG_USER_NS
22355 +               CLONE_NEWUSER |
22356 +#endif
22357 +               0
22358 +};
22359 +
22360 +static const struct vcmd_space_mask_v1 space_mask = {
22361 +       .mask = CLONE_FS |
22362 +               CLONE_NEWNS |
22363 +#ifdef CONFIG_UTS_NS
22364 +               CLONE_NEWUTS |
22365 +#endif
22366 +#ifdef CONFIG_IPC_NS
22367 +               CLONE_NEWIPC |
22368 +#endif
22369 +#ifdef CONFIG_USER_NS
22370 +               CLONE_NEWUSER |
22371 +#endif
22372 +#ifdef CONFIG_PID_NS
22373 +               CLONE_NEWPID |
22374 +#endif
22375 +#ifdef CONFIG_NET_NS
22376 +               CLONE_NEWNET |
22377 +#endif
22378 +               0
22379 +};
22380 +
22381 +static const struct vcmd_space_mask_v1 default_space_mask = {
22382 +       .mask = CLONE_FS |
22383 +               CLONE_NEWNS |
22384 +#ifdef CONFIG_UTS_NS
22385 +               CLONE_NEWUTS |
22386 +#endif
22387 +#ifdef CONFIG_IPC_NS
22388 +               CLONE_NEWIPC |
22389 +#endif
22390 +#ifdef CONFIG_USER_NS
22391 +               CLONE_NEWUSER |
22392 +#endif
22393 +#ifdef CONFIG_PID_NS
22394 +//             CLONE_NEWPID |
22395 +#endif
22396 +               0
22397 +};
22398 +
22399 +/*
22400 + *     build a new nsproxy mix
22401 + *      assumes that both proxies are 'const'
22402 + *     does not touch nsproxy refcounts
22403 + *     will hold a reference on the result.
22404 + */
22405 +
22406 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
22407 +       struct nsproxy *new_nsproxy, unsigned long mask)
22408 +{
22409 +       struct mnt_namespace *old_ns;
22410 +       struct uts_namespace *old_uts;
22411 +       struct ipc_namespace *old_ipc;
22412 +#ifdef CONFIG_PID_NS
22413 +       struct pid_namespace *old_pid;
22414 +#endif
22415 +#ifdef CONFIG_NET_NS
22416 +       struct net *old_net;
22417 +#endif
22418 +       struct nsproxy *nsproxy;
22419 +
22420 +       nsproxy = copy_nsproxy(old_nsproxy);
22421 +       if (!nsproxy)
22422 +               goto out;
22423 +
22424 +       if (mask & CLONE_NEWNS) {
22425 +               old_ns = nsproxy->mnt_ns;
22426 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
22427 +               if (nsproxy->mnt_ns)
22428 +                       get_mnt_ns(nsproxy->mnt_ns);
22429 +       } else
22430 +               old_ns = NULL;
22431 +
22432 +       if (mask & CLONE_NEWUTS) {
22433 +               old_uts = nsproxy->uts_ns;
22434 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
22435 +               if (nsproxy->uts_ns)
22436 +                       get_uts_ns(nsproxy->uts_ns);
22437 +       } else
22438 +               old_uts = NULL;
22439 +
22440 +       if (mask & CLONE_NEWIPC) {
22441 +               old_ipc = nsproxy->ipc_ns;
22442 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
22443 +               if (nsproxy->ipc_ns)
22444 +                       get_ipc_ns(nsproxy->ipc_ns);
22445 +       } else
22446 +               old_ipc = NULL;
22447 +
22448 +#ifdef CONFIG_PID_NS
22449 +       if (mask & CLONE_NEWPID) {
22450 +               old_pid = nsproxy->pid_ns;
22451 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
22452 +               if (nsproxy->pid_ns)
22453 +                       get_pid_ns(nsproxy->pid_ns);
22454 +       } else
22455 +               old_pid = NULL;
22456 +#endif
22457 +#ifdef CONFIG_NET_NS
22458 +       if (mask & CLONE_NEWNET) {
22459 +               old_net = nsproxy->net_ns;
22460 +               nsproxy->net_ns = new_nsproxy->net_ns;
22461 +               if (nsproxy->net_ns)
22462 +                       get_net(nsproxy->net_ns);
22463 +       } else
22464 +               old_net = NULL;
22465 +#endif
22466 +       if (old_ns)
22467 +               put_mnt_ns(old_ns);
22468 +       if (old_uts)
22469 +               put_uts_ns(old_uts);
22470 +       if (old_ipc)
22471 +               put_ipc_ns(old_ipc);
22472 +#ifdef CONFIG_PID_NS
22473 +       if (old_pid)
22474 +               put_pid_ns(old_pid);
22475 +#endif
22476 +#ifdef CONFIG_NET_NS
22477 +       if (old_net)
22478 +               put_net(old_net);
22479 +#endif
22480 +out:
22481 +       return nsproxy;
22482 +}
22483 +
22484 +
22485 +/*
22486 + *     merge two nsproxy structs into a new one.
22487 + *     will hold a reference on the result.
22488 + */
22489 +
22490 +static inline
22491 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
22492 +       struct nsproxy *proxy, unsigned long mask)
22493 +{
22494 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
22495 +
22496 +       if (!proxy)
22497 +               return NULL;
22498 +
22499 +       if (mask) {
22500 +               /* vs_mix_nsproxy returns with reference */
22501 +               return vs_mix_nsproxy(old ? old : &null_proxy,
22502 +                       proxy, mask);
22503 +       }
22504 +       get_nsproxy(proxy);
22505 +       return proxy;
22506 +}
22507 +
22508 +
22509 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
22510 +{
22511 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
22512 +       struct fs_struct *fs_cur, *fs = NULL;
22513 +       struct _vx_space *space;
22514 +       int ret, kill = 0;
22515 +
22516 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
22517 +               vxi, vxi->vx_id, mask, index);
22518 +
22519 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
22520 +               return -EACCES;
22521 +
22522 +       if (index >= VX_SPACES)
22523 +               return -EINVAL;
22524 +
22525 +       space = &vxi->space[index];
22526 +
22527 +       if (!mask)
22528 +               mask = space->vx_nsmask;
22529 +
22530 +       if ((mask & space->vx_nsmask) != mask)
22531 +               return -EINVAL;
22532 +
22533 +       if (mask & CLONE_FS) {
22534 +               fs = copy_fs_struct(space->vx_fs);
22535 +               if (!fs)
22536 +                       return -ENOMEM;
22537 +       }
22538 +       proxy = space->vx_nsproxy;
22539 +
22540 +       vxdprintk(VXD_CBIT(space, 9),
22541 +               "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
22542 +               vxi, vxi->vx_id, mask, index, proxy, fs);
22543 +
22544 +       task_lock(current);
22545 +       fs_cur = current->fs;
22546 +
22547 +       if (mask & CLONE_FS) {
22548 +               spin_lock(&fs_cur->lock);
22549 +               current->fs = fs;
22550 +               kill = !--fs_cur->users;
22551 +               spin_unlock(&fs_cur->lock);
22552 +       }
22553 +
22554 +       proxy_cur = current->nsproxy;
22555 +       get_nsproxy(proxy_cur);
22556 +       task_unlock(current);
22557 +
22558 +       if (kill)
22559 +               free_fs_struct(fs_cur);
22560 +
22561 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
22562 +       if (IS_ERR(proxy_new)) {
22563 +               ret = PTR_ERR(proxy_new);
22564 +               goto out_put;
22565 +       }
22566 +
22567 +       proxy_new = xchg(&current->nsproxy, proxy_new);
22568 +
22569 +       if (mask & CLONE_NEWUSER) {
22570 +               struct cred *cred;
22571 +
22572 +               vxdprintk(VXD_CBIT(space, 10),
22573 +                       "vx_enter_space(%p[#%u],%p) cred (%p,%p)",
22574 +                       vxi, vxi->vx_id, space->vx_cred,
22575 +                       current->real_cred, current->cred);
22576 +
22577 +               if (space->vx_cred) {
22578 +                       cred = __prepare_creds(space->vx_cred);
22579 +                       if (cred)
22580 +                               commit_creds(cred);
22581 +               }
22582 +       }
22583 +
22584 +       ret = 0;
22585 +
22586 +       if (proxy_new)
22587 +               put_nsproxy(proxy_new);
22588 +out_put:
22589 +       if (proxy_cur)
22590 +               put_nsproxy(proxy_cur);
22591 +       return ret;
22592 +}
22593 +
22594 +
22595 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
22596 +{
22597 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
22598 +       struct fs_struct *fs_vxi, *fs = NULL;
22599 +       struct _vx_space *space;
22600 +       int ret, kill = 0;
22601 +
22602 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
22603 +               vxi, vxi->vx_id, mask, index);
22604 +
22605 +       if ((mask & space_mask.mask) != mask)
22606 +               return -EINVAL;
22607 +
22608 +       if (index >= VX_SPACES)
22609 +               return -EINVAL;
22610 +
22611 +       space = &vxi->space[index];
22612 +
22613 +       proxy_vxi = space->vx_nsproxy;
22614 +       fs_vxi = space->vx_fs;
22615 +
22616 +       if (mask & CLONE_FS) {
22617 +               fs = copy_fs_struct(current->fs);
22618 +               if (!fs)
22619 +                       return -ENOMEM;
22620 +       }
22621 +
22622 +       task_lock(current);
22623 +
22624 +       if (mask & CLONE_FS) {
22625 +               spin_lock(&fs_vxi->lock);
22626 +               space->vx_fs = fs;
22627 +               kill = !--fs_vxi->users;
22628 +               spin_unlock(&fs_vxi->lock);
22629 +       }
22630 +
22631 +       proxy_cur = current->nsproxy;
22632 +       get_nsproxy(proxy_cur);
22633 +       task_unlock(current);
22634 +
22635 +       if (kill)
22636 +               free_fs_struct(fs_vxi);
22637 +
22638 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
22639 +       if (IS_ERR(proxy_new)) {
22640 +               ret = PTR_ERR(proxy_new);
22641 +               goto out_put;
22642 +       }
22643 +
22644 +       proxy_new = xchg(&space->vx_nsproxy, proxy_new);
22645 +       space->vx_nsmask |= mask;
22646 +
22647 +       if (mask & CLONE_NEWUSER) {
22648 +               struct cred *cred;
22649 +
22650 +               vxdprintk(VXD_CBIT(space, 10),
22651 +                       "vx_set_space(%p[#%u],%p) cred (%p,%p)",
22652 +                       vxi, vxi->vx_id, space->vx_cred,
22653 +                       current->real_cred, current->cred);
22654 +
22655 +               cred = prepare_creds();
22656 +               cred = (struct cred *)xchg(&space->vx_cred, cred);
22657 +               if (cred)
22658 +                       abort_creds(cred);
22659 +       }
22660 +
22661 +       ret = 0;
22662 +
22663 +       if (proxy_new)
22664 +               put_nsproxy(proxy_new);
22665 +out_put:
22666 +       if (proxy_cur)
22667 +               put_nsproxy(proxy_cur);
22668 +       return ret;
22669 +}
22670 +
22671 +
22672 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
22673 +{
22674 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22675 +
22676 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22677 +               return -EFAULT;
22678 +
22679 +       return vx_enter_space(vxi, vc_data.mask, 0);
22680 +}
22681 +
22682 +int vc_enter_space(struct vx_info *vxi, void __user *data)
22683 +{
22684 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22685 +
22686 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22687 +               return -EFAULT;
22688 +
22689 +       if (vc_data.index >= VX_SPACES)
22690 +               return -EINVAL;
22691 +
22692 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
22693 +}
22694 +
22695 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
22696 +{
22697 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22698 +
22699 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22700 +               return -EFAULT;
22701 +
22702 +       return vx_set_space(vxi, vc_data.mask, 0);
22703 +}
22704 +
22705 +int vc_set_space(struct vx_info *vxi, void __user *data)
22706 +{
22707 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22708 +
22709 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22710 +               return -EFAULT;
22711 +
22712 +       if (vc_data.index >= VX_SPACES)
22713 +               return -EINVAL;
22714 +
22715 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
22716 +}
22717 +
22718 +int vc_get_space_mask(void __user *data, int type)
22719 +{
22720 +       const struct vcmd_space_mask_v1 *mask;
22721 +
22722 +       if (type == 0)
22723 +               mask = &space_mask_v0;
22724 +       else if (type == 1)
22725 +               mask = &space_mask;
22726 +       else
22727 +               mask = &default_space_mask;
22728 +
22729 +       vxdprintk(VXD_CBIT(space, 10),
22730 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
22731 +
22732 +       if (copy_to_user(data, mask, sizeof(*mask)))
22733 +               return -EFAULT;
22734 +       return 0;
22735 +}
22736 +
22737 diff -NurpP --minimal linux-3.10.33/kernel/vserver/switch.c linux-3.10.33-vs2.3.6.8/kernel/vserver/switch.c
22738 --- linux-3.10.33/kernel/vserver/switch.c       1970-01-01 00:00:00.000000000 +0000
22739 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/switch.c     2013-08-22 20:30:00.000000000 +0000
22740 @@ -0,0 +1,556 @@
22741 +/*
22742 + *  linux/kernel/vserver/switch.c
22743 + *
22744 + *  Virtual Server: Syscall Switch
22745 + *
22746 + *  Copyright (C) 2003-2011  Herbert Pötzl
22747 + *
22748 + *  V0.01  syscall switch
22749 + *  V0.02  added signal to context
22750 + *  V0.03  added rlimit functions
22751 + *  V0.04  added iattr, task/xid functions
22752 + *  V0.05  added debug/history stuff
22753 + *  V0.06  added compat32 layer
22754 + *  V0.07  vcmd args and perms
22755 + *  V0.08  added status commands
22756 + *  V0.09  added tag commands
22757 + *  V0.10  added oom bias
22758 + *  V0.11  added device commands
22759 + *  V0.12  added warn mask
22760 + *
22761 + */
22762 +
22763 +#include <linux/vs_context.h>
22764 +#include <linux/vs_network.h>
22765 +#include <linux/vserver/switch.h>
22766 +
22767 +#include "vci_config.h"
22768 +
22769 +
22770 +static inline
22771 +int vc_get_version(uint32_t id)
22772 +{
22773 +       return VCI_VERSION;
22774 +}
22775 +
22776 +static inline
22777 +int vc_get_vci(uint32_t id)
22778 +{
22779 +       return vci_kernel_config();
22780 +}
22781 +
22782 +#include <linux/vserver/context_cmd.h>
22783 +#include <linux/vserver/cvirt_cmd.h>
22784 +#include <linux/vserver/cacct_cmd.h>
22785 +#include <linux/vserver/limit_cmd.h>
22786 +#include <linux/vserver/network_cmd.h>
22787 +#include <linux/vserver/sched_cmd.h>
22788 +#include <linux/vserver/debug_cmd.h>
22789 +#include <linux/vserver/inode_cmd.h>
22790 +#include <linux/vserver/dlimit_cmd.h>
22791 +#include <linux/vserver/signal_cmd.h>
22792 +#include <linux/vserver/space_cmd.h>
22793 +#include <linux/vserver/tag_cmd.h>
22794 +#include <linux/vserver/device_cmd.h>
22795 +
22796 +#include <linux/vserver/inode.h>
22797 +#include <linux/vserver/dlimit.h>
22798 +
22799 +
22800 +#ifdef CONFIG_COMPAT
22801 +#define __COMPAT(name, id, data, compat)       \
22802 +       (compat) ? name ## _x32(id, data) : name(id, data)
22803 +#define __COMPAT_NO_ID(name, data, compat)     \
22804 +       (compat) ? name ## _x32(data) : name(data)
22805 +#else
22806 +#define __COMPAT(name, id, data, compat)       \
22807 +       name(id, data)
22808 +#define __COMPAT_NO_ID(name, data, compat)     \
22809 +       name(data)
22810 +#endif
22811 +
22812 +
22813 +static inline
22814 +long do_vcmd(uint32_t cmd, uint32_t id,
22815 +       struct vx_info *vxi, struct nx_info *nxi,
22816 +       void __user *data, int compat)
22817 +{
22818 +       switch (cmd) {
22819 +
22820 +       case VCMD_get_version:
22821 +               return vc_get_version(id);
22822 +       case VCMD_get_vci:
22823 +               return vc_get_vci(id);
22824 +
22825 +       case VCMD_task_xid:
22826 +               return vc_task_xid(id);
22827 +       case VCMD_vx_info:
22828 +               return vc_vx_info(vxi, data);
22829 +
22830 +       case VCMD_task_nid:
22831 +               return vc_task_nid(id);
22832 +       case VCMD_nx_info:
22833 +               return vc_nx_info(nxi, data);
22834 +
22835 +       case VCMD_task_tag:
22836 +               return vc_task_tag(id);
22837 +
22838 +       case VCMD_set_space_v1:
22839 +               return vc_set_space_v1(vxi, data);
22840 +       /* this is version 2 */
22841 +       case VCMD_set_space:
22842 +               return vc_set_space(vxi, data);
22843 +
22844 +       case VCMD_get_space_mask_v0:
22845 +               return vc_get_space_mask(data, 0);
22846 +       /* this is version 1 */
22847 +       case VCMD_get_space_mask:
22848 +               return vc_get_space_mask(data, 1);
22849 +
22850 +       case VCMD_get_space_default:
22851 +               return vc_get_space_mask(data, -1);
22852 +
22853 +       case VCMD_set_umask:
22854 +               return vc_set_umask(vxi, data);
22855 +
22856 +       case VCMD_get_umask:
22857 +               return vc_get_umask(vxi, data);
22858 +
22859 +       case VCMD_set_wmask:
22860 +               return vc_set_wmask(vxi, data);
22861 +
22862 +       case VCMD_get_wmask:
22863 +               return vc_get_wmask(vxi, data);
22864 +#ifdef CONFIG_IA32_EMULATION
22865 +       case VCMD_get_rlimit:
22866 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
22867 +       case VCMD_set_rlimit:
22868 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
22869 +#else
22870 +       case VCMD_get_rlimit:
22871 +               return vc_get_rlimit(vxi, data);
22872 +       case VCMD_set_rlimit:
22873 +               return vc_set_rlimit(vxi, data);
22874 +#endif
22875 +       case VCMD_get_rlimit_mask:
22876 +               return vc_get_rlimit_mask(id, data);
22877 +       case VCMD_reset_hits:
22878 +               return vc_reset_hits(vxi, data);
22879 +       case VCMD_reset_minmax:
22880 +               return vc_reset_minmax(vxi, data);
22881 +
22882 +       case VCMD_get_vhi_name:
22883 +               return vc_get_vhi_name(vxi, data);
22884 +       case VCMD_set_vhi_name:
22885 +               return vc_set_vhi_name(vxi, data);
22886 +
22887 +       case VCMD_ctx_stat:
22888 +               return vc_ctx_stat(vxi, data);
22889 +       case VCMD_virt_stat:
22890 +               return vc_virt_stat(vxi, data);
22891 +       case VCMD_sock_stat:
22892 +               return vc_sock_stat(vxi, data);
22893 +       case VCMD_rlimit_stat:
22894 +               return vc_rlimit_stat(vxi, data);
22895 +
22896 +       case VCMD_set_cflags:
22897 +               return vc_set_cflags(vxi, data);
22898 +       case VCMD_get_cflags:
22899 +               return vc_get_cflags(vxi, data);
22900 +
22901 +       /* this is version 1 */
22902 +       case VCMD_set_ccaps:
22903 +               return vc_set_ccaps(vxi, data);
22904 +       /* this is version 1 */
22905 +       case VCMD_get_ccaps:
22906 +               return vc_get_ccaps(vxi, data);
22907 +       case VCMD_set_bcaps:
22908 +               return vc_set_bcaps(vxi, data);
22909 +       case VCMD_get_bcaps:
22910 +               return vc_get_bcaps(vxi, data);
22911 +
22912 +       case VCMD_set_badness:
22913 +               return vc_set_badness(vxi, data);
22914 +       case VCMD_get_badness:
22915 +               return vc_get_badness(vxi, data);
22916 +
22917 +       case VCMD_set_nflags:
22918 +               return vc_set_nflags(nxi, data);
22919 +       case VCMD_get_nflags:
22920 +               return vc_get_nflags(nxi, data);
22921 +
22922 +       case VCMD_set_ncaps:
22923 +               return vc_set_ncaps(nxi, data);
22924 +       case VCMD_get_ncaps:
22925 +               return vc_get_ncaps(nxi, data);
22926 +
22927 +       case VCMD_set_prio_bias:
22928 +               return vc_set_prio_bias(vxi, data);
22929 +       case VCMD_get_prio_bias:
22930 +               return vc_get_prio_bias(vxi, data);
22931 +       case VCMD_add_dlimit:
22932 +               return __COMPAT(vc_add_dlimit, id, data, compat);
22933 +       case VCMD_rem_dlimit:
22934 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
22935 +       case VCMD_set_dlimit:
22936 +               return __COMPAT(vc_set_dlimit, id, data, compat);
22937 +       case VCMD_get_dlimit:
22938 +               return __COMPAT(vc_get_dlimit, id, data, compat);
22939 +
22940 +       case VCMD_ctx_kill:
22941 +               return vc_ctx_kill(vxi, data);
22942 +
22943 +       case VCMD_wait_exit:
22944 +               return vc_wait_exit(vxi, data);
22945 +
22946 +       case VCMD_get_iattr:
22947 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
22948 +       case VCMD_set_iattr:
22949 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
22950 +
22951 +       case VCMD_fget_iattr:
22952 +               return vc_fget_iattr(id, data);
22953 +       case VCMD_fset_iattr:
22954 +               return vc_fset_iattr(id, data);
22955 +
22956 +       case VCMD_enter_space_v0:
22957 +               return vc_enter_space_v1(vxi, NULL);
22958 +       case VCMD_enter_space_v1:
22959 +               return vc_enter_space_v1(vxi, data);
22960 +       /* this is version 2 */
22961 +       case VCMD_enter_space:
22962 +               return vc_enter_space(vxi, data);
22963 +
22964 +       case VCMD_ctx_create_v0:
22965 +               return vc_ctx_create(id, NULL);
22966 +       case VCMD_ctx_create:
22967 +               return vc_ctx_create(id, data);
22968 +       case VCMD_ctx_migrate_v0:
22969 +               return vc_ctx_migrate(vxi, NULL);
22970 +       case VCMD_ctx_migrate:
22971 +               return vc_ctx_migrate(vxi, data);
22972 +
22973 +       case VCMD_net_create_v0:
22974 +               return vc_net_create(id, NULL);
22975 +       case VCMD_net_create:
22976 +               return vc_net_create(id, data);
22977 +       case VCMD_net_migrate:
22978 +               return vc_net_migrate(nxi, data);
22979 +
22980 +       case VCMD_tag_migrate:
22981 +               return vc_tag_migrate(id);
22982 +
22983 +       case VCMD_net_add:
22984 +               return vc_net_add(nxi, data);
22985 +       case VCMD_net_remove:
22986 +               return vc_net_remove(nxi, data);
22987 +
22988 +       case VCMD_net_add_ipv4_v1:
22989 +               return vc_net_add_ipv4_v1(nxi, data);
22990 +       /* this is version 2 */
22991 +       case VCMD_net_add_ipv4:
22992 +               return vc_net_add_ipv4(nxi, data);
22993 +
22994 +       case VCMD_net_rem_ipv4_v1:
22995 +               return vc_net_rem_ipv4_v1(nxi, data);
22996 +       /* this is version 2 */
22997 +       case VCMD_net_rem_ipv4:
22998 +               return vc_net_rem_ipv4(nxi, data);
22999 +#ifdef CONFIG_IPV6
23000 +       case VCMD_net_add_ipv6:
23001 +               return vc_net_add_ipv6(nxi, data);
23002 +       case VCMD_net_remove_ipv6:
23003 +               return vc_net_remove_ipv6(nxi, data);
23004 +#endif
23005 +/*     case VCMD_add_match_ipv4:
23006 +               return vc_add_match_ipv4(nxi, data);
23007 +       case VCMD_get_match_ipv4:
23008 +               return vc_get_match_ipv4(nxi, data);
23009 +#ifdef CONFIG_IPV6
23010 +       case VCMD_add_match_ipv6:
23011 +               return vc_add_match_ipv6(nxi, data);
23012 +       case VCMD_get_match_ipv6:
23013 +               return vc_get_match_ipv6(nxi, data);
23014 +#endif */
23015 +
23016 +#ifdef CONFIG_VSERVER_DEVICE
23017 +       case VCMD_set_mapping:
23018 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
23019 +       case VCMD_unset_mapping:
23020 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
23021 +#endif
23022 +#ifdef CONFIG_VSERVER_HISTORY
23023 +       case VCMD_dump_history:
23024 +               return vc_dump_history(id);
23025 +       case VCMD_read_history:
23026 +               return __COMPAT(vc_read_history, id, data, compat);
23027 +#endif
23028 +       default:
23029 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
23030 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
23031 +       }
23032 +       return -ENOSYS;
23033 +}
23034 +
23035 +
23036 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
23037 +       case VCMD_ ## vcmd: perm = _perm;               \
23038 +               args = _args; flags = _flags; break
23039 +
23040 +
23041 +#define VCA_NONE       0x00
23042 +#define VCA_VXI                0x01
23043 +#define VCA_NXI                0x02
23044 +
23045 +#define VCF_NONE       0x00
23046 +#define VCF_INFO       0x01
23047 +#define VCF_ADMIN      0x02
23048 +#define VCF_ARES       0x06    /* includes admin */
23049 +#define VCF_SETUP      0x08
23050 +
23051 +#define VCF_ZIDOK      0x10    /* zero id okay */
23052 +
23053 +
23054 +static inline
23055 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
23056 +{
23057 +       long ret;
23058 +       int permit = -1, state = 0;
23059 +       int perm = -1, args = 0, flags = 0;
23060 +       struct vx_info *vxi = NULL;
23061 +       struct nx_info *nxi = NULL;
23062 +
23063 +       switch (cmd) {
23064 +       /* unpriviledged commands */
23065 +       __VCMD(get_version,      0, VCA_NONE,   0);
23066 +       __VCMD(get_vci,          0, VCA_NONE,   0);
23067 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
23068 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
23069 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
23070 +       __VCMD(get_space_default,0, VCA_NONE,   0);
23071 +
23072 +       /* info commands */
23073 +       __VCMD(task_xid,         2, VCA_NONE,   0);
23074 +       __VCMD(reset_hits,       2, VCA_VXI,    0);
23075 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
23076 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
23077 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
23078 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
23079 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
23080 +       __VCMD(get_umask,        3, VCA_VXI,    VCF_INFO);
23081 +       __VCMD(get_wmask,        3, VCA_VXI,    VCF_INFO);
23082 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
23083 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
23084 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
23085 +
23086 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
23087 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
23088 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
23089 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
23090 +
23091 +       __VCMD(task_nid,         2, VCA_NONE,   0);
23092 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
23093 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
23094 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
23095 +
23096 +       __VCMD(task_tag,         2, VCA_NONE,   0);
23097 +
23098 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
23099 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
23100 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
23101 +       __VCMD(get_prio_bias,    3, VCA_VXI,    VCF_INFO);
23102 +
23103 +       /* lower admin commands */
23104 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
23105 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
23106 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
23107 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
23108 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
23109 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
23110 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
23111 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
23112 +
23113 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
23114 +       __VCMD(net_create,       5, VCA_NONE,   0);
23115 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
23116 +
23117 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
23118 +
23119 +       /* higher admin commands */
23120 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
23121 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23122 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23123 +
23124 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23125 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23126 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23127 +       __VCMD(set_umask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23128 +       __VCMD(set_wmask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23129 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23130 +
23131 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23132 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23133 +       __VCMD(set_prio_bias,    7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23134 +
23135 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23136 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23137 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23138 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23139 +       __VCMD(net_add_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23140 +       __VCMD(net_rem_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23141 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23142 +       __VCMD(net_rem_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23143 +#ifdef CONFIG_IPV6
23144 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23145 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23146 +#endif
23147 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
23148 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
23149 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
23150 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
23151 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
23152 +
23153 +#ifdef CONFIG_VSERVER_DEVICE
23154 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23155 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23156 +#endif
23157 +       /* debug level admin commands */
23158 +#ifdef CONFIG_VSERVER_HISTORY
23159 +       __VCMD(dump_history,     9, VCA_NONE,   0);
23160 +       __VCMD(read_history,     9, VCA_NONE,   0);
23161 +#endif
23162 +
23163 +       default:
23164 +               perm = -1;
23165 +       }
23166 +
23167 +       vxdprintk(VXD_CBIT(switch, 0),
23168 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
23169 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23170 +               VC_VERSION(cmd), id, data, compat,
23171 +               perm, args, flags);
23172 +
23173 +       ret = -ENOSYS;
23174 +       if (perm < 0)
23175 +               goto out;
23176 +
23177 +       state = 1;
23178 +       if (!capable(CAP_CONTEXT))
23179 +               goto out;
23180 +
23181 +       state = 2;
23182 +       /* moved here from the individual commands */
23183 +       ret = -EPERM;
23184 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
23185 +               goto out;
23186 +
23187 +       state = 3;
23188 +       /* vcmd involves resource management  */
23189 +       ret = -EPERM;
23190 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
23191 +               goto out;
23192 +
23193 +       state = 4;
23194 +       /* various legacy exceptions */
23195 +       switch (cmd) {
23196 +       /* will go away when spectator is a cap */
23197 +       case VCMD_ctx_migrate_v0:
23198 +       case VCMD_ctx_migrate:
23199 +               if (id == 1) {
23200 +                       current->xid = 1;
23201 +                       ret = 1;
23202 +                       goto out;
23203 +               }
23204 +               break;
23205 +
23206 +       /* will go away when spectator is a cap */
23207 +       case VCMD_net_migrate:
23208 +               if (id == 1) {
23209 +                       current->nid = 1;
23210 +                       ret = 1;
23211 +                       goto out;
23212 +               }
23213 +               break;
23214 +       }
23215 +
23216 +       /* vcmds are fine by default */
23217 +       permit = 1;
23218 +
23219 +       /* admin type vcmds require admin ... */
23220 +       if (flags & VCF_ADMIN)
23221 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
23222 +
23223 +       /* ... but setup type vcmds override that */
23224 +       if (!permit && (flags & VCF_SETUP))
23225 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
23226 +
23227 +       state = 5;
23228 +       ret = -EPERM;
23229 +       if (!permit)
23230 +               goto out;
23231 +
23232 +       state = 6;
23233 +       if (!id && (flags & VCF_ZIDOK))
23234 +               goto skip_id;
23235 +
23236 +       ret = -ESRCH;
23237 +       if (args & VCA_VXI) {
23238 +               vxi = lookup_vx_info(id);
23239 +               if (!vxi)
23240 +                       goto out;
23241 +
23242 +               if ((flags & VCF_ADMIN) &&
23243 +                       /* special case kill for shutdown */
23244 +                       (cmd != VCMD_ctx_kill) &&
23245 +                       /* can context be administrated? */
23246 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
23247 +                       ret = -EACCES;
23248 +                       goto out_vxi;
23249 +               }
23250 +       }
23251 +       state = 7;
23252 +       if (args & VCA_NXI) {
23253 +               nxi = lookup_nx_info(id);
23254 +               if (!nxi)
23255 +                       goto out_vxi;
23256 +
23257 +               if ((flags & VCF_ADMIN) &&
23258 +                       /* can context be administrated? */
23259 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
23260 +                       ret = -EACCES;
23261 +                       goto out_nxi;
23262 +               }
23263 +       }
23264 +skip_id:
23265 +       state = 8;
23266 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
23267 +
23268 +out_nxi:
23269 +       if ((args & VCA_NXI) && nxi)
23270 +               put_nx_info(nxi);
23271 +out_vxi:
23272 +       if ((args & VCA_VXI) && vxi)
23273 +               put_vx_info(vxi);
23274 +out:
23275 +       vxdprintk(VXD_CBIT(switch, 1),
23276 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
23277 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23278 +               VC_VERSION(cmd), ret, ret, state, permit);
23279 +       return ret;
23280 +}
23281 +
23282 +asmlinkage long
23283 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
23284 +{
23285 +       return do_vserver(cmd, id, data, 0);
23286 +}
23287 +
23288 +#ifdef CONFIG_COMPAT
23289 +
23290 +asmlinkage long
23291 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
23292 +{
23293 +       return do_vserver(cmd, id, data, 1);
23294 +}
23295 +
23296 +#endif /* CONFIG_COMPAT */
23297 diff -NurpP --minimal linux-3.10.33/kernel/vserver/sysctl.c linux-3.10.33-vs2.3.6.8/kernel/vserver/sysctl.c
23298 --- linux-3.10.33/kernel/vserver/sysctl.c       1970-01-01 00:00:00.000000000 +0000
23299 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/sysctl.c     2013-08-22 20:30:00.000000000 +0000
23300 @@ -0,0 +1,247 @@
23301 +/*
23302 + *  kernel/vserver/sysctl.c
23303 + *
23304 + *  Virtual Context Support
23305 + *
23306 + *  Copyright (C) 2004-2007  Herbert Pötzl
23307 + *
23308 + *  V0.01  basic structure
23309 + *
23310 + */
23311 +
23312 +#include <linux/module.h>
23313 +#include <linux/ctype.h>
23314 +#include <linux/sysctl.h>
23315 +#include <linux/parser.h>
23316 +#include <asm/uaccess.h>
23317 +
23318 +enum {
23319 +       CTL_DEBUG_ERROR         = 0,
23320 +       CTL_DEBUG_SWITCH        = 1,
23321 +       CTL_DEBUG_XID,
23322 +       CTL_DEBUG_NID,
23323 +       CTL_DEBUG_TAG,
23324 +       CTL_DEBUG_NET,
23325 +       CTL_DEBUG_LIMIT,
23326 +       CTL_DEBUG_CRES,
23327 +       CTL_DEBUG_DLIM,
23328 +       CTL_DEBUG_QUOTA,
23329 +       CTL_DEBUG_CVIRT,
23330 +       CTL_DEBUG_SPACE,
23331 +       CTL_DEBUG_PERM,
23332 +       CTL_DEBUG_MISC,
23333 +};
23334 +
23335 +
23336 +unsigned int vs_debug_switch   = 0;
23337 +unsigned int vs_debug_xid      = 0;
23338 +unsigned int vs_debug_nid      = 0;
23339 +unsigned int vs_debug_tag      = 0;
23340 +unsigned int vs_debug_net      = 0;
23341 +unsigned int vs_debug_limit    = 0;
23342 +unsigned int vs_debug_cres     = 0;
23343 +unsigned int vs_debug_dlim     = 0;
23344 +unsigned int vs_debug_quota    = 0;
23345 +unsigned int vs_debug_cvirt    = 0;
23346 +unsigned int vs_debug_space    = 0;
23347 +unsigned int vs_debug_perm     = 0;
23348 +unsigned int vs_debug_misc     = 0;
23349 +
23350 +
23351 +static struct ctl_table_header *vserver_table_header;
23352 +static ctl_table vserver_root_table[];
23353 +
23354 +
23355 +void vserver_register_sysctl(void)
23356 +{
23357 +       if (!vserver_table_header) {
23358 +               vserver_table_header = register_sysctl_table(vserver_root_table);
23359 +       }
23360 +
23361 +}
23362 +
23363 +void vserver_unregister_sysctl(void)
23364 +{
23365 +       if (vserver_table_header) {
23366 +               unregister_sysctl_table(vserver_table_header);
23367 +               vserver_table_header = NULL;
23368 +       }
23369 +}
23370 +
23371 +
23372 +static int proc_dodebug(ctl_table *table, int write,
23373 +       void __user *buffer, size_t *lenp, loff_t *ppos)
23374 +{
23375 +       char            tmpbuf[20], *p, c;
23376 +       unsigned int    value;
23377 +       size_t          left, len;
23378 +
23379 +       if ((*ppos && !write) || !*lenp) {
23380 +               *lenp = 0;
23381 +               return 0;
23382 +       }
23383 +
23384 +       left = *lenp;
23385 +
23386 +       if (write) {
23387 +               if (!access_ok(VERIFY_READ, buffer, left))
23388 +                       return -EFAULT;
23389 +               p = (char *)buffer;
23390 +               while (left && __get_user(c, p) >= 0 && isspace(c))
23391 +                       left--, p++;
23392 +               if (!left)
23393 +                       goto done;
23394 +
23395 +               if (left > sizeof(tmpbuf) - 1)
23396 +                       return -EINVAL;
23397 +               if (copy_from_user(tmpbuf, p, left))
23398 +                       return -EFAULT;
23399 +               tmpbuf[left] = '\0';
23400 +
23401 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
23402 +                       value = 10 * value + (*p - '0');
23403 +               if (*p && !isspace(*p))
23404 +                       return -EINVAL;
23405 +               while (left && isspace(*p))
23406 +                       left--, p++;
23407 +               *(unsigned int *)table->data = value;
23408 +       } else {
23409 +               if (!access_ok(VERIFY_WRITE, buffer, left))
23410 +                       return -EFAULT;
23411 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
23412 +               if (len > left)
23413 +                       len = left;
23414 +               if (__copy_to_user(buffer, tmpbuf, len))
23415 +                       return -EFAULT;
23416 +               if ((left -= len) > 0) {
23417 +                       if (put_user('\n', (char *)buffer + len))
23418 +                               return -EFAULT;
23419 +                       left--;
23420 +               }
23421 +       }
23422 +
23423 +done:
23424 +       *lenp -= left;
23425 +       *ppos += *lenp;
23426 +       return 0;
23427 +}
23428 +
23429 +static int zero;
23430 +
23431 +#define        CTL_ENTRY(ctl, name)                            \
23432 +       {                                               \
23433 +               .procname       = #name,                \
23434 +               .data           = &vs_ ## name,         \
23435 +               .maxlen         = sizeof(int),          \
23436 +               .mode           = 0644,                 \
23437 +               .proc_handler   = &proc_dodebug,        \
23438 +               .extra1         = &zero,                \
23439 +               .extra2         = &zero,                \
23440 +       }
23441 +
23442 +static ctl_table vserver_debug_table[] = {
23443 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
23444 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
23445 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
23446 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
23447 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
23448 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
23449 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
23450 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
23451 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
23452 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
23453 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
23454 +       CTL_ENTRY(CTL_DEBUG_PERM,       debug_perm),
23455 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
23456 +       { 0 }
23457 +};
23458 +
23459 +static ctl_table vserver_root_table[] = {
23460 +       {
23461 +               .procname       = "vserver",
23462 +               .mode           = 0555,
23463 +               .child          = vserver_debug_table
23464 +       },
23465 +       { 0 }
23466 +};
23467 +
23468 +
23469 +static match_table_t tokens = {
23470 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
23471 +       { CTL_DEBUG_XID,        "xid=%x"        },
23472 +       { CTL_DEBUG_NID,        "nid=%x"        },
23473 +       { CTL_DEBUG_TAG,        "tag=%x"        },
23474 +       { CTL_DEBUG_NET,        "net=%x"        },
23475 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
23476 +       { CTL_DEBUG_CRES,       "cres=%x"       },
23477 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
23478 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
23479 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
23480 +       { CTL_DEBUG_SPACE,      "space=%x"      },
23481 +       { CTL_DEBUG_PERM,       "perm=%x"       },
23482 +       { CTL_DEBUG_MISC,       "misc=%x"       },
23483 +       { CTL_DEBUG_ERROR,      NULL            }
23484 +};
23485 +
23486 +#define        HANDLE_CASE(id, name, val)                              \
23487 +       case CTL_DEBUG_ ## id:                                  \
23488 +               vs_debug_ ## name = val;                        \
23489 +               printk("vs_debug_" #name "=0x%x\n", val);       \
23490 +               break
23491 +
23492 +
23493 +static int __init vs_debug_setup(char *str)
23494 +{
23495 +       char *p;
23496 +       int token;
23497 +
23498 +       printk("vs_debug_setup(%s)\n", str);
23499 +       while ((p = strsep(&str, ",")) != NULL) {
23500 +               substring_t args[MAX_OPT_ARGS];
23501 +               unsigned int value;
23502 +
23503 +               if (!*p)
23504 +                       continue;
23505 +
23506 +               token = match_token(p, tokens, args);
23507 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
23508 +
23509 +               switch (token) {
23510 +               HANDLE_CASE(SWITCH, switch, value);
23511 +               HANDLE_CASE(XID,    xid,    value);
23512 +               HANDLE_CASE(NID,    nid,    value);
23513 +               HANDLE_CASE(TAG,    tag,    value);
23514 +               HANDLE_CASE(NET,    net,    value);
23515 +               HANDLE_CASE(LIMIT,  limit,  value);
23516 +               HANDLE_CASE(CRES,   cres,   value);
23517 +               HANDLE_CASE(DLIM,   dlim,   value);
23518 +               HANDLE_CASE(QUOTA,  quota,  value);
23519 +               HANDLE_CASE(CVIRT,  cvirt,  value);
23520 +               HANDLE_CASE(SPACE,  space,  value);
23521 +               HANDLE_CASE(PERM,   perm,   value);
23522 +               HANDLE_CASE(MISC,   misc,   value);
23523 +               default:
23524 +                       return -EINVAL;
23525 +                       break;
23526 +               }
23527 +       }
23528 +       return 1;
23529 +}
23530 +
23531 +__setup("vsdebug=", vs_debug_setup);
23532 +
23533 +
23534 +
23535 +EXPORT_SYMBOL_GPL(vs_debug_switch);
23536 +EXPORT_SYMBOL_GPL(vs_debug_xid);
23537 +EXPORT_SYMBOL_GPL(vs_debug_nid);
23538 +EXPORT_SYMBOL_GPL(vs_debug_net);
23539 +EXPORT_SYMBOL_GPL(vs_debug_limit);
23540 +EXPORT_SYMBOL_GPL(vs_debug_cres);
23541 +EXPORT_SYMBOL_GPL(vs_debug_dlim);
23542 +EXPORT_SYMBOL_GPL(vs_debug_quota);
23543 +EXPORT_SYMBOL_GPL(vs_debug_cvirt);
23544 +EXPORT_SYMBOL_GPL(vs_debug_space);
23545 +EXPORT_SYMBOL_GPL(vs_debug_perm);
23546 +EXPORT_SYMBOL_GPL(vs_debug_misc);
23547 +
23548 diff -NurpP --minimal linux-3.10.33/kernel/vserver/tag.c linux-3.10.33-vs2.3.6.8/kernel/vserver/tag.c
23549 --- linux-3.10.33/kernel/vserver/tag.c  1970-01-01 00:00:00.000000000 +0000
23550 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/tag.c        2013-08-22 20:30:00.000000000 +0000
23551 @@ -0,0 +1,63 @@
23552 +/*
23553 + *  linux/kernel/vserver/tag.c
23554 + *
23555 + *  Virtual Server: Shallow Tag Space
23556 + *
23557 + *  Copyright (C) 2007  Herbert Pötzl
23558 + *
23559 + *  V0.01  basic implementation
23560 + *
23561 + */
23562 +
23563 +#include <linux/sched.h>
23564 +#include <linux/vserver/debug.h>
23565 +#include <linux/vs_pid.h>
23566 +#include <linux/vs_tag.h>
23567 +
23568 +#include <linux/vserver/tag_cmd.h>
23569 +
23570 +
23571 +int dx_migrate_task(struct task_struct *p, vtag_t tag)
23572 +{
23573 +       if (!p)
23574 +               BUG();
23575 +
23576 +       vxdprintk(VXD_CBIT(tag, 5),
23577 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
23578 +
23579 +       task_lock(p);
23580 +       p->tag = tag;
23581 +       task_unlock(p);
23582 +
23583 +       vxdprintk(VXD_CBIT(tag, 5),
23584 +               "moved task %p into [#%d]", p, tag);
23585 +       return 0;
23586 +}
23587 +
23588 +/* vserver syscall commands below here */
23589 +
23590 +/* taks xid and vx_info functions */
23591 +
23592 +
23593 +int vc_task_tag(uint32_t id)
23594 +{
23595 +       vtag_t tag;
23596 +
23597 +       if (id) {
23598 +               struct task_struct *tsk;
23599 +               rcu_read_lock();
23600 +               tsk = find_task_by_real_pid(id);
23601 +               tag = (tsk) ? tsk->tag : -ESRCH;
23602 +               rcu_read_unlock();
23603 +       } else
23604 +               tag = dx_current_tag();
23605 +       return tag;
23606 +}
23607 +
23608 +
23609 +int vc_tag_migrate(uint32_t tag)
23610 +{
23611 +       return dx_migrate_task(current, tag & 0xFFFF);
23612 +}
23613 +
23614 +
23615 diff -NurpP --minimal linux-3.10.33/kernel/vserver/vci_config.h linux-3.10.33-vs2.3.6.8/kernel/vserver/vci_config.h
23616 --- linux-3.10.33/kernel/vserver/vci_config.h   1970-01-01 00:00:00.000000000 +0000
23617 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/vci_config.h 2013-08-22 20:30:00.000000000 +0000
23618 @@ -0,0 +1,80 @@
23619 +
23620 +/*  interface version */
23621 +
23622 +#define VCI_VERSION            0x00020308
23623 +
23624 +
23625 +enum {
23626 +       VCI_KCBIT_NO_DYNAMIC = 0,
23627 +
23628 +       VCI_KCBIT_PROC_SECURE = 4,
23629 +       /* VCI_KCBIT_HARDCPU = 5, */
23630 +       /* VCI_KCBIT_IDLELIMIT = 6, */
23631 +       /* VCI_KCBIT_IDLETIME = 7, */
23632 +
23633 +       VCI_KCBIT_COWBL = 8,
23634 +       VCI_KCBIT_FULLCOWBL = 9,
23635 +       VCI_KCBIT_SPACES = 10,
23636 +       VCI_KCBIT_NETV2 = 11,
23637 +       VCI_KCBIT_MEMCG = 12,
23638 +       VCI_KCBIT_MEMCG_SWAP = 13,
23639 +
23640 +       VCI_KCBIT_DEBUG = 16,
23641 +       VCI_KCBIT_HISTORY = 20,
23642 +       VCI_KCBIT_TAGGED = 24,
23643 +       VCI_KCBIT_PPTAG = 28,
23644 +
23645 +       VCI_KCBIT_MORE = 31,
23646 +};
23647 +
23648 +
23649 +static inline uint32_t vci_kernel_config(void)
23650 +{
23651 +       return
23652 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
23653 +
23654 +       /* configured features */
23655 +#ifdef CONFIG_VSERVER_PROC_SECURE
23656 +       (1 << VCI_KCBIT_PROC_SECURE) |
23657 +#endif
23658 +#ifdef CONFIG_VSERVER_COWBL
23659 +       (1 << VCI_KCBIT_COWBL) |
23660 +       (1 << VCI_KCBIT_FULLCOWBL) |
23661 +#endif
23662 +       (1 << VCI_KCBIT_SPACES) |
23663 +       (1 << VCI_KCBIT_NETV2) |
23664 +#ifdef CONFIG_MEMCG
23665 +       (1 << VCI_KCBIT_MEMCG) |
23666 +#endif
23667 +#ifdef CONFIG_MEMCG_SWAP
23668 +       (1 << VCI_KCBIT_MEMCG_SWAP) |
23669 +#endif
23670 +
23671 +       /* debug options */
23672 +#ifdef CONFIG_VSERVER_DEBUG
23673 +       (1 << VCI_KCBIT_DEBUG) |
23674 +#endif
23675 +#ifdef CONFIG_VSERVER_HISTORY
23676 +       (1 << VCI_KCBIT_HISTORY) |
23677 +#endif
23678 +
23679 +       /* inode context tagging */
23680 +#if    defined(CONFIG_TAGGING_NONE)
23681 +       (0 << VCI_KCBIT_TAGGED) |
23682 +#elif  defined(CONFIG_TAGGING_UID16)
23683 +       (1 << VCI_KCBIT_TAGGED) |
23684 +#elif  defined(CONFIG_TAGGING_GID16)
23685 +       (2 << VCI_KCBIT_TAGGED) |
23686 +#elif  defined(CONFIG_TAGGING_ID24)
23687 +       (3 << VCI_KCBIT_TAGGED) |
23688 +#elif  defined(CONFIG_TAGGING_INTERN)
23689 +       (4 << VCI_KCBIT_TAGGED) |
23690 +#elif  defined(CONFIG_TAGGING_RUNTIME)
23691 +       (5 << VCI_KCBIT_TAGGED) |
23692 +#else
23693 +       (7 << VCI_KCBIT_TAGGED) |
23694 +#endif
23695 +       (1 << VCI_KCBIT_PPTAG) |
23696 +       0;
23697 +}
23698 +
23699 diff -NurpP --minimal linux-3.10.33/mm/memcontrol.c linux-3.10.33-vs2.3.6.8/mm/memcontrol.c
23700 --- linux-3.10.33/mm/memcontrol.c       2014-03-12 13:16:02.000000000 +0000
23701 +++ linux-3.10.33-vs2.3.6.8/mm/memcontrol.c     2014-03-12 13:18:33.000000000 +0000
23702 @@ -1082,6 +1082,31 @@ struct mem_cgroup *mem_cgroup_from_task(
23703         return mem_cgroup_from_css(task_subsys_state(p, mem_cgroup_subsys_id));
23704  }
23705  
23706 +u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member)
23707 +{
23708 +       return res_counter_read_u64(&mem->res, member);
23709 +}
23710 +
23711 +u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member)
23712 +{
23713 +       return res_counter_read_u64(&mem->memsw, member);
23714 +}
23715 +
23716 +s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem)
23717 +{
23718 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_CACHE);
23719 +}
23720 +
23721 +s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem)
23722 +{
23723 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_RSS);
23724 +}
23725 +
23726 +s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem)
23727 +{
23728 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_FILE_MAPPED);
23729 +}
23730 +
23731  struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
23732  {
23733         struct mem_cgroup *memcg = NULL;
23734 diff -NurpP --minimal linux-3.10.33/mm/oom_kill.c linux-3.10.33-vs2.3.6.8/mm/oom_kill.c
23735 --- linux-3.10.33/mm/oom_kill.c 2014-03-12 13:16:02.000000000 +0000
23736 +++ linux-3.10.33-vs2.3.6.8/mm/oom_kill.c       2014-03-12 13:18:23.000000000 +0000
23737 @@ -35,6 +35,8 @@
23738  #include <linux/freezer.h>
23739  #include <linux/ftrace.h>
23740  #include <linux/ratelimit.h>
23741 +#include <linux/reboot.h>
23742 +#include <linux/vs_context.h>
23743  
23744  #define CREATE_TRACE_POINTS
23745  #include <trace/events/oom.h>
23746 @@ -113,11 +115,18 @@ struct task_struct *find_lock_task_mm(st
23747  static bool oom_unkillable_task(struct task_struct *p,
23748                 const struct mem_cgroup *memcg, const nodemask_t *nodemask)
23749  {
23750 -       if (is_global_init(p))
23751 +       unsigned xid = vx_current_xid();
23752 +
23753 +       /* skip the init task, global and per guest */
23754 +       if (task_is_init(p))
23755                 return true;
23756         if (p->flags & PF_KTHREAD)
23757                 return true;
23758  
23759 +       /* skip other guest and host processes if oom in guest */
23760 +       if (xid && vx_task_xid(p) != xid)
23761 +               return true;
23762 +
23763         /* When mem_cgroup_out_of_memory() and p is not member of the group */
23764         if (memcg && !task_in_mem_cgroup(p, memcg))
23765                 return true;
23766 @@ -426,8 +435,8 @@ void oom_kill_process(struct task_struct
23767                 dump_header(p, gfp_mask, order, memcg, nodemask);
23768  
23769         task_lock(p);
23770 -       pr_err("%s: Kill process %d (%s) score %d or sacrifice child\n",
23771 -               message, task_pid_nr(p), p->comm, points);
23772 +       pr_err("%s: Kill process %d:#%u (%s) score %d or sacrifice child\n",
23773 +               message, task_pid_nr(p), p->xid, p->comm, points);
23774         task_unlock(p);
23775  
23776         /*
23777 @@ -472,8 +481,8 @@ void oom_kill_process(struct task_struct
23778  
23779         /* mm cannot safely be dereferenced after task_unlock(victim) */
23780         mm = victim->mm;
23781 -       pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23782 -               task_pid_nr(victim), victim->comm, K(victim->mm->total_vm),
23783 +       pr_err("Killed process %d:#%u (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23784 +               task_pid_nr(victim), victim->xid, victim->comm, K(victim->mm->total_vm),
23785                 K(get_mm_counter(victim->mm, MM_ANONPAGES)),
23786                 K(get_mm_counter(victim->mm, MM_FILEPAGES)));
23787         task_unlock(victim);
23788 @@ -543,6 +552,8 @@ int unregister_oom_notifier(struct notif
23789  }
23790  EXPORT_SYMBOL_GPL(unregister_oom_notifier);
23791  
23792 +long vs_oom_action(unsigned int);
23793 +
23794  /*
23795   * Try to acquire the OOM killer lock for the zones in zonelist.  Returns zero
23796   * if a parallel OOM killing is already taking place that includes a zone in
23797 @@ -655,7 +666,12 @@ void out_of_memory(struct zonelist *zone
23798         /* Found nothing?!?! Either we hang forever, or we panic. */
23799         if (!p) {
23800                 dump_header(NULL, gfp_mask, order, NULL, mpol_mask);
23801 -               panic("Out of memory and no killable processes...\n");
23802 +
23803 +               /* avoid panic for guest OOM */
23804 +               if (vx_current_xid())
23805 +                       vs_oom_action(LINUX_REBOOT_CMD_OOM);
23806 +               else
23807 +                       panic("Out of memory and no killable processes...\n");
23808         }
23809         if (PTR_ERR(p) != -1UL) {
23810                 oom_kill_process(p, gfp_mask, order, points, totalpages, NULL,
23811 diff -NurpP --minimal linux-3.10.33/mm/page_alloc.c linux-3.10.33-vs2.3.6.8/mm/page_alloc.c
23812 --- linux-3.10.33/mm/page_alloc.c       2014-03-12 13:16:02.000000000 +0000
23813 +++ linux-3.10.33-vs2.3.6.8/mm/page_alloc.c     2013-11-13 17:17:16.000000000 +0000
23814 @@ -60,6 +60,8 @@
23815  #include <linux/page-debug-flags.h>
23816  #include <linux/hugetlb.h>
23817  #include <linux/sched/rt.h>
23818 +#include <linux/vs_base.h>
23819 +#include <linux/vs_limit.h>
23820  
23821  #include <asm/tlbflush.h>
23822  #include <asm/div64.h>
23823 @@ -2899,6 +2901,9 @@ void si_meminfo(struct sysinfo *val)
23824         val->totalhigh = totalhigh_pages;
23825         val->freehigh = nr_free_highpages();
23826         val->mem_unit = PAGE_SIZE;
23827 +
23828 +       if (vx_flags(VXF_VIRT_MEM, 0))
23829 +               vx_vsi_meminfo(val);
23830  }
23831  
23832  EXPORT_SYMBOL(si_meminfo);
23833 @@ -2919,6 +2924,9 @@ void si_meminfo_node(struct sysinfo *val
23834         val->freehigh = 0;
23835  #endif
23836         val->mem_unit = PAGE_SIZE;
23837 +
23838 +       if (vx_flags(VXF_VIRT_MEM, 0))
23839 +               vx_vsi_meminfo(val);
23840  }
23841  #endif
23842  
23843 diff -NurpP --minimal linux-3.10.33/mm/pgtable-generic.c linux-3.10.33-vs2.3.6.8/mm/pgtable-generic.c
23844 --- linux-3.10.33/mm/pgtable-generic.c  2014-03-12 13:16:02.000000000 +0000
23845 +++ linux-3.10.33-vs2.3.6.8/mm/pgtable-generic.c        2014-01-22 19:00:34.000000000 +0000
23846 @@ -6,6 +6,8 @@
23847   *  Copyright (C) 2010  Linus Torvalds
23848   */
23849  
23850 +#include <linux/mm.h>
23851 +
23852  #include <linux/pagemap.h>
23853  #include <asm/tlb.h>
23854  #include <asm-generic/pgtable.h>
23855 diff -NurpP --minimal linux-3.10.33/mm/shmem.c linux-3.10.33-vs2.3.6.8/mm/shmem.c
23856 --- linux-3.10.33/mm/shmem.c    2014-03-12 13:16:02.000000000 +0000
23857 +++ linux-3.10.33-vs2.3.6.8/mm/shmem.c  2013-11-13 17:17:16.000000000 +0000
23858 @@ -1911,7 +1911,7 @@ static int shmem_statfs(struct dentry *d
23859  {
23860         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
23861  
23862 -       buf->f_type = TMPFS_MAGIC;
23863 +       buf->f_type = TMPFS_SUPER_MAGIC;
23864         buf->f_bsize = PAGE_CACHE_SIZE;
23865         buf->f_namelen = NAME_MAX;
23866         if (sbinfo->max_blocks) {
23867 @@ -2608,7 +2608,7 @@ int shmem_fill_super(struct super_block
23868         sb->s_maxbytes = MAX_LFS_FILESIZE;
23869         sb->s_blocksize = PAGE_CACHE_SIZE;
23870         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
23871 -       sb->s_magic = TMPFS_MAGIC;
23872 +       sb->s_magic = TMPFS_SUPER_MAGIC;
23873         sb->s_op = &shmem_ops;
23874         sb->s_time_gran = 1;
23875  #ifdef CONFIG_TMPFS_XATTR
23876 diff -NurpP --minimal linux-3.10.33/mm/slab.c linux-3.10.33-vs2.3.6.8/mm/slab.c
23877 --- linux-3.10.33/mm/slab.c     2014-03-12 13:16:02.000000000 +0000
23878 +++ linux-3.10.33-vs2.3.6.8/mm/slab.c   2013-11-13 17:17:16.000000000 +0000
23879 @@ -388,6 +388,8 @@ static void kmem_cache_node_init(struct
23880  #define STATS_INC_FREEMISS(x)  do { } while (0)
23881  #endif
23882  
23883 +#include "slab_vs.h"
23884 +
23885  #if DEBUG
23886  
23887  /*
23888 @@ -3314,6 +3316,7 @@ retry:
23889  
23890         obj = slab_get_obj(cachep, slabp, nodeid);
23891         check_slabp(cachep, slabp);
23892 +       vx_slab_alloc(cachep, flags);
23893         n->free_objects--;
23894         /* move slabp to correct slabp list: */
23895         list_del(&slabp->list);
23896 @@ -3393,6 +3396,7 @@ slab_alloc_node(struct kmem_cache *cache
23897         /* ___cache_alloc_node can fall back to other nodes */
23898         ptr = ____cache_alloc_node(cachep, flags, nodeid);
23899    out:
23900 +       vx_slab_alloc(cachep, flags);
23901         local_irq_restore(save_flags);
23902         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
23903         kmemleak_alloc_recursive(ptr, cachep->object_size, 1, cachep->flags,
23904 @@ -3585,6 +3589,7 @@ static inline void __cache_free(struct k
23905         check_irq_off();
23906         kmemleak_free_recursive(objp, cachep->flags);
23907         objp = cache_free_debugcheck(cachep, objp, caller);
23908 +       vx_slab_free(cachep);
23909  
23910         kmemcheck_slab_free(cachep, objp, cachep->object_size);
23911  
23912 diff -NurpP --minimal linux-3.10.33/mm/slab_vs.h linux-3.10.33-vs2.3.6.8/mm/slab_vs.h
23913 --- linux-3.10.33/mm/slab_vs.h  1970-01-01 00:00:00.000000000 +0000
23914 +++ linux-3.10.33-vs2.3.6.8/mm/slab_vs.h        2013-08-22 20:30:00.000000000 +0000
23915 @@ -0,0 +1,29 @@
23916 +
23917 +#include <linux/vserver/context.h>
23918 +
23919 +#include <linux/vs_context.h>
23920 +
23921 +static inline
23922 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
23923 +{
23924 +       int what = gfp_zone(cachep->allocflags);
23925 +       struct vx_info *vxi = current_vx_info();
23926 +
23927 +       if (!vxi)
23928 +               return;
23929 +
23930 +       atomic_add(cachep->size, &vxi->cacct.slab[what]);
23931 +}
23932 +
23933 +static inline
23934 +void vx_slab_free(struct kmem_cache *cachep)
23935 +{
23936 +       int what = gfp_zone(cachep->allocflags);
23937 +       struct vx_info *vxi = current_vx_info();
23938 +
23939 +       if (!vxi)
23940 +               return;
23941 +
23942 +       atomic_sub(cachep->size, &vxi->cacct.slab[what]);
23943 +}
23944 +
23945 diff -NurpP --minimal linux-3.10.33/mm/swapfile.c linux-3.10.33-vs2.3.6.8/mm/swapfile.c
23946 --- linux-3.10.33/mm/swapfile.c 2013-07-14 17:01:36.000000000 +0000
23947 +++ linux-3.10.33-vs2.3.6.8/mm/swapfile.c       2013-08-22 20:30:00.000000000 +0000
23948 @@ -39,6 +39,7 @@
23949  #include <asm/tlbflush.h>
23950  #include <linux/swapops.h>
23951  #include <linux/page_cgroup.h>
23952 +#include <linux/vs_base.h>
23953  
23954  static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
23955                                  unsigned char);
23956 @@ -1768,6 +1769,16 @@ static int swap_show(struct seq_file *sw
23957  
23958         if (si == SEQ_START_TOKEN) {
23959                 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
23960 +               if (vx_flags(VXF_VIRT_MEM, 0)) {
23961 +                       struct sysinfo si;
23962 +
23963 +                       vx_vsi_swapinfo(&si);
23964 +                       if (si.totalswap < (1 << 10))
23965 +                               return 0;
23966 +                       seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
23967 +                               "hdv0", "partition", si.totalswap >> 10,
23968 +                               (si.totalswap - si.freeswap) >> 10, -1);
23969 +               }
23970                 return 0;
23971         }
23972  
23973 @@ -2196,6 +2207,8 @@ void si_swapinfo(struct sysinfo *val)
23974         val->freeswap = atomic_long_read(&nr_swap_pages) + nr_to_be_unused;
23975         val->totalswap = total_swap_pages + nr_to_be_unused;
23976         spin_unlock(&swap_lock);
23977 +       if (vx_flags(VXF_VIRT_MEM, 0))
23978 +               vx_vsi_swapinfo(val);
23979  }
23980  
23981  /*
23982 diff -NurpP --minimal linux-3.10.33/net/bridge/br_multicast.c linux-3.10.33-vs2.3.6.8/net/bridge/br_multicast.c
23983 --- linux-3.10.33/net/bridge/br_multicast.c     2014-03-12 13:16:02.000000000 +0000
23984 +++ linux-3.10.33-vs2.3.6.8/net/bridge/br_multicast.c   2014-01-22 19:00:34.000000000 +0000
23985 @@ -443,7 +443,7 @@ static struct sk_buff *br_ip6_multicast_
23986         ip6h->hop_limit = 1;
23987         ipv6_addr_set(&ip6h->daddr, htonl(0xff020000), 0, 0, htonl(1));
23988         if (ipv6_dev_get_saddr(dev_net(br->dev), br->dev, &ip6h->daddr, 0,
23989 -                              &ip6h->saddr)) {
23990 +                              &ip6h->saddr, NULL)) {
23991                 kfree_skb(skb);
23992                 return NULL;
23993         }
23994 diff -NurpP --minimal linux-3.10.33/net/core/dev.c linux-3.10.33-vs2.3.6.8/net/core/dev.c
23995 --- linux-3.10.33/net/core/dev.c        2014-03-12 13:16:02.000000000 +0000
23996 +++ linux-3.10.33-vs2.3.6.8/net/core/dev.c      2014-03-12 13:18:33.000000000 +0000
23997 @@ -122,6 +122,7 @@
23998  #include <linux/in.h>
23999  #include <linux/jhash.h>
24000  #include <linux/random.h>
24001 +#include <linux/vs_inet.h>
24002  #include <trace/events/napi.h>
24003  #include <trace/events/net.h>
24004  #include <trace/events/skb.h>
24005 @@ -660,7 +661,8 @@ struct net_device *__dev_get_by_name(str
24006         struct hlist_head *head = dev_name_hash(net, name);
24007  
24008         hlist_for_each_entry(dev, head, name_hlist)
24009 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24010 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24011 +                   nx_dev_visible(current_nx_info(), dev))
24012                         return dev;
24013  
24014         return NULL;
24015 @@ -685,7 +687,8 @@ struct net_device *dev_get_by_name_rcu(s
24016         struct hlist_head *head = dev_name_hash(net, name);
24017  
24018         hlist_for_each_entry_rcu(dev, head, name_hlist)
24019 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24020 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24021 +                   nx_dev_visible(current_nx_info(), dev))
24022                         return dev;
24023  
24024         return NULL;
24025 @@ -735,7 +738,8 @@ struct net_device *__dev_get_by_index(st
24026         struct hlist_head *head = dev_index_hash(net, ifindex);
24027  
24028         hlist_for_each_entry(dev, head, index_hlist)
24029 -               if (dev->ifindex == ifindex)
24030 +               if ((dev->ifindex == ifindex) &&
24031 +                   nx_dev_visible(current_nx_info(), dev))
24032                         return dev;
24033  
24034         return NULL;
24035 @@ -753,7 +757,7 @@ EXPORT_SYMBOL(__dev_get_by_index);
24036   *     about locking. The caller must hold RCU lock.
24037   */
24038  
24039 -struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
24040 +struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex)
24041  {
24042         struct net_device *dev;
24043         struct hlist_head *head = dev_index_hash(net, ifindex);
24044 @@ -764,6 +768,16 @@ struct net_device *dev_get_by_index_rcu(
24045  
24046         return NULL;
24047  }
24048 +EXPORT_SYMBOL(dev_get_by_index_real_rcu);
24049 +
24050 +struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
24051 +{
24052 +       struct net_device *dev = dev_get_by_index_real_rcu(net, ifindex);
24053 +
24054 +       if (nx_dev_visible(current_nx_info(), dev))
24055 +               return dev;
24056 +       return NULL;
24057 +}
24058  EXPORT_SYMBOL(dev_get_by_index_rcu);
24059  
24060  
24061 @@ -846,7 +860,8 @@ struct net_device *dev_getbyhwaddr_rcu(s
24062  
24063         for_each_netdev_rcu(net, dev)
24064                 if (dev->type == type &&
24065 -                   !memcmp(dev->dev_addr, ha, dev->addr_len))
24066 +                   !memcmp(dev->dev_addr, ha, dev->addr_len) &&
24067 +                   nx_dev_visible(current_nx_info(), dev))
24068                         return dev;
24069  
24070         return NULL;
24071 @@ -858,9 +873,11 @@ struct net_device *__dev_getfirstbyhwtyp
24072         struct net_device *dev;
24073  
24074         ASSERT_RTNL();
24075 -       for_each_netdev(net, dev)
24076 -               if (dev->type == type)
24077 +       for_each_netdev(net, dev) {
24078 +               if ((dev->type == type) &&
24079 +                   nx_dev_visible(current_nx_info(), dev))
24080                         return dev;
24081 +       }
24082  
24083         return NULL;
24084  }
24085 @@ -872,7 +889,8 @@ struct net_device *dev_getfirstbyhwtype(
24086  
24087         rcu_read_lock();
24088         for_each_netdev_rcu(net, dev)
24089 -               if (dev->type == type) {
24090 +               if ((dev->type == type) &&
24091 +                   nx_dev_visible(current_nx_info(), dev)) {
24092                         dev_hold(dev);
24093                         ret = dev;
24094                         break;
24095 @@ -900,7 +918,8 @@ struct net_device *dev_get_by_flags_rcu(
24096  
24097         ret = NULL;
24098         for_each_netdev_rcu(net, dev) {
24099 -               if (((dev->flags ^ if_flags) & mask) == 0) {
24100 +               if ((((dev->flags ^ if_flags) & mask) == 0) &&
24101 +                       nx_dev_visible(current_nx_info(), dev)) {
24102                         ret = dev;
24103                         break;
24104                 }
24105 @@ -978,6 +997,8 @@ static int __dev_alloc_name(struct net *
24106                                 continue;
24107                         if (i < 0 || i >= max_netdevices)
24108                                 continue;
24109 +                       if (!nx_dev_visible(current_nx_info(), d))
24110 +                               continue;
24111  
24112                         /*  avoid cases where sscanf is not exact inverse of printf */
24113                         snprintf(buf, IFNAMSIZ, name, i);
24114 diff -NurpP --minimal linux-3.10.33/net/core/net-procfs.c linux-3.10.33-vs2.3.6.8/net/core/net-procfs.c
24115 --- linux-3.10.33/net/core/net-procfs.c 2013-07-14 17:01:37.000000000 +0000
24116 +++ linux-3.10.33-vs2.3.6.8/net/core/net-procfs.c       2013-08-22 20:30:00.000000000 +0000
24117 @@ -1,6 +1,7 @@
24118  #include <linux/netdevice.h>
24119  #include <linux/proc_fs.h>
24120  #include <linux/seq_file.h>
24121 +#include <linux/vs_inet.h>
24122  #include <net/wext.h>
24123  
24124  #define BUCKET_SPACE (32 - NETDEV_HASHBITS - 1)
24125 @@ -77,8 +78,13 @@ static void dev_seq_stop(struct seq_file
24126  static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
24127  {
24128         struct rtnl_link_stats64 temp;
24129 -       const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
24130 +       const struct rtnl_link_stats64 *stats;
24131 +
24132 +       /* device visible inside network context? */
24133 +       if (!nx_dev_visible(current_nx_info(), dev))
24134 +               return;
24135  
24136 +       stats = dev_get_stats(dev, &temp);
24137         seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
24138                    "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
24139                    dev->name, stats->rx_bytes, stats->rx_packets,
24140 diff -NurpP --minimal linux-3.10.33/net/core/rtnetlink.c linux-3.10.33-vs2.3.6.8/net/core/rtnetlink.c
24141 --- linux-3.10.33/net/core/rtnetlink.c  2014-03-12 13:16:02.000000000 +0000
24142 +++ linux-3.10.33-vs2.3.6.8/net/core/rtnetlink.c        2013-11-13 17:17:16.000000000 +0000
24143 @@ -1059,6 +1059,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
24144                 hlist_for_each_entry_rcu(dev, head, index_hlist) {
24145                         if (idx < s_idx)
24146                                 goto cont;
24147 +                       if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
24148 +                               continue;
24149                         if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
24150                                              NETLINK_CB(cb->skb).portid,
24151                                              cb->nlh->nlmsg_seq, 0,
24152 @@ -1951,6 +1953,9 @@ void rtmsg_ifinfo(int type, struct net_d
24153         int err = -ENOBUFS;
24154         size_t if_info_size;
24155  
24156 +       if (!nx_dev_visible(current_nx_info(), dev))
24157 +               return;
24158 +
24159         skb = nlmsg_new((if_info_size = if_nlmsg_size(dev, 0)), GFP_KERNEL);
24160         if (skb == NULL)
24161                 goto errout;
24162 diff -NurpP --minimal linux-3.10.33/net/core/sock.c linux-3.10.33-vs2.3.6.8/net/core/sock.c
24163 --- linux-3.10.33/net/core/sock.c       2014-03-12 13:16:02.000000000 +0000
24164 +++ linux-3.10.33-vs2.3.6.8/net/core/sock.c     2014-03-12 13:18:33.000000000 +0000
24165 @@ -132,6 +132,10 @@
24166  #include <net/netprio_cgroup.h>
24167  
24168  #include <linux/filter.h>
24169 +#include <linux/vs_socket.h>
24170 +#include <linux/vs_limit.h>
24171 +#include <linux/vs_context.h>
24172 +#include <linux/vs_network.h>
24173  
24174  #include <trace/events/sock.h>
24175  
24176 @@ -1252,6 +1256,8 @@ static struct sock *sk_prot_alloc(struct
24177                         goto out_free_sec;
24178                 sk_tx_queue_clear(sk);
24179         }
24180 +               sock_vx_init(sk);
24181 +               sock_nx_init(sk);
24182  
24183         return sk;
24184  
24185 @@ -1360,6 +1366,11 @@ static void __sk_free(struct sock *sk)
24186                 put_cred(sk->sk_peer_cred);
24187         put_pid(sk->sk_peer_pid);
24188         put_net(sock_net(sk));
24189 +       vx_sock_dec(sk);
24190 +       clr_vx_info(&sk->sk_vx_info);
24191 +       sk->sk_xid = -1;
24192 +       clr_nx_info(&sk->sk_nx_info);
24193 +       sk->sk_nid = -1;
24194         sk_prot_free(sk->sk_prot_creator, sk);
24195  }
24196  
24197 @@ -1420,6 +1431,8 @@ struct sock *sk_clone_lock(const struct
24198  
24199                 /* SANITY */
24200                 get_net(sock_net(newsk));
24201 +               sock_vx_init(newsk);
24202 +               sock_nx_init(newsk);
24203                 sk_node_init(&newsk->sk_node);
24204                 sock_lock_init(newsk);
24205                 bh_lock_sock(newsk);
24206 @@ -1476,6 +1489,12 @@ struct sock *sk_clone_lock(const struct
24207                 smp_wmb();
24208                 atomic_set(&newsk->sk_refcnt, 2);
24209  
24210 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
24211 +               newsk->sk_xid = sk->sk_xid;
24212 +               vx_sock_inc(newsk);
24213 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
24214 +               newsk->sk_nid = sk->sk_nid;
24215 +
24216                 /*
24217                  * Increment the counter in the same struct proto as the master
24218                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
24219 @@ -2271,6 +2290,12 @@ void sock_init_data(struct socket *sock,
24220  
24221         sk->sk_stamp = ktime_set(-1L, 0);
24222  
24223 +       set_vx_info(&sk->sk_vx_info, current_vx_info());
24224 +       sk->sk_xid = vx_current_xid();
24225 +       vx_sock_inc(sk);
24226 +       set_nx_info(&sk->sk_nx_info, current_nx_info());
24227 +       sk->sk_nid = nx_current_nid();
24228 +
24229         sk->sk_pacing_rate = ~0U;
24230         /*
24231          * Before updating sk_refcnt, we must commit prior changes to memory
24232 diff -NurpP --minimal linux-3.10.33/net/ipv4/af_inet.c linux-3.10.33-vs2.3.6.8/net/ipv4/af_inet.c
24233 --- linux-3.10.33/net/ipv4/af_inet.c    2014-03-12 13:16:02.000000000 +0000
24234 +++ linux-3.10.33-vs2.3.6.8/net/ipv4/af_inet.c  2013-11-13 17:17:16.000000000 +0000
24235 @@ -118,6 +118,7 @@
24236  #ifdef CONFIG_IP_MROUTE
24237  #include <linux/mroute.h>
24238  #endif
24239 +#include <linux/vs_limit.h>
24240  
24241  
24242  /* The inetsw table contains everything that inet_create needs to
24243 @@ -336,10 +337,13 @@ lookup_protocol:
24244         }
24245  
24246         err = -EPERM;
24247 +       if ((protocol == IPPROTO_ICMP) &&
24248 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
24249 +               goto override;
24250         if (sock->type == SOCK_RAW && !kern &&
24251             !ns_capable(net->user_ns, CAP_NET_RAW))
24252                 goto out_rcu_unlock;
24253 -
24254 +override:
24255         sock->ops = answer->ops;
24256         answer_prot = answer->prot;
24257         answer_no_check = answer->no_check;
24258 @@ -460,6 +464,7 @@ int inet_bind(struct socket *sock, struc
24259         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
24260         struct sock *sk = sock->sk;
24261         struct inet_sock *inet = inet_sk(sk);
24262 +       struct nx_v4_sock_addr nsa;
24263         struct net *net = sock_net(sk);
24264         unsigned short snum;
24265         int chk_addr_ret;
24266 @@ -484,7 +489,11 @@ int inet_bind(struct socket *sock, struc
24267                         goto out;
24268         }
24269  
24270 -       chk_addr_ret = inet_addr_type(net, addr->sin_addr.s_addr);
24271 +       err = v4_map_sock_addr(inet, addr, &nsa);
24272 +       if (err)
24273 +               goto out;
24274 +
24275 +       chk_addr_ret = inet_addr_type(net, nsa.saddr);
24276  
24277         /* Not specified by any standard per-se, however it breaks too
24278          * many applications when removed.  It is unfortunate since
24279 @@ -496,7 +505,7 @@ int inet_bind(struct socket *sock, struc
24280         err = -EADDRNOTAVAIL;
24281         if (!sysctl_ip_nonlocal_bind &&
24282             !(inet->freebind || inet->transparent) &&
24283 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
24284 +           nsa.saddr != htonl(INADDR_ANY) &&
24285             chk_addr_ret != RTN_LOCAL &&
24286             chk_addr_ret != RTN_MULTICAST &&
24287             chk_addr_ret != RTN_BROADCAST)
24288 @@ -522,7 +531,7 @@ int inet_bind(struct socket *sock, struc
24289         if (sk->sk_state != TCP_CLOSE || inet->inet_num)
24290                 goto out_release_sock;
24291  
24292 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24293 +       v4_set_sock_addr(inet, &nsa);
24294         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24295                 inet->inet_saddr = 0;  /* Use device */
24296  
24297 @@ -741,11 +750,13 @@ int inet_getname(struct socket *sock, st
24298                      peer == 1))
24299                         return -ENOTCONN;
24300                 sin->sin_port = inet->inet_dport;
24301 -               sin->sin_addr.s_addr = inet->inet_daddr;
24302 +               sin->sin_addr.s_addr =
24303 +                       nx_map_sock_lback(sk->sk_nx_info, inet->inet_daddr);
24304         } else {
24305                 __be32 addr = inet->inet_rcv_saddr;
24306                 if (!addr)
24307                         addr = inet->inet_saddr;
24308 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
24309                 sin->sin_port = inet->inet_sport;
24310                 sin->sin_addr.s_addr = addr;
24311         }
24312 diff -NurpP --minimal linux-3.10.33/net/ipv4/arp.c linux-3.10.33-vs2.3.6.8/net/ipv4/arp.c
24313 --- linux-3.10.33/net/ipv4/arp.c        2013-07-14 17:01:37.000000000 +0000
24314 +++ linux-3.10.33-vs2.3.6.8/net/ipv4/arp.c      2013-08-22 20:30:00.000000000 +0000
24315 @@ -1332,6 +1332,7 @@ static void arp_format_neigh_entry(struc
24316         struct net_device *dev = n->dev;
24317         int hatype = dev->type;
24318  
24319 +       /* FIXME: check for network context */
24320         read_lock(&n->lock);
24321         /* Convert hardware address to XX:XX:XX:XX ... form. */
24322  #if IS_ENABLED(CONFIG_AX25)
24323 @@ -1363,6 +1364,7 @@ static void arp_format_pneigh_entry(stru
24324         int hatype = dev ? dev->type : 0;
24325         char tbuf[16];
24326  
24327 +       /* FIXME: check for network context */
24328         sprintf(tbuf, "%pI4", n->key);
24329         seq_printf(seq, "%-16s 0x%-10x0x%-10x%s     *        %s\n",
24330                    tbuf, hatype, ATF_PUBL | ATF_PERM, "00:00:00:00:00:00",
24331 diff -NurpP --minimal linux-3.10.33/net/ipv4/devinet.c linux-3.10.33-vs2.3.6.8/net/ipv4/devinet.c
24332 --- linux-3.10.33/net/ipv4/devinet.c    2014-03-12 13:16:02.000000000 +0000
24333 +++ linux-3.10.33-vs2.3.6.8/net/ipv4/devinet.c  2014-03-12 13:18:33.000000000 +0000
24334 @@ -522,6 +522,7 @@ struct in_device *inetdev_by_index(struc
24335  }
24336  EXPORT_SYMBOL(inetdev_by_index);
24337  
24338 +
24339  /* Called only from RTNL semaphored context. No locks. */
24340  
24341  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
24342 @@ -942,6 +943,8 @@ int devinet_ioctl(struct net *net, unsig
24343  
24344         in_dev = __in_dev_get_rtnl(dev);
24345         if (in_dev) {
24346 +               struct nx_info *nxi = current_nx_info();
24347 +
24348                 if (tryaddrmatch) {
24349                         /* Matthias Andree */
24350                         /* compare label and address (4.4BSD style) */
24351 @@ -950,6 +953,8 @@ int devinet_ioctl(struct net *net, unsig
24352                            This is checked above. */
24353                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24354                              ifap = &ifa->ifa_next) {
24355 +                               if (!nx_v4_ifa_visible(nxi, ifa))
24356 +                                       continue;
24357                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
24358                                     sin_orig.sin_addr.s_addr ==
24359                                                         ifa->ifa_local) {
24360 @@ -962,9 +967,12 @@ int devinet_ioctl(struct net *net, unsig
24361                    comparing just the label */
24362                 if (!ifa) {
24363                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24364 -                            ifap = &ifa->ifa_next)
24365 +                            ifap = &ifa->ifa_next) {
24366 +                               if (!nx_v4_ifa_visible(nxi, ifa))
24367 +                                       continue;
24368                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
24369                                         break;
24370 +                       }
24371                 }
24372         }
24373  
24374 @@ -1118,6 +1126,8 @@ static int inet_gifconf(struct net_devic
24375                 goto out;
24376  
24377         for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
24378 +               if (!nx_v4_ifa_visible(current_nx_info(), ifa))
24379 +                       continue;
24380                 if (!buf) {
24381                         done += sizeof(ifr);
24382                         continue;
24383 @@ -1522,6 +1532,7 @@ static int inet_dump_ifaddr(struct sk_bu
24384         struct net_device *dev;
24385         struct in_device *in_dev;
24386         struct in_ifaddr *ifa;
24387 +       struct sock *sk = skb->sk;
24388         struct hlist_head *head;
24389  
24390         s_h = cb->args[0];
24391 @@ -1545,6 +1556,8 @@ static int inet_dump_ifaddr(struct sk_bu
24392  
24393                         for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
24394                              ifa = ifa->ifa_next, ip_idx++) {
24395 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
24396 +                               continue;
24397                                 if (ip_idx < s_ip_idx)
24398                                         continue;
24399                                 if (inet_fill_ifaddr(skb, ifa,
24400 diff -NurpP --minimal linux-3.10.33/net/ipv4/fib_trie.c linux-3.10.33-vs2.3.6.8/net/ipv4/fib_trie.c
24401 --- linux-3.10.33/net/ipv4/fib_trie.c   2014-03-12 13:16:02.000000000 +0000
24402 +++ linux-3.10.33-vs2.3.6.8/net/ipv4/fib_trie.c 2013-11-13 17:17:16.000000000 +0000
24403 @@ -2536,6 +2536,7 @@ static int fib_route_seq_show(struct seq
24404                             || fa->fa_type == RTN_MULTICAST)
24405                                 continue;
24406  
24407 +                       /* FIXME: check for network context? */
24408                         if (fi)
24409                                 seq_printf(seq,
24410                                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t"
24411 diff -NurpP --minimal linux-3.10.33/net/ipv4/inet_connection_sock.c linux-3.10.33-vs2.3.6.8/net/ipv4/inet_connection_sock.c
24412 --- linux-3.10.33/net/ipv4/inet_connection_sock.c       2013-07-14 17:01:37.000000000 +0000
24413 +++ linux-3.10.33-vs2.3.6.8/net/ipv4/inet_connection_sock.c     2013-08-22 20:30:00.000000000 +0000
24414 @@ -53,6 +53,37 @@ void inet_get_local_port_range(int *low,
24415  }
24416  EXPORT_SYMBOL(inet_get_local_port_range);
24417  
24418 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24419 +{
24420 +       __be32  sk1_rcv_saddr = sk_rcv_saddr(sk1),
24421 +               sk2_rcv_saddr = sk_rcv_saddr(sk2);
24422 +
24423 +       if (inet_v6_ipv6only(sk2))
24424 +               return 0;
24425 +
24426 +       if (sk1_rcv_saddr &&
24427 +           sk2_rcv_saddr &&
24428 +           sk1_rcv_saddr == sk2_rcv_saddr)
24429 +               return 1;
24430 +
24431 +       if (sk1_rcv_saddr &&
24432 +           !sk2_rcv_saddr &&
24433 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
24434 +               return 1;
24435 +
24436 +       if (sk2_rcv_saddr &&
24437 +           !sk1_rcv_saddr &&
24438 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
24439 +               return 1;
24440 +
24441 +       if (!sk1_rcv_saddr &&
24442 +           !sk2_rcv_saddr &&
24443 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
24444 +               return 1;
24445 +
24446 +       return 0;
24447 +}
24448 +
24449  int inet_csk_bind_conflict(const struct sock *sk,
24450                            const struct inet_bind_bucket *tb, bool relax)
24451  {
24452 @@ -79,17 +110,12 @@ int inet_csk_bind_conflict(const struct
24453                             (!reuseport || !sk2->sk_reuseport ||
24454                             (sk2->sk_state != TCP_TIME_WAIT &&
24455                              !uid_eq(uid, sock_i_uid(sk2))))) {
24456 -                               const __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
24457 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr(sk) ||
24458 -                                   sk2_rcv_saddr == sk_rcv_saddr(sk))
24459 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
24460                                         break;
24461                         }
24462                         if (!relax && reuse && sk2->sk_reuse &&
24463                             sk2->sk_state != TCP_LISTEN) {
24464 -                               const __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
24465 -
24466 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr(sk) ||
24467 -                                   sk2_rcv_saddr == sk_rcv_saddr(sk))
24468 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
24469                                         break;
24470                         }
24471                 }
24472 diff -NurpP --minimal linux-3.10.33/net/ipv4/inet_diag.c linux-3.10.33-vs2.3.6.8/net/ipv4/inet_diag.c
24473 --- linux-3.10.33/net/ipv4/inet_diag.c  2014-03-12 13:16:02.000000000 +0000
24474 +++ linux-3.10.33-vs2.3.6.8/net/ipv4/inet_diag.c        2014-03-12 13:18:23.000000000 +0000
24475 @@ -31,6 +31,8 @@
24476  
24477  #include <linux/inet.h>
24478  #include <linux/stddef.h>
24479 +#include <linux/vs_network.h>
24480 +#include <linux/vs_inet.h>
24481  
24482  #include <linux/inet_diag.h>
24483  #include <linux/sock_diag.h>
24484 @@ -110,8 +112,10 @@ int inet_sk_diag_fill(struct sock *sk, s
24485         memset(&r->id.idiag_src, 0, sizeof(r->id.idiag_src));
24486         memset(&r->id.idiag_dst, 0, sizeof(r->id.idiag_dst));
24487  
24488 -       r->id.idiag_src[0] = inet->inet_rcv_saddr;
24489 -       r->id.idiag_dst[0] = inet->inet_daddr;
24490 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info,
24491 +               inet->inet_rcv_saddr);
24492 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info,
24493 +               inet->inet_daddr);
24494  
24495         if (nla_put_u8(skb, INET_DIAG_SHUTDOWN, sk->sk_shutdown))
24496                 goto errout;
24497 @@ -254,8 +258,8 @@ static int inet_twsk_diag_fill(struct in
24498         memset(&r->id.idiag_src, 0, sizeof(r->id.idiag_src));
24499         memset(&r->id.idiag_dst, 0, sizeof(r->id.idiag_dst));
24500  
24501 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
24502 -       r->id.idiag_dst[0]    = tw->tw_daddr;
24503 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
24504 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
24505  
24506         r->idiag_state        = tw->tw_substate;
24507         r->idiag_timer        = 3;
24508 @@ -300,12 +304,14 @@ int inet_diag_dump_one_icsk(struct inet_
24509  
24510         err = -EINVAL;
24511         if (req->sdiag_family == AF_INET) {
24512 +               /* TODO: lback */
24513                 sk = inet_lookup(net, hashinfo, req->id.idiag_dst[0],
24514                                  req->id.idiag_dport, req->id.idiag_src[0],
24515                                  req->id.idiag_sport, req->id.idiag_if);
24516         }
24517  #if IS_ENABLED(CONFIG_IPV6)
24518         else if (req->sdiag_family == AF_INET6) {
24519 +               /* TODO: lback */
24520                 sk = inet6_lookup(net, hashinfo,
24521                                   (struct in6_addr *)req->id.idiag_dst,
24522                                   req->id.idiag_dport,
24523 @@ -507,6 +513,7 @@ int inet_diag_bc_sk(const struct nlattr
24524         } else
24525  #endif
24526         {
24527 +                       /* TODO: lback */
24528                 entry.saddr = &inet->inet_rcv_saddr;
24529                 entry.daddr = &inet->inet_daddr;
24530         }
24531 @@ -665,6 +672,7 @@ static int inet_twsk_diag_dump(struct in
24532                 } else
24533  #endif
24534                 {
24535 +                       /* TODO: lback */
24536                         entry.saddr = &tw->tw_rcv_saddr;
24537                         entry.daddr = &tw->tw_daddr;
24538                 }
24539 @@ -747,8 +755,8 @@ static int inet_diag_fill_req(struct sk_
24540         memset(&r->id.idiag_src, 0, sizeof(r->id.idiag_src));
24541         memset(&r->id.idiag_dst, 0, sizeof(r->id.idiag_dst));
24542  
24543 -       r->id.idiag_src[0] = ireq->loc_addr;
24544 -       r->id.idiag_dst[0] = ireq->rmt_addr;
24545 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
24546 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
24547  
24548         r->idiag_expires = jiffies_to_msecs(tmo);
24549         r->idiag_rqueue = 0;
24550 @@ -812,6 +820,7 @@ static int inet_diag_dump_reqs(struct sk
24551                             r->id.idiag_dport)
24552                                 continue;
24553  
24554 +                       /* TODO: lback */
24555                         if (bc) {
24556                                 inet_diag_req_addrs(sk, req, &entry);
24557                                 entry.dport = ntohs(ireq->rmt_port);
24558 @@ -868,6 +877,8 @@ void inet_diag_dump_icsk(struct inet_has
24559                                 if (!net_eq(sock_net(sk), net))
24560                                         continue;
24561  
24562 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24563 +                                       continue;
24564                                 if (num < s_num) {
24565                                         num++;
24566                                         continue;
24567 @@ -940,6 +951,8 @@ skip_listen_ht:
24568  
24569                         if (!net_eq(sock_net(sk), net))
24570                                 continue;
24571 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24572 +                               continue;
24573                         if (num < s_num)
24574                                 goto next_normal;
24575                         if (!(r->idiag_states & (1 << sk->sk_state)))
24576 @@ -968,7 +981,8 @@ next_normal:
24577                                     &head->twchain) {
24578                                 if (!net_eq(twsk_net(tw), net))
24579                                         continue;
24580 -
24581 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
24582 +                                       continue;
24583                                 if (num < s_num)
24584                                         goto next_dying;
24585                                 if (!(r->idiag_states & (1 << tw->tw_substate)))
24586 diff -NurpP --minimal linux-3.10.33/net/ipv4/inet_hashtables.c linux-3.10.33-vs2.3.6.8/net/ipv4/inet_hashtables.c
24587 --- linux-3.10.33/net/ipv4/inet_hashtables.c    2014-03-12 13:16:02.000000000 +0000
24588 +++ linux-3.10.33-vs2.3.6.8/net/ipv4/inet_hashtables.c  2013-11-13 17:22:25.000000000 +0000
24589 @@ -22,6 +22,7 @@
24590  #include <net/inet_connection_sock.h>
24591  #include <net/inet_hashtables.h>
24592  #include <net/secure_seq.h>
24593 +#include <net/route.h>
24594  #include <net/ip.h>
24595  
24596  /*
24597 @@ -156,6 +157,11 @@ static inline int compute_score(struct s
24598                         if (rcv_saddr != daddr)
24599                                 return -1;
24600                         score += 4;
24601 +               } else {
24602 +                       /* block non nx_info ips */
24603 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
24604 +                               daddr, NXA_MASK_BIND))
24605 +                               return -1;
24606                 }
24607                 if (sk->sk_bound_dev_if) {
24608                         if (sk->sk_bound_dev_if != dif)
24609 @@ -173,7 +179,6 @@ static inline int compute_score(struct s
24610   * wildcarded during the search since they can never be otherwise.
24611   */
24612  
24613 -
24614  struct sock *__inet_lookup_listener(struct net *net,
24615                                     struct inet_hashinfo *hashinfo,
24616                                     const __be32 saddr, __be16 sport,
24617 @@ -209,6 +214,7 @@ begin:
24618                         phash = next_pseudo_random32(phash);
24619                 }
24620         }
24621 +
24622         /*
24623          * if the nulls value we got at the end of this lookup is
24624          * not the expected one, we must restart lookup.
24625 diff -NurpP --minimal linux-3.10.33/net/ipv4/netfilter.c linux-3.10.33-vs2.3.6.8/net/ipv4/netfilter.c
24626 --- linux-3.10.33/net/ipv4/netfilter.c  2013-07-14 17:01:37.000000000 +0000
24627 +++ linux-3.10.33-vs2.3.6.8/net/ipv4/netfilter.c        2013-08-22 20:30:00.000000000 +0000
24628 @@ -11,7 +11,7 @@
24629  #include <linux/skbuff.h>
24630  #include <linux/gfp.h>
24631  #include <linux/export.h>
24632 -#include <net/route.h>
24633 +// #include <net/route.h>
24634  #include <net/xfrm.h>
24635  #include <net/ip.h>
24636  #include <net/netfilter/nf_queue.h>
24637 diff -NurpP --minimal linux-3.10.33/net/ipv4/raw.c linux-3.10.33-vs2.3.6.8/net/ipv4/raw.c
24638 --- linux-3.10.33/net/ipv4/raw.c        2014-03-12 13:16:02.000000000 +0000
24639 +++ linux-3.10.33-vs2.3.6.8/net/ipv4/raw.c      2013-12-23 17:42:40.000000000 +0000
24640 @@ -116,7 +116,7 @@ static struct sock *__raw_v4_lookup(stru
24641  
24642                 if (net_eq(sock_net(sk), net) && inet->inet_num == num  &&
24643                     !(inet->inet_daddr && inet->inet_daddr != raddr)    &&
24644 -                   !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
24645 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
24646                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
24647                         goto found; /* gotcha */
24648         }
24649 @@ -395,6 +395,12 @@ static int raw_send_hdrinc(struct sock *
24650                 icmp_out_count(net, ((struct icmphdr *)
24651                         skb_transport_header(skb))->type);
24652  
24653 +       err = -EPERM;
24654 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
24655 +               sk->sk_nx_info &&
24656 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
24657 +               goto error_free;
24658 +
24659         err = NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT, skb, NULL,
24660                       rt->dst.dev, dst_output);
24661         if (err > 0)
24662 @@ -581,6 +587,16 @@ static int raw_sendmsg(struct kiocb *ioc
24663                         goto done;
24664         }
24665  
24666 +       if (sk->sk_nx_info) {
24667 +               rt = ip_v4_find_src(sock_net(sk), sk->sk_nx_info, &fl4);
24668 +               if (IS_ERR(rt)) {
24669 +                       err = PTR_ERR(rt);
24670 +                       rt = NULL;
24671 +                       goto done;
24672 +               }
24673 +               ip_rt_put(rt);
24674 +       }
24675 +
24676         security_sk_classify_flow(sk, flowi4_to_flowi(&fl4));
24677         rt = ip_route_output_flow(sock_net(sk), &fl4, sk);
24678         if (IS_ERR(rt)) {
24679 @@ -657,17 +673,19 @@ static int raw_bind(struct sock *sk, str
24680  {
24681         struct inet_sock *inet = inet_sk(sk);
24682         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
24683 +       struct nx_v4_sock_addr nsa = { 0 };
24684         int ret = -EINVAL;
24685         int chk_addr_ret;
24686  
24687         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
24688                 goto out;
24689 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
24690 +       v4_map_sock_addr(inet, addr, &nsa);
24691 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
24692         ret = -EADDRNOTAVAIL;
24693 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
24694 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
24695             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
24696                 goto out;
24697 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24698 +       v4_set_sock_addr(inet, &nsa);
24699         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24700                 inet->inet_saddr = 0;  /* Use device */
24701         sk_dst_reset(sk);
24702 @@ -716,7 +734,8 @@ static int raw_recvmsg(struct kiocb *ioc
24703         /* Copy the address. */
24704         if (sin) {
24705                 sin->sin_family = AF_INET;
24706 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
24707 +               sin->sin_addr.s_addr =
24708 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
24709                 sin->sin_port = 0;
24710                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
24711                 *addr_len = sizeof(*sin);
24712 @@ -912,7 +931,8 @@ static struct sock *raw_get_first(struct
24713         for (state->bucket = 0; state->bucket < RAW_HTABLE_SIZE;
24714                         ++state->bucket) {
24715                 sk_for_each(sk, &state->h->ht[state->bucket])
24716 -                       if (sock_net(sk) == seq_file_net(seq))
24717 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
24718 +                           nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24719                                 goto found;
24720         }
24721         sk = NULL;
24722 @@ -928,7 +948,8 @@ static struct sock *raw_get_next(struct
24723                 sk = sk_next(sk);
24724  try_again:
24725                 ;
24726 -       } while (sk && sock_net(sk) != seq_file_net(seq));
24727 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
24728 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
24729  
24730         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
24731                 sk = sk_head(&state->h->ht[state->bucket]);
24732 diff -NurpP --minimal linux-3.10.33/net/ipv4/route.c linux-3.10.33-vs2.3.6.8/net/ipv4/route.c
24733 --- linux-3.10.33/net/ipv4/route.c      2014-03-12 13:16:02.000000000 +0000
24734 +++ linux-3.10.33-vs2.3.6.8/net/ipv4/route.c    2014-03-12 13:18:33.000000000 +0000
24735 @@ -2007,7 +2007,7 @@ struct rtable *__ip_route_output_key(str
24736  
24737  
24738         if (fl4->flowi4_oif) {
24739 -               dev_out = dev_get_by_index_rcu(net, fl4->flowi4_oif);
24740 +               dev_out = dev_get_by_index_real_rcu(net, fl4->flowi4_oif);
24741                 rth = ERR_PTR(-ENODEV);
24742                 if (dev_out == NULL)
24743                         goto out;
24744 diff -NurpP --minimal linux-3.10.33/net/ipv4/tcp.c linux-3.10.33-vs2.3.6.8/net/ipv4/tcp.c
24745 --- linux-3.10.33/net/ipv4/tcp.c        2014-03-12 13:16:02.000000000 +0000
24746 +++ linux-3.10.33-vs2.3.6.8/net/ipv4/tcp.c      2013-12-23 17:42:40.000000000 +0000
24747 @@ -268,6 +268,7 @@
24748  #include <linux/crypto.h>
24749  #include <linux/time.h>
24750  #include <linux/slab.h>
24751 +#include <linux/in.h>
24752  
24753  #include <net/icmp.h>
24754  #include <net/inet_common.h>
24755 diff -NurpP --minimal linux-3.10.33/net/ipv4/tcp_ipv4.c linux-3.10.33-vs2.3.6.8/net/ipv4/tcp_ipv4.c
24756 --- linux-3.10.33/net/ipv4/tcp_ipv4.c   2014-03-12 13:16:02.000000000 +0000
24757 +++ linux-3.10.33-vs2.3.6.8/net/ipv4/tcp_ipv4.c 2013-12-23 17:42:40.000000000 +0000
24758 @@ -2263,6 +2263,12 @@ static void *listening_get_next(struct s
24759                 req = req->dl_next;
24760                 while (1) {
24761                         while (req) {
24762 +                               vxdprintk(VXD_CBIT(net, 6),
24763 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
24764 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
24765 +                               if (req->sk &&
24766 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
24767 +                                       continue;
24768                                 if (req->rsk_ops->family == st->family) {
24769                                         cur = req;
24770                                         goto out;
24771 @@ -2287,6 +2293,10 @@ get_req:
24772         }
24773  get_sk:
24774         sk_nulls_for_each_from(sk, node) {
24775 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
24776 +                       sk, sk->sk_nid, nx_current_nid());
24777 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24778 +                       continue;
24779                 if (!net_eq(sock_net(sk), net))
24780                         continue;
24781                 if (sk->sk_family == st->family) {
24782 @@ -2363,6 +2373,11 @@ static void *established_get_first(struc
24783  
24784                 spin_lock_bh(lock);
24785                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
24786 +                       vxdprintk(VXD_CBIT(net, 6),
24787 +                               "sk,egf: %p [#%d] (from %d)",
24788 +                               sk, sk->sk_nid, nx_current_nid());
24789 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24790 +                               continue;
24791                         if (sk->sk_family != st->family ||
24792                             !net_eq(sock_net(sk), net)) {
24793                                 continue;
24794 @@ -2373,6 +2388,11 @@ static void *established_get_first(struc
24795                 st->state = TCP_SEQ_STATE_TIME_WAIT;
24796                 inet_twsk_for_each(tw, node,
24797                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
24798 +                       vxdprintk(VXD_CBIT(net, 6),
24799 +                               "tw: %p [#%d] (from %d)",
24800 +                               tw, tw->tw_nid, nx_current_nid());
24801 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
24802 +                               continue;
24803                         if (tw->tw_family != st->family ||
24804                             !net_eq(twsk_net(tw), net)) {
24805                                 continue;
24806 @@ -2402,7 +2422,9 @@ static void *established_get_next(struct
24807                 tw = cur;
24808                 tw = tw_next(tw);
24809  get_tw:
24810 -               while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
24811 +               while (tw && (tw->tw_family != st->family ||
24812 +                       !net_eq(twsk_net(tw), net) ||
24813 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
24814                         tw = tw_next(tw);
24815                 }
24816                 if (tw) {
24817 @@ -2426,6 +2448,11 @@ get_tw:
24818                 sk = sk_nulls_next(sk);
24819  
24820         sk_nulls_for_each_from(sk, node) {
24821 +               vxdprintk(VXD_CBIT(net, 6),
24822 +                       "sk,egn: %p [#%d] (from %d)",
24823 +                       sk, sk->sk_nid, nx_current_nid());
24824 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24825 +                       continue;
24826                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
24827                         goto found;
24828         }
24829 @@ -2631,9 +2658,9 @@ static void get_openreq4(const struct so
24830         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
24831                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %pK%n",
24832                 i,
24833 -               ireq->loc_addr,
24834 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
24835                 ntohs(inet_sk(sk)->inet_sport),
24836 -               ireq->rmt_addr,
24837 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
24838                 ntohs(ireq->rmt_port),
24839                 TCP_SYN_RECV,
24840                 0, 0, /* could print option size, but that is af dependent. */
24841 @@ -2656,8 +2683,8 @@ static void get_tcp4_sock(struct sock *s
24842         const struct inet_connection_sock *icsk = inet_csk(sk);
24843         const struct inet_sock *inet = inet_sk(sk);
24844         struct fastopen_queue *fastopenq = icsk->icsk_accept_queue.fastopenq;
24845 -       __be32 dest = inet->inet_daddr;
24846 -       __be32 src = inet->inet_rcv_saddr;
24847 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
24848 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
24849         __u16 destp = ntohs(inet->inet_dport);
24850         __u16 srcp = ntohs(inet->inet_sport);
24851         int rx_queue;
24852 @@ -2715,8 +2742,8 @@ static void get_timewait4_sock(const str
24853         __u16 destp, srcp;
24854         long delta = tw->tw_ttd - jiffies;
24855  
24856 -       dest  = tw->tw_daddr;
24857 -       src   = tw->tw_rcv_saddr;
24858 +       dest  = nx_map_sock_lback(current_nx_info(), tw->tw_daddr);
24859 +       src   = nx_map_sock_lback(current_nx_info(), tw->tw_rcv_saddr);
24860         destp = ntohs(tw->tw_dport);
24861         srcp  = ntohs(tw->tw_sport);
24862  
24863 diff -NurpP --minimal linux-3.10.33/net/ipv4/tcp_minisocks.c linux-3.10.33-vs2.3.6.8/net/ipv4/tcp_minisocks.c
24864 --- linux-3.10.33/net/ipv4/tcp_minisocks.c      2013-07-14 17:01:37.000000000 +0000
24865 +++ linux-3.10.33-vs2.3.6.8/net/ipv4/tcp_minisocks.c    2013-08-22 20:30:00.000000000 +0000
24866 @@ -23,6 +23,9 @@
24867  #include <linux/slab.h>
24868  #include <linux/sysctl.h>
24869  #include <linux/workqueue.h>
24870 +#include <linux/vs_limit.h>
24871 +#include <linux/vs_socket.h>
24872 +#include <linux/vs_context.h>
24873  #include <net/tcp.h>
24874  #include <net/inet_common.h>
24875  #include <net/xfrm.h>
24876 @@ -290,6 +293,11 @@ void tcp_time_wait(struct sock *sk, int
24877                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
24878                 tcptw->tw_ts_offset     = tp->tsoffset;
24879  
24880 +               tw->tw_xid              = sk->sk_xid;
24881 +               tw->tw_vx_info          = NULL;
24882 +               tw->tw_nid              = sk->sk_nid;
24883 +               tw->tw_nx_info          = NULL;
24884 +
24885  #if IS_ENABLED(CONFIG_IPV6)
24886                 if (tw->tw_family == PF_INET6) {
24887                         struct ipv6_pinfo *np = inet6_sk(sk);
24888 diff -NurpP --minimal linux-3.10.33/net/ipv4/udp.c linux-3.10.33-vs2.3.6.8/net/ipv4/udp.c
24889 --- linux-3.10.33/net/ipv4/udp.c        2014-03-12 13:16:02.000000000 +0000
24890 +++ linux-3.10.33-vs2.3.6.8/net/ipv4/udp.c      2013-12-23 17:42:40.000000000 +0000
24891 @@ -306,14 +306,7 @@ fail:
24892  }
24893  EXPORT_SYMBOL(udp_lib_get_port);
24894  
24895 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24896 -{
24897 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
24898 -
24899 -       return  (!ipv6_only_sock(sk2)  &&
24900 -                (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr ||
24901 -                  inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
24902 -}
24903 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
24904  
24905  static unsigned int udp4_portaddr_hash(struct net *net, __be32 saddr,
24906                                        unsigned int port)
24907 @@ -348,6 +341,11 @@ static inline int compute_score(struct s
24908                         if (inet->inet_rcv_saddr != daddr)
24909                                 return -1;
24910                         score += 4;
24911 +               } else {
24912 +                       /* block non nx_info ips */
24913 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
24914 +                               daddr, NXA_MASK_BIND))
24915 +                               return -1;
24916                 }
24917                 if (inet->inet_daddr) {
24918                         if (inet->inet_daddr != saddr)
24919 @@ -458,6 +456,7 @@ begin:
24920         return result;
24921  }
24922  
24923 +
24924  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
24925   * harder than this. -DaveM
24926   */
24927 @@ -504,6 +503,11 @@ begin:
24928         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
24929                 score = compute_score(sk, net, saddr, hnum, sport,
24930                                       daddr, dport, dif);
24931 +               /* FIXME: disabled?
24932 +               if (score == 9) {
24933 +                       result = sk;
24934 +                       break;
24935 +               } else */
24936                 if (score > badness) {
24937                         result = sk;
24938                         badness = score;
24939 @@ -528,6 +532,7 @@ begin:
24940         if (get_nulls_value(node) != slot)
24941                 goto begin;
24942  
24943 +
24944         if (result) {
24945                 if (unlikely(!atomic_inc_not_zero_hint(&result->sk_refcnt, 2)))
24946                         result = NULL;
24947 @@ -537,6 +542,7 @@ begin:
24948                         goto begin;
24949                 }
24950         }
24951 +
24952         rcu_read_unlock();
24953         return result;
24954  }
24955 @@ -580,8 +586,7 @@ static inline struct sock *udp_v4_mcast_
24956                     udp_sk(s)->udp_port_hash != hnum ||
24957                     (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
24958                     (inet->inet_dport != rmt_port && inet->inet_dport) ||
24959 -                   (inet->inet_rcv_saddr &&
24960 -                    inet->inet_rcv_saddr != loc_addr) ||
24961 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
24962                     ipv6_only_sock(s) ||
24963                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
24964                         continue;
24965 @@ -965,6 +970,16 @@ int udp_sendmsg(struct kiocb *iocb, stru
24966                                    inet_sk_flowi_flags(sk)|FLOWI_FLAG_CAN_SLEEP,
24967                                    faddr, saddr, dport, inet->inet_sport);
24968  
24969 +               if (sk->sk_nx_info) {
24970 +                       rt = ip_v4_find_src(net, sk->sk_nx_info, fl4);
24971 +                       if (IS_ERR(rt)) {
24972 +                               err = PTR_ERR(rt);
24973 +                               rt = NULL;
24974 +                               goto out;
24975 +                       }
24976 +                       ip_rt_put(rt);
24977 +               }
24978 +
24979                 security_sk_classify_flow(sk, flowi4_to_flowi(fl4));
24980                 rt = ip_route_output_flow(net, fl4, sk);
24981                 if (IS_ERR(rt)) {
24982 @@ -1269,7 +1284,8 @@ try_again:
24983         if (sin) {
24984                 sin->sin_family = AF_INET;
24985                 sin->sin_port = udp_hdr(skb)->source;
24986 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
24987 +               sin->sin_addr.s_addr = nx_map_sock_lback(
24988 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
24989                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
24990                 *addr_len = sizeof(*sin);
24991         }
24992 @@ -2031,6 +2047,8 @@ static struct sock *udp_get_first(struct
24993                 sk_nulls_for_each(sk, node, &hslot->head) {
24994                         if (!net_eq(sock_net(sk), net))
24995                                 continue;
24996 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24997 +                               continue;
24998                         if (sk->sk_family == state->family)
24999                                 goto found;
25000                 }
25001 @@ -2048,7 +2066,9 @@ static struct sock *udp_get_next(struct
25002  
25003         do {
25004                 sk = sk_nulls_next(sk);
25005 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
25006 +       } while (sk && (!net_eq(sock_net(sk), net) ||
25007 +               sk->sk_family != state->family ||
25008 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
25009  
25010         if (!sk) {
25011                 if (state->bucket <= state->udp_table->mask)
25012 @@ -2144,8 +2164,8 @@ static void udp4_format_sock(struct sock
25013                 int bucket, int *len)
25014  {
25015         struct inet_sock *inet = inet_sk(sp);
25016 -       __be32 dest = inet->inet_daddr;
25017 -       __be32 src  = inet->inet_rcv_saddr;
25018 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
25019 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
25020         __u16 destp       = ntohs(inet->inet_dport);
25021         __u16 srcp        = ntohs(inet->inet_sport);
25022  
25023 diff -NurpP --minimal linux-3.10.33/net/ipv6/Kconfig linux-3.10.33-vs2.3.6.8/net/ipv6/Kconfig
25024 --- linux-3.10.33/net/ipv6/Kconfig      2013-07-14 17:01:38.000000000 +0000
25025 +++ linux-3.10.33-vs2.3.6.8/net/ipv6/Kconfig    2013-08-22 20:30:00.000000000 +0000
25026 @@ -4,8 +4,8 @@
25027  
25028  #   IPv6 as module will cause a CRASH if you try to unload it
25029  menuconfig IPV6
25030 -       tristate "The IPv6 protocol"
25031 -       default m
25032 +       bool "The IPv6 protocol"
25033 +       default n
25034         ---help---
25035           This is complemental support for the IP version 6.
25036           You will still be able to do traditional IPv4 networking as well.
25037 diff -NurpP --minimal linux-3.10.33/net/ipv6/addrconf.c linux-3.10.33-vs2.3.6.8/net/ipv6/addrconf.c
25038 --- linux-3.10.33/net/ipv6/addrconf.c   2014-03-12 13:16:02.000000000 +0000
25039 +++ linux-3.10.33-vs2.3.6.8/net/ipv6/addrconf.c 2013-11-13 17:17:16.000000000 +0000
25040 @@ -94,6 +94,8 @@
25041  #include <linux/proc_fs.h>
25042  #include <linux/seq_file.h>
25043  #include <linux/export.h>
25044 +#include <linux/vs_network.h>
25045 +#include <linux/vs_inet6.h>
25046  
25047  /* Set to 3 to get tracing... */
25048  #define ACONF_DEBUG 2
25049 @@ -1321,7 +1323,7 @@ out:
25050  
25051  int ipv6_dev_get_saddr(struct net *net, const struct net_device *dst_dev,
25052                        const struct in6_addr *daddr, unsigned int prefs,
25053 -                      struct in6_addr *saddr)
25054 +                      struct in6_addr *saddr, struct nx_info *nxi)
25055  {
25056         struct ipv6_saddr_score scores[2],
25057                                 *score = &scores[0], *hiscore = &scores[1];
25058 @@ -1393,6 +1395,8 @@ int ipv6_dev_get_saddr(struct net *net,
25059                                                dev->name);
25060                                 continue;
25061                         }
25062 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
25063 +                               continue;
25064  
25065                         score->rule = -1;
25066                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
25067 @@ -3448,7 +3452,10 @@ static void if6_seq_stop(struct seq_file
25068  static int if6_seq_show(struct seq_file *seq, void *v)
25069  {
25070         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
25071 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25072 +
25073 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
25074 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
25075 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25076                    &ifp->addr,
25077                    ifp->idev->dev->ifindex,
25078                    ifp->prefix_len,
25079 @@ -3952,6 +3959,11 @@ static int in6_dump_addrs(struct inet6_d
25080         struct ifacaddr6 *ifaca;
25081         int err = 1;
25082         int ip_idx = *p_ip_idx;
25083 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25084 +
25085 +       /* disable ipv6 on non v6 guests */
25086 +       if (nxi && !nx_info_has_v6(nxi))
25087 +               return skb->len;
25088  
25089         read_lock_bh(&idev->lock);
25090         switch (type) {
25091 @@ -3962,6 +3974,8 @@ static int in6_dump_addrs(struct inet6_d
25092                 list_for_each_entry(ifa, &idev->addr_list, if_list) {
25093                         if (++ip_idx < s_ip_idx)
25094                                 continue;
25095 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
25096 +                                       continue;
25097                         err = inet6_fill_ifaddr(skb, ifa,
25098                                                 NETLINK_CB(cb->skb).portid,
25099                                                 cb->nlh->nlmsg_seq,
25100 @@ -3979,6 +3993,8 @@ static int in6_dump_addrs(struct inet6_d
25101                      ifmca = ifmca->next, ip_idx++) {
25102                         if (ip_idx < s_ip_idx)
25103                                 continue;
25104 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
25105 +                                       continue;
25106                         err = inet6_fill_ifmcaddr(skb, ifmca,
25107                                                   NETLINK_CB(cb->skb).portid,
25108                                                   cb->nlh->nlmsg_seq,
25109 @@ -3994,6 +4010,8 @@ static int in6_dump_addrs(struct inet6_d
25110                      ifaca = ifaca->aca_next, ip_idx++) {
25111                         if (ip_idx < s_ip_idx)
25112                                 continue;
25113 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
25114 +                                       continue;
25115                         err = inet6_fill_ifacaddr(skb, ifaca,
25116                                                   NETLINK_CB(cb->skb).portid,
25117                                                   cb->nlh->nlmsg_seq,
25118 @@ -4022,6 +4040,10 @@ static int inet6_dump_addr(struct sk_buf
25119         struct inet6_dev *idev;
25120         struct hlist_head *head;
25121  
25122 +       /* FIXME: maybe disable ipv6 on non v6 guests?
25123 +       if (skb->sk && skb->sk->sk_vx_info)
25124 +               return skb->len; */
25125 +
25126         s_h = cb->args[0];
25127         s_idx = idx = cb->args[1];
25128         s_ip_idx = ip_idx = cb->args[2];
25129 @@ -4457,6 +4479,7 @@ static int inet6_dump_ifinfo(struct sk_b
25130         struct net_device *dev;
25131         struct inet6_dev *idev;
25132         struct hlist_head *head;
25133 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25134  
25135         s_h = cb->args[0];
25136         s_idx = cb->args[1];
25137 @@ -4468,6 +4491,8 @@ static int inet6_dump_ifinfo(struct sk_b
25138                 hlist_for_each_entry_rcu(dev, head, index_hlist) {
25139                         if (idx < s_idx)
25140                                 goto cont;
25141 +                       if (!v6_dev_in_nx_info(dev, nxi))
25142 +                               goto cont;
25143                         idev = __in6_dev_get(dev);
25144                         if (!idev)
25145                                 goto cont;
25146 diff -NurpP --minimal linux-3.10.33/net/ipv6/af_inet6.c linux-3.10.33-vs2.3.6.8/net/ipv6/af_inet6.c
25147 --- linux-3.10.33/net/ipv6/af_inet6.c   2013-07-14 17:01:38.000000000 +0000
25148 +++ linux-3.10.33-vs2.3.6.8/net/ipv6/af_inet6.c 2013-08-22 20:30:00.000000000 +0000
25149 @@ -43,6 +43,8 @@
25150  #include <linux/netdevice.h>
25151  #include <linux/icmpv6.h>
25152  #include <linux/netfilter_ipv6.h>
25153 +#include <linux/vs_inet.h>
25154 +#include <linux/vs_inet6.h>
25155  
25156  #include <net/ip.h>
25157  #include <net/ipv6.h>
25158 @@ -159,10 +161,13 @@ lookup_protocol:
25159         }
25160  
25161         err = -EPERM;
25162 +       if ((protocol == IPPROTO_ICMPV6) &&
25163 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
25164 +               goto override;
25165         if (sock->type == SOCK_RAW && !kern &&
25166             !ns_capable(net->user_ns, CAP_NET_RAW))
25167                 goto out_rcu_unlock;
25168 -
25169 +override:
25170         sock->ops = answer->ops;
25171         answer_prot = answer->prot;
25172         answer_no_check = answer->no_check;
25173 @@ -262,6 +267,7 @@ int inet6_bind(struct socket *sock, stru
25174         struct inet_sock *inet = inet_sk(sk);
25175         struct ipv6_pinfo *np = inet6_sk(sk);
25176         struct net *net = sock_net(sk);
25177 +       struct nx_v6_sock_addr nsa;
25178         __be32 v4addr = 0;
25179         unsigned short snum;
25180         int addr_type = 0;
25181 @@ -277,6 +283,10 @@ int inet6_bind(struct socket *sock, stru
25182         if (addr->sin6_family != AF_INET6)
25183                 return -EAFNOSUPPORT;
25184  
25185 +       err = v6_map_sock_addr(inet, addr, &nsa);
25186 +       if (err)
25187 +               return err;
25188 +
25189         addr_type = ipv6_addr_type(&addr->sin6_addr);
25190         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
25191                 return -EINVAL;
25192 @@ -308,6 +318,7 @@ int inet6_bind(struct socket *sock, stru
25193                 /* Reproduce AF_INET checks to make the bindings consistent */
25194                 v4addr = addr->sin6_addr.s6_addr32[3];
25195                 chk_addr_ret = inet_addr_type(net, v4addr);
25196 +
25197                 if (!sysctl_ip_nonlocal_bind &&
25198                     !(inet->freebind || inet->transparent) &&
25199                     v4addr != htonl(INADDR_ANY) &&
25200 @@ -317,6 +328,10 @@ int inet6_bind(struct socket *sock, stru
25201                         err = -EADDRNOTAVAIL;
25202                         goto out;
25203                 }
25204 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
25205 +                       err = -EADDRNOTAVAIL;
25206 +                       goto out;
25207 +               }
25208         } else {
25209                 if (addr_type != IPV6_ADDR_ANY) {
25210                         struct net_device *dev = NULL;
25211 @@ -343,6 +358,11 @@ int inet6_bind(struct socket *sock, stru
25212                                 }
25213                         }
25214  
25215 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25216 +                               err = -EADDRNOTAVAIL;
25217 +                               goto out_unlock;
25218 +                       }
25219 +
25220                         /* ipv4 addr of the socket is invalid.  Only the
25221                          * unspecified and mapped address have a v4 equivalent.
25222                          */
25223 @@ -359,6 +379,9 @@ int inet6_bind(struct socket *sock, stru
25224                 }
25225         }
25226  
25227 +       /* what's that for? */
25228 +       v6_set_sock_addr(inet, &nsa);
25229 +
25230         inet->inet_rcv_saddr = v4addr;
25231         inet->inet_saddr = v4addr;
25232  
25233 @@ -460,9 +483,11 @@ int inet6_getname(struct socket *sock, s
25234                         return -ENOTCONN;
25235                 sin->sin6_port = inet->inet_dport;
25236                 sin->sin6_addr = np->daddr;
25237 +               /* FIXME: remap lback? */
25238                 if (np->sndflow)
25239                         sin->sin6_flowinfo = np->flow_label;
25240         } else {
25241 +               /* FIXME: remap lback? */
25242                 if (ipv6_addr_any(&np->rcv_saddr))
25243                         sin->sin6_addr = np->saddr;
25244                 else
25245 diff -NurpP --minimal linux-3.10.33/net/ipv6/datagram.c linux-3.10.33-vs2.3.6.8/net/ipv6/datagram.c
25246 --- linux-3.10.33/net/ipv6/datagram.c   2014-03-12 13:16:02.000000000 +0000
25247 +++ linux-3.10.33-vs2.3.6.8/net/ipv6/datagram.c 2013-12-23 17:42:40.000000000 +0000
25248 @@ -656,7 +656,7 @@ int ip6_datagram_send_ctl(struct net *ne
25249  
25250                         rcu_read_lock();
25251                         if (fl6->flowi6_oif) {
25252 -                               dev = dev_get_by_index_rcu(net, fl6->flowi6_oif);
25253 +                               dev = dev_get_by_index_real_rcu(net, fl6->flowi6_oif);
25254                                 if (!dev) {
25255                                         rcu_read_unlock();
25256                                         return -ENODEV;
25257 diff -NurpP --minimal linux-3.10.33/net/ipv6/fib6_rules.c linux-3.10.33-vs2.3.6.8/net/ipv6/fib6_rules.c
25258 --- linux-3.10.33/net/ipv6/fib6_rules.c 2013-02-19 13:58:58.000000000 +0000
25259 +++ linux-3.10.33-vs2.3.6.8/net/ipv6/fib6_rules.c       2013-08-22 20:30:00.000000000 +0000
25260 @@ -90,7 +90,7 @@ static int fib6_rule_action(struct fib_r
25261                                                ip6_dst_idev(&rt->dst)->dev,
25262                                                &flp6->daddr,
25263                                                rt6_flags2srcprefs(flags),
25264 -                                              &saddr))
25265 +                                              &saddr, NULL))
25266                                 goto again;
25267                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
25268                                                r->src.plen))
25269 diff -NurpP --minimal linux-3.10.33/net/ipv6/inet6_hashtables.c linux-3.10.33-vs2.3.6.8/net/ipv6/inet6_hashtables.c
25270 --- linux-3.10.33/net/ipv6/inet6_hashtables.c   2014-03-12 13:16:02.000000000 +0000
25271 +++ linux-3.10.33-vs2.3.6.8/net/ipv6/inet6_hashtables.c 2013-11-13 17:22:25.000000000 +0000
25272 @@ -16,6 +16,7 @@
25273  
25274  #include <linux/module.h>
25275  #include <linux/random.h>
25276 +#include <linux/vs_inet6.h>
25277  
25278  #include <net/inet_connection_sock.h>
25279  #include <net/inet_hashtables.h>
25280 @@ -83,7 +84,6 @@ struct sock *__inet6_lookup_established(
25281         unsigned int slot = hash & hashinfo->ehash_mask;
25282         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
25283  
25284 -
25285         rcu_read_lock();
25286  begin:
25287         sk_nulls_for_each_rcu(sk, node, &head->chain) {
25288 @@ -97,7 +97,7 @@ begin:
25289                                 sock_put(sk);
25290                                 goto begin;
25291                         }
25292 -               goto out;
25293 +                       goto out;
25294                 }
25295         }
25296         if (get_nulls_value(node) != slot)
25297 @@ -147,6 +147,9 @@ static inline int compute_score(struct s
25298                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25299                                 return -1;
25300                         score++;
25301 +               } else {
25302 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25303 +                               return -1;
25304                 }
25305                 if (sk->sk_bound_dev_if) {
25306                         if (sk->sk_bound_dev_if != dif)
25307 diff -NurpP --minimal linux-3.10.33/net/ipv6/ip6_output.c linux-3.10.33-vs2.3.6.8/net/ipv6/ip6_output.c
25308 --- linux-3.10.33/net/ipv6/ip6_output.c 2014-03-12 13:16:02.000000000 +0000
25309 +++ linux-3.10.33-vs2.3.6.8/net/ipv6/ip6_output.c       2014-03-12 13:18:33.000000000 +0000
25310 @@ -896,7 +896,8 @@ static int ip6_dst_lookup_tail(struct so
25311                 struct rt6_info *rt = (struct rt6_info *) *dst;
25312                 err = ip6_route_get_saddr(net, rt, &fl6->daddr,
25313                                           sk ? inet6_sk(sk)->srcprefs : 0,
25314 -                                         &fl6->saddr);
25315 +                                         &fl6->saddr,
25316 +                                         sk ? sk->sk_nx_info : NULL);
25317                 if (err)
25318                         goto out_err_release;
25319         }
25320 diff -NurpP --minimal linux-3.10.33/net/ipv6/ndisc.c linux-3.10.33-vs2.3.6.8/net/ipv6/ndisc.c
25321 --- linux-3.10.33/net/ipv6/ndisc.c      2014-03-12 13:16:02.000000000 +0000
25322 +++ linux-3.10.33-vs2.3.6.8/net/ipv6/ndisc.c    2013-11-13 17:17:16.000000000 +0000
25323 @@ -487,7 +487,7 @@ static void ndisc_send_na(struct net_dev
25324         } else {
25325                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
25326                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
25327 -                                      &tmpaddr))
25328 +                                      &tmpaddr, NULL))
25329                         return;
25330                 src_addr = &tmpaddr;
25331         }
25332 diff -NurpP --minimal linux-3.10.33/net/ipv6/netfilter/ip6t_MASQUERADE.c linux-3.10.33-vs2.3.6.8/net/ipv6/netfilter/ip6t_MASQUERADE.c
25333 --- linux-3.10.33/net/ipv6/netfilter/ip6t_MASQUERADE.c  2012-12-11 03:30:57.000000000 +0000
25334 +++ linux-3.10.33-vs2.3.6.8/net/ipv6/netfilter/ip6t_MASQUERADE.c        2013-08-22 20:30:00.000000000 +0000
25335 @@ -34,7 +34,7 @@ masquerade_tg6(struct sk_buff *skb, cons
25336                             ctinfo == IP_CT_RELATED_REPLY));
25337  
25338         if (ipv6_dev_get_saddr(dev_net(par->out), par->out,
25339 -                              &ipv6_hdr(skb)->daddr, 0, &src) < 0)
25340 +                              &ipv6_hdr(skb)->daddr, 0, &src, NULL) < 0)
25341                 return NF_DROP;
25342  
25343         nfct_nat(ct)->masq_index = par->out->ifindex;
25344 diff -NurpP --minimal linux-3.10.33/net/ipv6/raw.c linux-3.10.33-vs2.3.6.8/net/ipv6/raw.c
25345 --- linux-3.10.33/net/ipv6/raw.c        2014-03-12 13:16:02.000000000 +0000
25346 +++ linux-3.10.33-vs2.3.6.8/net/ipv6/raw.c      2013-12-23 17:42:40.000000000 +0000
25347 @@ -30,6 +30,7 @@
25348  #include <linux/icmpv6.h>
25349  #include <linux/netfilter.h>
25350  #include <linux/netfilter_ipv6.h>
25351 +#include <linux/vs_inet6.h>
25352  #include <linux/skbuff.h>
25353  #include <linux/compat.h>
25354  #include <asm/uaccess.h>
25355 @@ -283,6 +284,13 @@ static int rawv6_bind(struct sock *sk, s
25356                                 goto out_unlock;
25357                 }
25358  
25359 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25360 +                       err = -EADDRNOTAVAIL;
25361 +                       if (dev)
25362 +                               dev_put(dev);
25363 +                       goto out;
25364 +               }
25365 +
25366                 /* ipv4 addr of the socket is invalid.  Only the
25367                  * unspecified and mapped address have a v4 equivalent.
25368                  */
25369 diff -NurpP --minimal linux-3.10.33/net/ipv6/route.c linux-3.10.33-vs2.3.6.8/net/ipv6/route.c
25370 --- linux-3.10.33/net/ipv6/route.c      2014-03-12 13:16:02.000000000 +0000
25371 +++ linux-3.10.33-vs2.3.6.8/net/ipv6/route.c    2014-01-22 19:00:34.000000000 +0000
25372 @@ -58,6 +58,7 @@
25373  #include <net/netevent.h>
25374  #include <net/netlink.h>
25375  #include <net/nexthop.h>
25376 +#include <linux/vs_inet6.h>
25377  
25378  #include <asm/uaccess.h>
25379  
25380 @@ -2129,15 +2130,17 @@ int ip6_route_get_saddr(struct net *net,
25381                         struct rt6_info *rt,
25382                         const struct in6_addr *daddr,
25383                         unsigned int prefs,
25384 -                       struct in6_addr *saddr)
25385 +                       struct in6_addr *saddr,
25386 +                       struct nx_info *nxi)
25387  {
25388         struct inet6_dev *idev = ip6_dst_idev((struct dst_entry*)rt);
25389         int err = 0;
25390 -       if (rt->rt6i_prefsrc.plen)
25391 +       if (rt->rt6i_prefsrc.plen && (!nxi ||
25392 +           v6_addr_in_nx_info(nxi, &rt->rt6i_prefsrc.addr, NXA_TYPE_ADDR)))
25393                 *saddr = rt->rt6i_prefsrc.addr;
25394         else
25395                 err = ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
25396 -                                        daddr, prefs, saddr);
25397 +                                        daddr, prefs, saddr, nxi);
25398         return err;
25399  }
25400  
25401 @@ -2557,7 +2560,8 @@ static int rt6_fill_node(struct net *net
25402                                 goto nla_put_failure;
25403         } else if (dst) {
25404                 struct in6_addr saddr_buf;
25405 -               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf) == 0 &&
25406 +               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf,
25407 +                   (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0 &&
25408                     nla_put(skb, RTA_PREFSRC, 16, &saddr_buf))
25409                         goto nla_put_failure;
25410         }
25411 @@ -2769,6 +2773,7 @@ static int rt6_info_route(struct rt6_inf
25412  {
25413         struct seq_file *m = p_arg;
25414  
25415 +       /* FIXME: check for network context? */
25416         seq_printf(m, "%pi6 %02x ", &rt->rt6i_dst.addr, rt->rt6i_dst.plen);
25417  
25418  #ifdef CONFIG_IPV6_SUBTREES
25419 diff -NurpP --minimal linux-3.10.33/net/ipv6/tcp_ipv6.c linux-3.10.33-vs2.3.6.8/net/ipv6/tcp_ipv6.c
25420 --- linux-3.10.33/net/ipv6/tcp_ipv6.c   2014-03-12 13:16:02.000000000 +0000
25421 +++ linux-3.10.33-vs2.3.6.8/net/ipv6/tcp_ipv6.c 2013-11-13 17:17:16.000000000 +0000
25422 @@ -71,6 +71,7 @@
25423  
25424  #include <linux/crypto.h>
25425  #include <linux/scatterlist.h>
25426 +#include <linux/vs_inet6.h>
25427  
25428  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
25429  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
25430 @@ -164,8 +165,15 @@ static int tcp_v6_connect(struct sock *s
25431          *      connect() to INADDR_ANY means loopback (BSD'ism).
25432          */
25433  
25434 -       if(ipv6_addr_any(&usin->sin6_addr))
25435 -               usin->sin6_addr.s6_addr[15] = 0x1;
25436 +       if(ipv6_addr_any(&usin->sin6_addr)) {
25437 +               struct nx_info *nxi =  sk->sk_nx_info;
25438 +
25439 +               if (nxi && nx_info_has_v6(nxi))
25440 +                       /* FIXME: remap lback? */
25441 +                       usin->sin6_addr = nxi->v6.ip;
25442 +               else
25443 +                       usin->sin6_addr.s6_addr[15] = 0x1;
25444 +       }
25445  
25446         addr_type = ipv6_addr_type(&usin->sin6_addr);
25447  
25448 diff -NurpP --minimal linux-3.10.33/net/ipv6/udp.c linux-3.10.33-vs2.3.6.8/net/ipv6/udp.c
25449 --- linux-3.10.33/net/ipv6/udp.c        2014-03-12 13:16:02.000000000 +0000
25450 +++ linux-3.10.33-vs2.3.6.8/net/ipv6/udp.c      2013-12-23 17:42:40.000000000 +0000
25451 @@ -46,42 +46,68 @@
25452  #include <net/ip6_checksum.h>
25453  #include <net/xfrm.h>
25454  #include <net/inet6_hashtables.h>
25455 +#include <linux/vs_inet6.h>
25456  
25457  #include <linux/proc_fs.h>
25458  #include <linux/seq_file.h>
25459  #include <trace/events/skb.h>
25460  #include "udp_impl.h"
25461  
25462 -int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
25463 +int ipv6_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25464  {
25465 -       const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
25466 +       const struct in6_addr *sk1_rcv_saddr6 = &inet6_sk(sk1)->rcv_saddr;
25467         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
25468 -       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk);
25469 +       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk1);
25470         __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
25471 -       int sk_ipv6only = ipv6_only_sock(sk);
25472 +       int sk1_ipv6only = ipv6_only_sock(sk1);
25473         int sk2_ipv6only = inet_v6_ipv6only(sk2);
25474 -       int addr_type = ipv6_addr_type(sk_rcv_saddr6);
25475 +       int addr_type = ipv6_addr_type(sk1_rcv_saddr6);
25476         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
25477  
25478         /* if both are mapped, treat as IPv4 */
25479 -       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
25480 -               return (!sk2_ipv6only &&
25481 +       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
25482 +               if (!sk2_ipv6only &&
25483                         (!sk1_rcv_saddr || !sk2_rcv_saddr ||
25484 -                         sk1_rcv_saddr == sk2_rcv_saddr));
25485 +                         sk1_rcv_saddr == sk2_rcv_saddr))
25486 +                       goto vs_v4;
25487 +               else
25488 +                       return 0;
25489 +       }
25490  
25491         if (addr_type2 == IPV6_ADDR_ANY &&
25492             !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
25493 -               return 1;
25494 +               goto vs;
25495  
25496         if (addr_type == IPV6_ADDR_ANY &&
25497 -           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
25498 -               return 1;
25499 +           !(sk1_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
25500 +               goto vs;
25501  
25502         if (sk2_rcv_saddr6 &&
25503 -           ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
25504 -               return 1;
25505 +           ipv6_addr_equal(sk1_rcv_saddr6, sk2_rcv_saddr6))
25506 +               goto vs;
25507  
25508         return 0;
25509 +
25510 +vs_v4:
25511 +       if (!sk1_rcv_saddr && !sk2_rcv_saddr)
25512 +               return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25513 +       if (!sk2_rcv_saddr)
25514 +               return v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, -1);
25515 +       if (!sk1_rcv_saddr)
25516 +               return v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, -1);
25517 +       return 1;
25518 +vs:
25519 +       if (addr_type2 == IPV6_ADDR_ANY && addr_type == IPV6_ADDR_ANY)
25520 +               return nx_v6_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25521 +       else if (addr_type2 == IPV6_ADDR_ANY)
25522 +               return v6_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr6, -1);
25523 +       else if (addr_type == IPV6_ADDR_ANY) {
25524 +               if (addr_type2 == IPV6_ADDR_MAPPED)
25525 +                       return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25526 +               else
25527 +                       return v6_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr6, -1);
25528 +       }
25529 +       return 1;
25530  }
25531  
25532  static unsigned int udp6_portaddr_hash(struct net *net,
25533 @@ -145,6 +171,10 @@ static inline int compute_score(struct s
25534                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25535                                 return -1;
25536                         score++;
25537 +               } else {
25538 +                       /* block non nx_info ips */
25539 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25540 +                               return -1;
25541                 }
25542                 if (!ipv6_addr_any(&np->daddr)) {
25543                         if (!ipv6_addr_equal(&np->daddr, saddr))
25544 diff -NurpP --minimal linux-3.10.33/net/ipv6/xfrm6_policy.c linux-3.10.33-vs2.3.6.8/net/ipv6/xfrm6_policy.c
25545 --- linux-3.10.33/net/ipv6/xfrm6_policy.c       2013-07-14 17:01:38.000000000 +0000
25546 +++ linux-3.10.33-vs2.3.6.8/net/ipv6/xfrm6_policy.c     2013-08-22 20:30:00.000000000 +0000
25547 @@ -63,7 +63,7 @@ static int xfrm6_get_saddr(struct net *n
25548         dev = ip6_dst_idev(dst)->dev;
25549         ipv6_dev_get_saddr(dev_net(dev), dev,
25550                            (struct in6_addr *)&daddr->a6, 0,
25551 -                          (struct in6_addr *)&saddr->a6);
25552 +                          (struct in6_addr *)&saddr->a6, NULL);
25553         dst_release(dst);
25554         return 0;
25555  }
25556 diff -NurpP --minimal linux-3.10.33/net/netfilter/ipvs/ip_vs_xmit.c linux-3.10.33-vs2.3.6.8/net/netfilter/ipvs/ip_vs_xmit.c
25557 --- linux-3.10.33/net/netfilter/ipvs/ip_vs_xmit.c       2014-03-12 13:16:02.000000000 +0000
25558 +++ linux-3.10.33-vs2.3.6.8/net/netfilter/ipvs/ip_vs_xmit.c     2013-11-13 17:17:16.000000000 +0000
25559 @@ -316,7 +316,7 @@ __ip_vs_route_output_v6(struct net *net,
25560                 return dst;
25561         if (ipv6_addr_any(&fl6.saddr) &&
25562             ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
25563 -                              &fl6.daddr, 0, &fl6.saddr) < 0)
25564 +                              &fl6.daddr, 0, &fl6.saddr, NULL) < 0)
25565                 goto out_err;
25566         if (do_xfrm) {
25567                 dst = xfrm_lookup(net, dst, flowi6_to_flowi(&fl6), NULL, 0);
25568 diff -NurpP --minimal linux-3.10.33/net/netlink/af_netlink.c linux-3.10.33-vs2.3.6.8/net/netlink/af_netlink.c
25569 --- linux-3.10.33/net/netlink/af_netlink.c      2014-03-12 13:16:02.000000000 +0000
25570 +++ linux-3.10.33-vs2.3.6.8/net/netlink/af_netlink.c    2013-12-23 17:42:40.000000000 +0000
25571 @@ -57,6 +57,9 @@
25572  #include <linux/audit.h>
25573  #include <linux/mutex.h>
25574  #include <linux/vmalloc.h>
25575 +#include <linux/vs_context.h>
25576 +#include <linux/vs_network.h>
25577 +#include <linux/vs_limit.h>
25578  #include <asm/cacheflush.h>
25579  
25580  #include <net/net_namespace.h>
25581 @@ -2682,6 +2685,8 @@ static struct sock *netlink_seq_socket_i
25582                         sk_for_each(s, &hash->table[j]) {
25583                                 if (sock_net(s) != seq_file_net(seq))
25584                                         continue;
25585 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25586 +                                       continue;
25587                                 if (off == pos) {
25588                                         iter->link = i;
25589                                         iter->hash_idx = j;
25590 @@ -2716,7 +2721,8 @@ static void *netlink_seq_next(struct seq
25591         s = v;
25592         do {
25593                 s = sk_next(s);
25594 -       } while (s && sock_net(s) != seq_file_net(seq));
25595 +       } while (s && (sock_net(s) != seq_file_net(seq) ||
25596 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
25597         if (s)
25598                 return s;
25599  
25600 @@ -2728,7 +2734,8 @@ static void *netlink_seq_next(struct seq
25601  
25602                 for (; j <= hash->mask; j++) {
25603                         s = sk_head(&hash->table[j]);
25604 -                       while (s && sock_net(s) != seq_file_net(seq))
25605 +                       while (s && (sock_net(s) != seq_file_net(seq) ||
25606 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
25607                                 s = sk_next(s);
25608                         if (s) {
25609                                 iter->link = i;
25610 diff -NurpP --minimal linux-3.10.33/net/socket.c linux-3.10.33-vs2.3.6.8/net/socket.c
25611 --- linux-3.10.33/net/socket.c  2014-03-12 13:16:02.000000000 +0000
25612 +++ linux-3.10.33-vs2.3.6.8/net/socket.c        2013-12-23 17:42:40.000000000 +0000
25613 @@ -98,6 +98,10 @@
25614  
25615  #include <net/sock.h>
25616  #include <linux/netfilter.h>
25617 +#include <linux/vs_base.h>
25618 +#include <linux/vs_socket.h>
25619 +#include <linux/vs_inet.h>
25620 +#include <linux/vs_inet6.h>
25621  
25622  #include <linux/if_tun.h>
25623  #include <linux/ipv6_route.h>
25624 @@ -617,13 +621,29 @@ static inline int __sock_sendmsg_nosec(s
25625                                        struct msghdr *msg, size_t size)
25626  {
25627         struct sock_iocb *si = kiocb_to_siocb(iocb);
25628 +       size_t len;
25629  
25630         si->sock = sock;
25631         si->scm = NULL;
25632         si->msg = msg;
25633         si->size = size;
25634  
25635 -       return sock->ops->sendmsg(iocb, sock, msg, size);
25636 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
25637 +       if (sock->sk) {
25638 +               if (len == size)
25639 +                       vx_sock_send(sock->sk, size);
25640 +               else
25641 +                       vx_sock_fail(sock->sk, size);
25642 +       }
25643 +       vxdprintk(VXD_CBIT(net, 7),
25644 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%zu",
25645 +               sock, sock->sk,
25646 +               (sock->sk)?sock->sk->sk_nx_info:0,
25647 +               (sock->sk)?sock->sk->sk_vx_info:0,
25648 +               (sock->sk)?sock->sk->sk_xid:0,
25649 +               (sock->sk)?sock->sk->sk_nid:0,
25650 +               (unsigned int)size, len);
25651 +       return len;
25652  }
25653  
25654  static inline int __sock_sendmsg(struct kiocb *iocb, struct socket *sock,
25655 @@ -767,6 +787,7 @@ static inline int __sock_recvmsg_nosec(s
25656                                        struct msghdr *msg, size_t size, int flags)
25657  {
25658         struct sock_iocb *si = kiocb_to_siocb(iocb);
25659 +       int len;
25660  
25661         si->sock = sock;
25662         si->scm = NULL;
25663 @@ -774,7 +795,18 @@ static inline int __sock_recvmsg_nosec(s
25664         si->size = size;
25665         si->flags = flags;
25666  
25667 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
25668 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
25669 +       if ((len >= 0) && sock->sk)
25670 +               vx_sock_recv(sock->sk, len);
25671 +       vxdprintk(VXD_CBIT(net, 7),
25672 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
25673 +               sock, sock->sk,
25674 +               (sock->sk)?sock->sk->sk_nx_info:0,
25675 +               (sock->sk)?sock->sk->sk_vx_info:0,
25676 +               (sock->sk)?sock->sk->sk_xid:0,
25677 +               (sock->sk)?sock->sk->sk_nid:0,
25678 +               (unsigned int)size, len);
25679 +       return len;
25680  }
25681  
25682  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
25683 @@ -1248,6 +1280,13 @@ int __sock_create(struct net *net, int f
25684         if (type < 0 || type >= SOCK_MAX)
25685                 return -EINVAL;
25686  
25687 +       if (!nx_check(0, VS_ADMIN)) {
25688 +               if (family == PF_INET && !current_nx_info_has_v4())
25689 +                       return -EAFNOSUPPORT;
25690 +               if (family == PF_INET6 && !current_nx_info_has_v6())
25691 +                       return -EAFNOSUPPORT;
25692 +       }
25693 +
25694         /* Compatibility.
25695  
25696            This uglymoron is moved from INET layer to here to avoid
25697 @@ -1382,6 +1421,7 @@ SYSCALL_DEFINE3(socket, int, family, int
25698         if (retval < 0)
25699                 goto out;
25700  
25701 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
25702         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
25703         if (retval < 0)
25704                 goto out_release;
25705 @@ -1423,10 +1463,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
25706         err = sock_create(family, type, protocol, &sock1);
25707         if (err < 0)
25708                 goto out;
25709 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
25710  
25711         err = sock_create(family, type, protocol, &sock2);
25712         if (err < 0)
25713                 goto out_release_1;
25714 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
25715  
25716         err = sock1->ops->socketpair(sock1, sock2);
25717         if (err < 0)
25718 diff -NurpP --minimal linux-3.10.33/net/sunrpc/auth.c linux-3.10.33-vs2.3.6.8/net/sunrpc/auth.c
25719 --- linux-3.10.33/net/sunrpc/auth.c     2013-07-14 17:01:39.000000000 +0000
25720 +++ linux-3.10.33-vs2.3.6.8/net/sunrpc/auth.c   2013-08-22 20:30:00.000000000 +0000
25721 @@ -15,6 +15,7 @@
25722  #include <linux/sunrpc/clnt.h>
25723  #include <linux/sunrpc/gss_api.h>
25724  #include <linux/spinlock.h>
25725 +#include <linux/vs_tag.h>
25726  
25727  #ifdef RPC_DEBUG
25728  # define RPCDBG_FACILITY       RPCDBG_AUTH
25729 @@ -553,6 +554,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
25730         memset(&acred, 0, sizeof(acred));
25731         acred.uid = cred->fsuid;
25732         acred.gid = cred->fsgid;
25733 +       acred.tag = make_ktag(&init_user_ns, dx_current_tag());
25734         acred.group_info = get_group_info(((struct cred *)cred)->group_info);
25735  
25736         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
25737 @@ -593,6 +595,7 @@ rpcauth_bind_root_cred(struct rpc_task *
25738         struct auth_cred acred = {
25739                 .uid = GLOBAL_ROOT_UID,
25740                 .gid = GLOBAL_ROOT_GID,
25741 +               .tag = KTAGT_INIT(dx_current_tag()),
25742         };
25743  
25744         dprintk("RPC: %5u looking up %s cred\n",
25745 diff -NurpP --minimal linux-3.10.33/net/sunrpc/auth_unix.c linux-3.10.33-vs2.3.6.8/net/sunrpc/auth_unix.c
25746 --- linux-3.10.33/net/sunrpc/auth_unix.c        2013-05-31 13:45:33.000000000 +0000
25747 +++ linux-3.10.33-vs2.3.6.8/net/sunrpc/auth_unix.c      2013-08-22 20:30:00.000000000 +0000
25748 @@ -13,11 +13,13 @@
25749  #include <linux/sunrpc/clnt.h>
25750  #include <linux/sunrpc/auth.h>
25751  #include <linux/user_namespace.h>
25752 +#include <linux/vs_tag.h>
25753  
25754  #define NFS_NGROUPS    16
25755  
25756  struct unx_cred {
25757         struct rpc_cred         uc_base;
25758 +       ktag_t                  uc_tag;
25759         kgid_t                  uc_gid;
25760         kgid_t                  uc_gids[NFS_NGROUPS];
25761  };
25762 @@ -80,6 +82,7 @@ unx_create_cred(struct rpc_auth *auth, s
25763                 groups = NFS_NGROUPS;
25764  
25765         cred->uc_gid = acred->gid;
25766 +       cred->uc_tag = acred->tag;
25767         for (i = 0; i < groups; i++)
25768                 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
25769         if (i < NFS_NGROUPS)
25770 @@ -121,7 +124,9 @@ unx_match(struct auth_cred *acred, struc
25771         unsigned int i;
25772  
25773  
25774 -       if (!uid_eq(cred->uc_uid, acred->uid) || !gid_eq(cred->uc_gid, acred->gid))
25775 +       if (!uid_eq(cred->uc_uid, acred->uid) ||
25776 +           !gid_eq(cred->uc_gid, acred->gid) ||
25777 +           !tag_eq(cred->uc_tag, acred->tag))
25778                 return 0;
25779  
25780         if (acred->group_info != NULL)
25781 @@ -146,7 +151,7 @@ unx_marshal(struct rpc_task *task, __be3
25782         struct rpc_clnt *clnt = task->tk_client;
25783         struct unx_cred *cred = container_of(task->tk_rqstp->rq_cred, struct unx_cred, uc_base);
25784         __be32          *base, *hold;
25785 -       int             i;
25786 +       int             i, tag;
25787  
25788         *p++ = htonl(RPC_AUTH_UNIX);
25789         base = p++;
25790 @@ -157,8 +162,11 @@ unx_marshal(struct rpc_task *task, __be3
25791          */
25792         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
25793  
25794 -       *p++ = htonl((u32) from_kuid(&init_user_ns, cred->uc_uid));
25795 -       *p++ = htonl((u32) from_kgid(&init_user_ns, cred->uc_gid));
25796 +       tag = task->tk_client->cl_tag;
25797 +       *p++ = htonl((u32) from_kuid(&init_user_ns,
25798 +               TAGINO_KUID(tag, cred->uc_uid, cred->uc_tag)));
25799 +       *p++ = htonl((u32) from_kgid(&init_user_ns,
25800 +               TAGINO_KGID(tag, cred->uc_gid, cred->uc_tag)));
25801         hold = p++;
25802         for (i = 0; i < 16 && gid_valid(cred->uc_gids[i]); i++)
25803                 *p++ = htonl((u32) from_kgid(&init_user_ns, cred->uc_gids[i]));
25804 diff -NurpP --minimal linux-3.10.33/net/sunrpc/clnt.c linux-3.10.33-vs2.3.6.8/net/sunrpc/clnt.c
25805 --- linux-3.10.33/net/sunrpc/clnt.c     2014-03-12 13:16:02.000000000 +0000
25806 +++ linux-3.10.33-vs2.3.6.8/net/sunrpc/clnt.c   2014-03-12 13:18:24.000000000 +0000
25807 @@ -31,6 +31,7 @@
25808  #include <linux/in6.h>
25809  #include <linux/un.h>
25810  #include <linux/rcupdate.h>
25811 +#include <linux/vs_cvirt.h>
25812  
25813  #include <linux/sunrpc/clnt.h>
25814  #include <linux/sunrpc/addr.h>
25815 @@ -486,6 +487,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
25816         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
25817                 clnt->cl_chatty = 1;
25818  
25819 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
25820 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
25821 +               clnt->cl_tag = 1; */
25822         return clnt;
25823  }
25824  EXPORT_SYMBOL_GPL(rpc_create);
25825 diff -NurpP --minimal linux-3.10.33/net/unix/af_unix.c linux-3.10.33-vs2.3.6.8/net/unix/af_unix.c
25826 --- linux-3.10.33/net/unix/af_unix.c    2014-03-12 13:16:02.000000000 +0000
25827 +++ linux-3.10.33-vs2.3.6.8/net/unix/af_unix.c  2014-01-22 19:00:34.000000000 +0000
25828 @@ -114,6 +114,8 @@
25829  #include <linux/mount.h>
25830  #include <net/checksum.h>
25831  #include <linux/security.h>
25832 +#include <linux/vs_context.h>
25833 +#include <linux/vs_limit.h>
25834  
25835  struct hlist_head unix_socket_table[2 * UNIX_HASH_SIZE];
25836  EXPORT_SYMBOL_GPL(unix_socket_table);
25837 @@ -270,6 +272,8 @@ static struct sock *__unix_find_socket_b
25838                 if (!net_eq(sock_net(s), net))
25839                         continue;
25840  
25841 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25842 +                       continue;
25843                 if (u->addr->len == len &&
25844                     !memcmp(u->addr->name, sunname, len))
25845                         goto found;
25846 @@ -2270,6 +2274,8 @@ static struct sock *unix_from_bucket(str
25847         for (sk = sk_head(&unix_socket_table[bucket]); sk; sk = sk_next(sk)) {
25848                 if (sock_net(sk) != seq_file_net(seq))
25849                         continue;
25850 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25851 +                       continue;
25852                 if (++count == offset)
25853                         break;
25854         }
25855 @@ -2287,6 +2293,8 @@ static struct sock *unix_next_socket(str
25856                 sk = sk_next(sk);
25857                 if (!sk)
25858                         goto next_bucket;
25859 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25860 +                       continue;
25861                 if (sock_net(sk) == seq_file_net(seq))
25862                         return sk;
25863         }
25864 diff -NurpP --minimal linux-3.10.33/scripts/checksyscalls.sh linux-3.10.33-vs2.3.6.8/scripts/checksyscalls.sh
25865 --- linux-3.10.33/scripts/checksyscalls.sh      2012-12-11 03:30:57.000000000 +0000
25866 +++ linux-3.10.33-vs2.3.6.8/scripts/checksyscalls.sh    2013-08-22 20:30:00.000000000 +0000
25867 @@ -193,7 +193,6 @@ cat << EOF
25868  #define __IGNORE_afs_syscall
25869  #define __IGNORE_getpmsg
25870  #define __IGNORE_putpmsg
25871 -#define __IGNORE_vserver
25872  EOF
25873  }
25874  
25875 diff -NurpP --minimal linux-3.10.33/security/commoncap.c linux-3.10.33-vs2.3.6.8/security/commoncap.c
25876 --- linux-3.10.33/security/commoncap.c  2013-05-31 13:45:34.000000000 +0000
25877 +++ linux-3.10.33-vs2.3.6.8/security/commoncap.c        2013-08-22 20:30:00.000000000 +0000
25878 @@ -76,6 +76,7 @@ int cap_netlink_send(struct sock *sk, st
25879  int cap_capable(const struct cred *cred, struct user_namespace *targ_ns,
25880                 int cap, int audit)
25881  {
25882 +       struct vx_info *vxi = current_vx_info(); /* FIXME: get vxi from cred? */
25883         struct user_namespace *ns = targ_ns;
25884  
25885         /* See if cred has the capability in the target user namespace
25886 @@ -84,8 +85,12 @@ int cap_capable(const struct cred *cred,
25887          */
25888         for (;;) {
25889                 /* Do we have the necessary capabilities? */
25890 -               if (ns == cred->user_ns)
25891 -                       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
25892 +               if (ns == cred->user_ns) {
25893 +                       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
25894 +                           cap_raised(cred->cap_effective, cap))
25895 +                               return 0;
25896 +                       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
25897 +               }
25898  
25899                 /* Have we tried all of the parent namespaces? */
25900                 if (ns == &init_user_ns)
25901 @@ -628,7 +633,7 @@ int cap_inode_setxattr(struct dentry *de
25902  
25903         if (!strncmp(name, XATTR_SECURITY_PREFIX,
25904                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
25905 -           !capable(CAP_SYS_ADMIN))
25906 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
25907                 return -EPERM;
25908         return 0;
25909  }
25910 @@ -654,7 +659,7 @@ int cap_inode_removexattr(struct dentry
25911  
25912         if (!strncmp(name, XATTR_SECURITY_PREFIX,
25913                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
25914 -           !capable(CAP_SYS_ADMIN))
25915 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
25916                 return -EPERM;
25917         return 0;
25918  }
25919 diff -NurpP --minimal linux-3.10.33/security/selinux/hooks.c linux-3.10.33-vs2.3.6.8/security/selinux/hooks.c
25920 --- linux-3.10.33/security/selinux/hooks.c      2014-03-12 13:16:02.000000000 +0000
25921 +++ linux-3.10.33-vs2.3.6.8/security/selinux/hooks.c    2014-03-12 13:18:24.000000000 +0000
25922 @@ -68,7 +68,6 @@
25923  #include <linux/dccp.h>
25924  #include <linux/quota.h>
25925  #include <linux/un.h>          /* for Unix socket types */
25926 -#include <net/af_unix.h>       /* for Unix socket types */
25927  #include <linux/parser.h>
25928  #include <linux/nfs_mount.h>
25929  #include <net/ipv6.h>
This page took 2.109101 seconds and 3 git commands to generate.