]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
b7360db428d63d694a40af58f80036324bd1a091
[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 @@ -39,6 +39,7 @@
2940  #include <linux/ratelimit.h>
2941  #include <linux/aio.h>
2942  #include <linux/bitops.h>
2943 +#include <linux/vs_tag.h>
2944  
2945  #include "ext4_jbd2.h"
2946  #include "xattr.h"
2947 @@ -4046,43 +4047,65 @@ void ext4_set_inode_flags(struct inode *
2948  {
2949         unsigned int flags = EXT4_I(inode)->i_flags;
2950         unsigned int new_fl = 0;
2951 +       unsigned int new_vf = 0;
2952 +
2953 +       if (flags & EXT4_IMMUTABLE_FL)
2954 +               new_fl |= S_IMMUTABLE;
2955 +       if (flags & EXT4_IXUNLINK_FL)
2956 +               new_fl |= S_IXUNLINK;
2957  
2958         if (flags & EXT4_SYNC_FL)
2959                 new_fl |= S_SYNC;
2960         if (flags & EXT4_APPEND_FL)
2961                 new_fl |= S_APPEND;
2962 -       if (flags & EXT4_IMMUTABLE_FL)
2963 -               new_fl |= S_IMMUTABLE;
2964         if (flags & EXT4_NOATIME_FL)
2965                 new_fl |= S_NOATIME;
2966         if (flags & EXT4_DIRSYNC_FL)
2967                 new_fl |= S_DIRSYNC;
2968         set_mask_bits(&inode->i_flags,
2969 -                     S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC, new_fl);
2970 +                     S_IMMUTABLE|S_IXUNLINK|S_SYNC|S_APPEND|S_NOATIME|S_DIRSYNC,
2971 +                     new_fl);
2972 +
2973 +       if (flags & EXT4_BARRIER_FL)
2974 +               new_vf |= V_BARRIER;
2975 +       if (flags & EXT4_COW_FL)
2976 +               new_vf |= V_COW;
2977 +       set_mask_bits(&inode->i_vflags, V_BARRIER|V_COW, new_vf);
2978  }
2979  
2980  /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
2981  void ext4_get_inode_flags(struct ext4_inode_info *ei)
2982  {
2983 -       unsigned int vfs_fl;
2984 +       unsigned int vfs_fl, vfs_vf;
2985         unsigned long old_fl, new_fl;
2986  
2987         do {
2988                 vfs_fl = ei->vfs_inode.i_flags;
2989 +               vfs_vf = ei->vfs_inode.i_vflags;
2990                 old_fl = ei->i_flags;
2991                 new_fl = old_fl & ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
2992                                 EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|
2993 -                               EXT4_DIRSYNC_FL);
2994 +                               EXT4_DIRSYNC_FL|EXT4_BARRIER_FL|
2995 +                               EXT4_COW_FL);
2996 +
2997 +               if (vfs_fl & S_IMMUTABLE)
2998 +                       new_fl |= EXT4_IMMUTABLE_FL;
2999 +               if (vfs_fl & S_IXUNLINK)
3000 +                       new_fl |= EXT4_IXUNLINK_FL;
3001 +
3002                 if (vfs_fl & S_SYNC)
3003                         new_fl |= EXT4_SYNC_FL;
3004                 if (vfs_fl & S_APPEND)
3005                         new_fl |= EXT4_APPEND_FL;
3006 -               if (vfs_fl & S_IMMUTABLE)
3007 -                       new_fl |= EXT4_IMMUTABLE_FL;
3008                 if (vfs_fl & S_NOATIME)
3009                         new_fl |= EXT4_NOATIME_FL;
3010                 if (vfs_fl & S_DIRSYNC)
3011                         new_fl |= EXT4_DIRSYNC_FL;
3012 +
3013 +               if (vfs_vf & V_BARRIER)
3014 +                       new_fl |= EXT4_BARRIER_FL;
3015 +               if (vfs_vf & V_COW)
3016 +                       new_fl |= EXT4_COW_FL;
3017         } while (cmpxchg(&ei->i_flags, old_fl, new_fl) != old_fl);
3018  }
3019  
3020 @@ -4184,8 +4208,10 @@ struct inode *ext4_iget(struct super_blo
3021                 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3022                 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3023         }
3024 -       i_uid_write(inode, i_uid);
3025 -       i_gid_write(inode, i_gid);
3026 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
3027 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
3028 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
3029 +               le16_to_cpu(raw_inode->i_raw_tag)));
3030         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
3031  
3032         ext4_clear_state_flags(ei);     /* Only relevant on 32-bit archs */
3033 @@ -4413,8 +4439,10 @@ static int ext4_do_update_inode(handle_t
3034  
3035         ext4_get_inode_flags(ei);
3036         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3037 -       i_uid = i_uid_read(inode);
3038 -       i_gid = i_gid_read(inode);
3039 +       i_uid = from_kuid(&init_user_ns,
3040 +               TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag));
3041 +       i_gid = from_kgid(&init_user_ns,
3042 +               TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag));
3043         if (!(test_opt(inode->i_sb, NO_UID32))) {
3044                 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(i_uid));
3045                 raw_inode->i_gid_low = cpu_to_le16(low_16_bits(i_gid));
3046 @@ -4437,6 +4465,9 @@ static int ext4_do_update_inode(handle_t
3047                 raw_inode->i_uid_high = 0;
3048                 raw_inode->i_gid_high = 0;
3049         }
3050 +#ifdef CONFIG_TAGGING_INTERN
3051 +       raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
3052 +#endif
3053         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3054  
3055         EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
3056 @@ -4667,7 +4698,8 @@ int ext4_setattr(struct dentry *dentry,
3057         if (is_quota_modification(inode, attr))
3058                 dquot_initialize(inode);
3059         if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) ||
3060 -           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) {
3061 +           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid)) ||
3062 +           (ia_valid & ATTR_TAG && !tag_eq(attr->ia_tag, inode->i_tag))) {
3063                 handle_t *handle;
3064  
3065                 /* (user+group)*(old+new) structure, inode write (sb,
3066 @@ -4690,6 +4722,8 @@ int ext4_setattr(struct dentry *dentry,
3067                         inode->i_uid = attr->ia_uid;
3068                 if (attr->ia_valid & ATTR_GID)
3069                         inode->i_gid = attr->ia_gid;
3070 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3071 +                       inode->i_tag = attr->ia_tag;
3072                 error = ext4_mark_inode_dirty(handle, inode);
3073                 ext4_journal_stop(handle);
3074         }
3075 diff -NurpP --minimal linux-3.10.33/fs/ext4/ioctl.c linux-3.10.33-vs2.3.6.8/fs/ext4/ioctl.c
3076 --- linux-3.10.33/fs/ext4/ioctl.c       2014-03-12 13:16:02.000000000 +0000
3077 +++ linux-3.10.33-vs2.3.6.8/fs/ext4/ioctl.c     2014-03-12 13:18:32.000000000 +0000
3078 @@ -14,6 +14,7 @@
3079  #include <linux/compat.h>
3080  #include <linux/mount.h>
3081  #include <linux/file.h>
3082 +#include <linux/vs_tag.h>
3083  #include <asm/uaccess.h>
3084  #include "ext4_jbd2.h"
3085  #include "ext4.h"
3086 @@ -215,6 +216,33 @@ swap_boot_out:
3087         return err;
3088  }
3089  
3090 +int ext4_sync_flags(struct inode *inode, int flags, int vflags)
3091 +{
3092 +       handle_t *handle = NULL;
3093 +       struct ext4_iloc iloc;
3094 +       int err;
3095 +
3096 +       handle = ext4_journal_start(inode, EXT4_HT_INODE, 1);
3097 +       if (IS_ERR(handle))
3098 +               return PTR_ERR(handle);
3099 +
3100 +       if (IS_SYNC(inode))
3101 +               ext4_handle_sync(handle);
3102 +       err = ext4_reserve_inode_write(handle, inode, &iloc);
3103 +       if (err)
3104 +               goto flags_err;
3105 +
3106 +       inode->i_flags = flags;
3107 +       inode->i_vflags = vflags;
3108 +       ext4_get_inode_flags(EXT4_I(inode));
3109 +       inode->i_ctime = ext4_current_time(inode);
3110 +
3111 +       err = ext4_mark_iloc_dirty(handle, inode, &iloc);
3112 +flags_err:
3113 +       ext4_journal_stop(handle);
3114 +       return err;
3115 +}
3116 +
3117  long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3118  {
3119         struct inode *inode = file_inode(filp);
3120 @@ -248,6 +276,11 @@ long ext4_ioctl(struct file *filp, unsig
3121  
3122                 flags = ext4_mask_flags(inode->i_mode, flags);
3123  
3124 +               if (IS_BARRIER(inode)) {
3125 +                       vxwprintk_task(1, "messing with the barrier.");
3126 +                       return -EACCES;
3127 +               }
3128 +
3129                 err = -EPERM;
3130                 mutex_lock(&inode->i_mutex);
3131                 /* Is it quota file? Do not allow user to mess with it */
3132 @@ -265,7 +298,9 @@ long ext4_ioctl(struct file *filp, unsig
3133                  *
3134                  * This test looks nicer. Thanks to Pauline Middelink
3135                  */
3136 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
3137 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
3138 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
3139 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
3140                         if (!capable(CAP_LINUX_IMMUTABLE))
3141                                 goto flags_out;
3142                 }
3143 diff -NurpP --minimal linux-3.10.33/fs/ext4/namei.c linux-3.10.33-vs2.3.6.8/fs/ext4/namei.c
3144 --- linux-3.10.33/fs/ext4/namei.c       2014-03-12 13:16:02.000000000 +0000
3145 +++ linux-3.10.33-vs2.3.6.8/fs/ext4/namei.c     2013-11-13 17:17:16.000000000 +0000
3146 @@ -34,6 +34,7 @@
3147  #include <linux/quotaops.h>
3148  #include <linux/buffer_head.h>
3149  #include <linux/bio.h>
3150 +#include <linux/vs_tag.h>
3151  #include "ext4.h"
3152  #include "ext4_jbd2.h"
3153  
3154 @@ -1299,6 +1300,7 @@ restart:
3155                                         ll_rw_block(READ | REQ_META | REQ_PRIO,
3156                                                     1, &bh);
3157                         }
3158 +               dx_propagate_tag(nd, inode);
3159                 }
3160                 if ((bh = bh_use[ra_ptr++]) == NULL)
3161                         goto next;
3162 @@ -3177,6 +3179,7 @@ const struct inode_operations ext4_dir_i
3163         .removexattr    = generic_removexattr,
3164         .get_acl        = ext4_get_acl,
3165         .fiemap         = ext4_fiemap,
3166 +       .sync_flags     = ext4_sync_flags,
3167  };
3168  
3169  const struct inode_operations ext4_special_inode_operations = {
3170 diff -NurpP --minimal linux-3.10.33/fs/ext4/super.c linux-3.10.33-vs2.3.6.8/fs/ext4/super.c
3171 --- linux-3.10.33/fs/ext4/super.c       2014-03-12 13:16:02.000000000 +0000
3172 +++ linux-3.10.33-vs2.3.6.8/fs/ext4/super.c     2014-03-12 13:18:32.000000000 +0000
3173 @@ -1129,7 +1129,7 @@ enum {
3174         Opt_inode_readahead_blks, Opt_journal_ioprio,
3175         Opt_dioread_nolock, Opt_dioread_lock,
3176         Opt_discard, Opt_nodiscard, Opt_init_itable, Opt_noinit_itable,
3177 -       Opt_max_dir_size_kb,
3178 +       Opt_max_dir_size_kb, Opt_tag, Opt_notag, Opt_tagid
3179  };
3180  
3181  static const match_table_t tokens = {
3182 @@ -1209,6 +1209,9 @@ static const match_table_t tokens = {
3183         {Opt_removed, "reservation"},   /* mount option from ext2/3 */
3184         {Opt_removed, "noreservation"}, /* mount option from ext2/3 */
3185         {Opt_removed, "journal=%u"},    /* mount option from ext2/3 */
3186 +       {Opt_tag, "tag"},
3187 +       {Opt_notag, "notag"},
3188 +       {Opt_tagid, "tagid=%u"},
3189         {Opt_err, NULL},
3190  };
3191  
3192 @@ -1439,6 +1442,20 @@ static int handle_mount_opt(struct super
3193         case Opt_i_version:
3194                 sb->s_flags |= MS_I_VERSION;
3195                 return 1;
3196 +#ifndef CONFIG_TAGGING_NONE
3197 +       case Opt_tag:
3198 +               set_opt(sb, TAGGED);
3199 +               return 1;
3200 +       case Opt_notag:
3201 +               clear_opt(sb, TAGGED);
3202 +               return 1;
3203 +#endif
3204 +#ifdef CONFIG_PROPAGATE
3205 +       case Opt_tagid:
3206 +               /* use args[0] */
3207 +               set_opt(sb, TAGGED);
3208 +               return 1;
3209 +#endif
3210         }
3211  
3212         for (m = ext4_mount_opts; m->token != Opt_err; m++)
3213 @@ -3461,6 +3478,9 @@ static int ext4_fill_super(struct super_
3214                         clear_opt(sb, DELALLOC);
3215         }
3216  
3217 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
3218 +               sb->s_flags |= MS_TAGGED;
3219 +
3220         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3221                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3222  
3223 @@ -4679,6 +4699,14 @@ static int ext4_remount(struct super_blo
3224         if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
3225                 ext4_abort(sb, "Abort forced by user");
3226  
3227 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
3228 +               !(sb->s_flags & MS_TAGGED)) {
3229 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
3230 +                       sb->s_id);
3231 +               err = -EINVAL;
3232 +               goto restore_opts;
3233 +       }
3234 +
3235         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3236                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3237  
3238 diff -NurpP --minimal linux-3.10.33/fs/fcntl.c linux-3.10.33-vs2.3.6.8/fs/fcntl.c
3239 --- linux-3.10.33/fs/fcntl.c    2013-05-31 13:45:23.000000000 +0000
3240 +++ linux-3.10.33-vs2.3.6.8/fs/fcntl.c  2013-08-22 20:29:59.000000000 +0000
3241 @@ -21,6 +21,7 @@
3242  #include <linux/rcupdate.h>
3243  #include <linux/pid_namespace.h>
3244  #include <linux/user_namespace.h>
3245 +#include <linux/vs_limit.h>
3246  
3247  #include <asm/poll.h>
3248  #include <asm/siginfo.h>
3249 @@ -378,6 +379,8 @@ SYSCALL_DEFINE3(fcntl64, unsigned int, f
3250  
3251         if (!f.file)
3252                 goto out;
3253 +       if (!vx_files_avail(1))
3254 +               goto out;
3255  
3256         if (unlikely(f.file->f_mode & FMODE_PATH)) {
3257                 if (!check_fcntl_cmd(cmd))
3258 diff -NurpP --minimal linux-3.10.33/fs/file.c linux-3.10.33-vs2.3.6.8/fs/file.c
3259 --- linux-3.10.33/fs/file.c     2014-03-12 13:16:02.000000000 +0000
3260 +++ linux-3.10.33-vs2.3.6.8/fs/file.c   2014-03-12 13:18:23.000000000 +0000
3261 @@ -22,6 +22,7 @@
3262  #include <linux/spinlock.h>
3263  #include <linux/rcupdate.h>
3264  #include <linux/workqueue.h>
3265 +#include <linux/vs_limit.h>
3266  
3267  int sysctl_nr_open __read_mostly = 1024*1024;
3268  int sysctl_nr_open_min = BITS_PER_LONG;
3269 @@ -311,6 +312,8 @@ struct files_struct *dup_fd(struct files
3270                 struct file *f = *old_fds++;
3271                 if (f) {
3272                         get_file(f);
3273 +                       /* TODO: sum it first for check and performance */
3274 +                       vx_openfd_inc(open_files - i);
3275                 } else {
3276                         /*
3277                          * The fd may be claimed in the fd bitmap but not yet
3278 @@ -376,9 +379,11 @@ static void close_files(struct files_str
3279                                         filp_close(file, files);
3280                                         cond_resched();
3281                                 }
3282 +                               vx_openfd_dec(i);
3283                         }
3284                         i++;
3285                         set >>= 1;
3286 +                       cond_resched();
3287                 }
3288         }
3289  }
3290 @@ -503,6 +508,7 @@ repeat:
3291         else
3292                 __clear_close_on_exec(fd, fdt);
3293         error = fd;
3294 +       vx_openfd_inc(fd);
3295  #if 1
3296         /* Sanity check */
3297         if (rcu_dereference_raw(fdt->fd[fd]) != NULL) {
3298 @@ -533,6 +539,7 @@ static void __put_unused_fd(struct files
3299         __clear_open_fd(fd, fdt);
3300         if (fd < files->next_fd)
3301                 files->next_fd = fd;
3302 +       vx_openfd_dec(fd);
3303  }
3304  
3305  void put_unused_fd(unsigned int fd)
3306 @@ -812,6 +819,8 @@ static int do_dup2(struct files_struct *
3307  
3308         if (tofree)
3309                 filp_close(tofree, files);
3310 +       else
3311 +               vx_openfd_inc(fd);      /* fd was unused */
3312  
3313         return fd;
3314  
3315 diff -NurpP --minimal linux-3.10.33/fs/file_table.c linux-3.10.33-vs2.3.6.8/fs/file_table.c
3316 --- linux-3.10.33/fs/file_table.c       2013-07-14 17:01:28.000000000 +0000
3317 +++ linux-3.10.33-vs2.3.6.8/fs/file_table.c     2013-08-22 20:29:59.000000000 +0000
3318 @@ -26,6 +26,8 @@
3319  #include <linux/hardirq.h>
3320  #include <linux/task_work.h>
3321  #include <linux/ima.h>
3322 +#include <linux/vs_limit.h>
3323 +#include <linux/vs_context.h>
3324  
3325  #include <linux/atomic.h>
3326  
3327 @@ -140,6 +142,8 @@ struct file *get_empty_filp(void)
3328         spin_lock_init(&f->f_lock);
3329         eventpoll_init_file(f);
3330         /* f->f_version: 0 */
3331 +       f->f_xid = vx_current_xid();
3332 +       vx_files_inc(f);
3333         return f;
3334  
3335  over:
3336 @@ -257,6 +261,8 @@ static void __fput(struct file *file)
3337                 i_readcount_dec(inode);
3338         if (file->f_mode & FMODE_WRITE)
3339                 drop_file_write_access(file);
3340 +       vx_files_dec(file);
3341 +       file->f_xid = 0;
3342         file->f_path.dentry = NULL;
3343         file->f_path.mnt = NULL;
3344         file->f_inode = NULL;
3345 @@ -345,6 +351,8 @@ void put_filp(struct file *file)
3346  {
3347         if (atomic_long_dec_and_test(&file->f_count)) {
3348                 security_file_free(file);
3349 +               vx_files_dec(file);
3350 +               file->f_xid = 0;
3351                 file_sb_list_del(file);
3352                 file_free(file);
3353         }
3354 diff -NurpP --minimal linux-3.10.33/fs/fs_struct.c linux-3.10.33-vs2.3.6.8/fs/fs_struct.c
3355 --- linux-3.10.33/fs/fs_struct.c        2013-05-31 13:45:23.000000000 +0000
3356 +++ linux-3.10.33-vs2.3.6.8/fs/fs_struct.c      2013-08-22 20:29:59.000000000 +0000
3357 @@ -4,6 +4,7 @@
3358  #include <linux/path.h>
3359  #include <linux/slab.h>
3360  #include <linux/fs_struct.h>
3361 +#include <linux/vserver/global.h>
3362  #include "internal.h"
3363  
3364  /*
3365 @@ -87,6 +88,7 @@ void free_fs_struct(struct fs_struct *fs
3366  {
3367         path_put(&fs->root);
3368         path_put(&fs->pwd);
3369 +       atomic_dec(&vs_global_fs);
3370         kmem_cache_free(fs_cachep, fs);
3371  }
3372  
3373 @@ -124,6 +126,7 @@ struct fs_struct *copy_fs_struct(struct
3374                 fs->pwd = old->pwd;
3375                 path_get(&fs->pwd);
3376                 spin_unlock(&old->lock);
3377 +               atomic_inc(&vs_global_fs);
3378         }
3379         return fs;
3380  }
3381 diff -NurpP --minimal linux-3.10.33/fs/gfs2/file.c linux-3.10.33-vs2.3.6.8/fs/gfs2/file.c
3382 --- linux-3.10.33/fs/gfs2/file.c        2013-07-14 17:01:28.000000000 +0000
3383 +++ linux-3.10.33-vs2.3.6.8/fs/gfs2/file.c      2013-08-22 20:29:59.000000000 +0000
3384 @@ -144,6 +144,9 @@ static const u32 fsflags_to_gfs2[32] = {
3385         [12] = GFS2_DIF_EXHASH,
3386         [14] = GFS2_DIF_INHERIT_JDATA,
3387         [17] = GFS2_DIF_TOPDIR,
3388 +       [27] = GFS2_DIF_IXUNLINK,
3389 +       [26] = GFS2_DIF_BARRIER,
3390 +       [29] = GFS2_DIF_COW,
3391  };
3392  
3393  static const u32 gfs2_to_fsflags[32] = {
3394 @@ -154,6 +157,9 @@ static const u32 gfs2_to_fsflags[32] = {
3395         [gfs2fl_ExHash] = FS_INDEX_FL,
3396         [gfs2fl_TopLevel] = FS_TOPDIR_FL,
3397         [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL,
3398 +       [gfs2fl_IXUnlink] = FS_IXUNLINK_FL,
3399 +       [gfs2fl_Barrier] = FS_BARRIER_FL,
3400 +       [gfs2fl_Cow] = FS_COW_FL,
3401  };
3402  
3403  static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
3404 @@ -184,12 +190,18 @@ void gfs2_set_inode_flags(struct inode *
3405  {
3406         struct gfs2_inode *ip = GFS2_I(inode);
3407         unsigned int flags = inode->i_flags;
3408 +       unsigned int vflags = inode->i_vflags;
3409 +
3410 +       flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3411 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC | S_NOSEC);
3412  
3413 -       flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC|S_NOSEC);
3414         if ((ip->i_eattr == 0) && !is_sxid(inode->i_mode))
3415                 inode->i_flags |= S_NOSEC;
3416         if (ip->i_diskflags & GFS2_DIF_IMMUTABLE)
3417                 flags |= S_IMMUTABLE;
3418 +       if (ip->i_diskflags & GFS2_DIF_IXUNLINK)
3419 +               flags |= S_IXUNLINK;
3420 +
3421         if (ip->i_diskflags & GFS2_DIF_APPENDONLY)
3422                 flags |= S_APPEND;
3423         if (ip->i_diskflags & GFS2_DIF_NOATIME)
3424 @@ -197,6 +209,43 @@ void gfs2_set_inode_flags(struct inode *
3425         if (ip->i_diskflags & GFS2_DIF_SYNC)
3426                 flags |= S_SYNC;
3427         inode->i_flags = flags;
3428 +
3429 +       vflags &= ~(V_BARRIER | V_COW);
3430 +
3431 +       if (ip->i_diskflags & GFS2_DIF_BARRIER)
3432 +               vflags |= V_BARRIER;
3433 +       if (ip->i_diskflags & GFS2_DIF_COW)
3434 +               vflags |= V_COW;
3435 +       inode->i_vflags = vflags;
3436 +}
3437 +
3438 +void gfs2_get_inode_flags(struct inode *inode)
3439 +{
3440 +       struct gfs2_inode *ip = GFS2_I(inode);
3441 +       unsigned int flags = inode->i_flags;
3442 +       unsigned int vflags = inode->i_vflags;
3443 +
3444 +       ip->i_diskflags &= ~(GFS2_DIF_APPENDONLY |
3445 +                       GFS2_DIF_NOATIME | GFS2_DIF_SYNC |
3446 +                       GFS2_DIF_IMMUTABLE | GFS2_DIF_IXUNLINK |
3447 +                       GFS2_DIF_BARRIER | GFS2_DIF_COW);
3448 +
3449 +       if (flags & S_IMMUTABLE)
3450 +               ip->i_diskflags |= GFS2_DIF_IMMUTABLE;
3451 +       if (flags & S_IXUNLINK)
3452 +               ip->i_diskflags |= GFS2_DIF_IXUNLINK;
3453 +
3454 +       if (flags & S_APPEND)
3455 +               ip->i_diskflags |= GFS2_DIF_APPENDONLY;
3456 +       if (flags & S_NOATIME)
3457 +               ip->i_diskflags |= GFS2_DIF_NOATIME;
3458 +       if (flags & S_SYNC)
3459 +               ip->i_diskflags |= GFS2_DIF_SYNC;
3460 +
3461 +       if (vflags & V_BARRIER)
3462 +               ip->i_diskflags |= GFS2_DIF_BARRIER;
3463 +       if (vflags & V_COW)
3464 +               ip->i_diskflags |= GFS2_DIF_COW;
3465  }
3466  
3467  /* Flags that can be set by user space */
3468 @@ -310,6 +359,37 @@ static int gfs2_set_flags(struct file *f
3469         return do_gfs2_set_flags(filp, gfsflags, ~GFS2_DIF_JDATA);
3470  }
3471  
3472 +int gfs2_sync_flags(struct inode *inode, int flags, int vflags)
3473 +{
3474 +       struct gfs2_inode *ip = GFS2_I(inode);
3475 +       struct gfs2_sbd *sdp = GFS2_SB(inode);
3476 +       struct buffer_head *bh;
3477 +       struct gfs2_holder gh;
3478 +       int error;
3479 +
3480 +       error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
3481 +       if (error)
3482 +               return error;
3483 +       error = gfs2_trans_begin(sdp, RES_DINODE, 0);
3484 +       if (error)
3485 +               goto out;
3486 +       error = gfs2_meta_inode_buffer(ip, &bh);
3487 +       if (error)
3488 +               goto out_trans_end;
3489 +       gfs2_trans_add_meta(ip->i_gl, bh);
3490 +       inode->i_flags = flags;
3491 +       inode->i_vflags = vflags;
3492 +       gfs2_get_inode_flags(inode);
3493 +       gfs2_dinode_out(ip, bh->b_data);
3494 +       brelse(bh);
3495 +       gfs2_set_aops(inode);
3496 +out_trans_end:
3497 +       gfs2_trans_end(sdp);
3498 +out:
3499 +       gfs2_glock_dq_uninit(&gh);
3500 +       return error;
3501 +}
3502 +
3503  static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3504  {
3505         switch(cmd) {
3506 diff -NurpP --minimal linux-3.10.33/fs/gfs2/inode.h linux-3.10.33-vs2.3.6.8/fs/gfs2/inode.h
3507 --- linux-3.10.33/fs/gfs2/inode.h       2012-12-11 03:30:57.000000000 +0000
3508 +++ linux-3.10.33-vs2.3.6.8/fs/gfs2/inode.h     2013-08-22 20:29:59.000000000 +0000
3509 @@ -117,6 +117,7 @@ extern const struct file_operations gfs2
3510  extern const struct file_operations gfs2_dir_fops_nolock;
3511  
3512  extern void gfs2_set_inode_flags(struct inode *inode);
3513 +extern int gfs2_sync_flags(struct inode *inode, int flags, int vflags);
3514   
3515  #ifdef CONFIG_GFS2_FS_LOCKING_DLM
3516  extern const struct file_operations gfs2_file_fops;
3517 diff -NurpP --minimal linux-3.10.33/fs/hostfs/hostfs.h linux-3.10.33-vs2.3.6.8/fs/hostfs/hostfs.h
3518 --- linux-3.10.33/fs/hostfs/hostfs.h    2012-12-11 03:30:57.000000000 +0000
3519 +++ linux-3.10.33-vs2.3.6.8/fs/hostfs/hostfs.h  2013-08-22 20:29:59.000000000 +0000
3520 @@ -42,6 +42,7 @@ struct hostfs_iattr {
3521         unsigned short  ia_mode;
3522         uid_t           ia_uid;
3523         gid_t           ia_gid;
3524 +       vtag_t          ia_tag;
3525         loff_t          ia_size;
3526         struct timespec ia_atime;
3527         struct timespec ia_mtime;
3528 diff -NurpP --minimal linux-3.10.33/fs/inode.c linux-3.10.33-vs2.3.6.8/fs/inode.c
3529 --- linux-3.10.33/fs/inode.c    2013-07-14 17:01:28.000000000 +0000
3530 +++ linux-3.10.33-vs2.3.6.8/fs/inode.c  2013-08-22 20:29:59.000000000 +0000
3531 @@ -17,6 +17,7 @@
3532  #include <linux/prefetch.h>
3533  #include <linux/buffer_head.h> /* for inode_has_buffers */
3534  #include <linux/ratelimit.h>
3535 +#include <linux/vs_tag.h>
3536  #include "internal.h"
3537  
3538  /*
3539 @@ -128,6 +129,8 @@ int inode_init_always(struct super_block
3540         struct address_space *const mapping = &inode->i_data;
3541  
3542         inode->i_sb = sb;
3543 +
3544 +       /* essential because of inode slab reuse */
3545         inode->i_blkbits = sb->s_blocksize_bits;
3546         inode->i_flags = 0;
3547         atomic_set(&inode->i_count, 1);
3548 @@ -137,6 +140,7 @@ int inode_init_always(struct super_block
3549         inode->i_opflags = 0;
3550         i_uid_write(inode, 0);
3551         i_gid_write(inode, 0);
3552 +       i_tag_write(inode, 0);
3553         atomic_set(&inode->i_writecount, 0);
3554         inode->i_size = 0;
3555         inode->i_blocks = 0;
3556 @@ -149,6 +153,7 @@ int inode_init_always(struct super_block
3557         inode->i_bdev = NULL;
3558         inode->i_cdev = NULL;
3559         inode->i_rdev = 0;
3560 +       inode->i_mdev = 0;
3561         inode->dirtied_when = 0;
3562  
3563         if (security_inode_alloc(inode))
3564 @@ -483,6 +488,8 @@ void __insert_inode_hash(struct inode *i
3565  }
3566  EXPORT_SYMBOL(__insert_inode_hash);
3567  
3568 +EXPORT_SYMBOL_GPL(__iget);
3569 +
3570  /**
3571   *     __remove_inode_hash - remove an inode from the hash
3572   *     @inode: inode to unhash
3573 @@ -1799,9 +1806,11 @@ void init_special_inode(struct inode *in
3574         if (S_ISCHR(mode)) {
3575                 inode->i_fop = &def_chr_fops;
3576                 inode->i_rdev = rdev;
3577 +               inode->i_mdev = rdev;
3578         } else if (S_ISBLK(mode)) {
3579                 inode->i_fop = &def_blk_fops;
3580                 inode->i_rdev = rdev;
3581 +               inode->i_mdev = rdev;
3582         } else if (S_ISFIFO(mode))
3583                 inode->i_fop = &pipefifo_fops;
3584         else if (S_ISSOCK(mode))
3585 @@ -1830,6 +1839,7 @@ void inode_init_owner(struct inode *inod
3586         } else
3587                 inode->i_gid = current_fsgid();
3588         inode->i_mode = mode;
3589 +       i_tag_write(inode, dx_current_fstag(inode->i_sb));
3590  }
3591  EXPORT_SYMBOL(inode_init_owner);
3592  
3593 diff -NurpP --minimal linux-3.10.33/fs/ioctl.c linux-3.10.33-vs2.3.6.8/fs/ioctl.c
3594 --- linux-3.10.33/fs/ioctl.c    2013-05-31 13:45:24.000000000 +0000
3595 +++ linux-3.10.33-vs2.3.6.8/fs/ioctl.c  2013-08-22 20:29:59.000000000 +0000
3596 @@ -15,6 +15,9 @@
3597  #include <linux/writeback.h>
3598  #include <linux/buffer_head.h>
3599  #include <linux/falloc.h>
3600 +#include <linux/proc_fs.h>
3601 +#include <linux/vserver/inode.h>
3602 +#include <linux/vs_tag.h>
3603  
3604  #include <asm/ioctls.h>
3605  
3606 diff -NurpP --minimal linux-3.10.33/fs/ioprio.c linux-3.10.33-vs2.3.6.8/fs/ioprio.c
3607 --- linux-3.10.33/fs/ioprio.c   2012-12-11 03:30:57.000000000 +0000
3608 +++ linux-3.10.33-vs2.3.6.8/fs/ioprio.c 2013-08-22 20:29:59.000000000 +0000
3609 @@ -28,6 +28,7 @@
3610  #include <linux/syscalls.h>
3611  #include <linux/security.h>
3612  #include <linux/pid_namespace.h>
3613 +#include <linux/vs_base.h>
3614  
3615  int set_task_ioprio(struct task_struct *task, int ioprio)
3616  {
3617 @@ -105,6 +106,8 @@ SYSCALL_DEFINE3(ioprio_set, int, which,
3618                         else
3619                                 pgrp = find_vpid(who);
3620                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3621 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3622 +                                       continue;
3623                                 ret = set_task_ioprio(p, ioprio);
3624                                 if (ret)
3625                                         break;
3626 @@ -198,6 +201,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which,
3627                         else
3628                                 pgrp = find_vpid(who);
3629                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3630 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3631 +                                       continue;
3632                                 tmpio = get_task_ioprio(p);
3633                                 if (tmpio < 0)
3634                                         continue;
3635 diff -NurpP --minimal linux-3.10.33/fs/jfs/file.c linux-3.10.33-vs2.3.6.8/fs/jfs/file.c
3636 --- linux-3.10.33/fs/jfs/file.c 2013-02-19 13:58:48.000000000 +0000
3637 +++ linux-3.10.33-vs2.3.6.8/fs/jfs/file.c       2013-08-22 20:29:59.000000000 +0000
3638 @@ -109,7 +109,8 @@ int jfs_setattr(struct dentry *dentry, s
3639         if (is_quota_modification(inode, iattr))
3640                 dquot_initialize(inode);
3641         if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
3642 -           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
3643 +           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid)) ||
3644 +           (iattr->ia_valid & ATTR_TAG && !tag_eq(iattr->ia_tag, inode->i_tag))) {
3645                 rc = dquot_transfer(inode, iattr);
3646                 if (rc)
3647                         return rc;
3648 @@ -144,6 +145,7 @@ const struct inode_operations jfs_file_i
3649  #ifdef CONFIG_JFS_POSIX_ACL
3650         .get_acl        = jfs_get_acl,
3651  #endif
3652 +       .sync_flags     = jfs_sync_flags,
3653  };
3654  
3655  const struct file_operations jfs_file_operations = {
3656 diff -NurpP --minimal linux-3.10.33/fs/jfs/ioctl.c linux-3.10.33-vs2.3.6.8/fs/jfs/ioctl.c
3657 --- linux-3.10.33/fs/jfs/ioctl.c        2013-05-31 13:45:24.000000000 +0000
3658 +++ linux-3.10.33-vs2.3.6.8/fs/jfs/ioctl.c      2013-08-22 20:29:59.000000000 +0000
3659 @@ -12,6 +12,7 @@
3660  #include <linux/time.h>
3661  #include <linux/sched.h>
3662  #include <linux/blkdev.h>
3663 +#include <linux/mount.h>
3664  #include <asm/current.h>
3665  #include <asm/uaccess.h>
3666  
3667 @@ -56,6 +57,16 @@ static long jfs_map_ext2(unsigned long f
3668  }
3669  
3670  
3671 +int jfs_sync_flags(struct inode *inode, int flags, int vflags)
3672 +{
3673 +       inode->i_flags = flags;
3674 +       inode->i_vflags = vflags;
3675 +       jfs_get_inode_flags(JFS_IP(inode));
3676 +       inode->i_ctime = CURRENT_TIME_SEC;
3677 +       mark_inode_dirty(inode);
3678 +       return 0;
3679 +}
3680 +
3681  long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3682  {
3683         struct inode *inode = file_inode(filp);
3684 @@ -89,6 +100,11 @@ long jfs_ioctl(struct file *filp, unsign
3685                 if (!S_ISDIR(inode->i_mode))
3686                         flags &= ~JFS_DIRSYNC_FL;
3687  
3688 +               if (IS_BARRIER(inode)) {
3689 +                       vxwprintk_task(1, "messing with the barrier.");
3690 +                       return -EACCES;
3691 +               }
3692 +
3693                 /* Is it quota file? Do not allow user to mess with it */
3694                 if (IS_NOQUOTA(inode)) {
3695                         err = -EPERM;
3696 @@ -106,8 +122,8 @@ long jfs_ioctl(struct file *filp, unsign
3697                  * the relevant capability.
3698                  */
3699                 if ((oldflags & JFS_IMMUTABLE_FL) ||
3700 -                       ((flags ^ oldflags) &
3701 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
3702 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
3703 +                       JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
3704                         if (!capable(CAP_LINUX_IMMUTABLE)) {
3705                                 mutex_unlock(&inode->i_mutex);
3706                                 err = -EPERM;
3707 @@ -115,7 +131,7 @@ long jfs_ioctl(struct file *filp, unsign
3708                         }
3709                 }
3710  
3711 -               flags = flags & JFS_FL_USER_MODIFIABLE;
3712 +               flags &= JFS_FL_USER_MODIFIABLE;
3713                 flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
3714                 jfs_inode->mode2 = flags;
3715  
3716 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
3717 --- linux-3.10.33/fs/jfs/jfs_dinode.h   2012-12-11 03:30:57.000000000 +0000
3718 +++ linux-3.10.33-vs2.3.6.8/fs/jfs/jfs_dinode.h 2013-08-22 20:29:59.000000000 +0000
3719 @@ -161,9 +161,13 @@ struct dinode {
3720  
3721  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
3722  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
3723 +#define JFS_IXUNLINK_FL                0x08000000 /* Immutable invert on unlink */
3724  
3725 -#define JFS_FL_USER_VISIBLE    0x03F80000
3726 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
3727 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
3728 +#define JFS_COW_FL             0x20000000 /* Copy on Write marker */
3729 +
3730 +#define JFS_FL_USER_VISIBLE    0x07F80000
3731 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
3732  #define JFS_FL_INHERIT         0x03C80000
3733  
3734  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
3735 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
3736 --- linux-3.10.33/fs/jfs/jfs_filsys.h   2012-12-11 03:30:57.000000000 +0000
3737 +++ linux-3.10.33-vs2.3.6.8/fs/jfs/jfs_filsys.h 2013-08-22 20:29:59.000000000 +0000
3738 @@ -266,6 +266,7 @@
3739  #define JFS_NAME_MAX   255
3740  #define JFS_PATH_MAX   BPSIZE
3741  
3742 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
3743  
3744  /*
3745   *     file system state (superblock state)
3746 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
3747 --- linux-3.10.33/fs/jfs/jfs_imap.c     2013-07-14 17:01:28.000000000 +0000
3748 +++ linux-3.10.33-vs2.3.6.8/fs/jfs/jfs_imap.c   2013-08-22 20:29:59.000000000 +0000
3749 @@ -46,6 +46,7 @@
3750  #include <linux/pagemap.h>
3751  #include <linux/quotaops.h>
3752  #include <linux/slab.h>
3753 +#include <linux/vs_tag.h>
3754  
3755  #include "jfs_incore.h"
3756  #include "jfs_inode.h"
3757 @@ -3058,6 +3059,8 @@ static int copy_from_dinode(struct dinod
3758  {
3759         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
3760         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
3761 +       kuid_t kuid;
3762 +       kgid_t kgid;
3763  
3764         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
3765         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
3766 @@ -3078,14 +3081,18 @@ static int copy_from_dinode(struct dinod
3767         }
3768         set_nlink(ip, le32_to_cpu(dip->di_nlink));
3769  
3770 -       jfs_ip->saved_uid = make_kuid(&init_user_ns, le32_to_cpu(dip->di_uid));
3771 +       kuid = make_kuid(&init_user_ns, le32_to_cpu(dip->di_uid));
3772 +       kgid = make_kgid(&init_user_ns, le32_to_cpu(dip->di_gid));
3773 +       ip->i_tag = INOTAG_KTAG(DX_TAG(ip), kuid, kgid, GLOBAL_ROOT_TAG);
3774 +
3775 +       jfs_ip->saved_uid = INOTAG_KUID(DX_TAG(ip), kuid, kgid);
3776         if (!uid_valid(sbi->uid))
3777                 ip->i_uid = jfs_ip->saved_uid;
3778         else {
3779                 ip->i_uid = sbi->uid;
3780         }
3781  
3782 -       jfs_ip->saved_gid = make_kgid(&init_user_ns, le32_to_cpu(dip->di_gid));
3783 +       jfs_ip->saved_gid = INOTAG_KGID(DX_TAG(ip), kuid, kgid);
3784         if (!gid_valid(sbi->gid))
3785                 ip->i_gid = jfs_ip->saved_gid;
3786         else {
3787 @@ -3150,16 +3157,14 @@ static void copy_to_dinode(struct dinode
3788         dip->di_size = cpu_to_le64(ip->i_size);
3789         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
3790         dip->di_nlink = cpu_to_le32(ip->i_nlink);
3791 -       if (!uid_valid(sbi->uid))
3792 -               dip->di_uid = cpu_to_le32(i_uid_read(ip));
3793 -       else
3794 -               dip->di_uid =cpu_to_le32(from_kuid(&init_user_ns,
3795 -                                                  jfs_ip->saved_uid));
3796 -       if (!gid_valid(sbi->gid))
3797 -               dip->di_gid = cpu_to_le32(i_gid_read(ip));
3798 -       else
3799 -               dip->di_gid = cpu_to_le32(from_kgid(&init_user_ns,
3800 -                                                   jfs_ip->saved_gid));
3801 +       dip->di_uid = cpu_to_le32(from_kuid(&init_user_ns,
3802 +               TAGINO_KUID(DX_TAG(ip),
3803 +               !uid_valid(sbi->uid) ? ip->i_uid : jfs_ip->saved_uid,
3804 +               ip->i_tag)));
3805 +       dip->di_gid = cpu_to_le32(from_kgid(&init_user_ns,
3806 +               TAGINO_KGID(DX_TAG(ip),
3807 +               !gid_valid(sbi->gid) ? ip->i_gid : jfs_ip->saved_gid,
3808 +               ip->i_tag)));
3809         jfs_get_inode_flags(jfs_ip);
3810         /*
3811          * mode2 is only needed for storing the higher order bits.
3812 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
3813 --- linux-3.10.33/fs/jfs/jfs_inode.c    2014-03-12 13:16:02.000000000 +0000
3814 +++ linux-3.10.33-vs2.3.6.8/fs/jfs/jfs_inode.c  2013-11-13 17:22:25.000000000 +0000
3815 @@ -18,6 +18,7 @@
3816  
3817  #include <linux/fs.h>
3818  #include <linux/quotaops.h>
3819 +#include <linux/vs_tag.h>
3820  #include "jfs_incore.h"
3821  #include "jfs_inode.h"
3822  #include "jfs_filsys.h"
3823 @@ -30,29 +31,46 @@ void jfs_set_inode_flags(struct inode *i
3824  {
3825         unsigned int flags = JFS_IP(inode)->mode2;
3826  
3827 -       inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
3828 -               S_NOATIME | S_DIRSYNC | S_SYNC);
3829 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3830 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3831  
3832         if (flags & JFS_IMMUTABLE_FL)
3833                 inode->i_flags |= S_IMMUTABLE;
3834 +       if (flags & JFS_IXUNLINK_FL)
3835 +               inode->i_flags |= S_IXUNLINK;
3836 +
3837 +       if (flags & JFS_SYNC_FL)
3838 +               inode->i_flags |= S_SYNC;
3839         if (flags & JFS_APPEND_FL)
3840                 inode->i_flags |= S_APPEND;
3841         if (flags & JFS_NOATIME_FL)
3842                 inode->i_flags |= S_NOATIME;
3843         if (flags & JFS_DIRSYNC_FL)
3844                 inode->i_flags |= S_DIRSYNC;
3845 -       if (flags & JFS_SYNC_FL)
3846 -               inode->i_flags |= S_SYNC;
3847 +
3848 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3849 +
3850 +       if (flags & JFS_BARRIER_FL)
3851 +               inode->i_vflags |= V_BARRIER;
3852 +       if (flags & JFS_COW_FL)
3853 +               inode->i_vflags |= V_COW;
3854  }
3855  
3856  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
3857  {
3858         unsigned int flags = jfs_ip->vfs_inode.i_flags;
3859 +       unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
3860 +
3861 +       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
3862 +                          JFS_APPEND_FL | JFS_NOATIME_FL |
3863 +                          JFS_DIRSYNC_FL | JFS_SYNC_FL |
3864 +                          JFS_BARRIER_FL | JFS_COW_FL);
3865  
3866 -       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
3867 -                          JFS_DIRSYNC_FL | JFS_SYNC_FL);
3868         if (flags & S_IMMUTABLE)
3869                 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
3870 +       if (flags & S_IXUNLINK)
3871 +               jfs_ip->mode2 |= JFS_IXUNLINK_FL;
3872 +
3873         if (flags & S_APPEND)
3874                 jfs_ip->mode2 |= JFS_APPEND_FL;
3875         if (flags & S_NOATIME)
3876 @@ -61,6 +79,11 @@ void jfs_get_inode_flags(struct jfs_inod
3877                 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
3878         if (flags & S_SYNC)
3879                 jfs_ip->mode2 |= JFS_SYNC_FL;
3880 +
3881 +       if (vflags & V_BARRIER)
3882 +               jfs_ip->mode2 |= JFS_BARRIER_FL;
3883 +       if (vflags & V_COW)
3884 +               jfs_ip->mode2 |= JFS_COW_FL;
3885  }
3886  
3887  /*
3888 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
3889 --- linux-3.10.33/fs/jfs/jfs_inode.h    2012-12-11 03:30:57.000000000 +0000
3890 +++ linux-3.10.33-vs2.3.6.8/fs/jfs/jfs_inode.h  2013-08-22 20:29:59.000000000 +0000
3891 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
3892  extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
3893         int fh_len, int fh_type);
3894  extern void jfs_set_inode_flags(struct inode *);
3895 +extern int jfs_sync_flags(struct inode *, int, int);
3896  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
3897  extern int jfs_setattr(struct dentry *, struct iattr *);
3898  
3899 diff -NurpP --minimal linux-3.10.33/fs/jfs/namei.c linux-3.10.33-vs2.3.6.8/fs/jfs/namei.c
3900 --- linux-3.10.33/fs/jfs/namei.c        2012-12-11 03:30:57.000000000 +0000
3901 +++ linux-3.10.33-vs2.3.6.8/fs/jfs/namei.c      2013-08-22 20:29:59.000000000 +0000
3902 @@ -22,6 +22,7 @@
3903  #include <linux/ctype.h>
3904  #include <linux/quotaops.h>
3905  #include <linux/exportfs.h>
3906 +#include <linux/vs_tag.h>
3907  #include "jfs_incore.h"
3908  #include "jfs_superblock.h"
3909  #include "jfs_inode.h"
3910 @@ -1461,6 +1462,7 @@ static struct dentry *jfs_lookup(struct
3911                         jfs_err("jfs_lookup: iget failed on inum %d", (uint)inum);
3912         }
3913  
3914 +       dx_propagate_tag(nd, ip);
3915         return d_splice_alias(ip, dentry);
3916  }
3917  
3918 @@ -1525,6 +1527,7 @@ const struct inode_operations jfs_dir_in
3919  #ifdef CONFIG_JFS_POSIX_ACL
3920         .get_acl        = jfs_get_acl,
3921  #endif
3922 +       .sync_flags     = jfs_sync_flags,
3923  };
3924  
3925  const struct file_operations jfs_dir_operations = {
3926 diff -NurpP --minimal linux-3.10.33/fs/jfs/super.c linux-3.10.33-vs2.3.6.8/fs/jfs/super.c
3927 --- linux-3.10.33/fs/jfs/super.c        2013-07-14 17:01:28.000000000 +0000
3928 +++ linux-3.10.33-vs2.3.6.8/fs/jfs/super.c      2013-08-22 20:29:59.000000000 +0000
3929 @@ -199,7 +199,8 @@ enum {
3930         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
3931         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
3932         Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
3933 -       Opt_discard, Opt_nodiscard, Opt_discard_minblk
3934 +       Opt_discard, Opt_nodiscard, Opt_discard_minblk,
3935 +       Opt_tag, Opt_notag, Opt_tagid
3936  };
3937  
3938  static const match_table_t tokens = {
3939 @@ -209,6 +210,10 @@ static const match_table_t tokens = {
3940         {Opt_resize, "resize=%u"},
3941         {Opt_resize_nosize, "resize"},
3942         {Opt_errors, "errors=%s"},
3943 +       {Opt_tag, "tag"},
3944 +       {Opt_notag, "notag"},
3945 +       {Opt_tagid, "tagid=%u"},
3946 +       {Opt_tag, "tagxid"},
3947         {Opt_ignore, "noquota"},
3948         {Opt_ignore, "quota"},
3949         {Opt_usrquota, "usrquota"},
3950 @@ -385,7 +390,20 @@ static int parse_options(char *options,
3951                         }
3952                         break;
3953                 }
3954 -
3955 +#ifndef CONFIG_TAGGING_NONE
3956 +               case Opt_tag:
3957 +                       *flag |= JFS_TAGGED;
3958 +                       break;
3959 +               case Opt_notag:
3960 +                       *flag &= JFS_TAGGED;
3961 +                       break;
3962 +#endif
3963 +#ifdef CONFIG_PROPAGATE
3964 +               case Opt_tagid:
3965 +                       /* use args[0] */
3966 +                       *flag |= JFS_TAGGED;
3967 +                       break;
3968 +#endif
3969                 default:
3970                         printk("jfs: Unrecognized mount option \"%s\" "
3971                                         " or missing value\n", p);
3972 @@ -417,6 +435,12 @@ static int jfs_remount(struct super_bloc
3973                 return -EINVAL;
3974         }
3975  
3976 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
3977 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
3978 +                       sb->s_id);
3979 +               return -EINVAL;
3980 +       }
3981 +
3982         if (newLVSize) {
3983                 if (sb->s_flags & MS_RDONLY) {
3984                         pr_err("JFS: resize requires volume" \
3985 @@ -502,6 +526,9 @@ static int jfs_fill_super(struct super_b
3986  #ifdef CONFIG_JFS_POSIX_ACL
3987         sb->s_flags |= MS_POSIXACL;
3988  #endif
3989 +       /* map mount option tagxid */
3990 +       if (sbi->flag & JFS_TAGGED)
3991 +               sb->s_flags |= MS_TAGGED;
3992  
3993         if (newLVSize) {
3994                 pr_err("resize option for remount only\n");
3995 diff -NurpP --minimal linux-3.10.33/fs/libfs.c linux-3.10.33-vs2.3.6.8/fs/libfs.c
3996 --- linux-3.10.33/fs/libfs.c    2013-02-19 13:58:48.000000000 +0000
3997 +++ linux-3.10.33-vs2.3.6.8/fs/libfs.c  2013-08-22 20:29:59.000000000 +0000
3998 @@ -135,7 +135,8 @@ static inline unsigned char dt_type(stru
3999   * both impossible due to the lock on directory.
4000   */
4001  
4002 -int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
4003 +static inline int do_dcache_readdir_filter(struct file *filp,
4004 +       void *dirent, filldir_t filldir, int (*filter)(struct dentry *dentry))
4005  {
4006         struct dentry *dentry = filp->f_path.dentry;
4007         struct dentry *cursor = filp->private_data;
4008 @@ -166,6 +167,8 @@ int dcache_readdir(struct file * filp, v
4009                         for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
4010                                 struct dentry *next;
4011                                 next = list_entry(p, struct dentry, d_u.d_child);
4012 +                               if (filter && !filter(next))
4013 +                                       continue;
4014                                 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
4015                                 if (!simple_positive(next)) {
4016                                         spin_unlock(&next->d_lock);
4017 @@ -192,6 +195,17 @@ int dcache_readdir(struct file * filp, v
4018         return 0;
4019  }
4020  
4021 +int dcache_readdir(struct file *filp, void *dirent, filldir_t filldir)
4022 +{
4023 +       return do_dcache_readdir_filter(filp, dirent, filldir, NULL);
4024 +}
4025 +
4026 +int dcache_readdir_filter(struct file *filp, void *dirent, filldir_t filldir,
4027 +       int (*filter)(struct dentry *))
4028 +{
4029 +       return do_dcache_readdir_filter(filp, dirent, filldir, filter);
4030 +}
4031 +
4032  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
4033  {
4034         return -EISDIR;
4035 @@ -981,6 +995,7 @@ EXPORT_SYMBOL(dcache_dir_close);
4036  EXPORT_SYMBOL(dcache_dir_lseek);
4037  EXPORT_SYMBOL(dcache_dir_open);
4038  EXPORT_SYMBOL(dcache_readdir);
4039 +EXPORT_SYMBOL(dcache_readdir_filter);
4040  EXPORT_SYMBOL(generic_read_dir);
4041  EXPORT_SYMBOL(mount_pseudo);
4042  EXPORT_SYMBOL(simple_write_begin);
4043 diff -NurpP --minimal linux-3.10.33/fs/locks.c linux-3.10.33-vs2.3.6.8/fs/locks.c
4044 --- linux-3.10.33/fs/locks.c    2013-05-31 13:45:24.000000000 +0000
4045 +++ linux-3.10.33-vs2.3.6.8/fs/locks.c  2013-08-22 20:29:59.000000000 +0000
4046 @@ -126,6 +126,8 @@
4047  #include <linux/time.h>
4048  #include <linux/rcupdate.h>
4049  #include <linux/pid_namespace.h>
4050 +#include <linux/vs_base.h>
4051 +#include <linux/vs_limit.h>
4052  
4053  #include <asm/uaccess.h>
4054  
4055 @@ -184,11 +186,17 @@ static void locks_init_lock_heads(struct
4056  /* Allocate an empty lock structure. */
4057  struct file_lock *locks_alloc_lock(void)
4058  {
4059 -       struct file_lock *fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4060 +       struct file_lock *fl;
4061  
4062 -       if (fl)
4063 -               locks_init_lock_heads(fl);
4064 +       if (!vx_locks_avail(1))
4065 +               return NULL;
4066  
4067 +       fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4068 +
4069 +       if (fl) {
4070 +               locks_init_lock_heads(fl);
4071 +               fl->fl_xid = -1;
4072 +       }
4073         return fl;
4074  }
4075  EXPORT_SYMBOL_GPL(locks_alloc_lock);
4076 @@ -212,6 +220,7 @@ void locks_free_lock(struct file_lock *f
4077         BUG_ON(!list_empty(&fl->fl_block));
4078         BUG_ON(!list_empty(&fl->fl_link));
4079  
4080 +       vx_locks_dec(fl);
4081         locks_release_private(fl);
4082         kmem_cache_free(filelock_cache, fl);
4083  }
4084 @@ -221,6 +230,7 @@ void locks_init_lock(struct file_lock *f
4085  {
4086         memset(fl, 0, sizeof(struct file_lock));
4087         locks_init_lock_heads(fl);
4088 +       fl->fl_xid = -1;
4089  }
4090  
4091  EXPORT_SYMBOL(locks_init_lock);
4092 @@ -261,6 +271,7 @@ void locks_copy_lock(struct file_lock *n
4093         new->fl_file = fl->fl_file;
4094         new->fl_ops = fl->fl_ops;
4095         new->fl_lmops = fl->fl_lmops;
4096 +       new->fl_xid = fl->fl_xid;
4097  
4098         locks_copy_private(new, fl);
4099  }
4100 @@ -299,6 +310,11 @@ static int flock_make_lock(struct file *
4101         fl->fl_flags = FL_FLOCK;
4102         fl->fl_type = type;
4103         fl->fl_end = OFFSET_MAX;
4104 +
4105 +       vxd_assert(filp->f_xid == vx_current_xid(),
4106 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4107 +       fl->fl_xid = filp->f_xid;
4108 +       vx_locks_inc(fl);
4109         
4110         *lock = fl;
4111         return 0;
4112 @@ -438,6 +454,7 @@ static int lease_init(struct file *filp,
4113  
4114         fl->fl_owner = current->files;
4115         fl->fl_pid = current->tgid;
4116 +       fl->fl_xid = vx_current_xid();
4117  
4118         fl->fl_file = filp;
4119         fl->fl_flags = FL_LEASE;
4120 @@ -457,6 +474,11 @@ static struct file_lock *lease_alloc(str
4121         if (fl == NULL)
4122                 return ERR_PTR(error);
4123  
4124 +       fl->fl_xid = vx_current_xid();
4125 +       if (filp)
4126 +               vxd_assert(filp->f_xid == fl->fl_xid,
4127 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
4128 +       vx_locks_inc(fl);
4129         error = lease_init(filp, type, fl);
4130         if (error) {
4131                 locks_free_lock(fl);
4132 @@ -753,6 +775,7 @@ static int flock_lock_file(struct file *
4133                 lock_flocks();
4134         }
4135  
4136 +       new_fl->fl_xid = -1;
4137  find_conflict:
4138         for_each_lock(inode, before) {
4139                 struct file_lock *fl = *before;
4140 @@ -773,6 +796,7 @@ find_conflict:
4141                 goto out;
4142         locks_copy_lock(new_fl, request);
4143         locks_insert_lock(before, new_fl);
4144 +       vx_locks_inc(new_fl);
4145         new_fl = NULL;
4146         error = 0;
4147  
4148 @@ -783,7 +807,8 @@ out:
4149         return error;
4150  }
4151  
4152 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
4153 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
4154 +       struct file_lock *conflock, vxid_t xid)
4155  {
4156         struct file_lock *fl;
4157         struct file_lock *new_fl = NULL;
4158 @@ -793,6 +818,8 @@ static int __posix_lock_file(struct inod
4159         struct file_lock **before;
4160         int error, added = 0;
4161  
4162 +       vxd_assert(xid == vx_current_xid(),
4163 +               "xid(%d) == current(%d)", xid, vx_current_xid());
4164         /*
4165          * We may need two file_lock structures for this operation,
4166          * so we get them in advance to avoid races.
4167 @@ -803,7 +830,11 @@ static int __posix_lock_file(struct inod
4168             (request->fl_type != F_UNLCK ||
4169              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
4170                 new_fl = locks_alloc_lock();
4171 +               new_fl->fl_xid = xid;
4172 +               vx_locks_inc(new_fl);
4173                 new_fl2 = locks_alloc_lock();
4174 +               new_fl2->fl_xid = xid;
4175 +               vx_locks_inc(new_fl2);
4176         }
4177  
4178         lock_flocks();
4179 @@ -1002,7 +1033,8 @@ static int __posix_lock_file(struct inod
4180  int posix_lock_file(struct file *filp, struct file_lock *fl,
4181                         struct file_lock *conflock)
4182  {
4183 -       return __posix_lock_file(file_inode(filp), fl, conflock);
4184 +       return __posix_lock_file(file_inode(filp),
4185 +               fl, conflock, filp->f_xid);
4186  }
4187  EXPORT_SYMBOL(posix_lock_file);
4188  
4189 @@ -1092,7 +1124,7 @@ int locks_mandatory_area(int read_write,
4190         fl.fl_end = offset + count - 1;
4191  
4192         for (;;) {
4193 -               error = __posix_lock_file(inode, &fl, NULL);
4194 +               error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
4195                 if (error != FILE_LOCK_DEFERRED)
4196                         break;
4197                 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
4198 @@ -1397,6 +1429,7 @@ int generic_add_lease(struct file *filp,
4199                 goto out;
4200  
4201         locks_insert_lock(before, lease);
4202 +       vx_locks_inc(lease);
4203         return 0;
4204  
4205  out:
4206 @@ -1836,6 +1869,11 @@ int fcntl_setlk(unsigned int fd, struct
4207         if (file_lock == NULL)
4208                 return -ENOLCK;
4209  
4210 +       vxd_assert(filp->f_xid == vx_current_xid(),
4211 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4212 +       file_lock->fl_xid = filp->f_xid;
4213 +       vx_locks_inc(file_lock);
4214 +
4215         /*
4216          * This might block, so we do it before checking the inode.
4217          */
4218 @@ -1954,6 +1992,11 @@ int fcntl_setlk64(unsigned int fd, struc
4219         if (file_lock == NULL)
4220                 return -ENOLCK;
4221  
4222 +       vxd_assert(filp->f_xid == vx_current_xid(),
4223 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4224 +       file_lock->fl_xid = filp->f_xid;
4225 +       vx_locks_inc(file_lock);
4226 +
4227         /*
4228          * This might block, so we do it before checking the inode.
4229          */
4230 @@ -2219,8 +2262,11 @@ static int locks_show(struct seq_file *f
4231  
4232         lock_get_status(f, fl, *((loff_t *)f->private), "");
4233  
4234 -       list_for_each_entry(bfl, &fl->fl_block, fl_block)
4235 +       list_for_each_entry(bfl, &fl->fl_block, fl_block) {
4236 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
4237 +                       continue;
4238                 lock_get_status(f, bfl, *((loff_t *)f->private), " ->");
4239 +       }
4240  
4241         return 0;
4242  }
4243 diff -NurpP --minimal linux-3.10.33/fs/mount.h linux-3.10.33-vs2.3.6.8/fs/mount.h
4244 --- linux-3.10.33/fs/mount.h    2014-03-12 13:16:02.000000000 +0000
4245 +++ linux-3.10.33-vs2.3.6.8/fs/mount.h  2014-03-12 13:18:23.000000000 +0000
4246 @@ -56,6 +56,7 @@ struct mount {
4247         int mnt_expiry_mark;            /* true if marked for expiry */
4248         int mnt_pinned;
4249         int mnt_ghosts;
4250 +       vtag_t mnt_tag;                 /* tagging used for vfsmount */
4251  };
4252  
4253  #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
4254 diff -NurpP --minimal linux-3.10.33/fs/namei.c linux-3.10.33-vs2.3.6.8/fs/namei.c
4255 --- linux-3.10.33/fs/namei.c    2014-03-12 13:16:02.000000000 +0000
4256 +++ linux-3.10.33-vs2.3.6.8/fs/namei.c  2013-12-23 17:42:40.000000000 +0000
4257 @@ -34,9 +34,19 @@
4258  #include <linux/device_cgroup.h>
4259  #include <linux/fs_struct.h>
4260  #include <linux/posix_acl.h>
4261 +#include <linux/proc_fs.h>
4262 +#include <linux/magic.h>
4263 +#include <linux/vserver/inode.h>
4264 +#include <linux/vs_base.h>
4265 +#include <linux/vs_tag.h>
4266 +#include <linux/vs_cowbl.h>
4267 +#include <linux/vs_device.h>
4268 +#include <linux/vs_context.h>
4269 +#include <linux/pid_namespace.h>
4270  #include <asm/uaccess.h>
4271  
4272  #include "internal.h"
4273 +#include "proc/internal.h"
4274  #include "mount.h"
4275  
4276  /* [Feb-1997 T. Schoebel-Theuer]
4277 @@ -266,6 +276,89 @@ static int check_acl(struct inode *inode
4278         return -EAGAIN;
4279  }
4280  
4281 +static inline int dx_barrier(const struct inode *inode)
4282 +{
4283 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
4284 +               vxwprintk_task(1, "did hit the barrier.");
4285 +               return 1;
4286 +       }
4287 +       return 0;
4288 +}
4289 +
4290 +static int __dx_permission(const struct inode *inode, int mask)
4291 +{
4292 +       if (dx_barrier(inode))
4293 +               return -EACCES;
4294 +
4295 +       if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
4296 +               /* devpts is xid tagged */
4297 +               if (S_ISDIR(inode->i_mode) ||
4298 +                   vx_check((vxid_t)i_tag_read(inode), VS_IDENT | VS_WATCH_P))
4299 +                       return 0;
4300 +
4301 +               /* just pretend we didn't find anything */
4302 +               return -ENOENT;
4303 +       }
4304 +       else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
4305 +               struct proc_dir_entry *de = PDE(inode);
4306 +
4307 +               if (de && !vx_hide_check(0, de->vx_flags))
4308 +                       goto out;
4309 +
4310 +               if ((mask & (MAY_WRITE | MAY_APPEND))) {
4311 +                       struct pid *pid;
4312 +                       struct task_struct *tsk;
4313 +
4314 +                       if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
4315 +                           vx_flags(VXF_STATE_SETUP, 0))
4316 +                               return 0;
4317 +
4318 +                       pid = PROC_I(inode)->pid;
4319 +                       if (!pid)
4320 +                               goto out;
4321 +
4322 +                       rcu_read_lock();
4323 +                       tsk = pid_task(pid, PIDTYPE_PID);
4324 +                       vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
4325 +                                 tsk, (tsk ? vx_task_xid(tsk) : 0));
4326 +                       if (tsk &&
4327 +                               vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P)) {
4328 +                               rcu_read_unlock();
4329 +                               return 0;
4330 +                       }
4331 +                       rcu_read_unlock();
4332 +               }
4333 +               else {
4334 +                       /* FIXME: Should we block some entries here? */
4335 +                       return 0;
4336 +               }
4337 +       }
4338 +       else {
4339 +               if (dx_notagcheck(inode->i_sb) ||
4340 +                   dx_check((vxid_t)i_tag_read(inode),
4341 +                       DX_HOSTID | DX_ADMIN | DX_WATCH | DX_IDENT))
4342 +                       return 0;
4343 +       }
4344 +
4345 +out:
4346 +       return -EACCES;
4347 +}
4348 +
4349 +int dx_permission(const struct inode *inode, int mask)
4350 +{
4351 +       int ret = __dx_permission(inode, mask);
4352 +       if (unlikely(ret)) {
4353 +#ifndef        CONFIG_VSERVER_WARN_DEVPTS
4354 +               if (inode->i_sb->s_magic != DEVPTS_SUPER_MAGIC)
4355 +#endif
4356 +                   vxwprintk_task(1,
4357 +                       "denied [0x%x] access to inode %s:%p[#%d,%lu]",
4358 +                       mask, inode->i_sb->s_id, inode,
4359 +                       i_tag_read(inode), inode->i_ino);
4360 +       }
4361 +       return ret;
4362 +}
4363 +
4364  /*
4365   * This does the basic permission checking
4366   */
4367 @@ -388,10 +481,14 @@ int __inode_permission(struct inode *ino
4368                 /*
4369                  * Nobody gets write access to an immutable file.
4370                  */
4371 -               if (IS_IMMUTABLE(inode))
4372 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
4373                         return -EACCES;
4374         }
4375  
4376 +       retval = dx_permission(inode, mask);
4377 +       if (retval)
4378 +               return retval;
4379 +
4380         retval = do_inode_permission(inode, mask);
4381         if (retval)
4382                 return retval;
4383 @@ -1238,7 +1335,8 @@ static void follow_dotdot(struct nameida
4384  
4385                 if (nd->path.dentry == nd->root.dentry &&
4386                     nd->path.mnt == nd->root.mnt) {
4387 -                       break;
4388 +                       /* for sane '/' avoid follow_mount() */
4389 +                       return;
4390                 }
4391                 if (nd->path.dentry != nd->path.mnt->mnt_root) {
4392                         /* rare case of legitimate dget_parent()... */
4393 @@ -1383,6 +1481,9 @@ static int lookup_fast(struct nameidata
4394                                 goto unlazy;
4395                         }
4396                 }
4397 +
4398 +               /* FIXME: check dx permission */
4399 +
4400                 path->mnt = mnt;
4401                 path->dentry = dentry;
4402                 if (unlikely(!__follow_mount_rcu(nd, path, inode)))
4403 @@ -1413,6 +1514,8 @@ unlazy:
4404                 }
4405         }
4406  
4407 +       /* FIXME: check dx permission */
4408 +
4409         path->mnt = mnt;
4410         path->dentry = dentry;
4411         err = follow_managed(path, nd->flags);
4412 @@ -2237,7 +2340,7 @@ static int may_delete(struct inode *dir,
4413         if (IS_APPEND(dir))
4414                 return -EPERM;
4415         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
4416 -           IS_IMMUTABLE(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4417 +               IS_IXORUNLINK(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4418                 return -EPERM;
4419         if (isdir) {
4420                 if (!S_ISDIR(victim->d_inode->i_mode))
4421 @@ -2317,19 +2420,25 @@ int vfs_create(struct inode *dir, struct
4422                 bool want_excl)
4423  {
4424         int error = may_create(dir, dentry);
4425 -       if (error)
4426 +       if (error) {
4427 +               vxdprintk(VXD_CBIT(misc, 3), "may_create failed with %d", error);
4428                 return error;
4429 +       }
4430  
4431         if (!dir->i_op->create)
4432                 return -EACCES; /* shouldn't it be ENOSYS? */
4433         mode &= S_IALLUGO;
4434         mode |= S_IFREG;
4435         error = security_inode_create(dir, dentry, mode);
4436 -       if (error)
4437 +       if (error) {
4438 +               vxdprintk(VXD_CBIT(misc, 3), "security_inode_create failed with %d", error);
4439                 return error;
4440 +       }
4441         error = dir->i_op->create(dir, dentry, mode, want_excl);
4442         if (!error)
4443                 fsnotify_create(dir, dentry);
4444 +       else
4445 +               vxdprintk(VXD_CBIT(misc, 3), "i_op->create failed with %d", error);
4446         return error;
4447  }
4448  
4449 @@ -2364,6 +2473,15 @@ static int may_open(struct path *path, i
4450                 break;
4451         }
4452  
4453 +#ifdef CONFIG_VSERVER_COWBL
4454 +       if (IS_COW(inode) &&
4455 +               ((flag & O_ACCMODE) != O_RDONLY)) {
4456 +               if (IS_COW_LINK(inode))
4457 +                       return -EMLINK;
4458 +               inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
4459 +               mark_inode_dirty(inode);
4460 +       }
4461 +#endif
4462         error = inode_permission(inode, acc_mode);
4463         if (error)
4464                 return error;
4465 @@ -2866,6 +2984,16 @@ finish_open:
4466         }
4467  finish_open_created:
4468         error = may_open(&nd->path, acc_mode, open_flag);
4469 +#ifdef CONFIG_VSERVER_COWBL
4470 +       if (error == -EMLINK) {
4471 +               struct dentry *dentry;
4472 +               dentry = cow_break_link(name->name);
4473 +               if (IS_ERR(dentry))
4474 +                       error = PTR_ERR(dentry);
4475 +               else
4476 +                       dput(dentry);
4477 +       }
4478 +#endif
4479         if (error)
4480                 goto out;
4481         file->f_path.mnt = nd->path.mnt;
4482 @@ -2930,6 +3058,7 @@ static struct file *path_openat(int dfd,
4483         int opened = 0;
4484         int error;
4485  
4486 +restart:
4487         file = get_empty_filp();
4488         if (IS_ERR(file))
4489                 return file;
4490 @@ -2966,6 +3095,16 @@ static struct file *path_openat(int dfd,
4491                 error = do_last(nd, &path, file, op, &opened, pathname);
4492                 put_link(nd, &link, cookie);
4493         }
4494 +
4495 +#ifdef CONFIG_VSERVER_COWBL
4496 +       if (error == -EMLINK) {
4497 +               if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4498 +                       path_put(&nd->root);
4499 +               if (base)
4500 +                       fput(base);
4501 +               goto restart;
4502 +       }
4503 +#endif
4504  out:
4505         if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4506                 path_put(&nd->root);
4507 @@ -3080,6 +3219,11 @@ struct dentry *kern_path_create(int dfd,
4508                 goto fail;
4509         }
4510         *path = nd.path;
4511 +       vxdprintk(VXD_CBIT(misc, 3), "kern_path_create path.dentry = %p (%.*s), dentry = %p (%.*s), d_inode = %p",
4512 +               path->dentry, path->dentry->d_name.len,
4513 +               path->dentry->d_name.name, dentry,
4514 +               dentry->d_name.len, dentry->d_name.name,
4515 +               path->dentry->d_inode);
4516         return dentry;
4517  fail:
4518         dput(dentry);
4519 @@ -3574,7 +3718,7 @@ int vfs_link(struct dentry *old_dentry,
4520         /*
4521          * A link to an append-only or immutable file cannot be created.
4522          */
4523 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
4524 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
4525                 return -EPERM;
4526         if (!dir->i_op->link)
4527                 return -EPERM;
4528 @@ -3977,6 +4121,287 @@ int vfs_follow_link(struct nameidata *nd
4529         return __vfs_follow_link(nd, link);
4530  }
4531  
4532 +
4533 +#ifdef CONFIG_VSERVER_COWBL
4534 +
4535 +static inline
4536 +long do_cow_splice(struct file *in, struct file *out, size_t len)
4537 +{
4538 +       loff_t ppos = 0;
4539 +       loff_t opos = 0;
4540 +
4541 +       return do_splice_direct(in, &ppos, out, &opos, len, 0);
4542 +}
4543 +
4544 +struct dentry *cow_break_link(const char *pathname)
4545 +{
4546 +       int ret, mode, pathlen, redo = 0, drop = 1;
4547 +       struct nameidata old_nd, dir_nd;
4548 +       struct path dir_path, *old_path, *new_path;
4549 +       struct dentry *dir, *old_dentry, *new_dentry = NULL;
4550 +       struct file *old_file;
4551 +       struct file *new_file;
4552 +       char *to, *path, pad='\251';
4553 +       loff_t size;
4554 +
4555 +       vxdprintk(VXD_CBIT(misc, 1),
4556 +               "cow_break_link(" VS_Q("%s") ")", pathname);
4557 +
4558 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
4559 +       ret = -ENOMEM;
4560 +       if (!path)
4561 +               goto out;
4562 +
4563 +       /* old_nd.path will have refs to dentry and mnt */
4564 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4565 +       vxdprintk(VXD_CBIT(misc, 2),
4566 +               "do_path_lookup(old): %d", ret);
4567 +       if (ret < 0)
4568 +               goto out_free_path;
4569 +
4570 +       /* dentry/mnt refs handed over to old_path */
4571 +       old_path = &old_nd.path;
4572 +       /* no explicit reference for old_dentry here */
4573 +       old_dentry = old_path->dentry;
4574 +
4575 +       mode = old_dentry->d_inode->i_mode;
4576 +       to = d_path(old_path, path, PATH_MAX-2);
4577 +       pathlen = strlen(to);
4578 +       vxdprintk(VXD_CBIT(misc, 2),
4579 +               "old path " VS_Q("%s") " [%p:" VS_Q("%.*s") ":%d]", to,
4580 +               old_dentry,
4581 +               old_dentry->d_name.len, old_dentry->d_name.name,
4582 +               old_dentry->d_name.len);
4583 +
4584 +       to[pathlen + 1] = 0;
4585 +retry:
4586 +       new_dentry = NULL;
4587 +       to[pathlen] = pad--;
4588 +       ret = -ELOOP;
4589 +       if (pad <= '\240')
4590 +               goto out_rel_old;
4591 +
4592 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy " VS_Q("%s"), to);
4593 +
4594 +       /* dir_nd.path will have refs to dentry and mnt */
4595 +       ret = do_path_lookup(AT_FDCWD, to,
4596 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
4597 +       vxdprintk(VXD_CBIT(misc, 2), "do_path_lookup(new): %d", ret);
4598 +       if (ret < 0)
4599 +               goto retry;
4600 +
4601 +       /* this puppy downs the dir inode mutex if successful.
4602 +          dir_path will hold refs to dentry and mnt and
4603 +          we'll have write access to the mnt */
4604 +       new_dentry = kern_path_create(AT_FDCWD, to, &dir_path, 0);
4605 +       if (!new_dentry || IS_ERR(new_dentry)) {
4606 +               path_put(&dir_nd.path);
4607 +               vxdprintk(VXD_CBIT(misc, 2),
4608 +                       "kern_path_create(new) failed with %ld",
4609 +                       PTR_ERR(new_dentry));
4610 +               goto retry;
4611 +       }
4612 +       vxdprintk(VXD_CBIT(misc, 2),
4613 +               "kern_path_create(new): %p [" VS_Q("%.*s") ":%d]",
4614 +               new_dentry,
4615 +               new_dentry->d_name.len, new_dentry->d_name.name,
4616 +               new_dentry->d_name.len);
4617 +
4618 +       /* take a reference on new_dentry */
4619 +       dget(new_dentry);
4620 +
4621 +       /* dentry/mnt refs handed over to new_path */
4622 +       new_path = &dir_path;
4623 +
4624 +       /* dentry for old/new dir */
4625 +       dir = dir_nd.path.dentry;
4626 +
4627 +       /* give up reference on dir */
4628 +       dput(new_path->dentry);
4629 +
4630 +       /* new_dentry already has a reference */
4631 +       new_path->dentry = new_dentry;
4632 +
4633 +       ret = vfs_create(dir->d_inode, new_dentry, mode, 1);
4634 +       vxdprintk(VXD_CBIT(misc, 2),
4635 +               "vfs_create(new): %d", ret);
4636 +       if (ret == -EEXIST) {
4637 +               path_put(&dir_nd.path);
4638 +               mutex_unlock(&dir->d_inode->i_mutex);
4639 +               mnt_drop_write(new_path->mnt);
4640 +               path_put(new_path);
4641 +               new_dentry = NULL;
4642 +               goto retry;
4643 +       }
4644 +       else if (ret < 0)
4645 +               goto out_unlock_new;
4646 +
4647 +       /* drop out early, ret passes ENOENT */
4648 +       ret = -ENOENT;
4649 +       if ((redo = d_unhashed(old_dentry)))
4650 +               goto out_unlock_new;
4651 +
4652 +       /* doesn't change refs for old_path */
4653 +       old_file = dentry_open(old_path, O_RDONLY, current_cred());
4654 +       vxdprintk(VXD_CBIT(misc, 2),
4655 +               "dentry_open(old): %p", old_file);
4656 +       if (IS_ERR(old_file)) {
4657 +               ret = PTR_ERR(old_file);
4658 +               goto out_unlock_new;
4659 +       }
4660 +
4661 +       /* doesn't change refs for new_path */
4662 +       new_file = dentry_open(new_path, O_WRONLY, current_cred());
4663 +       vxdprintk(VXD_CBIT(misc, 2),
4664 +               "dentry_open(new): %p", new_file);
4665 +       if (IS_ERR(new_file)) {
4666 +               ret = PTR_ERR(new_file);
4667 +               goto out_fput_old;
4668 +       }
4669 +
4670 +       /* unlock the inode mutex from kern_path_create() */
4671 +       mutex_unlock(&dir->d_inode->i_mutex);
4672 +
4673 +       /* drop write access to mnt */
4674 +       mnt_drop_write(new_path->mnt);
4675 +
4676 +       drop = 0;
4677 +
4678 +       size = i_size_read(old_file->f_dentry->d_inode);
4679 +       ret = do_cow_splice(old_file, new_file, size);
4680 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
4681 +       if (ret < 0) {
4682 +               goto out_fput_both;
4683 +       } else if (ret < size) {
4684 +               ret = -ENOSPC;
4685 +               goto out_fput_both;
4686 +       } else {
4687 +               struct inode *old_inode = old_dentry->d_inode;
4688 +               struct inode *new_inode = new_dentry->d_inode;
4689 +               struct iattr attr = {
4690 +                       .ia_uid = old_inode->i_uid,
4691 +                       .ia_gid = old_inode->i_gid,
4692 +                       .ia_valid = ATTR_UID | ATTR_GID
4693 +                       };
4694 +
4695 +               setattr_copy(new_inode, &attr);
4696 +               mark_inode_dirty(new_inode);
4697 +       }
4698 +
4699 +       /* lock rename mutex */
4700 +       mutex_lock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4701 +
4702 +       /* drop out late */
4703 +       ret = -ENOENT;
4704 +       if ((redo = d_unhashed(old_dentry)))
4705 +               goto out_unlock;
4706 +
4707 +       vxdprintk(VXD_CBIT(misc, 2),
4708 +               "vfs_rename: [" VS_Q("%*s") ":%d] -> [" VS_Q("%*s") ":%d]",
4709 +               new_dentry->d_name.len, new_dentry->d_name.name,
4710 +               new_dentry->d_name.len,
4711 +               old_dentry->d_name.len, old_dentry->d_name.name,
4712 +               old_dentry->d_name.len);
4713 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_dentry,
4714 +               old_dentry->d_parent->d_inode, old_dentry);
4715 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
4716 +
4717 +out_unlock:
4718 +       mutex_unlock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4719 +
4720 +out_fput_both:
4721 +       vxdprintk(VXD_CBIT(misc, 3),
4722 +               "fput(new_file=%p[#%ld])", new_file,
4723 +               atomic_long_read(&new_file->f_count));
4724 +       fput(new_file);
4725 +
4726 +out_fput_old:
4727 +       vxdprintk(VXD_CBIT(misc, 3),
4728 +               "fput(old_file=%p[#%ld])", old_file,
4729 +               atomic_long_read(&old_file->f_count));
4730 +       fput(old_file);
4731 +
4732 +out_unlock_new:
4733 +       /* drop references from dir_nd.path */
4734 +       path_put(&dir_nd.path);
4735 +
4736 +       if (drop) {
4737 +               /* unlock the inode mutex from kern_path_create() */
4738 +               mutex_unlock(&dir->d_inode->i_mutex);
4739 +
4740 +               /* drop write access to mnt */
4741 +               mnt_drop_write(new_path->mnt);
4742 +       }
4743 +
4744 +       if (!ret)
4745 +               goto out_redo;
4746 +
4747 +       /* error path cleanup */
4748 +       vfs_unlink(dir->d_inode, new_dentry);
4749 +
4750 +out_redo:
4751 +       if (!redo)
4752 +               goto out_rel_both;
4753 +
4754 +       /* lookup dentry once again
4755 +          old_nd.path will be freed as old_path in out_rel_old */
4756 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4757 +       if (ret)
4758 +               goto out_rel_both;
4759 +
4760 +       /* drop reference on new_dentry */
4761 +       dput(new_dentry);
4762 +       new_dentry = old_path->dentry;
4763 +       dget(new_dentry);
4764 +       vxdprintk(VXD_CBIT(misc, 2),
4765 +               "do_path_lookup(redo): %p [" VS_Q("%.*s") ":%d]",
4766 +               new_dentry,
4767 +               new_dentry->d_name.len, new_dentry->d_name.name,
4768 +               new_dentry->d_name.len);
4769 +
4770 +out_rel_both:
4771 +       if (new_path)
4772 +               path_put(new_path);
4773 +out_rel_old:
4774 +       path_put(old_path);
4775 +out_free_path:
4776 +       kfree(path);
4777 +out:
4778 +       if (ret) {
4779 +               dput(new_dentry);
4780 +               new_dentry = ERR_PTR(ret);
4781 +       }
4782 +       vxdprintk(VXD_CBIT(misc, 3),
4783 +               "cow_break_link returning with %p", new_dentry);
4784 +       return new_dentry;
4785 +}
4786 +
4787 +#endif
4788 +
4789 +int    vx_info_mnt_namespace(struct mnt_namespace *ns, char *buffer)
4790 +{
4791 +       struct path path;
4792 +       struct vfsmount *vmnt;
4793 +       char *pstr, *root;
4794 +       int length = 0;
4795 +
4796 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
4797 +       if (!pstr)
4798 +               return 0;
4799 +
4800 +       vmnt = &ns->root->mnt;
4801 +       path.mnt = vmnt;
4802 +       path.dentry = vmnt->mnt_root;
4803 +       root = d_path(&path, pstr, PATH_MAX - 2);
4804 +       length = sprintf(buffer + length,
4805 +               "Namespace:\t%p [#%u]\n"
4806 +               "RootPath:\t%s\n",
4807 +               ns, atomic_read(&ns->count),
4808 +               root);
4809 +       kfree(pstr);
4810 +       return length;
4811 +}
4812 +
4813  /* get the link contents into pagecache */
4814  static char *page_getlink(struct dentry * dentry, struct page **ppage)
4815  {
4816 @@ -4100,3 +4525,4 @@ EXPORT_SYMBOL(vfs_symlink);
4817  EXPORT_SYMBOL(vfs_unlink);
4818  EXPORT_SYMBOL(dentry_unhash);
4819  EXPORT_SYMBOL(generic_readlink);
4820 +EXPORT_SYMBOL(vx_info_mnt_namespace);
4821 diff -NurpP --minimal linux-3.10.33/fs/namespace.c linux-3.10.33-vs2.3.6.8/fs/namespace.c
4822 --- linux-3.10.33/fs/namespace.c        2014-03-12 13:16:02.000000000 +0000
4823 +++ linux-3.10.33-vs2.3.6.8/fs/namespace.c      2013-11-13 17:17:16.000000000 +0000
4824 @@ -23,6 +23,11 @@
4825  #include <linux/uaccess.h>
4826  #include <linux/proc_ns.h>
4827  #include <linux/magic.h>
4828 +#include <linux/vs_base.h>
4829 +#include <linux/vs_context.h>
4830 +#include <linux/vs_tag.h>
4831 +#include <linux/vserver/space.h>
4832 +#include <linux/vserver/global.h>
4833  #include "pnode.h"
4834  #include "internal.h"
4835  
4836 @@ -780,6 +785,10 @@ vfs_kern_mount(struct file_system_type *
4837         if (!type)
4838                 return ERR_PTR(-ENODEV);
4839  
4840 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
4841 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
4842 +               return ERR_PTR(-EPERM);
4843 +
4844         mnt = alloc_vfsmnt(name);
4845         if (!mnt)
4846                 return ERR_PTR(-ENOMEM);
4847 @@ -836,6 +845,7 @@ static struct mount *clone_mnt(struct mo
4848         mnt->mnt.mnt_root = dget(root);
4849         mnt->mnt_mountpoint = mnt->mnt.mnt_root;
4850         mnt->mnt_parent = mnt;
4851 +               mnt->mnt_tag = old->mnt_tag;
4852         br_write_lock(&vfsmount_lock);
4853         list_add_tail(&mnt->mnt_instance, &sb->s_mounts);
4854         br_write_unlock(&vfsmount_lock);
4855 @@ -1291,7 +1301,8 @@ static int do_umount(struct mount *mnt,
4856   */
4857  static inline bool may_mount(void)
4858  {
4859 -       return ns_capable(current->nsproxy->mnt_ns->user_ns, CAP_SYS_ADMIN);
4860 +       return vx_ns_capable(current->nsproxy->mnt_ns->user_ns,
4861 +               CAP_SYS_ADMIN, VXC_SECURE_MOUNT);
4862  }
4863  
4864  /*
4865 @@ -1685,6 +1696,7 @@ static int do_change_type(struct path *p
4866                 if (err)
4867                         goto out_unlock;
4868         }
4869 +       // mnt->mnt_flags = mnt_flags;
4870  
4871         br_write_lock(&vfsmount_lock);
4872         for (m = mnt; m; m = (recurse ? next_mnt(m, mnt) : NULL))
4873 @@ -1700,12 +1712,14 @@ static int do_change_type(struct path *p
4874   * do loopback mount.
4875   */
4876  static int do_loopback(struct path *path, const char *old_name,
4877 -                               int recurse)
4878 +       vtag_t tag, unsigned long flags, int mnt_flags)
4879  {
4880         struct path old_path;
4881         struct mount *mnt = NULL, *old, *parent;
4882         struct mountpoint *mp;
4883 +       int recurse = flags & MS_REC;
4884         int err;
4885 +
4886         if (!old_name || !*old_name)
4887                 return -EINVAL;
4888         err = kern_path(old_name, LOOKUP_FOLLOW|LOOKUP_AUTOMOUNT, &old_path);
4889 @@ -1780,7 +1794,7 @@ static int change_mount_flags(struct vfs
4890   * on it - tough luck.
4891   */
4892  static int do_remount(struct path *path, int flags, int mnt_flags,
4893 -                     void *data)
4894 +       void *data, vxid_t xid)
4895  {
4896         int err;
4897         struct super_block *sb = path->mnt->mnt_sb;
4898 @@ -2264,6 +2278,7 @@ long do_mount(const char *dev_name, cons
4899         struct path path;
4900         int retval = 0;
4901         int mnt_flags = 0;
4902 +       vtag_t tag = 0;
4903  
4904         /* Discard magic */
4905         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
4906 @@ -2293,6 +2308,12 @@ long do_mount(const char *dev_name, cons
4907         if (!(flags & MS_NOATIME))
4908                 mnt_flags |= MNT_RELATIME;
4909  
4910 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
4911 +               /* FIXME: bind and re-mounts get the tag flag? */
4912 +               if (flags & (MS_BIND|MS_REMOUNT))
4913 +                       flags |= MS_TAGID;
4914 +       }
4915 +
4916         /* Separate the per-mountpoint flags */
4917         if (flags & MS_NOSUID)
4918                 mnt_flags |= MNT_NOSUID;
4919 @@ -2309,15 +2330,17 @@ long do_mount(const char *dev_name, cons
4920         if (flags & MS_RDONLY)
4921                 mnt_flags |= MNT_READONLY;
4922  
4923 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_DEV_MOUNT))
4924 +               mnt_flags |= MNT_NODEV;
4925         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_BORN |
4926                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
4927                    MS_STRICTATIME);
4928  
4929         if (flags & MS_REMOUNT)
4930                 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
4931 -                                   data_page);
4932 +                                   data_page, tag);
4933         else if (flags & MS_BIND)
4934 -               retval = do_loopback(&path, dev_name, flags & MS_REC);
4935 +               retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
4936         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
4937                 retval = do_change_type(&path, flags);
4938         else if (flags & MS_MOVE)
4939 @@ -2426,6 +2449,7 @@ static struct mnt_namespace *dup_mnt_ns(
4940                 q = next_mnt(q, new);
4941         }
4942         namespace_unlock();
4943 +       atomic_inc(&vs_global_mnt_ns);
4944  
4945         if (rootmnt)
4946                 mntput(rootmnt);
4947 @@ -2624,9 +2648,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
4948         new_mnt = real_mount(new.mnt);
4949         root_mnt = real_mount(root.mnt);
4950         old_mnt = real_mount(old.mnt);
4951 -       if (IS_MNT_SHARED(old_mnt) ||
4952 +       if ((IS_MNT_SHARED(old_mnt) ||
4953                 IS_MNT_SHARED(new_mnt->mnt_parent) ||
4954 -               IS_MNT_SHARED(root_mnt->mnt_parent))
4955 +               IS_MNT_SHARED(root_mnt->mnt_parent)) &&
4956 +               !vx_flags(VXF_STATE_SETUP, 0))
4957                 goto out4;
4958         if (!check_mnt(root_mnt) || !check_mnt(new_mnt))
4959                 goto out4;
4960 @@ -2752,6 +2777,7 @@ void put_mnt_ns(struct mnt_namespace *ns
4961         umount_tree(ns->root, 0);
4962         br_write_unlock(&vfsmount_lock);
4963         namespace_unlock();
4964 +       atomic_dec(&vs_global_mnt_ns);
4965         free_mnt_ns(ns);
4966  }
4967  
4968 diff -NurpP --minimal linux-3.10.33/fs/nfs/client.c linux-3.10.33-vs2.3.6.8/fs/nfs/client.c
4969 --- linux-3.10.33/fs/nfs/client.c       2013-07-14 17:01:28.000000000 +0000
4970 +++ linux-3.10.33-vs2.3.6.8/fs/nfs/client.c     2013-08-22 20:29:59.000000000 +0000
4971 @@ -684,6 +684,9 @@ int nfs_init_server_rpcclient(struct nfs
4972         if (server->flags & NFS_MOUNT_SOFT)
4973                 server->client->cl_softrtry = 1;
4974  
4975 +       server->client->cl_tag = 0;
4976 +       if (server->flags & NFS_MOUNT_TAGGED)
4977 +               server->client->cl_tag = 1;
4978         return 0;
4979  }
4980  EXPORT_SYMBOL_GPL(nfs_init_server_rpcclient);
4981 @@ -863,6 +866,10 @@ static void nfs_server_set_fsinfo(struct
4982                 server->acdirmin = server->acdirmax = 0;
4983         }
4984  
4985 +       /* FIXME: needs fsinfo
4986 +       if (server->flags & NFS_MOUNT_TAGGED)
4987 +               sb->s_flags |= MS_TAGGED;       */
4988 +
4989         server->maxfilesize = fsinfo->maxfilesize;
4990  
4991         server->time_delta = fsinfo->time_delta;
4992 diff -NurpP --minimal linux-3.10.33/fs/nfs/dir.c linux-3.10.33-vs2.3.6.8/fs/nfs/dir.c
4993 --- linux-3.10.33/fs/nfs/dir.c  2013-07-14 17:01:28.000000000 +0000
4994 +++ linux-3.10.33-vs2.3.6.8/fs/nfs/dir.c        2013-08-22 20:29:59.000000000 +0000
4995 @@ -36,6 +36,7 @@
4996  #include <linux/sched.h>
4997  #include <linux/kmemleak.h>
4998  #include <linux/xattr.h>
4999 +#include <linux/vs_tag.h>
5000  
5001  #include "delegation.h"
5002  #include "iostat.h"
5003 @@ -1300,6 +1301,7 @@ struct dentry *nfs_lookup(struct inode *
5004         /* Success: notify readdir to use READDIRPLUS */
5005         nfs_advise_use_readdirplus(dir);
5006  
5007 +       dx_propagate_tag(nd, inode);
5008  no_entry:
5009         res = d_materialise_unique(dentry, inode);
5010         if (res != NULL) {
5011 diff -NurpP --minimal linux-3.10.33/fs/nfs/inode.c linux-3.10.33-vs2.3.6.8/fs/nfs/inode.c
5012 --- linux-3.10.33/fs/nfs/inode.c        2013-07-14 17:01:28.000000000 +0000
5013 +++ linux-3.10.33-vs2.3.6.8/fs/nfs/inode.c      2013-08-22 20:29:59.000000000 +0000
5014 @@ -39,6 +39,7 @@
5015  #include <linux/compat.h>
5016  #include <linux/freezer.h>
5017  #include <linux/crc32.h>
5018 +#include <linux/vs_tag.h>
5019  
5020  #include <asm/uaccess.h>
5021  
5022 @@ -290,6 +291,8 @@ nfs_fhget(struct super_block *sb, struct
5023         if (inode->i_state & I_NEW) {
5024                 struct nfs_inode *nfsi = NFS_I(inode);
5025                 unsigned long now = jiffies;
5026 +               kuid_t kuid;
5027 +               kgid_t kgid;
5028  
5029                 /* We set i_ino for the few things that still rely on it,
5030                  * such as stat(2) */
5031 @@ -334,8 +337,8 @@ nfs_fhget(struct super_block *sb, struct
5032                 inode->i_version = 0;
5033                 inode->i_size = 0;
5034                 clear_nlink(inode);
5035 -               inode->i_uid = make_kuid(&init_user_ns, -2);
5036 -               inode->i_gid = make_kgid(&init_user_ns, -2);
5037 +               kuid = make_kuid(&init_user_ns, -2);
5038 +               kgid = make_kgid(&init_user_ns, -2);
5039                 inode->i_blocks = 0;
5040                 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
5041                 nfsi->write_io = 0;
5042 @@ -369,11 +372,11 @@ nfs_fhget(struct super_block *sb, struct
5043                 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
5044                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5045                 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
5046 -                       inode->i_uid = fattr->uid;
5047 +                       kuid = fattr->uid;
5048                 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
5049                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5050                 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
5051 -                       inode->i_gid = fattr->gid;
5052 +                       kgid = fattr->gid;
5053                 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
5054                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5055                 if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED)
5056 @@ -384,6 +387,11 @@ nfs_fhget(struct super_block *sb, struct
5057                          */
5058                         inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
5059                 }
5060 +               inode->i_uid = INOTAG_KUID(DX_TAG(inode), kuid, kgid);
5061 +               inode->i_gid = INOTAG_KGID(DX_TAG(inode), kuid, kgid);
5062 +               inode->i_tag = INOTAG_KTAG(DX_TAG(inode), kuid, kgid, GLOBAL_ROOT_TAG);
5063 +                               /* maybe fattr->xid someday */
5064 +
5065                 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
5066                 nfsi->attrtimeo_timestamp = now;
5067                 nfsi->access_cache = RB_ROOT;
5068 @@ -505,6 +513,8 @@ void nfs_setattr_update_inode(struct ino
5069                         inode->i_uid = attr->ia_uid;
5070                 if ((attr->ia_valid & ATTR_GID) != 0)
5071                         inode->i_gid = attr->ia_gid;
5072 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5073 +                       inode->i_tag = attr->ia_tag;
5074                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5075                 spin_unlock(&inode->i_lock);
5076         }
5077 @@ -982,7 +992,9 @@ static int nfs_check_inode_attributes(st
5078         struct nfs_inode *nfsi = NFS_I(inode);
5079         loff_t cur_size, new_isize;
5080         unsigned long invalid = 0;
5081 -
5082 +       kuid_t kuid;
5083 +       kgid_t kgid;
5084 +       ktag_t ktag;
5085  
5086         if (nfs_have_delegated_attributes(inode))
5087                 return 0;
5088 @@ -1007,13 +1019,18 @@ static int nfs_check_inode_attributes(st
5089                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5090         }
5091  
5092 +       kuid = INOTAG_KUID(DX_TAG(inode), fattr->uid, fattr->gid);
5093 +       kgid = INOTAG_KGID(DX_TAG(inode), fattr->uid, fattr->gid);
5094 +       ktag = INOTAG_KTAG(DX_TAG(inode), fattr->uid, fattr->gid, GLOBAL_ROOT_TAG);
5095 +
5096         /* Have any file permissions changed? */
5097         if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
5098                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5099 -       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && !uid_eq(inode->i_uid, fattr->uid))
5100 +       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && !uid_eq(inode->i_uid, kuid))
5101                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5102 -       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && !gid_eq(inode->i_gid, fattr->gid))
5103 +       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && !gid_eq(inode->i_gid, kgid))
5104                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5105 +               /* maybe check for tag too? */
5106  
5107         /* Has the link count changed? */
5108         if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
5109 @@ -1319,6 +1336,9 @@ static int nfs_update_inode(struct inode
5110         unsigned long invalid = 0;
5111         unsigned long now = jiffies;
5112         unsigned long save_cache_validity;
5113 +       kuid_t kuid;
5114 +       kgid_t kgid;
5115 +       ktag_t ktag;
5116  
5117         dfprintk(VFS, "NFS: %s(%s/%ld fh_crc=0x%08x ct=%d info=0x%x)\n",
5118                         __func__, inode->i_sb->s_id, inode->i_ino,
5119 @@ -1420,6 +1440,9 @@ static int nfs_update_inode(struct inode
5120                                 | NFS_INO_REVAL_PAGECACHE
5121                                 | NFS_INO_REVAL_FORCED);
5122  
5123 +       kuid = TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag);
5124 +       kgid = TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag);
5125 +       ktag = TAGINO_KTAG(DX_TAG(inode), inode->i_tag);
5126  
5127         if (fattr->valid & NFS_ATTR_FATTR_ATIME)
5128                 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5129 @@ -1462,6 +1485,10 @@ static int nfs_update_inode(struct inode
5130                                 | NFS_INO_INVALID_ACL
5131                                 | NFS_INO_REVAL_FORCED);
5132  
5133 +       inode->i_uid = INOTAG_KUID(DX_TAG(inode), kuid, kgid);
5134 +       inode->i_gid = INOTAG_KGID(DX_TAG(inode), kuid, kgid);
5135 +       inode->i_tag = INOTAG_KTAG(DX_TAG(inode), kuid, kgid, ktag);
5136 +
5137         if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
5138                 if (inode->i_nlink != fattr->nlink) {
5139                         invalid |= NFS_INO_INVALID_ATTR;
5140 diff -NurpP --minimal linux-3.10.33/fs/nfs/nfs3xdr.c linux-3.10.33-vs2.3.6.8/fs/nfs/nfs3xdr.c
5141 --- linux-3.10.33/fs/nfs/nfs3xdr.c      2013-05-31 13:45:24.000000000 +0000
5142 +++ linux-3.10.33-vs2.3.6.8/fs/nfs/nfs3xdr.c    2013-08-22 20:29:59.000000000 +0000
5143 @@ -20,6 +20,7 @@
5144  #include <linux/nfs3.h>
5145  #include <linux/nfs_fs.h>
5146  #include <linux/nfsacl.h>
5147 +#include <linux/vs_tag.h>
5148  #include "internal.h"
5149  
5150  #define NFSDBG_FACILITY                NFSDBG_XDR
5151 @@ -558,7 +559,8 @@ static __be32 *xdr_decode_nfstime3(__be3
5152   *             set_mtime       mtime;
5153   *     };
5154   */
5155 -static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr)
5156 +static void encode_sattr3(struct xdr_stream *xdr,
5157 +       const struct iattr *attr, int tag)
5158  {
5159         u32 nbytes;
5160         __be32 *p;
5161 @@ -590,15 +592,19 @@ static void encode_sattr3(struct xdr_str
5162         } else
5163                 *p++ = xdr_zero;
5164  
5165 -       if (attr->ia_valid & ATTR_UID) {
5166 +       if (attr->ia_valid & ATTR_UID ||
5167 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5168                 *p++ = xdr_one;
5169 -               *p++ = cpu_to_be32(from_kuid(&init_user_ns, attr->ia_uid));
5170 +               *p++ = cpu_to_be32(from_kuid(&init_user_ns,
5171 +                       TAGINO_KUID(tag, attr->ia_uid, attr->ia_tag)));
5172         } else
5173                 *p++ = xdr_zero;
5174  
5175 -       if (attr->ia_valid & ATTR_GID) {
5176 +       if (attr->ia_valid & ATTR_GID ||
5177 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5178                 *p++ = xdr_one;
5179 -               *p++ = cpu_to_be32(from_kgid(&init_user_ns, attr->ia_gid));
5180 +               *p++ = cpu_to_be32(from_kgid(&init_user_ns,
5181 +                       TAGINO_KGID(tag, attr->ia_gid, attr->ia_tag)));
5182         } else
5183                 *p++ = xdr_zero;
5184  
5185 @@ -887,7 +893,7 @@ static void nfs3_xdr_enc_setattr3args(st
5186                                       const struct nfs3_sattrargs *args)
5187  {
5188         encode_nfs_fh3(xdr, args->fh);
5189 -       encode_sattr3(xdr, args->sattr);
5190 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5191         encode_sattrguard3(xdr, args);
5192  }
5193  
5194 @@ -1037,13 +1043,13 @@ static void nfs3_xdr_enc_write3args(stru
5195   *     };
5196   */
5197  static void encode_createhow3(struct xdr_stream *xdr,
5198 -                             const struct nfs3_createargs *args)
5199 +       const struct nfs3_createargs *args, int tag)
5200  {
5201         encode_uint32(xdr, args->createmode);
5202         switch (args->createmode) {
5203         case NFS3_CREATE_UNCHECKED:
5204         case NFS3_CREATE_GUARDED:
5205 -               encode_sattr3(xdr, args->sattr);
5206 +               encode_sattr3(xdr, args->sattr, tag);
5207                 break;
5208         case NFS3_CREATE_EXCLUSIVE:
5209                 encode_createverf3(xdr, args->verifier);
5210 @@ -1058,7 +1064,7 @@ static void nfs3_xdr_enc_create3args(str
5211                                      const struct nfs3_createargs *args)
5212  {
5213         encode_diropargs3(xdr, args->fh, args->name, args->len);
5214 -       encode_createhow3(xdr, args);
5215 +       encode_createhow3(xdr, args, req->rq_task->tk_client->cl_tag);
5216  }
5217  
5218  /*
5219 @@ -1074,7 +1080,7 @@ static void nfs3_xdr_enc_mkdir3args(stru
5220                                     const struct nfs3_mkdirargs *args)
5221  {
5222         encode_diropargs3(xdr, args->fh, args->name, args->len);
5223 -       encode_sattr3(xdr, args->sattr);
5224 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5225  }
5226  
5227  /*
5228 @@ -1091,9 +1097,9 @@ static void nfs3_xdr_enc_mkdir3args(stru
5229   *     };
5230   */
5231  static void encode_symlinkdata3(struct xdr_stream *xdr,
5232 -                               const struct nfs3_symlinkargs *args)
5233 +       const struct nfs3_symlinkargs *args, int tag)
5234  {
5235 -       encode_sattr3(xdr, args->sattr);
5236 +       encode_sattr3(xdr, args->sattr, tag);
5237         encode_nfspath3(xdr, args->pages, args->pathlen);
5238  }
5239  
5240 @@ -1102,7 +1108,7 @@ static void nfs3_xdr_enc_symlink3args(st
5241                                       const struct nfs3_symlinkargs *args)
5242  {
5243         encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen);
5244 -       encode_symlinkdata3(xdr, args);
5245 +       encode_symlinkdata3(xdr, args, req->rq_task->tk_client->cl_tag);
5246  }
5247  
5248  /*
5249 @@ -1130,24 +1136,24 @@ static void nfs3_xdr_enc_symlink3args(st
5250   *     };
5251   */
5252  static void encode_devicedata3(struct xdr_stream *xdr,
5253 -                              const struct nfs3_mknodargs *args)
5254 +       const struct nfs3_mknodargs *args, int tag)
5255  {
5256 -       encode_sattr3(xdr, args->sattr);
5257 +       encode_sattr3(xdr, args->sattr, tag);
5258         encode_specdata3(xdr, args->rdev);
5259  }
5260  
5261  static void encode_mknoddata3(struct xdr_stream *xdr,
5262 -                             const struct nfs3_mknodargs *args)
5263 +       const struct nfs3_mknodargs *args, int tag)
5264  {
5265         encode_ftype3(xdr, args->type);
5266         switch (args->type) {
5267         case NF3CHR:
5268         case NF3BLK:
5269 -               encode_devicedata3(xdr, args);
5270 +               encode_devicedata3(xdr, args, tag);
5271                 break;
5272         case NF3SOCK:
5273         case NF3FIFO:
5274 -               encode_sattr3(xdr, args->sattr);
5275 +               encode_sattr3(xdr, args->sattr, tag);
5276                 break;
5277         case NF3REG:
5278         case NF3DIR:
5279 @@ -1162,7 +1168,7 @@ static void nfs3_xdr_enc_mknod3args(stru
5280                                     const struct nfs3_mknodargs *args)
5281  {
5282         encode_diropargs3(xdr, args->fh, args->name, args->len);
5283 -       encode_mknoddata3(xdr, args);
5284 +       encode_mknoddata3(xdr, args, req->rq_task->tk_client->cl_tag);
5285  }
5286  
5287  /*
5288 diff -NurpP --minimal linux-3.10.33/fs/nfs/super.c linux-3.10.33-vs2.3.6.8/fs/nfs/super.c
5289 --- linux-3.10.33/fs/nfs/super.c        2013-07-14 17:01:28.000000000 +0000
5290 +++ linux-3.10.33-vs2.3.6.8/fs/nfs/super.c      2013-08-22 20:29:59.000000000 +0000
5291 @@ -55,6 +55,7 @@
5292  #include <linux/parser.h>
5293  #include <linux/nsproxy.h>
5294  #include <linux/rcupdate.h>
5295 +#include <linux/vs_tag.h>
5296  
5297  #include <asm/uaccess.h>
5298  
5299 @@ -103,6 +104,7 @@ enum {
5300         Opt_mountport,
5301         Opt_mountvers,
5302         Opt_minorversion,
5303 +       Opt_tagid,
5304  
5305         /* Mount options that take string arguments */
5306         Opt_nfsvers,
5307 @@ -115,6 +117,9 @@ enum {
5308         /* Special mount options */
5309         Opt_userspace, Opt_deprecated, Opt_sloppy,
5310  
5311 +       /* Linux-VServer tagging options */
5312 +       Opt_tag, Opt_notag,
5313 +
5314         Opt_err
5315  };
5316  
5317 @@ -184,6 +189,10 @@ static const match_table_t nfs_mount_opt
5318         { Opt_fscache_uniq, "fsc=%s" },
5319         { Opt_local_lock, "local_lock=%s" },
5320  
5321 +       { Opt_tag, "tag" },
5322 +       { Opt_notag, "notag" },
5323 +       { Opt_tagid, "tagid=%u" },
5324 +
5325         /* The following needs to be listed after all other options */
5326         { Opt_nfsvers, "v%s" },
5327  
5328 @@ -635,6 +644,7 @@ static void nfs_show_mount_options(struc
5329                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
5330                 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
5331                 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
5332 +               { NFS_MOUNT_TAGGED, ",tag", "" },
5333                 { 0, NULL, NULL }
5334         };
5335         const struct proc_nfs_info *nfs_infop;
5336 @@ -1261,6 +1271,14 @@ static int nfs_parse_mount_options(char
5337                 case Opt_nomigration:
5338                         mnt->options &= NFS_OPTION_MIGRATION;
5339                         break;
5340 +#ifndef CONFIG_TAGGING_NONE
5341 +               case Opt_tag:
5342 +                       mnt->flags |= NFS_MOUNT_TAGGED;
5343 +                       break;
5344 +               case Opt_notag:
5345 +                       mnt->flags &= ~NFS_MOUNT_TAGGED;
5346 +                       break;
5347 +#endif
5348  
5349                 /*
5350                  * options that take numeric values
5351 @@ -1347,6 +1365,12 @@ static int nfs_parse_mount_options(char
5352                                 goto out_invalid_value;
5353                         mnt->minorversion = option;
5354                         break;
5355 +#ifdef CONFIG_PROPAGATE
5356 +               case Opt_tagid:
5357 +                       /* use args[0] */
5358 +                       nfs_data.flags |= NFS_MOUNT_TAGGED;
5359 +                       break;
5360 +#endif
5361  
5362                 /*
5363                  * options that take text values
5364 diff -NurpP --minimal linux-3.10.33/fs/nfsd/auth.c linux-3.10.33-vs2.3.6.8/fs/nfsd/auth.c
5365 --- linux-3.10.33/fs/nfsd/auth.c        2013-05-31 13:45:24.000000000 +0000
5366 +++ linux-3.10.33-vs2.3.6.8/fs/nfsd/auth.c      2013-08-22 20:29:59.000000000 +0000
5367 @@ -2,6 +2,7 @@
5368  
5369  #include <linux/sched.h>
5370  #include <linux/user_namespace.h>
5371 +#include <linux/vs_tag.h>
5372  #include "nfsd.h"
5373  #include "auth.h"
5374  
5375 @@ -37,6 +38,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
5376  
5377         new->fsuid = rqstp->rq_cred.cr_uid;
5378         new->fsgid = rqstp->rq_cred.cr_gid;
5379 +       /* FIXME: this desperately needs a tag :)
5380 +       new->xid = (vxid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
5381 +                       */
5382  
5383         rqgi = rqstp->rq_cred.cr_group_info;
5384  
5385 diff -NurpP --minimal linux-3.10.33/fs/nfsd/nfs3xdr.c linux-3.10.33-vs2.3.6.8/fs/nfsd/nfs3xdr.c
5386 --- linux-3.10.33/fs/nfsd/nfs3xdr.c     2013-05-31 13:45:24.000000000 +0000
5387 +++ linux-3.10.33-vs2.3.6.8/fs/nfsd/nfs3xdr.c   2013-08-22 20:29:59.000000000 +0000
5388 @@ -8,6 +8,7 @@
5389  
5390  #include <linux/namei.h>
5391  #include <linux/sunrpc/svc_xprt.h>
5392 +#include <linux/vs_tag.h>
5393  #include "xdr3.h"
5394  #include "auth.h"
5395  #include "netns.h"
5396 @@ -98,6 +99,8 @@ static __be32 *
5397  decode_sattr3(__be32 *p, struct iattr *iap)
5398  {
5399         u32     tmp;
5400 +       kuid_t  kuid = GLOBAL_ROOT_UID;
5401 +       kgid_t  kgid = GLOBAL_ROOT_GID;
5402  
5403         iap->ia_valid = 0;
5404  
5405 @@ -106,15 +109,18 @@ decode_sattr3(__be32 *p, struct iattr *i
5406                 iap->ia_mode = ntohl(*p++);
5407         }
5408         if (*p++) {
5409 -               iap->ia_uid = make_kuid(&init_user_ns, ntohl(*p++));
5410 +               kuid = make_kuid(&init_user_ns, ntohl(*p++));
5411                 if (uid_valid(iap->ia_uid))
5412                         iap->ia_valid |= ATTR_UID;
5413         }
5414         if (*p++) {
5415 -               iap->ia_gid = make_kgid(&init_user_ns, ntohl(*p++));
5416 +               kgid = make_kgid(&init_user_ns, ntohl(*p++));
5417                 if (gid_valid(iap->ia_gid))
5418                         iap->ia_valid |= ATTR_GID;
5419         }
5420 +       iap->ia_uid = INOTAG_KUID(DX_TAG_NFSD, kuid, kgid);
5421 +       iap->ia_gid = INOTAG_KGID(DX_TAG_NFSD, kuid, kgid);
5422 +       iap->ia_tag = INOTAG_KTAG(DX_TAG_NFSD, kuid, kgid, GLOBAL_ROOT_TAG);
5423         if (*p++) {
5424                 u64     newsize;
5425  
5426 @@ -170,8 +176,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
5427         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
5428         *p++ = htonl((u32) stat->mode);
5429         *p++ = htonl((u32) stat->nlink);
5430 -       *p++ = htonl((u32) from_kuid(&init_user_ns, stat->uid));
5431 -       *p++ = htonl((u32) from_kgid(&init_user_ns, stat->gid));
5432 +       *p++ = htonl((u32) from_kuid(&init_user_ns,
5433 +               TAGINO_KUID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5434 +               stat->uid, stat->tag)));
5435 +       *p++ = htonl((u32) from_kgid(&init_user_ns,
5436 +               TAGINO_KGID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5437 +               stat->gid, stat->tag)));
5438         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
5439                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
5440         } else {
5441 diff -NurpP --minimal linux-3.10.33/fs/nfsd/nfs4xdr.c linux-3.10.33-vs2.3.6.8/fs/nfsd/nfs4xdr.c
5442 --- linux-3.10.33/fs/nfsd/nfs4xdr.c     2014-03-12 13:16:02.000000000 +0000
5443 +++ linux-3.10.33-vs2.3.6.8/fs/nfsd/nfs4xdr.c   2013-11-13 17:17:16.000000000 +0000
5444 @@ -46,6 +46,7 @@
5445  #include <linux/utsname.h>
5446  #include <linux/pagemap.h>
5447  #include <linux/sunrpc/svcauth_gss.h>
5448 +#include <linux/vs_tag.h>
5449  
5450  #include "idmap.h"
5451  #include "acl.h"
5452 @@ -2320,14 +2321,18 @@ out_acl:
5453                 WRITE32(stat.nlink);
5454         }
5455         if (bmval1 & FATTR4_WORD1_OWNER) {
5456 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
5457 +               status = nfsd4_encode_user(rqstp,
5458 +                       TAGINO_KUID(DX_TAG(dentry->d_inode),
5459 +                       stat.uid, stat.tag), &p, &buflen);
5460                 if (status == nfserr_resource)
5461                         goto out_resource;
5462                 if (status)
5463                         goto out;
5464         }
5465         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
5466 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
5467 +               status = nfsd4_encode_group(rqstp,
5468 +                       TAGINO_KGID(DX_TAG(dentry->d_inode),
5469 +                       stat.gid, stat.tag), &p, &buflen);
5470                 if (status == nfserr_resource)
5471                         goto out_resource;
5472                 if (status)
5473 diff -NurpP --minimal linux-3.10.33/fs/nfsd/nfsxdr.c linux-3.10.33-vs2.3.6.8/fs/nfsd/nfsxdr.c
5474 --- linux-3.10.33/fs/nfsd/nfsxdr.c      2013-05-31 13:45:24.000000000 +0000
5475 +++ linux-3.10.33-vs2.3.6.8/fs/nfsd/nfsxdr.c    2013-08-22 20:29:59.000000000 +0000
5476 @@ -7,6 +7,7 @@
5477  #include "vfs.h"
5478  #include "xdr.h"
5479  #include "auth.h"
5480 +#include <linux/vs_tag.h>
5481  
5482  #define NFSDDBG_FACILITY               NFSDDBG_XDR
5483  
5484 @@ -89,6 +90,8 @@ static __be32 *
5485  decode_sattr(__be32 *p, struct iattr *iap)
5486  {
5487         u32     tmp, tmp1;
5488 +       kuid_t  kuid = GLOBAL_ROOT_UID;
5489 +       kgid_t  kgid = GLOBAL_ROOT_GID;
5490  
5491         iap->ia_valid = 0;
5492  
5493 @@ -101,15 +104,18 @@ decode_sattr(__be32 *p, struct iattr *ia
5494                 iap->ia_mode = tmp;
5495         }
5496         if ((tmp = ntohl(*p++)) != (u32)-1) {
5497 -               iap->ia_uid = make_kuid(&init_user_ns, tmp);
5498 +               kuid = make_kuid(&init_user_ns, tmp);
5499                 if (uid_valid(iap->ia_uid))
5500                         iap->ia_valid |= ATTR_UID;
5501         }
5502         if ((tmp = ntohl(*p++)) != (u32)-1) {
5503 -               iap->ia_gid = make_kgid(&init_user_ns, tmp);
5504 +               kgid = make_kgid(&init_user_ns, tmp);
5505                 if (gid_valid(iap->ia_gid))
5506                         iap->ia_valid |= ATTR_GID;
5507         }
5508 +       iap->ia_uid = INOTAG_KUID(DX_TAG_NFSD, kuid, kgid);
5509 +       iap->ia_gid = INOTAG_KGID(DX_TAG_NFSD, kuid, kgid);
5510 +       iap->ia_tag = INOTAG_KTAG(DX_TAG_NFSD, kuid, kgid, GLOBAL_ROOT_TAG);
5511         if ((tmp = ntohl(*p++)) != (u32)-1) {
5512                 iap->ia_valid |= ATTR_SIZE;
5513                 iap->ia_size = tmp;
5514 @@ -154,8 +160,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
5515         *p++ = htonl(nfs_ftypes[type >> 12]);
5516         *p++ = htonl((u32) stat->mode);
5517         *p++ = htonl((u32) stat->nlink);
5518 -       *p++ = htonl((u32) from_kuid(&init_user_ns, stat->uid));
5519 -       *p++ = htonl((u32) from_kgid(&init_user_ns, stat->gid));
5520 +       *p++ = htonl((u32) from_kuid(&init_user_ns,
5521 +               TAGINO_KUID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
5522 +       *p++ = htonl((u32) from_kgid(&init_user_ns,
5523 +               TAGINO_KGID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
5524  
5525         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
5526                 *p++ = htonl(NFS_MAXPATHLEN);
5527 diff -NurpP --minimal linux-3.10.33/fs/ocfs2/dlmglue.c linux-3.10.33-vs2.3.6.8/fs/ocfs2/dlmglue.c
5528 --- linux-3.10.33/fs/ocfs2/dlmglue.c    2013-07-14 17:01:29.000000000 +0000
5529 +++ linux-3.10.33-vs2.3.6.8/fs/ocfs2/dlmglue.c  2013-08-22 20:29:59.000000000 +0000
5530 @@ -2047,6 +2047,7 @@ static void __ocfs2_stuff_meta_lvb(struc
5531         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
5532         lvb->lvb_iuid      = cpu_to_be32(i_uid_read(inode));
5533         lvb->lvb_igid      = cpu_to_be32(i_gid_read(inode));
5534 +       lvb->lvb_itag      = cpu_to_be16(i_tag_read(inode));
5535         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
5536         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
5537         lvb->lvb_iatime_packed  =
5538 @@ -2097,6 +2098,7 @@ static void ocfs2_refresh_inode_from_lvb
5539  
5540         i_uid_write(inode, be32_to_cpu(lvb->lvb_iuid));
5541         i_gid_write(inode, be32_to_cpu(lvb->lvb_igid));
5542 +       i_tag_write(inode, be16_to_cpu(lvb->lvb_itag));
5543         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
5544         set_nlink(inode, be16_to_cpu(lvb->lvb_inlink));
5545         ocfs2_unpack_timespec(&inode->i_atime,
5546 diff -NurpP --minimal linux-3.10.33/fs/ocfs2/dlmglue.h linux-3.10.33-vs2.3.6.8/fs/ocfs2/dlmglue.h
5547 --- linux-3.10.33/fs/ocfs2/dlmglue.h    2012-12-11 03:30:57.000000000 +0000
5548 +++ linux-3.10.33-vs2.3.6.8/fs/ocfs2/dlmglue.h  2013-08-22 20:29:59.000000000 +0000
5549 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
5550         __be16       lvb_inlink;
5551         __be32       lvb_iattr;
5552         __be32       lvb_igeneration;
5553 -       __be32       lvb_reserved2;
5554 +       __be16       lvb_itag;
5555 +       __be16       lvb_reserved2;
5556  };
5557  
5558  #define OCFS2_QINFO_LVB_VERSION 1
5559 diff -NurpP --minimal linux-3.10.33/fs/ocfs2/file.c linux-3.10.33-vs2.3.6.8/fs/ocfs2/file.c
5560 --- linux-3.10.33/fs/ocfs2/file.c       2013-07-14 17:01:29.000000000 +0000
5561 +++ linux-3.10.33-vs2.3.6.8/fs/ocfs2/file.c     2013-08-22 20:29:59.000000000 +0000
5562 @@ -1124,7 +1124,7 @@ int ocfs2_setattr(struct dentry *dentry,
5563                 attr->ia_valid &= ~ATTR_SIZE;
5564  
5565  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
5566 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
5567 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
5568         if (!(attr->ia_valid & OCFS2_VALID_ATTRS))
5569                 return 0;
5570  
5571 diff -NurpP --minimal linux-3.10.33/fs/ocfs2/inode.c linux-3.10.33-vs2.3.6.8/fs/ocfs2/inode.c
5572 --- linux-3.10.33/fs/ocfs2/inode.c      2013-05-31 13:45:24.000000000 +0000
5573 +++ linux-3.10.33-vs2.3.6.8/fs/ocfs2/inode.c    2013-08-22 20:29:59.000000000 +0000
5574 @@ -28,6 +28,7 @@
5575  #include <linux/highmem.h>
5576  #include <linux/pagemap.h>
5577  #include <linux/quotaops.h>
5578 +#include <linux/vs_tag.h>
5579  
5580  #include <asm/byteorder.h>
5581  
5582 @@ -78,11 +79,13 @@ void ocfs2_set_inode_flags(struct inode
5583  {
5584         unsigned int flags = OCFS2_I(inode)->ip_attr;
5585  
5586 -       inode->i_flags &= ~(S_IMMUTABLE |
5587 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
5588                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
5589  
5590         if (flags & OCFS2_IMMUTABLE_FL)
5591                 inode->i_flags |= S_IMMUTABLE;
5592 +       if (flags & OCFS2_IXUNLINK_FL)
5593 +               inode->i_flags |= S_IXUNLINK;
5594  
5595         if (flags & OCFS2_SYNC_FL)
5596                 inode->i_flags |= S_SYNC;
5597 @@ -92,25 +95,44 @@ void ocfs2_set_inode_flags(struct inode
5598                 inode->i_flags |= S_NOATIME;
5599         if (flags & OCFS2_DIRSYNC_FL)
5600                 inode->i_flags |= S_DIRSYNC;
5601 +
5602 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
5603 +
5604 +       if (flags & OCFS2_BARRIER_FL)
5605 +               inode->i_vflags |= V_BARRIER;
5606 +       if (flags & OCFS2_COW_FL)
5607 +               inode->i_vflags |= V_COW;
5608  }
5609  
5610  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
5611  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
5612  {
5613         unsigned int flags = oi->vfs_inode.i_flags;
5614 +       unsigned int vflags = oi->vfs_inode.i_vflags;
5615 +
5616 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
5617 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
5618 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
5619 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
5620 +
5621 +       if (flags & S_IMMUTABLE)
5622 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5623 +       if (flags & S_IXUNLINK)
5624 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
5625  
5626 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
5627 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
5628         if (flags & S_SYNC)
5629                 oi->ip_attr |= OCFS2_SYNC_FL;
5630         if (flags & S_APPEND)
5631                 oi->ip_attr |= OCFS2_APPEND_FL;
5632 -       if (flags & S_IMMUTABLE)
5633 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5634         if (flags & S_NOATIME)
5635                 oi->ip_attr |= OCFS2_NOATIME_FL;
5636         if (flags & S_DIRSYNC)
5637                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
5638 +
5639 +       if (vflags & V_BARRIER)
5640 +               oi->ip_attr |= OCFS2_BARRIER_FL;
5641 +       if (vflags & V_COW)
5642 +               oi->ip_attr |= OCFS2_COW_FL;
5643  }
5644  
5645  struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
5646 @@ -241,6 +263,8 @@ void ocfs2_populate_inode(struct inode *
5647         struct super_block *sb;
5648         struct ocfs2_super *osb;
5649         int use_plocks = 1;
5650 +       uid_t uid;
5651 +       gid_t gid;
5652  
5653         sb = inode->i_sb;
5654         osb = OCFS2_SB(sb);
5655 @@ -269,8 +293,12 @@ void ocfs2_populate_inode(struct inode *
5656         inode->i_generation = le32_to_cpu(fe->i_generation);
5657         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
5658         inode->i_mode = le16_to_cpu(fe->i_mode);
5659 -       i_uid_write(inode, le32_to_cpu(fe->i_uid));
5660 -       i_gid_write(inode, le32_to_cpu(fe->i_gid));
5661 +       uid = le32_to_cpu(fe->i_uid);
5662 +       gid = le32_to_cpu(fe->i_gid);
5663 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), uid, gid));
5664 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), uid, gid));
5665 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), uid, gid,
5666 +               /* le16_to_cpu(raw_inode->i_raw_tag) */ 0));
5667  
5668         /* Fast symlinks will have i_size but no allocated clusters. */
5669         if (S_ISLNK(inode->i_mode) && !fe->i_clusters) {
5670 diff -NurpP --minimal linux-3.10.33/fs/ocfs2/inode.h linux-3.10.33-vs2.3.6.8/fs/ocfs2/inode.h
5671 --- linux-3.10.33/fs/ocfs2/inode.h      2013-07-14 17:01:29.000000000 +0000
5672 +++ linux-3.10.33-vs2.3.6.8/fs/ocfs2/inode.h    2013-08-22 20:29:59.000000000 +0000
5673 @@ -152,6 +152,7 @@ struct buffer_head *ocfs2_bread(struct i
5674  
5675  void ocfs2_set_inode_flags(struct inode *inode);
5676  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
5677 +int ocfs2_sync_flags(struct inode *inode, int, int);
5678  
5679  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
5680  {
5681 diff -NurpP --minimal linux-3.10.33/fs/ocfs2/ioctl.c linux-3.10.33-vs2.3.6.8/fs/ocfs2/ioctl.c
5682 --- linux-3.10.33/fs/ocfs2/ioctl.c      2013-07-14 17:01:29.000000000 +0000
5683 +++ linux-3.10.33-vs2.3.6.8/fs/ocfs2/ioctl.c    2013-08-22 20:29:59.000000000 +0000
5684 @@ -76,7 +76,41 @@ static int ocfs2_get_inode_attr(struct i
5685         return status;
5686  }
5687  
5688 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5689 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
5690 +{
5691 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
5692 +       struct buffer_head *bh = NULL;
5693 +       handle_t *handle = NULL;
5694 +       int status;
5695 +
5696 +       status = ocfs2_inode_lock(inode, &bh, 1);
5697 +       if (status < 0) {
5698 +               mlog_errno(status);
5699 +               return status;
5700 +       }
5701 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5702 +       if (IS_ERR(handle)) {
5703 +               status = PTR_ERR(handle);
5704 +               mlog_errno(status);
5705 +               goto bail_unlock;
5706 +       }
5707 +
5708 +       inode->i_flags = flags;
5709 +       inode->i_vflags = vflags;
5710 +       ocfs2_get_inode_flags(OCFS2_I(inode));
5711 +
5712 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
5713 +       if (status < 0)
5714 +               mlog_errno(status);
5715 +
5716 +       ocfs2_commit_trans(osb, handle);
5717 +bail_unlock:
5718 +       ocfs2_inode_unlock(inode, 1);
5719 +       brelse(bh);
5720 +       return status;
5721 +}
5722 +
5723 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5724                                 unsigned mask)
5725  {
5726         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
5727 @@ -116,6 +150,11 @@ static int ocfs2_set_inode_attr(struct i
5728                         goto bail_unlock;
5729         }
5730  
5731 +       if (IS_BARRIER(inode)) {
5732 +               vxwprintk_task(1, "messing with the barrier.");
5733 +               goto bail_unlock;
5734 +       }
5735 +
5736         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5737         if (IS_ERR(handle)) {
5738                 status = PTR_ERR(handle);
5739 @@ -881,6 +920,7 @@ bail:
5740         return status;
5741  }
5742  
5743 +
5744  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
5745  {
5746         struct inode *inode = file_inode(filp);
5747 diff -NurpP --minimal linux-3.10.33/fs/ocfs2/namei.c linux-3.10.33-vs2.3.6.8/fs/ocfs2/namei.c
5748 --- linux-3.10.33/fs/ocfs2/namei.c      2013-07-14 17:01:29.000000000 +0000
5749 +++ linux-3.10.33-vs2.3.6.8/fs/ocfs2/namei.c    2013-08-22 20:29:59.000000000 +0000
5750 @@ -41,6 +41,7 @@
5751  #include <linux/slab.h>
5752  #include <linux/highmem.h>
5753  #include <linux/quotaops.h>
5754 +#include <linux/vs_tag.h>
5755  
5756  #include <cluster/masklog.h>
5757  
5758 @@ -475,6 +476,7 @@ static int __ocfs2_mknod_locked(struct i
5759         struct ocfs2_dinode *fe = NULL;
5760         struct ocfs2_extent_list *fel;
5761         u16 feat;
5762 +       ktag_t ktag;
5763  
5764         *new_fe_bh = NULL;
5765  
5766 @@ -512,8 +514,13 @@ static int __ocfs2_mknod_locked(struct i
5767         fe->i_suballoc_loc = cpu_to_le64(suballoc_loc);
5768         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
5769         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
5770 -       fe->i_uid = cpu_to_le32(i_uid_read(inode));
5771 -       fe->i_gid = cpu_to_le32(i_gid_read(inode));
5772 +
5773 +       ktag = make_ktag(&init_user_ns, dx_current_fstag(osb->sb));
5774 +       fe->i_uid = cpu_to_le32(from_kuid(&init_user_ns,
5775 +               TAGINO_KUID(DX_TAG(inode), inode->i_uid, ktag)));
5776 +       fe->i_gid = cpu_to_le32(from_kgid(&init_user_ns,
5777 +               TAGINO_KGID(DX_TAG(inode), inode->i_gid, ktag)));
5778 +       inode->i_tag = ktag; /* is this correct? */
5779         fe->i_mode = cpu_to_le16(inode->i_mode);
5780         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
5781                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
5782 diff -NurpP --minimal linux-3.10.33/fs/ocfs2/ocfs2.h linux-3.10.33-vs2.3.6.8/fs/ocfs2/ocfs2.h
5783 --- linux-3.10.33/fs/ocfs2/ocfs2.h      2012-12-11 03:30:57.000000000 +0000
5784 +++ linux-3.10.33-vs2.3.6.8/fs/ocfs2/ocfs2.h    2013-08-22 20:29:59.000000000 +0000
5785 @@ -272,6 +272,7 @@ enum ocfs2_mount_options
5786                                                      writes */
5787         OCFS2_MOUNT_HB_NONE = 1 << 13, /* No heartbeat */
5788         OCFS2_MOUNT_HB_GLOBAL = 1 << 14, /* Global heartbeat */
5789 +       OCFS2_MOUNT_TAGGED = 1 << 15, /* use tagging */
5790  };
5791  
5792  #define OCFS2_OSB_SOFT_RO                      0x0001
5793 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
5794 --- linux-3.10.33/fs/ocfs2/ocfs2_fs.h   2012-12-11 03:30:57.000000000 +0000
5795 +++ linux-3.10.33-vs2.3.6.8/fs/ocfs2/ocfs2_fs.h 2013-08-22 20:29:59.000000000 +0000
5796 @@ -266,6 +266,11 @@
5797  #define OCFS2_TOPDIR_FL                        FS_TOPDIR_FL    /* Top of directory hierarchies*/
5798  #define OCFS2_RESERVED_FL              FS_RESERVED_FL  /* reserved for ext2 lib */
5799  
5800 +#define OCFS2_IXUNLINK_FL              FS_IXUNLINK_FL  /* Immutable invert on unlink */
5801 +
5802 +#define OCFS2_BARRIER_FL               FS_BARRIER_FL   /* Barrier for chroot() */
5803 +#define OCFS2_COW_FL                   FS_COW_FL       /* Copy on Write marker */
5804 +
5805  #define OCFS2_FL_VISIBLE               FS_FL_USER_VISIBLE      /* User visible flags */
5806  #define OCFS2_FL_MODIFIABLE            FS_FL_USER_MODIFIABLE   /* User modifiable flags */
5807  
5808 diff -NurpP --minimal linux-3.10.33/fs/ocfs2/super.c linux-3.10.33-vs2.3.6.8/fs/ocfs2/super.c
5809 --- linux-3.10.33/fs/ocfs2/super.c      2013-05-31 13:45:25.000000000 +0000
5810 +++ linux-3.10.33-vs2.3.6.8/fs/ocfs2/super.c    2013-08-22 20:29:59.000000000 +0000
5811 @@ -185,6 +185,7 @@ enum {
5812         Opt_coherency_full,
5813         Opt_resv_level,
5814         Opt_dir_resv_level,
5815 +       Opt_tag, Opt_notag, Opt_tagid,
5816         Opt_err,
5817  };
5818  
5819 @@ -216,6 +217,9 @@ static const match_table_t tokens = {
5820         {Opt_coherency_full, "coherency=full"},
5821         {Opt_resv_level, "resv_level=%u"},
5822         {Opt_dir_resv_level, "dir_resv_level=%u"},
5823 +       {Opt_tag, "tag"},
5824 +       {Opt_notag, "notag"},
5825 +       {Opt_tagid, "tagid=%u"},
5826         {Opt_err, NULL}
5827  };
5828  
5829 @@ -662,6 +666,13 @@ static int ocfs2_remount(struct super_bl
5830                 goto out;
5831         }
5832  
5833 +       if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
5834 +           (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
5835 +               ret = -EINVAL;
5836 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
5837 +               goto out;
5838 +       }
5839 +
5840         /* We're going to/from readonly mode. */
5841         if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
5842                 /* Disable quota accounting before remounting RO */
5843 @@ -1177,6 +1188,9 @@ static int ocfs2_fill_super(struct super
5844  
5845         ocfs2_complete_mount_recovery(osb);
5846  
5847 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
5848 +               sb->s_flags |= MS_TAGGED;
5849 +
5850         if (ocfs2_mount_local(osb))
5851                 snprintf(nodestr, sizeof(nodestr), "local");
5852         else
5853 @@ -1504,6 +1518,20 @@ static int ocfs2_parse_options(struct su
5854                             option < OCFS2_MAX_RESV_LEVEL)
5855                                 mopt->dir_resv_level = option;
5856                         break;
5857 +#ifndef CONFIG_TAGGING_NONE
5858 +               case Opt_tag:
5859 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5860 +                       break;
5861 +               case Opt_notag:
5862 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
5863 +                       break;
5864 +#endif
5865 +#ifdef CONFIG_PROPAGATE
5866 +               case Opt_tagid:
5867 +                       /* use args[0] */
5868 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5869 +                       break;
5870 +#endif
5871                 default:
5872                         mlog(ML_ERROR,
5873                              "Unrecognized mount option \"%s\" "
5874 diff -NurpP --minimal linux-3.10.33/fs/open.c linux-3.10.33-vs2.3.6.8/fs/open.c
5875 --- linux-3.10.33/fs/open.c     2013-07-14 17:01:29.000000000 +0000
5876 +++ linux-3.10.33-vs2.3.6.8/fs/open.c   2013-08-22 20:29:59.000000000 +0000
5877 @@ -31,6 +31,11 @@
5878  #include <linux/ima.h>
5879  #include <linux/dnotify.h>
5880  #include <linux/compat.h>
5881 +#include <linux/vs_base.h>
5882 +#include <linux/vs_limit.h>
5883 +#include <linux/vs_tag.h>
5884 +#include <linux/vs_cowbl.h>
5885 +#include <linux/vserver/dlimit.h>
5886  
5887  #include "internal.h"
5888  
5889 @@ -67,6 +72,11 @@ long vfs_truncate(struct path *path, lof
5890         struct inode *inode;
5891         long error;
5892  
5893 +#ifdef CONFIG_VSERVER_COWBL
5894 +       error = cow_check_and_break(path);
5895 +       if (error)
5896 +               goto out;
5897 +#endif
5898         inode = path->dentry->d_inode;
5899  
5900         /* For directories it's -EISDIR, for other non-regulars - -EINVAL */
5901 @@ -504,6 +514,13 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
5902         unsigned int lookup_flags = LOOKUP_FOLLOW;
5903  retry:
5904         error = user_path_at(dfd, filename, lookup_flags, &path);
5905 +#ifdef CONFIG_VSERVER_COWBL
5906 +       if (!error) {
5907 +               error = cow_check_and_break(&path);
5908 +               if (error)
5909 +                       path_put(&path);
5910 +       }
5911 +#endif
5912         if (!error) {
5913                 error = chmod_common(&path, mode);
5914                 path_put(&path);
5915 @@ -536,13 +553,15 @@ static int chown_common(struct path *pat
5916                 if (!uid_valid(uid))
5917                         return -EINVAL;
5918                 newattrs.ia_valid |= ATTR_UID;
5919 -               newattrs.ia_uid = uid;
5920 +               newattrs.ia_uid = make_kuid(&init_user_ns,
5921 +                       dx_map_uid(user));
5922         }
5923         if (group != (gid_t) -1) {
5924                 if (!gid_valid(gid))
5925                         return -EINVAL;
5926                 newattrs.ia_valid |= ATTR_GID;
5927 -               newattrs.ia_gid = gid;
5928 +               newattrs.ia_gid = make_kgid(&init_user_ns,
5929 +                       dx_map_gid(group));
5930         }
5931         if (!S_ISDIR(inode->i_mode))
5932                 newattrs.ia_valid |=
5933 @@ -576,6 +595,18 @@ retry:
5934         error = mnt_want_write(path.mnt);
5935         if (error)
5936                 goto out_release;
5937 +#ifdef CONFIG_VSERVER_COWBL
5938 +       error = cow_check_and_break(&path);
5939 +       if (!error)
5940 +#endif
5941 +#ifdef CONFIG_VSERVER_COWBL
5942 +       error = cow_check_and_break(&path);
5943 +       if (!error)
5944 +#endif
5945 +#ifdef CONFIG_VSERVER_COWBL
5946 +       error = cow_check_and_break(&path);
5947 +       if (!error)
5948 +#endif
5949         error = chown_common(&path, user, group);
5950         mnt_drop_write(path.mnt);
5951  out_release:
5952 diff -NurpP --minimal linux-3.10.33/fs/proc/array.c linux-3.10.33-vs2.3.6.8/fs/proc/array.c
5953 --- linux-3.10.33/fs/proc/array.c       2013-05-31 13:45:25.000000000 +0000
5954 +++ linux-3.10.33-vs2.3.6.8/fs/proc/array.c     2013-08-22 20:29:59.000000000 +0000
5955 @@ -82,6 +82,8 @@
5956  #include <linux/ptrace.h>
5957  #include <linux/tracehook.h>
5958  #include <linux/user_namespace.h>
5959 +#include <linux/vs_context.h>
5960 +#include <linux/vs_network.h>
5961  
5962  #include <asm/pgtable.h>
5963  #include <asm/processor.h>
5964 @@ -173,6 +175,9 @@ static inline void task_state(struct seq
5965         rcu_read_lock();
5966         ppid = pid_alive(p) ?
5967                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
5968 +       if (unlikely(vx_current_initpid(p->pid)))
5969 +               ppid = 0;
5970 +
5971         tpid = 0;
5972         if (pid_alive(p)) {
5973                 struct task_struct *tracer = ptrace_parent(p);
5974 @@ -297,7 +302,7 @@ static inline void task_sig(struct seq_f
5975  }
5976  
5977  static void render_cap_t(struct seq_file *m, const char *header,
5978 -                       kernel_cap_t *a)
5979 +                       struct vx_info *vxi, kernel_cap_t *a)
5980  {
5981         unsigned __capi;
5982  
5983 @@ -331,10 +336,11 @@ static inline void task_cap(struct seq_f
5984         NORM_CAPS(cap_effective);
5985         NORM_CAPS(cap_bset);
5986  
5987 -       render_cap_t(m, "CapInh:\t", &cap_inheritable);
5988 -       render_cap_t(m, "CapPrm:\t", &cap_permitted);
5989 -       render_cap_t(m, "CapEff:\t", &cap_effective);
5990 -       render_cap_t(m, "CapBnd:\t", &cap_bset);
5991 +       /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
5992 +       render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
5993 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
5994 +       render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
5995 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
5996  }
5997  
5998  static inline void task_seccomp(struct seq_file *m, struct task_struct *p)
5999 @@ -363,6 +369,42 @@ static void task_cpus_allowed(struct seq
6000         seq_putc(m, '\n');
6001  }
6002  
6003 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6004 +                       struct pid *pid, struct task_struct *task)
6005 +{
6006 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
6007 +                       "Count:\t%u\n"
6008 +                       "uts:\t%p(%c)\n"
6009 +                       "ipc:\t%p(%c)\n"
6010 +                       "mnt:\t%p(%c)\n"
6011 +                       "pid:\t%p(%c)\n"
6012 +                       "net:\t%p(%c)\n",
6013 +                       task->nsproxy,
6014 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6015 +                       atomic_read(&task->nsproxy->count),
6016 +                       task->nsproxy->uts_ns,
6017 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6018 +                       task->nsproxy->ipc_ns,
6019 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6020 +                       task->nsproxy->mnt_ns,
6021 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6022 +                       task->nsproxy->pid_ns,
6023 +                       (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
6024 +                       task->nsproxy->net_ns,
6025 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6026 +       return 0;
6027 +}
6028 +
6029 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6030 +{
6031 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6032 +               return;
6033 +
6034 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6035 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6036 +}
6037 +
6038 +
6039  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6040                         struct pid *pid, struct task_struct *task)
6041  {
6042 @@ -380,6 +422,7 @@ int proc_pid_status(struct seq_file *m,
6043         task_seccomp(m, task);
6044         task_cpus_allowed(m, task);
6045         cpuset_task_status_allowed(m, task);
6046 +       task_vs_id(m, task);
6047         task_context_switch_counts(m, task);
6048         return 0;
6049  }
6050 @@ -489,6 +532,17 @@ static int do_task_stat(struct seq_file
6051         /* convert nsec -> ticks */
6052         start_time = nsec_to_clock_t(start_time);
6053  
6054 +       /* fixup start time for virt uptime */
6055 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6056 +               unsigned long long bias =
6057 +                       current->vx_info->cvirt.bias_clock;
6058 +
6059 +               if (start_time > bias)
6060 +                       start_time -= bias;
6061 +               else
6062 +                       start_time = 0;
6063 +       }
6064 +
6065         seq_printf(m, "%d (%s) %c", pid_nr_ns(pid, ns), tcomm, state);
6066         seq_put_decimal_ll(m, ' ', ppid);
6067         seq_put_decimal_ll(m, ' ', pgid);
6068 diff -NurpP --minimal linux-3.10.33/fs/proc/base.c linux-3.10.33-vs2.3.6.8/fs/proc/base.c
6069 --- linux-3.10.33/fs/proc/base.c        2013-07-14 17:01:29.000000000 +0000
6070 +++ linux-3.10.33-vs2.3.6.8/fs/proc/base.c      2013-08-22 22:18:21.000000000 +0000
6071 @@ -87,6 +87,8 @@
6072  #include <linux/slab.h>
6073  #include <linux/flex_array.h>
6074  #include <linux/posix-timers.h>
6075 +#include <linux/vs_context.h>
6076 +#include <linux/vs_network.h>
6077  #ifdef CONFIG_HARDWALL
6078  #include <asm/hardwall.h>
6079  #endif
6080 @@ -976,11 +978,15 @@ static ssize_t oom_adj_write(struct file
6081                 oom_adj = (oom_adj * OOM_SCORE_ADJ_MAX) / -OOM_DISABLE;
6082  
6083         if (oom_adj < task->signal->oom_score_adj &&
6084 -           !capable(CAP_SYS_RESOURCE)) {
6085 +           !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
6086                 err = -EACCES;
6087                 goto err_sighand;
6088         }
6089  
6090 +       /* prevent guest processes from circumventing the oom killer */
6091 +       if (vx_current_xid() && (oom_adj == OOM_DISABLE))
6092 +               oom_adj = OOM_ADJUST_MIN;
6093 +
6094         /*
6095          * /proc/pid/oom_adj is provided for legacy purposes, ask users to use
6096          * /proc/pid/oom_score_adj instead.
6097 @@ -1559,6 +1565,8 @@ struct inode *proc_pid_make_inode(struct
6098                 inode->i_gid = cred->egid;
6099                 rcu_read_unlock();
6100         }
6101 +       /* procfs is xid tagged */
6102 +       i_tag_write(inode, (vtag_t)vx_task_xid(task));
6103         security_task_to_inode(task, inode);
6104  
6105  out:
6106 @@ -1604,6 +1612,8 @@ int pid_getattr(struct vfsmount *mnt, st
6107  
6108  /* dentry stuff */
6109  
6110 +static unsigned name_to_int(struct dentry *dentry);
6111 +
6112  /*
6113   *     Exceptional case: normally we are not allowed to unhash a busy
6114   * directory. In this case, however, we can do it - no aliasing problems
6115 @@ -1632,6 +1642,12 @@ int pid_revalidate(struct dentry *dentry
6116         task = get_proc_task(inode);
6117  
6118         if (task) {
6119 +               unsigned pid = name_to_int(dentry);
6120 +
6121 +               if (pid != ~0U && pid != vx_map_pid(task->pid)) {
6122 +                       put_task_struct(task);
6123 +                       goto drop;
6124 +               }
6125                 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
6126                     task_dumpable(task)) {
6127                         rcu_read_lock();
6128 @@ -1648,6 +1664,7 @@ int pid_revalidate(struct dentry *dentry
6129                 put_task_struct(task);
6130                 return 1;
6131         }
6132 +drop:
6133         d_drop(dentry);
6134         return 0;
6135  }
6136 @@ -2196,6 +2213,13 @@ static struct dentry *proc_pident_lookup
6137         if (!task)
6138                 goto out_no_task;
6139  
6140 +       /* TODO: maybe we can come up with a generic approach? */
6141 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
6142 +               (dentry->d_name.len == 5) &&
6143 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
6144 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
6145 +               goto out;
6146 +
6147         /*
6148          * Yes, it does not scale. And it should not. Don't add
6149          * new entries into /proc/<tgid>/ without very good reasons.
6150 @@ -2630,6 +2654,9 @@ static int proc_pid_personality(struct s
6151  static const struct file_operations proc_task_operations;
6152  static const struct inode_operations proc_task_inode_operations;
6153  
6154 +extern int proc_pid_vx_info(struct task_struct *, char *);
6155 +extern int proc_pid_nx_info(struct task_struct *, char *);
6156 +
6157  static const struct pid_entry tgid_base_stuff[] = {
6158         DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
6159         DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
6160 @@ -2696,6 +2723,8 @@ static const struct pid_entry tgid_base_
6161  #ifdef CONFIG_CGROUPS
6162         REG("cgroup",  S_IRUGO, proc_cgroup_operations),
6163  #endif
6164 +       INF("vinfo",      S_IRUGO, proc_pid_vx_info),
6165 +       INF("ninfo",      S_IRUGO, proc_pid_nx_info),
6166         INF("oom_score",  S_IRUGO, proc_oom_score),
6167         REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adj_operations),
6168         REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations),
6169 @@ -2910,7 +2939,7 @@ retry:
6170         iter.task = NULL;
6171         pid = find_ge_pid(iter.tgid, ns);
6172         if (pid) {
6173 -               iter.tgid = pid_nr_ns(pid, ns);
6174 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
6175                 iter.task = pid_task(pid, PIDTYPE_PID);
6176                 /* What we to know is if the pid we have find is the
6177                  * pid of a thread_group_leader.  Testing for task
6178 @@ -2940,7 +2969,7 @@ static int proc_pid_fill_cache(struct fi
6179         struct tgid_iter iter)
6180  {
6181         char name[PROC_NUMBUF];
6182 -       int len = snprintf(name, sizeof(name), "%d", iter.tgid);
6183 +       int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
6184         return proc_fill_cache(filp, dirent, filldir, name, len,
6185                                 proc_pid_instantiate, iter.task, NULL);
6186  }
6187 @@ -2981,6 +3010,8 @@ int proc_pid_readdir(struct file * filp,
6188                         __filldir = fake_filldir;
6189  
6190                 filp->f_pos = iter.tgid + TGID_OFFSET;
6191 +               if (!vx_proc_task_visible(iter.task))
6192 +                       continue;
6193                 if (proc_pid_fill_cache(filp, dirent, __filldir, iter) < 0) {
6194                         put_task_struct(iter.task);
6195                         goto out;
6196 @@ -3073,6 +3104,7 @@ static const struct pid_entry tid_base_s
6197         REG("gid_map",    S_IRUGO|S_IWUSR, proc_gid_map_operations),
6198         REG("projid_map", S_IRUGO|S_IWUSR, proc_projid_map_operations),
6199  #endif
6200 +       ONE("nsproxy",  S_IRUGO, proc_pid_nsproxy),
6201  };
6202  
6203  static int proc_tid_base_readdir(struct file * filp,
6204 @@ -3141,6 +3173,8 @@ static struct dentry *proc_task_lookup(s
6205         tid = name_to_int(dentry);
6206         if (tid == ~0U)
6207                 goto out;
6208 +       if (vx_current_initpid(tid))
6209 +               goto out;
6210  
6211         ns = dentry->d_sb->s_fs_info;
6212         rcu_read_lock();
6213 diff -NurpP --minimal linux-3.10.33/fs/proc/generic.c linux-3.10.33-vs2.3.6.8/fs/proc/generic.c
6214 --- linux-3.10.33/fs/proc/generic.c     2013-07-14 17:01:29.000000000 +0000
6215 +++ linux-3.10.33-vs2.3.6.8/fs/proc/generic.c   2013-08-22 20:29:59.000000000 +0000
6216 @@ -23,6 +23,7 @@
6217  #include <linux/bitops.h>
6218  #include <linux/spinlock.h>
6219  #include <linux/completion.h>
6220 +#include <linux/vserver/inode.h>
6221  #include <asm/uaccess.h>
6222  
6223  #include "internal.h"
6224 @@ -203,6 +204,8 @@ struct dentry *proc_lookup_de(struct pro
6225         for (de = de->subdir; de ; de = de->next) {
6226                 if (de->namelen != dentry->d_name.len)
6227                         continue;
6228 +               if (!vx_hide_check(0, de->vx_flags))
6229 +                       continue;
6230                 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
6231                         pde_get(de);
6232                         spin_unlock(&proc_subdir_lock);
6233 @@ -211,6 +214,8 @@ struct dentry *proc_lookup_de(struct pro
6234                                 return ERR_PTR(-ENOMEM);
6235                         d_set_d_op(dentry, &proc_dentry_operations);
6236                         d_add(dentry, inode);
6237 +                       /* generic proc entries belong to the host */
6238 +                       i_tag_write(inode, 0);
6239                         return NULL;
6240                 }
6241         }
6242 @@ -279,6 +284,8 @@ int proc_readdir_de(struct proc_dir_entr
6243  
6244                                 /* filldir passes info to user space */
6245                                 pde_get(de);
6246 +                               if (!vx_hide_check(0, de->vx_flags))
6247 +                                       goto skip;
6248                                 spin_unlock(&proc_subdir_lock);
6249                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
6250                                             de->low_ino, de->mode >> 12) < 0) {
6251 @@ -286,6 +293,7 @@ int proc_readdir_de(struct proc_dir_entr
6252                                         goto out;
6253                                 }
6254                                 spin_lock(&proc_subdir_lock);
6255 +                       skip:
6256                                 filp->f_pos++;
6257                                 next = de->next;
6258                                 pde_put(de);
6259 @@ -395,6 +403,7 @@ static struct proc_dir_entry *__proc_cre
6260         ent->namelen = len;
6261         ent->mode = mode;
6262         ent->nlink = nlink;
6263 +       ent->vx_flags = IATTR_PROC_DEFAULT;
6264         atomic_set(&ent->count, 1);
6265         spin_lock_init(&ent->pde_unload_lock);
6266         INIT_LIST_HEAD(&ent->pde_openers);
6267 @@ -418,7 +427,8 @@ struct proc_dir_entry *proc_symlink(cons
6268                                 kfree(ent->data);
6269                                 kfree(ent);
6270                                 ent = NULL;
6271 -                       }
6272 +                       } else
6273 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
6274                 } else {
6275                         kfree(ent);
6276                         ent = NULL;
6277 diff -NurpP --minimal linux-3.10.33/fs/proc/inode.c linux-3.10.33-vs2.3.6.8/fs/proc/inode.c
6278 --- linux-3.10.33/fs/proc/inode.c       2013-07-14 17:01:29.000000000 +0000
6279 +++ linux-3.10.33-vs2.3.6.8/fs/proc/inode.c     2013-08-22 20:29:59.000000000 +0000
6280 @@ -387,6 +387,8 @@ struct inode *proc_get_inode(struct supe
6281                         inode->i_uid = de->uid;
6282                         inode->i_gid = de->gid;
6283                 }
6284 +               if (de->vx_flags)
6285 +                       PROC_I(inode)->vx_flags = de->vx_flags;
6286                 if (de->size)
6287                         inode->i_size = de->size;
6288                 if (de->nlink)
6289 diff -NurpP --minimal linux-3.10.33/fs/proc/internal.h linux-3.10.33-vs2.3.6.8/fs/proc/internal.h
6290 --- linux-3.10.33/fs/proc/internal.h    2013-07-14 17:01:29.000000000 +0000
6291 +++ linux-3.10.33-vs2.3.6.8/fs/proc/internal.h  2013-08-22 21:52:30.000000000 +0000
6292 @@ -14,6 +14,7 @@
6293  #include <linux/spinlock.h>
6294  #include <linux/atomic.h>
6295  #include <linux/binfmts.h>
6296 +#include <linux/vs_pid.h>
6297  
6298  struct ctl_table_header;
6299  struct mempolicy;
6300 @@ -35,6 +36,7 @@ struct proc_dir_entry {
6301         nlink_t nlink;
6302         kuid_t uid;
6303         kgid_t gid;
6304 +       int vx_flags;
6305         loff_t size;
6306         const struct inode_operations *proc_iops;
6307         const struct file_operations *proc_fops;
6308 @@ -50,16 +52,23 @@ struct proc_dir_entry {
6309         char name[];
6310  };
6311  
6312 +struct vx_info;
6313 +struct nx_info;
6314 +
6315  union proc_op {
6316         int (*proc_get_link)(struct dentry *, struct path *);
6317         int (*proc_read)(struct task_struct *task, char *page);
6318         int (*proc_show)(struct seq_file *m,
6319                 struct pid_namespace *ns, struct pid *pid,
6320                 struct task_struct *task);
6321 +       int (*proc_vs_read)(char *page);
6322 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
6323 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
6324  };
6325  
6326  struct proc_inode {
6327         struct pid *pid;
6328 +       int vx_flags;
6329         int fd;
6330         union proc_op op;
6331         struct proc_dir_entry *pde;
6332 @@ -92,11 +101,16 @@ static inline struct pid *proc_pid(struc
6333         return PROC_I(inode)->pid;
6334  }
6335  
6336 -static inline struct task_struct *get_proc_task(struct inode *inode)
6337 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
6338  {
6339         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
6340  }
6341  
6342 +static inline struct task_struct *get_proc_task(struct inode *inode)
6343 +{
6344 +       return vx_get_proc_task(inode, proc_pid(inode));
6345 +}
6346 +
6347  static inline int task_dumpable(struct task_struct *task)
6348  {
6349         int dumpable = 0;
6350 @@ -155,6 +169,8 @@ extern int proc_pid_status(struct seq_fi
6351                            struct pid *, struct task_struct *);
6352  extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
6353                           struct pid *, struct task_struct *);
6354 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6355 +                           struct pid *pid, struct task_struct *task);
6356  
6357  /*
6358   * base.c
6359 diff -NurpP --minimal linux-3.10.33/fs/proc/loadavg.c linux-3.10.33-vs2.3.6.8/fs/proc/loadavg.c
6360 --- linux-3.10.33/fs/proc/loadavg.c     2012-12-11 03:30:57.000000000 +0000
6361 +++ linux-3.10.33-vs2.3.6.8/fs/proc/loadavg.c   2013-08-22 20:30:00.000000000 +0000
6362 @@ -12,15 +12,27 @@
6363  
6364  static int loadavg_proc_show(struct seq_file *m, void *v)
6365  {
6366 +       unsigned long running;
6367 +       unsigned int threads;
6368         unsigned long avnrun[3];
6369  
6370         get_avenrun(avnrun, FIXED_1/200, 0);
6371  
6372 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
6373 +               struct vx_info *vxi = current_vx_info();
6374 +
6375 +               running = atomic_read(&vxi->cvirt.nr_running);
6376 +               threads = atomic_read(&vxi->cvirt.nr_threads);
6377 +       } else {
6378 +               running = nr_running();
6379 +               threads = nr_threads;
6380 +       }
6381 +
6382         seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
6383                 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
6384                 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
6385                 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
6386 -               nr_running(), nr_threads,
6387 +               running, threads,
6388                 task_active_pid_ns(current)->last_pid);
6389         return 0;
6390  }
6391 diff -NurpP --minimal linux-3.10.33/fs/proc/meminfo.c linux-3.10.33-vs2.3.6.8/fs/proc/meminfo.c
6392 --- linux-3.10.33/fs/proc/meminfo.c     2013-07-14 17:01:29.000000000 +0000
6393 +++ linux-3.10.33-vs2.3.6.8/fs/proc/meminfo.c   2013-08-22 20:30:00.000000000 +0000
6394 @@ -40,7 +40,8 @@ static int meminfo_proc_show(struct seq_
6395         allowed = ((totalram_pages - hugetlb_total_pages())
6396                 * sysctl_overcommit_ratio / 100) + total_swap_pages;
6397  
6398 -       cached = global_page_state(NR_FILE_PAGES) -
6399 +       cached = vx_flags(VXF_VIRT_MEM, 0) ?
6400 +               vx_vsi_cached(&i) : global_page_state(NR_FILE_PAGES) -
6401                         total_swapcache_pages() - i.bufferram;
6402         if (cached < 0)
6403                 cached = 0;
6404 diff -NurpP --minimal linux-3.10.33/fs/proc/root.c linux-3.10.33-vs2.3.6.8/fs/proc/root.c
6405 --- linux-3.10.33/fs/proc/root.c        2014-03-12 13:16:02.000000000 +0000
6406 +++ linux-3.10.33-vs2.3.6.8/fs/proc/root.c      2013-11-13 17:19:37.000000000 +0000
6407 @@ -20,9 +20,14 @@
6408  #include <linux/mount.h>
6409  #include <linux/pid_namespace.h>
6410  #include <linux/parser.h>
6411 +#include <linux/vserver/inode.h>
6412  
6413  #include "internal.h"
6414  
6415 +struct proc_dir_entry *proc_virtual;
6416 +
6417 +extern void proc_vx_init(void);
6418 +
6419  static int proc_test_super(struct super_block *sb, void *data)
6420  {
6421         return sb->s_fs_info == data;
6422 @@ -111,7 +116,8 @@ static struct dentry *proc_mount(struct
6423                 options = data;
6424  
6425                 if (!current_user_ns()->may_mount_proc ||
6426 -                   !ns_capable(ns->user_ns, CAP_SYS_ADMIN))
6427 +                   !vx_ns_capable(ns->user_ns,
6428 +                       CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
6429                         return ERR_PTR(-EPERM);
6430         }
6431  
6432 @@ -185,6 +191,7 @@ void __init proc_root_init(void)
6433  #endif
6434         proc_mkdir("bus", NULL);
6435         proc_sys_init();
6436 +       proc_vx_init();
6437  }
6438  
6439  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
6440 @@ -251,6 +258,7 @@ struct proc_dir_entry proc_root = {
6441         .proc_iops      = &proc_root_inode_operations, 
6442         .proc_fops      = &proc_root_operations,
6443         .parent         = &proc_root,
6444 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
6445         .name           = "/proc",
6446  };
6447  
6448 diff -NurpP --minimal linux-3.10.33/fs/proc/self.c linux-3.10.33-vs2.3.6.8/fs/proc/self.c
6449 --- linux-3.10.33/fs/proc/self.c        2013-07-14 17:01:29.000000000 +0000
6450 +++ linux-3.10.33-vs2.3.6.8/fs/proc/self.c      2013-08-23 00:07:45.000000000 +0000
6451 @@ -2,6 +2,7 @@
6452  #include <linux/namei.h>
6453  #include <linux/slab.h>
6454  #include <linux/pid_namespace.h>
6455 +#include <linux/vserver/inode.h>
6456  #include "internal.h"
6457  
6458  /*
6459 @@ -62,6 +63,8 @@ int proc_setup_self(struct super_block *
6460         self = d_alloc_name(s->s_root, "self");
6461         if (self) {
6462                 struct inode *inode = new_inode_pseudo(s);
6463 +
6464 +               // self->vx_flags = IATTR_PROC_SYMLINK;
6465                 if (inode) {
6466                         inode->i_ino = self_inum;
6467                         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
6468 diff -NurpP --minimal linux-3.10.33/fs/proc/stat.c linux-3.10.33-vs2.3.6.8/fs/proc/stat.c
6469 --- linux-3.10.33/fs/proc/stat.c        2013-07-14 17:01:29.000000000 +0000
6470 +++ linux-3.10.33-vs2.3.6.8/fs/proc/stat.c      2013-08-22 20:30:00.000000000 +0000
6471 @@ -9,8 +9,10 @@
6472  #include <linux/slab.h>
6473  #include <linux/time.h>
6474  #include <linux/irqnr.h>
6475 +#include <linux/vserver/cvirt.h>
6476  #include <asm/cputime.h>
6477  #include <linux/tick.h>
6478 +#include <linux/cpuset.h>
6479  
6480  #ifndef arch_irq_stat_cpu
6481  #define arch_irq_stat_cpu(cpu) 0
6482 @@ -87,14 +89,26 @@ static int show_stat(struct seq_file *p,
6483         u64 sum_softirq = 0;
6484         unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
6485         struct timespec boottime;
6486 +       cpumask_var_t cpus_allowed;
6487 +       bool virt_cpu = vx_flags(VXF_VIRT_CPU, 0);
6488  
6489         user = nice = system = idle = iowait =
6490                 irq = softirq = steal = 0;
6491         guest = guest_nice = 0;
6492         getboottime(&boottime);
6493 +
6494 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6495 +               vx_vsi_boottime(&boottime);
6496 +
6497 +       if (virt_cpu)
6498 +               cpuset_cpus_allowed(current, cpus_allowed);
6499 +
6500         jif = boottime.tv_sec;
6501  
6502         for_each_possible_cpu(i) {
6503 +               if (virt_cpu && !cpumask_test_cpu(i, cpus_allowed))
6504 +                       continue;
6505 +
6506                 user += kcpustat_cpu(i).cpustat[CPUTIME_USER];
6507                 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
6508                 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
6509 @@ -131,6 +145,9 @@ static int show_stat(struct seq_file *p,
6510         seq_putc(p, '\n');
6511  
6512         for_each_online_cpu(i) {
6513 +               if (virt_cpu && !cpumask_test_cpu(i, cpus_allowed))
6514 +                       continue;
6515 +
6516                 /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
6517                 user = kcpustat_cpu(i).cpustat[CPUTIME_USER];
6518                 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
6519 diff -NurpP --minimal linux-3.10.33/fs/proc/uptime.c linux-3.10.33-vs2.3.6.8/fs/proc/uptime.c
6520 --- linux-3.10.33/fs/proc/uptime.c      2012-12-11 03:30:57.000000000 +0000
6521 +++ linux-3.10.33-vs2.3.6.8/fs/proc/uptime.c    2013-08-22 20:30:00.000000000 +0000
6522 @@ -5,6 +5,7 @@
6523  #include <linux/seq_file.h>
6524  #include <linux/time.h>
6525  #include <linux/kernel_stat.h>
6526 +#include <linux/vserver/cvirt.h>
6527  #include <asm/cputime.h>
6528  
6529  static int uptime_proc_show(struct seq_file *m, void *v)
6530 @@ -25,6 +26,10 @@ static int uptime_proc_show(struct seq_f
6531         nsec = cputime64_to_jiffies64(idletime) * TICK_NSEC;
6532         idle.tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem);
6533         idle.tv_nsec = rem;
6534 +
6535 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6536 +               vx_vsi_uptime(&uptime, &idle);
6537 +
6538         seq_printf(m, "%lu.%02lu %lu.%02lu\n",
6539                         (unsigned long) uptime.tv_sec,
6540                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
6541 diff -NurpP --minimal linux-3.10.33/fs/proc_namespace.c linux-3.10.33-vs2.3.6.8/fs/proc_namespace.c
6542 --- linux-3.10.33/fs/proc_namespace.c   2012-12-11 03:30:57.000000000 +0000
6543 +++ linux-3.10.33-vs2.3.6.8/fs/proc_namespace.c 2013-08-22 20:30:00.000000000 +0000
6544 @@ -44,6 +44,8 @@ static int show_sb_opts(struct seq_file
6545                 { MS_SYNCHRONOUS, ",sync" },
6546                 { MS_DIRSYNC, ",dirsync" },
6547                 { MS_MANDLOCK, ",mand" },
6548 +               { MS_TAGGED, ",tag" },
6549 +               { MS_NOTAGCHECK, ",notagcheck" },
6550                 { 0, NULL }
6551         };
6552         const struct proc_fs_info *fs_infop;
6553 @@ -80,6 +82,40 @@ static inline void mangle(struct seq_fil
6554         seq_escape(m, s, " \t\n\\");
6555  }
6556  
6557 +#ifdef CONFIG_VSERVER_EXTRA_MNT_CHECK
6558 +
6559 +static int mnt_is_reachable(struct vfsmount *vfsmnt)
6560 +{
6561 +       struct path root;
6562 +       struct dentry *point;
6563 +       struct mount *mnt = real_mount(vfsmnt);
6564 +       struct mount *root_mnt;
6565 +       int ret;
6566 +
6567 +       if (mnt == mnt->mnt_ns->root)
6568 +               return 1;
6569 +
6570 +       br_read_lock(&vfsmount_lock);
6571 +       root = current->fs->root;
6572 +       root_mnt = real_mount(root.mnt);
6573 +       point = root.dentry;
6574 +
6575 +       while ((mnt != mnt->mnt_parent) && (mnt != root_mnt)) {
6576 +               point = mnt->mnt_mountpoint;
6577 +               mnt = mnt->mnt_parent;
6578 +       }
6579 +
6580 +       ret = (mnt == root_mnt) && is_subdir(point, root.dentry);
6581 +
6582 +       br_read_unlock(&vfsmount_lock);
6583 +
6584 +       return ret;
6585 +}
6586 +
6587 +#else
6588 +#define        mnt_is_reachable(v)     (1)
6589 +#endif
6590 +
6591  static void show_type(struct seq_file *m, struct super_block *sb)
6592  {
6593         mangle(m, sb->s_type->name);
6594 @@ -96,6 +132,17 @@ static int show_vfsmnt(struct seq_file *
6595         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
6596         struct super_block *sb = mnt_path.dentry->d_sb;
6597  
6598 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6599 +               return SEQ_SKIP;
6600 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6601 +               return SEQ_SKIP;
6602 +
6603 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6604 +               mnt == current->fs->root.mnt) {
6605 +               seq_puts(m, "/dev/root / ");
6606 +               goto type;
6607 +       }
6608 +
6609         if (sb->s_op->show_devname) {
6610                 err = sb->s_op->show_devname(m, mnt_path.dentry);
6611                 if (err)
6612 @@ -106,6 +153,7 @@ static int show_vfsmnt(struct seq_file *
6613         seq_putc(m, ' ');
6614         seq_path(m, &mnt_path, " \t\n\\");
6615         seq_putc(m, ' ');
6616 +type:
6617         show_type(m, sb);
6618         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
6619         err = show_sb_opts(m, sb);
6620 @@ -128,6 +176,11 @@ static int show_mountinfo(struct seq_fil
6621         struct path root = p->root;
6622         int err = 0;
6623  
6624 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6625 +               return SEQ_SKIP;
6626 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6627 +               return SEQ_SKIP;
6628 +
6629         seq_printf(m, "%i %i %u:%u ", r->mnt_id, r->mnt_parent->mnt_id,
6630                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
6631         if (sb->s_op->show_path)
6632 @@ -187,6 +240,17 @@ static int show_vfsstat(struct seq_file
6633         struct super_block *sb = mnt_path.dentry->d_sb;
6634         int err = 0;
6635  
6636 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6637 +               return SEQ_SKIP;
6638 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6639 +               return SEQ_SKIP;
6640 +
6641 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6642 +               mnt == current->fs->root.mnt) {
6643 +               seq_puts(m, "device /dev/root mounted on / ");
6644 +               goto type;
6645 +       }
6646 +
6647         /* device */
6648         if (sb->s_op->show_devname) {
6649                 seq_puts(m, "device ");
6650 @@ -203,7 +267,7 @@ static int show_vfsstat(struct seq_file
6651         seq_puts(m, " mounted on ");
6652         seq_path(m, &mnt_path, " \t\n\\");
6653         seq_putc(m, ' ');
6654 -
6655 +type:
6656         /* file system type */
6657         seq_puts(m, "with fstype ");
6658         show_type(m, sb);
6659 diff -NurpP --minimal linux-3.10.33/fs/quota/dquot.c linux-3.10.33-vs2.3.6.8/fs/quota/dquot.c
6660 --- linux-3.10.33/fs/quota/dquot.c      2014-03-12 13:16:02.000000000 +0000
6661 +++ linux-3.10.33-vs2.3.6.8/fs/quota/dquot.c    2014-03-12 13:18:32.000000000 +0000
6662 @@ -1593,6 +1593,9 @@ int __dquot_alloc_space(struct inode *in
6663         struct dquot **dquots = inode->i_dquot;
6664         int reserve = flags & DQUOT_SPACE_RESERVE;
6665  
6666 +       if ((ret = dl_alloc_space(inode, number)))
6667 +               return ret;
6668 +
6669         /*
6670          * First test before acquiring mutex - solves deadlocks when we
6671          * re-enter the quota code and are already holding the mutex
6672 @@ -1648,6 +1651,9 @@ int dquot_alloc_inode(const struct inode
6673         struct dquot_warn warn[MAXQUOTAS];
6674         struct dquot * const *dquots = inode->i_dquot;
6675  
6676 +       if ((ret = dl_alloc_inode(inode)))
6677 +               return ret;
6678 +
6679         /* First test before acquiring mutex - solves deadlocks when we
6680           * re-enter the quota code and are already holding the mutex */
6681         if (!dquot_active(inode))
6682 @@ -1719,6 +1725,8 @@ void __dquot_free_space(struct inode *in
6683         struct dquot **dquots = inode->i_dquot;
6684         int reserve = flags & DQUOT_SPACE_RESERVE;
6685  
6686 +       dl_free_space(inode, number);
6687 +
6688         /* First test before acquiring mutex - solves deadlocks when we
6689           * re-enter the quota code and are already holding the mutex */
6690         if (!dquot_active(inode)) {
6691 @@ -1763,6 +1771,8 @@ void dquot_free_inode(const struct inode
6692         struct dquot_warn warn[MAXQUOTAS];
6693         struct dquot * const *dquots = inode->i_dquot;
6694  
6695 +       dl_free_inode(inode);
6696 +
6697         /* First test before acquiring mutex - solves deadlocks when we
6698           * re-enter the quota code and are already holding the mutex */
6699         if (!dquot_active(inode))
6700 diff -NurpP --minimal linux-3.10.33/fs/quota/quota.c linux-3.10.33-vs2.3.6.8/fs/quota/quota.c
6701 --- linux-3.10.33/fs/quota/quota.c      2013-02-19 13:58:49.000000000 +0000
6702 +++ linux-3.10.33-vs2.3.6.8/fs/quota/quota.c    2013-08-22 20:30:00.000000000 +0000
6703 @@ -8,6 +8,7 @@
6704  #include <linux/fs.h>
6705  #include <linux/namei.h>
6706  #include <linux/slab.h>
6707 +#include <linux/vs_context.h>
6708  #include <asm/current.h>
6709  #include <linux/uaccess.h>
6710  #include <linux/kernel.h>
6711 @@ -37,7 +38,7 @@ static int check_quotactl_permission(str
6712                         break;
6713                 /*FALLTHROUGH*/
6714         default:
6715 -               if (!capable(CAP_SYS_ADMIN))
6716 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
6717                         return -EPERM;
6718         }
6719  
6720 @@ -309,6 +310,46 @@ static int do_quotactl(struct super_bloc
6721  
6722  #ifdef CONFIG_BLOCK
6723  
6724 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6725 +
6726 +#include <linux/vroot.h>
6727 +#include <linux/major.h>
6728 +#include <linux/module.h>
6729 +#include <linux/kallsyms.h>
6730 +#include <linux/vserver/debug.h>
6731 +
6732 +static vroot_grb_func *vroot_get_real_bdev = NULL;
6733 +
6734 +static DEFINE_SPINLOCK(vroot_grb_lock);
6735 +
6736 +int register_vroot_grb(vroot_grb_func *func) {
6737 +       int ret = -EBUSY;
6738 +
6739 +       spin_lock(&vroot_grb_lock);
6740 +       if (!vroot_get_real_bdev) {
6741 +               vroot_get_real_bdev = func;
6742 +               ret = 0;
6743 +       }
6744 +       spin_unlock(&vroot_grb_lock);
6745 +       return ret;
6746 +}
6747 +EXPORT_SYMBOL(register_vroot_grb);
6748 +
6749 +int unregister_vroot_grb(vroot_grb_func *func) {
6750 +       int ret = -EINVAL;
6751 +
6752 +       spin_lock(&vroot_grb_lock);
6753 +       if (vroot_get_real_bdev) {
6754 +               vroot_get_real_bdev = NULL;
6755 +               ret = 0;
6756 +       }
6757 +       spin_unlock(&vroot_grb_lock);
6758 +       return ret;
6759 +}
6760 +EXPORT_SYMBOL(unregister_vroot_grb);
6761 +
6762 +#endif
6763 +
6764  /* Return 1 if 'cmd' will block on frozen filesystem */
6765  static int quotactl_cmd_write(int cmd)
6766  {
6767 @@ -343,6 +384,22 @@ static struct super_block *quotactl_bloc
6768         putname(tmp);
6769         if (IS_ERR(bdev))
6770                 return ERR_CAST(bdev);
6771 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6772 +       if (bdev && bdev->bd_inode &&
6773 +               imajor(bdev->bd_inode) == VROOT_MAJOR) {
6774 +               struct block_device *bdnew = (void *)-EINVAL;
6775 +
6776 +               if (vroot_get_real_bdev)
6777 +                       bdnew = vroot_get_real_bdev(bdev);
6778 +               else
6779 +                       vxdprintk(VXD_CBIT(misc, 0),
6780 +                                       "vroot_get_real_bdev not set");
6781 +               bdput(bdev);
6782 +               if (IS_ERR(bdnew))
6783 +                       return ERR_PTR(PTR_ERR(bdnew));
6784 +               bdev = bdnew;
6785 +       }
6786 +#endif
6787         if (quotactl_cmd_write(cmd))
6788                 sb = get_super_thawed(bdev);
6789         else
6790 diff -NurpP --minimal linux-3.10.33/fs/stat.c linux-3.10.33-vs2.3.6.8/fs/stat.c
6791 --- linux-3.10.33/fs/stat.c     2013-05-31 13:45:25.000000000 +0000
6792 +++ linux-3.10.33-vs2.3.6.8/fs/stat.c   2013-08-22 20:30:00.000000000 +0000
6793 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
6794         stat->nlink = inode->i_nlink;
6795         stat->uid = inode->i_uid;
6796         stat->gid = inode->i_gid;
6797 +       stat->tag = inode->i_tag;
6798         stat->rdev = inode->i_rdev;
6799         stat->size = i_size_read(inode);
6800         stat->atime = inode->i_atime;
6801 diff -NurpP --minimal linux-3.10.33/fs/statfs.c linux-3.10.33-vs2.3.6.8/fs/statfs.c
6802 --- linux-3.10.33/fs/statfs.c   2014-03-12 13:16:02.000000000 +0000
6803 +++ linux-3.10.33-vs2.3.6.8/fs/statfs.c 2013-11-13 17:17:16.000000000 +0000
6804 @@ -7,6 +7,8 @@
6805  #include <linux/statfs.h>
6806  #include <linux/security.h>
6807  #include <linux/uaccess.h>
6808 +#include <linux/vs_base.h>
6809 +#include <linux/vs_dlimit.h>
6810  #include "internal.h"
6811  
6812  static int flags_by_mnt(int mnt_flags)
6813 @@ -60,6 +62,8 @@ static int statfs_by_dentry(struct dentr
6814         retval = dentry->d_sb->s_op->statfs(dentry, buf);
6815         if (retval == 0 && buf->f_frsize == 0)
6816                 buf->f_frsize = buf->f_bsize;
6817 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
6818 +               vx_vsi_statfs(dentry->d_sb, buf);
6819         return retval;
6820  }
6821  
6822 diff -NurpP --minimal linux-3.10.33/fs/super.c linux-3.10.33-vs2.3.6.8/fs/super.c
6823 --- linux-3.10.33/fs/super.c    2014-03-12 13:16:02.000000000 +0000
6824 +++ linux-3.10.33-vs2.3.6.8/fs/super.c  2013-11-13 17:17:16.000000000 +0000
6825 @@ -34,6 +34,8 @@
6826  #include <linux/cleancache.h>
6827  #include <linux/fsnotify.h>
6828  #include <linux/lockdep.h>
6829 +#include <linux/magic.h>
6830 +#include <linux/vs_context.h>
6831  #include "internal.h"
6832  
6833  
6834 @@ -1112,6 +1114,13 @@ mount_fs(struct file_system_type *type,
6835         WARN_ON(sb->s_bdi == &default_backing_dev_info);
6836         sb->s_flags |= MS_BORN;
6837  
6838 +       error = -EPERM;
6839 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) &&
6840 +               !sb->s_bdev &&
6841 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
6842 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
6843 +               goto out_sb;
6844 +
6845         error = security_sb_kern_mount(sb, flags, secdata);
6846         if (error)
6847                 goto out_sb;
6848 diff -NurpP --minimal linux-3.10.33/fs/sysfs/mount.c linux-3.10.33-vs2.3.6.8/fs/sysfs/mount.c
6849 --- linux-3.10.33/fs/sysfs/mount.c      2013-05-31 13:45:25.000000000 +0000
6850 +++ linux-3.10.33-vs2.3.6.8/fs/sysfs/mount.c    2013-08-22 20:30:00.000000000 +0000
6851 @@ -48,7 +48,7 @@ static int sysfs_fill_super(struct super
6852  
6853         sb->s_blocksize = PAGE_CACHE_SIZE;
6854         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
6855 -       sb->s_magic = SYSFS_MAGIC;
6856 +       sb->s_magic = SYSFS_SUPER_MAGIC;
6857         sb->s_op = &sysfs_ops;
6858         sb->s_time_gran = 1;
6859  
6860 diff -NurpP --minimal linux-3.10.33/fs/utimes.c linux-3.10.33-vs2.3.6.8/fs/utimes.c
6861 --- linux-3.10.33/fs/utimes.c   2013-02-19 13:58:49.000000000 +0000
6862 +++ linux-3.10.33-vs2.3.6.8/fs/utimes.c 2013-08-22 20:30:00.000000000 +0000
6863 @@ -8,6 +8,8 @@
6864  #include <linux/stat.h>
6865  #include <linux/utime.h>
6866  #include <linux/syscalls.h>
6867 +#include <linux/mount.h>
6868 +#include <linux/vs_cowbl.h>
6869  #include <asm/uaccess.h>
6870  #include <asm/unistd.h>
6871  
6872 @@ -52,12 +54,18 @@ static int utimes_common(struct path *pa
6873  {
6874         int error;
6875         struct iattr newattrs;
6876 -       struct inode *inode = path->dentry->d_inode;
6877 +       struct inode *inode;
6878 +
6879 +       error = cow_check_and_break(path);
6880 +       if (error)
6881 +               goto out;
6882  
6883         error = mnt_want_write(path->mnt);
6884         if (error)
6885                 goto out;
6886  
6887 +       inode = path->dentry->d_inode;
6888 +
6889         if (times && times[0].tv_nsec == UTIME_NOW &&
6890                      times[1].tv_nsec == UTIME_NOW)
6891                 times = NULL;
6892 diff -NurpP --minimal linux-3.10.33/fs/xattr.c linux-3.10.33-vs2.3.6.8/fs/xattr.c
6893 --- linux-3.10.33/fs/xattr.c    2013-02-19 13:58:49.000000000 +0000
6894 +++ linux-3.10.33-vs2.3.6.8/fs/xattr.c  2013-08-22 20:30:00.000000000 +0000
6895 @@ -21,6 +21,7 @@
6896  #include <linux/audit.h>
6897  #include <linux/vmalloc.h>
6898  #include <linux/posix_acl_xattr.h>
6899 +#include <linux/mount.h>
6900  
6901  #include <asm/uaccess.h>
6902  
6903 @@ -52,7 +53,7 @@ xattr_permission(struct inode *inode, co
6904          * The trusted.* namespace can only be accessed by privileged users.
6905          */
6906         if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN)) {
6907 -               if (!capable(CAP_SYS_ADMIN))
6908 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_FS_TRUSTED))
6909                         return (mask & MAY_WRITE) ? -EPERM : -ENODATA;
6910                 return 0;
6911         }
6912 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
6913 --- linux-3.10.33/fs/xfs/xfs_dinode.h   2013-07-14 17:01:29.000000000 +0000
6914 +++ linux-3.10.33-vs2.3.6.8/fs/xfs/xfs_dinode.h 2013-08-22 20:30:00.000000000 +0000
6915 @@ -51,7 +51,9 @@ typedef struct xfs_dinode {
6916         __be32          di_nlink;       /* number of links to file */
6917         __be16          di_projid_lo;   /* lower part of owner's project id */
6918         __be16          di_projid_hi;   /* higher part owner's project id */
6919 -       __u8            di_pad[6];      /* unused, zeroed space */
6920 +       __u8            di_pad[2];      /* unused, zeroed space */
6921 +       __be16          di_tag;         /* context tagging */
6922 +       __be16          di_vflags;      /* vserver specific flags */
6923         __be16          di_flushiter;   /* incremented on flush */
6924         xfs_timestamp_t di_atime;       /* time last accessed */
6925         xfs_timestamp_t di_mtime;       /* time last modified */
6926 @@ -209,6 +211,8 @@ static inline void xfs_dinode_put_rdev(s
6927  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
6928  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
6929  #define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
6930 +#define XFS_DIFLAG_IXUNLINK_BIT     15 /* Immutable inver on unlink */
6931 +
6932  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
6933  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
6934  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
6935 @@ -224,6 +228,7 @@ static inline void xfs_dinode_put_rdev(s
6936  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
6937  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
6938  #define XFS_DIFLAG_FILESTREAM    (1 << XFS_DIFLAG_FILESTREAM_BIT)
6939 +#define XFS_DIFLAG_IXUNLINK      (1 << XFS_DIFLAG_IXUNLINK_BIT)
6940  
6941  #ifdef CONFIG_XFS_RT
6942  #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
6943 @@ -236,6 +241,10 @@ static inline void xfs_dinode_put_rdev(s
6944          XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
6945          XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
6946          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
6947 -        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
6948 +        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM | \
6949 +        XFS_DIFLAG_IXUNLINK)
6950 +
6951 +#define XFS_DIVFLAG_BARRIER    0x01
6952 +#define XFS_DIVFLAG_COW                0x02
6953  
6954  #endif /* __XFS_DINODE_H__ */
6955 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
6956 --- linux-3.10.33/fs/xfs/xfs_fs.h       2013-07-14 17:01:29.000000000 +0000
6957 +++ linux-3.10.33-vs2.3.6.8/fs/xfs/xfs_fs.h     2013-08-22 20:30:00.000000000 +0000
6958 @@ -67,6 +67,9 @@ struct fsxattr {
6959  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
6960  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
6961  #define XFS_XFLAG_FILESTREAM   0x00004000      /* use filestream allocator */
6962 +#define XFS_XFLAG_IXUNLINK     0x00008000      /* immutable invert on unlink */
6963 +#define XFS_XFLAG_BARRIER      0x10000000      /* chroot() barrier */
6964 +#define XFS_XFLAG_COW          0x20000000      /* copy on write mark */
6965  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
6966  
6967  /*
6968 @@ -304,7 +307,8 @@ typedef struct xfs_bstat {
6969  #define        bs_projid       bs_projid_lo    /* (previously just bs_projid)  */
6970         __u16           bs_forkoff;     /* inode fork offset in bytes   */
6971         __u16           bs_projid_hi;   /* higher part of project id    */
6972 -       unsigned char   bs_pad[10];     /* pad space, unused            */
6973 +       unsigned char   bs_pad[8];      /* pad space, unused            */
6974 +       __u16           bs_tag;         /* context tagging              */
6975         __u32           bs_dmevmask;    /* DMIG event mask              */
6976         __u16           bs_dmstate;     /* DMIG state info              */
6977         __u16           bs_aextents;    /* attribute number of extents  */
6978 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
6979 --- linux-3.10.33/fs/xfs/xfs_ialloc.c   2013-07-14 17:01:29.000000000 +0000
6980 +++ linux-3.10.33-vs2.3.6.8/fs/xfs/xfs_ialloc.c 2013-08-22 20:30:00.000000000 +0000
6981 @@ -39,7 +39,6 @@
6982  #include "xfs_cksum.h"
6983  #include "xfs_buf_item.h"
6984  
6985 -
6986  /*
6987   * Allocation group level functions.
6988   */
6989 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
6990 --- linux-3.10.33/fs/xfs/xfs_inode.c    2013-07-14 17:01:29.000000000 +0000
6991 +++ linux-3.10.33-vs2.3.6.8/fs/xfs/xfs_inode.c  2013-08-22 21:50:34.000000000 +0000
6992 @@ -16,6 +16,7 @@
6993   * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
6994   */
6995  #include <linux/log2.h>
6996 +#include <linux/vs_tag.h>
6997  
6998  #include "xfs.h"
6999  #include "xfs_fs.h"
7000 @@ -836,15 +837,25 @@ xfs_iformat_btree(
7001  STATIC void
7002  xfs_dinode_from_disk(
7003         xfs_icdinode_t          *to,
7004 -       xfs_dinode_t            *from)
7005 +       xfs_dinode_t            *from,
7006 +       int                     tagged)
7007  {
7008 +       uint32_t uid, gid, tag;
7009 +
7010         to->di_magic = be16_to_cpu(from->di_magic);
7011         to->di_mode = be16_to_cpu(from->di_mode);
7012         to->di_version = from ->di_version;
7013         to->di_format = from->di_format;
7014         to->di_onlink = be16_to_cpu(from->di_onlink);
7015 -       to->di_uid = be32_to_cpu(from->di_uid);
7016 -       to->di_gid = be32_to_cpu(from->di_gid);
7017 +
7018 +       uid = be32_to_cpu(from->di_uid);
7019 +       gid = be32_to_cpu(from->di_gid);
7020 +       tag = be16_to_cpu(from->di_tag);
7021 +
7022 +       to->di_uid = INOTAG_UID(tagged, uid, gid);
7023 +       to->di_gid = INOTAG_GID(tagged, uid, gid);
7024 +       to->di_tag = INOTAG_TAG(tagged, uid, gid, tag);
7025 +
7026         to->di_nlink = be32_to_cpu(from->di_nlink);
7027         to->di_projid_lo = be16_to_cpu(from->di_projid_lo);
7028         to->di_projid_hi = be16_to_cpu(from->di_projid_hi);
7029 @@ -866,6 +877,7 @@ xfs_dinode_from_disk(
7030         to->di_dmevmask = be32_to_cpu(from->di_dmevmask);
7031         to->di_dmstate  = be16_to_cpu(from->di_dmstate);
7032         to->di_flags    = be16_to_cpu(from->di_flags);
7033 +       to->di_vflags   = be16_to_cpu(from->di_vflags);
7034         to->di_gen      = be32_to_cpu(from->di_gen);
7035  
7036         if (to->di_version == 3) {
7037 @@ -883,15 +895,19 @@ xfs_dinode_from_disk(
7038  void
7039  xfs_dinode_to_disk(
7040         xfs_dinode_t            *to,
7041 -       xfs_icdinode_t          *from)
7042 +       xfs_icdinode_t          *from,
7043 +       int                     tagged)
7044  {
7045         to->di_magic = cpu_to_be16(from->di_magic);
7046         to->di_mode = cpu_to_be16(from->di_mode);
7047         to->di_version = from ->di_version;
7048         to->di_format = from->di_format;
7049         to->di_onlink = cpu_to_be16(from->di_onlink);
7050 -       to->di_uid = cpu_to_be32(from->di_uid);
7051 -       to->di_gid = cpu_to_be32(from->di_gid);
7052 +
7053 +       to->di_uid = cpu_to_be32(TAGINO_UID(tagged, from->di_uid, from->di_tag));
7054 +       to->di_gid = cpu_to_be32(TAGINO_GID(tagged, from->di_gid, from->di_tag));
7055 +       to->di_tag = cpu_to_be16(TAGINO_TAG(tagged, from->di_tag));
7056 +
7057         to->di_nlink = cpu_to_be32(from->di_nlink);
7058         to->di_projid_lo = cpu_to_be16(from->di_projid_lo);
7059         to->di_projid_hi = cpu_to_be16(from->di_projid_hi);
7060 @@ -913,6 +929,7 @@ xfs_dinode_to_disk(
7061         to->di_dmevmask = cpu_to_be32(from->di_dmevmask);
7062         to->di_dmstate = cpu_to_be16(from->di_dmstate);
7063         to->di_flags = cpu_to_be16(from->di_flags);
7064 +       to->di_vflags = cpu_to_be16(from->di_vflags);
7065         to->di_gen = cpu_to_be32(from->di_gen);
7066  
7067         if (from->di_version == 3) {
7068 @@ -929,7 +946,8 @@ xfs_dinode_to_disk(
7069  
7070  STATIC uint
7071  _xfs_dic2xflags(
7072 -       __uint16_t              di_flags)
7073 +       __uint16_t              di_flags,
7074 +       __uint16_t              di_vflags)
7075  {
7076         uint                    flags = 0;
7077  
7078 @@ -940,6 +958,8 @@ _xfs_dic2xflags(
7079                         flags |= XFS_XFLAG_PREALLOC;
7080                 if (di_flags & XFS_DIFLAG_IMMUTABLE)
7081                         flags |= XFS_XFLAG_IMMUTABLE;
7082 +               if (di_flags & XFS_DIFLAG_IXUNLINK)
7083 +                       flags |= XFS_XFLAG_IXUNLINK;
7084                 if (di_flags & XFS_DIFLAG_APPEND)
7085                         flags |= XFS_XFLAG_APPEND;
7086                 if (di_flags & XFS_DIFLAG_SYNC)
7087 @@ -964,6 +984,10 @@ _xfs_dic2xflags(
7088                         flags |= XFS_XFLAG_FILESTREAM;
7089         }
7090  
7091 +       if (di_vflags & XFS_DIVFLAG_BARRIER)
7092 +               flags |= FS_BARRIER_FL;
7093 +       if (di_vflags & XFS_DIVFLAG_COW)
7094 +               flags |= FS_COW_FL;
7095         return flags;
7096  }
7097  
7098 @@ -973,7 +997,7 @@ xfs_ip2xflags(
7099  {
7100         xfs_icdinode_t          *dic = &ip->i_d;
7101  
7102 -       return _xfs_dic2xflags(dic->di_flags) |
7103 +       return _xfs_dic2xflags(dic->di_flags, dic->di_vflags) |
7104                                 (XFS_IFORK_Q(ip) ? XFS_XFLAG_HASATTR : 0);
7105  }
7106  
7107 @@ -981,7 +1005,8 @@ uint
7108  xfs_dic2xflags(
7109         xfs_dinode_t            *dip)
7110  {
7111 -       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags)) |
7112 +       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags),
7113 +                               be16_to_cpu(dip->di_vflags)) |
7114                                 (XFS_DFORK_Q(dip) ? XFS_XFLAG_HASATTR : 0);
7115  }
7116  
7117 @@ -1072,7 +1097,8 @@ xfs_iread(
7118          * Otherwise, just get the truly permanent information.
7119          */
7120         if (dip->di_mode) {
7121 -               xfs_dinode_from_disk(&ip->i_d, dip);
7122 +               xfs_dinode_from_disk(&ip->i_d, dip,
7123 +                       mp->m_flags & XFS_MOUNT_TAGGED);
7124                 error = xfs_iformat(ip, dip);
7125                 if (error)  {
7126  #ifdef DEBUG
7127 @@ -1270,6 +1296,7 @@ xfs_ialloc(
7128         ASSERT(ip->i_d.di_nlink == nlink);
7129         ip->i_d.di_uid = current_fsuid();
7130         ip->i_d.di_gid = current_fsgid();
7131 +       ip->i_d.di_tag = current_fstag(&ip->i_vnode);
7132         xfs_set_projid(ip, prid);
7133         memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
7134  
7135 @@ -1329,6 +1356,7 @@ xfs_ialloc(
7136         ip->i_d.di_dmevmask = 0;
7137         ip->i_d.di_dmstate = 0;
7138         ip->i_d.di_flags = 0;
7139 +       ip->i_d.di_vflags = 0;
7140  
7141         if (ip->i_d.di_version == 3) {
7142                 ASSERT(ip->i_d.di_ino == ino);
7143 @@ -2052,6 +2080,7 @@ xfs_ifree(
7144         }
7145         ip->i_d.di_mode = 0;            /* mark incore inode as free */
7146         ip->i_d.di_flags = 0;
7147 +       ip->i_d.di_vflags = 0;
7148         ip->i_d.di_dmevmask = 0;
7149         ip->i_d.di_forkoff = 0;         /* mark the attr fork not in use */
7150         ip->i_d.di_format = XFS_DINODE_FMT_EXTENTS;
7151 @@ -2219,7 +2248,6 @@ xfs_iroot_realloc(
7152         return;
7153  }
7154  
7155 -
7156  /*
7157   * This is called when the amount of space needed for if_data
7158   * is increased or decreased.  The change in size is indicated by
7159 @@ -2899,7 +2927,8 @@ xfs_iflush_int(
7160          * because if the inode is dirty at all the core must
7161          * be.
7162          */
7163 -       xfs_dinode_to_disk(dip, &ip->i_d);
7164 +       xfs_dinode_to_disk(dip, &ip->i_d,
7165 +               mp->m_flags & XFS_MOUNT_TAGGED);
7166  
7167         /* Wrap, we never let the log put out DI_MAX_FLUSH */
7168         if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
7169 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
7170 --- linux-3.10.33/fs/xfs/xfs_inode.h    2013-07-14 17:01:30.000000000 +0000
7171 +++ linux-3.10.33-vs2.3.6.8/fs/xfs/xfs_inode.h  2013-08-22 20:30:00.000000000 +0000
7172 @@ -134,7 +134,9 @@ typedef struct xfs_icdinode {
7173         __uint32_t      di_nlink;       /* number of links to file */
7174         __uint16_t      di_projid_lo;   /* lower part of owner's project id */
7175         __uint16_t      di_projid_hi;   /* higher part of owner's project id */
7176 -       __uint8_t       di_pad[6];      /* unused, zeroed space */
7177 +       __uint8_t       di_pad[2];      /* unused, zeroed space */
7178 +       __uint16_t      di_tag;         /* context tagging */
7179 +       __uint16_t      di_vflags;      /* vserver specific flags */
7180         __uint16_t      di_flushiter;   /* incremented on flush */
7181         xfs_ictimestamp_t di_atime;     /* time last accessed */
7182         xfs_ictimestamp_t di_mtime;     /* time last modified */
7183 @@ -583,7 +585,7 @@ int         xfs_iread(struct xfs_mount *, struc
7184                           struct xfs_inode *, uint);
7185  void           xfs_dinode_calc_crc(struct xfs_mount *, struct xfs_dinode *);
7186  void           xfs_dinode_to_disk(struct xfs_dinode *,
7187 -                                  struct xfs_icdinode *);
7188 +                                  struct xfs_icdinode *, int);
7189  void           xfs_idestroy_fork(struct xfs_inode *, int);
7190  void           xfs_idata_realloc(struct xfs_inode *, int, int);
7191  void           xfs_iroot_realloc(struct xfs_inode *, int, int);
7192 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
7193 --- linux-3.10.33/fs/xfs/xfs_ioctl.c    2014-03-12 13:16:02.000000000 +0000
7194 +++ linux-3.10.33-vs2.3.6.8/fs/xfs/xfs_ioctl.c  2013-12-23 17:42:40.000000000 +0000
7195 @@ -26,7 +26,7 @@
7196  #include "xfs_bmap_btree.h"
7197  #include "xfs_dinode.h"
7198  #include "xfs_inode.h"
7199 -#include "xfs_ioctl.h"
7200 +// #include "xfs_ioctl.h"
7201  #include "xfs_rtalloc.h"
7202  #include "xfs_itable.h"
7203  #include "xfs_error.h"
7204 @@ -770,6 +770,10 @@ xfs_merge_ioc_xflags(
7205                 xflags |= XFS_XFLAG_IMMUTABLE;
7206         else
7207                 xflags &= ~XFS_XFLAG_IMMUTABLE;
7208 +       if (flags & FS_IXUNLINK_FL)
7209 +               xflags |= XFS_XFLAG_IXUNLINK;
7210 +       else
7211 +               xflags &= ~XFS_XFLAG_IXUNLINK;
7212         if (flags & FS_APPEND_FL)
7213                 xflags |= XFS_XFLAG_APPEND;
7214         else
7215 @@ -798,6 +802,8 @@ xfs_di2lxflags(
7216  
7217         if (di_flags & XFS_DIFLAG_IMMUTABLE)
7218                 flags |= FS_IMMUTABLE_FL;
7219 +       if (di_flags & XFS_DIFLAG_IXUNLINK)
7220 +               flags |= FS_IXUNLINK_FL;
7221         if (di_flags & XFS_DIFLAG_APPEND)
7222                 flags |= FS_APPEND_FL;
7223         if (di_flags & XFS_DIFLAG_SYNC)
7224 @@ -858,6 +864,8 @@ xfs_set_diflags(
7225         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
7226         if (xflags & XFS_XFLAG_IMMUTABLE)
7227                 di_flags |= XFS_DIFLAG_IMMUTABLE;
7228 +       if (xflags & XFS_XFLAG_IXUNLINK)
7229 +               di_flags |= XFS_DIFLAG_IXUNLINK;
7230         if (xflags & XFS_XFLAG_APPEND)
7231                 di_flags |= XFS_DIFLAG_APPEND;
7232         if (xflags & XFS_XFLAG_SYNC)
7233 @@ -900,6 +908,10 @@ xfs_diflags_to_linux(
7234                 inode->i_flags |= S_IMMUTABLE;
7235         else
7236                 inode->i_flags &= ~S_IMMUTABLE;
7237 +       if (xflags & XFS_XFLAG_IXUNLINK)
7238 +               inode->i_flags |= S_IXUNLINK;
7239 +       else
7240 +               inode->i_flags &= ~S_IXUNLINK;
7241         if (xflags & XFS_XFLAG_APPEND)
7242                 inode->i_flags |= S_APPEND;
7243         else
7244 @@ -1404,10 +1416,18 @@ xfs_file_ioctl(
7245         case XFS_IOC_FSGETXATTRA:
7246                 return xfs_ioc_fsgetxattr(ip, 1, arg);
7247         case XFS_IOC_FSSETXATTR:
7248 +               if (IS_BARRIER(inode)) {
7249 +                       vxwprintk_task(1, "messing with the barrier.");
7250 +                       return -XFS_ERROR(EACCES);
7251 +               }
7252                 return xfs_ioc_fssetxattr(ip, filp, arg);
7253         case XFS_IOC_GETXFLAGS:
7254                 return xfs_ioc_getxflags(ip, arg);
7255         case XFS_IOC_SETXFLAGS:
7256 +               if (IS_BARRIER(inode)) {
7257 +                       vxwprintk_task(1, "messing with the barrier.");
7258 +                       return -XFS_ERROR(EACCES);
7259 +               }
7260                 return xfs_ioc_setxflags(ip, filp, arg);
7261  
7262         case XFS_IOC_FSSETDM: {
7263 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
7264 --- linux-3.10.33/fs/xfs/xfs_ioctl.h    2012-12-11 03:30:57.000000000 +0000
7265 +++ linux-3.10.33-vs2.3.6.8/fs/xfs/xfs_ioctl.h  2013-08-22 20:30:00.000000000 +0000
7266 @@ -70,6 +70,12 @@ xfs_handle_to_dentry(
7267         void __user             *uhandle,
7268         u32                     hlen);
7269  
7270 +extern int
7271 +xfs_sync_flags(
7272 +       struct inode            *inode,
7273 +       int                     flags,
7274 +       int                     vflags);
7275 +
7276  extern long
7277  xfs_file_ioctl(
7278         struct file             *filp,
7279 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
7280 --- linux-3.10.33/fs/xfs/xfs_iops.c     2013-07-14 17:01:30.000000000 +0000
7281 +++ linux-3.10.33-vs2.3.6.8/fs/xfs/xfs_iops.c   2013-08-22 20:30:00.000000000 +0000
7282 @@ -28,6 +28,7 @@
7283  #include "xfs_bmap_btree.h"
7284  #include "xfs_dinode.h"
7285  #include "xfs_inode.h"
7286 +#include "xfs_ioctl.h"
7287  #include "xfs_bmap.h"
7288  #include "xfs_rtalloc.h"
7289  #include "xfs_error.h"
7290 @@ -47,6 +48,7 @@
7291  #include <linux/security.h>
7292  #include <linux/fiemap.h>
7293  #include <linux/slab.h>
7294 +#include <linux/vs_tag.h>
7295  
7296  static int
7297  xfs_initxattrs(
7298 @@ -422,6 +424,7 @@ xfs_vn_getattr(
7299         stat->nlink = ip->i_d.di_nlink;
7300         stat->uid = ip->i_d.di_uid;
7301         stat->gid = ip->i_d.di_gid;
7302 +       stat->tag = ip->i_d.di_tag;
7303         stat->ino = ip->i_ino;
7304         stat->atime = inode->i_atime;
7305         stat->mtime = inode->i_mtime;
7306 @@ -1054,6 +1057,7 @@ static const struct inode_operations xfs
7307         .listxattr              = xfs_vn_listxattr,
7308         .fiemap                 = xfs_vn_fiemap,
7309         .update_time            = xfs_vn_update_time,
7310 +       .sync_flags             = xfs_sync_flags,
7311  };
7312  
7313  static const struct inode_operations xfs_dir_inode_operations = {
7314 @@ -1080,6 +1084,7 @@ static const struct inode_operations xfs
7315         .removexattr            = generic_removexattr,
7316         .listxattr              = xfs_vn_listxattr,
7317         .update_time            = xfs_vn_update_time,
7318 +       .sync_flags             = xfs_sync_flags,
7319  };
7320  
7321  static const struct inode_operations xfs_dir_ci_inode_operations = {
7322 @@ -1131,6 +1136,10 @@ xfs_diflags_to_iflags(
7323                 inode->i_flags |= S_IMMUTABLE;
7324         else
7325                 inode->i_flags &= ~S_IMMUTABLE;
7326 +       if (ip->i_d.di_flags & XFS_DIFLAG_IXUNLINK)
7327 +               inode->i_flags |= S_IXUNLINK;
7328 +       else
7329 +               inode->i_flags &= ~S_IXUNLINK;
7330         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
7331                 inode->i_flags |= S_APPEND;
7332         else
7333 @@ -1143,6 +1152,15 @@ xfs_diflags_to_iflags(
7334                 inode->i_flags |= S_NOATIME;
7335         else
7336                 inode->i_flags &= ~S_NOATIME;
7337 +
7338 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_BARRIER)
7339 +               inode->i_vflags |= V_BARRIER;
7340 +       else
7341 +               inode->i_vflags &= ~V_BARRIER;
7342 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_COW)
7343 +               inode->i_vflags |= V_COW;
7344 +       else
7345 +               inode->i_vflags &= ~V_COW;
7346  }
7347  
7348  /*
7349 @@ -1174,6 +1192,7 @@ xfs_setup_inode(
7350         set_nlink(inode, ip->i_d.di_nlink);
7351         inode->i_uid    = ip->i_d.di_uid;
7352         inode->i_gid    = ip->i_d.di_gid;
7353 +       inode->i_tag    = ip->i_d.di_tag;
7354  
7355         switch (inode->i_mode & S_IFMT) {
7356         case S_IFBLK:
7357 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
7358 --- linux-3.10.33/fs/xfs/xfs_itable.c   2013-02-19 13:58:49.000000000 +0000
7359 +++ linux-3.10.33-vs2.3.6.8/fs/xfs/xfs_itable.c 2013-08-22 20:30:00.000000000 +0000
7360 @@ -97,6 +97,7 @@ xfs_bulkstat_one_int(
7361         buf->bs_mode = dic->di_mode;
7362         buf->bs_uid = dic->di_uid;
7363         buf->bs_gid = dic->di_gid;
7364 +       buf->bs_tag = dic->di_tag;
7365         buf->bs_size = dic->di_size;
7366         buf->bs_atime.tv_sec = dic->di_atime.t_sec;
7367         buf->bs_atime.tv_nsec = dic->di_atime.t_nsec;
7368 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
7369 --- linux-3.10.33/fs/xfs/xfs_linux.h    2013-07-14 17:01:30.000000000 +0000
7370 +++ linux-3.10.33-vs2.3.6.8/fs/xfs/xfs_linux.h  2013-08-22 20:30:00.000000000 +0000
7371 @@ -124,6 +124,7 @@
7372  
7373  #define current_cpu()          (raw_smp_processor_id())
7374  #define current_pid()          (current->pid)
7375 +#define current_fstag(vp)      (dx_current_fstag((vp)->i_sb))
7376  #define current_test_flags(f)  (current->flags & (f))
7377  #define current_set_flags_nested(sp, f)                \
7378                 (*(sp) = current->flags, current->flags |= (f))
7379 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
7380 --- linux-3.10.33/fs/xfs/xfs_log_recover.c      2013-07-14 17:01:31.000000000 +0000
7381 +++ linux-3.10.33-vs2.3.6.8/fs/xfs/xfs_log_recover.c    2013-08-22 21:48:01.000000000 +0000
7382 @@ -2662,7 +2662,7 @@ xlog_recover_inode_pass2(
7383         }
7384  
7385         /* The core is in in-core format */
7386 -       xfs_dinode_to_disk(dip, dicp);
7387 +       xfs_dinode_to_disk(dip, dicp, mp->m_flags & XFS_MOUNT_TAGGED);
7388  
7389         /* the rest is in on-disk format */
7390         if (item->ri_buf[1].i_len > isize) {
7391 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
7392 --- linux-3.10.33/fs/xfs/xfs_mount.h    2013-07-14 17:01:31.000000000 +0000
7393 +++ linux-3.10.33-vs2.3.6.8/fs/xfs/xfs_mount.h  2013-08-22 20:30:00.000000000 +0000
7394 @@ -253,6 +253,7 @@ typedef struct xfs_mount {
7395                                                    allocator */
7396  #define XFS_MOUNT_NOATTR2      (1ULL << 25)    /* disable use of attr2 format */
7397  
7398 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
7399  
7400  /*
7401   * Default minimum read and write sizes.
7402 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
7403 --- linux-3.10.33/fs/xfs/xfs_super.c    2013-07-14 17:01:31.000000000 +0000
7404 +++ linux-3.10.33-vs2.3.6.8/fs/xfs/xfs_super.c  2013-08-22 20:30:00.000000000 +0000
7405 @@ -114,6 +114,9 @@ mempool_t *xfs_ioend_pool;
7406  #define MNTOPT_NODELAYLOG  "nodelaylog"        /* Delayed logging disabled */
7407  #define MNTOPT_DISCARD    "discard"    /* Discard unused blocks */
7408  #define MNTOPT_NODISCARD   "nodiscard" /* Do not discard unused blocks */
7409 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
7410 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
7411 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
7412  
7413  /*
7414   * Table driven mount option parser.
7415 @@ -126,6 +129,8 @@ enum {
7416         Opt_nobarrier,
7417         Opt_inode64,
7418         Opt_inode32,
7419 +       Opt_tag,
7420 +       Opt_notag,
7421         Opt_err
7422  };
7423  
7424 @@ -134,6 +139,9 @@ static const match_table_t tokens = {
7425         {Opt_nobarrier, "nobarrier"},
7426         {Opt_inode64, "inode64"},
7427         {Opt_inode32, "inode32"},
7428 +       {Opt_tag, "tagxid"},
7429 +       {Opt_tag, "tag"},
7430 +       {Opt_notag, "notag"},
7431         {Opt_err, NULL}
7432  };
7433  
7434 @@ -392,6 +400,19 @@ xfs_parseargs(
7435                 } else if (!strcmp(this_char, "irixsgid")) {
7436                         xfs_warn(mp,
7437         "irixsgid is now a sysctl(2) variable, option is deprecated.");
7438 +#ifndef CONFIG_TAGGING_NONE
7439 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7440 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7441 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
7442 +                       mp->m_flags &= ~XFS_MOUNT_TAGGED;
7443 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
7444 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7445 +#endif
7446 +#ifdef CONFIG_PROPAGATE
7447 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7448 +                       /* use value */
7449 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7450 +#endif
7451                 } else {
7452                         xfs_warn(mp, "unknown mount option [%s].", this_char);
7453                         return EINVAL;
7454 @@ -1238,6 +1259,16 @@ xfs_fs_remount(
7455                 case Opt_inode32:
7456                         mp->m_maxagi = xfs_set_inode32(mp);
7457                         break;
7458 +               case Opt_tag:
7459 +                       if (!(sb->s_flags & MS_TAGGED)) {
7460 +                               printk(KERN_INFO
7461 +                                       "XFS: %s: tagging not permitted on remount.\n",
7462 +                                       sb->s_id);
7463 +                               return -EINVAL;
7464 +                       }
7465 +                       break;
7466 +               case Opt_notag:
7467 +                       break;
7468                 default:
7469                         /*
7470                          * Logically we would return an error here to prevent
7471 @@ -1469,6 +1500,9 @@ xfs_fs_fill_super(
7472         if (error)
7473                 goto out_free_sb;
7474  
7475 +       if (mp->m_flags & XFS_MOUNT_TAGGED)
7476 +               sb->s_flags |= MS_TAGGED;
7477 +
7478         /*
7479          * we must configure the block size in the superblock before we run the
7480          * full mount process as the mount process can lookup and cache inodes.
7481 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
7482 --- linux-3.10.33/fs/xfs/xfs_vnodeops.c 2013-07-14 17:01:31.000000000 +0000
7483 +++ linux-3.10.33-vs2.3.6.8/fs/xfs/xfs_vnodeops.c       2013-08-22 20:30:00.000000000 +0000
7484 @@ -155,6 +155,77 @@ xfs_free_eofblocks(
7485         return error;
7486  }
7487  
7488 +
7489 +STATIC void
7490 +xfs_get_inode_flags(
7491 +       xfs_inode_t     *ip)
7492 +{
7493 +       struct inode    *inode = VFS_I(ip);
7494 +       unsigned int    flags = inode->i_flags;
7495 +       unsigned int    vflags = inode->i_vflags;
7496 +
7497 +       if (flags & S_IMMUTABLE)
7498 +               ip->i_d.di_flags |= XFS_DIFLAG_IMMUTABLE;
7499 +       else
7500 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IMMUTABLE;
7501 +       if (flags & S_IXUNLINK)
7502 +               ip->i_d.di_flags |= XFS_DIFLAG_IXUNLINK;
7503 +       else
7504 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IXUNLINK;
7505 +
7506 +       if (vflags & V_BARRIER)
7507 +               ip->i_d.di_vflags |= XFS_DIVFLAG_BARRIER;
7508 +       else
7509 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_BARRIER;
7510 +       if (vflags & V_COW)
7511 +               ip->i_d.di_vflags |= XFS_DIVFLAG_COW;
7512 +       else
7513 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_COW;
7514 +}
7515 +
7516 +int
7517 +xfs_sync_flags(
7518 +       struct inode            *inode,
7519 +       int                     flags,
7520 +       int                     vflags)
7521 +{
7522 +       struct xfs_inode        *ip = XFS_I(inode);
7523 +       struct xfs_mount        *mp = ip->i_mount;
7524 +       struct xfs_trans        *tp;
7525 +       unsigned int            lock_flags = 0;
7526 +       int                     code;
7527 +
7528 +       tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
7529 +       code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
7530 +       if (code)
7531 +               goto error_out;
7532 +
7533 +       xfs_ilock(ip, XFS_ILOCK_EXCL);
7534 +       xfs_trans_ijoin(tp, ip, 0);
7535 +
7536 +       inode->i_flags = flags;
7537 +       inode->i_vflags = vflags;
7538 +       xfs_get_inode_flags(ip);
7539 +
7540 +       xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
7541 +       xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG);
7542 +
7543 +       XFS_STATS_INC(xs_ig_attrchg);
7544 +
7545 +       if (mp->m_flags & XFS_MOUNT_WSYNC)
7546 +               xfs_trans_set_sync(tp);
7547 +       code = xfs_trans_commit(tp, 0);
7548 +       xfs_iunlock(ip, XFS_ILOCK_EXCL);
7549 +       return code;
7550 +
7551 +error_out:
7552 +       xfs_trans_cancel(tp, 0);
7553 +       if (lock_flags)
7554 +               xfs_iunlock(ip, XFS_ILOCK_EXCL);
7555 +       return code;
7556 +}
7557 +
7558 +
7559  int
7560  xfs_release(
7561         xfs_inode_t     *ip)
7562 diff -NurpP --minimal linux-3.10.33/include/linux/cred.h linux-3.10.33-vs2.3.6.8/include/linux/cred.h
7563 --- linux-3.10.33/include/linux/cred.h  2013-02-19 13:58:50.000000000 +0000
7564 +++ linux-3.10.33-vs2.3.6.8/include/linux/cred.h        2013-08-22 20:30:00.000000000 +0000
7565 @@ -143,6 +143,7 @@ extern void exit_creds(struct task_struc
7566  extern int copy_creds(struct task_struct *, unsigned long);
7567  extern const struct cred *get_task_cred(struct task_struct *);
7568  extern struct cred *cred_alloc_blank(void);
7569 +extern struct cred *__prepare_creds(const struct cred *);
7570  extern struct cred *prepare_creds(void);
7571  extern struct cred *prepare_exec_creds(void);
7572  extern int commit_creds(struct cred *);
7573 @@ -196,6 +197,31 @@ static inline void validate_process_cred
7574  }
7575  #endif
7576  
7577 +static inline void set_cred_subscribers(struct cred *cred, int n)
7578 +{
7579 +#ifdef CONFIG_DEBUG_CREDENTIALS
7580 +       atomic_set(&cred->subscribers, n);
7581 +#endif
7582 +}
7583 +
7584 +static inline int read_cred_subscribers(const struct cred *cred)
7585 +{
7586 +#ifdef CONFIG_DEBUG_CREDENTIALS
7587 +       return atomic_read(&cred->subscribers);
7588 +#else
7589 +       return 0;
7590 +#endif
7591 +}
7592 +
7593 +static inline void alter_cred_subscribers(const struct cred *_cred, int n)
7594 +{
7595 +#ifdef CONFIG_DEBUG_CREDENTIALS
7596 +       struct cred *cred = (struct cred *) _cred;
7597 +
7598 +       atomic_add(n, &cred->subscribers);
7599 +#endif
7600 +}
7601 +
7602  /**
7603   * get_new_cred - Get a reference on a new set of credentials
7604   * @cred: The new credentials to reference
7605 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
7606 --- linux-3.10.33/include/linux/devpts_fs.h     2013-02-19 13:58:50.000000000 +0000
7607 +++ linux-3.10.33-vs2.3.6.8/include/linux/devpts_fs.h   2013-08-22 20:30:00.000000000 +0000
7608 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
7609  
7610  #endif
7611  
7612 -
7613  #endif /* _LINUX_DEVPTS_FS_H */
7614 diff -NurpP --minimal linux-3.10.33/include/linux/fs.h linux-3.10.33-vs2.3.6.8/include/linux/fs.h
7615 --- linux-3.10.33/include/linux/fs.h    2013-07-14 17:01:32.000000000 +0000
7616 +++ linux-3.10.33-vs2.3.6.8/include/linux/fs.h  2013-08-22 20:30:00.000000000 +0000
7617 @@ -211,6 +211,7 @@ typedef void (dio_iodone_t)(struct kiocb
7618  #define ATTR_KILL_PRIV (1 << 14)
7619  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
7620  #define ATTR_TIMES_SET (1 << 16)
7621 +#define ATTR_TAG       (1 << 17)
7622  
7623  /*
7624   * This is the Inode Attributes structure, used for notify_change().  It
7625 @@ -226,6 +227,7 @@ struct iattr {
7626         umode_t         ia_mode;
7627         kuid_t          ia_uid;
7628         kgid_t          ia_gid;
7629 +       ktag_t          ia_tag;
7630         loff_t          ia_size;
7631         struct timespec ia_atime;
7632         struct timespec ia_mtime;
7633 @@ -523,7 +525,9 @@ struct inode {
7634         unsigned short          i_opflags;
7635         kuid_t                  i_uid;
7636         kgid_t                  i_gid;
7637 -       unsigned int            i_flags;
7638 +       ktag_t                  i_tag;
7639 +       unsigned short          i_flags;
7640 +       unsigned short          i_vflags;
7641  
7642  #ifdef CONFIG_FS_POSIX_ACL
7643         struct posix_acl        *i_acl;
7644 @@ -552,6 +556,7 @@ struct inode {
7645                 unsigned int __i_nlink;
7646         };
7647         dev_t                   i_rdev;
7648 +       dev_t                   i_mdev;
7649         loff_t                  i_size;
7650         struct timespec         i_atime;
7651         struct timespec         i_mtime;
7652 @@ -704,6 +709,11 @@ static inline gid_t i_gid_read(const str
7653         return from_kgid(&init_user_ns, inode->i_gid);
7654  }
7655  
7656 +static inline vtag_t i_tag_read(const struct inode *inode)
7657 +{
7658 +       return from_ktag(&init_user_ns, inode->i_tag);
7659 +}
7660 +
7661  static inline void i_uid_write(struct inode *inode, uid_t uid)
7662  {
7663         inode->i_uid = make_kuid(&init_user_ns, uid);
7664 @@ -714,14 +724,19 @@ static inline void i_gid_write(struct in
7665         inode->i_gid = make_kgid(&init_user_ns, gid);
7666  }
7667  
7668 +static inline void i_tag_write(struct inode *inode, vtag_t tag)
7669 +{
7670 +       inode->i_tag = make_ktag(&init_user_ns, tag);
7671 +}
7672 +
7673  static inline unsigned iminor(const struct inode *inode)
7674  {
7675 -       return MINOR(inode->i_rdev);
7676 +       return MINOR(inode->i_mdev);
7677  }
7678  
7679  static inline unsigned imajor(const struct inode *inode)
7680  {
7681 -       return MAJOR(inode->i_rdev);
7682 +       return MAJOR(inode->i_mdev);
7683  }
7684  
7685  extern struct block_device *I_BDEV(struct inode *inode);
7686 @@ -788,6 +803,7 @@ struct file {
7687         loff_t                  f_pos;
7688         struct fown_struct      f_owner;
7689         const struct cred       *f_cred;
7690 +       vxid_t                  f_xid;
7691         struct file_ra_state    f_ra;
7692  
7693         u64                     f_version;
7694 @@ -939,6 +955,7 @@ struct file_lock {
7695         struct file *fl_file;
7696         loff_t fl_start;
7697         loff_t fl_end;
7698 +       vxid_t fl_xid;
7699  
7700         struct fasync_struct *  fl_fasync; /* for lease break notifications */
7701         /* for lease breaks: */
7702 @@ -1569,6 +1586,7 @@ struct inode_operations {
7703         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
7704         ssize_t (*listxattr) (struct dentry *, char *, size_t);
7705         int (*removexattr) (struct dentry *, const char *);
7706 +       int (*sync_flags) (struct inode *, int, int);
7707         int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
7708                       u64 len);
7709         int (*update_time)(struct inode *, struct timespec *, int);
7710 @@ -1581,6 +1599,7 @@ ssize_t rw_copy_check_uvector(int type,
7711                               unsigned long nr_segs, unsigned long fast_segs,
7712                               struct iovec *fast_pointer,
7713                               struct iovec **ret_pointer);
7714 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
7715  
7716  extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
7717  extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *);
7718 @@ -1634,6 +1653,14 @@ struct super_operations {
7719  #define S_IMA          1024    /* Inode has an associated IMA struct */
7720  #define S_AUTOMOUNT    2048    /* Automount/referral quasi-directory */
7721  #define S_NOSEC                4096    /* no suid or xattr security attributes */
7722 +#define S_IXUNLINK     8192    /* Immutable Invert on unlink */
7723 +
7724 +/* Linux-VServer related Inode flags */
7725 +
7726 +#define V_VALID                1
7727 +#define V_XATTR                2
7728 +#define V_BARRIER      4       /* Barrier for chroot() */
7729 +#define V_COW          8       /* Copy on Write */
7730  
7731  /*
7732   * Note that nosuid etc flags are inode-specific: setting some file-system
7733 @@ -1658,10 +1685,13 @@ struct super_operations {
7734  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
7735  #define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
7736  #define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
7737 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
7738  
7739  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
7740  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
7741  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
7742 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
7743 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
7744  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
7745  
7746  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
7747 @@ -1672,6 +1702,16 @@ struct super_operations {
7748  #define IS_AUTOMOUNT(inode)    ((inode)->i_flags & S_AUTOMOUNT)
7749  #define IS_NOSEC(inode)                ((inode)->i_flags & S_NOSEC)
7750  
7751 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
7752 +
7753 +#ifdef CONFIG_VSERVER_COWBL
7754 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
7755 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
7756 +#else
7757 +#  define IS_COW(inode)                (0)
7758 +#  define IS_COW_LINK(inode)   (0)
7759 +#endif
7760 +
7761  /*
7762   * Inode state bits.  Protected by inode->i_lock
7763   *
7764 @@ -1900,6 +1940,9 @@ extern int rw_verify_area(int, struct fi
7765  extern int locks_mandatory_locked(struct inode *);
7766  extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t);
7767  
7768 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
7769 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
7770 +
7771  /*
7772   * Candidates for mandatory locking have the setgid bit set
7773   * but no group execute bit -  an otherwise meaningless combination.
7774 @@ -2525,6 +2568,7 @@ extern int dcache_dir_open(struct inode
7775  extern int dcache_dir_close(struct inode *, struct file *);
7776  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
7777  extern int dcache_readdir(struct file *, void *, filldir_t);
7778 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
7779  extern int simple_setattr(struct dentry *, struct iattr *);
7780  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
7781  extern int simple_statfs(struct dentry *, struct kstatfs *);
7782 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
7783 --- linux-3.10.33/include/linux/init_task.h     2013-05-31 13:45:27.000000000 +0000
7784 +++ linux-3.10.33-vs2.3.6.8/include/linux/init_task.h   2013-08-22 20:30:00.000000000 +0000
7785 @@ -222,6 +222,10 @@ extern struct task_group root_task_group
7786         INIT_TASK_RCU_PREEMPT(tsk)                                      \
7787         INIT_CPUSET_SEQ                                                 \
7788         INIT_VTIME(tsk)                                                 \
7789 +       .xid            = 0,                                            \
7790 +       .vx_info        = NULL,                                         \
7791 +       .nid            = 0,                                            \
7792 +       .nx_info        = NULL,                                         \
7793  }
7794  
7795  
7796 diff -NurpP --minimal linux-3.10.33/include/linux/ipc.h linux-3.10.33-vs2.3.6.8/include/linux/ipc.h
7797 --- linux-3.10.33/include/linux/ipc.h   2012-12-11 03:30:57.000000000 +0000
7798 +++ linux-3.10.33-vs2.3.6.8/include/linux/ipc.h 2013-08-22 20:30:00.000000000 +0000
7799 @@ -16,6 +16,7 @@ struct kern_ipc_perm
7800         key_t           key;
7801         kuid_t          uid;
7802         kgid_t          gid;
7803 +       vxid_t          xid;
7804         kuid_t          cuid;
7805         kgid_t          cgid;
7806         umode_t         mode; 
7807 diff -NurpP --minimal linux-3.10.33/include/linux/loop.h linux-3.10.33-vs2.3.6.8/include/linux/loop.h
7808 --- linux-3.10.33/include/linux/loop.h  2013-02-19 13:58:51.000000000 +0000
7809 +++ linux-3.10.33-vs2.3.6.8/include/linux/loop.h        2013-08-22 20:30:00.000000000 +0000
7810 @@ -41,6 +41,7 @@ struct loop_device {
7811         struct loop_func_table *lo_encryption;
7812         __u32           lo_init[2];
7813         kuid_t          lo_key_owner;   /* Who set the key */
7814 +       vxid_t          lo_xid;
7815         int             (*ioctl)(struct loop_device *, int cmd, 
7816                                  unsigned long arg); 
7817  
7818 diff -NurpP --minimal linux-3.10.33/include/linux/memcontrol.h linux-3.10.33-vs2.3.6.8/include/linux/memcontrol.h
7819 --- linux-3.10.33/include/linux/memcontrol.h    2013-05-31 13:45:28.000000000 +0000
7820 +++ linux-3.10.33-vs2.3.6.8/include/linux/memcontrol.h  2013-08-22 20:30:00.000000000 +0000
7821 @@ -86,6 +86,13 @@ extern struct mem_cgroup *try_get_mem_cg
7822  extern struct mem_cgroup *parent_mem_cgroup(struct mem_cgroup *memcg);
7823  extern struct mem_cgroup *mem_cgroup_from_cont(struct cgroup *cont);
7824  
7825 +extern u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member);
7826 +extern u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member);
7827 +
7828 +extern s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem);
7829 +extern s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem);
7830 +extern s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem);
7831 +
7832  static inline
7833  bool mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *memcg)
7834  {
7835 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
7836 --- linux-3.10.33/include/linux/mm_types.h      2014-03-12 13:16:02.000000000 +0000
7837 +++ linux-3.10.33-vs2.3.6.8/include/linux/mm_types.h    2014-01-22 19:00:34.000000000 +0000
7838 @@ -381,6 +381,7 @@ struct mm_struct {
7839  
7840         /* Architecture-specific MM context */
7841         mm_context_t context;
7842 +       struct vx_info *mm_vx_info;
7843  
7844         unsigned long flags; /* Must use atomic bitops to access the bits */
7845  
7846 diff -NurpP --minimal linux-3.10.33/include/linux/mount.h linux-3.10.33-vs2.3.6.8/include/linux/mount.h
7847 --- linux-3.10.33/include/linux/mount.h 2013-05-31 13:45:28.000000000 +0000
7848 +++ linux-3.10.33-vs2.3.6.8/include/linux/mount.h       2013-08-22 20:30:00.000000000 +0000
7849 @@ -49,6 +49,9 @@ struct mnt_namespace;
7850  
7851  #define MNT_LOCK_READONLY      0x400000
7852  
7853 +#define MNT_TAGID      0x10000
7854 +#define MNT_NOTAG      0x20000
7855 +
7856  struct vfsmount {
7857         struct dentry *mnt_root;        /* root of the mounted tree */
7858         struct super_block *mnt_sb;     /* pointer to superblock */
7859 diff -NurpP --minimal linux-3.10.33/include/linux/net.h linux-3.10.33-vs2.3.6.8/include/linux/net.h
7860 --- linux-3.10.33/include/linux/net.h   2014-03-12 13:16:02.000000000 +0000
7861 +++ linux-3.10.33-vs2.3.6.8/include/linux/net.h 2014-01-22 19:00:34.000000000 +0000
7862 @@ -38,6 +38,7 @@ struct net;
7863  #define SOCK_PASSCRED          3
7864  #define SOCK_PASSSEC           4
7865  #define SOCK_EXTERNALLY_ALLOCATED 5
7866 +#define SOCK_USER_SOCKET       6
7867  
7868  #ifndef ARCH_HAS_SOCKET_TYPES
7869  /**
7870 diff -NurpP --minimal linux-3.10.33/include/linux/netdevice.h linux-3.10.33-vs2.3.6.8/include/linux/netdevice.h
7871 --- linux-3.10.33/include/linux/netdevice.h     2014-03-12 13:16:02.000000000 +0000
7872 +++ linux-3.10.33-vs2.3.6.8/include/linux/netdevice.h   2014-03-12 13:18:32.000000000 +0000
7873 @@ -1694,6 +1694,7 @@ extern int                init_dummy_netdev(struct net
7874  
7875  extern struct net_device       *dev_get_by_index(struct net *net, int ifindex);
7876  extern struct net_device       *__dev_get_by_index(struct net *net, int ifindex);
7877 +extern struct net_device       *dev_get_by_index_real_rcu(struct net *net, int ifindex);
7878  extern struct net_device       *dev_get_by_index_rcu(struct net *net, int ifindex);
7879  extern int             netdev_get_name(struct net *net, char *name, int ifindex);
7880  extern int             dev_restart(struct net_device *dev);
7881 diff -NurpP --minimal linux-3.10.33/include/linux/nsproxy.h linux-3.10.33-vs2.3.6.8/include/linux/nsproxy.h
7882 --- linux-3.10.33/include/linux/nsproxy.h       2013-02-19 13:58:51.000000000 +0000
7883 +++ linux-3.10.33-vs2.3.6.8/include/linux/nsproxy.h     2013-08-22 20:30:00.000000000 +0000
7884 @@ -3,6 +3,7 @@
7885  
7886  #include <linux/spinlock.h>
7887  #include <linux/sched.h>
7888 +#include <linux/vserver/debug.h>
7889  
7890  struct mnt_namespace;
7891  struct uts_namespace;
7892 @@ -63,6 +64,7 @@ static inline struct nsproxy *task_nspro
7893  }
7894  
7895  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
7896 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
7897  void exit_task_namespaces(struct task_struct *tsk);
7898  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
7899  void free_nsproxy(struct nsproxy *ns);
7900 @@ -70,16 +72,26 @@ int unshare_nsproxy_namespaces(unsigned
7901         struct cred *, struct fs_struct *);
7902  int __init nsproxy_cache_init(void);
7903  
7904 -static inline void put_nsproxy(struct nsproxy *ns)
7905 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
7906 +
7907 +static inline void __get_nsproxy(struct nsproxy *ns,
7908 +       const char *_file, int _line)
7909  {
7910 -       if (atomic_dec_and_test(&ns->count)) {
7911 -               free_nsproxy(ns);
7912 -       }
7913 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
7914 +               ns, atomic_read(&ns->count), _file, _line);
7915 +       atomic_inc(&ns->count);
7916  }
7917  
7918 -static inline void get_nsproxy(struct nsproxy *ns)
7919 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
7920 +
7921 +static inline void __put_nsproxy(struct nsproxy *ns,
7922 +       const char *_file, int _line)
7923  {
7924 -       atomic_inc(&ns->count);
7925 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
7926 +               ns, atomic_read(&ns->count), _file, _line);
7927 +       if (atomic_dec_and_test(&ns->count)) {
7928 +               free_nsproxy(ns);
7929 +       }
7930  }
7931  
7932  #endif
7933 diff -NurpP --minimal linux-3.10.33/include/linux/pid.h linux-3.10.33-vs2.3.6.8/include/linux/pid.h
7934 --- linux-3.10.33/include/linux/pid.h   2013-05-31 13:45:28.000000000 +0000
7935 +++ linux-3.10.33-vs2.3.6.8/include/linux/pid.h 2013-08-22 20:30:00.000000000 +0000
7936 @@ -8,7 +8,8 @@ enum pid_type
7937         PIDTYPE_PID,
7938         PIDTYPE_PGID,
7939         PIDTYPE_SID,
7940 -       PIDTYPE_MAX
7941 +       PIDTYPE_MAX,
7942 +       PIDTYPE_REALPID
7943  };
7944  
7945  /*
7946 @@ -172,6 +173,7 @@ static inline pid_t pid_nr(struct pid *p
7947  }
7948  
7949  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
7950 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
7951  pid_t pid_vnr(struct pid *pid);
7952  
7953  #define do_each_pid_task(pid, type, task)                              \
7954 diff -NurpP --minimal linux-3.10.33/include/linux/quotaops.h linux-3.10.33-vs2.3.6.8/include/linux/quotaops.h
7955 --- linux-3.10.33/include/linux/quotaops.h      2012-12-11 03:30:57.000000000 +0000
7956 +++ linux-3.10.33-vs2.3.6.8/include/linux/quotaops.h    2013-08-22 20:30:00.000000000 +0000
7957 @@ -8,6 +8,7 @@
7958  #define _LINUX_QUOTAOPS_
7959  
7960  #include <linux/fs.h>
7961 +#include <linux/vs_dlimit.h>
7962  
7963  #define DQUOT_SPACE_WARN       0x1
7964  #define DQUOT_SPACE_RESERVE    0x2
7965 @@ -205,11 +206,12 @@ static inline void dquot_drop(struct ino
7966  
7967  static inline int dquot_alloc_inode(const struct inode *inode)
7968  {
7969 -       return 0;
7970 +       return dl_alloc_inode(inode);
7971  }
7972  
7973  static inline void dquot_free_inode(const struct inode *inode)
7974  {
7975 +       dl_free_inode(inode);
7976  }
7977  
7978  static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
7979 @@ -220,6 +222,10 @@ static inline int dquot_transfer(struct
7980  static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
7981                 int flags)
7982  {
7983 +       int ret = 0;
7984 +
7985 +       if ((ret = dl_alloc_space(inode, number)))
7986 +               return ret;
7987         if (!(flags & DQUOT_SPACE_RESERVE))
7988                 inode_add_bytes(inode, number);
7989         return 0;
7990 @@ -230,6 +236,7 @@ static inline void __dquot_free_space(st
7991  {
7992         if (!(flags & DQUOT_SPACE_RESERVE))
7993                 inode_sub_bytes(inode, number);
7994 +       dl_free_space(inode, number);
7995  }
7996  
7997  static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
7998 diff -NurpP --minimal linux-3.10.33/include/linux/sched.h linux-3.10.33-vs2.3.6.8/include/linux/sched.h
7999 --- linux-3.10.33/include/linux/sched.h 2014-03-12 13:16:02.000000000 +0000
8000 +++ linux-3.10.33-vs2.3.6.8/include/linux/sched.h       2013-11-30 07:53:00.000000000 +0000
8001 @@ -1237,6 +1237,14 @@ struct task_struct {
8002  #endif
8003         struct seccomp seccomp;
8004  
8005 +/* vserver context data */
8006 +       struct vx_info *vx_info;
8007 +       struct nx_info *nx_info;
8008 +
8009 +       vxid_t xid;
8010 +       vnid_t nid;
8011 +       vtag_t tag;
8012 +
8013  /* Thread group tracking */
8014         u32 parent_exec_id;
8015         u32 self_exec_id;
8016 @@ -1480,6 +1488,11 @@ struct pid_namespace;
8017  pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
8018                         struct pid_namespace *ns);
8019  
8020 +#include <linux/vserver/base.h>
8021 +#include <linux/vserver/context.h>
8022 +#include <linux/vserver/debug.h>
8023 +#include <linux/vserver/pid.h>
8024 +
8025  static inline pid_t task_pid_nr(struct task_struct *tsk)
8026  {
8027         return tsk->pid;
8028 @@ -1493,7 +1506,8 @@ static inline pid_t task_pid_nr_ns(struc
8029  
8030  static inline pid_t task_pid_vnr(struct task_struct *tsk)
8031  {
8032 -       return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
8033 +       // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
8034 +       return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
8035  }
8036  
8037  
8038 @@ -1506,7 +1520,7 @@ pid_t task_tgid_nr_ns(struct task_struct
8039  
8040  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
8041  {
8042 -       return pid_vnr(task_tgid(tsk));
8043 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
8044  }
8045  
8046  
8047 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
8048 --- linux-3.10.33/include/linux/shmem_fs.h      2012-12-11 03:30:57.000000000 +0000
8049 +++ linux-3.10.33-vs2.3.6.8/include/linux/shmem_fs.h    2013-08-22 20:30:00.000000000 +0000
8050 @@ -9,6 +9,9 @@
8051  
8052  /* inode in-kernel data */
8053  
8054 +#define TMPFS_SUPER_MAGIC      0x01021994
8055 +
8056 +
8057  struct shmem_inode_info {
8058         spinlock_t              lock;
8059         unsigned long           flags;
8060 diff -NurpP --minimal linux-3.10.33/include/linux/stat.h linux-3.10.33-vs2.3.6.8/include/linux/stat.h
8061 --- linux-3.10.33/include/linux/stat.h  2012-12-11 03:30:57.000000000 +0000
8062 +++ linux-3.10.33-vs2.3.6.8/include/linux/stat.h        2013-08-22 20:30:00.000000000 +0000
8063 @@ -25,6 +25,7 @@ struct kstat {
8064         unsigned int    nlink;
8065         kuid_t          uid;
8066         kgid_t          gid;
8067 +       ktag_t          tag;
8068         dev_t           rdev;
8069         loff_t          size;
8070         struct timespec  atime;
8071 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
8072 --- linux-3.10.33/include/linux/sunrpc/auth.h   2013-07-14 17:01:33.000000000 +0000
8073 +++ linux-3.10.33-vs2.3.6.8/include/linux/sunrpc/auth.h 2013-08-22 20:30:00.000000000 +0000
8074 @@ -28,6 +28,7 @@ struct rpcsec_gss_info;
8075  struct auth_cred {
8076         kuid_t  uid;
8077         kgid_t  gid;
8078 +       ktag_t  tag;
8079         struct group_info *group_info;
8080         const char *principal;
8081         unsigned char machine_cred : 1;
8082 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
8083 --- linux-3.10.33/include/linux/sunrpc/clnt.h   2013-07-14 17:01:33.000000000 +0000
8084 +++ linux-3.10.33-vs2.3.6.8/include/linux/sunrpc/clnt.h 2013-08-22 20:30:00.000000000 +0000
8085 @@ -49,7 +49,8 @@ struct rpc_clnt {
8086         unsigned int            cl_softrtry : 1,/* soft timeouts */
8087                                 cl_discrtry : 1,/* disconnect before retry */
8088                                 cl_autobind : 1,/* use getport() */
8089 -                               cl_chatty   : 1;/* be verbose */
8090 +                               cl_chatty   : 1,/* be verbose */
8091 +                               cl_tag      : 1;/* context tagging */
8092  
8093         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
8094         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
8095 diff -NurpP --minimal linux-3.10.33/include/linux/sysfs.h linux-3.10.33-vs2.3.6.8/include/linux/sysfs.h
8096 --- linux-3.10.33/include/linux/sysfs.h 2013-05-31 13:45:28.000000000 +0000
8097 +++ linux-3.10.33-vs2.3.6.8/include/linux/sysfs.h       2013-08-22 20:30:00.000000000 +0000
8098 @@ -19,6 +19,8 @@
8099  #include <linux/kobject_ns.h>
8100  #include <linux/atomic.h>
8101  
8102 +#define SYSFS_SUPER_MAGIC      0x62656572
8103 +
8104  struct kobject;
8105  struct module;
8106  enum kobj_ns_type;
8107 diff -NurpP --minimal linux-3.10.33/include/linux/types.h linux-3.10.33-vs2.3.6.8/include/linux/types.h
8108 --- linux-3.10.33/include/linux/types.h 2013-02-19 13:58:52.000000000 +0000
8109 +++ linux-3.10.33-vs2.3.6.8/include/linux/types.h       2013-08-22 20:30:00.000000000 +0000
8110 @@ -32,6 +32,9 @@ typedef __kernel_uid32_t      uid_t;
8111  typedef __kernel_gid32_t       gid_t;
8112  typedef __kernel_uid16_t        uid16_t;
8113  typedef __kernel_gid16_t        gid16_t;
8114 +typedef unsigned int           vxid_t;
8115 +typedef unsigned int           vnid_t;
8116 +typedef unsigned int           vtag_t;
8117  
8118  typedef unsigned long          uintptr_t;
8119  
8120 diff -NurpP --minimal linux-3.10.33/include/linux/uidgid.h linux-3.10.33-vs2.3.6.8/include/linux/uidgid.h
8121 --- linux-3.10.33/include/linux/uidgid.h        2012-12-11 03:30:57.000000000 +0000
8122 +++ linux-3.10.33-vs2.3.6.8/include/linux/uidgid.h      2013-08-22 20:30:00.000000000 +0000
8123 @@ -23,13 +23,17 @@ typedef struct {
8124         uid_t val;
8125  } kuid_t;
8126  
8127 -
8128  typedef struct {
8129         gid_t val;
8130  } kgid_t;
8131  
8132 +typedef struct {
8133 +       vtag_t val;
8134 +} ktag_t;
8135 +
8136  #define KUIDT_INIT(value) (kuid_t){ value }
8137  #define KGIDT_INIT(value) (kgid_t){ value }
8138 +#define KTAGT_INIT(value) (ktag_t){ value }
8139  
8140  static inline uid_t __kuid_val(kuid_t uid)
8141  {
8142 @@ -41,10 +45,16 @@ static inline gid_t __kgid_val(kgid_t gi
8143         return gid.val;
8144  }
8145  
8146 +static inline vtag_t __ktag_val(ktag_t tag)
8147 +{
8148 +       return tag.val;
8149 +}
8150 +
8151  #else
8152  
8153  typedef uid_t kuid_t;
8154  typedef gid_t kgid_t;
8155 +typedef vtag_t ktag_t;
8156  
8157  static inline uid_t __kuid_val(kuid_t uid)
8158  {
8159 @@ -56,16 +66,24 @@ static inline gid_t __kgid_val(kgid_t gi
8160         return gid;
8161  }
8162  
8163 +static inline vtag_t __ktag_val(ktag_t tag)
8164 +{
8165 +       return tag;
8166 +}
8167 +
8168  #define KUIDT_INIT(value) ((kuid_t) value )
8169  #define KGIDT_INIT(value) ((kgid_t) value )
8170 +#define KTAGT_INIT(value) ((ktag_t) value )
8171  
8172  #endif
8173  
8174  #define GLOBAL_ROOT_UID KUIDT_INIT(0)
8175  #define GLOBAL_ROOT_GID KGIDT_INIT(0)
8176 +#define GLOBAL_ROOT_TAG KTAGT_INIT(0)
8177  
8178  #define INVALID_UID KUIDT_INIT(-1)
8179  #define INVALID_GID KGIDT_INIT(-1)
8180 +#define INVALID_TAG KTAGT_INIT(-1)
8181  
8182  static inline bool uid_eq(kuid_t left, kuid_t right)
8183  {
8184 @@ -77,6 +95,11 @@ static inline bool gid_eq(kgid_t left, k
8185         return __kgid_val(left) == __kgid_val(right);
8186  }
8187  
8188 +static inline bool tag_eq(ktag_t left, ktag_t right)
8189 +{
8190 +       return __ktag_val(left) == __ktag_val(right);
8191 +}
8192 +
8193  static inline bool uid_gt(kuid_t left, kuid_t right)
8194  {
8195         return __kuid_val(left) > __kuid_val(right);
8196 @@ -127,13 +150,21 @@ static inline bool gid_valid(kgid_t gid)
8197         return !gid_eq(gid, INVALID_GID);
8198  }
8199  
8200 +static inline bool tag_valid(ktag_t tag)
8201 +{
8202 +       return !tag_eq(tag, INVALID_TAG);
8203 +}
8204 +
8205  #ifdef CONFIG_USER_NS
8206  
8207  extern kuid_t make_kuid(struct user_namespace *from, uid_t uid);
8208  extern kgid_t make_kgid(struct user_namespace *from, gid_t gid);
8209 +extern krag_t make_ktag(struct user_namespace *from, gid_t gid);
8210  
8211  extern uid_t from_kuid(struct user_namespace *to, kuid_t uid);
8212  extern gid_t from_kgid(struct user_namespace *to, kgid_t gid);
8213 +extern vtag_t from_ktag(struct user_namespace *to, ktag_t tag);
8214 +
8215  extern uid_t from_kuid_munged(struct user_namespace *to, kuid_t uid);
8216  extern gid_t from_kgid_munged(struct user_namespace *to, kgid_t gid);
8217  
8218 @@ -159,6 +190,11 @@ static inline kgid_t make_kgid(struct us
8219         return KGIDT_INIT(gid);
8220  }
8221  
8222 +static inline ktag_t make_ktag(struct user_namespace *from, vtag_t tag)
8223 +{
8224 +       return KTAGT_INIT(tag);
8225 +}
8226 +
8227  static inline uid_t from_kuid(struct user_namespace *to, kuid_t kuid)
8228  {
8229         return __kuid_val(kuid);
8230 @@ -169,6 +205,11 @@ static inline gid_t from_kgid(struct use
8231         return __kgid_val(kgid);
8232  }
8233  
8234 +static inline vtag_t from_ktag(struct user_namespace *to, ktag_t ktag)
8235 +{
8236 +       return __ktag_val(ktag);
8237 +}
8238 +
8239  static inline uid_t from_kuid_munged(struct user_namespace *to, kuid_t kuid)
8240  {
8241         uid_t uid = from_kuid(to, kuid);
8242 diff -NurpP --minimal linux-3.10.33/include/linux/vroot.h linux-3.10.33-vs2.3.6.8/include/linux/vroot.h
8243 --- linux-3.10.33/include/linux/vroot.h 1970-01-01 00:00:00.000000000 +0000
8244 +++ linux-3.10.33-vs2.3.6.8/include/linux/vroot.h       2013-08-22 20:30:00.000000000 +0000
8245 @@ -0,0 +1,51 @@
8246 +
8247 +/*
8248 + * include/linux/vroot.h
8249 + *
8250 + * written by Herbert Pötzl, 9/11/2002
8251 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
8252 + *
8253 + * Copyright (C) 2002-2007 by Herbert Pötzl.
8254 + * Redistribution of this file is permitted under the
8255 + * GNU General Public License.
8256 + */
8257 +
8258 +#ifndef _LINUX_VROOT_H
8259 +#define _LINUX_VROOT_H
8260 +
8261 +
8262 +#ifdef __KERNEL__
8263 +
8264 +/* Possible states of device */
8265 +enum {
8266 +       Vr_unbound,
8267 +       Vr_bound,
8268 +};
8269 +
8270 +struct vroot_device {
8271 +       int             vr_number;
8272 +       int             vr_refcnt;
8273 +
8274 +       struct semaphore        vr_ctl_mutex;
8275 +       struct block_device    *vr_device;
8276 +       int                     vr_state;
8277 +};
8278 +
8279 +
8280 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
8281 +
8282 +extern int register_vroot_grb(vroot_grb_func *);
8283 +extern int unregister_vroot_grb(vroot_grb_func *);
8284 +
8285 +#endif /* __KERNEL__ */
8286 +
8287 +#define MAX_VROOT_DEFAULT      8
8288 +
8289 +/*
8290 + * IOCTL commands --- we will commandeer 0x56 ('V')
8291 + */
8292 +
8293 +#define VROOT_SET_DEV          0x5600
8294 +#define VROOT_CLR_DEV          0x5601
8295 +
8296 +#endif /* _LINUX_VROOT_H */
8297 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
8298 --- linux-3.10.33/include/linux/vs_base.h       1970-01-01 00:00:00.000000000 +0000
8299 +++ linux-3.10.33-vs2.3.6.8/include/linux/vs_base.h     2013-08-22 20:30:00.000000000 +0000
8300 @@ -0,0 +1,10 @@
8301 +#ifndef _VS_BASE_H
8302 +#define _VS_BASE_H
8303 +
8304 +#include "vserver/base.h"
8305 +#include "vserver/check.h"
8306 +#include "vserver/debug.h"
8307 +
8308 +#else
8309 +#warning duplicate inclusion
8310 +#endif
8311 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
8312 --- linux-3.10.33/include/linux/vs_context.h    1970-01-01 00:00:00.000000000 +0000
8313 +++ linux-3.10.33-vs2.3.6.8/include/linux/vs_context.h  2013-08-22 20:30:00.000000000 +0000
8314 @@ -0,0 +1,242 @@
8315 +#ifndef _VS_CONTEXT_H
8316 +#define _VS_CONTEXT_H
8317 +
8318 +#include "vserver/base.h"
8319 +#include "vserver/check.h"
8320 +#include "vserver/context.h"
8321 +#include "vserver/history.h"
8322 +#include "vserver/debug.h"
8323 +
8324 +#include <linux/sched.h>
8325 +
8326 +
8327 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
8328 +
8329 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
8330 +       const char *_file, int _line, void *_here)
8331 +{
8332 +       if (!vxi)
8333 +               return NULL;
8334 +
8335 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
8336 +               vxi, vxi ? vxi->vx_id : 0,
8337 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8338 +               _file, _line);
8339 +       __vxh_get_vx_info(vxi, _here);
8340 +
8341 +       atomic_inc(&vxi->vx_usecnt);
8342 +       return vxi;
8343 +}
8344 +
8345 +
8346 +extern void free_vx_info(struct vx_info *);
8347 +
8348 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
8349 +
8350 +static inline void __put_vx_info(struct vx_info *vxi,
8351 +       const char *_file, int _line, void *_here)
8352 +{
8353 +       if (!vxi)
8354 +               return;
8355 +
8356 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
8357 +               vxi, vxi ? vxi->vx_id : 0,
8358 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8359 +               _file, _line);
8360 +       __vxh_put_vx_info(vxi, _here);
8361 +
8362 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
8363 +               free_vx_info(vxi);
8364 +}
8365 +
8366 +
8367 +#define init_vx_info(p, i) \
8368 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
8369 +
8370 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
8371 +       const char *_file, int _line, void *_here)
8372 +{
8373 +       if (vxi) {
8374 +               vxlprintk(VXD_CBIT(xid, 3),
8375 +                       "init_vx_info(%p[#%d.%d])",
8376 +                       vxi, vxi ? vxi->vx_id : 0,
8377 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8378 +                       _file, _line);
8379 +               __vxh_init_vx_info(vxi, vxp, _here);
8380 +
8381 +               atomic_inc(&vxi->vx_usecnt);
8382 +       }
8383 +       *vxp = vxi;
8384 +}
8385 +
8386 +
8387 +#define set_vx_info(p, i) \
8388 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
8389 +
8390 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
8391 +       const char *_file, int _line, void *_here)
8392 +{
8393 +       struct vx_info *vxo;
8394 +
8395 +       if (!vxi)
8396 +               return;
8397 +
8398 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
8399 +               vxi, vxi ? vxi->vx_id : 0,
8400 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8401 +               _file, _line);
8402 +       __vxh_set_vx_info(vxi, vxp, _here);
8403 +
8404 +       atomic_inc(&vxi->vx_usecnt);
8405 +       vxo = xchg(vxp, vxi);
8406 +       BUG_ON(vxo);
8407 +}
8408 +
8409 +
8410 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
8411 +
8412 +static inline void __clr_vx_info(struct vx_info **vxp,
8413 +       const char *_file, int _line, void *_here)
8414 +{
8415 +       struct vx_info *vxo;
8416 +
8417 +       vxo = xchg(vxp, NULL);
8418 +       if (!vxo)
8419 +               return;
8420 +
8421 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
8422 +               vxo, vxo ? vxo->vx_id : 0,
8423 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
8424 +               _file, _line);
8425 +       __vxh_clr_vx_info(vxo, vxp, _here);
8426 +
8427 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
8428 +               free_vx_info(vxo);
8429 +}
8430 +
8431 +
8432 +#define claim_vx_info(v, p) \
8433 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
8434 +
8435 +static inline void __claim_vx_info(struct vx_info *vxi,
8436 +       struct task_struct *task,
8437 +       const char *_file, int _line, void *_here)
8438 +{
8439 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
8440 +               vxi, vxi ? vxi->vx_id : 0,
8441 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8442 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
8443 +               task, _file, _line);
8444 +       __vxh_claim_vx_info(vxi, task, _here);
8445 +
8446 +       atomic_inc(&vxi->vx_tasks);
8447 +}
8448 +
8449 +
8450 +extern void unhash_vx_info(struct vx_info *);
8451 +
8452 +#define release_vx_info(v, p) \
8453 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
8454 +
8455 +static inline void __release_vx_info(struct vx_info *vxi,
8456 +       struct task_struct *task,
8457 +       const char *_file, int _line, void *_here)
8458 +{
8459 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
8460 +               vxi, vxi ? vxi->vx_id : 0,
8461 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8462 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
8463 +               task, _file, _line);
8464 +       __vxh_release_vx_info(vxi, task, _here);
8465 +
8466 +       might_sleep();
8467 +
8468 +       if (atomic_dec_and_test(&vxi->vx_tasks))
8469 +               unhash_vx_info(vxi);
8470 +}
8471 +
8472 +
8473 +#define task_get_vx_info(p) \
8474 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
8475 +
8476 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
8477 +       const char *_file, int _line, void *_here)
8478 +{
8479 +       struct vx_info *vxi;
8480 +
8481 +       task_lock(p);
8482 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
8483 +               p, _file, _line);
8484 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
8485 +       task_unlock(p);
8486 +       return vxi;
8487 +}
8488 +
8489 +
8490 +static inline void __wakeup_vx_info(struct vx_info *vxi)
8491 +{
8492 +       if (waitqueue_active(&vxi->vx_wait))
8493 +               wake_up_interruptible(&vxi->vx_wait);
8494 +}
8495 +
8496 +
8497 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
8498 +
8499 +static inline void __enter_vx_info(struct vx_info *vxi,
8500 +       struct vx_info_save *vxis, const char *_file, int _line)
8501 +{
8502 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
8503 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
8504 +               current->xid, current->vx_info, _file, _line);
8505 +       vxis->vxi = xchg(&current->vx_info, vxi);
8506 +       vxis->xid = current->xid;
8507 +       current->xid = vxi ? vxi->vx_id : 0;
8508 +}
8509 +
8510 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
8511 +
8512 +static inline void __leave_vx_info(struct vx_info_save *vxis,
8513 +       const char *_file, int _line)
8514 +{
8515 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
8516 +               vxis, vxis->xid, vxis->vxi, current,
8517 +               current->xid, current->vx_info, _file, _line);
8518 +       (void)xchg(&current->vx_info, vxis->vxi);
8519 +       current->xid = vxis->xid;
8520 +}
8521 +
8522 +
8523 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
8524 +{
8525 +       vxis->vxi = xchg(&current->vx_info, NULL);
8526 +       vxis->xid = xchg(&current->xid, (vxid_t)0);
8527 +}
8528 +
8529 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
8530 +{
8531 +       (void)xchg(&current->xid, vxis->xid);
8532 +       (void)xchg(&current->vx_info, vxis->vxi);
8533 +}
8534 +
8535 +#define task_is_init(p) \
8536 +       __task_is_init(p, __FILE__, __LINE__, __HERE__)
8537 +
8538 +static inline int __task_is_init(struct task_struct *p,
8539 +       const char *_file, int _line, void *_here)
8540 +{
8541 +       int is_init = is_global_init(p);
8542 +
8543 +       task_lock(p);
8544 +       if (p->vx_info)
8545 +               is_init = p->vx_info->vx_initpid == p->pid;
8546 +       task_unlock(p);
8547 +       return is_init;
8548 +}
8549 +
8550 +extern void exit_vx_info(struct task_struct *, int);
8551 +extern void exit_vx_info_early(struct task_struct *, int);
8552 +
8553 +
8554 +#else
8555 +#warning duplicate inclusion
8556 +#endif
8557 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
8558 --- linux-3.10.33/include/linux/vs_cowbl.h      1970-01-01 00:00:00.000000000 +0000
8559 +++ linux-3.10.33-vs2.3.6.8/include/linux/vs_cowbl.h    2013-08-22 20:30:00.000000000 +0000
8560 @@ -0,0 +1,48 @@
8561 +#ifndef _VS_COWBL_H
8562 +#define _VS_COWBL_H
8563 +
8564 +#include <linux/fs.h>
8565 +#include <linux/dcache.h>
8566 +#include <linux/namei.h>
8567 +#include <linux/slab.h>
8568 +
8569 +extern struct dentry *cow_break_link(const char *pathname);
8570 +
8571 +static inline int cow_check_and_break(struct path *path)
8572 +{
8573 +       struct inode *inode = path->dentry->d_inode;
8574 +       int error = 0;
8575 +
8576 +       /* do we need this check? */
8577 +       if (IS_RDONLY(inode))
8578 +               return -EROFS;
8579 +
8580 +       if (IS_COW(inode)) {
8581 +               if (IS_COW_LINK(inode)) {
8582 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
8583 +                       char *pp, *buf;
8584 +
8585 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
8586 +                       if (!buf) {
8587 +                               return -ENOMEM;
8588 +                       }
8589 +                       pp = d_path(path, buf, PATH_MAX);
8590 +                       new_dentry = cow_break_link(pp);
8591 +                       kfree(buf);
8592 +                       if (!IS_ERR(new_dentry)) {
8593 +                               path->dentry = new_dentry;
8594 +                               dput(old_dentry);
8595 +                       } else
8596 +                               error = PTR_ERR(new_dentry);
8597 +               } else {
8598 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
8599 +                       inode->i_ctime = CURRENT_TIME;
8600 +                       mark_inode_dirty(inode);
8601 +               }
8602 +       }
8603 +       return error;
8604 +}
8605 +
8606 +#else
8607 +#warning duplicate inclusion
8608 +#endif
8609 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
8610 --- linux-3.10.33/include/linux/vs_cvirt.h      1970-01-01 00:00:00.000000000 +0000
8611 +++ linux-3.10.33-vs2.3.6.8/include/linux/vs_cvirt.h    2013-08-22 20:30:00.000000000 +0000
8612 @@ -0,0 +1,50 @@
8613 +#ifndef _VS_CVIRT_H
8614 +#define _VS_CVIRT_H
8615 +
8616 +#include "vserver/cvirt.h"
8617 +#include "vserver/context.h"
8618 +#include "vserver/base.h"
8619 +#include "vserver/check.h"
8620 +#include "vserver/debug.h"
8621 +
8622 +
8623 +static inline void vx_activate_task(struct task_struct *p)
8624 +{
8625 +       struct vx_info *vxi;
8626 +
8627 +       if ((vxi = p->vx_info)) {
8628 +               vx_update_load(vxi);
8629 +               atomic_inc(&vxi->cvirt.nr_running);
8630 +       }
8631 +}
8632 +
8633 +static inline void vx_deactivate_task(struct task_struct *p)
8634 +{
8635 +       struct vx_info *vxi;
8636 +
8637 +       if ((vxi = p->vx_info)) {
8638 +               vx_update_load(vxi);
8639 +               atomic_dec(&vxi->cvirt.nr_running);
8640 +       }
8641 +}
8642 +
8643 +static inline void vx_uninterruptible_inc(struct task_struct *p)
8644 +{
8645 +       struct vx_info *vxi;
8646 +
8647 +       if ((vxi = p->vx_info))
8648 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
8649 +}
8650 +
8651 +static inline void vx_uninterruptible_dec(struct task_struct *p)
8652 +{
8653 +       struct vx_info *vxi;
8654 +
8655 +       if ((vxi = p->vx_info))
8656 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
8657 +}
8658 +
8659 +
8660 +#else
8661 +#warning duplicate inclusion
8662 +#endif
8663 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
8664 --- linux-3.10.33/include/linux/vs_device.h     1970-01-01 00:00:00.000000000 +0000
8665 +++ linux-3.10.33-vs2.3.6.8/include/linux/vs_device.h   2013-08-22 20:30:00.000000000 +0000
8666 @@ -0,0 +1,45 @@
8667 +#ifndef _VS_DEVICE_H
8668 +#define _VS_DEVICE_H
8669 +
8670 +#include "vserver/base.h"
8671 +#include "vserver/device.h"
8672 +#include "vserver/debug.h"
8673 +
8674 +
8675 +#ifdef CONFIG_VSERVER_DEVICE
8676 +
8677 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
8678 +
8679 +#define vs_device_perm(v, d, m, p) \
8680 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
8681 +
8682 +#else
8683 +
8684 +static inline
8685 +int vs_map_device(struct vx_info *vxi,
8686 +       dev_t device, dev_t *target, umode_t mode)
8687 +{
8688 +       if (target)
8689 +               *target = device;
8690 +       return ~0;
8691 +}
8692 +
8693 +#define vs_device_perm(v, d, m, p) ((p) == (p))
8694 +
8695 +#endif
8696 +
8697 +
8698 +#define vs_map_chrdev(d, t, p) \
8699 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
8700 +#define vs_map_blkdev(d, t, p) \
8701 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
8702 +
8703 +#define vs_chrdev_perm(d, p) \
8704 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
8705 +#define vs_blkdev_perm(d, p) \
8706 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
8707 +
8708 +
8709 +#else
8710 +#warning duplicate inclusion
8711 +#endif
8712 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
8713 --- linux-3.10.33/include/linux/vs_dlimit.h     1970-01-01 00:00:00.000000000 +0000
8714 +++ linux-3.10.33-vs2.3.6.8/include/linux/vs_dlimit.h   2013-08-22 20:30:00.000000000 +0000
8715 @@ -0,0 +1,215 @@
8716 +#ifndef _VS_DLIMIT_H
8717 +#define _VS_DLIMIT_H
8718 +
8719 +#include <linux/fs.h>
8720 +
8721 +#include "vserver/dlimit.h"
8722 +#include "vserver/base.h"
8723 +#include "vserver/debug.h"
8724 +
8725 +
8726 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
8727 +
8728 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
8729 +       const char *_file, int _line)
8730 +{
8731 +       if (!dli)
8732 +               return NULL;
8733 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
8734 +               dli, dli ? dli->dl_tag : 0,
8735 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
8736 +               _file, _line);
8737 +       atomic_inc(&dli->dl_usecnt);
8738 +       return dli;
8739 +}
8740 +
8741 +
8742 +#define free_dl_info(i) \
8743 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
8744 +
8745 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
8746 +
8747 +static inline void __put_dl_info(struct dl_info *dli,
8748 +       const char *_file, int _line)
8749 +{
8750 +       if (!dli)
8751 +               return;
8752 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
8753 +               dli, dli ? dli->dl_tag : 0,
8754 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
8755 +               _file, _line);
8756 +       if (atomic_dec_and_test(&dli->dl_usecnt))
8757 +               free_dl_info(dli);
8758 +}
8759 +
8760 +
8761 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
8762 +
8763 +static inline int __dl_alloc_space(struct super_block *sb,
8764 +       vtag_t tag, dlsize_t nr, const char *file, int line)
8765 +{
8766 +       struct dl_info *dli = NULL;
8767 +       int ret = 0;
8768 +
8769 +       if (nr == 0)
8770 +               goto out;
8771 +       dli = locate_dl_info(sb, tag);
8772 +       if (!dli)
8773 +               goto out;
8774 +
8775 +       spin_lock(&dli->dl_lock);
8776 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
8777 +       if (!ret)
8778 +               dli->dl_space_used += nr;
8779 +       spin_unlock(&dli->dl_lock);
8780 +       put_dl_info(dli);
8781 +out:
8782 +       vxlprintk(VXD_CBIT(dlim, 1),
8783 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
8784 +               sb, tag, __dlimit_char(dli), (long long)nr,
8785 +               ret, file, line);
8786 +       return ret ? -ENOSPC : 0;
8787 +}
8788 +
8789 +static inline void __dl_free_space(struct super_block *sb,
8790 +       vtag_t tag, dlsize_t nr, const char *_file, int _line)
8791 +{
8792 +       struct dl_info *dli = NULL;
8793 +
8794 +       if (nr == 0)
8795 +               goto out;
8796 +       dli = locate_dl_info(sb, tag);
8797 +       if (!dli)
8798 +               goto out;
8799 +
8800 +       spin_lock(&dli->dl_lock);
8801 +       if (dli->dl_space_used > nr)
8802 +               dli->dl_space_used -= nr;
8803 +       else
8804 +               dli->dl_space_used = 0;
8805 +       spin_unlock(&dli->dl_lock);
8806 +       put_dl_info(dli);
8807 +out:
8808 +       vxlprintk(VXD_CBIT(dlim, 1),
8809 +               "FREE  (%p,#%d)%c %lld bytes",
8810 +               sb, tag, __dlimit_char(dli), (long long)nr,
8811 +               _file, _line);
8812 +}
8813 +
8814 +static inline int __dl_alloc_inode(struct super_block *sb,
8815 +       vtag_t tag, const char *_file, int _line)
8816 +{
8817 +       struct dl_info *dli;
8818 +       int ret = 0;
8819 +
8820 +       dli = locate_dl_info(sb, tag);
8821 +       if (!dli)
8822 +               goto out;
8823 +
8824 +       spin_lock(&dli->dl_lock);
8825 +       dli->dl_inodes_used++;
8826 +       ret = (dli->dl_inodes_used > dli->dl_inodes_total);
8827 +       spin_unlock(&dli->dl_lock);
8828 +       put_dl_info(dli);
8829 +out:
8830 +       vxlprintk(VXD_CBIT(dlim, 0),
8831 +               "ALLOC (%p,#%d)%c inode (%d)",
8832 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
8833 +       return ret ? -ENOSPC : 0;
8834 +}
8835 +
8836 +static inline void __dl_free_inode(struct super_block *sb,
8837 +       vtag_t tag, const char *_file, int _line)
8838 +{
8839 +       struct dl_info *dli;
8840 +
8841 +       dli = locate_dl_info(sb, tag);
8842 +       if (!dli)
8843 +               goto out;
8844 +
8845 +       spin_lock(&dli->dl_lock);
8846 +       if (dli->dl_inodes_used > 1)
8847 +               dli->dl_inodes_used--;
8848 +       else
8849 +               dli->dl_inodes_used = 0;
8850 +       spin_unlock(&dli->dl_lock);
8851 +       put_dl_info(dli);
8852 +out:
8853 +       vxlprintk(VXD_CBIT(dlim, 0),
8854 +               "FREE  (%p,#%d)%c inode",
8855 +               sb, tag, __dlimit_char(dli), _file, _line);
8856 +}
8857 +
8858 +static inline void __dl_adjust_block(struct super_block *sb, vtag_t tag,
8859 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
8860 +       const char *_file, int _line)
8861 +{
8862 +       struct dl_info *dli;
8863 +       uint64_t broot, bfree;
8864 +
8865 +       dli = locate_dl_info(sb, tag);
8866 +       if (!dli)
8867 +               return;
8868 +
8869 +       spin_lock(&dli->dl_lock);
8870 +       broot = (dli->dl_space_total -
8871 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
8872 +               >> sb->s_blocksize_bits;
8873 +       bfree = (dli->dl_space_total - dli->dl_space_used)
8874 +                       >> sb->s_blocksize_bits;
8875 +       spin_unlock(&dli->dl_lock);
8876 +
8877 +       vxlprintk(VXD_CBIT(dlim, 2),
8878 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
8879 +               (long long)bfree, (long long)broot,
8880 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
8881 +               _file, _line);
8882 +       if (free_blocks) {
8883 +               if (*free_blocks > bfree)
8884 +                       *free_blocks = bfree;
8885 +       }
8886 +       if (root_blocks) {
8887 +               if (*root_blocks > broot)
8888 +                       *root_blocks = broot;
8889 +       }
8890 +       put_dl_info(dli);
8891 +}
8892 +
8893 +#define dl_prealloc_space(in, bytes) \
8894 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8895 +               __FILE__, __LINE__ )
8896 +
8897 +#define dl_alloc_space(in, bytes) \
8898 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8899 +               __FILE__, __LINE__ )
8900 +
8901 +#define dl_reserve_space(in, bytes) \
8902 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8903 +               __FILE__, __LINE__ )
8904 +
8905 +#define dl_claim_space(in, bytes) (0)
8906 +
8907 +#define dl_release_space(in, bytes) \
8908 +       __dl_free_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8909 +               __FILE__, __LINE__ )
8910 +
8911 +#define dl_free_space(in, bytes) \
8912 +       __dl_free_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8913 +               __FILE__, __LINE__ )
8914 +
8915 +
8916 +
8917 +#define dl_alloc_inode(in) \
8918 +       __dl_alloc_inode((in)->i_sb, i_tag_read(in), __FILE__, __LINE__ )
8919 +
8920 +#define dl_free_inode(in) \
8921 +       __dl_free_inode((in)->i_sb, i_tag_read(in), __FILE__, __LINE__ )
8922 +
8923 +
8924 +#define dl_adjust_block(sb, tag, fb, rb) \
8925 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
8926 +
8927 +
8928 +#else
8929 +#warning duplicate inclusion
8930 +#endif
8931 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
8932 --- linux-3.10.33/include/linux/vs_inet.h       1970-01-01 00:00:00.000000000 +0000
8933 +++ linux-3.10.33-vs2.3.6.8/include/linux/vs_inet.h     2013-08-22 20:30:00.000000000 +0000
8934 @@ -0,0 +1,364 @@
8935 +#ifndef _VS_INET_H
8936 +#define _VS_INET_H
8937 +
8938 +#include "vserver/base.h"
8939 +#include "vserver/network.h"
8940 +#include "vserver/debug.h"
8941 +
8942 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
8943 +
8944 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
8945 +                       NIPQUAD((a)->mask), (a)->type
8946 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
8947 +
8948 +#define NIPQUAD(addr) \
8949 +       ((unsigned char *)&addr)[0], \
8950 +       ((unsigned char *)&addr)[1], \
8951 +       ((unsigned char *)&addr)[2], \
8952 +       ((unsigned char *)&addr)[3]
8953 +
8954 +#define NIPQUAD_FMT "%u.%u.%u.%u"
8955 +
8956 +
8957 +static inline
8958 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
8959 +{
8960 +       __be32 ip = nxa->ip[0].s_addr;
8961 +       __be32 mask = nxa->mask.s_addr;
8962 +       __be32 bcast = ip | ~mask;
8963 +       int ret = 0;
8964 +
8965 +       switch (nxa->type & tmask) {
8966 +       case NXA_TYPE_MASK:
8967 +               ret = (ip == (addr & mask));
8968 +               break;
8969 +       case NXA_TYPE_ADDR:
8970 +               ret = 3;
8971 +               if (addr == ip)
8972 +                       break;
8973 +               /* fall through to broadcast */
8974 +       case NXA_MOD_BCAST:
8975 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
8976 +               break;
8977 +       case NXA_TYPE_RANGE:
8978 +               ret = ((nxa->ip[0].s_addr <= addr) &&
8979 +                       (nxa->ip[1].s_addr > addr));
8980 +               break;
8981 +       case NXA_TYPE_ANY:
8982 +               ret = 2;
8983 +               break;
8984 +       }
8985 +
8986 +       vxdprintk(VXD_CBIT(net, 0),
8987 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
8988 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
8989 +       return ret;
8990 +}
8991 +
8992 +static inline
8993 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
8994 +{
8995 +       struct nx_addr_v4 *nxa;
8996 +       unsigned long irqflags;
8997 +       int ret = 1;
8998 +
8999 +       if (!nxi)
9000 +               goto out;
9001 +
9002 +       ret = 2;
9003 +       /* allow 127.0.0.1 when remapping lback */
9004 +       if ((tmask & NXA_LOOPBACK) &&
9005 +               (addr == IPI_LOOPBACK) &&
9006 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9007 +               goto out;
9008 +       ret = 3;
9009 +       /* check for lback address */
9010 +       if ((tmask & NXA_MOD_LBACK) &&
9011 +               (nxi->v4_lback.s_addr == addr))
9012 +               goto out;
9013 +       ret = 4;
9014 +       /* check for broadcast address */
9015 +       if ((tmask & NXA_MOD_BCAST) &&
9016 +               (nxi->v4_bcast.s_addr == addr))
9017 +               goto out;
9018 +       ret = 5;
9019 +
9020 +       /* check for v4 addresses */
9021 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
9022 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
9023 +               if (v4_addr_match(nxa, addr, tmask))
9024 +                       goto out_unlock;
9025 +       ret = 0;
9026 +out_unlock:
9027 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
9028 +out:
9029 +       vxdprintk(VXD_CBIT(net, 0),
9030 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
9031 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
9032 +       return ret;
9033 +}
9034 +
9035 +static inline
9036 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
9037 +{
9038 +       /* FIXME: needs full range checks */
9039 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
9040 +}
9041 +
9042 +static inline
9043 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
9044 +{
9045 +       struct nx_addr_v4 *ptr;
9046 +       unsigned long irqflags;
9047 +       int ret = 1;
9048 +
9049 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
9050 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
9051 +               if (v4_nx_addr_match(ptr, nxa, mask))
9052 +                       goto out_unlock;
9053 +       ret = 0;
9054 +out_unlock:
9055 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
9056 +       return ret;
9057 +}
9058 +
9059 +#include <net/inet_sock.h>
9060 +
9061 +/*
9062 + *     Check if a given address matches for a socket
9063 + *
9064 + *     nxi:            the socket's nx_info if any
9065 + *     addr:           to be verified address
9066 + */
9067 +static inline
9068 +int v4_sock_addr_match (
9069 +       struct nx_info *nxi,
9070 +       struct inet_sock *inet,
9071 +       __be32 addr)
9072 +{
9073 +       __be32 saddr = inet->inet_rcv_saddr;
9074 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
9075 +
9076 +       if (addr && (saddr == addr || bcast == addr))
9077 +               return 1;
9078 +       if (!saddr)
9079 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
9080 +       return 0;
9081 +}
9082 +
9083 +
9084 +/* inet related checks and helpers */
9085 +
9086 +
9087 +struct in_ifaddr;
9088 +struct net_device;
9089 +struct sock;
9090 +
9091 +#ifdef CONFIG_INET
9092 +
9093 +#include <linux/netdevice.h>
9094 +#include <linux/inetdevice.h>
9095 +#include <net/inet_sock.h>
9096 +#include <net/inet_timewait_sock.h>
9097 +
9098 +
9099 +int dev_in_nx_info(struct net_device *, struct nx_info *);
9100 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
9101 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
9102 +
9103 +
9104 +/*
9105 + *     check if address is covered by socket
9106 + *
9107 + *     sk:     the socket to check against
9108 + *     addr:   the address in question (must be != 0)
9109 + */
9110 +
9111 +static inline
9112 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
9113 +{
9114 +       struct nx_info *nxi = sk->sk_nx_info;
9115 +       __be32 saddr = sk_rcv_saddr(sk);
9116 +
9117 +       vxdprintk(VXD_CBIT(net, 5),
9118 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
9119 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
9120 +               (sk->sk_socket?sk->sk_socket->flags:0));
9121 +
9122 +       if (saddr) {            /* direct address match */
9123 +               return v4_addr_match(nxa, saddr, -1);
9124 +       } else if (nxi) {       /* match against nx_info */
9125 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
9126 +       } else {                /* unrestricted any socket */
9127 +               return 1;
9128 +       }
9129 +}
9130 +
9131 +
9132 +
9133 +static inline
9134 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
9135 +{
9136 +       vxdprintk(VXD_CBIT(net, 1),
9137 +               "nx_dev_visible(%p[#%u],%p " VS_Q("%s") ") %d",
9138 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
9139 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
9140 +
9141 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9142 +               return 1;
9143 +       if (dev_in_nx_info(dev, nxi))
9144 +               return 1;
9145 +       return 0;
9146 +}
9147 +
9148 +
9149 +static inline
9150 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
9151 +{
9152 +       if (!nxi)
9153 +               return 1;
9154 +       if (!ifa)
9155 +               return 0;
9156 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
9157 +}
9158 +
9159 +static inline
9160 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
9161 +{
9162 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
9163 +               nxi, nxi ? nxi->nx_id : 0, ifa,
9164 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
9165 +
9166 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9167 +               return 1;
9168 +       if (v4_ifa_in_nx_info(ifa, nxi))
9169 +               return 1;
9170 +       return 0;
9171 +}
9172 +
9173 +
9174 +struct nx_v4_sock_addr {
9175 +       __be32 saddr;   /* Address used for validation */
9176 +       __be32 baddr;   /* Address used for socket bind */
9177 +};
9178 +
9179 +static inline
9180 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
9181 +       struct nx_v4_sock_addr *nsa)
9182 +{
9183 +       struct sock *sk = &inet->sk;
9184 +       struct nx_info *nxi = sk->sk_nx_info;
9185 +       __be32 saddr = addr->sin_addr.s_addr;
9186 +       __be32 baddr = saddr;
9187 +
9188 +       vxdprintk(VXD_CBIT(net, 3),
9189 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
9190 +               sk, sk->sk_nx_info, sk->sk_socket,
9191 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
9192 +               NIPQUAD(saddr));
9193 +
9194 +       if (nxi) {
9195 +               if (saddr == INADDR_ANY) {
9196 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
9197 +                               baddr = nxi->v4.ip[0].s_addr;
9198 +               } else if (saddr == IPI_LOOPBACK) {
9199 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9200 +                               baddr = nxi->v4_lback.s_addr;
9201 +               } else if (!ipv4_is_multicast(saddr) ||
9202 +                       !nx_info_ncaps(nxi, NXC_MULTICAST)) {
9203 +                       /* normal address bind */
9204 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
9205 +                               return -EADDRNOTAVAIL;
9206 +               }
9207 +       }
9208 +
9209 +       vxdprintk(VXD_CBIT(net, 3),
9210 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
9211 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
9212 +
9213 +       nsa->saddr = saddr;
9214 +       nsa->baddr = baddr;
9215 +       return 0;
9216 +}
9217 +
9218 +static inline
9219 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
9220 +{
9221 +       inet->inet_saddr = nsa->baddr;
9222 +       inet->inet_rcv_saddr = nsa->baddr;
9223 +}
9224 +
9225 +
9226 +/*
9227 + *      helper to simplify inet_lookup_listener
9228 + *
9229 + *      nxi:   the socket's nx_info if any
9230 + *      addr:  to be verified address
9231 + *      saddr: socket address
9232 + */
9233 +static inline int v4_inet_addr_match (
9234 +       struct nx_info *nxi,
9235 +       __be32 addr,
9236 +       __be32 saddr)
9237 +{
9238 +       if (addr && (saddr == addr))
9239 +               return 1;
9240 +       if (!saddr)
9241 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
9242 +       return 0;
9243 +}
9244 +
9245 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
9246 +{
9247 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
9248 +               (addr == nxi->v4_lback.s_addr))
9249 +               return IPI_LOOPBACK;
9250 +       return addr;
9251 +}
9252 +
9253 +static inline
9254 +int nx_info_has_v4(struct nx_info *nxi)
9255 +{
9256 +       if (!nxi)
9257 +               return 1;
9258 +       if (NX_IPV4(nxi))
9259 +               return 1;
9260 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9261 +               return 1;
9262 +       return 0;
9263 +}
9264 +
9265 +#else /* CONFIG_INET */
9266 +
9267 +static inline
9268 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
9269 +{
9270 +       return 1;
9271 +}
9272 +
9273 +static inline
9274 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
9275 +{
9276 +       return 1;
9277 +}
9278 +
9279 +static inline
9280 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
9281 +{
9282 +       return 1;
9283 +}
9284 +
9285 +static inline
9286 +int nx_info_has_v4(struct nx_info *nxi)
9287 +{
9288 +       return 0;
9289 +}
9290 +
9291 +#endif /* CONFIG_INET */
9292 +
9293 +#define current_nx_info_has_v4() \
9294 +       nx_info_has_v4(current_nx_info())
9295 +
9296 +#else
9297 +// #warning duplicate inclusion
9298 +#endif
9299 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
9300 --- linux-3.10.33/include/linux/vs_inet6.h      1970-01-01 00:00:00.000000000 +0000
9301 +++ linux-3.10.33-vs2.3.6.8/include/linux/vs_inet6.h    2013-08-22 20:30:00.000000000 +0000
9302 @@ -0,0 +1,257 @@
9303 +#ifndef _VS_INET6_H
9304 +#define _VS_INET6_H
9305 +
9306 +#include "vserver/base.h"
9307 +#include "vserver/network.h"
9308 +#include "vserver/debug.h"
9309 +
9310 +#include <net/ipv6.h>
9311 +
9312 +#define NXAV6(a)       &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
9313 +#define NXAV6_FMT      "[%pI6/%pI6/%d:%04x]"
9314 +
9315 +
9316 +#ifdef CONFIG_IPV6
9317 +
9318 +static inline
9319 +int v6_addr_match(struct nx_addr_v6 *nxa,
9320 +       const struct in6_addr *addr, uint16_t mask)
9321 +{
9322 +       int ret = 0;
9323 +
9324 +       switch (nxa->type & mask) {
9325 +       case NXA_TYPE_MASK:
9326 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
9327 +               break;
9328 +       case NXA_TYPE_ADDR:
9329 +               ret = ipv6_addr_equal(&nxa->ip, addr);
9330 +               break;
9331 +       case NXA_TYPE_ANY:
9332 +               ret = 1;
9333 +               break;
9334 +       }
9335 +       vxdprintk(VXD_CBIT(net, 0),
9336 +               "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
9337 +               nxa, NXAV6(nxa), addr, mask, ret);
9338 +       return ret;
9339 +}
9340 +
9341 +static inline
9342 +int v6_addr_in_nx_info(struct nx_info *nxi,
9343 +       const struct in6_addr *addr, uint16_t mask)
9344 +{
9345 +       struct nx_addr_v6 *nxa;
9346 +       unsigned long irqflags;
9347 +       int ret = 1;
9348 +
9349 +       if (!nxi)
9350 +               goto out;
9351 +
9352 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
9353 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
9354 +               if (v6_addr_match(nxa, addr, mask))
9355 +                       goto out_unlock;
9356 +       ret = 0;
9357 +out_unlock:
9358 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
9359 +out:
9360 +       vxdprintk(VXD_CBIT(net, 0),
9361 +               "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
9362 +               nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
9363 +       return ret;
9364 +}
9365 +
9366 +static inline
9367 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
9368 +{
9369 +       /* FIXME: needs full range checks */
9370 +       return v6_addr_match(nxa, &addr->ip, mask);
9371 +}
9372 +
9373 +static inline
9374 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
9375 +{
9376 +       struct nx_addr_v6 *ptr;
9377 +       unsigned long irqflags;
9378 +       int ret = 1;
9379 +
9380 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
9381 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
9382 +               if (v6_nx_addr_match(ptr, nxa, mask))
9383 +                       goto out_unlock;
9384 +       ret = 0;
9385 +out_unlock:
9386 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
9387 +       return ret;
9388 +}
9389 +
9390 +
9391 +/*
9392 + *     Check if a given address matches for a socket
9393 + *
9394 + *     nxi:            the socket's nx_info if any
9395 + *     addr:           to be verified address
9396 + */
9397 +static inline
9398 +int v6_sock_addr_match (
9399 +       struct nx_info *nxi,
9400 +       struct inet_sock *inet,
9401 +       struct in6_addr *addr)
9402 +{
9403 +       struct sock *sk = &inet->sk;
9404 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
9405 +
9406 +       if (!ipv6_addr_any(addr) &&
9407 +               ipv6_addr_equal(saddr, addr))
9408 +               return 1;
9409 +       if (ipv6_addr_any(saddr))
9410 +               return v6_addr_in_nx_info(nxi, addr, -1);
9411 +       return 0;
9412 +}
9413 +
9414 +/*
9415 + *     check if address is covered by socket
9416 + *
9417 + *     sk:     the socket to check against
9418 + *     addr:   the address in question (must be != 0)
9419 + */
9420 +
9421 +static inline
9422 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
9423 +{
9424 +       struct nx_info *nxi = sk->sk_nx_info;
9425 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
9426 +
9427 +       vxdprintk(VXD_CBIT(net, 5),
9428 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
9429 +               sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
9430 +               (sk->sk_socket?sk->sk_socket->flags:0));
9431 +
9432 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
9433 +               return v6_addr_match(nxa, saddr, -1);
9434 +       } else if (nxi) {               /* match against nx_info */
9435 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
9436 +       } else {                        /* unrestricted any socket */
9437 +               return 1;
9438 +       }
9439 +}
9440 +
9441 +
9442 +/* inet related checks and helpers */
9443 +
9444 +
9445 +struct in_ifaddr;
9446 +struct net_device;
9447 +struct sock;
9448 +
9449 +
9450 +#include <linux/netdevice.h>
9451 +#include <linux/inetdevice.h>
9452 +#include <net/inet_timewait_sock.h>
9453 +
9454 +
9455 +int dev_in_nx_info(struct net_device *, struct nx_info *);
9456 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
9457 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
9458 +
9459 +
9460 +
9461 +static inline
9462 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
9463 +{
9464 +       if (!nxi)
9465 +               return 1;
9466 +       if (!ifa)
9467 +               return 0;
9468 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
9469 +}
9470 +
9471 +static inline
9472 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
9473 +{
9474 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
9475 +               nxi, nxi ? nxi->nx_id : 0, ifa,
9476 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
9477 +
9478 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9479 +               return 1;
9480 +       if (v6_ifa_in_nx_info(ifa, nxi))
9481 +               return 1;
9482 +       return 0;
9483 +}
9484 +
9485 +
9486 +struct nx_v6_sock_addr {
9487 +       struct in6_addr saddr;  /* Address used for validation */
9488 +       struct in6_addr baddr;  /* Address used for socket bind */
9489 +};
9490 +
9491 +static inline
9492 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
9493 +       struct nx_v6_sock_addr *nsa)
9494 +{
9495 +       // struct sock *sk = &inet->sk;
9496 +       // struct nx_info *nxi = sk->sk_nx_info;
9497 +       struct in6_addr saddr = addr->sin6_addr;
9498 +       struct in6_addr baddr = saddr;
9499 +
9500 +       nsa->saddr = saddr;
9501 +       nsa->baddr = baddr;
9502 +       return 0;
9503 +}
9504 +
9505 +static inline
9506 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
9507 +{
9508 +       // struct sock *sk = &inet->sk;
9509 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
9510 +
9511 +       // *saddr = nsa->baddr;
9512 +       // inet->inet_saddr = nsa->baddr;
9513 +}
9514 +
9515 +static inline
9516 +int nx_info_has_v6(struct nx_info *nxi)
9517 +{
9518 +       if (!nxi)
9519 +               return 1;
9520 +       if (NX_IPV6(nxi))
9521 +               return 1;
9522 +       return 0;
9523 +}
9524 +
9525 +#else /* CONFIG_IPV6 */
9526 +
9527 +static inline
9528 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
9529 +{
9530 +       return 1;
9531 +}
9532 +
9533 +
9534 +static inline
9535 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
9536 +{
9537 +       return 1;
9538 +}
9539 +
9540 +static inline
9541 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
9542 +{
9543 +       return 1;
9544 +}
9545 +
9546 +static inline
9547 +int nx_info_has_v6(struct nx_info *nxi)
9548 +{
9549 +       return 0;
9550 +}
9551 +
9552 +#endif /* CONFIG_IPV6 */
9553 +
9554 +#define current_nx_info_has_v6() \
9555 +       nx_info_has_v6(current_nx_info())
9556 +
9557 +#else
9558 +#warning duplicate inclusion
9559 +#endif
9560 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
9561 --- linux-3.10.33/include/linux/vs_limit.h      1970-01-01 00:00:00.000000000 +0000
9562 +++ linux-3.10.33-vs2.3.6.8/include/linux/vs_limit.h    2013-08-22 20:30:00.000000000 +0000
9563 @@ -0,0 +1,140 @@
9564 +#ifndef _VS_LIMIT_H
9565 +#define _VS_LIMIT_H
9566 +
9567 +#include "vserver/limit.h"
9568 +#include "vserver/base.h"
9569 +#include "vserver/context.h"
9570 +#include "vserver/debug.h"
9571 +#include "vserver/context.h"
9572 +#include "vserver/limit_int.h"
9573 +
9574 +
9575 +#define vx_acc_cres(v, d, p, r) \
9576 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
9577 +
9578 +#define vx_acc_cres_cond(x, d, p, r) \
9579 +       __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
9580 +       r, d, p, __FILE__, __LINE__)
9581 +
9582 +
9583 +#define vx_add_cres(v, a, p, r) \
9584 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
9585 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
9586 +
9587 +#define vx_add_cres_cond(x, a, p, r) \
9588 +       __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
9589 +       r, a, p, __FILE__, __LINE__)
9590 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
9591 +
9592 +
9593 +/* process and file limits */
9594 +
9595 +#define vx_nproc_inc(p) \
9596 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
9597 +
9598 +#define vx_nproc_dec(p) \
9599 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
9600 +
9601 +#define vx_files_inc(f) \
9602 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
9603 +
9604 +#define vx_files_dec(f) \
9605 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
9606 +
9607 +#define vx_locks_inc(l) \
9608 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
9609 +
9610 +#define vx_locks_dec(l) \
9611 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
9612 +
9613 +#define vx_openfd_inc(f) \
9614 +       vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
9615 +
9616 +#define vx_openfd_dec(f) \
9617 +       vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
9618 +
9619 +
9620 +#define vx_cres_avail(v, n, r) \
9621 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
9622 +
9623 +
9624 +#define vx_nproc_avail(n) \
9625 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
9626 +
9627 +#define vx_files_avail(n) \
9628 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
9629 +
9630 +#define vx_locks_avail(n) \
9631 +       vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
9632 +
9633 +#define vx_openfd_avail(n) \
9634 +       vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
9635 +
9636 +
9637 +/* dentry limits */
9638 +
9639 +#define vx_dentry_inc(d) do {                                          \
9640 +       if ((d)->d_count == 1)                                          \
9641 +               vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY);    \
9642 +       } while (0)
9643 +
9644 +#define vx_dentry_dec(d) do {                                          \
9645 +       if ((d)->d_count == 0)                                          \
9646 +               vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY);    \
9647 +       } while (0)
9648 +
9649 +#define vx_dentry_avail(n) \
9650 +       vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
9651 +
9652 +
9653 +/* socket limits */
9654 +
9655 +#define vx_sock_inc(s) \
9656 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
9657 +
9658 +#define vx_sock_dec(s) \
9659 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
9660 +
9661 +#define vx_sock_avail(n) \
9662 +       vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
9663 +
9664 +
9665 +/* ipc resource limits */
9666 +
9667 +#define vx_ipcmsg_add(v, u, a) \
9668 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
9669 +
9670 +#define vx_ipcmsg_sub(v, u, a) \
9671 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
9672 +
9673 +#define vx_ipcmsg_avail(v, a) \
9674 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
9675 +
9676 +
9677 +#define vx_ipcshm_add(v, k, a) \
9678 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
9679 +
9680 +#define vx_ipcshm_sub(v, k, a) \
9681 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
9682 +
9683 +#define vx_ipcshm_avail(v, a) \
9684 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
9685 +
9686 +
9687 +#define vx_semary_inc(a) \
9688 +       vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
9689 +
9690 +#define vx_semary_dec(a) \
9691 +       vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
9692 +
9693 +
9694 +#define vx_nsems_add(a,n) \
9695 +       vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
9696 +
9697 +#define vx_nsems_sub(a,n) \
9698 +       vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
9699 +
9700 +
9701 +#else
9702 +#warning duplicate inclusion
9703 +#endif
9704 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
9705 --- linux-3.10.33/include/linux/vs_network.h    1970-01-01 00:00:00.000000000 +0000
9706 +++ linux-3.10.33-vs2.3.6.8/include/linux/vs_network.h  2013-08-22 20:30:00.000000000 +0000
9707 @@ -0,0 +1,169 @@
9708 +#ifndef _NX_VS_NETWORK_H
9709 +#define _NX_VS_NETWORK_H
9710 +
9711 +#include "vserver/context.h"
9712 +#include "vserver/network.h"
9713 +#include "vserver/base.h"
9714 +#include "vserver/check.h"
9715 +#include "vserver/debug.h"
9716 +
9717 +#include <linux/sched.h>
9718 +
9719 +
9720 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
9721 +
9722 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
9723 +       const char *_file, int _line)
9724 +{
9725 +       if (!nxi)
9726 +               return NULL;
9727 +
9728 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
9729 +               nxi, nxi ? nxi->nx_id : 0,
9730 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9731 +               _file, _line);
9732 +
9733 +       atomic_inc(&nxi->nx_usecnt);
9734 +       return nxi;
9735 +}
9736 +
9737 +
9738 +extern void free_nx_info(struct nx_info *);
9739 +
9740 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
9741 +
9742 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
9743 +{
9744 +       if (!nxi)
9745 +               return;
9746 +
9747 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
9748 +               nxi, nxi ? nxi->nx_id : 0,
9749 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9750 +               _file, _line);
9751 +
9752 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
9753 +               free_nx_info(nxi);
9754 +}
9755 +
9756 +
9757 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
9758 +
9759 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
9760 +               const char *_file, int _line)
9761 +{
9762 +       if (nxi) {
9763 +               vxlprintk(VXD_CBIT(nid, 3),
9764 +                       "init_nx_info(%p[#%d.%d])",
9765 +                       nxi, nxi ? nxi->nx_id : 0,
9766 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9767 +                       _file, _line);
9768 +
9769 +               atomic_inc(&nxi->nx_usecnt);
9770 +       }
9771 +       *nxp = nxi;
9772 +}
9773 +
9774 +
9775 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
9776 +
9777 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
9778 +       const char *_file, int _line)
9779 +{
9780 +       struct nx_info *nxo;
9781 +
9782 +       if (!nxi)
9783 +               return;
9784 +
9785 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
9786 +               nxi, nxi ? nxi->nx_id : 0,
9787 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9788 +               _file, _line);
9789 +
9790 +       atomic_inc(&nxi->nx_usecnt);
9791 +       nxo = xchg(nxp, nxi);
9792 +       BUG_ON(nxo);
9793 +}
9794 +
9795 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
9796 +
9797 +static inline void __clr_nx_info(struct nx_info **nxp,
9798 +       const char *_file, int _line)
9799 +{
9800 +       struct nx_info *nxo;
9801 +
9802 +       nxo = xchg(nxp, NULL);
9803 +       if (!nxo)
9804 +               return;
9805 +
9806 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
9807 +               nxo, nxo ? nxo->nx_id : 0,
9808 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
9809 +               _file, _line);
9810 +
9811 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
9812 +               free_nx_info(nxo);
9813 +}
9814 +
9815 +
9816 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
9817 +
9818 +static inline void __claim_nx_info(struct nx_info *nxi,
9819 +       struct task_struct *task, const char *_file, int _line)
9820 +{
9821 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
9822 +               nxi, nxi ? nxi->nx_id : 0,
9823 +               nxi?atomic_read(&nxi->nx_usecnt):0,
9824 +               nxi?atomic_read(&nxi->nx_tasks):0,
9825 +               task, _file, _line);
9826 +
9827 +       atomic_inc(&nxi->nx_tasks);
9828 +}
9829 +
9830 +
9831 +extern void unhash_nx_info(struct nx_info *);
9832 +
9833 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
9834 +
9835 +static inline void __release_nx_info(struct nx_info *nxi,
9836 +       struct task_struct *task, const char *_file, int _line)
9837 +{
9838 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
9839 +               nxi, nxi ? nxi->nx_id : 0,
9840 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9841 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
9842 +               task, _file, _line);
9843 +
9844 +       might_sleep();
9845 +
9846 +       if (atomic_dec_and_test(&nxi->nx_tasks))
9847 +               unhash_nx_info(nxi);
9848 +}
9849 +
9850 +
9851 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
9852 +
9853 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
9854 +       const char *_file, int _line)
9855 +{
9856 +       struct nx_info *nxi;
9857 +
9858 +       task_lock(p);
9859 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
9860 +               p, _file, _line);
9861 +       nxi = __get_nx_info(p->nx_info, _file, _line);
9862 +       task_unlock(p);
9863 +       return nxi;
9864 +}
9865 +
9866 +
9867 +static inline void exit_nx_info(struct task_struct *p)
9868 +{
9869 +       if (p->nx_info)
9870 +               release_nx_info(p->nx_info, p);
9871 +}
9872 +
9873 +
9874 +#else
9875 +#warning duplicate inclusion
9876 +#endif
9877 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
9878 --- linux-3.10.33/include/linux/vs_pid.h        1970-01-01 00:00:00.000000000 +0000
9879 +++ linux-3.10.33-vs2.3.6.8/include/linux/vs_pid.h      2013-08-22 20:30:00.000000000 +0000
9880 @@ -0,0 +1,50 @@
9881 +#ifndef _VS_PID_H
9882 +#define _VS_PID_H
9883 +
9884 +#include "vserver/base.h"
9885 +#include "vserver/check.h"
9886 +#include "vserver/context.h"
9887 +#include "vserver/debug.h"
9888 +#include "vserver/pid.h"
9889 +#include <linux/pid_namespace.h>
9890 +
9891 +
9892 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
9893 +
9894 +static inline
9895 +int vx_proc_task_visible(struct task_struct *task)
9896 +{
9897 +       if ((task->pid == 1) &&
9898 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
9899 +               /* show a blend through init */
9900 +               goto visible;
9901 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
9902 +               goto visible;
9903 +       return 0;
9904 +visible:
9905 +       return 1;
9906 +}
9907 +
9908 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
9909 +
9910 +
9911 +static inline
9912 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
9913 +{
9914 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
9915 +
9916 +       if (task && !vx_proc_task_visible(task)) {
9917 +               vxdprintk(VXD_CBIT(misc, 6),
9918 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
9919 +                       task, task->xid, task->pid,
9920 +                       current, current->xid, current->pid);
9921 +               put_task_struct(task);
9922 +               task = NULL;
9923 +       }
9924 +       return task;
9925 +}
9926 +
9927 +
9928 +#else
9929 +#warning duplicate inclusion
9930 +#endif
9931 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
9932 --- linux-3.10.33/include/linux/vs_sched.h      1970-01-01 00:00:00.000000000 +0000
9933 +++ linux-3.10.33-vs2.3.6.8/include/linux/vs_sched.h    2013-08-22 20:30:00.000000000 +0000
9934 @@ -0,0 +1,40 @@
9935 +#ifndef _VS_SCHED_H
9936 +#define _VS_SCHED_H
9937 +
9938 +#include "vserver/base.h"
9939 +#include "vserver/context.h"
9940 +#include "vserver/sched.h"
9941 +
9942 +
9943 +#define MAX_PRIO_BIAS           20
9944 +#define MIN_PRIO_BIAS          -20
9945 +
9946 +static inline
9947 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
9948 +{
9949 +       struct vx_info *vxi = p->vx_info;
9950 +
9951 +       if (vxi)
9952 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
9953 +       return prio;
9954 +}
9955 +
9956 +static inline void vx_account_user(struct vx_info *vxi,
9957 +       cputime_t cputime, int nice)
9958 +{
9959 +       if (!vxi)
9960 +               return;
9961 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
9962 +}
9963 +
9964 +static inline void vx_account_system(struct vx_info *vxi,
9965 +       cputime_t cputime, int idle)
9966 +{
9967 +       if (!vxi)
9968 +               return;
9969 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
9970 +}
9971 +
9972 +#else
9973 +#warning duplicate inclusion
9974 +#endif
9975 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
9976 --- linux-3.10.33/include/linux/vs_socket.h     1970-01-01 00:00:00.000000000 +0000
9977 +++ linux-3.10.33-vs2.3.6.8/include/linux/vs_socket.h   2013-08-22 20:30:00.000000000 +0000
9978 @@ -0,0 +1,67 @@
9979 +#ifndef _VS_SOCKET_H
9980 +#define _VS_SOCKET_H
9981 +
9982 +#include "vserver/debug.h"
9983 +#include "vserver/base.h"
9984 +#include "vserver/cacct.h"
9985 +#include "vserver/context.h"
9986 +#include "vserver/tag.h"
9987 +
9988 +
9989 +/* socket accounting */
9990 +
9991 +#include <linux/socket.h>
9992 +
9993 +static inline int vx_sock_type(int family)
9994 +{
9995 +       switch (family) {
9996 +       case PF_UNSPEC:
9997 +               return VXA_SOCK_UNSPEC;
9998 +       case PF_UNIX:
9999 +               return VXA_SOCK_UNIX;
10000 +       case PF_INET:
10001 +               return VXA_SOCK_INET;
10002 +       case PF_INET6:
10003 +               return VXA_SOCK_INET6;
10004 +       case PF_PACKET:
10005 +               return VXA_SOCK_PACKET;
10006 +       default:
10007 +               return VXA_SOCK_OTHER;
10008 +       }
10009 +}
10010 +
10011 +#define vx_acc_sock(v, f, p, s) \
10012 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
10013 +
10014 +static inline void __vx_acc_sock(struct vx_info *vxi,
10015 +       int family, int pos, int size, char *file, int line)
10016 +{
10017 +       if (vxi) {
10018 +               int type = vx_sock_type(family);
10019 +
10020 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
10021 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
10022 +       }
10023 +}
10024 +
10025 +#define vx_sock_recv(sk, s) \
10026 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
10027 +#define vx_sock_send(sk, s) \
10028 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
10029 +#define vx_sock_fail(sk, s) \
10030 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
10031 +
10032 +
10033 +#define sock_vx_init(s) do {           \
10034 +       (s)->sk_xid = 0;                \
10035 +       (s)->sk_vx_info = NULL;         \
10036 +       } while (0)
10037 +
10038 +#define sock_nx_init(s) do {           \
10039 +       (s)->sk_nid = 0;                \
10040 +       (s)->sk_nx_info = NULL;         \
10041 +       } while (0)
10042 +
10043 +#else
10044 +#warning duplicate inclusion
10045 +#endif
10046 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
10047 --- linux-3.10.33/include/linux/vs_tag.h        1970-01-01 00:00:00.000000000 +0000
10048 +++ linux-3.10.33-vs2.3.6.8/include/linux/vs_tag.h      2013-08-22 20:30:00.000000000 +0000
10049 @@ -0,0 +1,47 @@
10050 +#ifndef _VS_TAG_H
10051 +#define _VS_TAG_H
10052 +
10053 +#include <linux/vserver/tag.h>
10054 +
10055 +/* check conditions */
10056 +
10057 +#define DX_ADMIN       0x0001
10058 +#define DX_WATCH       0x0002
10059 +#define DX_HOSTID      0x0008
10060 +
10061 +#define DX_IDENT       0x0010
10062 +
10063 +#define DX_ARG_MASK    0x0010
10064 +
10065 +
10066 +#define dx_task_tag(t) ((t)->tag)
10067 +
10068 +#define dx_current_tag() dx_task_tag(current)
10069 +
10070 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
10071 +
10072 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
10073 +
10074 +
10075 +/*
10076 + * check current context for ADMIN/WATCH and
10077 + * optionally against supplied argument
10078 + */
10079 +static inline int __dx_check(vtag_t cid, vtag_t id, unsigned int mode)
10080 +{
10081 +       if (mode & DX_ARG_MASK) {
10082 +               if ((mode & DX_IDENT) && (id == cid))
10083 +                       return 1;
10084 +       }
10085 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
10086 +               ((mode & DX_WATCH) && (cid == 1)) ||
10087 +               ((mode & DX_HOSTID) && (id == 0)));
10088 +}
10089 +
10090 +struct inode;
10091 +int dx_permission(const struct inode *inode, int mask);
10092 +
10093 +
10094 +#else
10095 +#warning duplicate inclusion
10096 +#endif
10097 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
10098 --- linux-3.10.33/include/linux/vs_time.h       1970-01-01 00:00:00.000000000 +0000
10099 +++ linux-3.10.33-vs2.3.6.8/include/linux/vs_time.h     2013-08-22 20:30:00.000000000 +0000
10100 @@ -0,0 +1,19 @@
10101 +#ifndef _VS_TIME_H
10102 +#define _VS_TIME_H
10103 +
10104 +
10105 +/* time faking stuff */
10106 +
10107 +#ifdef CONFIG_VSERVER_VTIME
10108 +
10109 +extern void vx_adjust_timespec(struct timespec *ts);
10110 +extern int vx_settimeofday(const struct timespec *ts);
10111 +
10112 +#else
10113 +#define        vx_adjust_timespec(t)   do { } while (0)
10114 +#define        vx_settimeofday(t)      do_settimeofday(t)
10115 +#endif
10116 +
10117 +#else
10118 +#warning duplicate inclusion
10119 +#endif
10120 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
10121 --- linux-3.10.33/include/linux/vserver/base.h  1970-01-01 00:00:00.000000000 +0000
10122 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/base.h        2013-10-27 03:40:46.000000000 +0000
10123 @@ -0,0 +1,184 @@
10124 +#ifndef _VSERVER_BASE_H
10125 +#define _VSERVER_BASE_H
10126 +
10127 +
10128 +/* context state changes */
10129 +
10130 +enum {
10131 +       VSC_STARTUP = 1,
10132 +       VSC_SHUTDOWN,
10133 +
10134 +       VSC_NETUP,
10135 +       VSC_NETDOWN,
10136 +};
10137 +
10138 +
10139 +
10140 +#define vx_task_xid(t) ((t)->xid)
10141 +
10142 +#define vx_current_xid() vx_task_xid(current)
10143 +
10144 +#define current_vx_info() (current->vx_info)
10145 +
10146 +
10147 +#define nx_task_nid(t) ((t)->nid)
10148 +
10149 +#define nx_current_nid() nx_task_nid(current)
10150 +
10151 +#define current_nx_info() (current->nx_info)
10152 +
10153 +
10154 +/* generic flag merging */
10155 +
10156 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
10157 +
10158 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
10159 +
10160 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
10161 +
10162 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
10163 +
10164 +
10165 +/* context flags */
10166 +
10167 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
10168 +
10169 +#define vx_current_flags()     __vx_flags(current_vx_info())
10170 +
10171 +#define vx_info_flags(v, m, f) \
10172 +       vs_check_flags(__vx_flags(v), m, f)
10173 +
10174 +#define task_vx_flags(t, m, f) \
10175 +       ((t) && vx_info_flags((t)->vx_info, m, f))
10176 +
10177 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
10178 +
10179 +
10180 +/* context caps */
10181 +
10182 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
10183 +
10184 +#define vx_current_ccaps()     __vx_ccaps(current_vx_info())
10185 +
10186 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
10187 +
10188 +#define vx_ccaps(c)    vx_info_ccaps(current_vx_info(), (c))
10189 +
10190 +
10191 +
10192 +/* network flags */
10193 +
10194 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
10195 +
10196 +#define nx_current_flags()     __nx_flags(current_nx_info())
10197 +
10198 +#define nx_info_flags(n, m, f) \
10199 +       vs_check_flags(__nx_flags(n), m, f)
10200 +
10201 +#define task_nx_flags(t, m, f) \
10202 +       ((t) && nx_info_flags((t)->nx_info, m, f))
10203 +
10204 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
10205 +
10206 +
10207 +/* network caps */
10208 +
10209 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
10210 +
10211 +#define nx_current_ncaps()     __nx_ncaps(current_nx_info())
10212 +
10213 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
10214 +
10215 +#define nx_ncaps(c)    nx_info_ncaps(current_nx_info(), c)
10216 +
10217 +
10218 +/* context mask capabilities */
10219 +
10220 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
10221 +
10222 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
10223 +
10224 +#define vx_mcaps(c)    vx_info_mcaps(current_vx_info(), c)
10225 +
10226 +
10227 +/* context bcap mask */
10228 +
10229 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
10230 +
10231 +#define vx_current_bcaps()     __vx_bcaps(current_vx_info())
10232 +
10233 +
10234 +/* mask given bcaps */
10235 +
10236 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
10237 +
10238 +#define vx_mbcaps(c)           vx_info_mbcaps(current_vx_info(), c)
10239 +
10240 +
10241 +/* masked cap_bset */
10242 +
10243 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
10244 +
10245 +#define vx_current_cap_bset()  vx_info_cap_bset(current_vx_info())
10246 +
10247 +#if 0
10248 +#define vx_info_mbcap(v, b) \
10249 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
10250 +       vx_info_bcaps(v, b) : (b))
10251 +
10252 +#define task_vx_mbcap(t, b) \
10253 +       vx_info_mbcap((t)->vx_info, (t)->b)
10254 +
10255 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
10256 +#endif
10257 +
10258 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
10259 +
10260 +#define vx_capable(b, c) (capable(b) || \
10261 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10262 +
10263 +#define vx_ns_capable(n, b, c) (ns_capable(n, b) || \
10264 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10265 +
10266 +#define nx_capable(b, c) (capable(b) || \
10267 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
10268 +
10269 +#define nx_ns_capable(n, b, c) (ns_capable(n, b) || \
10270 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
10271 +
10272 +#define vx_task_initpid(t, n) \
10273 +       ((t)->vx_info && \
10274 +       ((t)->vx_info->vx_initpid == (n)))
10275 +
10276 +#define vx_current_initpid(n)  vx_task_initpid(current, n)
10277 +
10278 +
10279 +/* context unshare mask */
10280 +
10281 +#define __vx_umask(v)          ((v)->vx_umask)
10282 +
10283 +#define vx_current_umask()     __vx_umask(current_vx_info())
10284 +
10285 +#define vx_can_unshare(b, f) (capable(b) || \
10286 +       (cap_raised(current_cap(), b) && \
10287 +       !((f) & ~vx_current_umask())))
10288 +
10289 +#define vx_ns_can_unshare(n, b, f) (ns_capable(n, b) || \
10290 +       (cap_raised(current_cap(), b) && \
10291 +       !((f) & ~vx_current_umask())))
10292 +
10293 +#define __vx_wmask(v)          ((v)->vx_wmask)
10294 +
10295 +#define vx_current_wmask()     __vx_wmask(current_vx_info())
10296 +
10297 +
10298 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
10299 +
10300 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
10301 +
10302 +
10303 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
10304 +
10305 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
10306 +
10307 +#endif
10308 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
10309 --- linux-3.10.33/include/linux/vserver/cacct.h 1970-01-01 00:00:00.000000000 +0000
10310 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/cacct.h       2013-08-22 20:30:00.000000000 +0000
10311 @@ -0,0 +1,15 @@
10312 +#ifndef _VSERVER_CACCT_H
10313 +#define _VSERVER_CACCT_H
10314 +
10315 +
10316 +enum sock_acc_field {
10317 +       VXA_SOCK_UNSPEC = 0,
10318 +       VXA_SOCK_UNIX,
10319 +       VXA_SOCK_INET,
10320 +       VXA_SOCK_INET6,
10321 +       VXA_SOCK_PACKET,
10322 +       VXA_SOCK_OTHER,
10323 +       VXA_SOCK_SIZE   /* array size */
10324 +};
10325 +
10326 +#endif /* _VSERVER_CACCT_H */
10327 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
10328 --- linux-3.10.33/include/linux/vserver/cacct_cmd.h     1970-01-01 00:00:00.000000000 +0000
10329 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/cacct_cmd.h   2013-08-22 20:30:00.000000000 +0000
10330 @@ -0,0 +1,10 @@
10331 +#ifndef _VSERVER_CACCT_CMD_H
10332 +#define _VSERVER_CACCT_CMD_H
10333 +
10334 +
10335 +#include <linux/compiler.h>
10336 +#include <uapi/vserver/cacct_cmd.h>
10337 +
10338 +extern int vc_sock_stat(struct vx_info *, void __user *);
10339 +
10340 +#endif /* _VSERVER_CACCT_CMD_H */
10341 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
10342 --- linux-3.10.33/include/linux/vserver/cacct_def.h     1970-01-01 00:00:00.000000000 +0000
10343 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/cacct_def.h   2013-08-22 20:30:00.000000000 +0000
10344 @@ -0,0 +1,43 @@
10345 +#ifndef _VSERVER_CACCT_DEF_H
10346 +#define _VSERVER_CACCT_DEF_H
10347 +
10348 +#include <asm/atomic.h>
10349 +#include <linux/vserver/cacct.h>
10350 +
10351 +
10352 +struct _vx_sock_acc {
10353 +       atomic_long_t count;
10354 +       atomic_long_t total;
10355 +};
10356 +
10357 +/* context sub struct */
10358 +
10359 +struct _vx_cacct {
10360 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
10361 +       atomic_t slab[8];
10362 +       atomic_t page[6][8];
10363 +};
10364 +
10365 +#ifdef CONFIG_VSERVER_DEBUG
10366 +
10367 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
10368 +{
10369 +       int i, j;
10370 +
10371 +       printk("\t_vx_cacct:");
10372 +       for (i = 0; i < 6; i++) {
10373 +               struct _vx_sock_acc *ptr = cacct->sock[i];
10374 +
10375 +               printk("\t [%d] =", i);
10376 +               for (j = 0; j < 3; j++) {
10377 +                       printk(" [%d] = %8lu, %8lu", j,
10378 +                               atomic_long_read(&ptr[j].count),
10379 +                               atomic_long_read(&ptr[j].total));
10380 +               }
10381 +               printk("\n");
10382 +       }
10383 +}
10384 +
10385 +#endif
10386 +
10387 +#endif /* _VSERVER_CACCT_DEF_H */
10388 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
10389 --- linux-3.10.33/include/linux/vserver/cacct_int.h     1970-01-01 00:00:00.000000000 +0000
10390 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/cacct_int.h   2013-08-22 20:30:00.000000000 +0000
10391 @@ -0,0 +1,17 @@
10392 +#ifndef _VSERVER_CACCT_INT_H
10393 +#define _VSERVER_CACCT_INT_H
10394 +
10395 +static inline
10396 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
10397 +{
10398 +       return atomic_long_read(&cacct->sock[type][pos].count);
10399 +}
10400 +
10401 +
10402 +static inline
10403 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
10404 +{
10405 +       return atomic_long_read(&cacct->sock[type][pos].total);
10406 +}
10407 +
10408 +#endif /* _VSERVER_CACCT_INT_H */
10409 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
10410 --- linux-3.10.33/include/linux/vserver/check.h 1970-01-01 00:00:00.000000000 +0000
10411 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/check.h       2013-08-22 20:30:00.000000000 +0000
10412 @@ -0,0 +1,89 @@
10413 +#ifndef _VSERVER_CHECK_H
10414 +#define _VSERVER_CHECK_H
10415 +
10416 +
10417 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
10418 +
10419 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
10420 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
10421 +#else
10422 +#define MIN_D_CONTEXT  65536
10423 +#endif
10424 +
10425 +/* check conditions */
10426 +
10427 +#define VS_ADMIN       0x0001
10428 +#define VS_WATCH       0x0002
10429 +#define VS_HIDE                0x0004
10430 +#define VS_HOSTID      0x0008
10431 +
10432 +#define VS_IDENT       0x0010
10433 +#define VS_EQUIV       0x0020
10434 +#define VS_PARENT      0x0040
10435 +#define VS_CHILD       0x0080
10436 +
10437 +#define VS_ARG_MASK    0x00F0
10438 +
10439 +#define VS_DYNAMIC     0x0100
10440 +#define VS_STATIC      0x0200
10441 +
10442 +#define VS_ATR_MASK    0x0F00
10443 +
10444 +#ifdef CONFIG_VSERVER_PRIVACY
10445 +#define VS_ADMIN_P     (0)
10446 +#define VS_WATCH_P     (0)
10447 +#else
10448 +#define VS_ADMIN_P     VS_ADMIN
10449 +#define VS_WATCH_P     VS_WATCH
10450 +#endif
10451 +
10452 +#define VS_HARDIRQ     0x1000
10453 +#define VS_SOFTIRQ     0x2000
10454 +#define VS_IRQ         0x4000
10455 +
10456 +#define VS_IRQ_MASK    0xF000
10457 +
10458 +#include <linux/hardirq.h>
10459 +
10460 +/*
10461 + * check current context for ADMIN/WATCH and
10462 + * optionally against supplied argument
10463 + */
10464 +static inline int __vs_check(int cid, int id, unsigned int mode)
10465 +{
10466 +       if (mode & VS_ARG_MASK) {
10467 +               if ((mode & VS_IDENT) && (id == cid))
10468 +                       return 1;
10469 +       }
10470 +       if (mode & VS_ATR_MASK) {
10471 +               if ((mode & VS_DYNAMIC) &&
10472 +                       (id >= MIN_D_CONTEXT) &&
10473 +                       (id <= MAX_S_CONTEXT))
10474 +                       return 1;
10475 +               if ((mode & VS_STATIC) &&
10476 +                       (id > 1) && (id < MIN_D_CONTEXT))
10477 +                       return 1;
10478 +       }
10479 +       if (mode & VS_IRQ_MASK) {
10480 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
10481 +                       return 1;
10482 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
10483 +                       return 1;
10484 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
10485 +                       return 1;
10486 +       }
10487 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
10488 +               ((mode & VS_WATCH) && (cid == 1)) ||
10489 +               ((mode & VS_HOSTID) && (id == 0)));
10490 +}
10491 +
10492 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
10493 +
10494 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
10495 +
10496 +
10497 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
10498 +
10499 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
10500 +
10501 +#endif
10502 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
10503 --- linux-3.10.33/include/linux/vserver/context.h       1970-01-01 00:00:00.000000000 +0000
10504 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/context.h     2013-08-22 20:30:00.000000000 +0000
10505 @@ -0,0 +1,110 @@
10506 +#ifndef _VSERVER_CONTEXT_H
10507 +#define _VSERVER_CONTEXT_H
10508 +
10509 +
10510 +#include <linux/list.h>
10511 +#include <linux/spinlock.h>
10512 +#include <linux/rcupdate.h>
10513 +#include <uapi/vserver/context.h>
10514 +
10515 +#include "limit_def.h"
10516 +#include "sched_def.h"
10517 +#include "cvirt_def.h"
10518 +#include "cacct_def.h"
10519 +#include "device_def.h"
10520 +
10521 +#define VX_SPACES      2
10522 +
10523 +struct _vx_info_pc {
10524 +       struct _vx_sched_pc sched_pc;
10525 +       struct _vx_cvirt_pc cvirt_pc;
10526 +};
10527 +
10528 +struct _vx_space {
10529 +       unsigned long vx_nsmask;                /* assignment mask */
10530 +       struct nsproxy *vx_nsproxy;             /* private namespaces */
10531 +       struct fs_struct *vx_fs;                /* private namespace fs */
10532 +       const struct cred *vx_cred;             /* task credentials */
10533 +};
10534 +
10535 +struct vx_info {
10536 +       struct hlist_node vx_hlist;             /* linked list of contexts */
10537 +       vxid_t vx_id;                           /* context id */
10538 +       atomic_t vx_usecnt;                     /* usage count */
10539 +       atomic_t vx_tasks;                      /* tasks count */
10540 +       struct vx_info *vx_parent;              /* parent context */
10541 +       int vx_state;                           /* context state */
10542 +
10543 +       struct _vx_space space[VX_SPACES];      /* namespace store */
10544 +
10545 +       uint64_t vx_flags;                      /* context flags */
10546 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
10547 +       uint64_t vx_umask;                      /* unshare mask (guest) */
10548 +       uint64_t vx_wmask;                      /* warn mask (guest) */
10549 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
10550 +
10551 +       struct task_struct *vx_reaper;          /* guest reaper process */
10552 +       pid_t vx_initpid;                       /* PID of guest init */
10553 +       int64_t vx_badness_bias;                /* OOM points bias */
10554 +
10555 +       struct _vx_limit limit;                 /* vserver limits */
10556 +       struct _vx_sched sched;                 /* vserver scheduler */
10557 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
10558 +       struct _vx_cacct cacct;                 /* context accounting */
10559 +
10560 +       struct _vx_device dmap;                 /* default device map targets */
10561 +
10562 +#ifndef CONFIG_SMP
10563 +       struct _vx_info_pc info_pc;             /* per cpu data */
10564 +#else
10565 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
10566 +#endif
10567 +
10568 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
10569 +       int reboot_cmd;                         /* last sys_reboot() cmd */
10570 +       int exit_code;                          /* last process exit code */
10571 +
10572 +       char vx_name[65];                       /* vserver name */
10573 +};
10574 +
10575 +#ifndef CONFIG_SMP
10576 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
10577 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
10578 +#else
10579 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
10580 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
10581 +#endif
10582 +
10583 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
10584 +
10585 +
10586 +struct vx_info_save {
10587 +       struct vx_info *vxi;
10588 +       vxid_t xid;
10589 +};
10590 +
10591 +
10592 +/* status flags */
10593 +
10594 +#define VXS_HASHED     0x0001
10595 +#define VXS_PAUSED     0x0010
10596 +#define VXS_SHUTDOWN   0x0100
10597 +#define VXS_HELPER     0x1000
10598 +#define VXS_RELEASED   0x8000
10599 +
10600 +
10601 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
10602 +extern void release_vx_info(struct vx_info *, struct task_struct *);
10603 +
10604 +extern struct vx_info *lookup_vx_info(int);
10605 +extern struct vx_info *lookup_or_create_vx_info(int);
10606 +
10607 +extern int get_xid_list(int, unsigned int *, int);
10608 +extern int xid_is_hashed(vxid_t);
10609 +
10610 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
10611 +
10612 +extern long vs_state_change(struct vx_info *, unsigned int);
10613 +
10614 +
10615 +#endif /* _VSERVER_CONTEXT_H */
10616 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
10617 --- linux-3.10.33/include/linux/vserver/context_cmd.h   1970-01-01 00:00:00.000000000 +0000
10618 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/context_cmd.h 2013-08-22 20:30:00.000000000 +0000
10619 @@ -0,0 +1,33 @@
10620 +#ifndef _VSERVER_CONTEXT_CMD_H
10621 +#define _VSERVER_CONTEXT_CMD_H
10622 +
10623 +#include <uapi/vserver/context_cmd.h>
10624 +
10625 +extern int vc_task_xid(uint32_t);
10626 +
10627 +extern int vc_vx_info(struct vx_info *, void __user *);
10628 +
10629 +extern int vc_ctx_stat(struct vx_info *, void __user *);
10630 +
10631 +extern int vc_ctx_create(uint32_t, void __user *);
10632 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
10633 +
10634 +extern int vc_get_cflags(struct vx_info *, void __user *);
10635 +extern int vc_set_cflags(struct vx_info *, void __user *);
10636 +
10637 +extern int vc_get_ccaps(struct vx_info *, void __user *);
10638 +extern int vc_set_ccaps(struct vx_info *, void __user *);
10639 +
10640 +extern int vc_get_bcaps(struct vx_info *, void __user *);
10641 +extern int vc_set_bcaps(struct vx_info *, void __user *);
10642 +
10643 +extern int vc_get_umask(struct vx_info *, void __user *);
10644 +extern int vc_set_umask(struct vx_info *, void __user *);
10645 +
10646 +extern int vc_get_wmask(struct vx_info *, void __user *);
10647 +extern int vc_set_wmask(struct vx_info *, void __user *);
10648 +
10649 +extern int vc_get_badness(struct vx_info *, void __user *);
10650 +extern int vc_set_badness(struct vx_info *, void __user *);
10651 +
10652 +#endif /* _VSERVER_CONTEXT_CMD_H */
10653 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
10654 --- linux-3.10.33/include/linux/vserver/cvirt.h 1970-01-01 00:00:00.000000000 +0000
10655 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/cvirt.h       2013-08-22 20:30:00.000000000 +0000
10656 @@ -0,0 +1,18 @@
10657 +#ifndef _VSERVER_CVIRT_H
10658 +#define _VSERVER_CVIRT_H
10659 +
10660 +struct timespec;
10661 +
10662 +void vx_vsi_boottime(struct timespec *);
10663 +
10664 +void vx_vsi_uptime(struct timespec *, struct timespec *);
10665 +
10666 +
10667 +struct vx_info;
10668 +
10669 +void vx_update_load(struct vx_info *);
10670 +
10671 +
10672 +int vx_do_syslog(int, char __user *, int);
10673 +
10674 +#endif /* _VSERVER_CVIRT_H */
10675 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
10676 --- linux-3.10.33/include/linux/vserver/cvirt_cmd.h     1970-01-01 00:00:00.000000000 +0000
10677 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/cvirt_cmd.h   2013-08-22 20:30:00.000000000 +0000
10678 @@ -0,0 +1,13 @@
10679 +#ifndef _VSERVER_CVIRT_CMD_H
10680 +#define _VSERVER_CVIRT_CMD_H
10681 +
10682 +
10683 +#include <linux/compiler.h>
10684 +#include <uapi/vserver/cvirt_cmd.h>
10685 +
10686 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
10687 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
10688 +
10689 +extern int vc_virt_stat(struct vx_info *, void __user *);
10690 +
10691 +#endif /* _VSERVER_CVIRT_CMD_H */
10692 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
10693 --- linux-3.10.33/include/linux/vserver/cvirt_def.h     1970-01-01 00:00:00.000000000 +0000
10694 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/cvirt_def.h   2013-08-22 20:30:00.000000000 +0000
10695 @@ -0,0 +1,80 @@
10696 +#ifndef _VSERVER_CVIRT_DEF_H
10697 +#define _VSERVER_CVIRT_DEF_H
10698 +
10699 +#include <linux/jiffies.h>
10700 +#include <linux/spinlock.h>
10701 +#include <linux/wait.h>
10702 +#include <linux/time.h>
10703 +#include <asm/atomic.h>
10704 +
10705 +
10706 +struct _vx_usage_stat {
10707 +       uint64_t user;
10708 +       uint64_t nice;
10709 +       uint64_t system;
10710 +       uint64_t softirq;
10711 +       uint64_t irq;
10712 +       uint64_t idle;
10713 +       uint64_t iowait;
10714 +};
10715 +
10716 +struct _vx_syslog {
10717 +       wait_queue_head_t log_wait;
10718 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
10719 +
10720 +       unsigned long log_start;        /* next char to be read by syslog() */
10721 +       unsigned long con_start;        /* next char to be sent to consoles */
10722 +       unsigned long log_end;  /* most-recently-written-char + 1 */
10723 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
10724 +
10725 +       char log_buf[1024];
10726 +};
10727 +
10728 +
10729 +/* context sub struct */
10730 +
10731 +struct _vx_cvirt {
10732 +       atomic_t nr_threads;            /* number of current threads */
10733 +       atomic_t nr_running;            /* number of running threads */
10734 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
10735 +
10736 +       atomic_t nr_onhold;             /* processes on hold */
10737 +       uint32_t onhold_last;           /* jiffies when put on hold */
10738 +
10739 +       struct timespec bias_ts;        /* time offset to the host */
10740 +       struct timespec bias_idle;
10741 +       struct timespec bias_uptime;    /* context creation point */
10742 +       uint64_t bias_clock;            /* offset in clock_t */
10743 +
10744 +       spinlock_t load_lock;           /* lock for the load averages */
10745 +       atomic_t load_updates;          /* nr of load updates done so far */
10746 +       uint32_t load_last;             /* last time load was calculated */
10747 +       uint32_t load[3];               /* load averages 1,5,15 */
10748 +
10749 +       atomic_t total_forks;           /* number of forks so far */
10750 +
10751 +       struct _vx_syslog syslog;
10752 +};
10753 +
10754 +struct _vx_cvirt_pc {
10755 +       struct _vx_usage_stat cpustat;
10756 +};
10757 +
10758 +
10759 +#ifdef CONFIG_VSERVER_DEBUG
10760 +
10761 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
10762 +{
10763 +       printk("\t_vx_cvirt:\n");
10764 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
10765 +               atomic_read(&cvirt->nr_threads),
10766 +               atomic_read(&cvirt->nr_running),
10767 +               atomic_read(&cvirt->nr_uninterruptible),
10768 +               atomic_read(&cvirt->nr_onhold));
10769 +       /* add rest here */
10770 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
10771 +}
10772 +
10773 +#endif
10774 +
10775 +#endif /* _VSERVER_CVIRT_DEF_H */
10776 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
10777 --- linux-3.10.33/include/linux/vserver/debug.h 1970-01-01 00:00:00.000000000 +0000
10778 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/debug.h       2013-08-22 20:30:00.000000000 +0000
10779 @@ -0,0 +1,146 @@
10780 +#ifndef _VSERVER_DEBUG_H
10781 +#define _VSERVER_DEBUG_H
10782 +
10783 +
10784 +#define VXD_CBIT(n, m) (vs_debug_ ## n & (1 << (m)))
10785 +#define VXD_CMIN(n, m) (vs_debug_ ## n > (m))
10786 +#define VXD_MASK(n, m) (vs_debug_ ## n & (m))
10787 +
10788 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
10789 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
10790 +#define VXF_DEV                "%p[%lu,%d:%d]"
10791 +
10792 +#if    defined(CONFIG_QUOTES_UTF8)
10793 +#define        VS_Q_LQM        "\xc2\xbb"
10794 +#define        VS_Q_RQM        "\xc2\xab"
10795 +#elif  defined(CONFIG_QUOTES_ASCII)
10796 +#define        VS_Q_LQM        "\x27"
10797 +#define        VS_Q_RQM        "\x27"
10798 +#else
10799 +#define        VS_Q_LQM        "\xbb"
10800 +#define        VS_Q_RQM        "\xab"
10801 +#endif
10802 +
10803 +#define        VS_Q(f)         VS_Q_LQM f VS_Q_RQM
10804 +
10805 +
10806 +#define vxd_path(p)                                            \
10807 +       ({ static char _buffer[PATH_MAX];                       \
10808 +          d_path(p, _buffer, sizeof(_buffer)); })
10809 +
10810 +#define vxd_cond_path(n)                                       \
10811 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
10812 +
10813 +
10814 +#ifdef CONFIG_VSERVER_DEBUG
10815 +
10816 +extern unsigned int vs_debug_switch;
10817 +extern unsigned int vs_debug_xid;
10818 +extern unsigned int vs_debug_nid;
10819 +extern unsigned int vs_debug_tag;
10820 +extern unsigned int vs_debug_net;
10821 +extern unsigned int vs_debug_limit;
10822 +extern unsigned int vs_debug_cres;
10823 +extern unsigned int vs_debug_dlim;
10824 +extern unsigned int vs_debug_quota;
10825 +extern unsigned int vs_debug_cvirt;
10826 +extern unsigned int vs_debug_space;
10827 +extern unsigned int vs_debug_perm;
10828 +extern unsigned int vs_debug_misc;
10829 +
10830 +
10831 +#define VX_LOGLEVEL    "vxD: "
10832 +#define VX_PROC_FMT    "%p: "
10833 +#define VX_PROCESS     current
10834 +
10835 +#define vxdprintk(c, f, x...)                                  \
10836 +       do {                                                    \
10837 +               if (c)                                          \
10838 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
10839 +                               VX_PROCESS , ##x);              \
10840 +       } while (0)
10841 +
10842 +#define vxlprintk(c, f, x...)                                  \
10843 +       do {                                                    \
10844 +               if (c)                                          \
10845 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
10846 +       } while (0)
10847 +
10848 +#define vxfprintk(c, f, x...)                                  \
10849 +       do {                                                    \
10850 +               if (c)                                          \
10851 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
10852 +       } while (0)
10853 +
10854 +
10855 +struct vx_info;
10856 +
10857 +void dump_vx_info(struct vx_info *, int);
10858 +void dump_vx_info_inactive(int);
10859 +
10860 +#else  /* CONFIG_VSERVER_DEBUG */
10861 +
10862 +#define vs_debug_switch        0
10863 +#define vs_debug_xid   0
10864 +#define vs_debug_nid   0
10865 +#define vs_debug_tag   0
10866 +#define vs_debug_net   0
10867 +#define vs_debug_limit 0
10868 +#define vs_debug_cres  0
10869 +#define vs_debug_dlim  0
10870 +#define vs_debug_quota 0
10871 +#define vs_debug_cvirt 0
10872 +#define vs_debug_space 0
10873 +#define vs_debug_perm  0
10874 +#define vs_debug_misc  0
10875 +
10876 +#define vxdprintk(x...) do { } while (0)
10877 +#define vxlprintk(x...) do { } while (0)
10878 +#define vxfprintk(x...) do { } while (0)
10879 +
10880 +#endif /* CONFIG_VSERVER_DEBUG */
10881 +
10882 +
10883 +#ifdef CONFIG_VSERVER_WARN
10884 +
10885 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
10886 +#define VX_WARN_TASK   "[" VS_Q("%s") ",%u:#%u|%u|%u] "
10887 +#define VX_WARN_XID    "[xid #%u] "
10888 +#define VX_WARN_NID    "[nid #%u] "
10889 +#define VX_WARN_TAG    "[tag #%u] "
10890 +
10891 +#define vxwprintk(c, f, x...)                                  \
10892 +       do {                                                    \
10893 +               if (c)                                          \
10894 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
10895 +       } while (0)
10896 +
10897 +#else  /* CONFIG_VSERVER_WARN */
10898 +
10899 +#define vxwprintk(x...) do { } while (0)
10900 +
10901 +#endif /* CONFIG_VSERVER_WARN */
10902 +
10903 +#define vxwprintk_task(c, f, x...)                             \
10904 +       vxwprintk(c, VX_WARN_TASK f,                            \
10905 +               current->comm, current->pid,                    \
10906 +               current->xid, current->nid,                     \
10907 +               current->tag, ##x)
10908 +#define vxwprintk_xid(c, f, x...)                              \
10909 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
10910 +#define vxwprintk_nid(c, f, x...)                              \
10911 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
10912 +#define vxwprintk_tag(c, f, x...)                              \
10913 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
10914 +
10915 +#ifdef CONFIG_VSERVER_DEBUG
10916 +#define vxd_assert_lock(l)     assert_spin_locked(l)
10917 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
10918 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
10919 +#else
10920 +#define vxd_assert_lock(l)     do { } while (0)
10921 +#define vxd_assert(c, f, x...) do { } while (0)
10922 +#endif
10923 +
10924 +
10925 +#endif /* _VSERVER_DEBUG_H */
10926 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
10927 --- linux-3.10.33/include/linux/vserver/debug_cmd.h     1970-01-01 00:00:00.000000000 +0000
10928 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/debug_cmd.h   2013-08-22 20:30:00.000000000 +0000
10929 @@ -0,0 +1,37 @@
10930 +#ifndef _VSERVER_DEBUG_CMD_H
10931 +#define _VSERVER_DEBUG_CMD_H
10932 +
10933 +#include <uapi/vserver/debug_cmd.h>
10934 +
10935 +
10936 +#ifdef CONFIG_COMPAT
10937 +
10938 +#include <asm/compat.h>
10939 +
10940 +struct vcmd_read_history_v0_x32 {
10941 +       uint32_t index;
10942 +       uint32_t count;
10943 +       compat_uptr_t data_ptr;
10944 +};
10945 +
10946 +struct vcmd_read_monitor_v0_x32 {
10947 +       uint32_t index;
10948 +       uint32_t count;
10949 +       compat_uptr_t data_ptr;
10950 +};
10951 +
10952 +#endif  /* CONFIG_COMPAT */
10953 +
10954 +extern int vc_dump_history(uint32_t);
10955 +
10956 +extern int vc_read_history(uint32_t, void __user *);
10957 +extern int vc_read_monitor(uint32_t, void __user *);
10958 +
10959 +#ifdef CONFIG_COMPAT
10960 +
10961 +extern int vc_read_history_x32(uint32_t, void __user *);
10962 +extern int vc_read_monitor_x32(uint32_t, void __user *);
10963 +
10964 +#endif  /* CONFIG_COMPAT */
10965 +
10966 +#endif /* _VSERVER_DEBUG_CMD_H */
10967 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
10968 --- linux-3.10.33/include/linux/vserver/device.h        1970-01-01 00:00:00.000000000 +0000
10969 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/device.h      2013-08-22 20:30:00.000000000 +0000
10970 @@ -0,0 +1,9 @@
10971 +#ifndef _VSERVER_DEVICE_H
10972 +#define _VSERVER_DEVICE_H
10973 +
10974 +
10975 +#include <uapi/vserver/device.h>
10976 +
10977 +#else  /* _VSERVER_DEVICE_H */
10978 +#warning duplicate inclusion
10979 +#endif /* _VSERVER_DEVICE_H */
10980 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
10981 --- linux-3.10.33/include/linux/vserver/device_cmd.h    1970-01-01 00:00:00.000000000 +0000
10982 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/device_cmd.h  2013-08-22 20:30:00.000000000 +0000
10983 @@ -0,0 +1,31 @@
10984 +#ifndef _VSERVER_DEVICE_CMD_H
10985 +#define _VSERVER_DEVICE_CMD_H
10986 +
10987 +#include <uapi/vserver/device_cmd.h>
10988 +
10989 +
10990 +#ifdef CONFIG_COMPAT
10991 +
10992 +#include <asm/compat.h>
10993 +
10994 +struct vcmd_set_mapping_v0_x32 {
10995 +       compat_uptr_t device_ptr;
10996 +       compat_uptr_t target_ptr;
10997 +       uint32_t flags;
10998 +};
10999 +
11000 +#endif /* CONFIG_COMPAT */
11001 +
11002 +#include <linux/compiler.h>
11003 +
11004 +extern int vc_set_mapping(struct vx_info *, void __user *);
11005 +extern int vc_unset_mapping(struct vx_info *, void __user *);
11006 +
11007 +#ifdef CONFIG_COMPAT
11008 +
11009 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
11010 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
11011 +
11012 +#endif /* CONFIG_COMPAT */
11013 +
11014 +#endif /* _VSERVER_DEVICE_CMD_H */
11015 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
11016 --- linux-3.10.33/include/linux/vserver/device_def.h    1970-01-01 00:00:00.000000000 +0000
11017 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/device_def.h  2013-08-22 20:30:00.000000000 +0000
11018 @@ -0,0 +1,17 @@
11019 +#ifndef _VSERVER_DEVICE_DEF_H
11020 +#define _VSERVER_DEVICE_DEF_H
11021 +
11022 +#include <linux/types.h>
11023 +
11024 +struct vx_dmap_target {
11025 +       dev_t target;
11026 +       uint32_t flags;
11027 +};
11028 +
11029 +struct _vx_device {
11030 +#ifdef CONFIG_VSERVER_DEVICE
11031 +       struct vx_dmap_target targets[2];
11032 +#endif
11033 +};
11034 +
11035 +#endif /* _VSERVER_DEVICE_DEF_H */
11036 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
11037 --- linux-3.10.33/include/linux/vserver/dlimit.h        1970-01-01 00:00:00.000000000 +0000
11038 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/dlimit.h      2013-08-22 20:30:00.000000000 +0000
11039 @@ -0,0 +1,54 @@
11040 +#ifndef _VSERVER_DLIMIT_H
11041 +#define _VSERVER_DLIMIT_H
11042 +
11043 +#include "switch.h"
11044 +
11045 +
11046 +#ifdef __KERNEL__
11047 +
11048 +/*      keep in sync with CDLIM_INFINITY       */
11049 +
11050 +#define DLIM_INFINITY          (~0ULL)
11051 +
11052 +#include <linux/spinlock.h>
11053 +#include <linux/rcupdate.h>
11054 +
11055 +struct super_block;
11056 +
11057 +struct dl_info {
11058 +       struct hlist_node dl_hlist;             /* linked list of contexts */
11059 +       struct rcu_head dl_rcu;                 /* the rcu head */
11060 +       vtag_t dl_tag;                          /* context tag */
11061 +       atomic_t dl_usecnt;                     /* usage count */
11062 +       atomic_t dl_refcnt;                     /* reference count */
11063 +
11064 +       struct super_block *dl_sb;              /* associated superblock */
11065 +
11066 +       spinlock_t dl_lock;                     /* protect the values */
11067 +
11068 +       unsigned long long dl_space_used;       /* used space in bytes */
11069 +       unsigned long long dl_space_total;      /* maximum space in bytes */
11070 +       unsigned long dl_inodes_used;           /* used inodes */
11071 +       unsigned long dl_inodes_total;          /* maximum inodes */
11072 +
11073 +       unsigned int dl_nrlmult;                /* non root limit mult */
11074 +};
11075 +
11076 +struct rcu_head;
11077 +
11078 +extern void rcu_free_dl_info(struct rcu_head *);
11079 +extern void unhash_dl_info(struct dl_info *);
11080 +
11081 +extern struct dl_info *locate_dl_info(struct super_block *, vtag_t);
11082 +
11083 +
11084 +struct kstatfs;
11085 +
11086 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
11087 +
11088 +typedef uint64_t dlsize_t;
11089 +
11090 +#endif /* __KERNEL__ */
11091 +#else  /* _VSERVER_DLIMIT_H */
11092 +#warning duplicate inclusion
11093 +#endif /* _VSERVER_DLIMIT_H */
11094 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
11095 --- linux-3.10.33/include/linux/vserver/dlimit_cmd.h    1970-01-01 00:00:00.000000000 +0000
11096 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/dlimit_cmd.h  2013-08-22 20:30:00.000000000 +0000
11097 @@ -0,0 +1,46 @@
11098 +#ifndef _VSERVER_DLIMIT_CMD_H
11099 +#define _VSERVER_DLIMIT_CMD_H
11100 +
11101 +#include <uapi/vserver/dlimit_cmd.h>
11102 +
11103 +
11104 +#ifdef CONFIG_COMPAT
11105 +
11106 +#include <asm/compat.h>
11107 +
11108 +struct vcmd_ctx_dlimit_base_v0_x32 {
11109 +       compat_uptr_t name_ptr;
11110 +       uint32_t flags;
11111 +};
11112 +
11113 +struct vcmd_ctx_dlimit_v0_x32 {
11114 +       compat_uptr_t name_ptr;
11115 +       uint32_t space_used;                    /* used space in kbytes */
11116 +       uint32_t space_total;                   /* maximum space in kbytes */
11117 +       uint32_t inodes_used;                   /* used inodes */
11118 +       uint32_t inodes_total;                  /* maximum inodes */
11119 +       uint32_t reserved;                      /* reserved for root in % */
11120 +       uint32_t flags;
11121 +};
11122 +
11123 +#endif /* CONFIG_COMPAT */
11124 +
11125 +#include <linux/compiler.h>
11126 +
11127 +extern int vc_add_dlimit(uint32_t, void __user *);
11128 +extern int vc_rem_dlimit(uint32_t, void __user *);
11129 +
11130 +extern int vc_set_dlimit(uint32_t, void __user *);
11131 +extern int vc_get_dlimit(uint32_t, void __user *);
11132 +
11133 +#ifdef CONFIG_COMPAT
11134 +
11135 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
11136 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
11137 +
11138 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
11139 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
11140 +
11141 +#endif /* CONFIG_COMPAT */
11142 +
11143 +#endif /* _VSERVER_DLIMIT_CMD_H */
11144 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
11145 --- linux-3.10.33/include/linux/vserver/global.h        1970-01-01 00:00:00.000000000 +0000
11146 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/global.h      2013-08-22 20:30:00.000000000 +0000
11147 @@ -0,0 +1,19 @@
11148 +#ifndef _VSERVER_GLOBAL_H
11149 +#define _VSERVER_GLOBAL_H
11150 +
11151 +
11152 +extern atomic_t vx_global_ctotal;
11153 +extern atomic_t vx_global_cactive;
11154 +
11155 +extern atomic_t nx_global_ctotal;
11156 +extern atomic_t nx_global_cactive;
11157 +
11158 +extern atomic_t vs_global_nsproxy;
11159 +extern atomic_t vs_global_fs;
11160 +extern atomic_t vs_global_mnt_ns;
11161 +extern atomic_t vs_global_uts_ns;
11162 +extern atomic_t vs_global_user_ns;
11163 +extern atomic_t vs_global_pid_ns;
11164 +
11165 +
11166 +#endif /* _VSERVER_GLOBAL_H */
11167 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
11168 --- linux-3.10.33/include/linux/vserver/history.h       1970-01-01 00:00:00.000000000 +0000
11169 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/history.h     2013-08-22 20:30:00.000000000 +0000
11170 @@ -0,0 +1,197 @@
11171 +#ifndef _VSERVER_HISTORY_H
11172 +#define _VSERVER_HISTORY_H
11173 +
11174 +
11175 +enum {
11176 +       VXH_UNUSED = 0,
11177 +       VXH_THROW_OOPS = 1,
11178 +
11179 +       VXH_GET_VX_INFO,
11180 +       VXH_PUT_VX_INFO,
11181 +       VXH_INIT_VX_INFO,
11182 +       VXH_SET_VX_INFO,
11183 +       VXH_CLR_VX_INFO,
11184 +       VXH_CLAIM_VX_INFO,
11185 +       VXH_RELEASE_VX_INFO,
11186 +       VXH_ALLOC_VX_INFO,
11187 +       VXH_DEALLOC_VX_INFO,
11188 +       VXH_HASH_VX_INFO,
11189 +       VXH_UNHASH_VX_INFO,
11190 +       VXH_LOC_VX_INFO,
11191 +       VXH_LOOKUP_VX_INFO,
11192 +       VXH_CREATE_VX_INFO,
11193 +};
11194 +
11195 +struct _vxhe_vxi {
11196 +       struct vx_info *ptr;
11197 +       unsigned xid;
11198 +       unsigned usecnt;
11199 +       unsigned tasks;
11200 +};
11201 +
11202 +struct _vxhe_set_clr {
11203 +       void *data;
11204 +};
11205 +
11206 +struct _vxhe_loc_lookup {
11207 +       unsigned arg;
11208 +};
11209 +
11210 +struct _vx_hist_entry {
11211 +       void *loc;
11212 +       unsigned short seq;
11213 +       unsigned short type;
11214 +       struct _vxhe_vxi vxi;
11215 +       union {
11216 +               struct _vxhe_set_clr sc;
11217 +               struct _vxhe_loc_lookup ll;
11218 +       };
11219 +};
11220 +
11221 +#ifdef CONFIG_VSERVER_HISTORY
11222 +
11223 +extern unsigned volatile int vxh_active;
11224 +
11225 +struct _vx_hist_entry *vxh_advance(void *loc);
11226 +
11227 +
11228 +static inline
11229 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
11230 +{
11231 +       entry->vxi.ptr = vxi;
11232 +       if (vxi) {
11233 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
11234 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
11235 +               entry->vxi.xid = vxi->vx_id;
11236 +       }
11237 +}
11238 +
11239 +
11240 +#define        __HERE__ current_text_addr()
11241 +
11242 +#define __VXH_BODY(__type, __data, __here)     \
11243 +       struct _vx_hist_entry *entry;           \
11244 +                                               \
11245 +       preempt_disable();                      \
11246 +       entry = vxh_advance(__here);            \
11247 +       __data;                                 \
11248 +       entry->type = __type;                   \
11249 +       preempt_enable();
11250 +
11251 +
11252 +       /* pass vxi only */
11253 +
11254 +#define __VXH_SMPL                             \
11255 +       __vxh_copy_vxi(entry, vxi)
11256 +
11257 +static inline
11258 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
11259 +{
11260 +       __VXH_BODY(__type, __VXH_SMPL, __here)
11261 +}
11262 +
11263 +       /* pass vxi and data (void *) */
11264 +
11265 +#define __VXH_DATA                             \
11266 +       __vxh_copy_vxi(entry, vxi);             \
11267 +       entry->sc.data = data
11268 +
11269 +static inline
11270 +void   __vxh_data(struct vx_info *vxi, void *data,
11271 +                       int __type, void *__here)
11272 +{
11273 +       __VXH_BODY(__type, __VXH_DATA, __here)
11274 +}
11275 +
11276 +       /* pass vxi and arg (long) */
11277 +
11278 +#define __VXH_LONG                             \
11279 +       __vxh_copy_vxi(entry, vxi);             \
11280 +       entry->ll.arg = arg
11281 +
11282 +static inline
11283 +void   __vxh_long(struct vx_info *vxi, long arg,
11284 +                       int __type, void *__here)
11285 +{
11286 +       __VXH_BODY(__type, __VXH_LONG, __here)
11287 +}
11288 +
11289 +
11290 +static inline
11291 +void   __vxh_throw_oops(void *__here)
11292 +{
11293 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
11294 +       /* prevent further acquisition */
11295 +       vxh_active = 0;
11296 +}
11297 +
11298 +
11299 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
11300 +
11301 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
11302 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
11303 +
11304 +#define __vxh_init_vx_info(v, d, h) \
11305 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
11306 +#define __vxh_set_vx_info(v, d, h) \
11307 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
11308 +#define __vxh_clr_vx_info(v, d, h) \
11309 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
11310 +
11311 +#define __vxh_claim_vx_info(v, d, h) \
11312 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
11313 +#define __vxh_release_vx_info(v, d, h) \
11314 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
11315 +
11316 +#define vxh_alloc_vx_info(v) \
11317 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
11318 +#define vxh_dealloc_vx_info(v) \
11319 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
11320 +
11321 +#define vxh_hash_vx_info(v) \
11322 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
11323 +#define vxh_unhash_vx_info(v) \
11324 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
11325 +
11326 +#define vxh_loc_vx_info(v, l) \
11327 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
11328 +#define vxh_lookup_vx_info(v, l) \
11329 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
11330 +#define vxh_create_vx_info(v, l) \
11331 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
11332 +
11333 +extern void vxh_dump_history(void);
11334 +
11335 +
11336 +#else  /* CONFIG_VSERVER_HISTORY */
11337 +
11338 +#define        __HERE__        0
11339 +
11340 +#define vxh_throw_oops()               do { } while (0)
11341 +
11342 +#define __vxh_get_vx_info(v, h)                do { } while (0)
11343 +#define __vxh_put_vx_info(v, h)                do { } while (0)
11344 +
11345 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
11346 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
11347 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
11348 +
11349 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
11350 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
11351 +
11352 +#define vxh_alloc_vx_info(v)           do { } while (0)
11353 +#define vxh_dealloc_vx_info(v)         do { } while (0)
11354 +
11355 +#define vxh_hash_vx_info(v)            do { } while (0)
11356 +#define vxh_unhash_vx_info(v)          do { } while (0)
11357 +
11358 +#define vxh_loc_vx_info(v, l)          do { } while (0)
11359 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
11360 +#define vxh_create_vx_info(v, l)       do { } while (0)
11361 +
11362 +#define vxh_dump_history()             do { } while (0)
11363 +
11364 +
11365 +#endif /* CONFIG_VSERVER_HISTORY */
11366 +
11367 +#endif /* _VSERVER_HISTORY_H */
11368 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
11369 --- linux-3.10.33/include/linux/vserver/inode.h 1970-01-01 00:00:00.000000000 +0000
11370 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/inode.h       2013-08-22 20:30:00.000000000 +0000
11371 @@ -0,0 +1,19 @@
11372 +#ifndef _VSERVER_INODE_H
11373 +#define _VSERVER_INODE_H
11374 +
11375 +#include <uapi/vserver/inode.h>
11376 +
11377 +
11378 +#ifdef CONFIG_VSERVER_PROC_SECURE
11379 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
11380 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11381 +#else
11382 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
11383 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11384 +#endif
11385 +
11386 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
11387 +
11388 +#else  /* _VSERVER_INODE_H */
11389 +#warning duplicate inclusion
11390 +#endif /* _VSERVER_INODE_H */
11391 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
11392 --- linux-3.10.33/include/linux/vserver/inode_cmd.h     1970-01-01 00:00:00.000000000 +0000
11393 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/inode_cmd.h   2013-08-22 20:30:00.000000000 +0000
11394 @@ -0,0 +1,36 @@
11395 +#ifndef _VSERVER_INODE_CMD_H
11396 +#define _VSERVER_INODE_CMD_H
11397 +
11398 +#include <uapi/vserver/inode_cmd.h>
11399 +
11400 +
11401 +
11402 +#ifdef CONFIG_COMPAT
11403 +
11404 +#include <asm/compat.h>
11405 +
11406 +struct vcmd_ctx_iattr_v1_x32 {
11407 +       compat_uptr_t name_ptr;
11408 +       uint32_t tag;
11409 +       uint32_t flags;
11410 +       uint32_t mask;
11411 +};
11412 +
11413 +#endif /* CONFIG_COMPAT */
11414 +
11415 +#include <linux/compiler.h>
11416 +
11417 +extern int vc_get_iattr(void __user *);
11418 +extern int vc_set_iattr(void __user *);
11419 +
11420 +extern int vc_fget_iattr(uint32_t, void __user *);
11421 +extern int vc_fset_iattr(uint32_t, void __user *);
11422 +
11423 +#ifdef CONFIG_COMPAT
11424 +
11425 +extern int vc_get_iattr_x32(void __user *);
11426 +extern int vc_set_iattr_x32(void __user *);
11427 +
11428 +#endif /* CONFIG_COMPAT */
11429 +
11430 +#endif /* _VSERVER_INODE_CMD_H */
11431 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
11432 --- linux-3.10.33/include/linux/vserver/limit.h 1970-01-01 00:00:00.000000000 +0000
11433 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/limit.h       2013-08-22 20:30:00.000000000 +0000
11434 @@ -0,0 +1,61 @@
11435 +#ifndef _VSERVER_LIMIT_H
11436 +#define _VSERVER_LIMIT_H
11437 +
11438 +#include <uapi/vserver/limit.h>
11439 +
11440 +
11441 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
11442 +
11443 +/*     keep in sync with CRLIM_INFINITY */
11444 +
11445 +#define        VLIM_INFINITY   (~0ULL)
11446 +
11447 +#include <asm/atomic.h>
11448 +#include <asm/resource.h>
11449 +
11450 +#ifndef RLIM_INFINITY
11451 +#warning RLIM_INFINITY is undefined
11452 +#endif
11453 +
11454 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
11455 +
11456 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
11457 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
11458 +
11459 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
11460 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
11461 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
11462 +
11463 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
11464 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
11465 +
11466 +typedef atomic_long_t rlim_atomic_t;
11467 +typedef unsigned long rlim_t;
11468 +
11469 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
11470 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
11471 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
11472 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
11473 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
11474 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
11475 +
11476 +
11477 +#if    (RLIM_INFINITY == VLIM_INFINITY)
11478 +#define        VX_VLIM(r) ((long long)(long)(r))
11479 +#define        VX_RLIM(v) ((rlim_t)(v))
11480 +#else
11481 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
11482 +               ? VLIM_INFINITY : (long long)(r))
11483 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
11484 +               ? RLIM_INFINITY : (rlim_t)(v))
11485 +#endif
11486 +
11487 +struct sysinfo;
11488 +
11489 +void vx_vsi_meminfo(struct sysinfo *);
11490 +void vx_vsi_swapinfo(struct sysinfo *);
11491 +long vx_vsi_cached(struct sysinfo *);
11492 +
11493 +#define NUM_LIMITS     24
11494 +
11495 +#endif /* _VSERVER_LIMIT_H */
11496 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
11497 --- linux-3.10.33/include/linux/vserver/limit_cmd.h     1970-01-01 00:00:00.000000000 +0000
11498 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/limit_cmd.h   2013-08-22 20:30:00.000000000 +0000
11499 @@ -0,0 +1,35 @@
11500 +#ifndef _VSERVER_LIMIT_CMD_H
11501 +#define _VSERVER_LIMIT_CMD_H
11502 +
11503 +#include <uapi/vserver/limit_cmd.h>
11504 +
11505 +
11506 +#ifdef CONFIG_IA32_EMULATION
11507 +
11508 +struct vcmd_ctx_rlimit_v0_x32 {
11509 +       uint32_t id;
11510 +       uint64_t minimum;
11511 +       uint64_t softlimit;
11512 +       uint64_t maximum;
11513 +} __attribute__ ((packed));
11514 +
11515 +#endif /* CONFIG_IA32_EMULATION */
11516 +
11517 +#include <linux/compiler.h>
11518 +
11519 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
11520 +extern int vc_get_rlimit(struct vx_info *, void __user *);
11521 +extern int vc_set_rlimit(struct vx_info *, void __user *);
11522 +extern int vc_reset_hits(struct vx_info *, void __user *);
11523 +extern int vc_reset_minmax(struct vx_info *, void __user *);
11524 +
11525 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
11526 +
11527 +#ifdef CONFIG_IA32_EMULATION
11528 +
11529 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
11530 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
11531 +
11532 +#endif /* CONFIG_IA32_EMULATION */
11533 +
11534 +#endif /* _VSERVER_LIMIT_CMD_H */
11535 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
11536 --- linux-3.10.33/include/linux/vserver/limit_def.h     1970-01-01 00:00:00.000000000 +0000
11537 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/limit_def.h   2013-08-22 20:30:00.000000000 +0000
11538 @@ -0,0 +1,47 @@
11539 +#ifndef _VSERVER_LIMIT_DEF_H
11540 +#define _VSERVER_LIMIT_DEF_H
11541 +
11542 +#include <asm/atomic.h>
11543 +#include <asm/resource.h>
11544 +
11545 +#include "limit.h"
11546 +
11547 +
11548 +struct _vx_res_limit {
11549 +       rlim_t soft;            /* Context soft limit */
11550 +       rlim_t hard;            /* Context hard limit */
11551 +
11552 +       rlim_atomic_t rcur;     /* Current value */
11553 +       rlim_t rmin;            /* Context minimum */
11554 +       rlim_t rmax;            /* Context maximum */
11555 +
11556 +       atomic_t lhit;          /* Limit hits */
11557 +};
11558 +
11559 +/* context sub struct */
11560 +
11561 +struct _vx_limit {
11562 +       struct _vx_res_limit res[NUM_LIMITS];
11563 +};
11564 +
11565 +#ifdef CONFIG_VSERVER_DEBUG
11566 +
11567 +static inline void __dump_vx_limit(struct _vx_limit *limit)
11568 +{
11569 +       int i;
11570 +
11571 +       printk("\t_vx_limit:");
11572 +       for (i = 0; i < NUM_LIMITS; i++) {
11573 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
11574 +                       i, (unsigned long)__rlim_get(limit, i),
11575 +                       (unsigned long)__rlim_rmin(limit, i),
11576 +                       (unsigned long)__rlim_rmax(limit, i),
11577 +                       (long)__rlim_soft(limit, i),
11578 +                       (long)__rlim_hard(limit, i),
11579 +                       atomic_read(&__rlim_lhit(limit, i)));
11580 +       }
11581 +}
11582 +
11583 +#endif
11584 +
11585 +#endif /* _VSERVER_LIMIT_DEF_H */
11586 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
11587 --- linux-3.10.33/include/linux/vserver/limit_int.h     1970-01-01 00:00:00.000000000 +0000
11588 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/limit_int.h   2013-08-22 20:30:00.000000000 +0000
11589 @@ -0,0 +1,193 @@
11590 +#ifndef _VSERVER_LIMIT_INT_H
11591 +#define _VSERVER_LIMIT_INT_H
11592 +
11593 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
11594 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
11595 +
11596 +extern const char *vlimit_name[NUM_LIMITS];
11597 +
11598 +static inline void __vx_acc_cres(struct vx_info *vxi,
11599 +       int res, int dir, void *_data, char *_file, int _line)
11600 +{
11601 +       if (VXD_RCRES_COND(res))
11602 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
11603 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11604 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11605 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
11606 +       if (!vxi)
11607 +               return;
11608 +
11609 +       if (dir > 0)
11610 +               __rlim_inc(&vxi->limit, res);
11611 +       else
11612 +               __rlim_dec(&vxi->limit, res);
11613 +}
11614 +
11615 +static inline void __vx_add_cres(struct vx_info *vxi,
11616 +       int res, int amount, void *_data, char *_file, int _line)
11617 +{
11618 +       if (VXD_RCRES_COND(res))
11619 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
11620 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11621 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11622 +                       amount, _data, _file, _line);
11623 +       if (amount == 0)
11624 +               return;
11625 +       if (!vxi)
11626 +               return;
11627 +       __rlim_add(&vxi->limit, res, amount);
11628 +}
11629 +
11630 +static inline
11631 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
11632 +{
11633 +       int cond = (value > __rlim_rmax(limit, res));
11634 +
11635 +       if (cond)
11636 +               __rlim_rmax(limit, res) = value;
11637 +       return cond;
11638 +}
11639 +
11640 +static inline
11641 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
11642 +{
11643 +       int cond = (value < __rlim_rmin(limit, res));
11644 +
11645 +       if (cond)
11646 +               __rlim_rmin(limit, res) = value;
11647 +       return cond;
11648 +}
11649 +
11650 +static inline
11651 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
11652 +{
11653 +       if (!__vx_cres_adjust_max(limit, res, value))
11654 +               __vx_cres_adjust_min(limit, res, value);
11655 +}
11656 +
11657 +
11658 +/*     return values:
11659 +        +1 ... no limit hit
11660 +        -1 ... over soft limit
11661 +         0 ... over hard limit         */
11662 +
11663 +static inline int __vx_cres_avail(struct vx_info *vxi,
11664 +       int res, int num, char *_file, int _line)
11665 +{
11666 +       struct _vx_limit *limit;
11667 +       rlim_t value;
11668 +
11669 +       if (VXD_RLIMIT_COND(res))
11670 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
11671 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11672 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
11673 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
11674 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11675 +                       num, _file, _line);
11676 +       if (!vxi)
11677 +               return 1;
11678 +
11679 +       limit = &vxi->limit;
11680 +       value = __rlim_get(limit, res);
11681 +
11682 +       if (!__vx_cres_adjust_max(limit, res, value))
11683 +               __vx_cres_adjust_min(limit, res, value);
11684 +
11685 +       if (num == 0)
11686 +               return 1;
11687 +
11688 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
11689 +               return -1;
11690 +       if (value + num <= __rlim_soft(limit, res))
11691 +               return -1;
11692 +
11693 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
11694 +               return 1;
11695 +       if (value + num <= __rlim_hard(limit, res))
11696 +               return 1;
11697 +
11698 +       __rlim_hit(limit, res);
11699 +       return 0;
11700 +}
11701 +
11702 +
11703 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
11704 +
11705 +static inline
11706 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
11707 +{
11708 +       rlim_t value, sum = 0;
11709 +       int res;
11710 +
11711 +       while ((res = *array++)) {
11712 +               value = __rlim_get(limit, res);
11713 +               __vx_cres_fixup(limit, res, value);
11714 +               sum += value;
11715 +       }
11716 +       return sum;
11717 +}
11718 +
11719 +static inline
11720 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
11721 +{
11722 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
11723 +       int res = *array;
11724 +
11725 +       if (value == __rlim_get(limit, res))
11726 +               return value;
11727 +
11728 +       __rlim_set(limit, res, value);
11729 +       /* now adjust min/max */
11730 +       if (!__vx_cres_adjust_max(limit, res, value))
11731 +               __vx_cres_adjust_min(limit, res, value);
11732 +
11733 +       return value;
11734 +}
11735 +
11736 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
11737 +       const int *array, int num, char *_file, int _line)
11738 +{
11739 +       struct _vx_limit *limit;
11740 +       rlim_t value = 0;
11741 +       int res;
11742 +
11743 +       if (num == 0)
11744 +               return 1;
11745 +       if (!vxi)
11746 +               return 1;
11747 +
11748 +       limit = &vxi->limit;
11749 +       res = *array;
11750 +       value = __vx_cres_array_sum(limit, array + 1);
11751 +
11752 +       __rlim_set(limit, res, value);
11753 +       __vx_cres_fixup(limit, res, value);
11754 +
11755 +       return __vx_cres_avail(vxi, res, num, _file, _line);
11756 +}
11757 +
11758 +
11759 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
11760 +{
11761 +       rlim_t value;
11762 +       int res;
11763 +
11764 +       /* complex resources first */
11765 +       if ((id < 0) || (id == RLIMIT_RSS))
11766 +               __vx_cres_array_fixup(limit, VLA_RSS);
11767 +
11768 +       for (res = 0; res < NUM_LIMITS; res++) {
11769 +               if ((id > 0) && (res != id))
11770 +                       continue;
11771 +
11772 +               value = __rlim_get(limit, res);
11773 +               __vx_cres_fixup(limit, res, value);
11774 +
11775 +               /* not supposed to happen, maybe warn? */
11776 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
11777 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
11778 +       }
11779 +}
11780 +
11781 +
11782 +#endif /* _VSERVER_LIMIT_INT_H */
11783 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
11784 --- linux-3.10.33/include/linux/vserver/monitor.h       1970-01-01 00:00:00.000000000 +0000
11785 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/monitor.h     2013-08-22 20:30:00.000000000 +0000
11786 @@ -0,0 +1,6 @@
11787 +#ifndef _VSERVER_MONITOR_H
11788 +#define _VSERVER_MONITOR_H
11789 +
11790 +#include <uapi/vserver/monitor.h>
11791 +
11792 +#endif /* _VSERVER_MONITOR_H */
11793 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
11794 --- linux-3.10.33/include/linux/vserver/network.h       1970-01-01 00:00:00.000000000 +0000
11795 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/network.h     2013-08-22 20:30:00.000000000 +0000
11796 @@ -0,0 +1,76 @@
11797 +#ifndef _VSERVER_NETWORK_H
11798 +#define _VSERVER_NETWORK_H
11799 +
11800 +
11801 +#include <linux/list.h>
11802 +#include <linux/spinlock.h>
11803 +#include <linux/rcupdate.h>
11804 +#include <linux/in.h>
11805 +#include <linux/in6.h>
11806 +#include <asm/atomic.h>
11807 +#include <uapi/vserver/network.h>
11808 +
11809 +struct nx_addr_v4 {
11810 +       struct nx_addr_v4 *next;
11811 +       struct in_addr ip[2];
11812 +       struct in_addr mask;
11813 +       uint16_t type;
11814 +       uint16_t flags;
11815 +};
11816 +
11817 +struct nx_addr_v6 {
11818 +       struct nx_addr_v6 *next;
11819 +       struct in6_addr ip;
11820 +       struct in6_addr mask;
11821 +       uint32_t prefix;
11822 +       uint16_t type;
11823 +       uint16_t flags;
11824 +};
11825 +
11826 +struct nx_info {
11827 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
11828 +       vnid_t nx_id;                   /* vnet id */
11829 +       atomic_t nx_usecnt;             /* usage count */
11830 +       atomic_t nx_tasks;              /* tasks count */
11831 +       int nx_state;                   /* context state */
11832 +
11833 +       uint64_t nx_flags;              /* network flag word */
11834 +       uint64_t nx_ncaps;              /* network capabilities */
11835 +
11836 +       spinlock_t addr_lock;           /* protect address changes */
11837 +       struct in_addr v4_lback;        /* Loopback address */
11838 +       struct in_addr v4_bcast;        /* Broadcast address */
11839 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
11840 +#ifdef CONFIG_IPV6
11841 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
11842 +#endif
11843 +       char nx_name[65];               /* network context name */
11844 +};
11845 +
11846 +
11847 +/* status flags */
11848 +
11849 +#define NXS_HASHED      0x0001
11850 +#define NXS_SHUTDOWN    0x0100
11851 +#define NXS_RELEASED    0x8000
11852 +
11853 +extern struct nx_info *lookup_nx_info(int);
11854 +
11855 +extern int get_nid_list(int, unsigned int *, int);
11856 +extern int nid_is_hashed(vnid_t);
11857 +
11858 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
11859 +
11860 +extern long vs_net_change(struct nx_info *, unsigned int);
11861 +
11862 +struct sock;
11863 +
11864 +
11865 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
11866 +#ifdef  CONFIG_IPV6
11867 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
11868 +#else
11869 +#define NX_IPV6(n)     (0)
11870 +#endif
11871 +
11872 +#endif /* _VSERVER_NETWORK_H */
11873 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
11874 --- linux-3.10.33/include/linux/vserver/network_cmd.h   1970-01-01 00:00:00.000000000 +0000
11875 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/network_cmd.h 2013-08-22 20:30:00.000000000 +0000
11876 @@ -0,0 +1,37 @@
11877 +#ifndef _VSERVER_NETWORK_CMD_H
11878 +#define _VSERVER_NETWORK_CMD_H
11879 +
11880 +#include <uapi/vserver/network_cmd.h>
11881 +
11882 +extern int vc_task_nid(uint32_t);
11883 +
11884 +extern int vc_nx_info(struct nx_info *, void __user *);
11885 +
11886 +extern int vc_net_create(uint32_t, void __user *);
11887 +extern int vc_net_migrate(struct nx_info *, void __user *);
11888 +
11889 +extern int vc_net_add(struct nx_info *, void __user *);
11890 +extern int vc_net_remove(struct nx_info *, void __user *);
11891 +
11892 +extern int vc_net_add_ipv4_v1(struct nx_info *, void __user *);
11893 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
11894 +
11895 +extern int vc_net_rem_ipv4_v1(struct nx_info *, void __user *);
11896 +extern int vc_net_rem_ipv4(struct nx_info *, void __user *);
11897 +
11898 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
11899 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
11900 +
11901 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
11902 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
11903 +
11904 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
11905 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
11906 +
11907 +extern int vc_get_nflags(struct nx_info *, void __user *);
11908 +extern int vc_set_nflags(struct nx_info *, void __user *);
11909 +
11910 +extern int vc_get_ncaps(struct nx_info *, void __user *);
11911 +extern int vc_set_ncaps(struct nx_info *, void __user *);
11912 +
11913 +#endif /* _VSERVER_CONTEXT_CMD_H */
11914 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
11915 --- linux-3.10.33/include/linux/vserver/percpu.h        1970-01-01 00:00:00.000000000 +0000
11916 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/percpu.h      2013-08-22 20:30:00.000000000 +0000
11917 @@ -0,0 +1,14 @@
11918 +#ifndef _VSERVER_PERCPU_H
11919 +#define _VSERVER_PERCPU_H
11920 +
11921 +#include "cvirt_def.h"
11922 +#include "sched_def.h"
11923 +
11924 +struct _vx_percpu {
11925 +       struct _vx_cvirt_pc cvirt;
11926 +       struct _vx_sched_pc sched;
11927 +};
11928 +
11929 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
11930 +
11931 +#endif /* _VSERVER_PERCPU_H */
11932 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
11933 --- linux-3.10.33/include/linux/vserver/pid.h   1970-01-01 00:00:00.000000000 +0000
11934 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/pid.h 2013-08-22 20:30:00.000000000 +0000
11935 @@ -0,0 +1,51 @@
11936 +#ifndef _VSERVER_PID_H
11937 +#define _VSERVER_PID_H
11938 +
11939 +/* pid faking stuff */
11940 +
11941 +#define vx_info_map_pid(v, p) \
11942 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
11943 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
11944 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
11945 +#define vx_map_tgid(p) vx_map_pid(p)
11946 +
11947 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
11948 +       const char *func, const char *file, int line)
11949 +{
11950 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
11951 +               vxfprintk(VXD_CBIT(cvirt, 2),
11952 +                       "vx_map_tgid: %p/%llx: %d -> %d",
11953 +                       vxi, (long long)vxi->vx_flags, pid,
11954 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
11955 +                       func, file, line);
11956 +               if (pid == 0)
11957 +                       return 0;
11958 +               if (pid == vxi->vx_initpid)
11959 +                       return 1;
11960 +       }
11961 +       return pid;
11962 +}
11963 +
11964 +#define vx_info_rmap_pid(v, p) \
11965 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
11966 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
11967 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
11968 +
11969 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
11970 +       const char *func, const char *file, int line)
11971 +{
11972 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
11973 +               vxfprintk(VXD_CBIT(cvirt, 2),
11974 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
11975 +                       vxi, (long long)vxi->vx_flags, pid,
11976 +                       (pid == 1) ? vxi->vx_initpid : pid,
11977 +                       func, file, line);
11978 +               if ((pid == 1) && vxi->vx_initpid)
11979 +                       return vxi->vx_initpid;
11980 +               if (pid == vxi->vx_initpid)
11981 +                       return ~0U;
11982 +       }
11983 +       return pid;
11984 +}
11985 +
11986 +#endif
11987 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
11988 --- linux-3.10.33/include/linux/vserver/sched.h 1970-01-01 00:00:00.000000000 +0000
11989 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/sched.h       2013-08-22 20:30:00.000000000 +0000
11990 @@ -0,0 +1,23 @@
11991 +#ifndef _VSERVER_SCHED_H
11992 +#define _VSERVER_SCHED_H
11993 +
11994 +
11995 +#ifdef __KERNEL__
11996 +
11997 +struct timespec;
11998 +
11999 +void vx_vsi_uptime(struct timespec *, struct timespec *);
12000 +
12001 +
12002 +struct vx_info;
12003 +
12004 +void vx_update_load(struct vx_info *);
12005 +
12006 +
12007 +void vx_update_sched_param(struct _vx_sched *sched,
12008 +       struct _vx_sched_pc *sched_pc);
12009 +
12010 +#endif /* __KERNEL__ */
12011 +#else  /* _VSERVER_SCHED_H */
12012 +#warning duplicate inclusion
12013 +#endif /* _VSERVER_SCHED_H */
12014 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
12015 --- linux-3.10.33/include/linux/vserver/sched_cmd.h     1970-01-01 00:00:00.000000000 +0000
12016 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/sched_cmd.h   2013-08-22 20:30:00.000000000 +0000
12017 @@ -0,0 +1,11 @@
12018 +#ifndef _VSERVER_SCHED_CMD_H
12019 +#define _VSERVER_SCHED_CMD_H
12020 +
12021 +
12022 +#include <linux/compiler.h>
12023 +#include <uapi/vserver/sched_cmd.h>
12024 +
12025 +extern int vc_set_prio_bias(struct vx_info *, void __user *);
12026 +extern int vc_get_prio_bias(struct vx_info *, void __user *);
12027 +
12028 +#endif /* _VSERVER_SCHED_CMD_H */
12029 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
12030 --- linux-3.10.33/include/linux/vserver/sched_def.h     1970-01-01 00:00:00.000000000 +0000
12031 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/sched_def.h   2013-08-22 20:30:00.000000000 +0000
12032 @@ -0,0 +1,38 @@
12033 +#ifndef _VSERVER_SCHED_DEF_H
12034 +#define _VSERVER_SCHED_DEF_H
12035 +
12036 +#include <linux/spinlock.h>
12037 +#include <linux/jiffies.h>
12038 +#include <linux/cpumask.h>
12039 +#include <asm/atomic.h>
12040 +#include <asm/param.h>
12041 +
12042 +
12043 +/* context sub struct */
12044 +
12045 +struct _vx_sched {
12046 +       int prio_bias;                  /* bias offset for priority */
12047 +
12048 +       cpumask_t update;               /* CPUs which should update */
12049 +};
12050 +
12051 +struct _vx_sched_pc {
12052 +       int prio_bias;                  /* bias offset for priority */
12053 +
12054 +       uint64_t user_ticks;            /* token tick events */
12055 +       uint64_t sys_ticks;             /* token tick events */
12056 +       uint64_t hold_ticks;            /* token ticks paused */
12057 +};
12058 +
12059 +
12060 +#ifdef CONFIG_VSERVER_DEBUG
12061 +
12062 +static inline void __dump_vx_sched(struct _vx_sched *sched)
12063 +{
12064 +       printk("\t_vx_sched:\n");
12065 +       printk("\t priority = %4d\n", sched->prio_bias);
12066 +}
12067 +
12068 +#endif
12069 +
12070 +#endif /* _VSERVER_SCHED_DEF_H */
12071 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
12072 --- linux-3.10.33/include/linux/vserver/signal.h        1970-01-01 00:00:00.000000000 +0000
12073 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/signal.h      2013-08-22 20:30:00.000000000 +0000
12074 @@ -0,0 +1,14 @@
12075 +#ifndef _VSERVER_SIGNAL_H
12076 +#define _VSERVER_SIGNAL_H
12077 +
12078 +
12079 +#ifdef __KERNEL__
12080 +
12081 +struct vx_info;
12082 +
12083 +int vx_info_kill(struct vx_info *, int, int);
12084 +
12085 +#endif /* __KERNEL__ */
12086 +#else  /* _VSERVER_SIGNAL_H */
12087 +#warning duplicate inclusion
12088 +#endif /* _VSERVER_SIGNAL_H */
12089 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
12090 --- linux-3.10.33/include/linux/vserver/signal_cmd.h    1970-01-01 00:00:00.000000000 +0000
12091 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/signal_cmd.h  2013-08-22 20:30:00.000000000 +0000
12092 @@ -0,0 +1,14 @@
12093 +#ifndef _VSERVER_SIGNAL_CMD_H
12094 +#define _VSERVER_SIGNAL_CMD_H
12095 +
12096 +#include <uapi/vserver/signal_cmd.h>
12097 +
12098 +
12099 +extern int vc_ctx_kill(struct vx_info *, void __user *);
12100 +extern int vc_wait_exit(struct vx_info *, void __user *);
12101 +
12102 +
12103 +extern int vc_get_pflags(uint32_t pid, void __user *);
12104 +extern int vc_set_pflags(uint32_t pid, void __user *);
12105 +
12106 +#endif /* _VSERVER_SIGNAL_CMD_H */
12107 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
12108 --- linux-3.10.33/include/linux/vserver/space.h 1970-01-01 00:00:00.000000000 +0000
12109 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/space.h       2013-08-22 20:30:00.000000000 +0000
12110 @@ -0,0 +1,12 @@
12111 +#ifndef _VSERVER_SPACE_H
12112 +#define _VSERVER_SPACE_H
12113 +
12114 +#include <linux/types.h>
12115 +
12116 +struct vx_info;
12117 +
12118 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
12119 +
12120 +#else  /* _VSERVER_SPACE_H */
12121 +#warning duplicate inclusion
12122 +#endif /* _VSERVER_SPACE_H */
12123 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
12124 --- linux-3.10.33/include/linux/vserver/space_cmd.h     1970-01-01 00:00:00.000000000 +0000
12125 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/space_cmd.h   2013-08-22 20:30:00.000000000 +0000
12126 @@ -0,0 +1,13 @@
12127 +#ifndef _VSERVER_SPACE_CMD_H
12128 +#define _VSERVER_SPACE_CMD_H
12129 +
12130 +#include <uapi/vserver/space_cmd.h>
12131 +
12132 +
12133 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
12134 +extern int vc_set_space_v1(struct vx_info *, void __user *);
12135 +extern int vc_enter_space(struct vx_info *, void __user *);
12136 +extern int vc_set_space(struct vx_info *, void __user *);
12137 +extern int vc_get_space_mask(void __user *, int);
12138 +
12139 +#endif /* _VSERVER_SPACE_CMD_H */
12140 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
12141 --- linux-3.10.33/include/linux/vserver/switch.h        1970-01-01 00:00:00.000000000 +0000
12142 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/switch.h      2013-08-22 20:30:00.000000000 +0000
12143 @@ -0,0 +1,8 @@
12144 +#ifndef _VSERVER_SWITCH_H
12145 +#define _VSERVER_SWITCH_H
12146 +
12147 +
12148 +#include <linux/errno.h>
12149 +#include <uapi/vserver/switch.h>
12150 +
12151 +#endif /* _VSERVER_SWITCH_H */
12152 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
12153 --- linux-3.10.33/include/linux/vserver/tag.h   1970-01-01 00:00:00.000000000 +0000
12154 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/tag.h 2013-08-22 20:30:00.000000000 +0000
12155 @@ -0,0 +1,160 @@
12156 +#ifndef _DX_TAG_H
12157 +#define _DX_TAG_H
12158 +
12159 +#include <linux/types.h>
12160 +#include <linux/uidgid.h>
12161 +
12162 +
12163 +#define DX_TAG(in)     (IS_TAGGED(in))
12164 +
12165 +
12166 +#ifdef CONFIG_TAG_NFSD
12167 +#define DX_TAG_NFSD    1
12168 +#else
12169 +#define DX_TAG_NFSD    0
12170 +#endif
12171 +
12172 +
12173 +#ifdef CONFIG_TAGGING_NONE
12174 +
12175 +#define MAX_UID                0xFFFFFFFF
12176 +#define MAX_GID                0xFFFFFFFF
12177 +
12178 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
12179 +
12180 +#define TAGINO_UID(cond, uid, tag)     (uid)
12181 +#define TAGINO_GID(cond, gid, tag)     (gid)
12182 +
12183 +#endif
12184 +
12185 +
12186 +#ifdef CONFIG_TAGGING_GID16
12187 +
12188 +#define MAX_UID                0xFFFFFFFF
12189 +#define MAX_GID                0x0000FFFF
12190 +
12191 +#define INOTAG_TAG(cond, uid, gid, tag)        \
12192 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
12193 +
12194 +#define TAGINO_UID(cond, uid, tag)     (uid)
12195 +#define TAGINO_GID(cond, gid, tag)     \
12196 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
12197 +
12198 +#endif
12199 +
12200 +
12201 +#ifdef CONFIG_TAGGING_ID24
12202 +
12203 +#define MAX_UID                0x00FFFFFF
12204 +#define MAX_GID                0x00FFFFFF
12205 +
12206 +#define INOTAG_TAG(cond, uid, gid, tag)        \
12207 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
12208 +
12209 +#define TAGINO_UID(cond, uid, tag)     \
12210 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
12211 +#define TAGINO_GID(cond, gid, tag)     \
12212 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
12213 +
12214 +#endif
12215 +
12216 +
12217 +#ifdef CONFIG_TAGGING_UID16
12218 +
12219 +#define MAX_UID                0x0000FFFF
12220 +#define MAX_GID                0xFFFFFFFF
12221 +
12222 +#define INOTAG_TAG(cond, uid, gid, tag)        \
12223 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
12224 +
12225 +#define TAGINO_UID(cond, uid, tag)     \
12226 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
12227 +#define TAGINO_GID(cond, gid, tag)     (gid)
12228 +
12229 +#endif
12230 +
12231 +
12232 +#ifdef CONFIG_TAGGING_INTERN
12233 +
12234 +#define MAX_UID                0xFFFFFFFF
12235 +#define MAX_GID                0xFFFFFFFF
12236 +
12237 +#define INOTAG_TAG(cond, uid, gid, tag)        \
12238 +       ((cond) ? (tag) : 0)
12239 +
12240 +#define TAGINO_UID(cond, uid, tag)     (uid)
12241 +#define TAGINO_GID(cond, gid, tag)     (gid)
12242 +
12243 +#endif
12244 +
12245 +
12246 +#ifndef CONFIG_TAGGING_NONE
12247 +#define dx_current_fstag(sb)   \
12248 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
12249 +#else
12250 +#define dx_current_fstag(sb)   (0)
12251 +#endif
12252 +
12253 +#ifndef CONFIG_TAGGING_INTERN
12254 +#define TAGINO_TAG(cond, tag)  (0)
12255 +#else
12256 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
12257 +#endif
12258 +
12259 +#define TAGINO_KUID(cond, kuid, ktag)  \
12260 +       KUIDT_INIT(TAGINO_UID(cond, __kuid_val(kuid), __ktag_val(ktag)))
12261 +#define TAGINO_KGID(cond, kgid, ktag)  \
12262 +       KGIDT_INIT(TAGINO_GID(cond, __kgid_val(kgid), __ktag_val(ktag)))
12263 +#define TAGINO_KTAG(cond, ktag)                \
12264 +       KTAGT_INIT(TAGINO_TAG(cond, __ktag_val(ktag)))
12265 +
12266 +
12267 +#define INOTAG_UID(cond, uid, gid)     \
12268 +       ((cond) ? ((uid) & MAX_UID) : (uid))
12269 +#define INOTAG_GID(cond, uid, gid)     \
12270 +       ((cond) ? ((gid) & MAX_GID) : (gid))
12271 +
12272 +#define INOTAG_KUID(cond, kuid, kgid)  \
12273 +       KUIDT_INIT(INOTAG_UID(cond, __kuid_val(kuid), __kgid_val(kgid)))
12274 +#define INOTAG_KGID(cond, kuid, kgid)  \
12275 +       KGIDT_INIT(INOTAG_GID(cond, __kuid_val(kuid), __kgid_val(kgid)))
12276 +#define INOTAG_KTAG(cond, kuid, kgid, ktag) \
12277 +       KTAGT_INIT(INOTAG_TAG(cond, \
12278 +               __kuid_val(kuid), __kgid_val(kgid), __ktag_val(ktag)))
12279 +
12280 +
12281 +static inline uid_t dx_map_uid(uid_t uid)
12282 +{
12283 +       if ((uid > MAX_UID) && (uid != -1))
12284 +               uid = -2;
12285 +       return (uid & MAX_UID);
12286 +}
12287 +
12288 +static inline gid_t dx_map_gid(gid_t gid)
12289 +{
12290 +       if ((gid > MAX_GID) && (gid != -1))
12291 +               gid = -2;
12292 +       return (gid & MAX_GID);
12293 +}
12294 +
12295 +struct peer_tag {
12296 +       int32_t xid;
12297 +       int32_t nid;
12298 +};
12299 +
12300 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
12301 +
12302 +int dx_parse_tag(char *string, vtag_t *tag, int remove, int *mnt_flags,
12303 +                unsigned long *flags);
12304 +
12305 +#ifdef CONFIG_PROPAGATE
12306 +
12307 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
12308 +
12309 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
12310 +
12311 +#else
12312 +#define dx_propagate_tag(n, i) do { } while (0)
12313 +#endif
12314 +
12315 +#endif /* _DX_TAG_H */
12316 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
12317 --- linux-3.10.33/include/linux/vserver/tag_cmd.h       1970-01-01 00:00:00.000000000 +0000
12318 +++ linux-3.10.33-vs2.3.6.8/include/linux/vserver/tag_cmd.h     2013-08-22 20:30:00.000000000 +0000
12319 @@ -0,0 +1,10 @@
12320 +#ifndef _VSERVER_TAG_CMD_H
12321 +#define _VSERVER_TAG_CMD_H
12322 +
12323 +#include <uapi/vserver/tag_cmd.h>
12324 +
12325 +extern int vc_task_tag(uint32_t);
12326 +
12327 +extern int vc_tag_migrate(uint32_t);
12328 +
12329 +#endif /* _VSERVER_TAG_CMD_H */
12330 diff -NurpP --minimal linux-3.10.33/include/net/addrconf.h linux-3.10.33-vs2.3.6.8/include/net/addrconf.h
12331 --- linux-3.10.33/include/net/addrconf.h        2014-03-12 13:16:02.000000000 +0000
12332 +++ linux-3.10.33-vs2.3.6.8/include/net/addrconf.h      2013-11-13 17:19:37.000000000 +0000
12333 @@ -89,7 +89,8 @@ extern int                    ipv6_dev_get_saddr(struct n
12334                                                const struct net_device *dev,
12335                                                const struct in6_addr *daddr,
12336                                                unsigned int srcprefs,
12337 -                                              struct in6_addr *saddr);
12338 +                                              struct in6_addr *saddr,
12339 +                                              struct nx_info *nxi);
12340  extern int                     __ipv6_get_lladdr(struct inet6_dev *idev,
12341                                                   struct in6_addr *addr,
12342                                                   unsigned char banned_flags);
12343 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
12344 --- linux-3.10.33/include/net/af_unix.h 2013-07-14 17:01:33.000000000 +0000
12345 +++ linux-3.10.33-vs2.3.6.8/include/net/af_unix.h       2013-08-22 20:30:00.000000000 +0000
12346 @@ -4,6 +4,7 @@
12347  #include <linux/socket.h>
12348  #include <linux/un.h>
12349  #include <linux/mutex.h>
12350 +#include <linux/vs_base.h>
12351  #include <net/sock.h>
12352  
12353  extern void unix_inflight(struct file *fp);
12354 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
12355 --- linux-3.10.33/include/net/inet_timewait_sock.h      2013-05-31 13:45:28.000000000 +0000
12356 +++ linux-3.10.33-vs2.3.6.8/include/net/inet_timewait_sock.h    2013-08-22 20:30:00.000000000 +0000
12357 @@ -116,6 +116,10 @@ struct inet_timewait_sock {
12358  #define tw_dport               __tw_common.skc_dport
12359  #define tw_num                 __tw_common.skc_num
12360  #define tw_portpair            __tw_common.skc_portpair
12361 +#define tw_xid                 __tw_common.skc_xid
12362 +#define tw_vx_info             __tw_common.skc_vx_info
12363 +#define tw_nid                 __tw_common.skc_nid
12364 +#define tw_nx_info             __tw_common.skc_nx_info
12365  
12366         int                     tw_timeout;
12367         volatile unsigned char  tw_substate;
12368 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
12369 --- linux-3.10.33/include/net/ip6_route.h       2014-03-12 13:16:02.000000000 +0000
12370 +++ linux-3.10.33-vs2.3.6.8/include/net/ip6_route.h     2013-11-13 17:22:25.000000000 +0000
12371 @@ -95,7 +95,8 @@ extern int                    ip6_route_get_saddr(struct
12372                                                     struct rt6_info *rt,
12373                                                     const struct in6_addr *daddr,
12374                                                     unsigned int prefs,
12375 -                                                   struct in6_addr *saddr);
12376 +                                                   struct in6_addr *saddr,
12377 +                                                   struct nx_info *nxi);
12378  
12379  extern struct rt6_info         *rt6_lookup(struct net *net,
12380                                             const struct in6_addr *daddr,
12381 diff -NurpP --minimal linux-3.10.33/include/net/route.h linux-3.10.33-vs2.3.6.8/include/net/route.h
12382 --- linux-3.10.33/include/net/route.h   2013-02-19 13:58:52.000000000 +0000
12383 +++ linux-3.10.33-vs2.3.6.8/include/net/route.h 2013-08-22 20:30:00.000000000 +0000
12384 @@ -207,6 +207,9 @@ static inline void ip_rt_put(struct rtab
12385         dst_release(&rt->dst);
12386  }
12387  
12388 +#include <linux/vs_base.h>
12389 +#include <linux/vs_inet.h>
12390 +
12391  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
12392  
12393  extern const __u8 ip_tos2prio[16];
12394 @@ -256,6 +259,9 @@ static inline void ip_route_connect_init
12395                            protocol, flow_flags, dst, src, dport, sport);
12396  }
12397  
12398 +extern struct rtable *ip_v4_find_src(struct net *net, struct nx_info *,
12399 +       struct flowi4 *);
12400 +
12401  static inline struct rtable *ip_route_connect(struct flowi4 *fl4,
12402                                               __be32 dst, __be32 src, u32 tos,
12403                                               int oif, u8 protocol,
12404 @@ -264,11 +270,25 @@ static inline struct rtable *ip_route_co
12405  {
12406         struct net *net = sock_net(sk);
12407         struct rtable *rt;
12408 +       struct nx_info *nx_info = current_nx_info();
12409  
12410         ip_route_connect_init(fl4, dst, src, tos, oif, protocol,
12411                               sport, dport, sk, can_sleep);
12412  
12413 -       if (!dst || !src) {
12414 +       if (sk)
12415 +               nx_info = sk->sk_nx_info;
12416 +
12417 +       vxdprintk(VXD_CBIT(net, 4),
12418 +               "ip_route_connect(%p) %p,%p;%lx",
12419 +               sk, nx_info, sk->sk_socket,
12420 +               (sk->sk_socket?sk->sk_socket->flags:0));
12421 +
12422 +       rt = ip_v4_find_src(net, nx_info, fl4);
12423 +       if (IS_ERR(rt))
12424 +               return rt;
12425 +       ip_rt_put(rt);
12426 +
12427 +       if (!fl4->daddr || !fl4->saddr) {
12428                 rt = __ip_route_output_key(net, fl4);
12429                 if (IS_ERR(rt))
12430                         return rt;
12431 diff -NurpP --minimal linux-3.10.33/include/net/sock.h linux-3.10.33-vs2.3.6.8/include/net/sock.h
12432 --- linux-3.10.33/include/net/sock.h    2014-03-12 13:16:02.000000000 +0000
12433 +++ linux-3.10.33-vs2.3.6.8/include/net/sock.h  2013-11-13 17:22:25.000000000 +0000
12434 @@ -191,6 +191,10 @@ struct sock_common {
12435  #ifdef CONFIG_NET_NS
12436         struct net              *skc_net;
12437  #endif
12438 +       vxid_t                  skc_xid;
12439 +       struct vx_info          *skc_vx_info;
12440 +       vnid_t                  skc_nid;
12441 +       struct nx_info          *skc_nx_info;
12442         /*
12443          * fields between dontcopy_begin/dontcopy_end
12444          * are not copied in sock_copy()
12445 @@ -305,6 +309,10 @@ struct sock {
12446  #define sk_bind_node           __sk_common.skc_bind_node
12447  #define sk_prot                        __sk_common.skc_prot
12448  #define sk_net                 __sk_common.skc_net
12449 +#define sk_xid                 __sk_common.skc_xid
12450 +#define sk_vx_info             __sk_common.skc_vx_info
12451 +#define sk_nid                 __sk_common.skc_nid
12452 +#define sk_nx_info             __sk_common.skc_nx_info
12453         socket_lock_t           sk_lock;
12454         struct sk_buff_head     sk_receive_queue;
12455         /*
12456 diff -NurpP --minimal linux-3.10.33/include/uapi/Kbuild linux-3.10.33-vs2.3.6.8/include/uapi/Kbuild
12457 --- linux-3.10.33/include/uapi/Kbuild   2012-12-11 03:30:57.000000000 +0000
12458 +++ linux-3.10.33-vs2.3.6.8/include/uapi/Kbuild 2013-08-22 20:30:00.000000000 +0000
12459 @@ -12,3 +12,4 @@ header-y += video/
12460  header-y += drm/
12461  header-y += xen/
12462  header-y += scsi/
12463 +header-y += vserver/
12464 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
12465 --- linux-3.10.33/include/uapi/linux/capability.h       2012-12-11 03:30:57.000000000 +0000
12466 +++ linux-3.10.33-vs2.3.6.8/include/uapi/linux/capability.h     2013-08-22 20:30:00.000000000 +0000
12467 @@ -259,6 +259,7 @@ struct vfs_cap_data {
12468     arbitrary SCSI commands */
12469  /* Allow setting encryption key on loopback filesystem */
12470  /* Allow setting zone reclaim policy */
12471 +/* Allow the selection of a security context */
12472  
12473  #define CAP_SYS_ADMIN        21
12474  
12475 @@ -345,7 +346,12 @@ struct vfs_cap_data {
12476  
12477  #define CAP_LAST_CAP         CAP_BLOCK_SUSPEND
12478  
12479 -#define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
12480 +/* Allow context manipulations */
12481 +/* Allow changing context info on files */
12482 +
12483 +#define CAP_CONTEXT         63
12484 +
12485 +#define cap_valid(x) ((x) >= 0 && ((x) <= CAP_LAST_CAP || (x) == CAP_CONTEXT))
12486  
12487  /*
12488   * Bit location of each capability (used by user-space library and kernel)
12489 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
12490 --- linux-3.10.33/include/uapi/linux/fs.h       2013-07-14 17:01:34.000000000 +0000
12491 +++ linux-3.10.33-vs2.3.6.8/include/uapi/linux/fs.h     2013-08-22 20:30:00.000000000 +0000
12492 @@ -86,6 +86,9 @@ struct inodes_stat_t {
12493  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
12494  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
12495  #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
12496 +#define MS_TAGGED      (1<<8)  /* use generic inode tagging */
12497 +#define MS_NOTAGCHECK  (1<<9)  /* don't check tags */
12498 +#define MS_TAGID       (1<<25) /* use specific tag for this mount */
12499  
12500  /* These sb flags are internal to the kernel */
12501  #define MS_NOSEC       (1<<28)
12502 @@ -191,11 +194,14 @@ struct inodes_stat_t {
12503  #define FS_EXTENT_FL                   0x00080000 /* Extents */
12504  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
12505  #define FS_NOCOW_FL                    0x00800000 /* Do not cow file */
12506 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
12507  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
12508  
12509 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
12510 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
12511 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
12512 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
12513  
12514 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
12515 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
12516  
12517  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
12518  #define SYNC_FILE_RANGE_WRITE          2
12519 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
12520 --- linux-3.10.33/include/uapi/linux/gfs2_ondisk.h      2012-12-11 03:30:57.000000000 +0000
12521 +++ linux-3.10.33-vs2.3.6.8/include/uapi/linux/gfs2_ondisk.h    2013-08-22 20:30:00.000000000 +0000
12522 @@ -225,6 +225,9 @@ enum {
12523         gfs2fl_Sync             = 8,
12524         gfs2fl_System           = 9,
12525         gfs2fl_TopLevel         = 10,
12526 +       gfs2fl_IXUnlink         = 16,
12527 +       gfs2fl_Barrier          = 17,
12528 +       gfs2fl_Cow              = 18,
12529         gfs2fl_TruncInProg      = 29,
12530         gfs2fl_InheritDirectio  = 30,
12531         gfs2fl_InheritJdata     = 31,
12532 @@ -242,6 +245,9 @@ enum {
12533  #define GFS2_DIF_SYNC                  0x00000100
12534  #define GFS2_DIF_SYSTEM                        0x00000200 /* New in gfs2 */
12535  #define GFS2_DIF_TOPDIR                        0x00000400 /* New in gfs2 */
12536 +#define GFS2_DIF_IXUNLINK               0x00010000
12537 +#define GFS2_DIF_BARRIER                0x00020000
12538 +#define GFS2_DIF_COW                    0x00040000
12539  #define GFS2_DIF_TRUNC_IN_PROG         0x20000000 /* New in gfs2 */
12540  #define GFS2_DIF_INHERIT_DIRECTIO      0x40000000 /* only in gfs1 */
12541  #define GFS2_DIF_INHERIT_JDATA         0x80000000
12542 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
12543 --- linux-3.10.33/include/uapi/linux/if_tun.h   2013-02-19 13:58:55.000000000 +0000
12544 +++ linux-3.10.33-vs2.3.6.8/include/uapi/linux/if_tun.h 2013-08-22 20:30:00.000000000 +0000
12545 @@ -56,6 +56,7 @@
12546  #define TUNGETVNETHDRSZ _IOR('T', 215, int)
12547  #define TUNSETVNETHDRSZ _IOW('T', 216, int)
12548  #define TUNSETQUEUE  _IOW('T', 217, int)
12549 +#define TUNSETNID     _IOW('T', 218, int)
12550  
12551  /* TUNSETIFF ifr flags */
12552  #define IFF_TUN                0x0001
12553 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
12554 --- linux-3.10.33/include/uapi/linux/major.h    2012-12-11 03:30:57.000000000 +0000
12555 +++ linux-3.10.33-vs2.3.6.8/include/uapi/linux/major.h  2013-08-22 20:30:00.000000000 +0000
12556 @@ -15,6 +15,7 @@
12557  #define HD_MAJOR               IDE0_MAJOR
12558  #define PTY_SLAVE_MAJOR                3
12559  #define TTY_MAJOR              4
12560 +#define VROOT_MAJOR            4
12561  #define TTYAUX_MAJOR           5
12562  #define LP_MAJOR               6
12563  #define VCS_MAJOR              7
12564 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
12565 --- linux-3.10.33/include/uapi/linux/nfs_mount.h        2012-12-11 03:30:57.000000000 +0000
12566 +++ linux-3.10.33-vs2.3.6.8/include/uapi/linux/nfs_mount.h      2013-08-22 20:30:00.000000000 +0000
12567 @@ -63,7 +63,8 @@ struct nfs_mount_data {
12568  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
12569  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
12570  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
12571 -#define NFS_MOUNT_FLAGMASK     0xFFFF
12572 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
12573 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
12574  
12575  /* The following are for internal use only */
12576  #define NFS_MOUNT_LOOKUP_CACHE_NONEG   0x10000
12577 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
12578 --- linux-3.10.33/include/uapi/linux/reboot.h   2012-12-11 03:30:57.000000000 +0000
12579 +++ linux-3.10.33-vs2.3.6.8/include/uapi/linux/reboot.h 2013-08-22 20:30:00.000000000 +0000
12580 @@ -33,7 +33,7 @@
12581  #define        LINUX_REBOOT_CMD_RESTART2       0xA1B2C3D4
12582  #define        LINUX_REBOOT_CMD_SW_SUSPEND     0xD000FCE2
12583  #define        LINUX_REBOOT_CMD_KEXEC          0x45584543
12584 -
12585 +#define        LINUX_REBOOT_CMD_OOM            0xDEADBEEF
12586  
12587  
12588  #endif /* _UAPI_LINUX_REBOOT_H */
12589 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
12590 --- linux-3.10.33/include/uapi/linux/sysctl.h   2012-12-11 03:30:57.000000000 +0000
12591 +++ linux-3.10.33-vs2.3.6.8/include/uapi/linux/sysctl.h 2013-08-22 20:30:00.000000000 +0000
12592 @@ -60,6 +60,7 @@ enum
12593         CTL_ABI=9,              /* Binary emulation */
12594         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
12595         CTL_ARLAN=254,          /* arlan wireless driver */
12596 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
12597         CTL_S390DBF=5677,       /* s390 debug */
12598         CTL_SUNRPC=7249,        /* sunrpc debug */
12599         CTL_PM=9899,            /* frv power management */
12600 @@ -94,6 +95,7 @@ enum
12601  
12602         KERN_PANIC=15,          /* int: panic timeout */
12603         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
12604 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
12605  
12606         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
12607         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
12608 diff -NurpP --minimal linux-3.10.33/include/uapi/vserver/Kbuild linux-3.10.33-vs2.3.6.8/include/uapi/vserver/Kbuild
12609 --- linux-3.10.33/include/uapi/vserver/Kbuild   1970-01-01 00:00:00.000000000 +0000
12610 +++ linux-3.10.33-vs2.3.6.8/include/uapi/vserver/Kbuild 2013-08-22 20:30:00.000000000 +0000
12611 @@ -0,0 +1,9 @@
12612 +
12613 +header-y += context_cmd.h network_cmd.h space_cmd.h \
12614 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
12615 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
12616 +       debug_cmd.h device_cmd.h
12617 +
12618 +header-y += switch.h context.h network.h monitor.h \
12619 +       limit.h inode.h device.h
12620 +
12621 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
12622 --- linux-3.10.33/include/uapi/vserver/cacct_cmd.h      1970-01-01 00:00:00.000000000 +0000
12623 +++ linux-3.10.33-vs2.3.6.8/include/uapi/vserver/cacct_cmd.h    2013-08-22 20:30:00.000000000 +0000
12624 @@ -0,0 +1,15 @@
12625 +#ifndef _UAPI_VS_CACCT_CMD_H
12626 +#define _UAPI_VS_CACCT_CMD_H
12627 +
12628 +
12629 +/* virtual host info name commands */
12630 +
12631 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
12632 +
12633 +struct vcmd_sock_stat_v0 {
12634 +       uint32_t field;
12635 +       uint32_t count[3];
12636 +       uint64_t total[3];
12637 +};
12638 +
12639 +#endif /* _UAPI_VS_CACCT_CMD_H */
12640 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
12641 --- linux-3.10.33/include/uapi/vserver/context.h        1970-01-01 00:00:00.000000000 +0000
12642 +++ linux-3.10.33-vs2.3.6.8/include/uapi/vserver/context.h      2013-10-27 03:43:35.000000000 +0000
12643 @@ -0,0 +1,81 @@
12644 +#ifndef _UAPI_VS_CONTEXT_H
12645 +#define _UAPI_VS_CONTEXT_H
12646 +
12647 +#include <linux/types.h>
12648 +#include <linux/capability.h>
12649 +
12650 +
12651 +/* context flags */
12652 +
12653 +#define VXF_INFO_SCHED         0x00000002
12654 +#define VXF_INFO_NPROC         0x00000004
12655 +#define VXF_INFO_PRIVATE       0x00000008
12656 +
12657 +#define VXF_INFO_INIT          0x00000010
12658 +#define VXF_INFO_HIDE          0x00000020
12659 +#define VXF_INFO_ULIMIT                0x00000040
12660 +#define VXF_INFO_NSPACE                0x00000080
12661 +
12662 +#define VXF_SCHED_HARD         0x00000100
12663 +#define VXF_SCHED_PRIO         0x00000200
12664 +#define VXF_SCHED_PAUSE                0x00000400
12665 +
12666 +#define VXF_VIRT_MEM           0x00010000
12667 +#define VXF_VIRT_UPTIME                0x00020000
12668 +#define VXF_VIRT_CPU           0x00040000
12669 +#define VXF_VIRT_LOAD          0x00080000
12670 +#define VXF_VIRT_TIME          0x00100000
12671 +
12672 +#define VXF_HIDE_MOUNT         0x01000000
12673 +/* was VXF_HIDE_NETIF          0x02000000 */
12674 +#define VXF_HIDE_VINFO         0x04000000
12675 +
12676 +#define VXF_STATE_SETUP                (1ULL << 32)
12677 +#define VXF_STATE_INIT         (1ULL << 33)
12678 +#define VXF_STATE_ADMIN                (1ULL << 34)
12679 +
12680 +#define VXF_SC_HELPER          (1ULL << 36)
12681 +#define VXF_REBOOT_KILL                (1ULL << 37)
12682 +#define VXF_PERSISTENT         (1ULL << 38)
12683 +
12684 +#define VXF_FORK_RSS           (1ULL << 48)
12685 +#define VXF_PROLIFIC           (1ULL << 49)
12686 +
12687 +#define VXF_IGNEG_NICE         (1ULL << 52)
12688 +
12689 +#define VXF_ONE_TIME           (0x0007ULL << 32)
12690 +
12691 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
12692 +
12693 +
12694 +/* context migration */
12695 +
12696 +#define VXM_SET_INIT           0x00000001
12697 +#define VXM_SET_REAPER         0x00000002
12698 +
12699 +/* context caps */
12700 +
12701 +#define VXC_SET_UTSNAME                0x00000001
12702 +#define VXC_SET_RLIMIT         0x00000002
12703 +#define VXC_FS_SECURITY                0x00000004
12704 +#define VXC_FS_TRUSTED         0x00000008
12705 +#define VXC_TIOCSTI            0x00000010
12706 +
12707 +/* was VXC_RAW_ICMP            0x00000100 */
12708 +#define VXC_SYSLOG             0x00001000
12709 +#define VXC_OOM_ADJUST         0x00002000
12710 +#define VXC_AUDIT_CONTROL      0x00004000
12711 +
12712 +#define VXC_SECURE_MOUNT       0x00010000
12713 +/* #define VXC_SECURE_REMOUNT  0x00020000 */
12714 +#define VXC_BINARY_MOUNT       0x00040000
12715 +#define VXC_DEV_MOUNT          0x00080000
12716 +
12717 +#define VXC_QUOTA_CTL          0x00100000
12718 +#define VXC_ADMIN_MAPPER       0x00200000
12719 +#define VXC_ADMIN_CLOOP                0x00400000
12720 +
12721 +#define VXC_KTHREAD            0x01000000
12722 +#define VXC_NAMESPACE          0x02000000
12723 +
12724 +#endif /* _UAPI_VS_CONTEXT_H */
12725 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
12726 --- linux-3.10.33/include/uapi/vserver/context_cmd.h    1970-01-01 00:00:00.000000000 +0000
12727 +++ linux-3.10.33-vs2.3.6.8/include/uapi/vserver/context_cmd.h  2013-08-22 20:30:00.000000000 +0000
12728 @@ -0,0 +1,115 @@
12729 +#ifndef _UAPI_VS_CONTEXT_CMD_H
12730 +#define _UAPI_VS_CONTEXT_CMD_H
12731 +
12732 +
12733 +/* vinfo commands */
12734 +
12735 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
12736 +
12737 +
12738 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
12739 +
12740 +struct vcmd_vx_info_v0 {
12741 +       uint32_t xid;
12742 +       uint32_t initpid;
12743 +       /* more to come */
12744 +};
12745 +
12746 +
12747 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
12748 +
12749 +struct vcmd_ctx_stat_v0 {
12750 +       uint32_t usecnt;
12751 +       uint32_t tasks;
12752 +       /* more to come */
12753 +};
12754 +
12755 +
12756 +/* context commands */
12757 +
12758 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
12759 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
12760 +
12761 +struct vcmd_ctx_create {
12762 +       uint64_t flagword;
12763 +};
12764 +
12765 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
12766 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
12767 +
12768 +struct vcmd_ctx_migrate {
12769 +       uint64_t flagword;
12770 +};
12771 +
12772 +
12773 +
12774 +/* flag commands */
12775 +
12776 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
12777 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
12778 +
12779 +struct vcmd_ctx_flags_v0 {
12780 +       uint64_t flagword;
12781 +       uint64_t mask;
12782 +};
12783 +
12784 +
12785 +
12786 +/* context caps commands */
12787 +
12788 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
12789 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
12790 +
12791 +struct vcmd_ctx_caps_v1 {
12792 +       uint64_t ccaps;
12793 +       uint64_t cmask;
12794 +};
12795 +
12796 +
12797 +
12798 +/* bcaps commands */
12799 +
12800 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
12801 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
12802 +
12803 +struct vcmd_bcaps {
12804 +       uint64_t bcaps;
12805 +       uint64_t bmask;
12806 +};
12807 +
12808 +
12809 +
12810 +/* umask commands */
12811 +
12812 +#define VCMD_get_umask         VC_CMD(FLAGS, 13, 0)
12813 +#define VCMD_set_umask         VC_CMD(FLAGS, 14, 0)
12814 +
12815 +struct vcmd_umask {
12816 +       uint64_t umask;
12817 +       uint64_t mask;
12818 +};
12819 +
12820 +
12821 +
12822 +/* wmask commands */
12823 +
12824 +#define VCMD_get_wmask         VC_CMD(FLAGS, 15, 0)
12825 +#define VCMD_set_wmask         VC_CMD(FLAGS, 16, 0)
12826 +
12827 +struct vcmd_wmask {
12828 +       uint64_t wmask;
12829 +       uint64_t mask;
12830 +};
12831 +
12832 +
12833 +
12834 +/* OOM badness */
12835 +
12836 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
12837 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
12838 +
12839 +struct vcmd_badness_v0 {
12840 +       int64_t bias;
12841 +};
12842 +
12843 +#endif /* _UAPI_VS_CONTEXT_CMD_H */
12844 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
12845 --- linux-3.10.33/include/uapi/vserver/cvirt_cmd.h      1970-01-01 00:00:00.000000000 +0000
12846 +++ linux-3.10.33-vs2.3.6.8/include/uapi/vserver/cvirt_cmd.h    2013-08-22 20:30:00.000000000 +0000
12847 @@ -0,0 +1,41 @@
12848 +#ifndef _UAPI_VS_CVIRT_CMD_H
12849 +#define _UAPI_VS_CVIRT_CMD_H
12850 +
12851 +
12852 +/* virtual host info name commands */
12853 +
12854 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
12855 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
12856 +
12857 +struct vcmd_vhi_name_v0 {
12858 +       uint32_t field;
12859 +       char name[65];
12860 +};
12861 +
12862 +
12863 +enum vhi_name_field {
12864 +       VHIN_CONTEXT = 0,
12865 +       VHIN_SYSNAME,
12866 +       VHIN_NODENAME,
12867 +       VHIN_RELEASE,
12868 +       VHIN_VERSION,
12869 +       VHIN_MACHINE,
12870 +       VHIN_DOMAINNAME,
12871 +};
12872 +
12873 +
12874 +
12875 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
12876 +
12877 +struct vcmd_virt_stat_v0 {
12878 +       uint64_t offset;
12879 +       uint64_t uptime;
12880 +       uint32_t nr_threads;
12881 +       uint32_t nr_running;
12882 +       uint32_t nr_uninterruptible;
12883 +       uint32_t nr_onhold;
12884 +       uint32_t nr_forks;
12885 +       uint32_t load[3];
12886 +};
12887 +
12888 +#endif /* _UAPI_VS_CVIRT_CMD_H */
12889 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
12890 --- linux-3.10.33/include/uapi/vserver/debug_cmd.h      1970-01-01 00:00:00.000000000 +0000
12891 +++ linux-3.10.33-vs2.3.6.8/include/uapi/vserver/debug_cmd.h    2013-08-22 20:30:00.000000000 +0000
12892 @@ -0,0 +1,24 @@
12893 +#ifndef _UAPI_VS_DEBUG_CMD_H
12894 +#define _UAPI_VS_DEBUG_CMD_H
12895 +
12896 +
12897 +/* debug commands */
12898 +
12899 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
12900 +
12901 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
12902 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
12903 +
12904 +struct  vcmd_read_history_v0 {
12905 +       uint32_t index;
12906 +       uint32_t count;
12907 +       char __user *data;
12908 +};
12909 +
12910 +struct  vcmd_read_monitor_v0 {
12911 +       uint32_t index;
12912 +       uint32_t count;
12913 +       char __user *data;
12914 +};
12915 +
12916 +#endif /* _UAPI_VS_DEBUG_CMD_H */
12917 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
12918 --- linux-3.10.33/include/uapi/vserver/device.h 1970-01-01 00:00:00.000000000 +0000
12919 +++ linux-3.10.33-vs2.3.6.8/include/uapi/vserver/device.h       2013-08-22 20:30:00.000000000 +0000
12920 @@ -0,0 +1,12 @@
12921 +#ifndef _UAPI_VS_DEVICE_H
12922 +#define _UAPI_VS_DEVICE_H
12923 +
12924 +
12925 +#define DATTR_CREATE   0x00000001
12926 +#define DATTR_OPEN     0x00000002
12927 +
12928 +#define DATTR_REMAP    0x00000010
12929 +
12930 +#define DATTR_MASK     0x00000013
12931 +
12932 +#endif /* _UAPI_VS_DEVICE_H */
12933 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
12934 --- linux-3.10.33/include/uapi/vserver/device_cmd.h     1970-01-01 00:00:00.000000000 +0000
12935 +++ linux-3.10.33-vs2.3.6.8/include/uapi/vserver/device_cmd.h   2013-08-22 20:30:00.000000000 +0000
12936 @@ -0,0 +1,16 @@
12937 +#ifndef _UAPI_VS_DEVICE_CMD_H
12938 +#define _UAPI_VS_DEVICE_CMD_H
12939 +
12940 +
12941 +/*  device vserver commands */
12942 +
12943 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
12944 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
12945 +
12946 +struct vcmd_set_mapping_v0 {
12947 +       const char __user *device;
12948 +       const char __user *target;
12949 +       uint32_t flags;
12950 +};
12951 +
12952 +#endif /* _UAPI_VS_DEVICE_CMD_H */
12953 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
12954 --- linux-3.10.33/include/uapi/vserver/dlimit_cmd.h     1970-01-01 00:00:00.000000000 +0000
12955 +++ linux-3.10.33-vs2.3.6.8/include/uapi/vserver/dlimit_cmd.h   2013-08-22 20:30:00.000000000 +0000
12956 @@ -0,0 +1,67 @@
12957 +#ifndef _UAPI_VS_DLIMIT_CMD_H
12958 +#define _UAPI_VS_DLIMIT_CMD_H
12959 +
12960 +
12961 +/*  dlimit vserver commands */
12962 +
12963 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
12964 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
12965 +
12966 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
12967 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
12968 +
12969 +struct vcmd_ctx_dlimit_base_v0 {
12970 +       const char __user *name;
12971 +       uint32_t flags;
12972 +};
12973 +
12974 +struct vcmd_ctx_dlimit_v0 {
12975 +       const char __user *name;
12976 +       uint32_t space_used;                    /* used space in kbytes */
12977 +       uint32_t space_total;                   /* maximum space in kbytes */
12978 +       uint32_t inodes_used;                   /* used inodes */
12979 +       uint32_t inodes_total;                  /* maximum inodes */
12980 +       uint32_t reserved;                      /* reserved for root in % */
12981 +       uint32_t flags;
12982 +};
12983 +
12984 +#define CDLIM_UNSET            ((uint32_t)0UL)
12985 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
12986 +#define CDLIM_KEEP             ((uint32_t)~1UL)
12987 +
12988 +#define DLIME_UNIT     0
12989 +#define DLIME_KILO     1
12990 +#define DLIME_MEGA     2
12991 +#define DLIME_GIGA     3
12992 +
12993 +#define DLIMF_SHIFT    0x10
12994 +
12995 +#define DLIMS_USED     0
12996 +#define DLIMS_TOTAL    2
12997 +
12998 +static inline
12999 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
13000 +{
13001 +       int exp = (flags & DLIMF_SHIFT) ?
13002 +               (flags >> shift) & DLIME_GIGA : DLIME_KILO;
13003 +       return ((uint64_t)val) << (10 * exp);
13004 +}
13005 +
13006 +static inline
13007 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
13008 +{
13009 +       int exp = 0;
13010 +
13011 +       if (*flags & DLIMF_SHIFT) {
13012 +               while (val > (1LL << 32) && (exp < 3)) {
13013 +                       val >>= 10;
13014 +                       exp++;
13015 +               }
13016 +               *flags &= ~(DLIME_GIGA << shift);
13017 +               *flags |= exp << shift;
13018 +       } else
13019 +               val >>= 10;
13020 +       return val;
13021 +}
13022 +
13023 +#endif /* _UAPI_VS_DLIMIT_CMD_H */
13024 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
13025 --- linux-3.10.33/include/uapi/vserver/inode.h  1970-01-01 00:00:00.000000000 +0000
13026 +++ linux-3.10.33-vs2.3.6.8/include/uapi/vserver/inode.h        2013-08-22 20:30:00.000000000 +0000
13027 @@ -0,0 +1,23 @@
13028 +#ifndef _UAPI_VS_INODE_H
13029 +#define _UAPI_VS_INODE_H
13030 +
13031 +
13032 +#define IATTR_TAG      0x01000000
13033 +
13034 +#define IATTR_ADMIN    0x00000001
13035 +#define IATTR_WATCH    0x00000002
13036 +#define IATTR_HIDE     0x00000004
13037 +#define IATTR_FLAGS    0x00000007
13038 +
13039 +#define IATTR_BARRIER  0x00010000
13040 +#define IATTR_IXUNLINK 0x00020000
13041 +#define IATTR_IMMUTABLE 0x00040000
13042 +#define IATTR_COW      0x00080000
13043 +
13044 +
13045 +/* inode ioctls */
13046 +
13047 +#define FIOC_GETXFLG   _IOR('x', 5, long)
13048 +#define FIOC_SETXFLG   _IOW('x', 6, long)
13049 +
13050 +#endif /* _UAPI_VS_INODE_H */
13051 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
13052 --- linux-3.10.33/include/uapi/vserver/inode_cmd.h      1970-01-01 00:00:00.000000000 +0000
13053 +++ linux-3.10.33-vs2.3.6.8/include/uapi/vserver/inode_cmd.h    2013-08-22 20:30:00.000000000 +0000
13054 @@ -0,0 +1,26 @@
13055 +#ifndef _UAPI_VS_INODE_CMD_H
13056 +#define _UAPI_VS_INODE_CMD_H
13057 +
13058 +
13059 +/*  inode vserver commands */
13060 +
13061 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
13062 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
13063 +
13064 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
13065 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
13066 +
13067 +struct vcmd_ctx_iattr_v1 {
13068 +       const char __user *name;
13069 +       uint32_t tag;
13070 +       uint32_t flags;
13071 +       uint32_t mask;
13072 +};
13073 +
13074 +struct vcmd_ctx_fiattr_v0 {
13075 +       uint32_t tag;
13076 +       uint32_t flags;
13077 +       uint32_t mask;
13078 +};
13079 +
13080 +#endif /* _UAPI_VS_INODE_CMD_H */
13081 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
13082 --- linux-3.10.33/include/uapi/vserver/limit.h  1970-01-01 00:00:00.000000000 +0000
13083 +++ linux-3.10.33-vs2.3.6.8/include/uapi/vserver/limit.h        2013-08-22 20:30:00.000000000 +0000
13084 @@ -0,0 +1,14 @@
13085 +#ifndef _UAPI_VS_LIMIT_H
13086 +#define _UAPI_VS_LIMIT_H
13087 +
13088 +
13089 +#define VLIMIT_NSOCK   16
13090 +#define VLIMIT_OPENFD  17
13091 +#define VLIMIT_ANON    18
13092 +#define VLIMIT_SHMEM   19
13093 +#define VLIMIT_SEMARY  20
13094 +#define VLIMIT_NSEMS   21
13095 +#define VLIMIT_DENTRY  22
13096 +#define VLIMIT_MAPPED  23
13097 +
13098 +#endif /* _UAPI_VS_LIMIT_H */
13099 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
13100 --- linux-3.10.33/include/uapi/vserver/limit_cmd.h      1970-01-01 00:00:00.000000000 +0000
13101 +++ linux-3.10.33-vs2.3.6.8/include/uapi/vserver/limit_cmd.h    2013-08-22 20:30:00.000000000 +0000
13102 @@ -0,0 +1,40 @@
13103 +#ifndef _UAPI_VS_LIMIT_CMD_H
13104 +#define _UAPI_VS_LIMIT_CMD_H
13105 +
13106 +
13107 +/*  rlimit vserver commands */
13108 +
13109 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
13110 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
13111 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
13112 +#define VCMD_reset_hits                VC_CMD(RLIMIT, 7, 0)
13113 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
13114 +
13115 +struct vcmd_ctx_rlimit_v0 {
13116 +       uint32_t id;
13117 +       uint64_t minimum;
13118 +       uint64_t softlimit;
13119 +       uint64_t maximum;
13120 +};
13121 +
13122 +struct vcmd_ctx_rlimit_mask_v0 {
13123 +       uint32_t minimum;
13124 +       uint32_t softlimit;
13125 +       uint32_t maximum;
13126 +};
13127 +
13128 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
13129 +
13130 +struct vcmd_rlimit_stat_v0 {
13131 +       uint32_t id;
13132 +       uint32_t hits;
13133 +       uint64_t value;
13134 +       uint64_t minimum;
13135 +       uint64_t maximum;
13136 +};
13137 +
13138 +#define CRLIM_UNSET            (0ULL)
13139 +#define CRLIM_INFINITY         (~0ULL)
13140 +#define CRLIM_KEEP             (~1ULL)
13141 +
13142 +#endif /* _UAPI_VS_LIMIT_CMD_H */
13143 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
13144 --- linux-3.10.33/include/uapi/vserver/monitor.h        1970-01-01 00:00:00.000000000 +0000
13145 +++ linux-3.10.33-vs2.3.6.8/include/uapi/vserver/monitor.h      2013-08-22 20:30:00.000000000 +0000
13146 @@ -0,0 +1,96 @@
13147 +#ifndef _UAPI_VS_MONITOR_H
13148 +#define _UAPI_VS_MONITOR_H
13149 +
13150 +#include <linux/types.h>
13151 +
13152 +
13153 +enum {
13154 +       VXM_UNUSED = 0,
13155 +
13156 +       VXM_SYNC = 0x10,
13157 +
13158 +       VXM_UPDATE = 0x20,
13159 +       VXM_UPDATE_1,
13160 +       VXM_UPDATE_2,
13161 +
13162 +       VXM_RQINFO_1 = 0x24,
13163 +       VXM_RQINFO_2,
13164 +
13165 +       VXM_ACTIVATE = 0x40,
13166 +       VXM_DEACTIVATE,
13167 +       VXM_IDLE,
13168 +
13169 +       VXM_HOLD = 0x44,
13170 +       VXM_UNHOLD,
13171 +
13172 +       VXM_MIGRATE = 0x48,
13173 +       VXM_RESCHED,
13174 +
13175 +       /* all other bits are flags */
13176 +       VXM_SCHED = 0x80,
13177 +};
13178 +
13179 +struct _vxm_update_1 {
13180 +       uint32_t tokens_max;
13181 +       uint32_t fill_rate;
13182 +       uint32_t interval;
13183 +};
13184 +
13185 +struct _vxm_update_2 {
13186 +       uint32_t tokens_min;
13187 +       uint32_t fill_rate;
13188 +       uint32_t interval;
13189 +};
13190 +
13191 +struct _vxm_rqinfo_1 {
13192 +       uint16_t running;
13193 +       uint16_t onhold;
13194 +       uint16_t iowait;
13195 +       uint16_t uintr;
13196 +       uint32_t idle_tokens;
13197 +};
13198 +
13199 +struct _vxm_rqinfo_2 {
13200 +       uint32_t norm_time;
13201 +       uint32_t idle_time;
13202 +       uint32_t idle_skip;
13203 +};
13204 +
13205 +struct _vxm_sched {
13206 +       uint32_t tokens;
13207 +       uint32_t norm_time;
13208 +       uint32_t idle_time;
13209 +};
13210 +
13211 +struct _vxm_task {
13212 +       uint16_t pid;
13213 +       uint16_t state;
13214 +};
13215 +
13216 +struct _vxm_event {
13217 +       uint32_t jif;
13218 +       union {
13219 +               uint32_t seq;
13220 +               uint32_t sec;
13221 +       };
13222 +       union {
13223 +               uint32_t tokens;
13224 +               uint32_t nsec;
13225 +               struct _vxm_task tsk;
13226 +       };
13227 +};
13228 +
13229 +struct _vx_mon_entry {
13230 +       uint16_t type;
13231 +       uint16_t xid;
13232 +       union {
13233 +               struct _vxm_event ev;
13234 +               struct _vxm_sched sd;
13235 +               struct _vxm_update_1 u1;
13236 +               struct _vxm_update_2 u2;
13237 +               struct _vxm_rqinfo_1 q1;
13238 +               struct _vxm_rqinfo_2 q2;
13239 +       };
13240 +};
13241 +
13242 +#endif /* _UAPI_VS_MONITOR_H */
13243 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
13244 --- linux-3.10.33/include/uapi/vserver/network.h        1970-01-01 00:00:00.000000000 +0000
13245 +++ linux-3.10.33-vs2.3.6.8/include/uapi/vserver/network.h      2013-08-22 20:30:00.000000000 +0000
13246 @@ -0,0 +1,76 @@
13247 +#ifndef _UAPI_VS_NETWORK_H
13248 +#define _UAPI_VS_NETWORK_H
13249 +
13250 +#include <linux/types.h>
13251 +
13252 +
13253 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
13254 +
13255 +
13256 +/* network flags */
13257 +
13258 +#define NXF_INFO_PRIVATE       0x00000008
13259 +
13260 +#define NXF_SINGLE_IP          0x00000100
13261 +#define NXF_LBACK_REMAP                0x00000200
13262 +#define NXF_LBACK_ALLOW                0x00000400
13263 +
13264 +#define NXF_HIDE_NETIF         0x02000000
13265 +#define NXF_HIDE_LBACK         0x04000000
13266 +
13267 +#define NXF_STATE_SETUP                (1ULL << 32)
13268 +#define NXF_STATE_ADMIN                (1ULL << 34)
13269 +
13270 +#define NXF_SC_HELPER          (1ULL << 36)
13271 +#define NXF_PERSISTENT         (1ULL << 38)
13272 +
13273 +#define NXF_ONE_TIME           (0x0005ULL << 32)
13274 +
13275 +
13276 +#define        NXF_INIT_SET            (__nxf_init_set())
13277 +
13278 +static inline uint64_t __nxf_init_set(void) {
13279 +       return    NXF_STATE_ADMIN
13280 +#ifdef CONFIG_VSERVER_AUTO_LBACK
13281 +               | NXF_LBACK_REMAP
13282 +               | NXF_HIDE_LBACK
13283 +#endif
13284 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
13285 +               | NXF_SINGLE_IP
13286 +#endif
13287 +               | NXF_HIDE_NETIF;
13288 +}
13289 +
13290 +
13291 +/* network caps */
13292 +
13293 +#define NXC_TUN_CREATE         0x00000001
13294 +
13295 +#define NXC_RAW_ICMP           0x00000100
13296 +
13297 +#define NXC_MULTICAST          0x00001000
13298 +
13299 +
13300 +/* address types */
13301 +
13302 +#define NXA_TYPE_IPV4          0x0001
13303 +#define NXA_TYPE_IPV6          0x0002
13304 +
13305 +#define NXA_TYPE_NONE          0x0000
13306 +#define NXA_TYPE_ANY           0x00FF
13307 +
13308 +#define NXA_TYPE_ADDR          0x0010
13309 +#define NXA_TYPE_MASK          0x0020
13310 +#define NXA_TYPE_RANGE         0x0040
13311 +
13312 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
13313 +
13314 +#define NXA_MOD_BCAST          0x0100
13315 +#define NXA_MOD_LBACK          0x0200
13316 +
13317 +#define NXA_LOOPBACK           0x1000
13318 +
13319 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
13320 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
13321 +
13322 +#endif /* _UAPI_VS_NETWORK_H */
13323 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
13324 --- linux-3.10.33/include/uapi/vserver/network_cmd.h    1970-01-01 00:00:00.000000000 +0000
13325 +++ linux-3.10.33-vs2.3.6.8/include/uapi/vserver/network_cmd.h  2013-08-22 20:30:00.000000000 +0000
13326 @@ -0,0 +1,123 @@
13327 +#ifndef _UAPI_VS_NETWORK_CMD_H
13328 +#define _UAPI_VS_NETWORK_CMD_H
13329 +
13330 +
13331 +/* vinfo commands */
13332 +
13333 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
13334 +
13335 +
13336 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
13337 +
13338 +struct vcmd_nx_info_v0 {
13339 +       uint32_t nid;
13340 +       /* more to come */
13341 +};
13342 +
13343 +
13344 +#include <linux/in.h>
13345 +#include <linux/in6.h>
13346 +
13347 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
13348 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
13349 +
13350 +struct  vcmd_net_create {
13351 +       uint64_t flagword;
13352 +};
13353 +
13354 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
13355 +
13356 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
13357 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
13358 +
13359 +struct vcmd_net_addr_v0 {
13360 +       uint16_t type;
13361 +       uint16_t count;
13362 +       struct in_addr ip[4];
13363 +       struct in_addr mask[4];
13364 +};
13365 +
13366 +#define VCMD_net_add_ipv4_v1   VC_CMD(NETALT, 1, 1)
13367 +#define VCMD_net_rem_ipv4_v1   VC_CMD(NETALT, 2, 1)
13368 +
13369 +struct vcmd_net_addr_ipv4_v1 {
13370 +       uint16_t type;
13371 +       uint16_t flags;
13372 +       struct in_addr ip;
13373 +       struct in_addr mask;
13374 +};
13375 +
13376 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 2)
13377 +#define VCMD_net_rem_ipv4      VC_CMD(NETALT, 2, 2)
13378 +
13379 +struct vcmd_net_addr_ipv4_v2 {
13380 +       uint16_t type;
13381 +       uint16_t flags;
13382 +       struct in_addr ip;
13383 +       struct in_addr ip2;
13384 +       struct in_addr mask;
13385 +};
13386 +
13387 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
13388 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
13389 +
13390 +struct vcmd_net_addr_ipv6_v1 {
13391 +       uint16_t type;
13392 +       uint16_t flags;
13393 +       uint32_t prefix;
13394 +       struct in6_addr ip;
13395 +       struct in6_addr mask;
13396 +};
13397 +
13398 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
13399 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
13400 +
13401 +struct vcmd_match_ipv4_v0 {
13402 +       uint16_t type;
13403 +       uint16_t flags;
13404 +       uint16_t parent;
13405 +       uint16_t prefix;
13406 +       struct in_addr ip;
13407 +       struct in_addr ip2;
13408 +       struct in_addr mask;
13409 +};
13410 +
13411 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
13412 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
13413 +
13414 +struct vcmd_match_ipv6_v0 {
13415 +       uint16_t type;
13416 +       uint16_t flags;
13417 +       uint16_t parent;
13418 +       uint16_t prefix;
13419 +       struct in6_addr ip;
13420 +       struct in6_addr ip2;
13421 +       struct in6_addr mask;
13422 +};
13423 +
13424 +
13425 +
13426 +
13427 +/* flag commands */
13428 +
13429 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
13430 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
13431 +
13432 +struct vcmd_net_flags_v0 {
13433 +       uint64_t flagword;
13434 +       uint64_t mask;
13435 +};
13436 +
13437 +
13438 +
13439 +/* network caps commands */
13440 +
13441 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
13442 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
13443 +
13444 +struct vcmd_net_caps_v0 {
13445 +       uint64_t ncaps;
13446 +       uint64_t cmask;
13447 +};
13448 +
13449 +#endif /* _UAPI_VS_NETWORK_CMD_H */
13450 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
13451 --- linux-3.10.33/include/uapi/vserver/sched_cmd.h      1970-01-01 00:00:00.000000000 +0000
13452 +++ linux-3.10.33-vs2.3.6.8/include/uapi/vserver/sched_cmd.h    2013-08-22 20:30:00.000000000 +0000
13453 @@ -0,0 +1,13 @@
13454 +#ifndef _UAPI_VS_SCHED_CMD_H
13455 +#define _UAPI_VS_SCHED_CMD_H
13456 +
13457 +
13458 +struct vcmd_prio_bias {
13459 +       int32_t cpu_id;
13460 +       int32_t prio_bias;
13461 +};
13462 +
13463 +#define VCMD_set_prio_bias     VC_CMD(SCHED, 4, 0)
13464 +#define VCMD_get_prio_bias     VC_CMD(SCHED, 5, 0)
13465 +
13466 +#endif /* _UAPI_VS_SCHED_CMD_H */
13467 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
13468 --- linux-3.10.33/include/uapi/vserver/signal_cmd.h     1970-01-01 00:00:00.000000000 +0000
13469 +++ linux-3.10.33-vs2.3.6.8/include/uapi/vserver/signal_cmd.h   2013-08-22 20:30:00.000000000 +0000
13470 @@ -0,0 +1,31 @@
13471 +#ifndef _UAPI_VS_SIGNAL_CMD_H
13472 +#define _UAPI_VS_SIGNAL_CMD_H
13473 +
13474 +
13475 +/*  signalling vserver commands */
13476 +
13477 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
13478 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
13479 +
13480 +struct vcmd_ctx_kill_v0 {
13481 +       int32_t pid;
13482 +       int32_t sig;
13483 +};
13484 +
13485 +struct vcmd_wait_exit_v0 {
13486 +       int32_t reboot_cmd;
13487 +       int32_t exit_code;
13488 +};
13489 +
13490 +
13491 +/*  process alteration commands */
13492 +
13493 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
13494 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
13495 +
13496 +struct vcmd_pflags_v0 {
13497 +       uint32_t flagword;
13498 +       uint32_t mask;
13499 +};
13500 +
13501 +#endif /* _UAPI_VS_SIGNAL_CMD_H */
13502 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
13503 --- linux-3.10.33/include/uapi/vserver/space_cmd.h      1970-01-01 00:00:00.000000000 +0000
13504 +++ linux-3.10.33-vs2.3.6.8/include/uapi/vserver/space_cmd.h    2013-08-22 20:30:00.000000000 +0000
13505 @@ -0,0 +1,28 @@
13506 +#ifndef _UAPI_VS_SPACE_CMD_H
13507 +#define _UAPI_VS_SPACE_CMD_H
13508 +
13509 +
13510 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
13511 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
13512 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
13513 +
13514 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
13515 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
13516 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
13517 +
13518 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
13519 +
13520 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
13521 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
13522 +
13523 +
13524 +struct vcmd_space_mask_v1 {
13525 +       uint64_t mask;
13526 +};
13527 +
13528 +struct vcmd_space_mask_v2 {
13529 +       uint64_t mask;
13530 +       uint32_t index;
13531 +};
13532 +
13533 +#endif /* _UAPI_VS_SPACE_CMD_H */
13534 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
13535 --- linux-3.10.33/include/uapi/vserver/switch.h 1970-01-01 00:00:00.000000000 +0000
13536 +++ linux-3.10.33-vs2.3.6.8/include/uapi/vserver/switch.h       2013-08-22 20:30:00.000000000 +0000
13537 @@ -0,0 +1,90 @@
13538 +#ifndef _UAPI_VS_SWITCH_H
13539 +#define _UAPI_VS_SWITCH_H
13540 +
13541 +#include <linux/types.h>
13542 +
13543 +
13544 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
13545 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
13546 +#define VC_VERSION(c)          ((c) & 0xFFF)
13547 +
13548 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
13549 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
13550 +
13551 +/*
13552 +
13553 +  Syscall Matrix V2.8
13554 +
13555 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
13556 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
13557 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
13558 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13559 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
13560 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
13561 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13562 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
13563 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
13564 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13565 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
13566 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
13567 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13568 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
13569 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
13570 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13571 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
13572 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
13573 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13574 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
13575 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
13576 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
13577 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
13578 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
13579 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13580 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
13581 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
13582 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13583 +
13584 +*/
13585 +
13586 +#define VC_CAT_VERSION         0
13587 +
13588 +#define VC_CAT_VSETUP          1
13589 +#define VC_CAT_VHOST           2
13590 +
13591 +#define VC_CAT_DEVICE          6
13592 +
13593 +#define VC_CAT_VPROC           9
13594 +#define VC_CAT_PROCALT         10
13595 +#define VC_CAT_PROCMIG         11
13596 +#define VC_CAT_PROCTRL         12
13597 +
13598 +#define VC_CAT_SCHED           14
13599 +#define VC_CAT_MEMCTRL         20
13600 +
13601 +#define VC_CAT_VNET            25
13602 +#define VC_CAT_NETALT          26
13603 +#define VC_CAT_NETMIG          27
13604 +#define VC_CAT_NETCTRL         28
13605 +
13606 +#define VC_CAT_TAGMIG          35
13607 +#define VC_CAT_DLIMIT          36
13608 +#define VC_CAT_INODE           38
13609 +
13610 +#define VC_CAT_VSTAT           40
13611 +#define VC_CAT_VINFO           46
13612 +#define VC_CAT_EVENT           48
13613 +
13614 +#define VC_CAT_FLAGS           52
13615 +#define VC_CAT_VSPACE          54
13616 +#define VC_CAT_DEBUG           56
13617 +#define VC_CAT_RLIMIT          60
13618 +
13619 +#define VC_CAT_SYSTEST         61
13620 +#define VC_CAT_COMPAT          63
13621 +
13622 +/*  query version */
13623 +
13624 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
13625 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
13626 +
13627 +#endif /* _UAPI_VS_SWITCH_H */
13628 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
13629 --- linux-3.10.33/include/uapi/vserver/tag_cmd.h        1970-01-01 00:00:00.000000000 +0000
13630 +++ linux-3.10.33-vs2.3.6.8/include/uapi/vserver/tag_cmd.h      2013-08-22 20:30:00.000000000 +0000
13631 @@ -0,0 +1,14 @@
13632 +#ifndef _UAPI_VS_TAG_CMD_H
13633 +#define _UAPI_VS_TAG_CMD_H
13634 +
13635 +
13636 +/* vinfo commands */
13637 +
13638 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
13639 +
13640 +
13641 +/* context commands */
13642 +
13643 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
13644 +
13645 +#endif /* _UAPI_VS_TAG_CMD_H */
13646 diff -NurpP --minimal linux-3.10.33/init/Kconfig linux-3.10.33-vs2.3.6.8/init/Kconfig
13647 --- linux-3.10.33/init/Kconfig  2013-07-14 17:01:34.000000000 +0000
13648 +++ linux-3.10.33-vs2.3.6.8/init/Kconfig        2013-08-22 20:30:00.000000000 +0000
13649 @@ -805,6 +805,7 @@ config NUMA_BALANCING
13650  menuconfig CGROUPS
13651         boolean "Control Group support"
13652         depends on EVENTFD
13653 +       default y
13654         help
13655           This option adds support for grouping sets of processes together, for
13656           use with process control subsystems such as Cpusets, CFS, memory
13657 @@ -1067,6 +1068,7 @@ config IPC_NS
13658  config USER_NS
13659         bool "User namespace"
13660         depends on UIDGID_CONVERTED
13661 +       depends on VSERVER_DISABLED
13662         select UIDGID_STRICT_TYPE_CHECKS
13663  
13664         default n
13665 diff -NurpP --minimal linux-3.10.33/init/main.c linux-3.10.33-vs2.3.6.8/init/main.c
13666 --- linux-3.10.33/init/main.c   2014-03-12 13:16:02.000000000 +0000
13667 +++ linux-3.10.33-vs2.3.6.8/init/main.c 2013-11-13 17:19:37.000000000 +0000
13668 @@ -75,6 +75,7 @@
13669  #include <linux/blkdev.h>
13670  #include <linux/elevator.h>
13671  #include <linux/random.h>
13672 +#include <linux/vserver/percpu.h>
13673  
13674  #include <asm/io.h>
13675  #include <asm/bugs.h>
13676 diff -NurpP --minimal linux-3.10.33/ipc/mqueue.c linux-3.10.33-vs2.3.6.8/ipc/mqueue.c
13677 --- linux-3.10.33/ipc/mqueue.c  2014-03-12 13:16:02.000000000 +0000
13678 +++ linux-3.10.33-vs2.3.6.8/ipc/mqueue.c        2014-03-12 13:18:33.000000000 +0000
13679 @@ -35,6 +35,8 @@
13680  #include <linux/ipc_namespace.h>
13681  #include <linux/user_namespace.h>
13682  #include <linux/slab.h>
13683 +#include <linux/vs_context.h>
13684 +#include <linux/vs_limit.h>
13685  
13686  #include <net/sock.h>
13687  #include "util.h"
13688 @@ -76,6 +78,7 @@ struct mqueue_inode_info {
13689         struct pid* notify_owner;
13690         struct user_namespace *notify_user_ns;
13691         struct user_struct *user;       /* user who created, for accounting */
13692 +       struct vx_info *vxi;
13693         struct sock *notify_sock;
13694         struct sk_buff *notify_cookie;
13695  
13696 @@ -234,6 +237,7 @@ static struct inode *mqueue_get_inode(st
13697         if (S_ISREG(mode)) {
13698                 struct mqueue_inode_info *info;
13699                 unsigned long mq_bytes, mq_treesize;
13700 +               struct vx_info *vxi = current_vx_info();
13701  
13702                 inode->i_fop = &mqueue_file_operations;
13703                 inode->i_size = FILENT_SIZE;
13704 @@ -247,6 +251,7 @@ static struct inode *mqueue_get_inode(st
13705                 info->notify_user_ns = NULL;
13706                 info->qsize = 0;
13707                 info->user = NULL;      /* set when all is ok */
13708 +               info->vxi = NULL;
13709                 info->msg_tree = RB_ROOT;
13710                 info->node_cache = NULL;
13711                 memset(&info->attr, 0, sizeof(info->attr));
13712 @@ -280,17 +285,20 @@ static struct inode *mqueue_get_inode(st
13713  
13714                 spin_lock(&mq_lock);
13715                 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
13716 -                   u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
13717 +                   u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE) ||
13718 +                   !vx_ipcmsg_avail(vxi, mq_bytes)) {
13719                         spin_unlock(&mq_lock);
13720                         /* mqueue_evict_inode() releases info->messages */
13721                         ret = -EMFILE;
13722                         goto out_inode;
13723                 }
13724                 u->mq_bytes += mq_bytes;
13725 +               vx_ipcmsg_add(vxi, u, mq_bytes);
13726                 spin_unlock(&mq_lock);
13727  
13728                 /* all is ok */
13729                 info->user = get_uid(u);
13730 +               info->vxi = get_vx_info(vxi);
13731         } else if (S_ISDIR(mode)) {
13732                 inc_nlink(inode);
13733                 /* Some things misbehave if size == 0 on a directory */
13734 @@ -402,8 +410,11 @@ static void mqueue_evict_inode(struct in
13735  
13736         user = info->user;
13737         if (user) {
13738 +               struct vx_info *vxi = info->vxi;
13739 +
13740                 spin_lock(&mq_lock);
13741                 user->mq_bytes -= mq_bytes;
13742 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
13743                 /*
13744                  * get_ns_from_inode() ensures that the
13745                  * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
13746 @@ -413,6 +424,7 @@ static void mqueue_evict_inode(struct in
13747                 if (ipc_ns)
13748                         ipc_ns->mq_queues_count--;
13749                 spin_unlock(&mq_lock);
13750 +               put_vx_info(vxi);
13751                 free_uid(user);
13752         }
13753         if (ipc_ns)
13754 diff -NurpP --minimal linux-3.10.33/ipc/msg.c linux-3.10.33-vs2.3.6.8/ipc/msg.c
13755 --- linux-3.10.33/ipc/msg.c     2014-03-12 13:16:02.000000000 +0000
13756 +++ linux-3.10.33-vs2.3.6.8/ipc/msg.c   2013-11-13 17:17:16.000000000 +0000
13757 @@ -37,6 +37,7 @@
13758  #include <linux/rwsem.h>
13759  #include <linux/nsproxy.h>
13760  #include <linux/ipc_namespace.h>
13761 +#include <linux/vs_base.h>
13762  
13763  #include <asm/current.h>
13764  #include <asm/uaccess.h>
13765 @@ -194,6 +195,7 @@ static int newque(struct ipc_namespace *
13766  
13767         msq->q_perm.mode = msgflg & S_IRWXUGO;
13768         msq->q_perm.key = key;
13769 +       msq->q_perm.xid = vx_current_xid();
13770  
13771         msq->q_perm.security = NULL;
13772         retval = security_msg_queue_alloc(msq);
13773 diff -NurpP --minimal linux-3.10.33/ipc/sem.c linux-3.10.33-vs2.3.6.8/ipc/sem.c
13774 --- linux-3.10.33/ipc/sem.c     2014-03-12 13:16:02.000000000 +0000
13775 +++ linux-3.10.33-vs2.3.6.8/ipc/sem.c   2013-12-23 17:42:40.000000000 +0000
13776 @@ -86,6 +86,8 @@
13777  #include <linux/rwsem.h>
13778  #include <linux/nsproxy.h>
13779  #include <linux/ipc_namespace.h>
13780 +#include <linux/vs_base.h>
13781 +#include <linux/vs_limit.h>
13782  
13783  #include <asm/uaccess.h>
13784  #include "util.h"
13785 @@ -500,6 +502,7 @@ static int newary(struct ipc_namespace *
13786  
13787         sma->sem_perm.mode = (semflg & S_IRWXUGO);
13788         sma->sem_perm.key = key;
13789 +       sma->sem_perm.xid = vx_current_xid();
13790  
13791         sma->sem_perm.security = NULL;
13792         retval = security_sem_alloc(sma);
13793 @@ -514,6 +517,9 @@ static int newary(struct ipc_namespace *
13794                 return id;
13795         }
13796         ns->used_sems += nsems;
13797 +       /* FIXME: obsoleted? */
13798 +       vx_semary_inc(sma);
13799 +       vx_nsems_add(sma, nsems);
13800  
13801         sma->sem_base = (struct sem *) &sma[1];
13802  
13803 @@ -1103,6 +1109,9 @@ static void freeary(struct ipc_namespace
13804  
13805         wake_up_sem_queue_do(&tasks);
13806         ns->used_sems -= sma->sem_nsems;
13807 +       /* FIXME: obsoleted? */
13808 +       vx_nsems_sub(sma, sma->sem_nsems);
13809 +       vx_semary_dec(sma);
13810         ipc_rcu_putref(sma, sem_rcu_free);
13811  }
13812  
13813 diff -NurpP --minimal linux-3.10.33/ipc/shm.c linux-3.10.33-vs2.3.6.8/ipc/shm.c
13814 --- linux-3.10.33/ipc/shm.c     2014-03-12 13:16:02.000000000 +0000
13815 +++ linux-3.10.33-vs2.3.6.8/ipc/shm.c   2013-11-30 07:55:52.000000000 +0000
13816 @@ -42,6 +42,8 @@
13817  #include <linux/nsproxy.h>
13818  #include <linux/mount.h>
13819  #include <linux/ipc_namespace.h>
13820 +#include <linux/vs_context.h>
13821 +#include <linux/vs_limit.h>
13822  
13823  #include <asm/uaccess.h>
13824  
13825 @@ -209,10 +211,14 @@ static void shm_open(struct vm_area_stru
13826  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
13827  {
13828         struct file *shm_file;
13829 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
13830 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
13831  
13832         shm_file = shp->shm_file;
13833         shp->shm_file = NULL;
13834 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
13835 +       vx_ipcshm_sub(vxi, shp, numpages);
13836 +       ns->shm_tot -= numpages;
13837 +
13838         shm_rmid(ns, shp);
13839         shm_unlock(shp);
13840         if (!is_file_hugepages(shm_file))
13841 @@ -220,6 +226,7 @@ static void shm_destroy(struct ipc_names
13842         else if (shp->mlock_user)
13843                 user_shm_unlock(file_inode(shm_file)->i_size, shp->mlock_user);
13844         fput(shm_file);
13845 +       put_vx_info(vxi);
13846         ipc_rcu_putref(shp, shm_rcu_free);
13847  }
13848  
13849 @@ -497,11 +504,15 @@ static int newseg(struct ipc_namespace *
13850         if (ns->shm_tot + numpages > ns->shm_ctlall)
13851                 return -ENOSPC;
13852  
13853 +       if (!vx_ipcshm_avail(current_vx_info(), numpages))
13854 +               return -ENOSPC;
13855 +
13856         shp = ipc_rcu_alloc(sizeof(*shp));
13857         if (!shp)
13858                 return -ENOMEM;
13859  
13860         shp->shm_perm.key = key;
13861 +       shp->shm_perm.xid = vx_current_xid();
13862         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
13863         shp->mlock_user = NULL;
13864  
13865 @@ -570,6 +581,7 @@ static int newseg(struct ipc_namespace *
13866  
13867         ipc_unlock_object(&shp->shm_perm);
13868         rcu_read_unlock();
13869 +       vx_ipcshm_add(current_vx_info(), key, numpages);
13870         return error;
13871  
13872  no_id:
13873 diff -NurpP --minimal linux-3.10.33/kernel/Makefile linux-3.10.33-vs2.3.6.8/kernel/Makefile
13874 --- linux-3.10.33/kernel/Makefile       2013-07-14 17:01:34.000000000 +0000
13875 +++ linux-3.10.33-vs2.3.6.8/kernel/Makefile     2013-08-22 21:18:32.000000000 +0000
13876 @@ -25,6 +25,7 @@ endif
13877  obj-y += sched/
13878  obj-y += power/
13879  obj-y += cpu/
13880 +obj-y += vserver/
13881  
13882  obj-$(CONFIG_CHECKPOINT_RESTORE) += kcmp.o
13883  obj-$(CONFIG_FREEZER) += freezer.o
13884 diff -NurpP --minimal linux-3.10.33/kernel/auditsc.c linux-3.10.33-vs2.3.6.8/kernel/auditsc.c
13885 --- linux-3.10.33/kernel/auditsc.c      2014-03-12 13:16:02.000000000 +0000
13886 +++ linux-3.10.33-vs2.3.6.8/kernel/auditsc.c    2013-12-23 17:42:40.000000000 +0000
13887 @@ -1982,7 +1982,7 @@ int audit_set_loginuid(kuid_t loginuid)
13888         if (audit_loginuid_set(task))
13889                 return -EPERM;
13890  #else /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
13891 -       if (!capable(CAP_AUDIT_CONTROL))
13892 +       if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
13893                 return -EPERM;
13894  #endif  /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
13895  
13896 diff -NurpP --minimal linux-3.10.33/kernel/capability.c linux-3.10.33-vs2.3.6.8/kernel/capability.c
13897 --- linux-3.10.33/kernel/capability.c   2013-05-31 13:45:29.000000000 +0000
13898 +++ linux-3.10.33-vs2.3.6.8/kernel/capability.c 2013-08-22 20:30:00.000000000 +0000
13899 @@ -15,6 +15,7 @@
13900  #include <linux/syscalls.h>
13901  #include <linux/pid_namespace.h>
13902  #include <linux/user_namespace.h>
13903 +#include <linux/vs_context.h>
13904  #include <asm/uaccess.h>
13905  
13906  /*
13907 @@ -116,6 +117,7 @@ static int cap_validate_magic(cap_user_h
13908         return 0;
13909  }
13910  
13911 +
13912  /*
13913   * The only thing that can change the capabilities of the current
13914   * process is the current process. As such, we can't be in this code
13915 @@ -349,6 +351,8 @@ bool has_ns_capability_noaudit(struct ta
13916         return (ret == 0);
13917  }
13918  
13919 +#include <linux/vserver/base.h>
13920 +
13921  /**
13922   * has_capability_noaudit - Does a task have a capability (unaudited) in the
13923   * initial user ns
13924 diff -NurpP --minimal linux-3.10.33/kernel/compat.c linux-3.10.33-vs2.3.6.8/kernel/compat.c
13925 --- linux-3.10.33/kernel/compat.c       2013-07-14 17:01:34.000000000 +0000
13926 +++ linux-3.10.33-vs2.3.6.8/kernel/compat.c     2013-08-22 20:30:00.000000000 +0000
13927 @@ -27,6 +27,7 @@
13928  #include <linux/times.h>
13929  #include <linux/ptrace.h>
13930  #include <linux/gfp.h>
13931 +#include <linux/vs_time.h>
13932  
13933  #include <asm/uaccess.h>
13934  
13935 @@ -1040,7 +1041,7 @@ asmlinkage long compat_sys_stime(compat_
13936         if (err)
13937                 return err;
13938  
13939 -       do_settimeofday(&tv);
13940 +       vx_settimeofday(&tv);
13941         return 0;
13942  }
13943  
13944 diff -NurpP --minimal linux-3.10.33/kernel/cred.c linux-3.10.33-vs2.3.6.8/kernel/cred.c
13945 --- linux-3.10.33/kernel/cred.c 2013-02-19 13:58:56.000000000 +0000
13946 +++ linux-3.10.33-vs2.3.6.8/kernel/cred.c       2013-08-22 20:30:00.000000000 +0000
13947 @@ -56,31 +56,6 @@ struct cred init_cred = {
13948         .group_info             = &init_groups,
13949  };
13950  
13951 -static inline void set_cred_subscribers(struct cred *cred, int n)
13952 -{
13953 -#ifdef CONFIG_DEBUG_CREDENTIALS
13954 -       atomic_set(&cred->subscribers, n);
13955 -#endif
13956 -}
13957 -
13958 -static inline int read_cred_subscribers(const struct cred *cred)
13959 -{
13960 -#ifdef CONFIG_DEBUG_CREDENTIALS
13961 -       return atomic_read(&cred->subscribers);
13962 -#else
13963 -       return 0;
13964 -#endif
13965 -}
13966 -
13967 -static inline void alter_cred_subscribers(const struct cred *_cred, int n)
13968 -{
13969 -#ifdef CONFIG_DEBUG_CREDENTIALS
13970 -       struct cred *cred = (struct cred *) _cred;
13971 -
13972 -       atomic_add(n, &cred->subscribers);
13973 -#endif
13974 -}
13975 -
13976  /*
13977   * The RCU callback to actually dispose of a set of credentials
13978   */
13979 @@ -232,21 +207,16 @@ error:
13980   *
13981   * Call commit_creds() or abort_creds() to clean up.
13982   */
13983 -struct cred *prepare_creds(void)
13984 +struct cred *__prepare_creds(const struct cred *old)
13985  {
13986 -       struct task_struct *task = current;
13987 -       const struct cred *old;
13988         struct cred *new;
13989  
13990 -       validate_process_creds();
13991 -
13992         new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
13993         if (!new)
13994                 return NULL;
13995  
13996         kdebug("prepare_creds() alloc %p", new);
13997  
13998 -       old = task->cred;
13999         memcpy(new, old, sizeof(struct cred));
14000  
14001         atomic_set(&new->usage, 1);
14002 @@ -275,6 +245,13 @@ error:
14003         abort_creds(new);
14004         return NULL;
14005  }
14006 +
14007 +struct cred *prepare_creds(void)
14008 +{
14009 +       validate_process_creds();
14010 +
14011 +       return __prepare_creds(current->cred);
14012 +}
14013  EXPORT_SYMBOL(prepare_creds);
14014  
14015  /*
14016 diff -NurpP --minimal linux-3.10.33/kernel/exit.c linux-3.10.33-vs2.3.6.8/kernel/exit.c
14017 --- linux-3.10.33/kernel/exit.c 2013-07-14 17:01:35.000000000 +0000
14018 +++ linux-3.10.33-vs2.3.6.8/kernel/exit.c       2013-08-22 20:30:00.000000000 +0000
14019 @@ -48,6 +48,10 @@
14020  #include <linux/fs_struct.h>
14021  #include <linux/init_task.h>
14022  #include <linux/perf_event.h>
14023 +#include <linux/vs_limit.h>
14024 +#include <linux/vs_context.h>
14025 +#include <linux/vs_network.h>
14026 +#include <linux/vs_pid.h>
14027  #include <trace/events/sched.h>
14028  #include <linux/hw_breakpoint.h>
14029  #include <linux/oom.h>
14030 @@ -514,15 +518,25 @@ static struct task_struct *find_new_reap
14031         __acquires(&tasklist_lock)
14032  {
14033         struct pid_namespace *pid_ns = task_active_pid_ns(father);
14034 -       struct task_struct *thread;
14035 +       struct vx_info *vxi = task_get_vx_info(father);
14036 +       struct task_struct *thread = father;
14037 +       struct task_struct *reaper;
14038  
14039 -       thread = father;
14040         while_each_thread(father, thread) {
14041                 if (thread->flags & PF_EXITING)
14042                         continue;
14043                 if (unlikely(pid_ns->child_reaper == father))
14044                         pid_ns->child_reaper = thread;
14045 -               return thread;
14046 +               reaper = thread;
14047 +               goto out_put;
14048 +       }
14049 +
14050 +       reaper = pid_ns->child_reaper;
14051 +       if (vxi) {
14052 +               BUG_ON(!vxi->vx_reaper);
14053 +               if (vxi->vx_reaper != init_pid_ns.child_reaper &&
14054 +                   vxi->vx_reaper != father)
14055 +                       reaper = vxi->vx_reaper;
14056         }
14057  
14058         if (unlikely(pid_ns->child_reaper == father)) {
14059 @@ -560,7 +574,9 @@ static struct task_struct *find_new_reap
14060                 }
14061         }
14062  
14063 -       return pid_ns->child_reaper;
14064 +out_put:
14065 +       put_vx_info(vxi);
14066 +       return reaper;
14067  }
14068  
14069  /*
14070 @@ -611,10 +627,15 @@ static void forget_original_parent(struc
14071         list_for_each_entry_safe(p, n, &father->children, sibling) {
14072                 struct task_struct *t = p;
14073                 do {
14074 -                       t->real_parent = reaper;
14075 +                       struct task_struct *new_parent = reaper;
14076 +
14077 +                       if (unlikely(p == reaper))
14078 +                               new_parent = task_active_pid_ns(p)->child_reaper;
14079 +
14080 +                       t->real_parent = new_parent;
14081                         if (t->parent == father) {
14082                                 BUG_ON(t->ptrace);
14083 -                               t->parent = t->real_parent;
14084 +                               t->parent = new_parent;
14085                         }
14086                         if (t->pdeath_signal)
14087                                 group_send_sig_info(t->pdeath_signal,
14088 @@ -821,6 +842,9 @@ void do_exit(long code)
14089          */
14090         ptrace_put_breakpoints(tsk);
14091  
14092 +       /* needs to stay before exit_notify() */
14093 +       exit_vx_info_early(tsk, code);
14094 +
14095         exit_notify(tsk, group_dead);
14096  #ifdef CONFIG_NUMA
14097         task_lock(tsk);
14098 @@ -874,10 +898,15 @@ void do_exit(long code)
14099         smp_mb();
14100         raw_spin_unlock_wait(&tsk->pi_lock);
14101  
14102 +       /* needs to stay after exit_notify() */
14103 +       exit_vx_info(tsk, code);
14104 +       exit_nx_info(tsk);
14105 +
14106         /* causes final put_task_struct in finish_task_switch(). */
14107         tsk->state = TASK_DEAD;
14108         tsk->flags |= PF_NOFREEZE;      /* tell freezer to ignore us */
14109         schedule();
14110 +       printk("bad task: %p [%lx]\n", current, current->state);
14111         BUG();
14112         /* Avoid "noreturn function does return".  */
14113         for (;;)
14114 diff -NurpP --minimal linux-3.10.33/kernel/fork.c linux-3.10.33-vs2.3.6.8/kernel/fork.c
14115 --- linux-3.10.33/kernel/fork.c 2014-03-12 13:16:02.000000000 +0000
14116 +++ linux-3.10.33-vs2.3.6.8/kernel/fork.c       2014-01-22 19:00:34.000000000 +0000
14117 @@ -71,6 +71,9 @@
14118  #include <linux/signalfd.h>
14119  #include <linux/uprobes.h>
14120  #include <linux/aio.h>
14121 +#include <linux/vs_context.h>
14122 +#include <linux/vs_network.h>
14123 +#include <linux/vs_limit.h>
14124  
14125  #include <asm/pgtable.h>
14126  #include <asm/pgalloc.h>
14127 @@ -211,6 +214,8 @@ void free_task(struct task_struct *tsk)
14128         arch_release_thread_info(tsk->stack);
14129         free_thread_info(tsk->stack);
14130         rt_mutex_debug_task_free(tsk);
14131 +       clr_vx_info(&tsk->vx_info);
14132 +       clr_nx_info(&tsk->nx_info);
14133         ftrace_graph_exit_task(tsk);
14134         put_seccomp_filter(tsk);
14135         arch_release_task_struct(tsk);
14136 @@ -549,6 +554,7 @@ static struct mm_struct *mm_init(struct
14137         if (likely(!mm_alloc_pgd(mm))) {
14138                 mm->def_flags = 0;
14139                 mmu_notifier_mm_init(mm);
14140 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
14141                 return mm;
14142         }
14143  
14144 @@ -601,6 +607,7 @@ void __mmdrop(struct mm_struct *mm)
14145         destroy_context(mm);
14146         mmu_notifier_mm_destroy(mm);
14147         check_mm(mm);
14148 +       clr_vx_info(&mm->mm_vx_info);
14149         free_mm(mm);
14150  }
14151  EXPORT_SYMBOL_GPL(__mmdrop);
14152 @@ -820,6 +827,7 @@ struct mm_struct *dup_mm(struct task_str
14153                 goto fail_nomem;
14154  
14155         memcpy(mm, oldmm, sizeof(*mm));
14156 +       mm->mm_vx_info = NULL;
14157         mm_init_cpumask(mm);
14158  
14159  #ifdef CONFIG_TRANSPARENT_HUGEPAGE
14160 @@ -861,6 +869,7 @@ fail_nocontext:
14161          * If init_new_context() failed, we cannot use mmput() to free the mm
14162          * because it calls destroy_context()
14163          */
14164 +       clr_vx_info(&mm->mm_vx_info);
14165         mm_free_pgd(mm);
14166         free_mm(mm);
14167         return NULL;
14168 @@ -1139,6 +1148,8 @@ static struct task_struct *copy_process(
14169  {
14170         int retval;
14171         struct task_struct *p;
14172 +       struct vx_info *vxi;
14173 +       struct nx_info *nxi;
14174  
14175         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
14176                 return ERR_PTR(-EINVAL);
14177 @@ -1198,7 +1209,12 @@ static struct task_struct *copy_process(
14178         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
14179         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
14180  #endif
14181 +       init_vx_info(&p->vx_info, current_vx_info());
14182 +       init_nx_info(&p->nx_info, current_nx_info());
14183 +
14184         retval = -EAGAIN;
14185 +       if (!vx_nproc_avail(1))
14186 +               goto bad_fork_free;
14187         if (atomic_read(&p->real_cred->user->processes) >=
14188                         task_rlimit(p, RLIMIT_NPROC)) {
14189                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
14190 @@ -1479,6 +1495,18 @@ static struct task_struct *copy_process(
14191  
14192         total_forks++;
14193         spin_unlock(&current->sighand->siglock);
14194 +
14195 +       /* p is copy of current */
14196 +       vxi = p->vx_info;
14197 +       if (vxi) {
14198 +               claim_vx_info(vxi, p);
14199 +               atomic_inc(&vxi->cvirt.nr_threads);
14200 +               atomic_inc(&vxi->cvirt.total_forks);
14201 +               vx_nproc_inc(p);
14202 +       }
14203 +       nxi = p->nx_info;
14204 +       if (nxi)
14205 +               claim_nx_info(nxi, p);
14206         write_unlock_irq(&tasklist_lock);
14207         proc_fork_connector(p);
14208         cgroup_post_fork(p);
14209 diff -NurpP --minimal linux-3.10.33/kernel/kthread.c linux-3.10.33-vs2.3.6.8/kernel/kthread.c
14210 --- linux-3.10.33/kernel/kthread.c      2013-07-14 17:01:35.000000000 +0000
14211 +++ linux-3.10.33-vs2.3.6.8/kernel/kthread.c    2013-08-22 21:14:28.000000000 +0000
14212 @@ -18,6 +18,7 @@
14213  #include <linux/freezer.h>
14214  #include <linux/ptrace.h>
14215  #include <linux/uaccess.h>
14216 +#include <linux/vs_pid.h>
14217  #include <trace/events/sched.h>
14218  
14219  static DEFINE_SPINLOCK(kthread_create_lock);
14220 diff -NurpP --minimal linux-3.10.33/kernel/nsproxy.c linux-3.10.33-vs2.3.6.8/kernel/nsproxy.c
14221 --- linux-3.10.33/kernel/nsproxy.c      2013-07-14 17:01:35.000000000 +0000
14222 +++ linux-3.10.33-vs2.3.6.8/kernel/nsproxy.c    2013-08-22 21:09:55.000000000 +0000
14223 @@ -20,11 +20,14 @@
14224  #include <linux/mnt_namespace.h>
14225  #include <linux/utsname.h>
14226  #include <linux/pid_namespace.h>
14227 +#include <linux/vserver/global.h>
14228 +#include <linux/vserver/debug.h>
14229  #include <net/net_namespace.h>
14230  #include <linux/ipc_namespace.h>
14231  #include <linux/proc_ns.h>
14232  #include <linux/file.h>
14233  #include <linux/syscalls.h>
14234 +#include "../fs/mount.h"
14235  
14236  static struct kmem_cache *nsproxy_cachep;
14237  
14238 @@ -46,8 +49,11 @@ static inline struct nsproxy *create_nsp
14239         struct nsproxy *nsproxy;
14240  
14241         nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
14242 -       if (nsproxy)
14243 +       if (nsproxy) {
14244                 atomic_set(&nsproxy->count, 1);
14245 +               atomic_inc(&vs_global_nsproxy);
14246 +       }
14247 +       vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
14248         return nsproxy;
14249  }
14250  
14251 @@ -56,9 +62,12 @@ static inline struct nsproxy *create_nsp
14252   * Return the newly created nsproxy.  Do not attach this to the task,
14253   * leave it to the caller to do proper locking and attach it to task.
14254   */
14255 -static struct nsproxy *create_new_namespaces(unsigned long flags,
14256 -       struct task_struct *tsk, struct user_namespace *user_ns,
14257 -       struct fs_struct *new_fs)
14258 +static struct nsproxy *unshare_namespaces(
14259 +       unsigned long flags,
14260 +       struct nsproxy *orig,
14261 +       struct fs_struct *new_fs,
14262 +       struct user_namespace *new_user,
14263 +       struct pid_namespace *new_pid)
14264  {
14265         struct nsproxy *new_nsp;
14266         int err;
14267 @@ -67,31 +76,31 @@ static struct nsproxy *create_new_namesp
14268         if (!new_nsp)
14269                 return ERR_PTR(-ENOMEM);
14270  
14271 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, user_ns, new_fs);
14272 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_user, new_fs);
14273         if (IS_ERR(new_nsp->mnt_ns)) {
14274                 err = PTR_ERR(new_nsp->mnt_ns);
14275                 goto out_ns;
14276         }
14277  
14278 -       new_nsp->uts_ns = copy_utsname(flags, user_ns, tsk->nsproxy->uts_ns);
14279 +       new_nsp->uts_ns = copy_utsname(flags, new_user, orig->uts_ns);
14280         if (IS_ERR(new_nsp->uts_ns)) {
14281                 err = PTR_ERR(new_nsp->uts_ns);
14282                 goto out_uts;
14283         }
14284  
14285 -       new_nsp->ipc_ns = copy_ipcs(flags, user_ns, tsk->nsproxy->ipc_ns);
14286 +       new_nsp->ipc_ns = copy_ipcs(flags, new_user, orig->ipc_ns);
14287         if (IS_ERR(new_nsp->ipc_ns)) {
14288                 err = PTR_ERR(new_nsp->ipc_ns);
14289                 goto out_ipc;
14290         }
14291  
14292 -       new_nsp->pid_ns = copy_pid_ns(flags, user_ns, tsk->nsproxy->pid_ns);
14293 +       new_nsp->pid_ns = copy_pid_ns(flags, new_user, new_pid);
14294         if (IS_ERR(new_nsp->pid_ns)) {
14295                 err = PTR_ERR(new_nsp->pid_ns);
14296                 goto out_pid;
14297         }
14298  
14299 -       new_nsp->net_ns = copy_net_ns(flags, user_ns, tsk->nsproxy->net_ns);
14300 +       new_nsp->net_ns = copy_net_ns(flags, new_user, orig->net_ns);
14301         if (IS_ERR(new_nsp->net_ns)) {
14302                 err = PTR_ERR(new_nsp->net_ns);
14303                 goto out_net;
14304 @@ -116,6 +125,41 @@ out_ns:
14305         return ERR_PTR(err);
14306  }
14307  
14308 +static struct nsproxy *create_new_namespaces(unsigned long flags,
14309 +       struct task_struct *tsk, struct user_namespace *user_ns,
14310 +       struct fs_struct *new_fs)
14311 +
14312 +{
14313 +       return unshare_namespaces(flags, tsk->nsproxy,
14314 +               new_fs, user_ns, task_active_pid_ns(tsk));
14315 +}
14316 +
14317 +/*
14318 + * copies the nsproxy, setting refcount to 1, and grabbing a
14319 + * reference to all contained namespaces.
14320 + */
14321 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
14322 +{
14323 +       struct nsproxy *ns = create_nsproxy();
14324 +
14325 +       if (ns) {
14326 +               memcpy(ns, orig, sizeof(struct nsproxy));
14327 +               atomic_set(&ns->count, 1);
14328 +
14329 +               if (ns->mnt_ns)
14330 +                       get_mnt_ns(ns->mnt_ns);
14331 +               if (ns->uts_ns)
14332 +                       get_uts_ns(ns->uts_ns);
14333 +               if (ns->ipc_ns)
14334 +                       get_ipc_ns(ns->ipc_ns);
14335 +               if (ns->pid_ns)
14336 +                       get_pid_ns(ns->pid_ns);
14337 +               if (ns->net_ns)
14338 +                       get_net(ns->net_ns);
14339 +       }
14340 +       return ns;
14341 +}
14342 +
14343  /*
14344   * called from clone.  This now handles copy for nsproxy and all
14345   * namespaces therein.
14346 @@ -124,9 +168,12 @@ int copy_namespaces(unsigned long flags,
14347  {
14348         struct nsproxy *old_ns = tsk->nsproxy;
14349         struct user_namespace *user_ns = task_cred_xxx(tsk, user_ns);
14350 -       struct nsproxy *new_ns;
14351 +       struct nsproxy *new_ns = NULL;
14352         int err = 0;
14353  
14354 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
14355 +               flags, tsk, old_ns);
14356 +
14357         if (!old_ns)
14358                 return 0;
14359  
14360 @@ -136,7 +183,7 @@ int copy_namespaces(unsigned long flags,
14361                                 CLONE_NEWPID | CLONE_NEWNET)))
14362                 return 0;
14363  
14364 -       if (!ns_capable(user_ns, CAP_SYS_ADMIN)) {
14365 +       if (!vx_ns_can_unshare(user_ns, CAP_SYS_ADMIN, flags)) {
14366                 err = -EPERM;
14367                 goto out;
14368         }
14369 @@ -163,6 +210,9 @@ int copy_namespaces(unsigned long flags,
14370  
14371  out:
14372         put_nsproxy(old_ns);
14373 +       vxdprintk(VXD_CBIT(space, 3),
14374 +               "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
14375 +               flags, tsk, old_ns, err, new_ns);
14376         return err;
14377  }
14378  
14379 @@ -176,7 +226,9 @@ void free_nsproxy(struct nsproxy *ns)
14380                 put_ipc_ns(ns->ipc_ns);
14381         if (ns->pid_ns)
14382                 put_pid_ns(ns->pid_ns);
14383 -       put_net(ns->net_ns);
14384 +       if (ns->net_ns)
14385 +               put_net(ns->net_ns);
14386 +       atomic_dec(&vs_global_nsproxy);
14387         kmem_cache_free(nsproxy_cachep, ns);
14388  }
14389  
14390 @@ -190,12 +242,16 @@ int unshare_nsproxy_namespaces(unsigned
14391         struct user_namespace *user_ns;
14392         int err = 0;
14393  
14394 +       vxdprintk(VXD_CBIT(space, 4),
14395 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
14396 +               unshare_flags, current->nsproxy);
14397 +
14398         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
14399                                CLONE_NEWNET | CLONE_NEWPID)))
14400                 return 0;
14401  
14402         user_ns = new_cred ? new_cred->user_ns : current_user_ns();
14403 -       if (!ns_capable(user_ns, CAP_SYS_ADMIN))
14404 +       if (!vx_ns_can_unshare(user_ns, CAP_SYS_ADMIN, unshare_flags))
14405                 return -EPERM;
14406  
14407         *new_nsp = create_new_namespaces(unshare_flags, current, user_ns,
14408 diff -NurpP --minimal linux-3.10.33/kernel/pid.c linux-3.10.33-vs2.3.6.8/kernel/pid.c
14409 --- linux-3.10.33/kernel/pid.c  2014-03-12 13:16:02.000000000 +0000
14410 +++ linux-3.10.33-vs2.3.6.8/kernel/pid.c        2013-11-13 17:17:16.000000000 +0000
14411 @@ -38,6 +38,7 @@
14412  #include <linux/syscalls.h>
14413  #include <linux/proc_ns.h>
14414  #include <linux/proc_fs.h>
14415 +#include <linux/vs_pid.h>
14416  
14417  #define pid_hashfn(nr, ns)     \
14418         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
14419 @@ -367,7 +368,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
14420  
14421  struct pid *find_vpid(int nr)
14422  {
14423 -       return find_pid_ns(nr, task_active_pid_ns(current));
14424 +       return find_pid_ns(vx_rmap_pid(nr), task_active_pid_ns(current));
14425  }
14426  EXPORT_SYMBOL_GPL(find_vpid);
14427  
14428 @@ -427,6 +428,9 @@ void transfer_pid(struct task_struct *ol
14429  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
14430  {
14431         struct task_struct *result = NULL;
14432 +
14433 +       if (type == PIDTYPE_REALPID)
14434 +               type = PIDTYPE_PID;
14435         if (pid) {
14436                 struct hlist_node *first;
14437                 first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]),
14438 @@ -446,7 +450,7 @@ struct task_struct *find_task_by_pid_ns(
14439         rcu_lockdep_assert(rcu_read_lock_held(),
14440                            "find_task_by_pid_ns() needs rcu_read_lock()"
14441                            " protection");
14442 -       return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
14443 +       return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
14444  }
14445  
14446  struct task_struct *find_task_by_vpid(pid_t vnr)
14447 @@ -490,7 +494,7 @@ struct pid *find_get_pid(pid_t nr)
14448  }
14449  EXPORT_SYMBOL_GPL(find_get_pid);
14450  
14451 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
14452 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
14453  {
14454         struct upid *upid;
14455         pid_t nr = 0;
14456 @@ -504,6 +508,11 @@ pid_t pid_nr_ns(struct pid *pid, struct
14457  }
14458  EXPORT_SYMBOL_GPL(pid_nr_ns);
14459  
14460 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
14461 +{
14462 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
14463 +}
14464 +
14465  pid_t pid_vnr(struct pid *pid)
14466  {
14467         return pid_nr_ns(pid, task_active_pid_ns(current));
14468 diff -NurpP --minimal linux-3.10.33/kernel/pid_namespace.c linux-3.10.33-vs2.3.6.8/kernel/pid_namespace.c
14469 --- linux-3.10.33/kernel/pid_namespace.c        2013-07-14 17:01:35.000000000 +0000
14470 +++ linux-3.10.33-vs2.3.6.8/kernel/pid_namespace.c      2013-08-22 20:30:00.000000000 +0000
14471 @@ -18,6 +18,7 @@
14472  #include <linux/proc_ns.h>
14473  #include <linux/reboot.h>
14474  #include <linux/export.h>
14475 +#include <linux/vserver/global.h>
14476  
14477  struct pid_cache {
14478         int nr_ids;
14479 @@ -110,6 +111,7 @@ static struct pid_namespace *create_pid_
14480                 goto out_free_map;
14481  
14482         kref_init(&ns->kref);
14483 +       atomic_inc(&vs_global_pid_ns);
14484         ns->level = level;
14485         ns->parent = get_pid_ns(parent_pid_ns);
14486         ns->user_ns = get_user_ns(user_ns);
14487 @@ -140,6 +142,7 @@ static void destroy_pid_namespace(struct
14488         for (i = 0; i < PIDMAP_ENTRIES; i++)
14489                 kfree(ns->pidmap[i].page);
14490         put_user_ns(ns->user_ns);
14491 +       atomic_dec(&vs_global_pid_ns);
14492         kmem_cache_free(pid_ns_cachep, ns);
14493  }
14494  
14495 diff -NurpP --minimal linux-3.10.33/kernel/posix-timers.c linux-3.10.33-vs2.3.6.8/kernel/posix-timers.c
14496 --- linux-3.10.33/kernel/posix-timers.c 2013-07-14 17:01:35.000000000 +0000
14497 +++ linux-3.10.33-vs2.3.6.8/kernel/posix-timers.c       2013-08-22 21:10:34.000000000 +0000
14498 @@ -48,6 +48,7 @@
14499  #include <linux/workqueue.h>
14500  #include <linux/export.h>
14501  #include <linux/hashtable.h>
14502 +#include <linux/vs_context.h>
14503  
14504  /*
14505   * Management arrays for POSIX timers. Timers are now kept in static hash table
14506 @@ -398,6 +399,7 @@ int posix_timer_event(struct k_itimer *t
14507  {
14508         struct task_struct *task;
14509         int shared, ret = -1;
14510 +
14511         /*
14512          * FIXME: if ->sigq is queued we can race with
14513          * dequeue_signal()->do_schedule_next_timer().
14514 @@ -414,10 +416,18 @@ int posix_timer_event(struct k_itimer *t
14515         rcu_read_lock();
14516         task = pid_task(timr->it_pid, PIDTYPE_PID);
14517         if (task) {
14518 +               struct vx_info_save vxis;
14519 +               struct vx_info *vxi;
14520 +
14521 +               vxi = get_vx_info(task->vx_info);
14522 +               enter_vx_info(vxi, &vxis);
14523                 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
14524                 ret = send_sigqueue(timr->sigq, task, shared);
14525 +               leave_vx_info(&vxis);
14526 +               put_vx_info(vxi);
14527         }
14528         rcu_read_unlock();
14529 +
14530         /* If we failed to send the signal the timer stops. */
14531         return ret > 0;
14532  }
14533 diff -NurpP --minimal linux-3.10.33/kernel/printk.c linux-3.10.33-vs2.3.6.8/kernel/printk.c
14534 --- linux-3.10.33/kernel/printk.c       2014-03-12 13:16:02.000000000 +0000
14535 +++ linux-3.10.33-vs2.3.6.8/kernel/printk.c     2013-11-13 17:17:16.000000000 +0000
14536 @@ -45,6 +45,7 @@
14537  #include <linux/poll.h>
14538  #include <linux/irq_work.h>
14539  #include <linux/utsname.h>
14540 +#include <linux/vs_cvirt.h>
14541  
14542  #include <asm/uaccess.h>
14543  
14544 @@ -391,7 +392,7 @@ static int check_syslog_permissions(int
14545                 return 0;
14546  
14547         if (syslog_action_restricted(type)) {
14548 -               if (capable(CAP_SYSLOG))
14549 +               if (vx_capable(CAP_SYSLOG, VXC_SYSLOG))
14550                         return 0;
14551                 /*
14552                  * For historical reasons, accept CAP_SYS_ADMIN too, with
14553 @@ -1140,12 +1141,9 @@ int do_syslog(int type, char __user *buf
14554         if (error)
14555                 return error;
14556  
14557 -       switch (type) {
14558 -       case SYSLOG_ACTION_CLOSE:       /* Close log */
14559 -               break;
14560 -       case SYSLOG_ACTION_OPEN:        /* Open log */
14561 -               break;
14562 -       case SYSLOG_ACTION_READ:        /* Read from log */
14563 +       if ((type == SYSLOG_ACTION_READ) ||
14564 +           (type == SYSLOG_ACTION_READ_ALL) ||
14565 +           (type == SYSLOG_ACTION_READ_CLEAR)) {
14566                 error = -EINVAL;
14567                 if (!buf || len < 0)
14568                         goto out;
14569 @@ -1156,6 +1154,16 @@ int do_syslog(int type, char __user *buf
14570                         error = -EFAULT;
14571                         goto out;
14572                 }
14573 +       }
14574 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
14575 +               return vx_do_syslog(type, buf, len);
14576 +
14577 +       switch (type) {
14578 +       case SYSLOG_ACTION_CLOSE:       /* Close log */
14579 +               break;
14580 +       case SYSLOG_ACTION_OPEN:        /* Open log */
14581 +               break;
14582 +       case SYSLOG_ACTION_READ:        /* Read from log */
14583                 error = wait_event_interruptible(log_wait,
14584                                                  syslog_seq != log_next_seq);
14585                 if (error)
14586 @@ -1168,16 +1176,6 @@ int do_syslog(int type, char __user *buf
14587                 /* FALL THRU */
14588         /* Read last kernel messages */
14589         case SYSLOG_ACTION_READ_ALL:
14590 -               error = -EINVAL;
14591 -               if (!buf || len < 0)
14592 -                       goto out;
14593 -               error = 0;
14594 -               if (!len)
14595 -                       goto out;
14596 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
14597 -                       error = -EFAULT;
14598 -                       goto out;
14599 -               }
14600                 error = syslog_print_all(buf, len, clear);
14601                 break;
14602         /* Clear ring buffer */
14603 diff -NurpP --minimal linux-3.10.33/kernel/ptrace.c linux-3.10.33-vs2.3.6.8/kernel/ptrace.c
14604 --- linux-3.10.33/kernel/ptrace.c       2014-03-12 13:16:02.000000000 +0000
14605 +++ linux-3.10.33-vs2.3.6.8/kernel/ptrace.c     2013-11-30 07:53:00.000000000 +0000
14606 @@ -23,6 +23,7 @@
14607  #include <linux/syscalls.h>
14608  #include <linux/uaccess.h>
14609  #include <linux/regset.h>
14610 +#include <linux/vs_context.h>
14611  #include <linux/hw_breakpoint.h>
14612  #include <linux/cn_proc.h>
14613  #include <linux/compat.h>
14614 @@ -264,6 +265,11 @@ ok:
14615         }
14616         rcu_read_unlock();
14617  
14618 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_WATCH_P|VS_IDENT))
14619 +               return -EPERM;
14620 +       if (!vx_check(task->xid, VS_IDENT) &&
14621 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
14622 +               return -EACCES;
14623         return security_ptrace_access_check(task, mode);
14624  }
14625  
14626 diff -NurpP --minimal linux-3.10.33/kernel/sched/core.c linux-3.10.33-vs2.3.6.8/kernel/sched/core.c
14627 --- linux-3.10.33/kernel/sched/core.c   2014-03-12 13:16:02.000000000 +0000
14628 +++ linux-3.10.33-vs2.3.6.8/kernel/sched/core.c 2014-01-22 19:00:34.000000000 +0000
14629 @@ -73,6 +73,8 @@
14630  #include <linux/init_task.h>
14631  #include <linux/binfmts.h>
14632  #include <linux/context_tracking.h>
14633 +#include <linux/vs_sched.h>
14634 +#include <linux/vs_cvirt.h>
14635  
14636  #include <asm/switch_to.h>
14637  #include <asm/tlb.h>
14638 @@ -2145,9 +2147,17 @@ EXPORT_SYMBOL(avenrun); /* should be rem
14639   */
14640  void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
14641  {
14642 -       loads[0] = (avenrun[0] + offset) << shift;
14643 -       loads[1] = (avenrun[1] + offset) << shift;
14644 -       loads[2] = (avenrun[2] + offset) << shift;
14645 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
14646 +               struct vx_info *vxi = current_vx_info();
14647 +
14648 +               loads[0] = (vxi->cvirt.load[0] + offset) << shift;
14649 +               loads[1] = (vxi->cvirt.load[1] + offset) << shift;
14650 +               loads[2] = (vxi->cvirt.load[2] + offset) << shift;
14651 +       } else {
14652 +               loads[0] = (avenrun[0] + offset) << shift;
14653 +               loads[1] = (avenrun[1] + offset) << shift;
14654 +               loads[2] = (avenrun[2] + offset) << shift;
14655 +       }
14656  }
14657  
14658  static long calc_load_fold_active(struct rq *this_rq)
14659 @@ -3750,7 +3760,7 @@ SYSCALL_DEFINE1(nice, int, increment)
14660                 nice = 19;
14661  
14662         if (increment < 0 && !can_nice(current, nice))
14663 -               return -EPERM;
14664 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
14665  
14666         retval = security_task_setnice(current, nice);
14667         if (retval)
14668 diff -NurpP --minimal linux-3.10.33/kernel/sched/cputime.c linux-3.10.33-vs2.3.6.8/kernel/sched/cputime.c
14669 --- linux-3.10.33/kernel/sched/cputime.c        2014-03-12 13:16:02.000000000 +0000
14670 +++ linux-3.10.33-vs2.3.6.8/kernel/sched/cputime.c      2013-11-13 17:17:16.000000000 +0000
14671 @@ -4,6 +4,7 @@
14672  #include <linux/kernel_stat.h>
14673  #include <linux/static_key.h>
14674  #include <linux/context_tracking.h>
14675 +#include <linux/vs_sched.h>
14676  #include "sched.h"
14677  
14678  
14679 @@ -135,14 +136,17 @@ static inline void task_group_account_fi
14680  void account_user_time(struct task_struct *p, cputime_t cputime,
14681                        cputime_t cputime_scaled)
14682  {
14683 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
14684 +       int nice = (TASK_NICE(p) > 0);
14685         int index;
14686  
14687         /* Add user time to process. */
14688         p->utime += cputime;
14689         p->utimescaled += cputime_scaled;
14690 +       vx_account_user(vxi, cputime, nice);
14691         account_group_user_time(p, cputime);
14692  
14693 -       index = (TASK_NICE(p) > 0) ? CPUTIME_NICE : CPUTIME_USER;
14694 +       index = (nice) ? CPUTIME_NICE : CPUTIME_USER;
14695  
14696         /* Add user time to cpustat. */
14697         task_group_account_field(p, index, (__force u64) cputime);
14698 @@ -189,9 +193,12 @@ static inline
14699  void __account_system_time(struct task_struct *p, cputime_t cputime,
14700                         cputime_t cputime_scaled, int index)
14701  {
14702 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
14703 +
14704         /* Add system time to process. */
14705         p->stime += cputime;
14706         p->stimescaled += cputime_scaled;
14707 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
14708         account_group_system_time(p, cputime);
14709  
14710         /* Add system time to cpustat. */
14711 diff -NurpP --minimal linux-3.10.33/kernel/sched/fair.c linux-3.10.33-vs2.3.6.8/kernel/sched/fair.c
14712 --- linux-3.10.33/kernel/sched/fair.c   2014-03-12 13:16:02.000000000 +0000
14713 +++ linux-3.10.33-vs2.3.6.8/kernel/sched/fair.c 2014-01-22 19:00:34.000000000 +0000
14714 @@ -29,6 +29,7 @@
14715  #include <linux/mempolicy.h>
14716  #include <linux/migrate.h>
14717  #include <linux/task_work.h>
14718 +#include <linux/vs_cvirt.h>
14719  
14720  #include <trace/events/sched.h>
14721  
14722 @@ -1743,6 +1744,8 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
14723                 __enqueue_entity(cfs_rq, se);
14724         se->on_rq = 1;
14725  
14726 +       if (entity_is_task(se))
14727 +               vx_activate_task(task_of(se));
14728         if (cfs_rq->nr_running == 1) {
14729                 list_add_leaf_cfs_rq(cfs_rq);
14730                 check_enqueue_throttle(cfs_rq);
14731 @@ -1824,6 +1827,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
14732         if (se != cfs_rq->curr)
14733                 __dequeue_entity(cfs_rq, se);
14734         se->on_rq = 0;
14735 +       if (entity_is_task(se))
14736 +               vx_deactivate_task(task_of(se));
14737         account_entity_dequeue(cfs_rq, se);
14738  
14739         /*
14740 diff -NurpP --minimal linux-3.10.33/kernel/signal.c linux-3.10.33-vs2.3.6.8/kernel/signal.c
14741 --- linux-3.10.33/kernel/signal.c       2013-07-14 17:01:35.000000000 +0000
14742 +++ linux-3.10.33-vs2.3.6.8/kernel/signal.c     2013-08-22 21:13:50.000000000 +0000
14743 @@ -33,6 +33,8 @@
14744  #include <linux/uprobes.h>
14745  #include <linux/compat.h>
14746  #include <linux/cn_proc.h>
14747 +#include <linux/vs_context.h>
14748 +#include <linux/vs_pid.h>
14749  #define CREATE_TRACE_POINTS
14750  #include <trace/events/signal.h>
14751  
14752 @@ -790,9 +792,18 @@ static int check_kill_permission(int sig
14753         struct pid *sid;
14754         int error;
14755  
14756 +       vxdprintk(VXD_CBIT(misc, 7),
14757 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
14758 +               sig, info, t, vx_task_xid(t), t->pid);
14759 +
14760         if (!valid_signal(sig))
14761                 return -EINVAL;
14762  
14763 +/*     FIXME: needed? if so, why?
14764 +       if ((info != SEND_SIG_NOINFO) &&
14765 +               (is_si_special(info) || !si_fromuser(info)))
14766 +               goto skip;      */
14767 +
14768         if (!si_fromuser(info))
14769                 return 0;
14770  
14771 @@ -816,6 +827,20 @@ static int check_kill_permission(int sig
14772                 }
14773         }
14774  
14775 +       error = -EPERM;
14776 +       if (t->pid == 1 && current->xid)
14777 +               return error;
14778 +
14779 +       error = -ESRCH;
14780 +       /* FIXME: we shouldn't return ESRCH ever, to avoid
14781 +                 loops, maybe ENOENT or EACCES? */
14782 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
14783 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
14784 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
14785 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
14786 +               return error;
14787 +       }
14788 +/* skip: */
14789         return security_task_kill(t, info, sig, 0);
14790  }
14791  
14792 @@ -1353,7 +1378,7 @@ int kill_pid_info(int sig, struct siginf
14793         rcu_read_lock();
14794  retry:
14795         p = pid_task(pid, PIDTYPE_PID);
14796 -       if (p) {
14797 +       if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
14798                 error = group_send_sig_info(sig, info, p);
14799                 if (unlikely(error == -ESRCH))
14800                         /*
14801 @@ -1401,7 +1426,7 @@ int kill_pid_info_as_cred(int sig, struc
14802  
14803         rcu_read_lock();
14804         p = pid_task(pid, PIDTYPE_PID);
14805 -       if (!p) {
14806 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
14807                 ret = -ESRCH;
14808                 goto out_unlock;
14809         }
14810 @@ -1453,8 +1478,10 @@ static int kill_something_info(int sig,
14811                 struct task_struct * p;
14812  
14813                 for_each_process(p) {
14814 -                       if (task_pid_vnr(p) > 1 &&
14815 -                                       !same_thread_group(p, current)) {
14816 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
14817 +                               task_pid_vnr(p) > 1 &&
14818 +                               !same_thread_group(p, current) &&
14819 +                               !vx_current_initpid(p->pid)) {
14820                                 int err = group_send_sig_info(sig, info, p);
14821                                 ++count;
14822                                 if (err != -EPERM)
14823 @@ -2308,6 +2335,11 @@ relock:
14824                                 !sig_kernel_only(signr))
14825                         continue;
14826  
14827 +               /* virtual init is protected against user signals */
14828 +               if ((info->si_code == SI_USER) &&
14829 +                       vx_current_initpid(current->pid))
14830 +                       continue;
14831 +
14832                 if (sig_kernel_stop(signr)) {
14833                         /*
14834                          * The default action is to stop all threads in
14835 diff -NurpP --minimal linux-3.10.33/kernel/softirq.c linux-3.10.33-vs2.3.6.8/kernel/softirq.c
14836 --- linux-3.10.33/kernel/softirq.c      2014-03-12 13:16:02.000000000 +0000
14837 +++ linux-3.10.33-vs2.3.6.8/kernel/softirq.c    2013-11-13 17:17:16.000000000 +0000
14838 @@ -25,6 +25,7 @@
14839  #include <linux/smp.h>
14840  #include <linux/smpboot.h>
14841  #include <linux/tick.h>
14842 +#include <linux/vs_context.h>
14843  
14844  #define CREATE_TRACE_POINTS
14845  #include <trace/events/irq.h>
14846 diff -NurpP --minimal linux-3.10.33/kernel/sys.c linux-3.10.33-vs2.3.6.8/kernel/sys.c
14847 --- linux-3.10.33/kernel/sys.c  2013-07-14 17:01:35.000000000 +0000
14848 +++ linux-3.10.33-vs2.3.6.8/kernel/sys.c        2013-08-22 20:30:00.000000000 +0000
14849 @@ -55,6 +55,7 @@
14850  #include <linux/cred.h>
14851  
14852  #include <linux/kmsg_dump.h>
14853 +#include <linux/vs_pid.h>
14854  /* Move somewhere else to avoid recompiling? */
14855  #include <generated/utsrelease.h>
14856  
14857 @@ -160,7 +161,10 @@ static int set_one_prio(struct task_stru
14858                 goto out;
14859         }
14860         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
14861 -               error = -EACCES;
14862 +               if (vx_flags(VXF_IGNEG_NICE, 0))
14863 +                       error = 0;
14864 +               else
14865 +                       error = -EACCES;
14866                 goto out;
14867         }
14868         no_nice = security_task_setnice(p, niceval);
14869 @@ -211,6 +215,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
14870                         else
14871                                 pgrp = task_pgrp(current);
14872                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
14873 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
14874 +                                       continue;
14875                                 error = set_one_prio(p, niceval, error);
14876                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
14877                         break;
14878 @@ -276,6 +282,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
14879                         else
14880                                 pgrp = task_pgrp(current);
14881                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
14882 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
14883 +                                       continue;
14884                                 niceval = 20 - task_nice(p);
14885                                 if (niceval > retval)
14886                                         retval = niceval;
14887 @@ -452,6 +460,8 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
14888  
14889  static DEFINE_MUTEX(reboot_mutex);
14890  
14891 +long vs_reboot(unsigned int, void __user *);
14892 +
14893  /*
14894   * Reboot system call: for obvious reasons only root may call it,
14895   * and even root needs to set up some magic numbers in the registers
14896 @@ -494,6 +504,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
14897         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
14898                 cmd = LINUX_REBOOT_CMD_HALT;
14899  
14900 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
14901 +               return vs_reboot(cmd, arg);
14902 +
14903         mutex_lock(&reboot_mutex);
14904         switch (cmd) {
14905         case LINUX_REBOOT_CMD_RESTART:
14906 @@ -1462,7 +1475,8 @@ SYSCALL_DEFINE2(sethostname, char __user
14907         int errno;
14908         char tmp[__NEW_UTS_LEN];
14909  
14910 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
14911 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
14912 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
14913                 return -EPERM;
14914  
14915         if (len < 0 || len > __NEW_UTS_LEN)
14916 @@ -1513,7 +1527,8 @@ SYSCALL_DEFINE2(setdomainname, char __us
14917         int errno;
14918         char tmp[__NEW_UTS_LEN];
14919  
14920 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
14921 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
14922 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
14923                 return -EPERM;
14924         if (len < 0 || len > __NEW_UTS_LEN)
14925                 return -EINVAL;
14926 @@ -1632,7 +1647,7 @@ int do_prlimit(struct task_struct *tsk,
14927                 /* Keep the capable check against init_user_ns until
14928                    cgroups can contain all limits */
14929                 if (new_rlim->rlim_max > rlim->rlim_max &&
14930 -                               !capable(CAP_SYS_RESOURCE))
14931 +                       !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
14932                         retval = -EPERM;
14933                 if (!retval)
14934                         retval = security_task_setrlimit(tsk->group_leader,
14935 @@ -1685,7 +1700,8 @@ static int check_prlimit_permission(stru
14936             gid_eq(cred->gid, tcred->sgid) &&
14937             gid_eq(cred->gid, tcred->gid))
14938                 return 0;
14939 -       if (ns_capable(tcred->user_ns, CAP_SYS_RESOURCE))
14940 +       if (vx_ns_capable(tcred->user_ns,
14941 +               CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
14942                 return 0;
14943  
14944         return -EPERM;
14945 diff -NurpP --minimal linux-3.10.33/kernel/sysctl.c linux-3.10.33-vs2.3.6.8/kernel/sysctl.c
14946 --- linux-3.10.33/kernel/sysctl.c       2013-07-14 17:01:35.000000000 +0000
14947 +++ linux-3.10.33-vs2.3.6.8/kernel/sysctl.c     2013-08-22 20:30:00.000000000 +0000
14948 @@ -83,6 +83,7 @@
14949  #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
14950  #include <linux/lockdep.h>
14951  #endif
14952 +extern char vshelper_path[];
14953  #ifdef CONFIG_CHR_DEV_SG
14954  #include <scsi/sg.h>
14955  #endif
14956 @@ -628,6 +629,13 @@ static struct ctl_table kern_table[] = {
14957                 .mode           = 0644,
14958                 .proc_handler   = proc_dostring,
14959         },
14960 +       {
14961 +               .procname       = "vshelper",
14962 +               .data           = &vshelper_path,
14963 +               .maxlen         = 256,
14964 +               .mode           = 0644,
14965 +               .proc_handler   = &proc_dostring,
14966 +       },
14967  
14968  #ifdef CONFIG_CHR_DEV_SG
14969         {
14970 diff -NurpP --minimal linux-3.10.33/kernel/sysctl_binary.c linux-3.10.33-vs2.3.6.8/kernel/sysctl_binary.c
14971 --- linux-3.10.33/kernel/sysctl_binary.c        2013-07-14 17:01:35.000000000 +0000
14972 +++ linux-3.10.33-vs2.3.6.8/kernel/sysctl_binary.c      2013-08-22 20:30:00.000000000 +0000
14973 @@ -74,6 +74,7 @@ static const struct bin_table bin_kern_t
14974  
14975         { CTL_INT,      KERN_PANIC,                     "panic" },
14976         { CTL_INT,      KERN_REALROOTDEV,               "real-root-dev" },
14977 +       { CTL_STR,      KERN_VSHELPER,                  "vshelper" },
14978  
14979         { CTL_STR,      KERN_SPARC_REBOOT,              "reboot-cmd" },
14980         { CTL_INT,      KERN_CTLALTDEL,                 "ctrl-alt-del" },
14981 diff -NurpP --minimal linux-3.10.33/kernel/time/timekeeping.c linux-3.10.33-vs2.3.6.8/kernel/time/timekeeping.c
14982 --- linux-3.10.33/kernel/time/timekeeping.c     2014-03-12 13:16:02.000000000 +0000
14983 +++ linux-3.10.33-vs2.3.6.8/kernel/time/timekeeping.c   2014-03-12 13:18:23.000000000 +0000
14984 @@ -22,6 +22,7 @@
14985  #include <linux/tick.h>
14986  #include <linux/stop_machine.h>
14987  #include <linux/pvclock_gtod.h>
14988 +#include <linux/vs_time.h>
14989  
14990  #include "tick-internal.h"
14991  #include "ntp_internal.h"
14992 @@ -694,6 +695,7 @@ void getrawmonotonic(struct timespec *ts
14993         } while (read_seqcount_retry(&timekeeper_seq, seq));
14994  
14995         timespec_add_ns(ts, nsecs);
14996 +       vx_adjust_timespec(ts);
14997  }
14998  EXPORT_SYMBOL(getrawmonotonic);
14999  
15000 diff -NurpP --minimal linux-3.10.33/kernel/time.c linux-3.10.33-vs2.3.6.8/kernel/time.c
15001 --- linux-3.10.33/kernel/time.c 2013-07-14 17:01:35.000000000 +0000
15002 +++ linux-3.10.33-vs2.3.6.8/kernel/time.c       2013-08-22 20:30:00.000000000 +0000
15003 @@ -37,6 +37,7 @@
15004  #include <linux/fs.h>
15005  #include <linux/math64.h>
15006  #include <linux/ptrace.h>
15007 +#include <linux/vs_time.h>
15008  
15009  #include <asm/uaccess.h>
15010  #include <asm/unistd.h>
15011 @@ -92,7 +93,7 @@ SYSCALL_DEFINE1(stime, time_t __user *,
15012         if (err)
15013                 return err;
15014  
15015 -       do_settimeofday(&tv);
15016 +       vx_settimeofday(&tv);
15017         return 0;
15018  }
15019  
15020 @@ -181,7 +182,7 @@ int do_sys_settimeofday(const struct tim
15021                 }
15022         }
15023         if (tv)
15024 -               return do_settimeofday(tv);
15025 +               return vx_settimeofday(tv);
15026         return 0;
15027  }
15028  
15029 diff -NurpP --minimal linux-3.10.33/kernel/timer.c linux-3.10.33-vs2.3.6.8/kernel/timer.c
15030 --- linux-3.10.33/kernel/timer.c        2014-03-12 13:16:02.000000000 +0000
15031 +++ linux-3.10.33-vs2.3.6.8/kernel/timer.c      2013-11-13 17:17:16.000000000 +0000
15032 @@ -42,6 +42,10 @@
15033  #include <linux/sched/sysctl.h>
15034  #include <linux/slab.h>
15035  #include <linux/compat.h>
15036 +#include <linux/vs_base.h>
15037 +#include <linux/vs_cvirt.h>
15038 +#include <linux/vs_pid.h>
15039 +#include <linux/vserver/sched.h>
15040  
15041  #include <asm/uaccess.h>
15042  #include <asm/unistd.h>
15043 diff -NurpP --minimal linux-3.10.33/kernel/user_namespace.c linux-3.10.33-vs2.3.6.8/kernel/user_namespace.c
15044 --- linux-3.10.33/kernel/user_namespace.c       2014-03-12 13:16:02.000000000 +0000
15045 +++ linux-3.10.33-vs2.3.6.8/kernel/user_namespace.c     2013-11-13 17:17:16.000000000 +0000
15046 @@ -22,6 +22,7 @@
15047  #include <linux/ctype.h>
15048  #include <linux/projid.h>
15049  #include <linux/fs_struct.h>
15050 +#include <linux/vserver/global.h>
15051  
15052  static struct kmem_cache *user_ns_cachep __read_mostly;
15053  
15054 @@ -94,6 +95,7 @@ int create_user_ns(struct cred *new)
15055  
15056         atomic_set(&ns->count, 1);
15057         /* Leave the new->user_ns reference with the new user namespace. */
15058 +       atomic_inc(&vs_global_user_ns);
15059         ns->parent = parent_ns;
15060         ns->level = parent_ns->level + 1;
15061         ns->owner = owner;
15062 @@ -844,6 +846,8 @@ static void *userns_get(struct task_stru
15063  
15064  static void userns_put(void *ns)
15065  {
15066 +       /* FIXME: maybe move into destroyer? */
15067 +       atomic_dec(&vs_global_user_ns);
15068         put_user_ns(ns);
15069  }
15070  
15071 diff -NurpP --minimal linux-3.10.33/kernel/utsname.c linux-3.10.33-vs2.3.6.8/kernel/utsname.c
15072 --- linux-3.10.33/kernel/utsname.c      2013-07-14 17:01:35.000000000 +0000
15073 +++ linux-3.10.33-vs2.3.6.8/kernel/utsname.c    2013-08-22 21:03:08.000000000 +0000
15074 @@ -16,14 +16,17 @@
15075  #include <linux/slab.h>
15076  #include <linux/user_namespace.h>
15077  #include <linux/proc_ns.h>
15078 +#include <linux/vserver/global.h>
15079  
15080  static struct uts_namespace *create_uts_ns(void)
15081  {
15082         struct uts_namespace *uts_ns;
15083  
15084         uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
15085 -       if (uts_ns)
15086 -               kref_init(&uts_ns->kref);
15087 +       if (uts_ns) {
15088 +               kref_init(&uts_ns->kref);
15089 +               atomic_inc(&vs_global_uts_ns);
15090 +       }
15091         return uts_ns;
15092  }
15093  
15094 @@ -85,6 +88,7 @@ void free_uts_ns(struct kref *kref)
15095         ns = container_of(kref, struct uts_namespace, kref);
15096         put_user_ns(ns->user_ns);
15097         proc_free_inum(ns->proc_inum);
15098 +       atomic_dec(&vs_global_uts_ns);
15099         kfree(ns);
15100  }
15101  
15102 diff -NurpP --minimal linux-3.10.33/kernel/vserver/Kconfig linux-3.10.33-vs2.3.6.8/kernel/vserver/Kconfig
15103 --- linux-3.10.33/kernel/vserver/Kconfig        1970-01-01 00:00:00.000000000 +0000
15104 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/Kconfig      2013-11-14 04:29:47.000000000 +0000
15105 @@ -0,0 +1,230 @@
15106 +#
15107 +# Linux VServer configuration
15108 +#
15109 +
15110 +menu "Linux VServer"
15111 +
15112 +config VSERVER_AUTO_LBACK
15113 +       bool    "Automatically Assign Loopback IP"
15114 +       default y
15115 +       help
15116 +         Automatically assign a guest specific loopback
15117 +         IP and add it to the kernel network stack on
15118 +         startup.
15119 +
15120 +config VSERVER_AUTO_SINGLE
15121 +       bool    "Automatic Single IP Special Casing"
15122 +       default n
15123 +       help
15124 +         This allows network contexts with a single IP to
15125 +         automatically remap 0.0.0.0 bindings to that IP,
15126 +         avoiding further network checks and improving
15127 +         performance.
15128 +
15129 +         (note: such guests do not allow to change the ip
15130 +          on the fly and do not show loopback addresses)
15131 +
15132 +config VSERVER_COWBL
15133 +       bool    "Enable COW Immutable Link Breaking"
15134 +       default y
15135 +       help
15136 +         This enables the COW (Copy-On-Write) link break code.
15137 +         It allows you to treat unified files like normal files
15138 +         when writing to them (which will implicitely break the
15139 +         link and create a copy of the unified file)
15140 +
15141 +config VSERVER_VTIME
15142 +       bool    "Enable Virtualized Guest Time (EXPERIMENTAL)"
15143 +       default n
15144 +       help
15145 +         This enables per guest time offsets to allow for
15146 +         adjusting the system clock individually per guest.
15147 +         this adds some overhead to the time functions and
15148 +         therefore should not be enabled without good reason.
15149 +
15150 +config VSERVER_DEVICE
15151 +       bool    "Enable Guest Device Mapping (EXPERIMENTAL)"
15152 +       default n
15153 +       help
15154 +         This enables generic device remapping.
15155 +
15156 +config VSERVER_PROC_SECURE
15157 +       bool    "Enable Proc Security"
15158 +       depends on PROC_FS
15159 +       default y
15160 +       help
15161 +         This configures ProcFS security to initially hide
15162 +         non-process entries for all contexts except the main and
15163 +         spectator context (i.e. for all guests), which is a secure
15164 +         default.
15165 +
15166 +         (note: on 1.2x the entries were visible by default)
15167 +
15168 +choice
15169 +       prompt  "Persistent Inode Tagging"
15170 +       default TAGGING_ID24
15171 +       help
15172 +         This adds persistent context information to filesystems
15173 +         mounted with the tagxid option. Tagging is a requirement
15174 +         for per-context disk limits and per-context quota.
15175 +
15176 +
15177 +config TAGGING_NONE
15178 +       bool    "Disabled"
15179 +       help
15180 +         do not store per-context information in inodes.
15181 +
15182 +config TAGGING_UID16
15183 +       bool    "UID16/GID32"
15184 +       help
15185 +         reduces UID to 16 bit, but leaves GID at 32 bit.
15186 +
15187 +config TAGGING_GID16
15188 +       bool    "UID32/GID16"
15189 +       help
15190 +         reduces GID to 16 bit, but leaves UID at 32 bit.
15191 +
15192 +config TAGGING_ID24
15193 +       bool    "UID24/GID24"
15194 +       help
15195 +         uses the upper 8bit from UID and GID for XID tagging
15196 +         which leaves 24bit for UID/GID each, which should be
15197 +         more than sufficient for normal use.
15198 +
15199 +config TAGGING_INTERN
15200 +       bool    "UID32/GID32"
15201 +       help
15202 +         this uses otherwise reserved inode fields in the on
15203 +         disk representation, which limits the use to a few
15204 +         filesystems (currently ext2 and ext3)
15205 +
15206 +endchoice
15207 +
15208 +config TAG_NFSD
15209 +       bool    "Tag NFSD User Auth and Files"
15210 +       default n
15211 +       help
15212 +         Enable this if you do want the in-kernel NFS
15213 +         Server to use the tagging specified above.
15214 +         (will require patched clients too)
15215 +
15216 +config VSERVER_PRIVACY
15217 +       bool    "Honor Privacy Aspects of Guests"
15218 +       default n
15219 +       help
15220 +         When enabled, most context checks will disallow
15221 +         access to structures assigned to a specific context,
15222 +         like ptys or loop devices.
15223 +
15224 +config VSERVER_CONTEXTS
15225 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
15226 +       range 1 65533
15227 +       default "768"   if 64BIT
15228 +       default "256"
15229 +       help
15230 +         This setting will optimize certain data structures
15231 +         and memory allocations according to the expected
15232 +         maximum.
15233 +
15234 +         note: this is not a strict upper limit.
15235 +
15236 +config VSERVER_WARN
15237 +       bool    "VServer Warnings"
15238 +       default y
15239 +       help
15240 +         This enables various runtime warnings, which will
15241 +         notify about potential manipulation attempts or
15242 +         resource shortage. It is generally considered to
15243 +         be a good idea to have that enabled.
15244 +
15245 +config VSERVER_WARN_DEVPTS
15246 +       bool    "VServer DevPTS Warnings"
15247 +       depends on VSERVER_WARN
15248 +       default y
15249 +       help
15250 +         This enables DevPTS related warnings, issued when a
15251 +         process inside a context tries to lookup or access
15252 +         a dynamic pts from the host or a different context.
15253 +
15254 +config VSERVER_DEBUG
15255 +       bool    "VServer Debugging Code"
15256 +       default n
15257 +       help
15258 +         Set this to yes if you want to be able to activate
15259 +         debugging output at runtime. It adds a very small
15260 +         overhead to all vserver related functions and
15261 +         increases the kernel size by about 20k.
15262 +
15263 +config VSERVER_HISTORY
15264 +       bool    "VServer History Tracing"
15265 +       depends on VSERVER_DEBUG
15266 +       default n
15267 +       help
15268 +         Set this to yes if you want to record the history of
15269 +         linux-vserver activities, so they can be replayed in
15270 +         the event of a kernel panic or oops.
15271 +
15272 +config VSERVER_HISTORY_SIZE
15273 +       int     "Per-CPU History Size (32-65536)"
15274 +       depends on VSERVER_HISTORY
15275 +       range 32 65536
15276 +       default 64
15277 +       help
15278 +         This allows you to specify the number of entries in
15279 +         the per-CPU history buffer.
15280 +
15281 +config VSERVER_EXTRA_MNT_CHECK
15282 +       bool    "Extra Checks for Reachability"
15283 +       default n
15284 +       help
15285 +         Set this to yes if you want to do extra checks for
15286 +         vfsmount reachability in the proc filesystem code.
15287 +         This shouldn't be required on any setup utilizing
15288 +         mnt namespaces.
15289 +
15290 +choice
15291 +       prompt  "Quotes used in debug and warn messages"
15292 +       default QUOTES_ISO8859
15293 +
15294 +config QUOTES_ISO8859
15295 +       bool    "Extended ASCII (ISO 8859) angle quotes"
15296 +       help
15297 +         This uses the extended ASCII characters \xbb
15298 +         and \xab for quoting file and process names.
15299 +
15300 +config QUOTES_UTF8
15301 +       bool    "UTF-8 angle quotes"
15302 +       help
15303 +         This uses the the UTF-8 sequences for angle
15304 +         quotes to quote file and process names.
15305 +
15306 +config QUOTES_ASCII
15307 +       bool    "ASCII single quotes"
15308 +       help
15309 +         This uses the ASCII single quote character
15310 +         (\x27) to quote file and process names.
15311 +
15312 +endchoice
15313 +
15314 +endmenu
15315 +
15316 +
15317 +config VSERVER
15318 +       bool
15319 +       default y
15320 +       select NAMESPACES
15321 +       select UTS_NS
15322 +       select IPC_NS
15323 +#      select USER_NS
15324 +       select SYSVIPC
15325 +
15326 +config VSERVER_SECURITY
15327 +       bool
15328 +       depends on SECURITY
15329 +       default y
15330 +       select SECURITY_CAPABILITIES
15331 +
15332 +config VSERVER_DISABLED
15333 +       bool
15334 +       default n
15335 +
15336 diff -NurpP --minimal linux-3.10.33/kernel/vserver/Makefile linux-3.10.33-vs2.3.6.8/kernel/vserver/Makefile
15337 --- linux-3.10.33/kernel/vserver/Makefile       1970-01-01 00:00:00.000000000 +0000
15338 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/Makefile     2013-08-22 20:30:00.000000000 +0000
15339 @@ -0,0 +1,18 @@
15340 +#
15341 +# Makefile for the Linux vserver routines.
15342 +#
15343 +
15344 +
15345 +obj-y          += vserver.o
15346 +
15347 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
15348 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
15349 +                  dlimit.o tag.o
15350 +
15351 +vserver-$(CONFIG_INET) += inet.o
15352 +vserver-$(CONFIG_PROC_FS) += proc.o
15353 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
15354 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
15355 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
15356 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
15357 +
15358 diff -NurpP --minimal linux-3.10.33/kernel/vserver/cacct.c linux-3.10.33-vs2.3.6.8/kernel/vserver/cacct.c
15359 --- linux-3.10.33/kernel/vserver/cacct.c        1970-01-01 00:00:00.000000000 +0000
15360 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/cacct.c      2013-08-22 20:30:00.000000000 +0000
15361 @@ -0,0 +1,42 @@
15362 +/*
15363 + *  linux/kernel/vserver/cacct.c
15364 + *
15365 + *  Virtual Server: Context Accounting
15366 + *
15367 + *  Copyright (C) 2006-2007 Herbert Pötzl
15368 + *
15369 + *  V0.01  added accounting stats
15370 + *
15371 + */
15372 +
15373 +#include <linux/types.h>
15374 +#include <linux/vs_context.h>
15375 +#include <linux/vserver/cacct_cmd.h>
15376 +#include <linux/vserver/cacct_int.h>
15377 +
15378 +#include <asm/errno.h>
15379 +#include <asm/uaccess.h>
15380 +
15381 +
15382 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
15383 +{
15384 +       struct vcmd_sock_stat_v0 vc_data;
15385 +       int j, field;
15386 +
15387 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15388 +               return -EFAULT;
15389 +
15390 +       field = vc_data.field;
15391 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
15392 +               return -EINVAL;
15393 +
15394 +       for (j = 0; j < 3; j++) {
15395 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
15396 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
15397 +       }
15398 +
15399 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15400 +               return -EFAULT;
15401 +       return 0;
15402 +}
15403 +
15404 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
15405 --- linux-3.10.33/kernel/vserver/cacct_init.h   1970-01-01 00:00:00.000000000 +0000
15406 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/cacct_init.h 2013-08-22 20:30:00.000000000 +0000
15407 @@ -0,0 +1,25 @@
15408 +
15409 +
15410 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
15411 +{
15412 +       int i, j;
15413 +
15414 +
15415 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
15416 +               for (j = 0; j < 3; j++) {
15417 +                       atomic_long_set(&cacct->sock[i][j].count, 0);
15418 +                       atomic_long_set(&cacct->sock[i][j].total, 0);
15419 +               }
15420 +       }
15421 +       for (i = 0; i < 8; i++)
15422 +               atomic_set(&cacct->slab[i], 0);
15423 +       for (i = 0; i < 5; i++)
15424 +               for (j = 0; j < 4; j++)
15425 +                       atomic_set(&cacct->page[i][j], 0);
15426 +}
15427 +
15428 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
15429 +{
15430 +       return;
15431 +}
15432 +
15433 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
15434 --- linux-3.10.33/kernel/vserver/cacct_proc.h   1970-01-01 00:00:00.000000000 +0000
15435 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/cacct_proc.h 2013-08-22 20:30:00.000000000 +0000
15436 @@ -0,0 +1,53 @@
15437 +#ifndef _VX_CACCT_PROC_H
15438 +#define _VX_CACCT_PROC_H
15439 +
15440 +#include <linux/vserver/cacct_int.h>
15441 +
15442 +
15443 +#define VX_SOCKA_TOP   \
15444 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
15445 +
15446 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
15447 +{
15448 +       int i, j, length = 0;
15449 +       static char *type[VXA_SOCK_SIZE] = {
15450 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
15451 +       };
15452 +
15453 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
15454 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
15455 +               length += sprintf(buffer + length, "%s:", type[i]);
15456 +               for (j = 0; j < 3; j++) {
15457 +                       length += sprintf(buffer + length,
15458 +                               "\t%10lu/%-10lu",
15459 +                               vx_sock_count(cacct, i, j),
15460 +                               vx_sock_total(cacct, i, j));
15461 +               }
15462 +               buffer[length++] = '\n';
15463 +       }
15464 +
15465 +       length += sprintf(buffer + length, "\n");
15466 +       length += sprintf(buffer + length,
15467 +               "slab:\t %8u %8u %8u %8u\n",
15468 +               atomic_read(&cacct->slab[1]),
15469 +               atomic_read(&cacct->slab[4]),
15470 +               atomic_read(&cacct->slab[0]),
15471 +               atomic_read(&cacct->slab[2]));
15472 +
15473 +       length += sprintf(buffer + length, "\n");
15474 +       for (i = 0; i < 5; i++) {
15475 +               length += sprintf(buffer + length,
15476 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
15477 +                       atomic_read(&cacct->page[i][0]),
15478 +                       atomic_read(&cacct->page[i][1]),
15479 +                       atomic_read(&cacct->page[i][2]),
15480 +                       atomic_read(&cacct->page[i][3]),
15481 +                       atomic_read(&cacct->page[i][4]),
15482 +                       atomic_read(&cacct->page[i][5]),
15483 +                       atomic_read(&cacct->page[i][6]),
15484 +                       atomic_read(&cacct->page[i][7]));
15485 +       }
15486 +       return length;
15487 +}
15488 +
15489 +#endif /* _VX_CACCT_PROC_H */
15490 diff -NurpP --minimal linux-3.10.33/kernel/vserver/context.c linux-3.10.33-vs2.3.6.8/kernel/vserver/context.c
15491 --- linux-3.10.33/kernel/vserver/context.c      1970-01-01 00:00:00.000000000 +0000
15492 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/context.c    2013-08-22 20:30:00.000000000 +0000
15493 @@ -0,0 +1,1119 @@
15494 +/*
15495 + *  linux/kernel/vserver/context.c
15496 + *
15497 + *  Virtual Server: Context Support
15498 + *
15499 + *  Copyright (C) 2003-2011  Herbert Pötzl
15500 + *
15501 + *  V0.01  context helper
15502 + *  V0.02  vx_ctx_kill syscall command
15503 + *  V0.03  replaced context_info calls
15504 + *  V0.04  redesign of struct (de)alloc
15505 + *  V0.05  rlimit basic implementation
15506 + *  V0.06  task_xid and info commands
15507 + *  V0.07  context flags and caps
15508 + *  V0.08  switch to RCU based hash
15509 + *  V0.09  revert to non RCU for now
15510 + *  V0.10  and back to working RCU hash
15511 + *  V0.11  and back to locking again
15512 + *  V0.12  referenced context store
15513 + *  V0.13  separate per cpu data
15514 + *  V0.14  changed vcmds to vxi arg
15515 + *  V0.15  added context stat
15516 + *  V0.16  have __create claim() the vxi
15517 + *  V0.17  removed older and legacy stuff
15518 + *  V0.18  added user credentials
15519 + *  V0.19  added warn mask
15520 + *
15521 + */
15522 +
15523 +#include <linux/slab.h>
15524 +#include <linux/types.h>
15525 +#include <linux/security.h>
15526 +#include <linux/pid_namespace.h>
15527 +#include <linux/capability.h>
15528 +
15529 +#include <linux/vserver/context.h>
15530 +#include <linux/vserver/network.h>
15531 +#include <linux/vserver/debug.h>
15532 +#include <linux/vserver/limit.h>
15533 +#include <linux/vserver/limit_int.h>
15534 +#include <linux/vserver/space.h>
15535 +#include <linux/init_task.h>
15536 +#include <linux/fs_struct.h>
15537 +#include <linux/cred.h>
15538 +
15539 +#include <linux/vs_context.h>
15540 +#include <linux/vs_limit.h>
15541 +#include <linux/vs_pid.h>
15542 +#include <linux/vserver/context_cmd.h>
15543 +
15544 +#include "cvirt_init.h"
15545 +#include "cacct_init.h"
15546 +#include "limit_init.h"
15547 +#include "sched_init.h"
15548 +
15549 +
15550 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
15551 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
15552 +
15553 +
15554 +/*     now inactive context structures */
15555 +
15556 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
15557 +
15558 +static DEFINE_SPINLOCK(vx_info_inactive_lock);
15559 +
15560 +
15561 +/*     __alloc_vx_info()
15562 +
15563 +       * allocate an initialized vx_info struct
15564 +       * doesn't make it visible (hash)                        */
15565 +
15566 +static struct vx_info *__alloc_vx_info(vxid_t xid)
15567 +{
15568 +       struct vx_info *new = NULL;
15569 +       int cpu, index;
15570 +
15571 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
15572 +
15573 +       /* would this benefit from a slab cache? */
15574 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
15575 +       if (!new)
15576 +               return 0;
15577 +
15578 +       memset(new, 0, sizeof(struct vx_info));
15579 +#ifdef CONFIG_SMP
15580 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
15581 +       if (!new->ptr_pc)
15582 +               goto error;
15583 +#endif
15584 +       new->vx_id = xid;
15585 +       INIT_HLIST_NODE(&new->vx_hlist);
15586 +       atomic_set(&new->vx_usecnt, 0);
15587 +       atomic_set(&new->vx_tasks, 0);
15588 +       new->vx_parent = NULL;
15589 +       new->vx_state = 0;
15590 +       init_waitqueue_head(&new->vx_wait);
15591 +
15592 +       /* prepare reaper */
15593 +       get_task_struct(init_pid_ns.child_reaper);
15594 +       new->vx_reaper = init_pid_ns.child_reaper;
15595 +       new->vx_badness_bias = 0;
15596 +
15597 +       /* rest of init goes here */
15598 +       vx_info_init_limit(&new->limit);
15599 +       vx_info_init_sched(&new->sched);
15600 +       vx_info_init_cvirt(&new->cvirt);
15601 +       vx_info_init_cacct(&new->cacct);
15602 +
15603 +       /* per cpu data structures */
15604 +       for_each_possible_cpu(cpu) {
15605 +               vx_info_init_sched_pc(
15606 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
15607 +               vx_info_init_cvirt_pc(
15608 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
15609 +       }
15610 +
15611 +       new->vx_flags = VXF_INIT_SET;
15612 +       new->vx_bcaps = CAP_FULL_SET;   // maybe ~CAP_SETPCAP
15613 +       new->vx_ccaps = 0;
15614 +       new->vx_umask = 0;
15615 +       new->vx_wmask = 0;
15616 +
15617 +       new->reboot_cmd = 0;
15618 +       new->exit_code = 0;
15619 +
15620 +       // preconfig spaces
15621 +       for (index = 0; index < VX_SPACES; index++) {
15622 +               struct _vx_space *space = &new->space[index];
15623 +
15624 +               // filesystem
15625 +               spin_lock(&init_fs.lock);
15626 +               init_fs.users++;
15627 +               spin_unlock(&init_fs.lock);
15628 +               space->vx_fs = &init_fs;
15629 +
15630 +               /* FIXME: do we want defaults? */
15631 +               // space->vx_real_cred = 0;
15632 +               // space->vx_cred = 0;
15633 +       }
15634 +
15635 +
15636 +       vxdprintk(VXD_CBIT(xid, 0),
15637 +               "alloc_vx_info(%d) = %p", xid, new);
15638 +       vxh_alloc_vx_info(new);
15639 +       atomic_inc(&vx_global_ctotal);
15640 +       return new;
15641 +#ifdef CONFIG_SMP
15642 +error:
15643 +       kfree(new);
15644 +       return 0;
15645 +#endif
15646 +}
15647 +
15648 +/*     __dealloc_vx_info()
15649 +
15650 +       * final disposal of vx_info                             */
15651 +
15652 +static void __dealloc_vx_info(struct vx_info *vxi)
15653 +{
15654 +#ifdef CONFIG_VSERVER_WARN
15655 +       struct vx_info_save vxis;
15656 +       int cpu;
15657 +#endif
15658 +       vxdprintk(VXD_CBIT(xid, 0),
15659 +               "dealloc_vx_info(%p)", vxi);
15660 +       vxh_dealloc_vx_info(vxi);
15661 +
15662 +#ifdef CONFIG_VSERVER_WARN
15663 +       enter_vx_info(vxi, &vxis);
15664 +       vx_info_exit_limit(&vxi->limit);
15665 +       vx_info_exit_sched(&vxi->sched);
15666 +       vx_info_exit_cvirt(&vxi->cvirt);
15667 +       vx_info_exit_cacct(&vxi->cacct);
15668 +
15669 +       for_each_possible_cpu(cpu) {
15670 +               vx_info_exit_sched_pc(
15671 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
15672 +               vx_info_exit_cvirt_pc(
15673 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
15674 +       }
15675 +       leave_vx_info(&vxis);
15676 +#endif
15677 +
15678 +       vxi->vx_id = -1;
15679 +       vxi->vx_state |= VXS_RELEASED;
15680 +
15681 +#ifdef CONFIG_SMP
15682 +       free_percpu(vxi->ptr_pc);
15683 +#endif
15684 +       kfree(vxi);
15685 +       atomic_dec(&vx_global_ctotal);
15686 +}
15687 +
15688 +static void __shutdown_vx_info(struct vx_info *vxi)
15689 +{
15690 +       struct nsproxy *nsproxy;
15691 +       struct fs_struct *fs;
15692 +       struct cred *cred;
15693 +       int index, kill;
15694 +
15695 +       might_sleep();
15696 +
15697 +       vxi->vx_state |= VXS_SHUTDOWN;
15698 +       vs_state_change(vxi, VSC_SHUTDOWN);
15699 +
15700 +       for (index = 0; index < VX_SPACES; index++) {
15701 +               struct _vx_space *space = &vxi->space[index];
15702 +
15703 +               nsproxy = xchg(&space->vx_nsproxy, NULL);
15704 +               if (nsproxy)
15705 +                       put_nsproxy(nsproxy);
15706 +
15707 +               fs = xchg(&space->vx_fs, NULL);
15708 +               spin_lock(&fs->lock);
15709 +               kill = !--fs->users;
15710 +               spin_unlock(&fs->lock);
15711 +               if (kill)
15712 +                       free_fs_struct(fs);
15713 +
15714 +               cred = (struct cred *)xchg(&space->vx_cred, NULL);
15715 +               if (cred)
15716 +                       abort_creds(cred);
15717 +       }
15718 +}
15719 +
15720 +/* exported stuff */
15721 +
15722 +void free_vx_info(struct vx_info *vxi)
15723 +{
15724 +       unsigned long flags;
15725 +       unsigned index;
15726 +
15727 +       /* check for reference counts first */
15728 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
15729 +       BUG_ON(atomic_read(&vxi->vx_tasks));
15730 +
15731 +       /* context must not be hashed */
15732 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
15733 +
15734 +       /* context shutdown is mandatory */
15735 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
15736 +
15737 +       /* spaces check */
15738 +       for (index = 0; index < VX_SPACES; index++) {
15739 +               struct _vx_space *space = &vxi->space[index];
15740 +
15741 +               BUG_ON(space->vx_nsproxy);
15742 +               BUG_ON(space->vx_fs);
15743 +               // BUG_ON(space->vx_real_cred);
15744 +               // BUG_ON(space->vx_cred);
15745 +       }
15746 +
15747 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
15748 +       hlist_del(&vxi->vx_hlist);
15749 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
15750 +
15751 +       __dealloc_vx_info(vxi);
15752 +}
15753 +
15754 +
15755 +/*     hash table for vx_info hash */
15756 +
15757 +#define VX_HASH_SIZE   13
15758 +
15759 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
15760 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
15761 +
15762 +static DEFINE_SPINLOCK(vx_info_hash_lock);
15763 +
15764 +
15765 +static inline unsigned int __hashval(vxid_t xid)
15766 +{
15767 +       return (xid % VX_HASH_SIZE);
15768 +}
15769 +
15770 +
15771 +
15772 +/*     __hash_vx_info()
15773 +
15774 +       * add the vxi to the global hash table
15775 +       * requires the hash_lock to be held                     */
15776 +
15777 +static inline void __hash_vx_info(struct vx_info *vxi)
15778 +{
15779 +       struct hlist_head *head;
15780 +
15781 +       vxd_assert_lock(&vx_info_hash_lock);
15782 +       vxdprintk(VXD_CBIT(xid, 4),
15783 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
15784 +       vxh_hash_vx_info(vxi);
15785 +
15786 +       /* context must not be hashed */
15787 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
15788 +
15789 +       vxi->vx_state |= VXS_HASHED;
15790 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
15791 +       hlist_add_head(&vxi->vx_hlist, head);
15792 +       atomic_inc(&vx_global_cactive);
15793 +}
15794 +
15795 +/*     __unhash_vx_info()
15796 +
15797 +       * remove the vxi from the global hash table
15798 +       * requires the hash_lock to be held                     */
15799 +
15800 +static inline void __unhash_vx_info(struct vx_info *vxi)
15801 +{
15802 +       unsigned long flags;
15803 +
15804 +       vxd_assert_lock(&vx_info_hash_lock);
15805 +       vxdprintk(VXD_CBIT(xid, 4),
15806 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
15807 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
15808 +       vxh_unhash_vx_info(vxi);
15809 +
15810 +       /* context must be hashed */
15811 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
15812 +       /* but without tasks */
15813 +       BUG_ON(atomic_read(&vxi->vx_tasks));
15814 +
15815 +       vxi->vx_state &= ~VXS_HASHED;
15816 +       hlist_del_init(&vxi->vx_hlist);
15817 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
15818 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
15819 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
15820 +       atomic_dec(&vx_global_cactive);
15821 +}
15822 +
15823 +
15824 +/*     __lookup_vx_info()
15825 +
15826 +       * requires the hash_lock to be held
15827 +       * doesn't increment the vx_refcnt                       */
15828 +
15829 +static inline struct vx_info *__lookup_vx_info(vxid_t xid)
15830 +{
15831 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
15832 +       struct hlist_node *pos;
15833 +       struct vx_info *vxi;
15834 +
15835 +       vxd_assert_lock(&vx_info_hash_lock);
15836 +       hlist_for_each(pos, head) {
15837 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
15838 +
15839 +               if (vxi->vx_id == xid)
15840 +                       goto found;
15841 +       }
15842 +       vxi = NULL;
15843 +found:
15844 +       vxdprintk(VXD_CBIT(xid, 0),
15845 +               "__lookup_vx_info(#%u): %p[#%u]",
15846 +               xid, vxi, vxi ? vxi->vx_id : 0);
15847 +       vxh_lookup_vx_info(vxi, xid);
15848 +       return vxi;
15849 +}
15850 +
15851 +
15852 +/*     __create_vx_info()
15853 +
15854 +       * create the requested context
15855 +       * get(), claim() and hash it                            */
15856 +
15857 +static struct vx_info *__create_vx_info(int id)
15858 +{
15859 +       struct vx_info *new, *vxi = NULL;
15860 +
15861 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
15862 +
15863 +       if (!(new = __alloc_vx_info(id)))
15864 +               return ERR_PTR(-ENOMEM);
15865 +
15866 +       /* required to make dynamic xids unique */
15867 +       spin_lock(&vx_info_hash_lock);
15868 +
15869 +       /* static context requested */
15870 +       if ((vxi = __lookup_vx_info(id))) {
15871 +               vxdprintk(VXD_CBIT(xid, 0),
15872 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
15873 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
15874 +                       vxi = ERR_PTR(-EBUSY);
15875 +               else
15876 +                       vxi = ERR_PTR(-EEXIST);
15877 +               goto out_unlock;
15878 +       }
15879 +       /* new context */
15880 +       vxdprintk(VXD_CBIT(xid, 0),
15881 +               "create_vx_info(%d) = %p (new)", id, new);
15882 +       claim_vx_info(new, NULL);
15883 +       __hash_vx_info(get_vx_info(new));
15884 +       vxi = new, new = NULL;
15885 +
15886 +out_unlock:
15887 +       spin_unlock(&vx_info_hash_lock);
15888 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
15889 +       if (new)
15890 +               __dealloc_vx_info(new);
15891 +       return vxi;
15892 +}
15893 +
15894 +
15895 +/*     exported stuff                                          */
15896 +
15897 +
15898 +void unhash_vx_info(struct vx_info *vxi)
15899 +{
15900 +       spin_lock(&vx_info_hash_lock);
15901 +       __unhash_vx_info(vxi);
15902 +       spin_unlock(&vx_info_hash_lock);
15903 +       __shutdown_vx_info(vxi);
15904 +       __wakeup_vx_info(vxi);
15905 +}
15906 +
15907 +
15908 +/*     lookup_vx_info()
15909 +
15910 +       * search for a vx_info and get() it
15911 +       * negative id means current                             */
15912 +
15913 +struct vx_info *lookup_vx_info(int id)
15914 +{
15915 +       struct vx_info *vxi = NULL;
15916 +
15917 +       if (id < 0) {
15918 +               vxi = get_vx_info(current_vx_info());
15919 +       } else if (id > 1) {
15920 +               spin_lock(&vx_info_hash_lock);
15921 +               vxi = get_vx_info(__lookup_vx_info(id));
15922 +               spin_unlock(&vx_info_hash_lock);
15923 +       }
15924 +       return vxi;
15925 +}
15926 +
15927 +/*     xid_is_hashed()
15928 +
15929 +       * verify that xid is still hashed                       */
15930 +
15931 +int xid_is_hashed(vxid_t xid)
15932 +{
15933 +       int hashed;
15934 +
15935 +       spin_lock(&vx_info_hash_lock);
15936 +       hashed = (__lookup_vx_info(xid) != NULL);
15937 +       spin_unlock(&vx_info_hash_lock);
15938 +       return hashed;
15939 +}
15940 +
15941 +#ifdef CONFIG_PROC_FS
15942 +
15943 +/*     get_xid_list()
15944 +
15945 +       * get a subset of hashed xids for proc
15946 +       * assumes size is at least one                          */
15947 +
15948 +int get_xid_list(int index, unsigned int *xids, int size)
15949 +{
15950 +       int hindex, nr_xids = 0;
15951 +
15952 +       /* only show current and children */
15953 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
15954 +               if (index > 0)
15955 +                       return 0;
15956 +               xids[nr_xids] = vx_current_xid();
15957 +               return 1;
15958 +       }
15959 +
15960 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
15961 +               struct hlist_head *head = &vx_info_hash[hindex];
15962 +               struct hlist_node *pos;
15963 +
15964 +               spin_lock(&vx_info_hash_lock);
15965 +               hlist_for_each(pos, head) {
15966 +                       struct vx_info *vxi;
15967 +
15968 +                       if (--index > 0)
15969 +                               continue;
15970 +
15971 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
15972 +                       xids[nr_xids] = vxi->vx_id;
15973 +                       if (++nr_xids >= size) {
15974 +                               spin_unlock(&vx_info_hash_lock);
15975 +                               goto out;
15976 +                       }
15977 +               }
15978 +               /* keep the lock time short */
15979 +               spin_unlock(&vx_info_hash_lock);
15980 +       }
15981 +out:
15982 +       return nr_xids;
15983 +}
15984 +#endif
15985 +
15986 +#ifdef CONFIG_VSERVER_DEBUG
15987 +
15988 +void   dump_vx_info_inactive(int level)
15989 +{
15990 +       struct hlist_node *entry, *next;
15991 +
15992 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
15993 +               struct vx_info *vxi =
15994 +                       list_entry(entry, struct vx_info, vx_hlist);
15995 +
15996 +               dump_vx_info(vxi, level);
15997 +       }
15998 +}
15999 +
16000 +#endif
16001 +
16002 +#if 0
16003 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
16004 +{
16005 +       struct user_struct *new_user, *old_user;
16006 +
16007 +       if (!p || !vxi)
16008 +               BUG();
16009 +
16010 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
16011 +               return -EACCES;
16012 +
16013 +       new_user = alloc_uid(vxi->vx_id, p->uid);
16014 +       if (!new_user)
16015 +               return -ENOMEM;
16016 +
16017 +       old_user = p->user;
16018 +       if (new_user != old_user) {
16019 +               atomic_inc(&new_user->processes);
16020 +               atomic_dec(&old_user->processes);
16021 +               p->user = new_user;
16022 +       }
16023 +       free_uid(old_user);
16024 +       return 0;
16025 +}
16026 +#endif
16027 +
16028 +#if 0
16029 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
16030 +{
16031 +       // p->cap_effective &= vxi->vx_cap_bset;
16032 +       p->cap_effective =
16033 +               cap_intersect(p->cap_effective, vxi->cap_bset);
16034 +       // p->cap_inheritable &= vxi->vx_cap_bset;
16035 +       p->cap_inheritable =
16036 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
16037 +       // p->cap_permitted &= vxi->vx_cap_bset;
16038 +       p->cap_permitted =
16039 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
16040 +}
16041 +#endif
16042 +
16043 +
16044 +#include <linux/file.h>
16045 +#include <linux/fdtable.h>
16046 +
16047 +static int vx_openfd_task(struct task_struct *tsk)
16048 +{
16049 +       struct files_struct *files = tsk->files;
16050 +       struct fdtable *fdt;
16051 +       const unsigned long *bptr;
16052 +       int count, total;
16053 +
16054 +       /* no rcu_read_lock() because of spin_lock() */
16055 +       spin_lock(&files->file_lock);
16056 +       fdt = files_fdtable(files);
16057 +       bptr = fdt->open_fds;
16058 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
16059 +       for (total = 0; count > 0; count--) {
16060 +               if (*bptr)
16061 +                       total += hweight_long(*bptr);
16062 +               bptr++;
16063 +       }
16064 +       spin_unlock(&files->file_lock);
16065 +       return total;
16066 +}
16067 +
16068 +
16069 +/*     for *space compatibility */
16070 +
16071 +asmlinkage long sys_unshare(unsigned long);
16072 +
16073 +/*
16074 + *     migrate task to new context
16075 + *     gets vxi, puts old_vxi on change
16076 + *     optionally unshares namespaces (hack)
16077 + */
16078 +
16079 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
16080 +{
16081 +       struct vx_info *old_vxi;
16082 +       int ret = 0;
16083 +
16084 +       if (!p || !vxi)
16085 +               BUG();
16086 +
16087 +       vxdprintk(VXD_CBIT(xid, 5),
16088 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
16089 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
16090 +
16091 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
16092 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16093 +               return -EACCES;
16094 +
16095 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
16096 +               return -EFAULT;
16097 +
16098 +       old_vxi = task_get_vx_info(p);
16099 +       if (old_vxi == vxi)
16100 +               goto out;
16101 +
16102 +//     if (!(ret = vx_migrate_user(p, vxi))) {
16103 +       {
16104 +               int openfd;
16105 +
16106 +               task_lock(p);
16107 +               openfd = vx_openfd_task(p);
16108 +
16109 +               if (old_vxi) {
16110 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
16111 +                       atomic_dec(&old_vxi->cvirt.nr_running);
16112 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
16113 +                       /* FIXME: what about the struct files here? */
16114 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
16115 +                       /* account for the executable */
16116 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
16117 +               }
16118 +               atomic_inc(&vxi->cvirt.nr_threads);
16119 +               atomic_inc(&vxi->cvirt.nr_running);
16120 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
16121 +               /* FIXME: what about the struct files here? */
16122 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
16123 +               /* account for the executable */
16124 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
16125 +
16126 +               if (old_vxi) {
16127 +                       release_vx_info(old_vxi, p);
16128 +                       clr_vx_info(&p->vx_info);
16129 +               }
16130 +               claim_vx_info(vxi, p);
16131 +               set_vx_info(&p->vx_info, vxi);
16132 +               p->xid = vxi->vx_id;
16133 +
16134 +               vxdprintk(VXD_CBIT(xid, 5),
16135 +                       "moved task %p into vxi:%p[#%d]",
16136 +                       p, vxi, vxi->vx_id);
16137 +
16138 +               // vx_mask_cap_bset(vxi, p);
16139 +               task_unlock(p);
16140 +
16141 +               /* hack for *spaces to provide compatibility */
16142 +               if (unshare) {
16143 +                       struct nsproxy *old_nsp, *new_nsp;
16144 +
16145 +                       ret = unshare_nsproxy_namespaces(
16146 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
16147 +                               &new_nsp, NULL, NULL);
16148 +                       if (ret)
16149 +                               goto out;
16150 +
16151 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
16152 +                       vx_set_space(vxi,
16153 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
16154 +                       put_nsproxy(old_nsp);
16155 +               }
16156 +       }
16157 +out:
16158 +       put_vx_info(old_vxi);
16159 +       return ret;
16160 +}
16161 +
16162 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
16163 +{
16164 +       struct task_struct *old_reaper;
16165 +       struct vx_info *reaper_vxi;
16166 +
16167 +       if (!vxi)
16168 +               return -EINVAL;
16169 +
16170 +       vxdprintk(VXD_CBIT(xid, 6),
16171 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
16172 +               vxi, vxi->vx_id, p, p->xid, p->pid);
16173 +
16174 +       old_reaper = vxi->vx_reaper;
16175 +       if (old_reaper == p)
16176 +               return 0;
16177 +
16178 +       reaper_vxi = task_get_vx_info(p);
16179 +       if (reaper_vxi && reaper_vxi != vxi) {
16180 +               vxwprintk(1,
16181 +                       "Unsuitable reaper [" VS_Q("%s") ",%u:#%u] "
16182 +                       "for [xid #%u]",
16183 +                       p->comm, p->pid, p->xid, vx_current_xid());
16184 +               goto out;
16185 +       }
16186 +
16187 +       /* set new child reaper */
16188 +       get_task_struct(p);
16189 +       vxi->vx_reaper = p;
16190 +       put_task_struct(old_reaper);
16191 +out:
16192 +       put_vx_info(reaper_vxi);
16193 +       return 0;
16194 +}
16195 +
16196 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
16197 +{
16198 +       if (!vxi)
16199 +               return -EINVAL;
16200 +
16201 +       vxdprintk(VXD_CBIT(xid, 6),
16202 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
16203 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16204 +
16205 +       vxi->vx_flags &= ~VXF_STATE_INIT;
16206 +       // vxi->vx_initpid = p->tgid;
16207 +       vxi->vx_initpid = p->pid;
16208 +       return 0;
16209 +}
16210 +
16211 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
16212 +{
16213 +       vxdprintk(VXD_CBIT(xid, 6),
16214 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
16215 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16216 +
16217 +       vxi->exit_code = code;
16218 +       vxi->vx_initpid = 0;
16219 +}
16220 +
16221 +
16222 +void vx_set_persistent(struct vx_info *vxi)
16223 +{
16224 +       vxdprintk(VXD_CBIT(xid, 6),
16225 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
16226 +
16227 +       get_vx_info(vxi);
16228 +       claim_vx_info(vxi, NULL);
16229 +}
16230 +
16231 +void vx_clear_persistent(struct vx_info *vxi)
16232 +{
16233 +       vxdprintk(VXD_CBIT(xid, 6),
16234 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
16235 +
16236 +       release_vx_info(vxi, NULL);
16237 +       put_vx_info(vxi);
16238 +}
16239 +
16240 +void vx_update_persistent(struct vx_info *vxi)
16241 +{
16242 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
16243 +               vx_set_persistent(vxi);
16244 +       else
16245 +               vx_clear_persistent(vxi);
16246 +}
16247 +
16248 +
16249 +/*     task must be current or locked          */
16250 +
16251 +void   exit_vx_info(struct task_struct *p, int code)
16252 +{
16253 +       struct vx_info *vxi = p->vx_info;
16254 +
16255 +       if (vxi) {
16256 +               atomic_dec(&vxi->cvirt.nr_threads);
16257 +               vx_nproc_dec(p);
16258 +
16259 +               vxi->exit_code = code;
16260 +               release_vx_info(vxi, p);
16261 +       }
16262 +}
16263 +
16264 +void   exit_vx_info_early(struct task_struct *p, int code)
16265 +{
16266 +       struct vx_info *vxi = p->vx_info;
16267 +
16268 +       if (vxi) {
16269 +               if (vxi->vx_initpid == p->pid)
16270 +                       vx_exit_init(vxi, p, code);
16271 +               if (vxi->vx_reaper == p)
16272 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
16273 +       }
16274 +}
16275 +
16276 +
16277 +/* vserver syscall commands below here */
16278 +
16279 +/* taks xid and vx_info functions */
16280 +
16281 +#include <asm/uaccess.h>
16282 +
16283 +
16284 +int vc_task_xid(uint32_t id)
16285 +{
16286 +       vxid_t xid;
16287 +
16288 +       if (id) {
16289 +               struct task_struct *tsk;
16290 +
16291 +               rcu_read_lock();
16292 +               tsk = find_task_by_real_pid(id);
16293 +               xid = (tsk) ? tsk->xid : -ESRCH;
16294 +               rcu_read_unlock();
16295 +       } else
16296 +               xid = vx_current_xid();
16297 +       return xid;
16298 +}
16299 +
16300 +
16301 +int vc_vx_info(struct vx_info *vxi, void __user *data)
16302 +{
16303 +       struct vcmd_vx_info_v0 vc_data;
16304 +
16305 +       vc_data.xid = vxi->vx_id;
16306 +       vc_data.initpid = vxi->vx_initpid;
16307 +
16308 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16309 +               return -EFAULT;
16310 +       return 0;
16311 +}
16312 +
16313 +
16314 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
16315 +{
16316 +       struct vcmd_ctx_stat_v0 vc_data;
16317 +
16318 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
16319 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
16320 +
16321 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16322 +               return -EFAULT;
16323 +       return 0;
16324 +}
16325 +
16326 +
16327 +/* context functions */
16328 +
16329 +int vc_ctx_create(uint32_t xid, void __user *data)
16330 +{
16331 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
16332 +       struct vx_info *new_vxi;
16333 +       int ret;
16334 +
16335 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16336 +               return -EFAULT;
16337 +
16338 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
16339 +               return -EINVAL;
16340 +
16341 +       new_vxi = __create_vx_info(xid);
16342 +       if (IS_ERR(new_vxi))
16343 +               return PTR_ERR(new_vxi);
16344 +
16345 +       /* initial flags */
16346 +       new_vxi->vx_flags = vc_data.flagword;
16347 +
16348 +       ret = -ENOEXEC;
16349 +       if (vs_state_change(new_vxi, VSC_STARTUP))
16350 +               goto out;
16351 +
16352 +       ret = vx_migrate_task(current, new_vxi, (!data));
16353 +       if (ret)
16354 +               goto out;
16355 +
16356 +       /* return context id on success */
16357 +       ret = new_vxi->vx_id;
16358 +
16359 +       /* get a reference for persistent contexts */
16360 +       if ((vc_data.flagword & VXF_PERSISTENT))
16361 +               vx_set_persistent(new_vxi);
16362 +out:
16363 +       release_vx_info(new_vxi, NULL);
16364 +       put_vx_info(new_vxi);
16365 +       return ret;
16366 +}
16367 +
16368 +
16369 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
16370 +{
16371 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
16372 +       int ret;
16373 +
16374 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16375 +               return -EFAULT;
16376 +
16377 +       ret = vx_migrate_task(current, vxi, 0);
16378 +       if (ret)
16379 +               return ret;
16380 +       if (vc_data.flagword & VXM_SET_INIT)
16381 +               ret = vx_set_init(vxi, current);
16382 +       if (ret)
16383 +               return ret;
16384 +       if (vc_data.flagword & VXM_SET_REAPER)
16385 +               ret = vx_set_reaper(vxi, current);
16386 +       return ret;
16387 +}
16388 +
16389 +
16390 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
16391 +{
16392 +       struct vcmd_ctx_flags_v0 vc_data;
16393 +
16394 +       vc_data.flagword = vxi->vx_flags;
16395 +
16396 +       /* special STATE flag handling */
16397 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
16398 +
16399 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16400 +               return -EFAULT;
16401 +       return 0;
16402 +}
16403 +
16404 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
16405 +{
16406 +       struct vcmd_ctx_flags_v0 vc_data;
16407 +       uint64_t mask, trigger;
16408 +
16409 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16410 +               return -EFAULT;
16411 +
16412 +       /* special STATE flag handling */
16413 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
16414 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
16415 +
16416 +       if (vxi == current_vx_info()) {
16417 +               /* if (trigger & VXF_STATE_SETUP)
16418 +                       vx_mask_cap_bset(vxi, current); */
16419 +               if (trigger & VXF_STATE_INIT) {
16420 +                       int ret;
16421 +
16422 +                       ret = vx_set_init(vxi, current);
16423 +                       if (ret)
16424 +                               return ret;
16425 +                       ret = vx_set_reaper(vxi, current);
16426 +                       if (ret)
16427 +                               return ret;
16428 +               }
16429 +       }
16430 +
16431 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
16432 +               vc_data.flagword, mask);
16433 +       if (trigger & VXF_PERSISTENT)
16434 +               vx_update_persistent(vxi);
16435 +
16436 +       return 0;
16437 +}
16438 +
16439 +
16440 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
16441 +{
16442 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
16443 +
16444 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
16445 +       return v;
16446 +}
16447 +
16448 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
16449 +{
16450 +       kernel_cap_t c = __cap_empty_set;
16451 +
16452 +       c.cap[0] = v & 0xFFFFFFFF;
16453 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
16454 +
16455 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
16456 +       return c;
16457 +}
16458 +
16459 +
16460 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
16461 +{
16462 +       if (bcaps)
16463 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
16464 +       if (ccaps)
16465 +               *ccaps = vxi->vx_ccaps;
16466 +
16467 +       return 0;
16468 +}
16469 +
16470 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
16471 +{
16472 +       struct vcmd_ctx_caps_v1 vc_data;
16473 +       int ret;
16474 +
16475 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
16476 +       if (ret)
16477 +               return ret;
16478 +       vc_data.cmask = ~0ULL;
16479 +
16480 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16481 +               return -EFAULT;
16482 +       return 0;
16483 +}
16484 +
16485 +static int do_set_caps(struct vx_info *vxi,
16486 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
16487 +{
16488 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
16489 +
16490 +#if 0
16491 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
16492 +               bcaps, bmask, ccaps, cmask);
16493 +#endif
16494 +       vxi->vx_bcaps = cap_t_from_caps(
16495 +               vs_mask_flags(bcold, bcaps, bmask));
16496 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
16497 +
16498 +       return 0;
16499 +}
16500 +
16501 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
16502 +{
16503 +       struct vcmd_ctx_caps_v1 vc_data;
16504 +
16505 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16506 +               return -EFAULT;
16507 +
16508 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
16509 +}
16510 +
16511 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
16512 +{
16513 +       struct vcmd_bcaps vc_data;
16514 +       int ret;
16515 +
16516 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
16517 +       if (ret)
16518 +               return ret;
16519 +       vc_data.bmask = ~0ULL;
16520 +
16521 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16522 +               return -EFAULT;
16523 +       return 0;
16524 +}
16525 +
16526 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
16527 +{
16528 +       struct vcmd_bcaps vc_data;
16529 +
16530 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16531 +               return -EFAULT;
16532 +
16533 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
16534 +}
16535 +
16536 +
16537 +int vc_get_umask(struct vx_info *vxi, void __user *data)
16538 +{
16539 +       struct vcmd_umask vc_data;
16540 +
16541 +       vc_data.umask = vxi->vx_umask;
16542 +       vc_data.mask = ~0ULL;
16543 +
16544 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16545 +               return -EFAULT;
16546 +       return 0;
16547 +}
16548 +
16549 +int vc_set_umask(struct vx_info *vxi, void __user *data)
16550 +{
16551 +       struct vcmd_umask vc_data;
16552 +
16553 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16554 +               return -EFAULT;
16555 +
16556 +       vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
16557 +               vc_data.umask, vc_data.mask);
16558 +       return 0;
16559 +}
16560 +
16561 +
16562 +int vc_get_wmask(struct vx_info *vxi, void __user *data)
16563 +{
16564 +       struct vcmd_wmask vc_data;
16565 +
16566 +       vc_data.wmask = vxi->vx_wmask;
16567 +       vc_data.mask = ~0ULL;
16568 +
16569 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16570 +               return -EFAULT;
16571 +       return 0;
16572 +}
16573 +
16574 +int vc_set_wmask(struct vx_info *vxi, void __user *data)
16575 +{
16576 +       struct vcmd_wmask vc_data;
16577 +
16578 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16579 +               return -EFAULT;
16580 +
16581 +       vxi->vx_wmask = vs_mask_flags(vxi->vx_wmask,
16582 +               vc_data.wmask, vc_data.mask);
16583 +       return 0;
16584 +}
16585 +
16586 +
16587 +int vc_get_badness(struct vx_info *vxi, void __user *data)
16588 +{
16589 +       struct vcmd_badness_v0 vc_data;
16590 +
16591 +       vc_data.bias = vxi->vx_badness_bias;
16592 +
16593 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16594 +               return -EFAULT;
16595 +       return 0;
16596 +}
16597 +
16598 +int vc_set_badness(struct vx_info *vxi, void __user *data)
16599 +{
16600 +       struct vcmd_badness_v0 vc_data;
16601 +
16602 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16603 +               return -EFAULT;
16604 +
16605 +       vxi->vx_badness_bias = vc_data.bias;
16606 +       return 0;
16607 +}
16608 +
16609 +#include <linux/module.h>
16610 +
16611 +EXPORT_SYMBOL_GPL(free_vx_info);
16612 +
16613 diff -NurpP --minimal linux-3.10.33/kernel/vserver/cvirt.c linux-3.10.33-vs2.3.6.8/kernel/vserver/cvirt.c
16614 --- linux-3.10.33/kernel/vserver/cvirt.c        1970-01-01 00:00:00.000000000 +0000
16615 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/cvirt.c      2013-08-22 20:30:00.000000000 +0000
16616 @@ -0,0 +1,313 @@
16617 +/*
16618 + *  linux/kernel/vserver/cvirt.c
16619 + *
16620 + *  Virtual Server: Context Virtualization
16621 + *
16622 + *  Copyright (C) 2004-2007  Herbert Pötzl
16623 + *
16624 + *  V0.01  broken out from limit.c
16625 + *  V0.02  added utsname stuff
16626 + *  V0.03  changed vcmds to vxi arg
16627 + *
16628 + */
16629 +
16630 +#include <linux/types.h>
16631 +#include <linux/utsname.h>
16632 +#include <linux/vs_cvirt.h>
16633 +#include <linux/vserver/switch.h>
16634 +#include <linux/vserver/cvirt_cmd.h>
16635 +
16636 +#include <asm/uaccess.h>
16637 +
16638 +
16639 +void vx_vsi_boottime(struct timespec *boottime)
16640 +{
16641 +       struct vx_info *vxi = current_vx_info();
16642 +
16643 +       set_normalized_timespec(boottime,
16644 +               boottime->tv_sec + vxi->cvirt.bias_uptime.tv_sec,
16645 +               boottime->tv_nsec + vxi->cvirt.bias_uptime.tv_nsec);
16646 +       return;
16647 +}
16648 +
16649 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
16650 +{
16651 +       struct vx_info *vxi = current_vx_info();
16652 +
16653 +       set_normalized_timespec(uptime,
16654 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
16655 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
16656 +       if (!idle)
16657 +               return;
16658 +       set_normalized_timespec(idle,
16659 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
16660 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
16661 +       return;
16662 +}
16663 +
16664 +uint64_t vx_idle_jiffies(void)
16665 +{
16666 +       return init_task.utime + init_task.stime;
16667 +}
16668 +
16669 +
16670 +
16671 +static inline uint32_t __update_loadavg(uint32_t load,
16672 +       int wsize, int delta, int n)
16673 +{
16674 +       unsigned long long calc, prev;
16675 +
16676 +       /* just set it to n */
16677 +       if (unlikely(delta >= wsize))
16678 +               return (n << FSHIFT);
16679 +
16680 +       calc = delta * n;
16681 +       calc <<= FSHIFT;
16682 +       prev = (wsize - delta);
16683 +       prev *= load;
16684 +       calc += prev;
16685 +       do_div(calc, wsize);
16686 +       return calc;
16687 +}
16688 +
16689 +
16690 +void vx_update_load(struct vx_info *vxi)
16691 +{
16692 +       uint32_t now, last, delta;
16693 +       unsigned int nr_running, nr_uninterruptible;
16694 +       unsigned int total;
16695 +       unsigned long flags;
16696 +
16697 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
16698 +
16699 +       now = jiffies;
16700 +       last = vxi->cvirt.load_last;
16701 +       delta = now - last;
16702 +
16703 +       if (delta < 5*HZ)
16704 +               goto out;
16705 +
16706 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
16707 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
16708 +       total = nr_running + nr_uninterruptible;
16709 +
16710 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
16711 +               60*HZ, delta, total);
16712 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
16713 +               5*60*HZ, delta, total);
16714 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
16715 +               15*60*HZ, delta, total);
16716 +
16717 +       vxi->cvirt.load_last = now;
16718 +out:
16719 +       atomic_inc(&vxi->cvirt.load_updates);
16720 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
16721 +}
16722 +
16723 +
16724 +/*
16725 + * Commands to do_syslog:
16726 + *
16727 + *      0 -- Close the log.  Currently a NOP.
16728 + *      1 -- Open the log. Currently a NOP.
16729 + *      2 -- Read from the log.
16730 + *      3 -- Read all messages remaining in the ring buffer.
16731 + *      4 -- Read and clear all messages remaining in the ring buffer
16732 + *      5 -- Clear ring buffer.
16733 + *      6 -- Disable printk's to console
16734 + *      7 -- Enable printk's to console
16735 + *      8 -- Set level of messages printed to console
16736 + *      9 -- Return number of unread characters in the log buffer
16737 + *     10 -- Return size of the log buffer
16738 + */
16739 +int vx_do_syslog(int type, char __user *buf, int len)
16740 +{
16741 +       int error = 0;
16742 +       int do_clear = 0;
16743 +       struct vx_info *vxi = current_vx_info();
16744 +       struct _vx_syslog *log;
16745 +
16746 +       if (!vxi)
16747 +               return -EINVAL;
16748 +       log = &vxi->cvirt.syslog;
16749 +
16750 +       switch (type) {
16751 +       case 0:         /* Close log */
16752 +       case 1:         /* Open log */
16753 +               break;
16754 +       case 2:         /* Read from log */
16755 +               error = wait_event_interruptible(log->log_wait,
16756 +                       (log->log_start - log->log_end));
16757 +               if (error)
16758 +                       break;
16759 +               spin_lock_irq(&log->logbuf_lock);
16760 +               spin_unlock_irq(&log->logbuf_lock);
16761 +               break;
16762 +       case 4:         /* Read/clear last kernel messages */
16763 +               do_clear = 1;
16764 +               /* fall through */
16765 +       case 3:         /* Read last kernel messages */
16766 +               return 0;
16767 +
16768 +       case 5:         /* Clear ring buffer */
16769 +               return 0;
16770 +
16771 +       case 6:         /* Disable logging to console */
16772 +       case 7:         /* Enable logging to console */
16773 +       case 8:         /* Set level of messages printed to console */
16774 +               break;
16775 +
16776 +       case 9:         /* Number of chars in the log buffer */
16777 +               return 0;
16778 +       case 10:        /* Size of the log buffer */
16779 +               return 0;
16780 +       default:
16781 +               error = -EINVAL;
16782 +               break;
16783 +       }
16784 +       return error;
16785 +}
16786 +
16787 +
16788 +/* virtual host info names */
16789 +
16790 +static char *vx_vhi_name(struct vx_info *vxi, int id)
16791 +{
16792 +       struct nsproxy *nsproxy;
16793 +       struct uts_namespace *uts;
16794 +
16795 +       if (id == VHIN_CONTEXT)
16796 +               return vxi->vx_name;
16797 +
16798 +       nsproxy = vxi->space[0].vx_nsproxy;
16799 +       if (!nsproxy)
16800 +               return NULL;
16801 +
16802 +       uts = nsproxy->uts_ns;
16803 +       if (!uts)
16804 +               return NULL;
16805 +
16806 +       switch (id) {
16807 +       case VHIN_SYSNAME:
16808 +               return uts->name.sysname;
16809 +       case VHIN_NODENAME:
16810 +               return uts->name.nodename;
16811 +       case VHIN_RELEASE:
16812 +               return uts->name.release;
16813 +       case VHIN_VERSION:
16814 +               return uts->name.version;
16815 +       case VHIN_MACHINE:
16816 +               return uts->name.machine;
16817 +       case VHIN_DOMAINNAME:
16818 +               return uts->name.domainname;
16819 +       default:
16820 +               return NULL;
16821 +       }
16822 +       return NULL;
16823 +}
16824 +
16825 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
16826 +{
16827 +       struct vcmd_vhi_name_v0 vc_data;
16828 +       char *name;
16829 +
16830 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16831 +               return -EFAULT;
16832 +
16833 +       name = vx_vhi_name(vxi, vc_data.field);
16834 +       if (!name)
16835 +               return -EINVAL;
16836 +
16837 +       memcpy(name, vc_data.name, 65);
16838 +       return 0;
16839 +}
16840 +
16841 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
16842 +{
16843 +       struct vcmd_vhi_name_v0 vc_data;
16844 +       char *name;
16845 +
16846 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16847 +               return -EFAULT;
16848 +
16849 +       name = vx_vhi_name(vxi, vc_data.field);
16850 +       if (!name)
16851 +               return -EINVAL;
16852 +
16853 +       memcpy(vc_data.name, name, 65);
16854 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16855 +               return -EFAULT;
16856 +       return 0;
16857 +}
16858 +
16859 +
16860 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
16861 +{
16862 +       struct vcmd_virt_stat_v0 vc_data;
16863 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
16864 +       struct timespec uptime;
16865 +
16866 +       do_posix_clock_monotonic_gettime(&uptime);
16867 +       set_normalized_timespec(&uptime,
16868 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
16869 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
16870 +
16871 +       vc_data.offset = timespec_to_ns(&cvirt->bias_ts);
16872 +       vc_data.uptime = timespec_to_ns(&uptime);
16873 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
16874 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
16875 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
16876 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
16877 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
16878 +       vc_data.load[0] = cvirt->load[0];
16879 +       vc_data.load[1] = cvirt->load[1];
16880 +       vc_data.load[2] = cvirt->load[2];
16881 +
16882 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16883 +               return -EFAULT;
16884 +       return 0;
16885 +}
16886 +
16887 +
16888 +#ifdef CONFIG_VSERVER_VTIME
16889 +
16890 +/* virtualized time base */
16891 +
16892 +void vx_adjust_timespec(struct timespec *ts)
16893 +{
16894 +       struct vx_info *vxi;
16895 +
16896 +       if (!vx_flags(VXF_VIRT_TIME, 0))
16897 +               return;
16898 +
16899 +       vxi = current_vx_info();
16900 +       ts->tv_sec += vxi->cvirt.bias_ts.tv_sec;
16901 +       ts->tv_nsec += vxi->cvirt.bias_ts.tv_nsec;
16902 +
16903 +       if (ts->tv_nsec >= NSEC_PER_SEC) {
16904 +               ts->tv_sec++;
16905 +               ts->tv_nsec -= NSEC_PER_SEC;
16906 +       } else if (ts->tv_nsec < 0) {
16907 +               ts->tv_sec--;
16908 +               ts->tv_nsec += NSEC_PER_SEC;
16909 +       }
16910 +}
16911 +
16912 +int vx_settimeofday(const struct timespec *ts)
16913 +{
16914 +       struct timespec ats, delta;
16915 +       struct vx_info *vxi;
16916 +
16917 +       if (!vx_flags(VXF_VIRT_TIME, 0))
16918 +               return do_settimeofday(ts);
16919 +
16920 +       getnstimeofday(&ats);
16921 +       delta = timespec_sub(*ts, ats);
16922 +
16923 +       vxi = current_vx_info();
16924 +       vxi->cvirt.bias_ts = timespec_add(vxi->cvirt.bias_ts, delta);
16925 +       return 0;
16926 +}
16927 +
16928 +#endif
16929 +
16930 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
16931 --- linux-3.10.33/kernel/vserver/cvirt_init.h   1970-01-01 00:00:00.000000000 +0000
16932 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/cvirt_init.h 2013-08-22 20:30:00.000000000 +0000
16933 @@ -0,0 +1,70 @@
16934 +
16935 +
16936 +extern uint64_t vx_idle_jiffies(void);
16937 +
16938 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
16939 +{
16940 +       uint64_t idle_jiffies = vx_idle_jiffies();
16941 +       uint64_t nsuptime;
16942 +
16943 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
16944 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
16945 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
16946 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
16947 +       cvirt->bias_ts.tv_sec = 0;
16948 +       cvirt->bias_ts.tv_nsec = 0;
16949 +
16950 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
16951 +       atomic_set(&cvirt->nr_threads, 0);
16952 +       atomic_set(&cvirt->nr_running, 0);
16953 +       atomic_set(&cvirt->nr_uninterruptible, 0);
16954 +       atomic_set(&cvirt->nr_onhold, 0);
16955 +
16956 +       spin_lock_init(&cvirt->load_lock);
16957 +       cvirt->load_last = jiffies;
16958 +       atomic_set(&cvirt->load_updates, 0);
16959 +       cvirt->load[0] = 0;
16960 +       cvirt->load[1] = 0;
16961 +       cvirt->load[2] = 0;
16962 +       atomic_set(&cvirt->total_forks, 0);
16963 +
16964 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
16965 +       init_waitqueue_head(&cvirt->syslog.log_wait);
16966 +       cvirt->syslog.log_start = 0;
16967 +       cvirt->syslog.log_end = 0;
16968 +       cvirt->syslog.con_start = 0;
16969 +       cvirt->syslog.logged_chars = 0;
16970 +}
16971 +
16972 +static inline
16973 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
16974 +{
16975 +       // cvirt_pc->cpustat = { 0 };
16976 +}
16977 +
16978 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
16979 +{
16980 +#ifdef CONFIG_VSERVER_WARN
16981 +       int value;
16982 +#endif
16983 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
16984 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
16985 +               cvirt, value);
16986 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
16987 +               "!!! cvirt: %p[nr_running] = %d on exit.",
16988 +               cvirt, value);
16989 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
16990 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
16991 +               cvirt, value);
16992 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
16993 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
16994 +               cvirt, value);
16995 +       return;
16996 +}
16997 +
16998 +static inline
16999 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17000 +{
17001 +       return;
17002 +}
17003 +
17004 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
17005 --- linux-3.10.33/kernel/vserver/cvirt_proc.h   1970-01-01 00:00:00.000000000 +0000
17006 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/cvirt_proc.h 2013-08-22 20:30:00.000000000 +0000
17007 @@ -0,0 +1,123 @@
17008 +#ifndef _VX_CVIRT_PROC_H
17009 +#define _VX_CVIRT_PROC_H
17010 +
17011 +#include <linux/nsproxy.h>
17012 +#include <linux/mnt_namespace.h>
17013 +#include <linux/ipc_namespace.h>
17014 +#include <linux/utsname.h>
17015 +#include <linux/ipc.h>
17016 +
17017 +extern int vx_info_mnt_namespace(struct mnt_namespace *, char *);
17018 +
17019 +static inline
17020 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
17021 +{
17022 +       struct mnt_namespace *ns;
17023 +       struct uts_namespace *uts;
17024 +       struct ipc_namespace *ipc;
17025 +       int length = 0;
17026 +
17027 +       if (!nsproxy)
17028 +               goto out;
17029 +
17030 +       length += sprintf(buffer + length,
17031 +               "NSProxy:\t%p [%p,%p,%p]\n",
17032 +               nsproxy, nsproxy->mnt_ns,
17033 +               nsproxy->uts_ns, nsproxy->ipc_ns);
17034 +
17035 +       ns = nsproxy->mnt_ns;
17036 +       if (!ns)
17037 +               goto skip_ns;
17038 +
17039 +       length += vx_info_mnt_namespace(ns, buffer + length);
17040 +
17041 +skip_ns:
17042 +
17043 +       uts = nsproxy->uts_ns;
17044 +       if (!uts)
17045 +               goto skip_uts;
17046 +
17047 +       length += sprintf(buffer + length,
17048 +               "SysName:\t%.*s\n"
17049 +               "NodeName:\t%.*s\n"
17050 +               "Release:\t%.*s\n"
17051 +               "Version:\t%.*s\n"
17052 +               "Machine:\t%.*s\n"
17053 +               "DomainName:\t%.*s\n",
17054 +               __NEW_UTS_LEN, uts->name.sysname,
17055 +               __NEW_UTS_LEN, uts->name.nodename,
17056 +               __NEW_UTS_LEN, uts->name.release,
17057 +               __NEW_UTS_LEN, uts->name.version,
17058 +               __NEW_UTS_LEN, uts->name.machine,
17059 +               __NEW_UTS_LEN, uts->name.domainname);
17060 +skip_uts:
17061 +
17062 +       ipc = nsproxy->ipc_ns;
17063 +       if (!ipc)
17064 +               goto skip_ipc;
17065 +
17066 +       length += sprintf(buffer + length,
17067 +               "SEMS:\t\t%d %d %d %d  %d\n"
17068 +               "MSG:\t\t%d %d %d\n"
17069 +               "SHM:\t\t%lu %lu  %d %ld\n",
17070 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
17071 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
17072 +               ipc->used_sems,
17073 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
17074 +               (unsigned long)ipc->shm_ctlmax,
17075 +               (unsigned long)ipc->shm_ctlall,
17076 +               ipc->shm_ctlmni, ipc->shm_tot);
17077 +skip_ipc:
17078 +out:
17079 +       return length;
17080 +}
17081 +
17082 +
17083 +#include <linux/sched.h>
17084 +
17085 +#define LOAD_INT(x) ((x) >> FSHIFT)
17086 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
17087 +
17088 +static inline
17089 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
17090 +{
17091 +       int length = 0;
17092 +       int a, b, c;
17093 +
17094 +       length += sprintf(buffer + length,
17095 +               "BiasUptime:\t%lu.%02lu\n",
17096 +               (unsigned long)cvirt->bias_uptime.tv_sec,
17097 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
17098 +
17099 +       a = cvirt->load[0] + (FIXED_1 / 200);
17100 +       b = cvirt->load[1] + (FIXED_1 / 200);
17101 +       c = cvirt->load[2] + (FIXED_1 / 200);
17102 +       length += sprintf(buffer + length,
17103 +               "nr_threads:\t%d\n"
17104 +               "nr_running:\t%d\n"
17105 +               "nr_unintr:\t%d\n"
17106 +               "nr_onhold:\t%d\n"
17107 +               "load_updates:\t%d\n"
17108 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
17109 +               "total_forks:\t%d\n",
17110 +               atomic_read(&cvirt->nr_threads),
17111 +               atomic_read(&cvirt->nr_running),
17112 +               atomic_read(&cvirt->nr_uninterruptible),
17113 +               atomic_read(&cvirt->nr_onhold),
17114 +               atomic_read(&cvirt->load_updates),
17115 +               LOAD_INT(a), LOAD_FRAC(a),
17116 +               LOAD_INT(b), LOAD_FRAC(b),
17117 +               LOAD_INT(c), LOAD_FRAC(c),
17118 +               atomic_read(&cvirt->total_forks));
17119 +       return length;
17120 +}
17121 +
17122 +static inline
17123 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
17124 +       char *buffer, int cpu)
17125 +{
17126 +       int length = 0;
17127 +       return length;
17128 +}
17129 +
17130 +#endif /* _VX_CVIRT_PROC_H */
17131 diff -NurpP --minimal linux-3.10.33/kernel/vserver/debug.c linux-3.10.33-vs2.3.6.8/kernel/vserver/debug.c
17132 --- linux-3.10.33/kernel/vserver/debug.c        1970-01-01 00:00:00.000000000 +0000
17133 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/debug.c      2013-08-22 20:30:00.000000000 +0000
17134 @@ -0,0 +1,32 @@
17135 +/*
17136 + *  kernel/vserver/debug.c
17137 + *
17138 + *  Copyright (C) 2005-2007 Herbert Pötzl
17139 + *
17140 + *  V0.01  vx_info dump support
17141 + *
17142 + */
17143 +
17144 +#include <linux/module.h>
17145 +
17146 +#include <linux/vserver/context.h>
17147 +
17148 +
17149 +void   dump_vx_info(struct vx_info *vxi, int level)
17150 +{
17151 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
17152 +               atomic_read(&vxi->vx_usecnt),
17153 +               atomic_read(&vxi->vx_tasks),
17154 +               vxi->vx_state);
17155 +       if (level > 0) {
17156 +               __dump_vx_limit(&vxi->limit);
17157 +               __dump_vx_sched(&vxi->sched);
17158 +               __dump_vx_cvirt(&vxi->cvirt);
17159 +               __dump_vx_cacct(&vxi->cacct);
17160 +       }
17161 +       printk("---\n");
17162 +}
17163 +
17164 +
17165 +EXPORT_SYMBOL_GPL(dump_vx_info);
17166 +
17167 diff -NurpP --minimal linux-3.10.33/kernel/vserver/device.c linux-3.10.33-vs2.3.6.8/kernel/vserver/device.c
17168 --- linux-3.10.33/kernel/vserver/device.c       1970-01-01 00:00:00.000000000 +0000
17169 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/device.c     2013-08-22 20:30:00.000000000 +0000
17170 @@ -0,0 +1,443 @@
17171 +/*
17172 + *  linux/kernel/vserver/device.c
17173 + *
17174 + *  Linux-VServer: Device Support
17175 + *
17176 + *  Copyright (C) 2006  Herbert Pötzl
17177 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
17178 + *
17179 + *  V0.01  device mapping basics
17180 + *  V0.02  added defaults
17181 + *
17182 + */
17183 +
17184 +#include <linux/slab.h>
17185 +#include <linux/rcupdate.h>
17186 +#include <linux/fs.h>
17187 +#include <linux/namei.h>
17188 +#include <linux/hash.h>
17189 +
17190 +#include <asm/errno.h>
17191 +#include <asm/uaccess.h>
17192 +#include <linux/vserver/base.h>
17193 +#include <linux/vserver/debug.h>
17194 +#include <linux/vserver/context.h>
17195 +#include <linux/vserver/device.h>
17196 +#include <linux/vserver/device_cmd.h>
17197 +
17198 +
17199 +#define DMAP_HASH_BITS 4
17200 +
17201 +
17202 +struct vs_mapping {
17203 +       union {
17204 +               struct hlist_node hlist;
17205 +               struct list_head list;
17206 +       } u;
17207 +#define dm_hlist       u.hlist
17208 +#define dm_list                u.list
17209 +       vxid_t xid;
17210 +       dev_t device;
17211 +       struct vx_dmap_target target;
17212 +};
17213 +
17214 +
17215 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
17216 +
17217 +static DEFINE_SPINLOCK(dmap_main_hash_lock);
17218 +
17219 +static struct vx_dmap_target dmap_defaults[2] = {
17220 +       { .flags = DATTR_OPEN },
17221 +       { .flags = DATTR_OPEN },
17222 +};
17223 +
17224 +
17225 +struct kmem_cache *dmap_cachep __read_mostly;
17226 +
17227 +int __init dmap_cache_init(void)
17228 +{
17229 +       dmap_cachep = kmem_cache_create("dmap_cache",
17230 +               sizeof(struct vs_mapping), 0,
17231 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
17232 +       return 0;
17233 +}
17234 +
17235 +__initcall(dmap_cache_init);
17236 +
17237 +
17238 +static inline unsigned int __hashval(dev_t dev, int bits)
17239 +{
17240 +       return hash_long((unsigned long)dev, bits);
17241 +}
17242 +
17243 +
17244 +/*     __hash_mapping()
17245 + *     add the mapping to the hash table
17246 + */
17247 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
17248 +{
17249 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17250 +       struct hlist_head *head, *hash = dmap_main_hash;
17251 +       int device = vdm->device;
17252 +
17253 +       spin_lock(hash_lock);
17254 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
17255 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
17256 +
17257 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
17258 +       hlist_add_head(&vdm->dm_hlist, head);
17259 +       spin_unlock(hash_lock);
17260 +}
17261 +
17262 +
17263 +static inline int __mode_to_default(umode_t mode)
17264 +{
17265 +       switch (mode) {
17266 +       case S_IFBLK:
17267 +               return 0;
17268 +       case S_IFCHR:
17269 +               return 1;
17270 +       default:
17271 +               BUG();
17272 +       }
17273 +}
17274 +
17275 +
17276 +/*     __set_default()
17277 + *     set a default
17278 + */
17279 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
17280 +       struct vx_dmap_target *vdmt)
17281 +{
17282 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17283 +       spin_lock(hash_lock);
17284 +
17285 +       if (vxi)
17286 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
17287 +       else
17288 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
17289 +
17290 +
17291 +       spin_unlock(hash_lock);
17292 +
17293 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
17294 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
17295 +}
17296 +
17297 +
17298 +/*     __remove_default()
17299 + *     remove a default
17300 + */
17301 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
17302 +{
17303 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17304 +       spin_lock(hash_lock);
17305 +
17306 +       if (vxi)
17307 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
17308 +       else    /* remove == reset */
17309 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
17310 +
17311 +       spin_unlock(hash_lock);
17312 +       return 0;
17313 +}
17314 +
17315 +
17316 +/*     __find_mapping()
17317 + *     find a mapping in the hash table
17318 + *
17319 + *     caller must hold hash_lock
17320 + */
17321 +static inline int __find_mapping(vxid_t xid, dev_t device, umode_t mode,
17322 +       struct vs_mapping **local, struct vs_mapping **global)
17323 +{
17324 +       struct hlist_head *hash = dmap_main_hash;
17325 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
17326 +       struct hlist_node *pos;
17327 +       struct vs_mapping *vdm;
17328 +
17329 +       *local = NULL;
17330 +       if (global)
17331 +               *global = NULL;
17332 +
17333 +       hlist_for_each(pos, head) {
17334 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
17335 +
17336 +               if ((vdm->device == device) &&
17337 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
17338 +                       if (vdm->xid == xid) {
17339 +                               *local = vdm;
17340 +                               return 1;
17341 +                       } else if (global && vdm->xid == 0)
17342 +                               *global = vdm;
17343 +               }
17344 +       }
17345 +
17346 +       if (global && *global)
17347 +               return 0;
17348 +       else
17349 +               return -ENOENT;
17350 +}
17351 +
17352 +
17353 +/*     __lookup_mapping()
17354 + *     find a mapping and store the result in target and flags
17355 + */
17356 +static inline int __lookup_mapping(struct vx_info *vxi,
17357 +       dev_t device, dev_t *target, int *flags, umode_t mode)
17358 +{
17359 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17360 +       struct vs_mapping *vdm, *global;
17361 +       struct vx_dmap_target *vdmt;
17362 +       int ret = 0;
17363 +       vxid_t xid = vxi->vx_id;
17364 +       int index;
17365 +
17366 +       spin_lock(hash_lock);
17367 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
17368 +               ret = 1;
17369 +               vdmt = &vdm->target;
17370 +               goto found;
17371 +       }
17372 +
17373 +       index = __mode_to_default(mode);
17374 +       if (vxi && vxi->dmap.targets[index].flags) {
17375 +               ret = 2;
17376 +               vdmt = &vxi->dmap.targets[index];
17377 +       } else if (global) {
17378 +               ret = 3;
17379 +               vdmt = &global->target;
17380 +               goto found;
17381 +       } else {
17382 +               ret = 4;
17383 +               vdmt = &dmap_defaults[index];
17384 +       }
17385 +
17386 +found:
17387 +       if (target && (vdmt->flags & DATTR_REMAP))
17388 +               *target = vdmt->target;
17389 +       else if (target)
17390 +               *target = device;
17391 +       if (flags)
17392 +               *flags = vdmt->flags;
17393 +
17394 +       spin_unlock(hash_lock);
17395 +
17396 +       return ret;
17397 +}
17398 +
17399 +
17400 +/*     __remove_mapping()
17401 + *     remove a mapping from the hash table
17402 + */
17403 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
17404 +       umode_t mode)
17405 +{
17406 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17407 +       struct vs_mapping *vdm = NULL;
17408 +       int ret = 0;
17409 +
17410 +       spin_lock(hash_lock);
17411 +
17412 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
17413 +               NULL);
17414 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
17415 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
17416 +       if (ret < 0)
17417 +               goto out;
17418 +       hlist_del(&vdm->dm_hlist);
17419 +
17420 +out:
17421 +       spin_unlock(hash_lock);
17422 +       if (vdm)
17423 +               kmem_cache_free(dmap_cachep, vdm);
17424 +       return ret;
17425 +}
17426 +
17427 +
17428 +
17429 +int vs_map_device(struct vx_info *vxi,
17430 +       dev_t device, dev_t *target, umode_t mode)
17431 +{
17432 +       int ret, flags = DATTR_MASK;
17433 +
17434 +       if (!vxi) {
17435 +               if (target)
17436 +                       *target = device;
17437 +               goto out;
17438 +       }
17439 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
17440 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
17441 +               device, target ? *target : 0, flags, mode, ret);
17442 +out:
17443 +       return (flags & DATTR_MASK);
17444 +}
17445 +
17446 +
17447 +
17448 +static int do_set_mapping(struct vx_info *vxi,
17449 +       dev_t device, dev_t target, int flags, umode_t mode)
17450 +{
17451 +       if (device) {
17452 +               struct vs_mapping *new;
17453 +
17454 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
17455 +               if (!new)
17456 +                       return -ENOMEM;
17457 +
17458 +               INIT_HLIST_NODE(&new->dm_hlist);
17459 +               new->device = device;
17460 +               new->target.target = target;
17461 +               new->target.flags = flags | mode;
17462 +               new->xid = (vxi ? vxi->vx_id : 0);
17463 +
17464 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
17465 +               __hash_mapping(vxi, new);
17466 +       } else {
17467 +               struct vx_dmap_target new = {
17468 +                       .target = target,
17469 +                       .flags = flags | mode,
17470 +               };
17471 +               __set_default(vxi, mode, &new);
17472 +       }
17473 +       return 0;
17474 +}
17475 +
17476 +
17477 +static int do_unset_mapping(struct vx_info *vxi,
17478 +       dev_t device, dev_t target, int flags, umode_t mode)
17479 +{
17480 +       int ret = -EINVAL;
17481 +
17482 +       if (device) {
17483 +               ret = __remove_mapping(vxi, device, mode);
17484 +               if (ret < 0)
17485 +                       goto out;
17486 +       } else {
17487 +               ret = __remove_default(vxi, mode);
17488 +               if (ret < 0)
17489 +                       goto out;
17490 +       }
17491 +
17492 +out:
17493 +       return ret;
17494 +}
17495 +
17496 +
17497 +static inline int __user_device(const char __user *name, dev_t *dev,
17498 +       umode_t *mode)
17499 +{
17500 +       struct nameidata nd;
17501 +       int ret;
17502 +
17503 +       if (!name) {
17504 +               *dev = 0;
17505 +               return 0;
17506 +       }
17507 +       ret = user_lpath(name, &nd.path);
17508 +       if (ret)
17509 +               return ret;
17510 +       if (nd.path.dentry->d_inode) {
17511 +               *dev = nd.path.dentry->d_inode->i_rdev;
17512 +               *mode = nd.path.dentry->d_inode->i_mode;
17513 +       }
17514 +       path_put(&nd.path);
17515 +       return 0;
17516 +}
17517 +
17518 +static inline int __mapping_mode(dev_t device, dev_t target,
17519 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
17520 +{
17521 +       if (device)
17522 +               *mode = device_mode & S_IFMT;
17523 +       else if (target)
17524 +               *mode = target_mode & S_IFMT;
17525 +       else
17526 +               return -EINVAL;
17527 +
17528 +       /* if both given, device and target mode have to match */
17529 +       if (device && target &&
17530 +               ((device_mode ^ target_mode) & S_IFMT))
17531 +               return -EINVAL;
17532 +       return 0;
17533 +}
17534 +
17535 +
17536 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
17537 +       const char __user *target_path, int flags, int set)
17538 +{
17539 +       dev_t device = ~0, target = ~0;
17540 +       umode_t device_mode = 0, target_mode = 0, mode;
17541 +       int ret;
17542 +
17543 +       ret = __user_device(device_path, &device, &device_mode);
17544 +       if (ret)
17545 +               return ret;
17546 +       ret = __user_device(target_path, &target, &target_mode);
17547 +       if (ret)
17548 +               return ret;
17549 +
17550 +       ret = __mapping_mode(device, target,
17551 +               device_mode, target_mode, &mode);
17552 +       if (ret)
17553 +               return ret;
17554 +
17555 +       if (set)
17556 +               return do_set_mapping(vxi, device, target,
17557 +                       flags, mode);
17558 +       else
17559 +               return do_unset_mapping(vxi, device, target,
17560 +                       flags, mode);
17561 +}
17562 +
17563 +
17564 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
17565 +{
17566 +       struct vcmd_set_mapping_v0 vc_data;
17567 +
17568 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17569 +               return -EFAULT;
17570 +
17571 +       return do_mapping(vxi, vc_data.device, vc_data.target,
17572 +               vc_data.flags, 1);
17573 +}
17574 +
17575 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
17576 +{
17577 +       struct vcmd_set_mapping_v0 vc_data;
17578 +
17579 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17580 +               return -EFAULT;
17581 +
17582 +       return do_mapping(vxi, vc_data.device, vc_data.target,
17583 +               vc_data.flags, 0);
17584 +}
17585 +
17586 +
17587 +#ifdef CONFIG_COMPAT
17588 +
17589 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
17590 +{
17591 +       struct vcmd_set_mapping_v0_x32 vc_data;
17592 +
17593 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17594 +               return -EFAULT;
17595 +
17596 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
17597 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
17598 +}
17599 +
17600 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
17601 +{
17602 +       struct vcmd_set_mapping_v0_x32 vc_data;
17603 +
17604 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17605 +               return -EFAULT;
17606 +
17607 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
17608 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
17609 +}
17610 +
17611 +#endif /* CONFIG_COMPAT */
17612 +
17613 +
17614 diff -NurpP --minimal linux-3.10.33/kernel/vserver/dlimit.c linux-3.10.33-vs2.3.6.8/kernel/vserver/dlimit.c
17615 --- linux-3.10.33/kernel/vserver/dlimit.c       1970-01-01 00:00:00.000000000 +0000
17616 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/dlimit.c     2013-08-22 20:30:00.000000000 +0000
17617 @@ -0,0 +1,528 @@
17618 +/*
17619 + *  linux/kernel/vserver/dlimit.c
17620 + *
17621 + *  Virtual Server: Context Disk Limits
17622 + *
17623 + *  Copyright (C) 2004-2009  Herbert Pötzl
17624 + *
17625 + *  V0.01  initial version
17626 + *  V0.02  compat32 splitup
17627 + *  V0.03  extended interface
17628 + *
17629 + */
17630 +
17631 +#include <linux/statfs.h>
17632 +#include <linux/sched.h>
17633 +#include <linux/namei.h>
17634 +#include <linux/vs_tag.h>
17635 +#include <linux/vs_dlimit.h>
17636 +#include <linux/vserver/dlimit_cmd.h>
17637 +#include <linux/slab.h>
17638 +// #include <linux/gfp.h>
17639 +
17640 +#include <asm/uaccess.h>
17641 +
17642 +/*     __alloc_dl_info()
17643 +
17644 +       * allocate an initialized dl_info struct
17645 +       * doesn't make it visible (hash)                        */
17646 +
17647 +static struct dl_info *__alloc_dl_info(struct super_block *sb, vtag_t tag)
17648 +{
17649 +       struct dl_info *new = NULL;
17650 +
17651 +       vxdprintk(VXD_CBIT(dlim, 5),
17652 +               "alloc_dl_info(%p,%d)*", sb, tag);
17653 +
17654 +       /* would this benefit from a slab cache? */
17655 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
17656 +       if (!new)
17657 +               return 0;
17658 +
17659 +       memset(new, 0, sizeof(struct dl_info));
17660 +       new->dl_tag = tag;
17661 +       new->dl_sb = sb;
17662 +       // INIT_RCU_HEAD(&new->dl_rcu);
17663 +       INIT_HLIST_NODE(&new->dl_hlist);
17664 +       spin_lock_init(&new->dl_lock);
17665 +       atomic_set(&new->dl_refcnt, 0);
17666 +       atomic_set(&new->dl_usecnt, 0);
17667 +
17668 +       /* rest of init goes here */
17669 +
17670 +       vxdprintk(VXD_CBIT(dlim, 4),
17671 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
17672 +       return new;
17673 +}
17674 +
17675 +/*     __dealloc_dl_info()
17676 +
17677 +       * final disposal of dl_info                             */
17678 +
17679 +static void __dealloc_dl_info(struct dl_info *dli)
17680 +{
17681 +       vxdprintk(VXD_CBIT(dlim, 4),
17682 +               "dealloc_dl_info(%p)", dli);
17683 +
17684 +       dli->dl_hlist.next = LIST_POISON1;
17685 +       dli->dl_tag = -1;
17686 +       dli->dl_sb = 0;
17687 +
17688 +       BUG_ON(atomic_read(&dli->dl_usecnt));
17689 +       BUG_ON(atomic_read(&dli->dl_refcnt));
17690 +
17691 +       kfree(dli);
17692 +}
17693 +
17694 +
17695 +/*     hash table for dl_info hash */
17696 +
17697 +#define DL_HASH_SIZE   13
17698 +
17699 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
17700 +
17701 +static DEFINE_SPINLOCK(dl_info_hash_lock);
17702 +
17703 +
17704 +static inline unsigned int __hashval(struct super_block *sb, vtag_t tag)
17705 +{
17706 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
17707 +}
17708 +
17709 +
17710 +
17711 +/*     __hash_dl_info()
17712 +
17713 +       * add the dli to the global hash table
17714 +       * requires the hash_lock to be held                     */
17715 +
17716 +static inline void __hash_dl_info(struct dl_info *dli)
17717 +{
17718 +       struct hlist_head *head;
17719 +
17720 +       vxdprintk(VXD_CBIT(dlim, 6),
17721 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
17722 +       get_dl_info(dli);
17723 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
17724 +       hlist_add_head_rcu(&dli->dl_hlist, head);
17725 +}
17726 +
17727 +/*     __unhash_dl_info()
17728 +
17729 +       * remove the dli from the global hash table
17730 +       * requires the hash_lock to be held                     */
17731 +
17732 +static inline void __unhash_dl_info(struct dl_info *dli)
17733 +{
17734 +       vxdprintk(VXD_CBIT(dlim, 6),
17735 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
17736 +       hlist_del_rcu(&dli->dl_hlist);
17737 +       put_dl_info(dli);
17738 +}
17739 +
17740 +
17741 +/*     __lookup_dl_info()
17742 +
17743 +       * requires the rcu_read_lock()
17744 +       * doesn't increment the dl_refcnt                       */
17745 +
17746 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, vtag_t tag)
17747 +{
17748 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
17749 +       struct dl_info *dli;
17750 +
17751 +       hlist_for_each_entry_rcu(dli, head, dl_hlist) {
17752 +               if (dli->dl_tag == tag && dli->dl_sb == sb)
17753 +                       return dli;
17754 +       }
17755 +       return NULL;
17756 +}
17757 +
17758 +
17759 +struct dl_info *locate_dl_info(struct super_block *sb, vtag_t tag)
17760 +{
17761 +       struct dl_info *dli;
17762 +
17763 +       rcu_read_lock();
17764 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
17765 +       vxdprintk(VXD_CBIT(dlim, 7),
17766 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
17767 +       rcu_read_unlock();
17768 +       return dli;
17769 +}
17770 +
17771 +void rcu_free_dl_info(struct rcu_head *head)
17772 +{
17773 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
17774 +       int usecnt, refcnt;
17775 +
17776 +       BUG_ON(!dli || !head);
17777 +
17778 +       usecnt = atomic_read(&dli->dl_usecnt);
17779 +       BUG_ON(usecnt < 0);
17780 +
17781 +       refcnt = atomic_read(&dli->dl_refcnt);
17782 +       BUG_ON(refcnt < 0);
17783 +
17784 +       vxdprintk(VXD_CBIT(dlim, 3),
17785 +               "rcu_free_dl_info(%p)", dli);
17786 +       if (!usecnt)
17787 +               __dealloc_dl_info(dli);
17788 +       else
17789 +               printk("!!! rcu didn't free\n");
17790 +}
17791 +
17792 +
17793 +
17794 +
17795 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
17796 +       uint32_t flags, int add)
17797 +{
17798 +       struct path path;
17799 +       int ret;
17800 +
17801 +       ret = user_lpath(name, &path);
17802 +       if (!ret) {
17803 +               struct super_block *sb;
17804 +               struct dl_info *dli;
17805 +
17806 +               ret = -EINVAL;
17807 +               if (!path.dentry->d_inode)
17808 +                       goto out_release;
17809 +               if (!(sb = path.dentry->d_inode->i_sb))
17810 +                       goto out_release;
17811 +
17812 +               if (add) {
17813 +                       dli = __alloc_dl_info(sb, id);
17814 +                       spin_lock(&dl_info_hash_lock);
17815 +
17816 +                       ret = -EEXIST;
17817 +                       if (__lookup_dl_info(sb, id))
17818 +                               goto out_unlock;
17819 +                       __hash_dl_info(dli);
17820 +                       dli = NULL;
17821 +               } else {
17822 +                       spin_lock(&dl_info_hash_lock);
17823 +                       dli = __lookup_dl_info(sb, id);
17824 +
17825 +                       ret = -ESRCH;
17826 +                       if (!dli)
17827 +                               goto out_unlock;
17828 +                       __unhash_dl_info(dli);
17829 +               }
17830 +               ret = 0;
17831 +       out_unlock:
17832 +               spin_unlock(&dl_info_hash_lock);
17833 +               if (add && dli)
17834 +                       __dealloc_dl_info(dli);
17835 +       out_release:
17836 +               path_put(&path);
17837 +       }
17838 +       return ret;
17839 +}
17840 +
17841 +int vc_add_dlimit(uint32_t id, void __user *data)
17842 +{
17843 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
17844 +
17845 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17846 +               return -EFAULT;
17847 +
17848 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
17849 +}
17850 +
17851 +int vc_rem_dlimit(uint32_t id, void __user *data)
17852 +{
17853 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
17854 +
17855 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17856 +               return -EFAULT;
17857 +
17858 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
17859 +}
17860 +
17861 +#ifdef CONFIG_COMPAT
17862 +
17863 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
17864 +{
17865 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
17866 +
17867 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17868 +               return -EFAULT;
17869 +
17870 +       return do_addrem_dlimit(id,
17871 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
17872 +}
17873 +
17874 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
17875 +{
17876 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
17877 +
17878 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17879 +               return -EFAULT;
17880 +
17881 +       return do_addrem_dlimit(id,
17882 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
17883 +}
17884 +
17885 +#endif /* CONFIG_COMPAT */
17886 +
17887 +
17888 +static inline
17889 +int do_set_dlimit(uint32_t id, const char __user *name,
17890 +       uint32_t space_used, uint32_t space_total,
17891 +       uint32_t inodes_used, uint32_t inodes_total,
17892 +       uint32_t reserved, uint32_t flags)
17893 +{
17894 +       struct path path;
17895 +       int ret;
17896 +
17897 +       ret = user_lpath(name, &path);
17898 +       if (!ret) {
17899 +               struct super_block *sb;
17900 +               struct dl_info *dli;
17901 +
17902 +               ret = -EINVAL;
17903 +               if (!path.dentry->d_inode)
17904 +                       goto out_release;
17905 +               if (!(sb = path.dentry->d_inode->i_sb))
17906 +                       goto out_release;
17907 +
17908 +               /* sanity checks */
17909 +               if ((reserved != CDLIM_KEEP &&
17910 +                       reserved > 100) ||
17911 +                       (inodes_used != CDLIM_KEEP &&
17912 +                       inodes_used > inodes_total) ||
17913 +                       (space_used != CDLIM_KEEP &&
17914 +                       space_used > space_total))
17915 +                       goto out_release;
17916 +
17917 +               ret = -ESRCH;
17918 +               dli = locate_dl_info(sb, id);
17919 +               if (!dli)
17920 +                       goto out_release;
17921 +
17922 +               spin_lock(&dli->dl_lock);
17923 +
17924 +               if (inodes_used != CDLIM_KEEP)
17925 +                       dli->dl_inodes_used = inodes_used;
17926 +               if (inodes_total != CDLIM_KEEP)
17927 +                       dli->dl_inodes_total = inodes_total;
17928 +               if (space_used != CDLIM_KEEP)
17929 +                       dli->dl_space_used = dlimit_space_32to64(
17930 +                               space_used, flags, DLIMS_USED);
17931 +
17932 +               if (space_total == CDLIM_INFINITY)
17933 +                       dli->dl_space_total = DLIM_INFINITY;
17934 +               else if (space_total != CDLIM_KEEP)
17935 +                       dli->dl_space_total = dlimit_space_32to64(
17936 +                               space_total, flags, DLIMS_TOTAL);
17937 +
17938 +               if (reserved != CDLIM_KEEP)
17939 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
17940 +
17941 +               spin_unlock(&dli->dl_lock);
17942 +
17943 +               put_dl_info(dli);
17944 +               ret = 0;
17945 +
17946 +       out_release:
17947 +               path_put(&path);
17948 +       }
17949 +       return ret;
17950 +}
17951 +
17952 +int vc_set_dlimit(uint32_t id, void __user *data)
17953 +{
17954 +       struct vcmd_ctx_dlimit_v0 vc_data;
17955 +
17956 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17957 +               return -EFAULT;
17958 +
17959 +       return do_set_dlimit(id, vc_data.name,
17960 +               vc_data.space_used, vc_data.space_total,
17961 +               vc_data.inodes_used, vc_data.inodes_total,
17962 +               vc_data.reserved, vc_data.flags);
17963 +}
17964 +
17965 +#ifdef CONFIG_COMPAT
17966 +
17967 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
17968 +{
17969 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
17970 +
17971 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17972 +               return -EFAULT;
17973 +
17974 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
17975 +               vc_data.space_used, vc_data.space_total,
17976 +               vc_data.inodes_used, vc_data.inodes_total,
17977 +               vc_data.reserved, vc_data.flags);
17978 +}
17979 +
17980 +#endif /* CONFIG_COMPAT */
17981 +
17982 +
17983 +static inline
17984 +int do_get_dlimit(uint32_t id, const char __user *name,
17985 +       uint32_t *space_used, uint32_t *space_total,
17986 +       uint32_t *inodes_used, uint32_t *inodes_total,
17987 +       uint32_t *reserved, uint32_t *flags)
17988 +{
17989 +       struct path path;
17990 +       int ret;
17991 +
17992 +       ret = user_lpath(name, &path);
17993 +       if (!ret) {
17994 +               struct super_block *sb;
17995 +               struct dl_info *dli;
17996 +
17997 +               ret = -EINVAL;
17998 +               if (!path.dentry->d_inode)
17999 +                       goto out_release;
18000 +               if (!(sb = path.dentry->d_inode->i_sb))
18001 +                       goto out_release;
18002 +
18003 +               ret = -ESRCH;
18004 +               dli = locate_dl_info(sb, id);
18005 +               if (!dli)
18006 +                       goto out_release;
18007 +
18008 +               spin_lock(&dli->dl_lock);
18009 +               *inodes_used = dli->dl_inodes_used;
18010 +               *inodes_total = dli->dl_inodes_total;
18011 +
18012 +               *space_used = dlimit_space_64to32(
18013 +                       dli->dl_space_used, flags, DLIMS_USED);
18014 +
18015 +               if (dli->dl_space_total == DLIM_INFINITY)
18016 +                       *space_total = CDLIM_INFINITY;
18017 +               else
18018 +                       *space_total = dlimit_space_64to32(
18019 +                               dli->dl_space_total, flags, DLIMS_TOTAL);
18020 +
18021 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
18022 +               spin_unlock(&dli->dl_lock);
18023 +
18024 +               put_dl_info(dli);
18025 +               ret = -EFAULT;
18026 +
18027 +               ret = 0;
18028 +       out_release:
18029 +               path_put(&path);
18030 +       }
18031 +       return ret;
18032 +}
18033 +
18034 +
18035 +int vc_get_dlimit(uint32_t id, void __user *data)
18036 +{
18037 +       struct vcmd_ctx_dlimit_v0 vc_data;
18038 +       int ret;
18039 +
18040 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18041 +               return -EFAULT;
18042 +
18043 +       ret = do_get_dlimit(id, vc_data.name,
18044 +               &vc_data.space_used, &vc_data.space_total,
18045 +               &vc_data.inodes_used, &vc_data.inodes_total,
18046 +               &vc_data.reserved, &vc_data.flags);
18047 +       if (ret)
18048 +               return ret;
18049 +
18050 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18051 +               return -EFAULT;
18052 +       return 0;
18053 +}
18054 +
18055 +#ifdef CONFIG_COMPAT
18056 +
18057 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
18058 +{
18059 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18060 +       int ret;
18061 +
18062 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18063 +               return -EFAULT;
18064 +
18065 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
18066 +               &vc_data.space_used, &vc_data.space_total,
18067 +               &vc_data.inodes_used, &vc_data.inodes_total,
18068 +               &vc_data.reserved, &vc_data.flags);
18069 +       if (ret)
18070 +               return ret;
18071 +
18072 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18073 +               return -EFAULT;
18074 +       return 0;
18075 +}
18076 +
18077 +#endif /* CONFIG_COMPAT */
18078 +
18079 +
18080 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
18081 +{
18082 +       struct dl_info *dli;
18083 +       __u64 blimit, bfree, bavail;
18084 +       __u32 ifree;
18085 +
18086 +       dli = locate_dl_info(sb, dx_current_tag());
18087 +       if (!dli)
18088 +               return;
18089 +
18090 +       spin_lock(&dli->dl_lock);
18091 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
18092 +               goto no_ilim;
18093 +
18094 +       /* reduce max inodes available to limit */
18095 +       if (buf->f_files > dli->dl_inodes_total)
18096 +               buf->f_files = dli->dl_inodes_total;
18097 +
18098 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
18099 +       /* reduce free inodes to min */
18100 +       if (ifree < buf->f_ffree)
18101 +               buf->f_ffree = ifree;
18102 +
18103 +no_ilim:
18104 +       if (dli->dl_space_total == DLIM_INFINITY)
18105 +               goto no_blim;
18106 +
18107 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
18108 +
18109 +       if (dli->dl_space_total < dli->dl_space_used)
18110 +               bfree = 0;
18111 +       else
18112 +               bfree = (dli->dl_space_total - dli->dl_space_used)
18113 +                       >> sb->s_blocksize_bits;
18114 +
18115 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
18116 +       if (bavail < dli->dl_space_used)
18117 +               bavail = 0;
18118 +       else
18119 +               bavail = (bavail - dli->dl_space_used)
18120 +                       >> sb->s_blocksize_bits;
18121 +
18122 +       /* reduce max space available to limit */
18123 +       if (buf->f_blocks > blimit)
18124 +               buf->f_blocks = blimit;
18125 +
18126 +       /* reduce free space to min */
18127 +       if (bfree < buf->f_bfree)
18128 +               buf->f_bfree = bfree;
18129 +
18130 +       /* reduce avail space to min */
18131 +       if (bavail < buf->f_bavail)
18132 +               buf->f_bavail = bavail;
18133 +
18134 +no_blim:
18135 +       spin_unlock(&dli->dl_lock);
18136 +       put_dl_info(dli);
18137 +
18138 +       return;
18139 +}
18140 +
18141 +#include <linux/module.h>
18142 +
18143 +EXPORT_SYMBOL_GPL(locate_dl_info);
18144 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
18145 +
18146 diff -NurpP --minimal linux-3.10.33/kernel/vserver/helper.c linux-3.10.33-vs2.3.6.8/kernel/vserver/helper.c
18147 --- linux-3.10.33/kernel/vserver/helper.c       1970-01-01 00:00:00.000000000 +0000
18148 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/helper.c     2013-08-23 00:55:48.000000000 +0000
18149 @@ -0,0 +1,242 @@
18150 +/*
18151 + *  linux/kernel/vserver/helper.c
18152 + *
18153 + *  Virtual Context Support
18154 + *
18155 + *  Copyright (C) 2004-2007  Herbert Pötzl
18156 + *
18157 + *  V0.01  basic helper
18158 + *
18159 + */
18160 +
18161 +#include <linux/kmod.h>
18162 +#include <linux/reboot.h>
18163 +#include <linux/vs_context.h>
18164 +#include <linux/vs_network.h>
18165 +#include <linux/vserver/signal.h>
18166 +
18167 +
18168 +char vshelper_path[255] = "/sbin/vshelper";
18169 +
18170 +static int vshelper_init(struct subprocess_info *info, struct cred *new_cred)
18171 +{
18172 +       current->flags &= ~PF_NO_SETAFFINITY;
18173 +       return 0;
18174 +}
18175 +
18176 +static int vs_call_usermodehelper(char *path, char **argv, char **envp, int wait)
18177 +{
18178 +       struct subprocess_info *info;
18179 +       gfp_t gfp_mask = (wait == UMH_NO_WAIT) ? GFP_ATOMIC : GFP_KERNEL;
18180 +
18181 +       info = call_usermodehelper_setup(path, argv, envp, gfp_mask,
18182 +                                        vshelper_init, NULL, NULL);
18183 +       if (info == NULL)
18184 +               return -ENOMEM;
18185 +
18186 +       return call_usermodehelper_exec(info, wait);
18187 +}
18188 +
18189 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
18190 +{
18191 +       int ret;
18192 +
18193 +       if ((ret = vs_call_usermodehelper(name, argv, envp,
18194 +               sync ? UMH_WAIT_PROC : UMH_WAIT_EXEC))) {
18195 +               printk(KERN_WARNING "%s: (%s %s) returned %s with %d\n",
18196 +                       name, argv[1], argv[2],
18197 +                       sync ? "sync" : "async", ret);
18198 +       }
18199 +       vxdprintk(VXD_CBIT(switch, 4),
18200 +               "%s: (%s %s) returned %s with %d",
18201 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
18202 +       return ret;
18203 +}
18204 +
18205 +/*
18206 + *      vshelper path is set via /proc/sys
18207 + *      invoked by vserver sys_reboot(), with
18208 + *      the following arguments
18209 + *
18210 + *      argv [0] = vshelper_path;
18211 + *      argv [1] = action: "restart", "halt", "poweroff", ...
18212 + *      argv [2] = context identifier
18213 + *
18214 + *      envp [*] = type-specific parameters
18215 + */
18216 +
18217 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
18218 +{
18219 +       char id_buf[8], cmd_buf[16];
18220 +       char uid_buf[16], pid_buf[16];
18221 +       int ret;
18222 +
18223 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18224 +       char *envp[] = {"HOME=/", "TERM=linux",
18225 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
18226 +                       uid_buf, pid_buf, cmd_buf, 0};
18227 +
18228 +       if (vx_info_state(vxi, VXS_HELPER))
18229 +               return -EAGAIN;
18230 +       vxi->vx_state |= VXS_HELPER;
18231 +
18232 +       snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
18233 +
18234 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18235 +       snprintf(uid_buf, sizeof(uid_buf), "VS_UID=%d",
18236 +               from_kuid(&init_user_ns, current_uid()));
18237 +       snprintf(pid_buf, sizeof(pid_buf), "VS_PID=%d", current->pid);
18238 +
18239 +       switch (cmd) {
18240 +       case LINUX_REBOOT_CMD_RESTART:
18241 +               argv[1] = "restart";
18242 +               break;
18243 +
18244 +       case LINUX_REBOOT_CMD_HALT:
18245 +               argv[1] = "halt";
18246 +               break;
18247 +
18248 +       case LINUX_REBOOT_CMD_POWER_OFF:
18249 +               argv[1] = "poweroff";
18250 +               break;
18251 +
18252 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
18253 +               argv[1] = "swsusp";
18254 +               break;
18255 +
18256 +       case LINUX_REBOOT_CMD_OOM:
18257 +               argv[1] = "oom";
18258 +               break;
18259 +
18260 +       default:
18261 +               vxi->vx_state &= ~VXS_HELPER;
18262 +               return 0;
18263 +       }
18264 +
18265 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
18266 +       vxi->vx_state &= ~VXS_HELPER;
18267 +       __wakeup_vx_info(vxi);
18268 +       return (ret) ? -EPERM : 0;
18269 +}
18270 +
18271 +
18272 +long vs_reboot(unsigned int cmd, void __user *arg)
18273 +{
18274 +       struct vx_info *vxi = current_vx_info();
18275 +       long ret = 0;
18276 +
18277 +       vxdprintk(VXD_CBIT(misc, 5),
18278 +               "vs_reboot(%p[#%d],%u)",
18279 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18280 +
18281 +       ret = vs_reboot_helper(vxi, cmd, arg);
18282 +       if (ret)
18283 +               return ret;
18284 +
18285 +       vxi->reboot_cmd = cmd;
18286 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18287 +               switch (cmd) {
18288 +               case LINUX_REBOOT_CMD_RESTART:
18289 +               case LINUX_REBOOT_CMD_HALT:
18290 +               case LINUX_REBOOT_CMD_POWER_OFF:
18291 +                       vx_info_kill(vxi, 0, SIGKILL);
18292 +                       vx_info_kill(vxi, 1, SIGKILL);
18293 +               default:
18294 +                       break;
18295 +               }
18296 +       }
18297 +       return 0;
18298 +}
18299 +
18300 +long vs_oom_action(unsigned int cmd)
18301 +{
18302 +       struct vx_info *vxi = current_vx_info();
18303 +       long ret = 0;
18304 +
18305 +       vxdprintk(VXD_CBIT(misc, 5),
18306 +               "vs_oom_action(%p[#%d],%u)",
18307 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18308 +
18309 +       ret = vs_reboot_helper(vxi, cmd, NULL);
18310 +       if (ret)
18311 +               return ret;
18312 +
18313 +       vxi->reboot_cmd = cmd;
18314 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18315 +               vx_info_kill(vxi, 0, SIGKILL);
18316 +               vx_info_kill(vxi, 1, SIGKILL);
18317 +       }
18318 +       return 0;
18319 +}
18320 +
18321 +/*
18322 + *      argv [0] = vshelper_path;
18323 + *      argv [1] = action: "startup", "shutdown"
18324 + *      argv [2] = context identifier
18325 + *
18326 + *      envp [*] = type-specific parameters
18327 + */
18328 +
18329 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
18330 +{
18331 +       char id_buf[8], cmd_buf[16];
18332 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18333 +       char *envp[] = {"HOME=/", "TERM=linux",
18334 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18335 +
18336 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
18337 +               return 0;
18338 +
18339 +       snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
18340 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18341 +
18342 +       switch (cmd) {
18343 +       case VSC_STARTUP:
18344 +               argv[1] = "startup";
18345 +               break;
18346 +       case VSC_SHUTDOWN:
18347 +               argv[1] = "shutdown";
18348 +               break;
18349 +       default:
18350 +               return 0;
18351 +       }
18352 +
18353 +       return do_vshelper(vshelper_path, argv, envp, 1);
18354 +}
18355 +
18356 +
18357 +/*
18358 + *      argv [0] = vshelper_path;
18359 + *      argv [1] = action: "netup", "netdown"
18360 + *      argv [2] = context identifier
18361 + *
18362 + *      envp [*] = type-specific parameters
18363 + */
18364 +
18365 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
18366 +{
18367 +       char id_buf[8], cmd_buf[16];
18368 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18369 +       char *envp[] = {"HOME=/", "TERM=linux",
18370 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18371 +
18372 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
18373 +               return 0;
18374 +
18375 +       snprintf(id_buf, sizeof(id_buf), "%d", nxi->nx_id);
18376 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18377 +
18378 +       switch (cmd) {
18379 +       case VSC_NETUP:
18380 +               argv[1] = "netup";
18381 +               break;
18382 +       case VSC_NETDOWN:
18383 +               argv[1] = "netdown";
18384 +               break;
18385 +       default:
18386 +               return 0;
18387 +       }
18388 +
18389 +       return do_vshelper(vshelper_path, argv, envp, 1);
18390 +}
18391 +
18392 diff -NurpP --minimal linux-3.10.33/kernel/vserver/history.c linux-3.10.33-vs2.3.6.8/kernel/vserver/history.c
18393 --- linux-3.10.33/kernel/vserver/history.c      1970-01-01 00:00:00.000000000 +0000
18394 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/history.c    2013-08-22 20:30:00.000000000 +0000
18395 @@ -0,0 +1,258 @@
18396 +/*
18397 + *  kernel/vserver/history.c
18398 + *
18399 + *  Virtual Context History Backtrace
18400 + *
18401 + *  Copyright (C) 2004-2007  Herbert Pötzl
18402 + *
18403 + *  V0.01  basic structure
18404 + *  V0.02  hash/unhash and trace
18405 + *  V0.03  preemption fixes
18406 + *
18407 + */
18408 +
18409 +#include <linux/module.h>
18410 +#include <asm/uaccess.h>
18411 +
18412 +#include <linux/vserver/context.h>
18413 +#include <linux/vserver/debug.h>
18414 +#include <linux/vserver/debug_cmd.h>
18415 +#include <linux/vserver/history.h>
18416 +
18417 +
18418 +#ifdef CONFIG_VSERVER_HISTORY
18419 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
18420 +#else
18421 +#define VXH_SIZE       64
18422 +#endif
18423 +
18424 +struct _vx_history {
18425 +       unsigned int counter;
18426 +
18427 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
18428 +};
18429 +
18430 +
18431 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
18432 +
18433 +unsigned volatile int vxh_active = 1;
18434 +
18435 +static atomic_t sequence = ATOMIC_INIT(0);
18436 +
18437 +
18438 +/*     vxh_advance()
18439 +
18440 +       * requires disabled preemption                          */
18441 +
18442 +struct _vx_hist_entry *vxh_advance(void *loc)
18443 +{
18444 +       unsigned int cpu = smp_processor_id();
18445 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
18446 +       struct _vx_hist_entry *entry;
18447 +       unsigned int index;
18448 +
18449 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
18450 +       entry = &hist->entry[index];
18451 +
18452 +       entry->seq = atomic_inc_return(&sequence);
18453 +       entry->loc = loc;
18454 +       return entry;
18455 +}
18456 +
18457 +EXPORT_SYMBOL_GPL(vxh_advance);
18458 +
18459 +
18460 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
18461 +
18462 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
18463 +
18464 +
18465 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
18466 +
18467 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
18468 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
18469 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
18470 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
18471 +
18472 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
18473 +{
18474 +       switch (e->type) {
18475 +       case VXH_THROW_OOPS:
18476 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
18477 +               break;
18478 +
18479 +       case VXH_GET_VX_INFO:
18480 +       case VXH_PUT_VX_INFO:
18481 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
18482 +                       VXH_LOC_ARGS(e),
18483 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
18484 +                       VXH_VXI_ARGS(e));
18485 +               break;
18486 +
18487 +       case VXH_INIT_VX_INFO:
18488 +       case VXH_SET_VX_INFO:
18489 +       case VXH_CLR_VX_INFO:
18490 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
18491 +                       VXH_LOC_ARGS(e),
18492 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
18493 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
18494 +                       VXH_VXI_ARGS(e), e->sc.data);
18495 +               break;
18496 +
18497 +       case VXH_CLAIM_VX_INFO:
18498 +       case VXH_RELEASE_VX_INFO:
18499 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
18500 +                       VXH_LOC_ARGS(e),
18501 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
18502 +                       VXH_VXI_ARGS(e), e->sc.data);
18503 +               break;
18504 +
18505 +       case VXH_ALLOC_VX_INFO:
18506 +       case VXH_DEALLOC_VX_INFO:
18507 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
18508 +                       VXH_LOC_ARGS(e),
18509 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
18510 +                       VXH_VXI_ARGS(e));
18511 +               break;
18512 +
18513 +       case VXH_HASH_VX_INFO:
18514 +       case VXH_UNHASH_VX_INFO:
18515 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
18516 +                       VXH_LOC_ARGS(e),
18517 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
18518 +                       VXH_VXI_ARGS(e));
18519 +               break;
18520 +
18521 +       case VXH_LOC_VX_INFO:
18522 +       case VXH_LOOKUP_VX_INFO:
18523 +       case VXH_CREATE_VX_INFO:
18524 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
18525 +                       VXH_LOC_ARGS(e),
18526 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
18527 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
18528 +                       e->ll.arg, VXH_VXI_ARGS(e));
18529 +               break;
18530 +       }
18531 +}
18532 +
18533 +static void __vxh_dump_history(void)
18534 +{
18535 +       unsigned int i, cpu;
18536 +
18537 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
18538 +               atomic_read(&sequence), NR_CPUS);
18539 +
18540 +       for (i = 0; i < VXH_SIZE; i++) {
18541 +               for_each_online_cpu(cpu) {
18542 +                       struct _vx_history *hist =
18543 +                               &per_cpu(vx_history_buffer, cpu);
18544 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
18545 +                       struct _vx_hist_entry *entry = &hist->entry[index];
18546 +
18547 +                       vxh_dump_entry(entry, cpu);
18548 +               }
18549 +       }
18550 +}
18551 +
18552 +void   vxh_dump_history(void)
18553 +{
18554 +       vxh_active = 0;
18555 +#ifdef CONFIG_SMP
18556 +       local_irq_enable();
18557 +       smp_send_stop();
18558 +       local_irq_disable();
18559 +#endif
18560 +       __vxh_dump_history();
18561 +}
18562 +
18563 +
18564 +/* vserver syscall commands below here */
18565 +
18566 +
18567 +int vc_dump_history(uint32_t id)
18568 +{
18569 +       vxh_active = 0;
18570 +       __vxh_dump_history();
18571 +       vxh_active = 1;
18572 +
18573 +       return 0;
18574 +}
18575 +
18576 +
18577 +int do_read_history(struct __user _vx_hist_entry *data,
18578 +       int cpu, uint32_t *index, uint32_t *count)
18579 +{
18580 +       int pos, ret = 0;
18581 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
18582 +       int end = hist->counter;
18583 +       int start = end - VXH_SIZE + 2;
18584 +       int idx = *index;
18585 +
18586 +       /* special case: get current pos */
18587 +       if (!*count) {
18588 +               *index = end;
18589 +               return 0;
18590 +       }
18591 +
18592 +       /* have we lost some data? */
18593 +       if (idx < start)
18594 +               idx = start;
18595 +
18596 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
18597 +               struct _vx_hist_entry *entry =
18598 +                       &hist->entry[idx % VXH_SIZE];
18599 +
18600 +               /* send entry to userspace */
18601 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
18602 +               if (ret)
18603 +                       break;
18604 +       }
18605 +       /* save new index and count */
18606 +       *index = idx;
18607 +       *count = pos;
18608 +       return ret ? ret : (*index < end);
18609 +}
18610 +
18611 +int vc_read_history(uint32_t id, void __user *data)
18612 +{
18613 +       struct vcmd_read_history_v0 vc_data;
18614 +       int ret;
18615 +
18616 +       if (id >= NR_CPUS)
18617 +               return -EINVAL;
18618 +
18619 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18620 +               return -EFAULT;
18621 +
18622 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
18623 +               id, &vc_data.index, &vc_data.count);
18624 +
18625 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18626 +               return -EFAULT;
18627 +       return ret;
18628 +}
18629 +
18630 +#ifdef CONFIG_COMPAT
18631 +
18632 +int vc_read_history_x32(uint32_t id, void __user *data)
18633 +{
18634 +       struct vcmd_read_history_v0_x32 vc_data;
18635 +       int ret;
18636 +
18637 +       if (id >= NR_CPUS)
18638 +               return -EINVAL;
18639 +
18640 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18641 +               return -EFAULT;
18642 +
18643 +       ret = do_read_history((struct __user _vx_hist_entry *)
18644 +               compat_ptr(vc_data.data_ptr),
18645 +               id, &vc_data.index, &vc_data.count);
18646 +
18647 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18648 +               return -EFAULT;
18649 +       return ret;
18650 +}
18651 +
18652 +#endif /* CONFIG_COMPAT */
18653 +
18654 diff -NurpP --minimal linux-3.10.33/kernel/vserver/inet.c linux-3.10.33-vs2.3.6.8/kernel/vserver/inet.c
18655 --- linux-3.10.33/kernel/vserver/inet.c 1970-01-01 00:00:00.000000000 +0000
18656 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/inet.c       2013-08-22 20:30:00.000000000 +0000
18657 @@ -0,0 +1,236 @@
18658 +
18659 +#include <linux/in.h>
18660 +#include <linux/inetdevice.h>
18661 +#include <linux/export.h>
18662 +#include <linux/vs_inet.h>
18663 +#include <linux/vs_inet6.h>
18664 +#include <linux/vserver/debug.h>
18665 +#include <net/route.h>
18666 +#include <net/addrconf.h>
18667 +
18668 +
18669 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
18670 +{
18671 +       int ret = 0;
18672 +
18673 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
18674 +               ret = 1;
18675 +       else {
18676 +               struct nx_addr_v4 *ptr;
18677 +               unsigned long irqflags;
18678 +
18679 +               spin_lock_irqsave(&nxi1->addr_lock, irqflags);
18680 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
18681 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
18682 +                               ret = 1;
18683 +                               break;
18684 +                       }
18685 +               }
18686 +               spin_unlock_irqrestore(&nxi1->addr_lock, irqflags);
18687 +       }
18688 +
18689 +       vxdprintk(VXD_CBIT(net, 2),
18690 +               "nx_v4_addr_conflict(%p,%p): %d",
18691 +               nxi1, nxi2, ret);
18692 +
18693 +       return ret;
18694 +}
18695 +
18696 +
18697 +#ifdef CONFIG_IPV6
18698 +
18699 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
18700 +{
18701 +       int ret = 0;
18702 +
18703 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
18704 +               ret = 1;
18705 +       else {
18706 +               struct nx_addr_v6 *ptr;
18707 +               unsigned long irqflags;
18708 +
18709 +               spin_lock_irqsave(&nxi1->addr_lock, irqflags);
18710 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
18711 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
18712 +                               ret = 1;
18713 +                               break;
18714 +                       }
18715 +               }
18716 +               spin_unlock_irqrestore(&nxi1->addr_lock, irqflags);
18717 +       }
18718 +
18719 +       vxdprintk(VXD_CBIT(net, 2),
18720 +               "nx_v6_addr_conflict(%p,%p): %d",
18721 +               nxi1, nxi2, ret);
18722 +
18723 +       return ret;
18724 +}
18725 +
18726 +#endif
18727 +
18728 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18729 +{
18730 +       struct in_device *in_dev;
18731 +       struct in_ifaddr **ifap;
18732 +       struct in_ifaddr *ifa;
18733 +       int ret = 0;
18734 +
18735 +       if (!dev)
18736 +               goto out;
18737 +       in_dev = in_dev_get(dev);
18738 +       if (!in_dev)
18739 +               goto out;
18740 +
18741 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
18742 +               ifap = &ifa->ifa_next) {
18743 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
18744 +                       ret = 1;
18745 +                       break;
18746 +               }
18747 +       }
18748 +       in_dev_put(in_dev);
18749 +out:
18750 +       return ret;
18751 +}
18752 +
18753 +
18754 +#ifdef CONFIG_IPV6
18755 +
18756 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18757 +{
18758 +       struct inet6_dev *in_dev;
18759 +       struct inet6_ifaddr *ifa;
18760 +       int ret = 0;
18761 +
18762 +       if (!dev)
18763 +               goto out;
18764 +       in_dev = in6_dev_get(dev);
18765 +       if (!in_dev)
18766 +               goto out;
18767 +
18768 +       // for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
18769 +       list_for_each_entry(ifa, &in_dev->addr_list, if_list) {
18770 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
18771 +                       ret = 1;
18772 +                       break;
18773 +               }
18774 +       }
18775 +       in6_dev_put(in_dev);
18776 +out:
18777 +       return ret;
18778 +}
18779 +
18780 +#endif
18781 +
18782 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18783 +{
18784 +       int ret = 1;
18785 +
18786 +       if (!nxi)
18787 +               goto out;
18788 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
18789 +               goto out;
18790 +#ifdef CONFIG_IPV6
18791 +       ret = 2;
18792 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
18793 +               goto out;
18794 +#endif
18795 +       ret = 0;
18796 +out:
18797 +       vxdprintk(VXD_CBIT(net, 3),
18798 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
18799 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
18800 +       return ret;
18801 +}
18802 +
18803 +struct rtable *ip_v4_find_src(struct net *net, struct nx_info *nxi,
18804 +       struct flowi4 *fl4)
18805 +{
18806 +       struct rtable *rt;
18807 +
18808 +       if (!nxi)
18809 +               return NULL;
18810 +
18811 +       /* FIXME: handle lback only case */
18812 +       if (!NX_IPV4(nxi))
18813 +               return ERR_PTR(-EPERM);
18814 +
18815 +       vxdprintk(VXD_CBIT(net, 4),
18816 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
18817 +               nxi, nxi ? nxi->nx_id : 0,
18818 +               NIPQUAD(fl4->saddr), NIPQUAD(fl4->daddr));
18819 +
18820 +       /* single IP is unconditional */
18821 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
18822 +               (fl4->saddr == INADDR_ANY))
18823 +               fl4->saddr = nxi->v4.ip[0].s_addr;
18824 +
18825 +       if (fl4->saddr == INADDR_ANY) {
18826 +               struct nx_addr_v4 *ptr;
18827 +               __be32 found = 0;
18828 +
18829 +               rt = __ip_route_output_key(net, fl4);
18830 +               if (!IS_ERR(rt)) {
18831 +                       found = fl4->saddr;
18832 +                       ip_rt_put(rt);
18833 +                       vxdprintk(VXD_CBIT(net, 4),
18834 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
18835 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(found));
18836 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
18837 +                               goto found;
18838 +               }
18839 +
18840 +               WARN_ON_ONCE(in_irq());
18841 +               spin_lock_bh(&nxi->addr_lock);
18842 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
18843 +                       __be32 primary = ptr->ip[0].s_addr;
18844 +                       __be32 mask = ptr->mask.s_addr;
18845 +                       __be32 neta = primary & mask;
18846 +
18847 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
18848 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
18849 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
18850 +                               NIPQUAD(mask), NIPQUAD(neta));
18851 +                       if ((found & mask) != neta)
18852 +                               continue;
18853 +
18854 +                       fl4->saddr = primary;
18855 +                       rt = __ip_route_output_key(net, fl4);
18856 +                       vxdprintk(VXD_CBIT(net, 4),
18857 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
18858 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(primary));
18859 +                       if (!IS_ERR(rt)) {
18860 +                               found = fl4->saddr;
18861 +                               ip_rt_put(rt);
18862 +                               if (found == primary)
18863 +                                       goto found_unlock;
18864 +                       }
18865 +               }
18866 +               /* still no source ip? */
18867 +               found = ipv4_is_loopback(fl4->daddr)
18868 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
18869 +       found_unlock:
18870 +               spin_unlock_bh(&nxi->addr_lock);
18871 +       found:
18872 +               /* assign src ip to flow */
18873 +               fl4->saddr = found;
18874 +
18875 +       } else {
18876 +               if (!v4_addr_in_nx_info(nxi, fl4->saddr, NXA_MASK_BIND))
18877 +                       return ERR_PTR(-EPERM);
18878 +       }
18879 +
18880 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
18881 +               if (ipv4_is_loopback(fl4->daddr))
18882 +                       fl4->daddr = nxi->v4_lback.s_addr;
18883 +               if (ipv4_is_loopback(fl4->saddr))
18884 +                       fl4->saddr = nxi->v4_lback.s_addr;
18885 +       } else if (ipv4_is_loopback(fl4->daddr) &&
18886 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
18887 +               return ERR_PTR(-EPERM);
18888 +
18889 +       return NULL;
18890 +}
18891 +
18892 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
18893 +
18894 diff -NurpP --minimal linux-3.10.33/kernel/vserver/init.c linux-3.10.33-vs2.3.6.8/kernel/vserver/init.c
18895 --- linux-3.10.33/kernel/vserver/init.c 1970-01-01 00:00:00.000000000 +0000
18896 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/init.c       2013-08-22 20:30:00.000000000 +0000
18897 @@ -0,0 +1,45 @@
18898 +/*
18899 + *  linux/kernel/init.c
18900 + *
18901 + *  Virtual Server Init
18902 + *
18903 + *  Copyright (C) 2004-2007  Herbert Pötzl
18904 + *
18905 + *  V0.01  basic structure
18906 + *
18907 + */
18908 +
18909 +#include <linux/init.h>
18910 +
18911 +int    vserver_register_sysctl(void);
18912 +void   vserver_unregister_sysctl(void);
18913 +
18914 +
18915 +static int __init init_vserver(void)
18916 +{
18917 +       int ret = 0;
18918 +
18919 +#ifdef CONFIG_VSERVER_DEBUG
18920 +       vserver_register_sysctl();
18921 +#endif
18922 +       return ret;
18923 +}
18924 +
18925 +
18926 +static void __exit exit_vserver(void)
18927 +{
18928 +
18929 +#ifdef CONFIG_VSERVER_DEBUG
18930 +       vserver_unregister_sysctl();
18931 +#endif
18932 +       return;
18933 +}
18934 +
18935 +/* FIXME: GFP_ZONETYPES gone
18936 +long vx_slab[GFP_ZONETYPES]; */
18937 +long vx_area;
18938 +
18939 +
18940 +module_init(init_vserver);
18941 +module_exit(exit_vserver);
18942 +
18943 diff -NurpP --minimal linux-3.10.33/kernel/vserver/inode.c linux-3.10.33-vs2.3.6.8/kernel/vserver/inode.c
18944 --- linux-3.10.33/kernel/vserver/inode.c        1970-01-01 00:00:00.000000000 +0000
18945 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/inode.c      2013-08-22 23:14:01.000000000 +0000
18946 @@ -0,0 +1,440 @@
18947 +/*
18948 + *  linux/kernel/vserver/inode.c
18949 + *
18950 + *  Virtual Server: File System Support
18951 + *
18952 + *  Copyright (C) 2004-2007  Herbert Pötzl
18953 + *
18954 + *  V0.01  separated from vcontext V0.05
18955 + *  V0.02  moved to tag (instead of xid)
18956 + *
18957 + */
18958 +
18959 +#include <linux/tty.h>
18960 +#include <linux/proc_fs.h>
18961 +#include <linux/devpts_fs.h>
18962 +#include <linux/fs.h>
18963 +#include <linux/file.h>
18964 +#include <linux/mount.h>
18965 +#include <linux/parser.h>
18966 +#include <linux/namei.h>
18967 +#include <linux/magic.h>
18968 +#include <linux/slab.h>
18969 +#include <linux/vserver/inode.h>
18970 +#include <linux/vserver/inode_cmd.h>
18971 +#include <linux/vs_base.h>
18972 +#include <linux/vs_tag.h>
18973 +
18974 +#include <asm/uaccess.h>
18975 +#include <../../fs/proc/internal.h>
18976 +
18977 +
18978 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
18979 +{
18980 +       struct proc_dir_entry *entry;
18981 +
18982 +       if (!in || !in->i_sb)
18983 +               return -ESRCH;
18984 +
18985 +       *flags = IATTR_TAG
18986 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
18987 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
18988 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
18989 +               | (IS_COW(in) ? IATTR_COW : 0);
18990 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
18991 +
18992 +       if (S_ISDIR(in->i_mode))
18993 +               *mask |= IATTR_BARRIER;
18994 +
18995 +       if (IS_TAGGED(in)) {
18996 +               *tag = i_tag_read(in);
18997 +               *mask |= IATTR_TAG;
18998 +       }
18999 +
19000 +       switch (in->i_sb->s_magic) {
19001 +       case PROC_SUPER_MAGIC:
19002 +               entry = PROC_I(in)->pde;
19003 +
19004 +               /* check for specific inodes? */
19005 +               if (entry)
19006 +                       *mask |= IATTR_FLAGS;
19007 +               if (entry)
19008 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
19009 +               else
19010 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
19011 +               break;
19012 +
19013 +       case DEVPTS_SUPER_MAGIC:
19014 +               *tag = i_tag_read(in);
19015 +               *mask |= IATTR_TAG;
19016 +               break;
19017 +
19018 +       default:
19019 +               break;
19020 +       }
19021 +       return 0;
19022 +}
19023 +
19024 +int vc_get_iattr(void __user *data)
19025 +{
19026 +       struct path path;
19027 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
19028 +       int ret;
19029 +
19030 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19031 +               return -EFAULT;
19032 +
19033 +       ret = user_lpath(vc_data.name, &path);
19034 +       if (!ret) {
19035 +               ret = __vc_get_iattr(path.dentry->d_inode,
19036 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19037 +               path_put(&path);
19038 +       }
19039 +       if (ret)
19040 +               return ret;
19041 +
19042 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19043 +               ret = -EFAULT;
19044 +       return ret;
19045 +}
19046 +
19047 +#ifdef CONFIG_COMPAT
19048 +
19049 +int vc_get_iattr_x32(void __user *data)
19050 +{
19051 +       struct path path;
19052 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
19053 +       int ret;
19054 +
19055 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19056 +               return -EFAULT;
19057 +
19058 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19059 +       if (!ret) {
19060 +               ret = __vc_get_iattr(path.dentry->d_inode,
19061 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19062 +               path_put(&path);
19063 +       }
19064 +       if (ret)
19065 +               return ret;
19066 +
19067 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19068 +               ret = -EFAULT;
19069 +       return ret;
19070 +}
19071 +
19072 +#endif /* CONFIG_COMPAT */
19073 +
19074 +
19075 +int vc_fget_iattr(uint32_t fd, void __user *data)
19076 +{
19077 +       struct file *filp;
19078 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
19079 +       int ret;
19080 +
19081 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19082 +               return -EFAULT;
19083 +
19084 +       filp = fget(fd);
19085 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19086 +               return -EBADF;
19087 +
19088 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
19089 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
19090 +
19091 +       fput(filp);
19092 +
19093 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19094 +               ret = -EFAULT;
19095 +       return ret;
19096 +}
19097 +
19098 +
19099 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19100 +{
19101 +       struct inode *in = de->d_inode;
19102 +       int error = 0, is_proc = 0, has_tag = 0;
19103 +       struct iattr attr = { 0 };
19104 +
19105 +       if (!in || !in->i_sb)
19106 +               return -ESRCH;
19107 +
19108 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
19109 +       if ((*mask & IATTR_FLAGS) && !is_proc)
19110 +               return -EINVAL;
19111 +
19112 +       has_tag = IS_TAGGED(in) ||
19113 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
19114 +       if ((*mask & IATTR_TAG) && !has_tag)
19115 +               return -EINVAL;
19116 +
19117 +       mutex_lock(&in->i_mutex);
19118 +       if (*mask & IATTR_TAG) {
19119 +               attr.ia_tag = make_ktag(&init_user_ns, *tag);
19120 +               attr.ia_valid |= ATTR_TAG;
19121 +       }
19122 +
19123 +       if (*mask & IATTR_FLAGS) {
19124 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
19125 +               unsigned int iflags = PROC_I(in)->vx_flags;
19126 +
19127 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
19128 +                       | (*flags & IATTR_FLAGS);
19129 +               PROC_I(in)->vx_flags = iflags;
19130 +               if (entry)
19131 +                       entry->vx_flags = iflags;
19132 +       }
19133 +
19134 +       if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
19135 +               IATTR_BARRIER | IATTR_COW)) {
19136 +               int iflags = in->i_flags;
19137 +               int vflags = in->i_vflags;
19138 +
19139 +               if (*mask & IATTR_IMMUTABLE) {
19140 +                       if (*flags & IATTR_IMMUTABLE)
19141 +                               iflags |= S_IMMUTABLE;
19142 +                       else
19143 +                               iflags &= ~S_IMMUTABLE;
19144 +               }
19145 +               if (*mask & IATTR_IXUNLINK) {
19146 +                       if (*flags & IATTR_IXUNLINK)
19147 +                               iflags |= S_IXUNLINK;
19148 +                       else
19149 +                               iflags &= ~S_IXUNLINK;
19150 +               }
19151 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
19152 +                       if (*flags & IATTR_BARRIER)
19153 +                               vflags |= V_BARRIER;
19154 +                       else
19155 +                               vflags &= ~V_BARRIER;
19156 +               }
19157 +               if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
19158 +                       if (*flags & IATTR_COW)
19159 +                               vflags |= V_COW;
19160 +                       else
19161 +                               vflags &= ~V_COW;
19162 +               }
19163 +               if (in->i_op && in->i_op->sync_flags) {
19164 +                       error = in->i_op->sync_flags(in, iflags, vflags);
19165 +                       if (error)
19166 +                               goto out;
19167 +               }
19168 +       }
19169 +
19170 +       if (attr.ia_valid) {
19171 +               if (in->i_op && in->i_op->setattr)
19172 +                       error = in->i_op->setattr(de, &attr);
19173 +               else {
19174 +                       error = inode_change_ok(in, &attr);
19175 +                       if (!error) {
19176 +                               setattr_copy(in, &attr);
19177 +                               mark_inode_dirty(in);
19178 +                       }
19179 +               }
19180 +       }
19181 +
19182 +out:
19183 +       mutex_unlock(&in->i_mutex);
19184 +       return error;
19185 +}
19186 +
19187 +int vc_set_iattr(void __user *data)
19188 +{
19189 +       struct path path;
19190 +       struct vcmd_ctx_iattr_v1 vc_data;
19191 +       int ret;
19192 +
19193 +       if (!capable(CAP_LINUX_IMMUTABLE))
19194 +               return -EPERM;
19195 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19196 +               return -EFAULT;
19197 +
19198 +       ret = user_lpath(vc_data.name, &path);
19199 +       if (!ret) {
19200 +               ret = __vc_set_iattr(path.dentry,
19201 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19202 +               path_put(&path);
19203 +       }
19204 +
19205 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19206 +               ret = -EFAULT;
19207 +       return ret;
19208 +}
19209 +
19210 +#ifdef CONFIG_COMPAT
19211 +
19212 +int vc_set_iattr_x32(void __user *data)
19213 +{
19214 +       struct path path;
19215 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
19216 +       int ret;
19217 +
19218 +       if (!capable(CAP_LINUX_IMMUTABLE))
19219 +               return -EPERM;
19220 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19221 +               return -EFAULT;
19222 +
19223 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19224 +       if (!ret) {
19225 +               ret = __vc_set_iattr(path.dentry,
19226 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19227 +               path_put(&path);
19228 +       }
19229 +
19230 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19231 +               ret = -EFAULT;
19232 +       return ret;
19233 +}
19234 +
19235 +#endif /* CONFIG_COMPAT */
19236 +
19237 +int vc_fset_iattr(uint32_t fd, void __user *data)
19238 +{
19239 +       struct file *filp;
19240 +       struct vcmd_ctx_fiattr_v0 vc_data;
19241 +       int ret;
19242 +
19243 +       if (!capable(CAP_LINUX_IMMUTABLE))
19244 +               return -EPERM;
19245 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19246 +               return -EFAULT;
19247 +
19248 +       filp = fget(fd);
19249 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19250 +               return -EBADF;
19251 +
19252 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
19253 +               &vc_data.flags, &vc_data.mask);
19254 +
19255 +       fput(filp);
19256 +
19257 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19258 +               return -EFAULT;
19259 +       return ret;
19260 +}
19261 +
19262 +
19263 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
19264 +
19265 +static match_table_t tokens = {
19266 +       {Opt_notagcheck, "notagcheck"},
19267 +#ifdef CONFIG_PROPAGATE
19268 +       {Opt_notag, "notag"},
19269 +       {Opt_tag, "tag"},
19270 +       {Opt_tagid, "tagid=%u"},
19271 +#endif
19272 +       {Opt_err, NULL}
19273 +};
19274 +
19275 +
19276 +static void __dx_parse_remove(char *string, char *opt)
19277 +{
19278 +       char *p = strstr(string, opt);
19279 +       char *q = p;
19280 +
19281 +       if (p) {
19282 +               while (*q != '\0' && *q != ',')
19283 +                       q++;
19284 +               while (*q)
19285 +                       *p++ = *q++;
19286 +               while (*p)
19287 +                       *p++ = '\0';
19288 +       }
19289 +}
19290 +
19291 +int dx_parse_tag(char *string, vtag_t *tag, int remove, int *mnt_flags,
19292 +                unsigned long *flags)
19293 +{
19294 +       int set = 0;
19295 +       substring_t args[MAX_OPT_ARGS];
19296 +       int token;
19297 +       char *s, *p, *opts;
19298 +#if defined(CONFIG_PROPAGATE) || defined(CONFIG_VSERVER_DEBUG)
19299 +       int option = 0;
19300 +#endif
19301 +
19302 +       if (!string)
19303 +               return 0;
19304 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
19305 +       if (!s)
19306 +               return 0;
19307 +
19308 +       opts = s;
19309 +       while ((p = strsep(&opts, ",")) != NULL) {
19310 +               token = match_token(p, tokens, args);
19311 +
19312 +               switch (token) {
19313 +#ifdef CONFIG_PROPAGATE
19314 +               case Opt_tag:
19315 +                       if (tag)
19316 +                               *tag = 0;
19317 +                       if (remove)
19318 +                               __dx_parse_remove(s, "tag");
19319 +                       *mnt_flags |= MNT_TAGID;
19320 +                       set |= MNT_TAGID;
19321 +                       break;
19322 +               case Opt_notag:
19323 +                       if (remove)
19324 +                               __dx_parse_remove(s, "notag");
19325 +                       *mnt_flags |= MNT_NOTAG;
19326 +                       set |= MNT_NOTAG;
19327 +                       break;
19328 +               case Opt_tagid:
19329 +                       if (tag && !match_int(args, &option))
19330 +                               *tag = option;
19331 +                       if (remove)
19332 +                               __dx_parse_remove(s, "tagid");
19333 +                       *mnt_flags |= MNT_TAGID;
19334 +                       set |= MNT_TAGID;
19335 +                       break;
19336 +#endif /* CONFIG_PROPAGATE */
19337 +               case Opt_notagcheck:
19338 +                       if (remove)
19339 +                               __dx_parse_remove(s, "notagcheck");
19340 +                       *flags |= MS_NOTAGCHECK;
19341 +                       set |= MS_NOTAGCHECK;
19342 +                       break;
19343 +               }
19344 +               vxdprintk(VXD_CBIT(tag, 7),
19345 +                       "dx_parse_tag(" VS_Q("%s") "): %d:#%d",
19346 +                       p, token, option);
19347 +       }
19348 +       if (set)
19349 +               strcpy(string, s);
19350 +       kfree(s);
19351 +       return set;
19352 +}
19353 +
19354 +#ifdef CONFIG_PROPAGATE
19355 +
19356 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
19357 +{
19358 +       vtag_t new_tag = 0;
19359 +       struct vfsmount *mnt;
19360 +       int propagate;
19361 +
19362 +       if (!nd)
19363 +               return;
19364 +       mnt = nd->path.mnt;
19365 +       if (!mnt)
19366 +               return;
19367 +
19368 +       propagate = (mnt->mnt_flags & MNT_TAGID);
19369 +       if (propagate)
19370 +               new_tag = mnt->mnt_tag;
19371 +
19372 +       vxdprintk(VXD_CBIT(tag, 7),
19373 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
19374 +               inode, inode->i_ino, inode->i_tag,
19375 +               new_tag, (propagate) ? 1 : 0);
19376 +
19377 +       if (propagate)
19378 +               i_tag_write(inode, new_tag);
19379 +}
19380 +
19381 +#include <linux/module.h>
19382 +
19383 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
19384 +
19385 +#endif /* CONFIG_PROPAGATE */
19386 +
19387 diff -NurpP --minimal linux-3.10.33/kernel/vserver/limit.c linux-3.10.33-vs2.3.6.8/kernel/vserver/limit.c
19388 --- linux-3.10.33/kernel/vserver/limit.c        1970-01-01 00:00:00.000000000 +0000
19389 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/limit.c      2013-08-22 20:30:00.000000000 +0000
19390 @@ -0,0 +1,345 @@
19391 +/*
19392 + *  linux/kernel/vserver/limit.c
19393 + *
19394 + *  Virtual Server: Context Limits
19395 + *
19396 + *  Copyright (C) 2004-2010  Herbert Pötzl
19397 + *
19398 + *  V0.01  broken out from vcontext V0.05
19399 + *  V0.02  changed vcmds to vxi arg
19400 + *  V0.03  added memory cgroup support
19401 + *
19402 + */
19403 +
19404 +#include <linux/sched.h>
19405 +#include <linux/module.h>
19406 +#include <linux/memcontrol.h>
19407 +#include <linux/res_counter.h>
19408 +#include <linux/vs_limit.h>
19409 +#include <linux/vserver/limit.h>
19410 +#include <linux/vserver/limit_cmd.h>
19411 +
19412 +#include <asm/uaccess.h>
19413 +
19414 +
19415 +const char *vlimit_name[NUM_LIMITS] = {
19416 +       [RLIMIT_CPU]            = "CPU",
19417 +       [RLIMIT_NPROC]          = "NPROC",
19418 +       [RLIMIT_NOFILE]         = "NOFILE",
19419 +       [RLIMIT_LOCKS]          = "LOCKS",
19420 +       [RLIMIT_SIGPENDING]     = "SIGP",
19421 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
19422 +
19423 +       [VLIMIT_NSOCK]          = "NSOCK",
19424 +       [VLIMIT_OPENFD]         = "OPENFD",
19425 +       [VLIMIT_SHMEM]          = "SHMEM",
19426 +       [VLIMIT_DENTRY]         = "DENTRY",
19427 +};
19428 +
19429 +EXPORT_SYMBOL_GPL(vlimit_name);
19430 +
19431 +#define MASK_ENTRY(x)  (1 << (x))
19432 +
19433 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
19434 +               /* minimum */
19435 +       0
19436 +       ,       /* softlimit */
19437 +       0
19438 +       ,       /* maximum */
19439 +       MASK_ENTRY( RLIMIT_NPROC        ) |
19440 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
19441 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
19442 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
19443 +
19444 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
19445 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
19446 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
19447 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
19448 +       0
19449 +};
19450 +               /* accounting only */
19451 +uint32_t account_mask =
19452 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
19453 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
19454 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
19455 +       0;
19456 +
19457 +
19458 +static int is_valid_vlimit(int id)
19459 +{
19460 +       uint32_t mask = vlimit_mask.minimum |
19461 +               vlimit_mask.softlimit | vlimit_mask.maximum;
19462 +       return mask & (1 << id);
19463 +}
19464 +
19465 +static int is_accounted_vlimit(int id)
19466 +{
19467 +       if (is_valid_vlimit(id))
19468 +               return 1;
19469 +       return account_mask & (1 << id);
19470 +}
19471 +
19472 +
19473 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
19474 +{
19475 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
19476 +       return VX_VLIM(limit);
19477 +}
19478 +
19479 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
19480 +{
19481 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
19482 +       return VX_VLIM(limit);
19483 +}
19484 +
19485 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
19486 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
19487 +{
19488 +       if (!is_valid_vlimit(id))
19489 +               return -EINVAL;
19490 +
19491 +       if (minimum)
19492 +               *minimum = CRLIM_UNSET;
19493 +       if (softlimit)
19494 +               *softlimit = vc_get_soft(vxi, id);
19495 +       if (maximum)
19496 +               *maximum = vc_get_hard(vxi, id);
19497 +       return 0;
19498 +}
19499 +
19500 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
19501 +{
19502 +       struct vcmd_ctx_rlimit_v0 vc_data;
19503 +       int ret;
19504 +
19505 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19506 +               return -EFAULT;
19507 +
19508 +       ret = do_get_rlimit(vxi, vc_data.id,
19509 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
19510 +       if (ret)
19511 +               return ret;
19512 +
19513 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19514 +               return -EFAULT;
19515 +       return 0;
19516 +}
19517 +
19518 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
19519 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
19520 +{
19521 +       if (!is_valid_vlimit(id))
19522 +               return -EINVAL;
19523 +
19524 +       if (maximum != CRLIM_KEEP)
19525 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
19526 +       if (softlimit != CRLIM_KEEP)
19527 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
19528 +
19529 +       /* clamp soft limit */
19530 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
19531 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
19532 +
19533 +       return 0;
19534 +}
19535 +
19536 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
19537 +{
19538 +       struct vcmd_ctx_rlimit_v0 vc_data;
19539 +
19540 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19541 +               return -EFAULT;
19542 +
19543 +       return do_set_rlimit(vxi, vc_data.id,
19544 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
19545 +}
19546 +
19547 +#ifdef CONFIG_IA32_EMULATION
19548 +
19549 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
19550 +{
19551 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
19552 +
19553 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19554 +               return -EFAULT;
19555 +
19556 +       return do_set_rlimit(vxi, vc_data.id,
19557 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
19558 +}
19559 +
19560 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
19561 +{
19562 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
19563 +       int ret;
19564 +
19565 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19566 +               return -EFAULT;
19567 +
19568 +       ret = do_get_rlimit(vxi, vc_data.id,
19569 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
19570 +       if (ret)
19571 +               return ret;
19572 +
19573 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19574 +               return -EFAULT;
19575 +       return 0;
19576 +}
19577 +
19578 +#endif /* CONFIG_IA32_EMULATION */
19579 +
19580 +
19581 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
19582 +{
19583 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
19584 +               return -EFAULT;
19585 +       return 0;
19586 +}
19587 +
19588 +
19589 +static inline void vx_reset_hits(struct _vx_limit *limit)
19590 +{
19591 +       int lim;
19592 +
19593 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19594 +               atomic_set(&__rlim_lhit(limit, lim), 0);
19595 +       }
19596 +}
19597 +
19598 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
19599 +{
19600 +       vx_reset_hits(&vxi->limit);
19601 +       return 0;
19602 +}
19603 +
19604 +static inline void vx_reset_minmax(struct _vx_limit *limit)
19605 +{
19606 +       rlim_t value;
19607 +       int lim;
19608 +
19609 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19610 +               value = __rlim_get(limit, lim);
19611 +               __rlim_rmax(limit, lim) = value;
19612 +               __rlim_rmin(limit, lim) = value;
19613 +       }
19614 +}
19615 +
19616 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
19617 +{
19618 +       vx_reset_minmax(&vxi->limit);
19619 +       return 0;
19620 +}
19621 +
19622 +
19623 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
19624 +{
19625 +       struct vcmd_rlimit_stat_v0 vc_data;
19626 +       struct _vx_limit *limit = &vxi->limit;
19627 +       int id;
19628 +
19629 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19630 +               return -EFAULT;
19631 +
19632 +       id = vc_data.id;
19633 +       if (!is_accounted_vlimit(id))
19634 +               return -EINVAL;
19635 +
19636 +       vx_limit_fixup(limit, id);
19637 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
19638 +       vc_data.value = __rlim_get(limit, id);
19639 +       vc_data.minimum = __rlim_rmin(limit, id);
19640 +       vc_data.maximum = __rlim_rmax(limit, id);
19641 +
19642 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19643 +               return -EFAULT;
19644 +       return 0;
19645 +}
19646 +
19647 +
19648 +void vx_vsi_meminfo(struct sysinfo *val)
19649 +{
19650 +#ifdef CONFIG_MEMCG
19651 +       struct mem_cgroup *mcg;
19652 +       u64 res_limit, res_usage;
19653 +
19654 +       rcu_read_lock();
19655 +       mcg = mem_cgroup_from_task(current);
19656 +       rcu_read_unlock();
19657 +       if (!mcg)
19658 +               goto out;
19659 +
19660 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
19661 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
19662 +
19663 +       if (res_limit != RESOURCE_MAX)
19664 +               val->totalram = (res_limit >> PAGE_SHIFT);
19665 +       val->freeram = val->totalram - (res_usage >> PAGE_SHIFT);
19666 +       val->bufferram = 0;
19667 +       val->totalhigh = 0;
19668 +       val->freehigh = 0;
19669 +out:
19670 +#endif /* CONFIG_MEMCG */
19671 +       return;
19672 +}
19673 +
19674 +void vx_vsi_swapinfo(struct sysinfo *val)
19675 +{
19676 +#ifdef CONFIG_MEMCG
19677 +#ifdef CONFIG_MEMCG_SWAP
19678 +       struct mem_cgroup *mcg;
19679 +       u64 res_limit, res_usage, memsw_limit, memsw_usage;
19680 +       s64 swap_limit, swap_usage;
19681 +
19682 +       rcu_read_lock();
19683 +       mcg = mem_cgroup_from_task(current);
19684 +       rcu_read_unlock();
19685 +       if (!mcg)
19686 +               goto out;
19687 +
19688 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
19689 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
19690 +       memsw_limit = mem_cgroup_memsw_read_u64(mcg, RES_LIMIT);
19691 +       memsw_usage = mem_cgroup_memsw_read_u64(mcg, RES_USAGE);
19692 +
19693 +       /* memory unlimited */
19694 +       if (res_limit == RESOURCE_MAX)
19695 +               goto out;
19696 +
19697 +       swap_limit = memsw_limit - res_limit;
19698 +       /* we have a swap limit? */
19699 +       if (memsw_limit != RESOURCE_MAX)
19700 +               val->totalswap = swap_limit >> PAGE_SHIFT;
19701 +
19702 +       /* calculate swap part */
19703 +       swap_usage = (memsw_usage > res_usage) ?
19704 +               memsw_usage - res_usage : 0;
19705 +
19706 +       /* total shown minus usage gives free swap */
19707 +       val->freeswap = (swap_usage < swap_limit) ?
19708 +               val->totalswap - (swap_usage >> PAGE_SHIFT) : 0;
19709 +out:
19710 +#else  /* !CONFIG_MEMCG_SWAP */
19711 +       val->totalswap = 0;
19712 +       val->freeswap = 0;
19713 +#endif /* !CONFIG_MEMCG_SWAP */
19714 +#endif /* CONFIG_MEMCG */
19715 +       return;
19716 +}
19717 +
19718 +long vx_vsi_cached(struct sysinfo *val)
19719 +{
19720 +       long cache = 0;
19721 +#ifdef CONFIG_MEMCG
19722 +       struct mem_cgroup *mcg;
19723 +
19724 +       rcu_read_lock();
19725 +       mcg = mem_cgroup_from_task(current);
19726 +       rcu_read_unlock();
19727 +       if (!mcg)
19728 +               goto out;
19729 +
19730 +       cache = mem_cgroup_stat_read_cache(mcg);
19731 +out:
19732 +#endif
19733 +       return cache;
19734 +}
19735 +
19736 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
19737 --- linux-3.10.33/kernel/vserver/limit_init.h   1970-01-01 00:00:00.000000000 +0000
19738 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/limit_init.h 2013-08-22 20:30:00.000000000 +0000
19739 @@ -0,0 +1,31 @@
19740 +
19741 +
19742 +static inline void vx_info_init_limit(struct _vx_limit *limit)
19743 +{
19744 +       int lim;
19745 +
19746 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19747 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
19748 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
19749 +               __rlim_set(limit, lim, 0);
19750 +               atomic_set(&__rlim_lhit(limit, lim), 0);
19751 +               __rlim_rmin(limit, lim) = 0;
19752 +               __rlim_rmax(limit, lim) = 0;
19753 +       }
19754 +}
19755 +
19756 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
19757 +{
19758 +       rlim_t value;
19759 +       int lim;
19760 +
19761 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19762 +               if ((1 << lim) & VLIM_NOCHECK)
19763 +                       continue;
19764 +               value = __rlim_get(limit, lim);
19765 +               vxwprintk_xid(value,
19766 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
19767 +                       limit, vlimit_name[lim], lim, (long)value);
19768 +       }
19769 +}
19770 +
19771 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
19772 --- linux-3.10.33/kernel/vserver/limit_proc.h   1970-01-01 00:00:00.000000000 +0000
19773 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/limit_proc.h 2013-08-22 20:30:00.000000000 +0000
19774 @@ -0,0 +1,57 @@
19775 +#ifndef _VX_LIMIT_PROC_H
19776 +#define _VX_LIMIT_PROC_H
19777 +
19778 +#include <linux/vserver/limit_int.h>
19779 +
19780 +
19781 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
19782 +#define VX_LIMIT_TOP   \
19783 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
19784 +
19785 +#define VX_LIMIT_ARG(r)                                \
19786 +       (unsigned long)__rlim_get(limit, r),    \
19787 +       (unsigned long)__rlim_rmin(limit, r),   \
19788 +       (unsigned long)__rlim_rmax(limit, r),   \
19789 +       VX_VLIM(__rlim_soft(limit, r)),         \
19790 +       VX_VLIM(__rlim_hard(limit, r)),         \
19791 +       atomic_read(&__rlim_lhit(limit, r))
19792 +
19793 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
19794 +{
19795 +       vx_limit_fixup(limit, -1);
19796 +       return sprintf(buffer, VX_LIMIT_TOP
19797 +               "PROC"  VX_LIMIT_FMT
19798 +               "VM"    VX_LIMIT_FMT
19799 +               "VML"   VX_LIMIT_FMT
19800 +               "RSS"   VX_LIMIT_FMT
19801 +               "ANON"  VX_LIMIT_FMT
19802 +               "RMAP"  VX_LIMIT_FMT
19803 +               "FILES" VX_LIMIT_FMT
19804 +               "OFD"   VX_LIMIT_FMT
19805 +               "LOCKS" VX_LIMIT_FMT
19806 +               "SOCK"  VX_LIMIT_FMT
19807 +               "MSGQ"  VX_LIMIT_FMT
19808 +               "SHM"   VX_LIMIT_FMT
19809 +               "SEMA"  VX_LIMIT_FMT
19810 +               "SEMS"  VX_LIMIT_FMT
19811 +               "DENT"  VX_LIMIT_FMT,
19812 +               VX_LIMIT_ARG(RLIMIT_NPROC),
19813 +               VX_LIMIT_ARG(RLIMIT_AS),
19814 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
19815 +               VX_LIMIT_ARG(RLIMIT_RSS),
19816 +               VX_LIMIT_ARG(VLIMIT_ANON),
19817 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
19818 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
19819 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
19820 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
19821 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
19822 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
19823 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
19824 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
19825 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
19826 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
19827 +}
19828 +
19829 +#endif /* _VX_LIMIT_PROC_H */
19830 +
19831 +
19832 diff -NurpP --minimal linux-3.10.33/kernel/vserver/network.c linux-3.10.33-vs2.3.6.8/kernel/vserver/network.c
19833 --- linux-3.10.33/kernel/vserver/network.c      1970-01-01 00:00:00.000000000 +0000
19834 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/network.c    2013-08-22 20:30:00.000000000 +0000
19835 @@ -0,0 +1,1053 @@
19836 +/*
19837 + *  linux/kernel/vserver/network.c
19838 + *
19839 + *  Virtual Server: Network Support
19840 + *
19841 + *  Copyright (C) 2003-2007  Herbert Pötzl
19842 + *
19843 + *  V0.01  broken out from vcontext V0.05
19844 + *  V0.02  cleaned up implementation
19845 + *  V0.03  added equiv nx commands
19846 + *  V0.04  switch to RCU based hash
19847 + *  V0.05  and back to locking again
19848 + *  V0.06  changed vcmds to nxi arg
19849 + *  V0.07  have __create claim() the nxi
19850 + *
19851 + */
19852 +
19853 +#include <linux/err.h>
19854 +#include <linux/slab.h>
19855 +#include <linux/rcupdate.h>
19856 +#include <net/ipv6.h>
19857 +
19858 +#include <linux/vs_network.h>
19859 +#include <linux/vs_pid.h>
19860 +#include <linux/vserver/network_cmd.h>
19861 +
19862 +
19863 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
19864 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
19865 +
19866 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
19867 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
19868 +
19869 +
19870 +static int __init init_network(void)
19871 +{
19872 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
19873 +               sizeof(struct nx_addr_v4), 0,
19874 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19875 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
19876 +               sizeof(struct nx_addr_v6), 0,
19877 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19878 +       return 0;
19879 +}
19880 +
19881 +
19882 +/*     __alloc_nx_addr_v4()                                    */
19883 +
19884 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
19885 +{
19886 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
19887 +               nx_addr_v4_cachep, GFP_KERNEL);
19888 +
19889 +       if (!IS_ERR(nxa))
19890 +               memset(nxa, 0, sizeof(*nxa));
19891 +       return nxa;
19892 +}
19893 +
19894 +/*     __dealloc_nx_addr_v4()                                  */
19895 +
19896 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
19897 +{
19898 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
19899 +}
19900 +
19901 +/*     __dealloc_nx_addr_v4_all()                              */
19902 +
19903 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
19904 +{
19905 +       while (nxa) {
19906 +               struct nx_addr_v4 *next = nxa->next;
19907 +
19908 +               __dealloc_nx_addr_v4(nxa);
19909 +               nxa = next;
19910 +       }
19911 +}
19912 +
19913 +
19914 +#ifdef CONFIG_IPV6
19915 +
19916 +/*     __alloc_nx_addr_v6()                                    */
19917 +
19918 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
19919 +{
19920 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
19921 +               nx_addr_v6_cachep, GFP_KERNEL);
19922 +
19923 +       if (!IS_ERR(nxa))
19924 +               memset(nxa, 0, sizeof(*nxa));
19925 +       return nxa;
19926 +}
19927 +
19928 +/*     __dealloc_nx_addr_v6()                                  */
19929 +
19930 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
19931 +{
19932 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
19933 +}
19934 +
19935 +/*     __dealloc_nx_addr_v6_all()                              */
19936 +
19937 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
19938 +{
19939 +       while (nxa) {
19940 +               struct nx_addr_v6 *next = nxa->next;
19941 +
19942 +               __dealloc_nx_addr_v6(nxa);
19943 +               nxa = next;
19944 +       }
19945 +}
19946 +
19947 +#endif /* CONFIG_IPV6 */
19948 +
19949 +/*     __alloc_nx_info()
19950 +
19951 +       * allocate an initialized nx_info struct
19952 +       * doesn't make it visible (hash)                        */
19953 +
19954 +static struct nx_info *__alloc_nx_info(vnid_t nid)
19955 +{
19956 +       struct nx_info *new = NULL;
19957 +
19958 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
19959 +
19960 +       /* would this benefit from a slab cache? */
19961 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
19962 +       if (!new)
19963 +               return 0;
19964 +
19965 +       memset(new, 0, sizeof(struct nx_info));
19966 +       new->nx_id = nid;
19967 +       INIT_HLIST_NODE(&new->nx_hlist);
19968 +       atomic_set(&new->nx_usecnt, 0);
19969 +       atomic_set(&new->nx_tasks, 0);
19970 +       spin_lock_init(&new->addr_lock);
19971 +       new->nx_state = 0;
19972 +
19973 +       new->nx_flags = NXF_INIT_SET;
19974 +
19975 +       /* rest of init goes here */
19976 +
19977 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
19978 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
19979 +
19980 +       vxdprintk(VXD_CBIT(nid, 0),
19981 +               "alloc_nx_info(%d) = %p", nid, new);
19982 +       atomic_inc(&nx_global_ctotal);
19983 +       return new;
19984 +}
19985 +
19986 +/*     __dealloc_nx_info()
19987 +
19988 +       * final disposal of nx_info                             */
19989 +
19990 +static void __dealloc_nx_info(struct nx_info *nxi)
19991 +{
19992 +       vxdprintk(VXD_CBIT(nid, 0),
19993 +               "dealloc_nx_info(%p)", nxi);
19994 +
19995 +       nxi->nx_hlist.next = LIST_POISON1;
19996 +       nxi->nx_id = -1;
19997 +
19998 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
19999 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20000 +
20001 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
20002 +#ifdef CONFIG_IPV6
20003 +       __dealloc_nx_addr_v6_all(nxi->v6.next);
20004 +#endif
20005 +
20006 +       nxi->nx_state |= NXS_RELEASED;
20007 +       kfree(nxi);
20008 +       atomic_dec(&nx_global_ctotal);
20009 +}
20010 +
20011 +static void __shutdown_nx_info(struct nx_info *nxi)
20012 +{
20013 +       nxi->nx_state |= NXS_SHUTDOWN;
20014 +       vs_net_change(nxi, VSC_NETDOWN);
20015 +}
20016 +
20017 +/*     exported stuff                                          */
20018 +
20019 +void free_nx_info(struct nx_info *nxi)
20020 +{
20021 +       /* context shutdown is mandatory */
20022 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
20023 +
20024 +       /* context must not be hashed */
20025 +       BUG_ON(nxi->nx_state & NXS_HASHED);
20026 +
20027 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20028 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20029 +
20030 +       __dealloc_nx_info(nxi);
20031 +}
20032 +
20033 +
20034 +void __nx_set_lback(struct nx_info *nxi)
20035 +{
20036 +       int nid = nxi->nx_id;
20037 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
20038 +
20039 +       nxi->v4_lback.s_addr = lback;
20040 +}
20041 +
20042 +extern int __nx_inet_add_lback(__be32 addr);
20043 +extern int __nx_inet_del_lback(__be32 addr);
20044 +
20045 +
20046 +/*     hash table for nx_info hash */
20047 +
20048 +#define NX_HASH_SIZE   13
20049 +
20050 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
20051 +
20052 +static DEFINE_SPINLOCK(nx_info_hash_lock);
20053 +
20054 +
20055 +static inline unsigned int __hashval(vnid_t nid)
20056 +{
20057 +       return (nid % NX_HASH_SIZE);
20058 +}
20059 +
20060 +
20061 +
20062 +/*     __hash_nx_info()
20063 +
20064 +       * add the nxi to the global hash table
20065 +       * requires the hash_lock to be held                     */
20066 +
20067 +static inline void __hash_nx_info(struct nx_info *nxi)
20068 +{
20069 +       struct hlist_head *head;
20070 +
20071 +       vxd_assert_lock(&nx_info_hash_lock);
20072 +       vxdprintk(VXD_CBIT(nid, 4),
20073 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
20074 +
20075 +       /* context must not be hashed */
20076 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
20077 +
20078 +       nxi->nx_state |= NXS_HASHED;
20079 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
20080 +       hlist_add_head(&nxi->nx_hlist, head);
20081 +       atomic_inc(&nx_global_cactive);
20082 +}
20083 +
20084 +/*     __unhash_nx_info()
20085 +
20086 +       * remove the nxi from the global hash table
20087 +       * requires the hash_lock to be held                     */
20088 +
20089 +static inline void __unhash_nx_info(struct nx_info *nxi)
20090 +{
20091 +       vxd_assert_lock(&nx_info_hash_lock);
20092 +       vxdprintk(VXD_CBIT(nid, 4),
20093 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
20094 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
20095 +
20096 +       /* context must be hashed */
20097 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
20098 +       /* but without tasks */
20099 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20100 +
20101 +       nxi->nx_state &= ~NXS_HASHED;
20102 +       hlist_del(&nxi->nx_hlist);
20103 +       atomic_dec(&nx_global_cactive);
20104 +}
20105 +
20106 +
20107 +/*     __lookup_nx_info()
20108 +
20109 +       * requires the hash_lock to be held
20110 +       * doesn't increment the nx_refcnt                       */
20111 +
20112 +static inline struct nx_info *__lookup_nx_info(vnid_t nid)
20113 +{
20114 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
20115 +       struct hlist_node *pos;
20116 +       struct nx_info *nxi;
20117 +
20118 +       vxd_assert_lock(&nx_info_hash_lock);
20119 +       hlist_for_each(pos, head) {
20120 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20121 +
20122 +               if (nxi->nx_id == nid)
20123 +                       goto found;
20124 +       }
20125 +       nxi = NULL;
20126 +found:
20127 +       vxdprintk(VXD_CBIT(nid, 0),
20128 +               "__lookup_nx_info(#%u): %p[#%u]",
20129 +               nid, nxi, nxi ? nxi->nx_id : 0);
20130 +       return nxi;
20131 +}
20132 +
20133 +
20134 +/*     __create_nx_info()
20135 +
20136 +       * create the requested context
20137 +       * get(), claim() and hash it                            */
20138 +
20139 +static struct nx_info *__create_nx_info(int id)
20140 +{
20141 +       struct nx_info *new, *nxi = NULL;
20142 +
20143 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
20144 +
20145 +       if (!(new = __alloc_nx_info(id)))
20146 +               return ERR_PTR(-ENOMEM);
20147 +
20148 +       /* required to make dynamic xids unique */
20149 +       spin_lock(&nx_info_hash_lock);
20150 +
20151 +       /* static context requested */
20152 +       if ((nxi = __lookup_nx_info(id))) {
20153 +               vxdprintk(VXD_CBIT(nid, 0),
20154 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
20155 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20156 +                       nxi = ERR_PTR(-EBUSY);
20157 +               else
20158 +                       nxi = ERR_PTR(-EEXIST);
20159 +               goto out_unlock;
20160 +       }
20161 +       /* new context */
20162 +       vxdprintk(VXD_CBIT(nid, 0),
20163 +               "create_nx_info(%d) = %p (new)", id, new);
20164 +       claim_nx_info(new, NULL);
20165 +       __nx_set_lback(new);
20166 +       __hash_nx_info(get_nx_info(new));
20167 +       nxi = new, new = NULL;
20168 +
20169 +out_unlock:
20170 +       spin_unlock(&nx_info_hash_lock);
20171 +       if (new)
20172 +               __dealloc_nx_info(new);
20173 +       return nxi;
20174 +}
20175 +
20176 +
20177 +
20178 +/*     exported stuff                                          */
20179 +
20180 +
20181 +void unhash_nx_info(struct nx_info *nxi)
20182 +{
20183 +       __shutdown_nx_info(nxi);
20184 +       spin_lock(&nx_info_hash_lock);
20185 +       __unhash_nx_info(nxi);
20186 +       spin_unlock(&nx_info_hash_lock);
20187 +}
20188 +
20189 +/*     lookup_nx_info()
20190 +
20191 +       * search for a nx_info and get() it
20192 +       * negative id means current                             */
20193 +
20194 +struct nx_info *lookup_nx_info(int id)
20195 +{
20196 +       struct nx_info *nxi = NULL;
20197 +
20198 +       if (id < 0) {
20199 +               nxi = get_nx_info(current_nx_info());
20200 +       } else if (id > 1) {
20201 +               spin_lock(&nx_info_hash_lock);
20202 +               nxi = get_nx_info(__lookup_nx_info(id));
20203 +               spin_unlock(&nx_info_hash_lock);
20204 +       }
20205 +       return nxi;
20206 +}
20207 +
20208 +/*     nid_is_hashed()
20209 +
20210 +       * verify that nid is still hashed                       */
20211 +
20212 +int nid_is_hashed(vnid_t nid)
20213 +{
20214 +       int hashed;
20215 +
20216 +       spin_lock(&nx_info_hash_lock);
20217 +       hashed = (__lookup_nx_info(nid) != NULL);
20218 +       spin_unlock(&nx_info_hash_lock);
20219 +       return hashed;
20220 +}
20221 +
20222 +
20223 +#ifdef CONFIG_PROC_FS
20224 +
20225 +/*     get_nid_list()
20226 +
20227 +       * get a subset of hashed nids for proc
20228 +       * assumes size is at least one                          */
20229 +
20230 +int get_nid_list(int index, unsigned int *nids, int size)
20231 +{
20232 +       int hindex, nr_nids = 0;
20233 +
20234 +       /* only show current and children */
20235 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
20236 +               if (index > 0)
20237 +                       return 0;
20238 +               nids[nr_nids] = nx_current_nid();
20239 +               return 1;
20240 +       }
20241 +
20242 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
20243 +               struct hlist_head *head = &nx_info_hash[hindex];
20244 +               struct hlist_node *pos;
20245 +
20246 +               spin_lock(&nx_info_hash_lock);
20247 +               hlist_for_each(pos, head) {
20248 +                       struct nx_info *nxi;
20249 +
20250 +                       if (--index > 0)
20251 +                               continue;
20252 +
20253 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20254 +                       nids[nr_nids] = nxi->nx_id;
20255 +                       if (++nr_nids >= size) {
20256 +                               spin_unlock(&nx_info_hash_lock);
20257 +                               goto out;
20258 +                       }
20259 +               }
20260 +               /* keep the lock time short */
20261 +               spin_unlock(&nx_info_hash_lock);
20262 +       }
20263 +out:
20264 +       return nr_nids;
20265 +}
20266 +#endif
20267 +
20268 +
20269 +/*
20270 + *     migrate task to new network
20271 + *     gets nxi, puts old_nxi on change
20272 + */
20273 +
20274 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
20275 +{
20276 +       struct nx_info *old_nxi;
20277 +       int ret = 0;
20278 +
20279 +       if (!p || !nxi)
20280 +               BUG();
20281 +
20282 +       vxdprintk(VXD_CBIT(nid, 5),
20283 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
20284 +               p, nxi, nxi->nx_id,
20285 +               atomic_read(&nxi->nx_usecnt),
20286 +               atomic_read(&nxi->nx_tasks));
20287 +
20288 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
20289 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20290 +               return -EACCES;
20291 +
20292 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
20293 +               return -EFAULT;
20294 +
20295 +       /* maybe disallow this completely? */
20296 +       old_nxi = task_get_nx_info(p);
20297 +       if (old_nxi == nxi)
20298 +               goto out;
20299 +
20300 +       task_lock(p);
20301 +       if (old_nxi)
20302 +               clr_nx_info(&p->nx_info);
20303 +       claim_nx_info(nxi, p);
20304 +       set_nx_info(&p->nx_info, nxi);
20305 +       p->nid = nxi->nx_id;
20306 +       task_unlock(p);
20307 +
20308 +       vxdprintk(VXD_CBIT(nid, 5),
20309 +               "moved task %p into nxi:%p[#%d]",
20310 +               p, nxi, nxi->nx_id);
20311 +
20312 +       if (old_nxi)
20313 +               release_nx_info(old_nxi, p);
20314 +       ret = 0;
20315 +out:
20316 +       put_nx_info(old_nxi);
20317 +       return ret;
20318 +}
20319 +
20320 +
20321 +void nx_set_persistent(struct nx_info *nxi)
20322 +{
20323 +       vxdprintk(VXD_CBIT(nid, 6),
20324 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
20325 +
20326 +       get_nx_info(nxi);
20327 +       claim_nx_info(nxi, NULL);
20328 +}
20329 +
20330 +void nx_clear_persistent(struct nx_info *nxi)
20331 +{
20332 +       vxdprintk(VXD_CBIT(nid, 6),
20333 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
20334 +
20335 +       release_nx_info(nxi, NULL);
20336 +       put_nx_info(nxi);
20337 +}
20338 +
20339 +void nx_update_persistent(struct nx_info *nxi)
20340 +{
20341 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
20342 +               nx_set_persistent(nxi);
20343 +       else
20344 +               nx_clear_persistent(nxi);
20345 +}
20346 +
20347 +/* vserver syscall commands below here */
20348 +
20349 +/* taks nid and nx_info functions */
20350 +
20351 +#include <asm/uaccess.h>
20352 +
20353 +
20354 +int vc_task_nid(uint32_t id)
20355 +{
20356 +       vnid_t nid;
20357 +
20358 +       if (id) {
20359 +               struct task_struct *tsk;
20360 +
20361 +               rcu_read_lock();
20362 +               tsk = find_task_by_real_pid(id);
20363 +               nid = (tsk) ? tsk->nid : -ESRCH;
20364 +               rcu_read_unlock();
20365 +       } else
20366 +               nid = nx_current_nid();
20367 +       return nid;
20368 +}
20369 +
20370 +
20371 +int vc_nx_info(struct nx_info *nxi, void __user *data)
20372 +{
20373 +       struct vcmd_nx_info_v0 vc_data;
20374 +
20375 +       vc_data.nid = nxi->nx_id;
20376 +
20377 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20378 +               return -EFAULT;
20379 +       return 0;
20380 +}
20381 +
20382 +
20383 +/* network functions */
20384 +
20385 +int vc_net_create(uint32_t nid, void __user *data)
20386 +{
20387 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
20388 +       struct nx_info *new_nxi;
20389 +       int ret;
20390 +
20391 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20392 +               return -EFAULT;
20393 +
20394 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
20395 +               return -EINVAL;
20396 +
20397 +       new_nxi = __create_nx_info(nid);
20398 +       if (IS_ERR(new_nxi))
20399 +               return PTR_ERR(new_nxi);
20400 +
20401 +       /* initial flags */
20402 +       new_nxi->nx_flags = vc_data.flagword;
20403 +
20404 +       ret = -ENOEXEC;
20405 +       if (vs_net_change(new_nxi, VSC_NETUP))
20406 +               goto out;
20407 +
20408 +       ret = nx_migrate_task(current, new_nxi);
20409 +       if (ret)
20410 +               goto out;
20411 +
20412 +       /* return context id on success */
20413 +       ret = new_nxi->nx_id;
20414 +
20415 +       /* get a reference for persistent contexts */
20416 +       if ((vc_data.flagword & NXF_PERSISTENT))
20417 +               nx_set_persistent(new_nxi);
20418 +out:
20419 +       release_nx_info(new_nxi, NULL);
20420 +       put_nx_info(new_nxi);
20421 +       return ret;
20422 +}
20423 +
20424 +
20425 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
20426 +{
20427 +       return nx_migrate_task(current, nxi);
20428 +}
20429 +
20430 +
20431 +static inline
20432 +struct nx_addr_v4 *__find_v4_addr(struct nx_info *nxi,
20433 +       __be32 ip, __be32 ip2, __be32 mask, uint16_t type, uint16_t flags,
20434 +       struct nx_addr_v4 **prev)
20435 +{
20436 +       struct nx_addr_v4 *nxa = &nxi->v4;
20437 +
20438 +       for (; nxa; nxa = nxa->next) {
20439 +               if ((nxa->ip[0].s_addr == ip) &&
20440 +                   (nxa->ip[1].s_addr == ip2) &&
20441 +                   (nxa->mask.s_addr == mask) &&
20442 +                   (nxa->type == type) &&
20443 +                   (nxa->flags == flags))
20444 +                   return nxa;
20445 +
20446 +               /* save previous entry */
20447 +               if (prev)
20448 +                       *prev = nxa;
20449 +       }
20450 +       return NULL;
20451 +}
20452 +
20453 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
20454 +       uint16_t type, uint16_t flags)
20455 +{
20456 +       struct nx_addr_v4 *nxa = NULL;
20457 +       struct nx_addr_v4 *new = __alloc_nx_addr_v4();
20458 +       unsigned long irqflags;
20459 +       int ret = -EEXIST;
20460 +
20461 +       if (IS_ERR(new))
20462 +               return PTR_ERR(new);
20463 +
20464 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
20465 +       if (__find_v4_addr(nxi, ip, ip2, mask, type, flags, &nxa))
20466 +               goto out_unlock;
20467 +
20468 +       if (NX_IPV4(nxi)) {
20469 +               nxa->next = new;
20470 +               nxa = new;
20471 +               new = NULL;
20472 +
20473 +               /* remove single ip for ip list */
20474 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
20475 +       }
20476 +
20477 +       nxa->ip[0].s_addr = ip;
20478 +       nxa->ip[1].s_addr = ip2;
20479 +       nxa->mask.s_addr = mask;
20480 +       nxa->type = type;
20481 +       nxa->flags = flags;
20482 +       ret = 0;
20483 +out_unlock:
20484 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20485 +       if (new)
20486 +               __dealloc_nx_addr_v4(new);
20487 +       return ret;
20488 +}
20489 +
20490 +int do_remove_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
20491 +       uint16_t type, uint16_t flags)
20492 +{
20493 +       struct nx_addr_v4 *nxa = NULL;
20494 +       struct nx_addr_v4 *old = NULL;
20495 +       unsigned long irqflags;
20496 +       int ret = 0;
20497 +
20498 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
20499 +       switch (type) {
20500 +       case NXA_TYPE_ADDR:
20501 +               old = __find_v4_addr(nxi, ip, ip2, mask, type, flags, &nxa);
20502 +               if (old) {
20503 +                       if (nxa) {
20504 +                               nxa->next = old->next;
20505 +                               old->next = NULL;
20506 +                       } else {
20507 +                               if (old->next) {
20508 +                                       nxa = old;
20509 +                                       old = old->next;
20510 +                                       *nxa = *old;
20511 +                                       old->next = NULL;
20512 +                               } else {
20513 +                                       memset(old, 0, sizeof(*old));
20514 +                                       old = NULL;
20515 +                               }
20516 +                       }
20517 +               } else
20518 +                       ret = -ESRCH;
20519 +               break;
20520 +
20521 +       case NXA_TYPE_ANY:
20522 +               nxa = &nxi->v4;
20523 +               old = nxa->next;
20524 +               memset(nxa, 0, sizeof(*nxa));
20525 +               break;
20526 +
20527 +       default:
20528 +               ret = -EINVAL;
20529 +       }
20530 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20531 +       __dealloc_nx_addr_v4_all(old);
20532 +       return ret;
20533 +}
20534 +
20535 +
20536 +int vc_net_add(struct nx_info *nxi, void __user *data)
20537 +{
20538 +       struct vcmd_net_addr_v0 vc_data;
20539 +       int index, ret = 0;
20540 +
20541 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20542 +               return -EFAULT;
20543 +
20544 +       switch (vc_data.type) {
20545 +       case NXA_TYPE_IPV4:
20546 +               if ((vc_data.count < 1) || (vc_data.count > 4))
20547 +                       return -EINVAL;
20548 +
20549 +               index = 0;
20550 +               while (index < vc_data.count) {
20551 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
20552 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
20553 +                       if (ret)
20554 +                               return ret;
20555 +                       index++;
20556 +               }
20557 +               ret = index;
20558 +               break;
20559 +
20560 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
20561 +               nxi->v4_bcast = vc_data.ip[0];
20562 +               ret = 1;
20563 +               break;
20564 +
20565 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
20566 +               nxi->v4_lback = vc_data.ip[0];
20567 +               ret = 1;
20568 +               break;
20569 +
20570 +       default:
20571 +               ret = -EINVAL;
20572 +               break;
20573 +       }
20574 +       return ret;
20575 +}
20576 +
20577 +int vc_net_remove(struct nx_info *nxi, void __user *data)
20578 +{
20579 +       struct vcmd_net_addr_v0 vc_data;
20580 +
20581 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20582 +               return -EFAULT;
20583 +
20584 +       switch (vc_data.type) {
20585 +       case NXA_TYPE_ANY:
20586 +               return do_remove_v4_addr(nxi, 0, 0, 0, vc_data.type, 0);
20587 +       default:
20588 +               return -EINVAL;
20589 +       }
20590 +       return 0;
20591 +}
20592 +
20593 +
20594 +int vc_net_add_ipv4_v1(struct nx_info *nxi, void __user *data)
20595 +{
20596 +       struct vcmd_net_addr_ipv4_v1 vc_data;
20597 +
20598 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20599 +               return -EFAULT;
20600 +
20601 +       switch (vc_data.type) {
20602 +       case NXA_TYPE_ADDR:
20603 +       case NXA_TYPE_MASK:
20604 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
20605 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20606 +
20607 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
20608 +               nxi->v4_bcast = vc_data.ip;
20609 +               break;
20610 +
20611 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
20612 +               nxi->v4_lback = vc_data.ip;
20613 +               break;
20614 +
20615 +       default:
20616 +               return -EINVAL;
20617 +       }
20618 +       return 0;
20619 +}
20620 +
20621 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
20622 +{
20623 +       struct vcmd_net_addr_ipv4_v2 vc_data;
20624 +
20625 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20626 +               return -EFAULT;
20627 +
20628 +       switch (vc_data.type) {
20629 +       case NXA_TYPE_ADDR:
20630 +       case NXA_TYPE_MASK:
20631 +       case NXA_TYPE_RANGE:
20632 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
20633 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20634 +
20635 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
20636 +               nxi->v4_bcast = vc_data.ip;
20637 +               break;
20638 +
20639 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
20640 +               nxi->v4_lback = vc_data.ip;
20641 +               break;
20642 +
20643 +       default:
20644 +               return -EINVAL;
20645 +       }
20646 +       return 0;
20647 +}
20648 +
20649 +int vc_net_rem_ipv4_v1(struct nx_info *nxi, void __user *data)
20650 +{
20651 +       struct vcmd_net_addr_ipv4_v1 vc_data;
20652 +
20653 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20654 +               return -EFAULT;
20655 +
20656 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, 0,
20657 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20658 +}
20659 +
20660 +int vc_net_rem_ipv4(struct nx_info *nxi, void __user *data)
20661 +{
20662 +       struct vcmd_net_addr_ipv4_v2 vc_data;
20663 +
20664 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20665 +               return -EFAULT;
20666 +
20667 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
20668 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20669 +}
20670 +
20671 +#ifdef CONFIG_IPV6
20672 +
20673 +static inline
20674 +struct nx_addr_v6 *__find_v6_addr(struct nx_info *nxi,
20675 +       struct in6_addr *ip, struct in6_addr *mask,
20676 +       uint32_t prefix, uint16_t type, uint16_t flags,
20677 +       struct nx_addr_v6 **prev)
20678 +{
20679 +       struct nx_addr_v6 *nxa = &nxi->v6;
20680 +
20681 +       for (; nxa; nxa = nxa->next) {
20682 +               if (ipv6_addr_equal(&nxa->ip, ip) &&
20683 +                   ipv6_addr_equal(&nxa->mask, mask) &&
20684 +                   (nxa->prefix == prefix) &&
20685 +                   (nxa->type == type) &&
20686 +                   (nxa->flags == flags))
20687 +                   return nxa;
20688 +
20689 +               /* save previous entry */
20690 +               if (prev)
20691 +                       *prev = nxa;
20692 +       }
20693 +       return NULL;
20694 +}
20695 +
20696 +
20697 +int do_add_v6_addr(struct nx_info *nxi,
20698 +       struct in6_addr *ip, struct in6_addr *mask,
20699 +       uint32_t prefix, uint16_t type, uint16_t flags)
20700 +{
20701 +       struct nx_addr_v6 *nxa = NULL;
20702 +       struct nx_addr_v6 *new = __alloc_nx_addr_v6();
20703 +       unsigned long irqflags;
20704 +       int ret = -EEXIST;
20705 +
20706 +       if (IS_ERR(new))
20707 +               return PTR_ERR(new);
20708 +
20709 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
20710 +       if (__find_v6_addr(nxi, ip, mask, prefix, type, flags, &nxa))
20711 +               goto out_unlock;
20712 +
20713 +       if (NX_IPV6(nxi)) {
20714 +               nxa->next = new;
20715 +               nxa = new;
20716 +               new = NULL;
20717 +       }
20718 +
20719 +       nxa->ip = *ip;
20720 +       nxa->mask = *mask;
20721 +       nxa->prefix = prefix;
20722 +       nxa->type = type;
20723 +       nxa->flags = flags;
20724 +       ret = 0;
20725 +out_unlock:
20726 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20727 +       if (new)
20728 +               __dealloc_nx_addr_v6(new);
20729 +       return ret;
20730 +}
20731 +
20732 +int do_remove_v6_addr(struct nx_info *nxi,
20733 +       struct in6_addr *ip, struct in6_addr *mask,
20734 +       uint32_t prefix, uint16_t type, uint16_t flags)
20735 +{
20736 +       struct nx_addr_v6 *nxa = NULL;
20737 +       struct nx_addr_v6 *old = NULL;
20738 +       unsigned long irqflags;
20739 +       int ret = 0;
20740 +
20741 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
20742 +       switch (type) {
20743 +       case NXA_TYPE_ADDR:
20744 +               old = __find_v6_addr(nxi, ip, mask, prefix, type, flags, &nxa);
20745 +               if (old) {
20746 +                       if (nxa) {
20747 +                               nxa->next = old->next;
20748 +                               old->next = NULL;
20749 +                       } else {
20750 +                               if (old->next) {
20751 +                                       nxa = old;
20752 +                                       old = old->next;
20753 +                                       *nxa = *old;
20754 +                                       old->next = NULL;
20755 +                               } else {
20756 +                                       memset(old, 0, sizeof(*old));
20757 +                                       old = NULL;
20758 +                               }
20759 +                       }
20760 +               } else
20761 +                       ret = -ESRCH;
20762 +               break;
20763 +
20764 +       case NXA_TYPE_ANY:
20765 +               nxa = &nxi->v6;
20766 +               old = nxa->next;
20767 +               memset(nxa, 0, sizeof(*nxa));
20768 +               break;
20769 +
20770 +       default:
20771 +               ret = -EINVAL;
20772 +       }
20773 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20774 +       __dealloc_nx_addr_v6_all(old);
20775 +       return ret;
20776 +}
20777 +
20778 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
20779 +{
20780 +       struct vcmd_net_addr_ipv6_v1 vc_data;
20781 +
20782 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20783 +               return -EFAULT;
20784 +
20785 +       switch (vc_data.type) {
20786 +       case NXA_TYPE_ADDR:
20787 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
20788 +               /* fallthrough */
20789 +       case NXA_TYPE_MASK:
20790 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
20791 +                       vc_data.prefix, vc_data.type, vc_data.flags);
20792 +       default:
20793 +               return -EINVAL;
20794 +       }
20795 +       return 0;
20796 +}
20797 +
20798 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
20799 +{
20800 +       struct vcmd_net_addr_ipv6_v1 vc_data;
20801 +
20802 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20803 +               return -EFAULT;
20804 +
20805 +       switch (vc_data.type) {
20806 +       case NXA_TYPE_ADDR:
20807 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
20808 +               /* fallthrough */
20809 +       case NXA_TYPE_MASK:
20810 +               return do_remove_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
20811 +                       vc_data.prefix, vc_data.type, vc_data.flags);
20812 +       case NXA_TYPE_ANY:
20813 +               return do_remove_v6_addr(nxi, NULL, NULL, 0, vc_data.type, 0);
20814 +       default:
20815 +               return -EINVAL;
20816 +       }
20817 +       return 0;
20818 +}
20819 +
20820 +#endif /* CONFIG_IPV6 */
20821 +
20822 +
20823 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
20824 +{
20825 +       struct vcmd_net_flags_v0 vc_data;
20826 +
20827 +       vc_data.flagword = nxi->nx_flags;
20828 +
20829 +       /* special STATE flag handling */
20830 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
20831 +
20832 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20833 +               return -EFAULT;
20834 +       return 0;
20835 +}
20836 +
20837 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
20838 +{
20839 +       struct vcmd_net_flags_v0 vc_data;
20840 +       uint64_t mask, trigger;
20841 +
20842 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20843 +               return -EFAULT;
20844 +
20845 +       /* special STATE flag handling */
20846 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
20847 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
20848 +
20849 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
20850 +               vc_data.flagword, mask);
20851 +       if (trigger & NXF_PERSISTENT)
20852 +               nx_update_persistent(nxi);
20853 +
20854 +       return 0;
20855 +}
20856 +
20857 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
20858 +{
20859 +       struct vcmd_net_caps_v0 vc_data;
20860 +
20861 +       vc_data.ncaps = nxi->nx_ncaps;
20862 +       vc_data.cmask = ~0ULL;
20863 +
20864 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20865 +               return -EFAULT;
20866 +       return 0;
20867 +}
20868 +
20869 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
20870 +{
20871 +       struct vcmd_net_caps_v0 vc_data;
20872 +
20873 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20874 +               return -EFAULT;
20875 +
20876 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
20877 +               vc_data.ncaps, vc_data.cmask);
20878 +       return 0;
20879 +}
20880 +
20881 +
20882 +#include <linux/module.h>
20883 +
20884 +module_init(init_network);
20885 +
20886 +EXPORT_SYMBOL_GPL(free_nx_info);
20887 +EXPORT_SYMBOL_GPL(unhash_nx_info);
20888 +
20889 diff -NurpP --minimal linux-3.10.33/kernel/vserver/proc.c linux-3.10.33-vs2.3.6.8/kernel/vserver/proc.c
20890 --- linux-3.10.33/kernel/vserver/proc.c 1970-01-01 00:00:00.000000000 +0000
20891 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/proc.c       2013-08-22 23:31:37.000000000 +0000
20892 @@ -0,0 +1,1113 @@
20893 +/*
20894 + *  linux/kernel/vserver/proc.c
20895 + *
20896 + *  Virtual Context Support
20897 + *
20898 + *  Copyright (C) 2003-2011  Herbert Pötzl
20899 + *
20900 + *  V0.01  basic structure
20901 + *  V0.02  adaptation vs1.3.0
20902 + *  V0.03  proc permissions
20903 + *  V0.04  locking/generic
20904 + *  V0.05  next generation procfs
20905 + *  V0.06  inode validation
20906 + *  V0.07  generic rewrite vid
20907 + *  V0.08  remove inode type
20908 + *  V0.09  added u/wmask info
20909 + *
20910 + */
20911 +
20912 +#include <linux/proc_fs.h>
20913 +#include <linux/fs_struct.h>
20914 +#include <linux/mount.h>
20915 +#include <linux/namei.h>
20916 +#include <asm/unistd.h>
20917 +
20918 +#include <linux/vs_context.h>
20919 +#include <linux/vs_network.h>
20920 +#include <linux/vs_cvirt.h>
20921 +
20922 +#include <linux/in.h>
20923 +#include <linux/inetdevice.h>
20924 +#include <linux/vs_inet.h>
20925 +#include <linux/vs_inet6.h>
20926 +
20927 +#include <linux/vserver/global.h>
20928 +
20929 +#include "cvirt_proc.h"
20930 +#include "cacct_proc.h"
20931 +#include "limit_proc.h"
20932 +#include "sched_proc.h"
20933 +#include "vci_config.h"
20934 +
20935 +#include <../../fs/proc/internal.h>
20936 +
20937 +
20938 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
20939 +{
20940 +       unsigned __capi;
20941 +
20942 +       CAP_FOR_EACH_U32(__capi) {
20943 +               buffer += sprintf(buffer, "%08x",
20944 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
20945 +       }
20946 +       return buffer;
20947 +}
20948 +
20949 +
20950 +static struct proc_dir_entry *proc_virtual;
20951 +
20952 +static struct proc_dir_entry *proc_virtnet;
20953 +
20954 +
20955 +/* first the actual feeds */
20956 +
20957 +
20958 +static int proc_vci(char *buffer)
20959 +{
20960 +       return sprintf(buffer,
20961 +               "VCIVersion:\t%04x:%04x\n"
20962 +               "VCISyscall:\t%d\n"
20963 +               "VCIKernel:\t%08x\n",
20964 +               VCI_VERSION >> 16,
20965 +               VCI_VERSION & 0xFFFF,
20966 +               __NR_vserver,
20967 +               vci_kernel_config());
20968 +}
20969 +
20970 +static int proc_virtual_info(char *buffer)
20971 +{
20972 +       return proc_vci(buffer);
20973 +}
20974 +
20975 +static int proc_virtual_status(char *buffer)
20976 +{
20977 +       return sprintf(buffer,
20978 +               "#CTotal:\t%d\n"
20979 +               "#CActive:\t%d\n"
20980 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
20981 +               "#InitTask:\t%d\t%d %d\n",
20982 +               atomic_read(&vx_global_ctotal),
20983 +               atomic_read(&vx_global_cactive),
20984 +               atomic_read(&vs_global_nsproxy),
20985 +               atomic_read(&vs_global_fs),
20986 +               atomic_read(&vs_global_mnt_ns),
20987 +               atomic_read(&vs_global_uts_ns),
20988 +               atomic_read(&nr_ipc_ns),
20989 +               atomic_read(&vs_global_user_ns),
20990 +               atomic_read(&vs_global_pid_ns),
20991 +               atomic_read(&init_task.usage),
20992 +               atomic_read(&init_task.nsproxy->count),
20993 +               init_task.fs->users);
20994 +}
20995 +
20996 +
20997 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
20998 +{
20999 +       int length;
21000 +
21001 +       length = sprintf(buffer,
21002 +               "ID:\t%d\n"
21003 +               "Info:\t%p\n"
21004 +               "Init:\t%d\n"
21005 +               "OOM:\t%lld\n",
21006 +               vxi->vx_id,
21007 +               vxi,
21008 +               vxi->vx_initpid,
21009 +               vxi->vx_badness_bias);
21010 +       return length;
21011 +}
21012 +
21013 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
21014 +{
21015 +       char *orig = buffer;
21016 +
21017 +       buffer += sprintf(buffer,
21018 +               "UseCnt:\t%d\n"
21019 +               "Tasks:\t%d\n"
21020 +               "Flags:\t%016llx\n",
21021 +               atomic_read(&vxi->vx_usecnt),
21022 +               atomic_read(&vxi->vx_tasks),
21023 +               (unsigned long long)vxi->vx_flags);
21024 +
21025 +       buffer += sprintf(buffer, "BCaps:\t");
21026 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
21027 +       buffer += sprintf(buffer, "\n");
21028 +
21029 +       buffer += sprintf(buffer,
21030 +               "CCaps:\t%016llx\n"
21031 +               "Umask:\t%16llx\n"
21032 +               "Wmask:\t%16llx\n"
21033 +               "Spaces:\t%08lx %08lx\n",
21034 +               (unsigned long long)vxi->vx_ccaps,
21035 +               (unsigned long long)vxi->vx_umask,
21036 +               (unsigned long long)vxi->vx_wmask,
21037 +               vxi->space[0].vx_nsmask, vxi->space[1].vx_nsmask);
21038 +       return buffer - orig;
21039 +}
21040 +
21041 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
21042 +{
21043 +       return vx_info_proc_limit(&vxi->limit, buffer);
21044 +}
21045 +
21046 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
21047 +{
21048 +       int cpu, length;
21049 +
21050 +       length = vx_info_proc_sched(&vxi->sched, buffer);
21051 +       for_each_online_cpu(cpu) {
21052 +               length += vx_info_proc_sched_pc(
21053 +                       &vx_per_cpu(vxi, sched_pc, cpu),
21054 +                       buffer + length, cpu);
21055 +       }
21056 +       return length;
21057 +}
21058 +
21059 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
21060 +{
21061 +       return vx_info_proc_nsproxy(vxi->space[0].vx_nsproxy, buffer);
21062 +}
21063 +
21064 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
21065 +{
21066 +       return vx_info_proc_nsproxy(vxi->space[1].vx_nsproxy, buffer);
21067 +}
21068 +
21069 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
21070 +{
21071 +       int cpu, length;
21072 +
21073 +       vx_update_load(vxi);
21074 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
21075 +       for_each_online_cpu(cpu) {
21076 +               length += vx_info_proc_cvirt_pc(
21077 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
21078 +                       buffer + length, cpu);
21079 +       }
21080 +       return length;
21081 +}
21082 +
21083 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
21084 +{
21085 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
21086 +}
21087 +
21088 +
21089 +static int proc_virtnet_info(char *buffer)
21090 +{
21091 +       return proc_vci(buffer);
21092 +}
21093 +
21094 +static int proc_virtnet_status(char *buffer)
21095 +{
21096 +       return sprintf(buffer,
21097 +               "#CTotal:\t%d\n"
21098 +               "#CActive:\t%d\n",
21099 +               atomic_read(&nx_global_ctotal),
21100 +               atomic_read(&nx_global_cactive));
21101 +}
21102 +
21103 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
21104 +{
21105 +       struct nx_addr_v4 *v4a;
21106 +#ifdef CONFIG_IPV6
21107 +       struct nx_addr_v6 *v6a;
21108 +#endif
21109 +       int length, i;
21110 +
21111 +       length = sprintf(buffer,
21112 +               "ID:\t%d\n"
21113 +               "Info:\t%p\n"
21114 +               "Bcast:\t" NIPQUAD_FMT "\n"
21115 +               "Lback:\t" NIPQUAD_FMT "\n",
21116 +               nxi->nx_id,
21117 +               nxi,
21118 +               NIPQUAD(nxi->v4_bcast.s_addr),
21119 +               NIPQUAD(nxi->v4_lback.s_addr));
21120 +
21121 +       if (!NX_IPV4(nxi))
21122 +               goto skip_v4;
21123 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
21124 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
21125 +                       i, NXAV4(v4a));
21126 +skip_v4:
21127 +#ifdef CONFIG_IPV6
21128 +       if (!NX_IPV6(nxi))
21129 +               goto skip_v6;
21130 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
21131 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
21132 +                       i, NXAV6(v6a));
21133 +skip_v6:
21134 +#endif
21135 +       return length;
21136 +}
21137 +
21138 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
21139 +{
21140 +       int length;
21141 +
21142 +       length = sprintf(buffer,
21143 +               "UseCnt:\t%d\n"
21144 +               "Tasks:\t%d\n"
21145 +               "Flags:\t%016llx\n"
21146 +               "NCaps:\t%016llx\n",
21147 +               atomic_read(&nxi->nx_usecnt),
21148 +               atomic_read(&nxi->nx_tasks),
21149 +               (unsigned long long)nxi->nx_flags,
21150 +               (unsigned long long)nxi->nx_ncaps);
21151 +       return length;
21152 +}
21153 +
21154 +
21155 +
21156 +/* here the inode helpers */
21157 +
21158 +struct vs_entry {
21159 +       int len;
21160 +       char *name;
21161 +       mode_t mode;
21162 +       struct inode_operations *iop;
21163 +       struct file_operations *fop;
21164 +       union proc_op op;
21165 +};
21166 +
21167 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
21168 +{
21169 +       struct inode *inode = new_inode(sb);
21170 +
21171 +       if (!inode)
21172 +               goto out;
21173 +
21174 +       inode->i_mode = p->mode;
21175 +       if (p->iop)
21176 +               inode->i_op = p->iop;
21177 +       if (p->fop)
21178 +               inode->i_fop = p->fop;
21179 +
21180 +       set_nlink(inode, (p->mode & S_IFDIR) ? 2 : 1);
21181 +       inode->i_flags |= S_IMMUTABLE;
21182 +
21183 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
21184 +
21185 +       i_uid_write(inode, 0);
21186 +       i_gid_write(inode, 0);
21187 +       i_tag_write(inode, 0);
21188 +out:
21189 +       return inode;
21190 +}
21191 +
21192 +static struct dentry *vs_proc_instantiate(struct inode *dir,
21193 +       struct dentry *dentry, int id, void *ptr)
21194 +{
21195 +       struct vs_entry *p = ptr;
21196 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
21197 +       struct dentry *error = ERR_PTR(-EINVAL);
21198 +
21199 +       if (!inode)
21200 +               goto out;
21201 +
21202 +       PROC_I(inode)->op = p->op;
21203 +       PROC_I(inode)->fd = id;
21204 +       d_add(dentry, inode);
21205 +       error = NULL;
21206 +out:
21207 +       return error;
21208 +}
21209 +
21210 +/* Lookups */
21211 +
21212 +typedef struct dentry *vx_instantiate_t(struct inode *, struct dentry *, int, void *);
21213 +
21214 +
21215 +/*
21216 + * Fill a directory entry.
21217 + *
21218 + * If possible create the dcache entry and derive our inode number and
21219 + * file type from dcache entry.
21220 + *
21221 + * Since all of the proc inode numbers are dynamically generated, the inode
21222 + * numbers do not exist until the inode is cache.  This means creating the
21223 + * the dcache entry in readdir is necessary to keep the inode numbers
21224 + * reported by readdir in sync with the inode numbers reported
21225 + * by stat.
21226 + */
21227 +static int vx_proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
21228 +       char *name, int len, vx_instantiate_t instantiate, int id, void *ptr)
21229 +{
21230 +       struct dentry *child, *dir = filp->f_dentry;
21231 +       struct inode *inode;
21232 +       struct qstr qname;
21233 +       ino_t ino = 0;
21234 +       unsigned type = DT_UNKNOWN;
21235 +
21236 +       qname.name = name;
21237 +       qname.len  = len;
21238 +       qname.hash = full_name_hash(name, len);
21239 +
21240 +       child = d_lookup(dir, &qname);
21241 +       if (!child) {
21242 +               struct dentry *new;
21243 +               new = d_alloc(dir, &qname);
21244 +               if (new) {
21245 +                       child = instantiate(dir->d_inode, new, id, ptr);
21246 +                       if (child)
21247 +                               dput(new);
21248 +                       else
21249 +                               child = new;
21250 +               }
21251 +       }
21252 +       if (!child || IS_ERR(child) || !child->d_inode)
21253 +               goto end_instantiate;
21254 +       inode = child->d_inode;
21255 +       if (inode) {
21256 +               ino = inode->i_ino;
21257 +               type = inode->i_mode >> 12;
21258 +       }
21259 +       dput(child);
21260 +end_instantiate:
21261 +       if (!ino)
21262 +               ino = find_inode_number(dir, &qname);
21263 +       if (!ino)
21264 +               ino = 1;
21265 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
21266 +}
21267 +
21268 +
21269 +
21270 +/* get and revalidate vx_info/xid */
21271 +
21272 +static inline
21273 +struct vx_info *get_proc_vx_info(struct inode *inode)
21274 +{
21275 +       return lookup_vx_info(PROC_I(inode)->fd);
21276 +}
21277 +
21278 +static int proc_xid_revalidate(struct dentry *dentry, unsigned int flags)
21279 +{
21280 +       struct inode *inode = dentry->d_inode;
21281 +       vxid_t xid = PROC_I(inode)->fd;
21282 +
21283 +       if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
21284 +               return -ECHILD;
21285 +
21286 +       if (!xid || xid_is_hashed(xid))
21287 +               return 1;
21288 +       d_drop(dentry);
21289 +       return 0;
21290 +}
21291 +
21292 +
21293 +/* get and revalidate nx_info/nid */
21294 +
21295 +static int proc_nid_revalidate(struct dentry *dentry, unsigned int flags)
21296 +{
21297 +       struct inode *inode = dentry->d_inode;
21298 +       vnid_t nid = PROC_I(inode)->fd;
21299 +
21300 +       if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
21301 +               return -ECHILD;
21302 +
21303 +       if (!nid || nid_is_hashed(nid))
21304 +               return 1;
21305 +       d_drop(dentry);
21306 +       return 0;
21307 +}
21308 +
21309 +
21310 +
21311 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
21312 +
21313 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
21314 +                         size_t count, loff_t *ppos)
21315 +{
21316 +       struct inode *inode = file->f_dentry->d_inode;
21317 +       unsigned long page;
21318 +       ssize_t length = 0;
21319 +
21320 +       if (count > PROC_BLOCK_SIZE)
21321 +               count = PROC_BLOCK_SIZE;
21322 +
21323 +       /* fade that out as soon as stable */
21324 +       WARN_ON(PROC_I(inode)->fd);
21325 +
21326 +       if (!(page = __get_free_page(GFP_KERNEL)))
21327 +               return -ENOMEM;
21328 +
21329 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
21330 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
21331 +
21332 +       if (length >= 0)
21333 +               length = simple_read_from_buffer(buf, count, ppos,
21334 +                       (char *)page, length);
21335 +
21336 +       free_page(page);
21337 +       return length;
21338 +}
21339 +
21340 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
21341 +                         size_t count, loff_t *ppos)
21342 +{
21343 +       struct inode *inode = file->f_dentry->d_inode;
21344 +       struct vx_info *vxi = NULL;
21345 +       vxid_t xid = PROC_I(inode)->fd;
21346 +       unsigned long page;
21347 +       ssize_t length = 0;
21348 +
21349 +       if (count > PROC_BLOCK_SIZE)
21350 +               count = PROC_BLOCK_SIZE;
21351 +
21352 +       /* fade that out as soon as stable */
21353 +       WARN_ON(!xid);
21354 +       vxi = lookup_vx_info(xid);
21355 +       if (!vxi)
21356 +               goto out;
21357 +
21358 +       length = -ENOMEM;
21359 +       if (!(page = __get_free_page(GFP_KERNEL)))
21360 +               goto out_put;
21361 +
21362 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
21363 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
21364 +
21365 +       if (length >= 0)
21366 +               length = simple_read_from_buffer(buf, count, ppos,
21367 +                       (char *)page, length);
21368 +
21369 +       free_page(page);
21370 +out_put:
21371 +       put_vx_info(vxi);
21372 +out:
21373 +       return length;
21374 +}
21375 +
21376 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
21377 +                         size_t count, loff_t *ppos)
21378 +{
21379 +       struct inode *inode = file->f_dentry->d_inode;
21380 +       struct nx_info *nxi = NULL;
21381 +       vnid_t nid = PROC_I(inode)->fd;
21382 +       unsigned long page;
21383 +       ssize_t length = 0;
21384 +
21385 +       if (count > PROC_BLOCK_SIZE)
21386 +               count = PROC_BLOCK_SIZE;
21387 +
21388 +       /* fade that out as soon as stable */
21389 +       WARN_ON(!nid);
21390 +       nxi = lookup_nx_info(nid);
21391 +       if (!nxi)
21392 +               goto out;
21393 +
21394 +       length = -ENOMEM;
21395 +       if (!(page = __get_free_page(GFP_KERNEL)))
21396 +               goto out_put;
21397 +
21398 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
21399 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
21400 +
21401 +       if (length >= 0)
21402 +               length = simple_read_from_buffer(buf, count, ppos,
21403 +                       (char *)page, length);
21404 +
21405 +       free_page(page);
21406 +out_put:
21407 +       put_nx_info(nxi);
21408 +out:
21409 +       return length;
21410 +}
21411 +
21412 +
21413 +
21414 +/* here comes the lower level */
21415 +
21416 +
21417 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
21418 +       .len  = sizeof(NAME) - 1,       \
21419 +       .name = (NAME),                 \
21420 +       .mode = MODE,                   \
21421 +       .iop  = IOP,                    \
21422 +       .fop  = FOP,                    \
21423 +       .op   = OP,                     \
21424 +}
21425 +
21426 +
21427 +#define DIR(NAME, MODE, OTYPE)                         \
21428 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
21429 +               &proc_ ## OTYPE ## _inode_operations,   \
21430 +               &proc_ ## OTYPE ## _file_operations, { } )
21431 +
21432 +#define INF(NAME, MODE, OTYPE)                         \
21433 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21434 +               &proc_vs_info_file_operations,          \
21435 +               { .proc_vs_read = &proc_##OTYPE } )
21436 +
21437 +#define VINF(NAME, MODE, OTYPE)                                \
21438 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21439 +               &proc_vx_info_file_operations,          \
21440 +               { .proc_vxi_read = &proc_##OTYPE } )
21441 +
21442 +#define NINF(NAME, MODE, OTYPE)                                \
21443 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21444 +               &proc_nx_info_file_operations,          \
21445 +               { .proc_nxi_read = &proc_##OTYPE } )
21446 +
21447 +
21448 +static struct file_operations proc_vs_info_file_operations = {
21449 +       .read =         proc_vs_info_read,
21450 +};
21451 +
21452 +static struct file_operations proc_vx_info_file_operations = {
21453 +       .read =         proc_vx_info_read,
21454 +};
21455 +
21456 +static struct dentry_operations proc_xid_dentry_operations = {
21457 +       .d_revalidate = proc_xid_revalidate,
21458 +};
21459 +
21460 +static struct vs_entry vx_base_stuff[] = {
21461 +       VINF("info",    S_IRUGO, vxi_info),
21462 +       VINF("status",  S_IRUGO, vxi_status),
21463 +       VINF("limit",   S_IRUGO, vxi_limit),
21464 +       VINF("sched",   S_IRUGO, vxi_sched),
21465 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
21466 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
21467 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
21468 +       VINF("cacct",   S_IRUGO, vxi_cacct),
21469 +       {}
21470 +};
21471 +
21472 +
21473 +
21474 +
21475 +static struct dentry *proc_xid_instantiate(struct inode *dir,
21476 +       struct dentry *dentry, int id, void *ptr)
21477 +{
21478 +       dentry->d_op = &proc_xid_dentry_operations;
21479 +       return vs_proc_instantiate(dir, dentry, id, ptr);
21480 +}
21481 +
21482 +static struct dentry *proc_xid_lookup(struct inode *dir,
21483 +       struct dentry *dentry, unsigned int flags)
21484 +{
21485 +       struct vs_entry *p = vx_base_stuff;
21486 +       struct dentry *error = ERR_PTR(-ENOENT);
21487 +
21488 +       for (; p->name; p++) {
21489 +               if (p->len != dentry->d_name.len)
21490 +                       continue;
21491 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21492 +                       break;
21493 +       }
21494 +       if (!p->name)
21495 +               goto out;
21496 +
21497 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
21498 +out:
21499 +       return error;
21500 +}
21501 +
21502 +static int proc_xid_readdir(struct file *filp,
21503 +       void *dirent, filldir_t filldir)
21504 +{
21505 +       struct dentry *dentry = filp->f_dentry;
21506 +       struct inode *inode = dentry->d_inode;
21507 +       struct vs_entry *p = vx_base_stuff;
21508 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
21509 +       int pos, index;
21510 +       u64 ino;
21511 +
21512 +       pos = filp->f_pos;
21513 +       switch (pos) {
21514 +       case 0:
21515 +               ino = inode->i_ino;
21516 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21517 +                       goto out;
21518 +               pos++;
21519 +               /* fall through */
21520 +       case 1:
21521 +               ino = parent_ino(dentry);
21522 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21523 +                       goto out;
21524 +               pos++;
21525 +               /* fall through */
21526 +       default:
21527 +               index = pos - 2;
21528 +               if (index >= size)
21529 +                       goto out;
21530 +               for (p += index; p->name; p++) {
21531 +                       if (vx_proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21532 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
21533 +                               goto out;
21534 +                       pos++;
21535 +               }
21536 +       }
21537 +out:
21538 +       filp->f_pos = pos;
21539 +       return 1;
21540 +}
21541 +
21542 +
21543 +
21544 +static struct file_operations proc_nx_info_file_operations = {
21545 +       .read =         proc_nx_info_read,
21546 +};
21547 +
21548 +static struct dentry_operations proc_nid_dentry_operations = {
21549 +       .d_revalidate = proc_nid_revalidate,
21550 +};
21551 +
21552 +static struct vs_entry nx_base_stuff[] = {
21553 +       NINF("info",    S_IRUGO, nxi_info),
21554 +       NINF("status",  S_IRUGO, nxi_status),
21555 +       {}
21556 +};
21557 +
21558 +
21559 +static struct dentry *proc_nid_instantiate(struct inode *dir,
21560 +       struct dentry *dentry, int id, void *ptr)
21561 +{
21562 +       dentry->d_op = &proc_nid_dentry_operations;
21563 +       return vs_proc_instantiate(dir, dentry, id, ptr);
21564 +}
21565 +
21566 +static struct dentry *proc_nid_lookup(struct inode *dir,
21567 +       struct dentry *dentry, unsigned int flags)
21568 +{
21569 +       struct vs_entry *p = nx_base_stuff;
21570 +       struct dentry *error = ERR_PTR(-ENOENT);
21571 +
21572 +       for (; p->name; p++) {
21573 +               if (p->len != dentry->d_name.len)
21574 +                       continue;
21575 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21576 +                       break;
21577 +       }
21578 +       if (!p->name)
21579 +               goto out;
21580 +
21581 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
21582 +out:
21583 +       return error;
21584 +}
21585 +
21586 +static int proc_nid_readdir(struct file *filp,
21587 +       void *dirent, filldir_t filldir)
21588 +{
21589 +       struct dentry *dentry = filp->f_dentry;
21590 +       struct inode *inode = dentry->d_inode;
21591 +       struct vs_entry *p = nx_base_stuff;
21592 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
21593 +       int pos, index;
21594 +       u64 ino;
21595 +
21596 +       pos = filp->f_pos;
21597 +       switch (pos) {
21598 +       case 0:
21599 +               ino = inode->i_ino;
21600 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21601 +                       goto out;
21602 +               pos++;
21603 +               /* fall through */
21604 +       case 1:
21605 +               ino = parent_ino(dentry);
21606 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21607 +                       goto out;
21608 +               pos++;
21609 +               /* fall through */
21610 +       default:
21611 +               index = pos - 2;
21612 +               if (index >= size)
21613 +                       goto out;
21614 +               for (p += index; p->name; p++) {
21615 +                       if (vx_proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21616 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
21617 +                               goto out;
21618 +                       pos++;
21619 +               }
21620 +       }
21621 +out:
21622 +       filp->f_pos = pos;
21623 +       return 1;
21624 +}
21625 +
21626 +
21627 +#define MAX_MULBY10    ((~0U - 9) / 10)
21628 +
21629 +static inline int atovid(const char *str, int len)
21630 +{
21631 +       int vid, c;
21632 +
21633 +       vid = 0;
21634 +       while (len-- > 0) {
21635 +               c = *str - '0';
21636 +               str++;
21637 +               if (c > 9)
21638 +                       return -1;
21639 +               if (vid >= MAX_MULBY10)
21640 +                       return -1;
21641 +               vid *= 10;
21642 +               vid += c;
21643 +               if (!vid)
21644 +                       return -1;
21645 +       }
21646 +       return vid;
21647 +}
21648 +
21649 +/* now the upper level (virtual) */
21650 +
21651 +
21652 +static struct file_operations proc_xid_file_operations = {
21653 +       .read =         generic_read_dir,
21654 +       .readdir =      proc_xid_readdir,
21655 +};
21656 +
21657 +static struct inode_operations proc_xid_inode_operations = {
21658 +       .lookup =       proc_xid_lookup,
21659 +};
21660 +
21661 +static struct vs_entry vx_virtual_stuff[] = {
21662 +       INF("info",     S_IRUGO, virtual_info),
21663 +       INF("status",   S_IRUGO, virtual_status),
21664 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
21665 +};
21666 +
21667 +
21668 +static struct dentry *proc_virtual_lookup(struct inode *dir,
21669 +       struct dentry *dentry, unsigned int flags)
21670 +{
21671 +       struct vs_entry *p = vx_virtual_stuff;
21672 +       struct dentry *error = ERR_PTR(-ENOENT);
21673 +       int id = 0;
21674 +
21675 +       for (; p->name; p++) {
21676 +               if (p->len != dentry->d_name.len)
21677 +                       continue;
21678 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21679 +                       break;
21680 +       }
21681 +       if (p->name)
21682 +               goto instantiate;
21683 +
21684 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
21685 +       if ((id < 0) || !xid_is_hashed(id))
21686 +               goto out;
21687 +
21688 +instantiate:
21689 +       error = proc_xid_instantiate(dir, dentry, id, p);
21690 +out:
21691 +       return error;
21692 +}
21693 +
21694 +static struct file_operations proc_nid_file_operations = {
21695 +       .read =         generic_read_dir,
21696 +       .readdir =      proc_nid_readdir,
21697 +};
21698 +
21699 +static struct inode_operations proc_nid_inode_operations = {
21700 +       .lookup =       proc_nid_lookup,
21701 +};
21702 +
21703 +static struct vs_entry nx_virtnet_stuff[] = {
21704 +       INF("info",     S_IRUGO, virtnet_info),
21705 +       INF("status",   S_IRUGO, virtnet_status),
21706 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
21707 +};
21708 +
21709 +
21710 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
21711 +       struct dentry *dentry, unsigned int flags)
21712 +{
21713 +       struct vs_entry *p = nx_virtnet_stuff;
21714 +       struct dentry *error = ERR_PTR(-ENOENT);
21715 +       int id = 0;
21716 +
21717 +       for (; p->name; p++) {
21718 +               if (p->len != dentry->d_name.len)
21719 +                       continue;
21720 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21721 +                       break;
21722 +       }
21723 +       if (p->name)
21724 +               goto instantiate;
21725 +
21726 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
21727 +       if ((id < 0) || !nid_is_hashed(id))
21728 +               goto out;
21729 +
21730 +instantiate:
21731 +       error = proc_nid_instantiate(dir, dentry, id, p);
21732 +out:
21733 +       return error;
21734 +}
21735 +
21736 +
21737 +#define PROC_MAXVIDS 32
21738 +
21739 +int proc_virtual_readdir(struct file *filp,
21740 +       void *dirent, filldir_t filldir)
21741 +{
21742 +       struct dentry *dentry = filp->f_dentry;
21743 +       struct inode *inode = dentry->d_inode;
21744 +       struct vs_entry *p = vx_virtual_stuff;
21745 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
21746 +       int pos, index;
21747 +       unsigned int xid_array[PROC_MAXVIDS];
21748 +       char buf[PROC_NUMBUF];
21749 +       unsigned int nr_xids, i;
21750 +       u64 ino;
21751 +
21752 +       pos = filp->f_pos;
21753 +       switch (pos) {
21754 +       case 0:
21755 +               ino = inode->i_ino;
21756 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21757 +                       goto out;
21758 +               pos++;
21759 +               /* fall through */
21760 +       case 1:
21761 +               ino = parent_ino(dentry);
21762 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21763 +                       goto out;
21764 +               pos++;
21765 +               /* fall through */
21766 +       default:
21767 +               index = pos - 2;
21768 +               if (index >= size)
21769 +                       goto entries;
21770 +               for (p += index; p->name; p++) {
21771 +                       if (vx_proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21772 +                               vs_proc_instantiate, 0, p))
21773 +                               goto out;
21774 +                       pos++;
21775 +               }
21776 +       entries:
21777 +               index = pos - size;
21778 +               p = &vx_virtual_stuff[size - 1];
21779 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
21780 +               for (i = 0; i < nr_xids; i++) {
21781 +                       int n, xid = xid_array[i];
21782 +                       unsigned int j = PROC_NUMBUF;
21783 +
21784 +                       n = xid;
21785 +                       do
21786 +                               buf[--j] = '0' + (n % 10);
21787 +                       while (n /= 10);
21788 +
21789 +                       if (vx_proc_fill_cache(filp, dirent, filldir,
21790 +                               buf + j, PROC_NUMBUF - j,
21791 +                               vs_proc_instantiate, xid, p))
21792 +                               goto out;
21793 +                       pos++;
21794 +               }
21795 +       }
21796 +out:
21797 +       filp->f_pos = pos;
21798 +       return 0;
21799 +}
21800 +
21801 +static int proc_virtual_getattr(struct vfsmount *mnt,
21802 +       struct dentry *dentry, struct kstat *stat)
21803 +{
21804 +       struct inode *inode = dentry->d_inode;
21805 +
21806 +       generic_fillattr(inode, stat);
21807 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
21808 +       return 0;
21809 +}
21810 +
21811 +static struct file_operations proc_virtual_dir_operations = {
21812 +       .read =         generic_read_dir,
21813 +       .readdir =      proc_virtual_readdir,
21814 +};
21815 +
21816 +static struct inode_operations proc_virtual_dir_inode_operations = {
21817 +       .getattr =      proc_virtual_getattr,
21818 +       .lookup =       proc_virtual_lookup,
21819 +};
21820 +
21821 +
21822 +
21823 +
21824 +
21825 +int proc_virtnet_readdir(struct file *filp,
21826 +       void *dirent, filldir_t filldir)
21827 +{
21828 +       struct dentry *dentry = filp->f_dentry;
21829 +       struct inode *inode = dentry->d_inode;
21830 +       struct vs_entry *p = nx_virtnet_stuff;
21831 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
21832 +       int pos, index;
21833 +       unsigned int nid_array[PROC_MAXVIDS];
21834 +       char buf[PROC_NUMBUF];
21835 +       unsigned int nr_nids, i;
21836 +       u64 ino;
21837 +
21838 +       pos = filp->f_pos;
21839 +       switch (pos) {
21840 +       case 0:
21841 +               ino = inode->i_ino;
21842 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21843 +                       goto out;
21844 +               pos++;
21845 +               /* fall through */
21846 +       case 1:
21847 +               ino = parent_ino(dentry);
21848 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21849 +                       goto out;
21850 +               pos++;
21851 +               /* fall through */
21852 +       default:
21853 +               index = pos - 2;
21854 +               if (index >= size)
21855 +                       goto entries;
21856 +               for (p += index; p->name; p++) {
21857 +                       if (vx_proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21858 +                               vs_proc_instantiate, 0, p))
21859 +                               goto out;
21860 +                       pos++;
21861 +               }
21862 +       entries:
21863 +               index = pos - size;
21864 +               p = &nx_virtnet_stuff[size - 1];
21865 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
21866 +               for (i = 0; i < nr_nids; i++) {
21867 +                       int n, nid = nid_array[i];
21868 +                       unsigned int j = PROC_NUMBUF;
21869 +
21870 +                       n = nid;
21871 +                       do
21872 +                               buf[--j] = '0' + (n % 10);
21873 +                       while (n /= 10);
21874 +
21875 +                       if (vx_proc_fill_cache(filp, dirent, filldir,
21876 +                               buf + j, PROC_NUMBUF - j,
21877 +                               vs_proc_instantiate, nid, p))
21878 +                               goto out;
21879 +                       pos++;
21880 +               }
21881 +       }
21882 +out:
21883 +       filp->f_pos = pos;
21884 +       return 0;
21885 +}
21886 +
21887 +static int proc_virtnet_getattr(struct vfsmount *mnt,
21888 +       struct dentry *dentry, struct kstat *stat)
21889 +{
21890 +       struct inode *inode = dentry->d_inode;
21891 +
21892 +       generic_fillattr(inode, stat);
21893 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
21894 +       return 0;
21895 +}
21896 +
21897 +static struct file_operations proc_virtnet_dir_operations = {
21898 +       .read =         generic_read_dir,
21899 +       .readdir =      proc_virtnet_readdir,
21900 +};
21901 +
21902 +static struct inode_operations proc_virtnet_dir_inode_operations = {
21903 +       .getattr =      proc_virtnet_getattr,
21904 +       .lookup =       proc_virtnet_lookup,
21905 +};
21906 +
21907 +
21908 +
21909 +void proc_vx_init(void)
21910 +{
21911 +       struct proc_dir_entry *ent;
21912 +
21913 +       ent = proc_mkdir("virtual", 0);
21914 +       if (ent) {
21915 +               ent->proc_fops = &proc_virtual_dir_operations;
21916 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
21917 +       }
21918 +       proc_virtual = ent;
21919 +
21920 +       ent = proc_mkdir("virtnet", 0);
21921 +       if (ent) {
21922 +               ent->proc_fops = &proc_virtnet_dir_operations;
21923 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
21924 +       }
21925 +       proc_virtnet = ent;
21926 +}
21927 +
21928 +
21929 +
21930 +
21931 +/* per pid info */
21932 +
21933 +
21934 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
21935 +{
21936 +       struct vx_info *vxi;
21937 +       char *orig = buffer;
21938 +
21939 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
21940 +
21941 +       vxi = task_get_vx_info(p);
21942 +       if (!vxi)
21943 +               goto out;
21944 +
21945 +       buffer += sprintf(buffer, "BCaps:\t");
21946 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
21947 +       buffer += sprintf(buffer, "\n");
21948 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
21949 +               (unsigned long long)vxi->vx_ccaps);
21950 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
21951 +               (unsigned long long)vxi->vx_flags);
21952 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
21953 +
21954 +       put_vx_info(vxi);
21955 +out:
21956 +       return buffer - orig;
21957 +}
21958 +
21959 +
21960 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
21961 +{
21962 +       struct nx_info *nxi;
21963 +       struct nx_addr_v4 *v4a;
21964 +#ifdef CONFIG_IPV6
21965 +       struct nx_addr_v6 *v6a;
21966 +#endif
21967 +       char *orig = buffer;
21968 +       int i;
21969 +
21970 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
21971 +
21972 +       nxi = task_get_nx_info(p);
21973 +       if (!nxi)
21974 +               goto out;
21975 +
21976 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
21977 +               (unsigned long long)nxi->nx_ncaps);
21978 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
21979 +               (unsigned long long)nxi->nx_flags);
21980 +
21981 +       buffer += sprintf(buffer,
21982 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
21983 +               NIPQUAD(nxi->v4_bcast.s_addr));
21984 +       buffer += sprintf (buffer,
21985 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
21986 +               NIPQUAD(nxi->v4_lback.s_addr));
21987 +       if (!NX_IPV4(nxi))
21988 +               goto skip_v4;
21989 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
21990 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
21991 +                       i, NXAV4(v4a));
21992 +skip_v4:
21993 +#ifdef CONFIG_IPV6
21994 +       if (!NX_IPV6(nxi))
21995 +               goto skip_v6;
21996 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
21997 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
21998 +                       i, NXAV6(v6a));
21999 +skip_v6:
22000 +#endif
22001 +       put_nx_info(nxi);
22002 +out:
22003 +       return buffer - orig;
22004 +}
22005 +
22006 diff -NurpP --minimal linux-3.10.33/kernel/vserver/sched.c linux-3.10.33-vs2.3.6.8/kernel/vserver/sched.c
22007 --- linux-3.10.33/kernel/vserver/sched.c        1970-01-01 00:00:00.000000000 +0000
22008 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/sched.c      2013-08-22 20:30:00.000000000 +0000
22009 @@ -0,0 +1,83 @@
22010 +/*
22011 + *  linux/kernel/vserver/sched.c
22012 + *
22013 + *  Virtual Server: Scheduler Support
22014 + *
22015 + *  Copyright (C) 2004-2010  Herbert Pötzl
22016 + *
22017 + *  V0.01  adapted Sam Vilains version to 2.6.3
22018 + *  V0.02  removed legacy interface
22019 + *  V0.03  changed vcmds to vxi arg
22020 + *  V0.04  removed older and legacy interfaces
22021 + *  V0.05  removed scheduler code/commands
22022 + *
22023 + */
22024 +
22025 +#include <linux/vs_context.h>
22026 +#include <linux/vs_sched.h>
22027 +#include <linux/cpumask.h>
22028 +#include <linux/vserver/sched_cmd.h>
22029 +
22030 +#include <asm/uaccess.h>
22031 +
22032 +
22033 +void vx_update_sched_param(struct _vx_sched *sched,
22034 +       struct _vx_sched_pc *sched_pc)
22035 +{
22036 +       sched_pc->prio_bias = sched->prio_bias;
22037 +}
22038 +
22039 +static int do_set_prio_bias(struct vx_info *vxi, struct vcmd_prio_bias *data)
22040 +{
22041 +       int cpu;
22042 +
22043 +       if (data->prio_bias > MAX_PRIO_BIAS)
22044 +               data->prio_bias = MAX_PRIO_BIAS;
22045 +       if (data->prio_bias < MIN_PRIO_BIAS)
22046 +               data->prio_bias = MIN_PRIO_BIAS;
22047 +
22048 +       if (data->cpu_id != ~0) {
22049 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
22050 +               cpumask_and(&vxi->sched.update, &vxi->sched.update,
22051 +                       cpu_online_mask);
22052 +       } else
22053 +               cpumask_copy(&vxi->sched.update, cpu_online_mask);
22054 +
22055 +       for_each_cpu_mask(cpu, vxi->sched.update)
22056 +               vx_update_sched_param(&vxi->sched,
22057 +                       &vx_per_cpu(vxi, sched_pc, cpu));
22058 +       return 0;
22059 +}
22060 +
22061 +int vc_set_prio_bias(struct vx_info *vxi, void __user *data)
22062 +{
22063 +       struct vcmd_prio_bias vc_data;
22064 +
22065 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22066 +               return -EFAULT;
22067 +
22068 +       return do_set_prio_bias(vxi, &vc_data);
22069 +}
22070 +
22071 +int vc_get_prio_bias(struct vx_info *vxi, void __user *data)
22072 +{
22073 +       struct vcmd_prio_bias vc_data;
22074 +       struct _vx_sched_pc *pcd;
22075 +       int cpu;
22076 +
22077 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22078 +               return -EFAULT;
22079 +
22080 +       cpu = vc_data.cpu_id;
22081 +
22082 +       if (!cpu_possible(cpu))
22083 +               return -EINVAL;
22084 +
22085 +       pcd = &vx_per_cpu(vxi, sched_pc, cpu);
22086 +       vc_data.prio_bias = pcd->prio_bias;
22087 +
22088 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22089 +               return -EFAULT;
22090 +       return 0;
22091 +}
22092 +
22093 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
22094 --- linux-3.10.33/kernel/vserver/sched_init.h   1970-01-01 00:00:00.000000000 +0000
22095 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/sched_init.h 2013-08-22 20:30:00.000000000 +0000
22096 @@ -0,0 +1,27 @@
22097 +
22098 +static inline void vx_info_init_sched(struct _vx_sched *sched)
22099 +{
22100 +       /* scheduling; hard code starting values as constants */
22101 +       sched->prio_bias = 0;
22102 +}
22103 +
22104 +static inline
22105 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22106 +{
22107 +       sched_pc->prio_bias = 0;
22108 +
22109 +       sched_pc->user_ticks = 0;
22110 +       sched_pc->sys_ticks = 0;
22111 +       sched_pc->hold_ticks = 0;
22112 +}
22113 +
22114 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
22115 +{
22116 +       return;
22117 +}
22118 +
22119 +static inline
22120 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22121 +{
22122 +       return;
22123 +}
22124 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
22125 --- linux-3.10.33/kernel/vserver/sched_proc.h   1970-01-01 00:00:00.000000000 +0000
22126 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/sched_proc.h 2013-08-22 20:30:00.000000000 +0000
22127 @@ -0,0 +1,32 @@
22128 +#ifndef _VX_SCHED_PROC_H
22129 +#define _VX_SCHED_PROC_H
22130 +
22131 +
22132 +static inline
22133 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
22134 +{
22135 +       int length = 0;
22136 +
22137 +       length += sprintf(buffer,
22138 +               "PrioBias:\t%8d\n",
22139 +               sched->prio_bias);
22140 +       return length;
22141 +}
22142 +
22143 +static inline
22144 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
22145 +       char *buffer, int cpu)
22146 +{
22147 +       int length = 0;
22148 +
22149 +       length += sprintf(buffer + length,
22150 +               "cpu %d: %lld %lld %lld", cpu,
22151 +               (unsigned long long)sched_pc->user_ticks,
22152 +               (unsigned long long)sched_pc->sys_ticks,
22153 +               (unsigned long long)sched_pc->hold_ticks);
22154 +       length += sprintf(buffer + length,
22155 +               " %d\n", sched_pc->prio_bias);
22156 +       return length;
22157 +}
22158 +
22159 +#endif /* _VX_SCHED_PROC_H */
22160 diff -NurpP --minimal linux-3.10.33/kernel/vserver/signal.c linux-3.10.33-vs2.3.6.8/kernel/vserver/signal.c
22161 --- linux-3.10.33/kernel/vserver/signal.c       1970-01-01 00:00:00.000000000 +0000
22162 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/signal.c     2013-08-22 20:30:00.000000000 +0000
22163 @@ -0,0 +1,134 @@
22164 +/*
22165 + *  linux/kernel/vserver/signal.c
22166 + *
22167 + *  Virtual Server: Signal Support
22168 + *
22169 + *  Copyright (C) 2003-2007  Herbert Pötzl
22170 + *
22171 + *  V0.01  broken out from vcontext V0.05
22172 + *  V0.02  changed vcmds to vxi arg
22173 + *  V0.03  adjusted siginfo for kill
22174 + *
22175 + */
22176 +
22177 +#include <asm/uaccess.h>
22178 +
22179 +#include <linux/vs_context.h>
22180 +#include <linux/vs_pid.h>
22181 +#include <linux/vserver/signal_cmd.h>
22182 +
22183 +
22184 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
22185 +{
22186 +       int retval, count = 0;
22187 +       struct task_struct *p;
22188 +       struct siginfo *sip = SEND_SIG_PRIV;
22189 +
22190 +       retval = -ESRCH;
22191 +       vxdprintk(VXD_CBIT(misc, 4),
22192 +               "vx_info_kill(%p[#%d],%d,%d)*",
22193 +               vxi, vxi->vx_id, pid, sig);
22194 +       read_lock(&tasklist_lock);
22195 +       switch (pid) {
22196 +       case  0:
22197 +       case -1:
22198 +               for_each_process(p) {
22199 +                       int err = 0;
22200 +
22201 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
22202 +                               (pid && vxi->vx_initpid == p->pid))
22203 +                               continue;
22204 +
22205 +                       err = group_send_sig_info(sig, sip, p);
22206 +                       ++count;
22207 +                       if (err != -EPERM)
22208 +                               retval = err;
22209 +               }
22210 +               break;
22211 +
22212 +       case 1:
22213 +               if (vxi->vx_initpid) {
22214 +                       pid = vxi->vx_initpid;
22215 +                       /* for now, only SIGINT to private init ... */
22216 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22217 +                               /* ... as long as there are tasks left */
22218 +                               (atomic_read(&vxi->vx_tasks) > 1))
22219 +                               sig = SIGINT;
22220 +               }
22221 +               /* fallthrough */
22222 +       default:
22223 +               rcu_read_lock();
22224 +               p = find_task_by_real_pid(pid);
22225 +               rcu_read_unlock();
22226 +               if (p) {
22227 +                       if (vx_task_xid(p) == vxi->vx_id)
22228 +                               retval = group_send_sig_info(sig, sip, p);
22229 +               }
22230 +               break;
22231 +       }
22232 +       read_unlock(&tasklist_lock);
22233 +       vxdprintk(VXD_CBIT(misc, 4),
22234 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
22235 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
22236 +       return retval;
22237 +}
22238 +
22239 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
22240 +{
22241 +       struct vcmd_ctx_kill_v0 vc_data;
22242 +
22243 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22244 +               return -EFAULT;
22245 +
22246 +       /* special check to allow guest shutdown */
22247 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22248 +               /* forbid killall pid=0 when init is present */
22249 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
22250 +               (vc_data.pid > 1)))
22251 +               return -EACCES;
22252 +
22253 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
22254 +}
22255 +
22256 +
22257 +static int __wait_exit(struct vx_info *vxi)
22258 +{
22259 +       DECLARE_WAITQUEUE(wait, current);
22260 +       int ret = 0;
22261 +
22262 +       add_wait_queue(&vxi->vx_wait, &wait);
22263 +       set_current_state(TASK_INTERRUPTIBLE);
22264 +
22265 +wait:
22266 +       if (vx_info_state(vxi,
22267 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
22268 +               goto out;
22269 +       if (signal_pending(current)) {
22270 +               ret = -ERESTARTSYS;
22271 +               goto out;
22272 +       }
22273 +       schedule();
22274 +       goto wait;
22275 +
22276 +out:
22277 +       set_current_state(TASK_RUNNING);
22278 +       remove_wait_queue(&vxi->vx_wait, &wait);
22279 +       return ret;
22280 +}
22281 +
22282 +
22283 +
22284 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
22285 +{
22286 +       struct vcmd_wait_exit_v0 vc_data;
22287 +       int ret;
22288 +
22289 +       ret = __wait_exit(vxi);
22290 +       vc_data.reboot_cmd = vxi->reboot_cmd;
22291 +       vc_data.exit_code = vxi->exit_code;
22292 +
22293 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22294 +               ret = -EFAULT;
22295 +       return ret;
22296 +}
22297 +
22298 diff -NurpP --minimal linux-3.10.33/kernel/vserver/space.c linux-3.10.33-vs2.3.6.8/kernel/vserver/space.c
22299 --- linux-3.10.33/kernel/vserver/space.c        1970-01-01 00:00:00.000000000 +0000
22300 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/space.c      2013-08-22 20:30:00.000000000 +0000
22301 @@ -0,0 +1,436 @@
22302 +/*
22303 + *  linux/kernel/vserver/space.c
22304 + *
22305 + *  Virtual Server: Context Space Support
22306 + *
22307 + *  Copyright (C) 2003-2010  Herbert Pötzl
22308 + *
22309 + *  V0.01  broken out from context.c 0.07
22310 + *  V0.02  added task locking for namespace
22311 + *  V0.03  broken out vx_enter_namespace
22312 + *  V0.04  added *space support and commands
22313 + *  V0.05  added credential support
22314 + *
22315 + */
22316 +
22317 +#include <linux/utsname.h>
22318 +#include <linux/nsproxy.h>
22319 +#include <linux/err.h>
22320 +#include <linux/fs_struct.h>
22321 +#include <linux/cred.h>
22322 +#include <asm/uaccess.h>
22323 +
22324 +#include <linux/vs_context.h>
22325 +#include <linux/vserver/space.h>
22326 +#include <linux/vserver/space_cmd.h>
22327 +
22328 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
22329 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
22330 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
22331 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
22332 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
22333 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
22334 +
22335 +
22336 +/* namespace functions */
22337 +
22338 +#include <linux/mnt_namespace.h>
22339 +#include <linux/user_namespace.h>
22340 +#include <linux/pid_namespace.h>
22341 +#include <linux/ipc_namespace.h>
22342 +#include <net/net_namespace.h>
22343 +#include "../fs/mount.h"
22344 +
22345 +
22346 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
22347 +       .mask = CLONE_FS |
22348 +               CLONE_NEWNS |
22349 +#ifdef CONFIG_UTS_NS
22350 +               CLONE_NEWUTS |
22351 +#endif
22352 +#ifdef CONFIG_IPC_NS
22353 +               CLONE_NEWIPC |
22354 +#endif
22355 +#ifdef CONFIG_USER_NS
22356 +               CLONE_NEWUSER |
22357 +#endif
22358 +               0
22359 +};
22360 +
22361 +static const struct vcmd_space_mask_v1 space_mask = {
22362 +       .mask = CLONE_FS |
22363 +               CLONE_NEWNS |
22364 +#ifdef CONFIG_UTS_NS
22365 +               CLONE_NEWUTS |
22366 +#endif
22367 +#ifdef CONFIG_IPC_NS
22368 +               CLONE_NEWIPC |
22369 +#endif
22370 +#ifdef CONFIG_USER_NS
22371 +               CLONE_NEWUSER |
22372 +#endif
22373 +#ifdef CONFIG_PID_NS
22374 +               CLONE_NEWPID |
22375 +#endif
22376 +#ifdef CONFIG_NET_NS
22377 +               CLONE_NEWNET |
22378 +#endif
22379 +               0
22380 +};
22381 +
22382 +static const struct vcmd_space_mask_v1 default_space_mask = {
22383 +       .mask = CLONE_FS |
22384 +               CLONE_NEWNS |
22385 +#ifdef CONFIG_UTS_NS
22386 +               CLONE_NEWUTS |
22387 +#endif
22388 +#ifdef CONFIG_IPC_NS
22389 +               CLONE_NEWIPC |
22390 +#endif
22391 +#ifdef CONFIG_USER_NS
22392 +               CLONE_NEWUSER |
22393 +#endif
22394 +#ifdef CONFIG_PID_NS
22395 +//             CLONE_NEWPID |
22396 +#endif
22397 +               0
22398 +};
22399 +
22400 +/*
22401 + *     build a new nsproxy mix
22402 + *      assumes that both proxies are 'const'
22403 + *     does not touch nsproxy refcounts
22404 + *     will hold a reference on the result.
22405 + */
22406 +
22407 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
22408 +       struct nsproxy *new_nsproxy, unsigned long mask)
22409 +{
22410 +       struct mnt_namespace *old_ns;
22411 +       struct uts_namespace *old_uts;
22412 +       struct ipc_namespace *old_ipc;
22413 +#ifdef CONFIG_PID_NS
22414 +       struct pid_namespace *old_pid;
22415 +#endif
22416 +#ifdef CONFIG_NET_NS
22417 +       struct net *old_net;
22418 +#endif
22419 +       struct nsproxy *nsproxy;
22420 +
22421 +       nsproxy = copy_nsproxy(old_nsproxy);
22422 +       if (!nsproxy)
22423 +               goto out;
22424 +
22425 +       if (mask & CLONE_NEWNS) {
22426 +               old_ns = nsproxy->mnt_ns;
22427 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
22428 +               if (nsproxy->mnt_ns)
22429 +                       get_mnt_ns(nsproxy->mnt_ns);
22430 +       } else
22431 +               old_ns = NULL;
22432 +
22433 +       if (mask & CLONE_NEWUTS) {
22434 +               old_uts = nsproxy->uts_ns;
22435 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
22436 +               if (nsproxy->uts_ns)
22437 +                       get_uts_ns(nsproxy->uts_ns);
22438 +       } else
22439 +               old_uts = NULL;
22440 +
22441 +       if (mask & CLONE_NEWIPC) {
22442 +               old_ipc = nsproxy->ipc_ns;
22443 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
22444 +               if (nsproxy->ipc_ns)
22445 +                       get_ipc_ns(nsproxy->ipc_ns);
22446 +       } else
22447 +               old_ipc = NULL;
22448 +
22449 +#ifdef CONFIG_PID_NS
22450 +       if (mask & CLONE_NEWPID) {
22451 +               old_pid = nsproxy->pid_ns;
22452 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
22453 +               if (nsproxy->pid_ns)
22454 +                       get_pid_ns(nsproxy->pid_ns);
22455 +       } else
22456 +               old_pid = NULL;
22457 +#endif
22458 +#ifdef CONFIG_NET_NS
22459 +       if (mask & CLONE_NEWNET) {
22460 +               old_net = nsproxy->net_ns;
22461 +               nsproxy->net_ns = new_nsproxy->net_ns;
22462 +               if (nsproxy->net_ns)
22463 +                       get_net(nsproxy->net_ns);
22464 +       } else
22465 +               old_net = NULL;
22466 +#endif
22467 +       if (old_ns)
22468 +               put_mnt_ns(old_ns);
22469 +       if (old_uts)
22470 +               put_uts_ns(old_uts);
22471 +       if (old_ipc)
22472 +               put_ipc_ns(old_ipc);
22473 +#ifdef CONFIG_PID_NS
22474 +       if (old_pid)
22475 +               put_pid_ns(old_pid);
22476 +#endif
22477 +#ifdef CONFIG_NET_NS
22478 +       if (old_net)
22479 +               put_net(old_net);
22480 +#endif
22481 +out:
22482 +       return nsproxy;
22483 +}
22484 +
22485 +
22486 +/*
22487 + *     merge two nsproxy structs into a new one.
22488 + *     will hold a reference on the result.
22489 + */
22490 +
22491 +static inline
22492 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
22493 +       struct nsproxy *proxy, unsigned long mask)
22494 +{
22495 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
22496 +
22497 +       if (!proxy)
22498 +               return NULL;
22499 +
22500 +       if (mask) {
22501 +               /* vs_mix_nsproxy returns with reference */
22502 +               return vs_mix_nsproxy(old ? old : &null_proxy,
22503 +                       proxy, mask);
22504 +       }
22505 +       get_nsproxy(proxy);
22506 +       return proxy;
22507 +}
22508 +
22509 +
22510 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
22511 +{
22512 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
22513 +       struct fs_struct *fs_cur, *fs = NULL;
22514 +       struct _vx_space *space;
22515 +       int ret, kill = 0;
22516 +
22517 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
22518 +               vxi, vxi->vx_id, mask, index);
22519 +
22520 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
22521 +               return -EACCES;
22522 +
22523 +       if (index >= VX_SPACES)
22524 +               return -EINVAL;
22525 +
22526 +       space = &vxi->space[index];
22527 +
22528 +       if (!mask)
22529 +               mask = space->vx_nsmask;
22530 +
22531 +       if ((mask & space->vx_nsmask) != mask)
22532 +               return -EINVAL;
22533 +
22534 +       if (mask & CLONE_FS) {
22535 +               fs = copy_fs_struct(space->vx_fs);
22536 +               if (!fs)
22537 +                       return -ENOMEM;
22538 +       }
22539 +       proxy = space->vx_nsproxy;
22540 +
22541 +       vxdprintk(VXD_CBIT(space, 9),
22542 +               "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
22543 +               vxi, vxi->vx_id, mask, index, proxy, fs);
22544 +
22545 +       task_lock(current);
22546 +       fs_cur = current->fs;
22547 +
22548 +       if (mask & CLONE_FS) {
22549 +               spin_lock(&fs_cur->lock);
22550 +               current->fs = fs;
22551 +               kill = !--fs_cur->users;
22552 +               spin_unlock(&fs_cur->lock);
22553 +       }
22554 +
22555 +       proxy_cur = current->nsproxy;
22556 +       get_nsproxy(proxy_cur);
22557 +       task_unlock(current);
22558 +
22559 +       if (kill)
22560 +               free_fs_struct(fs_cur);
22561 +
22562 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
22563 +       if (IS_ERR(proxy_new)) {
22564 +               ret = PTR_ERR(proxy_new);
22565 +               goto out_put;
22566 +       }
22567 +
22568 +       proxy_new = xchg(&current->nsproxy, proxy_new);
22569 +
22570 +       if (mask & CLONE_NEWUSER) {
22571 +               struct cred *cred;
22572 +
22573 +               vxdprintk(VXD_CBIT(space, 10),
22574 +                       "vx_enter_space(%p[#%u],%p) cred (%p,%p)",
22575 +                       vxi, vxi->vx_id, space->vx_cred,
22576 +                       current->real_cred, current->cred);
22577 +
22578 +               if (space->vx_cred) {
22579 +                       cred = __prepare_creds(space->vx_cred);
22580 +                       if (cred)
22581 +                               commit_creds(cred);
22582 +               }
22583 +       }
22584 +
22585 +       ret = 0;
22586 +
22587 +       if (proxy_new)
22588 +               put_nsproxy(proxy_new);
22589 +out_put:
22590 +       if (proxy_cur)
22591 +               put_nsproxy(proxy_cur);
22592 +       return ret;
22593 +}
22594 +
22595 +
22596 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
22597 +{
22598 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
22599 +       struct fs_struct *fs_vxi, *fs = NULL;
22600 +       struct _vx_space *space;
22601 +       int ret, kill = 0;
22602 +
22603 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
22604 +               vxi, vxi->vx_id, mask, index);
22605 +
22606 +       if ((mask & space_mask.mask) != mask)
22607 +               return -EINVAL;
22608 +
22609 +       if (index >= VX_SPACES)
22610 +               return -EINVAL;
22611 +
22612 +       space = &vxi->space[index];
22613 +
22614 +       proxy_vxi = space->vx_nsproxy;
22615 +       fs_vxi = space->vx_fs;
22616 +
22617 +       if (mask & CLONE_FS) {
22618 +               fs = copy_fs_struct(current->fs);
22619 +               if (!fs)
22620 +                       return -ENOMEM;
22621 +       }
22622 +
22623 +       task_lock(current);
22624 +
22625 +       if (mask & CLONE_FS) {
22626 +               spin_lock(&fs_vxi->lock);
22627 +               space->vx_fs = fs;
22628 +               kill = !--fs_vxi->users;
22629 +               spin_unlock(&fs_vxi->lock);
22630 +       }
22631 +
22632 +       proxy_cur = current->nsproxy;
22633 +       get_nsproxy(proxy_cur);
22634 +       task_unlock(current);
22635 +
22636 +       if (kill)
22637 +               free_fs_struct(fs_vxi);
22638 +
22639 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
22640 +       if (IS_ERR(proxy_new)) {
22641 +               ret = PTR_ERR(proxy_new);
22642 +               goto out_put;
22643 +       }
22644 +
22645 +       proxy_new = xchg(&space->vx_nsproxy, proxy_new);
22646 +       space->vx_nsmask |= mask;
22647 +
22648 +       if (mask & CLONE_NEWUSER) {
22649 +               struct cred *cred;
22650 +
22651 +               vxdprintk(VXD_CBIT(space, 10),
22652 +                       "vx_set_space(%p[#%u],%p) cred (%p,%p)",
22653 +                       vxi, vxi->vx_id, space->vx_cred,
22654 +                       current->real_cred, current->cred);
22655 +
22656 +               cred = prepare_creds();
22657 +               cred = (struct cred *)xchg(&space->vx_cred, cred);
22658 +               if (cred)
22659 +                       abort_creds(cred);
22660 +       }
22661 +
22662 +       ret = 0;
22663 +
22664 +       if (proxy_new)
22665 +               put_nsproxy(proxy_new);
22666 +out_put:
22667 +       if (proxy_cur)
22668 +               put_nsproxy(proxy_cur);
22669 +       return ret;
22670 +}
22671 +
22672 +
22673 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
22674 +{
22675 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22676 +
22677 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22678 +               return -EFAULT;
22679 +
22680 +       return vx_enter_space(vxi, vc_data.mask, 0);
22681 +}
22682 +
22683 +int vc_enter_space(struct vx_info *vxi, void __user *data)
22684 +{
22685 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22686 +
22687 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22688 +               return -EFAULT;
22689 +
22690 +       if (vc_data.index >= VX_SPACES)
22691 +               return -EINVAL;
22692 +
22693 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
22694 +}
22695 +
22696 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
22697 +{
22698 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22699 +
22700 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22701 +               return -EFAULT;
22702 +
22703 +       return vx_set_space(vxi, vc_data.mask, 0);
22704 +}
22705 +
22706 +int vc_set_space(struct vx_info *vxi, void __user *data)
22707 +{
22708 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22709 +
22710 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22711 +               return -EFAULT;
22712 +
22713 +       if (vc_data.index >= VX_SPACES)
22714 +               return -EINVAL;
22715 +
22716 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
22717 +}
22718 +
22719 +int vc_get_space_mask(void __user *data, int type)
22720 +{
22721 +       const struct vcmd_space_mask_v1 *mask;
22722 +
22723 +       if (type == 0)
22724 +               mask = &space_mask_v0;
22725 +       else if (type == 1)
22726 +               mask = &space_mask;
22727 +       else
22728 +               mask = &default_space_mask;
22729 +
22730 +       vxdprintk(VXD_CBIT(space, 10),
22731 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
22732 +
22733 +       if (copy_to_user(data, mask, sizeof(*mask)))
22734 +               return -EFAULT;
22735 +       return 0;
22736 +}
22737 +
22738 diff -NurpP --minimal linux-3.10.33/kernel/vserver/switch.c linux-3.10.33-vs2.3.6.8/kernel/vserver/switch.c
22739 --- linux-3.10.33/kernel/vserver/switch.c       1970-01-01 00:00:00.000000000 +0000
22740 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/switch.c     2013-08-22 20:30:00.000000000 +0000
22741 @@ -0,0 +1,556 @@
22742 +/*
22743 + *  linux/kernel/vserver/switch.c
22744 + *
22745 + *  Virtual Server: Syscall Switch
22746 + *
22747 + *  Copyright (C) 2003-2011  Herbert Pötzl
22748 + *
22749 + *  V0.01  syscall switch
22750 + *  V0.02  added signal to context
22751 + *  V0.03  added rlimit functions
22752 + *  V0.04  added iattr, task/xid functions
22753 + *  V0.05  added debug/history stuff
22754 + *  V0.06  added compat32 layer
22755 + *  V0.07  vcmd args and perms
22756 + *  V0.08  added status commands
22757 + *  V0.09  added tag commands
22758 + *  V0.10  added oom bias
22759 + *  V0.11  added device commands
22760 + *  V0.12  added warn mask
22761 + *
22762 + */
22763 +
22764 +#include <linux/vs_context.h>
22765 +#include <linux/vs_network.h>
22766 +#include <linux/vserver/switch.h>
22767 +
22768 +#include "vci_config.h"
22769 +
22770 +
22771 +static inline
22772 +int vc_get_version(uint32_t id)
22773 +{
22774 +       return VCI_VERSION;
22775 +}
22776 +
22777 +static inline
22778 +int vc_get_vci(uint32_t id)
22779 +{
22780 +       return vci_kernel_config();
22781 +}
22782 +
22783 +#include <linux/vserver/context_cmd.h>
22784 +#include <linux/vserver/cvirt_cmd.h>
22785 +#include <linux/vserver/cacct_cmd.h>
22786 +#include <linux/vserver/limit_cmd.h>
22787 +#include <linux/vserver/network_cmd.h>
22788 +#include <linux/vserver/sched_cmd.h>
22789 +#include <linux/vserver/debug_cmd.h>
22790 +#include <linux/vserver/inode_cmd.h>
22791 +#include <linux/vserver/dlimit_cmd.h>
22792 +#include <linux/vserver/signal_cmd.h>
22793 +#include <linux/vserver/space_cmd.h>
22794 +#include <linux/vserver/tag_cmd.h>
22795 +#include <linux/vserver/device_cmd.h>
22796 +
22797 +#include <linux/vserver/inode.h>
22798 +#include <linux/vserver/dlimit.h>
22799 +
22800 +
22801 +#ifdef CONFIG_COMPAT
22802 +#define __COMPAT(name, id, data, compat)       \
22803 +       (compat) ? name ## _x32(id, data) : name(id, data)
22804 +#define __COMPAT_NO_ID(name, data, compat)     \
22805 +       (compat) ? name ## _x32(data) : name(data)
22806 +#else
22807 +#define __COMPAT(name, id, data, compat)       \
22808 +       name(id, data)
22809 +#define __COMPAT_NO_ID(name, data, compat)     \
22810 +       name(data)
22811 +#endif
22812 +
22813 +
22814 +static inline
22815 +long do_vcmd(uint32_t cmd, uint32_t id,
22816 +       struct vx_info *vxi, struct nx_info *nxi,
22817 +       void __user *data, int compat)
22818 +{
22819 +       switch (cmd) {
22820 +
22821 +       case VCMD_get_version:
22822 +               return vc_get_version(id);
22823 +       case VCMD_get_vci:
22824 +               return vc_get_vci(id);
22825 +
22826 +       case VCMD_task_xid:
22827 +               return vc_task_xid(id);
22828 +       case VCMD_vx_info:
22829 +               return vc_vx_info(vxi, data);
22830 +
22831 +       case VCMD_task_nid:
22832 +               return vc_task_nid(id);
22833 +       case VCMD_nx_info:
22834 +               return vc_nx_info(nxi, data);
22835 +
22836 +       case VCMD_task_tag:
22837 +               return vc_task_tag(id);
22838 +
22839 +       case VCMD_set_space_v1:
22840 +               return vc_set_space_v1(vxi, data);
22841 +       /* this is version 2 */
22842 +       case VCMD_set_space:
22843 +               return vc_set_space(vxi, data);
22844 +
22845 +       case VCMD_get_space_mask_v0:
22846 +               return vc_get_space_mask(data, 0);
22847 +       /* this is version 1 */
22848 +       case VCMD_get_space_mask:
22849 +               return vc_get_space_mask(data, 1);
22850 +
22851 +       case VCMD_get_space_default:
22852 +               return vc_get_space_mask(data, -1);
22853 +
22854 +       case VCMD_set_umask:
22855 +               return vc_set_umask(vxi, data);
22856 +
22857 +       case VCMD_get_umask:
22858 +               return vc_get_umask(vxi, data);
22859 +
22860 +       case VCMD_set_wmask:
22861 +               return vc_set_wmask(vxi, data);
22862 +
22863 +       case VCMD_get_wmask:
22864 +               return vc_get_wmask(vxi, data);
22865 +#ifdef CONFIG_IA32_EMULATION
22866 +       case VCMD_get_rlimit:
22867 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
22868 +       case VCMD_set_rlimit:
22869 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
22870 +#else
22871 +       case VCMD_get_rlimit:
22872 +               return vc_get_rlimit(vxi, data);
22873 +       case VCMD_set_rlimit:
22874 +               return vc_set_rlimit(vxi, data);
22875 +#endif
22876 +       case VCMD_get_rlimit_mask:
22877 +               return vc_get_rlimit_mask(id, data);
22878 +       case VCMD_reset_hits:
22879 +               return vc_reset_hits(vxi, data);
22880 +       case VCMD_reset_minmax:
22881 +               return vc_reset_minmax(vxi, data);
22882 +
22883 +       case VCMD_get_vhi_name:
22884 +               return vc_get_vhi_name(vxi, data);
22885 +       case VCMD_set_vhi_name:
22886 +               return vc_set_vhi_name(vxi, data);
22887 +
22888 +       case VCMD_ctx_stat:
22889 +               return vc_ctx_stat(vxi, data);
22890 +       case VCMD_virt_stat:
22891 +               return vc_virt_stat(vxi, data);
22892 +       case VCMD_sock_stat:
22893 +               return vc_sock_stat(vxi, data);
22894 +       case VCMD_rlimit_stat:
22895 +               return vc_rlimit_stat(vxi, data);
22896 +
22897 +       case VCMD_set_cflags:
22898 +               return vc_set_cflags(vxi, data);
22899 +       case VCMD_get_cflags:
22900 +               return vc_get_cflags(vxi, data);
22901 +
22902 +       /* this is version 1 */
22903 +       case VCMD_set_ccaps:
22904 +               return vc_set_ccaps(vxi, data);
22905 +       /* this is version 1 */
22906 +       case VCMD_get_ccaps:
22907 +               return vc_get_ccaps(vxi, data);
22908 +       case VCMD_set_bcaps:
22909 +               return vc_set_bcaps(vxi, data);
22910 +       case VCMD_get_bcaps:
22911 +               return vc_get_bcaps(vxi, data);
22912 +
22913 +       case VCMD_set_badness:
22914 +               return vc_set_badness(vxi, data);
22915 +       case VCMD_get_badness:
22916 +               return vc_get_badness(vxi, data);
22917 +
22918 +       case VCMD_set_nflags:
22919 +               return vc_set_nflags(nxi, data);
22920 +       case VCMD_get_nflags:
22921 +               return vc_get_nflags(nxi, data);
22922 +
22923 +       case VCMD_set_ncaps:
22924 +               return vc_set_ncaps(nxi, data);
22925 +       case VCMD_get_ncaps:
22926 +               return vc_get_ncaps(nxi, data);
22927 +
22928 +       case VCMD_set_prio_bias:
22929 +               return vc_set_prio_bias(vxi, data);
22930 +       case VCMD_get_prio_bias:
22931 +               return vc_get_prio_bias(vxi, data);
22932 +       case VCMD_add_dlimit:
22933 +               return __COMPAT(vc_add_dlimit, id, data, compat);
22934 +       case VCMD_rem_dlimit:
22935 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
22936 +       case VCMD_set_dlimit:
22937 +               return __COMPAT(vc_set_dlimit, id, data, compat);
22938 +       case VCMD_get_dlimit:
22939 +               return __COMPAT(vc_get_dlimit, id, data, compat);
22940 +
22941 +       case VCMD_ctx_kill:
22942 +               return vc_ctx_kill(vxi, data);
22943 +
22944 +       case VCMD_wait_exit:
22945 +               return vc_wait_exit(vxi, data);
22946 +
22947 +       case VCMD_get_iattr:
22948 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
22949 +       case VCMD_set_iattr:
22950 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
22951 +
22952 +       case VCMD_fget_iattr:
22953 +               return vc_fget_iattr(id, data);
22954 +       case VCMD_fset_iattr:
22955 +               return vc_fset_iattr(id, data);
22956 +
22957 +       case VCMD_enter_space_v0:
22958 +               return vc_enter_space_v1(vxi, NULL);
22959 +       case VCMD_enter_space_v1:
22960 +               return vc_enter_space_v1(vxi, data);
22961 +       /* this is version 2 */
22962 +       case VCMD_enter_space:
22963 +               return vc_enter_space(vxi, data);
22964 +
22965 +       case VCMD_ctx_create_v0:
22966 +               return vc_ctx_create(id, NULL);
22967 +       case VCMD_ctx_create:
22968 +               return vc_ctx_create(id, data);
22969 +       case VCMD_ctx_migrate_v0:
22970 +               return vc_ctx_migrate(vxi, NULL);
22971 +       case VCMD_ctx_migrate:
22972 +               return vc_ctx_migrate(vxi, data);
22973 +
22974 +       case VCMD_net_create_v0:
22975 +               return vc_net_create(id, NULL);
22976 +       case VCMD_net_create:
22977 +               return vc_net_create(id, data);
22978 +       case VCMD_net_migrate:
22979 +               return vc_net_migrate(nxi, data);
22980 +
22981 +       case VCMD_tag_migrate:
22982 +               return vc_tag_migrate(id);
22983 +
22984 +       case VCMD_net_add:
22985 +               return vc_net_add(nxi, data);
22986 +       case VCMD_net_remove:
22987 +               return vc_net_remove(nxi, data);
22988 +
22989 +       case VCMD_net_add_ipv4_v1:
22990 +               return vc_net_add_ipv4_v1(nxi, data);
22991 +       /* this is version 2 */
22992 +       case VCMD_net_add_ipv4:
22993 +               return vc_net_add_ipv4(nxi, data);
22994 +
22995 +       case VCMD_net_rem_ipv4_v1:
22996 +               return vc_net_rem_ipv4_v1(nxi, data);
22997 +       /* this is version 2 */
22998 +       case VCMD_net_rem_ipv4:
22999 +               return vc_net_rem_ipv4(nxi, data);
23000 +#ifdef CONFIG_IPV6
23001 +       case VCMD_net_add_ipv6:
23002 +               return vc_net_add_ipv6(nxi, data);
23003 +       case VCMD_net_remove_ipv6:
23004 +               return vc_net_remove_ipv6(nxi, data);
23005 +#endif
23006 +/*     case VCMD_add_match_ipv4:
23007 +               return vc_add_match_ipv4(nxi, data);
23008 +       case VCMD_get_match_ipv4:
23009 +               return vc_get_match_ipv4(nxi, data);
23010 +#ifdef CONFIG_IPV6
23011 +       case VCMD_add_match_ipv6:
23012 +               return vc_add_match_ipv6(nxi, data);
23013 +       case VCMD_get_match_ipv6:
23014 +               return vc_get_match_ipv6(nxi, data);
23015 +#endif */
23016 +
23017 +#ifdef CONFIG_VSERVER_DEVICE
23018 +       case VCMD_set_mapping:
23019 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
23020 +       case VCMD_unset_mapping:
23021 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
23022 +#endif
23023 +#ifdef CONFIG_VSERVER_HISTORY
23024 +       case VCMD_dump_history:
23025 +               return vc_dump_history(id);
23026 +       case VCMD_read_history:
23027 +               return __COMPAT(vc_read_history, id, data, compat);
23028 +#endif
23029 +       default:
23030 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
23031 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
23032 +       }
23033 +       return -ENOSYS;
23034 +}
23035 +
23036 +
23037 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
23038 +       case VCMD_ ## vcmd: perm = _perm;               \
23039 +               args = _args; flags = _flags; break
23040 +
23041 +
23042 +#define VCA_NONE       0x00
23043 +#define VCA_VXI                0x01
23044 +#define VCA_NXI                0x02
23045 +
23046 +#define VCF_NONE       0x00
23047 +#define VCF_INFO       0x01
23048 +#define VCF_ADMIN      0x02
23049 +#define VCF_ARES       0x06    /* includes admin */
23050 +#define VCF_SETUP      0x08
23051 +
23052 +#define VCF_ZIDOK      0x10    /* zero id okay */
23053 +
23054 +
23055 +static inline
23056 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
23057 +{
23058 +       long ret;
23059 +       int permit = -1, state = 0;
23060 +       int perm = -1, args = 0, flags = 0;
23061 +       struct vx_info *vxi = NULL;
23062 +       struct nx_info *nxi = NULL;
23063 +
23064 +       switch (cmd) {
23065 +       /* unpriviledged commands */
23066 +       __VCMD(get_version,      0, VCA_NONE,   0);
23067 +       __VCMD(get_vci,          0, VCA_NONE,   0);
23068 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
23069 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
23070 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
23071 +       __VCMD(get_space_default,0, VCA_NONE,   0);
23072 +
23073 +       /* info commands */
23074 +       __VCMD(task_xid,         2, VCA_NONE,   0);
23075 +       __VCMD(reset_hits,       2, VCA_VXI,    0);
23076 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
23077 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
23078 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
23079 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
23080 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
23081 +       __VCMD(get_umask,        3, VCA_VXI,    VCF_INFO);
23082 +       __VCMD(get_wmask,        3, VCA_VXI,    VCF_INFO);
23083 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
23084 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
23085 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
23086 +
23087 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
23088 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
23089 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
23090 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
23091 +
23092 +       __VCMD(task_nid,         2, VCA_NONE,   0);
23093 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
23094 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
23095 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
23096 +
23097 +       __VCMD(task_tag,         2, VCA_NONE,   0);
23098 +
23099 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
23100 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
23101 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
23102 +       __VCMD(get_prio_bias,    3, VCA_VXI,    VCF_INFO);
23103 +
23104 +       /* lower admin commands */
23105 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
23106 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
23107 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
23108 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
23109 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
23110 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
23111 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
23112 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
23113 +
23114 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
23115 +       __VCMD(net_create,       5, VCA_NONE,   0);
23116 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
23117 +
23118 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
23119 +
23120 +       /* higher admin commands */
23121 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
23122 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23123 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23124 +
23125 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23126 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23127 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23128 +       __VCMD(set_umask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23129 +       __VCMD(set_wmask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23130 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23131 +
23132 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23133 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23134 +       __VCMD(set_prio_bias,    7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23135 +
23136 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23137 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23138 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23139 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23140 +       __VCMD(net_add_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23141 +       __VCMD(net_rem_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23142 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23143 +       __VCMD(net_rem_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23144 +#ifdef CONFIG_IPV6
23145 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23146 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23147 +#endif
23148 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
23149 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
23150 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
23151 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
23152 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
23153 +
23154 +#ifdef CONFIG_VSERVER_DEVICE
23155 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23156 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23157 +#endif
23158 +       /* debug level admin commands */
23159 +#ifdef CONFIG_VSERVER_HISTORY
23160 +       __VCMD(dump_history,     9, VCA_NONE,   0);
23161 +       __VCMD(read_history,     9, VCA_NONE,   0);
23162 +#endif
23163 +
23164 +       default:
23165 +               perm = -1;
23166 +       }
23167 +
23168 +       vxdprintk(VXD_CBIT(switch, 0),
23169 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
23170 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23171 +               VC_VERSION(cmd), id, data, compat,
23172 +               perm, args, flags);
23173 +
23174 +       ret = -ENOSYS;
23175 +       if (perm < 0)
23176 +               goto out;
23177 +
23178 +       state = 1;
23179 +       if (!capable(CAP_CONTEXT))
23180 +               goto out;
23181 +
23182 +       state = 2;
23183 +       /* moved here from the individual commands */
23184 +       ret = -EPERM;
23185 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
23186 +               goto out;
23187 +
23188 +       state = 3;
23189 +       /* vcmd involves resource management  */
23190 +       ret = -EPERM;
23191 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
23192 +               goto out;
23193 +
23194 +       state = 4;
23195 +       /* various legacy exceptions */
23196 +       switch (cmd) {
23197 +       /* will go away when spectator is a cap */
23198 +       case VCMD_ctx_migrate_v0:
23199 +       case VCMD_ctx_migrate:
23200 +               if (id == 1) {
23201 +                       current->xid = 1;
23202 +                       ret = 1;
23203 +                       goto out;
23204 +               }
23205 +               break;
23206 +
23207 +       /* will go away when spectator is a cap */
23208 +       case VCMD_net_migrate:
23209 +               if (id == 1) {
23210 +                       current->nid = 1;
23211 +                       ret = 1;
23212 +                       goto out;
23213 +               }
23214 +               break;
23215 +       }
23216 +
23217 +       /* vcmds are fine by default */
23218 +       permit = 1;
23219 +
23220 +       /* admin type vcmds require admin ... */
23221 +       if (flags & VCF_ADMIN)
23222 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
23223 +
23224 +       /* ... but setup type vcmds override that */
23225 +       if (!permit && (flags & VCF_SETUP))
23226 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
23227 +
23228 +       state = 5;
23229 +       ret = -EPERM;
23230 +       if (!permit)
23231 +               goto out;
23232 +
23233 +       state = 6;
23234 +       if (!id && (flags & VCF_ZIDOK))
23235 +               goto skip_id;
23236 +
23237 +       ret = -ESRCH;
23238 +       if (args & VCA_VXI) {
23239 +               vxi = lookup_vx_info(id);
23240 +               if (!vxi)
23241 +                       goto out;
23242 +
23243 +               if ((flags & VCF_ADMIN) &&
23244 +                       /* special case kill for shutdown */
23245 +                       (cmd != VCMD_ctx_kill) &&
23246 +                       /* can context be administrated? */
23247 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
23248 +                       ret = -EACCES;
23249 +                       goto out_vxi;
23250 +               }
23251 +       }
23252 +       state = 7;
23253 +       if (args & VCA_NXI) {
23254 +               nxi = lookup_nx_info(id);
23255 +               if (!nxi)
23256 +                       goto out_vxi;
23257 +
23258 +               if ((flags & VCF_ADMIN) &&
23259 +                       /* can context be administrated? */
23260 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
23261 +                       ret = -EACCES;
23262 +                       goto out_nxi;
23263 +               }
23264 +       }
23265 +skip_id:
23266 +       state = 8;
23267 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
23268 +
23269 +out_nxi:
23270 +       if ((args & VCA_NXI) && nxi)
23271 +               put_nx_info(nxi);
23272 +out_vxi:
23273 +       if ((args & VCA_VXI) && vxi)
23274 +               put_vx_info(vxi);
23275 +out:
23276 +       vxdprintk(VXD_CBIT(switch, 1),
23277 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
23278 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23279 +               VC_VERSION(cmd), ret, ret, state, permit);
23280 +       return ret;
23281 +}
23282 +
23283 +asmlinkage long
23284 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
23285 +{
23286 +       return do_vserver(cmd, id, data, 0);
23287 +}
23288 +
23289 +#ifdef CONFIG_COMPAT
23290 +
23291 +asmlinkage long
23292 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
23293 +{
23294 +       return do_vserver(cmd, id, data, 1);
23295 +}
23296 +
23297 +#endif /* CONFIG_COMPAT */
23298 diff -NurpP --minimal linux-3.10.33/kernel/vserver/sysctl.c linux-3.10.33-vs2.3.6.8/kernel/vserver/sysctl.c
23299 --- linux-3.10.33/kernel/vserver/sysctl.c       1970-01-01 00:00:00.000000000 +0000
23300 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/sysctl.c     2013-08-22 20:30:00.000000000 +0000
23301 @@ -0,0 +1,247 @@
23302 +/*
23303 + *  kernel/vserver/sysctl.c
23304 + *
23305 + *  Virtual Context Support
23306 + *
23307 + *  Copyright (C) 2004-2007  Herbert Pötzl
23308 + *
23309 + *  V0.01  basic structure
23310 + *
23311 + */
23312 +
23313 +#include <linux/module.h>
23314 +#include <linux/ctype.h>
23315 +#include <linux/sysctl.h>
23316 +#include <linux/parser.h>
23317 +#include <asm/uaccess.h>
23318 +
23319 +enum {
23320 +       CTL_DEBUG_ERROR         = 0,
23321 +       CTL_DEBUG_SWITCH        = 1,
23322 +       CTL_DEBUG_XID,
23323 +       CTL_DEBUG_NID,
23324 +       CTL_DEBUG_TAG,
23325 +       CTL_DEBUG_NET,
23326 +       CTL_DEBUG_LIMIT,
23327 +       CTL_DEBUG_CRES,
23328 +       CTL_DEBUG_DLIM,
23329 +       CTL_DEBUG_QUOTA,
23330 +       CTL_DEBUG_CVIRT,
23331 +       CTL_DEBUG_SPACE,
23332 +       CTL_DEBUG_PERM,
23333 +       CTL_DEBUG_MISC,
23334 +};
23335 +
23336 +
23337 +unsigned int vs_debug_switch   = 0;
23338 +unsigned int vs_debug_xid      = 0;
23339 +unsigned int vs_debug_nid      = 0;
23340 +unsigned int vs_debug_tag      = 0;
23341 +unsigned int vs_debug_net      = 0;
23342 +unsigned int vs_debug_limit    = 0;
23343 +unsigned int vs_debug_cres     = 0;
23344 +unsigned int vs_debug_dlim     = 0;
23345 +unsigned int vs_debug_quota    = 0;
23346 +unsigned int vs_debug_cvirt    = 0;
23347 +unsigned int vs_debug_space    = 0;
23348 +unsigned int vs_debug_perm     = 0;
23349 +unsigned int vs_debug_misc     = 0;
23350 +
23351 +
23352 +static struct ctl_table_header *vserver_table_header;
23353 +static ctl_table vserver_root_table[];
23354 +
23355 +
23356 +void vserver_register_sysctl(void)
23357 +{
23358 +       if (!vserver_table_header) {
23359 +               vserver_table_header = register_sysctl_table(vserver_root_table);
23360 +       }
23361 +
23362 +}
23363 +
23364 +void vserver_unregister_sysctl(void)
23365 +{
23366 +       if (vserver_table_header) {
23367 +               unregister_sysctl_table(vserver_table_header);
23368 +               vserver_table_header = NULL;
23369 +       }
23370 +}
23371 +
23372 +
23373 +static int proc_dodebug(ctl_table *table, int write,
23374 +       void __user *buffer, size_t *lenp, loff_t *ppos)
23375 +{
23376 +       char            tmpbuf[20], *p, c;
23377 +       unsigned int    value;
23378 +       size_t          left, len;
23379 +
23380 +       if ((*ppos && !write) || !*lenp) {
23381 +               *lenp = 0;
23382 +               return 0;
23383 +       }
23384 +
23385 +       left = *lenp;
23386 +
23387 +       if (write) {
23388 +               if (!access_ok(VERIFY_READ, buffer, left))
23389 +                       return -EFAULT;
23390 +               p = (char *)buffer;
23391 +               while (left && __get_user(c, p) >= 0 && isspace(c))
23392 +                       left--, p++;
23393 +               if (!left)
23394 +                       goto done;
23395 +
23396 +               if (left > sizeof(tmpbuf) - 1)
23397 +                       return -EINVAL;
23398 +               if (copy_from_user(tmpbuf, p, left))
23399 +                       return -EFAULT;
23400 +               tmpbuf[left] = '\0';
23401 +
23402 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
23403 +                       value = 10 * value + (*p - '0');
23404 +               if (*p && !isspace(*p))
23405 +                       return -EINVAL;
23406 +               while (left && isspace(*p))
23407 +                       left--, p++;
23408 +               *(unsigned int *)table->data = value;
23409 +       } else {
23410 +               if (!access_ok(VERIFY_WRITE, buffer, left))
23411 +                       return -EFAULT;
23412 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
23413 +               if (len > left)
23414 +                       len = left;
23415 +               if (__copy_to_user(buffer, tmpbuf, len))
23416 +                       return -EFAULT;
23417 +               if ((left -= len) > 0) {
23418 +                       if (put_user('\n', (char *)buffer + len))
23419 +                               return -EFAULT;
23420 +                       left--;
23421 +               }
23422 +       }
23423 +
23424 +done:
23425 +       *lenp -= left;
23426 +       *ppos += *lenp;
23427 +       return 0;
23428 +}
23429 +
23430 +static int zero;
23431 +
23432 +#define        CTL_ENTRY(ctl, name)                            \
23433 +       {                                               \
23434 +               .procname       = #name,                \
23435 +               .data           = &vs_ ## name,         \
23436 +               .maxlen         = sizeof(int),          \
23437 +               .mode           = 0644,                 \
23438 +               .proc_handler   = &proc_dodebug,        \
23439 +               .extra1         = &zero,                \
23440 +               .extra2         = &zero,                \
23441 +       }
23442 +
23443 +static ctl_table vserver_debug_table[] = {
23444 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
23445 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
23446 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
23447 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
23448 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
23449 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
23450 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
23451 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
23452 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
23453 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
23454 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
23455 +       CTL_ENTRY(CTL_DEBUG_PERM,       debug_perm),
23456 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
23457 +       { 0 }
23458 +};
23459 +
23460 +static ctl_table vserver_root_table[] = {
23461 +       {
23462 +               .procname       = "vserver",
23463 +               .mode           = 0555,
23464 +               .child          = vserver_debug_table
23465 +       },
23466 +       { 0 }
23467 +};
23468 +
23469 +
23470 +static match_table_t tokens = {
23471 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
23472 +       { CTL_DEBUG_XID,        "xid=%x"        },
23473 +       { CTL_DEBUG_NID,        "nid=%x"        },
23474 +       { CTL_DEBUG_TAG,        "tag=%x"        },
23475 +       { CTL_DEBUG_NET,        "net=%x"        },
23476 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
23477 +       { CTL_DEBUG_CRES,       "cres=%x"       },
23478 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
23479 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
23480 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
23481 +       { CTL_DEBUG_SPACE,      "space=%x"      },
23482 +       { CTL_DEBUG_PERM,       "perm=%x"       },
23483 +       { CTL_DEBUG_MISC,       "misc=%x"       },
23484 +       { CTL_DEBUG_ERROR,      NULL            }
23485 +};
23486 +
23487 +#define        HANDLE_CASE(id, name, val)                              \
23488 +       case CTL_DEBUG_ ## id:                                  \
23489 +               vs_debug_ ## name = val;                        \
23490 +               printk("vs_debug_" #name "=0x%x\n", val);       \
23491 +               break
23492 +
23493 +
23494 +static int __init vs_debug_setup(char *str)
23495 +{
23496 +       char *p;
23497 +       int token;
23498 +
23499 +       printk("vs_debug_setup(%s)\n", str);
23500 +       while ((p = strsep(&str, ",")) != NULL) {
23501 +               substring_t args[MAX_OPT_ARGS];
23502 +               unsigned int value;
23503 +
23504 +               if (!*p)
23505 +                       continue;
23506 +
23507 +               token = match_token(p, tokens, args);
23508 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
23509 +
23510 +               switch (token) {
23511 +               HANDLE_CASE(SWITCH, switch, value);
23512 +               HANDLE_CASE(XID,    xid,    value);
23513 +               HANDLE_CASE(NID,    nid,    value);
23514 +               HANDLE_CASE(TAG,    tag,    value);
23515 +               HANDLE_CASE(NET,    net,    value);
23516 +               HANDLE_CASE(LIMIT,  limit,  value);
23517 +               HANDLE_CASE(CRES,   cres,   value);
23518 +               HANDLE_CASE(DLIM,   dlim,   value);
23519 +               HANDLE_CASE(QUOTA,  quota,  value);
23520 +               HANDLE_CASE(CVIRT,  cvirt,  value);
23521 +               HANDLE_CASE(SPACE,  space,  value);
23522 +               HANDLE_CASE(PERM,   perm,   value);
23523 +               HANDLE_CASE(MISC,   misc,   value);
23524 +               default:
23525 +                       return -EINVAL;
23526 +                       break;
23527 +               }
23528 +       }
23529 +       return 1;
23530 +}
23531 +
23532 +__setup("vsdebug=", vs_debug_setup);
23533 +
23534 +
23535 +
23536 +EXPORT_SYMBOL_GPL(vs_debug_switch);
23537 +EXPORT_SYMBOL_GPL(vs_debug_xid);
23538 +EXPORT_SYMBOL_GPL(vs_debug_nid);
23539 +EXPORT_SYMBOL_GPL(vs_debug_net);
23540 +EXPORT_SYMBOL_GPL(vs_debug_limit);
23541 +EXPORT_SYMBOL_GPL(vs_debug_cres);
23542 +EXPORT_SYMBOL_GPL(vs_debug_dlim);
23543 +EXPORT_SYMBOL_GPL(vs_debug_quota);
23544 +EXPORT_SYMBOL_GPL(vs_debug_cvirt);
23545 +EXPORT_SYMBOL_GPL(vs_debug_space);
23546 +EXPORT_SYMBOL_GPL(vs_debug_perm);
23547 +EXPORT_SYMBOL_GPL(vs_debug_misc);
23548 +
23549 diff -NurpP --minimal linux-3.10.33/kernel/vserver/tag.c linux-3.10.33-vs2.3.6.8/kernel/vserver/tag.c
23550 --- linux-3.10.33/kernel/vserver/tag.c  1970-01-01 00:00:00.000000000 +0000
23551 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/tag.c        2013-08-22 20:30:00.000000000 +0000
23552 @@ -0,0 +1,63 @@
23553 +/*
23554 + *  linux/kernel/vserver/tag.c
23555 + *
23556 + *  Virtual Server: Shallow Tag Space
23557 + *
23558 + *  Copyright (C) 2007  Herbert Pötzl
23559 + *
23560 + *  V0.01  basic implementation
23561 + *
23562 + */
23563 +
23564 +#include <linux/sched.h>
23565 +#include <linux/vserver/debug.h>
23566 +#include <linux/vs_pid.h>
23567 +#include <linux/vs_tag.h>
23568 +
23569 +#include <linux/vserver/tag_cmd.h>
23570 +
23571 +
23572 +int dx_migrate_task(struct task_struct *p, vtag_t tag)
23573 +{
23574 +       if (!p)
23575 +               BUG();
23576 +
23577 +       vxdprintk(VXD_CBIT(tag, 5),
23578 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
23579 +
23580 +       task_lock(p);
23581 +       p->tag = tag;
23582 +       task_unlock(p);
23583 +
23584 +       vxdprintk(VXD_CBIT(tag, 5),
23585 +               "moved task %p into [#%d]", p, tag);
23586 +       return 0;
23587 +}
23588 +
23589 +/* vserver syscall commands below here */
23590 +
23591 +/* taks xid and vx_info functions */
23592 +
23593 +
23594 +int vc_task_tag(uint32_t id)
23595 +{
23596 +       vtag_t tag;
23597 +
23598 +       if (id) {
23599 +               struct task_struct *tsk;
23600 +               rcu_read_lock();
23601 +               tsk = find_task_by_real_pid(id);
23602 +               tag = (tsk) ? tsk->tag : -ESRCH;
23603 +               rcu_read_unlock();
23604 +       } else
23605 +               tag = dx_current_tag();
23606 +       return tag;
23607 +}
23608 +
23609 +
23610 +int vc_tag_migrate(uint32_t tag)
23611 +{
23612 +       return dx_migrate_task(current, tag & 0xFFFF);
23613 +}
23614 +
23615 +
23616 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
23617 --- linux-3.10.33/kernel/vserver/vci_config.h   1970-01-01 00:00:00.000000000 +0000
23618 +++ linux-3.10.33-vs2.3.6.8/kernel/vserver/vci_config.h 2013-08-22 20:30:00.000000000 +0000
23619 @@ -0,0 +1,80 @@
23620 +
23621 +/*  interface version */
23622 +
23623 +#define VCI_VERSION            0x00020308
23624 +
23625 +
23626 +enum {
23627 +       VCI_KCBIT_NO_DYNAMIC = 0,
23628 +
23629 +       VCI_KCBIT_PROC_SECURE = 4,
23630 +       /* VCI_KCBIT_HARDCPU = 5, */
23631 +       /* VCI_KCBIT_IDLELIMIT = 6, */
23632 +       /* VCI_KCBIT_IDLETIME = 7, */
23633 +
23634 +       VCI_KCBIT_COWBL = 8,
23635 +       VCI_KCBIT_FULLCOWBL = 9,
23636 +       VCI_KCBIT_SPACES = 10,
23637 +       VCI_KCBIT_NETV2 = 11,
23638 +       VCI_KCBIT_MEMCG = 12,
23639 +       VCI_KCBIT_MEMCG_SWAP = 13,
23640 +
23641 +       VCI_KCBIT_DEBUG = 16,
23642 +       VCI_KCBIT_HISTORY = 20,
23643 +       VCI_KCBIT_TAGGED = 24,
23644 +       VCI_KCBIT_PPTAG = 28,
23645 +
23646 +       VCI_KCBIT_MORE = 31,
23647 +};
23648 +
23649 +
23650 +static inline uint32_t vci_kernel_config(void)
23651 +{
23652 +       return
23653 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
23654 +
23655 +       /* configured features */
23656 +#ifdef CONFIG_VSERVER_PROC_SECURE
23657 +       (1 << VCI_KCBIT_PROC_SECURE) |
23658 +#endif
23659 +#ifdef CONFIG_VSERVER_COWBL
23660 +       (1 << VCI_KCBIT_COWBL) |
23661 +       (1 << VCI_KCBIT_FULLCOWBL) |
23662 +#endif
23663 +       (1 << VCI_KCBIT_SPACES) |
23664 +       (1 << VCI_KCBIT_NETV2) |
23665 +#ifdef CONFIG_MEMCG
23666 +       (1 << VCI_KCBIT_MEMCG) |
23667 +#endif
23668 +#ifdef CONFIG_MEMCG_SWAP
23669 +       (1 << VCI_KCBIT_MEMCG_SWAP) |
23670 +#endif
23671 +
23672 +       /* debug options */
23673 +#ifdef CONFIG_VSERVER_DEBUG
23674 +       (1 << VCI_KCBIT_DEBUG) |
23675 +#endif
23676 +#ifdef CONFIG_VSERVER_HISTORY
23677 +       (1 << VCI_KCBIT_HISTORY) |
23678 +#endif
23679 +
23680 +       /* inode context tagging */
23681 +#if    defined(CONFIG_TAGGING_NONE)
23682 +       (0 << VCI_KCBIT_TAGGED) |
23683 +#elif  defined(CONFIG_TAGGING_UID16)
23684 +       (1 << VCI_KCBIT_TAGGED) |
23685 +#elif  defined(CONFIG_TAGGING_GID16)
23686 +       (2 << VCI_KCBIT_TAGGED) |
23687 +#elif  defined(CONFIG_TAGGING_ID24)
23688 +       (3 << VCI_KCBIT_TAGGED) |
23689 +#elif  defined(CONFIG_TAGGING_INTERN)
23690 +       (4 << VCI_KCBIT_TAGGED) |
23691 +#elif  defined(CONFIG_TAGGING_RUNTIME)
23692 +       (5 << VCI_KCBIT_TAGGED) |
23693 +#else
23694 +       (7 << VCI_KCBIT_TAGGED) |
23695 +#endif
23696 +       (1 << VCI_KCBIT_PPTAG) |
23697 +       0;
23698 +}
23699 +
23700 diff -NurpP --minimal linux-3.10.33/mm/memcontrol.c linux-3.10.33-vs2.3.6.8/mm/memcontrol.c
23701 --- linux-3.10.33/mm/memcontrol.c       2014-03-12 13:16:02.000000000 +0000
23702 +++ linux-3.10.33-vs2.3.6.8/mm/memcontrol.c     2014-03-12 13:18:33.000000000 +0000
23703 @@ -1082,6 +1082,31 @@ struct mem_cgroup *mem_cgroup_from_task(
23704         return mem_cgroup_from_css(task_subsys_state(p, mem_cgroup_subsys_id));
23705  }
23706  
23707 +u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member)
23708 +{
23709 +       return res_counter_read_u64(&mem->res, member);
23710 +}
23711 +
23712 +u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member)
23713 +{
23714 +       return res_counter_read_u64(&mem->memsw, member);
23715 +}
23716 +
23717 +s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem)
23718 +{
23719 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_CACHE);
23720 +}
23721 +
23722 +s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem)
23723 +{
23724 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_RSS);
23725 +}
23726 +
23727 +s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem)
23728 +{
23729 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_FILE_MAPPED);
23730 +}
23731 +
23732  struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
23733  {
23734         struct mem_cgroup *memcg = NULL;
23735 diff -NurpP --minimal linux-3.10.33/mm/oom_kill.c linux-3.10.33-vs2.3.6.8/mm/oom_kill.c
23736 --- linux-3.10.33/mm/oom_kill.c 2014-03-12 13:16:02.000000000 +0000
23737 +++ linux-3.10.33-vs2.3.6.8/mm/oom_kill.c       2014-03-12 13:18:23.000000000 +0000
23738 @@ -35,6 +35,8 @@
23739  #include <linux/freezer.h>
23740  #include <linux/ftrace.h>
23741  #include <linux/ratelimit.h>
23742 +#include <linux/reboot.h>
23743 +#include <linux/vs_context.h>
23744  
23745  #define CREATE_TRACE_POINTS
23746  #include <trace/events/oom.h>
23747 @@ -113,11 +115,18 @@ struct task_struct *find_lock_task_mm(st
23748  static bool oom_unkillable_task(struct task_struct *p,
23749                 const struct mem_cgroup *memcg, const nodemask_t *nodemask)
23750  {
23751 -       if (is_global_init(p))
23752 +       unsigned xid = vx_current_xid();
23753 +
23754 +       /* skip the init task, global and per guest */
23755 +       if (task_is_init(p))
23756                 return true;
23757         if (p->flags & PF_KTHREAD)
23758                 return true;
23759  
23760 +       /* skip other guest and host processes if oom in guest */
23761 +       if (xid && vx_task_xid(p) != xid)
23762 +               return true;
23763 +
23764         /* When mem_cgroup_out_of_memory() and p is not member of the group */
23765         if (memcg && !task_in_mem_cgroup(p, memcg))
23766                 return true;
23767 @@ -426,8 +435,8 @@ void oom_kill_process(struct task_struct
23768                 dump_header(p, gfp_mask, order, memcg, nodemask);
23769  
23770         task_lock(p);
23771 -       pr_err("%s: Kill process %d (%s) score %d or sacrifice child\n",
23772 -               message, task_pid_nr(p), p->comm, points);
23773 +       pr_err("%s: Kill process %d:#%u (%s) score %d or sacrifice child\n",
23774 +               message, task_pid_nr(p), p->xid, p->comm, points);
23775         task_unlock(p);
23776  
23777         /*
23778 @@ -472,8 +481,8 @@ void oom_kill_process(struct task_struct
23779  
23780         /* mm cannot safely be dereferenced after task_unlock(victim) */
23781         mm = victim->mm;
23782 -       pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23783 -               task_pid_nr(victim), victim->comm, K(victim->mm->total_vm),
23784 +       pr_err("Killed process %d:#%u (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23785 +               task_pid_nr(victim), victim->xid, victim->comm, K(victim->mm->total_vm),
23786                 K(get_mm_counter(victim->mm, MM_ANONPAGES)),
23787                 K(get_mm_counter(victim->mm, MM_FILEPAGES)));
23788         task_unlock(victim);
23789 @@ -543,6 +552,8 @@ int unregister_oom_notifier(struct notif
23790  }
23791  EXPORT_SYMBOL_GPL(unregister_oom_notifier);
23792  
23793 +long vs_oom_action(unsigned int);
23794 +
23795  /*
23796   * Try to acquire the OOM killer lock for the zones in zonelist.  Returns zero
23797   * if a parallel OOM killing is already taking place that includes a zone in
23798 @@ -655,7 +666,12 @@ void out_of_memory(struct zonelist *zone
23799         /* Found nothing?!?! Either we hang forever, or we panic. */
23800         if (!p) {
23801                 dump_header(NULL, gfp_mask, order, NULL, mpol_mask);
23802 -               panic("Out of memory and no killable processes...\n");
23803 +
23804 +               /* avoid panic for guest OOM */
23805 +               if (vx_current_xid())
23806 +                       vs_oom_action(LINUX_REBOOT_CMD_OOM);
23807 +               else
23808 +                       panic("Out of memory and no killable processes...\n");
23809         }
23810         if (PTR_ERR(p) != -1UL) {
23811                 oom_kill_process(p, gfp_mask, order, points, totalpages, NULL,
23812 diff -NurpP --minimal linux-3.10.33/mm/page_alloc.c linux-3.10.33-vs2.3.6.8/mm/page_alloc.c
23813 --- linux-3.10.33/mm/page_alloc.c       2014-03-12 13:16:02.000000000 +0000
23814 +++ linux-3.10.33-vs2.3.6.8/mm/page_alloc.c     2013-11-13 17:17:16.000000000 +0000
23815 @@ -60,6 +60,8 @@
23816  #include <linux/page-debug-flags.h>
23817  #include <linux/hugetlb.h>
23818  #include <linux/sched/rt.h>
23819 +#include <linux/vs_base.h>
23820 +#include <linux/vs_limit.h>
23821  
23822  #include <asm/tlbflush.h>
23823  #include <asm/div64.h>
23824 @@ -2899,6 +2901,9 @@ void si_meminfo(struct sysinfo *val)
23825         val->totalhigh = totalhigh_pages;
23826         val->freehigh = nr_free_highpages();
23827         val->mem_unit = PAGE_SIZE;
23828 +
23829 +       if (vx_flags(VXF_VIRT_MEM, 0))
23830 +               vx_vsi_meminfo(val);
23831  }
23832  
23833  EXPORT_SYMBOL(si_meminfo);
23834 @@ -2919,6 +2924,9 @@ void si_meminfo_node(struct sysinfo *val
23835         val->freehigh = 0;
23836  #endif
23837         val->mem_unit = PAGE_SIZE;
23838 +
23839 +       if (vx_flags(VXF_VIRT_MEM, 0))
23840 +               vx_vsi_meminfo(val);
23841  }
23842  #endif
23843  
23844 diff -NurpP --minimal linux-3.10.33/mm/pgtable-generic.c linux-3.10.33-vs2.3.6.8/mm/pgtable-generic.c
23845 --- linux-3.10.33/mm/pgtable-generic.c  2014-03-12 13:16:02.000000000 +0000
23846 +++ linux-3.10.33-vs2.3.6.8/mm/pgtable-generic.c        2014-01-22 19:00:34.000000000 +0000
23847 @@ -6,6 +6,8 @@
23848   *  Copyright (C) 2010  Linus Torvalds
23849   */
23850  
23851 +#include <linux/mm.h>
23852 +
23853  #include <linux/pagemap.h>
23854  #include <asm/tlb.h>
23855  #include <asm-generic/pgtable.h>
23856 diff -NurpP --minimal linux-3.10.33/mm/shmem.c linux-3.10.33-vs2.3.6.8/mm/shmem.c
23857 --- linux-3.10.33/mm/shmem.c    2014-03-12 13:16:02.000000000 +0000
23858 +++ linux-3.10.33-vs2.3.6.8/mm/shmem.c  2013-11-13 17:17:16.000000000 +0000
23859 @@ -1911,7 +1911,7 @@ static int shmem_statfs(struct dentry *d
23860  {
23861         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
23862  
23863 -       buf->f_type = TMPFS_MAGIC;
23864 +       buf->f_type = TMPFS_SUPER_MAGIC;
23865         buf->f_bsize = PAGE_CACHE_SIZE;
23866         buf->f_namelen = NAME_MAX;
23867         if (sbinfo->max_blocks) {
23868 @@ -2608,7 +2608,7 @@ int shmem_fill_super(struct super_block
23869         sb->s_maxbytes = MAX_LFS_FILESIZE;
23870         sb->s_blocksize = PAGE_CACHE_SIZE;
23871         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
23872 -       sb->s_magic = TMPFS_MAGIC;
23873 +       sb->s_magic = TMPFS_SUPER_MAGIC;
23874         sb->s_op = &shmem_ops;
23875         sb->s_time_gran = 1;
23876  #ifdef CONFIG_TMPFS_XATTR
23877 diff -NurpP --minimal linux-3.10.33/mm/slab.c linux-3.10.33-vs2.3.6.8/mm/slab.c
23878 --- linux-3.10.33/mm/slab.c     2014-03-12 13:16:02.000000000 +0000
23879 +++ linux-3.10.33-vs2.3.6.8/mm/slab.c   2013-11-13 17:17:16.000000000 +0000
23880 @@ -388,6 +388,8 @@ static void kmem_cache_node_init(struct
23881  #define STATS_INC_FREEMISS(x)  do { } while (0)
23882  #endif
23883  
23884 +#include "slab_vs.h"
23885 +
23886  #if DEBUG
23887  
23888  /*
23889 @@ -3314,6 +3316,7 @@ retry:
23890  
23891         obj = slab_get_obj(cachep, slabp, nodeid);
23892         check_slabp(cachep, slabp);
23893 +       vx_slab_alloc(cachep, flags);
23894         n->free_objects--;
23895         /* move slabp to correct slabp list: */
23896         list_del(&slabp->list);
23897 @@ -3393,6 +3396,7 @@ slab_alloc_node(struct kmem_cache *cache
23898         /* ___cache_alloc_node can fall back to other nodes */
23899         ptr = ____cache_alloc_node(cachep, flags, nodeid);
23900    out:
23901 +       vx_slab_alloc(cachep, flags);
23902         local_irq_restore(save_flags);
23903         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
23904         kmemleak_alloc_recursive(ptr, cachep->object_size, 1, cachep->flags,
23905 @@ -3585,6 +3589,7 @@ static inline void __cache_free(struct k
23906         check_irq_off();
23907         kmemleak_free_recursive(objp, cachep->flags);
23908         objp = cache_free_debugcheck(cachep, objp, caller);
23909 +       vx_slab_free(cachep);
23910  
23911         kmemcheck_slab_free(cachep, objp, cachep->object_size);
23912  
23913 diff -NurpP --minimal linux-3.10.33/mm/slab_vs.h linux-3.10.33-vs2.3.6.8/mm/slab_vs.h
23914 --- linux-3.10.33/mm/slab_vs.h  1970-01-01 00:00:00.000000000 +0000
23915 +++ linux-3.10.33-vs2.3.6.8/mm/slab_vs.h        2013-08-22 20:30:00.000000000 +0000
23916 @@ -0,0 +1,29 @@
23917 +
23918 +#include <linux/vserver/context.h>
23919 +
23920 +#include <linux/vs_context.h>
23921 +
23922 +static inline
23923 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
23924 +{
23925 +       int what = gfp_zone(cachep->allocflags);
23926 +       struct vx_info *vxi = current_vx_info();
23927 +
23928 +       if (!vxi)
23929 +               return;
23930 +
23931 +       atomic_add(cachep->size, &vxi->cacct.slab[what]);
23932 +}
23933 +
23934 +static inline
23935 +void vx_slab_free(struct kmem_cache *cachep)
23936 +{
23937 +       int what = gfp_zone(cachep->allocflags);
23938 +       struct vx_info *vxi = current_vx_info();
23939 +
23940 +       if (!vxi)
23941 +               return;
23942 +
23943 +       atomic_sub(cachep->size, &vxi->cacct.slab[what]);
23944 +}
23945 +
23946 diff -NurpP --minimal linux-3.10.33/mm/swapfile.c linux-3.10.33-vs2.3.6.8/mm/swapfile.c
23947 --- linux-3.10.33/mm/swapfile.c 2013-07-14 17:01:36.000000000 +0000
23948 +++ linux-3.10.33-vs2.3.6.8/mm/swapfile.c       2013-08-22 20:30:00.000000000 +0000
23949 @@ -39,6 +39,7 @@
23950  #include <asm/tlbflush.h>
23951  #include <linux/swapops.h>
23952  #include <linux/page_cgroup.h>
23953 +#include <linux/vs_base.h>
23954  
23955  static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
23956                                  unsigned char);
23957 @@ -1768,6 +1769,16 @@ static int swap_show(struct seq_file *sw
23958  
23959         if (si == SEQ_START_TOKEN) {
23960                 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
23961 +               if (vx_flags(VXF_VIRT_MEM, 0)) {
23962 +                       struct sysinfo si;
23963 +
23964 +                       vx_vsi_swapinfo(&si);
23965 +                       if (si.totalswap < (1 << 10))
23966 +                               return 0;
23967 +                       seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
23968 +                               "hdv0", "partition", si.totalswap >> 10,
23969 +                               (si.totalswap - si.freeswap) >> 10, -1);
23970 +               }
23971                 return 0;
23972         }
23973  
23974 @@ -2196,6 +2207,8 @@ void si_swapinfo(struct sysinfo *val)
23975         val->freeswap = atomic_long_read(&nr_swap_pages) + nr_to_be_unused;
23976         val->totalswap = total_swap_pages + nr_to_be_unused;
23977         spin_unlock(&swap_lock);
23978 +       if (vx_flags(VXF_VIRT_MEM, 0))
23979 +               vx_vsi_swapinfo(val);
23980  }
23981  
23982  /*
23983 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
23984 --- linux-3.10.33/net/bridge/br_multicast.c     2014-03-12 13:16:02.000000000 +0000
23985 +++ linux-3.10.33-vs2.3.6.8/net/bridge/br_multicast.c   2014-01-22 19:00:34.000000000 +0000
23986 @@ -443,7 +443,7 @@ static struct sk_buff *br_ip6_multicast_
23987         ip6h->hop_limit = 1;
23988         ipv6_addr_set(&ip6h->daddr, htonl(0xff020000), 0, 0, htonl(1));
23989         if (ipv6_dev_get_saddr(dev_net(br->dev), br->dev, &ip6h->daddr, 0,
23990 -                              &ip6h->saddr)) {
23991 +                              &ip6h->saddr, NULL)) {
23992                 kfree_skb(skb);
23993                 return NULL;
23994         }
23995 diff -NurpP --minimal linux-3.10.33/net/core/dev.c linux-3.10.33-vs2.3.6.8/net/core/dev.c
23996 --- linux-3.10.33/net/core/dev.c        2014-03-12 13:16:02.000000000 +0000
23997 +++ linux-3.10.33-vs2.3.6.8/net/core/dev.c      2014-03-12 13:18:33.000000000 +0000
23998 @@ -122,6 +122,7 @@
23999  #include <linux/in.h>
24000  #include <linux/jhash.h>
24001  #include <linux/random.h>
24002 +#include <linux/vs_inet.h>
24003  #include <trace/events/napi.h>
24004  #include <trace/events/net.h>
24005  #include <trace/events/skb.h>
24006 @@ -660,7 +661,8 @@ struct net_device *__dev_get_by_name(str
24007         struct hlist_head *head = dev_name_hash(net, name);
24008  
24009         hlist_for_each_entry(dev, head, name_hlist)
24010 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24011 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24012 +                   nx_dev_visible(current_nx_info(), dev))
24013                         return dev;
24014  
24015         return NULL;
24016 @@ -685,7 +687,8 @@ struct net_device *dev_get_by_name_rcu(s
24017         struct hlist_head *head = dev_name_hash(net, name);
24018  
24019         hlist_for_each_entry_rcu(dev, head, name_hlist)
24020 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24021 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24022 +                   nx_dev_visible(current_nx_info(), dev))
24023                         return dev;
24024  
24025         return NULL;
24026 @@ -735,7 +738,8 @@ struct net_device *__dev_get_by_index(st
24027         struct hlist_head *head = dev_index_hash(net, ifindex);
24028  
24029         hlist_for_each_entry(dev, head, index_hlist)
24030 -               if (dev->ifindex == ifindex)
24031 +               if ((dev->ifindex == ifindex) &&
24032 +                   nx_dev_visible(current_nx_info(), dev))
24033                         return dev;
24034  
24035         return NULL;
24036 @@ -753,7 +757,7 @@ EXPORT_SYMBOL(__dev_get_by_index);
24037   *     about locking. The caller must hold RCU lock.
24038   */
24039  
24040 -struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
24041 +struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex)
24042  {
24043         struct net_device *dev;
24044         struct hlist_head *head = dev_index_hash(net, ifindex);
24045 @@ -764,6 +768,16 @@ struct net_device *dev_get_by_index_rcu(
24046  
24047         return NULL;
24048  }
24049 +EXPORT_SYMBOL(dev_get_by_index_real_rcu);
24050 +
24051 +struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
24052 +{
24053 +       struct net_device *dev = dev_get_by_index_real_rcu(net, ifindex);
24054 +
24055 +       if (nx_dev_visible(current_nx_info(), dev))
24056 +               return dev;
24057 +       return NULL;
24058 +}
24059  EXPORT_SYMBOL(dev_get_by_index_rcu);
24060  
24061  
24062 @@ -846,7 +860,8 @@ struct net_device *dev_getbyhwaddr_rcu(s
24063  
24064         for_each_netdev_rcu(net, dev)
24065                 if (dev->type == type &&
24066 -                   !memcmp(dev->dev_addr, ha, dev->addr_len))
24067 +                   !memcmp(dev->dev_addr, ha, dev->addr_len) &&
24068 +                   nx_dev_visible(current_nx_info(), dev))
24069                         return dev;
24070  
24071         return NULL;
24072 @@ -858,9 +873,11 @@ struct net_device *__dev_getfirstbyhwtyp
24073         struct net_device *dev;
24074  
24075         ASSERT_RTNL();
24076 -       for_each_netdev(net, dev)
24077 -               if (dev->type == type)
24078 +       for_each_netdev(net, dev) {
24079 +               if ((dev->type == type) &&
24080 +                   nx_dev_visible(current_nx_info(), dev))
24081                         return dev;
24082 +       }
24083  
24084         return NULL;
24085  }
24086 @@ -872,7 +889,8 @@ struct net_device *dev_getfirstbyhwtype(
24087  
24088         rcu_read_lock();
24089         for_each_netdev_rcu(net, dev)
24090 -               if (dev->type == type) {
24091 +               if ((dev->type == type) &&
24092 +                   nx_dev_visible(current_nx_info(), dev)) {
24093                         dev_hold(dev);
24094                         ret = dev;
24095                         break;
24096 @@ -900,7 +918,8 @@ struct net_device *dev_get_by_flags_rcu(
24097  
24098         ret = NULL;
24099         for_each_netdev_rcu(net, dev) {
24100 -               if (((dev->flags ^ if_flags) & mask) == 0) {
24101 +               if ((((dev->flags ^ if_flags) & mask) == 0) &&
24102 +                       nx_dev_visible(current_nx_info(), dev)) {
24103                         ret = dev;
24104                         break;
24105                 }
24106 @@ -978,6 +997,8 @@ static int __dev_alloc_name(struct net *
24107                                 continue;
24108                         if (i < 0 || i >= max_netdevices)
24109                                 continue;
24110 +                       if (!nx_dev_visible(current_nx_info(), d))
24111 +                               continue;
24112  
24113                         /*  avoid cases where sscanf is not exact inverse of printf */
24114                         snprintf(buf, IFNAMSIZ, name, i);
24115 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
24116 --- linux-3.10.33/net/core/net-procfs.c 2013-07-14 17:01:37.000000000 +0000
24117 +++ linux-3.10.33-vs2.3.6.8/net/core/net-procfs.c       2013-08-22 20:30:00.000000000 +0000
24118 @@ -1,6 +1,7 @@
24119  #include <linux/netdevice.h>
24120  #include <linux/proc_fs.h>
24121  #include <linux/seq_file.h>
24122 +#include <linux/vs_inet.h>
24123  #include <net/wext.h>
24124  
24125  #define BUCKET_SPACE (32 - NETDEV_HASHBITS - 1)
24126 @@ -77,8 +78,13 @@ static void dev_seq_stop(struct seq_file
24127  static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
24128  {
24129         struct rtnl_link_stats64 temp;
24130 -       const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
24131 +       const struct rtnl_link_stats64 *stats;
24132 +
24133 +       /* device visible inside network context? */
24134 +       if (!nx_dev_visible(current_nx_info(), dev))
24135 +               return;
24136  
24137 +       stats = dev_get_stats(dev, &temp);
24138         seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
24139                    "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
24140                    dev->name, stats->rx_bytes, stats->rx_packets,
24141 diff -NurpP --minimal linux-3.10.33/net/core/rtnetlink.c linux-3.10.33-vs2.3.6.8/net/core/rtnetlink.c
24142 --- linux-3.10.33/net/core/rtnetlink.c  2014-03-12 13:16:02.000000000 +0000
24143 +++ linux-3.10.33-vs2.3.6.8/net/core/rtnetlink.c        2013-11-13 17:17:16.000000000 +0000
24144 @@ -1059,6 +1059,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
24145                 hlist_for_each_entry_rcu(dev, head, index_hlist) {
24146                         if (idx < s_idx)
24147                                 goto cont;
24148 +                       if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
24149 +                               continue;
24150                         if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
24151                                              NETLINK_CB(cb->skb).portid,
24152                                              cb->nlh->nlmsg_seq, 0,
24153 @@ -1951,6 +1953,9 @@ void rtmsg_ifinfo(int type, struct net_d
24154         int err = -ENOBUFS;
24155         size_t if_info_size;
24156  
24157 +       if (!nx_dev_visible(current_nx_info(), dev))
24158 +               return;
24159 +
24160         skb = nlmsg_new((if_info_size = if_nlmsg_size(dev, 0)), GFP_KERNEL);
24161         if (skb == NULL)
24162                 goto errout;
24163 diff -NurpP --minimal linux-3.10.33/net/core/sock.c linux-3.10.33-vs2.3.6.8/net/core/sock.c
24164 --- linux-3.10.33/net/core/sock.c       2014-03-12 13:16:02.000000000 +0000
24165 +++ linux-3.10.33-vs2.3.6.8/net/core/sock.c     2014-03-12 13:18:33.000000000 +0000
24166 @@ -132,6 +132,10 @@
24167  #include <net/netprio_cgroup.h>
24168  
24169  #include <linux/filter.h>
24170 +#include <linux/vs_socket.h>
24171 +#include <linux/vs_limit.h>
24172 +#include <linux/vs_context.h>
24173 +#include <linux/vs_network.h>
24174  
24175  #include <trace/events/sock.h>
24176  
24177 @@ -1252,6 +1256,8 @@ static struct sock *sk_prot_alloc(struct
24178                         goto out_free_sec;
24179                 sk_tx_queue_clear(sk);
24180         }
24181 +               sock_vx_init(sk);
24182 +               sock_nx_init(sk);
24183  
24184         return sk;
24185  
24186 @@ -1360,6 +1366,11 @@ static void __sk_free(struct sock *sk)
24187                 put_cred(sk->sk_peer_cred);
24188         put_pid(sk->sk_peer_pid);
24189         put_net(sock_net(sk));
24190 +       vx_sock_dec(sk);
24191 +       clr_vx_info(&sk->sk_vx_info);
24192 +       sk->sk_xid = -1;
24193 +       clr_nx_info(&sk->sk_nx_info);
24194 +       sk->sk_nid = -1;
24195         sk_prot_free(sk->sk_prot_creator, sk);
24196  }
24197  
24198 @@ -1420,6 +1431,8 @@ struct sock *sk_clone_lock(const struct
24199  
24200                 /* SANITY */
24201                 get_net(sock_net(newsk));
24202 +               sock_vx_init(newsk);
24203 +               sock_nx_init(newsk);
24204                 sk_node_init(&newsk->sk_node);
24205                 sock_lock_init(newsk);
24206                 bh_lock_sock(newsk);
24207 @@ -1476,6 +1489,12 @@ struct sock *sk_clone_lock(const struct
24208                 smp_wmb();
24209                 atomic_set(&newsk->sk_refcnt, 2);
24210  
24211 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
24212 +               newsk->sk_xid = sk->sk_xid;
24213 +               vx_sock_inc(newsk);
24214 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
24215 +               newsk->sk_nid = sk->sk_nid;
24216 +
24217                 /*
24218                  * Increment the counter in the same struct proto as the master
24219                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
24220 @@ -2271,6 +2290,12 @@ void sock_init_data(struct socket *sock,
24221  
24222         sk->sk_stamp = ktime_set(-1L, 0);
24223  
24224 +       set_vx_info(&sk->sk_vx_info, current_vx_info());
24225 +       sk->sk_xid = vx_current_xid();
24226 +       vx_sock_inc(sk);
24227 +       set_nx_info(&sk->sk_nx_info, current_nx_info());
24228 +       sk->sk_nid = nx_current_nid();
24229 +
24230         sk->sk_pacing_rate = ~0U;
24231         /*
24232          * Before updating sk_refcnt, we must commit prior changes to memory
24233 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
24234 --- linux-3.10.33/net/ipv4/af_inet.c    2014-03-12 13:16:02.000000000 +0000
24235 +++ linux-3.10.33-vs2.3.6.8/net/ipv4/af_inet.c  2013-11-13 17:17:16.000000000 +0000
24236 @@ -118,6 +118,7 @@
24237  #ifdef CONFIG_IP_MROUTE
24238  #include <linux/mroute.h>
24239  #endif
24240 +#include <linux/vs_limit.h>
24241  
24242  
24243  /* The inetsw table contains everything that inet_create needs to
24244 @@ -336,10 +337,13 @@ lookup_protocol:
24245         }
24246  
24247         err = -EPERM;
24248 +       if ((protocol == IPPROTO_ICMP) &&
24249 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
24250 +               goto override;
24251         if (sock->type == SOCK_RAW && !kern &&
24252             !ns_capable(net->user_ns, CAP_NET_RAW))
24253                 goto out_rcu_unlock;
24254 -
24255 +override:
24256         sock->ops = answer->ops;
24257         answer_prot = answer->prot;
24258         answer_no_check = answer->no_check;
24259 @@ -460,6 +464,7 @@ int inet_bind(struct socket *sock, struc
24260         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
24261         struct sock *sk = sock->sk;
24262         struct inet_sock *inet = inet_sk(sk);
24263 +       struct nx_v4_sock_addr nsa;
24264         struct net *net = sock_net(sk);
24265         unsigned short snum;
24266         int chk_addr_ret;
24267 @@ -484,7 +489,11 @@ int inet_bind(struct socket *sock, struc
24268                         goto out;
24269         }
24270  
24271 -       chk_addr_ret = inet_addr_type(net, addr->sin_addr.s_addr);
24272 +       err = v4_map_sock_addr(inet, addr, &nsa);
24273 +       if (err)
24274 +               goto out;
24275 +
24276 +       chk_addr_ret = inet_addr_type(net, nsa.saddr);
24277  
24278         /* Not specified by any standard per-se, however it breaks too
24279          * many applications when removed.  It is unfortunate since
24280 @@ -496,7 +505,7 @@ int inet_bind(struct socket *sock, struc
24281         err = -EADDRNOTAVAIL;
24282         if (!sysctl_ip_nonlocal_bind &&
24283             !(inet->freebind || inet->transparent) &&
24284 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
24285 +           nsa.saddr != htonl(INADDR_ANY) &&
24286             chk_addr_ret != RTN_LOCAL &&
24287             chk_addr_ret != RTN_MULTICAST &&
24288             chk_addr_ret != RTN_BROADCAST)
24289 @@ -522,7 +531,7 @@ int inet_bind(struct socket *sock, struc
24290         if (sk->sk_state != TCP_CLOSE || inet->inet_num)
24291                 goto out_release_sock;
24292  
24293 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24294 +       v4_set_sock_addr(inet, &nsa);
24295         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24296                 inet->inet_saddr = 0;  /* Use device */
24297  
24298 @@ -741,11 +750,13 @@ int inet_getname(struct socket *sock, st
24299                      peer == 1))
24300                         return -ENOTCONN;
24301                 sin->sin_port = inet->inet_dport;
24302 -               sin->sin_addr.s_addr = inet->inet_daddr;
24303 +               sin->sin_addr.s_addr =
24304 +                       nx_map_sock_lback(sk->sk_nx_info, inet->inet_daddr);
24305         } else {
24306                 __be32 addr = inet->inet_rcv_saddr;
24307                 if (!addr)
24308                         addr = inet->inet_saddr;
24309 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
24310                 sin->sin_port = inet->inet_sport;
24311                 sin->sin_addr.s_addr = addr;
24312         }
24313 diff -NurpP --minimal linux-3.10.33/net/ipv4/arp.c linux-3.10.33-vs2.3.6.8/net/ipv4/arp.c
24314 --- linux-3.10.33/net/ipv4/arp.c        2013-07-14 17:01:37.000000000 +0000
24315 +++ linux-3.10.33-vs2.3.6.8/net/ipv4/arp.c      2013-08-22 20:30:00.000000000 +0000
24316 @@ -1332,6 +1332,7 @@ static void arp_format_neigh_entry(struc
24317         struct net_device *dev = n->dev;
24318         int hatype = dev->type;
24319  
24320 +       /* FIXME: check for network context */
24321         read_lock(&n->lock);
24322         /* Convert hardware address to XX:XX:XX:XX ... form. */
24323  #if IS_ENABLED(CONFIG_AX25)
24324 @@ -1363,6 +1364,7 @@ static void arp_format_pneigh_entry(stru
24325         int hatype = dev ? dev->type : 0;
24326         char tbuf[16];
24327  
24328 +       /* FIXME: check for network context */
24329         sprintf(tbuf, "%pI4", n->key);
24330         seq_printf(seq, "%-16s 0x%-10x0x%-10x%s     *        %s\n",
24331                    tbuf, hatype, ATF_PUBL | ATF_PERM, "00:00:00:00:00:00",
24332 diff -NurpP --minimal linux-3.10.33/net/ipv4/devinet.c linux-3.10.33-vs2.3.6.8/net/ipv4/devinet.c
24333 --- linux-3.10.33/net/ipv4/devinet.c    2014-03-12 13:16:02.000000000 +0000
24334 +++ linux-3.10.33-vs2.3.6.8/net/ipv4/devinet.c  2014-03-12 13:18:33.000000000 +0000
24335 @@ -522,6 +522,7 @@ struct in_device *inetdev_by_index(struc
24336  }
24337  EXPORT_SYMBOL(inetdev_by_index);
24338  
24339 +
24340  /* Called only from RTNL semaphored context. No locks. */
24341  
24342  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
24343 @@ -942,6 +943,8 @@ int devinet_ioctl(struct net *net, unsig
24344  
24345         in_dev = __in_dev_get_rtnl(dev);
24346         if (in_dev) {
24347 +               struct nx_info *nxi = current_nx_info();
24348 +
24349                 if (tryaddrmatch) {
24350                         /* Matthias Andree */
24351                         /* compare label and address (4.4BSD style) */
24352 @@ -950,6 +953,8 @@ int devinet_ioctl(struct net *net, unsig
24353                            This is checked above. */
24354                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24355                              ifap = &ifa->ifa_next) {
24356 +                               if (!nx_v4_ifa_visible(nxi, ifa))
24357 +                                       continue;
24358                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
24359                                     sin_orig.sin_addr.s_addr ==
24360                                                         ifa->ifa_local) {
24361 @@ -962,9 +967,12 @@ int devinet_ioctl(struct net *net, unsig
24362                    comparing just the label */
24363                 if (!ifa) {
24364                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24365 -                            ifap = &ifa->ifa_next)
24366 +                            ifap = &ifa->ifa_next) {
24367 +                               if (!nx_v4_ifa_visible(nxi, ifa))
24368 +                                       continue;
24369                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
24370                                         break;
24371 +                       }
24372                 }
24373         }
24374  
24375 @@ -1118,6 +1126,8 @@ static int inet_gifconf(struct net_devic
24376                 goto out;
24377  
24378         for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
24379 +               if (!nx_v4_ifa_visible(current_nx_info(), ifa))
24380 +                       continue;
24381                 if (!buf) {
24382                         done += sizeof(ifr);
24383                         continue;
24384 @@ -1522,6 +1532,7 @@ static int inet_dump_ifaddr(struct sk_bu
24385         struct net_device *dev;
24386         struct in_device *in_dev;
24387         struct in_ifaddr *ifa;
24388 +       struct sock *sk = skb->sk;
24389         struct hlist_head *head;
24390  
24391         s_h = cb->args[0];
24392 @@ -1545,6 +1556,8 @@ static int inet_dump_ifaddr(struct sk_bu
24393  
24394                         for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
24395                              ifa = ifa->ifa_next, ip_idx++) {
24396 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
24397 +                               continue;
24398                                 if (ip_idx < s_ip_idx)
24399                                         continue;
24400                                 if (inet_fill_ifaddr(skb, ifa,
24401 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
24402 --- linux-3.10.33/net/ipv4/fib_trie.c   2014-03-12 13:16:02.000000000 +0000
24403 +++ linux-3.10.33-vs2.3.6.8/net/ipv4/fib_trie.c 2013-11-13 17:17:16.000000000 +0000
24404 @@ -2536,6 +2536,7 @@ static int fib_route_seq_show(struct seq
24405                             || fa->fa_type == RTN_MULTICAST)
24406                                 continue;
24407  
24408 +                       /* FIXME: check for network context? */
24409                         if (fi)
24410                                 seq_printf(seq,
24411                                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t"
24412 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
24413 --- linux-3.10.33/net/ipv4/inet_connection_sock.c       2013-07-14 17:01:37.000000000 +0000
24414 +++ linux-3.10.33-vs2.3.6.8/net/ipv4/inet_connection_sock.c     2013-08-22 20:30:00.000000000 +0000
24415 @@ -53,6 +53,37 @@ void inet_get_local_port_range(int *low,
24416  }
24417  EXPORT_SYMBOL(inet_get_local_port_range);
24418  
24419 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24420 +{
24421 +       __be32  sk1_rcv_saddr = sk_rcv_saddr(sk1),
24422 +               sk2_rcv_saddr = sk_rcv_saddr(sk2);
24423 +
24424 +       if (inet_v6_ipv6only(sk2))
24425 +               return 0;
24426 +
24427 +       if (sk1_rcv_saddr &&
24428 +           sk2_rcv_saddr &&
24429 +           sk1_rcv_saddr == sk2_rcv_saddr)
24430 +               return 1;
24431 +
24432 +       if (sk1_rcv_saddr &&
24433 +           !sk2_rcv_saddr &&
24434 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
24435 +               return 1;
24436 +
24437 +       if (sk2_rcv_saddr &&
24438 +           !sk1_rcv_saddr &&
24439 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
24440 +               return 1;
24441 +
24442 +       if (!sk1_rcv_saddr &&
24443 +           !sk2_rcv_saddr &&
24444 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
24445 +               return 1;
24446 +
24447 +       return 0;
24448 +}
24449 +
24450  int inet_csk_bind_conflict(const struct sock *sk,
24451                            const struct inet_bind_bucket *tb, bool relax)
24452  {
24453 @@ -79,17 +110,12 @@ int inet_csk_bind_conflict(const struct
24454                             (!reuseport || !sk2->sk_reuseport ||
24455                             (sk2->sk_state != TCP_TIME_WAIT &&
24456                              !uid_eq(uid, sock_i_uid(sk2))))) {
24457 -                               const __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
24458 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr(sk) ||
24459 -                                   sk2_rcv_saddr == sk_rcv_saddr(sk))
24460 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
24461                                         break;
24462                         }
24463                         if (!relax && reuse && sk2->sk_reuse &&
24464                             sk2->sk_state != TCP_LISTEN) {
24465 -                               const __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
24466 -
24467 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr(sk) ||
24468 -                                   sk2_rcv_saddr == sk_rcv_saddr(sk))
24469 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
24470                                         break;
24471                         }
24472                 }
24473 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
24474 --- linux-3.10.33/net/ipv4/inet_diag.c  2014-03-12 13:16:02.000000000 +0000
24475 +++ linux-3.10.33-vs2.3.6.8/net/ipv4/inet_diag.c        2014-03-12 13:18:23.000000000 +0000
24476 @@ -31,6 +31,8 @@
24477  
24478  #include <linux/inet.h>
24479  #include <linux/stddef.h>
24480 +#include <linux/vs_network.h>
24481 +#include <linux/vs_inet.h>
24482  
24483  #include <linux/inet_diag.h>
24484  #include <linux/sock_diag.h>
24485 @@ -110,8 +112,10 @@ int inet_sk_diag_fill(struct sock *sk, s
24486         memset(&r->id.idiag_src, 0, sizeof(r->id.idiag_src));
24487         memset(&r->id.idiag_dst, 0, sizeof(r->id.idiag_dst));
24488  
24489 -       r->id.idiag_src[0] = inet->inet_rcv_saddr;
24490 -       r->id.idiag_dst[0] = inet->inet_daddr;
24491 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info,
24492 +               inet->inet_rcv_saddr);
24493 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info,
24494 +               inet->inet_daddr);
24495  
24496         if (nla_put_u8(skb, INET_DIAG_SHUTDOWN, sk->sk_shutdown))
24497                 goto errout;
24498 @@ -254,8 +258,8 @@ static int inet_twsk_diag_fill(struct in
24499         memset(&r->id.idiag_src, 0, sizeof(r->id.idiag_src));
24500         memset(&r->id.idiag_dst, 0, sizeof(r->id.idiag_dst));
24501  
24502 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
24503 -       r->id.idiag_dst[0]    = tw->tw_daddr;
24504 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
24505 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
24506  
24507         r->idiag_state        = tw->tw_substate;
24508         r->idiag_timer        = 3;
24509 @@ -300,12 +304,14 @@ int inet_diag_dump_one_icsk(struct inet_
24510  
24511         err = -EINVAL;
24512         if (req->sdiag_family == AF_INET) {
24513 +               /* TODO: lback */
24514                 sk = inet_lookup(net, hashinfo, req->id.idiag_dst[0],
24515                                  req->id.idiag_dport, req->id.idiag_src[0],
24516                                  req->id.idiag_sport, req->id.idiag_if);
24517         }
24518  #if IS_ENABLED(CONFIG_IPV6)
24519         else if (req->sdiag_family == AF_INET6) {
24520 +               /* TODO: lback */
24521                 sk = inet6_lookup(net, hashinfo,
24522                                   (struct in6_addr *)req->id.idiag_dst,
24523                                   req->id.idiag_dport,
24524 @@ -507,6 +513,7 @@ int inet_diag_bc_sk(const struct nlattr
24525         } else
24526  #endif
24527         {
24528 +                       /* TODO: lback */
24529                 entry.saddr = &inet->inet_rcv_saddr;
24530                 entry.daddr = &inet->inet_daddr;
24531         }
24532 @@ -665,6 +672,7 @@ static int inet_twsk_diag_dump(struct in
24533                 } else
24534  #endif
24535                 {
24536 +                       /* TODO: lback */
24537                         entry.saddr = &tw->tw_rcv_saddr;
24538                         entry.daddr = &tw->tw_daddr;
24539                 }
24540 @@ -747,8 +755,8 @@ static int inet_diag_fill_req(struct sk_
24541         memset(&r->id.idiag_src, 0, sizeof(r->id.idiag_src));
24542         memset(&r->id.idiag_dst, 0, sizeof(r->id.idiag_dst));
24543  
24544 -       r->id.idiag_src[0] = ireq->loc_addr;
24545 -       r->id.idiag_dst[0] = ireq->rmt_addr;
24546 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
24547 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
24548  
24549         r->idiag_expires = jiffies_to_msecs(tmo);
24550         r->idiag_rqueue = 0;
24551 @@ -812,6 +820,7 @@ static int inet_diag_dump_reqs(struct sk
24552                             r->id.idiag_dport)
24553                                 continue;
24554  
24555 +                       /* TODO: lback */
24556                         if (bc) {
24557                                 inet_diag_req_addrs(sk, req, &entry);
24558                                 entry.dport = ntohs(ireq->rmt_port);
24559 @@ -868,6 +877,8 @@ void inet_diag_dump_icsk(struct inet_has
24560                                 if (!net_eq(sock_net(sk), net))
24561                                         continue;
24562  
24563 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24564 +                                       continue;
24565                                 if (num < s_num) {
24566                                         num++;
24567                                         continue;
24568 @@ -940,6 +951,8 @@ skip_listen_ht:
24569  
24570                         if (!net_eq(sock_net(sk), net))
24571                                 continue;
24572 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24573 +                               continue;
24574                         if (num < s_num)
24575                                 goto next_normal;
24576                         if (!(r->idiag_states & (1 << sk->sk_state)))
24577 @@ -968,7 +981,8 @@ next_normal:
24578                                     &head->twchain) {
24579                                 if (!net_eq(twsk_net(tw), net))
24580                                         continue;
24581 -
24582 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
24583 +                                       continue;
24584                                 if (num < s_num)
24585                                         goto next_dying;
24586                                 if (!(r->idiag_states & (1 << tw->tw_substate)))
24587 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
24588 --- linux-3.10.33/net/ipv4/inet_hashtables.c    2014-03-12 13:16:02.000000000 +0000
24589 +++ linux-3.10.33-vs2.3.6.8/net/ipv4/inet_hashtables.c  2013-11-13 17:22:25.000000000 +0000
24590 @@ -22,6 +22,7 @@
24591  #include <net/inet_connection_sock.h>
24592  #include <net/inet_hashtables.h>
24593  #include <net/secure_seq.h>
24594 +#include <net/route.h>
24595  #include <net/ip.h>
24596  
24597  /*
24598 @@ -156,6 +157,11 @@ static inline int compute_score(struct s
24599                         if (rcv_saddr != daddr)
24600                                 return -1;
24601                         score += 4;
24602 +               } else {
24603 +                       /* block non nx_info ips */
24604 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
24605 +                               daddr, NXA_MASK_BIND))
24606 +                               return -1;
24607                 }
24608                 if (sk->sk_bound_dev_if) {
24609                         if (sk->sk_bound_dev_if != dif)
24610 @@ -173,7 +179,6 @@ static inline int compute_score(struct s
24611   * wildcarded during the search since they can never be otherwise.
24612   */
24613  
24614 -
24615  struct sock *__inet_lookup_listener(struct net *net,
24616                                     struct inet_hashinfo *hashinfo,
24617                                     const __be32 saddr, __be16 sport,
24618 @@ -209,6 +214,7 @@ begin:
24619                         phash = next_pseudo_random32(phash);
24620                 }
24621         }
24622 +
24623         /*
24624          * if the nulls value we got at the end of this lookup is
24625          * not the expected one, we must restart lookup.
24626 diff -NurpP --minimal linux-3.10.33/net/ipv4/netfilter.c linux-3.10.33-vs2.3.6.8/net/ipv4/netfilter.c
24627 --- linux-3.10.33/net/ipv4/netfilter.c  2013-07-14 17:01:37.000000000 +0000
24628 +++ linux-3.10.33-vs2.3.6.8/net/ipv4/netfilter.c        2013-08-22 20:30:00.000000000 +0000
24629 @@ -11,7 +11,7 @@
24630  #include <linux/skbuff.h>
24631  #include <linux/gfp.h>
24632  #include <linux/export.h>
24633 -#include <net/route.h>
24634 +// #include <net/route.h>
24635  #include <net/xfrm.h>
24636  #include <net/ip.h>
24637  #include <net/netfilter/nf_queue.h>
24638 diff -NurpP --minimal linux-3.10.33/net/ipv4/raw.c linux-3.10.33-vs2.3.6.8/net/ipv4/raw.c
24639 --- linux-3.10.33/net/ipv4/raw.c        2014-03-12 13:16:02.000000000 +0000
24640 +++ linux-3.10.33-vs2.3.6.8/net/ipv4/raw.c      2013-12-23 17:42:40.000000000 +0000
24641 @@ -116,7 +116,7 @@ static struct sock *__raw_v4_lookup(stru
24642  
24643                 if (net_eq(sock_net(sk), net) && inet->inet_num == num  &&
24644                     !(inet->inet_daddr && inet->inet_daddr != raddr)    &&
24645 -                   !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
24646 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
24647                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
24648                         goto found; /* gotcha */
24649         }
24650 @@ -395,6 +395,12 @@ static int raw_send_hdrinc(struct sock *
24651                 icmp_out_count(net, ((struct icmphdr *)
24652                         skb_transport_header(skb))->type);
24653  
24654 +       err = -EPERM;
24655 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
24656 +               sk->sk_nx_info &&
24657 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
24658 +               goto error_free;
24659 +
24660         err = NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT, skb, NULL,
24661                       rt->dst.dev, dst_output);
24662         if (err > 0)
24663 @@ -581,6 +587,16 @@ static int raw_sendmsg(struct kiocb *ioc
24664                         goto done;
24665         }
24666  
24667 +       if (sk->sk_nx_info) {
24668 +               rt = ip_v4_find_src(sock_net(sk), sk->sk_nx_info, &fl4);
24669 +               if (IS_ERR(rt)) {
24670 +                       err = PTR_ERR(rt);
24671 +                       rt = NULL;
24672 +                       goto done;
24673 +               }
24674 +               ip_rt_put(rt);
24675 +       }
24676 +
24677         security_sk_classify_flow(sk, flowi4_to_flowi(&fl4));
24678         rt = ip_route_output_flow(sock_net(sk), &fl4, sk);
24679         if (IS_ERR(rt)) {
24680 @@ -657,17 +673,19 @@ static int raw_bind(struct sock *sk, str
24681  {
24682         struct inet_sock *inet = inet_sk(sk);
24683         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
24684 +       struct nx_v4_sock_addr nsa = { 0 };
24685         int ret = -EINVAL;
24686         int chk_addr_ret;
24687  
24688         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
24689                 goto out;
24690 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
24691 +       v4_map_sock_addr(inet, addr, &nsa);
24692 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
24693         ret = -EADDRNOTAVAIL;
24694 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
24695 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
24696             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
24697                 goto out;
24698 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24699 +       v4_set_sock_addr(inet, &nsa);
24700         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24701                 inet->inet_saddr = 0;  /* Use device */
24702         sk_dst_reset(sk);
24703 @@ -716,7 +734,8 @@ static int raw_recvmsg(struct kiocb *ioc
24704         /* Copy the address. */
24705         if (sin) {
24706                 sin->sin_family = AF_INET;
24707 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
24708 +               sin->sin_addr.s_addr =
24709 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
24710                 sin->sin_port = 0;
24711                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
24712                 *addr_len = sizeof(*sin);
24713 @@ -912,7 +931,8 @@ static struct sock *raw_get_first(struct
24714         for (state->bucket = 0; state->bucket < RAW_HTABLE_SIZE;
24715                         ++state->bucket) {
24716                 sk_for_each(sk, &state->h->ht[state->bucket])
24717 -                       if (sock_net(sk) == seq_file_net(seq))
24718 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
24719 +                           nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24720                                 goto found;
24721         }
24722         sk = NULL;
24723 @@ -928,7 +948,8 @@ static struct sock *raw_get_next(struct
24724                 sk = sk_next(sk);
24725  try_again:
24726                 ;
24727 -       } while (sk && sock_net(sk) != seq_file_net(seq));
24728 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
24729 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
24730  
24731         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
24732                 sk = sk_head(&state->h->ht[state->bucket]);
24733 diff -NurpP --minimal linux-3.10.33/net/ipv4/route.c linux-3.10.33-vs2.3.6.8/net/ipv4/route.c
24734 --- linux-3.10.33/net/ipv4/route.c      2014-03-12 13:16:02.000000000 +0000
24735 +++ linux-3.10.33-vs2.3.6.8/net/ipv4/route.c    2014-03-12 13:18:33.000000000 +0000
24736 @@ -2007,7 +2007,7 @@ struct rtable *__ip_route_output_key(str
24737  
24738  
24739         if (fl4->flowi4_oif) {
24740 -               dev_out = dev_get_by_index_rcu(net, fl4->flowi4_oif);
24741 +               dev_out = dev_get_by_index_real_rcu(net, fl4->flowi4_oif);
24742                 rth = ERR_PTR(-ENODEV);
24743                 if (dev_out == NULL)
24744                         goto out;
24745 diff -NurpP --minimal linux-3.10.33/net/ipv4/tcp.c linux-3.10.33-vs2.3.6.8/net/ipv4/tcp.c
24746 --- linux-3.10.33/net/ipv4/tcp.c        2014-03-12 13:16:02.000000000 +0000
24747 +++ linux-3.10.33-vs2.3.6.8/net/ipv4/tcp.c      2013-12-23 17:42:40.000000000 +0000
24748 @@ -268,6 +268,7 @@
24749  #include <linux/crypto.h>
24750  #include <linux/time.h>
24751  #include <linux/slab.h>
24752 +#include <linux/in.h>
24753  
24754  #include <net/icmp.h>
24755  #include <net/inet_common.h>
24756 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
24757 --- linux-3.10.33/net/ipv4/tcp_ipv4.c   2014-03-12 13:16:02.000000000 +0000
24758 +++ linux-3.10.33-vs2.3.6.8/net/ipv4/tcp_ipv4.c 2013-12-23 17:42:40.000000000 +0000
24759 @@ -2263,6 +2263,12 @@ static void *listening_get_next(struct s
24760                 req = req->dl_next;
24761                 while (1) {
24762                         while (req) {
24763 +                               vxdprintk(VXD_CBIT(net, 6),
24764 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
24765 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
24766 +                               if (req->sk &&
24767 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
24768 +                                       continue;
24769                                 if (req->rsk_ops->family == st->family) {
24770                                         cur = req;
24771                                         goto out;
24772 @@ -2287,6 +2293,10 @@ get_req:
24773         }
24774  get_sk:
24775         sk_nulls_for_each_from(sk, node) {
24776 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
24777 +                       sk, sk->sk_nid, nx_current_nid());
24778 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24779 +                       continue;
24780                 if (!net_eq(sock_net(sk), net))
24781                         continue;
24782                 if (sk->sk_family == st->family) {
24783 @@ -2363,6 +2373,11 @@ static void *established_get_first(struc
24784  
24785                 spin_lock_bh(lock);
24786                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
24787 +                       vxdprintk(VXD_CBIT(net, 6),
24788 +                               "sk,egf: %p [#%d] (from %d)",
24789 +                               sk, sk->sk_nid, nx_current_nid());
24790 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24791 +                               continue;
24792                         if (sk->sk_family != st->family ||
24793                             !net_eq(sock_net(sk), net)) {
24794                                 continue;
24795 @@ -2373,6 +2388,11 @@ static void *established_get_first(struc
24796                 st->state = TCP_SEQ_STATE_TIME_WAIT;
24797                 inet_twsk_for_each(tw, node,
24798                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
24799 +                       vxdprintk(VXD_CBIT(net, 6),
24800 +                               "tw: %p [#%d] (from %d)",
24801 +                               tw, tw->tw_nid, nx_current_nid());
24802 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
24803 +                               continue;
24804                         if (tw->tw_family != st->family ||
24805                             !net_eq(twsk_net(tw), net)) {
24806                                 continue;
24807 @@ -2402,7 +2422,9 @@ static void *established_get_next(struct
24808                 tw = cur;
24809                 tw = tw_next(tw);
24810  get_tw:
24811 -               while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
24812 +               while (tw && (tw->tw_family != st->family ||
24813 +                       !net_eq(twsk_net(tw), net) ||
24814 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
24815                         tw = tw_next(tw);
24816                 }
24817                 if (tw) {
24818 @@ -2426,6 +2448,11 @@ get_tw:
24819                 sk = sk_nulls_next(sk);
24820  
24821         sk_nulls_for_each_from(sk, node) {
24822 +               vxdprintk(VXD_CBIT(net, 6),
24823 +                       "sk,egn: %p [#%d] (from %d)",
24824 +                       sk, sk->sk_nid, nx_current_nid());
24825 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24826 +                       continue;
24827                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
24828                         goto found;
24829         }
24830 @@ -2631,9 +2658,9 @@ static void get_openreq4(const struct so
24831         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
24832                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %pK%n",
24833                 i,
24834 -               ireq->loc_addr,
24835 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
24836                 ntohs(inet_sk(sk)->inet_sport),
24837 -               ireq->rmt_addr,
24838 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
24839                 ntohs(ireq->rmt_port),
24840                 TCP_SYN_RECV,
24841                 0, 0, /* could print option size, but that is af dependent. */
24842 @@ -2656,8 +2683,8 @@ static void get_tcp4_sock(struct sock *s
24843         const struct inet_connection_sock *icsk = inet_csk(sk);
24844         const struct inet_sock *inet = inet_sk(sk);
24845         struct fastopen_queue *fastopenq = icsk->icsk_accept_queue.fastopenq;
24846 -       __be32 dest = inet->inet_daddr;
24847 -       __be32 src = inet->inet_rcv_saddr;
24848 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
24849 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
24850         __u16 destp = ntohs(inet->inet_dport);
24851         __u16 srcp = ntohs(inet->inet_sport);
24852         int rx_queue;
24853 @@ -2715,8 +2742,8 @@ static void get_timewait4_sock(const str
24854         __u16 destp, srcp;
24855         long delta = tw->tw_ttd - jiffies;
24856  
24857 -       dest  = tw->tw_daddr;
24858 -       src   = tw->tw_rcv_saddr;
24859 +       dest  = nx_map_sock_lback(current_nx_info(), tw->tw_daddr);
24860 +       src   = nx_map_sock_lback(current_nx_info(), tw->tw_rcv_saddr);
24861         destp = ntohs(tw->tw_dport);
24862         srcp  = ntohs(tw->tw_sport);
24863  
24864 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
24865 --- linux-3.10.33/net/ipv4/tcp_minisocks.c      2013-07-14 17:01:37.000000000 +0000
24866 +++ linux-3.10.33-vs2.3.6.8/net/ipv4/tcp_minisocks.c    2013-08-22 20:30:00.000000000 +0000
24867 @@ -23,6 +23,9 @@
24868  #include <linux/slab.h>
24869  #include <linux/sysctl.h>
24870  #include <linux/workqueue.h>
24871 +#include <linux/vs_limit.h>
24872 +#include <linux/vs_socket.h>
24873 +#include <linux/vs_context.h>
24874  #include <net/tcp.h>
24875  #include <net/inet_common.h>
24876  #include <net/xfrm.h>
24877 @@ -290,6 +293,11 @@ void tcp_time_wait(struct sock *sk, int
24878                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
24879                 tcptw->tw_ts_offset     = tp->tsoffset;
24880  
24881 +               tw->tw_xid              = sk->sk_xid;
24882 +               tw->tw_vx_info          = NULL;
24883 +               tw->tw_nid              = sk->sk_nid;
24884 +               tw->tw_nx_info          = NULL;
24885 +
24886  #if IS_ENABLED(CONFIG_IPV6)
24887                 if (tw->tw_family == PF_INET6) {
24888                         struct ipv6_pinfo *np = inet6_sk(sk);
24889 diff -NurpP --minimal linux-3.10.33/net/ipv4/udp.c linux-3.10.33-vs2.3.6.8/net/ipv4/udp.c
24890 --- linux-3.10.33/net/ipv4/udp.c        2014-03-12 13:16:02.000000000 +0000
24891 +++ linux-3.10.33-vs2.3.6.8/net/ipv4/udp.c      2013-12-23 17:42:40.000000000 +0000
24892 @@ -306,14 +306,7 @@ fail:
24893  }
24894  EXPORT_SYMBOL(udp_lib_get_port);
24895  
24896 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24897 -{
24898 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
24899 -
24900 -       return  (!ipv6_only_sock(sk2)  &&
24901 -                (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr ||
24902 -                  inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
24903 -}
24904 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
24905  
24906  static unsigned int udp4_portaddr_hash(struct net *net, __be32 saddr,
24907                                        unsigned int port)
24908 @@ -348,6 +341,11 @@ static inline int compute_score(struct s
24909                         if (inet->inet_rcv_saddr != daddr)
24910                                 return -1;
24911                         score += 4;
24912 +               } else {
24913 +                       /* block non nx_info ips */
24914 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
24915 +                               daddr, NXA_MASK_BIND))
24916 +                               return -1;
24917                 }
24918                 if (inet->inet_daddr) {
24919                         if (inet->inet_daddr != saddr)
24920 @@ -458,6 +456,7 @@ begin:
24921         return result;
24922  }
24923  
24924 +
24925  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
24926   * harder than this. -DaveM
24927   */
24928 @@ -504,6 +503,11 @@ begin:
24929         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
24930                 score = compute_score(sk, net, saddr, hnum, sport,
24931                                       daddr, dport, dif);
24932 +               /* FIXME: disabled?
24933 +               if (score == 9) {
24934 +                       result = sk;
24935 +                       break;
24936 +               } else */
24937                 if (score > badness) {
24938                         result = sk;
24939                         badness = score;
24940 @@ -528,6 +532,7 @@ begin:
24941         if (get_nulls_value(node) != slot)
24942                 goto begin;
24943  
24944 +
24945         if (result) {
24946                 if (unlikely(!atomic_inc_not_zero_hint(&result->sk_refcnt, 2)))
24947                         result = NULL;
24948 @@ -537,6 +542,7 @@ begin:
24949                         goto begin;
24950                 }
24951         }
24952 +
24953         rcu_read_unlock();
24954         return result;
24955  }
24956 @@ -580,8 +586,7 @@ static inline struct sock *udp_v4_mcast_
24957                     udp_sk(s)->udp_port_hash != hnum ||
24958                     (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
24959                     (inet->inet_dport != rmt_port && inet->inet_dport) ||
24960 -                   (inet->inet_rcv_saddr &&
24961 -                    inet->inet_rcv_saddr != loc_addr) ||
24962 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
24963                     ipv6_only_sock(s) ||
24964                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
24965                         continue;
24966 @@ -965,6 +970,16 @@ int udp_sendmsg(struct kiocb *iocb, stru
24967                                    inet_sk_flowi_flags(sk)|FLOWI_FLAG_CAN_SLEEP,
24968                                    faddr, saddr, dport, inet->inet_sport);
24969  
24970 +               if (sk->sk_nx_info) {
24971 +                       rt = ip_v4_find_src(net, sk->sk_nx_info, fl4);
24972 +                       if (IS_ERR(rt)) {
24973 +                               err = PTR_ERR(rt);
24974 +                               rt = NULL;
24975 +                               goto out;
24976 +                       }
24977 +                       ip_rt_put(rt);
24978 +               }
24979 +
24980                 security_sk_classify_flow(sk, flowi4_to_flowi(fl4));
24981                 rt = ip_route_output_flow(net, fl4, sk);
24982                 if (IS_ERR(rt)) {
24983 @@ -1269,7 +1284,8 @@ try_again:
24984         if (sin) {
24985                 sin->sin_family = AF_INET;
24986                 sin->sin_port = udp_hdr(skb)->source;
24987 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
24988 +               sin->sin_addr.s_addr = nx_map_sock_lback(
24989 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
24990                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
24991                 *addr_len = sizeof(*sin);
24992         }
24993 @@ -2031,6 +2047,8 @@ static struct sock *udp_get_first(struct
24994                 sk_nulls_for_each(sk, node, &hslot->head) {
24995                         if (!net_eq(sock_net(sk), net))
24996                                 continue;
24997 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24998 +                               continue;
24999                         if (sk->sk_family == state->family)
25000                                 goto found;
25001                 }
25002 @@ -2048,7 +2066,9 @@ static struct sock *udp_get_next(struct
25003  
25004         do {
25005                 sk = sk_nulls_next(sk);
25006 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
25007 +       } while (sk && (!net_eq(sock_net(sk), net) ||
25008 +               sk->sk_family != state->family ||
25009 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
25010  
25011         if (!sk) {
25012                 if (state->bucket <= state->udp_table->mask)
25013 @@ -2144,8 +2164,8 @@ static void udp4_format_sock(struct sock
25014                 int bucket, int *len)
25015  {
25016         struct inet_sock *inet = inet_sk(sp);
25017 -       __be32 dest = inet->inet_daddr;
25018 -       __be32 src  = inet->inet_rcv_saddr;
25019 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
25020 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
25021         __u16 destp       = ntohs(inet->inet_dport);
25022         __u16 srcp        = ntohs(inet->inet_sport);
25023  
25024 diff -NurpP --minimal linux-3.10.33/net/ipv6/Kconfig linux-3.10.33-vs2.3.6.8/net/ipv6/Kconfig
25025 --- linux-3.10.33/net/ipv6/Kconfig      2013-07-14 17:01:38.000000000 +0000
25026 +++ linux-3.10.33-vs2.3.6.8/net/ipv6/Kconfig    2013-08-22 20:30:00.000000000 +0000
25027 @@ -4,8 +4,8 @@
25028  
25029  #   IPv6 as module will cause a CRASH if you try to unload it
25030  menuconfig IPV6
25031 -       tristate "The IPv6 protocol"
25032 -       default m
25033 +       bool "The IPv6 protocol"
25034 +       default n
25035         ---help---
25036           This is complemental support for the IP version 6.
25037           You will still be able to do traditional IPv4 networking as well.
25038 diff -NurpP --minimal linux-3.10.33/net/ipv6/addrconf.c linux-3.10.33-vs2.3.6.8/net/ipv6/addrconf.c
25039 --- linux-3.10.33/net/ipv6/addrconf.c   2014-03-12 13:16:02.000000000 +0000
25040 +++ linux-3.10.33-vs2.3.6.8/net/ipv6/addrconf.c 2013-11-13 17:17:16.000000000 +0000
25041 @@ -94,6 +94,8 @@
25042  #include <linux/proc_fs.h>
25043  #include <linux/seq_file.h>
25044  #include <linux/export.h>
25045 +#include <linux/vs_network.h>
25046 +#include <linux/vs_inet6.h>
25047  
25048  /* Set to 3 to get tracing... */
25049  #define ACONF_DEBUG 2
25050 @@ -1321,7 +1323,7 @@ out:
25051  
25052  int ipv6_dev_get_saddr(struct net *net, const struct net_device *dst_dev,
25053                        const struct in6_addr *daddr, unsigned int prefs,
25054 -                      struct in6_addr *saddr)
25055 +                      struct in6_addr *saddr, struct nx_info *nxi)
25056  {
25057         struct ipv6_saddr_score scores[2],
25058                                 *score = &scores[0], *hiscore = &scores[1];
25059 @@ -1393,6 +1395,8 @@ int ipv6_dev_get_saddr(struct net *net,
25060                                                dev->name);
25061                                 continue;
25062                         }
25063 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
25064 +                               continue;
25065  
25066                         score->rule = -1;
25067                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
25068 @@ -3448,7 +3452,10 @@ static void if6_seq_stop(struct seq_file
25069  static int if6_seq_show(struct seq_file *seq, void *v)
25070  {
25071         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
25072 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25073 +
25074 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
25075 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
25076 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25077                    &ifp->addr,
25078                    ifp->idev->dev->ifindex,
25079                    ifp->prefix_len,
25080 @@ -3952,6 +3959,11 @@ static int in6_dump_addrs(struct inet6_d
25081         struct ifacaddr6 *ifaca;
25082         int err = 1;
25083         int ip_idx = *p_ip_idx;
25084 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25085 +
25086 +       /* disable ipv6 on non v6 guests */
25087 +       if (nxi && !nx_info_has_v6(nxi))
25088 +               return skb->len;
25089  
25090         read_lock_bh(&idev->lock);
25091         switch (type) {
25092 @@ -3962,6 +3974,8 @@ static int in6_dump_addrs(struct inet6_d
25093                 list_for_each_entry(ifa, &idev->addr_list, if_list) {
25094                         if (++ip_idx < s_ip_idx)
25095                                 continue;
25096 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
25097 +                                       continue;
25098                         err = inet6_fill_ifaddr(skb, ifa,
25099                                                 NETLINK_CB(cb->skb).portid,
25100                                                 cb->nlh->nlmsg_seq,
25101 @@ -3979,6 +3993,8 @@ static int in6_dump_addrs(struct inet6_d
25102                      ifmca = ifmca->next, ip_idx++) {
25103                         if (ip_idx < s_ip_idx)
25104                                 continue;
25105 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
25106 +                                       continue;
25107                         err = inet6_fill_ifmcaddr(skb, ifmca,
25108                                                   NETLINK_CB(cb->skb).portid,
25109                                                   cb->nlh->nlmsg_seq,
25110 @@ -3994,6 +4010,8 @@ static int in6_dump_addrs(struct inet6_d
25111                      ifaca = ifaca->aca_next, ip_idx++) {
25112                         if (ip_idx < s_ip_idx)
25113                                 continue;
25114 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
25115 +                                       continue;
25116                         err = inet6_fill_ifacaddr(skb, ifaca,
25117                                                   NETLINK_CB(cb->skb).portid,
25118                                                   cb->nlh->nlmsg_seq,
25119 @@ -4022,6 +4040,10 @@ static int inet6_dump_addr(struct sk_buf
25120         struct inet6_dev *idev;
25121         struct hlist_head *head;
25122  
25123 +       /* FIXME: maybe disable ipv6 on non v6 guests?
25124 +       if (skb->sk && skb->sk->sk_vx_info)
25125 +               return skb->len; */
25126 +
25127         s_h = cb->args[0];
25128         s_idx = idx = cb->args[1];
25129         s_ip_idx = ip_idx = cb->args[2];
25130 @@ -4457,6 +4479,7 @@ static int inet6_dump_ifinfo(struct sk_b
25131         struct net_device *dev;
25132         struct inet6_dev *idev;
25133         struct hlist_head *head;
25134 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25135  
25136         s_h = cb->args[0];
25137         s_idx = cb->args[1];
25138 @@ -4468,6 +4491,8 @@ static int inet6_dump_ifinfo(struct sk_b
25139                 hlist_for_each_entry_rcu(dev, head, index_hlist) {
25140                         if (idx < s_idx)
25141                                 goto cont;
25142 +                       if (!v6_dev_in_nx_info(dev, nxi))
25143 +                               goto cont;
25144                         idev = __in6_dev_get(dev);
25145                         if (!idev)
25146                                 goto cont;
25147 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
25148 --- linux-3.10.33/net/ipv6/af_inet6.c   2013-07-14 17:01:38.000000000 +0000
25149 +++ linux-3.10.33-vs2.3.6.8/net/ipv6/af_inet6.c 2013-08-22 20:30:00.000000000 +0000
25150 @@ -43,6 +43,8 @@
25151  #include <linux/netdevice.h>
25152  #include <linux/icmpv6.h>
25153  #include <linux/netfilter_ipv6.h>
25154 +#include <linux/vs_inet.h>
25155 +#include <linux/vs_inet6.h>
25156  
25157  #include <net/ip.h>
25158  #include <net/ipv6.h>
25159 @@ -159,10 +161,13 @@ lookup_protocol:
25160         }
25161  
25162         err = -EPERM;
25163 +       if ((protocol == IPPROTO_ICMPV6) &&
25164 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
25165 +               goto override;
25166         if (sock->type == SOCK_RAW && !kern &&
25167             !ns_capable(net->user_ns, CAP_NET_RAW))
25168                 goto out_rcu_unlock;
25169 -
25170 +override:
25171         sock->ops = answer->ops;
25172         answer_prot = answer->prot;
25173         answer_no_check = answer->no_check;
25174 @@ -262,6 +267,7 @@ int inet6_bind(struct socket *sock, stru
25175         struct inet_sock *inet = inet_sk(sk);
25176         struct ipv6_pinfo *np = inet6_sk(sk);
25177         struct net *net = sock_net(sk);
25178 +       struct nx_v6_sock_addr nsa;
25179         __be32 v4addr = 0;
25180         unsigned short snum;
25181         int addr_type = 0;
25182 @@ -277,6 +283,10 @@ int inet6_bind(struct socket *sock, stru
25183         if (addr->sin6_family != AF_INET6)
25184                 return -EAFNOSUPPORT;
25185  
25186 +       err = v6_map_sock_addr(inet, addr, &nsa);
25187 +       if (err)
25188 +               return err;
25189 +
25190         addr_type = ipv6_addr_type(&addr->sin6_addr);
25191         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
25192                 return -EINVAL;
25193 @@ -308,6 +318,7 @@ int inet6_bind(struct socket *sock, stru
25194                 /* Reproduce AF_INET checks to make the bindings consistent */
25195                 v4addr = addr->sin6_addr.s6_addr32[3];
25196                 chk_addr_ret = inet_addr_type(net, v4addr);
25197 +
25198                 if (!sysctl_ip_nonlocal_bind &&
25199                     !(inet->freebind || inet->transparent) &&
25200                     v4addr != htonl(INADDR_ANY) &&
25201 @@ -317,6 +328,10 @@ int inet6_bind(struct socket *sock, stru
25202                         err = -EADDRNOTAVAIL;
25203                         goto out;
25204                 }
25205 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
25206 +                       err = -EADDRNOTAVAIL;
25207 +                       goto out;
25208 +               }
25209         } else {
25210                 if (addr_type != IPV6_ADDR_ANY) {
25211                         struct net_device *dev = NULL;
25212 @@ -343,6 +358,11 @@ int inet6_bind(struct socket *sock, stru
25213                                 }
25214                         }
25215  
25216 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25217 +                               err = -EADDRNOTAVAIL;
25218 +                               goto out_unlock;
25219 +                       }
25220 +
25221                         /* ipv4 addr of the socket is invalid.  Only the
25222                          * unspecified and mapped address have a v4 equivalent.
25223                          */
25224 @@ -359,6 +379,9 @@ int inet6_bind(struct socket *sock, stru
25225                 }
25226         }
25227  
25228 +       /* what's that for? */
25229 +       v6_set_sock_addr(inet, &nsa);
25230 +
25231         inet->inet_rcv_saddr = v4addr;
25232         inet->inet_saddr = v4addr;
25233  
25234 @@ -460,9 +483,11 @@ int inet6_getname(struct socket *sock, s
25235                         return -ENOTCONN;
25236                 sin->sin6_port = inet->inet_dport;
25237                 sin->sin6_addr = np->daddr;
25238 +               /* FIXME: remap lback? */
25239                 if (np->sndflow)
25240                         sin->sin6_flowinfo = np->flow_label;
25241         } else {
25242 +               /* FIXME: remap lback? */
25243                 if (ipv6_addr_any(&np->rcv_saddr))
25244                         sin->sin6_addr = np->saddr;
25245                 else
25246 diff -NurpP --minimal linux-3.10.33/net/ipv6/datagram.c linux-3.10.33-vs2.3.6.8/net/ipv6/datagram.c
25247 --- linux-3.10.33/net/ipv6/datagram.c   2014-03-12 13:16:02.000000000 +0000
25248 +++ linux-3.10.33-vs2.3.6.8/net/ipv6/datagram.c 2013-12-23 17:42:40.000000000 +0000
25249 @@ -656,7 +656,7 @@ int ip6_datagram_send_ctl(struct net *ne
25250  
25251                         rcu_read_lock();
25252                         if (fl6->flowi6_oif) {
25253 -                               dev = dev_get_by_index_rcu(net, fl6->flowi6_oif);
25254 +                               dev = dev_get_by_index_real_rcu(net, fl6->flowi6_oif);
25255                                 if (!dev) {
25256                                         rcu_read_unlock();
25257                                         return -ENODEV;
25258 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
25259 --- linux-3.10.33/net/ipv6/fib6_rules.c 2013-02-19 13:58:58.000000000 +0000
25260 +++ linux-3.10.33-vs2.3.6.8/net/ipv6/fib6_rules.c       2013-08-22 20:30:00.000000000 +0000
25261 @@ -90,7 +90,7 @@ static int fib6_rule_action(struct fib_r
25262                                                ip6_dst_idev(&rt->dst)->dev,
25263                                                &flp6->daddr,
25264                                                rt6_flags2srcprefs(flags),
25265 -                                              &saddr))
25266 +                                              &saddr, NULL))
25267                                 goto again;
25268                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
25269                                                r->src.plen))
25270 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
25271 --- linux-3.10.33/net/ipv6/inet6_hashtables.c   2014-03-12 13:16:02.000000000 +0000
25272 +++ linux-3.10.33-vs2.3.6.8/net/ipv6/inet6_hashtables.c 2013-11-13 17:22:25.000000000 +0000
25273 @@ -16,6 +16,7 @@
25274  
25275  #include <linux/module.h>
25276  #include <linux/random.h>
25277 +#include <linux/vs_inet6.h>
25278  
25279  #include <net/inet_connection_sock.h>
25280  #include <net/inet_hashtables.h>
25281 @@ -83,7 +84,6 @@ struct sock *__inet6_lookup_established(
25282         unsigned int slot = hash & hashinfo->ehash_mask;
25283         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
25284  
25285 -
25286         rcu_read_lock();
25287  begin:
25288         sk_nulls_for_each_rcu(sk, node, &head->chain) {
25289 @@ -97,7 +97,7 @@ begin:
25290                                 sock_put(sk);
25291                                 goto begin;
25292                         }
25293 -               goto out;
25294 +                       goto out;
25295                 }
25296         }
25297         if (get_nulls_value(node) != slot)
25298 @@ -147,6 +147,9 @@ static inline int compute_score(struct s
25299                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25300                                 return -1;
25301                         score++;
25302 +               } else {
25303 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25304 +                               return -1;
25305                 }
25306                 if (sk->sk_bound_dev_if) {
25307                         if (sk->sk_bound_dev_if != dif)
25308 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
25309 --- linux-3.10.33/net/ipv6/ip6_output.c 2014-03-12 13:16:02.000000000 +0000
25310 +++ linux-3.10.33-vs2.3.6.8/net/ipv6/ip6_output.c       2014-03-12 13:18:33.000000000 +0000
25311 @@ -896,7 +896,8 @@ static int ip6_dst_lookup_tail(struct so
25312                 struct rt6_info *rt = (struct rt6_info *) *dst;
25313                 err = ip6_route_get_saddr(net, rt, &fl6->daddr,
25314                                           sk ? inet6_sk(sk)->srcprefs : 0,
25315 -                                         &fl6->saddr);
25316 +                                         &fl6->saddr,
25317 +                                         sk ? sk->sk_nx_info : NULL);
25318                 if (err)
25319                         goto out_err_release;
25320         }
25321 diff -NurpP --minimal linux-3.10.33/net/ipv6/ndisc.c linux-3.10.33-vs2.3.6.8/net/ipv6/ndisc.c
25322 --- linux-3.10.33/net/ipv6/ndisc.c      2014-03-12 13:16:02.000000000 +0000
25323 +++ linux-3.10.33-vs2.3.6.8/net/ipv6/ndisc.c    2013-11-13 17:17:16.000000000 +0000
25324 @@ -487,7 +487,7 @@ static void ndisc_send_na(struct net_dev
25325         } else {
25326                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
25327                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
25328 -                                      &tmpaddr))
25329 +                                      &tmpaddr, NULL))
25330                         return;
25331                 src_addr = &tmpaddr;
25332         }
25333 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
25334 --- linux-3.10.33/net/ipv6/netfilter/ip6t_MASQUERADE.c  2012-12-11 03:30:57.000000000 +0000
25335 +++ linux-3.10.33-vs2.3.6.8/net/ipv6/netfilter/ip6t_MASQUERADE.c        2013-08-22 20:30:00.000000000 +0000
25336 @@ -34,7 +34,7 @@ masquerade_tg6(struct sk_buff *skb, cons
25337                             ctinfo == IP_CT_RELATED_REPLY));
25338  
25339         if (ipv6_dev_get_saddr(dev_net(par->out), par->out,
25340 -                              &ipv6_hdr(skb)->daddr, 0, &src) < 0)
25341 +                              &ipv6_hdr(skb)->daddr, 0, &src, NULL) < 0)
25342                 return NF_DROP;
25343  
25344         nfct_nat(ct)->masq_index = par->out->ifindex;
25345 diff -NurpP --minimal linux-3.10.33/net/ipv6/raw.c linux-3.10.33-vs2.3.6.8/net/ipv6/raw.c
25346 --- linux-3.10.33/net/ipv6/raw.c        2014-03-12 13:16:02.000000000 +0000
25347 +++ linux-3.10.33-vs2.3.6.8/net/ipv6/raw.c      2013-12-23 17:42:40.000000000 +0000
25348 @@ -30,6 +30,7 @@
25349  #include <linux/icmpv6.h>
25350  #include <linux/netfilter.h>
25351  #include <linux/netfilter_ipv6.h>
25352 +#include <linux/vs_inet6.h>
25353  #include <linux/skbuff.h>
25354  #include <linux/compat.h>
25355  #include <asm/uaccess.h>
25356 @@ -283,6 +284,13 @@ static int rawv6_bind(struct sock *sk, s
25357                                 goto out_unlock;
25358                 }
25359  
25360 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25361 +                       err = -EADDRNOTAVAIL;
25362 +                       if (dev)
25363 +                               dev_put(dev);
25364 +                       goto out;
25365 +               }
25366 +
25367                 /* ipv4 addr of the socket is invalid.  Only the
25368                  * unspecified and mapped address have a v4 equivalent.
25369                  */
25370 diff -NurpP --minimal linux-3.10.33/net/ipv6/route.c linux-3.10.33-vs2.3.6.8/net/ipv6/route.c
25371 --- linux-3.10.33/net/ipv6/route.c      2014-03-12 13:16:02.000000000 +0000
25372 +++ linux-3.10.33-vs2.3.6.8/net/ipv6/route.c    2014-01-22 19:00:34.000000000 +0000
25373 @@ -58,6 +58,7 @@
25374  #include <net/netevent.h>
25375  #include <net/netlink.h>
25376  #include <net/nexthop.h>
25377 +#include <linux/vs_inet6.h>
25378  
25379  #include <asm/uaccess.h>
25380  
25381 @@ -2129,15 +2130,17 @@ int ip6_route_get_saddr(struct net *net,
25382                         struct rt6_info *rt,
25383                         const struct in6_addr *daddr,
25384                         unsigned int prefs,
25385 -                       struct in6_addr *saddr)
25386 +                       struct in6_addr *saddr,
25387 +                       struct nx_info *nxi)
25388  {
25389         struct inet6_dev *idev = ip6_dst_idev((struct dst_entry*)rt);
25390         int err = 0;
25391 -       if (rt->rt6i_prefsrc.plen)
25392 +       if (rt->rt6i_prefsrc.plen && (!nxi ||
25393 +           v6_addr_in_nx_info(nxi, &rt->rt6i_prefsrc.addr, NXA_TYPE_ADDR)))
25394                 *saddr = rt->rt6i_prefsrc.addr;
25395         else
25396                 err = ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
25397 -                                        daddr, prefs, saddr);
25398 +                                        daddr, prefs, saddr, nxi);
25399         return err;
25400  }
25401  
25402 @@ -2557,7 +2560,8 @@ static int rt6_fill_node(struct net *net
25403                                 goto nla_put_failure;
25404         } else if (dst) {
25405                 struct in6_addr saddr_buf;
25406 -               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf) == 0 &&
25407 +               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf,
25408 +                   (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0 &&
25409                     nla_put(skb, RTA_PREFSRC, 16, &saddr_buf))
25410                         goto nla_put_failure;
25411         }
25412 @@ -2769,6 +2773,7 @@ static int rt6_info_route(struct rt6_inf
25413  {
25414         struct seq_file *m = p_arg;
25415  
25416 +       /* FIXME: check for network context? */
25417         seq_printf(m, "%pi6 %02x ", &rt->rt6i_dst.addr, rt->rt6i_dst.plen);
25418  
25419  #ifdef CONFIG_IPV6_SUBTREES
25420 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
25421 --- linux-3.10.33/net/ipv6/tcp_ipv6.c   2014-03-12 13:16:02.000000000 +0000
25422 +++ linux-3.10.33-vs2.3.6.8/net/ipv6/tcp_ipv6.c 2013-11-13 17:17:16.000000000 +0000
25423 @@ -71,6 +71,7 @@
25424  
25425  #include <linux/crypto.h>
25426  #include <linux/scatterlist.h>
25427 +#include <linux/vs_inet6.h>
25428  
25429  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
25430  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
25431 @@ -164,8 +165,15 @@ static int tcp_v6_connect(struct sock *s
25432          *      connect() to INADDR_ANY means loopback (BSD'ism).
25433          */
25434  
25435 -       if(ipv6_addr_any(&usin->sin6_addr))
25436 -               usin->sin6_addr.s6_addr[15] = 0x1;
25437 +       if(ipv6_addr_any(&usin->sin6_addr)) {
25438 +               struct nx_info *nxi =  sk->sk_nx_info;
25439 +
25440 +               if (nxi && nx_info_has_v6(nxi))
25441 +                       /* FIXME: remap lback? */
25442 +                       usin->sin6_addr = nxi->v6.ip;
25443 +               else
25444 +                       usin->sin6_addr.s6_addr[15] = 0x1;
25445 +       }
25446  
25447         addr_type = ipv6_addr_type(&usin->sin6_addr);
25448  
25449 diff -NurpP --minimal linux-3.10.33/net/ipv6/udp.c linux-3.10.33-vs2.3.6.8/net/ipv6/udp.c
25450 --- linux-3.10.33/net/ipv6/udp.c        2014-03-12 13:16:02.000000000 +0000
25451 +++ linux-3.10.33-vs2.3.6.8/net/ipv6/udp.c      2013-12-23 17:42:40.000000000 +0000
25452 @@ -46,42 +46,68 @@
25453  #include <net/ip6_checksum.h>
25454  #include <net/xfrm.h>
25455  #include <net/inet6_hashtables.h>
25456 +#include <linux/vs_inet6.h>
25457  
25458  #include <linux/proc_fs.h>
25459  #include <linux/seq_file.h>
25460  #include <trace/events/skb.h>
25461  #include "udp_impl.h"
25462  
25463 -int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
25464 +int ipv6_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25465  {
25466 -       const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
25467 +       const struct in6_addr *sk1_rcv_saddr6 = &inet6_sk(sk1)->rcv_saddr;
25468         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
25469 -       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk);
25470 +       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk1);
25471         __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
25472 -       int sk_ipv6only = ipv6_only_sock(sk);
25473 +       int sk1_ipv6only = ipv6_only_sock(sk1);
25474         int sk2_ipv6only = inet_v6_ipv6only(sk2);
25475 -       int addr_type = ipv6_addr_type(sk_rcv_saddr6);
25476 +       int addr_type = ipv6_addr_type(sk1_rcv_saddr6);
25477         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
25478  
25479         /* if both are mapped, treat as IPv4 */
25480 -       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
25481 -               return (!sk2_ipv6only &&
25482 +       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
25483 +               if (!sk2_ipv6only &&
25484                         (!sk1_rcv_saddr || !sk2_rcv_saddr ||
25485 -                         sk1_rcv_saddr == sk2_rcv_saddr));
25486 +                         sk1_rcv_saddr == sk2_rcv_saddr))
25487 +                       goto vs_v4;
25488 +               else
25489 +                       return 0;
25490 +       }
25491  
25492         if (addr_type2 == IPV6_ADDR_ANY &&
25493             !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
25494 -               return 1;
25495 +               goto vs;
25496  
25497         if (addr_type == IPV6_ADDR_ANY &&
25498 -           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
25499 -               return 1;
25500 +           !(sk1_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
25501 +               goto vs;
25502  
25503         if (sk2_rcv_saddr6 &&
25504 -           ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
25505 -               return 1;
25506 +           ipv6_addr_equal(sk1_rcv_saddr6, sk2_rcv_saddr6))
25507 +               goto vs;
25508  
25509         return 0;
25510 +
25511 +vs_v4:
25512 +       if (!sk1_rcv_saddr && !sk2_rcv_saddr)
25513 +               return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25514 +       if (!sk2_rcv_saddr)
25515 +               return v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, -1);
25516 +       if (!sk1_rcv_saddr)
25517 +               return v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, -1);
25518 +       return 1;
25519 +vs:
25520 +       if (addr_type2 == IPV6_ADDR_ANY && addr_type == IPV6_ADDR_ANY)
25521 +               return nx_v6_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25522 +       else if (addr_type2 == IPV6_ADDR_ANY)
25523 +               return v6_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr6, -1);
25524 +       else if (addr_type == IPV6_ADDR_ANY) {
25525 +               if (addr_type2 == IPV6_ADDR_MAPPED)
25526 +                       return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25527 +               else
25528 +                       return v6_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr6, -1);
25529 +       }
25530 +       return 1;
25531  }
25532  
25533  static unsigned int udp6_portaddr_hash(struct net *net,
25534 @@ -145,6 +171,10 @@ static inline int compute_score(struct s
25535                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25536                                 return -1;
25537                         score++;
25538 +               } else {
25539 +                       /* block non nx_info ips */
25540 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25541 +                               return -1;
25542                 }
25543                 if (!ipv6_addr_any(&np->daddr)) {
25544                         if (!ipv6_addr_equal(&np->daddr, saddr))
25545 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
25546 --- linux-3.10.33/net/ipv6/xfrm6_policy.c       2013-07-14 17:01:38.000000000 +0000
25547 +++ linux-3.10.33-vs2.3.6.8/net/ipv6/xfrm6_policy.c     2013-08-22 20:30:00.000000000 +0000
25548 @@ -63,7 +63,7 @@ static int xfrm6_get_saddr(struct net *n
25549         dev = ip6_dst_idev(dst)->dev;
25550         ipv6_dev_get_saddr(dev_net(dev), dev,
25551                            (struct in6_addr *)&daddr->a6, 0,
25552 -                          (struct in6_addr *)&saddr->a6);
25553 +                          (struct in6_addr *)&saddr->a6, NULL);
25554         dst_release(dst);
25555         return 0;
25556  }
25557 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
25558 --- linux-3.10.33/net/netfilter/ipvs/ip_vs_xmit.c       2014-03-12 13:16:02.000000000 +0000
25559 +++ linux-3.10.33-vs2.3.6.8/net/netfilter/ipvs/ip_vs_xmit.c     2013-11-13 17:17:16.000000000 +0000
25560 @@ -316,7 +316,7 @@ __ip_vs_route_output_v6(struct net *net,
25561                 return dst;
25562         if (ipv6_addr_any(&fl6.saddr) &&
25563             ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
25564 -                              &fl6.daddr, 0, &fl6.saddr) < 0)
25565 +                              &fl6.daddr, 0, &fl6.saddr, NULL) < 0)
25566                 goto out_err;
25567         if (do_xfrm) {
25568                 dst = xfrm_lookup(net, dst, flowi6_to_flowi(&fl6), NULL, 0);
25569 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
25570 --- linux-3.10.33/net/netlink/af_netlink.c      2014-03-12 13:16:02.000000000 +0000
25571 +++ linux-3.10.33-vs2.3.6.8/net/netlink/af_netlink.c    2013-12-23 17:42:40.000000000 +0000
25572 @@ -57,6 +57,9 @@
25573  #include <linux/audit.h>
25574  #include <linux/mutex.h>
25575  #include <linux/vmalloc.h>
25576 +#include <linux/vs_context.h>
25577 +#include <linux/vs_network.h>
25578 +#include <linux/vs_limit.h>
25579  #include <asm/cacheflush.h>
25580  
25581  #include <net/net_namespace.h>
25582 @@ -2682,6 +2685,8 @@ static struct sock *netlink_seq_socket_i
25583                         sk_for_each(s, &hash->table[j]) {
25584                                 if (sock_net(s) != seq_file_net(seq))
25585                                         continue;
25586 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25587 +                                       continue;
25588                                 if (off == pos) {
25589                                         iter->link = i;
25590                                         iter->hash_idx = j;
25591 @@ -2716,7 +2721,8 @@ static void *netlink_seq_next(struct seq
25592         s = v;
25593         do {
25594                 s = sk_next(s);
25595 -       } while (s && sock_net(s) != seq_file_net(seq));
25596 +       } while (s && (sock_net(s) != seq_file_net(seq) ||
25597 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
25598         if (s)
25599                 return s;
25600  
25601 @@ -2728,7 +2734,8 @@ static void *netlink_seq_next(struct seq
25602  
25603                 for (; j <= hash->mask; j++) {
25604                         s = sk_head(&hash->table[j]);
25605 -                       while (s && sock_net(s) != seq_file_net(seq))
25606 +                       while (s && (sock_net(s) != seq_file_net(seq) ||
25607 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
25608                                 s = sk_next(s);
25609                         if (s) {
25610                                 iter->link = i;
25611 diff -NurpP --minimal linux-3.10.33/net/socket.c linux-3.10.33-vs2.3.6.8/net/socket.c
25612 --- linux-3.10.33/net/socket.c  2014-03-12 13:16:02.000000000 +0000
25613 +++ linux-3.10.33-vs2.3.6.8/net/socket.c        2013-12-23 17:42:40.000000000 +0000
25614 @@ -98,6 +98,10 @@
25615  
25616  #include <net/sock.h>
25617  #include <linux/netfilter.h>
25618 +#include <linux/vs_base.h>
25619 +#include <linux/vs_socket.h>
25620 +#include <linux/vs_inet.h>
25621 +#include <linux/vs_inet6.h>
25622  
25623  #include <linux/if_tun.h>
25624  #include <linux/ipv6_route.h>
25625 @@ -617,13 +621,29 @@ static inline int __sock_sendmsg_nosec(s
25626                                        struct msghdr *msg, size_t size)
25627  {
25628         struct sock_iocb *si = kiocb_to_siocb(iocb);
25629 +       size_t len;
25630  
25631         si->sock = sock;
25632         si->scm = NULL;
25633         si->msg = msg;
25634         si->size = size;
25635  
25636 -       return sock->ops->sendmsg(iocb, sock, msg, size);
25637 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
25638 +       if (sock->sk) {
25639 +               if (len == size)
25640 +                       vx_sock_send(sock->sk, size);
25641 +               else
25642 +                       vx_sock_fail(sock->sk, size);
25643 +       }
25644 +       vxdprintk(VXD_CBIT(net, 7),
25645 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%zu",
25646 +               sock, sock->sk,
25647 +               (sock->sk)?sock->sk->sk_nx_info:0,
25648 +               (sock->sk)?sock->sk->sk_vx_info:0,
25649 +               (sock->sk)?sock->sk->sk_xid:0,
25650 +               (sock->sk)?sock->sk->sk_nid:0,
25651 +               (unsigned int)size, len);
25652 +       return len;
25653  }
25654  
25655  static inline int __sock_sendmsg(struct kiocb *iocb, struct socket *sock,
25656 @@ -767,6 +787,7 @@ static inline int __sock_recvmsg_nosec(s
25657                                        struct msghdr *msg, size_t size, int flags)
25658  {
25659         struct sock_iocb *si = kiocb_to_siocb(iocb);
25660 +       int len;
25661  
25662         si->sock = sock;
25663         si->scm = NULL;
25664 @@ -774,7 +795,18 @@ static inline int __sock_recvmsg_nosec(s
25665         si->size = size;
25666         si->flags = flags;
25667  
25668 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
25669 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
25670 +       if ((len >= 0) && sock->sk)
25671 +               vx_sock_recv(sock->sk, len);
25672 +       vxdprintk(VXD_CBIT(net, 7),
25673 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
25674 +               sock, sock->sk,
25675 +               (sock->sk)?sock->sk->sk_nx_info:0,
25676 +               (sock->sk)?sock->sk->sk_vx_info:0,
25677 +               (sock->sk)?sock->sk->sk_xid:0,
25678 +               (sock->sk)?sock->sk->sk_nid:0,
25679 +               (unsigned int)size, len);
25680 +       return len;
25681  }
25682  
25683  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
25684 @@ -1248,6 +1280,13 @@ int __sock_create(struct net *net, int f
25685         if (type < 0 || type >= SOCK_MAX)
25686                 return -EINVAL;
25687  
25688 +       if (!nx_check(0, VS_ADMIN)) {
25689 +               if (family == PF_INET && !current_nx_info_has_v4())
25690 +                       return -EAFNOSUPPORT;
25691 +               if (family == PF_INET6 && !current_nx_info_has_v6())
25692 +                       return -EAFNOSUPPORT;
25693 +       }
25694 +
25695         /* Compatibility.
25696  
25697            This uglymoron is moved from INET layer to here to avoid
25698 @@ -1382,6 +1421,7 @@ SYSCALL_DEFINE3(socket, int, family, int
25699         if (retval < 0)
25700                 goto out;
25701  
25702 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
25703         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
25704         if (retval < 0)
25705                 goto out_release;
25706 @@ -1423,10 +1463,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
25707         err = sock_create(family, type, protocol, &sock1);
25708         if (err < 0)
25709                 goto out;
25710 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
25711  
25712         err = sock_create(family, type, protocol, &sock2);
25713         if (err < 0)
25714                 goto out_release_1;
25715 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
25716  
25717         err = sock1->ops->socketpair(sock1, sock2);
25718         if (err < 0)
25719 diff -NurpP --minimal linux-3.10.33/net/sunrpc/auth.c linux-3.10.33-vs2.3.6.8/net/sunrpc/auth.c
25720 --- linux-3.10.33/net/sunrpc/auth.c     2013-07-14 17:01:39.000000000 +0000
25721 +++ linux-3.10.33-vs2.3.6.8/net/sunrpc/auth.c   2013-08-22 20:30:00.000000000 +0000
25722 @@ -15,6 +15,7 @@
25723  #include <linux/sunrpc/clnt.h>
25724  #include <linux/sunrpc/gss_api.h>
25725  #include <linux/spinlock.h>
25726 +#include <linux/vs_tag.h>
25727  
25728  #ifdef RPC_DEBUG
25729  # define RPCDBG_FACILITY       RPCDBG_AUTH
25730 @@ -553,6 +554,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
25731         memset(&acred, 0, sizeof(acred));
25732         acred.uid = cred->fsuid;
25733         acred.gid = cred->fsgid;
25734 +       acred.tag = make_ktag(&init_user_ns, dx_current_tag());
25735         acred.group_info = get_group_info(((struct cred *)cred)->group_info);
25736  
25737         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
25738 @@ -593,6 +595,7 @@ rpcauth_bind_root_cred(struct rpc_task *
25739         struct auth_cred acred = {
25740                 .uid = GLOBAL_ROOT_UID,
25741                 .gid = GLOBAL_ROOT_GID,
25742 +               .tag = KTAGT_INIT(dx_current_tag()),
25743         };
25744  
25745         dprintk("RPC: %5u looking up %s cred\n",
25746 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
25747 --- linux-3.10.33/net/sunrpc/auth_unix.c        2013-05-31 13:45:33.000000000 +0000
25748 +++ linux-3.10.33-vs2.3.6.8/net/sunrpc/auth_unix.c      2013-08-22 20:30:00.000000000 +0000
25749 @@ -13,11 +13,13 @@
25750  #include <linux/sunrpc/clnt.h>
25751  #include <linux/sunrpc/auth.h>
25752  #include <linux/user_namespace.h>
25753 +#include <linux/vs_tag.h>
25754  
25755  #define NFS_NGROUPS    16
25756  
25757  struct unx_cred {
25758         struct rpc_cred         uc_base;
25759 +       ktag_t                  uc_tag;
25760         kgid_t                  uc_gid;
25761         kgid_t                  uc_gids[NFS_NGROUPS];
25762  };
25763 @@ -80,6 +82,7 @@ unx_create_cred(struct rpc_auth *auth, s
25764                 groups = NFS_NGROUPS;
25765  
25766         cred->uc_gid = acred->gid;
25767 +       cred->uc_tag = acred->tag;
25768         for (i = 0; i < groups; i++)
25769                 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
25770         if (i < NFS_NGROUPS)
25771 @@ -121,7 +124,9 @@ unx_match(struct auth_cred *acred, struc
25772         unsigned int i;
25773  
25774  
25775 -       if (!uid_eq(cred->uc_uid, acred->uid) || !gid_eq(cred->uc_gid, acred->gid))
25776 +       if (!uid_eq(cred->uc_uid, acred->uid) ||
25777 +           !gid_eq(cred->uc_gid, acred->gid) ||
25778 +           !tag_eq(cred->uc_tag, acred->tag))
25779                 return 0;
25780  
25781         if (acred->group_info != NULL)
25782 @@ -146,7 +151,7 @@ unx_marshal(struct rpc_task *task, __be3
25783         struct rpc_clnt *clnt = task->tk_client;
25784         struct unx_cred *cred = container_of(task->tk_rqstp->rq_cred, struct unx_cred, uc_base);
25785         __be32          *base, *hold;
25786 -       int             i;
25787 +       int             i, tag;
25788  
25789         *p++ = htonl(RPC_AUTH_UNIX);
25790         base = p++;
25791 @@ -157,8 +162,11 @@ unx_marshal(struct rpc_task *task, __be3
25792          */
25793         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
25794  
25795 -       *p++ = htonl((u32) from_kuid(&init_user_ns, cred->uc_uid));
25796 -       *p++ = htonl((u32) from_kgid(&init_user_ns, cred->uc_gid));
25797 +       tag = task->tk_client->cl_tag;
25798 +       *p++ = htonl((u32) from_kuid(&init_user_ns,
25799 +               TAGINO_KUID(tag, cred->uc_uid, cred->uc_tag)));
25800 +       *p++ = htonl((u32) from_kgid(&init_user_ns,
25801 +               TAGINO_KGID(tag, cred->uc_gid, cred->uc_tag)));
25802         hold = p++;
25803         for (i = 0; i < 16 && gid_valid(cred->uc_gids[i]); i++)
25804                 *p++ = htonl((u32) from_kgid(&init_user_ns, cred->uc_gids[i]));
25805 diff -NurpP --minimal linux-3.10.33/net/sunrpc/clnt.c linux-3.10.33-vs2.3.6.8/net/sunrpc/clnt.c
25806 --- linux-3.10.33/net/sunrpc/clnt.c     2014-03-12 13:16:02.000000000 +0000
25807 +++ linux-3.10.33-vs2.3.6.8/net/sunrpc/clnt.c   2014-03-12 13:18:24.000000000 +0000
25808 @@ -31,6 +31,7 @@
25809  #include <linux/in6.h>
25810  #include <linux/un.h>
25811  #include <linux/rcupdate.h>
25812 +#include <linux/vs_cvirt.h>
25813  
25814  #include <linux/sunrpc/clnt.h>
25815  #include <linux/sunrpc/addr.h>
25816 @@ -486,6 +487,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
25817         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
25818                 clnt->cl_chatty = 1;
25819  
25820 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
25821 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
25822 +               clnt->cl_tag = 1; */
25823         return clnt;
25824  }
25825  EXPORT_SYMBOL_GPL(rpc_create);
25826 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
25827 --- linux-3.10.33/net/unix/af_unix.c    2014-03-12 13:16:02.000000000 +0000
25828 +++ linux-3.10.33-vs2.3.6.8/net/unix/af_unix.c  2014-01-22 19:00:34.000000000 +0000
25829 @@ -114,6 +114,8 @@
25830  #include <linux/mount.h>
25831  #include <net/checksum.h>
25832  #include <linux/security.h>
25833 +#include <linux/vs_context.h>
25834 +#include <linux/vs_limit.h>
25835  
25836  struct hlist_head unix_socket_table[2 * UNIX_HASH_SIZE];
25837  EXPORT_SYMBOL_GPL(unix_socket_table);
25838 @@ -270,6 +272,8 @@ static struct sock *__unix_find_socket_b
25839                 if (!net_eq(sock_net(s), net))
25840                         continue;
25841  
25842 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25843 +                       continue;
25844                 if (u->addr->len == len &&
25845                     !memcmp(u->addr->name, sunname, len))
25846                         goto found;
25847 @@ -2270,6 +2274,8 @@ static struct sock *unix_from_bucket(str
25848         for (sk = sk_head(&unix_socket_table[bucket]); sk; sk = sk_next(sk)) {
25849                 if (sock_net(sk) != seq_file_net(seq))
25850                         continue;
25851 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25852 +                       continue;
25853                 if (++count == offset)
25854                         break;
25855         }
25856 @@ -2287,6 +2293,8 @@ static struct sock *unix_next_socket(str
25857                 sk = sk_next(sk);
25858                 if (!sk)
25859                         goto next_bucket;
25860 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25861 +                       continue;
25862                 if (sock_net(sk) == seq_file_net(seq))
25863                         return sk;
25864         }
25865 diff -NurpP --minimal linux-3.10.33/scripts/checksyscalls.sh linux-3.10.33-vs2.3.6.8/scripts/checksyscalls.sh
25866 --- linux-3.10.33/scripts/checksyscalls.sh      2012-12-11 03:30:57.000000000 +0000
25867 +++ linux-3.10.33-vs2.3.6.8/scripts/checksyscalls.sh    2013-08-22 20:30:00.000000000 +0000
25868 @@ -193,7 +193,6 @@ cat << EOF
25869  #define __IGNORE_afs_syscall
25870  #define __IGNORE_getpmsg
25871  #define __IGNORE_putpmsg
25872 -#define __IGNORE_vserver
25873  EOF
25874  }
25875  
25876 diff -NurpP --minimal linux-3.10.33/security/commoncap.c linux-3.10.33-vs2.3.6.8/security/commoncap.c
25877 --- linux-3.10.33/security/commoncap.c  2013-05-31 13:45:34.000000000 +0000
25878 +++ linux-3.10.33-vs2.3.6.8/security/commoncap.c        2013-08-22 20:30:00.000000000 +0000
25879 @@ -76,6 +76,7 @@ int cap_netlink_send(struct sock *sk, st
25880  int cap_capable(const struct cred *cred, struct user_namespace *targ_ns,
25881                 int cap, int audit)
25882  {
25883 +       struct vx_info *vxi = current_vx_info(); /* FIXME: get vxi from cred? */
25884         struct user_namespace *ns = targ_ns;
25885  
25886         /* See if cred has the capability in the target user namespace
25887 @@ -84,8 +85,12 @@ int cap_capable(const struct cred *cred,
25888          */
25889         for (;;) {
25890                 /* Do we have the necessary capabilities? */
25891 -               if (ns == cred->user_ns)
25892 -                       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
25893 +               if (ns == cred->user_ns) {
25894 +                       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
25895 +                           cap_raised(cred->cap_effective, cap))
25896 +                               return 0;
25897 +                       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
25898 +               }
25899  
25900                 /* Have we tried all of the parent namespaces? */
25901                 if (ns == &init_user_ns)
25902 @@ -628,7 +633,7 @@ int cap_inode_setxattr(struct dentry *de
25903  
25904         if (!strncmp(name, XATTR_SECURITY_PREFIX,
25905                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
25906 -           !capable(CAP_SYS_ADMIN))
25907 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
25908                 return -EPERM;
25909         return 0;
25910  }
25911 @@ -654,7 +659,7 @@ int cap_inode_removexattr(struct dentry
25912  
25913         if (!strncmp(name, XATTR_SECURITY_PREFIX,
25914                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
25915 -           !capable(CAP_SYS_ADMIN))
25916 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
25917                 return -EPERM;
25918         return 0;
25919  }
25920 diff -NurpP --minimal linux-3.10.33/security/selinux/hooks.c linux-3.10.33-vs2.3.6.8/security/selinux/hooks.c
25921 --- linux-3.10.33/security/selinux/hooks.c      2014-03-12 13:16:02.000000000 +0000
25922 +++ linux-3.10.33-vs2.3.6.8/security/selinux/hooks.c    2014-03-12 13:18:24.000000000 +0000
25923 @@ -68,7 +68,6 @@
25924  #include <linux/dccp.h>
25925  #include <linux/quota.h>
25926  #include <linux/un.h>          /* for Unix socket types */
25927 -#include <net/af_unix.h>       /* for Unix socket types */
25928  #include <linux/parser.h>
25929  #include <linux/nfs_mount.h>
25930  #include <net/ipv6.h>
This page took 2.533928 seconds and 2 git commands to generate.