]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
- up to 3.9.6; vserver up to 3.9.5-vs2.3.6.5
[packages/kernel.git] / kernel-vserver-2.3.patch
1 diff -NurpP --minimal linux-3.9.5/Documentation/vserver/debug.txt linux-3.9.5-vs2.3.6.5/Documentation/vserver/debug.txt
2 --- linux-3.9.5/Documentation/vserver/debug.txt 1970-01-01 00:00:00.000000000 +0000
3 +++ linux-3.9.5-vs2.3.6.5/Documentation/vserver/debug.txt       2013-05-31 14:47:10.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.9.5/arch/alpha/Kconfig linux-3.9.5-vs2.3.6.5/arch/alpha/Kconfig
160 --- linux-3.9.5/arch/alpha/Kconfig      2013-05-31 13:44:28.000000000 +0000
161 +++ linux-3.9.5-vs2.3.6.5/arch/alpha/Kconfig    2013-05-31 14:47:10.000000000 +0000
162 @@ -669,6 +669,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.9.5/arch/alpha/kernel/systbls.S linux-3.9.5-vs2.3.6.5/arch/alpha/kernel/systbls.S
172 --- linux-3.9.5/arch/alpha/kernel/systbls.S     2013-02-19 13:56:11.000000000 +0000
173 +++ linux-3.9.5-vs2.3.6.5/arch/alpha/kernel/systbls.S   2013-05-31 14:47:11.000000000 +0000
174 @@ -446,7 +446,7 @@ sys_call_table:
175         .quad sys_stat64                        /* 425 */
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.9.5/arch/alpha/kernel/traps.c linux-3.9.5-vs2.3.6.5/arch/alpha/kernel/traps.c
184 --- linux-3.9.5/arch/alpha/kernel/traps.c       2013-05-31 13:44:28.000000000 +0000
185 +++ linux-3.9.5-vs2.3.6.5/arch/alpha/kernel/traps.c     2013-06-12 09:32:34.000000000 +0000
186 @@ -184,7 +184,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.9.5/arch/arm/Kconfig linux-3.9.5-vs2.3.6.5/arch/arm/Kconfig
197 --- linux-3.9.5/arch/arm/Kconfig        2013-05-31 13:44:29.000000000 +0000
198 +++ linux-3.9.5-vs2.3.6.5/arch/arm/Kconfig      2013-05-31 14:47:11.000000000 +0000
199 @@ -2353,6 +2353,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.9.5/arch/arm/kernel/calls.S linux-3.9.5-vs2.3.6.5/arch/arm/kernel/calls.S
209 --- linux-3.9.5/arch/arm/kernel/calls.S 2013-05-31 13:44:29.000000000 +0000
210 +++ linux-3.9.5-vs2.3.6.5/arch/arm/kernel/calls.S       2013-05-31 14:47:11.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.9.5/arch/arm/kernel/process.c linux-3.9.5-vs2.3.6.5/arch/arm/kernel/process.c
221 --- linux-3.9.5/arch/arm/kernel/process.c       2013-05-31 13:44:29.000000000 +0000
222 +++ linux-3.9.5-vs2.3.6.5/arch/arm/kernel/process.c     2013-06-12 09:33:04.000000000 +0000
223 @@ -332,7 +332,8 @@ void __show_regs(struct pt_regs *regs)
224  void show_regs(struct pt_regs * regs)
225  {
226         printk("\n");
227 -       printk("Pid: %d, comm: %20s\n", task_pid_nr(current), current->comm);
228 +       printk("Pid: %d:#%u, comm: %20s\n",
229 +               task_pid_nr(current), current->xid, current->comm);
230         __show_regs(regs);
231         dump_stack();
232  }
233 diff -NurpP --minimal linux-3.9.5/arch/arm/kernel/traps.c linux-3.9.5-vs2.3.6.5/arch/arm/kernel/traps.c
234 --- linux-3.9.5/arch/arm/kernel/traps.c 2013-05-31 13:44:29.000000000 +0000
235 +++ linux-3.9.5-vs2.3.6.5/arch/arm/kernel/traps.c       2013-05-31 14:47:11.000000000 +0000
236 @@ -249,8 +249,8 @@ static int __die(const char *str, int er
237  
238         print_modules();
239         __show_regs(regs);
240 -       printk(KERN_EMERG "Process %.*s (pid: %d, stack limit = 0x%p)\n",
241 -               TASK_COMM_LEN, tsk->comm, task_pid_nr(tsk), end_of_stack(tsk));
242 +       printk(KERN_EMERG "Process %.*s (pid: %d:#%u, stack limit = 0x%p)\n",
243 +               TASK_COMM_LEN, tsk->comm, task_pid_nr(tsk), tsk->xid, end_of_stack(tsk));
244  
245         if (!user_mode(regs) || in_interrupt()) {
246                 dump_mem(KERN_EMERG, "Stack: ", regs->ARM_sp,
247 diff -NurpP --minimal linux-3.9.5/arch/cris/Kconfig linux-3.9.5-vs2.3.6.5/arch/cris/Kconfig
248 --- linux-3.9.5/arch/cris/Kconfig       2013-05-31 13:44:37.000000000 +0000
249 +++ linux-3.9.5-vs2.3.6.5/arch/cris/Kconfig     2013-05-31 14:47:11.000000000 +0000
250 @@ -674,6 +674,8 @@ source "drivers/staging/Kconfig"
251  
252  source "arch/cris/Kconfig.debug"
253  
254 +source "kernel/vserver/Kconfig"
255 +
256  source "security/Kconfig"
257  
258  source "crypto/Kconfig"
259 diff -NurpP --minimal linux-3.9.5/arch/h8300/Kconfig linux-3.9.5-vs2.3.6.5/arch/h8300/Kconfig
260 --- linux-3.9.5/arch/h8300/Kconfig      2013-05-31 13:44:38.000000000 +0000
261 +++ linux-3.9.5-vs2.3.6.5/arch/h8300/Kconfig    2013-05-31 14:47:11.000000000 +0000
262 @@ -221,6 +221,8 @@ source "fs/Kconfig"
263  
264  source "arch/h8300/Kconfig.debug"
265  
266 +source "kernel/vserver/Kconfig"
267 +
268  source "security/Kconfig"
269  
270  source "crypto/Kconfig"
271 diff -NurpP --minimal linux-3.9.5/arch/ia64/Kconfig linux-3.9.5-vs2.3.6.5/arch/ia64/Kconfig
272 --- linux-3.9.5/arch/ia64/Kconfig       2013-05-31 13:44:38.000000000 +0000
273 +++ linux-3.9.5-vs2.3.6.5/arch/ia64/Kconfig     2013-05-31 14:47:11.000000000 +0000
274 @@ -645,6 +645,8 @@ source "fs/Kconfig"
275  
276  source "arch/ia64/Kconfig.debug"
277  
278 +source "kernel/vserver/Kconfig"
279 +
280  source "security/Kconfig"
281  
282  source "crypto/Kconfig"
283 diff -NurpP --minimal linux-3.9.5/arch/ia64/kernel/entry.S linux-3.9.5-vs2.3.6.5/arch/ia64/kernel/entry.S
284 --- linux-3.9.5/arch/ia64/kernel/entry.S        2013-05-31 13:44:38.000000000 +0000
285 +++ linux-3.9.5-vs2.3.6.5/arch/ia64/kernel/entry.S      2013-05-31 14:47:11.000000000 +0000
286 @@ -1719,7 +1719,7 @@ sys_call_table:
287         data8 sys_mq_notify
288         data8 sys_mq_getsetattr
289         data8 sys_kexec_load
290 -       data8 sys_ni_syscall                    // reserved for vserver
291 +       data8 sys_vserver
292         data8 sys_waitid                        // 1270
293         data8 sys_add_key
294         data8 sys_request_key
295 diff -NurpP --minimal linux-3.9.5/arch/ia64/kernel/process.c linux-3.9.5-vs2.3.6.5/arch/ia64/kernel/process.c
296 --- linux-3.9.5/arch/ia64/kernel/process.c      2013-05-31 13:44:38.000000000 +0000
297 +++ linux-3.9.5-vs2.3.6.5/arch/ia64/kernel/process.c    2013-06-12 09:33:32.000000000 +0000
298 @@ -109,8 +109,8 @@ show_regs (struct pt_regs *regs)
299         unsigned long ip = regs->cr_iip + ia64_psr(regs)->ri;
300  
301         print_modules();
302 -       printk("\nPid: %d, CPU %d, comm: %20s\n", task_pid_nr(current),
303 -                       smp_processor_id(), current->comm);
304 +       printk("\nPid: %d:#%u, CPU %d, comm: %20s\n", task_pid_nr(current),
305 +                       current->xid, smp_processor_id(), current->comm);
306         printk("psr : %016lx ifs : %016lx ip  : [<%016lx>]    %s (%s)\n",
307                regs->cr_ipsr, regs->cr_ifs, ip, print_tainted(),
308                init_utsname()->release);
309 diff -NurpP --minimal linux-3.9.5/arch/ia64/kernel/ptrace.c linux-3.9.5-vs2.3.6.5/arch/ia64/kernel/ptrace.c
310 --- linux-3.9.5/arch/ia64/kernel/ptrace.c       2013-02-19 13:56:51.000000000 +0000
311 +++ linux-3.9.5-vs2.3.6.5/arch/ia64/kernel/ptrace.c     2013-05-31 14:47:11.000000000 +0000
312 @@ -21,6 +21,7 @@
313  #include <linux/regset.h>
314  #include <linux/elf.h>
315  #include <linux/tracehook.h>
316 +#include <linux/vs_base.h>
317  
318  #include <asm/pgtable.h>
319  #include <asm/processor.h>
320 diff -NurpP --minimal linux-3.9.5/arch/ia64/kernel/traps.c linux-3.9.5-vs2.3.6.5/arch/ia64/kernel/traps.c
321 --- linux-3.9.5/arch/ia64/kernel/traps.c        2013-05-31 13:44:38.000000000 +0000
322 +++ linux-3.9.5-vs2.3.6.5/arch/ia64/kernel/traps.c      2013-06-12 09:33:50.000000000 +0000
323 @@ -60,8 +60,9 @@ die (const char *str, struct pt_regs *re
324         put_cpu();
325  
326         if (++die.lock_owner_depth < 3) {
327 -               printk("%s[%d]: %s %ld [%d]\n",
328 -               current->comm, task_pid_nr(current), str, err, ++die_counter);
329 +               printk("%s[%d:#%u]: %s %ld [%d]\n",
330 +                       current->comm, task_pid_nr(current), current->xid,
331 +                       str, err, ++die_counter);
332                 if (notify_die(DIE_OOPS, str, regs, err, 255, SIGSEGV)
333                     != NOTIFY_STOP)
334                         show_regs(regs);
335 @@ -324,8 +325,9 @@ handle_fpu_swa (int fp_fault, struct pt_
336                         if ((last.count & 15) < 5 && (ia64_fetchadd(1, &last.count, acq) & 15) < 5) {
337                                 last.time = current_jiffies + 5 * HZ;
338                                 printk(KERN_WARNING
339 -                                       "%s(%d): floating-point assist fault at ip %016lx, isr %016lx\n",
340 -                                       current->comm, task_pid_nr(current), regs->cr_iip + ia64_psr(regs)->ri, isr);
341 +                                       "%s(%d:#%u): floating-point assist fault at ip %016lx, isr %016lx\n",
342 +                                       current->comm, task_pid_nr(current), current->xid,
343 +                                       regs->cr_iip + ia64_psr(regs)->ri, isr);
344                         }
345                 }
346         }
347 diff -NurpP --minimal linux-3.9.5/arch/m32r/kernel/traps.c linux-3.9.5-vs2.3.6.5/arch/m32r/kernel/traps.c
348 --- linux-3.9.5/arch/m32r/kernel/traps.c        2012-12-11 03:30:57.000000000 +0000
349 +++ linux-3.9.5-vs2.3.6.5/arch/m32r/kernel/traps.c      2013-06-12 09:33:58.000000000 +0000
350 @@ -195,8 +195,9 @@ static void show_registers(struct pt_reg
351         } else {
352                 printk("SPI: %08lx\n", sp);
353         }
354 -       printk("Process %s (pid: %d, process nr: %d, stackpage=%08lx)",
355 -               current->comm, task_pid_nr(current), 0xffff & i, 4096+(unsigned long)current);
356 +       printk("Process %s (pid: %d:#%u, process nr: %d, stackpage=%08lx)",
357 +               current->comm, task_pid_nr(current), current->xid,
358 +               0xffff & i, 4096+(unsigned long)current);
359  
360         /*
361          * When in-kernel, we also print out the stack and code at the
362 diff -NurpP --minimal linux-3.9.5/arch/m68k/Kconfig linux-3.9.5-vs2.3.6.5/arch/m68k/Kconfig
363 --- linux-3.9.5/arch/m68k/Kconfig       2013-05-31 13:44:38.000000000 +0000
364 +++ linux-3.9.5-vs2.3.6.5/arch/m68k/Kconfig     2013-05-31 14:47:11.000000000 +0000
365 @@ -137,6 +137,8 @@ source "fs/Kconfig"
366  
367  source "arch/m68k/Kconfig.debug"
368  
369 +source "kernel/vserver/Kconfig"
370 +
371  source "security/Kconfig"
372  
373  source "crypto/Kconfig"
374 diff -NurpP --minimal linux-3.9.5/arch/mips/Kconfig linux-3.9.5-vs2.3.6.5/arch/mips/Kconfig
375 --- linux-3.9.5/arch/mips/Kconfig       2013-05-31 13:44:39.000000000 +0000
376 +++ linux-3.9.5-vs2.3.6.5/arch/mips/Kconfig     2013-05-31 14:47:11.000000000 +0000
377 @@ -2550,6 +2550,8 @@ source "fs/Kconfig"
378  
379  source "arch/mips/Kconfig.debug"
380  
381 +source "kernel/vserver/Kconfig"
382 +
383  source "security/Kconfig"
384  
385  source "crypto/Kconfig"
386 diff -NurpP --minimal linux-3.9.5/arch/mips/kernel/ptrace.c linux-3.9.5-vs2.3.6.5/arch/mips/kernel/ptrace.c
387 --- linux-3.9.5/arch/mips/kernel/ptrace.c       2013-05-31 13:44:42.000000000 +0000
388 +++ linux-3.9.5-vs2.3.6.5/arch/mips/kernel/ptrace.c     2013-05-31 14:47:11.000000000 +0000
389 @@ -25,6 +25,7 @@
390  #include <linux/security.h>
391  #include <linux/audit.h>
392  #include <linux/seccomp.h>
393 +#include <linux/vs_base.h>
394  
395  #include <asm/byteorder.h>
396  #include <asm/cpu.h>
397 @@ -262,6 +263,9 @@ long arch_ptrace(struct task_struct *chi
398         void __user *datavp = (void __user *) data;
399         unsigned long __user *datalp = (void __user *) data;
400  
401 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
402 +               goto out;
403 +
404         switch (request) {
405         /* when I and D space are separate, these will need to be fixed. */
406         case PTRACE_PEEKTEXT: /* read word at location addr. */
407 diff -NurpP --minimal linux-3.9.5/arch/mips/kernel/scall32-o32.S linux-3.9.5-vs2.3.6.5/arch/mips/kernel/scall32-o32.S
408 --- linux-3.9.5/arch/mips/kernel/scall32-o32.S  2013-05-31 13:44:42.000000000 +0000
409 +++ linux-3.9.5-vs2.3.6.5/arch/mips/kernel/scall32-o32.S        2013-05-31 14:47:11.000000000 +0000
410 @@ -512,7 +512,7 @@ einval: li  v0, -ENOSYS
411         sys     sys_mq_timedreceive     5
412         sys     sys_mq_notify           2       /* 4275 */
413         sys     sys_mq_getsetattr       3
414 -       sys     sys_ni_syscall          0       /* sys_vserver */
415 +       sys     sys_vserver             3
416         sys     sys_waitid              5
417         sys     sys_ni_syscall          0       /* available, was setaltroot */
418         sys     sys_add_key             5       /* 4280 */
419 diff -NurpP --minimal linux-3.9.5/arch/mips/kernel/scall64-64.S linux-3.9.5-vs2.3.6.5/arch/mips/kernel/scall64-64.S
420 --- linux-3.9.5/arch/mips/kernel/scall64-64.S   2013-05-31 13:44:42.000000000 +0000
421 +++ linux-3.9.5-vs2.3.6.5/arch/mips/kernel/scall64-64.S 2013-05-31 14:47:11.000000000 +0000
422 @@ -351,7 +351,7 @@ sys_call_table:
423         PTR     sys_mq_timedreceive
424         PTR     sys_mq_notify
425         PTR     sys_mq_getsetattr               /* 5235 */
426 -       PTR     sys_ni_syscall                  /* sys_vserver */
427 +       PTR     sys_vserver
428         PTR     sys_waitid
429         PTR     sys_ni_syscall                  /* available, was setaltroot */
430         PTR     sys_add_key
431 diff -NurpP --minimal linux-3.9.5/arch/mips/kernel/scall64-n32.S linux-3.9.5-vs2.3.6.5/arch/mips/kernel/scall64-n32.S
432 --- linux-3.9.5/arch/mips/kernel/scall64-n32.S  2013-05-31 13:44:42.000000000 +0000
433 +++ linux-3.9.5-vs2.3.6.5/arch/mips/kernel/scall64-n32.S        2013-05-31 14:47:11.000000000 +0000
434 @@ -344,7 +344,7 @@ EXPORT(sysn32_call_table)
435         PTR     compat_sys_mq_timedreceive
436         PTR     compat_sys_mq_notify
437         PTR     compat_sys_mq_getsetattr
438 -       PTR     sys_ni_syscall                  /* 6240, sys_vserver */
439 +       PTR     sys32_vserver                   /* 6240 */
440         PTR     compat_sys_waitid
441         PTR     sys_ni_syscall                  /* available, was setaltroot */
442         PTR     sys_add_key
443 diff -NurpP --minimal linux-3.9.5/arch/mips/kernel/scall64-o32.S linux-3.9.5-vs2.3.6.5/arch/mips/kernel/scall64-o32.S
444 --- linux-3.9.5/arch/mips/kernel/scall64-o32.S  2013-05-31 13:44:42.000000000 +0000
445 +++ linux-3.9.5-vs2.3.6.5/arch/mips/kernel/scall64-o32.S        2013-05-31 15:07:53.000000000 +0000
446 @@ -469,7 +469,7 @@ sys_call_table:
447         PTR     compat_sys_mq_timedreceive
448         PTR     compat_sys_mq_notify            /* 4275 */
449         PTR     compat_sys_mq_getsetattr
450 -       PTR     sys_ni_syscall                  /* sys_vserver */
451 +       PTR     sys32_vserver
452         PTR     compat_sys_waitid
453         PTR     sys_ni_syscall                  /* available, was setaltroot */
454         PTR     sys_add_key                     /* 4280 */
455 diff -NurpP --minimal linux-3.9.5/arch/mips/kernel/traps.c linux-3.9.5-vs2.3.6.5/arch/mips/kernel/traps.c
456 --- linux-3.9.5/arch/mips/kernel/traps.c        2013-05-31 13:44:42.000000000 +0000
457 +++ linux-3.9.5-vs2.3.6.5/arch/mips/kernel/traps.c      2013-05-31 14:47:11.000000000 +0000
458 @@ -348,9 +348,10 @@ void show_registers(struct pt_regs *regs
459  
460         __show_regs(regs);
461         print_modules();
462 -       printk("Process %s (pid: %d, threadinfo=%p, task=%p, tls=%0*lx)\n",
463 -              current->comm, current->pid, current_thread_info(), current,
464 -             field, current_thread_info()->tp_value);
465 +       printk("Process %s (pid: %d:#%u, threadinfo=%p, task=%p, tls=%0*lx)\n",
466 +               current->comm, task_pid_nr(current), current->xid,
467 +               current_thread_info(), current,
468 +               field, current_thread_info()->tp_value);
469         if (cpu_has_userlocal) {
470                 unsigned long tls;
471  
472 diff -NurpP --minimal linux-3.9.5/arch/parisc/Kconfig linux-3.9.5-vs2.3.6.5/arch/parisc/Kconfig
473 --- linux-3.9.5/arch/parisc/Kconfig     2013-05-31 13:44:44.000000000 +0000
474 +++ linux-3.9.5-vs2.3.6.5/arch/parisc/Kconfig   2013-05-31 14:47:11.000000000 +0000
475 @@ -308,6 +308,8 @@ source "fs/Kconfig"
476  
477  source "arch/parisc/Kconfig.debug"
478  
479 +source "kernel/vserver/Kconfig"
480 +
481  source "security/Kconfig"
482  
483  source "crypto/Kconfig"
484 diff -NurpP --minimal linux-3.9.5/arch/parisc/kernel/syscall_table.S linux-3.9.5-vs2.3.6.5/arch/parisc/kernel/syscall_table.S
485 --- linux-3.9.5/arch/parisc/kernel/syscall_table.S      2013-05-31 13:44:44.000000000 +0000
486 +++ linux-3.9.5-vs2.3.6.5/arch/parisc/kernel/syscall_table.S    2013-05-31 14:47:11.000000000 +0000
487 @@ -358,7 +358,7 @@
488         ENTRY_COMP(mbind)               /* 260 */
489         ENTRY_COMP(get_mempolicy)
490         ENTRY_COMP(set_mempolicy)
491 -       ENTRY_SAME(ni_syscall)  /* 263: reserved for vserver */
492 +       ENTRY_DIFF(vserver)
493         ENTRY_SAME(add_key)
494         ENTRY_SAME(request_key)         /* 265 */
495         ENTRY_SAME(keyctl)
496 diff -NurpP --minimal linux-3.9.5/arch/parisc/kernel/traps.c linux-3.9.5-vs2.3.6.5/arch/parisc/kernel/traps.c
497 --- linux-3.9.5/arch/parisc/kernel/traps.c      2013-05-31 13:44:44.000000000 +0000
498 +++ linux-3.9.5-vs2.3.6.5/arch/parisc/kernel/traps.c    2013-05-31 14:47:11.000000000 +0000
499 @@ -235,8 +235,9 @@ void die_if_kernel(char *str, struct pt_
500                 if (err == 0)
501                         return; /* STFU */
502  
503 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld) at " RFMT "\n",
504 -                       current->comm, task_pid_nr(current), str, err, regs->iaoq[0]);
505 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld) at " RFMT "\n",
506 +                       current->comm, task_pid_nr(current), current->xid,
507 +                       str, err, regs->iaoq[0]);
508  #ifdef PRINT_USER_FAULTS
509                 /* XXX for debugging only */
510                 show_regs(regs);
511 @@ -269,8 +270,8 @@ void die_if_kernel(char *str, struct pt_
512                 pdc_console_restart();
513         
514         if (err)
515 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld)\n",
516 -                       current->comm, task_pid_nr(current), str, err);
517 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld)\n",
518 +                       current->comm, task_pid_nr(current), current->xid, str, err);
519  
520         /* Wot's wrong wif bein' racy? */
521         if (current->thread.flags & PARISC_KERNEL_DEATH) {
522 diff -NurpP --minimal linux-3.9.5/arch/parisc/mm/fault.c linux-3.9.5-vs2.3.6.5/arch/parisc/mm/fault.c
523 --- linux-3.9.5/arch/parisc/mm/fault.c  2013-05-31 13:44:44.000000000 +0000
524 +++ linux-3.9.5-vs2.3.6.5/arch/parisc/mm/fault.c        2013-05-31 14:47:11.000000000 +0000
525 @@ -257,8 +257,9 @@ bad_area:
526  
527  #ifdef PRINT_USER_FAULTS
528                 printk(KERN_DEBUG "\n");
529 -               printk(KERN_DEBUG "do_page_fault() pid=%d command='%s' type=%lu address=0x%08lx\n",
530 -                   task_pid_nr(tsk), tsk->comm, code, address);
531 +               printk(KERN_DEBUG "do_page_fault() pid=%d:#%u "
532 +                   "command='%s' type=%lu address=0x%08lx\n",
533 +                   task_pid_nr(tsk), tsk->xid, tsk->comm, code, address);
534                 if (vma) {
535                         printk(KERN_DEBUG "vm_start = 0x%08lx, vm_end = 0x%08lx\n",
536                                         vma->vm_start, vma->vm_end);
537 diff -NurpP --minimal linux-3.9.5/arch/powerpc/Kconfig linux-3.9.5-vs2.3.6.5/arch/powerpc/Kconfig
538 --- linux-3.9.5/arch/powerpc/Kconfig    2013-05-31 13:44:44.000000000 +0000
539 +++ linux-3.9.5-vs2.3.6.5/arch/powerpc/Kconfig  2013-05-31 14:47:11.000000000 +0000
540 @@ -1027,6 +1027,8 @@ source "lib/Kconfig"
541  
542  source "arch/powerpc/Kconfig.debug"
543  
544 +source "kernel/vserver/Kconfig"
545 +
546  source "security/Kconfig"
547  
548  config KEYS_COMPAT
549 diff -NurpP --minimal linux-3.9.5/arch/powerpc/include/uapi/asm/unistd.h linux-3.9.5-vs2.3.6.5/arch/powerpc/include/uapi/asm/unistd.h
550 --- linux-3.9.5/arch/powerpc/include/uapi/asm/unistd.h  2013-05-31 13:44:44.000000000 +0000
551 +++ linux-3.9.5-vs2.3.6.5/arch/powerpc/include/uapi/asm/unistd.h        2013-05-31 14:47:11.000000000 +0000
552 @@ -275,7 +275,7 @@
553  #endif
554  #define __NR_rtas              255
555  #define __NR_sys_debug_setcontext 256
556 -/* Number 257 is reserved for vserver */
557 +#define __NR_vserver           257
558  #define __NR_migrate_pages     258
559  #define __NR_mbind             259
560  #define __NR_get_mempolicy     260
561 diff -NurpP --minimal linux-3.9.5/arch/powerpc/kernel/process.c linux-3.9.5-vs2.3.6.5/arch/powerpc/kernel/process.c
562 --- linux-3.9.5/arch/powerpc/kernel/process.c   2013-05-31 13:44:44.000000000 +0000
563 +++ linux-3.9.5-vs2.3.6.5/arch/powerpc/kernel/process.c 2013-06-12 09:34:39.000000000 +0000
564 @@ -850,8 +850,9 @@ void show_regs(struct pt_regs * regs)
565  #else
566                 printk("DAR: "REG", DSISR: %08lx\n", regs->dar, regs->dsisr);
567  #endif
568 -       printk("TASK = %p[%d] '%s' THREAD: %p",
569 -              current, task_pid_nr(current), current->comm, task_thread_info(current));
570 +       printk("TASK = %p[%d:#%u] '%s' THREAD: %p",
571 +              current, task_pid_nr(current), current->xid,
572 +              current->comm, task_thread_info(current));
573  
574  #ifdef CONFIG_SMP
575         printk(" CPU: %d", raw_smp_processor_id());
576 diff -NurpP --minimal linux-3.9.5/arch/powerpc/kernel/traps.c linux-3.9.5-vs2.3.6.5/arch/powerpc/kernel/traps.c
577 --- linux-3.9.5/arch/powerpc/kernel/traps.c     2013-06-11 12:22:35.000000000 +0000
578 +++ linux-3.9.5-vs2.3.6.5/arch/powerpc/kernel/traps.c   2013-06-13 00:14:31.000000000 +0000
579 @@ -1196,8 +1196,9 @@ void nonrecoverable_exception(struct pt_
580  
581  void trace_syscall(struct pt_regs *regs)
582  {
583 -       printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
584 -              current, task_pid_nr(current), regs->nip, regs->link, regs->gpr[0],
585 +       printk("Task: %p(%d:#%u), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
586 +              current, task_pid_nr(current), current->xid,
587 +              regs->nip, regs->link, regs->gpr[0],
588                regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted());
589  }
590  
591 diff -NurpP --minimal linux-3.9.5/arch/s390/Kconfig linux-3.9.5-vs2.3.6.5/arch/s390/Kconfig
592 --- linux-3.9.5/arch/s390/Kconfig       2013-05-31 13:44:45.000000000 +0000
593 +++ linux-3.9.5-vs2.3.6.5/arch/s390/Kconfig     2013-05-31 14:47:11.000000000 +0000
594 @@ -592,6 +592,8 @@ source "fs/Kconfig"
595  
596  source "arch/s390/Kconfig.debug"
597  
598 +source "kernel/vserver/Kconfig"
599 +
600  source "security/Kconfig"
601  
602  source "crypto/Kconfig"
603 diff -NurpP --minimal linux-3.9.5/arch/s390/include/asm/tlb.h linux-3.9.5-vs2.3.6.5/arch/s390/include/asm/tlb.h
604 --- linux-3.9.5/arch/s390/include/asm/tlb.h     2012-12-11 03:30:57.000000000 +0000
605 +++ linux-3.9.5-vs2.3.6.5/arch/s390/include/asm/tlb.h   2013-05-31 14:47:11.000000000 +0000
606 @@ -24,6 +24,7 @@
607  #include <linux/mm.h>
608  #include <linux/pagemap.h>
609  #include <linux/swap.h>
610 +
611  #include <asm/processor.h>
612  #include <asm/pgalloc.h>
613  #include <asm/tlbflush.h>
614 diff -NurpP --minimal linux-3.9.5/arch/s390/include/uapi/asm/unistd.h linux-3.9.5-vs2.3.6.5/arch/s390/include/uapi/asm/unistd.h
615 --- linux-3.9.5/arch/s390/include/uapi/asm/unistd.h     2013-02-19 13:57:16.000000000 +0000
616 +++ linux-3.9.5-vs2.3.6.5/arch/s390/include/uapi/asm/unistd.h   2013-05-31 14:47:11.000000000 +0000
617 @@ -200,7 +200,7 @@
618  #define __NR_clock_gettime     (__NR_timer_create+6)
619  #define __NR_clock_getres      (__NR_timer_create+7)
620  #define __NR_clock_nanosleep   (__NR_timer_create+8)
621 -/* Number 263 is reserved for vserver */
622 +#define __NR_vserver           263
623  #define __NR_statfs64          265
624  #define __NR_fstatfs64         266
625  #define __NR_remap_file_pages  267
626 diff -NurpP --minimal linux-3.9.5/arch/s390/kernel/ptrace.c linux-3.9.5-vs2.3.6.5/arch/s390/kernel/ptrace.c
627 --- linux-3.9.5/arch/s390/kernel/ptrace.c       2012-12-11 03:30:57.000000000 +0000
628 +++ linux-3.9.5-vs2.3.6.5/arch/s390/kernel/ptrace.c     2013-05-31 14:47:11.000000000 +0000
629 @@ -21,6 +21,7 @@
630  #include <linux/tracehook.h>
631  #include <linux/seccomp.h>
632  #include <linux/compat.h>
633 +#include <linux/vs_base.h>
634  #include <trace/syscall.h>
635  #include <asm/segment.h>
636  #include <asm/page.h>
637 diff -NurpP --minimal linux-3.9.5/arch/s390/kernel/syscalls.S linux-3.9.5-vs2.3.6.5/arch/s390/kernel/syscalls.S
638 --- linux-3.9.5/arch/s390/kernel/syscalls.S     2013-05-31 13:44:45.000000000 +0000
639 +++ linux-3.9.5-vs2.3.6.5/arch/s390/kernel/syscalls.S   2013-05-31 14:47:11.000000000 +0000
640 @@ -271,7 +271,7 @@ SYSCALL(sys_clock_settime,sys_clock_sett
641  SYSCALL(sys_clock_gettime,sys_clock_gettime,sys32_clock_gettime_wrapper)       /* 260 */
642  SYSCALL(sys_clock_getres,sys_clock_getres,sys32_clock_getres_wrapper)
643  SYSCALL(sys_clock_nanosleep,sys_clock_nanosleep,sys32_clock_nanosleep_wrapper)
644 -NI_SYSCALL                                                     /* reserved for vserver */
645 +SYSCALL(sys_vserver,sys_vserver,sys32_vserver)
646  SYSCALL(sys_s390_fadvise64_64,sys_ni_syscall,sys32_fadvise64_64_wrapper)
647  SYSCALL(sys_statfs64,sys_statfs64,compat_sys_statfs64_wrapper)
648  SYSCALL(sys_fstatfs64,sys_fstatfs64,compat_sys_fstatfs64_wrapper)
649 diff -NurpP --minimal linux-3.9.5/arch/sh/Kconfig linux-3.9.5-vs2.3.6.5/arch/sh/Kconfig
650 --- linux-3.9.5/arch/sh/Kconfig 2013-05-31 13:44:45.000000000 +0000
651 +++ linux-3.9.5-vs2.3.6.5/arch/sh/Kconfig       2013-05-31 14:47:11.000000000 +0000
652 @@ -951,6 +951,8 @@ source "fs/Kconfig"
653  
654  source "arch/sh/Kconfig.debug"
655  
656 +source "kernel/vserver/Kconfig"
657 +
658  source "security/Kconfig"
659  
660  source "crypto/Kconfig"
661 diff -NurpP --minimal linux-3.9.5/arch/sh/kernel/irq.c linux-3.9.5-vs2.3.6.5/arch/sh/kernel/irq.c
662 --- linux-3.9.5/arch/sh/kernel/irq.c    2012-12-11 03:30:57.000000000 +0000
663 +++ linux-3.9.5-vs2.3.6.5/arch/sh/kernel/irq.c  2013-05-31 14:47:11.000000000 +0000
664 @@ -14,6 +14,7 @@
665  #include <linux/ftrace.h>
666  #include <linux/delay.h>
667  #include <linux/ratelimit.h>
668 +// #include <linux/vs_context.h>
669  #include <asm/processor.h>
670  #include <asm/machvec.h>
671  #include <asm/uaccess.h>
672 diff -NurpP --minimal linux-3.9.5/arch/sparc/Kconfig linux-3.9.5-vs2.3.6.5/arch/sparc/Kconfig
673 --- linux-3.9.5/arch/sparc/Kconfig      2013-05-31 13:44:47.000000000 +0000
674 +++ linux-3.9.5-vs2.3.6.5/arch/sparc/Kconfig    2013-05-31 14:47:11.000000000 +0000
675 @@ -559,6 +559,8 @@ source "fs/Kconfig"
676  
677  source "arch/sparc/Kconfig.debug"
678  
679 +source "kernel/vserver/Kconfig"
680 +
681  source "security/Kconfig"
682  
683  source "crypto/Kconfig"
684 diff -NurpP --minimal linux-3.9.5/arch/sparc/include/uapi/asm/unistd.h linux-3.9.5-vs2.3.6.5/arch/sparc/include/uapi/asm/unistd.h
685 --- linux-3.9.5/arch/sparc/include/uapi/asm/unistd.h    2013-02-19 13:57:17.000000000 +0000
686 +++ linux-3.9.5-vs2.3.6.5/arch/sparc/include/uapi/asm/unistd.h  2013-05-31 14:47:11.000000000 +0000
687 @@ -332,7 +332,7 @@
688  #define __NR_timer_getoverrun  264
689  #define __NR_timer_delete      265
690  #define __NR_timer_create      266
691 -/* #define __NR_vserver                267 Reserved for VSERVER */
692 +#define __NR_vserver           267
693  #define __NR_io_setup          268
694  #define __NR_io_destroy                269
695  #define __NR_io_submit         270
696 diff -NurpP --minimal linux-3.9.5/arch/sparc/kernel/systbls_32.S linux-3.9.5-vs2.3.6.5/arch/sparc/kernel/systbls_32.S
697 --- linux-3.9.5/arch/sparc/kernel/systbls_32.S  2013-05-31 13:44:48.000000000 +0000
698 +++ linux-3.9.5-vs2.3.6.5/arch/sparc/kernel/systbls_32.S        2013-05-31 14:47:11.000000000 +0000
699 @@ -70,7 +70,7 @@ sys_call_table:
700  /*250*/        .long sys_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_ni_syscall
701  /*255*/        .long sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
702  /*260*/        .long sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
703 -/*265*/        .long sys_timer_delete, sys_timer_create, sys_nis_syscall, sys_io_setup, sys_io_destroy
704 +/*265*/        .long sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
705  /*270*/        .long sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
706  /*275*/        .long sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
707  /*280*/        .long sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
708 diff -NurpP --minimal linux-3.9.5/arch/sparc/kernel/systbls_64.S linux-3.9.5-vs2.3.6.5/arch/sparc/kernel/systbls_64.S
709 --- linux-3.9.5/arch/sparc/kernel/systbls_64.S  2013-05-31 13:44:48.000000000 +0000
710 +++ linux-3.9.5-vs2.3.6.5/arch/sparc/kernel/systbls_64.S        2013-05-31 14:47:11.000000000 +0000
711 @@ -71,7 +71,7 @@ sys_call_table32:
712  /*250*/        .word sys_mremap, compat_sys_sysctl, sys_getsid, sys_fdatasync, sys_nis_syscall
713         .word sys32_sync_file_range, compat_sys_clock_settime, compat_sys_clock_gettime, compat_sys_clock_getres, sys32_clock_nanosleep
714  /*260*/        .word compat_sys_sched_getaffinity, compat_sys_sched_setaffinity, sys32_timer_settime, compat_sys_timer_gettime, sys_timer_getoverrun
715 -       .word sys_timer_delete, compat_sys_timer_create, sys_ni_syscall, compat_sys_io_setup, sys_io_destroy
716 +       .word sys_timer_delete, compat_sys_timer_create, sys32_vserver, compat_sys_io_setup, sys_io_destroy
717  /*270*/        .word sys32_io_submit, sys_io_cancel, compat_sys_io_getevents, sys32_mq_open, sys_mq_unlink
718         .word compat_sys_mq_timedsend, compat_sys_mq_timedreceive, compat_sys_mq_notify, compat_sys_mq_getsetattr, compat_sys_waitid
719  /*280*/        .word sys_tee, sys_add_key, sys_request_key, compat_sys_keyctl, compat_sys_openat
720 @@ -149,7 +149,7 @@ sys_call_table:
721  /*250*/        .word sys_64_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nis_syscall
722         .word sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
723  /*260*/        .word sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
724 -       .word sys_timer_delete, sys_timer_create, sys_ni_syscall, sys_io_setup, sys_io_destroy
725 +       .word sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
726  /*270*/        .word sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
727         .word sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
728  /*280*/        .word sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
729 diff -NurpP --minimal linux-3.9.5/arch/um/Kconfig.rest linux-3.9.5-vs2.3.6.5/arch/um/Kconfig.rest
730 --- linux-3.9.5/arch/um/Kconfig.rest    2012-12-11 03:30:57.000000000 +0000
731 +++ linux-3.9.5-vs2.3.6.5/arch/um/Kconfig.rest  2013-05-31 14:47:11.000000000 +0000
732 @@ -12,6 +12,8 @@ source "arch/um/Kconfig.net"
733  
734  source "fs/Kconfig"
735  
736 +source "kernel/vserver/Kconfig"
737 +
738  source "security/Kconfig"
739  
740  source "crypto/Kconfig"
741 diff -NurpP --minimal linux-3.9.5/arch/x86/Kconfig linux-3.9.5-vs2.3.6.5/arch/x86/Kconfig
742 --- linux-3.9.5/arch/x86/Kconfig        2013-06-11 12:22:36.000000000 +0000
743 +++ linux-3.9.5-vs2.3.6.5/arch/x86/Kconfig      2013-05-31 14:47:11.000000000 +0000
744 @@ -2341,6 +2341,8 @@ source "fs/Kconfig"
745  
746  source "arch/x86/Kconfig.debug"
747  
748 +source "kernel/vserver/Kconfig"
749 +
750  source "security/Kconfig"
751  
752  source "crypto/Kconfig"
753 diff -NurpP --minimal linux-3.9.5/arch/x86/kernel/dumpstack.c linux-3.9.5-vs2.3.6.5/arch/x86/kernel/dumpstack.c
754 --- linux-3.9.5/arch/x86/kernel/dumpstack.c     2013-05-31 13:44:49.000000000 +0000
755 +++ linux-3.9.5-vs2.3.6.5/arch/x86/kernel/dumpstack.c   2013-06-12 11:03:19.000000000 +0000
756 @@ -188,8 +188,8 @@ void dump_stack(void)
757         unsigned long stack;
758  
759         bp = stack_frame(current, NULL);
760 -       printk("Pid: %d, comm: %.20s %s %s %.*s\n",
761 -               current->pid, current->comm, print_tainted(),
762 +       printk("Pid: %d:#%u, comm: %.20s %s %s %.*s\n",
763 +               current->pid, current->xid, current->comm, print_tainted(),
764                 init_utsname()->release,
765                 (int)strcspn(init_utsname()->version, " "),
766                 init_utsname()->version);
767 diff -NurpP --minimal linux-3.9.5/arch/x86/kernel/process.c linux-3.9.5-vs2.3.6.5/arch/x86/kernel/process.c
768 --- linux-3.9.5/arch/x86/kernel/process.c       2013-05-31 13:44:49.000000000 +0000
769 +++ linux-3.9.5-vs2.3.6.5/arch/x86/kernel/process.c     2013-06-12 11:02:45.000000000 +0000
770 @@ -135,8 +135,8 @@ void show_regs_common(void)
771         /* Board Name is optional */
772         board = dmi_get_system_info(DMI_BOARD_NAME);
773  
774 -       printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
775 -              current->pid, current->comm, print_tainted(),
776 +       printk(KERN_DEFAULT "Pid: %d:#%u, comm: %.20s %s %s %.*s %s %s%s%s\n",
777 +              current->pid, current->xid, current->comm, print_tainted(),
778                init_utsname()->release,
779                (int)strcspn(init_utsname()->version, " "),
780                init_utsname()->version,
781 diff -NurpP --minimal linux-3.9.5/arch/x86/syscalls/syscall_32.tbl linux-3.9.5-vs2.3.6.5/arch/x86/syscalls/syscall_32.tbl
782 --- linux-3.9.5/arch/x86/syscalls/syscall_32.tbl        2013-05-31 13:44:50.000000000 +0000
783 +++ linux-3.9.5-vs2.3.6.5/arch/x86/syscalls/syscall_32.tbl      2013-05-31 14:47:11.000000000 +0000
784 @@ -279,7 +279,7 @@
785  270    i386    tgkill                  sys_tgkill
786  271    i386    utimes                  sys_utimes                      compat_sys_utimes
787  272    i386    fadvise64_64            sys_fadvise64_64                sys32_fadvise64_64
788 -273    i386    vserver
789 +273    i386    vserver                 sys_vserver                     sys32_vserver
790  274    i386    mbind                   sys_mbind
791  275    i386    get_mempolicy           sys_get_mempolicy               compat_sys_get_mempolicy
792  276    i386    set_mempolicy           sys_set_mempolicy
793 diff -NurpP --minimal linux-3.9.5/arch/x86/syscalls/syscall_64.tbl linux-3.9.5-vs2.3.6.5/arch/x86/syscalls/syscall_64.tbl
794 --- linux-3.9.5/arch/x86/syscalls/syscall_64.tbl        2013-05-31 13:44:50.000000000 +0000
795 +++ linux-3.9.5-vs2.3.6.5/arch/x86/syscalls/syscall_64.tbl      2013-05-31 14:47:11.000000000 +0000
796 @@ -242,7 +242,7 @@
797  233    common  epoll_ctl               sys_epoll_ctl
798  234    common  tgkill                  sys_tgkill
799  235    common  utimes                  sys_utimes
800 -236    64      vserver
801 +236    64      vserver                 sys_vserver
802  237    common  mbind                   sys_mbind
803  238    common  set_mempolicy           sys_set_mempolicy
804  239    common  get_mempolicy           sys_get_mempolicy
805 diff -NurpP --minimal linux-3.9.5/drivers/block/Kconfig linux-3.9.5-vs2.3.6.5/drivers/block/Kconfig
806 --- linux-3.9.5/drivers/block/Kconfig   2013-05-31 13:44:51.000000000 +0000
807 +++ linux-3.9.5-vs2.3.6.5/drivers/block/Kconfig 2013-05-31 14:47:11.000000000 +0000
808 @@ -278,6 +278,13 @@ config BLK_DEV_CRYPTOLOOP
809  
810  source "drivers/block/drbd/Kconfig"
811  
812 +config BLK_DEV_VROOT
813 +       tristate "Virtual Root device support"
814 +       depends on QUOTACTL
815 +       ---help---
816 +         Saying Y here will allow you to use quota/fs ioctls on a shared
817 +         partition within a virtual server without compromising security.
818 +
819  config BLK_DEV_NBD
820         tristate "Network block device support"
821         depends on NET
822 diff -NurpP --minimal linux-3.9.5/drivers/block/Makefile linux-3.9.5-vs2.3.6.5/drivers/block/Makefile
823 --- linux-3.9.5/drivers/block/Makefile  2013-05-31 13:44:51.000000000 +0000
824 +++ linux-3.9.5-vs2.3.6.5/drivers/block/Makefile        2013-05-31 14:47:11.000000000 +0000
825 @@ -33,6 +33,7 @@ obj-$(CONFIG_VIRTIO_BLK)      += virtio_blk.o
826  obj-$(CONFIG_VIODASD)          += viodasd.o
827  obj-$(CONFIG_BLK_DEV_SX8)      += sx8.o
828  obj-$(CONFIG_BLK_DEV_HD)       += hd.o
829 +obj-$(CONFIG_BLK_DEV_VROOT)    += vroot.o
830  
831  obj-$(CONFIG_XEN_BLKDEV_FRONTEND)      += xen-blkfront.o
832  obj-$(CONFIG_XEN_BLKDEV_BACKEND)       += xen-blkback/
833 diff -NurpP --minimal linux-3.9.5/drivers/block/loop.c linux-3.9.5-vs2.3.6.5/drivers/block/loop.c
834 --- linux-3.9.5/drivers/block/loop.c    2013-05-31 13:44:51.000000000 +0000
835 +++ linux-3.9.5-vs2.3.6.5/drivers/block/loop.c  2013-05-31 14:47:11.000000000 +0000
836 @@ -76,6 +76,7 @@
837  #include <linux/sysfs.h>
838  #include <linux/miscdevice.h>
839  #include <linux/falloc.h>
840 +#include <linux/vs_context.h>
841  
842  #include <asm/uaccess.h>
843  
844 @@ -882,6 +883,7 @@ static int loop_set_fd(struct loop_devic
845         lo->lo_blocksize = lo_blocksize;
846         lo->lo_device = bdev;
847         lo->lo_flags = lo_flags;
848 +       lo->lo_xid = vx_current_xid();
849         lo->lo_backing_file = file;
850         lo->transfer = transfer_none;
851         lo->ioctl = NULL;
852 @@ -1033,6 +1035,7 @@ static int loop_clr_fd(struct loop_devic
853         lo->lo_sizelimit = 0;
854         lo->lo_encrypt_key_size = 0;
855         lo->lo_thread = NULL;
856 +       lo->lo_xid = 0;
857         memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
858         memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
859         memset(lo->lo_file_name, 0, LO_NAME_SIZE);
860 @@ -1076,7 +1079,7 @@ loop_set_status(struct loop_device *lo,
861  
862         if (lo->lo_encrypt_key_size &&
863             !uid_eq(lo->lo_key_owner, uid) &&
864 -           !capable(CAP_SYS_ADMIN))
865 +           !vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP))
866                 return -EPERM;
867         if (lo->lo_state != Lo_bound)
868                 return -ENXIO;
869 @@ -1166,7 +1169,8 @@ loop_get_status(struct loop_device *lo,
870         memcpy(info->lo_crypt_name, lo->lo_crypt_name, LO_NAME_SIZE);
871         info->lo_encrypt_type =
872                 lo->lo_encryption ? lo->lo_encryption->number : 0;
873 -       if (lo->lo_encrypt_key_size && capable(CAP_SYS_ADMIN)) {
874 +       if (lo->lo_encrypt_key_size &&
875 +               vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP)) {
876                 info->lo_encrypt_key_size = lo->lo_encrypt_key_size;
877                 memcpy(info->lo_encrypt_key, lo->lo_encrypt_key,
878                        lo->lo_encrypt_key_size);
879 @@ -1508,6 +1512,11 @@ static int lo_open(struct block_device *
880                 goto out;
881         }
882  
883 +       if (!vx_check(lo->lo_xid, VS_IDENT|VS_HOSTID|VS_ADMIN_P)) {
884 +               err = -EACCES;
885 +               goto out;
886 +       }
887 +
888         mutex_lock(&lo->lo_ctl_mutex);
889         lo->lo_refcnt++;
890         mutex_unlock(&lo->lo_ctl_mutex);
891 diff -NurpP --minimal linux-3.9.5/drivers/block/vroot.c linux-3.9.5-vs2.3.6.5/drivers/block/vroot.c
892 --- linux-3.9.5/drivers/block/vroot.c   1970-01-01 00:00:00.000000000 +0000
893 +++ linux-3.9.5-vs2.3.6.5/drivers/block/vroot.c 2013-05-31 14:47:11.000000000 +0000
894 @@ -0,0 +1,291 @@
895 +/*
896 + *  linux/drivers/block/vroot.c
897 + *
898 + *  written by Herbert Pötzl, 9/11/2002
899 + *  ported to 2.6.10 by Herbert Pötzl, 30/12/2004
900 + *
901 + *  based on the loop.c code by Theodore Ts'o.
902 + *
903 + * Copyright (C) 2002-2007 by Herbert Pötzl.
904 + * Redistribution of this file is permitted under the
905 + * GNU General Public License.
906 + *
907 + */
908 +
909 +#include <linux/module.h>
910 +#include <linux/moduleparam.h>
911 +#include <linux/file.h>
912 +#include <linux/major.h>
913 +#include <linux/blkdev.h>
914 +#include <linux/slab.h>
915 +
916 +#include <linux/vroot.h>
917 +#include <linux/vs_context.h>
918 +
919 +
920 +static int max_vroot = 8;
921 +
922 +static struct vroot_device *vroot_dev;
923 +static struct gendisk **disks;
924 +
925 +
926 +static int vroot_set_dev(
927 +       struct vroot_device *vr,
928 +       struct block_device *bdev,
929 +       unsigned int arg)
930 +{
931 +       struct block_device *real_bdev;
932 +       struct file *file;
933 +       struct inode *inode;
934 +       int error;
935 +
936 +       error = -EBUSY;
937 +       if (vr->vr_state != Vr_unbound)
938 +               goto out;
939 +
940 +       error = -EBADF;
941 +       file = fget(arg);
942 +       if (!file)
943 +               goto out;
944 +
945 +       error = -EINVAL;
946 +       inode = file->f_dentry->d_inode;
947 +
948 +
949 +       if (S_ISBLK(inode->i_mode)) {
950 +               real_bdev = inode->i_bdev;
951 +               vr->vr_device = real_bdev;
952 +               __iget(real_bdev->bd_inode);
953 +       } else
954 +               goto out_fput;
955 +
956 +       vxdprintk(VXD_CBIT(misc, 0),
957 +               "vroot[%d]_set_dev: dev=" VXF_DEV,
958 +               vr->vr_number, VXD_DEV(real_bdev));
959 +
960 +       vr->vr_state = Vr_bound;
961 +       error = 0;
962 +
963 + out_fput:
964 +       fput(file);
965 + out:
966 +       return error;
967 +}
968 +
969 +static int vroot_clr_dev(
970 +       struct vroot_device *vr,
971 +       struct block_device *bdev)
972 +{
973 +       struct block_device *real_bdev;
974 +
975 +       if (vr->vr_state != Vr_bound)
976 +               return -ENXIO;
977 +       if (vr->vr_refcnt > 1)  /* we needed one fd for the ioctl */
978 +               return -EBUSY;
979 +
980 +       real_bdev = vr->vr_device;
981 +
982 +       vxdprintk(VXD_CBIT(misc, 0),
983 +               "vroot[%d]_clr_dev: dev=" VXF_DEV,
984 +               vr->vr_number, VXD_DEV(real_bdev));
985 +
986 +       bdput(real_bdev);
987 +       vr->vr_state = Vr_unbound;
988 +       vr->vr_device = NULL;
989 +       return 0;
990 +}
991 +
992 +
993 +static int vr_ioctl(struct block_device *bdev, fmode_t mode,
994 +       unsigned int cmd, unsigned long arg)
995 +{
996 +       struct vroot_device *vr = bdev->bd_disk->private_data;
997 +       int err;
998 +
999 +       down(&vr->vr_ctl_mutex);
1000 +       switch (cmd) {
1001 +       case VROOT_SET_DEV:
1002 +               err = vroot_set_dev(vr, bdev, arg);
1003 +               break;
1004 +       case VROOT_CLR_DEV:
1005 +               err = vroot_clr_dev(vr, bdev);
1006 +               break;
1007 +       default:
1008 +               err = -EINVAL;
1009 +               break;
1010 +       }
1011 +       up(&vr->vr_ctl_mutex);
1012 +       return err;
1013 +}
1014 +
1015 +static int vr_open(struct block_device *bdev, fmode_t mode)
1016 +{
1017 +       struct vroot_device *vr = bdev->bd_disk->private_data;
1018 +
1019 +       down(&vr->vr_ctl_mutex);
1020 +       vr->vr_refcnt++;
1021 +       up(&vr->vr_ctl_mutex);
1022 +       return 0;
1023 +}
1024 +
1025 +static int vr_release(struct gendisk *disk, fmode_t mode)
1026 +{
1027 +       struct vroot_device *vr = disk->private_data;
1028 +
1029 +       down(&vr->vr_ctl_mutex);
1030 +       --vr->vr_refcnt;
1031 +       up(&vr->vr_ctl_mutex);
1032 +       return 0;
1033 +}
1034 +
1035 +static struct block_device_operations vr_fops = {
1036 +       .owner =        THIS_MODULE,
1037 +       .open =         vr_open,
1038 +       .release =      vr_release,
1039 +       .ioctl =        vr_ioctl,
1040 +};
1041 +
1042 +static void vroot_make_request(struct request_queue *q, struct bio *bio)
1043 +{
1044 +       printk("vroot_make_request %p, %p\n", q, bio);
1045 +       bio_io_error(bio);
1046 +}
1047 +
1048 +struct block_device *__vroot_get_real_bdev(struct block_device *bdev)
1049 +{
1050 +       struct inode *inode = bdev->bd_inode;
1051 +       struct vroot_device *vr;
1052 +       struct block_device *real_bdev;
1053 +       int minor = iminor(inode);
1054 +
1055 +       vr = &vroot_dev[minor];
1056 +       real_bdev = vr->vr_device;
1057 +
1058 +       vxdprintk(VXD_CBIT(misc, 0),
1059 +               "vroot[%d]_get_real_bdev: dev=" VXF_DEV,
1060 +               vr->vr_number, VXD_DEV(real_bdev));
1061 +
1062 +       if (vr->vr_state != Vr_bound)
1063 +               return ERR_PTR(-ENXIO);
1064 +
1065 +       __iget(real_bdev->bd_inode);
1066 +       return real_bdev;
1067 +}
1068 +
1069 +
1070 +
1071 +/*
1072 + * And now the modules code and kernel interface.
1073 + */
1074 +
1075 +module_param(max_vroot, int, 0);
1076 +
1077 +MODULE_PARM_DESC(max_vroot, "Maximum number of vroot devices (1-256)");
1078 +MODULE_LICENSE("GPL");
1079 +MODULE_ALIAS_BLOCKDEV_MAJOR(VROOT_MAJOR);
1080 +
1081 +MODULE_AUTHOR ("Herbert Pötzl");
1082 +MODULE_DESCRIPTION ("Virtual Root Device Mapper");
1083 +
1084 +
1085 +int __init vroot_init(void)
1086 +{
1087 +       int err, i;
1088 +
1089 +       if (max_vroot < 1 || max_vroot > 256) {
1090 +               max_vroot = MAX_VROOT_DEFAULT;
1091 +               printk(KERN_WARNING "vroot: invalid max_vroot "
1092 +                       "(must be between 1 and 256), "
1093 +                       "using default (%d)\n", max_vroot);
1094 +       }
1095 +
1096 +       if (register_blkdev(VROOT_MAJOR, "vroot"))
1097 +               return -EIO;
1098 +
1099 +       err = -ENOMEM;
1100 +       vroot_dev = kmalloc(max_vroot * sizeof(struct vroot_device), GFP_KERNEL);
1101 +       if (!vroot_dev)
1102 +               goto out_mem1;
1103 +       memset(vroot_dev, 0, max_vroot * sizeof(struct vroot_device));
1104 +
1105 +       disks = kmalloc(max_vroot * sizeof(struct gendisk *), GFP_KERNEL);
1106 +       if (!disks)
1107 +               goto out_mem2;
1108 +
1109 +       for (i = 0; i < max_vroot; i++) {
1110 +               disks[i] = alloc_disk(1);
1111 +               if (!disks[i])
1112 +                       goto out_mem3;
1113 +               disks[i]->queue = blk_alloc_queue(GFP_KERNEL);
1114 +               if (!disks[i]->queue)
1115 +                       goto out_mem3;
1116 +               blk_queue_make_request(disks[i]->queue, vroot_make_request);
1117 +       }
1118 +
1119 +       for (i = 0; i < max_vroot; i++) {
1120 +               struct vroot_device *vr = &vroot_dev[i];
1121 +               struct gendisk *disk = disks[i];
1122 +
1123 +               memset(vr, 0, sizeof(*vr));
1124 +               sema_init(&vr->vr_ctl_mutex, 1);
1125 +               vr->vr_number = i;
1126 +               disk->major = VROOT_MAJOR;
1127 +               disk->first_minor = i;
1128 +               disk->fops = &vr_fops;
1129 +               sprintf(disk->disk_name, "vroot%d", i);
1130 +               disk->private_data = vr;
1131 +       }
1132 +
1133 +       err = register_vroot_grb(&__vroot_get_real_bdev);
1134 +       if (err)
1135 +               goto out_mem3;
1136 +
1137 +       for (i = 0; i < max_vroot; i++)
1138 +               add_disk(disks[i]);
1139 +       printk(KERN_INFO "vroot: loaded (max %d devices)\n", max_vroot);
1140 +       return 0;
1141 +
1142 +out_mem3:
1143 +       while (i--)
1144 +               put_disk(disks[i]);
1145 +       kfree(disks);
1146 +out_mem2:
1147 +       kfree(vroot_dev);
1148 +out_mem1:
1149 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1150 +       printk(KERN_ERR "vroot: ran out of memory\n");
1151 +       return err;
1152 +}
1153 +
1154 +void vroot_exit(void)
1155 +{
1156 +       int i;
1157 +
1158 +       if (unregister_vroot_grb(&__vroot_get_real_bdev))
1159 +               printk(KERN_WARNING "vroot: cannot unregister grb\n");
1160 +
1161 +       for (i = 0; i < max_vroot; i++) {
1162 +               del_gendisk(disks[i]);
1163 +               put_disk(disks[i]);
1164 +       }
1165 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1166 +
1167 +       kfree(disks);
1168 +       kfree(vroot_dev);
1169 +}
1170 +
1171 +module_init(vroot_init);
1172 +module_exit(vroot_exit);
1173 +
1174 +#ifndef MODULE
1175 +
1176 +static int __init max_vroot_setup(char *str)
1177 +{
1178 +       max_vroot = simple_strtol(str, NULL, 0);
1179 +       return 1;
1180 +}
1181 +
1182 +__setup("max_vroot=", max_vroot_setup);
1183 +
1184 +#endif
1185 +
1186 diff -NurpP --minimal linux-3.9.5/drivers/infiniband/Kconfig linux-3.9.5-vs2.3.6.5/drivers/infiniband/Kconfig
1187 --- linux-3.9.5/drivers/infiniband/Kconfig      2012-12-11 03:30:57.000000000 +0000
1188 +++ linux-3.9.5-vs2.3.6.5/drivers/infiniband/Kconfig    2013-05-31 14:47:11.000000000 +0000
1189 @@ -39,7 +39,7 @@ config INFINIBAND_USER_MEM
1190  config INFINIBAND_ADDR_TRANS
1191         bool
1192         depends on INET
1193 -       depends on !(INFINIBAND = y && IPV6 = m)
1194 +       depends on !(INFINIBAND = y && IPV6 = y)
1195         default y
1196  
1197  source "drivers/infiniband/hw/mthca/Kconfig"
1198 diff -NurpP --minimal linux-3.9.5/drivers/infiniband/core/addr.c linux-3.9.5-vs2.3.6.5/drivers/infiniband/core/addr.c
1199 --- linux-3.9.5/drivers/infiniband/core/addr.c  2012-12-11 03:30:57.000000000 +0000
1200 +++ linux-3.9.5-vs2.3.6.5/drivers/infiniband/core/addr.c        2013-05-31 14:47:11.000000000 +0000
1201 @@ -261,7 +261,7 @@ static int addr6_resolve(struct sockaddr
1202  
1203         if (ipv6_addr_any(&fl6.saddr)) {
1204                 ret = ipv6_dev_get_saddr(&init_net, ip6_dst_idev(dst)->dev,
1205 -                                        &fl6.daddr, 0, &fl6.saddr);
1206 +                                        &fl6.daddr, 0, &fl6.saddr, NULL);
1207                 if (ret)
1208                         goto put;
1209  
1210 diff -NurpP --minimal linux-3.9.5/drivers/md/dm-ioctl.c linux-3.9.5-vs2.3.6.5/drivers/md/dm-ioctl.c
1211 --- linux-3.9.5/drivers/md/dm-ioctl.c   2013-05-31 13:44:59.000000000 +0000
1212 +++ linux-3.9.5-vs2.3.6.5/drivers/md/dm-ioctl.c 2013-05-31 14:47:11.000000000 +0000
1213 @@ -16,6 +16,7 @@
1214  #include <linux/dm-ioctl.h>
1215  #include <linux/hdreg.h>
1216  #include <linux/compat.h>
1217 +#include <linux/vs_context.h>
1218  
1219  #include <asm/uaccess.h>
1220  
1221 @@ -106,7 +107,8 @@ static struct hash_cell *__get_name_cell
1222         unsigned int h = hash_str(str);
1223  
1224         list_for_each_entry (hc, _name_buckets + h, name_list)
1225 -               if (!strcmp(hc->name, str)) {
1226 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1227 +                       !strcmp(hc->name, str)) {
1228                         dm_get(hc->md);
1229                         return hc;
1230                 }
1231 @@ -120,7 +122,8 @@ static struct hash_cell *__get_uuid_cell
1232         unsigned int h = hash_str(str);
1233  
1234         list_for_each_entry (hc, _uuid_buckets + h, uuid_list)
1235 -               if (!strcmp(hc->uuid, str)) {
1236 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1237 +                       !strcmp(hc->uuid, str)) {
1238                         dm_get(hc->md);
1239                         return hc;
1240                 }
1241 @@ -131,13 +134,15 @@ static struct hash_cell *__get_uuid_cell
1242  static struct hash_cell *__get_dev_cell(uint64_t dev)
1243  {
1244         struct mapped_device *md;
1245 -       struct hash_cell *hc;
1246 +       struct hash_cell *hc = NULL;
1247  
1248         md = dm_get_md(huge_decode_dev(dev));
1249         if (!md)
1250                 return NULL;
1251  
1252 -       hc = dm_get_mdptr(md);
1253 +       if (vx_check(dm_get_xid(md), VS_WATCH_P | VS_IDENT))
1254 +               hc = dm_get_mdptr(md);
1255 +
1256         if (!hc) {
1257                 dm_put(md);
1258                 return NULL;
1259 @@ -445,6 +450,9 @@ typedef int (*ioctl_fn)(struct dm_ioctl
1260  
1261  static int remove_all(struct dm_ioctl *param, size_t param_size)
1262  {
1263 +       if (!vx_check(0, VS_ADMIN))
1264 +               return -EPERM;
1265 +
1266         dm_hash_remove_all(1);
1267         param->data_size = 0;
1268         return 0;
1269 @@ -492,6 +500,8 @@ static int list_devices(struct dm_ioctl
1270          */
1271         for (i = 0; i < NUM_BUCKETS; i++) {
1272                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1273 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1274 +                               continue;
1275                         needed += sizeof(struct dm_name_list);
1276                         needed += strlen(hc->name) + 1;
1277                         needed += ALIGN_MASK;
1278 @@ -515,6 +525,8 @@ static int list_devices(struct dm_ioctl
1279          */
1280         for (i = 0; i < NUM_BUCKETS; i++) {
1281                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1282 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1283 +                               continue;
1284                         if (old_nl)
1285                                 old_nl->next = (uint32_t) ((void *) nl -
1286                                                            (void *) old_nl);
1287 @@ -1722,8 +1734,8 @@ static int ctl_ioctl(uint command, struc
1288         size_t input_param_size;
1289         struct dm_ioctl param_kernel;
1290  
1291 -       /* only root can play with this */
1292 -       if (!capable(CAP_SYS_ADMIN))
1293 +       /* only root and certain contexts can play with this */
1294 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_MAPPER))
1295                 return -EACCES;
1296  
1297         if (_IOC_TYPE(command) != DM_IOCTL)
1298 diff -NurpP --minimal linux-3.9.5/drivers/md/dm.c linux-3.9.5-vs2.3.6.5/drivers/md/dm.c
1299 --- linux-3.9.5/drivers/md/dm.c 2013-05-31 13:44:59.000000000 +0000
1300 +++ linux-3.9.5-vs2.3.6.5/drivers/md/dm.c       2013-06-12 23:49:08.000000000 +0000
1301 @@ -19,6 +19,7 @@
1302  #include <linux/idr.h>
1303  #include <linux/hdreg.h>
1304  #include <linux/delay.h>
1305 +#include <linux/vs_base.h>
1306  
1307  #include <trace/events/block.h>
1308  
1309 @@ -125,6 +126,7 @@ struct mapped_device {
1310         rwlock_t map_lock;
1311         atomic_t holders;
1312         atomic_t open_count;
1313 +       vxid_t xid;
1314  
1315         unsigned long flags;
1316  
1317 @@ -317,6 +319,7 @@ int dm_deleting_md(struct mapped_device
1318  static int dm_blk_open(struct block_device *bdev, fmode_t mode)
1319  {
1320         struct mapped_device *md;
1321 +       int ret = -ENXIO;
1322  
1323         spin_lock(&_minor_lock);
1324  
1325 @@ -325,18 +328,19 @@ static int dm_blk_open(struct block_devi
1326                 goto out;
1327  
1328         if (test_bit(DMF_FREEING, &md->flags) ||
1329 -           dm_deleting_md(md)) {
1330 -               md = NULL;
1331 +           dm_deleting_md(md))
1332 +               goto out;
1333 +
1334 +       ret = -EACCES;
1335 +       if (!vx_check(md->xid, VS_IDENT|VS_HOSTID))
1336                 goto out;
1337 -       }
1338  
1339         dm_get(md);
1340         atomic_inc(&md->open_count);
1341 -
1342 +       ret = 0;
1343  out:
1344         spin_unlock(&_minor_lock);
1345 -
1346 -       return md ? 0 : -ENXIO;
1347 +       return ret;
1348  }
1349  
1350  static int dm_blk_close(struct gendisk *disk, fmode_t mode)
1351 @@ -547,6 +551,14 @@ int dm_set_geometry(struct mapped_device
1352         return 0;
1353  }
1354  
1355 +/*
1356 + * Get the xid associated with a dm device
1357 + */
1358 +vxid_t dm_get_xid(struct mapped_device *md)
1359 +{
1360 +       return md->xid;
1361 +}
1362 +
1363  /*-----------------------------------------------------------------
1364   * CRUD START:
1365   *   A more elegant soln is in the works that uses the queue
1366 @@ -1884,6 +1896,7 @@ static struct mapped_device *alloc_dev(i
1367         INIT_LIST_HEAD(&md->uevent_list);
1368         spin_lock_init(&md->uevent_lock);
1369  
1370 +       md->xid = vx_current_xid();
1371         md->queue = blk_alloc_queue(GFP_KERNEL);
1372         if (!md->queue)
1373                 goto bad_queue;
1374 diff -NurpP --minimal linux-3.9.5/drivers/md/dm.h linux-3.9.5-vs2.3.6.5/drivers/md/dm.h
1375 --- linux-3.9.5/drivers/md/dm.h 2013-02-19 13:57:51.000000000 +0000
1376 +++ linux-3.9.5-vs2.3.6.5/drivers/md/dm.h       2013-06-12 23:49:08.000000000 +0000
1377 @@ -46,6 +46,8 @@ struct dm_dev_internal {
1378  struct dm_table;
1379  struct dm_md_mempools;
1380  
1381 +vxid_t dm_get_xid(struct mapped_device *md);
1382 +
1383  /*-----------------------------------------------------------------
1384   * Internal table functions.
1385   *---------------------------------------------------------------*/
1386 diff -NurpP --minimal linux-3.9.5/drivers/net/tun.c linux-3.9.5-vs2.3.6.5/drivers/net/tun.c
1387 --- linux-3.9.5/drivers/net/tun.c       2013-06-11 12:22:38.000000000 +0000
1388 +++ linux-3.9.5-vs2.3.6.5/drivers/net/tun.c     2013-06-12 23:49:08.000000000 +0000
1389 @@ -64,6 +64,7 @@
1390  #include <linux/nsproxy.h>
1391  #include <linux/virtio_net.h>
1392  #include <linux/rcupdate.h>
1393 +#include <linux/vs_network.h>
1394  #include <net/net_namespace.h>
1395  #include <net/netns/generic.h>
1396  #include <net/rtnetlink.h>
1397 @@ -164,6 +165,7 @@ struct tun_struct {
1398         unsigned int            flags;
1399         kuid_t                  owner;
1400         kgid_t                  group;
1401 +       vnid_t                  nid;
1402  
1403         struct net_device       *dev;
1404         netdev_features_t       set_features;
1405 @@ -380,6 +382,7 @@ static inline bool tun_not_capable(struc
1406         return ((uid_valid(tun->owner) && !uid_eq(cred->euid, tun->owner)) ||
1407                   (gid_valid(tun->group) && !in_egroup_p(tun->group))) &&
1408                 !ns_capable(net->user_ns, CAP_NET_ADMIN);
1409 +               /* !cap_raised(current_cap(), CAP_NET_ADMIN) */
1410  }
1411  
1412  static void tun_set_real_num_queues(struct tun_struct *tun)
1413 @@ -1404,6 +1407,7 @@ static void tun_setup(struct net_device
1414  
1415         tun->owner = INVALID_UID;
1416         tun->group = INVALID_GID;
1417 +       tun->nid = nx_current_nid();
1418  
1419         dev->ethtool_ops = &tun_ethtool_ops;
1420         dev->destructor = tun_free_netdev;
1421 @@ -1591,6 +1595,9 @@ static int tun_set_iff(struct net *net,
1422                 if (err < 0)
1423                         return err;
1424  
1425 +               if (!nx_check(tun->nid, VS_IDENT | VS_HOSTID | VS_ADMIN_P))
1426 +                       return -EPERM;
1427 +
1428                 err = tun_attach(tun, file);
1429                 if (err < 0)
1430                         return err;
1431 @@ -1605,7 +1612,7 @@ static int tun_set_iff(struct net *net,
1432                 int queues = ifr->ifr_flags & IFF_MULTI_QUEUE ?
1433                              MAX_TAP_QUEUES : 1;
1434  
1435 -               if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
1436 +               if (!vx_ns_capable(net->user_ns, CAP_NET_ADMIN, NXC_TUN_CREATE))
1437                         return -EPERM;
1438                 err = security_tun_dev_create();
1439                 if (err < 0)
1440 @@ -1950,6 +1957,16 @@ static long __tun_chr_ioctl(struct file
1441                           from_kgid(&init_user_ns, tun->group));
1442                 break;
1443  
1444 +       case TUNSETNID:
1445 +               if (!capable(CAP_CONTEXT))
1446 +                       return -EPERM;
1447 +
1448 +               /* Set nid owner of the device */
1449 +               tun->nid = (vnid_t) arg;
1450 +
1451 +               tun_debug(KERN_INFO, tun, "nid owner set to %u\n", tun->nid);
1452 +               break;
1453 +
1454         case TUNSETLINK:
1455                 /* Only allow setting the type when the interface is down */
1456                 if (tun->dev->flags & IFF_UP) {
1457 diff -NurpP --minimal linux-3.9.5/drivers/tty/sysrq.c linux-3.9.5-vs2.3.6.5/drivers/tty/sysrq.c
1458 --- linux-3.9.5/drivers/tty/sysrq.c     2013-05-31 13:45:19.000000000 +0000
1459 +++ linux-3.9.5-vs2.3.6.5/drivers/tty/sysrq.c   2013-05-31 15:08:19.000000000 +0000
1460 @@ -43,6 +43,7 @@
1461  #include <linux/input.h>
1462  #include <linux/uaccess.h>
1463  #include <linux/moduleparam.h>
1464 +#include <linux/vserver/debug.h>
1465  
1466  #include <asm/ptrace.h>
1467  #include <asm/irq_regs.h>
1468 @@ -401,6 +402,21 @@ static struct sysrq_key_op sysrq_unrt_op
1469         .enable_mask    = SYSRQ_ENABLE_RTNICE,
1470  };
1471  
1472 +
1473 +#ifdef CONFIG_VSERVER_DEBUG
1474 +static void sysrq_handle_vxinfo(int key)
1475 +{
1476 +       dump_vx_info_inactive((key == 'x') ? 0 : 1);
1477 +}
1478 +
1479 +static struct sysrq_key_op sysrq_showvxinfo_op = {
1480 +       .handler        = sysrq_handle_vxinfo,
1481 +       .help_msg       = "conteXt",
1482 +       .action_msg     = "Show Context Info",
1483 +       .enable_mask    = SYSRQ_ENABLE_DUMP,
1484 +};
1485 +#endif
1486 +
1487  /* Key Operations table and lock */
1488  static DEFINE_SPINLOCK(sysrq_key_table_lock);
1489  
1490 @@ -456,7 +472,11 @@ static struct sysrq_key_op *sysrq_key_ta
1491         &sysrq_showstate_blocked_op,    /* w */
1492         /* x: May be registered on ppc/powerpc for xmon */
1493         /* x: May be registered on sparc64 for global PMU dump */
1494 +#ifdef CONFIG_VSERVER_DEBUG
1495 +       &sysrq_showvxinfo_op,           /* x */
1496 +#else
1497         NULL,                           /* x */
1498 +#endif
1499         /* y: May be registered on sparc64 for global register dump */
1500         NULL,                           /* y */
1501         &sysrq_ftrace_dump_op,          /* z */
1502 @@ -471,6 +491,8 @@ static int sysrq_key_table_key2index(int
1503                 retval = key - '0';
1504         else if ((key >= 'a') && (key <= 'z'))
1505                 retval = key + 10 - 'a';
1506 +       else if ((key >= 'A') && (key <= 'Z'))
1507 +               retval = key + 10 - 'A';
1508         else
1509                 retval = -1;
1510         return retval;
1511 diff -NurpP --minimal linux-3.9.5/drivers/tty/tty_io.c linux-3.9.5-vs2.3.6.5/drivers/tty/tty_io.c
1512 --- linux-3.9.5/drivers/tty/tty_io.c    2013-06-11 12:22:39.000000000 +0000
1513 +++ linux-3.9.5-vs2.3.6.5/drivers/tty/tty_io.c  2013-05-31 14:47:11.000000000 +0000
1514 @@ -104,6 +104,7 @@
1515  
1516  #include <linux/kmod.h>
1517  #include <linux/nsproxy.h>
1518 +#include <linux/vs_pid.h>
1519  
1520  #undef TTY_DEBUG_HANGUP
1521  
1522 @@ -2144,7 +2145,8 @@ static int tiocsti(struct tty_struct *tt
1523         char ch, mbz = 0;
1524         struct tty_ldisc *ld;
1525  
1526 -       if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN))
1527 +       if (((current->signal->tty != tty) &&
1528 +               !vx_capable(CAP_SYS_ADMIN, VXC_TIOCSTI)))
1529                 return -EPERM;
1530         if (get_user(ch, p))
1531                 return -EFAULT;
1532 @@ -2432,6 +2434,7 @@ static int tiocspgrp(struct tty_struct *
1533                 return -ENOTTY;
1534         if (get_user(pgrp_nr, p))
1535                 return -EFAULT;
1536 +       pgrp_nr = vx_rmap_pid(pgrp_nr);
1537         if (pgrp_nr < 0)
1538                 return -EINVAL;
1539         rcu_read_lock();
1540 diff -NurpP --minimal linux-3.9.5/fs/attr.c linux-3.9.5-vs2.3.6.5/fs/attr.c
1541 --- linux-3.9.5/fs/attr.c       2013-02-19 13:58:46.000000000 +0000
1542 +++ linux-3.9.5-vs2.3.6.5/fs/attr.c     2013-05-31 14:47:11.000000000 +0000
1543 @@ -15,6 +15,9 @@
1544  #include <linux/security.h>
1545  #include <linux/evm.h>
1546  #include <linux/ima.h>
1547 +#include <linux/proc_fs.h>
1548 +#include <linux/devpts_fs.h>
1549 +#include <linux/vs_tag.h>
1550  
1551  /**
1552   * inode_change_ok - check if attribute changes to an inode are allowed
1553 @@ -77,6 +80,10 @@ int inode_change_ok(const struct inode *
1554                         return -EPERM;
1555         }
1556  
1557 +       /* check for inode tag permission */
1558 +       if (dx_permission(inode, MAY_WRITE))
1559 +               return -EACCES;
1560 +
1561         return 0;
1562  }
1563  EXPORT_SYMBOL(inode_change_ok);
1564 @@ -147,6 +154,8 @@ void setattr_copy(struct inode *inode, c
1565                 inode->i_uid = attr->ia_uid;
1566         if (ia_valid & ATTR_GID)
1567                 inode->i_gid = attr->ia_gid;
1568 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
1569 +               inode->i_tag = attr->ia_tag;
1570         if (ia_valid & ATTR_ATIME)
1571                 inode->i_atime = timespec_trunc(attr->ia_atime,
1572                                                 inode->i_sb->s_time_gran);
1573 @@ -177,7 +186,8 @@ int notify_change(struct dentry * dentry
1574  
1575         WARN_ON_ONCE(!mutex_is_locked(&inode->i_mutex));
1576  
1577 -       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_TIMES_SET)) {
1578 +       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID |
1579 +               ATTR_TAG | ATTR_TIMES_SET)) {
1580                 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
1581                         return -EPERM;
1582         }
1583 diff -NurpP --minimal linux-3.9.5/fs/block_dev.c linux-3.9.5-vs2.3.6.5/fs/block_dev.c
1584 --- linux-3.9.5/fs/block_dev.c  2013-05-31 13:45:22.000000000 +0000
1585 +++ linux-3.9.5-vs2.3.6.5/fs/block_dev.c        2013-05-31 14:47:11.000000000 +0000
1586 @@ -27,6 +27,7 @@
1587  #include <linux/namei.h>
1588  #include <linux/log2.h>
1589  #include <linux/cleancache.h>
1590 +#include <linux/vs_device.h>
1591  #include <asm/uaccess.h>
1592  #include "internal.h"
1593  
1594 @@ -528,6 +529,7 @@ struct block_device *bdget(dev_t dev)
1595                 bdev->bd_invalidated = 0;
1596                 inode->i_mode = S_IFBLK;
1597                 inode->i_rdev = dev;
1598 +               inode->i_mdev = dev;
1599                 inode->i_bdev = bdev;
1600                 inode->i_data.a_ops = &def_blk_aops;
1601                 mapping_set_gfp_mask(&inode->i_data, GFP_USER);
1602 @@ -575,6 +577,11 @@ EXPORT_SYMBOL(bdput);
1603  static struct block_device *bd_acquire(struct inode *inode)
1604  {
1605         struct block_device *bdev;
1606 +       dev_t mdev;
1607 +
1608 +       if (!vs_map_blkdev(inode->i_rdev, &mdev, DATTR_OPEN))
1609 +               return NULL;
1610 +       inode->i_mdev = mdev;
1611  
1612         spin_lock(&bdev_lock);
1613         bdev = inode->i_bdev;
1614 @@ -585,7 +592,7 @@ static struct block_device *bd_acquire(s
1615         }
1616         spin_unlock(&bdev_lock);
1617  
1618 -       bdev = bdget(inode->i_rdev);
1619 +       bdev = bdget(mdev);
1620         if (bdev) {
1621                 spin_lock(&bdev_lock);
1622                 if (!inode->i_bdev) {
1623 diff -NurpP --minimal linux-3.9.5/fs/btrfs/ctree.h linux-3.9.5-vs2.3.6.5/fs/btrfs/ctree.h
1624 --- linux-3.9.5/fs/btrfs/ctree.h        2013-05-31 13:45:22.000000000 +0000
1625 +++ linux-3.9.5-vs2.3.6.5/fs/btrfs/ctree.h      2013-05-31 14:47:11.000000000 +0000
1626 @@ -705,11 +705,14 @@ struct btrfs_inode_item {
1627         /* modification sequence number for NFS */
1628         __le64 sequence;
1629  
1630 +       __le16 tag;
1631         /*
1632          * a little future expansion, for more than this we can
1633          * just grow the inode item and version it
1634          */
1635 -       __le64 reserved[4];
1636 +       __le16 reserved16;
1637 +       __le32 reserved32;
1638 +       __le64 reserved[3];
1639         struct btrfs_timespec atime;
1640         struct btrfs_timespec ctime;
1641         struct btrfs_timespec mtime;
1642 @@ -1901,6 +1904,8 @@ struct btrfs_ioctl_defrag_range_args {
1643  #define BTRFS_MOUNT_CHECK_INTEGRITY_INCLUDING_EXTENT_DATA (1 << 21)
1644  #define BTRFS_MOUNT_PANIC_ON_FATAL_ERROR       (1 << 22)
1645  
1646 +#define BTRFS_MOUNT_TAGGED             (1 << 24)
1647 +
1648  #define btrfs_clear_opt(o, opt)                ((o) &= ~BTRFS_MOUNT_##opt)
1649  #define btrfs_set_opt(o, opt)          ((o) |= BTRFS_MOUNT_##opt)
1650  #define btrfs_raw_test_opt(o, opt)     ((o) & BTRFS_MOUNT_##opt)
1651 @@ -2170,6 +2175,7 @@ BTRFS_SETGET_FUNCS(inode_block_group, st
1652  BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
1653  BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
1654  BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
1655 +BTRFS_SETGET_FUNCS(inode_tag, struct btrfs_inode_item, tag, 16);
1656  BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
1657  BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
1658  BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
1659 @@ -2223,6 +2229,10 @@ BTRFS_SETGET_FUNCS(extent_flags, struct
1660  
1661  BTRFS_SETGET_FUNCS(extent_refs_v0, struct btrfs_extent_item_v0, refs, 32);
1662  
1663 +#define BTRFS_INODE_IXUNLINK           (1 << 24)
1664 +#define BTRFS_INODE_BARRIER            (1 << 25)
1665 +#define BTRFS_INODE_COW                        (1 << 26)
1666 +
1667  
1668  BTRFS_SETGET_FUNCS(tree_block_level, struct btrfs_tree_block_info, level, 8);
1669  
1670 @@ -3581,6 +3591,7 @@ extern const struct dentry_operations bt
1671  long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
1672  void btrfs_update_iflags(struct inode *inode);
1673  void btrfs_inherit_iflags(struct inode *inode, struct inode *dir);
1674 +int btrfs_sync_flags(struct inode *inode, int, int);
1675  int btrfs_defrag_file(struct inode *inode, struct file *file,
1676                       struct btrfs_ioctl_defrag_range_args *range,
1677                       u64 newer_than, unsigned long max_pages);
1678 diff -NurpP --minimal linux-3.9.5/fs/btrfs/disk-io.c linux-3.9.5-vs2.3.6.5/fs/btrfs/disk-io.c
1679 --- linux-3.9.5/fs/btrfs/disk-io.c      2013-05-31 13:45:22.000000000 +0000
1680 +++ linux-3.9.5-vs2.3.6.5/fs/btrfs/disk-io.c    2013-05-31 14:47:11.000000000 +0000
1681 @@ -2258,6 +2258,9 @@ int open_ctree(struct super_block *sb,
1682                 goto fail_alloc;
1683         }
1684  
1685 +       if (btrfs_test_opt(tree_root, TAGGED))
1686 +               sb->s_flags |= MS_TAGGED;
1687 +
1688         features = btrfs_super_incompat_flags(disk_super) &
1689                 ~BTRFS_FEATURE_INCOMPAT_SUPP;
1690         if (features) {
1691 diff -NurpP --minimal linux-3.9.5/fs/btrfs/inode.c linux-3.9.5-vs2.3.6.5/fs/btrfs/inode.c
1692 --- linux-3.9.5/fs/btrfs/inode.c        2013-06-11 12:22:39.000000000 +0000
1693 +++ linux-3.9.5-vs2.3.6.5/fs/btrfs/inode.c      2013-06-03 19:37:03.000000000 +0000
1694 @@ -41,6 +41,7 @@
1695  #include <linux/mount.h>
1696  #include <linux/btrfs.h>
1697  #include <linux/blkdev.h>
1698 +#include <linux/vs_tag.h>
1699  #include "compat.h"
1700  #include "ctree.h"
1701  #include "disk-io.h"
1702 @@ -3312,6 +3313,9 @@ static void btrfs_read_locked_inode(stru
1703         struct btrfs_key location;
1704         int maybe_acls;
1705         u32 rdev;
1706 +       kuid_t kuid;
1707 +       kgid_t kgid;
1708 +       ktag_t ktag;
1709         int ret;
1710         bool filled = false;
1711  
1712 @@ -3339,8 +3343,14 @@ static void btrfs_read_locked_inode(stru
1713                                     struct btrfs_inode_item);
1714         inode->i_mode = btrfs_inode_mode(leaf, inode_item);
1715         set_nlink(inode, btrfs_inode_nlink(leaf, inode_item));
1716 -       i_uid_write(inode, btrfs_inode_uid(leaf, inode_item));
1717 -       i_gid_write(inode, btrfs_inode_gid(leaf, inode_item));
1718 +
1719 +       kuid = make_kuid(&init_user_ns, btrfs_inode_uid(leaf, inode_item));
1720 +       kgid = make_kgid(&init_user_ns, btrfs_inode_gid(leaf, inode_item));
1721 +       ktag = make_ktag(&init_user_ns, btrfs_inode_tag(leaf, inode_item));
1722 +
1723 +       inode->i_uid = INOTAG_KUID(DX_TAG(inode), kuid, kgid);
1724 +       inode->i_gid = INOTAG_KGID(DX_TAG(inode), kuid, kgid);
1725 +       inode->i_tag = INOTAG_KTAG(DX_TAG(inode), kuid, kgid, ktag);
1726         btrfs_i_size_write(inode, btrfs_inode_size(leaf, inode_item));
1727  
1728         tspec = btrfs_inode_atime(inode_item);
1729 @@ -3431,11 +3441,18 @@ static void fill_inode_item(struct btrfs
1730                             struct inode *inode)
1731  {
1732         struct btrfs_map_token token;
1733 +       uid_t uid = from_kuid(&init_user_ns,
1734 +               TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag));
1735 +       gid_t gid = from_kgid(&init_user_ns,
1736 +               TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag));
1737  
1738         btrfs_init_map_token(&token);
1739  
1740 -       btrfs_set_token_inode_uid(leaf, item, i_uid_read(inode), &token);
1741 -       btrfs_set_token_inode_gid(leaf, item, i_gid_read(inode), &token);
1742 +       btrfs_set_token_inode_uid(leaf, item, uid, &token);
1743 +       btrfs_set_token_inode_gid(leaf, item, gid, &token);
1744 +#ifdef CONFIG_TAGGING_INTERN
1745 +       btrfs_set_token_inode_tag(leaf, item, i_tag_read(inode), &token);
1746 +#endif
1747         btrfs_set_token_inode_size(leaf, item, BTRFS_I(inode)->disk_i_size,
1748                                    &token);
1749         btrfs_set_token_inode_mode(leaf, item, inode->i_mode, &token);
1750 @@ -8683,11 +8700,13 @@ static const struct inode_operations btr
1751         .listxattr      = btrfs_listxattr,
1752         .removexattr    = btrfs_removexattr,
1753         .permission     = btrfs_permission,
1754 +       .sync_flags     = btrfs_sync_flags,
1755         .get_acl        = btrfs_get_acl,
1756  };
1757  static const struct inode_operations btrfs_dir_ro_inode_operations = {
1758         .lookup         = btrfs_lookup,
1759         .permission     = btrfs_permission,
1760 +       .sync_flags     = btrfs_sync_flags,
1761         .get_acl        = btrfs_get_acl,
1762  };
1763  
1764 diff -NurpP --minimal linux-3.9.5/fs/btrfs/ioctl.c linux-3.9.5-vs2.3.6.5/fs/btrfs/ioctl.c
1765 --- linux-3.9.5/fs/btrfs/ioctl.c        2013-06-11 12:22:39.000000000 +0000
1766 +++ linux-3.9.5-vs2.3.6.5/fs/btrfs/ioctl.c      2013-05-31 14:47:11.000000000 +0000
1767 @@ -75,10 +75,13 @@ static unsigned int btrfs_flags_to_ioctl
1768  {
1769         unsigned int iflags = 0;
1770  
1771 -       if (flags & BTRFS_INODE_SYNC)
1772 -               iflags |= FS_SYNC_FL;
1773         if (flags & BTRFS_INODE_IMMUTABLE)
1774                 iflags |= FS_IMMUTABLE_FL;
1775 +       if (flags & BTRFS_INODE_IXUNLINK)
1776 +               iflags |= FS_IXUNLINK_FL;
1777 +
1778 +       if (flags & BTRFS_INODE_SYNC)
1779 +               iflags |= FS_SYNC_FL;
1780         if (flags & BTRFS_INODE_APPEND)
1781                 iflags |= FS_APPEND_FL;
1782         if (flags & BTRFS_INODE_NODUMP)
1783 @@ -95,28 +98,78 @@ static unsigned int btrfs_flags_to_ioctl
1784         else if (flags & BTRFS_INODE_NOCOMPRESS)
1785                 iflags |= FS_NOCOMP_FL;
1786  
1787 +       if (flags & BTRFS_INODE_BARRIER)
1788 +               iflags |= FS_BARRIER_FL;
1789 +       if (flags & BTRFS_INODE_COW)
1790 +               iflags |= FS_COW_FL;
1791         return iflags;
1792  }
1793  
1794  /*
1795 - * Update inode->i_flags based on the btrfs internal flags.
1796 + * Update inode->i_(v)flags based on the btrfs internal flags.
1797   */
1798  void btrfs_update_iflags(struct inode *inode)
1799  {
1800         struct btrfs_inode *ip = BTRFS_I(inode);
1801  
1802 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
1803 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
1804 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
1805  
1806 -       if (ip->flags & BTRFS_INODE_SYNC)
1807 -               inode->i_flags |= S_SYNC;
1808         if (ip->flags & BTRFS_INODE_IMMUTABLE)
1809                 inode->i_flags |= S_IMMUTABLE;
1810 +       if (ip->flags & BTRFS_INODE_IXUNLINK)
1811 +               inode->i_flags |= S_IXUNLINK;
1812 +
1813 +       if (ip->flags & BTRFS_INODE_SYNC)
1814 +               inode->i_flags |= S_SYNC;
1815         if (ip->flags & BTRFS_INODE_APPEND)
1816                 inode->i_flags |= S_APPEND;
1817         if (ip->flags & BTRFS_INODE_NOATIME)
1818                 inode->i_flags |= S_NOATIME;
1819         if (ip->flags & BTRFS_INODE_DIRSYNC)
1820                 inode->i_flags |= S_DIRSYNC;
1821 +
1822 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
1823 +
1824 +       if (ip->flags & BTRFS_INODE_BARRIER)
1825 +               inode->i_vflags |= V_BARRIER;
1826 +       if (ip->flags & BTRFS_INODE_COW)
1827 +               inode->i_vflags |= V_COW;
1828 +}
1829 +
1830 +/*
1831 + * Update btrfs internal flags from inode->i_(v)flags.
1832 + */
1833 +void btrfs_update_flags(struct inode *inode)
1834 +{
1835 +       struct btrfs_inode *ip = BTRFS_I(inode);
1836 +
1837 +       unsigned int flags = inode->i_flags;
1838 +       unsigned int vflags = inode->i_vflags;
1839 +
1840 +       ip->flags &= ~(BTRFS_INODE_SYNC | BTRFS_INODE_APPEND |
1841 +                       BTRFS_INODE_IMMUTABLE | BTRFS_INODE_IXUNLINK |
1842 +                       BTRFS_INODE_NOATIME | BTRFS_INODE_DIRSYNC |
1843 +                       BTRFS_INODE_BARRIER | BTRFS_INODE_COW);
1844 +
1845 +       if (flags & S_IMMUTABLE)
1846 +               ip->flags |= BTRFS_INODE_IMMUTABLE;
1847 +       if (flags & S_IXUNLINK)
1848 +               ip->flags |= BTRFS_INODE_IXUNLINK;
1849 +
1850 +       if (flags & S_SYNC)
1851 +               ip->flags |= BTRFS_INODE_SYNC;
1852 +       if (flags & S_APPEND)
1853 +               ip->flags |= BTRFS_INODE_APPEND;
1854 +       if (flags & S_NOATIME)
1855 +               ip->flags |= BTRFS_INODE_NOATIME;
1856 +       if (flags & S_DIRSYNC)
1857 +               ip->flags |= BTRFS_INODE_DIRSYNC;
1858 +
1859 +       if (vflags & V_BARRIER)
1860 +               ip->flags |= BTRFS_INODE_BARRIER;
1861 +       if (vflags & V_COW)
1862 +               ip->flags |= BTRFS_INODE_COW;
1863  }
1864  
1865  /*
1866 @@ -132,6 +185,7 @@ void btrfs_inherit_iflags(struct inode *
1867                 return;
1868  
1869         flags = BTRFS_I(dir)->flags;
1870 +       flags &= ~BTRFS_INODE_BARRIER;
1871  
1872         if (flags & BTRFS_INODE_NOCOMPRESS) {
1873                 BTRFS_I(inode)->flags &= ~BTRFS_INODE_COMPRESS;
1874 @@ -150,6 +204,30 @@ void btrfs_inherit_iflags(struct inode *
1875         btrfs_update_iflags(inode);
1876  }
1877  
1878 +int btrfs_sync_flags(struct inode *inode, int flags, int vflags)
1879 +{
1880 +       struct btrfs_inode *ip = BTRFS_I(inode);
1881 +       struct btrfs_root *root = ip->root;
1882 +       struct btrfs_trans_handle *trans;
1883 +       int ret;
1884 +
1885 +       trans = btrfs_join_transaction(root);
1886 +       BUG_ON(!trans);
1887 +
1888 +       inode->i_flags = flags;
1889 +       inode->i_vflags = vflags;
1890 +       btrfs_update_flags(inode);
1891 +
1892 +       ret = btrfs_update_inode(trans, root, inode);
1893 +       BUG_ON(ret);
1894 +
1895 +       btrfs_update_iflags(inode);
1896 +       inode->i_ctime = CURRENT_TIME;
1897 +       btrfs_end_transaction(trans, root);
1898 +
1899 +       return 0;
1900 +}
1901 +
1902  static int btrfs_ioctl_getflags(struct file *file, void __user *arg)
1903  {
1904         struct btrfs_inode *ip = BTRFS_I(file_inode(file));
1905 @@ -212,21 +290,27 @@ static int btrfs_ioctl_setflags(struct f
1906  
1907         flags = btrfs_mask_flags(inode->i_mode, flags);
1908         oldflags = btrfs_flags_to_ioctl(ip->flags);
1909 -       if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) {
1910 +       if ((flags ^ oldflags) & (FS_APPEND_FL |
1911 +               FS_IMMUTABLE_FL | FS_IXUNLINK_FL)) {
1912                 if (!capable(CAP_LINUX_IMMUTABLE)) {
1913                         ret = -EPERM;
1914                         goto out_unlock;
1915                 }
1916         }
1917  
1918 -       if (flags & FS_SYNC_FL)
1919 -               ip->flags |= BTRFS_INODE_SYNC;
1920 -       else
1921 -               ip->flags &= ~BTRFS_INODE_SYNC;
1922         if (flags & FS_IMMUTABLE_FL)
1923                 ip->flags |= BTRFS_INODE_IMMUTABLE;
1924         else
1925                 ip->flags &= ~BTRFS_INODE_IMMUTABLE;
1926 +       if (flags & FS_IXUNLINK_FL)
1927 +               ip->flags |= BTRFS_INODE_IXUNLINK;
1928 +       else
1929 +               ip->flags &= ~BTRFS_INODE_IXUNLINK;
1930 +
1931 +       if (flags & FS_SYNC_FL)
1932 +               ip->flags |= BTRFS_INODE_SYNC;
1933 +       else
1934 +               ip->flags &= ~BTRFS_INODE_SYNC;
1935         if (flags & FS_APPEND_FL)
1936                 ip->flags |= BTRFS_INODE_APPEND;
1937         else
1938 diff -NurpP --minimal linux-3.9.5/fs/btrfs/super.c linux-3.9.5-vs2.3.6.5/fs/btrfs/super.c
1939 --- linux-3.9.5/fs/btrfs/super.c        2013-05-31 13:45:22.000000000 +0000
1940 +++ linux-3.9.5-vs2.3.6.5/fs/btrfs/super.c      2013-05-31 14:47:11.000000000 +0000
1941 @@ -321,7 +321,7 @@ enum {
1942         Opt_no_space_cache, Opt_recovery, Opt_skip_balance,
1943         Opt_check_integrity, Opt_check_integrity_including_extent_data,
1944         Opt_check_integrity_print_mask, Opt_fatal_errors,
1945 -       Opt_err,
1946 +       Opt_tag, Opt_notag, Opt_tagid, Opt_err,
1947  };
1948  
1949  static match_table_t tokens = {
1950 @@ -361,6 +361,9 @@ static match_table_t tokens = {
1951         {Opt_check_integrity_including_extent_data, "check_int_data"},
1952         {Opt_check_integrity_print_mask, "check_int_print_mask=%d"},
1953         {Opt_fatal_errors, "fatal_errors=%s"},
1954 +       {Opt_tag, "tag"},
1955 +       {Opt_notag, "notag"},
1956 +       {Opt_tagid, "tagid=%u"},
1957         {Opt_err, NULL},
1958  };
1959  
1960 @@ -626,6 +629,22 @@ int btrfs_parse_options(struct btrfs_roo
1961                                 goto out;
1962                         }
1963                         break;
1964 +#ifndef CONFIG_TAGGING_NONE
1965 +               case Opt_tag:
1966 +                       printk(KERN_INFO "btrfs: use tagging\n");
1967 +                       btrfs_set_opt(info->mount_opt, TAGGED);
1968 +                       break;
1969 +               case Opt_notag:
1970 +                       printk(KERN_INFO "btrfs: disabled tagging\n");
1971 +                       btrfs_clear_opt(info->mount_opt, TAGGED);
1972 +                       break;
1973 +#endif
1974 +#ifdef CONFIG_PROPAGATE
1975 +               case Opt_tagid:
1976 +                       /* use args[0] */
1977 +                       btrfs_set_opt(info->mount_opt, TAGGED);
1978 +                       break;
1979 +#endif
1980                 case Opt_err:
1981                         printk(KERN_INFO "btrfs: unrecognized mount option "
1982                                "'%s'\n", p);
1983 @@ -1258,6 +1277,12 @@ static int btrfs_remount(struct super_bl
1984         btrfs_resize_thread_pool(fs_info,
1985                 fs_info->thread_pool_size, old_thread_pool_size);
1986  
1987 +       if (btrfs_test_opt(root, TAGGED) && !(sb->s_flags & MS_TAGGED)) {
1988 +               printk("btrfs: %s: tagging not permitted on remount.\n",
1989 +                       sb->s_id);
1990 +               return -EINVAL;
1991 +       }
1992 +
1993         if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
1994                 goto out;
1995  
1996 diff -NurpP --minimal linux-3.9.5/fs/char_dev.c linux-3.9.5-vs2.3.6.5/fs/char_dev.c
1997 --- linux-3.9.5/fs/char_dev.c   2012-12-11 03:30:57.000000000 +0000
1998 +++ linux-3.9.5-vs2.3.6.5/fs/char_dev.c 2013-05-31 14:47:11.000000000 +0000
1999 @@ -21,6 +21,8 @@
2000  #include <linux/mutex.h>
2001  #include <linux/backing-dev.h>
2002  #include <linux/tty.h>
2003 +#include <linux/vs_context.h>
2004 +#include <linux/vs_device.h>
2005  
2006  #include "internal.h"
2007  
2008 @@ -371,14 +373,21 @@ static int chrdev_open(struct inode *ino
2009         struct cdev *p;
2010         struct cdev *new = NULL;
2011         int ret = 0;
2012 +       dev_t mdev;
2013 +
2014 +       if (!vs_map_chrdev(inode->i_rdev, &mdev, DATTR_OPEN))
2015 +               return -EPERM;
2016 +       inode->i_mdev = mdev;
2017  
2018         spin_lock(&cdev_lock);
2019         p = inode->i_cdev;
2020         if (!p) {
2021                 struct kobject *kobj;
2022                 int idx;
2023 +
2024                 spin_unlock(&cdev_lock);
2025 -               kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
2026 +
2027 +               kobj = kobj_lookup(cdev_map, mdev, &idx);
2028                 if (!kobj)
2029                         return -ENXIO;
2030                 new = container_of(kobj, struct cdev, kobj);
2031 diff -NurpP --minimal linux-3.9.5/fs/dcache.c linux-3.9.5-vs2.3.6.5/fs/dcache.c
2032 --- linux-3.9.5/fs/dcache.c     2013-06-11 12:22:39.000000000 +0000
2033 +++ linux-3.9.5-vs2.3.6.5/fs/dcache.c   2013-05-31 14:47:11.000000000 +0000
2034 @@ -37,6 +37,7 @@
2035  #include <linux/rculist_bl.h>
2036  #include <linux/prefetch.h>
2037  #include <linux/ratelimit.h>
2038 +#include <linux/vs_limit.h>
2039  #include "internal.h"
2040  #include "mount.h"
2041  
2042 @@ -593,6 +594,8 @@ int d_invalidate(struct dentry * dentry)
2043                 spin_lock(&dentry->d_lock);
2044         }
2045  
2046 +       vx_dentry_dec(dentry);
2047 +
2048         /*
2049          * Somebody else still using it?
2050          *
2051 @@ -622,6 +625,7 @@ EXPORT_SYMBOL(d_invalidate);
2052  static inline void __dget_dlock(struct dentry *dentry)
2053  {
2054         dentry->d_count++;
2055 +       vx_dentry_inc(dentry);
2056  }
2057  
2058  static inline void __dget(struct dentry *dentry)
2059 @@ -1252,6 +1256,9 @@ struct dentry *__d_alloc(struct super_bl
2060         struct dentry *dentry;
2061         char *dname;
2062  
2063 +       if (!vx_dentry_avail(1))
2064 +               return NULL;
2065 +
2066         dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
2067         if (!dentry)
2068                 return NULL;
2069 @@ -1284,6 +1291,7 @@ struct dentry *__d_alloc(struct super_bl
2070  
2071         dentry->d_count = 1;
2072         dentry->d_flags = 0;
2073 +       vx_dentry_inc(dentry);
2074         spin_lock_init(&dentry->d_lock);
2075         seqcount_init(&dentry->d_seq);
2076         dentry->d_inode = NULL;
2077 @@ -1984,6 +1992,7 @@ struct dentry *__d_lookup(const struct d
2078                 }
2079  
2080                 dentry->d_count++;
2081 +               vx_dentry_inc(dentry);
2082                 found = dentry;
2083                 spin_unlock(&dentry->d_lock);
2084                 break;
2085 diff -NurpP --minimal linux-3.9.5/fs/devpts/inode.c linux-3.9.5-vs2.3.6.5/fs/devpts/inode.c
2086 --- linux-3.9.5/fs/devpts/inode.c       2013-05-31 13:45:23.000000000 +0000
2087 +++ linux-3.9.5-vs2.3.6.5/fs/devpts/inode.c     2013-06-12 23:49:08.000000000 +0000
2088 @@ -25,6 +25,7 @@
2089  #include <linux/parser.h>
2090  #include <linux/fsnotify.h>
2091  #include <linux/seq_file.h>
2092 +#include <linux/vs_base.h>
2093  
2094  #define DEVPTS_DEFAULT_MODE 0600
2095  /*
2096 @@ -36,6 +37,21 @@
2097  #define DEVPTS_DEFAULT_PTMX_MODE 0000
2098  #define PTMX_MINOR     2
2099  
2100 +static int devpts_permission(struct inode *inode, int mask)
2101 +{
2102 +       int ret = -EACCES;
2103 +
2104 +       /* devpts is xid tagged */
2105 +       if (vx_check((vxid_t)i_tag_read(inode), VS_WATCH_P | VS_IDENT))
2106 +               ret = generic_permission(inode, mask);
2107 +       return ret;
2108 +}
2109 +
2110 +static struct inode_operations devpts_file_inode_operations = {
2111 +       .permission     = devpts_permission,
2112 +};
2113 +
2114 +
2115  /*
2116   * sysctl support for setting limits on the number of Unix98 ptys allocated.
2117   * Otherwise one can eat up all kernel memory by opening /dev/ptmx repeatedly.
2118 @@ -345,6 +361,34 @@ static int devpts_show_options(struct se
2119         return 0;
2120  }
2121  
2122 +static int devpts_filter(struct dentry *de)
2123 +{
2124 +       vxid_t xid = 0;
2125 +
2126 +       /* devpts is xid tagged */
2127 +       if (de && de->d_inode)
2128 +               xid = (vxid_t)i_tag_read(de->d_inode);
2129 +#ifdef CONFIG_VSERVER_WARN_DEVPTS
2130 +       else
2131 +               vxwprintk_task(1, "devpts " VS_Q("%.*s") " without inode.",
2132 +                       de->d_name.len, de->d_name.name);
2133 +#endif
2134 +       return vx_check(xid, VS_WATCH_P | VS_IDENT);
2135 +}
2136 +
2137 +static int devpts_readdir(struct file * filp, void * dirent, filldir_t filldir)
2138 +{
2139 +       return dcache_readdir_filter(filp, dirent, filldir, devpts_filter);
2140 +}
2141 +
2142 +static struct file_operations devpts_dir_operations = {
2143 +       .open           = dcache_dir_open,
2144 +       .release        = dcache_dir_close,
2145 +       .llseek         = dcache_dir_lseek,
2146 +       .read           = generic_read_dir,
2147 +       .readdir        = devpts_readdir,
2148 +};
2149 +
2150  static const struct super_operations devpts_sops = {
2151         .statfs         = simple_statfs,
2152         .remount_fs     = devpts_remount,
2153 @@ -388,8 +432,10 @@ devpts_fill_super(struct super_block *s,
2154         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2155         inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
2156         inode->i_op = &simple_dir_inode_operations;
2157 -       inode->i_fop = &simple_dir_operations;
2158 +       inode->i_fop = &devpts_dir_operations;
2159         set_nlink(inode, 2);
2160 +       /* devpts is xid tagged */
2161 +       i_tag_write(inode, (vtag_t)vx_current_xid());
2162  
2163         s->s_root = d_make_root(inode);
2164         if (s->s_root)
2165 @@ -592,6 +638,9 @@ struct inode *devpts_pty_new(struct inod
2166         inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
2167         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2168         init_special_inode(inode, S_IFCHR|opts->mode, device);
2169 +       /* devpts is xid tagged */
2170 +       i_tag_write(inode, (vtag_t)vx_current_xid());
2171 +       inode->i_op = &devpts_file_inode_operations;
2172         inode->i_private = priv;
2173  
2174         sprintf(s, "%d", index);
2175 diff -NurpP --minimal linux-3.9.5/fs/ext2/balloc.c linux-3.9.5-vs2.3.6.5/fs/ext2/balloc.c
2176 --- linux-3.9.5/fs/ext2/balloc.c        2013-05-31 13:45:23.000000000 +0000
2177 +++ linux-3.9.5-vs2.3.6.5/fs/ext2/balloc.c      2013-05-31 14:47:11.000000000 +0000
2178 @@ -693,7 +693,6 @@ ext2_try_to_allocate(struct super_block
2179                         start = 0;
2180                 end = EXT2_BLOCKS_PER_GROUP(sb);
2181         }
2182 -
2183         BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
2184  
2185  repeat:
2186 diff -NurpP --minimal linux-3.9.5/fs/ext2/ext2.h linux-3.9.5-vs2.3.6.5/fs/ext2/ext2.h
2187 --- linux-3.9.5/fs/ext2/ext2.h  2012-12-11 03:30:57.000000000 +0000
2188 +++ linux-3.9.5-vs2.3.6.5/fs/ext2/ext2.h        2013-05-31 14:47:11.000000000 +0000
2189 @@ -244,8 +244,12 @@ struct ext2_group_desc
2190  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
2191  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
2192  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
2193 +#define EXT2_IXUNLINK_FL               FS_IXUNLINK_FL  /* Immutable invert on unlink */
2194  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
2195  
2196 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
2197 +#define EXT2_COW_FL                    FS_COW_FL       /* Copy on Write marker */
2198 +
2199  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
2200  #define EXT2_FL_USER_MODIFIABLE                FS_FL_USER_MODIFIABLE   /* User modifiable flags */
2201  
2202 @@ -329,7 +333,8 @@ struct ext2_inode {
2203                         __u16   i_pad1;
2204                         __le16  l_i_uid_high;   /* these 2 fields    */
2205                         __le16  l_i_gid_high;   /* were reserved2[0] */
2206 -                       __u32   l_i_reserved2;
2207 +                       __le16  l_i_tag;        /* Context Tag */
2208 +                       __u16   l_i_reserved2;
2209                 } linux2;
2210                 struct {
2211                         __u8    h_i_frag;       /* Fragment number */
2212 @@ -357,6 +362,7 @@ struct ext2_inode {
2213  #define i_gid_low      i_gid
2214  #define i_uid_high     osd2.linux2.l_i_uid_high
2215  #define i_gid_high     osd2.linux2.l_i_gid_high
2216 +#define i_raw_tag      osd2.linux2.l_i_tag
2217  #define i_reserved2    osd2.linux2.l_i_reserved2
2218  
2219  /*
2220 @@ -384,6 +390,7 @@ struct ext2_inode {
2221  #define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
2222  #define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
2223  #define EXT2_MOUNT_RESERVATION         0x080000  /* Preallocation */
2224 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
2225  
2226  
2227  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
2228 @@ -757,6 +764,7 @@ extern void ext2_set_inode_flags(struct
2229  extern void ext2_get_inode_flags(struct ext2_inode_info *);
2230  extern int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2231                        u64 start, u64 len);
2232 +extern int ext2_sync_flags(struct inode *, int, int);
2233  
2234  /* ioctl.c */
2235  extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
2236 diff -NurpP --minimal linux-3.9.5/fs/ext2/file.c linux-3.9.5-vs2.3.6.5/fs/ext2/file.c
2237 --- linux-3.9.5/fs/ext2/file.c  2012-12-11 03:30:57.000000000 +0000
2238 +++ linux-3.9.5-vs2.3.6.5/fs/ext2/file.c        2013-05-31 14:47:11.000000000 +0000
2239 @@ -104,4 +104,5 @@ const struct inode_operations ext2_file_
2240         .setattr        = ext2_setattr,
2241         .get_acl        = ext2_get_acl,
2242         .fiemap         = ext2_fiemap,
2243 +       .sync_flags     = ext2_sync_flags,
2244  };
2245 diff -NurpP --minimal linux-3.9.5/fs/ext2/ialloc.c linux-3.9.5-vs2.3.6.5/fs/ext2/ialloc.c
2246 --- linux-3.9.5/fs/ext2/ialloc.c        2013-05-31 13:45:23.000000000 +0000
2247 +++ linux-3.9.5-vs2.3.6.5/fs/ext2/ialloc.c      2013-06-03 18:58:16.000000000 +0000
2248 @@ -17,6 +17,7 @@
2249  #include <linux/backing-dev.h>
2250  #include <linux/buffer_head.h>
2251  #include <linux/random.h>
2252 +#include <linux/vs_tag.h>
2253  #include "ext2.h"
2254  #include "xattr.h"
2255  #include "acl.h"
2256 @@ -546,6 +547,7 @@ got:
2257                 inode->i_mode = mode;
2258                 inode->i_uid = current_fsuid();
2259                 inode->i_gid = dir->i_gid;
2260 +               i_tag_write(inode, dx_current_fstag(sb));
2261         } else
2262                 inode_init_owner(inode, dir, mode);
2263  
2264 diff -NurpP --minimal linux-3.9.5/fs/ext2/inode.c linux-3.9.5-vs2.3.6.5/fs/ext2/inode.c
2265 --- linux-3.9.5/fs/ext2/inode.c 2013-05-31 13:45:23.000000000 +0000
2266 +++ linux-3.9.5-vs2.3.6.5/fs/ext2/inode.c       2013-06-03 19:42:51.000000000 +0000
2267 @@ -31,6 +31,7 @@
2268  #include <linux/mpage.h>
2269  #include <linux/fiemap.h>
2270  #include <linux/namei.h>
2271 +#include <linux/vs_tag.h>
2272  #include "ext2.h"
2273  #include "acl.h"
2274  #include "xip.h"
2275 @@ -1179,7 +1180,7 @@ static void ext2_truncate_blocks(struct
2276                 return;
2277         if (ext2_inode_is_fast_symlink(inode))
2278                 return;
2279 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2280 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2281                 return;
2282         __ext2_truncate_blocks(inode, offset);
2283  }
2284 @@ -1270,36 +1271,61 @@ void ext2_set_inode_flags(struct inode *
2285  {
2286         unsigned int flags = EXT2_I(inode)->i_flags;
2287  
2288 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2289 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2290 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2291 +
2292 +
2293 +       if (flags & EXT2_IMMUTABLE_FL)
2294 +               inode->i_flags |= S_IMMUTABLE;
2295 +       if (flags & EXT2_IXUNLINK_FL)
2296 +               inode->i_flags |= S_IXUNLINK;
2297 +
2298         if (flags & EXT2_SYNC_FL)
2299                 inode->i_flags |= S_SYNC;
2300         if (flags & EXT2_APPEND_FL)
2301                 inode->i_flags |= S_APPEND;
2302 -       if (flags & EXT2_IMMUTABLE_FL)
2303 -               inode->i_flags |= S_IMMUTABLE;
2304         if (flags & EXT2_NOATIME_FL)
2305                 inode->i_flags |= S_NOATIME;
2306         if (flags & EXT2_DIRSYNC_FL)
2307                 inode->i_flags |= S_DIRSYNC;
2308 +
2309 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2310 +
2311 +       if (flags & EXT2_BARRIER_FL)
2312 +               inode->i_vflags |= V_BARRIER;
2313 +       if (flags & EXT2_COW_FL)
2314 +               inode->i_vflags |= V_COW;
2315  }
2316  
2317  /* Propagate flags from i_flags to EXT2_I(inode)->i_flags */
2318  void ext2_get_inode_flags(struct ext2_inode_info *ei)
2319  {
2320         unsigned int flags = ei->vfs_inode.i_flags;
2321 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2322 +
2323 +       ei->i_flags &= ~(EXT2_SYNC_FL | EXT2_APPEND_FL |
2324 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL |
2325 +                       EXT2_NOATIME_FL | EXT2_DIRSYNC_FL |
2326 +                       EXT2_BARRIER_FL | EXT2_COW_FL);
2327 +
2328 +       if (flags & S_IMMUTABLE)
2329 +               ei->i_flags |= EXT2_IMMUTABLE_FL;
2330 +       if (flags & S_IXUNLINK)
2331 +               ei->i_flags |= EXT2_IXUNLINK_FL;
2332  
2333 -       ei->i_flags &= ~(EXT2_SYNC_FL|EXT2_APPEND_FL|
2334 -                       EXT2_IMMUTABLE_FL|EXT2_NOATIME_FL|EXT2_DIRSYNC_FL);
2335         if (flags & S_SYNC)
2336                 ei->i_flags |= EXT2_SYNC_FL;
2337         if (flags & S_APPEND)
2338                 ei->i_flags |= EXT2_APPEND_FL;
2339 -       if (flags & S_IMMUTABLE)
2340 -               ei->i_flags |= EXT2_IMMUTABLE_FL;
2341         if (flags & S_NOATIME)
2342                 ei->i_flags |= EXT2_NOATIME_FL;
2343         if (flags & S_DIRSYNC)
2344                 ei->i_flags |= EXT2_DIRSYNC_FL;
2345 +
2346 +       if (vflags & V_BARRIER)
2347 +               ei->i_flags |= EXT2_BARRIER_FL;
2348 +       if (vflags & V_COW)
2349 +               ei->i_flags |= EXT2_COW_FL;
2350  }
2351  
2352  struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
2353 @@ -1335,8 +1361,10 @@ struct inode *ext2_iget (struct super_bl
2354                 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2355                 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2356         }
2357 -       i_uid_write(inode, i_uid);
2358 -       i_gid_write(inode, i_gid);
2359 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
2360 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
2361 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
2362 +               le16_to_cpu(raw_inode->i_raw_tag)));
2363         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2364         inode->i_size = le32_to_cpu(raw_inode->i_size);
2365         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2366 @@ -1434,8 +1462,10 @@ static int __ext2_write_inode(struct ino
2367         struct ext2_inode_info *ei = EXT2_I(inode);
2368         struct super_block *sb = inode->i_sb;
2369         ino_t ino = inode->i_ino;
2370 -       uid_t uid = i_uid_read(inode);
2371 -       gid_t gid = i_gid_read(inode);
2372 +       uid_t uid = from_kuid(&init_user_ns,
2373 +               TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag));
2374 +       gid_t gid = from_kgid(&init_user_ns,
2375 +               TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag));
2376         struct buffer_head * bh;
2377         struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2378         int n;
2379 @@ -1471,6 +1501,9 @@ static int __ext2_write_inode(struct ino
2380                 raw_inode->i_uid_high = 0;
2381                 raw_inode->i_gid_high = 0;
2382         }
2383 +#ifdef CONFIG_TAGGING_INTERN
2384 +       raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
2385 +#endif
2386         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2387         raw_inode->i_size = cpu_to_le32(inode->i_size);
2388         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2389 @@ -1551,7 +1584,8 @@ int ext2_setattr(struct dentry *dentry,
2390         if (is_quota_modification(inode, iattr))
2391                 dquot_initialize(inode);
2392         if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
2393 -           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
2394 +           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid)) ||
2395 +           (iattr->ia_valid & ATTR_TAG && !tag_eq(iattr->ia_tag, inode->i_tag))) {
2396                 error = dquot_transfer(inode, iattr);
2397                 if (error)
2398                         return error;
2399 diff -NurpP --minimal linux-3.9.5/fs/ext2/ioctl.c linux-3.9.5-vs2.3.6.5/fs/ext2/ioctl.c
2400 --- linux-3.9.5/fs/ext2/ioctl.c 2013-05-31 13:45:23.000000000 +0000
2401 +++ linux-3.9.5-vs2.3.6.5/fs/ext2/ioctl.c       2013-05-31 14:47:11.000000000 +0000
2402 @@ -17,6 +17,16 @@
2403  #include <asm/uaccess.h>
2404  
2405  
2406 +int ext2_sync_flags(struct inode *inode, int flags, int vflags)
2407 +{
2408 +       inode->i_flags = flags;
2409 +       inode->i_vflags = vflags;
2410 +       ext2_get_inode_flags(EXT2_I(inode));
2411 +       inode->i_ctime = CURRENT_TIME_SEC;
2412 +       mark_inode_dirty(inode);
2413 +       return 0;
2414 +}
2415 +
2416  long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2417  {
2418         struct inode *inode = file_inode(filp);
2419 @@ -51,6 +61,11 @@ long ext2_ioctl(struct file *filp, unsig
2420  
2421                 flags = ext2_mask_flags(inode->i_mode, flags);
2422  
2423 +               if (IS_BARRIER(inode)) {
2424 +                       vxwprintk_task(1, "messing with the barrier.");
2425 +                       return -EACCES;
2426 +               }
2427 +
2428                 mutex_lock(&inode->i_mutex);
2429                 /* Is it quota file? Do not allow user to mess with it */
2430                 if (IS_NOQUOTA(inode)) {
2431 @@ -66,7 +81,9 @@ long ext2_ioctl(struct file *filp, unsig
2432                  *
2433                  * This test looks nicer. Thanks to Pauline Middelink
2434                  */
2435 -               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
2436 +               if ((oldflags & EXT2_IMMUTABLE_FL) ||
2437 +                       ((flags ^ oldflags) & (EXT2_APPEND_FL |
2438 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
2439                         if (!capable(CAP_LINUX_IMMUTABLE)) {
2440                                 mutex_unlock(&inode->i_mutex);
2441                                 ret = -EPERM;
2442 @@ -74,7 +91,7 @@ long ext2_ioctl(struct file *filp, unsig
2443                         }
2444                 }
2445  
2446 -               flags = flags & EXT2_FL_USER_MODIFIABLE;
2447 +               flags &= EXT2_FL_USER_MODIFIABLE;
2448                 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
2449                 ei->i_flags = flags;
2450  
2451 diff -NurpP --minimal linux-3.9.5/fs/ext2/namei.c linux-3.9.5-vs2.3.6.5/fs/ext2/namei.c
2452 --- linux-3.9.5/fs/ext2/namei.c 2012-12-11 03:30:57.000000000 +0000
2453 +++ linux-3.9.5-vs2.3.6.5/fs/ext2/namei.c       2013-05-31 14:47:11.000000000 +0000
2454 @@ -32,6 +32,7 @@
2455  
2456  #include <linux/pagemap.h>
2457  #include <linux/quotaops.h>
2458 +#include <linux/vs_tag.h>
2459  #include "ext2.h"
2460  #include "xattr.h"
2461  #include "acl.h"
2462 @@ -73,6 +74,7 @@ static struct dentry *ext2_lookup(struct
2463                                         (unsigned long) ino);
2464                         return ERR_PTR(-EIO);
2465                 }
2466 +               dx_propagate_tag(nd, inode);
2467         }
2468         return d_splice_alias(inode, dentry);
2469  }
2470 @@ -397,6 +399,7 @@ const struct inode_operations ext2_dir_i
2471         .removexattr    = generic_removexattr,
2472  #endif
2473         .setattr        = ext2_setattr,
2474 +       .sync_flags     = ext2_sync_flags,
2475         .get_acl        = ext2_get_acl,
2476  };
2477  
2478 diff -NurpP --minimal linux-3.9.5/fs/ext2/super.c linux-3.9.5-vs2.3.6.5/fs/ext2/super.c
2479 --- linux-3.9.5/fs/ext2/super.c 2013-05-31 13:45:23.000000000 +0000
2480 +++ linux-3.9.5-vs2.3.6.5/fs/ext2/super.c       2013-05-31 14:47:11.000000000 +0000
2481 @@ -395,7 +395,8 @@ enum {
2482         Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
2483         Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
2484         Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
2485 -       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
2486 +       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
2487 +       Opt_tag, Opt_notag, Opt_tagid
2488  };
2489  
2490  static const match_table_t tokens = {
2491 @@ -423,6 +424,9 @@ static const match_table_t tokens = {
2492         {Opt_acl, "acl"},
2493         {Opt_noacl, "noacl"},
2494         {Opt_xip, "xip"},
2495 +       {Opt_tag, "tag"},
2496 +       {Opt_notag, "notag"},
2497 +       {Opt_tagid, "tagid=%u"},
2498         {Opt_grpquota, "grpquota"},
2499         {Opt_ignore, "noquota"},
2500         {Opt_quota, "quota"},
2501 @@ -506,6 +510,20 @@ static int parse_options(char *options,
2502                 case Opt_nouid32:
2503                         set_opt (sbi->s_mount_opt, NO_UID32);
2504                         break;
2505 +#ifndef CONFIG_TAGGING_NONE
2506 +               case Opt_tag:
2507 +                       set_opt (sbi->s_mount_opt, TAGGED);
2508 +                       break;
2509 +               case Opt_notag:
2510 +                       clear_opt (sbi->s_mount_opt, TAGGED);
2511 +                       break;
2512 +#endif
2513 +#ifdef CONFIG_PROPAGATE
2514 +               case Opt_tagid:
2515 +                       /* use args[0] */
2516 +                       set_opt (sbi->s_mount_opt, TAGGED);
2517 +                       break;
2518 +#endif
2519                 case Opt_nocheck:
2520                         clear_opt (sbi->s_mount_opt, CHECK);
2521                         break;
2522 @@ -864,6 +882,8 @@ static int ext2_fill_super(struct super_
2523         if (!parse_options((char *) data, sb))
2524                 goto failed_mount;
2525  
2526 +       if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
2527 +               sb->s_flags |= MS_TAGGED;
2528         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2529                 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
2530                  MS_POSIXACL : 0);
2531 @@ -1269,6 +1289,14 @@ static int ext2_remount (struct super_bl
2532                 err = -EINVAL;
2533                 goto restore_opts;
2534         }
2535 +
2536 +       if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
2537 +               !(sb->s_flags & MS_TAGGED)) {
2538 +               printk("EXT2-fs: %s: tagging not permitted on remount.\n",
2539 +                      sb->s_id);
2540 +               err = -EINVAL;
2541 +               goto restore_opts;
2542 +       }
2543  
2544         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2545                 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
2546 diff -NurpP --minimal linux-3.9.5/fs/ext3/ext3.h linux-3.9.5-vs2.3.6.5/fs/ext3/ext3.h
2547 --- linux-3.9.5/fs/ext3/ext3.h  2012-12-11 03:30:57.000000000 +0000
2548 +++ linux-3.9.5-vs2.3.6.5/fs/ext3/ext3.h        2013-05-31 14:47:11.000000000 +0000
2549 @@ -151,10 +151,14 @@ struct ext3_group_desc
2550  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
2551  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
2552  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
2553 +#define EXT3_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
2554  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
2555  
2556 -#define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
2557 -#define EXT3_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
2558 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
2559 +#define EXT3_COW_FL                    0x20000000 /* Copy on Write marker */
2560 +
2561 +#define EXT3_FL_USER_VISIBLE           0x0103DFFF /* User visible flags */
2562 +#define EXT3_FL_USER_MODIFIABLE                0x010380FF /* User modifiable flags */
2563  
2564  /* Flags that should be inherited by new inodes from their parent. */
2565  #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
2566 @@ -290,7 +294,8 @@ struct ext3_inode {
2567                         __u16   i_pad1;
2568                         __le16  l_i_uid_high;   /* these 2 fields    */
2569                         __le16  l_i_gid_high;   /* were reserved2[0] */
2570 -                       __u32   l_i_reserved2;
2571 +                       __le16  l_i_tag;        /* Context Tag */
2572 +                       __u16   l_i_reserved2;
2573                 } linux2;
2574                 struct {
2575                         __u8    h_i_frag;       /* Fragment number */
2576 @@ -320,6 +325,7 @@ struct ext3_inode {
2577  #define i_gid_low      i_gid
2578  #define i_uid_high     osd2.linux2.l_i_uid_high
2579  #define i_gid_high     osd2.linux2.l_i_gid_high
2580 +#define i_raw_tag      osd2.linux2.l_i_tag
2581  #define i_reserved2    osd2.linux2.l_i_reserved2
2582  
2583  /*
2584 @@ -364,6 +370,7 @@ struct ext3_inode {
2585  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
2586  #define EXT3_MOUNT_DATA_ERR_ABORT      0x400000 /* Abort on file data write
2587                                                   * error in ordered mode */
2588 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
2589  
2590  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
2591  #ifndef _LINUX_EXT2_FS_H
2592 @@ -1061,6 +1068,7 @@ extern void ext3_get_inode_flags(struct
2593  extern void ext3_set_aops(struct inode *inode);
2594  extern int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2595                        u64 start, u64 len);
2596 +extern int ext3_sync_flags(struct inode *, int, int);
2597  
2598  /* ioctl.c */
2599  extern long ext3_ioctl(struct file *, unsigned int, unsigned long);
2600 diff -NurpP --minimal linux-3.9.5/fs/ext3/file.c linux-3.9.5-vs2.3.6.5/fs/ext3/file.c
2601 --- linux-3.9.5/fs/ext3/file.c  2012-12-11 03:30:57.000000000 +0000
2602 +++ linux-3.9.5-vs2.3.6.5/fs/ext3/file.c        2013-05-31 14:47:11.000000000 +0000
2603 @@ -76,5 +76,6 @@ const struct inode_operations ext3_file_
2604  #endif
2605         .get_acl        = ext3_get_acl,
2606         .fiemap         = ext3_fiemap,
2607 +       .sync_flags     = ext3_sync_flags,
2608  };
2609  
2610 diff -NurpP --minimal linux-3.9.5/fs/ext3/ialloc.c linux-3.9.5-vs2.3.6.5/fs/ext3/ialloc.c
2611 --- linux-3.9.5/fs/ext3/ialloc.c        2012-12-11 03:30:57.000000000 +0000
2612 +++ linux-3.9.5-vs2.3.6.5/fs/ext3/ialloc.c      2013-06-03 19:43:33.000000000 +0000
2613 @@ -14,6 +14,7 @@
2614  
2615  #include <linux/quotaops.h>
2616  #include <linux/random.h>
2617 +#include <linux/vs_tag.h>
2618  
2619  #include "ext3.h"
2620  #include "xattr.h"
2621 @@ -469,6 +470,7 @@ got:
2622                 inode->i_mode = mode;
2623                 inode->i_uid = current_fsuid();
2624                 inode->i_gid = dir->i_gid;
2625 +               i_tag_write(inode, dx_current_fstag(sb));
2626         } else
2627                 inode_init_owner(inode, dir, mode);
2628  
2629 diff -NurpP --minimal linux-3.9.5/fs/ext3/inode.c linux-3.9.5-vs2.3.6.5/fs/ext3/inode.c
2630 --- linux-3.9.5/fs/ext3/inode.c 2013-05-31 13:45:23.000000000 +0000
2631 +++ linux-3.9.5-vs2.3.6.5/fs/ext3/inode.c       2013-06-03 19:44:35.000000000 +0000
2632 @@ -27,6 +27,8 @@
2633  #include <linux/writeback.h>
2634  #include <linux/mpage.h>
2635  #include <linux/namei.h>
2636 +#include <linux/vs_tag.h>
2637 +
2638  #include "ext3.h"
2639  #include "xattr.h"
2640  #include "acl.h"
2641 @@ -2851,36 +2853,60 @@ void ext3_set_inode_flags(struct inode *
2642  {
2643         unsigned int flags = EXT3_I(inode)->i_flags;
2644  
2645 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2646 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2647 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2648 +
2649 +       if (flags & EXT3_IMMUTABLE_FL)
2650 +               inode->i_flags |= S_IMMUTABLE;
2651 +       if (flags & EXT3_IXUNLINK_FL)
2652 +               inode->i_flags |= S_IXUNLINK;
2653 +
2654         if (flags & EXT3_SYNC_FL)
2655                 inode->i_flags |= S_SYNC;
2656         if (flags & EXT3_APPEND_FL)
2657                 inode->i_flags |= S_APPEND;
2658 -       if (flags & EXT3_IMMUTABLE_FL)
2659 -               inode->i_flags |= S_IMMUTABLE;
2660         if (flags & EXT3_NOATIME_FL)
2661                 inode->i_flags |= S_NOATIME;
2662         if (flags & EXT3_DIRSYNC_FL)
2663                 inode->i_flags |= S_DIRSYNC;
2664 +
2665 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2666 +
2667 +       if (flags & EXT3_BARRIER_FL)
2668 +               inode->i_vflags |= V_BARRIER;
2669 +       if (flags & EXT3_COW_FL)
2670 +               inode->i_vflags |= V_COW;
2671  }
2672  
2673  /* Propagate flags from i_flags to EXT3_I(inode)->i_flags */
2674  void ext3_get_inode_flags(struct ext3_inode_info *ei)
2675  {
2676         unsigned int flags = ei->vfs_inode.i_flags;
2677 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2678 +
2679 +       ei->i_flags &= ~(EXT3_SYNC_FL | EXT3_APPEND_FL |
2680 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL |
2681 +                       EXT3_NOATIME_FL | EXT3_DIRSYNC_FL |
2682 +                       EXT3_BARRIER_FL | EXT3_COW_FL);
2683 +
2684 +       if (flags & S_IMMUTABLE)
2685 +               ei->i_flags |= EXT3_IMMUTABLE_FL;
2686 +       if (flags & S_IXUNLINK)
2687 +               ei->i_flags |= EXT3_IXUNLINK_FL;
2688  
2689 -       ei->i_flags &= ~(EXT3_SYNC_FL|EXT3_APPEND_FL|
2690 -                       EXT3_IMMUTABLE_FL|EXT3_NOATIME_FL|EXT3_DIRSYNC_FL);
2691         if (flags & S_SYNC)
2692                 ei->i_flags |= EXT3_SYNC_FL;
2693         if (flags & S_APPEND)
2694                 ei->i_flags |= EXT3_APPEND_FL;
2695 -       if (flags & S_IMMUTABLE)
2696 -               ei->i_flags |= EXT3_IMMUTABLE_FL;
2697         if (flags & S_NOATIME)
2698                 ei->i_flags |= EXT3_NOATIME_FL;
2699         if (flags & S_DIRSYNC)
2700                 ei->i_flags |= EXT3_DIRSYNC_FL;
2701 +
2702 +       if (vflags & V_BARRIER)
2703 +               ei->i_flags |= EXT3_BARRIER_FL;
2704 +       if (vflags & V_COW)
2705 +               ei->i_flags |= EXT3_COW_FL;
2706  }
2707  
2708  struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
2709 @@ -2918,8 +2944,10 @@ struct inode *ext3_iget(struct super_blo
2710                 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2711                 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2712         }
2713 -       i_uid_write(inode, i_uid);
2714 -       i_gid_write(inode, i_gid);
2715 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
2716 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
2717 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
2718 +               le16_to_cpu(raw_inode->i_raw_tag)));
2719         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2720         inode->i_size = le32_to_cpu(raw_inode->i_size);
2721         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2722 @@ -3091,8 +3119,10 @@ again:
2723  
2724         ext3_get_inode_flags(ei);
2725         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
2726 -       i_uid = i_uid_read(inode);
2727 -       i_gid = i_gid_read(inode);
2728 +       i_uid = from_kuid(&init_user_ns,
2729 +               TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag));
2730 +       i_gid = from_kgid(&init_user_ns,
2731 +               TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag));
2732         if(!(test_opt(inode->i_sb, NO_UID32))) {
2733                 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(i_uid));
2734                 raw_inode->i_gid_low = cpu_to_le16(low_16_bits(i_gid));
2735 @@ -3117,6 +3147,9 @@ again:
2736                 raw_inode->i_uid_high = 0;
2737                 raw_inode->i_gid_high = 0;
2738         }
2739 +#ifdef CONFIG_TAGGING_INTERN
2740 +       raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
2741 +#endif
2742         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2743         disksize = cpu_to_le32(ei->i_disksize);
2744         if (disksize != raw_inode->i_size) {
2745 @@ -3285,7 +3318,8 @@ int ext3_setattr(struct dentry *dentry,
2746         if (is_quota_modification(inode, attr))
2747                 dquot_initialize(inode);
2748         if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) ||
2749 -           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) {
2750 +           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid)) ||
2751 +           (ia_valid & ATTR_TAG && !tag_eq(attr->ia_tag, inode->i_tag))) {
2752                 handle_t *handle;
2753  
2754                 /* (user+group)*(old+new) structure, inode write (sb,
2755 @@ -3307,6 +3341,8 @@ int ext3_setattr(struct dentry *dentry,
2756                         inode->i_uid = attr->ia_uid;
2757                 if (attr->ia_valid & ATTR_GID)
2758                         inode->i_gid = attr->ia_gid;
2759 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2760 +                       inode->i_tag = attr->ia_tag;
2761                 error = ext3_mark_inode_dirty(handle, inode);
2762                 ext3_journal_stop(handle);
2763         }
2764 diff -NurpP --minimal linux-3.9.5/fs/ext3/ioctl.c linux-3.9.5-vs2.3.6.5/fs/ext3/ioctl.c
2765 --- linux-3.9.5/fs/ext3/ioctl.c 2013-05-31 13:45:23.000000000 +0000
2766 +++ linux-3.9.5-vs2.3.6.5/fs/ext3/ioctl.c       2013-05-31 14:47:11.000000000 +0000
2767 @@ -12,6 +12,34 @@
2768  #include <asm/uaccess.h>
2769  #include "ext3.h"
2770  
2771 +
2772 +int ext3_sync_flags(struct inode *inode, int flags, int vflags)
2773 +{
2774 +       handle_t *handle = NULL;
2775 +       struct ext3_iloc iloc;
2776 +       int err;
2777 +
2778 +       handle = ext3_journal_start(inode, 1);
2779 +       if (IS_ERR(handle))
2780 +               return PTR_ERR(handle);
2781 +
2782 +       if (IS_SYNC(inode))
2783 +               handle->h_sync = 1;
2784 +       err = ext3_reserve_inode_write(handle, inode, &iloc);
2785 +       if (err)
2786 +               goto flags_err;
2787 +
2788 +       inode->i_flags = flags;
2789 +       inode->i_vflags = vflags;
2790 +       ext3_get_inode_flags(EXT3_I(inode));
2791 +       inode->i_ctime = CURRENT_TIME_SEC;
2792 +
2793 +       err = ext3_mark_iloc_dirty(handle, inode, &iloc);
2794 +flags_err:
2795 +       ext3_journal_stop(handle);
2796 +       return err;
2797 +}
2798 +
2799  long ext3_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2800  {
2801         struct inode *inode = file_inode(filp);
2802 @@ -45,6 +73,11 @@ long ext3_ioctl(struct file *filp, unsig
2803  
2804                 flags = ext3_mask_flags(inode->i_mode, flags);
2805  
2806 +               if (IS_BARRIER(inode)) {
2807 +                       vxwprintk_task(1, "messing with the barrier.");
2808 +                       return -EACCES;
2809 +               }
2810 +
2811                 mutex_lock(&inode->i_mutex);
2812  
2813                 /* Is it quota file? Do not allow user to mess with it */
2814 @@ -63,7 +96,9 @@ long ext3_ioctl(struct file *filp, unsig
2815                  *
2816                  * This test looks nicer. Thanks to Pauline Middelink
2817                  */
2818 -               if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
2819 +               if ((oldflags & EXT3_IMMUTABLE_FL) ||
2820 +                       ((flags ^ oldflags) & (EXT3_APPEND_FL |
2821 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL))) {
2822                         if (!capable(CAP_LINUX_IMMUTABLE))
2823                                 goto flags_out;
2824                 }
2825 @@ -88,7 +123,7 @@ long ext3_ioctl(struct file *filp, unsig
2826                 if (err)
2827                         goto flags_err;
2828  
2829 -               flags = flags & EXT3_FL_USER_MODIFIABLE;
2830 +               flags &= EXT3_FL_USER_MODIFIABLE;
2831                 flags |= oldflags & ~EXT3_FL_USER_MODIFIABLE;
2832                 ei->i_flags = flags;
2833  
2834 diff -NurpP --minimal linux-3.9.5/fs/ext3/namei.c linux-3.9.5-vs2.3.6.5/fs/ext3/namei.c
2835 --- linux-3.9.5/fs/ext3/namei.c 2013-05-31 13:45:23.000000000 +0000
2836 +++ linux-3.9.5-vs2.3.6.5/fs/ext3/namei.c       2013-05-31 14:47:11.000000000 +0000
2837 @@ -25,6 +25,8 @@
2838   */
2839  
2840  #include <linux/quotaops.h>
2841 +#include <linux/vs_tag.h>
2842 +
2843  #include "ext3.h"
2844  #include "namei.h"
2845  #include "xattr.h"
2846 @@ -918,6 +920,7 @@ restart:
2847                                         submit_bh(READ | REQ_META | REQ_PRIO,
2848                                                   bh);
2849                                 }
2850 +               dx_propagate_tag(nd, inode);
2851                         }
2852                 }
2853                 if ((bh = bh_use[ra_ptr++]) == NULL)
2854 @@ -2527,6 +2530,7 @@ const struct inode_operations ext3_dir_i
2855         .listxattr      = ext3_listxattr,
2856         .removexattr    = generic_removexattr,
2857  #endif
2858 +       .sync_flags     = ext3_sync_flags,
2859         .get_acl        = ext3_get_acl,
2860  };
2861  
2862 diff -NurpP --minimal linux-3.9.5/fs/ext3/super.c linux-3.9.5-vs2.3.6.5/fs/ext3/super.c
2863 --- linux-3.9.5/fs/ext3/super.c 2013-05-31 13:45:23.000000000 +0000
2864 +++ linux-3.9.5-vs2.3.6.5/fs/ext3/super.c       2013-05-31 14:47:11.000000000 +0000
2865 @@ -816,7 +816,8 @@ enum {
2866         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
2867         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota,
2868         Opt_noquota, Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err,
2869 -       Opt_resize, Opt_usrquota, Opt_grpquota
2870 +       Opt_resize, Opt_usrquota, Opt_grpquota,
2871 +       Opt_tag, Opt_notag, Opt_tagid
2872  };
2873  
2874  static const match_table_t tokens = {
2875 @@ -873,6 +874,9 @@ static const match_table_t tokens = {
2876         {Opt_barrier, "barrier"},
2877         {Opt_nobarrier, "nobarrier"},
2878         {Opt_resize, "resize"},
2879 +       {Opt_tag, "tag"},
2880 +       {Opt_notag, "notag"},
2881 +       {Opt_tagid, "tagid=%u"},
2882         {Opt_err, NULL},
2883  };
2884  
2885 @@ -1040,6 +1044,20 @@ static int parse_options (char *options,
2886                 case Opt_nouid32:
2887                         set_opt (sbi->s_mount_opt, NO_UID32);
2888                         break;
2889 +#ifndef CONFIG_TAGGING_NONE
2890 +               case Opt_tag:
2891 +                       set_opt (sbi->s_mount_opt, TAGGED);
2892 +                       break;
2893 +               case Opt_notag:
2894 +                       clear_opt (sbi->s_mount_opt, TAGGED);
2895 +                       break;
2896 +#endif
2897 +#ifdef CONFIG_PROPAGATE
2898 +               case Opt_tagid:
2899 +                       /* use args[0] */
2900 +                       set_opt (sbi->s_mount_opt, TAGGED);
2901 +                       break;
2902 +#endif
2903                 case Opt_nocheck:
2904                         clear_opt (sbi->s_mount_opt, CHECK);
2905                         break;
2906 @@ -1737,6 +1755,9 @@ static int ext3_fill_super (struct super
2907                             NULL, 0))
2908                 goto failed_mount;
2909  
2910 +       if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
2911 +               sb->s_flags |= MS_TAGGED;
2912 +
2913         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2914                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2915  
2916 @@ -2633,6 +2654,14 @@ static int ext3_remount (struct super_bl
2917         if (test_opt(sb, ABORT))
2918                 ext3_abort(sb, __func__, "Abort forced by user");
2919  
2920 +       if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
2921 +               !(sb->s_flags & MS_TAGGED)) {
2922 +               printk("EXT3-fs: %s: tagging not permitted on remount.\n",
2923 +                       sb->s_id);
2924 +               err = -EINVAL;
2925 +               goto restore_opts;
2926 +       }
2927 +
2928         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2929                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2930  
2931 diff -NurpP --minimal linux-3.9.5/fs/ext4/ext4.h linux-3.9.5-vs2.3.6.5/fs/ext4/ext4.h
2932 --- linux-3.9.5/fs/ext4/ext4.h  2013-05-31 13:45:23.000000000 +0000
2933 +++ linux-3.9.5-vs2.3.6.5/fs/ext4/ext4.h        2013-05-31 16:22:49.000000000 +0000
2934 @@ -399,7 +399,10 @@ struct flex_groups {
2935  #define EXT4_EXTENTS_FL                        0x00080000 /* Inode uses extents */
2936  #define EXT4_EA_INODE_FL               0x00200000 /* Inode used for large EA */
2937  #define EXT4_EOFBLOCKS_FL              0x00400000 /* Blocks allocated beyond EOF */
2938 +#define EXT4_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
2939 +#define EXT4_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
2940  #define EXT4_INLINE_DATA_FL            0x10000000 /* Inode has inline data. */
2941 +#define EXT4_COW_FL                    0x20000000 /* Copy on Write marker */
2942  #define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
2943  
2944  #define EXT4_FL_USER_VISIBLE           0x004BDFFF /* User visible flags */
2945 @@ -674,7 +677,7 @@ struct ext4_inode {
2946                         __le16  l_i_uid_high;   /* these 2 fields */
2947                         __le16  l_i_gid_high;   /* were reserved2[0] */
2948                         __le16  l_i_checksum_lo;/* crc32c(uuid+inum+inode) LE */
2949 -                       __le16  l_i_reserved;
2950 +                       __le16  l_i_tag;        /* Context Tag */
2951                 } linux2;
2952                 struct {
2953                         __le16  h_i_reserved1;  /* Obsoleted fragment number/size which are removed in ext4 */
2954 @@ -792,6 +795,7 @@ do {                                                                               \
2955  #define i_gid_low      i_gid
2956  #define i_uid_high     osd2.linux2.l_i_uid_high
2957  #define i_gid_high     osd2.linux2.l_i_gid_high
2958 +#define i_raw_tag      osd2.linux2.l_i_tag
2959  #define i_checksum_lo  osd2.linux2.l_i_checksum_lo
2960  
2961  #elif defined(__GNU__)
2962 @@ -969,6 +973,7 @@ struct ext4_inode_info {
2963  #define EXT4_MOUNT_POSIX_ACL           0x08000 /* POSIX Access Control Lists */
2964  #define EXT4_MOUNT_NO_AUTO_DA_ALLOC    0x10000 /* No auto delalloc mapping */
2965  #define EXT4_MOUNT_BARRIER             0x20000 /* Use block barriers */
2966 +#define EXT4_MOUNT_TAGGED              0x40000 /* Enable Context Tags */
2967  #define EXT4_MOUNT_QUOTA               0x80000 /* Some quota option set */
2968  #define EXT4_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
2969  #define EXT4_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
2970 @@ -2527,6 +2532,7 @@ extern struct buffer_head *ext4_get_firs
2971  extern int ext4_inline_data_fiemap(struct inode *inode,
2972                                    struct fiemap_extent_info *fieinfo,
2973                                    int *has_inline);
2974 +extern int ext4_sync_flags(struct inode *, int, int);
2975  extern int ext4_try_to_evict_inline_data(handle_t *handle,
2976                                          struct inode *inode,
2977                                          int needed);
2978 diff -NurpP --minimal linux-3.9.5/fs/ext4/file.c linux-3.9.5-vs2.3.6.5/fs/ext4/file.c
2979 --- linux-3.9.5/fs/ext4/file.c  2013-05-31 13:45:23.000000000 +0000
2980 +++ linux-3.9.5-vs2.3.6.5/fs/ext4/file.c        2013-05-31 14:47:11.000000000 +0000
2981 @@ -650,5 +650,6 @@ const struct inode_operations ext4_file_
2982         .removexattr    = generic_removexattr,
2983         .get_acl        = ext4_get_acl,
2984         .fiemap         = ext4_fiemap,
2985 +       .sync_flags     = ext4_sync_flags,
2986  };
2987  
2988 diff -NurpP --minimal linux-3.9.5/fs/ext4/ialloc.c linux-3.9.5-vs2.3.6.5/fs/ext4/ialloc.c
2989 --- linux-3.9.5/fs/ext4/ialloc.c        2013-05-31 13:45:23.000000000 +0000
2990 +++ linux-3.9.5-vs2.3.6.5/fs/ext4/ialloc.c      2013-06-03 19:45:15.000000000 +0000
2991 @@ -22,6 +22,7 @@
2992  #include <linux/random.h>
2993  #include <linux/bitops.h>
2994  #include <linux/blkdev.h>
2995 +#include <linux/vs_tag.h>
2996  #include <asm/byteorder.h>
2997  
2998  #include "ext4.h"
2999 @@ -859,6 +860,7 @@ got:
3000                 inode->i_mode = mode;
3001                 inode->i_uid = current_fsuid();
3002                 inode->i_gid = dir->i_gid;
3003 +               i_tag_write(inode, dx_current_fstag(sb));
3004         } else
3005                 inode_init_owner(inode, dir, mode);
3006  
3007 diff -NurpP --minimal linux-3.9.5/fs/ext4/inode.c linux-3.9.5-vs2.3.6.5/fs/ext4/inode.c
3008 --- linux-3.9.5/fs/ext4/inode.c 2013-06-11 12:22:39.000000000 +0000
3009 +++ linux-3.9.5-vs2.3.6.5/fs/ext4/inode.c       2013-06-03 19:45:35.000000000 +0000
3010 @@ -37,6 +37,7 @@
3011  #include <linux/printk.h>
3012  #include <linux/slab.h>
3013  #include <linux/ratelimit.h>
3014 +#include <linux/vs_tag.h>
3015  
3016  #include "ext4_jbd2.h"
3017  #include "xattr.h"
3018 @@ -3870,41 +3871,64 @@ void ext4_set_inode_flags(struct inode *
3019  {
3020         unsigned int flags = EXT4_I(inode)->i_flags;
3021  
3022 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3023 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3024 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3025 +
3026 +       if (flags & EXT4_IMMUTABLE_FL)
3027 +               inode->i_flags |= S_IMMUTABLE;
3028 +       if (flags & EXT4_IXUNLINK_FL)
3029 +               inode->i_flags |= S_IXUNLINK;
3030 +
3031         if (flags & EXT4_SYNC_FL)
3032                 inode->i_flags |= S_SYNC;
3033         if (flags & EXT4_APPEND_FL)
3034                 inode->i_flags |= S_APPEND;
3035 -       if (flags & EXT4_IMMUTABLE_FL)
3036 -               inode->i_flags |= S_IMMUTABLE;
3037         if (flags & EXT4_NOATIME_FL)
3038                 inode->i_flags |= S_NOATIME;
3039         if (flags & EXT4_DIRSYNC_FL)
3040                 inode->i_flags |= S_DIRSYNC;
3041 +
3042 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3043 +
3044 +       if (flags & EXT4_BARRIER_FL)
3045 +               inode->i_vflags |= V_BARRIER;
3046 +       if (flags & EXT4_COW_FL)
3047 +               inode->i_vflags |= V_COW;
3048  }
3049  
3050  /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
3051  void ext4_get_inode_flags(struct ext4_inode_info *ei)
3052  {
3053 -       unsigned int vfs_fl;
3054 +       unsigned int vfs_fl, vfs_vf;
3055         unsigned long old_fl, new_fl;
3056  
3057         do {
3058                 vfs_fl = ei->vfs_inode.i_flags;
3059 +               vfs_vf = ei->vfs_inode.i_vflags;
3060                 old_fl = ei->i_flags;
3061                 new_fl = old_fl & ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
3062                                 EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|
3063 -                               EXT4_DIRSYNC_FL);
3064 +                               EXT4_DIRSYNC_FL|EXT4_BARRIER_FL|
3065 +                               EXT4_COW_FL);
3066 +
3067 +               if (vfs_fl & S_IMMUTABLE)
3068 +                       new_fl |= EXT4_IMMUTABLE_FL;
3069 +               if (vfs_fl & S_IXUNLINK)
3070 +                       new_fl |= EXT4_IXUNLINK_FL;
3071 +
3072                 if (vfs_fl & S_SYNC)
3073                         new_fl |= EXT4_SYNC_FL;
3074                 if (vfs_fl & S_APPEND)
3075                         new_fl |= EXT4_APPEND_FL;
3076 -               if (vfs_fl & S_IMMUTABLE)
3077 -                       new_fl |= EXT4_IMMUTABLE_FL;
3078                 if (vfs_fl & S_NOATIME)
3079                         new_fl |= EXT4_NOATIME_FL;
3080                 if (vfs_fl & S_DIRSYNC)
3081                         new_fl |= EXT4_DIRSYNC_FL;
3082 +
3083 +               if (vfs_vf & V_BARRIER)
3084 +                       new_fl |= EXT4_BARRIER_FL;
3085 +               if (vfs_vf & V_COW)
3086 +                       new_fl |= EXT4_COW_FL;
3087         } while (cmpxchg(&ei->i_flags, old_fl, new_fl) != old_fl);
3088  }
3089  
3090 @@ -4009,8 +4033,10 @@ struct inode *ext4_iget(struct super_blo
3091                 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3092                 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3093         }
3094 -       i_uid_write(inode, i_uid);
3095 -       i_gid_write(inode, i_gid);
3096 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
3097 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
3098 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
3099 +               le16_to_cpu(raw_inode->i_raw_tag)));
3100         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
3101  
3102         ext4_clear_state_flags(ei);     /* Only relevant on 32-bit archs */
3103 @@ -4233,8 +4259,10 @@ static int ext4_do_update_inode(handle_t
3104  
3105         ext4_get_inode_flags(ei);
3106         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3107 -       i_uid = i_uid_read(inode);
3108 -       i_gid = i_gid_read(inode);
3109 +       i_uid = from_kuid(&init_user_ns,
3110 +               TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag));
3111 +       i_gid = from_kgid(&init_user_ns,
3112 +               TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag));
3113         if (!(test_opt(inode->i_sb, NO_UID32))) {
3114                 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(i_uid));
3115                 raw_inode->i_gid_low = cpu_to_le16(low_16_bits(i_gid));
3116 @@ -4257,6 +4285,9 @@ static int ext4_do_update_inode(handle_t
3117                 raw_inode->i_uid_high = 0;
3118                 raw_inode->i_gid_high = 0;
3119         }
3120 +#ifdef CONFIG_TAGGING_INTERN
3121 +       raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
3122 +#endif
3123         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3124  
3125         EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
3126 @@ -4487,7 +4518,8 @@ int ext4_setattr(struct dentry *dentry,
3127         if (is_quota_modification(inode, attr))
3128                 dquot_initialize(inode);
3129         if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) ||
3130 -           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) {
3131 +           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid)) ||
3132 +           (ia_valid & ATTR_TAG && !tag_eq(attr->ia_tag, inode->i_tag))) {
3133                 handle_t *handle;
3134  
3135                 /* (user+group)*(old+new) structure, inode write (sb,
3136 @@ -4510,6 +4542,8 @@ int ext4_setattr(struct dentry *dentry,
3137                         inode->i_uid = attr->ia_uid;
3138                 if (attr->ia_valid & ATTR_GID)
3139                         inode->i_gid = attr->ia_gid;
3140 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3141 +                       inode->i_tag = attr->ia_tag;
3142                 error = ext4_mark_inode_dirty(handle, inode);
3143                 ext4_journal_stop(handle);
3144         }
3145 diff -NurpP --minimal linux-3.9.5/fs/ext4/ioctl.c linux-3.9.5-vs2.3.6.5/fs/ext4/ioctl.c
3146 --- linux-3.9.5/fs/ext4/ioctl.c 2013-05-31 13:45:23.000000000 +0000
3147 +++ linux-3.9.5-vs2.3.6.5/fs/ext4/ioctl.c       2013-05-31 19:50:08.000000000 +0000
3148 @@ -14,12 +14,40 @@
3149  #include <linux/compat.h>
3150  #include <linux/mount.h>
3151  #include <linux/file.h>
3152 +#include <linux/vs_tag.h>
3153  #include <asm/uaccess.h>
3154  #include "ext4_jbd2.h"
3155  #include "ext4.h"
3156  
3157  #define MAX_32_NUM ((((unsigned long long) 1) << 32) - 1)
3158  
3159 +int ext4_sync_flags(struct inode *inode, int flags, int vflags)
3160 +{
3161 +       handle_t *handle = NULL;
3162 +       struct ext4_iloc iloc;
3163 +       int err;
3164 +
3165 +       handle = ext4_journal_start(inode, EXT4_HT_INODE, 1);
3166 +       if (IS_ERR(handle))
3167 +               return PTR_ERR(handle);
3168 +
3169 +       if (IS_SYNC(inode))
3170 +               ext4_handle_sync(handle);
3171 +       err = ext4_reserve_inode_write(handle, inode, &iloc);
3172 +       if (err)
3173 +               goto flags_err;
3174 +
3175 +       inode->i_flags = flags;
3176 +       inode->i_vflags = vflags;
3177 +       ext4_get_inode_flags(EXT4_I(inode));
3178 +       inode->i_ctime = ext4_current_time(inode);
3179 +
3180 +       err = ext4_mark_iloc_dirty(handle, inode, &iloc);
3181 +flags_err:
3182 +       ext4_journal_stop(handle);
3183 +       return err;
3184 +}
3185 +
3186  long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3187  {
3188         struct inode *inode = file_inode(filp);
3189 @@ -53,6 +81,11 @@ long ext4_ioctl(struct file *filp, unsig
3190  
3191                 flags = ext4_mask_flags(inode->i_mode, flags);
3192  
3193 +               if (IS_BARRIER(inode)) {
3194 +                       vxwprintk_task(1, "messing with the barrier.");
3195 +                       return -EACCES;
3196 +               }
3197 +
3198                 err = -EPERM;
3199                 mutex_lock(&inode->i_mutex);
3200                 /* Is it quota file? Do not allow user to mess with it */
3201 @@ -70,7 +103,9 @@ long ext4_ioctl(struct file *filp, unsig
3202                  *
3203                  * This test looks nicer. Thanks to Pauline Middelink
3204                  */
3205 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
3206 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
3207 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
3208 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
3209                         if (!capable(CAP_LINUX_IMMUTABLE))
3210                                 goto flags_out;
3211                 }
3212 diff -NurpP --minimal linux-3.9.5/fs/ext4/namei.c linux-3.9.5-vs2.3.6.5/fs/ext4/namei.c
3213 --- linux-3.9.5/fs/ext4/namei.c 2013-05-31 13:45:23.000000000 +0000
3214 +++ linux-3.9.5-vs2.3.6.5/fs/ext4/namei.c       2013-05-31 14:47:11.000000000 +0000
3215 @@ -34,6 +34,7 @@
3216  #include <linux/quotaops.h>
3217  #include <linux/buffer_head.h>
3218  #include <linux/bio.h>
3219 +#include <linux/vs_tag.h>
3220  #include "ext4.h"
3221  #include "ext4_jbd2.h"
3222  
3223 @@ -1290,6 +1291,7 @@ restart:
3224                                         ll_rw_block(READ | REQ_META | REQ_PRIO,
3225                                                     1, &bh);
3226                         }
3227 +               dx_propagate_tag(nd, inode);
3228                 }
3229                 if ((bh = bh_use[ra_ptr++]) == NULL)
3230                         goto next;
3231 @@ -3190,6 +3192,7 @@ const struct inode_operations ext4_dir_i
3232         .removexattr    = generic_removexattr,
3233         .get_acl        = ext4_get_acl,
3234         .fiemap         = ext4_fiemap,
3235 +       .sync_flags     = ext4_sync_flags,
3236  };
3237  
3238  const struct inode_operations ext4_special_inode_operations = {
3239 diff -NurpP --minimal linux-3.9.5/fs/ext4/super.c linux-3.9.5-vs2.3.6.5/fs/ext4/super.c
3240 --- linux-3.9.5/fs/ext4/super.c 2013-06-11 12:22:39.000000000 +0000
3241 +++ linux-3.9.5-vs2.3.6.5/fs/ext4/super.c       2013-05-31 14:47:11.000000000 +0000
3242 @@ -1131,7 +1131,7 @@ enum {
3243         Opt_inode_readahead_blks, Opt_journal_ioprio,
3244         Opt_dioread_nolock, Opt_dioread_lock,
3245         Opt_discard, Opt_nodiscard, Opt_init_itable, Opt_noinit_itable,
3246 -       Opt_max_dir_size_kb,
3247 +       Opt_max_dir_size_kb, Opt_tag, Opt_notag, Opt_tagid
3248  };
3249  
3250  static const match_table_t tokens = {
3251 @@ -1211,6 +1211,9 @@ static const match_table_t tokens = {
3252         {Opt_removed, "reservation"},   /* mount option from ext2/3 */
3253         {Opt_removed, "noreservation"}, /* mount option from ext2/3 */
3254         {Opt_removed, "journal=%u"},    /* mount option from ext2/3 */
3255 +       {Opt_tag, "tag"},
3256 +       {Opt_notag, "notag"},
3257 +       {Opt_tagid, "tagid=%u"},
3258         {Opt_err, NULL},
3259  };
3260  
3261 @@ -1441,6 +1444,20 @@ static int handle_mount_opt(struct super
3262         case Opt_i_version:
3263                 sb->s_flags |= MS_I_VERSION;
3264                 return 1;
3265 +#ifndef CONFIG_TAGGING_NONE
3266 +       case Opt_tag:
3267 +               set_opt(sb, TAGGED);
3268 +               return 1;
3269 +       case Opt_notag:
3270 +               clear_opt(sb, TAGGED);
3271 +               return 1;
3272 +#endif
3273 +#ifdef CONFIG_PROPAGATE
3274 +       case Opt_tagid:
3275 +               /* use args[0] */
3276 +               set_opt(sb, TAGGED);
3277 +               return 1;
3278 +#endif
3279         }
3280  
3281         for (m = ext4_mount_opts; m->token != Opt_err; m++)
3282 @@ -3401,6 +3418,9 @@ static int ext4_fill_super(struct super_
3283                         clear_opt(sb, DELALLOC);
3284         }
3285  
3286 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
3287 +               sb->s_flags |= MS_TAGGED;
3288 +
3289         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3290                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3291  
3292 @@ -4587,6 +4607,14 @@ static int ext4_remount(struct super_blo
3293         if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
3294                 ext4_abort(sb, "Abort forced by user");
3295  
3296 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
3297 +               !(sb->s_flags & MS_TAGGED)) {
3298 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
3299 +                       sb->s_id);
3300 +               err = -EINVAL;
3301 +               goto restore_opts;
3302 +       }
3303 +
3304         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3305                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3306  
3307 diff -NurpP --minimal linux-3.9.5/fs/fcntl.c linux-3.9.5-vs2.3.6.5/fs/fcntl.c
3308 --- linux-3.9.5/fs/fcntl.c      2013-05-31 13:45:23.000000000 +0000
3309 +++ linux-3.9.5-vs2.3.6.5/fs/fcntl.c    2013-05-31 14:47:11.000000000 +0000
3310 @@ -21,6 +21,7 @@
3311  #include <linux/rcupdate.h>
3312  #include <linux/pid_namespace.h>
3313  #include <linux/user_namespace.h>
3314 +#include <linux/vs_limit.h>
3315  
3316  #include <asm/poll.h>
3317  #include <asm/siginfo.h>
3318 @@ -378,6 +379,8 @@ SYSCALL_DEFINE3(fcntl64, unsigned int, f
3319  
3320         if (!f.file)
3321                 goto out;
3322 +       if (!vx_files_avail(1))
3323 +               goto out;
3324  
3325         if (unlikely(f.file->f_mode & FMODE_PATH)) {
3326                 if (!check_fcntl_cmd(cmd))
3327 diff -NurpP --minimal linux-3.9.5/fs/file.c linux-3.9.5-vs2.3.6.5/fs/file.c
3328 --- linux-3.9.5/fs/file.c       2013-05-31 13:45:23.000000000 +0000
3329 +++ linux-3.9.5-vs2.3.6.5/fs/file.c     2013-05-31 14:47:11.000000000 +0000
3330 @@ -22,6 +22,7 @@
3331  #include <linux/spinlock.h>
3332  #include <linux/rcupdate.h>
3333  #include <linux/workqueue.h>
3334 +#include <linux/vs_limit.h>
3335  
3336  struct fdtable_defer {
3337         spinlock_t lock;
3338 @@ -364,6 +365,8 @@ struct files_struct *dup_fd(struct files
3339                 struct file *f = *old_fds++;
3340                 if (f) {
3341                         get_file(f);
3342 +                       /* TODO: sum it first for check and performance */
3343 +                       vx_openfd_inc(open_files - i);
3344                 } else {
3345                         /*
3346                          * The fd may be claimed in the fd bitmap but not yet
3347 @@ -429,9 +432,11 @@ static void close_files(struct files_str
3348                                         filp_close(file, files);
3349                                         cond_resched();
3350                                 }
3351 +                               vx_openfd_dec(i);
3352                         }
3353                         i++;
3354                         set >>= 1;
3355 +                       cond_resched();
3356                 }
3357         }
3358  }
3359 @@ -567,6 +572,7 @@ repeat:
3360         else
3361                 __clear_close_on_exec(fd, fdt);
3362         error = fd;
3363 +       vx_openfd_inc(fd);
3364  #if 1
3365         /* Sanity check */
3366         if (rcu_dereference_raw(fdt->fd[fd]) != NULL) {
3367 @@ -597,6 +603,7 @@ static void __put_unused_fd(struct files
3368         __clear_open_fd(fd, fdt);
3369         if (fd < files->next_fd)
3370                 files->next_fd = fd;
3371 +       vx_openfd_dec(fd);
3372  }
3373  
3374  void put_unused_fd(unsigned int fd)
3375 @@ -876,6 +883,8 @@ static int do_dup2(struct files_struct *
3376  
3377         if (tofree)
3378                 filp_close(tofree, files);
3379 +       else
3380 +               vx_openfd_inc(fd);      /* fd was unused */
3381  
3382         return fd;
3383  
3384 diff -NurpP --minimal linux-3.9.5/fs/file_table.c linux-3.9.5-vs2.3.6.5/fs/file_table.c
3385 --- linux-3.9.5/fs/file_table.c 2013-05-31 13:45:23.000000000 +0000
3386 +++ linux-3.9.5-vs2.3.6.5/fs/file_table.c       2013-05-31 14:47:11.000000000 +0000
3387 @@ -26,6 +26,8 @@
3388  #include <linux/hardirq.h>
3389  #include <linux/task_work.h>
3390  #include <linux/ima.h>
3391 +#include <linux/vs_limit.h>
3392 +#include <linux/vs_context.h>
3393  
3394  #include <linux/atomic.h>
3395  
3396 @@ -140,6 +142,8 @@ struct file *get_empty_filp(void)
3397         spin_lock_init(&f->f_lock);
3398         eventpoll_init_file(f);
3399         /* f->f_version: 0 */
3400 +       f->f_xid = vx_current_xid();
3401 +       vx_files_inc(f);
3402         return f;
3403  
3404  over:
3405 @@ -257,6 +261,8 @@ static void __fput(struct file *file)
3406                 i_readcount_dec(inode);
3407         if (file->f_mode & FMODE_WRITE)
3408                 drop_file_write_access(file);
3409 +       vx_files_dec(file);
3410 +       file->f_xid = 0;
3411         file->f_path.dentry = NULL;
3412         file->f_path.mnt = NULL;
3413         file->f_inode = NULL;
3414 @@ -344,6 +350,8 @@ void put_filp(struct file *file)
3415  {
3416         if (atomic_long_dec_and_test(&file->f_count)) {
3417                 security_file_free(file);
3418 +               vx_files_dec(file);
3419 +               file->f_xid = 0;
3420                 file_sb_list_del(file);
3421                 file_free(file);
3422         }
3423 diff -NurpP --minimal linux-3.9.5/fs/fs_struct.c linux-3.9.5-vs2.3.6.5/fs/fs_struct.c
3424 --- linux-3.9.5/fs/fs_struct.c  2013-05-31 13:45:23.000000000 +0000
3425 +++ linux-3.9.5-vs2.3.6.5/fs/fs_struct.c        2013-05-31 14:47:11.000000000 +0000
3426 @@ -4,6 +4,7 @@
3427  #include <linux/path.h>
3428  #include <linux/slab.h>
3429  #include <linux/fs_struct.h>
3430 +#include <linux/vserver/global.h>
3431  #include "internal.h"
3432  
3433  /*
3434 @@ -87,6 +88,7 @@ void free_fs_struct(struct fs_struct *fs
3435  {
3436         path_put(&fs->root);
3437         path_put(&fs->pwd);
3438 +       atomic_dec(&vs_global_fs);
3439         kmem_cache_free(fs_cachep, fs);
3440  }
3441  
3442 @@ -124,6 +126,7 @@ struct fs_struct *copy_fs_struct(struct
3443                 fs->pwd = old->pwd;
3444                 path_get(&fs->pwd);
3445                 spin_unlock(&old->lock);
3446 +               atomic_inc(&vs_global_fs);
3447         }
3448         return fs;
3449  }
3450 diff -NurpP --minimal linux-3.9.5/fs/gfs2/file.c linux-3.9.5-vs2.3.6.5/fs/gfs2/file.c
3451 --- linux-3.9.5/fs/gfs2/file.c  2013-05-31 13:45:23.000000000 +0000
3452 +++ linux-3.9.5-vs2.3.6.5/fs/gfs2/file.c        2013-05-31 19:54:27.000000000 +0000
3453 @@ -143,6 +143,9 @@ static const u32 fsflags_to_gfs2[32] = {
3454         [12] = GFS2_DIF_EXHASH,
3455         [14] = GFS2_DIF_INHERIT_JDATA,
3456         [17] = GFS2_DIF_TOPDIR,
3457 +       [27] = GFS2_DIF_IXUNLINK,
3458 +       [26] = GFS2_DIF_BARRIER,
3459 +       [29] = GFS2_DIF_COW,
3460  };
3461  
3462  static const u32 gfs2_to_fsflags[32] = {
3463 @@ -153,6 +156,9 @@ static const u32 gfs2_to_fsflags[32] = {
3464         [gfs2fl_ExHash] = FS_INDEX_FL,
3465         [gfs2fl_TopLevel] = FS_TOPDIR_FL,
3466         [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL,
3467 +       [gfs2fl_IXUnlink] = FS_IXUNLINK_FL,
3468 +       [gfs2fl_Barrier] = FS_BARRIER_FL,
3469 +       [gfs2fl_Cow] = FS_COW_FL,
3470  };
3471  
3472  static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
3473 @@ -183,12 +189,18 @@ void gfs2_set_inode_flags(struct inode *
3474  {
3475         struct gfs2_inode *ip = GFS2_I(inode);
3476         unsigned int flags = inode->i_flags;
3477 +       unsigned int vflags = inode->i_vflags;
3478 +
3479 +       flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3480 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC | S_NOSEC);
3481  
3482 -       flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC|S_NOSEC);
3483         if ((ip->i_eattr == 0) && !is_sxid(inode->i_mode))
3484                 inode->i_flags |= S_NOSEC;
3485         if (ip->i_diskflags & GFS2_DIF_IMMUTABLE)
3486                 flags |= S_IMMUTABLE;
3487 +       if (ip->i_diskflags & GFS2_DIF_IXUNLINK)
3488 +               flags |= S_IXUNLINK;
3489 +
3490         if (ip->i_diskflags & GFS2_DIF_APPENDONLY)
3491                 flags |= S_APPEND;
3492         if (ip->i_diskflags & GFS2_DIF_NOATIME)
3493 @@ -196,6 +208,43 @@ void gfs2_set_inode_flags(struct inode *
3494         if (ip->i_diskflags & GFS2_DIF_SYNC)
3495                 flags |= S_SYNC;
3496         inode->i_flags = flags;
3497 +
3498 +       vflags &= ~(V_BARRIER | V_COW);
3499 +
3500 +       if (ip->i_diskflags & GFS2_DIF_BARRIER)
3501 +               vflags |= V_BARRIER;
3502 +       if (ip->i_diskflags & GFS2_DIF_COW)
3503 +               vflags |= V_COW;
3504 +       inode->i_vflags = vflags;
3505 +}
3506 +
3507 +void gfs2_get_inode_flags(struct inode *inode)
3508 +{
3509 +       struct gfs2_inode *ip = GFS2_I(inode);
3510 +       unsigned int flags = inode->i_flags;
3511 +       unsigned int vflags = inode->i_vflags;
3512 +
3513 +       ip->i_diskflags &= ~(GFS2_DIF_APPENDONLY |
3514 +                       GFS2_DIF_NOATIME | GFS2_DIF_SYNC |
3515 +                       GFS2_DIF_IMMUTABLE | GFS2_DIF_IXUNLINK |
3516 +                       GFS2_DIF_BARRIER | GFS2_DIF_COW);
3517 +
3518 +       if (flags & S_IMMUTABLE)
3519 +               ip->i_diskflags |= GFS2_DIF_IMMUTABLE;
3520 +       if (flags & S_IXUNLINK)
3521 +               ip->i_diskflags |= GFS2_DIF_IXUNLINK;
3522 +
3523 +       if (flags & S_APPEND)
3524 +               ip->i_diskflags |= GFS2_DIF_APPENDONLY;
3525 +       if (flags & S_NOATIME)
3526 +               ip->i_diskflags |= GFS2_DIF_NOATIME;
3527 +       if (flags & S_SYNC)
3528 +               ip->i_diskflags |= GFS2_DIF_SYNC;
3529 +
3530 +       if (vflags & V_BARRIER)
3531 +               ip->i_diskflags |= GFS2_DIF_BARRIER;
3532 +       if (vflags & V_COW)
3533 +               ip->i_diskflags |= GFS2_DIF_COW;
3534  }
3535  
3536  /* Flags that can be set by user space */
3537 @@ -309,6 +358,37 @@ static int gfs2_set_flags(struct file *f
3538         return do_gfs2_set_flags(filp, gfsflags, ~GFS2_DIF_JDATA);
3539  }
3540  
3541 +int gfs2_sync_flags(struct inode *inode, int flags, int vflags)
3542 +{
3543 +       struct gfs2_inode *ip = GFS2_I(inode);
3544 +       struct gfs2_sbd *sdp = GFS2_SB(inode);
3545 +       struct buffer_head *bh;
3546 +       struct gfs2_holder gh;
3547 +       int error;
3548 +
3549 +       error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
3550 +       if (error)
3551 +               return error;
3552 +       error = gfs2_trans_begin(sdp, RES_DINODE, 0);
3553 +       if (error)
3554 +               goto out;
3555 +       error = gfs2_meta_inode_buffer(ip, &bh);
3556 +       if (error)
3557 +               goto out_trans_end;
3558 +       gfs2_trans_add_meta(ip->i_gl, bh);
3559 +       inode->i_flags = flags;
3560 +       inode->i_vflags = vflags;
3561 +       gfs2_get_inode_flags(inode);
3562 +       gfs2_dinode_out(ip, bh->b_data);
3563 +       brelse(bh);
3564 +       gfs2_set_aops(inode);
3565 +out_trans_end:
3566 +       gfs2_trans_end(sdp);
3567 +out:
3568 +       gfs2_glock_dq_uninit(&gh);
3569 +       return error;
3570 +}
3571 +
3572  static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3573  {
3574         switch(cmd) {
3575 diff -NurpP --minimal linux-3.9.5/fs/gfs2/inode.h linux-3.9.5-vs2.3.6.5/fs/gfs2/inode.h
3576 --- linux-3.9.5/fs/gfs2/inode.h 2012-12-11 03:30:57.000000000 +0000
3577 +++ linux-3.9.5-vs2.3.6.5/fs/gfs2/inode.h       2013-05-31 14:47:11.000000000 +0000
3578 @@ -117,6 +117,7 @@ extern const struct file_operations gfs2
3579  extern const struct file_operations gfs2_dir_fops_nolock;
3580  
3581  extern void gfs2_set_inode_flags(struct inode *inode);
3582 +extern int gfs2_sync_flags(struct inode *inode, int flags, int vflags);
3583   
3584  #ifdef CONFIG_GFS2_FS_LOCKING_DLM
3585  extern const struct file_operations gfs2_file_fops;
3586 diff -NurpP --minimal linux-3.9.5/fs/hostfs/hostfs.h linux-3.9.5-vs2.3.6.5/fs/hostfs/hostfs.h
3587 --- linux-3.9.5/fs/hostfs/hostfs.h      2012-12-11 03:30:57.000000000 +0000
3588 +++ linux-3.9.5-vs2.3.6.5/fs/hostfs/hostfs.h    2013-06-12 23:49:08.000000000 +0000
3589 @@ -42,6 +42,7 @@ struct hostfs_iattr {
3590         unsigned short  ia_mode;
3591         uid_t           ia_uid;
3592         gid_t           ia_gid;
3593 +       vtag_t          ia_tag;
3594         loff_t          ia_size;
3595         struct timespec ia_atime;
3596         struct timespec ia_mtime;
3597 diff -NurpP --minimal linux-3.9.5/fs/inode.c linux-3.9.5-vs2.3.6.5/fs/inode.c
3598 --- linux-3.9.5/fs/inode.c      2013-05-31 13:45:24.000000000 +0000
3599 +++ linux-3.9.5-vs2.3.6.5/fs/inode.c    2013-06-03 18:32:17.000000000 +0000
3600 @@ -17,6 +17,7 @@
3601  #include <linux/prefetch.h>
3602  #include <linux/buffer_head.h> /* for inode_has_buffers */
3603  #include <linux/ratelimit.h>
3604 +#include <linux/vs_tag.h>
3605  #include "internal.h"
3606  
3607  /*
3608 @@ -128,6 +129,8 @@ int inode_init_always(struct super_block
3609         struct address_space *const mapping = &inode->i_data;
3610  
3611         inode->i_sb = sb;
3612 +
3613 +       /* essential because of inode slab reuse */
3614         inode->i_blkbits = sb->s_blocksize_bits;
3615         inode->i_flags = 0;
3616         atomic_set(&inode->i_count, 1);
3617 @@ -137,6 +140,7 @@ int inode_init_always(struct super_block
3618         inode->i_opflags = 0;
3619         i_uid_write(inode, 0);
3620         i_gid_write(inode, 0);
3621 +       i_tag_write(inode, 0);
3622         atomic_set(&inode->i_writecount, 0);
3623         inode->i_size = 0;
3624         inode->i_blocks = 0;
3625 @@ -149,6 +153,7 @@ int inode_init_always(struct super_block
3626         inode->i_bdev = NULL;
3627         inode->i_cdev = NULL;
3628         inode->i_rdev = 0;
3629 +       inode->i_mdev = 0;
3630         inode->dirtied_when = 0;
3631  
3632         if (security_inode_alloc(inode))
3633 @@ -483,6 +488,8 @@ void __insert_inode_hash(struct inode *i
3634  }
3635  EXPORT_SYMBOL(__insert_inode_hash);
3636  
3637 +EXPORT_SYMBOL_GPL(__iget);
3638 +
3639  /**
3640   *     __remove_inode_hash - remove an inode from the hash
3641   *     @inode: inode to unhash
3642 @@ -1799,9 +1806,11 @@ void init_special_inode(struct inode *in
3643         if (S_ISCHR(mode)) {
3644                 inode->i_fop = &def_chr_fops;
3645                 inode->i_rdev = rdev;
3646 +               inode->i_mdev = rdev;
3647         } else if (S_ISBLK(mode)) {
3648                 inode->i_fop = &def_blk_fops;
3649                 inode->i_rdev = rdev;
3650 +               inode->i_mdev = rdev;
3651         } else if (S_ISFIFO(mode))
3652                 inode->i_fop = &def_fifo_fops;
3653         else if (S_ISSOCK(mode))
3654 @@ -1830,6 +1839,7 @@ void inode_init_owner(struct inode *inod
3655         } else
3656                 inode->i_gid = current_fsgid();
3657         inode->i_mode = mode;
3658 +       i_tag_write(inode, dx_current_fstag(inode->i_sb));
3659  }
3660  EXPORT_SYMBOL(inode_init_owner);
3661  
3662 diff -NurpP --minimal linux-3.9.5/fs/ioctl.c linux-3.9.5-vs2.3.6.5/fs/ioctl.c
3663 --- linux-3.9.5/fs/ioctl.c      2013-05-31 13:45:24.000000000 +0000
3664 +++ linux-3.9.5-vs2.3.6.5/fs/ioctl.c    2013-05-31 14:47:11.000000000 +0000
3665 @@ -15,6 +15,9 @@
3666  #include <linux/writeback.h>
3667  #include <linux/buffer_head.h>
3668  #include <linux/falloc.h>
3669 +#include <linux/proc_fs.h>
3670 +#include <linux/vserver/inode.h>
3671 +#include <linux/vs_tag.h>
3672  
3673  #include <asm/ioctls.h>
3674  
3675 diff -NurpP --minimal linux-3.9.5/fs/ioprio.c linux-3.9.5-vs2.3.6.5/fs/ioprio.c
3676 --- linux-3.9.5/fs/ioprio.c     2012-12-11 03:30:57.000000000 +0000
3677 +++ linux-3.9.5-vs2.3.6.5/fs/ioprio.c   2013-05-31 14:47:11.000000000 +0000
3678 @@ -28,6 +28,7 @@
3679  #include <linux/syscalls.h>
3680  #include <linux/security.h>
3681  #include <linux/pid_namespace.h>
3682 +#include <linux/vs_base.h>
3683  
3684  int set_task_ioprio(struct task_struct *task, int ioprio)
3685  {
3686 @@ -105,6 +106,8 @@ SYSCALL_DEFINE3(ioprio_set, int, which,
3687                         else
3688                                 pgrp = find_vpid(who);
3689                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3690 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3691 +                                       continue;
3692                                 ret = set_task_ioprio(p, ioprio);
3693                                 if (ret)
3694                                         break;
3695 @@ -198,6 +201,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which,
3696                         else
3697                                 pgrp = find_vpid(who);
3698                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3699 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3700 +                                       continue;
3701                                 tmpio = get_task_ioprio(p);
3702                                 if (tmpio < 0)
3703                                         continue;
3704 diff -NurpP --minimal linux-3.9.5/fs/jfs/file.c linux-3.9.5-vs2.3.6.5/fs/jfs/file.c
3705 --- linux-3.9.5/fs/jfs/file.c   2013-02-19 13:58:48.000000000 +0000
3706 +++ linux-3.9.5-vs2.3.6.5/fs/jfs/file.c 2013-05-31 14:47:11.000000000 +0000
3707 @@ -109,7 +109,8 @@ int jfs_setattr(struct dentry *dentry, s
3708         if (is_quota_modification(inode, iattr))
3709                 dquot_initialize(inode);
3710         if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
3711 -           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
3712 +           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid)) ||
3713 +           (iattr->ia_valid & ATTR_TAG && !tag_eq(iattr->ia_tag, inode->i_tag))) {
3714                 rc = dquot_transfer(inode, iattr);
3715                 if (rc)
3716                         return rc;
3717 @@ -144,6 +145,7 @@ const struct inode_operations jfs_file_i
3718  #ifdef CONFIG_JFS_POSIX_ACL
3719         .get_acl        = jfs_get_acl,
3720  #endif
3721 +       .sync_flags     = jfs_sync_flags,
3722  };
3723  
3724  const struct file_operations jfs_file_operations = {
3725 diff -NurpP --minimal linux-3.9.5/fs/jfs/ioctl.c linux-3.9.5-vs2.3.6.5/fs/jfs/ioctl.c
3726 --- linux-3.9.5/fs/jfs/ioctl.c  2013-05-31 13:45:24.000000000 +0000
3727 +++ linux-3.9.5-vs2.3.6.5/fs/jfs/ioctl.c        2013-05-31 14:47:11.000000000 +0000
3728 @@ -12,6 +12,7 @@
3729  #include <linux/time.h>
3730  #include <linux/sched.h>
3731  #include <linux/blkdev.h>
3732 +#include <linux/mount.h>
3733  #include <asm/current.h>
3734  #include <asm/uaccess.h>
3735  
3736 @@ -56,6 +57,16 @@ static long jfs_map_ext2(unsigned long f
3737  }
3738  
3739  
3740 +int jfs_sync_flags(struct inode *inode, int flags, int vflags)
3741 +{
3742 +       inode->i_flags = flags;
3743 +       inode->i_vflags = vflags;
3744 +       jfs_get_inode_flags(JFS_IP(inode));
3745 +       inode->i_ctime = CURRENT_TIME_SEC;
3746 +       mark_inode_dirty(inode);
3747 +       return 0;
3748 +}
3749 +
3750  long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3751  {
3752         struct inode *inode = file_inode(filp);
3753 @@ -89,6 +100,11 @@ long jfs_ioctl(struct file *filp, unsign
3754                 if (!S_ISDIR(inode->i_mode))
3755                         flags &= ~JFS_DIRSYNC_FL;
3756  
3757 +               if (IS_BARRIER(inode)) {
3758 +                       vxwprintk_task(1, "messing with the barrier.");
3759 +                       return -EACCES;
3760 +               }
3761 +
3762                 /* Is it quota file? Do not allow user to mess with it */
3763                 if (IS_NOQUOTA(inode)) {
3764                         err = -EPERM;
3765 @@ -106,8 +122,8 @@ long jfs_ioctl(struct file *filp, unsign
3766                  * the relevant capability.
3767                  */
3768                 if ((oldflags & JFS_IMMUTABLE_FL) ||
3769 -                       ((flags ^ oldflags) &
3770 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
3771 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
3772 +                       JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
3773                         if (!capable(CAP_LINUX_IMMUTABLE)) {
3774                                 mutex_unlock(&inode->i_mutex);
3775                                 err = -EPERM;
3776 @@ -115,7 +131,7 @@ long jfs_ioctl(struct file *filp, unsign
3777                         }
3778                 }
3779  
3780 -               flags = flags & JFS_FL_USER_MODIFIABLE;
3781 +               flags &= JFS_FL_USER_MODIFIABLE;
3782                 flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
3783                 jfs_inode->mode2 = flags;
3784  
3785 diff -NurpP --minimal linux-3.9.5/fs/jfs/jfs_dinode.h linux-3.9.5-vs2.3.6.5/fs/jfs/jfs_dinode.h
3786 --- linux-3.9.5/fs/jfs/jfs_dinode.h     2012-12-11 03:30:57.000000000 +0000
3787 +++ linux-3.9.5-vs2.3.6.5/fs/jfs/jfs_dinode.h   2013-05-31 14:47:11.000000000 +0000
3788 @@ -161,9 +161,13 @@ struct dinode {
3789  
3790  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
3791  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
3792 +#define JFS_IXUNLINK_FL                0x08000000 /* Immutable invert on unlink */
3793  
3794 -#define JFS_FL_USER_VISIBLE    0x03F80000
3795 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
3796 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
3797 +#define JFS_COW_FL             0x20000000 /* Copy on Write marker */
3798 +
3799 +#define JFS_FL_USER_VISIBLE    0x07F80000
3800 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
3801  #define JFS_FL_INHERIT         0x03C80000
3802  
3803  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
3804 diff -NurpP --minimal linux-3.9.5/fs/jfs/jfs_filsys.h linux-3.9.5-vs2.3.6.5/fs/jfs/jfs_filsys.h
3805 --- linux-3.9.5/fs/jfs/jfs_filsys.h     2012-12-11 03:30:57.000000000 +0000
3806 +++ linux-3.9.5-vs2.3.6.5/fs/jfs/jfs_filsys.h   2013-05-31 14:47:11.000000000 +0000
3807 @@ -266,6 +266,7 @@
3808  #define JFS_NAME_MAX   255
3809  #define JFS_PATH_MAX   BPSIZE
3810  
3811 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
3812  
3813  /*
3814   *     file system state (superblock state)
3815 diff -NurpP --minimal linux-3.9.5/fs/jfs/jfs_imap.c linux-3.9.5-vs2.3.6.5/fs/jfs/jfs_imap.c
3816 --- linux-3.9.5/fs/jfs/jfs_imap.c       2012-12-11 03:30:57.000000000 +0000
3817 +++ linux-3.9.5-vs2.3.6.5/fs/jfs/jfs_imap.c     2013-06-03 19:53:45.000000000 +0000
3818 @@ -46,6 +46,7 @@
3819  #include <linux/pagemap.h>
3820  #include <linux/quotaops.h>
3821  #include <linux/slab.h>
3822 +#include <linux/vs_tag.h>
3823  
3824  #include "jfs_incore.h"
3825  #include "jfs_inode.h"
3826 @@ -3058,6 +3059,8 @@ static int copy_from_dinode(struct dinod
3827  {
3828         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
3829         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
3830 +       kuid_t kuid;
3831 +       kgid_t kgid;
3832  
3833         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
3834         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
3835 @@ -3078,14 +3081,18 @@ static int copy_from_dinode(struct dinod
3836         }
3837         set_nlink(ip, le32_to_cpu(dip->di_nlink));
3838  
3839 -       jfs_ip->saved_uid = make_kuid(&init_user_ns, le32_to_cpu(dip->di_uid));
3840 +       kuid = make_kuid(&init_user_ns, le32_to_cpu(dip->di_uid));
3841 +       kgid = make_kgid(&init_user_ns, le32_to_cpu(dip->di_gid));
3842 +       ip->i_tag = INOTAG_KTAG(DX_TAG(ip), kuid, kgid, GLOBAL_ROOT_TAG);
3843 +
3844 +       jfs_ip->saved_uid = INOTAG_KUID(DX_TAG(ip), kuid, kgid);
3845         if (!uid_valid(sbi->uid))
3846                 ip->i_uid = jfs_ip->saved_uid;
3847         else {
3848                 ip->i_uid = sbi->uid;
3849         }
3850  
3851 -       jfs_ip->saved_gid = make_kgid(&init_user_ns, le32_to_cpu(dip->di_gid));
3852 +       jfs_ip->saved_gid = INOTAG_KGID(DX_TAG(ip), kuid, kgid);
3853         if (!gid_valid(sbi->gid))
3854                 ip->i_gid = jfs_ip->saved_gid;
3855         else {
3856 @@ -3150,16 +3157,14 @@ static void copy_to_dinode(struct dinode
3857         dip->di_size = cpu_to_le64(ip->i_size);
3858         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
3859         dip->di_nlink = cpu_to_le32(ip->i_nlink);
3860 -       if (!uid_valid(sbi->uid))
3861 -               dip->di_uid = cpu_to_le32(i_uid_read(ip));
3862 -       else
3863 -               dip->di_uid =cpu_to_le32(from_kuid(&init_user_ns,
3864 -                                                  jfs_ip->saved_uid));
3865 -       if (!gid_valid(sbi->gid))
3866 -               dip->di_gid = cpu_to_le32(i_gid_read(ip));
3867 -       else
3868 -               dip->di_gid = cpu_to_le32(from_kgid(&init_user_ns,
3869 -                                                   jfs_ip->saved_gid));
3870 +       dip->di_uid = cpu_to_le32(from_kuid(&init_user_ns,
3871 +               TAGINO_KUID(DX_TAG(ip),
3872 +               !uid_valid(sbi->uid) ? ip->i_uid : jfs_ip->saved_uid,
3873 +               ip->i_tag)));
3874 +       dip->di_gid = cpu_to_le32(from_kgid(&init_user_ns,
3875 +               TAGINO_KGID(DX_TAG(ip),
3876 +               !gid_valid(sbi->gid) ? ip->i_gid : jfs_ip->saved_gid,
3877 +               ip->i_tag)));
3878         jfs_get_inode_flags(jfs_ip);
3879         /*
3880          * mode2 is only needed for storing the higher order bits.
3881 diff -NurpP --minimal linux-3.9.5/fs/jfs/jfs_inode.c linux-3.9.5-vs2.3.6.5/fs/jfs/jfs_inode.c
3882 --- linux-3.9.5/fs/jfs/jfs_inode.c      2012-12-11 03:30:57.000000000 +0000
3883 +++ linux-3.9.5-vs2.3.6.5/fs/jfs/jfs_inode.c    2013-05-31 14:47:11.000000000 +0000
3884 @@ -18,6 +18,7 @@
3885  
3886  #include <linux/fs.h>
3887  #include <linux/quotaops.h>
3888 +#include <linux/vs_tag.h>
3889  #include "jfs_incore.h"
3890  #include "jfs_inode.h"
3891  #include "jfs_filsys.h"
3892 @@ -30,29 +31,46 @@ void jfs_set_inode_flags(struct inode *i
3893  {
3894         unsigned int flags = JFS_IP(inode)->mode2;
3895  
3896 -       inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
3897 -               S_NOATIME | S_DIRSYNC | S_SYNC);
3898 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3899 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3900  
3901         if (flags & JFS_IMMUTABLE_FL)
3902                 inode->i_flags |= S_IMMUTABLE;
3903 +       if (flags & JFS_IXUNLINK_FL)
3904 +               inode->i_flags |= S_IXUNLINK;
3905 +
3906 +       if (flags & JFS_SYNC_FL)
3907 +               inode->i_flags |= S_SYNC;
3908         if (flags & JFS_APPEND_FL)
3909                 inode->i_flags |= S_APPEND;
3910         if (flags & JFS_NOATIME_FL)
3911                 inode->i_flags |= S_NOATIME;
3912         if (flags & JFS_DIRSYNC_FL)
3913                 inode->i_flags |= S_DIRSYNC;
3914 -       if (flags & JFS_SYNC_FL)
3915 -               inode->i_flags |= S_SYNC;
3916 +
3917 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3918 +
3919 +       if (flags & JFS_BARRIER_FL)
3920 +               inode->i_vflags |= V_BARRIER;
3921 +       if (flags & JFS_COW_FL)
3922 +               inode->i_vflags |= V_COW;
3923  }
3924  
3925  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
3926  {
3927         unsigned int flags = jfs_ip->vfs_inode.i_flags;
3928 +       unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
3929 +
3930 +       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
3931 +                          JFS_APPEND_FL | JFS_NOATIME_FL |
3932 +                          JFS_DIRSYNC_FL | JFS_SYNC_FL |
3933 +                          JFS_BARRIER_FL | JFS_COW_FL);
3934  
3935 -       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
3936 -                          JFS_DIRSYNC_FL | JFS_SYNC_FL);
3937         if (flags & S_IMMUTABLE)
3938                 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
3939 +       if (flags & S_IXUNLINK)
3940 +               jfs_ip->mode2 |= JFS_IXUNLINK_FL;
3941 +
3942         if (flags & S_APPEND)
3943                 jfs_ip->mode2 |= JFS_APPEND_FL;
3944         if (flags & S_NOATIME)
3945 @@ -61,6 +79,11 @@ void jfs_get_inode_flags(struct jfs_inod
3946                 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
3947         if (flags & S_SYNC)
3948                 jfs_ip->mode2 |= JFS_SYNC_FL;
3949 +
3950 +       if (vflags & V_BARRIER)
3951 +               jfs_ip->mode2 |= JFS_BARRIER_FL;
3952 +       if (vflags & V_COW)
3953 +               jfs_ip->mode2 |= JFS_COW_FL;
3954  }
3955  
3956  /*
3957 diff -NurpP --minimal linux-3.9.5/fs/jfs/jfs_inode.h linux-3.9.5-vs2.3.6.5/fs/jfs/jfs_inode.h
3958 --- linux-3.9.5/fs/jfs/jfs_inode.h      2012-12-11 03:30:57.000000000 +0000
3959 +++ linux-3.9.5-vs2.3.6.5/fs/jfs/jfs_inode.h    2013-05-31 14:47:11.000000000 +0000
3960 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
3961  extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
3962         int fh_len, int fh_type);
3963  extern void jfs_set_inode_flags(struct inode *);
3964 +extern int jfs_sync_flags(struct inode *, int, int);
3965  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
3966  extern int jfs_setattr(struct dentry *, struct iattr *);
3967  
3968 diff -NurpP --minimal linux-3.9.5/fs/jfs/namei.c linux-3.9.5-vs2.3.6.5/fs/jfs/namei.c
3969 --- linux-3.9.5/fs/jfs/namei.c  2012-12-11 03:30:57.000000000 +0000
3970 +++ linux-3.9.5-vs2.3.6.5/fs/jfs/namei.c        2013-05-31 14:47:11.000000000 +0000
3971 @@ -22,6 +22,7 @@
3972  #include <linux/ctype.h>
3973  #include <linux/quotaops.h>
3974  #include <linux/exportfs.h>
3975 +#include <linux/vs_tag.h>
3976  #include "jfs_incore.h"
3977  #include "jfs_superblock.h"
3978  #include "jfs_inode.h"
3979 @@ -1461,6 +1462,7 @@ static struct dentry *jfs_lookup(struct
3980                         jfs_err("jfs_lookup: iget failed on inum %d", (uint)inum);
3981         }
3982  
3983 +       dx_propagate_tag(nd, ip);
3984         return d_splice_alias(ip, dentry);
3985  }
3986  
3987 @@ -1525,6 +1527,7 @@ const struct inode_operations jfs_dir_in
3988  #ifdef CONFIG_JFS_POSIX_ACL
3989         .get_acl        = jfs_get_acl,
3990  #endif
3991 +       .sync_flags     = jfs_sync_flags,
3992  };
3993  
3994  const struct file_operations jfs_dir_operations = {
3995 diff -NurpP --minimal linux-3.9.5/fs/jfs/super.c linux-3.9.5-vs2.3.6.5/fs/jfs/super.c
3996 --- linux-3.9.5/fs/jfs/super.c  2013-05-31 13:45:24.000000000 +0000
3997 +++ linux-3.9.5-vs2.3.6.5/fs/jfs/super.c        2013-05-31 14:47:11.000000000 +0000
3998 @@ -199,7 +199,8 @@ enum {
3999         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
4000         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
4001         Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
4002 -       Opt_discard, Opt_nodiscard, Opt_discard_minblk
4003 +       Opt_discard, Opt_nodiscard, Opt_discard_minblk,
4004 +       Opt_tag, Opt_notag, Opt_tagid
4005  };
4006  
4007  static const match_table_t tokens = {
4008 @@ -209,6 +210,10 @@ static const match_table_t tokens = {
4009         {Opt_resize, "resize=%u"},
4010         {Opt_resize_nosize, "resize"},
4011         {Opt_errors, "errors=%s"},
4012 +       {Opt_tag, "tag"},
4013 +       {Opt_notag, "notag"},
4014 +       {Opt_tagid, "tagid=%u"},
4015 +       {Opt_tag, "tagxid"},
4016         {Opt_ignore, "noquota"},
4017         {Opt_ignore, "quota"},
4018         {Opt_usrquota, "usrquota"},
4019 @@ -385,7 +390,20 @@ static int parse_options(char *options,
4020                         }
4021                         break;
4022                 }
4023 -
4024 +#ifndef CONFIG_TAGGING_NONE
4025 +               case Opt_tag:
4026 +                       *flag |= JFS_TAGGED;
4027 +                       break;
4028 +               case Opt_notag:
4029 +                       *flag &= JFS_TAGGED;
4030 +                       break;
4031 +#endif
4032 +#ifdef CONFIG_PROPAGATE
4033 +               case Opt_tagid:
4034 +                       /* use args[0] */
4035 +                       *flag |= JFS_TAGGED;
4036 +                       break;
4037 +#endif
4038                 default:
4039                         printk("jfs: Unrecognized mount option \"%s\" "
4040                                         " or missing value\n", p);
4041 @@ -417,6 +435,12 @@ static int jfs_remount(struct super_bloc
4042                 return -EINVAL;
4043         }
4044  
4045 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
4046 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
4047 +                       sb->s_id);
4048 +               return -EINVAL;
4049 +       }
4050 +
4051         if (newLVSize) {
4052                 if (sb->s_flags & MS_RDONLY) {
4053                         pr_err("JFS: resize requires volume" \
4054 @@ -502,6 +526,9 @@ static int jfs_fill_super(struct super_b
4055  #ifdef CONFIG_JFS_POSIX_ACL
4056         sb->s_flags |= MS_POSIXACL;
4057  #endif
4058 +       /* map mount option tagxid */
4059 +       if (sbi->flag & JFS_TAGGED)
4060 +               sb->s_flags |= MS_TAGGED;
4061  
4062         if (newLVSize) {
4063                 pr_err("resize option for remount only\n");
4064 diff -NurpP --minimal linux-3.9.5/fs/libfs.c linux-3.9.5-vs2.3.6.5/fs/libfs.c
4065 --- linux-3.9.5/fs/libfs.c      2013-02-19 13:58:48.000000000 +0000
4066 +++ linux-3.9.5-vs2.3.6.5/fs/libfs.c    2013-05-31 14:47:11.000000000 +0000
4067 @@ -135,7 +135,8 @@ static inline unsigned char dt_type(stru
4068   * both impossible due to the lock on directory.
4069   */
4070  
4071 -int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
4072 +static inline int do_dcache_readdir_filter(struct file *filp,
4073 +       void *dirent, filldir_t filldir, int (*filter)(struct dentry *dentry))
4074  {
4075         struct dentry *dentry = filp->f_path.dentry;
4076         struct dentry *cursor = filp->private_data;
4077 @@ -166,6 +167,8 @@ int dcache_readdir(struct file * filp, v
4078                         for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
4079                                 struct dentry *next;
4080                                 next = list_entry(p, struct dentry, d_u.d_child);
4081 +                               if (filter && !filter(next))
4082 +                                       continue;
4083                                 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
4084                                 if (!simple_positive(next)) {
4085                                         spin_unlock(&next->d_lock);
4086 @@ -192,6 +195,17 @@ int dcache_readdir(struct file * filp, v
4087         return 0;
4088  }
4089  
4090 +int dcache_readdir(struct file *filp, void *dirent, filldir_t filldir)
4091 +{
4092 +       return do_dcache_readdir_filter(filp, dirent, filldir, NULL);
4093 +}
4094 +
4095 +int dcache_readdir_filter(struct file *filp, void *dirent, filldir_t filldir,
4096 +       int (*filter)(struct dentry *))
4097 +{
4098 +       return do_dcache_readdir_filter(filp, dirent, filldir, filter);
4099 +}
4100 +
4101  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
4102  {
4103         return -EISDIR;
4104 @@ -981,6 +995,7 @@ EXPORT_SYMBOL(dcache_dir_close);
4105  EXPORT_SYMBOL(dcache_dir_lseek);
4106  EXPORT_SYMBOL(dcache_dir_open);
4107  EXPORT_SYMBOL(dcache_readdir);
4108 +EXPORT_SYMBOL(dcache_readdir_filter);
4109  EXPORT_SYMBOL(generic_read_dir);
4110  EXPORT_SYMBOL(mount_pseudo);
4111  EXPORT_SYMBOL(simple_write_begin);
4112 diff -NurpP --minimal linux-3.9.5/fs/locks.c linux-3.9.5-vs2.3.6.5/fs/locks.c
4113 --- linux-3.9.5/fs/locks.c      2013-05-31 13:45:24.000000000 +0000
4114 +++ linux-3.9.5-vs2.3.6.5/fs/locks.c    2013-06-12 23:49:08.000000000 +0000
4115 @@ -126,6 +126,8 @@
4116  #include <linux/time.h>
4117  #include <linux/rcupdate.h>
4118  #include <linux/pid_namespace.h>
4119 +#include <linux/vs_base.h>
4120 +#include <linux/vs_limit.h>
4121  
4122  #include <asm/uaccess.h>
4123  
4124 @@ -184,11 +186,17 @@ static void locks_init_lock_heads(struct
4125  /* Allocate an empty lock structure. */
4126  struct file_lock *locks_alloc_lock(void)
4127  {
4128 -       struct file_lock *fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4129 +       struct file_lock *fl;
4130  
4131 -       if (fl)
4132 -               locks_init_lock_heads(fl);
4133 +       if (!vx_locks_avail(1))
4134 +               return NULL;
4135  
4136 +       fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4137 +
4138 +       if (fl) {
4139 +               locks_init_lock_heads(fl);
4140 +               fl->fl_xid = -1;
4141 +       }
4142         return fl;
4143  }
4144  EXPORT_SYMBOL_GPL(locks_alloc_lock);
4145 @@ -212,6 +220,7 @@ void locks_free_lock(struct file_lock *f
4146         BUG_ON(!list_empty(&fl->fl_block));
4147         BUG_ON(!list_empty(&fl->fl_link));
4148  
4149 +       vx_locks_dec(fl);
4150         locks_release_private(fl);
4151         kmem_cache_free(filelock_cache, fl);
4152  }
4153 @@ -221,6 +230,7 @@ void locks_init_lock(struct file_lock *f
4154  {
4155         memset(fl, 0, sizeof(struct file_lock));
4156         locks_init_lock_heads(fl);
4157 +       fl->fl_xid = -1;
4158  }
4159  
4160  EXPORT_SYMBOL(locks_init_lock);
4161 @@ -261,6 +271,7 @@ void locks_copy_lock(struct file_lock *n
4162         new->fl_file = fl->fl_file;
4163         new->fl_ops = fl->fl_ops;
4164         new->fl_lmops = fl->fl_lmops;
4165 +       new->fl_xid = fl->fl_xid;
4166  
4167         locks_copy_private(new, fl);
4168  }
4169 @@ -299,6 +310,11 @@ static int flock_make_lock(struct file *
4170         fl->fl_flags = FL_FLOCK;
4171         fl->fl_type = type;
4172         fl->fl_end = OFFSET_MAX;
4173 +
4174 +       vxd_assert(filp->f_xid == vx_current_xid(),
4175 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4176 +       fl->fl_xid = filp->f_xid;
4177 +       vx_locks_inc(fl);
4178         
4179         *lock = fl;
4180         return 0;
4181 @@ -438,6 +454,7 @@ static int lease_init(struct file *filp,
4182  
4183         fl->fl_owner = current->files;
4184         fl->fl_pid = current->tgid;
4185 +       fl->fl_xid = vx_current_xid();
4186  
4187         fl->fl_file = filp;
4188         fl->fl_flags = FL_LEASE;
4189 @@ -457,6 +474,11 @@ static struct file_lock *lease_alloc(str
4190         if (fl == NULL)
4191                 return ERR_PTR(error);
4192  
4193 +       fl->fl_xid = vx_current_xid();
4194 +       if (filp)
4195 +               vxd_assert(filp->f_xid == fl->fl_xid,
4196 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
4197 +       vx_locks_inc(fl);
4198         error = lease_init(filp, type, fl);
4199         if (error) {
4200                 locks_free_lock(fl);
4201 @@ -753,6 +775,7 @@ static int flock_lock_file(struct file *
4202                 lock_flocks();
4203         }
4204  
4205 +       new_fl->fl_xid = -1;
4206  find_conflict:
4207         for_each_lock(inode, before) {
4208                 struct file_lock *fl = *before;
4209 @@ -773,6 +796,7 @@ find_conflict:
4210                 goto out;
4211         locks_copy_lock(new_fl, request);
4212         locks_insert_lock(before, new_fl);
4213 +       vx_locks_inc(new_fl);
4214         new_fl = NULL;
4215         error = 0;
4216  
4217 @@ -783,7 +807,8 @@ out:
4218         return error;
4219  }
4220  
4221 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
4222 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
4223 +       struct file_lock *conflock, vxid_t xid)
4224  {
4225         struct file_lock *fl;
4226         struct file_lock *new_fl = NULL;
4227 @@ -793,6 +818,8 @@ static int __posix_lock_file(struct inod
4228         struct file_lock **before;
4229         int error, added = 0;
4230  
4231 +       vxd_assert(xid == vx_current_xid(),
4232 +               "xid(%d) == current(%d)", xid, vx_current_xid());
4233         /*
4234          * We may need two file_lock structures for this operation,
4235          * so we get them in advance to avoid races.
4236 @@ -803,7 +830,11 @@ static int __posix_lock_file(struct inod
4237             (request->fl_type != F_UNLCK ||
4238              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
4239                 new_fl = locks_alloc_lock();
4240 +               new_fl->fl_xid = xid;
4241 +               vx_locks_inc(new_fl);
4242                 new_fl2 = locks_alloc_lock();
4243 +               new_fl2->fl_xid = xid;
4244 +               vx_locks_inc(new_fl2);
4245         }
4246  
4247         lock_flocks();
4248 @@ -1002,7 +1033,8 @@ static int __posix_lock_file(struct inod
4249  int posix_lock_file(struct file *filp, struct file_lock *fl,
4250                         struct file_lock *conflock)
4251  {
4252 -       return __posix_lock_file(file_inode(filp), fl, conflock);
4253 +       return __posix_lock_file(file_inode(filp),
4254 +               fl, conflock, filp->f_xid);
4255  }
4256  EXPORT_SYMBOL(posix_lock_file);
4257  
4258 @@ -1092,7 +1124,7 @@ int locks_mandatory_area(int read_write,
4259         fl.fl_end = offset + count - 1;
4260  
4261         for (;;) {
4262 -               error = __posix_lock_file(inode, &fl, NULL);
4263 +               error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
4264                 if (error != FILE_LOCK_DEFERRED)
4265                         break;
4266                 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
4267 @@ -1397,6 +1429,7 @@ int generic_add_lease(struct file *filp,
4268                 goto out;
4269  
4270         locks_insert_lock(before, lease);
4271 +       vx_locks_inc(lease);
4272         return 0;
4273  
4274  out:
4275 @@ -1836,6 +1869,11 @@ int fcntl_setlk(unsigned int fd, struct
4276         if (file_lock == NULL)
4277                 return -ENOLCK;
4278  
4279 +       vxd_assert(filp->f_xid == vx_current_xid(),
4280 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4281 +       file_lock->fl_xid = filp->f_xid;
4282 +       vx_locks_inc(file_lock);
4283 +
4284         /*
4285          * This might block, so we do it before checking the inode.
4286          */
4287 @@ -1954,6 +1992,11 @@ int fcntl_setlk64(unsigned int fd, struc
4288         if (file_lock == NULL)
4289                 return -ENOLCK;
4290  
4291 +       vxd_assert(filp->f_xid == vx_current_xid(),
4292 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4293 +       file_lock->fl_xid = filp->f_xid;
4294 +       vx_locks_inc(file_lock);
4295 +
4296         /*
4297          * This might block, so we do it before checking the inode.
4298          */
4299 @@ -2219,8 +2262,11 @@ static int locks_show(struct seq_file *f
4300  
4301         lock_get_status(f, fl, *((loff_t *)f->private), "");
4302  
4303 -       list_for_each_entry(bfl, &fl->fl_block, fl_block)
4304 +       list_for_each_entry(bfl, &fl->fl_block, fl_block) {
4305 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
4306 +                       continue;
4307                 lock_get_status(f, bfl, *((loff_t *)f->private), " ->");
4308 +       }
4309  
4310         return 0;
4311  }
4312 diff -NurpP --minimal linux-3.9.5/fs/mount.h linux-3.9.5-vs2.3.6.5/fs/mount.h
4313 --- linux-3.9.5/fs/mount.h      2013-02-19 13:58:48.000000000 +0000
4314 +++ linux-3.9.5-vs2.3.6.5/fs/mount.h    2013-06-12 23:49:08.000000000 +0000
4315 @@ -49,6 +49,7 @@ struct mount {
4316         int mnt_expiry_mark;            /* true if marked for expiry */
4317         int mnt_pinned;
4318         int mnt_ghosts;
4319 +       vtag_t mnt_tag;                 /* tagging used for vfsmount */
4320  };
4321  
4322  #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
4323 diff -NurpP --minimal linux-3.9.5/fs/namei.c linux-3.9.5-vs2.3.6.5/fs/namei.c
4324 --- linux-3.9.5/fs/namei.c      2013-06-11 12:22:39.000000000 +0000
4325 +++ linux-3.9.5-vs2.3.6.5/fs/namei.c    2013-06-12 23:49:08.000000000 +0000
4326 @@ -34,6 +34,14 @@
4327  #include <linux/device_cgroup.h>
4328  #include <linux/fs_struct.h>
4329  #include <linux/posix_acl.h>
4330 +#include <linux/proc_fs.h>
4331 +#include <linux/vserver/inode.h>
4332 +#include <linux/vs_base.h>
4333 +#include <linux/vs_tag.h>
4334 +#include <linux/vs_cowbl.h>
4335 +#include <linux/vs_device.h>
4336 +#include <linux/vs_context.h>
4337 +#include <linux/pid_namespace.h>
4338  #include <asm/uaccess.h>
4339  
4340  #include "internal.h"
4341 @@ -266,6 +274,89 @@ static int check_acl(struct inode *inode
4342         return -EAGAIN;
4343  }
4344  
4345 +static inline int dx_barrier(const struct inode *inode)
4346 +{
4347 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
4348 +               vxwprintk_task(1, "did hit the barrier.");
4349 +               return 1;
4350 +       }
4351 +       return 0;
4352 +}
4353 +
4354 +static int __dx_permission(const struct inode *inode, int mask)
4355 +{
4356 +       if (dx_barrier(inode))
4357 +               return -EACCES;
4358 +
4359 +       if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
4360 +               /* devpts is xid tagged */
4361 +               if (S_ISDIR(inode->i_mode) ||
4362 +                   vx_check((vxid_t)i_tag_read(inode), VS_IDENT | VS_WATCH_P))
4363 +                       return 0;
4364 +
4365 +               /* just pretend we didn't find anything */
4366 +               return -ENOENT;
4367 +       }
4368 +       else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
4369 +               struct proc_dir_entry *de = PDE(inode);
4370 +
4371 +               if (de && !vx_hide_check(0, de->vx_flags))
4372 +                       goto out;
4373 +
4374 +               if ((mask & (MAY_WRITE | MAY_APPEND))) {
4375 +                       struct pid *pid;
4376 +                       struct task_struct *tsk;
4377 +
4378 +                       if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
4379 +                           vx_flags(VXF_STATE_SETUP, 0))
4380 +                               return 0;
4381 +
4382 +                       pid = PROC_I(inode)->pid;
4383 +                       if (!pid)
4384 +                               goto out;
4385 +
4386 +                       rcu_read_lock();
4387 +                       tsk = pid_task(pid, PIDTYPE_PID);
4388 +                       vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
4389 +                                 tsk, (tsk ? vx_task_xid(tsk) : 0));
4390 +                       if (tsk &&
4391 +                               vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P)) {
4392 +                               rcu_read_unlock();
4393 +                               return 0;
4394 +                       }
4395 +                       rcu_read_unlock();
4396 +               }
4397 +               else {
4398 +                       /* FIXME: Should we block some entries here? */
4399 +                       return 0;
4400 +               }
4401 +       }
4402 +       else {
4403 +               if (dx_notagcheck(inode->i_sb) ||
4404 +                   dx_check((vxid_t)i_tag_read(inode),
4405 +                       DX_HOSTID | DX_ADMIN | DX_WATCH | DX_IDENT))
4406 +                       return 0;
4407 +       }
4408 +
4409 +out:
4410 +       return -EACCES;
4411 +}
4412 +
4413 +int dx_permission(const struct inode *inode, int mask)
4414 +{
4415 +       int ret = __dx_permission(inode, mask);
4416 +       if (unlikely(ret)) {
4417 +#ifndef        CONFIG_VSERVER_WARN_DEVPTS
4418 +               if (inode->i_sb->s_magic != DEVPTS_SUPER_MAGIC)
4419 +#endif
4420 +                   vxwprintk_task(1,
4421 +                       "denied [0x%x] access to inode %s:%p[#%d,%lu]",
4422 +                       mask, inode->i_sb->s_id, inode,
4423 +                       i_tag_read(inode), inode->i_ino);
4424 +       }
4425 +       return ret;
4426 +}
4427 +
4428  /*
4429   * This does the basic permission checking
4430   */
4431 @@ -388,10 +479,14 @@ int __inode_permission(struct inode *ino
4432                 /*
4433                  * Nobody gets write access to an immutable file.
4434                  */
4435 -               if (IS_IMMUTABLE(inode))
4436 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
4437                         return -EACCES;
4438         }
4439  
4440 +       retval = dx_permission(inode, mask);
4441 +       if (retval)
4442 +               return retval;
4443 +
4444         retval = do_inode_permission(inode, mask);
4445         if (retval)
4446                 return retval;
4447 @@ -1238,7 +1333,8 @@ static void follow_dotdot(struct nameida
4448  
4449                 if (nd->path.dentry == nd->root.dentry &&
4450                     nd->path.mnt == nd->root.mnt) {
4451 -                       break;
4452 +                       /* for sane '/' avoid follow_mount() */
4453 +                       return;
4454                 }
4455                 if (nd->path.dentry != nd->path.mnt->mnt_root) {
4456                         /* rare case of legitimate dget_parent()... */
4457 @@ -1383,6 +1479,9 @@ static int lookup_fast(struct nameidata
4458                                 goto unlazy;
4459                         }
4460                 }
4461 +
4462 +               /* FIXME: check dx permission */
4463 +
4464                 path->mnt = mnt;
4465                 path->dentry = dentry;
4466                 if (unlikely(!__follow_mount_rcu(nd, path, inode)))
4467 @@ -1413,6 +1512,8 @@ unlazy:
4468                 }
4469         }
4470  
4471 +       /* FIXME: check dx permission */
4472 +
4473         path->mnt = mnt;
4474         path->dentry = dentry;
4475         err = follow_managed(path, nd->flags);
4476 @@ -2237,7 +2338,7 @@ static int may_delete(struct inode *dir,
4477         if (IS_APPEND(dir))
4478                 return -EPERM;
4479         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
4480 -           IS_IMMUTABLE(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4481 +               IS_IXORUNLINK(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4482                 return -EPERM;
4483         if (isdir) {
4484                 if (!S_ISDIR(victim->d_inode->i_mode))
4485 @@ -2316,19 +2417,25 @@ int vfs_create(struct inode *dir, struct
4486                 bool want_excl)
4487  {
4488         int error = may_create(dir, dentry);
4489 -       if (error)
4490 +       if (error) {
4491 +               vxdprintk(VXD_CBIT(misc, 3), "may_create failed with %d", error);
4492                 return error;
4493 +       }
4494  
4495         if (!dir->i_op->create)
4496                 return -EACCES; /* shouldn't it be ENOSYS? */
4497         mode &= S_IALLUGO;
4498         mode |= S_IFREG;
4499         error = security_inode_create(dir, dentry, mode);
4500 -       if (error)
4501 +       if (error) {
4502 +               vxdprintk(VXD_CBIT(misc, 3), "security_inode_create failed with %d", error);
4503                 return error;
4504 +       }
4505         error = dir->i_op->create(dir, dentry, mode, want_excl);
4506         if (!error)
4507                 fsnotify_create(dir, dentry);
4508 +       else
4509 +               vxdprintk(VXD_CBIT(misc, 3), "i_op->create failed with %d", error);
4510         return error;
4511  }
4512  
4513 @@ -2363,6 +2470,15 @@ static int may_open(struct path *path, i
4514                 break;
4515         }
4516  
4517 +#ifdef CONFIG_VSERVER_COWBL
4518 +       if (IS_COW(inode) &&
4519 +               ((flag & O_ACCMODE) != O_RDONLY)) {
4520 +               if (IS_COW_LINK(inode))
4521 +                       return -EMLINK;
4522 +               inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
4523 +               mark_inode_dirty(inode);
4524 +       }
4525 +#endif
4526         error = inode_permission(inode, acc_mode);
4527         if (error)
4528                 return error;
4529 @@ -2865,6 +2981,16 @@ finish_open:
4530         }
4531  finish_open_created:
4532         error = may_open(&nd->path, acc_mode, open_flag);
4533 +#ifdef CONFIG_VSERVER_COWBL
4534 +       if (error == -EMLINK) {
4535 +               struct dentry *dentry;
4536 +               dentry = cow_break_link(name->name);
4537 +               if (IS_ERR(dentry))
4538 +                       error = PTR_ERR(dentry);
4539 +               else
4540 +                       dput(dentry);
4541 +       }
4542 +#endif
4543         if (error)
4544                 goto out;
4545         file->f_path.mnt = nd->path.mnt;
4546 @@ -2929,6 +3055,7 @@ static struct file *path_openat(int dfd,
4547         int opened = 0;
4548         int error;
4549  
4550 +restart:
4551         file = get_empty_filp();
4552         if (IS_ERR(file))
4553                 return file;
4554 @@ -2965,6 +3092,16 @@ static struct file *path_openat(int dfd,
4555                 error = do_last(nd, &path, file, op, &opened, pathname);
4556                 put_link(nd, &link, cookie);
4557         }
4558 +
4559 +#ifdef CONFIG_VSERVER_COWBL
4560 +       if (error == -EMLINK) {
4561 +               if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4562 +                       path_put(&nd->root);
4563 +               if (base)
4564 +                       fput(base);
4565 +               goto restart;
4566 +       }
4567 +#endif
4568  out:
4569         if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4570                 path_put(&nd->root);
4571 @@ -3079,6 +3216,11 @@ struct dentry *kern_path_create(int dfd,
4572                 goto fail;
4573         }
4574         *path = nd.path;
4575 +       vxdprintk(VXD_CBIT(misc, 3), "kern_path_create path.dentry = %p (%.*s), dentry = %p (%.*s), d_inode = %p",
4576 +               path->dentry, path->dentry->d_name.len,
4577 +               path->dentry->d_name.name, dentry,
4578 +               dentry->d_name.len, dentry->d_name.name,
4579 +               path->dentry->d_inode);
4580         return dentry;
4581  fail:
4582         dput(dentry);
4583 @@ -3573,7 +3715,7 @@ int vfs_link(struct dentry *old_dentry,
4584         /*
4585          * A link to an append-only or immutable file cannot be created.
4586          */
4587 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
4588 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
4589                 return -EPERM;
4590         if (!dir->i_op->link)
4591                 return -EPERM;
4592 @@ -3976,6 +4118,286 @@ int vfs_follow_link(struct nameidata *nd
4593         return __vfs_follow_link(nd, link);
4594  }
4595  
4596 +
4597 +#ifdef CONFIG_VSERVER_COWBL
4598 +
4599 +static inline
4600 +long do_cow_splice(struct file *in, struct file *out, size_t len)
4601 +{
4602 +       loff_t ppos = 0;
4603 +
4604 +       return do_splice_direct(in, &ppos, out, len, 0);
4605 +}
4606 +
4607 +struct dentry *cow_break_link(const char *pathname)
4608 +{
4609 +       int ret, mode, pathlen, redo = 0, drop = 1;
4610 +       struct nameidata old_nd, dir_nd;
4611 +       struct path dir_path, *old_path, *new_path;
4612 +       struct dentry *dir, *old_dentry, *new_dentry = NULL;
4613 +       struct file *old_file;
4614 +       struct file *new_file;
4615 +       char *to, *path, pad='\251';
4616 +       loff_t size;
4617 +
4618 +       vxdprintk(VXD_CBIT(misc, 1),
4619 +               "cow_break_link(" VS_Q("%s") ")", pathname);
4620 +
4621 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
4622 +       ret = -ENOMEM;
4623 +       if (!path)
4624 +               goto out;
4625 +
4626 +       /* old_nd.path will have refs to dentry and mnt */
4627 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4628 +       vxdprintk(VXD_CBIT(misc, 2),
4629 +               "do_path_lookup(old): %d", ret);
4630 +       if (ret < 0)
4631 +               goto out_free_path;
4632 +
4633 +       /* dentry/mnt refs handed over to old_path */
4634 +       old_path = &old_nd.path;
4635 +       /* no explicit reference for old_dentry here */
4636 +       old_dentry = old_path->dentry;
4637 +
4638 +       mode = old_dentry->d_inode->i_mode;
4639 +       to = d_path(old_path, path, PATH_MAX-2);
4640 +       pathlen = strlen(to);
4641 +       vxdprintk(VXD_CBIT(misc, 2),
4642 +               "old path " VS_Q("%s") " [%p:" VS_Q("%.*s") ":%d]", to,
4643 +               old_dentry,
4644 +               old_dentry->d_name.len, old_dentry->d_name.name,
4645 +               old_dentry->d_name.len);
4646 +
4647 +       to[pathlen + 1] = 0;
4648 +retry:
4649 +       new_dentry = NULL;
4650 +       to[pathlen] = pad--;
4651 +       ret = -ELOOP;
4652 +       if (pad <= '\240')
4653 +               goto out_rel_old;
4654 +
4655 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy " VS_Q("%s"), to);
4656 +
4657 +       /* dir_nd.path will have refs to dentry and mnt */
4658 +       ret = do_path_lookup(AT_FDCWD, to,
4659 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
4660 +       vxdprintk(VXD_CBIT(misc, 2), "do_path_lookup(new): %d", ret);
4661 +       if (ret < 0)
4662 +               goto retry;
4663 +
4664 +       /* this puppy downs the dir inode mutex if successful.
4665 +          dir_path will hold refs to dentry and mnt and
4666 +          we'll have write access to the mnt */
4667 +       new_dentry = kern_path_create(AT_FDCWD, to, &dir_path, 0);
4668 +       if (!new_dentry || IS_ERR(new_dentry)) {
4669 +               path_put(&dir_nd.path);
4670 +               vxdprintk(VXD_CBIT(misc, 2),
4671 +                       "kern_path_create(new) failed with %ld",
4672 +                       PTR_ERR(new_dentry));
4673 +               goto retry;
4674 +       }
4675 +       vxdprintk(VXD_CBIT(misc, 2),
4676 +               "kern_path_create(new): %p [" VS_Q("%.*s") ":%d]",
4677 +               new_dentry,
4678 +               new_dentry->d_name.len, new_dentry->d_name.name,
4679 +               new_dentry->d_name.len);
4680 +
4681 +       /* take a reference on new_dentry */
4682 +       dget(new_dentry);
4683 +
4684 +       /* dentry/mnt refs handed over to new_path */
4685 +       new_path = &dir_path;
4686 +
4687 +       /* dentry for old/new dir */
4688 +       dir = dir_nd.path.dentry;
4689 +
4690 +       /* give up reference on dir */
4691 +       dput(new_path->dentry);
4692 +
4693 +       /* new_dentry already has a reference */
4694 +       new_path->dentry = new_dentry;
4695 +
4696 +       ret = vfs_create(dir->d_inode, new_dentry, mode, 1);
4697 +       vxdprintk(VXD_CBIT(misc, 2),
4698 +               "vfs_create(new): %d", ret);
4699 +       if (ret == -EEXIST) {
4700 +               path_put(&dir_nd.path);
4701 +               mutex_unlock(&dir->d_inode->i_mutex);
4702 +               mnt_drop_write(new_path->mnt);
4703 +               path_put(new_path);
4704 +               new_dentry = NULL;
4705 +               goto retry;
4706 +       }
4707 +       else if (ret < 0)
4708 +               goto out_unlock_new;
4709 +
4710 +       /* drop out early, ret passes ENOENT */
4711 +       ret = -ENOENT;
4712 +       if ((redo = d_unhashed(old_dentry)))
4713 +               goto out_unlock_new;
4714 +
4715 +       /* doesn't change refs for old_path */
4716 +       old_file = dentry_open(old_path, O_RDONLY, current_cred());
4717 +       vxdprintk(VXD_CBIT(misc, 2),
4718 +               "dentry_open(old): %p", old_file);
4719 +       if (IS_ERR(old_file)) {
4720 +               ret = PTR_ERR(old_file);
4721 +               goto out_unlock_new;
4722 +       }
4723 +
4724 +       /* doesn't change refs for new_path */
4725 +       new_file = dentry_open(new_path, O_WRONLY, current_cred());
4726 +       vxdprintk(VXD_CBIT(misc, 2),
4727 +               "dentry_open(new): %p", new_file);
4728 +       if (IS_ERR(new_file)) {
4729 +               ret = PTR_ERR(new_file);
4730 +               goto out_fput_old;
4731 +       }
4732 +
4733 +       /* unlock the inode mutex from kern_path_create() */
4734 +       mutex_unlock(&dir->d_inode->i_mutex);
4735 +
4736 +       /* drop write access to mnt */
4737 +       mnt_drop_write(new_path->mnt);
4738 +
4739 +       drop = 0;
4740 +
4741 +       size = i_size_read(old_file->f_dentry->d_inode);
4742 +       ret = do_cow_splice(old_file, new_file, size);
4743 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
4744 +       if (ret < 0) {
4745 +               goto out_fput_both;
4746 +       } else if (ret < size) {
4747 +               ret = -ENOSPC;
4748 +               goto out_fput_both;
4749 +       } else {
4750 +               struct inode *old_inode = old_dentry->d_inode;
4751 +               struct inode *new_inode = new_dentry->d_inode;
4752 +               struct iattr attr = {
4753 +                       .ia_uid = old_inode->i_uid,
4754 +                       .ia_gid = old_inode->i_gid,
4755 +                       .ia_valid = ATTR_UID | ATTR_GID
4756 +                       };
4757 +
4758 +               setattr_copy(new_inode, &attr);
4759 +               mark_inode_dirty(new_inode);
4760 +       }
4761 +
4762 +       /* lock rename mutex */
4763 +       mutex_lock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4764 +
4765 +       /* drop out late */
4766 +       ret = -ENOENT;
4767 +       if ((redo = d_unhashed(old_dentry)))
4768 +               goto out_unlock;
4769 +
4770 +       vxdprintk(VXD_CBIT(misc, 2),
4771 +               "vfs_rename: [" VS_Q("%*s") ":%d] -> [" VS_Q("%*s") ":%d]",
4772 +               new_dentry->d_name.len, new_dentry->d_name.name,
4773 +               new_dentry->d_name.len,
4774 +               old_dentry->d_name.len, old_dentry->d_name.name,
4775 +               old_dentry->d_name.len);
4776 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_dentry,
4777 +               old_dentry->d_parent->d_inode, old_dentry);
4778 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
4779 +
4780 +out_unlock:
4781 +       mutex_unlock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4782 +
4783 +out_fput_both:
4784 +       vxdprintk(VXD_CBIT(misc, 3),
4785 +               "fput(new_file=%p[#%ld])", new_file,
4786 +               atomic_long_read(&new_file->f_count));
4787 +       fput(new_file);
4788 +
4789 +out_fput_old:
4790 +       vxdprintk(VXD_CBIT(misc, 3),
4791 +               "fput(old_file=%p[#%ld])", old_file,
4792 +               atomic_long_read(&old_file->f_count));
4793 +       fput(old_file);
4794 +
4795 +out_unlock_new:
4796 +       /* drop references from dir_nd.path */
4797 +       path_put(&dir_nd.path);
4798 +
4799 +       if (drop) {
4800 +               /* unlock the inode mutex from kern_path_create() */
4801 +               mutex_unlock(&dir->d_inode->i_mutex);
4802 +
4803 +               /* drop write access to mnt */
4804 +               mnt_drop_write(new_path->mnt);
4805 +       }
4806 +
4807 +       if (!ret)
4808 +               goto out_redo;
4809 +
4810 +       /* error path cleanup */
4811 +       vfs_unlink(dir->d_inode, new_dentry);
4812 +
4813 +out_redo:
4814 +       if (!redo)
4815 +               goto out_rel_both;
4816 +
4817 +       /* lookup dentry once again
4818 +          old_nd.path will be freed as old_path in out_rel_old */
4819 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4820 +       if (ret)
4821 +               goto out_rel_both;
4822 +
4823 +       /* drop reference on new_dentry */
4824 +       dput(new_dentry);
4825 +       new_dentry = old_path->dentry;
4826 +       dget(new_dentry);
4827 +       vxdprintk(VXD_CBIT(misc, 2),
4828 +               "do_path_lookup(redo): %p [" VS_Q("%.*s") ":%d]",
4829 +               new_dentry,
4830 +               new_dentry->d_name.len, new_dentry->d_name.name,
4831 +               new_dentry->d_name.len);
4832 +
4833 +out_rel_both:
4834 +       if (new_path)
4835 +               path_put(new_path);
4836 +out_rel_old:
4837 +       path_put(old_path);
4838 +out_free_path:
4839 +       kfree(path);
4840 +out:
4841 +       if (ret) {
4842 +               dput(new_dentry);
4843 +               new_dentry = ERR_PTR(ret);
4844 +       }
4845 +       vxdprintk(VXD_CBIT(misc, 3),
4846 +               "cow_break_link returning with %p", new_dentry);
4847 +       return new_dentry;
4848 +}
4849 +
4850 +#endif
4851 +
4852 +int    vx_info_mnt_namespace(struct mnt_namespace *ns, char *buffer)
4853 +{
4854 +       struct path path;
4855 +       struct vfsmount *vmnt;
4856 +       char *pstr, *root;
4857 +       int length = 0;
4858 +
4859 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
4860 +       if (!pstr)
4861 +               return 0;
4862 +
4863 +       vmnt = &ns->root->mnt;
4864 +       path.mnt = vmnt;
4865 +       path.dentry = vmnt->mnt_root;
4866 +       root = d_path(&path, pstr, PATH_MAX - 2);
4867 +       length = sprintf(buffer + length,
4868 +               "Namespace:\t%p [#%u]\n"
4869 +               "RootPath:\t%s\n",
4870 +               ns, atomic_read(&ns->count),
4871 +               root);
4872 +       kfree(pstr);
4873 +       return length;
4874 +}
4875 +
4876  /* get the link contents into pagecache */
4877  static char *page_getlink(struct dentry * dentry, struct page **ppage)
4878  {
4879 @@ -4099,3 +4521,4 @@ EXPORT_SYMBOL(vfs_symlink);
4880  EXPORT_SYMBOL(vfs_unlink);
4881  EXPORT_SYMBOL(dentry_unhash);
4882  EXPORT_SYMBOL(generic_readlink);
4883 +EXPORT_SYMBOL(vx_info_mnt_namespace);
4884 diff -NurpP --minimal linux-3.9.5/fs/namespace.c linux-3.9.5-vs2.3.6.5/fs/namespace.c
4885 --- linux-3.9.5/fs/namespace.c  2013-06-11 12:22:39.000000000 +0000
4886 +++ linux-3.9.5-vs2.3.6.5/fs/namespace.c        2013-06-12 23:49:08.000000000 +0000
4887 @@ -22,6 +22,11 @@
4888  #include <linux/fsnotify.h>    /* fsnotify_vfsmount_delete */
4889  #include <linux/uaccess.h>
4890  #include <linux/proc_fs.h>
4891 +#include <linux/vs_base.h>
4892 +#include <linux/vs_context.h>
4893 +#include <linux/vs_tag.h>
4894 +#include <linux/vserver/space.h>
4895 +#include <linux/vserver/global.h>
4896  #include "pnode.h"
4897  #include "internal.h"
4898  
4899 @@ -751,6 +756,10 @@ vfs_kern_mount(struct file_system_type *
4900         if (!type)
4901                 return ERR_PTR(-ENODEV);
4902  
4903 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
4904 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
4905 +               return ERR_PTR(-EPERM);
4906 +
4907         mnt = alloc_vfsmnt(name);
4908         if (!mnt)
4909                 return ERR_PTR(-ENOMEM);
4910 @@ -807,6 +816,7 @@ static struct mount *clone_mnt(struct mo
4911         mnt->mnt.mnt_root = dget(root);
4912         mnt->mnt_mountpoint = mnt->mnt.mnt_root;
4913         mnt->mnt_parent = mnt;
4914 +               mnt->mnt_tag = old->mnt_tag;
4915         br_write_lock(&vfsmount_lock);
4916         list_add_tail(&mnt->mnt_instance, &sb->s_mounts);
4917         br_write_unlock(&vfsmount_lock);
4918 @@ -1639,6 +1649,7 @@ static int do_change_type(struct path *p
4919                 if (err)
4920                         goto out_unlock;
4921         }
4922 +       // mnt->mnt_flags = mnt_flags;
4923  
4924         br_write_lock(&vfsmount_lock);
4925         for (m = mnt; m; m = (recurse ? next_mnt(m, mnt) : NULL))
4926 @@ -1654,12 +1665,14 @@ static int do_change_type(struct path *p
4927   * do loopback mount.
4928   */
4929  static int do_loopback(struct path *path, const char *old_name,
4930 -                               int recurse)
4931 +       vtag_t tag, unsigned long flags, int mnt_flags)
4932  {
4933         LIST_HEAD(umount_list);
4934         struct path old_path;
4935         struct mount *mnt = NULL, *old;
4936 +       int recurse = flags & MS_REC;
4937         int err;
4938 +
4939         if (!old_name || !*old_name)
4940                 return -EINVAL;
4941         err = kern_path(old_name, LOOKUP_FOLLOW|LOOKUP_AUTOMOUNT, &old_path);
4942 @@ -1733,7 +1746,7 @@ static int change_mount_flags(struct vfs
4943   * on it - tough luck.
4944   */
4945  static int do_remount(struct path *path, int flags, int mnt_flags,
4946 -                     void *data)
4947 +       void *data, vxid_t xid)
4948  {
4949         int err;
4950         struct super_block *sb = path->mnt->mnt_sb;
4951 @@ -2046,7 +2059,6 @@ void mark_mounts_for_expiry(struct list_
4952         }
4953         br_write_unlock(&vfsmount_lock);
4954         up_write(&namespace_sem);
4955 -
4956         release_mounts(&umounts);
4957  }
4958  
4959 @@ -2218,6 +2230,7 @@ long do_mount(const char *dev_name, cons
4960         struct path path;
4961         int retval = 0;
4962         int mnt_flags = 0;
4963 +       vtag_t tag = 0;
4964  
4965         /* Discard magic */
4966         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
4967 @@ -2247,6 +2260,12 @@ long do_mount(const char *dev_name, cons
4968         if (!(flags & MS_NOATIME))
4969                 mnt_flags |= MNT_RELATIME;
4970  
4971 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
4972 +               /* FIXME: bind and re-mounts get the tag flag? */
4973 +               if (flags & (MS_BIND|MS_REMOUNT))
4974 +                       flags |= MS_TAGID;
4975 +       }
4976 +
4977         /* Separate the per-mountpoint flags */
4978         if (flags & MS_NOSUID)
4979                 mnt_flags |= MNT_NOSUID;
4980 @@ -2263,15 +2282,17 @@ long do_mount(const char *dev_name, cons
4981         if (flags & MS_RDONLY)
4982                 mnt_flags |= MNT_READONLY;
4983  
4984 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_DEV_MOUNT))
4985 +               mnt_flags |= MNT_NODEV;
4986         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_BORN |
4987                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
4988                    MS_STRICTATIME);
4989  
4990         if (flags & MS_REMOUNT)
4991                 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
4992 -                                   data_page);
4993 +                                   data_page, tag);
4994         else if (flags & MS_BIND)
4995 -               retval = do_loopback(&path, dev_name, flags & MS_REC);
4996 +               retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
4997         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
4998                 retval = do_change_type(&path, flags);
4999         else if (flags & MS_MOVE)
5000 @@ -2380,6 +2401,7 @@ static struct mnt_namespace *dup_mnt_ns(
5001                 q = next_mnt(q, new);
5002         }
5003         up_write(&namespace_sem);
5004 +       atomic_inc(&vs_global_mnt_ns);
5005  
5006         if (rootmnt)
5007                 mntput(rootmnt);
5008 @@ -2575,9 +2597,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
5009         error = -EINVAL;
5010         new_mnt = real_mount(new.mnt);
5011         root_mnt = real_mount(root.mnt);
5012 -       if (IS_MNT_SHARED(real_mount(old.mnt)) ||
5013 +       if ((IS_MNT_SHARED(real_mount(old.mnt)) ||
5014                 IS_MNT_SHARED(new_mnt->mnt_parent) ||
5015 -               IS_MNT_SHARED(root_mnt->mnt_parent))
5016 +               IS_MNT_SHARED(root_mnt->mnt_parent)) &&
5017 +               !vx_flags(VXF_STATE_SETUP, 0))
5018                 goto out4;
5019         if (!check_mnt(root_mnt) || !check_mnt(new_mnt))
5020                 goto out4;
5021 @@ -2703,6 +2726,7 @@ void put_mnt_ns(struct mnt_namespace *ns
5022         br_write_unlock(&vfsmount_lock);
5023         up_write(&namespace_sem);
5024         release_mounts(&umount_list);
5025 +       atomic_dec(&vs_global_mnt_ns);
5026         free_mnt_ns(ns);
5027  }
5028  
5029 diff -NurpP --minimal linux-3.9.5/fs/nfs/client.c linux-3.9.5-vs2.3.6.5/fs/nfs/client.c
5030 --- linux-3.9.5/fs/nfs/client.c 2013-05-31 13:45:24.000000000 +0000
5031 +++ linux-3.9.5-vs2.3.6.5/fs/nfs/client.c       2013-05-31 14:47:11.000000000 +0000
5032 @@ -682,6 +682,9 @@ int nfs_init_server_rpcclient(struct nfs
5033         if (server->flags & NFS_MOUNT_SOFT)
5034                 server->client->cl_softrtry = 1;
5035  
5036 +       server->client->cl_tag = 0;
5037 +       if (server->flags & NFS_MOUNT_TAGGED)
5038 +               server->client->cl_tag = 1;
5039         return 0;
5040  }
5041  EXPORT_SYMBOL_GPL(nfs_init_server_rpcclient);
5042 @@ -861,6 +864,10 @@ static void nfs_server_set_fsinfo(struct
5043                 server->acdirmin = server->acdirmax = 0;
5044         }
5045  
5046 +       /* FIXME: needs fsinfo
5047 +       if (server->flags & NFS_MOUNT_TAGGED)
5048 +               sb->s_flags |= MS_TAGGED;       */
5049 +
5050         server->maxfilesize = fsinfo->maxfilesize;
5051  
5052         server->time_delta = fsinfo->time_delta;
5053 diff -NurpP --minimal linux-3.9.5/fs/nfs/dir.c linux-3.9.5-vs2.3.6.5/fs/nfs/dir.c
5054 --- linux-3.9.5/fs/nfs/dir.c    2013-05-31 13:45:24.000000000 +0000
5055 +++ linux-3.9.5-vs2.3.6.5/fs/nfs/dir.c  2013-05-31 14:47:11.000000000 +0000
5056 @@ -36,6 +36,7 @@
5057  #include <linux/sched.h>
5058  #include <linux/kmemleak.h>
5059  #include <linux/xattr.h>
5060 +#include <linux/vs_tag.h>
5061  
5062  #include "delegation.h"
5063  #include "iostat.h"
5064 @@ -1300,6 +1301,7 @@ struct dentry *nfs_lookup(struct inode *
5065         /* Success: notify readdir to use READDIRPLUS */
5066         nfs_advise_use_readdirplus(dir);
5067  
5068 +       dx_propagate_tag(nd, inode);
5069  no_entry:
5070         res = d_materialise_unique(dentry, inode);
5071         if (res != NULL) {
5072 diff -NurpP --minimal linux-3.9.5/fs/nfs/inode.c linux-3.9.5-vs2.3.6.5/fs/nfs/inode.c
5073 --- linux-3.9.5/fs/nfs/inode.c  2013-05-31 13:45:24.000000000 +0000
5074 +++ linux-3.9.5-vs2.3.6.5/fs/nfs/inode.c        2013-06-03 19:32:53.000000000 +0000
5075 @@ -39,6 +39,7 @@
5076  #include <linux/compat.h>
5077  #include <linux/freezer.h>
5078  #include <linux/crc32.h>
5079 +#include <linux/vs_tag.h>
5080  
5081  #include <asm/uaccess.h>
5082  
5083 @@ -290,6 +291,8 @@ nfs_fhget(struct super_block *sb, struct
5084         if (inode->i_state & I_NEW) {
5085                 struct nfs_inode *nfsi = NFS_I(inode);
5086                 unsigned long now = jiffies;
5087 +               kuid_t kuid;
5088 +               kgid_t kgid;
5089  
5090                 /* We set i_ino for the few things that still rely on it,
5091                  * such as stat(2) */
5092 @@ -334,8 +337,8 @@ nfs_fhget(struct super_block *sb, struct
5093                 inode->i_version = 0;
5094                 inode->i_size = 0;
5095                 clear_nlink(inode);
5096 -               inode->i_uid = make_kuid(&init_user_ns, -2);
5097 -               inode->i_gid = make_kgid(&init_user_ns, -2);
5098 +               kuid = make_kuid(&init_user_ns, -2);
5099 +               kgid = make_kgid(&init_user_ns, -2);
5100                 inode->i_blocks = 0;
5101                 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
5102                 nfsi->write_io = 0;
5103 @@ -369,11 +372,11 @@ nfs_fhget(struct super_block *sb, struct
5104                 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
5105                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5106                 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
5107 -                       inode->i_uid = fattr->uid;
5108 +                       kuid = fattr->uid;
5109                 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
5110                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5111                 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
5112 -                       inode->i_gid = fattr->gid;
5113 +                       kgid = fattr->gid;
5114                 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
5115                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5116                 if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED)
5117 @@ -384,6 +387,11 @@ nfs_fhget(struct super_block *sb, struct
5118                          */
5119                         inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
5120                 }
5121 +               inode->i_uid = INOTAG_KUID(DX_TAG(inode), kuid, kgid);
5122 +               inode->i_gid = INOTAG_KGID(DX_TAG(inode), kuid, kgid);
5123 +               inode->i_tag = INOTAG_KTAG(DX_TAG(inode), kuid, kgid, GLOBAL_ROOT_TAG);
5124 +                               /* maybe fattr->xid someday */
5125 +
5126                 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
5127                 nfsi->attrtimeo_timestamp = now;
5128                 nfsi->access_cache = RB_ROOT;
5129 @@ -505,6 +513,8 @@ void nfs_setattr_update_inode(struct ino
5130                         inode->i_uid = attr->ia_uid;
5131                 if ((attr->ia_valid & ATTR_GID) != 0)
5132                         inode->i_gid = attr->ia_gid;
5133 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5134 +                       inode->i_tag = attr->ia_tag;
5135                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5136                 spin_unlock(&inode->i_lock);
5137         }
5138 @@ -980,7 +990,9 @@ static int nfs_check_inode_attributes(st
5139         struct nfs_inode *nfsi = NFS_I(inode);
5140         loff_t cur_size, new_isize;
5141         unsigned long invalid = 0;
5142 -
5143 +       kuid_t kuid;
5144 +       kgid_t kgid;
5145 +       ktag_t ktag;
5146  
5147         if (nfs_have_delegated_attributes(inode))
5148                 return 0;
5149 @@ -1005,13 +1017,18 @@ static int nfs_check_inode_attributes(st
5150                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5151         }
5152  
5153 +       kuid = INOTAG_KUID(DX_TAG(inode), fattr->uid, fattr->gid);
5154 +       kgid = INOTAG_KGID(DX_TAG(inode), fattr->uid, fattr->gid);
5155 +       ktag = INOTAG_KTAG(DX_TAG(inode), fattr->uid, fattr->gid, GLOBAL_ROOT_TAG);
5156 +
5157         /* Have any file permissions changed? */
5158         if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
5159                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5160 -       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && !uid_eq(inode->i_uid, fattr->uid))
5161 +       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && !uid_eq(inode->i_uid, kuid))
5162                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5163 -       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && !gid_eq(inode->i_gid, fattr->gid))
5164 +       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && !gid_eq(inode->i_gid, kgid))
5165                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5166 +               /* maybe check for tag too? */
5167  
5168         /* Has the link count changed? */
5169         if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
5170 @@ -1317,6 +1334,9 @@ static int nfs_update_inode(struct inode
5171         unsigned long invalid = 0;
5172         unsigned long now = jiffies;
5173         unsigned long save_cache_validity;
5174 +       kuid_t kuid;
5175 +       kgid_t kgid;
5176 +       ktag_t ktag;
5177  
5178         dfprintk(VFS, "NFS: %s(%s/%ld fh_crc=0x%08x ct=%d info=0x%x)\n",
5179                         __func__, inode->i_sb->s_id, inode->i_ino,
5180 @@ -1418,6 +1438,9 @@ static int nfs_update_inode(struct inode
5181                                 | NFS_INO_REVAL_PAGECACHE
5182                                 | NFS_INO_REVAL_FORCED);
5183  
5184 +       kuid = TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag);
5185 +       kgid = TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag);
5186 +       ktag = TAGINO_KTAG(DX_TAG(inode), inode->i_tag);
5187  
5188         if (fattr->valid & NFS_ATTR_FATTR_ATIME)
5189                 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5190 @@ -1460,6 +1483,10 @@ static int nfs_update_inode(struct inode
5191                                 | NFS_INO_INVALID_ACL
5192                                 | NFS_INO_REVAL_FORCED);
5193  
5194 +       inode->i_uid = INOTAG_KUID(DX_TAG(inode), kuid, kgid);
5195 +       inode->i_gid = INOTAG_KGID(DX_TAG(inode), kuid, kgid);
5196 +       inode->i_tag = INOTAG_KTAG(DX_TAG(inode), kuid, kgid, ktag);
5197 +
5198         if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
5199                 if (inode->i_nlink != fattr->nlink) {
5200                         invalid |= NFS_INO_INVALID_ATTR;
5201 diff -NurpP --minimal linux-3.9.5/fs/nfs/nfs3xdr.c linux-3.9.5-vs2.3.6.5/fs/nfs/nfs3xdr.c
5202 --- linux-3.9.5/fs/nfs/nfs3xdr.c        2013-05-31 13:45:24.000000000 +0000
5203 +++ linux-3.9.5-vs2.3.6.5/fs/nfs/nfs3xdr.c      2013-06-03 19:33:10.000000000 +0000
5204 @@ -20,6 +20,7 @@
5205  #include <linux/nfs3.h>
5206  #include <linux/nfs_fs.h>
5207  #include <linux/nfsacl.h>
5208 +#include <linux/vs_tag.h>
5209  #include "internal.h"
5210  
5211  #define NFSDBG_FACILITY                NFSDBG_XDR
5212 @@ -558,7 +559,8 @@ static __be32 *xdr_decode_nfstime3(__be3
5213   *             set_mtime       mtime;
5214   *     };
5215   */
5216 -static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr)
5217 +static void encode_sattr3(struct xdr_stream *xdr,
5218 +       const struct iattr *attr, int tag)
5219  {
5220         u32 nbytes;
5221         __be32 *p;
5222 @@ -590,15 +592,19 @@ static void encode_sattr3(struct xdr_str
5223         } else
5224                 *p++ = xdr_zero;
5225  
5226 -       if (attr->ia_valid & ATTR_UID) {
5227 +       if (attr->ia_valid & ATTR_UID ||
5228 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5229                 *p++ = xdr_one;
5230 -               *p++ = cpu_to_be32(from_kuid(&init_user_ns, attr->ia_uid));
5231 +               *p++ = cpu_to_be32(from_kuid(&init_user_ns,
5232 +                       TAGINO_KUID(tag, attr->ia_uid, attr->ia_tag)));
5233         } else
5234                 *p++ = xdr_zero;
5235  
5236 -       if (attr->ia_valid & ATTR_GID) {
5237 +       if (attr->ia_valid & ATTR_GID ||
5238 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5239                 *p++ = xdr_one;
5240 -               *p++ = cpu_to_be32(from_kgid(&init_user_ns, attr->ia_gid));
5241 +               *p++ = cpu_to_be32(from_kgid(&init_user_ns,
5242 +                       TAGINO_KGID(tag, attr->ia_gid, attr->ia_tag)));
5243         } else
5244                 *p++ = xdr_zero;
5245  
5246 @@ -887,7 +893,7 @@ static void nfs3_xdr_enc_setattr3args(st
5247                                       const struct nfs3_sattrargs *args)
5248  {
5249         encode_nfs_fh3(xdr, args->fh);
5250 -       encode_sattr3(xdr, args->sattr);
5251 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5252         encode_sattrguard3(xdr, args);
5253  }
5254  
5255 @@ -1037,13 +1043,13 @@ static void nfs3_xdr_enc_write3args(stru
5256   *     };
5257   */
5258  static void encode_createhow3(struct xdr_stream *xdr,
5259 -                             const struct nfs3_createargs *args)
5260 +       const struct nfs3_createargs *args, int tag)
5261  {
5262         encode_uint32(xdr, args->createmode);
5263         switch (args->createmode) {
5264         case NFS3_CREATE_UNCHECKED:
5265         case NFS3_CREATE_GUARDED:
5266 -               encode_sattr3(xdr, args->sattr);
5267 +               encode_sattr3(xdr, args->sattr, tag);
5268                 break;
5269         case NFS3_CREATE_EXCLUSIVE:
5270                 encode_createverf3(xdr, args->verifier);
5271 @@ -1058,7 +1064,7 @@ static void nfs3_xdr_enc_create3args(str
5272                                      const struct nfs3_createargs *args)
5273  {
5274         encode_diropargs3(xdr, args->fh, args->name, args->len);
5275 -       encode_createhow3(xdr, args);
5276 +       encode_createhow3(xdr, args, req->rq_task->tk_client->cl_tag);
5277  }
5278  
5279  /*
5280 @@ -1074,7 +1080,7 @@ static void nfs3_xdr_enc_mkdir3args(stru
5281                                     const struct nfs3_mkdirargs *args)
5282  {
5283         encode_diropargs3(xdr, args->fh, args->name, args->len);
5284 -       encode_sattr3(xdr, args->sattr);
5285 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5286  }
5287  
5288  /*
5289 @@ -1091,9 +1097,9 @@ static void nfs3_xdr_enc_mkdir3args(stru
5290   *     };
5291   */
5292  static void encode_symlinkdata3(struct xdr_stream *xdr,
5293 -                               const struct nfs3_symlinkargs *args)
5294 +       const struct nfs3_symlinkargs *args, int tag)
5295  {
5296 -       encode_sattr3(xdr, args->sattr);
5297 +       encode_sattr3(xdr, args->sattr, tag);
5298         encode_nfspath3(xdr, args->pages, args->pathlen);
5299  }
5300  
5301 @@ -1102,7 +1108,7 @@ static void nfs3_xdr_enc_symlink3args(st
5302                                       const struct nfs3_symlinkargs *args)
5303  {
5304         encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen);
5305 -       encode_symlinkdata3(xdr, args);
5306 +       encode_symlinkdata3(xdr, args, req->rq_task->tk_client->cl_tag);
5307  }
5308  
5309  /*
5310 @@ -1130,24 +1136,24 @@ static void nfs3_xdr_enc_symlink3args(st
5311   *     };
5312   */
5313  static void encode_devicedata3(struct xdr_stream *xdr,
5314 -                              const struct nfs3_mknodargs *args)
5315 +       const struct nfs3_mknodargs *args, int tag)
5316  {
5317 -       encode_sattr3(xdr, args->sattr);
5318 +       encode_sattr3(xdr, args->sattr, tag);
5319         encode_specdata3(xdr, args->rdev);
5320  }
5321  
5322  static void encode_mknoddata3(struct xdr_stream *xdr,
5323 -                             const struct nfs3_mknodargs *args)
5324 +       const struct nfs3_mknodargs *args, int tag)
5325  {
5326         encode_ftype3(xdr, args->type);
5327         switch (args->type) {
5328         case NF3CHR:
5329         case NF3BLK:
5330 -               encode_devicedata3(xdr, args);
5331 +               encode_devicedata3(xdr, args, tag);
5332                 break;
5333         case NF3SOCK:
5334         case NF3FIFO:
5335 -               encode_sattr3(xdr, args->sattr);
5336 +               encode_sattr3(xdr, args->sattr, tag);
5337                 break;
5338         case NF3REG:
5339         case NF3DIR:
5340 @@ -1162,7 +1168,7 @@ static void nfs3_xdr_enc_mknod3args(stru
5341                                     const struct nfs3_mknodargs *args)
5342  {
5343         encode_diropargs3(xdr, args->fh, args->name, args->len);
5344 -       encode_mknoddata3(xdr, args);
5345 +       encode_mknoddata3(xdr, args, req->rq_task->tk_client->cl_tag);
5346  }
5347  
5348  /*
5349 diff -NurpP --minimal linux-3.9.5/fs/nfs/super.c linux-3.9.5-vs2.3.6.5/fs/nfs/super.c
5350 --- linux-3.9.5/fs/nfs/super.c  2013-05-31 13:45:24.000000000 +0000
5351 +++ linux-3.9.5-vs2.3.6.5/fs/nfs/super.c        2013-05-31 15:41:34.000000000 +0000
5352 @@ -55,6 +55,7 @@
5353  #include <linux/parser.h>
5354  #include <linux/nsproxy.h>
5355  #include <linux/rcupdate.h>
5356 +#include <linux/vs_tag.h>
5357  
5358  #include <asm/uaccess.h>
5359  
5360 @@ -103,6 +104,7 @@ enum {
5361         Opt_mountport,
5362         Opt_mountvers,
5363         Opt_minorversion,
5364 +       Opt_tagid,
5365  
5366         /* Mount options that take string arguments */
5367         Opt_nfsvers,
5368 @@ -115,6 +117,9 @@ enum {
5369         /* Special mount options */
5370         Opt_userspace, Opt_deprecated, Opt_sloppy,
5371  
5372 +       /* Linux-VServer tagging options */
5373 +       Opt_tag, Opt_notag,
5374 +
5375         Opt_err
5376  };
5377  
5378 @@ -184,6 +189,10 @@ static const match_table_t nfs_mount_opt
5379         { Opt_fscache_uniq, "fsc=%s" },
5380         { Opt_local_lock, "local_lock=%s" },
5381  
5382 +       { Opt_tag, "tag" },
5383 +       { Opt_notag, "notag" },
5384 +       { Opt_tagid, "tagid=%u" },
5385 +
5386         /* The following needs to be listed after all other options */
5387         { Opt_nfsvers, "v%s" },
5388  
5389 @@ -635,6 +644,7 @@ static void nfs_show_mount_options(struc
5390                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
5391                 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
5392                 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
5393 +               { NFS_MOUNT_TAGGED, ",tag", "" },
5394                 { 0, NULL, NULL }
5395         };
5396         const struct proc_nfs_info *nfs_infop;
5397 @@ -1261,6 +1271,14 @@ static int nfs_parse_mount_options(char
5398                 case Opt_nomigration:
5399                         mnt->options &= NFS_OPTION_MIGRATION;
5400                         break;
5401 +#ifndef CONFIG_TAGGING_NONE
5402 +               case Opt_tag:
5403 +                       mnt->flags |= NFS_MOUNT_TAGGED;
5404 +                       break;
5405 +               case Opt_notag:
5406 +                       mnt->flags &= ~NFS_MOUNT_TAGGED;
5407 +                       break;
5408 +#endif
5409  
5410                 /*
5411                  * options that take numeric values
5412 @@ -1347,6 +1365,12 @@ static int nfs_parse_mount_options(char
5413                                 goto out_invalid_value;
5414                         mnt->minorversion = option;
5415                         break;
5416 +#ifdef CONFIG_PROPAGATE
5417 +               case Opt_tagid:
5418 +                       /* use args[0] */
5419 +                       nfs_data.flags |= NFS_MOUNT_TAGGED;
5420 +                       break;
5421 +#endif
5422  
5423                 /*
5424                  * options that take text values
5425 diff -NurpP --minimal linux-3.9.5/fs/nfsd/auth.c linux-3.9.5-vs2.3.6.5/fs/nfsd/auth.c
5426 --- linux-3.9.5/fs/nfsd/auth.c  2013-05-31 13:45:24.000000000 +0000
5427 +++ linux-3.9.5-vs2.3.6.5/fs/nfsd/auth.c        2013-06-12 23:49:08.000000000 +0000
5428 @@ -2,6 +2,7 @@
5429  
5430  #include <linux/sched.h>
5431  #include <linux/user_namespace.h>
5432 +#include <linux/vs_tag.h>
5433  #include "nfsd.h"
5434  #include "auth.h"
5435  
5436 @@ -37,6 +38,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
5437  
5438         new->fsuid = rqstp->rq_cred.cr_uid;
5439         new->fsgid = rqstp->rq_cred.cr_gid;
5440 +       /* FIXME: this desperately needs a tag :)
5441 +       new->xid = (vxid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
5442 +                       */
5443  
5444         rqgi = rqstp->rq_cred.cr_group_info;
5445  
5446 diff -NurpP --minimal linux-3.9.5/fs/nfsd/nfs3xdr.c linux-3.9.5-vs2.3.6.5/fs/nfsd/nfs3xdr.c
5447 --- linux-3.9.5/fs/nfsd/nfs3xdr.c       2013-05-31 13:45:24.000000000 +0000
5448 +++ linux-3.9.5-vs2.3.6.5/fs/nfsd/nfs3xdr.c     2013-06-03 19:57:43.000000000 +0000
5449 @@ -8,6 +8,7 @@
5450  
5451  #include <linux/namei.h>
5452  #include <linux/sunrpc/svc_xprt.h>
5453 +#include <linux/vs_tag.h>
5454  #include "xdr3.h"
5455  #include "auth.h"
5456  #include "netns.h"
5457 @@ -98,6 +99,8 @@ static __be32 *
5458  decode_sattr3(__be32 *p, struct iattr *iap)
5459  {
5460         u32     tmp;
5461 +       kuid_t  kuid = GLOBAL_ROOT_UID;
5462 +       kgid_t  kgid = GLOBAL_ROOT_GID;
5463  
5464         iap->ia_valid = 0;
5465  
5466 @@ -106,15 +109,18 @@ decode_sattr3(__be32 *p, struct iattr *i
5467                 iap->ia_mode = ntohl(*p++);
5468         }
5469         if (*p++) {
5470 -               iap->ia_uid = make_kuid(&init_user_ns, ntohl(*p++));
5471 +               kuid = make_kuid(&init_user_ns, ntohl(*p++));
5472                 if (uid_valid(iap->ia_uid))
5473                         iap->ia_valid |= ATTR_UID;
5474         }
5475         if (*p++) {
5476 -               iap->ia_gid = make_kgid(&init_user_ns, ntohl(*p++));
5477 +               kgid = make_kgid(&init_user_ns, ntohl(*p++));
5478                 if (gid_valid(iap->ia_gid))
5479                         iap->ia_valid |= ATTR_GID;
5480         }
5481 +       iap->ia_uid = INOTAG_KUID(DX_TAG_NFSD, kuid, kgid);
5482 +       iap->ia_gid = INOTAG_KGID(DX_TAG_NFSD, kuid, kgid);
5483 +       iap->ia_tag = INOTAG_KTAG(DX_TAG_NFSD, kuid, kgid, GLOBAL_ROOT_TAG);
5484         if (*p++) {
5485                 u64     newsize;
5486  
5487 @@ -170,8 +176,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
5488         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
5489         *p++ = htonl((u32) stat->mode);
5490         *p++ = htonl((u32) stat->nlink);
5491 -       *p++ = htonl((u32) from_kuid(&init_user_ns, stat->uid));
5492 -       *p++ = htonl((u32) from_kgid(&init_user_ns, stat->gid));
5493 +       *p++ = htonl((u32) from_kuid(&init_user_ns,
5494 +               TAGINO_KUID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5495 +               stat->uid, stat->tag)));
5496 +       *p++ = htonl((u32) from_kgid(&init_user_ns,
5497 +               TAGINO_KGID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5498 +               stat->gid, stat->tag)));
5499         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
5500                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
5501         } else {
5502 diff -NurpP --minimal linux-3.9.5/fs/nfsd/nfs4xdr.c linux-3.9.5-vs2.3.6.5/fs/nfsd/nfs4xdr.c
5503 --- linux-3.9.5/fs/nfsd/nfs4xdr.c       2013-06-11 12:22:39.000000000 +0000
5504 +++ linux-3.9.5-vs2.3.6.5/fs/nfsd/nfs4xdr.c     2013-06-03 19:33:44.000000000 +0000
5505 @@ -46,6 +46,7 @@
5506  #include <linux/utsname.h>
5507  #include <linux/pagemap.h>
5508  #include <linux/sunrpc/svcauth_gss.h>
5509 +#include <linux/vs_tag.h>
5510  
5511  #include "idmap.h"
5512  #include "acl.h"
5513 @@ -2349,14 +2350,18 @@ out_acl:
5514                 WRITE32(stat.nlink);
5515         }
5516         if (bmval1 & FATTR4_WORD1_OWNER) {
5517 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
5518 +               status = nfsd4_encode_user(rqstp,
5519 +                       TAGINO_KUID(DX_TAG(dentry->d_inode),
5520 +                       stat.uid, stat.tag), &p, &buflen);
5521                 if (status == nfserr_resource)
5522                         goto out_resource;
5523                 if (status)
5524                         goto out;
5525         }
5526         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
5527 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
5528 +               status = nfsd4_encode_group(rqstp,
5529 +                       TAGINO_KGID(DX_TAG(dentry->d_inode),
5530 +                       stat.gid, stat.tag), &p, &buflen);
5531                 if (status == nfserr_resource)
5532                         goto out_resource;
5533                 if (status)
5534 diff -NurpP --minimal linux-3.9.5/fs/nfsd/nfsxdr.c linux-3.9.5-vs2.3.6.5/fs/nfsd/nfsxdr.c
5535 --- linux-3.9.5/fs/nfsd/nfsxdr.c        2013-05-31 13:45:24.000000000 +0000
5536 +++ linux-3.9.5-vs2.3.6.5/fs/nfsd/nfsxdr.c      2013-06-03 19:56:35.000000000 +0000
5537 @@ -7,6 +7,7 @@
5538  #include "vfs.h"
5539  #include "xdr.h"
5540  #include "auth.h"
5541 +#include <linux/vs_tag.h>
5542  
5543  #define NFSDDBG_FACILITY               NFSDDBG_XDR
5544  
5545 @@ -89,6 +90,8 @@ static __be32 *
5546  decode_sattr(__be32 *p, struct iattr *iap)
5547  {
5548         u32     tmp, tmp1;
5549 +       kuid_t  kuid = GLOBAL_ROOT_UID;
5550 +       kgid_t  kgid = GLOBAL_ROOT_GID;
5551  
5552         iap->ia_valid = 0;
5553  
5554 @@ -101,15 +104,18 @@ decode_sattr(__be32 *p, struct iattr *ia
5555                 iap->ia_mode = tmp;
5556         }
5557         if ((tmp = ntohl(*p++)) != (u32)-1) {
5558 -               iap->ia_uid = make_kuid(&init_user_ns, tmp);
5559 +               kuid = make_kuid(&init_user_ns, tmp);
5560                 if (uid_valid(iap->ia_uid))
5561                         iap->ia_valid |= ATTR_UID;
5562         }
5563         if ((tmp = ntohl(*p++)) != (u32)-1) {
5564 -               iap->ia_gid = make_kgid(&init_user_ns, tmp);
5565 +               kgid = make_kgid(&init_user_ns, tmp);
5566                 if (gid_valid(iap->ia_gid))
5567                         iap->ia_valid |= ATTR_GID;
5568         }
5569 +       iap->ia_uid = INOTAG_KUID(DX_TAG_NFSD, kuid, kgid);
5570 +       iap->ia_gid = INOTAG_KGID(DX_TAG_NFSD, kuid, kgid);
5571 +       iap->ia_tag = INOTAG_KTAG(DX_TAG_NFSD, kuid, kgid, GLOBAL_ROOT_TAG);
5572         if ((tmp = ntohl(*p++)) != (u32)-1) {
5573                 iap->ia_valid |= ATTR_SIZE;
5574                 iap->ia_size = tmp;
5575 @@ -154,8 +160,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
5576         *p++ = htonl(nfs_ftypes[type >> 12]);
5577         *p++ = htonl((u32) stat->mode);
5578         *p++ = htonl((u32) stat->nlink);
5579 -       *p++ = htonl((u32) from_kuid(&init_user_ns, stat->uid));
5580 -       *p++ = htonl((u32) from_kgid(&init_user_ns, stat->gid));
5581 +       *p++ = htonl((u32) from_kuid(&init_user_ns,
5582 +               TAGINO_KUID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
5583 +       *p++ = htonl((u32) from_kgid(&init_user_ns,
5584 +               TAGINO_KGID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
5585  
5586         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
5587                 *p++ = htonl(NFS_MAXPATHLEN);
5588 diff -NurpP --minimal linux-3.9.5/fs/ocfs2/dlmglue.c linux-3.9.5-vs2.3.6.5/fs/ocfs2/dlmglue.c
5589 --- linux-3.9.5/fs/ocfs2/dlmglue.c      2013-05-31 13:45:24.000000000 +0000
5590 +++ linux-3.9.5-vs2.3.6.5/fs/ocfs2/dlmglue.c    2013-06-03 19:59:20.000000000 +0000
5591 @@ -2047,6 +2047,7 @@ static void __ocfs2_stuff_meta_lvb(struc
5592         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
5593         lvb->lvb_iuid      = cpu_to_be32(i_uid_read(inode));
5594         lvb->lvb_igid      = cpu_to_be32(i_gid_read(inode));
5595 +       lvb->lvb_itag      = cpu_to_be16(i_tag_read(inode));
5596         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
5597         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
5598         lvb->lvb_iatime_packed  =
5599 @@ -2097,6 +2098,7 @@ static void ocfs2_refresh_inode_from_lvb
5600  
5601         i_uid_write(inode, be32_to_cpu(lvb->lvb_iuid));
5602         i_gid_write(inode, be32_to_cpu(lvb->lvb_igid));
5603 +       i_tag_write(inode, be16_to_cpu(lvb->lvb_itag));
5604         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
5605         set_nlink(inode, be16_to_cpu(lvb->lvb_inlink));
5606         ocfs2_unpack_timespec(&inode->i_atime,
5607 diff -NurpP --minimal linux-3.9.5/fs/ocfs2/dlmglue.h linux-3.9.5-vs2.3.6.5/fs/ocfs2/dlmglue.h
5608 --- linux-3.9.5/fs/ocfs2/dlmglue.h      2012-12-11 03:30:57.000000000 +0000
5609 +++ linux-3.9.5-vs2.3.6.5/fs/ocfs2/dlmglue.h    2013-05-31 14:47:11.000000000 +0000
5610 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
5611         __be16       lvb_inlink;
5612         __be32       lvb_iattr;
5613         __be32       lvb_igeneration;
5614 -       __be32       lvb_reserved2;
5615 +       __be16       lvb_itag;
5616 +       __be16       lvb_reserved2;
5617  };
5618  
5619  #define OCFS2_QINFO_LVB_VERSION 1
5620 diff -NurpP --minimal linux-3.9.5/fs/ocfs2/file.c linux-3.9.5-vs2.3.6.5/fs/ocfs2/file.c
5621 --- linux-3.9.5/fs/ocfs2/file.c 2013-05-31 13:45:24.000000000 +0000
5622 +++ linux-3.9.5-vs2.3.6.5/fs/ocfs2/file.c       2013-05-31 14:47:11.000000000 +0000
5623 @@ -1124,7 +1124,7 @@ int ocfs2_setattr(struct dentry *dentry,
5624                 attr->ia_valid &= ~ATTR_SIZE;
5625  
5626  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
5627 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
5628 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
5629         if (!(attr->ia_valid & OCFS2_VALID_ATTRS))
5630                 return 0;
5631  
5632 diff -NurpP --minimal linux-3.9.5/fs/ocfs2/inode.c linux-3.9.5-vs2.3.6.5/fs/ocfs2/inode.c
5633 --- linux-3.9.5/fs/ocfs2/inode.c        2013-05-31 13:45:24.000000000 +0000
5634 +++ linux-3.9.5-vs2.3.6.5/fs/ocfs2/inode.c      2013-05-31 20:39:47.000000000 +0000
5635 @@ -28,6 +28,7 @@
5636  #include <linux/highmem.h>
5637  #include <linux/pagemap.h>
5638  #include <linux/quotaops.h>
5639 +#include <linux/vs_tag.h>
5640  
5641  #include <asm/byteorder.h>
5642  
5643 @@ -78,11 +79,13 @@ void ocfs2_set_inode_flags(struct inode
5644  {
5645         unsigned int flags = OCFS2_I(inode)->ip_attr;
5646  
5647 -       inode->i_flags &= ~(S_IMMUTABLE |
5648 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
5649                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
5650  
5651         if (flags & OCFS2_IMMUTABLE_FL)
5652                 inode->i_flags |= S_IMMUTABLE;
5653 +       if (flags & OCFS2_IXUNLINK_FL)
5654 +               inode->i_flags |= S_IXUNLINK;
5655  
5656         if (flags & OCFS2_SYNC_FL)
5657                 inode->i_flags |= S_SYNC;
5658 @@ -92,25 +95,44 @@ void ocfs2_set_inode_flags(struct inode
5659                 inode->i_flags |= S_NOATIME;
5660         if (flags & OCFS2_DIRSYNC_FL)
5661                 inode->i_flags |= S_DIRSYNC;
5662 +
5663 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
5664 +
5665 +       if (flags & OCFS2_BARRIER_FL)
5666 +               inode->i_vflags |= V_BARRIER;
5667 +       if (flags & OCFS2_COW_FL)
5668 +               inode->i_vflags |= V_COW;
5669  }
5670  
5671  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
5672  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
5673  {
5674         unsigned int flags = oi->vfs_inode.i_flags;
5675 +       unsigned int vflags = oi->vfs_inode.i_vflags;
5676 +
5677 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
5678 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
5679 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
5680 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
5681 +
5682 +       if (flags & S_IMMUTABLE)
5683 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5684 +       if (flags & S_IXUNLINK)
5685 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
5686  
5687 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
5688 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
5689         if (flags & S_SYNC)
5690                 oi->ip_attr |= OCFS2_SYNC_FL;
5691         if (flags & S_APPEND)
5692                 oi->ip_attr |= OCFS2_APPEND_FL;
5693 -       if (flags & S_IMMUTABLE)
5694 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5695         if (flags & S_NOATIME)
5696                 oi->ip_attr |= OCFS2_NOATIME_FL;
5697         if (flags & S_DIRSYNC)
5698                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
5699 +
5700 +       if (vflags & V_BARRIER)
5701 +               oi->ip_attr |= OCFS2_BARRIER_FL;
5702 +       if (vflags & V_COW)
5703 +               oi->ip_attr |= OCFS2_COW_FL;
5704  }
5705  
5706  struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
5707 @@ -241,6 +263,8 @@ void ocfs2_populate_inode(struct inode *
5708         struct super_block *sb;
5709         struct ocfs2_super *osb;
5710         int use_plocks = 1;
5711 +       uid_t uid;
5712 +       gid_t gid;
5713  
5714         sb = inode->i_sb;
5715         osb = OCFS2_SB(sb);
5716 @@ -269,8 +293,12 @@ void ocfs2_populate_inode(struct inode *
5717         inode->i_generation = le32_to_cpu(fe->i_generation);
5718         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
5719         inode->i_mode = le16_to_cpu(fe->i_mode);
5720 -       i_uid_write(inode, le32_to_cpu(fe->i_uid));
5721 -       i_gid_write(inode, le32_to_cpu(fe->i_gid));
5722 +       uid = le32_to_cpu(fe->i_uid);
5723 +       gid = le32_to_cpu(fe->i_gid);
5724 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), uid, gid));
5725 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), uid, gid));
5726 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), uid, gid,
5727 +               /* le16_to_cpu(raw_inode->i_raw_tag) */ 0));
5728  
5729         /* Fast symlinks will have i_size but no allocated clusters. */
5730         if (S_ISLNK(inode->i_mode) && !fe->i_clusters) {
5731 diff -NurpP --minimal linux-3.9.5/fs/ocfs2/inode.h linux-3.9.5-vs2.3.6.5/fs/ocfs2/inode.h
5732 --- linux-3.9.5/fs/ocfs2/inode.h        2012-12-11 03:30:57.000000000 +0000
5733 +++ linux-3.9.5-vs2.3.6.5/fs/ocfs2/inode.h      2013-05-31 14:47:11.000000000 +0000
5734 @@ -154,6 +154,7 @@ struct buffer_head *ocfs2_bread(struct i
5735  
5736  void ocfs2_set_inode_flags(struct inode *inode);
5737  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
5738 +int ocfs2_sync_flags(struct inode *inode, int, int);
5739  
5740  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
5741  {
5742 diff -NurpP --minimal linux-3.9.5/fs/ocfs2/ioctl.c linux-3.9.5-vs2.3.6.5/fs/ocfs2/ioctl.c
5743 --- linux-3.9.5/fs/ocfs2/ioctl.c        2013-05-31 13:45:24.000000000 +0000
5744 +++ linux-3.9.5-vs2.3.6.5/fs/ocfs2/ioctl.c      2013-05-31 14:47:11.000000000 +0000
5745 @@ -76,7 +76,41 @@ static int ocfs2_get_inode_attr(struct i
5746         return status;
5747  }
5748  
5749 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5750 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
5751 +{
5752 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
5753 +       struct buffer_head *bh = NULL;
5754 +       handle_t *handle = NULL;
5755 +       int status;
5756 +
5757 +       status = ocfs2_inode_lock(inode, &bh, 1);
5758 +       if (status < 0) {
5759 +               mlog_errno(status);
5760 +               return status;
5761 +       }
5762 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5763 +       if (IS_ERR(handle)) {
5764 +               status = PTR_ERR(handle);
5765 +               mlog_errno(status);
5766 +               goto bail_unlock;
5767 +       }
5768 +
5769 +       inode->i_flags = flags;
5770 +       inode->i_vflags = vflags;
5771 +       ocfs2_get_inode_flags(OCFS2_I(inode));
5772 +
5773 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
5774 +       if (status < 0)
5775 +               mlog_errno(status);
5776 +
5777 +       ocfs2_commit_trans(osb, handle);
5778 +bail_unlock:
5779 +       ocfs2_inode_unlock(inode, 1);
5780 +       brelse(bh);
5781 +       return status;
5782 +}
5783 +
5784 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5785                                 unsigned mask)
5786  {
5787         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
5788 @@ -101,6 +135,11 @@ static int ocfs2_set_inode_attr(struct i
5789         if (!S_ISDIR(inode->i_mode))
5790                 flags &= ~OCFS2_DIRSYNC_FL;
5791  
5792 +       if (IS_BARRIER(inode)) {
5793 +               vxwprintk_task(1, "messing with the barrier.");
5794 +               goto bail_unlock;
5795 +       }
5796 +
5797         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5798         if (IS_ERR(handle)) {
5799                 status = PTR_ERR(handle);
5800 @@ -879,6 +918,7 @@ bail:
5801         return status;
5802  }
5803  
5804 +
5805  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
5806  {
5807         struct inode *inode = file_inode(filp);
5808 diff -NurpP --minimal linux-3.9.5/fs/ocfs2/namei.c linux-3.9.5-vs2.3.6.5/fs/ocfs2/namei.c
5809 --- linux-3.9.5/fs/ocfs2/namei.c        2013-05-31 13:45:24.000000000 +0000
5810 +++ linux-3.9.5-vs2.3.6.5/fs/ocfs2/namei.c      2013-06-03 20:00:35.000000000 +0000
5811 @@ -41,6 +41,7 @@
5812  #include <linux/slab.h>
5813  #include <linux/highmem.h>
5814  #include <linux/quotaops.h>
5815 +#include <linux/vs_tag.h>
5816  
5817  #include <cluster/masklog.h>
5818  
5819 @@ -475,6 +476,7 @@ static int __ocfs2_mknod_locked(struct i
5820         struct ocfs2_dinode *fe = NULL;
5821         struct ocfs2_extent_list *fel;
5822         u16 feat;
5823 +       ktag_t ktag;
5824  
5825         *new_fe_bh = NULL;
5826  
5827 @@ -512,8 +514,13 @@ static int __ocfs2_mknod_locked(struct i
5828         fe->i_suballoc_loc = cpu_to_le64(suballoc_loc);
5829         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
5830         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
5831 -       fe->i_uid = cpu_to_le32(i_uid_read(inode));
5832 -       fe->i_gid = cpu_to_le32(i_gid_read(inode));
5833 +
5834 +       ktag = make_ktag(&init_user_ns, dx_current_fstag(osb->sb));
5835 +       fe->i_uid = cpu_to_le32(from_kuid(&init_user_ns,
5836 +               TAGINO_KUID(DX_TAG(inode), inode->i_uid, ktag)));
5837 +       fe->i_gid = cpu_to_le32(from_kgid(&init_user_ns,
5838 +               TAGINO_KGID(DX_TAG(inode), inode->i_gid, ktag)));
5839 +       inode->i_tag = ktag; /* is this correct? */
5840         fe->i_mode = cpu_to_le16(inode->i_mode);
5841         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
5842                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
5843 diff -NurpP --minimal linux-3.9.5/fs/ocfs2/ocfs2.h linux-3.9.5-vs2.3.6.5/fs/ocfs2/ocfs2.h
5844 --- linux-3.9.5/fs/ocfs2/ocfs2.h        2012-12-11 03:30:57.000000000 +0000
5845 +++ linux-3.9.5-vs2.3.6.5/fs/ocfs2/ocfs2.h      2013-05-31 14:47:11.000000000 +0000
5846 @@ -272,6 +272,7 @@ enum ocfs2_mount_options
5847                                                      writes */
5848         OCFS2_MOUNT_HB_NONE = 1 << 13, /* No heartbeat */
5849         OCFS2_MOUNT_HB_GLOBAL = 1 << 14, /* Global heartbeat */
5850 +       OCFS2_MOUNT_TAGGED = 1 << 15, /* use tagging */
5851  };
5852  
5853  #define OCFS2_OSB_SOFT_RO                      0x0001
5854 diff -NurpP --minimal linux-3.9.5/fs/ocfs2/ocfs2_fs.h linux-3.9.5-vs2.3.6.5/fs/ocfs2/ocfs2_fs.h
5855 --- linux-3.9.5/fs/ocfs2/ocfs2_fs.h     2012-12-11 03:30:57.000000000 +0000
5856 +++ linux-3.9.5-vs2.3.6.5/fs/ocfs2/ocfs2_fs.h   2013-05-31 14:47:11.000000000 +0000
5857 @@ -266,6 +266,11 @@
5858  #define OCFS2_TOPDIR_FL                        FS_TOPDIR_FL    /* Top of directory hierarchies*/
5859  #define OCFS2_RESERVED_FL              FS_RESERVED_FL  /* reserved for ext2 lib */
5860  
5861 +#define OCFS2_IXUNLINK_FL              FS_IXUNLINK_FL  /* Immutable invert on unlink */
5862 +
5863 +#define OCFS2_BARRIER_FL               FS_BARRIER_FL   /* Barrier for chroot() */
5864 +#define OCFS2_COW_FL                   FS_COW_FL       /* Copy on Write marker */
5865 +
5866  #define OCFS2_FL_VISIBLE               FS_FL_USER_VISIBLE      /* User visible flags */
5867  #define OCFS2_FL_MODIFIABLE            FS_FL_USER_MODIFIABLE   /* User modifiable flags */
5868  
5869 diff -NurpP --minimal linux-3.9.5/fs/ocfs2/super.c linux-3.9.5-vs2.3.6.5/fs/ocfs2/super.c
5870 --- linux-3.9.5/fs/ocfs2/super.c        2013-05-31 13:45:25.000000000 +0000
5871 +++ linux-3.9.5-vs2.3.6.5/fs/ocfs2/super.c      2013-05-31 14:47:11.000000000 +0000
5872 @@ -185,6 +185,7 @@ enum {
5873         Opt_coherency_full,
5874         Opt_resv_level,
5875         Opt_dir_resv_level,
5876 +       Opt_tag, Opt_notag, Opt_tagid,
5877         Opt_err,
5878  };
5879  
5880 @@ -216,6 +217,9 @@ static const match_table_t tokens = {
5881         {Opt_coherency_full, "coherency=full"},
5882         {Opt_resv_level, "resv_level=%u"},
5883         {Opt_dir_resv_level, "dir_resv_level=%u"},
5884 +       {Opt_tag, "tag"},
5885 +       {Opt_notag, "notag"},
5886 +       {Opt_tagid, "tagid=%u"},
5887         {Opt_err, NULL}
5888  };
5889  
5890 @@ -662,6 +666,13 @@ static int ocfs2_remount(struct super_bl
5891                 goto out;
5892         }
5893  
5894 +       if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
5895 +           (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
5896 +               ret = -EINVAL;
5897 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
5898 +               goto out;
5899 +       }
5900 +
5901         /* We're going to/from readonly mode. */
5902         if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
5903                 /* Disable quota accounting before remounting RO */
5904 @@ -1177,6 +1188,9 @@ static int ocfs2_fill_super(struct super
5905  
5906         ocfs2_complete_mount_recovery(osb);
5907  
5908 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
5909 +               sb->s_flags |= MS_TAGGED;
5910 +
5911         if (ocfs2_mount_local(osb))
5912                 snprintf(nodestr, sizeof(nodestr), "local");
5913         else
5914 @@ -1504,6 +1518,20 @@ static int ocfs2_parse_options(struct su
5915                             option < OCFS2_MAX_RESV_LEVEL)
5916                                 mopt->dir_resv_level = option;
5917                         break;
5918 +#ifndef CONFIG_TAGGING_NONE
5919 +               case Opt_tag:
5920 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5921 +                       break;
5922 +               case Opt_notag:
5923 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
5924 +                       break;
5925 +#endif
5926 +#ifdef CONFIG_PROPAGATE
5927 +               case Opt_tagid:
5928 +                       /* use args[0] */
5929 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5930 +                       break;
5931 +#endif
5932                 default:
5933                         mlog(ML_ERROR,
5934                              "Unrecognized mount option \"%s\" "
5935 diff -NurpP --minimal linux-3.9.5/fs/open.c linux-3.9.5-vs2.3.6.5/fs/open.c
5936 --- linux-3.9.5/fs/open.c       2013-05-31 13:45:25.000000000 +0000
5937 +++ linux-3.9.5-vs2.3.6.5/fs/open.c     2013-06-01 08:41:29.000000000 +0000
5938 @@ -31,6 +31,11 @@
5939  #include <linux/ima.h>
5940  #include <linux/dnotify.h>
5941  #include <linux/compat.h>
5942 +#include <linux/vs_base.h>
5943 +#include <linux/vs_limit.h>
5944 +#include <linux/vs_tag.h>
5945 +#include <linux/vs_cowbl.h>
5946 +#include <linux/vserver/dlimit.h>
5947  
5948  #include "internal.h"
5949  
5950 @@ -67,6 +72,11 @@ long vfs_truncate(struct path *path, lof
5951         struct inode *inode;
5952         long error;
5953  
5954 +#ifdef CONFIG_VSERVER_COWBL
5955 +       error = cow_check_and_break(path);
5956 +       if (error)
5957 +               goto out;
5958 +#endif
5959         inode = path->dentry->d_inode;
5960  
5961         /* For directories it's -EISDIR, for other non-regulars - -EINVAL */
5962 @@ -532,6 +542,13 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
5963         unsigned int lookup_flags = LOOKUP_FOLLOW;
5964  retry:
5965         error = user_path_at(dfd, filename, lookup_flags, &path);
5966 +#ifdef CONFIG_VSERVER_COWBL
5967 +       if (!error) {
5968 +               error = cow_check_and_break(&path);
5969 +               if (error)
5970 +                       path_put(&path);
5971 +       }
5972 +#endif
5973         if (!error) {
5974                 error = chmod_common(&path, mode);
5975                 path_put(&path);
5976 @@ -564,13 +581,15 @@ static int chown_common(struct path *pat
5977                 if (!uid_valid(uid))
5978                         return -EINVAL;
5979                 newattrs.ia_valid |= ATTR_UID;
5980 -               newattrs.ia_uid = uid;
5981 +               newattrs.ia_uid = make_kuid(&init_user_ns,
5982 +                       dx_map_uid(user));
5983         }
5984         if (group != (gid_t) -1) {
5985                 if (!gid_valid(gid))
5986                         return -EINVAL;
5987                 newattrs.ia_valid |= ATTR_GID;
5988 -               newattrs.ia_gid = gid;
5989 +               newattrs.ia_gid = make_kgid(&init_user_ns,
5990 +                       dx_map_gid(group));
5991         }
5992         if (!S_ISDIR(inode->i_mode))
5993                 newattrs.ia_valid |=
5994 @@ -604,6 +623,18 @@ retry:
5995         error = mnt_want_write(path.mnt);
5996         if (error)
5997                 goto out_release;
5998 +#ifdef CONFIG_VSERVER_COWBL
5999 +       error = cow_check_and_break(&path);
6000 +       if (!error)
6001 +#endif
6002 +#ifdef CONFIG_VSERVER_COWBL
6003 +       error = cow_check_and_break(&path);
6004 +       if (!error)
6005 +#endif
6006 +#ifdef CONFIG_VSERVER_COWBL
6007 +       error = cow_check_and_break(&path);
6008 +       if (!error)
6009 +#endif
6010         error = chown_common(&path, user, group);
6011         mnt_drop_write(path.mnt);
6012  out_release:
6013 diff -NurpP --minimal linux-3.9.5/fs/proc/array.c linux-3.9.5-vs2.3.6.5/fs/proc/array.c
6014 --- linux-3.9.5/fs/proc/array.c 2013-05-31 13:45:25.000000000 +0000
6015 +++ linux-3.9.5-vs2.3.6.5/fs/proc/array.c       2013-05-31 14:47:11.000000000 +0000
6016 @@ -82,6 +82,8 @@
6017  #include <linux/ptrace.h>
6018  #include <linux/tracehook.h>
6019  #include <linux/user_namespace.h>
6020 +#include <linux/vs_context.h>
6021 +#include <linux/vs_network.h>
6022  
6023  #include <asm/pgtable.h>
6024  #include <asm/processor.h>
6025 @@ -173,6 +175,9 @@ static inline void task_state(struct seq
6026         rcu_read_lock();
6027         ppid = pid_alive(p) ?
6028                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
6029 +       if (unlikely(vx_current_initpid(p->pid)))
6030 +               ppid = 0;
6031 +
6032         tpid = 0;
6033         if (pid_alive(p)) {
6034                 struct task_struct *tracer = ptrace_parent(p);
6035 @@ -297,7 +302,7 @@ static inline void task_sig(struct seq_f
6036  }
6037  
6038  static void render_cap_t(struct seq_file *m, const char *header,
6039 -                       kernel_cap_t *a)
6040 +                       struct vx_info *vxi, kernel_cap_t *a)
6041  {
6042         unsigned __capi;
6043  
6044 @@ -331,10 +336,11 @@ static inline void task_cap(struct seq_f
6045         NORM_CAPS(cap_effective);
6046         NORM_CAPS(cap_bset);
6047  
6048 -       render_cap_t(m, "CapInh:\t", &cap_inheritable);
6049 -       render_cap_t(m, "CapPrm:\t", &cap_permitted);
6050 -       render_cap_t(m, "CapEff:\t", &cap_effective);
6051 -       render_cap_t(m, "CapBnd:\t", &cap_bset);
6052 +       /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
6053 +       render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
6054 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
6055 +       render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
6056 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
6057  }
6058  
6059  static inline void task_seccomp(struct seq_file *m, struct task_struct *p)
6060 @@ -363,6 +369,42 @@ static void task_cpus_allowed(struct seq
6061         seq_putc(m, '\n');
6062  }
6063  
6064 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6065 +                       struct pid *pid, struct task_struct *task)
6066 +{
6067 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
6068 +                       "Count:\t%u\n"
6069 +                       "uts:\t%p(%c)\n"
6070 +                       "ipc:\t%p(%c)\n"
6071 +                       "mnt:\t%p(%c)\n"
6072 +                       "pid:\t%p(%c)\n"
6073 +                       "net:\t%p(%c)\n",
6074 +                       task->nsproxy,
6075 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6076 +                       atomic_read(&task->nsproxy->count),
6077 +                       task->nsproxy->uts_ns,
6078 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6079 +                       task->nsproxy->ipc_ns,
6080 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6081 +                       task->nsproxy->mnt_ns,
6082 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6083 +                       task->nsproxy->pid_ns,
6084 +                       (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
6085 +                       task->nsproxy->net_ns,
6086 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6087 +       return 0;
6088 +}
6089 +
6090 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6091 +{
6092 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6093 +               return;
6094 +
6095 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6096 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6097 +}
6098 +
6099 +
6100  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6101                         struct pid *pid, struct task_struct *task)
6102  {
6103 @@ -380,6 +422,7 @@ int proc_pid_status(struct seq_file *m,
6104         task_seccomp(m, task);
6105         task_cpus_allowed(m, task);
6106         cpuset_task_status_allowed(m, task);
6107 +       task_vs_id(m, task);
6108         task_context_switch_counts(m, task);
6109         return 0;
6110  }
6111 @@ -489,6 +532,17 @@ static int do_task_stat(struct seq_file
6112         /* convert nsec -> ticks */
6113         start_time = nsec_to_clock_t(start_time);
6114  
6115 +       /* fixup start time for virt uptime */
6116 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6117 +               unsigned long long bias =
6118 +                       current->vx_info->cvirt.bias_clock;
6119 +
6120 +               if (start_time > bias)
6121 +                       start_time -= bias;
6122 +               else
6123 +                       start_time = 0;
6124 +       }
6125 +
6126         seq_printf(m, "%d (%s) %c", pid_nr_ns(pid, ns), tcomm, state);
6127         seq_put_decimal_ll(m, ' ', ppid);
6128         seq_put_decimal_ll(m, ' ', pgid);
6129 diff -NurpP --minimal linux-3.9.5/fs/proc/base.c linux-3.9.5-vs2.3.6.5/fs/proc/base.c
6130 --- linux-3.9.5/fs/proc/base.c  2013-05-31 13:45:25.000000000 +0000
6131 +++ linux-3.9.5-vs2.3.6.5/fs/proc/base.c        2013-06-12 23:49:08.000000000 +0000
6132 @@ -86,6 +86,8 @@
6133  #include <linux/fs_struct.h>
6134  #include <linux/slab.h>
6135  #include <linux/flex_array.h>
6136 +#include <linux/vs_context.h>
6137 +#include <linux/vs_network.h>
6138  #ifdef CONFIG_HARDWALL
6139  #include <asm/hardwall.h>
6140  #endif
6141 @@ -944,11 +946,15 @@ static ssize_t oom_adj_write(struct file
6142                 oom_adj = (oom_adj * OOM_SCORE_ADJ_MAX) / -OOM_DISABLE;
6143  
6144         if (oom_adj < task->signal->oom_score_adj &&
6145 -           !capable(CAP_SYS_RESOURCE)) {
6146 +           !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
6147                 err = -EACCES;
6148                 goto err_sighand;
6149         }
6150  
6151 +       /* prevent guest processes from circumventing the oom killer */
6152 +       if (vx_current_xid() && (oom_adj == OOM_DISABLE))
6153 +               oom_adj = OOM_ADJUST_MIN;
6154 +
6155         /*
6156          * /proc/pid/oom_adj is provided for legacy purposes, ask users to use
6157          * /proc/pid/oom_score_adj instead.
6158 @@ -1528,6 +1534,8 @@ struct inode *proc_pid_make_inode(struct
6159                 inode->i_gid = cred->egid;
6160                 rcu_read_unlock();
6161         }
6162 +       /* procfs is xid tagged */
6163 +       i_tag_write(inode, (vtag_t)vx_task_xid(task));
6164         security_task_to_inode(task, inode);
6165  
6166  out:
6167 @@ -1573,6 +1581,8 @@ int pid_getattr(struct vfsmount *mnt, st
6168  
6169  /* dentry stuff */
6170  
6171 +static unsigned name_to_int(struct dentry *dentry);
6172 +
6173  /*
6174   *     Exceptional case: normally we are not allowed to unhash a busy
6175   * directory. In this case, however, we can do it - no aliasing problems
6176 @@ -1601,6 +1611,12 @@ int pid_revalidate(struct dentry *dentry
6177         task = get_proc_task(inode);
6178  
6179         if (task) {
6180 +               unsigned pid = name_to_int(dentry);
6181 +
6182 +               if (pid != ~0U && pid != vx_map_pid(task->pid)) {
6183 +                       put_task_struct(task);
6184 +                       goto drop;
6185 +               }
6186                 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
6187                     task_dumpable(task)) {
6188                         rcu_read_lock();
6189 @@ -1617,6 +1633,7 @@ int pid_revalidate(struct dentry *dentry
6190                 put_task_struct(task);
6191                 return 1;
6192         }
6193 +drop:
6194         d_drop(dentry);
6195         return 0;
6196  }
6197 @@ -2059,6 +2076,13 @@ static struct dentry *proc_pident_lookup
6198         if (!task)
6199                 goto out_no_task;
6200  
6201 +       /* TODO: maybe we can come up with a generic approach? */
6202 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
6203 +               (dentry->d_name.len == 5) &&
6204 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
6205 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
6206 +               goto out;
6207 +
6208         /*
6209          * Yes, it does not scale. And it should not. Don't add
6210          * new entries into /proc/<tgid>/ without very good reasons.
6211 @@ -2493,6 +2517,9 @@ static int proc_pid_personality(struct s
6212  static const struct file_operations proc_task_operations;
6213  static const struct inode_operations proc_task_inode_operations;
6214  
6215 +extern int proc_pid_vx_info(struct task_struct *, char *);
6216 +extern int proc_pid_nx_info(struct task_struct *, char *);
6217 +
6218  static const struct pid_entry tgid_base_stuff[] = {
6219         DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
6220         DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
6221 @@ -2559,6 +2586,8 @@ static const struct pid_entry tgid_base_
6222  #ifdef CONFIG_CGROUPS
6223         REG("cgroup",  S_IRUGO, proc_cgroup_operations),
6224  #endif
6225 +       INF("vinfo",      S_IRUGO, proc_pid_vx_info),
6226 +       INF("ninfo",      S_IRUGO, proc_pid_nx_info),
6227         INF("oom_score",  S_IRUGO, proc_oom_score),
6228         REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adj_operations),
6229         REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations),
6230 @@ -2583,6 +2612,7 @@ static const struct pid_entry tgid_base_
6231         REG("gid_map",    S_IRUGO|S_IWUSR, proc_gid_map_operations),
6232         REG("projid_map", S_IRUGO|S_IWUSR, proc_projid_map_operations),
6233  #endif
6234 +       ONE("nsproxy",  S_IRUGO, proc_pid_nsproxy),
6235  };
6236  
6237  static int proc_tgid_base_readdir(struct file * filp,
6238 @@ -2770,7 +2800,7 @@ retry:
6239         iter.task = NULL;
6240         pid = find_ge_pid(iter.tgid, ns);
6241         if (pid) {
6242 -               iter.tgid = pid_nr_ns(pid, ns);
6243 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
6244                 iter.task = pid_task(pid, PIDTYPE_PID);
6245                 /* What we to know is if the pid we have find is the
6246                  * pid of a thread_group_leader.  Testing for task
6247 @@ -2800,7 +2830,7 @@ static int proc_pid_fill_cache(struct fi
6248         struct tgid_iter iter)
6249  {
6250         char name[PROC_NUMBUF];
6251 -       int len = snprintf(name, sizeof(name), "%d", iter.tgid);
6252 +       int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
6253         return proc_fill_cache(filp, dirent, filldir, name, len,
6254                                 proc_pid_instantiate, iter.task, NULL);
6255  }
6256 @@ -2833,6 +2863,8 @@ int proc_pid_readdir(struct file * filp,
6257                         __filldir = fake_filldir;
6258  
6259                 filp->f_pos = iter.tgid + TGID_OFFSET;
6260 +               if (!vx_proc_task_visible(iter.task))
6261 +                       continue;
6262                 if (proc_pid_fill_cache(filp, dirent, __filldir, iter) < 0) {
6263                         put_task_struct(iter.task);
6264                         goto out;
6265 @@ -2993,6 +3025,8 @@ static struct dentry *proc_task_lookup(s
6266         tid = name_to_int(dentry);
6267         if (tid == ~0U)
6268                 goto out;
6269 +       if (vx_current_initpid(tid))
6270 +               goto out;
6271  
6272         ns = dentry->d_sb->s_fs_info;
6273         rcu_read_lock();
6274 diff -NurpP --minimal linux-3.9.5/fs/proc/generic.c linux-3.9.5-vs2.3.6.5/fs/proc/generic.c
6275 --- linux-3.9.5/fs/proc/generic.c       2013-05-31 13:45:25.000000000 +0000
6276 +++ linux-3.9.5-vs2.3.6.5/fs/proc/generic.c     2013-05-31 16:13:42.000000000 +0000
6277 @@ -23,6 +23,7 @@
6278  #include <linux/bitops.h>
6279  #include <linux/spinlock.h>
6280  #include <linux/completion.h>
6281 +#include <linux/vserver/inode.h>
6282  #include <asm/uaccess.h>
6283  
6284  #include "internal.h"
6285 @@ -409,6 +410,8 @@ struct dentry *proc_lookup_de(struct pro
6286         for (de = de->subdir; de ; de = de->next) {
6287                 if (de->namelen != dentry->d_name.len)
6288                         continue;
6289 +               if (!vx_hide_check(0, de->vx_flags))
6290 +                       continue;
6291                 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
6292                         pde_get(de);
6293                         spin_unlock(&proc_subdir_lock);
6294 @@ -417,6 +420,8 @@ struct dentry *proc_lookup_de(struct pro
6295                                 return ERR_PTR(-ENOMEM);
6296                         d_set_d_op(dentry, &proc_dentry_operations);
6297                         d_add(dentry, inode);
6298 +                       /* generic proc entries belong to the host */
6299 +                       i_tag_write(inode, 0);
6300                         return NULL;
6301                 }
6302         }
6303 @@ -485,6 +490,8 @@ int proc_readdir_de(struct proc_dir_entr
6304  
6305                                 /* filldir passes info to user space */
6306                                 pde_get(de);
6307 +                               if (!vx_hide_check(0, de->vx_flags))
6308 +                                       goto skip;
6309                                 spin_unlock(&proc_subdir_lock);
6310                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
6311                                             de->low_ino, de->mode >> 12) < 0) {
6312 @@ -492,6 +499,7 @@ int proc_readdir_de(struct proc_dir_entr
6313                                         goto out;
6314                                 }
6315                                 spin_lock(&proc_subdir_lock);
6316 +                       skip:
6317                                 filp->f_pos++;
6318                                 next = de->next;
6319                                 pde_put(de);
6320 @@ -603,6 +611,7 @@ static struct proc_dir_entry *__proc_cre
6321         ent->namelen = len;
6322         ent->mode = mode;
6323         ent->nlink = nlink;
6324 +       ent->vx_flags = IATTR_PROC_DEFAULT;
6325         atomic_set(&ent->count, 1);
6326         spin_lock_init(&ent->pde_unload_lock);
6327         INIT_LIST_HEAD(&ent->pde_openers);
6328 @@ -626,7 +635,8 @@ struct proc_dir_entry *proc_symlink(cons
6329                                 kfree(ent->data);
6330                                 kfree(ent);
6331                                 ent = NULL;
6332 -                       }
6333 +                       } else
6334 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
6335                 } else {
6336                         kfree(ent);
6337                         ent = NULL;
6338 diff -NurpP --minimal linux-3.9.5/fs/proc/inode.c linux-3.9.5-vs2.3.6.5/fs/proc/inode.c
6339 --- linux-3.9.5/fs/proc/inode.c 2013-05-31 13:45:25.000000000 +0000
6340 +++ linux-3.9.5-vs2.3.6.5/fs/proc/inode.c       2013-05-31 14:47:11.000000000 +0000
6341 @@ -458,6 +458,8 @@ struct inode *proc_get_inode(struct supe
6342                         inode->i_uid = de->uid;
6343                         inode->i_gid = de->gid;
6344                 }
6345 +               if (de->vx_flags)
6346 +                       PROC_I(inode)->vx_flags = de->vx_flags;
6347                 if (de->size)
6348                         inode->i_size = de->size;
6349                 if (de->nlink)
6350 diff -NurpP --minimal linux-3.9.5/fs/proc/internal.h linux-3.9.5-vs2.3.6.5/fs/proc/internal.h
6351 --- linux-3.9.5/fs/proc/internal.h      2013-05-31 13:45:25.000000000 +0000
6352 +++ linux-3.9.5-vs2.3.6.5/fs/proc/internal.h    2013-05-31 16:04:34.000000000 +0000
6353 @@ -12,6 +12,8 @@
6354  #include <linux/sched.h>
6355  #include <linux/proc_fs.h>
6356  #include <linux/binfmts.h>
6357 +#include <linux/vs_pid.h>
6358 +
6359  struct  ctl_table_header;
6360  struct  mempolicy;
6361  
6362 @@ -56,6 +58,9 @@ extern int proc_pid_status(struct seq_fi
6363                                 struct pid *pid, struct task_struct *task);
6364  extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
6365                                 struct pid *pid, struct task_struct *task);
6366 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6367 +                               struct pid *pid, struct task_struct *task);
6368 +
6369  extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
6370  
6371  extern const struct file_operations proc_tid_children_operations;
6372 @@ -89,11 +94,16 @@ static inline struct pid *proc_pid(struc
6373         return PROC_I(inode)->pid;
6374  }
6375  
6376 -static inline struct task_struct *get_proc_task(struct inode *inode)
6377 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
6378  {
6379         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
6380  }
6381  
6382 +static inline struct task_struct *get_proc_task(struct inode *inode)
6383 +{
6384 +       return vx_get_proc_task(inode, proc_pid(inode));
6385 +}
6386 +
6387  static inline int proc_fd(struct inode *inode)
6388  {
6389         return PROC_I(inode)->fd;
6390 diff -NurpP --minimal linux-3.9.5/fs/proc/loadavg.c linux-3.9.5-vs2.3.6.5/fs/proc/loadavg.c
6391 --- linux-3.9.5/fs/proc/loadavg.c       2012-12-11 03:30:57.000000000 +0000
6392 +++ linux-3.9.5-vs2.3.6.5/fs/proc/loadavg.c     2013-05-31 14:47:11.000000000 +0000
6393 @@ -12,15 +12,27 @@
6394  
6395  static int loadavg_proc_show(struct seq_file *m, void *v)
6396  {
6397 +       unsigned long running;
6398 +       unsigned int threads;
6399         unsigned long avnrun[3];
6400  
6401         get_avenrun(avnrun, FIXED_1/200, 0);
6402  
6403 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
6404 +               struct vx_info *vxi = current_vx_info();
6405 +
6406 +               running = atomic_read(&vxi->cvirt.nr_running);
6407 +               threads = atomic_read(&vxi->cvirt.nr_threads);
6408 +       } else {
6409 +               running = nr_running();
6410 +               threads = nr_threads;
6411 +       }
6412 +
6413         seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
6414                 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
6415                 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
6416                 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
6417 -               nr_running(), nr_threads,
6418 +               running, threads,
6419                 task_active_pid_ns(current)->last_pid);
6420         return 0;
6421  }
6422 diff -NurpP --minimal linux-3.9.5/fs/proc/meminfo.c linux-3.9.5-vs2.3.6.5/fs/proc/meminfo.c
6423 --- linux-3.9.5/fs/proc/meminfo.c       2013-05-31 13:45:25.000000000 +0000
6424 +++ linux-3.9.5-vs2.3.6.5/fs/proc/meminfo.c     2013-05-31 16:05:39.000000000 +0000
6425 @@ -39,7 +39,8 @@ static int meminfo_proc_show(struct seq_
6426         allowed = ((totalram_pages - hugetlb_total_pages())
6427                 * sysctl_overcommit_ratio / 100) + total_swap_pages;
6428  
6429 -       cached = global_page_state(NR_FILE_PAGES) -
6430 +       cached = vx_flags(VXF_VIRT_MEM, 0) ?
6431 +               vx_vsi_cached(&i) : global_page_state(NR_FILE_PAGES) -
6432                         total_swapcache_pages() - i.bufferram;
6433         if (cached < 0)
6434                 cached = 0;
6435 diff -NurpP --minimal linux-3.9.5/fs/proc/root.c linux-3.9.5-vs2.3.6.5/fs/proc/root.c
6436 --- linux-3.9.5/fs/proc/root.c  2013-05-31 13:45:25.000000000 +0000
6437 +++ linux-3.9.5-vs2.3.6.5/fs/proc/root.c        2013-05-31 14:47:11.000000000 +0000
6438 @@ -20,9 +20,14 @@
6439  #include <linux/mount.h>
6440  #include <linux/pid_namespace.h>
6441  #include <linux/parser.h>
6442 +#include <linux/vserver/inode.h>
6443  
6444  #include "internal.h"
6445  
6446 +struct proc_dir_entry *proc_virtual;
6447 +
6448 +extern void proc_vx_init(void);
6449 +
6450  static int proc_test_super(struct super_block *sb, void *data)
6451  {
6452         return sb->s_fs_info == data;
6453 @@ -182,6 +187,7 @@ void __init proc_root_init(void)
6454  #endif
6455         proc_mkdir("bus", NULL);
6456         proc_sys_init();
6457 +       proc_vx_init();
6458  }
6459  
6460  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
6461 @@ -248,6 +254,7 @@ struct proc_dir_entry proc_root = {
6462         .proc_iops      = &proc_root_inode_operations, 
6463         .proc_fops      = &proc_root_operations,
6464         .parent         = &proc_root,
6465 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
6466         .name           = "/proc",
6467  };
6468  
6469 diff -NurpP --minimal linux-3.9.5/fs/proc/self.c linux-3.9.5-vs2.3.6.5/fs/proc/self.c
6470 --- linux-3.9.5/fs/proc/self.c  2013-02-19 13:58:49.000000000 +0000
6471 +++ linux-3.9.5-vs2.3.6.5/fs/proc/self.c        2013-05-31 20:57:54.000000000 +0000
6472 @@ -1,6 +1,7 @@
6473  #include <linux/proc_fs.h>
6474  #include <linux/sched.h>
6475  #include <linux/namei.h>
6476 +#include <linux/vserver/inode.h>
6477  
6478  /*
6479   * /proc/self:
6480 @@ -56,4 +57,5 @@ void __init proc_self_init(void)
6481         mode = S_IFLNK | S_IRWXUGO;
6482         proc_self_symlink = proc_create("self", mode, NULL, NULL );
6483         proc_self_symlink->proc_iops = &proc_self_inode_operations;
6484 +       proc_self_symlink->vx_flags = IATTR_PROC_SYMLINK;
6485  }
6486 diff -NurpP --minimal linux-3.9.5/fs/proc/stat.c linux-3.9.5-vs2.3.6.5/fs/proc/stat.c
6487 --- linux-3.9.5/fs/proc/stat.c  2012-12-11 03:30:57.000000000 +0000
6488 +++ linux-3.9.5-vs2.3.6.5/fs/proc/stat.c        2013-05-31 14:47:11.000000000 +0000
6489 @@ -9,8 +9,10 @@
6490  #include <linux/slab.h>
6491  #include <linux/time.h>
6492  #include <linux/irqnr.h>
6493 +#include <linux/vserver/cvirt.h>
6494  #include <asm/cputime.h>
6495  #include <linux/tick.h>
6496 +#include <linux/cpuset.h>
6497  
6498  #ifndef arch_irq_stat_cpu
6499  #define arch_irq_stat_cpu(cpu) 0
6500 @@ -87,14 +89,26 @@ static int show_stat(struct seq_file *p,
6501         u64 sum_softirq = 0;
6502         unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
6503         struct timespec boottime;
6504 +       cpumask_var_t cpus_allowed;
6505 +       bool virt_cpu = vx_flags(VXF_VIRT_CPU, 0);
6506  
6507         user = nice = system = idle = iowait =
6508                 irq = softirq = steal = 0;
6509         guest = guest_nice = 0;
6510         getboottime(&boottime);
6511 +
6512 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6513 +               vx_vsi_boottime(&boottime);
6514 +
6515 +       if (virt_cpu)
6516 +               cpuset_cpus_allowed(current, cpus_allowed);
6517 +
6518         jif = boottime.tv_sec;
6519  
6520         for_each_possible_cpu(i) {
6521 +               if (virt_cpu && !cpumask_test_cpu(i, cpus_allowed))
6522 +                       continue;
6523 +
6524                 user += kcpustat_cpu(i).cpustat[CPUTIME_USER];
6525                 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
6526                 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
6527 @@ -131,6 +145,9 @@ static int show_stat(struct seq_file *p,
6528         seq_putc(p, '\n');
6529  
6530         for_each_online_cpu(i) {
6531 +               if (virt_cpu && !cpumask_test_cpu(i, cpus_allowed))
6532 +                       continue;
6533 +
6534                 /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
6535                 user = kcpustat_cpu(i).cpustat[CPUTIME_USER];
6536                 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
6537 diff -NurpP --minimal linux-3.9.5/fs/proc/uptime.c linux-3.9.5-vs2.3.6.5/fs/proc/uptime.c
6538 --- linux-3.9.5/fs/proc/uptime.c        2012-12-11 03:30:57.000000000 +0000
6539 +++ linux-3.9.5-vs2.3.6.5/fs/proc/uptime.c      2013-05-31 14:47:11.000000000 +0000
6540 @@ -5,6 +5,7 @@
6541  #include <linux/seq_file.h>
6542  #include <linux/time.h>
6543  #include <linux/kernel_stat.h>
6544 +#include <linux/vserver/cvirt.h>
6545  #include <asm/cputime.h>
6546  
6547  static int uptime_proc_show(struct seq_file *m, void *v)
6548 @@ -25,6 +26,10 @@ static int uptime_proc_show(struct seq_f
6549         nsec = cputime64_to_jiffies64(idletime) * TICK_NSEC;
6550         idle.tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem);
6551         idle.tv_nsec = rem;
6552 +
6553 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6554 +               vx_vsi_uptime(&uptime, &idle);
6555 +
6556         seq_printf(m, "%lu.%02lu %lu.%02lu\n",
6557                         (unsigned long) uptime.tv_sec,
6558                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
6559 diff -NurpP --minimal linux-3.9.5/fs/proc_namespace.c linux-3.9.5-vs2.3.6.5/fs/proc_namespace.c
6560 --- linux-3.9.5/fs/proc_namespace.c     2012-12-11 03:30:57.000000000 +0000
6561 +++ linux-3.9.5-vs2.3.6.5/fs/proc_namespace.c   2013-05-31 17:17:53.000000000 +0000
6562 @@ -44,6 +44,8 @@ static int show_sb_opts(struct seq_file
6563                 { MS_SYNCHRONOUS, ",sync" },
6564                 { MS_DIRSYNC, ",dirsync" },
6565                 { MS_MANDLOCK, ",mand" },
6566 +               { MS_TAGGED, ",tag" },
6567 +               { MS_NOTAGCHECK, ",notagcheck" },
6568                 { 0, NULL }
6569         };
6570         const struct proc_fs_info *fs_infop;
6571 @@ -80,6 +82,40 @@ static inline void mangle(struct seq_fil
6572         seq_escape(m, s, " \t\n\\");
6573  }
6574  
6575 +#ifdef CONFIG_VSERVER_EXTRA_MNT_CHECK
6576 +
6577 +static int mnt_is_reachable(struct vfsmount *vfsmnt)
6578 +{
6579 +       struct path root;
6580 +       struct dentry *point;
6581 +       struct mount *mnt = real_mount(vfsmnt);
6582 +       struct mount *root_mnt;
6583 +       int ret;
6584 +
6585 +       if (mnt == mnt->mnt_ns->root)
6586 +               return 1;
6587 +
6588 +       br_read_lock(&vfsmount_lock);
6589 +       root = current->fs->root;
6590 +       root_mnt = real_mount(root.mnt);
6591 +       point = root.dentry;
6592 +
6593 +       while ((mnt != mnt->mnt_parent) && (mnt != root_mnt)) {
6594 +               point = mnt->mnt_mountpoint;
6595 +               mnt = mnt->mnt_parent;
6596 +       }
6597 +
6598 +       ret = (mnt == root_mnt) && is_subdir(point, root.dentry);
6599 +
6600 +       br_read_unlock(&vfsmount_lock);
6601 +
6602 +       return ret;
6603 +}
6604 +
6605 +#else
6606 +#define        mnt_is_reachable(v)     (1)
6607 +#endif
6608 +
6609  static void show_type(struct seq_file *m, struct super_block *sb)
6610  {
6611         mangle(m, sb->s_type->name);
6612 @@ -96,6 +132,17 @@ static int show_vfsmnt(struct seq_file *
6613         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
6614         struct super_block *sb = mnt_path.dentry->d_sb;
6615  
6616 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6617 +               return SEQ_SKIP;
6618 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6619 +               return SEQ_SKIP;
6620 +
6621 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6622 +               mnt == current->fs->root.mnt) {
6623 +               seq_puts(m, "/dev/root / ");
6624 +               goto type;
6625 +       }
6626 +
6627         if (sb->s_op->show_devname) {
6628                 err = sb->s_op->show_devname(m, mnt_path.dentry);
6629                 if (err)
6630 @@ -106,6 +153,7 @@ static int show_vfsmnt(struct seq_file *
6631         seq_putc(m, ' ');
6632         seq_path(m, &mnt_path, " \t\n\\");
6633         seq_putc(m, ' ');
6634 +type:
6635         show_type(m, sb);
6636         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
6637         err = show_sb_opts(m, sb);
6638 @@ -128,6 +176,11 @@ static int show_mountinfo(struct seq_fil
6639         struct path root = p->root;
6640         int err = 0;
6641  
6642 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6643 +               return SEQ_SKIP;
6644 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6645 +               return SEQ_SKIP;
6646 +
6647         seq_printf(m, "%i %i %u:%u ", r->mnt_id, r->mnt_parent->mnt_id,
6648                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
6649         if (sb->s_op->show_path)
6650 @@ -187,6 +240,17 @@ static int show_vfsstat(struct seq_file
6651         struct super_block *sb = mnt_path.dentry->d_sb;
6652         int err = 0;
6653  
6654 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6655 +               return SEQ_SKIP;
6656 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6657 +               return SEQ_SKIP;
6658 +
6659 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6660 +               mnt == current->fs->root.mnt) {
6661 +               seq_puts(m, "device /dev/root mounted on / ");
6662 +               goto type;
6663 +       }
6664 +
6665         /* device */
6666         if (sb->s_op->show_devname) {
6667                 seq_puts(m, "device ");
6668 @@ -203,7 +267,7 @@ static int show_vfsstat(struct seq_file
6669         seq_puts(m, " mounted on ");
6670         seq_path(m, &mnt_path, " \t\n\\");
6671         seq_putc(m, ' ');
6672 -
6673 +type:
6674         /* file system type */
6675         seq_puts(m, "with fstype ");
6676         show_type(m, sb);
6677 diff -NurpP --minimal linux-3.9.5/fs/quota/dquot.c linux-3.9.5-vs2.3.6.5/fs/quota/dquot.c
6678 --- linux-3.9.5/fs/quota/dquot.c        2013-05-31 13:45:25.000000000 +0000
6679 +++ linux-3.9.5-vs2.3.6.5/fs/quota/dquot.c      2013-05-31 14:47:11.000000000 +0000
6680 @@ -1585,6 +1585,9 @@ int __dquot_alloc_space(struct inode *in
6681         struct dquot **dquots = inode->i_dquot;
6682         int reserve = flags & DQUOT_SPACE_RESERVE;
6683  
6684 +       if ((ret = dl_alloc_space(inode, number)))
6685 +               return ret;
6686 +
6687         /*
6688          * First test before acquiring mutex - solves deadlocks when we
6689          * re-enter the quota code and are already holding the mutex
6690 @@ -1640,6 +1643,9 @@ int dquot_alloc_inode(const struct inode
6691         struct dquot_warn warn[MAXQUOTAS];
6692         struct dquot * const *dquots = inode->i_dquot;
6693  
6694 +       if ((ret = dl_alloc_inode(inode)))
6695 +               return ret;
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 @@ -1711,6 +1717,8 @@ void __dquot_free_space(struct inode *in
6701         struct dquot **dquots = inode->i_dquot;
6702         int reserve = flags & DQUOT_SPACE_RESERVE;
6703  
6704 +       dl_free_space(inode, number);
6705 +
6706         /* First test before acquiring mutex - solves deadlocks when we
6707           * re-enter the quota code and are already holding the mutex */
6708         if (!dquot_active(inode)) {
6709 @@ -1755,6 +1763,8 @@ void dquot_free_inode(const struct inode
6710         struct dquot_warn warn[MAXQUOTAS];
6711         struct dquot * const *dquots = inode->i_dquot;
6712  
6713 +       dl_free_inode(inode);
6714 +
6715         /* First test before acquiring mutex - solves deadlocks when we
6716           * re-enter the quota code and are already holding the mutex */
6717         if (!dquot_active(inode))
6718 diff -NurpP --minimal linux-3.9.5/fs/quota/quota.c linux-3.9.5-vs2.3.6.5/fs/quota/quota.c
6719 --- linux-3.9.5/fs/quota/quota.c        2013-02-19 13:58:49.000000000 +0000
6720 +++ linux-3.9.5-vs2.3.6.5/fs/quota/quota.c      2013-05-31 14:47:11.000000000 +0000
6721 @@ -8,6 +8,7 @@
6722  #include <linux/fs.h>
6723  #include <linux/namei.h>
6724  #include <linux/slab.h>
6725 +#include <linux/vs_context.h>
6726  #include <asm/current.h>
6727  #include <linux/uaccess.h>
6728  #include <linux/kernel.h>
6729 @@ -37,7 +38,7 @@ static int check_quotactl_permission(str
6730                         break;
6731                 /*FALLTHROUGH*/
6732         default:
6733 -               if (!capable(CAP_SYS_ADMIN))
6734 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
6735                         return -EPERM;
6736         }
6737  
6738 @@ -309,6 +310,46 @@ static int do_quotactl(struct super_bloc
6739  
6740  #ifdef CONFIG_BLOCK
6741  
6742 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6743 +
6744 +#include <linux/vroot.h>
6745 +#include <linux/major.h>
6746 +#include <linux/module.h>
6747 +#include <linux/kallsyms.h>
6748 +#include <linux/vserver/debug.h>
6749 +
6750 +static vroot_grb_func *vroot_get_real_bdev = NULL;
6751 +
6752 +static DEFINE_SPINLOCK(vroot_grb_lock);
6753 +
6754 +int register_vroot_grb(vroot_grb_func *func) {
6755 +       int ret = -EBUSY;
6756 +
6757 +       spin_lock(&vroot_grb_lock);
6758 +       if (!vroot_get_real_bdev) {
6759 +               vroot_get_real_bdev = func;
6760 +               ret = 0;
6761 +       }
6762 +       spin_unlock(&vroot_grb_lock);
6763 +       return ret;
6764 +}
6765 +EXPORT_SYMBOL(register_vroot_grb);
6766 +
6767 +int unregister_vroot_grb(vroot_grb_func *func) {
6768 +       int ret = -EINVAL;
6769 +
6770 +       spin_lock(&vroot_grb_lock);
6771 +       if (vroot_get_real_bdev) {
6772 +               vroot_get_real_bdev = NULL;
6773 +               ret = 0;
6774 +       }
6775 +       spin_unlock(&vroot_grb_lock);
6776 +       return ret;
6777 +}
6778 +EXPORT_SYMBOL(unregister_vroot_grb);
6779 +
6780 +#endif
6781 +
6782  /* Return 1 if 'cmd' will block on frozen filesystem */
6783  static int quotactl_cmd_write(int cmd)
6784  {
6785 @@ -343,6 +384,22 @@ static struct super_block *quotactl_bloc
6786         putname(tmp);
6787         if (IS_ERR(bdev))
6788                 return ERR_CAST(bdev);
6789 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6790 +       if (bdev && bdev->bd_inode &&
6791 +               imajor(bdev->bd_inode) == VROOT_MAJOR) {
6792 +               struct block_device *bdnew = (void *)-EINVAL;
6793 +
6794 +               if (vroot_get_real_bdev)
6795 +                       bdnew = vroot_get_real_bdev(bdev);
6796 +               else
6797 +                       vxdprintk(VXD_CBIT(misc, 0),
6798 +                                       "vroot_get_real_bdev not set");
6799 +               bdput(bdev);
6800 +               if (IS_ERR(bdnew))
6801 +                       return ERR_PTR(PTR_ERR(bdnew));
6802 +               bdev = bdnew;
6803 +       }
6804 +#endif
6805         if (quotactl_cmd_write(cmd))
6806                 sb = get_super_thawed(bdev);
6807         else
6808 diff -NurpP --minimal linux-3.9.5/fs/stat.c linux-3.9.5-vs2.3.6.5/fs/stat.c
6809 --- linux-3.9.5/fs/stat.c       2013-05-31 13:45:25.000000000 +0000
6810 +++ linux-3.9.5-vs2.3.6.5/fs/stat.c     2013-06-01 08:53:01.000000000 +0000
6811 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
6812         stat->nlink = inode->i_nlink;
6813         stat->uid = inode->i_uid;
6814         stat->gid = inode->i_gid;
6815 +       stat->tag = inode->i_tag;
6816         stat->rdev = inode->i_rdev;
6817         stat->size = i_size_read(inode);
6818         stat->atime = inode->i_atime;
6819 diff -NurpP --minimal linux-3.9.5/fs/statfs.c linux-3.9.5-vs2.3.6.5/fs/statfs.c
6820 --- linux-3.9.5/fs/statfs.c     2013-02-19 13:58:49.000000000 +0000
6821 +++ linux-3.9.5-vs2.3.6.5/fs/statfs.c   2013-05-31 14:47:11.000000000 +0000
6822 @@ -7,6 +7,8 @@
6823  #include <linux/statfs.h>
6824  #include <linux/security.h>
6825  #include <linux/uaccess.h>
6826 +#include <linux/vs_base.h>
6827 +#include <linux/vs_dlimit.h>
6828  #include "internal.h"
6829  
6830  static int flags_by_mnt(int mnt_flags)
6831 @@ -60,6 +62,8 @@ static int statfs_by_dentry(struct dentr
6832         retval = dentry->d_sb->s_op->statfs(dentry, buf);
6833         if (retval == 0 && buf->f_frsize == 0)
6834                 buf->f_frsize = buf->f_bsize;
6835 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
6836 +               vx_vsi_statfs(dentry->d_sb, buf);
6837         return retval;
6838  }
6839  
6840 diff -NurpP --minimal linux-3.9.5/fs/super.c linux-3.9.5-vs2.3.6.5/fs/super.c
6841 --- linux-3.9.5/fs/super.c      2013-05-31 13:45:25.000000000 +0000
6842 +++ linux-3.9.5-vs2.3.6.5/fs/super.c    2013-05-31 14:47:11.000000000 +0000
6843 @@ -34,6 +34,8 @@
6844  #include <linux/cleancache.h>
6845  #include <linux/fsnotify.h>
6846  #include <linux/lockdep.h>
6847 +#include <linux/magic.h>
6848 +#include <linux/vs_context.h>
6849  #include "internal.h"
6850  
6851  
6852 @@ -1117,6 +1119,13 @@ mount_fs(struct file_system_type *type,
6853         WARN_ON(sb->s_bdi == &default_backing_dev_info);
6854         sb->s_flags |= MS_BORN;
6855  
6856 +       error = -EPERM;
6857 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) &&
6858 +               !sb->s_bdev &&
6859 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
6860 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
6861 +               goto out_sb;
6862 +
6863         error = security_sb_kern_mount(sb, flags, secdata);
6864         if (error)
6865                 goto out_sb;
6866 diff -NurpP --minimal linux-3.9.5/fs/sysfs/mount.c linux-3.9.5-vs2.3.6.5/fs/sysfs/mount.c
6867 --- linux-3.9.5/fs/sysfs/mount.c        2013-05-31 13:45:25.000000000 +0000
6868 +++ linux-3.9.5-vs2.3.6.5/fs/sysfs/mount.c      2013-05-31 14:47:11.000000000 +0000
6869 @@ -48,7 +48,7 @@ static int sysfs_fill_super(struct super
6870  
6871         sb->s_blocksize = PAGE_CACHE_SIZE;
6872         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
6873 -       sb->s_magic = SYSFS_MAGIC;
6874 +       sb->s_magic = SYSFS_SUPER_MAGIC;
6875         sb->s_op = &sysfs_ops;
6876         sb->s_time_gran = 1;
6877  
6878 diff -NurpP --minimal linux-3.9.5/fs/utimes.c linux-3.9.5-vs2.3.6.5/fs/utimes.c
6879 --- linux-3.9.5/fs/utimes.c     2013-02-19 13:58:49.000000000 +0000
6880 +++ linux-3.9.5-vs2.3.6.5/fs/utimes.c   2013-05-31 22:40:16.000000000 +0000
6881 @@ -8,6 +8,8 @@
6882  #include <linux/stat.h>
6883  #include <linux/utime.h>
6884  #include <linux/syscalls.h>
6885 +#include <linux/mount.h>
6886 +#include <linux/vs_cowbl.h>
6887  #include <asm/uaccess.h>
6888  #include <asm/unistd.h>
6889  
6890 @@ -52,12 +54,18 @@ static int utimes_common(struct path *pa
6891  {
6892         int error;
6893         struct iattr newattrs;
6894 -       struct inode *inode = path->dentry->d_inode;
6895 +       struct inode *inode;
6896 +
6897 +       error = cow_check_and_break(path);
6898 +       if (error)
6899 +               goto out;
6900  
6901         error = mnt_want_write(path->mnt);
6902         if (error)
6903                 goto out;
6904  
6905 +       inode = path->dentry->d_inode;
6906 +
6907         if (times && times[0].tv_nsec == UTIME_NOW &&
6908                      times[1].tv_nsec == UTIME_NOW)
6909                 times = NULL;
6910 diff -NurpP --minimal linux-3.9.5/fs/xattr.c linux-3.9.5-vs2.3.6.5/fs/xattr.c
6911 --- linux-3.9.5/fs/xattr.c      2013-02-19 13:58:49.000000000 +0000
6912 +++ linux-3.9.5-vs2.3.6.5/fs/xattr.c    2013-05-31 14:47:11.000000000 +0000
6913 @@ -21,6 +21,7 @@
6914  #include <linux/audit.h>
6915  #include <linux/vmalloc.h>
6916  #include <linux/posix_acl_xattr.h>
6917 +#include <linux/mount.h>
6918  
6919  #include <asm/uaccess.h>
6920  
6921 @@ -52,7 +53,7 @@ xattr_permission(struct inode *inode, co
6922          * The trusted.* namespace can only be accessed by privileged users.
6923          */
6924         if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN)) {
6925 -               if (!capable(CAP_SYS_ADMIN))
6926 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_FS_TRUSTED))
6927                         return (mask & MAY_WRITE) ? -EPERM : -ENODATA;
6928                 return 0;
6929         }
6930 diff -NurpP --minimal linux-3.9.5/fs/xfs/xfs_dinode.h linux-3.9.5-vs2.3.6.5/fs/xfs/xfs_dinode.h
6931 --- linux-3.9.5/fs/xfs/xfs_dinode.h     2012-12-11 03:30:57.000000000 +0000
6932 +++ linux-3.9.5-vs2.3.6.5/fs/xfs/xfs_dinode.h   2013-05-31 14:47:11.000000000 +0000
6933 @@ -51,7 +51,9 @@ typedef struct xfs_dinode {
6934         __be32          di_nlink;       /* number of links to file */
6935         __be16          di_projid_lo;   /* lower part of owner's project id */
6936         __be16          di_projid_hi;   /* higher part owner's project id */
6937 -       __u8            di_pad[6];      /* unused, zeroed space */
6938 +       __u8            di_pad[2];      /* unused, zeroed space */
6939 +       __be16          di_tag;         /* context tagging */
6940 +       __be16          di_vflags;      /* vserver specific flags */
6941         __be16          di_flushiter;   /* incremented on flush */
6942         xfs_timestamp_t di_atime;       /* time last accessed */
6943         xfs_timestamp_t di_mtime;       /* time last modified */
6944 @@ -184,6 +186,8 @@ static inline void xfs_dinode_put_rdev(s
6945  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
6946  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
6947  #define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
6948 +#define XFS_DIFLAG_IXUNLINK_BIT     15 /* Immutable inver on unlink */
6949 +
6950  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
6951  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
6952  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
6953 @@ -199,6 +203,7 @@ static inline void xfs_dinode_put_rdev(s
6954  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
6955  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
6956  #define XFS_DIFLAG_FILESTREAM    (1 << XFS_DIFLAG_FILESTREAM_BIT)
6957 +#define XFS_DIFLAG_IXUNLINK      (1 << XFS_DIFLAG_IXUNLINK_BIT)
6958  
6959  #ifdef CONFIG_XFS_RT
6960  #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
6961 @@ -211,6 +216,10 @@ static inline void xfs_dinode_put_rdev(s
6962          XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
6963          XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
6964          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
6965 -        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
6966 +        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM | \
6967 +        XFS_DIFLAG_IXUNLINK)
6968 +
6969 +#define XFS_DIVFLAG_BARRIER    0x01
6970 +#define XFS_DIVFLAG_COW                0x02
6971  
6972  #endif /* __XFS_DINODE_H__ */
6973 diff -NurpP --minimal linux-3.9.5/fs/xfs/xfs_fs.h linux-3.9.5-vs2.3.6.5/fs/xfs/xfs_fs.h
6974 --- linux-3.9.5/fs/xfs/xfs_fs.h 2013-02-19 13:58:49.000000000 +0000
6975 +++ linux-3.9.5-vs2.3.6.5/fs/xfs/xfs_fs.h       2013-05-31 14:47:11.000000000 +0000
6976 @@ -67,6 +67,9 @@ struct fsxattr {
6977  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
6978  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
6979  #define XFS_XFLAG_FILESTREAM   0x00004000      /* use filestream allocator */
6980 +#define XFS_XFLAG_IXUNLINK     0x00008000      /* immutable invert on unlink */
6981 +#define XFS_XFLAG_BARRIER      0x10000000      /* chroot() barrier */
6982 +#define XFS_XFLAG_COW          0x20000000      /* copy on write mark */
6983  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
6984  
6985  /*
6986 @@ -303,7 +306,8 @@ typedef struct xfs_bstat {
6987  #define        bs_projid       bs_projid_lo    /* (previously just bs_projid)  */
6988         __u16           bs_forkoff;     /* inode fork offset in bytes   */
6989         __u16           bs_projid_hi;   /* higher part of project id    */
6990 -       unsigned char   bs_pad[10];     /* pad space, unused            */
6991 +       unsigned char   bs_pad[8];      /* pad space, unused            */
6992 +       __u16           bs_tag;         /* context tagging              */
6993         __u32           bs_dmevmask;    /* DMIG event mask              */
6994         __u16           bs_dmstate;     /* DMIG state info              */
6995         __u16           bs_aextents;    /* attribute number of extents  */
6996 diff -NurpP --minimal linux-3.9.5/fs/xfs/xfs_ialloc.c linux-3.9.5-vs2.3.6.5/fs/xfs/xfs_ialloc.c
6997 --- linux-3.9.5/fs/xfs/xfs_ialloc.c     2013-05-31 13:45:25.000000000 +0000
6998 +++ linux-3.9.5-vs2.3.6.5/fs/xfs/xfs_ialloc.c   2013-05-31 14:47:11.000000000 +0000
6999 @@ -37,7 +37,6 @@
7000  #include "xfs_error.h"
7001  #include "xfs_bmap.h"
7002  
7003 -
7004  /*
7005   * Allocation group level functions.
7006   */
7007 diff -NurpP --minimal linux-3.9.5/fs/xfs/xfs_inode.c linux-3.9.5-vs2.3.6.5/fs/xfs/xfs_inode.c
7008 --- linux-3.9.5/fs/xfs/xfs_inode.c      2013-05-31 13:45:25.000000000 +0000
7009 +++ linux-3.9.5-vs2.3.6.5/fs/xfs/xfs_inode.c    2013-06-03 19:35:13.000000000 +0000
7010 @@ -16,6 +16,7 @@
7011   * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
7012   */
7013  #include <linux/log2.h>
7014 +#include <linux/vs_tag.h>
7015  
7016  #include "xfs.h"
7017  #include "xfs_fs.h"
7018 @@ -835,15 +836,25 @@ xfs_iformat_btree(
7019  STATIC void
7020  xfs_dinode_from_disk(
7021         xfs_icdinode_t          *to,
7022 -       xfs_dinode_t            *from)
7023 +       xfs_dinode_t            *from,
7024 +       int                     tagged)
7025  {
7026 +       uint32_t uid, gid, tag;
7027 +
7028         to->di_magic = be16_to_cpu(from->di_magic);
7029         to->di_mode = be16_to_cpu(from->di_mode);
7030         to->di_version = from ->di_version;
7031         to->di_format = from->di_format;
7032         to->di_onlink = be16_to_cpu(from->di_onlink);
7033 -       to->di_uid = be32_to_cpu(from->di_uid);
7034 -       to->di_gid = be32_to_cpu(from->di_gid);
7035 +
7036 +       uid = be32_to_cpu(from->di_uid);
7037 +       gid = be32_to_cpu(from->di_gid);
7038 +       tag = be16_to_cpu(from->di_tag);
7039 +
7040 +       to->di_uid = INOTAG_UID(tagged, uid, gid);
7041 +       to->di_gid = INOTAG_GID(tagged, uid, gid);
7042 +       to->di_tag = INOTAG_TAG(tagged, uid, gid, tag);
7043 +
7044         to->di_nlink = be32_to_cpu(from->di_nlink);
7045         to->di_projid_lo = be16_to_cpu(from->di_projid_lo);
7046         to->di_projid_hi = be16_to_cpu(from->di_projid_hi);
7047 @@ -865,21 +876,26 @@ xfs_dinode_from_disk(
7048         to->di_dmevmask = be32_to_cpu(from->di_dmevmask);
7049         to->di_dmstate  = be16_to_cpu(from->di_dmstate);
7050         to->di_flags    = be16_to_cpu(from->di_flags);
7051 +       to->di_vflags   = be16_to_cpu(from->di_vflags);
7052         to->di_gen      = be32_to_cpu(from->di_gen);
7053  }
7054  
7055  void
7056  xfs_dinode_to_disk(
7057         xfs_dinode_t            *to,
7058 -       xfs_icdinode_t          *from)
7059 +       xfs_icdinode_t          *from,
7060 +       int                     tagged)
7061  {
7062         to->di_magic = cpu_to_be16(from->di_magic);
7063         to->di_mode = cpu_to_be16(from->di_mode);
7064         to->di_version = from ->di_version;
7065         to->di_format = from->di_format;
7066         to->di_onlink = cpu_to_be16(from->di_onlink);
7067 -       to->di_uid = cpu_to_be32(from->di_uid);
7068 -       to->di_gid = cpu_to_be32(from->di_gid);
7069 +
7070 +       to->di_uid = cpu_to_be32(TAGINO_UID(tagged, from->di_uid, from->di_tag));
7071 +       to->di_gid = cpu_to_be32(TAGINO_GID(tagged, from->di_gid, from->di_tag));
7072 +       to->di_tag = cpu_to_be16(TAGINO_TAG(tagged, from->di_tag));
7073 +
7074         to->di_nlink = cpu_to_be32(from->di_nlink);
7075         to->di_projid_lo = cpu_to_be16(from->di_projid_lo);
7076         to->di_projid_hi = cpu_to_be16(from->di_projid_hi);
7077 @@ -901,12 +917,14 @@ xfs_dinode_to_disk(
7078         to->di_dmevmask = cpu_to_be32(from->di_dmevmask);
7079         to->di_dmstate = cpu_to_be16(from->di_dmstate);
7080         to->di_flags = cpu_to_be16(from->di_flags);
7081 +       to->di_vflags = cpu_to_be16(from->di_vflags);
7082         to->di_gen = cpu_to_be32(from->di_gen);
7083  }
7084  
7085  STATIC uint
7086  _xfs_dic2xflags(
7087 -       __uint16_t              di_flags)
7088 +       __uint16_t              di_flags,
7089 +       __uint16_t              di_vflags)
7090  {
7091         uint                    flags = 0;
7092  
7093 @@ -917,6 +935,8 @@ _xfs_dic2xflags(
7094                         flags |= XFS_XFLAG_PREALLOC;
7095                 if (di_flags & XFS_DIFLAG_IMMUTABLE)
7096                         flags |= XFS_XFLAG_IMMUTABLE;
7097 +               if (di_flags & XFS_DIFLAG_IXUNLINK)
7098 +                       flags |= XFS_XFLAG_IXUNLINK;
7099                 if (di_flags & XFS_DIFLAG_APPEND)
7100                         flags |= XFS_XFLAG_APPEND;
7101                 if (di_flags & XFS_DIFLAG_SYNC)
7102 @@ -941,6 +961,10 @@ _xfs_dic2xflags(
7103                         flags |= XFS_XFLAG_FILESTREAM;
7104         }
7105  
7106 +       if (di_vflags & XFS_DIVFLAG_BARRIER)
7107 +               flags |= FS_BARRIER_FL;
7108 +       if (di_vflags & XFS_DIVFLAG_COW)
7109 +               flags |= FS_COW_FL;
7110         return flags;
7111  }
7112  
7113 @@ -950,7 +974,7 @@ xfs_ip2xflags(
7114  {
7115         xfs_icdinode_t          *dic = &ip->i_d;
7116  
7117 -       return _xfs_dic2xflags(dic->di_flags) |
7118 +       return _xfs_dic2xflags(dic->di_flags, dic->di_vflags) |
7119                                 (XFS_IFORK_Q(ip) ? XFS_XFLAG_HASATTR : 0);
7120  }
7121  
7122 @@ -958,7 +982,8 @@ uint
7123  xfs_dic2xflags(
7124         xfs_dinode_t            *dip)
7125  {
7126 -       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags)) |
7127 +       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags),
7128 +                               be16_to_cpu(dip->di_vflags)) |
7129                                 (XFS_DFORK_Q(dip) ? XFS_XFLAG_HASATTR : 0);
7130  }
7131  
7132 @@ -1012,7 +1037,8 @@ xfs_iread(
7133          * Otherwise, just get the truly permanent information.
7134          */
7135         if (dip->di_mode) {
7136 -               xfs_dinode_from_disk(&ip->i_d, dip);
7137 +               xfs_dinode_from_disk(&ip->i_d, dip,
7138 +                       mp->m_flags & XFS_MOUNT_TAGGED);
7139                 error = xfs_iformat(ip, dip);
7140                 if (error)  {
7141  #ifdef DEBUG
7142 @@ -1199,6 +1225,7 @@ xfs_ialloc(
7143         ASSERT(ip->i_d.di_nlink == nlink);
7144         ip->i_d.di_uid = current_fsuid();
7145         ip->i_d.di_gid = current_fsgid();
7146 +       ip->i_d.di_tag = current_fstag(&ip->i_vnode);
7147         xfs_set_projid(ip, prid);
7148         memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
7149  
7150 @@ -1258,6 +1285,7 @@ xfs_ialloc(
7151         ip->i_d.di_dmevmask = 0;
7152         ip->i_d.di_dmstate = 0;
7153         ip->i_d.di_flags = 0;
7154 +       ip->i_d.di_vflags = 0;
7155         flags = XFS_ILOG_CORE;
7156         switch (mode & S_IFMT) {
7157         case S_IFIFO:
7158 @@ -1952,6 +1980,7 @@ xfs_ifree(
7159         }
7160         ip->i_d.di_mode = 0;            /* mark incore inode as free */
7161         ip->i_d.di_flags = 0;
7162 +       ip->i_d.di_vflags = 0;
7163         ip->i_d.di_dmevmask = 0;
7164         ip->i_d.di_forkoff = 0;         /* mark the attr fork not in use */
7165         ip->i_d.di_format = XFS_DINODE_FMT_EXTENTS;
7166 @@ -2118,7 +2147,6 @@ xfs_iroot_realloc(
7167         return;
7168  }
7169  
7170 -
7171  /*
7172   * This is called when the amount of space needed for if_data
7173   * is increased or decreased.  The change in size is indicated by
7174 @@ -2800,7 +2828,8 @@ xfs_iflush_int(
7175          * because if the inode is dirty at all the core must
7176          * be.
7177          */
7178 -       xfs_dinode_to_disk(dip, &ip->i_d);
7179 +       xfs_dinode_to_disk(dip, &ip->i_d,
7180 +               mp->m_flags & XFS_MOUNT_TAGGED);
7181  
7182         /* Wrap, we never let the log put out DI_MAX_FLUSH */
7183         if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
7184 diff -NurpP --minimal linux-3.9.5/fs/xfs/xfs_inode.h linux-3.9.5-vs2.3.6.5/fs/xfs/xfs_inode.h
7185 --- linux-3.9.5/fs/xfs/xfs_inode.h      2013-05-31 13:45:25.000000000 +0000
7186 +++ linux-3.9.5-vs2.3.6.5/fs/xfs/xfs_inode.h    2013-05-31 14:47:11.000000000 +0000
7187 @@ -134,7 +134,9 @@ typedef struct xfs_icdinode {
7188         __uint32_t      di_nlink;       /* number of links to file */
7189         __uint16_t      di_projid_lo;   /* lower part of owner's project id */
7190         __uint16_t      di_projid_hi;   /* higher part of owner's project id */
7191 -       __uint8_t       di_pad[6];      /* unused, zeroed space */
7192 +       __uint8_t       di_pad[2];      /* unused, zeroed space */
7193 +       __uint16_t      di_tag;         /* context tagging */
7194 +       __uint16_t      di_vflags;      /* vserver specific flags */
7195         __uint16_t      di_flushiter;   /* incremented on flush */
7196         xfs_ictimestamp_t di_atime;     /* time last accessed */
7197         xfs_ictimestamp_t di_mtime;     /* time last modified */
7198 @@ -556,7 +558,7 @@ int         xfs_imap_to_bp(struct xfs_mount *,
7199  int            xfs_iread(struct xfs_mount *, struct xfs_trans *,
7200                           struct xfs_inode *, uint);
7201  void           xfs_dinode_to_disk(struct xfs_dinode *,
7202 -                                  struct xfs_icdinode *);
7203 +                                  struct xfs_icdinode *, int);
7204  void           xfs_idestroy_fork(struct xfs_inode *, int);
7205  void           xfs_idata_realloc(struct xfs_inode *, int, int);
7206  void           xfs_iroot_realloc(struct xfs_inode *, int, int);
7207 diff -NurpP --minimal linux-3.9.5/fs/xfs/xfs_ioctl.c linux-3.9.5-vs2.3.6.5/fs/xfs/xfs_ioctl.c
7208 --- linux-3.9.5/fs/xfs/xfs_ioctl.c      2013-05-31 13:45:25.000000000 +0000
7209 +++ linux-3.9.5-vs2.3.6.5/fs/xfs/xfs_ioctl.c    2013-05-31 14:47:11.000000000 +0000
7210 @@ -26,7 +26,7 @@
7211  #include "xfs_bmap_btree.h"
7212  #include "xfs_dinode.h"
7213  #include "xfs_inode.h"
7214 -#include "xfs_ioctl.h"
7215 +// #include "xfs_ioctl.h"
7216  #include "xfs_rtalloc.h"
7217  #include "xfs_itable.h"
7218  #include "xfs_error.h"
7219 @@ -763,6 +763,10 @@ xfs_merge_ioc_xflags(
7220                 xflags |= XFS_XFLAG_IMMUTABLE;
7221         else
7222                 xflags &= ~XFS_XFLAG_IMMUTABLE;
7223 +       if (flags & FS_IXUNLINK_FL)
7224 +               xflags |= XFS_XFLAG_IXUNLINK;
7225 +       else
7226 +               xflags &= ~XFS_XFLAG_IXUNLINK;
7227         if (flags & FS_APPEND_FL)
7228                 xflags |= XFS_XFLAG_APPEND;
7229         else
7230 @@ -791,6 +795,8 @@ xfs_di2lxflags(
7231  
7232         if (di_flags & XFS_DIFLAG_IMMUTABLE)
7233                 flags |= FS_IMMUTABLE_FL;
7234 +       if (di_flags & XFS_DIFLAG_IXUNLINK)
7235 +               flags |= FS_IXUNLINK_FL;
7236         if (di_flags & XFS_DIFLAG_APPEND)
7237                 flags |= FS_APPEND_FL;
7238         if (di_flags & XFS_DIFLAG_SYNC)
7239 @@ -851,6 +857,8 @@ xfs_set_diflags(
7240         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
7241         if (xflags & XFS_XFLAG_IMMUTABLE)
7242                 di_flags |= XFS_DIFLAG_IMMUTABLE;
7243 +       if (xflags & XFS_XFLAG_IXUNLINK)
7244 +               di_flags |= XFS_DIFLAG_IXUNLINK;
7245         if (xflags & XFS_XFLAG_APPEND)
7246                 di_flags |= XFS_DIFLAG_APPEND;
7247         if (xflags & XFS_XFLAG_SYNC)
7248 @@ -893,6 +901,10 @@ xfs_diflags_to_linux(
7249                 inode->i_flags |= S_IMMUTABLE;
7250         else
7251                 inode->i_flags &= ~S_IMMUTABLE;
7252 +       if (xflags & XFS_XFLAG_IXUNLINK)
7253 +               inode->i_flags |= S_IXUNLINK;
7254 +       else
7255 +               inode->i_flags &= ~S_IXUNLINK;
7256         if (xflags & XFS_XFLAG_APPEND)
7257                 inode->i_flags |= S_APPEND;
7258         else
7259 @@ -1397,10 +1409,18 @@ xfs_file_ioctl(
7260         case XFS_IOC_FSGETXATTRA:
7261                 return xfs_ioc_fsgetxattr(ip, 1, arg);
7262         case XFS_IOC_FSSETXATTR:
7263 +               if (IS_BARRIER(inode)) {
7264 +                       vxwprintk_task(1, "messing with the barrier.");
7265 +                       return -XFS_ERROR(EACCES);
7266 +               }
7267                 return xfs_ioc_fssetxattr(ip, filp, arg);
7268         case XFS_IOC_GETXFLAGS:
7269                 return xfs_ioc_getxflags(ip, arg);
7270         case XFS_IOC_SETXFLAGS:
7271 +               if (IS_BARRIER(inode)) {
7272 +                       vxwprintk_task(1, "messing with the barrier.");
7273 +                       return -XFS_ERROR(EACCES);
7274 +               }
7275                 return xfs_ioc_setxflags(ip, filp, arg);
7276  
7277         case XFS_IOC_FSSETDM: {
7278 diff -NurpP --minimal linux-3.9.5/fs/xfs/xfs_ioctl.h linux-3.9.5-vs2.3.6.5/fs/xfs/xfs_ioctl.h
7279 --- linux-3.9.5/fs/xfs/xfs_ioctl.h      2012-12-11 03:30:57.000000000 +0000
7280 +++ linux-3.9.5-vs2.3.6.5/fs/xfs/xfs_ioctl.h    2013-05-31 14:47:11.000000000 +0000
7281 @@ -70,6 +70,12 @@ xfs_handle_to_dentry(
7282         void __user             *uhandle,
7283         u32                     hlen);
7284  
7285 +extern int
7286 +xfs_sync_flags(
7287 +       struct inode            *inode,
7288 +       int                     flags,
7289 +       int                     vflags);
7290 +
7291  extern long
7292  xfs_file_ioctl(
7293         struct file             *filp,
7294 diff -NurpP --minimal linux-3.9.5/fs/xfs/xfs_iops.c linux-3.9.5-vs2.3.6.5/fs/xfs/xfs_iops.c
7295 --- linux-3.9.5/fs/xfs/xfs_iops.c       2013-06-11 12:22:40.000000000 +0000
7296 +++ linux-3.9.5-vs2.3.6.5/fs/xfs/xfs_iops.c     2013-06-13 00:14:32.000000000 +0000
7297 @@ -28,6 +28,7 @@
7298  #include "xfs_bmap_btree.h"
7299  #include "xfs_dinode.h"
7300  #include "xfs_inode.h"
7301 +#include "xfs_ioctl.h"
7302  #include "xfs_bmap.h"
7303  #include "xfs_rtalloc.h"
7304  #include "xfs_error.h"
7305 @@ -47,6 +48,7 @@
7306  #include <linux/security.h>
7307  #include <linux/fiemap.h>
7308  #include <linux/slab.h>
7309 +#include <linux/vs_tag.h>
7310  
7311  static int
7312  xfs_initxattrs(
7313 @@ -422,6 +424,7 @@ xfs_vn_getattr(
7314         stat->nlink = ip->i_d.di_nlink;
7315         stat->uid = ip->i_d.di_uid;
7316         stat->gid = ip->i_d.di_gid;
7317 +       stat->tag = ip->i_d.di_tag;
7318         stat->ino = ip->i_ino;
7319         stat->atime = inode->i_atime;
7320         stat->mtime = inode->i_mtime;
7321 @@ -1054,6 +1057,7 @@ static const struct inode_operations xfs
7322         .listxattr              = xfs_vn_listxattr,
7323         .fiemap                 = xfs_vn_fiemap,
7324         .update_time            = xfs_vn_update_time,
7325 +       .sync_flags             = xfs_sync_flags,
7326  };
7327  
7328  static const struct inode_operations xfs_dir_inode_operations = {
7329 @@ -1080,6 +1084,7 @@ static const struct inode_operations xfs
7330         .removexattr            = generic_removexattr,
7331         .listxattr              = xfs_vn_listxattr,
7332         .update_time            = xfs_vn_update_time,
7333 +       .sync_flags             = xfs_sync_flags,
7334  };
7335  
7336  static const struct inode_operations xfs_dir_ci_inode_operations = {
7337 @@ -1131,6 +1136,10 @@ xfs_diflags_to_iflags(
7338                 inode->i_flags |= S_IMMUTABLE;
7339         else
7340                 inode->i_flags &= ~S_IMMUTABLE;
7341 +       if (ip->i_d.di_flags & XFS_DIFLAG_IXUNLINK)
7342 +               inode->i_flags |= S_IXUNLINK;
7343 +       else
7344 +               inode->i_flags &= ~S_IXUNLINK;
7345         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
7346                 inode->i_flags |= S_APPEND;
7347         else
7348 @@ -1143,6 +1152,15 @@ xfs_diflags_to_iflags(
7349                 inode->i_flags |= S_NOATIME;
7350         else
7351                 inode->i_flags &= ~S_NOATIME;
7352 +
7353 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_BARRIER)
7354 +               inode->i_vflags |= V_BARRIER;
7355 +       else
7356 +               inode->i_vflags &= ~V_BARRIER;
7357 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_COW)
7358 +               inode->i_vflags |= V_COW;
7359 +       else
7360 +               inode->i_vflags &= ~V_COW;
7361  }
7362  
7363  /*
7364 @@ -1174,6 +1192,7 @@ xfs_setup_inode(
7365         set_nlink(inode, ip->i_d.di_nlink);
7366         inode->i_uid    = ip->i_d.di_uid;
7367         inode->i_gid    = ip->i_d.di_gid;
7368 +       inode->i_tag    = ip->i_d.di_tag;
7369  
7370         switch (inode->i_mode & S_IFMT) {
7371         case S_IFBLK:
7372 diff -NurpP --minimal linux-3.9.5/fs/xfs/xfs_itable.c linux-3.9.5-vs2.3.6.5/fs/xfs/xfs_itable.c
7373 --- linux-3.9.5/fs/xfs/xfs_itable.c     2013-02-19 13:58:49.000000000 +0000
7374 +++ linux-3.9.5-vs2.3.6.5/fs/xfs/xfs_itable.c   2013-05-31 14:47:11.000000000 +0000
7375 @@ -97,6 +97,7 @@ xfs_bulkstat_one_int(
7376         buf->bs_mode = dic->di_mode;
7377         buf->bs_uid = dic->di_uid;
7378         buf->bs_gid = dic->di_gid;
7379 +       buf->bs_tag = dic->di_tag;
7380         buf->bs_size = dic->di_size;
7381         buf->bs_atime.tv_sec = dic->di_atime.t_sec;
7382         buf->bs_atime.tv_nsec = dic->di_atime.t_nsec;
7383 diff -NurpP --minimal linux-3.9.5/fs/xfs/xfs_linux.h linux-3.9.5-vs2.3.6.5/fs/xfs/xfs_linux.h
7384 --- linux-3.9.5/fs/xfs/xfs_linux.h      2013-02-19 13:58:49.000000000 +0000
7385 +++ linux-3.9.5-vs2.3.6.5/fs/xfs/xfs_linux.h    2013-05-31 14:47:11.000000000 +0000
7386 @@ -123,6 +123,7 @@
7387  
7388  #define current_cpu()          (raw_smp_processor_id())
7389  #define current_pid()          (current->pid)
7390 +#define current_fstag(vp)      (dx_current_fstag((vp)->i_sb))
7391  #define current_test_flags(f)  (current->flags & (f))
7392  #define current_set_flags_nested(sp, f)                \
7393                 (*(sp) = current->flags, current->flags |= (f))
7394 diff -NurpP --minimal linux-3.9.5/fs/xfs/xfs_log_recover.c linux-3.9.5-vs2.3.6.5/fs/xfs/xfs_log_recover.c
7395 --- linux-3.9.5/fs/xfs/xfs_log_recover.c        2013-05-31 13:45:25.000000000 +0000
7396 +++ linux-3.9.5-vs2.3.6.5/fs/xfs/xfs_log_recover.c      2013-05-31 14:47:11.000000000 +0000
7397 @@ -2361,7 +2361,8 @@ xlog_recover_inode_pass2(
7398         }
7399  
7400         /* The core is in in-core format */
7401 -       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr);
7402 +       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr,
7403 +               mp->m_flags & XFS_MOUNT_TAGGED);
7404  
7405         /* the rest is in on-disk format */
7406         if (item->ri_buf[1].i_len > sizeof(struct xfs_icdinode)) {
7407 diff -NurpP --minimal linux-3.9.5/fs/xfs/xfs_mount.h linux-3.9.5-vs2.3.6.5/fs/xfs/xfs_mount.h
7408 --- linux-3.9.5/fs/xfs/xfs_mount.h      2013-05-31 13:45:25.000000000 +0000
7409 +++ linux-3.9.5-vs2.3.6.5/fs/xfs/xfs_mount.h    2013-05-31 14:47:11.000000000 +0000
7410 @@ -254,6 +254,7 @@ typedef struct xfs_mount {
7411                                                    allocator */
7412  #define XFS_MOUNT_NOATTR2      (1ULL << 25)    /* disable use of attr2 format */
7413  
7414 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
7415  
7416  /*
7417   * Default minimum read and write sizes.
7418 diff -NurpP --minimal linux-3.9.5/fs/xfs/xfs_super.c linux-3.9.5-vs2.3.6.5/fs/xfs/xfs_super.c
7419 --- linux-3.9.5/fs/xfs/xfs_super.c      2013-05-31 13:45:25.000000000 +0000
7420 +++ linux-3.9.5-vs2.3.6.5/fs/xfs/xfs_super.c    2013-05-31 14:47:11.000000000 +0000
7421 @@ -114,6 +114,9 @@ mempool_t *xfs_ioend_pool;
7422  #define MNTOPT_NODELAYLOG  "nodelaylog"        /* Delayed logging disabled */
7423  #define MNTOPT_DISCARD    "discard"    /* Discard unused blocks */
7424  #define MNTOPT_NODISCARD   "nodiscard" /* Do not discard unused blocks */
7425 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
7426 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
7427 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
7428  
7429  /*
7430   * Table driven mount option parser.
7431 @@ -126,6 +129,8 @@ enum {
7432         Opt_nobarrier,
7433         Opt_inode64,
7434         Opt_inode32,
7435 +       Opt_tag,
7436 +       Opt_notag,
7437         Opt_err
7438  };
7439  
7440 @@ -134,6 +139,9 @@ static const match_table_t tokens = {
7441         {Opt_nobarrier, "nobarrier"},
7442         {Opt_inode64, "inode64"},
7443         {Opt_inode32, "inode32"},
7444 +       {Opt_tag, "tagxid"},
7445 +       {Opt_tag, "tag"},
7446 +       {Opt_notag, "notag"},
7447         {Opt_err, NULL}
7448  };
7449  
7450 @@ -392,6 +400,19 @@ xfs_parseargs(
7451                 } else if (!strcmp(this_char, "irixsgid")) {
7452                         xfs_warn(mp,
7453         "irixsgid is now a sysctl(2) variable, option is deprecated.");
7454 +#ifndef CONFIG_TAGGING_NONE
7455 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7456 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7457 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
7458 +                       mp->m_flags &= ~XFS_MOUNT_TAGGED;
7459 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
7460 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7461 +#endif
7462 +#ifdef CONFIG_PROPAGATE
7463 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7464 +                       /* use value */
7465 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7466 +#endif
7467                 } else {
7468                         xfs_warn(mp, "unknown mount option [%s].", this_char);
7469                         return EINVAL;
7470 @@ -1238,6 +1259,16 @@ xfs_fs_remount(
7471                 case Opt_inode32:
7472                         mp->m_maxagi = xfs_set_inode32(mp);
7473                         break;
7474 +               case Opt_tag:
7475 +                       if (!(sb->s_flags & MS_TAGGED)) {
7476 +                               printk(KERN_INFO
7477 +                                       "XFS: %s: tagging not permitted on remount.\n",
7478 +                                       sb->s_id);
7479 +                               return -EINVAL;
7480 +                       }
7481 +                       break;
7482 +               case Opt_notag:
7483 +                       break;
7484                 default:
7485                         /*
7486                          * Logically we would return an error here to prevent
7487 @@ -1458,6 +1489,9 @@ xfs_fs_fill_super(
7488         if (error)
7489                 goto out_free_sb;
7490  
7491 +       if (mp->m_flags & XFS_MOUNT_TAGGED)
7492 +               sb->s_flags |= MS_TAGGED;
7493 +
7494         /*
7495          * we must configure the block size in the superblock before we run the
7496          * full mount process as the mount process can lookup and cache inodes.
7497 diff -NurpP --minimal linux-3.9.5/fs/xfs/xfs_vnodeops.c linux-3.9.5-vs2.3.6.5/fs/xfs/xfs_vnodeops.c
7498 --- linux-3.9.5/fs/xfs/xfs_vnodeops.c   2013-05-31 13:45:25.000000000 +0000
7499 +++ linux-3.9.5-vs2.3.6.5/fs/xfs/xfs_vnodeops.c 2013-05-31 14:47:11.000000000 +0000
7500 @@ -104,6 +104,77 @@ xfs_readlink_bmap(
7501         return error;
7502  }
7503  
7504 +
7505 +STATIC void
7506 +xfs_get_inode_flags(
7507 +       xfs_inode_t     *ip)
7508 +{
7509 +       struct inode    *inode = VFS_I(ip);
7510 +       unsigned int    flags = inode->i_flags;
7511 +       unsigned int    vflags = inode->i_vflags;
7512 +
7513 +       if (flags & S_IMMUTABLE)
7514 +               ip->i_d.di_flags |= XFS_DIFLAG_IMMUTABLE;
7515 +       else
7516 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IMMUTABLE;
7517 +       if (flags & S_IXUNLINK)
7518 +               ip->i_d.di_flags |= XFS_DIFLAG_IXUNLINK;
7519 +       else
7520 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IXUNLINK;
7521 +
7522 +       if (vflags & V_BARRIER)
7523 +               ip->i_d.di_vflags |= XFS_DIVFLAG_BARRIER;
7524 +       else
7525 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_BARRIER;
7526 +       if (vflags & V_COW)
7527 +               ip->i_d.di_vflags |= XFS_DIVFLAG_COW;
7528 +       else
7529 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_COW;
7530 +}
7531 +
7532 +int
7533 +xfs_sync_flags(
7534 +       struct inode            *inode,
7535 +       int                     flags,
7536 +       int                     vflags)
7537 +{
7538 +       struct xfs_inode        *ip = XFS_I(inode);
7539 +       struct xfs_mount        *mp = ip->i_mount;
7540 +       struct xfs_trans        *tp;
7541 +       unsigned int            lock_flags = 0;
7542 +       int                     code;
7543 +
7544 +       tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
7545 +       code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
7546 +       if (code)
7547 +               goto error_out;
7548 +
7549 +       xfs_ilock(ip, XFS_ILOCK_EXCL);
7550 +       xfs_trans_ijoin(tp, ip, 0);
7551 +
7552 +       inode->i_flags = flags;
7553 +       inode->i_vflags = vflags;
7554 +       xfs_get_inode_flags(ip);
7555 +
7556 +       xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
7557 +       xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG);
7558 +
7559 +       XFS_STATS_INC(xs_ig_attrchg);
7560 +
7561 +       if (mp->m_flags & XFS_MOUNT_WSYNC)
7562 +               xfs_trans_set_sync(tp);
7563 +       code = xfs_trans_commit(tp, 0);
7564 +       xfs_iunlock(ip, XFS_ILOCK_EXCL);
7565 +       return code;
7566 +
7567 +error_out:
7568 +       xfs_trans_cancel(tp, 0);
7569 +       if (lock_flags)
7570 +               xfs_iunlock(ip, XFS_ILOCK_EXCL);
7571 +       return code;
7572 +}
7573 +
7574 +
7575  int
7576  xfs_readlink(
7577         xfs_inode_t     *ip,
7578 diff -NurpP --minimal linux-3.9.5/include/linux/cred.h linux-3.9.5-vs2.3.6.5/include/linux/cred.h
7579 --- linux-3.9.5/include/linux/cred.h    2013-02-19 13:58:50.000000000 +0000
7580 +++ linux-3.9.5-vs2.3.6.5/include/linux/cred.h  2013-05-31 14:47:11.000000000 +0000
7581 @@ -143,6 +143,7 @@ extern void exit_creds(struct task_struc
7582  extern int copy_creds(struct task_struct *, unsigned long);
7583  extern const struct cred *get_task_cred(struct task_struct *);
7584  extern struct cred *cred_alloc_blank(void);
7585 +extern struct cred *__prepare_creds(const struct cred *);
7586  extern struct cred *prepare_creds(void);
7587  extern struct cred *prepare_exec_creds(void);
7588  extern int commit_creds(struct cred *);
7589 @@ -196,6 +197,31 @@ static inline void validate_process_cred
7590  }
7591  #endif
7592  
7593 +static inline void set_cred_subscribers(struct cred *cred, int n)
7594 +{
7595 +#ifdef CONFIG_DEBUG_CREDENTIALS
7596 +       atomic_set(&cred->subscribers, n);
7597 +#endif
7598 +}
7599 +
7600 +static inline int read_cred_subscribers(const struct cred *cred)
7601 +{
7602 +#ifdef CONFIG_DEBUG_CREDENTIALS
7603 +       return atomic_read(&cred->subscribers);
7604 +#else
7605 +       return 0;
7606 +#endif
7607 +}
7608 +
7609 +static inline void alter_cred_subscribers(const struct cred *_cred, int n)
7610 +{
7611 +#ifdef CONFIG_DEBUG_CREDENTIALS
7612 +       struct cred *cred = (struct cred *) _cred;
7613 +
7614 +       atomic_add(n, &cred->subscribers);
7615 +#endif
7616 +}
7617 +
7618  /**
7619   * get_new_cred - Get a reference on a new set of credentials
7620   * @cred: The new credentials to reference
7621 diff -NurpP --minimal linux-3.9.5/include/linux/devpts_fs.h linux-3.9.5-vs2.3.6.5/include/linux/devpts_fs.h
7622 --- linux-3.9.5/include/linux/devpts_fs.h       2013-02-19 13:58:50.000000000 +0000
7623 +++ linux-3.9.5-vs2.3.6.5/include/linux/devpts_fs.h     2013-05-31 14:47:11.000000000 +0000
7624 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
7625  
7626  #endif
7627  
7628 -
7629  #endif /* _LINUX_DEVPTS_FS_H */
7630 diff -NurpP --minimal linux-3.9.5/include/linux/fs.h linux-3.9.5-vs2.3.6.5/include/linux/fs.h
7631 --- linux-3.9.5/include/linux/fs.h      2013-05-31 13:45:27.000000000 +0000
7632 +++ linux-3.9.5-vs2.3.6.5/include/linux/fs.h    2013-06-12 23:49:08.000000000 +0000
7633 @@ -211,6 +211,7 @@ typedef void (dio_iodone_t)(struct kiocb
7634  #define ATTR_KILL_PRIV (1 << 14)
7635  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
7636  #define ATTR_TIMES_SET (1 << 16)
7637 +#define ATTR_TAG       (1 << 17)
7638  
7639  /*
7640   * This is the Inode Attributes structure, used for notify_change().  It
7641 @@ -226,6 +227,7 @@ struct iattr {
7642         umode_t         ia_mode;
7643         kuid_t          ia_uid;
7644         kgid_t          ia_gid;
7645 +       ktag_t          ia_tag;
7646         loff_t          ia_size;
7647         struct timespec ia_atime;
7648         struct timespec ia_mtime;
7649 @@ -523,7 +525,9 @@ struct inode {
7650         unsigned short          i_opflags;
7651         kuid_t                  i_uid;
7652         kgid_t                  i_gid;
7653 -       unsigned int            i_flags;
7654 +       ktag_t                  i_tag;
7655 +       unsigned short          i_flags;
7656 +       unsigned short          i_vflags;
7657  
7658  #ifdef CONFIG_FS_POSIX_ACL
7659         struct posix_acl        *i_acl;
7660 @@ -552,6 +556,7 @@ struct inode {
7661                 unsigned int __i_nlink;
7662         };
7663         dev_t                   i_rdev;
7664 +       dev_t                   i_mdev;
7665         loff_t                  i_size;
7666         struct timespec         i_atime;
7667         struct timespec         i_mtime;
7668 @@ -702,6 +707,11 @@ static inline gid_t i_gid_read(const str
7669         return from_kgid(&init_user_ns, inode->i_gid);
7670  }
7671  
7672 +static inline vtag_t i_tag_read(const struct inode *inode)
7673 +{
7674 +       return from_ktag(&init_user_ns, inode->i_tag);
7675 +}
7676 +
7677  static inline void i_uid_write(struct inode *inode, uid_t uid)
7678  {
7679         inode->i_uid = make_kuid(&init_user_ns, uid);
7680 @@ -712,14 +722,19 @@ static inline void i_gid_write(struct in
7681         inode->i_gid = make_kgid(&init_user_ns, gid);
7682  }
7683  
7684 +static inline void i_tag_write(struct inode *inode, vtag_t tag)
7685 +{
7686 +       inode->i_tag = make_ktag(&init_user_ns, tag);
7687 +}
7688 +
7689  static inline unsigned iminor(const struct inode *inode)
7690  {
7691 -       return MINOR(inode->i_rdev);
7692 +       return MINOR(inode->i_mdev);
7693  }
7694  
7695  static inline unsigned imajor(const struct inode *inode)
7696  {
7697 -       return MAJOR(inode->i_rdev);
7698 +       return MAJOR(inode->i_mdev);
7699  }
7700  
7701  extern struct block_device *I_BDEV(struct inode *inode);
7702 @@ -786,6 +801,7 @@ struct file {
7703         loff_t                  f_pos;
7704         struct fown_struct      f_owner;
7705         const struct cred       *f_cred;
7706 +       vxid_t                  f_xid;
7707         struct file_ra_state    f_ra;
7708  
7709         u64                     f_version;
7710 @@ -937,6 +953,7 @@ struct file_lock {
7711         struct file *fl_file;
7712         loff_t fl_start;
7713         loff_t fl_end;
7714 +       vxid_t fl_xid;
7715  
7716         struct fasync_struct *  fl_fasync; /* for lease break notifications */
7717         /* for lease breaks: */
7718 @@ -1567,6 +1584,7 @@ struct inode_operations {
7719         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
7720         ssize_t (*listxattr) (struct dentry *, char *, size_t);
7721         int (*removexattr) (struct dentry *, const char *);
7722 +       int (*sync_flags) (struct inode *, int, int);
7723         int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
7724                       u64 len);
7725         int (*update_time)(struct inode *, struct timespec *, int);
7726 @@ -1579,6 +1597,7 @@ ssize_t rw_copy_check_uvector(int type,
7727                               unsigned long nr_segs, unsigned long fast_segs,
7728                               struct iovec *fast_pointer,
7729                               struct iovec **ret_pointer);
7730 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
7731  
7732  extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
7733  extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *);
7734 @@ -1632,6 +1651,14 @@ struct super_operations {
7735  #define S_IMA          1024    /* Inode has an associated IMA struct */
7736  #define S_AUTOMOUNT    2048    /* Automount/referral quasi-directory */
7737  #define S_NOSEC                4096    /* no suid or xattr security attributes */
7738 +#define S_IXUNLINK     8192    /* Immutable Invert on unlink */
7739 +
7740 +/* Linux-VServer related Inode flags */
7741 +
7742 +#define V_VALID                1
7743 +#define V_XATTR                2
7744 +#define V_BARRIER      4       /* Barrier for chroot() */
7745 +#define V_COW          8       /* Copy on Write */
7746  
7747  /*
7748   * Note that nosuid etc flags are inode-specific: setting some file-system
7749 @@ -1656,10 +1683,13 @@ struct super_operations {
7750  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
7751  #define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
7752  #define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
7753 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
7754  
7755  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
7756  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
7757  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
7758 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
7759 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
7760  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
7761  
7762  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
7763 @@ -1670,6 +1700,16 @@ struct super_operations {
7764  #define IS_AUTOMOUNT(inode)    ((inode)->i_flags & S_AUTOMOUNT)
7765  #define IS_NOSEC(inode)                ((inode)->i_flags & S_NOSEC)
7766  
7767 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
7768 +
7769 +#ifdef CONFIG_VSERVER_COWBL
7770 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
7771 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
7772 +#else
7773 +#  define IS_COW(inode)                (0)
7774 +#  define IS_COW_LINK(inode)   (0)
7775 +#endif
7776 +
7777  /*
7778   * Inode state bits.  Protected by inode->i_lock
7779   *
7780 @@ -1898,6 +1938,9 @@ extern int rw_verify_area(int, struct fi
7781  extern int locks_mandatory_locked(struct inode *);
7782  extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t);
7783  
7784 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
7785 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
7786 +
7787  /*
7788   * Candidates for mandatory locking have the setgid bit set
7789   * but no group execute bit -  an otherwise meaningless combination.
7790 @@ -2509,6 +2552,7 @@ extern int dcache_dir_open(struct inode
7791  extern int dcache_dir_close(struct inode *, struct file *);
7792  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
7793  extern int dcache_readdir(struct file *, void *, filldir_t);
7794 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
7795  extern int simple_setattr(struct dentry *, struct iattr *);
7796  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
7797  extern int simple_statfs(struct dentry *, struct kstatfs *);
7798 diff -NurpP --minimal linux-3.9.5/include/linux/init_task.h linux-3.9.5-vs2.3.6.5/include/linux/init_task.h
7799 --- linux-3.9.5/include/linux/init_task.h       2013-05-31 13:45:27.000000000 +0000
7800 +++ linux-3.9.5-vs2.3.6.5/include/linux/init_task.h     2013-05-31 14:53:41.000000000 +0000
7801 @@ -222,6 +222,10 @@ extern struct task_group root_task_group
7802         INIT_TASK_RCU_PREEMPT(tsk)                                      \
7803         INIT_CPUSET_SEQ                                                 \
7804         INIT_VTIME(tsk)                                                 \
7805 +       .xid            = 0,                                            \
7806 +       .vx_info        = NULL,                                         \
7807 +       .nid            = 0,                                            \
7808 +       .nx_info        = NULL,                                         \
7809  }
7810  
7811  
7812 diff -NurpP --minimal linux-3.9.5/include/linux/ipc.h linux-3.9.5-vs2.3.6.5/include/linux/ipc.h
7813 --- linux-3.9.5/include/linux/ipc.h     2012-12-11 03:30:57.000000000 +0000
7814 +++ linux-3.9.5-vs2.3.6.5/include/linux/ipc.h   2013-06-12 23:49:08.000000000 +0000
7815 @@ -16,6 +16,7 @@ struct kern_ipc_perm
7816         key_t           key;
7817         kuid_t          uid;
7818         kgid_t          gid;
7819 +       vxid_t          xid;
7820         kuid_t          cuid;
7821         kgid_t          cgid;
7822         umode_t         mode; 
7823 diff -NurpP --minimal linux-3.9.5/include/linux/loop.h linux-3.9.5-vs2.3.6.5/include/linux/loop.h
7824 --- linux-3.9.5/include/linux/loop.h    2013-02-19 13:58:51.000000000 +0000
7825 +++ linux-3.9.5-vs2.3.6.5/include/linux/loop.h  2013-06-12 23:49:08.000000000 +0000
7826 @@ -41,6 +41,7 @@ struct loop_device {
7827         struct loop_func_table *lo_encryption;
7828         __u32           lo_init[2];
7829         kuid_t          lo_key_owner;   /* Who set the key */
7830 +       vxid_t          lo_xid;
7831         int             (*ioctl)(struct loop_device *, int cmd, 
7832                                  unsigned long arg); 
7833  
7834 diff -NurpP --minimal linux-3.9.5/include/linux/memcontrol.h linux-3.9.5-vs2.3.6.5/include/linux/memcontrol.h
7835 --- linux-3.9.5/include/linux/memcontrol.h      2013-05-31 13:45:28.000000000 +0000
7836 +++ linux-3.9.5-vs2.3.6.5/include/linux/memcontrol.h    2013-05-31 14:47:11.000000000 +0000
7837 @@ -86,6 +86,13 @@ extern struct mem_cgroup *try_get_mem_cg
7838  extern struct mem_cgroup *parent_mem_cgroup(struct mem_cgroup *memcg);
7839  extern struct mem_cgroup *mem_cgroup_from_cont(struct cgroup *cont);
7840  
7841 +extern u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member);
7842 +extern u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member);
7843 +
7844 +extern s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem);
7845 +extern s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem);
7846 +extern s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem);
7847 +
7848  static inline
7849  bool mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *memcg)
7850  {
7851 diff -NurpP --minimal linux-3.9.5/include/linux/mm_types.h linux-3.9.5-vs2.3.6.5/include/linux/mm_types.h
7852 --- linux-3.9.5/include/linux/mm_types.h        2013-05-31 13:45:28.000000000 +0000
7853 +++ linux-3.9.5-vs2.3.6.5/include/linux/mm_types.h      2013-05-31 14:47:11.000000000 +0000
7854 @@ -380,6 +380,7 @@ struct mm_struct {
7855  
7856         /* Architecture-specific MM context */
7857         mm_context_t context;
7858 +       struct vx_info *mm_vx_info;
7859  
7860         unsigned long flags; /* Must use atomic bitops to access the bits */
7861  
7862 diff -NurpP --minimal linux-3.9.5/include/linux/mount.h linux-3.9.5-vs2.3.6.5/include/linux/mount.h
7863 --- linux-3.9.5/include/linux/mount.h   2013-05-31 13:45:28.000000000 +0000
7864 +++ linux-3.9.5-vs2.3.6.5/include/linux/mount.h 2013-05-31 14:47:11.000000000 +0000
7865 @@ -49,6 +49,9 @@ struct mnt_namespace;
7866  
7867  #define MNT_LOCK_READONLY      0x400000
7868  
7869 +#define MNT_TAGID      0x10000
7870 +#define MNT_NOTAG      0x20000
7871 +
7872  struct vfsmount {
7873         struct dentry *mnt_root;        /* root of the mounted tree */
7874         struct super_block *mnt_sb;     /* pointer to superblock */
7875 diff -NurpP --minimal linux-3.9.5/include/linux/net.h linux-3.9.5-vs2.3.6.5/include/linux/net.h
7876 --- linux-3.9.5/include/linux/net.h     2012-12-11 03:30:57.000000000 +0000
7877 +++ linux-3.9.5-vs2.3.6.5/include/linux/net.h   2013-05-31 14:47:11.000000000 +0000
7878 @@ -38,6 +38,7 @@ struct net;
7879  #define SOCK_PASSCRED          3
7880  #define SOCK_PASSSEC           4
7881  #define SOCK_EXTERNALLY_ALLOCATED 5
7882 +#define SOCK_USER_SOCKET       6
7883  
7884  #ifndef ARCH_HAS_SOCKET_TYPES
7885  /**
7886 diff -NurpP --minimal linux-3.9.5/include/linux/netdevice.h linux-3.9.5-vs2.3.6.5/include/linux/netdevice.h
7887 --- linux-3.9.5/include/linux/netdevice.h       2013-05-31 13:45:28.000000000 +0000
7888 +++ linux-3.9.5-vs2.3.6.5/include/linux/netdevice.h     2013-05-31 14:47:11.000000000 +0000
7889 @@ -1688,6 +1688,7 @@ extern void               netdev_resync_ops(struct ne
7890  
7891  extern struct net_device       *dev_get_by_index(struct net *net, int ifindex);
7892  extern struct net_device       *__dev_get_by_index(struct net *net, int ifindex);
7893 +extern struct net_device       *dev_get_by_index_real_rcu(struct net *net, int ifindex);
7894  extern struct net_device       *dev_get_by_index_rcu(struct net *net, int ifindex);
7895  extern int             dev_restart(struct net_device *dev);
7896  #ifdef CONFIG_NETPOLL_TRAP
7897 diff -NurpP --minimal linux-3.9.5/include/linux/nsproxy.h linux-3.9.5-vs2.3.6.5/include/linux/nsproxy.h
7898 --- linux-3.9.5/include/linux/nsproxy.h 2013-02-19 13:58:51.000000000 +0000
7899 +++ linux-3.9.5-vs2.3.6.5/include/linux/nsproxy.h       2013-05-31 17:17:53.000000000 +0000
7900 @@ -3,6 +3,7 @@
7901  
7902  #include <linux/spinlock.h>
7903  #include <linux/sched.h>
7904 +#include <linux/vserver/debug.h>
7905  
7906  struct mnt_namespace;
7907  struct uts_namespace;
7908 @@ -63,6 +64,7 @@ static inline struct nsproxy *task_nspro
7909  }
7910  
7911  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
7912 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
7913  void exit_task_namespaces(struct task_struct *tsk);
7914  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
7915  void free_nsproxy(struct nsproxy *ns);
7916 @@ -70,16 +72,26 @@ int unshare_nsproxy_namespaces(unsigned
7917         struct cred *, struct fs_struct *);
7918  int __init nsproxy_cache_init(void);
7919  
7920 -static inline void put_nsproxy(struct nsproxy *ns)
7921 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
7922 +
7923 +static inline void __get_nsproxy(struct nsproxy *ns,
7924 +       const char *_file, int _line)
7925  {
7926 -       if (atomic_dec_and_test(&ns->count)) {
7927 -               free_nsproxy(ns);
7928 -       }
7929 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
7930 +               ns, atomic_read(&ns->count), _file, _line);
7931 +       atomic_inc(&ns->count);
7932  }
7933  
7934 -static inline void get_nsproxy(struct nsproxy *ns)
7935 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
7936 +
7937 +static inline void __put_nsproxy(struct nsproxy *ns,
7938 +       const char *_file, int _line)
7939  {
7940 -       atomic_inc(&ns->count);
7941 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
7942 +               ns, atomic_read(&ns->count), _file, _line);
7943 +       if (atomic_dec_and_test(&ns->count)) {
7944 +               free_nsproxy(ns);
7945 +       }
7946  }
7947  
7948  #endif
7949 diff -NurpP --minimal linux-3.9.5/include/linux/pid.h linux-3.9.5-vs2.3.6.5/include/linux/pid.h
7950 --- linux-3.9.5/include/linux/pid.h     2013-05-31 13:45:28.000000000 +0000
7951 +++ linux-3.9.5-vs2.3.6.5/include/linux/pid.h   2013-05-31 14:47:11.000000000 +0000
7952 @@ -8,7 +8,8 @@ enum pid_type
7953         PIDTYPE_PID,
7954         PIDTYPE_PGID,
7955         PIDTYPE_SID,
7956 -       PIDTYPE_MAX
7957 +       PIDTYPE_MAX,
7958 +       PIDTYPE_REALPID
7959  };
7960  
7961  /*
7962 @@ -172,6 +173,7 @@ static inline pid_t pid_nr(struct pid *p
7963  }
7964  
7965  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
7966 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
7967  pid_t pid_vnr(struct pid *pid);
7968  
7969  #define do_each_pid_task(pid, type, task)                              \
7970 diff -NurpP --minimal linux-3.9.5/include/linux/proc_fs.h linux-3.9.5-vs2.3.6.5/include/linux/proc_fs.h
7971 --- linux-3.9.5/include/linux/proc_fs.h 2013-05-31 13:45:28.000000000 +0000
7972 +++ linux-3.9.5-vs2.3.6.5/include/linux/proc_fs.h       2013-05-31 14:47:11.000000000 +0000
7973 @@ -58,6 +58,7 @@ struct proc_dir_entry {
7974         nlink_t nlink;
7975         kuid_t uid;
7976         kgid_t gid;
7977 +       int vx_flags;
7978         loff_t size;
7979         const struct inode_operations *proc_iops;
7980         /*
7981 @@ -274,12 +275,18 @@ extern const struct proc_ns_operations p
7982  extern const struct proc_ns_operations userns_operations;
7983  extern const struct proc_ns_operations mntns_operations;
7984  
7985 +struct vx_info;
7986 +struct nx_info;
7987 +
7988  union proc_op {
7989         int (*proc_get_link)(struct dentry *, struct path *);
7990         int (*proc_read)(struct task_struct *task, char *page);
7991         int (*proc_show)(struct seq_file *m,
7992                 struct pid_namespace *ns, struct pid *pid,
7993                 struct task_struct *task);
7994 +       int (*proc_vs_read)(char *page);
7995 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
7996 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
7997  };
7998  
7999  struct ctl_table_header;
8000 @@ -287,6 +294,7 @@ struct ctl_table;
8001  
8002  struct proc_inode {
8003         struct pid *pid;
8004 +       int vx_flags;
8005         int fd;
8006         union proc_op op;
8007         struct proc_dir_entry *pde;
8008 diff -NurpP --minimal linux-3.9.5/include/linux/quotaops.h linux-3.9.5-vs2.3.6.5/include/linux/quotaops.h
8009 --- linux-3.9.5/include/linux/quotaops.h        2012-12-11 03:30:57.000000000 +0000
8010 +++ linux-3.9.5-vs2.3.6.5/include/linux/quotaops.h      2013-05-31 14:47:11.000000000 +0000
8011 @@ -8,6 +8,7 @@
8012  #define _LINUX_QUOTAOPS_
8013  
8014  #include <linux/fs.h>
8015 +#include <linux/vs_dlimit.h>
8016  
8017  #define DQUOT_SPACE_WARN       0x1
8018  #define DQUOT_SPACE_RESERVE    0x2
8019 @@ -205,11 +206,12 @@ static inline void dquot_drop(struct ino
8020  
8021  static inline int dquot_alloc_inode(const struct inode *inode)
8022  {
8023 -       return 0;
8024 +       return dl_alloc_inode(inode);
8025  }
8026  
8027  static inline void dquot_free_inode(const struct inode *inode)
8028  {
8029 +       dl_free_inode(inode);
8030  }
8031  
8032  static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
8033 @@ -220,6 +222,10 @@ static inline int dquot_transfer(struct
8034  static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
8035                 int flags)
8036  {
8037 +       int ret = 0;
8038 +
8039 +       if ((ret = dl_alloc_space(inode, number)))
8040 +               return ret;
8041         if (!(flags & DQUOT_SPACE_RESERVE))
8042                 inode_add_bytes(inode, number);
8043         return 0;
8044 @@ -230,6 +236,7 @@ static inline void __dquot_free_space(st
8045  {
8046         if (!(flags & DQUOT_SPACE_RESERVE))
8047                 inode_sub_bytes(inode, number);
8048 +       dl_free_space(inode, number);
8049  }
8050  
8051  static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
8052 diff -NurpP --minimal linux-3.9.5/include/linux/sched.h linux-3.9.5-vs2.3.6.5/include/linux/sched.h
8053 --- linux-3.9.5/include/linux/sched.h   2013-06-11 12:22:40.000000000 +0000
8054 +++ linux-3.9.5-vs2.3.6.5/include/linux/sched.h 2013-06-12 23:49:08.000000000 +0000
8055 @@ -1398,6 +1398,14 @@ struct task_struct {
8056  #endif
8057         struct seccomp seccomp;
8058  
8059 +/* vserver context data */
8060 +       struct vx_info *vx_info;
8061 +       struct nx_info *nx_info;
8062 +
8063 +       vxid_t xid;
8064 +       vnid_t nid;
8065 +       vtag_t tag;
8066 +
8067  /* Thread group tracking */
8068         u32 parent_exec_id;
8069         u32 self_exec_id;
8070 @@ -1637,6 +1645,11 @@ struct pid_namespace;
8071  pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
8072                         struct pid_namespace *ns);
8073  
8074 +#include <linux/vserver/base.h>
8075 +#include <linux/vserver/context.h>
8076 +#include <linux/vserver/debug.h>
8077 +#include <linux/vserver/pid.h>
8078 +
8079  static inline pid_t task_pid_nr(struct task_struct *tsk)
8080  {
8081         return tsk->pid;
8082 @@ -1650,7 +1663,8 @@ static inline pid_t task_pid_nr_ns(struc
8083  
8084  static inline pid_t task_pid_vnr(struct task_struct *tsk)
8085  {
8086 -       return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
8087 +       // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
8088 +       return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
8089  }
8090  
8091  
8092 @@ -1663,7 +1677,7 @@ pid_t task_tgid_nr_ns(struct task_struct
8093  
8094  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
8095  {
8096 -       return pid_vnr(task_tgid(tsk));
8097 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
8098  }
8099  
8100  
8101 diff -NurpP --minimal linux-3.9.5/include/linux/shmem_fs.h linux-3.9.5-vs2.3.6.5/include/linux/shmem_fs.h
8102 --- linux-3.9.5/include/linux/shmem_fs.h        2012-12-11 03:30:57.000000000 +0000
8103 +++ linux-3.9.5-vs2.3.6.5/include/linux/shmem_fs.h      2013-05-31 14:47:11.000000000 +0000
8104 @@ -9,6 +9,9 @@
8105  
8106  /* inode in-kernel data */
8107  
8108 +#define TMPFS_SUPER_MAGIC      0x01021994
8109 +
8110 +
8111  struct shmem_inode_info {
8112         spinlock_t              lock;
8113         unsigned long           flags;
8114 diff -NurpP --minimal linux-3.9.5/include/linux/stat.h linux-3.9.5-vs2.3.6.5/include/linux/stat.h
8115 --- linux-3.9.5/include/linux/stat.h    2012-12-11 03:30:57.000000000 +0000
8116 +++ linux-3.9.5-vs2.3.6.5/include/linux/stat.h  2013-06-01 08:53:13.000000000 +0000
8117 @@ -25,6 +25,7 @@ struct kstat {
8118         unsigned int    nlink;
8119         kuid_t          uid;
8120         kgid_t          gid;
8121 +       ktag_t          tag;
8122         dev_t           rdev;
8123         loff_t          size;
8124         struct timespec  atime;
8125 diff -NurpP --minimal linux-3.9.5/include/linux/sunrpc/auth.h linux-3.9.5-vs2.3.6.5/include/linux/sunrpc/auth.h
8126 --- linux-3.9.5/include/linux/sunrpc/auth.h     2013-05-31 13:45:28.000000000 +0000
8127 +++ linux-3.9.5-vs2.3.6.5/include/linux/sunrpc/auth.h   2013-05-31 14:52:57.000000000 +0000
8128 @@ -26,6 +26,7 @@
8129  struct auth_cred {
8130         kuid_t  uid;
8131         kgid_t  gid;
8132 +       ktag_t  tag;
8133         struct group_info *group_info;
8134         const char *principal;
8135         unsigned char machine_cred : 1;
8136 diff -NurpP --minimal linux-3.9.5/include/linux/sunrpc/clnt.h linux-3.9.5-vs2.3.6.5/include/linux/sunrpc/clnt.h
8137 --- linux-3.9.5/include/linux/sunrpc/clnt.h     2013-05-31 13:45:28.000000000 +0000
8138 +++ linux-3.9.5-vs2.3.6.5/include/linux/sunrpc/clnt.h   2013-05-31 14:47:11.000000000 +0000
8139 @@ -49,7 +49,8 @@ struct rpc_clnt {
8140         unsigned int            cl_softrtry : 1,/* soft timeouts */
8141                                 cl_discrtry : 1,/* disconnect before retry */
8142                                 cl_autobind : 1,/* use getport() */
8143 -                               cl_chatty   : 1;/* be verbose */
8144 +                               cl_chatty   : 1,/* be verbose */
8145 +                               cl_tag      : 1;/* context tagging */
8146  
8147         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
8148         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
8149 diff -NurpP --minimal linux-3.9.5/include/linux/sysfs.h linux-3.9.5-vs2.3.6.5/include/linux/sysfs.h
8150 --- linux-3.9.5/include/linux/sysfs.h   2013-05-31 13:45:28.000000000 +0000
8151 +++ linux-3.9.5-vs2.3.6.5/include/linux/sysfs.h 2013-05-31 14:47:11.000000000 +0000
8152 @@ -19,6 +19,8 @@
8153  #include <linux/kobject_ns.h>
8154  #include <linux/atomic.h>
8155  
8156 +#define SYSFS_SUPER_MAGIC      0x62656572
8157 +
8158  struct kobject;
8159  struct module;
8160  enum kobj_ns_type;
8161 diff -NurpP --minimal linux-3.9.5/include/linux/types.h linux-3.9.5-vs2.3.6.5/include/linux/types.h
8162 --- linux-3.9.5/include/linux/types.h   2013-02-19 13:58:52.000000000 +0000
8163 +++ linux-3.9.5-vs2.3.6.5/include/linux/types.h 2013-06-12 23:49:08.000000000 +0000
8164 @@ -32,6 +32,9 @@ typedef __kernel_uid32_t      uid_t;
8165  typedef __kernel_gid32_t       gid_t;
8166  typedef __kernel_uid16_t        uid16_t;
8167  typedef __kernel_gid16_t        gid16_t;
8168 +typedef unsigned int           vxid_t;
8169 +typedef unsigned int           vnid_t;
8170 +typedef unsigned int           vtag_t;
8171  
8172  typedef unsigned long          uintptr_t;
8173  
8174 diff -NurpP --minimal linux-3.9.5/include/linux/uidgid.h linux-3.9.5-vs2.3.6.5/include/linux/uidgid.h
8175 --- linux-3.9.5/include/linux/uidgid.h  2012-12-11 03:30:57.000000000 +0000
8176 +++ linux-3.9.5-vs2.3.6.5/include/linux/uidgid.h        2013-06-12 23:49:08.000000000 +0000
8177 @@ -23,13 +23,17 @@ typedef struct {
8178         uid_t val;
8179  } kuid_t;
8180  
8181 -
8182  typedef struct {
8183         gid_t val;
8184  } kgid_t;
8185  
8186 +typedef struct {
8187 +       vtag_t val;
8188 +} ktag_t;
8189 +
8190  #define KUIDT_INIT(value) (kuid_t){ value }
8191  #define KGIDT_INIT(value) (kgid_t){ value }
8192 +#define KTAGT_INIT(value) (ktag_t){ value }
8193  
8194  static inline uid_t __kuid_val(kuid_t uid)
8195  {
8196 @@ -41,10 +45,16 @@ static inline gid_t __kgid_val(kgid_t gi
8197         return gid.val;
8198  }
8199  
8200 +static inline vtag_t __ktag_val(ktag_t tag)
8201 +{
8202 +       return tag.val;
8203 +}
8204 +
8205  #else
8206  
8207  typedef uid_t kuid_t;
8208  typedef gid_t kgid_t;
8209 +typedef vtag_t ktag_t;
8210  
8211  static inline uid_t __kuid_val(kuid_t uid)
8212  {
8213 @@ -56,16 +66,24 @@ static inline gid_t __kgid_val(kgid_t gi
8214         return gid;
8215  }
8216  
8217 +static inline vtag_t __ktag_val(ktag_t tag)
8218 +{
8219 +       return tag;
8220 +}
8221 +
8222  #define KUIDT_INIT(value) ((kuid_t) value )
8223  #define KGIDT_INIT(value) ((kgid_t) value )
8224 +#define KTAGT_INIT(value) ((ktag_t) value )
8225  
8226  #endif
8227  
8228  #define GLOBAL_ROOT_UID KUIDT_INIT(0)
8229  #define GLOBAL_ROOT_GID KGIDT_INIT(0)
8230 +#define GLOBAL_ROOT_TAG KTAGT_INIT(0)
8231  
8232  #define INVALID_UID KUIDT_INIT(-1)
8233  #define INVALID_GID KGIDT_INIT(-1)
8234 +#define INVALID_TAG KTAGT_INIT(-1)
8235  
8236  static inline bool uid_eq(kuid_t left, kuid_t right)
8237  {
8238 @@ -77,6 +95,11 @@ static inline bool gid_eq(kgid_t left, k
8239         return __kgid_val(left) == __kgid_val(right);
8240  }
8241  
8242 +static inline bool tag_eq(ktag_t left, ktag_t right)
8243 +{
8244 +       return __ktag_val(left) == __ktag_val(right);
8245 +}
8246 +
8247  static inline bool uid_gt(kuid_t left, kuid_t right)
8248  {
8249         return __kuid_val(left) > __kuid_val(right);
8250 @@ -127,13 +150,21 @@ static inline bool gid_valid(kgid_t gid)
8251         return !gid_eq(gid, INVALID_GID);
8252  }
8253  
8254 +static inline bool tag_valid(ktag_t tag)
8255 +{
8256 +       return !tag_eq(tag, INVALID_TAG);
8257 +}
8258 +
8259  #ifdef CONFIG_USER_NS
8260  
8261  extern kuid_t make_kuid(struct user_namespace *from, uid_t uid);
8262  extern kgid_t make_kgid(struct user_namespace *from, gid_t gid);
8263 +extern krag_t make_ktag(struct user_namespace *from, gid_t gid);
8264  
8265  extern uid_t from_kuid(struct user_namespace *to, kuid_t uid);
8266  extern gid_t from_kgid(struct user_namespace *to, kgid_t gid);
8267 +extern vtag_t from_ktag(struct user_namespace *to, ktag_t tag);
8268 +
8269  extern uid_t from_kuid_munged(struct user_namespace *to, kuid_t uid);
8270  extern gid_t from_kgid_munged(struct user_namespace *to, kgid_t gid);
8271  
8272 @@ -159,6 +190,11 @@ static inline kgid_t make_kgid(struct us
8273         return KGIDT_INIT(gid);
8274  }
8275  
8276 +static inline ktag_t make_ktag(struct user_namespace *from, vtag_t tag)
8277 +{
8278 +       return KTAGT_INIT(tag);
8279 +}
8280 +
8281  static inline uid_t from_kuid(struct user_namespace *to, kuid_t kuid)
8282  {
8283         return __kuid_val(kuid);
8284 @@ -169,6 +205,11 @@ static inline gid_t from_kgid(struct use
8285         return __kgid_val(kgid);
8286  }
8287  
8288 +static inline vtag_t from_ktag(struct user_namespace *to, ktag_t ktag)
8289 +{
8290 +       return __ktag_val(ktag);
8291 +}
8292 +
8293  static inline uid_t from_kuid_munged(struct user_namespace *to, kuid_t kuid)
8294  {
8295         uid_t uid = from_kuid(to, kuid);
8296 diff -NurpP --minimal linux-3.9.5/include/linux/vroot.h linux-3.9.5-vs2.3.6.5/include/linux/vroot.h
8297 --- linux-3.9.5/include/linux/vroot.h   1970-01-01 00:00:00.000000000 +0000
8298 +++ linux-3.9.5-vs2.3.6.5/include/linux/vroot.h 2013-05-31 14:47:11.000000000 +0000
8299 @@ -0,0 +1,51 @@
8300 +
8301 +/*
8302 + * include/linux/vroot.h
8303 + *
8304 + * written by Herbert Pötzl, 9/11/2002
8305 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
8306 + *
8307 + * Copyright (C) 2002-2007 by Herbert Pötzl.
8308 + * Redistribution of this file is permitted under the
8309 + * GNU General Public License.
8310 + */
8311 +
8312 +#ifndef _LINUX_VROOT_H
8313 +#define _LINUX_VROOT_H
8314 +
8315 +
8316 +#ifdef __KERNEL__
8317 +
8318 +/* Possible states of device */
8319 +enum {
8320 +       Vr_unbound,
8321 +       Vr_bound,
8322 +};
8323 +
8324 +struct vroot_device {
8325 +       int             vr_number;
8326 +       int             vr_refcnt;
8327 +
8328 +       struct semaphore        vr_ctl_mutex;
8329 +       struct block_device    *vr_device;
8330 +       int                     vr_state;
8331 +};
8332 +
8333 +
8334 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
8335 +
8336 +extern int register_vroot_grb(vroot_grb_func *);
8337 +extern int unregister_vroot_grb(vroot_grb_func *);
8338 +
8339 +#endif /* __KERNEL__ */
8340 +
8341 +#define MAX_VROOT_DEFAULT      8
8342 +
8343 +/*
8344 + * IOCTL commands --- we will commandeer 0x56 ('V')
8345 + */
8346 +
8347 +#define VROOT_SET_DEV          0x5600
8348 +#define VROOT_CLR_DEV          0x5601
8349 +
8350 +#endif /* _LINUX_VROOT_H */
8351 diff -NurpP --minimal linux-3.9.5/include/linux/vs_base.h linux-3.9.5-vs2.3.6.5/include/linux/vs_base.h
8352 --- linux-3.9.5/include/linux/vs_base.h 1970-01-01 00:00:00.000000000 +0000
8353 +++ linux-3.9.5-vs2.3.6.5/include/linux/vs_base.h       2013-05-31 14:47:11.000000000 +0000
8354 @@ -0,0 +1,10 @@
8355 +#ifndef _VS_BASE_H
8356 +#define _VS_BASE_H
8357 +
8358 +#include "vserver/base.h"
8359 +#include "vserver/check.h"
8360 +#include "vserver/debug.h"
8361 +
8362 +#else
8363 +#warning duplicate inclusion
8364 +#endif
8365 diff -NurpP --minimal linux-3.9.5/include/linux/vs_context.h linux-3.9.5-vs2.3.6.5/include/linux/vs_context.h
8366 --- linux-3.9.5/include/linux/vs_context.h      1970-01-01 00:00:00.000000000 +0000
8367 +++ linux-3.9.5-vs2.3.6.5/include/linux/vs_context.h    2013-06-12 23:49:08.000000000 +0000
8368 @@ -0,0 +1,242 @@
8369 +#ifndef _VS_CONTEXT_H
8370 +#define _VS_CONTEXT_H
8371 +
8372 +#include "vserver/base.h"
8373 +#include "vserver/check.h"
8374 +#include "vserver/context.h"
8375 +#include "vserver/history.h"
8376 +#include "vserver/debug.h"
8377 +
8378 +#include <linux/sched.h>
8379 +
8380 +
8381 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
8382 +
8383 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
8384 +       const char *_file, int _line, void *_here)
8385 +{
8386 +       if (!vxi)
8387 +               return NULL;
8388 +
8389 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
8390 +               vxi, vxi ? vxi->vx_id : 0,
8391 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8392 +               _file, _line);
8393 +       __vxh_get_vx_info(vxi, _here);
8394 +
8395 +       atomic_inc(&vxi->vx_usecnt);
8396 +       return vxi;
8397 +}
8398 +
8399 +
8400 +extern void free_vx_info(struct vx_info *);
8401 +
8402 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
8403 +
8404 +static inline void __put_vx_info(struct vx_info *vxi,
8405 +       const char *_file, int _line, void *_here)
8406 +{
8407 +       if (!vxi)
8408 +               return;
8409 +
8410 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
8411 +               vxi, vxi ? vxi->vx_id : 0,
8412 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8413 +               _file, _line);
8414 +       __vxh_put_vx_info(vxi, _here);
8415 +
8416 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
8417 +               free_vx_info(vxi);
8418 +}
8419 +
8420 +
8421 +#define init_vx_info(p, i) \
8422 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
8423 +
8424 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
8425 +       const char *_file, int _line, void *_here)
8426 +{
8427 +       if (vxi) {
8428 +               vxlprintk(VXD_CBIT(xid, 3),
8429 +                       "init_vx_info(%p[#%d.%d])",
8430 +                       vxi, vxi ? vxi->vx_id : 0,
8431 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8432 +                       _file, _line);
8433 +               __vxh_init_vx_info(vxi, vxp, _here);
8434 +
8435 +               atomic_inc(&vxi->vx_usecnt);
8436 +       }
8437 +       *vxp = vxi;
8438 +}
8439 +
8440 +
8441 +#define set_vx_info(p, i) \
8442 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
8443 +
8444 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
8445 +       const char *_file, int _line, void *_here)
8446 +{
8447 +       struct vx_info *vxo;
8448 +
8449 +       if (!vxi)
8450 +               return;
8451 +
8452 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
8453 +               vxi, vxi ? vxi->vx_id : 0,
8454 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8455 +               _file, _line);
8456 +       __vxh_set_vx_info(vxi, vxp, _here);
8457 +
8458 +       atomic_inc(&vxi->vx_usecnt);
8459 +       vxo = xchg(vxp, vxi);
8460 +       BUG_ON(vxo);
8461 +}
8462 +
8463 +
8464 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
8465 +
8466 +static inline void __clr_vx_info(struct vx_info **vxp,
8467 +       const char *_file, int _line, void *_here)
8468 +{
8469 +       struct vx_info *vxo;
8470 +
8471 +       vxo = xchg(vxp, NULL);
8472 +       if (!vxo)
8473 +               return;
8474 +
8475 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
8476 +               vxo, vxo ? vxo->vx_id : 0,
8477 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
8478 +               _file, _line);
8479 +       __vxh_clr_vx_info(vxo, vxp, _here);
8480 +
8481 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
8482 +               free_vx_info(vxo);
8483 +}
8484 +
8485 +
8486 +#define claim_vx_info(v, p) \
8487 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
8488 +
8489 +static inline void __claim_vx_info(struct vx_info *vxi,
8490 +       struct task_struct *task,
8491 +       const char *_file, int _line, void *_here)
8492 +{
8493 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
8494 +               vxi, vxi ? vxi->vx_id : 0,
8495 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8496 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
8497 +               task, _file, _line);
8498 +       __vxh_claim_vx_info(vxi, task, _here);
8499 +
8500 +       atomic_inc(&vxi->vx_tasks);
8501 +}
8502 +
8503 +
8504 +extern void unhash_vx_info(struct vx_info *);
8505 +
8506 +#define release_vx_info(v, p) \
8507 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
8508 +
8509 +static inline void __release_vx_info(struct vx_info *vxi,
8510 +       struct task_struct *task,
8511 +       const char *_file, int _line, void *_here)
8512 +{
8513 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
8514 +               vxi, vxi ? vxi->vx_id : 0,
8515 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8516 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
8517 +               task, _file, _line);
8518 +       __vxh_release_vx_info(vxi, task, _here);
8519 +
8520 +       might_sleep();
8521 +
8522 +       if (atomic_dec_and_test(&vxi->vx_tasks))
8523 +               unhash_vx_info(vxi);
8524 +}
8525 +
8526 +
8527 +#define task_get_vx_info(p) \
8528 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
8529 +
8530 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
8531 +       const char *_file, int _line, void *_here)
8532 +{
8533 +       struct vx_info *vxi;
8534 +
8535 +       task_lock(p);
8536 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
8537 +               p, _file, _line);
8538 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
8539 +       task_unlock(p);
8540 +       return vxi;
8541 +}
8542 +
8543 +
8544 +static inline void __wakeup_vx_info(struct vx_info *vxi)
8545 +{
8546 +       if (waitqueue_active(&vxi->vx_wait))
8547 +               wake_up_interruptible(&vxi->vx_wait);
8548 +}
8549 +
8550 +
8551 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
8552 +
8553 +static inline void __enter_vx_info(struct vx_info *vxi,
8554 +       struct vx_info_save *vxis, const char *_file, int _line)
8555 +{
8556 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
8557 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
8558 +               current->xid, current->vx_info, _file, _line);
8559 +       vxis->vxi = xchg(&current->vx_info, vxi);
8560 +       vxis->xid = current->xid;
8561 +       current->xid = vxi ? vxi->vx_id : 0;
8562 +}
8563 +
8564 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
8565 +
8566 +static inline void __leave_vx_info(struct vx_info_save *vxis,
8567 +       const char *_file, int _line)
8568 +{
8569 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
8570 +               vxis, vxis->xid, vxis->vxi, current,
8571 +               current->xid, current->vx_info, _file, _line);
8572 +       (void)xchg(&current->vx_info, vxis->vxi);
8573 +       current->xid = vxis->xid;
8574 +}
8575 +
8576 +
8577 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
8578 +{
8579 +       vxis->vxi = xchg(&current->vx_info, NULL);
8580 +       vxis->xid = xchg(&current->xid, (vxid_t)0);
8581 +}
8582 +
8583 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
8584 +{
8585 +       (void)xchg(&current->xid, vxis->xid);
8586 +       (void)xchg(&current->vx_info, vxis->vxi);
8587 +}
8588 +
8589 +#define task_is_init(p) \
8590 +       __task_is_init(p, __FILE__, __LINE__, __HERE__)
8591 +
8592 +static inline int __task_is_init(struct task_struct *p,
8593 +       const char *_file, int _line, void *_here)
8594 +{
8595 +       int is_init = is_global_init(p);
8596 +
8597 +       task_lock(p);
8598 +       if (p->vx_info)
8599 +               is_init = p->vx_info->vx_initpid == p->pid;
8600 +       task_unlock(p);
8601 +       return is_init;
8602 +}
8603 +
8604 +extern void exit_vx_info(struct task_struct *, int);
8605 +extern void exit_vx_info_early(struct task_struct *, int);
8606 +
8607 +
8608 +#else
8609 +#warning duplicate inclusion
8610 +#endif
8611 diff -NurpP --minimal linux-3.9.5/include/linux/vs_cowbl.h linux-3.9.5-vs2.3.6.5/include/linux/vs_cowbl.h
8612 --- linux-3.9.5/include/linux/vs_cowbl.h        1970-01-01 00:00:00.000000000 +0000
8613 +++ linux-3.9.5-vs2.3.6.5/include/linux/vs_cowbl.h      2013-05-31 14:47:11.000000000 +0000
8614 @@ -0,0 +1,48 @@
8615 +#ifndef _VS_COWBL_H
8616 +#define _VS_COWBL_H
8617 +
8618 +#include <linux/fs.h>
8619 +#include <linux/dcache.h>
8620 +#include <linux/namei.h>
8621 +#include <linux/slab.h>
8622 +
8623 +extern struct dentry *cow_break_link(const char *pathname);
8624 +
8625 +static inline int cow_check_and_break(struct path *path)
8626 +{
8627 +       struct inode *inode = path->dentry->d_inode;
8628 +       int error = 0;
8629 +
8630 +       /* do we need this check? */
8631 +       if (IS_RDONLY(inode))
8632 +               return -EROFS;
8633 +
8634 +       if (IS_COW(inode)) {
8635 +               if (IS_COW_LINK(inode)) {
8636 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
8637 +                       char *pp, *buf;
8638 +
8639 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
8640 +                       if (!buf) {
8641 +                               return -ENOMEM;
8642 +                       }
8643 +                       pp = d_path(path, buf, PATH_MAX);
8644 +                       new_dentry = cow_break_link(pp);
8645 +                       kfree(buf);
8646 +                       if (!IS_ERR(new_dentry)) {
8647 +                               path->dentry = new_dentry;
8648 +                               dput(old_dentry);
8649 +                       } else
8650 +                               error = PTR_ERR(new_dentry);
8651 +               } else {
8652 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
8653 +                       inode->i_ctime = CURRENT_TIME;
8654 +                       mark_inode_dirty(inode);
8655 +               }
8656 +       }
8657 +       return error;
8658 +}
8659 +
8660 +#else
8661 +#warning duplicate inclusion
8662 +#endif
8663 diff -NurpP --minimal linux-3.9.5/include/linux/vs_cvirt.h linux-3.9.5-vs2.3.6.5/include/linux/vs_cvirt.h
8664 --- linux-3.9.5/include/linux/vs_cvirt.h        1970-01-01 00:00:00.000000000 +0000
8665 +++ linux-3.9.5-vs2.3.6.5/include/linux/vs_cvirt.h      2013-05-31 14:47:11.000000000 +0000
8666 @@ -0,0 +1,50 @@
8667 +#ifndef _VS_CVIRT_H
8668 +#define _VS_CVIRT_H
8669 +
8670 +#include "vserver/cvirt.h"
8671 +#include "vserver/context.h"
8672 +#include "vserver/base.h"
8673 +#include "vserver/check.h"
8674 +#include "vserver/debug.h"
8675 +
8676 +
8677 +static inline void vx_activate_task(struct task_struct *p)
8678 +{
8679 +       struct vx_info *vxi;
8680 +
8681 +       if ((vxi = p->vx_info)) {
8682 +               vx_update_load(vxi);
8683 +               atomic_inc(&vxi->cvirt.nr_running);
8684 +       }
8685 +}
8686 +
8687 +static inline void vx_deactivate_task(struct task_struct *p)
8688 +{
8689 +       struct vx_info *vxi;
8690 +
8691 +       if ((vxi = p->vx_info)) {
8692 +               vx_update_load(vxi);
8693 +               atomic_dec(&vxi->cvirt.nr_running);
8694 +       }
8695 +}
8696 +
8697 +static inline void vx_uninterruptible_inc(struct task_struct *p)
8698 +{
8699 +       struct vx_info *vxi;
8700 +
8701 +       if ((vxi = p->vx_info))
8702 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
8703 +}
8704 +
8705 +static inline void vx_uninterruptible_dec(struct task_struct *p)
8706 +{
8707 +       struct vx_info *vxi;
8708 +
8709 +       if ((vxi = p->vx_info))
8710 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
8711 +}
8712 +
8713 +
8714 +#else
8715 +#warning duplicate inclusion
8716 +#endif
8717 diff -NurpP --minimal linux-3.9.5/include/linux/vs_device.h linux-3.9.5-vs2.3.6.5/include/linux/vs_device.h
8718 --- linux-3.9.5/include/linux/vs_device.h       1970-01-01 00:00:00.000000000 +0000
8719 +++ linux-3.9.5-vs2.3.6.5/include/linux/vs_device.h     2013-05-31 14:47:11.000000000 +0000
8720 @@ -0,0 +1,45 @@
8721 +#ifndef _VS_DEVICE_H
8722 +#define _VS_DEVICE_H
8723 +
8724 +#include "vserver/base.h"
8725 +#include "vserver/device.h"
8726 +#include "vserver/debug.h"
8727 +
8728 +
8729 +#ifdef CONFIG_VSERVER_DEVICE
8730 +
8731 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
8732 +
8733 +#define vs_device_perm(v, d, m, p) \
8734 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
8735 +
8736 +#else
8737 +
8738 +static inline
8739 +int vs_map_device(struct vx_info *vxi,
8740 +       dev_t device, dev_t *target, umode_t mode)
8741 +{
8742 +       if (target)
8743 +               *target = device;
8744 +       return ~0;
8745 +}
8746 +
8747 +#define vs_device_perm(v, d, m, p) ((p) == (p))
8748 +
8749 +#endif
8750 +
8751 +
8752 +#define vs_map_chrdev(d, t, p) \
8753 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
8754 +#define vs_map_blkdev(d, t, p) \
8755 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
8756 +
8757 +#define vs_chrdev_perm(d, p) \
8758 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
8759 +#define vs_blkdev_perm(d, p) \
8760 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
8761 +
8762 +
8763 +#else
8764 +#warning duplicate inclusion
8765 +#endif
8766 diff -NurpP --minimal linux-3.9.5/include/linux/vs_dlimit.h linux-3.9.5-vs2.3.6.5/include/linux/vs_dlimit.h
8767 --- linux-3.9.5/include/linux/vs_dlimit.h       1970-01-01 00:00:00.000000000 +0000
8768 +++ linux-3.9.5-vs2.3.6.5/include/linux/vs_dlimit.h     2013-06-12 23:49:08.000000000 +0000
8769 @@ -0,0 +1,215 @@
8770 +#ifndef _VS_DLIMIT_H
8771 +#define _VS_DLIMIT_H
8772 +
8773 +#include <linux/fs.h>
8774 +
8775 +#include "vserver/dlimit.h"
8776 +#include "vserver/base.h"
8777 +#include "vserver/debug.h"
8778 +
8779 +
8780 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
8781 +
8782 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
8783 +       const char *_file, int _line)
8784 +{
8785 +       if (!dli)
8786 +               return NULL;
8787 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
8788 +               dli, dli ? dli->dl_tag : 0,
8789 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
8790 +               _file, _line);
8791 +       atomic_inc(&dli->dl_usecnt);
8792 +       return dli;
8793 +}
8794 +
8795 +
8796 +#define free_dl_info(i) \
8797 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
8798 +
8799 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
8800 +
8801 +static inline void __put_dl_info(struct dl_info *dli,
8802 +       const char *_file, int _line)
8803 +{
8804 +       if (!dli)
8805 +               return;
8806 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
8807 +               dli, dli ? dli->dl_tag : 0,
8808 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
8809 +               _file, _line);
8810 +       if (atomic_dec_and_test(&dli->dl_usecnt))
8811 +               free_dl_info(dli);
8812 +}
8813 +
8814 +
8815 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
8816 +
8817 +static inline int __dl_alloc_space(struct super_block *sb,
8818 +       vtag_t tag, dlsize_t nr, const char *file, int line)
8819 +{
8820 +       struct dl_info *dli = NULL;
8821 +       int ret = 0;
8822 +
8823 +       if (nr == 0)
8824 +               goto out;
8825 +       dli = locate_dl_info(sb, tag);
8826 +       if (!dli)
8827 +               goto out;
8828 +
8829 +       spin_lock(&dli->dl_lock);
8830 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
8831 +       if (!ret)
8832 +               dli->dl_space_used += nr;
8833 +       spin_unlock(&dli->dl_lock);
8834 +       put_dl_info(dli);
8835 +out:
8836 +       vxlprintk(VXD_CBIT(dlim, 1),
8837 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
8838 +               sb, tag, __dlimit_char(dli), (long long)nr,
8839 +               ret, file, line);
8840 +       return ret ? -ENOSPC : 0;
8841 +}
8842 +
8843 +static inline void __dl_free_space(struct super_block *sb,
8844 +       vtag_t tag, dlsize_t nr, const char *_file, int _line)
8845 +{
8846 +       struct dl_info *dli = NULL;
8847 +
8848 +       if (nr == 0)
8849 +               goto out;
8850 +       dli = locate_dl_info(sb, tag);
8851 +       if (!dli)
8852 +               goto out;
8853 +
8854 +       spin_lock(&dli->dl_lock);
8855 +       if (dli->dl_space_used > nr)
8856 +               dli->dl_space_used -= nr;
8857 +       else
8858 +               dli->dl_space_used = 0;
8859 +       spin_unlock(&dli->dl_lock);
8860 +       put_dl_info(dli);
8861 +out:
8862 +       vxlprintk(VXD_CBIT(dlim, 1),
8863 +               "FREE  (%p,#%d)%c %lld bytes",
8864 +               sb, tag, __dlimit_char(dli), (long long)nr,
8865 +               _file, _line);
8866 +}
8867 +
8868 +static inline int __dl_alloc_inode(struct super_block *sb,
8869 +       vtag_t tag, const char *_file, int _line)
8870 +{
8871 +       struct dl_info *dli;
8872 +       int ret = 0;
8873 +
8874 +       dli = locate_dl_info(sb, tag);
8875 +       if (!dli)
8876 +               goto out;
8877 +
8878 +       spin_lock(&dli->dl_lock);
8879 +       dli->dl_inodes_used++;
8880 +       ret = (dli->dl_inodes_used > dli->dl_inodes_total);
8881 +       spin_unlock(&dli->dl_lock);
8882 +       put_dl_info(dli);
8883 +out:
8884 +       vxlprintk(VXD_CBIT(dlim, 0),
8885 +               "ALLOC (%p,#%d)%c inode (%d)",
8886 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
8887 +       return ret ? -ENOSPC : 0;
8888 +}
8889 +
8890 +static inline void __dl_free_inode(struct super_block *sb,
8891 +       vtag_t tag, const char *_file, int _line)
8892 +{
8893 +       struct dl_info *dli;
8894 +
8895 +       dli = locate_dl_info(sb, tag);
8896 +       if (!dli)
8897 +               goto out;
8898 +
8899 +       spin_lock(&dli->dl_lock);
8900 +       if (dli->dl_inodes_used > 1)
8901 +               dli->dl_inodes_used--;
8902 +       else
8903 +               dli->dl_inodes_used = 0;
8904 +       spin_unlock(&dli->dl_lock);
8905 +       put_dl_info(dli);
8906 +out:
8907 +       vxlprintk(VXD_CBIT(dlim, 0),
8908 +               "FREE  (%p,#%d)%c inode",
8909 +               sb, tag, __dlimit_char(dli), _file, _line);
8910 +}
8911 +
8912 +static inline void __dl_adjust_block(struct super_block *sb, vtag_t tag,
8913 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
8914 +       const char *_file, int _line)
8915 +{
8916 +       struct dl_info *dli;
8917 +       uint64_t broot, bfree;
8918 +
8919 +       dli = locate_dl_info(sb, tag);
8920 +       if (!dli)
8921 +               return;
8922 +
8923 +       spin_lock(&dli->dl_lock);
8924 +       broot = (dli->dl_space_total -
8925 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
8926 +               >> sb->s_blocksize_bits;
8927 +       bfree = (dli->dl_space_total - dli->dl_space_used)
8928 +                       >> sb->s_blocksize_bits;
8929 +       spin_unlock(&dli->dl_lock);
8930 +
8931 +       vxlprintk(VXD_CBIT(dlim, 2),
8932 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
8933 +               (long long)bfree, (long long)broot,
8934 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
8935 +               _file, _line);
8936 +       if (free_blocks) {
8937 +               if (*free_blocks > bfree)
8938 +                       *free_blocks = bfree;
8939 +       }
8940 +       if (root_blocks) {
8941 +               if (*root_blocks > broot)
8942 +                       *root_blocks = broot;
8943 +       }
8944 +       put_dl_info(dli);
8945 +}
8946 +
8947 +#define dl_prealloc_space(in, bytes) \
8948 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8949 +               __FILE__, __LINE__ )
8950 +
8951 +#define dl_alloc_space(in, bytes) \
8952 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8953 +               __FILE__, __LINE__ )
8954 +
8955 +#define dl_reserve_space(in, bytes) \
8956 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8957 +               __FILE__, __LINE__ )
8958 +
8959 +#define dl_claim_space(in, bytes) (0)
8960 +
8961 +#define dl_release_space(in, bytes) \
8962 +       __dl_free_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8963 +               __FILE__, __LINE__ )
8964 +
8965 +#define dl_free_space(in, bytes) \
8966 +       __dl_free_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8967 +               __FILE__, __LINE__ )
8968 +
8969 +
8970 +
8971 +#define dl_alloc_inode(in) \
8972 +       __dl_alloc_inode((in)->i_sb, i_tag_read(in), __FILE__, __LINE__ )
8973 +
8974 +#define dl_free_inode(in) \
8975 +       __dl_free_inode((in)->i_sb, i_tag_read(in), __FILE__, __LINE__ )
8976 +
8977 +
8978 +#define dl_adjust_block(sb, tag, fb, rb) \
8979 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
8980 +
8981 +
8982 +#else
8983 +#warning duplicate inclusion
8984 +#endif
8985 diff -NurpP --minimal linux-3.9.5/include/linux/vs_inet.h linux-3.9.5-vs2.3.6.5/include/linux/vs_inet.h
8986 --- linux-3.9.5/include/linux/vs_inet.h 1970-01-01 00:00:00.000000000 +0000
8987 +++ linux-3.9.5-vs2.3.6.5/include/linux/vs_inet.h       2013-05-31 14:47:11.000000000 +0000
8988 @@ -0,0 +1,364 @@
8989 +#ifndef _VS_INET_H
8990 +#define _VS_INET_H
8991 +
8992 +#include "vserver/base.h"
8993 +#include "vserver/network.h"
8994 +#include "vserver/debug.h"
8995 +
8996 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
8997 +
8998 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
8999 +                       NIPQUAD((a)->mask), (a)->type
9000 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
9001 +
9002 +#define NIPQUAD(addr) \
9003 +       ((unsigned char *)&addr)[0], \
9004 +       ((unsigned char *)&addr)[1], \
9005 +       ((unsigned char *)&addr)[2], \
9006 +       ((unsigned char *)&addr)[3]
9007 +
9008 +#define NIPQUAD_FMT "%u.%u.%u.%u"
9009 +
9010 +
9011 +static inline
9012 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
9013 +{
9014 +       __be32 ip = nxa->ip[0].s_addr;
9015 +       __be32 mask = nxa->mask.s_addr;
9016 +       __be32 bcast = ip | ~mask;
9017 +       int ret = 0;
9018 +
9019 +       switch (nxa->type & tmask) {
9020 +       case NXA_TYPE_MASK:
9021 +               ret = (ip == (addr & mask));
9022 +               break;
9023 +       case NXA_TYPE_ADDR:
9024 +               ret = 3;
9025 +               if (addr == ip)
9026 +                       break;
9027 +               /* fall through to broadcast */
9028 +       case NXA_MOD_BCAST:
9029 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
9030 +               break;
9031 +       case NXA_TYPE_RANGE:
9032 +               ret = ((nxa->ip[0].s_addr <= addr) &&
9033 +                       (nxa->ip[1].s_addr > addr));
9034 +               break;
9035 +       case NXA_TYPE_ANY:
9036 +               ret = 2;
9037 +               break;
9038 +       }
9039 +
9040 +       vxdprintk(VXD_CBIT(net, 0),
9041 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
9042 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
9043 +       return ret;
9044 +}
9045 +
9046 +static inline
9047 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
9048 +{
9049 +       struct nx_addr_v4 *nxa;
9050 +       unsigned long irqflags;
9051 +       int ret = 1;
9052 +
9053 +       if (!nxi)
9054 +               goto out;
9055 +
9056 +       ret = 2;
9057 +       /* allow 127.0.0.1 when remapping lback */
9058 +       if ((tmask & NXA_LOOPBACK) &&
9059 +               (addr == IPI_LOOPBACK) &&
9060 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9061 +               goto out;
9062 +       ret = 3;
9063 +       /* check for lback address */
9064 +       if ((tmask & NXA_MOD_LBACK) &&
9065 +               (nxi->v4_lback.s_addr == addr))
9066 +               goto out;
9067 +       ret = 4;
9068 +       /* check for broadcast address */
9069 +       if ((tmask & NXA_MOD_BCAST) &&
9070 +               (nxi->v4_bcast.s_addr == addr))
9071 +               goto out;
9072 +       ret = 5;
9073 +
9074 +       /* check for v4 addresses */
9075 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
9076 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
9077 +               if (v4_addr_match(nxa, addr, tmask))
9078 +                       goto out_unlock;
9079 +       ret = 0;
9080 +out_unlock:
9081 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
9082 +out:
9083 +       vxdprintk(VXD_CBIT(net, 0),
9084 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
9085 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
9086 +       return ret;
9087 +}
9088 +
9089 +static inline
9090 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
9091 +{
9092 +       /* FIXME: needs full range checks */
9093 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
9094 +}
9095 +
9096 +static inline
9097 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
9098 +{
9099 +       struct nx_addr_v4 *ptr;
9100 +       unsigned long irqflags;
9101 +       int ret = 1;
9102 +
9103 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
9104 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
9105 +               if (v4_nx_addr_match(ptr, nxa, mask))
9106 +                       goto out_unlock;
9107 +       ret = 0;
9108 +out_unlock:
9109 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
9110 +       return ret;
9111 +}
9112 +
9113 +#include <net/inet_sock.h>
9114 +
9115 +/*
9116 + *     Check if a given address matches for a socket
9117 + *
9118 + *     nxi:            the socket's nx_info if any
9119 + *     addr:           to be verified address
9120 + */
9121 +static inline
9122 +int v4_sock_addr_match (
9123 +       struct nx_info *nxi,
9124 +       struct inet_sock *inet,
9125 +       __be32 addr)
9126 +{
9127 +       __be32 saddr = inet->inet_rcv_saddr;
9128 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
9129 +
9130 +       if (addr && (saddr == addr || bcast == addr))
9131 +               return 1;
9132 +       if (!saddr)
9133 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
9134 +       return 0;
9135 +}
9136 +
9137 +
9138 +/* inet related checks and helpers */
9139 +
9140 +
9141 +struct in_ifaddr;
9142 +struct net_device;
9143 +struct sock;
9144 +
9145 +#ifdef CONFIG_INET
9146 +
9147 +#include <linux/netdevice.h>
9148 +#include <linux/inetdevice.h>
9149 +#include <net/inet_sock.h>
9150 +#include <net/inet_timewait_sock.h>
9151 +
9152 +
9153 +int dev_in_nx_info(struct net_device *, struct nx_info *);
9154 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
9155 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
9156 +
9157 +
9158 +/*
9159 + *     check if address is covered by socket
9160 + *
9161 + *     sk:     the socket to check against
9162 + *     addr:   the address in question (must be != 0)
9163 + */
9164 +
9165 +static inline
9166 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
9167 +{
9168 +       struct nx_info *nxi = sk->sk_nx_info;
9169 +       __be32 saddr = sk_rcv_saddr(sk);
9170 +
9171 +       vxdprintk(VXD_CBIT(net, 5),
9172 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
9173 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
9174 +               (sk->sk_socket?sk->sk_socket->flags:0));
9175 +
9176 +       if (saddr) {            /* direct address match */
9177 +               return v4_addr_match(nxa, saddr, -1);
9178 +       } else if (nxi) {       /* match against nx_info */
9179 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
9180 +       } else {                /* unrestricted any socket */
9181 +               return 1;
9182 +       }
9183 +}
9184 +
9185 +
9186 +
9187 +static inline
9188 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
9189 +{
9190 +       vxdprintk(VXD_CBIT(net, 1),
9191 +               "nx_dev_visible(%p[#%u],%p " VS_Q("%s") ") %d",
9192 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
9193 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
9194 +
9195 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9196 +               return 1;
9197 +       if (dev_in_nx_info(dev, nxi))
9198 +               return 1;
9199 +       return 0;
9200 +}
9201 +
9202 +
9203 +static inline
9204 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
9205 +{
9206 +       if (!nxi)
9207 +               return 1;
9208 +       if (!ifa)
9209 +               return 0;
9210 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
9211 +}
9212 +
9213 +static inline
9214 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
9215 +{
9216 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
9217 +               nxi, nxi ? nxi->nx_id : 0, ifa,
9218 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
9219 +
9220 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9221 +               return 1;
9222 +       if (v4_ifa_in_nx_info(ifa, nxi))
9223 +               return 1;
9224 +       return 0;
9225 +}
9226 +
9227 +
9228 +struct nx_v4_sock_addr {
9229 +       __be32 saddr;   /* Address used for validation */
9230 +       __be32 baddr;   /* Address used for socket bind */
9231 +};
9232 +
9233 +static inline
9234 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
9235 +       struct nx_v4_sock_addr *nsa)
9236 +{
9237 +       struct sock *sk = &inet->sk;
9238 +       struct nx_info *nxi = sk->sk_nx_info;
9239 +       __be32 saddr = addr->sin_addr.s_addr;
9240 +       __be32 baddr = saddr;
9241 +
9242 +       vxdprintk(VXD_CBIT(net, 3),
9243 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
9244 +               sk, sk->sk_nx_info, sk->sk_socket,
9245 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
9246 +               NIPQUAD(saddr));
9247 +
9248 +       if (nxi) {
9249 +               if (saddr == INADDR_ANY) {
9250 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
9251 +                               baddr = nxi->v4.ip[0].s_addr;
9252 +               } else if (saddr == IPI_LOOPBACK) {
9253 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9254 +                               baddr = nxi->v4_lback.s_addr;
9255 +               } else if (!ipv4_is_multicast(saddr) ||
9256 +                       !nx_info_ncaps(nxi, NXC_MULTICAST)) {
9257 +                       /* normal address bind */
9258 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
9259 +                               return -EADDRNOTAVAIL;
9260 +               }
9261 +       }
9262 +
9263 +       vxdprintk(VXD_CBIT(net, 3),
9264 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
9265 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
9266 +
9267 +       nsa->saddr = saddr;
9268 +       nsa->baddr = baddr;
9269 +       return 0;
9270 +}
9271 +
9272 +static inline
9273 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
9274 +{
9275 +       inet->inet_saddr = nsa->baddr;
9276 +       inet->inet_rcv_saddr = nsa->baddr;
9277 +}
9278 +
9279 +
9280 +/*
9281 + *      helper to simplify inet_lookup_listener
9282 + *
9283 + *      nxi:   the socket's nx_info if any
9284 + *      addr:  to be verified address
9285 + *      saddr: socket address
9286 + */
9287 +static inline int v4_inet_addr_match (
9288 +       struct nx_info *nxi,
9289 +       __be32 addr,
9290 +       __be32 saddr)
9291 +{
9292 +       if (addr && (saddr == addr))
9293 +               return 1;
9294 +       if (!saddr)
9295 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
9296 +       return 0;
9297 +}
9298 +
9299 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
9300 +{
9301 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
9302 +               (addr == nxi->v4_lback.s_addr))
9303 +               return IPI_LOOPBACK;
9304 +       return addr;
9305 +}
9306 +
9307 +static inline
9308 +int nx_info_has_v4(struct nx_info *nxi)
9309 +{
9310 +       if (!nxi)
9311 +               return 1;
9312 +       if (NX_IPV4(nxi))
9313 +               return 1;
9314 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9315 +               return 1;
9316 +       return 0;
9317 +}
9318 +
9319 +#else /* CONFIG_INET */
9320 +
9321 +static inline
9322 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
9323 +{
9324 +       return 1;
9325 +}
9326 +
9327 +static inline
9328 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
9329 +{
9330 +       return 1;
9331 +}
9332 +
9333 +static inline
9334 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
9335 +{
9336 +       return 1;
9337 +}
9338 +
9339 +static inline
9340 +int nx_info_has_v4(struct nx_info *nxi)
9341 +{
9342 +       return 0;
9343 +}
9344 +
9345 +#endif /* CONFIG_INET */
9346 +
9347 +#define current_nx_info_has_v4() \
9348 +       nx_info_has_v4(current_nx_info())
9349 +
9350 +#else
9351 +// #warning duplicate inclusion
9352 +#endif
9353 diff -NurpP --minimal linux-3.9.5/include/linux/vs_inet6.h linux-3.9.5-vs2.3.6.5/include/linux/vs_inet6.h
9354 --- linux-3.9.5/include/linux/vs_inet6.h        1970-01-01 00:00:00.000000000 +0000
9355 +++ linux-3.9.5-vs2.3.6.5/include/linux/vs_inet6.h      2013-05-31 14:47:11.000000000 +0000
9356 @@ -0,0 +1,257 @@
9357 +#ifndef _VS_INET6_H
9358 +#define _VS_INET6_H
9359 +
9360 +#include "vserver/base.h"
9361 +#include "vserver/network.h"
9362 +#include "vserver/debug.h"
9363 +
9364 +#include <net/ipv6.h>
9365 +
9366 +#define NXAV6(a)       &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
9367 +#define NXAV6_FMT      "[%pI6/%pI6/%d:%04x]"
9368 +
9369 +
9370 +#ifdef CONFIG_IPV6
9371 +
9372 +static inline
9373 +int v6_addr_match(struct nx_addr_v6 *nxa,
9374 +       const struct in6_addr *addr, uint16_t mask)
9375 +{
9376 +       int ret = 0;
9377 +
9378 +       switch (nxa->type & mask) {
9379 +       case NXA_TYPE_MASK:
9380 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
9381 +               break;
9382 +       case NXA_TYPE_ADDR:
9383 +               ret = ipv6_addr_equal(&nxa->ip, addr);
9384 +               break;
9385 +       case NXA_TYPE_ANY:
9386 +               ret = 1;
9387 +               break;
9388 +       }
9389 +       vxdprintk(VXD_CBIT(net, 0),
9390 +               "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
9391 +               nxa, NXAV6(nxa), addr, mask, ret);
9392 +       return ret;
9393 +}
9394 +
9395 +static inline
9396 +int v6_addr_in_nx_info(struct nx_info *nxi,
9397 +       const struct in6_addr *addr, uint16_t mask)
9398 +{
9399 +       struct nx_addr_v6 *nxa;
9400 +       unsigned long irqflags;
9401 +       int ret = 1;
9402 +
9403 +       if (!nxi)
9404 +               goto out;
9405 +
9406 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
9407 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
9408 +               if (v6_addr_match(nxa, addr, mask))
9409 +                       goto out_unlock;
9410 +       ret = 0;
9411 +out_unlock:
9412 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
9413 +out:
9414 +       vxdprintk(VXD_CBIT(net, 0),
9415 +               "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
9416 +               nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
9417 +       return ret;
9418 +}
9419 +
9420 +static inline
9421 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
9422 +{
9423 +       /* FIXME: needs full range checks */
9424 +       return v6_addr_match(nxa, &addr->ip, mask);
9425 +}
9426 +
9427 +static inline
9428 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
9429 +{
9430 +       struct nx_addr_v6 *ptr;
9431 +       unsigned long irqflags;
9432 +       int ret = 1;
9433 +
9434 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
9435 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
9436 +               if (v6_nx_addr_match(ptr, nxa, mask))
9437 +                       goto out_unlock;
9438 +       ret = 0;
9439 +out_unlock:
9440 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
9441 +       return ret;
9442 +}
9443 +
9444 +
9445 +/*
9446 + *     Check if a given address matches for a socket
9447 + *
9448 + *     nxi:            the socket's nx_info if any
9449 + *     addr:           to be verified address
9450 + */
9451 +static inline
9452 +int v6_sock_addr_match (
9453 +       struct nx_info *nxi,
9454 +       struct inet_sock *inet,
9455 +       struct in6_addr *addr)
9456 +{
9457 +       struct sock *sk = &inet->sk;
9458 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
9459 +
9460 +       if (!ipv6_addr_any(addr) &&
9461 +               ipv6_addr_equal(saddr, addr))
9462 +               return 1;
9463 +       if (ipv6_addr_any(saddr))
9464 +               return v6_addr_in_nx_info(nxi, addr, -1);
9465 +       return 0;
9466 +}
9467 +
9468 +/*
9469 + *     check if address is covered by socket
9470 + *
9471 + *     sk:     the socket to check against
9472 + *     addr:   the address in question (must be != 0)
9473 + */
9474 +
9475 +static inline
9476 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
9477 +{
9478 +       struct nx_info *nxi = sk->sk_nx_info;
9479 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
9480 +
9481 +       vxdprintk(VXD_CBIT(net, 5),
9482 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
9483 +               sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
9484 +               (sk->sk_socket?sk->sk_socket->flags:0));
9485 +
9486 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
9487 +               return v6_addr_match(nxa, saddr, -1);
9488 +       } else if (nxi) {               /* match against nx_info */
9489 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
9490 +       } else {                        /* unrestricted any socket */
9491 +               return 1;
9492 +       }
9493 +}
9494 +
9495 +
9496 +/* inet related checks and helpers */
9497 +
9498 +
9499 +struct in_ifaddr;
9500 +struct net_device;
9501 +struct sock;
9502 +
9503 +
9504 +#include <linux/netdevice.h>
9505 +#include <linux/inetdevice.h>
9506 +#include <net/inet_timewait_sock.h>
9507 +
9508 +
9509 +int dev_in_nx_info(struct net_device *, struct nx_info *);
9510 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
9511 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
9512 +
9513 +
9514 +
9515 +static inline
9516 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
9517 +{
9518 +       if (!nxi)
9519 +               return 1;
9520 +       if (!ifa)
9521 +               return 0;
9522 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
9523 +}
9524 +
9525 +static inline
9526 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
9527 +{
9528 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
9529 +               nxi, nxi ? nxi->nx_id : 0, ifa,
9530 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
9531 +
9532 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9533 +               return 1;
9534 +       if (v6_ifa_in_nx_info(ifa, nxi))
9535 +               return 1;
9536 +       return 0;
9537 +}
9538 +
9539 +
9540 +struct nx_v6_sock_addr {
9541 +       struct in6_addr saddr;  /* Address used for validation */
9542 +       struct in6_addr baddr;  /* Address used for socket bind */
9543 +};
9544 +
9545 +static inline
9546 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
9547 +       struct nx_v6_sock_addr *nsa)
9548 +{
9549 +       // struct sock *sk = &inet->sk;
9550 +       // struct nx_info *nxi = sk->sk_nx_info;
9551 +       struct in6_addr saddr = addr->sin6_addr;
9552 +       struct in6_addr baddr = saddr;
9553 +
9554 +       nsa->saddr = saddr;
9555 +       nsa->baddr = baddr;
9556 +       return 0;
9557 +}
9558 +
9559 +static inline
9560 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
9561 +{
9562 +       // struct sock *sk = &inet->sk;
9563 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
9564 +
9565 +       // *saddr = nsa->baddr;
9566 +       // inet->inet_saddr = nsa->baddr;
9567 +}
9568 +
9569 +static inline
9570 +int nx_info_has_v6(struct nx_info *nxi)
9571 +{
9572 +       if (!nxi)
9573 +               return 1;
9574 +       if (NX_IPV6(nxi))
9575 +               return 1;
9576 +       return 0;
9577 +}
9578 +
9579 +#else /* CONFIG_IPV6 */
9580 +
9581 +static inline
9582 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
9583 +{
9584 +       return 1;
9585 +}
9586 +
9587 +
9588 +static inline
9589 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
9590 +{
9591 +       return 1;
9592 +}
9593 +
9594 +static inline
9595 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
9596 +{
9597 +       return 1;
9598 +}
9599 +
9600 +static inline
9601 +int nx_info_has_v6(struct nx_info *nxi)
9602 +{
9603 +       return 0;
9604 +}
9605 +
9606 +#endif /* CONFIG_IPV6 */
9607 +
9608 +#define current_nx_info_has_v6() \
9609 +       nx_info_has_v6(current_nx_info())
9610 +
9611 +#else
9612 +#warning duplicate inclusion
9613 +#endif
9614 diff -NurpP --minimal linux-3.9.5/include/linux/vs_limit.h linux-3.9.5-vs2.3.6.5/include/linux/vs_limit.h
9615 --- linux-3.9.5/include/linux/vs_limit.h        1970-01-01 00:00:00.000000000 +0000
9616 +++ linux-3.9.5-vs2.3.6.5/include/linux/vs_limit.h      2013-05-31 14:47:11.000000000 +0000
9617 @@ -0,0 +1,140 @@
9618 +#ifndef _VS_LIMIT_H
9619 +#define _VS_LIMIT_H
9620 +
9621 +#include "vserver/limit.h"
9622 +#include "vserver/base.h"
9623 +#include "vserver/context.h"
9624 +#include "vserver/debug.h"
9625 +#include "vserver/context.h"
9626 +#include "vserver/limit_int.h"
9627 +
9628 +
9629 +#define vx_acc_cres(v, d, p, r) \
9630 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
9631 +
9632 +#define vx_acc_cres_cond(x, d, p, r) \
9633 +       __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
9634 +       r, d, p, __FILE__, __LINE__)
9635 +
9636 +
9637 +#define vx_add_cres(v, a, p, r) \
9638 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
9639 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
9640 +
9641 +#define vx_add_cres_cond(x, a, p, r) \
9642 +       __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
9643 +       r, a, p, __FILE__, __LINE__)
9644 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
9645 +
9646 +
9647 +/* process and file limits */
9648 +
9649 +#define vx_nproc_inc(p) \
9650 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
9651 +
9652 +#define vx_nproc_dec(p) \
9653 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
9654 +
9655 +#define vx_files_inc(f) \
9656 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
9657 +
9658 +#define vx_files_dec(f) \
9659 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
9660 +
9661 +#define vx_locks_inc(l) \
9662 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
9663 +
9664 +#define vx_locks_dec(l) \
9665 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
9666 +
9667 +#define vx_openfd_inc(f) \
9668 +       vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
9669 +
9670 +#define vx_openfd_dec(f) \
9671 +       vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
9672 +
9673 +
9674 +#define vx_cres_avail(v, n, r) \
9675 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
9676 +
9677 +
9678 +#define vx_nproc_avail(n) \
9679 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
9680 +
9681 +#define vx_files_avail(n) \
9682 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
9683 +
9684 +#define vx_locks_avail(n) \
9685 +       vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
9686 +
9687 +#define vx_openfd_avail(n) \
9688 +       vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
9689 +
9690 +
9691 +/* dentry limits */
9692 +
9693 +#define vx_dentry_inc(d) do {                                          \
9694 +       if ((d)->d_count == 1)                                          \
9695 +               vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY);    \
9696 +       } while (0)
9697 +
9698 +#define vx_dentry_dec(d) do {                                          \
9699 +       if ((d)->d_count == 0)                                          \
9700 +               vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY);    \
9701 +       } while (0)
9702 +
9703 +#define vx_dentry_avail(n) \
9704 +       vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
9705 +
9706 +
9707 +/* socket limits */
9708 +
9709 +#define vx_sock_inc(s) \
9710 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
9711 +
9712 +#define vx_sock_dec(s) \
9713 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
9714 +
9715 +#define vx_sock_avail(n) \
9716 +       vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
9717 +
9718 +
9719 +/* ipc resource limits */
9720 +
9721 +#define vx_ipcmsg_add(v, u, a) \
9722 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
9723 +
9724 +#define vx_ipcmsg_sub(v, u, a) \
9725 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
9726 +
9727 +#define vx_ipcmsg_avail(v, a) \
9728 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
9729 +
9730 +
9731 +#define vx_ipcshm_add(v, k, a) \
9732 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
9733 +
9734 +#define vx_ipcshm_sub(v, k, a) \
9735 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
9736 +
9737 +#define vx_ipcshm_avail(v, a) \
9738 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
9739 +
9740 +
9741 +#define vx_semary_inc(a) \
9742 +       vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
9743 +
9744 +#define vx_semary_dec(a) \
9745 +       vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
9746 +
9747 +
9748 +#define vx_nsems_add(a,n) \
9749 +       vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
9750 +
9751 +#define vx_nsems_sub(a,n) \
9752 +       vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
9753 +
9754 +
9755 +#else
9756 +#warning duplicate inclusion
9757 +#endif
9758 diff -NurpP --minimal linux-3.9.5/include/linux/vs_network.h linux-3.9.5-vs2.3.6.5/include/linux/vs_network.h
9759 --- linux-3.9.5/include/linux/vs_network.h      1970-01-01 00:00:00.000000000 +0000
9760 +++ linux-3.9.5-vs2.3.6.5/include/linux/vs_network.h    2013-05-31 14:47:11.000000000 +0000
9761 @@ -0,0 +1,169 @@
9762 +#ifndef _NX_VS_NETWORK_H
9763 +#define _NX_VS_NETWORK_H
9764 +
9765 +#include "vserver/context.h"
9766 +#include "vserver/network.h"
9767 +#include "vserver/base.h"
9768 +#include "vserver/check.h"
9769 +#include "vserver/debug.h"
9770 +
9771 +#include <linux/sched.h>
9772 +
9773 +
9774 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
9775 +
9776 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
9777 +       const char *_file, int _line)
9778 +{
9779 +       if (!nxi)
9780 +               return NULL;
9781 +
9782 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
9783 +               nxi, nxi ? nxi->nx_id : 0,
9784 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9785 +               _file, _line);
9786 +
9787 +       atomic_inc(&nxi->nx_usecnt);
9788 +       return nxi;
9789 +}
9790 +
9791 +
9792 +extern void free_nx_info(struct nx_info *);
9793 +
9794 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
9795 +
9796 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
9797 +{
9798 +       if (!nxi)
9799 +               return;
9800 +
9801 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
9802 +               nxi, nxi ? nxi->nx_id : 0,
9803 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9804 +               _file, _line);
9805 +
9806 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
9807 +               free_nx_info(nxi);
9808 +}
9809 +
9810 +
9811 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
9812 +
9813 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
9814 +               const char *_file, int _line)
9815 +{
9816 +       if (nxi) {
9817 +               vxlprintk(VXD_CBIT(nid, 3),
9818 +                       "init_nx_info(%p[#%d.%d])",
9819 +                       nxi, nxi ? nxi->nx_id : 0,
9820 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9821 +                       _file, _line);
9822 +
9823 +               atomic_inc(&nxi->nx_usecnt);
9824 +       }
9825 +       *nxp = nxi;
9826 +}
9827 +
9828 +
9829 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
9830 +
9831 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
9832 +       const char *_file, int _line)
9833 +{
9834 +       struct nx_info *nxo;
9835 +
9836 +       if (!nxi)
9837 +               return;
9838 +
9839 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
9840 +               nxi, nxi ? nxi->nx_id : 0,
9841 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9842 +               _file, _line);
9843 +
9844 +       atomic_inc(&nxi->nx_usecnt);
9845 +       nxo = xchg(nxp, nxi);
9846 +       BUG_ON(nxo);
9847 +}
9848 +
9849 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
9850 +
9851 +static inline void __clr_nx_info(struct nx_info **nxp,
9852 +       const char *_file, int _line)
9853 +{
9854 +       struct nx_info *nxo;
9855 +
9856 +       nxo = xchg(nxp, NULL);
9857 +       if (!nxo)
9858 +               return;
9859 +
9860 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
9861 +               nxo, nxo ? nxo->nx_id : 0,
9862 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
9863 +               _file, _line);
9864 +
9865 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
9866 +               free_nx_info(nxo);
9867 +}
9868 +
9869 +
9870 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
9871 +
9872 +static inline void __claim_nx_info(struct nx_info *nxi,
9873 +       struct task_struct *task, const char *_file, int _line)
9874 +{
9875 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
9876 +               nxi, nxi ? nxi->nx_id : 0,
9877 +               nxi?atomic_read(&nxi->nx_usecnt):0,
9878 +               nxi?atomic_read(&nxi->nx_tasks):0,
9879 +               task, _file, _line);
9880 +
9881 +       atomic_inc(&nxi->nx_tasks);
9882 +}
9883 +
9884 +
9885 +extern void unhash_nx_info(struct nx_info *);
9886 +
9887 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
9888 +
9889 +static inline void __release_nx_info(struct nx_info *nxi,
9890 +       struct task_struct *task, const char *_file, int _line)
9891 +{
9892 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
9893 +               nxi, nxi ? nxi->nx_id : 0,
9894 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9895 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
9896 +               task, _file, _line);
9897 +
9898 +       might_sleep();
9899 +
9900 +       if (atomic_dec_and_test(&nxi->nx_tasks))
9901 +               unhash_nx_info(nxi);
9902 +}
9903 +
9904 +
9905 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
9906 +
9907 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
9908 +       const char *_file, int _line)
9909 +{
9910 +       struct nx_info *nxi;
9911 +
9912 +       task_lock(p);
9913 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
9914 +               p, _file, _line);
9915 +       nxi = __get_nx_info(p->nx_info, _file, _line);
9916 +       task_unlock(p);
9917 +       return nxi;
9918 +}
9919 +
9920 +
9921 +static inline void exit_nx_info(struct task_struct *p)
9922 +{
9923 +       if (p->nx_info)
9924 +               release_nx_info(p->nx_info, p);
9925 +}
9926 +
9927 +
9928 +#else
9929 +#warning duplicate inclusion
9930 +#endif
9931 diff -NurpP --minimal linux-3.9.5/include/linux/vs_pid.h linux-3.9.5-vs2.3.6.5/include/linux/vs_pid.h
9932 --- linux-3.9.5/include/linux/vs_pid.h  1970-01-01 00:00:00.000000000 +0000
9933 +++ linux-3.9.5-vs2.3.6.5/include/linux/vs_pid.h        2013-05-31 14:47:11.000000000 +0000
9934 @@ -0,0 +1,50 @@
9935 +#ifndef _VS_PID_H
9936 +#define _VS_PID_H
9937 +
9938 +#include "vserver/base.h"
9939 +#include "vserver/check.h"
9940 +#include "vserver/context.h"
9941 +#include "vserver/debug.h"
9942 +#include "vserver/pid.h"
9943 +#include <linux/pid_namespace.h>
9944 +
9945 +
9946 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
9947 +
9948 +static inline
9949 +int vx_proc_task_visible(struct task_struct *task)
9950 +{
9951 +       if ((task->pid == 1) &&
9952 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
9953 +               /* show a blend through init */
9954 +               goto visible;
9955 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
9956 +               goto visible;
9957 +       return 0;
9958 +visible:
9959 +       return 1;
9960 +}
9961 +
9962 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
9963 +
9964 +
9965 +static inline
9966 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
9967 +{
9968 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
9969 +
9970 +       if (task && !vx_proc_task_visible(task)) {
9971 +               vxdprintk(VXD_CBIT(misc, 6),
9972 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
9973 +                       task, task->xid, task->pid,
9974 +                       current, current->xid, current->pid);
9975 +               put_task_struct(task);
9976 +               task = NULL;
9977 +       }
9978 +       return task;
9979 +}
9980 +
9981 +
9982 +#else
9983 +#warning duplicate inclusion
9984 +#endif
9985 diff -NurpP --minimal linux-3.9.5/include/linux/vs_sched.h linux-3.9.5-vs2.3.6.5/include/linux/vs_sched.h
9986 --- linux-3.9.5/include/linux/vs_sched.h        1970-01-01 00:00:00.000000000 +0000
9987 +++ linux-3.9.5-vs2.3.6.5/include/linux/vs_sched.h      2013-05-31 14:47:11.000000000 +0000
9988 @@ -0,0 +1,40 @@
9989 +#ifndef _VS_SCHED_H
9990 +#define _VS_SCHED_H
9991 +
9992 +#include "vserver/base.h"
9993 +#include "vserver/context.h"
9994 +#include "vserver/sched.h"
9995 +
9996 +
9997 +#define MAX_PRIO_BIAS           20
9998 +#define MIN_PRIO_BIAS          -20
9999 +
10000 +static inline
10001 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
10002 +{
10003 +       struct vx_info *vxi = p->vx_info;
10004 +
10005 +       if (vxi)
10006 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
10007 +       return prio;
10008 +}
10009 +
10010 +static inline void vx_account_user(struct vx_info *vxi,
10011 +       cputime_t cputime, int nice)
10012 +{
10013 +       if (!vxi)
10014 +               return;
10015 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
10016 +}
10017 +
10018 +static inline void vx_account_system(struct vx_info *vxi,
10019 +       cputime_t cputime, int idle)
10020 +{
10021 +       if (!vxi)
10022 +               return;
10023 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
10024 +}
10025 +
10026 +#else
10027 +#warning duplicate inclusion
10028 +#endif
10029 diff -NurpP --minimal linux-3.9.5/include/linux/vs_socket.h linux-3.9.5-vs2.3.6.5/include/linux/vs_socket.h
10030 --- linux-3.9.5/include/linux/vs_socket.h       1970-01-01 00:00:00.000000000 +0000
10031 +++ linux-3.9.5-vs2.3.6.5/include/linux/vs_socket.h     2013-05-31 14:47:11.000000000 +0000
10032 @@ -0,0 +1,67 @@
10033 +#ifndef _VS_SOCKET_H
10034 +#define _VS_SOCKET_H
10035 +
10036 +#include "vserver/debug.h"
10037 +#include "vserver/base.h"
10038 +#include "vserver/cacct.h"
10039 +#include "vserver/context.h"
10040 +#include "vserver/tag.h"
10041 +
10042 +
10043 +/* socket accounting */
10044 +
10045 +#include <linux/socket.h>
10046 +
10047 +static inline int vx_sock_type(int family)
10048 +{
10049 +       switch (family) {
10050 +       case PF_UNSPEC:
10051 +               return VXA_SOCK_UNSPEC;
10052 +       case PF_UNIX:
10053 +               return VXA_SOCK_UNIX;
10054 +       case PF_INET:
10055 +               return VXA_SOCK_INET;
10056 +       case PF_INET6:
10057 +               return VXA_SOCK_INET6;
10058 +       case PF_PACKET:
10059 +               return VXA_SOCK_PACKET;
10060 +       default:
10061 +               return VXA_SOCK_OTHER;
10062 +       }
10063 +}
10064 +
10065 +#define vx_acc_sock(v, f, p, s) \
10066 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
10067 +
10068 +static inline void __vx_acc_sock(struct vx_info *vxi,
10069 +       int family, int pos, int size, char *file, int line)
10070 +{
10071 +       if (vxi) {
10072 +               int type = vx_sock_type(family);
10073 +
10074 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
10075 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
10076 +       }
10077 +}
10078 +
10079 +#define vx_sock_recv(sk, s) \
10080 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
10081 +#define vx_sock_send(sk, s) \
10082 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
10083 +#define vx_sock_fail(sk, s) \
10084 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
10085 +
10086 +
10087 +#define sock_vx_init(s) do {           \
10088 +       (s)->sk_xid = 0;                \
10089 +       (s)->sk_vx_info = NULL;         \
10090 +       } while (0)
10091 +
10092 +#define sock_nx_init(s) do {           \
10093 +       (s)->sk_nid = 0;                \
10094 +       (s)->sk_nx_info = NULL;         \
10095 +       } while (0)
10096 +
10097 +#else
10098 +#warning duplicate inclusion
10099 +#endif
10100 diff -NurpP --minimal linux-3.9.5/include/linux/vs_tag.h linux-3.9.5-vs2.3.6.5/include/linux/vs_tag.h
10101 --- linux-3.9.5/include/linux/vs_tag.h  1970-01-01 00:00:00.000000000 +0000
10102 +++ linux-3.9.5-vs2.3.6.5/include/linux/vs_tag.h        2013-06-12 23:49:08.000000000 +0000
10103 @@ -0,0 +1,47 @@
10104 +#ifndef _VS_TAG_H
10105 +#define _VS_TAG_H
10106 +
10107 +#include <linux/vserver/tag.h>
10108 +
10109 +/* check conditions */
10110 +
10111 +#define DX_ADMIN       0x0001
10112 +#define DX_WATCH       0x0002
10113 +#define DX_HOSTID      0x0008
10114 +
10115 +#define DX_IDENT       0x0010
10116 +
10117 +#define DX_ARG_MASK    0x0010
10118 +
10119 +
10120 +#define dx_task_tag(t) ((t)->tag)
10121 +
10122 +#define dx_current_tag() dx_task_tag(current)
10123 +
10124 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
10125 +
10126 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
10127 +
10128 +
10129 +/*
10130 + * check current context for ADMIN/WATCH and
10131 + * optionally against supplied argument
10132 + */
10133 +static inline int __dx_check(vtag_t cid, vtag_t id, unsigned int mode)
10134 +{
10135 +       if (mode & DX_ARG_MASK) {
10136 +               if ((mode & DX_IDENT) && (id == cid))
10137 +                       return 1;
10138 +       }
10139 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
10140 +               ((mode & DX_WATCH) && (cid == 1)) ||
10141 +               ((mode & DX_HOSTID) && (id == 0)));
10142 +}
10143 +
10144 +struct inode;
10145 +int dx_permission(const struct inode *inode, int mask);
10146 +
10147 +
10148 +#else
10149 +#warning duplicate inclusion
10150 +#endif
10151 diff -NurpP --minimal linux-3.9.5/include/linux/vs_time.h linux-3.9.5-vs2.3.6.5/include/linux/vs_time.h
10152 --- linux-3.9.5/include/linux/vs_time.h 1970-01-01 00:00:00.000000000 +0000
10153 +++ linux-3.9.5-vs2.3.6.5/include/linux/vs_time.h       2013-05-31 14:47:11.000000000 +0000
10154 @@ -0,0 +1,19 @@
10155 +#ifndef _VS_TIME_H
10156 +#define _VS_TIME_H
10157 +
10158 +
10159 +/* time faking stuff */
10160 +
10161 +#ifdef CONFIG_VSERVER_VTIME
10162 +
10163 +extern void vx_adjust_timespec(struct timespec *ts);
10164 +extern int vx_settimeofday(const struct timespec *ts);
10165 +
10166 +#else
10167 +#define        vx_adjust_timespec(t)   do { } while (0)
10168 +#define        vx_settimeofday(t)      do_settimeofday(t)
10169 +#endif
10170 +
10171 +#else
10172 +#warning duplicate inclusion
10173 +#endif
10174 diff -NurpP --minimal linux-3.9.5/include/linux/vserver/base.h linux-3.9.5-vs2.3.6.5/include/linux/vserver/base.h
10175 --- linux-3.9.5/include/linux/vserver/base.h    1970-01-01 00:00:00.000000000 +0000
10176 +++ linux-3.9.5-vs2.3.6.5/include/linux/vserver/base.h  2013-05-31 17:55:09.000000000 +0000
10177 @@ -0,0 +1,181 @@
10178 +#ifndef _VSERVER_BASE_H
10179 +#define _VSERVER_BASE_H
10180 +
10181 +
10182 +/* context state changes */
10183 +
10184 +enum {
10185 +       VSC_STARTUP = 1,
10186 +       VSC_SHUTDOWN,
10187 +
10188 +       VSC_NETUP,
10189 +       VSC_NETDOWN,
10190 +};
10191 +
10192 +
10193 +
10194 +#define vx_task_xid(t) ((t)->xid)
10195 +
10196 +#define vx_current_xid() vx_task_xid(current)
10197 +
10198 +#define current_vx_info() (current->vx_info)
10199 +
10200 +
10201 +#define nx_task_nid(t) ((t)->nid)
10202 +
10203 +#define nx_current_nid() nx_task_nid(current)
10204 +
10205 +#define current_nx_info() (current->nx_info)
10206 +
10207 +
10208 +/* generic flag merging */
10209 +
10210 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
10211 +
10212 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
10213 +
10214 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
10215 +
10216 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
10217 +
10218 +
10219 +/* context flags */
10220 +
10221 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
10222 +
10223 +#define vx_current_flags()     __vx_flags(current_vx_info())
10224 +
10225 +#define vx_info_flags(v, m, f) \
10226 +       vs_check_flags(__vx_flags(v), m, f)
10227 +
10228 +#define task_vx_flags(t, m, f) \
10229 +       ((t) && vx_info_flags((t)->vx_info, m, f))
10230 +
10231 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
10232 +
10233 +
10234 +/* context caps */
10235 +
10236 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
10237 +
10238 +#define vx_current_ccaps()     __vx_ccaps(current_vx_info())
10239 +
10240 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
10241 +
10242 +#define vx_ccaps(c)    vx_info_ccaps(current_vx_info(), (c))
10243 +
10244 +
10245 +
10246 +/* network flags */
10247 +
10248 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
10249 +
10250 +#define nx_current_flags()     __nx_flags(current_nx_info())
10251 +
10252 +#define nx_info_flags(n, m, f) \
10253 +       vs_check_flags(__nx_flags(n), m, f)
10254 +
10255 +#define task_nx_flags(t, m, f) \
10256 +       ((t) && nx_info_flags((t)->nx_info, m, f))
10257 +
10258 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
10259 +
10260 +
10261 +/* network caps */
10262 +
10263 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
10264 +
10265 +#define nx_current_ncaps()     __nx_ncaps(current_nx_info())
10266 +
10267 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
10268 +
10269 +#define nx_ncaps(c)    nx_info_ncaps(current_nx_info(), c)
10270 +
10271 +
10272 +/* context mask capabilities */
10273 +
10274 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
10275 +
10276 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
10277 +
10278 +#define vx_mcaps(c)    vx_info_mcaps(current_vx_info(), c)
10279 +
10280 +
10281 +/* context bcap mask */
10282 +
10283 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
10284 +
10285 +#define vx_current_bcaps()     __vx_bcaps(current_vx_info())
10286 +
10287 +
10288 +/* mask given bcaps */
10289 +
10290 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
10291 +
10292 +#define vx_mbcaps(c)           vx_info_mbcaps(current_vx_info(), c)
10293 +
10294 +
10295 +/* masked cap_bset */
10296 +
10297 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
10298 +
10299 +#define vx_current_cap_bset()  vx_info_cap_bset(current_vx_info())
10300 +
10301 +#if 0
10302 +#define vx_info_mbcap(v, b) \
10303 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
10304 +       vx_info_bcaps(v, b) : (b))
10305 +
10306 +#define task_vx_mbcap(t, b) \
10307 +       vx_info_mbcap((t)->vx_info, (t)->b)
10308 +
10309 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
10310 +#endif
10311 +
10312 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
10313 +
10314 +#define vx_capable(b, c) (capable(b) || \
10315 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10316 +
10317 +#define vx_ns_capable(n, b, c) (ns_capable(n, b) || \
10318 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10319 +
10320 +#define nx_capable(b, c) (capable(b) || \
10321 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
10322 +
10323 +#define vx_task_initpid(t, n) \
10324 +       ((t)->vx_info && \
10325 +       ((t)->vx_info->vx_initpid == (n)))
10326 +
10327 +#define vx_current_initpid(n)  vx_task_initpid(current, n)
10328 +
10329 +
10330 +/* context unshare mask */
10331 +
10332 +#define __vx_umask(v)          ((v)->vx_umask)
10333 +
10334 +#define vx_current_umask()     __vx_umask(current_vx_info())
10335 +
10336 +#define vx_can_unshare(b, f) (capable(b) || \
10337 +       (cap_raised(current_cap(), b) && \
10338 +       !((f) & ~vx_current_umask())))
10339 +
10340 +#define vx_ns_can_unshare(n, b, f) (ns_capable(n, b) || \
10341 +       (cap_raised(current_cap(), b) && \
10342 +       !((f) & ~vx_current_umask())))
10343 +
10344 +#define __vx_wmask(v)          ((v)->vx_wmask)
10345 +
10346 +#define vx_current_wmask()     __vx_wmask(current_vx_info())
10347 +
10348 +
10349 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
10350 +
10351 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
10352 +
10353 +
10354 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
10355 +
10356 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
10357 +
10358 +#endif
10359 diff -NurpP --minimal linux-3.9.5/include/linux/vserver/cacct.h linux-3.9.5-vs2.3.6.5/include/linux/vserver/cacct.h
10360 --- linux-3.9.5/include/linux/vserver/cacct.h   1970-01-01 00:00:00.000000000 +0000
10361 +++ linux-3.9.5-vs2.3.6.5/include/linux/vserver/cacct.h 2013-05-31 14:47:11.000000000 +0000
10362 @@ -0,0 +1,15 @@
10363 +#ifndef _VSERVER_CACCT_H
10364 +#define _VSERVER_CACCT_H
10365 +
10366 +
10367 +enum sock_acc_field {
10368 +       VXA_SOCK_UNSPEC = 0,
10369 +       VXA_SOCK_UNIX,
10370 +       VXA_SOCK_INET,
10371 +       VXA_SOCK_INET6,
10372 +       VXA_SOCK_PACKET,
10373 +       VXA_SOCK_OTHER,
10374 +       VXA_SOCK_SIZE   /* array size */
10375 +};
10376 +
10377 +#endif /* _VSERVER_CACCT_H */
10378 diff -NurpP --minimal linux-3.9.5/include/linux/vserver/cacct_cmd.h linux-3.9.5-vs2.3.6.5/include/linux/vserver/cacct_cmd.h
10379 --- linux-3.9.5/include/linux/vserver/cacct_cmd.h       1970-01-01 00:00:00.000000000 +0000
10380 +++ linux-3.9.5-vs2.3.6.5/include/linux/vserver/cacct_cmd.h     2013-05-31 14:47:11.000000000 +0000
10381 @@ -0,0 +1,10 @@
10382 +#ifndef _VSERVER_CACCT_CMD_H
10383 +#define _VSERVER_CACCT_CMD_H
10384 +
10385 +
10386 +#include <linux/compiler.h>
10387 +#include <uapi/vserver/cacct_cmd.h>
10388 +
10389 +extern int vc_sock_stat(struct vx_info *, void __user *);
10390 +
10391 +#endif /* _VSERVER_CACCT_CMD_H */
10392 diff -NurpP --minimal linux-3.9.5/include/linux/vserver/cacct_def.h linux-3.9.5-vs2.3.6.5/include/linux/vserver/cacct_def.h
10393 --- linux-3.9.5/include/linux/vserver/cacct_def.h       1970-01-01 00:00:00.000000000 +0000
10394 +++ linux-3.9.5-vs2.3.6.5/include/linux/vserver/cacct_def.h     2013-05-31 14:47:11.000000000 +0000
10395 @@ -0,0 +1,43 @@
10396 +#ifndef _VSERVER_CACCT_DEF_H
10397 +#define _VSERVER_CACCT_DEF_H
10398 +
10399 +#include <asm/atomic.h>
10400 +#include <linux/vserver/cacct.h>
10401 +
10402 +
10403 +struct _vx_sock_acc {
10404 +       atomic_long_t count;
10405 +       atomic_long_t total;
10406 +};
10407 +
10408 +/* context sub struct */
10409 +
10410 +struct _vx_cacct {
10411 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
10412 +       atomic_t slab[8];
10413 +       atomic_t page[6][8];
10414 +};
10415 +
10416 +#ifdef CONFIG_VSERVER_DEBUG
10417 +
10418 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
10419 +{
10420 +       int i, j;
10421 +
10422 +       printk("\t_vx_cacct:");
10423 +       for (i = 0; i < 6; i++) {
10424 +               struct _vx_sock_acc *ptr = cacct->sock[i];
10425 +
10426 +               printk("\t [%d] =", i);
10427 +               for (j = 0; j < 3; j++) {
10428 +                       printk(" [%d] = %8lu, %8lu", j,
10429 +                               atomic_long_read(&ptr[j].count),
10430 +                               atomic_long_read(&ptr[j].total));
10431 +               }
10432 +               printk("\n");
10433 +       }
10434 +}
10435 +
10436 +#endif
10437 +
10438 +#endif /* _VSERVER_CACCT_DEF_H */
10439 diff -NurpP --minimal linux-3.9.5/include/linux/vserver/cacct_int.h linux-3.9.5-vs2.3.6.5/include/linux/vserver/cacct_int.h
10440 --- linux-3.9.5/include/linux/vserver/cacct_int.h       1970-01-01 00:00:00.000000000 +0000
10441 +++ linux-3.9.5-vs2.3.6.5/include/linux/vserver/cacct_int.h     2013-05-31 14:47:11.000000000 +0000
10442 @@ -0,0 +1,17 @@
10443 +#ifndef _VSERVER_CACCT_INT_H
10444 +#define _VSERVER_CACCT_INT_H
10445 +
10446 +static inline
10447 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
10448 +{
10449 +       return atomic_long_read(&cacct->sock[type][pos].count);
10450 +}
10451 +
10452 +
10453 +static inline
10454 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
10455 +{
10456 +       return atomic_long_read(&cacct->sock[type][pos].total);
10457 +}
10458 +
10459 +#endif /* _VSERVER_CACCT_INT_H */
10460 diff -NurpP --minimal linux-3.9.5/include/linux/vserver/check.h linux-3.9.5-vs2.3.6.5/include/linux/vserver/check.h
10461 --- linux-3.9.5/include/linux/vserver/check.h   1970-01-01 00:00:00.000000000 +0000
10462 +++ linux-3.9.5-vs2.3.6.5/include/linux/vserver/check.h 2013-05-31 14:47:11.000000000 +0000
10463 @@ -0,0 +1,89 @@
10464 +#ifndef _VSERVER_CHECK_H
10465 +#define _VSERVER_CHECK_H
10466 +
10467 +
10468 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
10469 +
10470 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
10471 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
10472 +#else
10473 +#define MIN_D_CONTEXT  65536
10474 +#endif
10475 +
10476 +/* check conditions */
10477 +
10478 +#define VS_ADMIN       0x0001
10479 +#define VS_WATCH       0x0002
10480 +#define VS_HIDE                0x0004
10481 +#define VS_HOSTID      0x0008
10482 +
10483 +#define VS_IDENT       0x0010
10484 +#define VS_EQUIV       0x0020
10485 +#define VS_PARENT      0x0040
10486 +#define VS_CHILD       0x0080
10487 +
10488 +#define VS_ARG_MASK    0x00F0
10489 +
10490 +#define VS_DYNAMIC     0x0100
10491 +#define VS_STATIC      0x0200
10492 +
10493 +#define VS_ATR_MASK    0x0F00
10494 +
10495 +#ifdef CONFIG_VSERVER_PRIVACY
10496 +#define VS_ADMIN_P     (0)
10497 +#define VS_WATCH_P     (0)
10498 +#else
10499 +#define VS_ADMIN_P     VS_ADMIN
10500 +#define VS_WATCH_P     VS_WATCH
10501 +#endif
10502 +
10503 +#define VS_HARDIRQ     0x1000
10504 +#define VS_SOFTIRQ     0x2000
10505 +#define VS_IRQ         0x4000
10506 +
10507 +#define VS_IRQ_MASK    0xF000
10508 +
10509 +#include <linux/hardirq.h>
10510 +
10511 +/*
10512 + * check current context for ADMIN/WATCH and
10513 + * optionally against supplied argument
10514 + */
10515 +static inline int __vs_check(int cid, int id, unsigned int mode)
10516 +{
10517 +       if (mode & VS_ARG_MASK) {
10518 +               if ((mode & VS_IDENT) && (id == cid))
10519 +                       return 1;
10520 +       }
10521 +       if (mode & VS_ATR_MASK) {
10522 +               if ((mode & VS_DYNAMIC) &&
10523 +                       (id >= MIN_D_CONTEXT) &&
10524 +                       (id <= MAX_S_CONTEXT))
10525 +                       return 1;
10526 +               if ((mode & VS_STATIC) &&
10527 +                       (id > 1) && (id < MIN_D_CONTEXT))
10528 +                       return 1;
10529 +       }
10530 +       if (mode & VS_IRQ_MASK) {
10531 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
10532 +                       return 1;
10533 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
10534 +                       return 1;
10535 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
10536 +                       return 1;
10537 +       }
10538 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
10539 +               ((mode & VS_WATCH) && (cid == 1)) ||
10540 +               ((mode & VS_HOSTID) && (id == 0)));
10541 +}
10542 +
10543 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
10544 +
10545 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
10546 +
10547 +
10548 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
10549 +
10550 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
10551 +
10552 +#endif
10553 diff -NurpP --minimal linux-3.9.5/include/linux/vserver/context.h linux-3.9.5-vs2.3.6.5/include/linux/vserver/context.h
10554 --- linux-3.9.5/include/linux/vserver/context.h 1970-01-01 00:00:00.000000000 +0000
10555 +++ linux-3.9.5-vs2.3.6.5/include/linux/vserver/context.h       2013-06-12 23:49:08.000000000 +0000
10556 @@ -0,0 +1,110 @@
10557 +#ifndef _VSERVER_CONTEXT_H
10558 +#define _VSERVER_CONTEXT_H
10559 +
10560 +
10561 +#include <linux/list.h>
10562 +#include <linux/spinlock.h>
10563 +#include <linux/rcupdate.h>
10564 +#include <uapi/vserver/context.h>
10565 +
10566 +#include "limit_def.h"
10567 +#include "sched_def.h"
10568 +#include "cvirt_def.h"
10569 +#include "cacct_def.h"
10570 +#include "device_def.h"
10571 +
10572 +#define VX_SPACES      2
10573 +
10574 +struct _vx_info_pc {
10575 +       struct _vx_sched_pc sched_pc;
10576 +       struct _vx_cvirt_pc cvirt_pc;
10577 +};
10578 +
10579 +struct _vx_space {
10580 +       unsigned long vx_nsmask;                /* assignment mask */
10581 +       struct nsproxy *vx_nsproxy;             /* private namespaces */
10582 +       struct fs_struct *vx_fs;                /* private namespace fs */
10583 +       const struct cred *vx_cred;             /* task credentials */
10584 +};
10585 +
10586 +struct vx_info {
10587 +       struct hlist_node vx_hlist;             /* linked list of contexts */
10588 +       vxid_t vx_id;                           /* context id */
10589 +       atomic_t vx_usecnt;                     /* usage count */
10590 +       atomic_t vx_tasks;                      /* tasks count */
10591 +       struct vx_info *vx_parent;              /* parent context */
10592 +       int vx_state;                           /* context state */
10593 +
10594 +       struct _vx_space space[VX_SPACES];      /* namespace store */
10595 +
10596 +       uint64_t vx_flags;                      /* context flags */
10597 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
10598 +       uint64_t vx_umask;                      /* unshare mask (guest) */
10599 +       uint64_t vx_wmask;                      /* warn mask (guest) */
10600 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
10601 +
10602 +       struct task_struct *vx_reaper;          /* guest reaper process */
10603 +       pid_t vx_initpid;                       /* PID of guest init */
10604 +       int64_t vx_badness_bias;                /* OOM points bias */
10605 +
10606 +       struct _vx_limit limit;                 /* vserver limits */
10607 +       struct _vx_sched sched;                 /* vserver scheduler */
10608 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
10609 +       struct _vx_cacct cacct;                 /* context accounting */
10610 +
10611 +       struct _vx_device dmap;                 /* default device map targets */
10612 +
10613 +#ifndef CONFIG_SMP
10614 +       struct _vx_info_pc info_pc;             /* per cpu data */
10615 +#else
10616 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
10617 +#endif
10618 +
10619 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
10620 +       int reboot_cmd;                         /* last sys_reboot() cmd */
10621 +       int exit_code;                          /* last process exit code */
10622 +
10623 +       char vx_name[65];                       /* vserver name */
10624 +};
10625 +
10626 +#ifndef CONFIG_SMP
10627 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
10628 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
10629 +#else
10630 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
10631 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
10632 +#endif
10633 +
10634 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
10635 +
10636 +
10637 +struct vx_info_save {
10638 +       struct vx_info *vxi;
10639 +       vxid_t xid;
10640 +};
10641 +
10642 +
10643 +/* status flags */
10644 +
10645 +#define VXS_HASHED     0x0001
10646 +#define VXS_PAUSED     0x0010
10647 +#define VXS_SHUTDOWN   0x0100
10648 +#define VXS_HELPER     0x1000
10649 +#define VXS_RELEASED   0x8000
10650 +
10651 +
10652 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
10653 +extern void release_vx_info(struct vx_info *, struct task_struct *);
10654 +
10655 +extern struct vx_info *lookup_vx_info(int);
10656 +extern struct vx_info *lookup_or_create_vx_info(int);
10657 +
10658 +extern int get_xid_list(int, unsigned int *, int);
10659 +extern int xid_is_hashed(vxid_t);
10660 +
10661 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
10662 +
10663 +extern long vs_state_change(struct vx_info *, unsigned int);
10664 +
10665 +
10666 +#endif /* _VSERVER_CONTEXT_H */
10667 diff -NurpP --minimal linux-3.9.5/include/linux/vserver/context_cmd.h linux-3.9.5-vs2.3.6.5/include/linux/vserver/context_cmd.h
10668 --- linux-3.9.5/include/linux/vserver/context_cmd.h     1970-01-01 00:00:00.000000000 +0000
10669 +++ linux-3.9.5-vs2.3.6.5/include/linux/vserver/context_cmd.h   2013-05-31 14:47:11.000000000 +0000
10670 @@ -0,0 +1,33 @@
10671 +#ifndef _VSERVER_CONTEXT_CMD_H
10672 +#define _VSERVER_CONTEXT_CMD_H
10673 +
10674 +#include <uapi/vserver/context_cmd.h>
10675 +
10676 +extern int vc_task_xid(uint32_t);
10677 +
10678 +extern int vc_vx_info(struct vx_info *, void __user *);
10679 +
10680 +extern int vc_ctx_stat(struct vx_info *, void __user *);
10681 +
10682 +extern int vc_ctx_create(uint32_t, void __user *);
10683 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
10684 +
10685 +extern int vc_get_cflags(struct vx_info *, void __user *);
10686 +extern int vc_set_cflags(struct vx_info *, void __user *);
10687 +
10688 +extern int vc_get_ccaps(struct vx_info *, void __user *);
10689 +extern int vc_set_ccaps(struct vx_info *, void __user *);
10690 +
10691 +extern int vc_get_bcaps(struct vx_info *, void __user *);
10692 +extern int vc_set_bcaps(struct vx_info *, void __user *);
10693 +
10694 +extern int vc_get_umask(struct vx_info *, void __user *);
10695 +extern int vc_set_umask(struct vx_info *, void __user *);
10696 +
10697 +extern int vc_get_wmask(struct vx_info *, void __user *);
10698 +extern int vc_set_wmask(struct vx_info *, void __user *);
10699 +
10700 +extern int vc_get_badness(struct vx_info *, void __user *);
10701 +extern int vc_set_badness(struct vx_info *, void __user *);
10702 +
10703 +#endif /* _VSERVER_CONTEXT_CMD_H */
10704 diff -NurpP --minimal linux-3.9.5/include/linux/vserver/cvirt.h linux-3.9.5-vs2.3.6.5/include/linux/vserver/cvirt.h
10705 --- linux-3.9.5/include/linux/vserver/cvirt.h   1970-01-01 00:00:00.000000000 +0000
10706 +++ linux-3.9.5-vs2.3.6.5/include/linux/vserver/cvirt.h 2013-05-31 14:47:11.000000000 +0000
10707 @@ -0,0 +1,18 @@
10708 +#ifndef _VSERVER_CVIRT_H
10709 +#define _VSERVER_CVIRT_H
10710 +
10711 +struct timespec;
10712 +
10713 +void vx_vsi_boottime(struct timespec *);
10714 +
10715 +void vx_vsi_uptime(struct timespec *, struct timespec *);
10716 +
10717 +
10718 +struct vx_info;
10719 +
10720 +void vx_update_load(struct vx_info *);
10721 +
10722 +
10723 +int vx_do_syslog(int, char __user *, int);
10724 +
10725 +#endif /* _VSERVER_CVIRT_H */
10726 diff -NurpP --minimal linux-3.9.5/include/linux/vserver/cvirt_cmd.h linux-3.9.5-vs2.3.6.5/include/linux/vserver/cvirt_cmd.h
10727 --- linux-3.9.5/include/linux/vserver/cvirt_cmd.h       1970-01-01 00:00:00.000000000 +0000
10728 +++ linux-3.9.5-vs2.3.6.5/include/linux/vserver/cvirt_cmd.h     2013-05-31 14:47:11.000000000 +0000
10729 @@ -0,0 +1,13 @@
10730 +#ifndef _VSERVER_CVIRT_CMD_H
10731 +#define _VSERVER_CVIRT_CMD_H
10732 +
10733 +
10734 +#include <linux/compiler.h>
10735 +#include <uapi/vserver/cvirt_cmd.h>
10736 +
10737 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
10738 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
10739 +
10740 +extern int vc_virt_stat(struct vx_info *, void __user *);
10741 +
10742 +#endif /* _VSERVER_CVIRT_CMD_H */
10743 diff -NurpP --minimal linux-3.9.5/include/linux/vserver/cvirt_def.h linux-3.9.5-vs2.3.6.5/include/linux/vserver/cvirt_def.h
10744 --- linux-3.9.5/include/linux/vserver/cvirt_def.h       1970-01-01 00:00:00.000000000 +0000
10745 +++ linux-3.9.5-vs2.3.6.5/include/linux/vserver/cvirt_def.h     2013-05-31 14:47:11.000000000 +0000
10746 @@ -0,0 +1,80 @@
10747 +#ifndef _VSERVER_CVIRT_DEF_H
10748 +#define _VSERVER_CVIRT_DEF_H
10749 +
10750 +#include <linux/jiffies.h>
10751 +#include <linux/spinlock.h>
10752 +#include <linux/wait.h>
10753 +#include <linux/time.h>
10754 +#include <asm/atomic.h>
10755 +
10756 +
10757 +struct _vx_usage_stat {
10758 +       uint64_t user;
10759 +       uint64_t nice;
10760 +       uint64_t system;
10761 +       uint64_t softirq;
10762 +       uint64_t irq;
10763 +       uint64_t idle;
10764 +       uint64_t iowait;
10765 +};
10766 +
10767 +struct _vx_syslog {
10768 +       wait_queue_head_t log_wait;
10769 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
10770 +
10771 +       unsigned long log_start;        /* next char to be read by syslog() */
10772 +       unsigned long con_start;        /* next char to be sent to consoles */
10773 +       unsigned long log_end;  /* most-recently-written-char + 1 */
10774 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
10775 +
10776 +       char log_buf[1024];
10777 +};
10778 +
10779 +
10780 +/* context sub struct */
10781 +
10782 +struct _vx_cvirt {
10783 +       atomic_t nr_threads;            /* number of current threads */
10784 +       atomic_t nr_running;            /* number of running threads */
10785 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
10786 +
10787 +       atomic_t nr_onhold;             /* processes on hold */
10788 +       uint32_t onhold_last;           /* jiffies when put on hold */
10789 +
10790 +       struct timespec bias_ts;        /* time offset to the host */
10791 +       struct timespec bias_idle;
10792 +       struct timespec bias_uptime;    /* context creation point */
10793 +       uint64_t bias_clock;            /* offset in clock_t */
10794 +
10795 +       spinlock_t load_lock;           /* lock for the load averages */
10796 +       atomic_t load_updates;          /* nr of load updates done so far */
10797 +       uint32_t load_last;             /* last time load was calculated */
10798 +       uint32_t load[3];               /* load averages 1,5,15 */
10799 +
10800 +       atomic_t total_forks;           /* number of forks so far */
10801 +
10802 +       struct _vx_syslog syslog;
10803 +};
10804 +
10805 +struct _vx_cvirt_pc {
10806 +       struct _vx_usage_stat cpustat;
10807 +};
10808 +
10809 +
10810 +#ifdef CONFIG_VSERVER_DEBUG
10811 +
10812 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
10813 +{
10814 +       printk("\t_vx_cvirt:\n");
10815 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
10816 +               atomic_read(&cvirt->nr_threads),
10817 +               atomic_read(&cvirt->nr_running),
10818 +               atomic_read(&cvirt->nr_uninterruptible),
10819 +               atomic_read(&cvirt->nr_onhold));
10820 +       /* add rest here */
10821 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
10822 +}
10823 +
10824 +#endif
10825 +
10826 +#endif /* _VSERVER_CVIRT_DEF_H */
10827 diff -NurpP --minimal linux-3.9.5/include/linux/vserver/debug.h linux-3.9.5-vs2.3.6.5/include/linux/vserver/debug.h
10828 --- linux-3.9.5/include/linux/vserver/debug.h   1970-01-01 00:00:00.000000000 +0000
10829 +++ linux-3.9.5-vs2.3.6.5/include/linux/vserver/debug.h 2013-06-03 18:27:34.000000000 +0000
10830 @@ -0,0 +1,146 @@
10831 +#ifndef _VSERVER_DEBUG_H
10832 +#define _VSERVER_DEBUG_H
10833 +
10834 +
10835 +#define VXD_CBIT(n, m) (vs_debug_ ## n & (1 << (m)))
10836 +#define VXD_CMIN(n, m) (vs_debug_ ## n > (m))
10837 +#define VXD_MASK(n, m) (vs_debug_ ## n & (m))
10838 +
10839 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
10840 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
10841 +#define VXF_DEV                "%p[%lu,%d:%d]"
10842 +
10843 +#if    defined(CONFIG_QUOTES_UTF8)
10844 +#define        VS_Q_LQM        "\xc2\xbb"
10845 +#define        VS_Q_RQM        "\xc2\xab"
10846 +#elif  defined(CONFIG_QUOTES_ASCII)
10847 +#define        VS_Q_LQM        "\x27"
10848 +#define        VS_Q_RQM        "\x27"
10849 +#else
10850 +#define        VS_Q_LQM        "\xbb"
10851 +#define        VS_Q_RQM        "\xab"
10852 +#endif
10853 +
10854 +#define        VS_Q(f)         VS_Q_LQM f VS_Q_RQM
10855 +
10856 +
10857 +#define vxd_path(p)                                            \
10858 +       ({ static char _buffer[PATH_MAX];                       \
10859 +          d_path(p, _buffer, sizeof(_buffer)); })
10860 +
10861 +#define vxd_cond_path(n)                                       \
10862 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
10863 +
10864 +
10865 +#ifdef CONFIG_VSERVER_DEBUG
10866 +
10867 +extern unsigned int vs_debug_switch;
10868 +extern unsigned int vs_debug_xid;
10869 +extern unsigned int vs_debug_nid;
10870 +extern unsigned int vs_debug_tag;
10871 +extern unsigned int vs_debug_net;
10872 +extern unsigned int vs_debug_limit;
10873 +extern unsigned int vs_debug_cres;
10874 +extern unsigned int vs_debug_dlim;
10875 +extern unsigned int vs_debug_quota;
10876 +extern unsigned int vs_debug_cvirt;
10877 +extern unsigned int vs_debug_space;
10878 +extern unsigned int vs_debug_perm;
10879 +extern unsigned int vs_debug_misc;
10880 +
10881 +
10882 +#define VX_LOGLEVEL    "vxD: "
10883 +#define VX_PROC_FMT    "%p: "
10884 +#define VX_PROCESS     current
10885 +
10886 +#define vxdprintk(c, f, x...)                                  \
10887 +       do {                                                    \
10888 +               if (c)                                          \
10889 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
10890 +                               VX_PROCESS , ##x);              \
10891 +       } while (0)
10892 +
10893 +#define vxlprintk(c, f, x...)                                  \
10894 +       do {                                                    \
10895 +               if (c)                                          \
10896 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
10897 +       } while (0)
10898 +
10899 +#define vxfprintk(c, f, x...)                                  \
10900 +       do {                                                    \
10901 +               if (c)                                          \
10902 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
10903 +       } while (0)
10904 +
10905 +
10906 +struct vx_info;
10907 +
10908 +void dump_vx_info(struct vx_info *, int);
10909 +void dump_vx_info_inactive(int);
10910 +
10911 +#else  /* CONFIG_VSERVER_DEBUG */
10912 +
10913 +#define vs_debug_switch        0
10914 +#define vs_debug_xid   0
10915 +#define vs_debug_nid   0
10916 +#define vs_debug_tag   0
10917 +#define vs_debug_net   0
10918 +#define vs_debug_limit 0
10919 +#define vs_debug_cres  0
10920 +#define vs_debug_dlim  0
10921 +#define vs_debug_quota 0
10922 +#define vs_debug_cvirt 0
10923 +#define vs_debug_space 0
10924 +#define vs_debug_perm  0
10925 +#define vs_debug_misc  0
10926 +
10927 +#define vxdprintk(x...) do { } while (0)
10928 +#define vxlprintk(x...) do { } while (0)
10929 +#define vxfprintk(x...) do { } while (0)
10930 +
10931 +#endif /* CONFIG_VSERVER_DEBUG */
10932 +
10933 +
10934 +#ifdef CONFIG_VSERVER_WARN
10935 +
10936 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
10937 +#define VX_WARN_TASK   "[" VS_Q("%s") ",%u:#%u|%u|%u] "
10938 +#define VX_WARN_XID    "[xid #%u] "
10939 +#define VX_WARN_NID    "[nid #%u] "
10940 +#define VX_WARN_TAG    "[tag #%u] "
10941 +
10942 +#define vxwprintk(c, f, x...)                                  \
10943 +       do {                                                    \
10944 +               if (c)                                          \
10945 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
10946 +       } while (0)
10947 +
10948 +#else  /* CONFIG_VSERVER_WARN */
10949 +
10950 +#define vxwprintk(x...) do { } while (0)
10951 +
10952 +#endif /* CONFIG_VSERVER_WARN */
10953 +
10954 +#define vxwprintk_task(c, f, x...)                             \
10955 +       vxwprintk(c, VX_WARN_TASK f,                            \
10956 +               current->comm, current->pid,                    \
10957 +               current->xid, current->nid,                     \
10958 +               current->tag, ##x)
10959 +#define vxwprintk_xid(c, f, x...)                              \
10960 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
10961 +#define vxwprintk_nid(c, f, x...)                              \
10962 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
10963 +#define vxwprintk_tag(c, f, x...)                              \
10964 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
10965 +
10966 +#ifdef CONFIG_VSERVER_DEBUG
10967 +#define vxd_assert_lock(l)     assert_spin_locked(l)
10968 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
10969 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
10970 +#else
10971 +#define vxd_assert_lock(l)     do { } while (0)
10972 +#define vxd_assert(c, f, x...) do { } while (0)
10973 +#endif
10974 +
10975 +
10976 +#endif /* _VSERVER_DEBUG_H */
10977 diff -NurpP --minimal linux-3.9.5/include/linux/vserver/debug_cmd.h linux-3.9.5-vs2.3.6.5/include/linux/vserver/debug_cmd.h
10978 --- linux-3.9.5/include/linux/vserver/debug_cmd.h       1970-01-01 00:00:00.000000000 +0000
10979 +++ linux-3.9.5-vs2.3.6.5/include/linux/vserver/debug_cmd.h     2013-05-31 14:47:11.000000000 +0000
10980 @@ -0,0 +1,37 @@
10981 +#ifndef _VSERVER_DEBUG_CMD_H
10982 +#define _VSERVER_DEBUG_CMD_H
10983 +
10984 +#include <uapi/vserver/debug_cmd.h>
10985 +
10986 +
10987 +#ifdef CONFIG_COMPAT
10988 +
10989 +#include <asm/compat.h>
10990 +
10991 +struct vcmd_read_history_v0_x32 {
10992 +       uint32_t index;
10993 +       uint32_t count;
10994 +       compat_uptr_t data_ptr;
10995 +};
10996 +
10997 +struct vcmd_read_monitor_v0_x32 {
10998 +       uint32_t index;
10999 +       uint32_t count;
11000 +       compat_uptr_t data_ptr;
11001 +};
11002 +
11003 +#endif  /* CONFIG_COMPAT */
11004 +
11005 +extern int vc_dump_history(uint32_t);
11006 +
11007 +extern int vc_read_history(uint32_t, void __user *);
11008 +extern int vc_read_monitor(uint32_t, void __user *);
11009 +
11010 +#ifdef CONFIG_COMPAT
11011 +
11012 +extern int vc_read_history_x32(uint32_t, void __user *);
11013 +extern int vc_read_monitor_x32(uint32_t, void __user *);
11014 +
11015 +#endif  /* CONFIG_COMPAT */
11016 +
11017 +#endif /* _VSERVER_DEBUG_CMD_H */
11018 diff -NurpP --minimal linux-3.9.5/include/linux/vserver/device.h linux-3.9.5-vs2.3.6.5/include/linux/vserver/device.h
11019 --- linux-3.9.5/include/linux/vserver/device.h  1970-01-01 00:00:00.000000000 +0000
11020 +++ linux-3.9.5-vs2.3.6.5/include/linux/vserver/device.h        2013-05-31 14:47:11.000000000 +0000
11021 @@ -0,0 +1,9 @@
11022 +#ifndef _VSERVER_DEVICE_H
11023 +#define _VSERVER_DEVICE_H
11024 +
11025 +
11026 +#include <uapi/vserver/device.h>
11027 +
11028 +#else  /* _VSERVER_DEVICE_H */
11029 +#warning duplicate inclusion
11030 +#endif /* _VSERVER_DEVICE_H */
11031 diff -NurpP --minimal linux-3.9.5/include/linux/vserver/device_cmd.h linux-3.9.5-vs2.3.6.5/include/linux/vserver/device_cmd.h
11032 --- linux-3.9.5/include/linux/vserver/device_cmd.h      1970-01-01 00:00:00.000000000 +0000
11033 +++ linux-3.9.5-vs2.3.6.5/include/linux/vserver/device_cmd.h    2013-05-31 14:47:11.000000000 +0000
11034 @@ -0,0 +1,31 @@
11035 +#ifndef _VSERVER_DEVICE_CMD_H
11036 +#define _VSERVER_DEVICE_CMD_H
11037 +
11038 +#include <uapi/vserver/device_cmd.h>
11039 +
11040 +
11041 +#ifdef CONFIG_COMPAT
11042 +
11043 +#include <asm/compat.h>
11044 +
11045 +struct vcmd_set_mapping_v0_x32 {
11046 +       compat_uptr_t device_ptr;
11047 +       compat_uptr_t target_ptr;
11048 +       uint32_t flags;
11049 +};
11050 +
11051 +#endif /* CONFIG_COMPAT */
11052 +
11053 +#include <linux/compiler.h>
11054 +
11055 +extern int vc_set_mapping(struct vx_info *, void __user *);
11056 +extern int vc_unset_mapping(struct vx_info *, void __user *);
11057 +
11058 +#ifdef CONFIG_COMPAT
11059 +
11060 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
11061 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
11062 +
11063 +#endif /* CONFIG_COMPAT */
11064 +
11065 +#endif /* _VSERVER_DEVICE_CMD_H */
11066 diff -NurpP --minimal linux-3.9.5/include/linux/vserver/device_def.h linux-3.9.5-vs2.3.6.5/include/linux/vserver/device_def.h
11067 --- linux-3.9.5/include/linux/vserver/device_def.h      1970-01-01 00:00:00.000000000 +0000
11068 +++ linux-3.9.5-vs2.3.6.5/include/linux/vserver/device_def.h    2013-05-31 14:47:11.000000000 +0000
11069 @@ -0,0 +1,17 @@
11070 +#ifndef _VSERVER_DEVICE_DEF_H
11071 +#define _VSERVER_DEVICE_DEF_H
11072 +
11073 +#include <linux/types.h>
11074 +
11075 +struct vx_dmap_target {
11076 +       dev_t target;
11077 +       uint32_t flags;
11078 +};
11079 +
11080 +struct _vx_device {
11081 +#ifdef CONFIG_VSERVER_DEVICE
11082 +       struct vx_dmap_target targets[2];
11083 +#endif
11084 +};
11085 +
11086 +#endif /* _VSERVER_DEVICE_DEF_H */
11087 diff -NurpP --minimal linux-3.9.5/include/linux/vserver/dlimit.h linux-3.9.5-vs2.3.6.5/include/linux/vserver/dlimit.h
11088 --- linux-3.9.5/include/linux/vserver/dlimit.h  1970-01-01 00:00:00.000000000 +0000
11089 +++ linux-3.9.5-vs2.3.6.5/include/linux/vserver/dlimit.h        2013-06-12 23:49:09.000000000 +0000
11090 @@ -0,0 +1,54 @@
11091 +#ifndef _VSERVER_DLIMIT_H
11092 +#define _VSERVER_DLIMIT_H
11093 +
11094 +#include "switch.h"
11095 +
11096 +
11097 +#ifdef __KERNEL__
11098 +
11099 +/*      keep in sync with CDLIM_INFINITY       */
11100 +
11101 +#define DLIM_INFINITY          (~0ULL)
11102 +
11103 +#include <linux/spinlock.h>
11104 +#include <linux/rcupdate.h>
11105 +
11106 +struct super_block;
11107 +
11108 +struct dl_info {
11109 +       struct hlist_node dl_hlist;             /* linked list of contexts */
11110 +       struct rcu_head dl_rcu;                 /* the rcu head */
11111 +       vtag_t dl_tag;                          /* context tag */
11112 +       atomic_t dl_usecnt;                     /* usage count */
11113 +       atomic_t dl_refcnt;                     /* reference count */
11114 +
11115 +       struct super_block *dl_sb;              /* associated superblock */
11116 +
11117 +       spinlock_t dl_lock;                     /* protect the values */
11118 +
11119 +       unsigned long long dl_space_used;       /* used space in bytes */
11120 +       unsigned long long dl_space_total;      /* maximum space in bytes */
11121 +       unsigned long dl_inodes_used;           /* used inodes */
11122 +       unsigned long dl_inodes_total;          /* maximum inodes */
11123 +
11124 +       unsigned int dl_nrlmult;                /* non root limit mult */
11125 +};
11126 +
11127 +struct rcu_head;
11128 +
11129 +extern void rcu_free_dl_info(struct rcu_head *);
11130 +extern void unhash_dl_info(struct dl_info *);
11131 +
11132 +extern struct dl_info *locate_dl_info(struct super_block *, vtag_t);
11133 +
11134 +
11135 +struct kstatfs;
11136 +
11137 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
11138 +
11139 +typedef uint64_t dlsize_t;
11140 +
11141 +#endif /* __KERNEL__ */
11142 +#else  /* _VSERVER_DLIMIT_H */
11143 +#warning duplicate inclusion
11144 +#endif /* _VSERVER_DLIMIT_H */
11145 diff -NurpP --minimal linux-3.9.5/include/linux/vserver/dlimit_cmd.h linux-3.9.5-vs2.3.6.5/include/linux/vserver/dlimit_cmd.h
11146 --- linux-3.9.5/include/linux/vserver/dlimit_cmd.h      1970-01-01 00:00:00.000000000 +0000
11147 +++ linux-3.9.5-vs2.3.6.5/include/linux/vserver/dlimit_cmd.h    2013-05-31 14:47:11.000000000 +0000
11148 @@ -0,0 +1,46 @@
11149 +#ifndef _VSERVER_DLIMIT_CMD_H
11150 +#define _VSERVER_DLIMIT_CMD_H
11151 +
11152 +#include <uapi/vserver/dlimit_cmd.h>
11153 +
11154 +
11155 +#ifdef CONFIG_COMPAT
11156 +
11157 +#include <asm/compat.h>
11158 +
11159 +struct vcmd_ctx_dlimit_base_v0_x32 {
11160 +       compat_uptr_t name_ptr;
11161 +       uint32_t flags;
11162 +};
11163 +
11164 +struct vcmd_ctx_dlimit_v0_x32 {
11165 +       compat_uptr_t name_ptr;
11166 +       uint32_t space_used;                    /* used space in kbytes */
11167 +       uint32_t space_total;                   /* maximum space in kbytes */
11168 +       uint32_t inodes_used;                   /* used inodes */
11169 +       uint32_t inodes_total;                  /* maximum inodes */
11170 +       uint32_t reserved;                      /* reserved for root in % */
11171 +       uint32_t flags;
11172 +};
11173 +
11174 +#endif /* CONFIG_COMPAT */
11175 +
11176 +#include <linux/compiler.h>
11177 +
11178 +extern int vc_add_dlimit(uint32_t, void __user *);
11179 +extern int vc_rem_dlimit(uint32_t, void __user *);
11180 +
11181 +extern int vc_set_dlimit(uint32_t, void __user *);
11182 +extern int vc_get_dlimit(uint32_t, void __user *);
11183 +
11184 +#ifdef CONFIG_COMPAT
11185 +
11186 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
11187 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
11188 +
11189 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
11190 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
11191 +
11192 +#endif /* CONFIG_COMPAT */
11193 +
11194 +#endif /* _VSERVER_DLIMIT_CMD_H */
11195 diff -NurpP --minimal linux-3.9.5/include/linux/vserver/global.h linux-3.9.5-vs2.3.6.5/include/linux/vserver/global.h
11196 --- linux-3.9.5/include/linux/vserver/global.h  1970-01-01 00:00:00.000000000 +0000
11197 +++ linux-3.9.5-vs2.3.6.5/include/linux/vserver/global.h        2013-05-31 14:47:11.000000000 +0000
11198 @@ -0,0 +1,19 @@
11199 +#ifndef _VSERVER_GLOBAL_H
11200 +#define _VSERVER_GLOBAL_H
11201 +
11202 +
11203 +extern atomic_t vx_global_ctotal;
11204 +extern atomic_t vx_global_cactive;
11205 +
11206 +extern atomic_t nx_global_ctotal;
11207 +extern atomic_t nx_global_cactive;
11208 +
11209 +extern atomic_t vs_global_nsproxy;
11210 +extern atomic_t vs_global_fs;
11211 +extern atomic_t vs_global_mnt_ns;
11212 +extern atomic_t vs_global_uts_ns;
11213 +extern atomic_t vs_global_user_ns;
11214 +extern atomic_t vs_global_pid_ns;
11215 +
11216 +
11217 +#endif /* _VSERVER_GLOBAL_H */
11218 diff -NurpP --minimal linux-3.9.5/include/linux/vserver/history.h linux-3.9.5-vs2.3.6.5/include/linux/vserver/history.h
11219 --- linux-3.9.5/include/linux/vserver/history.h 1970-01-01 00:00:00.000000000 +0000
11220 +++ linux-3.9.5-vs2.3.6.5/include/linux/vserver/history.h       2013-05-31 14:47:11.000000000 +0000
11221 @@ -0,0 +1,197 @@
11222 +#ifndef _VSERVER_HISTORY_H
11223 +#define _VSERVER_HISTORY_H
11224 +
11225 +
11226 +enum {
11227 +       VXH_UNUSED = 0,
11228 +       VXH_THROW_OOPS = 1,
11229 +
11230 +       VXH_GET_VX_INFO,
11231 +       VXH_PUT_VX_INFO,
11232 +       VXH_INIT_VX_INFO,
11233 +       VXH_SET_VX_INFO,
11234 +       VXH_CLR_VX_INFO,
11235 +       VXH_CLAIM_VX_INFO,
11236 +       VXH_RELEASE_VX_INFO,
11237 +       VXH_ALLOC_VX_INFO,
11238 +       VXH_DEALLOC_VX_INFO,
11239 +       VXH_HASH_VX_INFO,
11240 +       VXH_UNHASH_VX_INFO,
11241 +       VXH_LOC_VX_INFO,
11242 +       VXH_LOOKUP_VX_INFO,
11243 +       VXH_CREATE_VX_INFO,
11244 +};
11245 +
11246 +struct _vxhe_vxi {
11247 +       struct vx_info *ptr;
11248 +       unsigned xid;
11249 +       unsigned usecnt;
11250 +       unsigned tasks;
11251 +};
11252 +
11253 +struct _vxhe_set_clr {
11254 +       void *data;
11255 +};
11256 +
11257 +struct _vxhe_loc_lookup {
11258 +       unsigned arg;
11259 +};
11260 +
11261 +struct _vx_hist_entry {
11262 +       void *loc;
11263 +       unsigned short seq;
11264 +       unsigned short type;
11265 +       struct _vxhe_vxi vxi;
11266 +       union {
11267 +               struct _vxhe_set_clr sc;
11268 +               struct _vxhe_loc_lookup ll;
11269 +       };
11270 +};
11271 +
11272 +#ifdef CONFIG_VSERVER_HISTORY
11273 +
11274 +extern unsigned volatile int vxh_active;
11275 +
11276 +struct _vx_hist_entry *vxh_advance(void *loc);
11277 +
11278 +
11279 +static inline
11280 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
11281 +{
11282 +       entry->vxi.ptr = vxi;
11283 +       if (vxi) {
11284 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
11285 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
11286 +               entry->vxi.xid = vxi->vx_id;
11287 +       }
11288 +}
11289 +
11290 +
11291 +#define        __HERE__ current_text_addr()
11292 +
11293 +#define __VXH_BODY(__type, __data, __here)     \
11294 +       struct _vx_hist_entry *entry;           \
11295 +                                               \
11296 +       preempt_disable();                      \
11297 +       entry = vxh_advance(__here);            \
11298 +       __data;                                 \
11299 +       entry->type = __type;                   \
11300 +       preempt_enable();
11301 +
11302 +
11303 +       /* pass vxi only */
11304 +
11305 +#define __VXH_SMPL                             \
11306 +       __vxh_copy_vxi(entry, vxi)
11307 +
11308 +static inline
11309 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
11310 +{
11311 +       __VXH_BODY(__type, __VXH_SMPL, __here)
11312 +}
11313 +
11314 +       /* pass vxi and data (void *) */
11315 +
11316 +#define __VXH_DATA                             \
11317 +       __vxh_copy_vxi(entry, vxi);             \
11318 +       entry->sc.data = data
11319 +
11320 +static inline
11321 +void   __vxh_data(struct vx_info *vxi, void *data,
11322 +                       int __type, void *__here)
11323 +{
11324 +       __VXH_BODY(__type, __VXH_DATA, __here)
11325 +}
11326 +
11327 +       /* pass vxi and arg (long) */
11328 +
11329 +#define __VXH_LONG                             \
11330 +       __vxh_copy_vxi(entry, vxi);             \
11331 +       entry->ll.arg = arg
11332 +
11333 +static inline
11334 +void   __vxh_long(struct vx_info *vxi, long arg,
11335 +                       int __type, void *__here)
11336 +{
11337 +       __VXH_BODY(__type, __VXH_LONG, __here)
11338 +}
11339 +
11340 +
11341 +static inline
11342 +void   __vxh_throw_oops(void *__here)
11343 +{
11344 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
11345 +       /* prevent further acquisition */
11346 +       vxh_active = 0;
11347 +}
11348 +
11349 +
11350 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
11351 +
11352 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
11353 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
11354 +
11355 +#define __vxh_init_vx_info(v, d, h) \
11356 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
11357 +#define __vxh_set_vx_info(v, d, h) \
11358 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
11359 +#define __vxh_clr_vx_info(v, d, h) \
11360 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
11361 +
11362 +#define __vxh_claim_vx_info(v, d, h) \
11363 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
11364 +#define __vxh_release_vx_info(v, d, h) \
11365 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
11366 +
11367 +#define vxh_alloc_vx_info(v) \
11368 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
11369 +#define vxh_dealloc_vx_info(v) \
11370 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
11371 +
11372 +#define vxh_hash_vx_info(v) \
11373 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
11374 +#define vxh_unhash_vx_info(v) \
11375 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
11376 +
11377 +#define vxh_loc_vx_info(v, l) \
11378 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
11379 +#define vxh_lookup_vx_info(v, l) \
11380 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
11381 +#define vxh_create_vx_info(v, l) \
11382 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
11383 +
11384 +extern void vxh_dump_history(void);
11385 +
11386 +
11387 +#else  /* CONFIG_VSERVER_HISTORY */
11388 +
11389 +#define        __HERE__        0
11390 +
11391 +#define vxh_throw_oops()               do { } while (0)
11392 +
11393 +#define __vxh_get_vx_info(v, h)                do { } while (0)
11394 +#define __vxh_put_vx_info(v, h)                do { } while (0)
11395 +
11396 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
11397 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
11398 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
11399 +
11400 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
11401 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
11402 +
11403 +#define vxh_alloc_vx_info(v)           do { } while (0)
11404 +#define vxh_dealloc_vx_info(v)         do { } while (0)
11405 +
11406 +#define vxh_hash_vx_info(v)            do { } while (0)
11407 +#define vxh_unhash_vx_info(v)          do { } while (0)
11408 +
11409 +#define vxh_loc_vx_info(v, l)          do { } while (0)
11410 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
11411 +#define vxh_create_vx_info(v, l)       do { } while (0)
11412 +
11413 +#define vxh_dump_history()             do { } while (0)
11414 +
11415 +
11416 +#endif /* CONFIG_VSERVER_HISTORY */
11417 +
11418 +#endif /* _VSERVER_HISTORY_H */
11419 diff -NurpP --minimal linux-3.9.5/include/linux/vserver/inode.h linux-3.9.5-vs2.3.6.5/include/linux/vserver/inode.h
11420 --- linux-3.9.5/include/linux/vserver/inode.h   1970-01-01 00:00:00.000000000 +0000
11421 +++ linux-3.9.5-vs2.3.6.5/include/linux/vserver/inode.h 2013-05-31 14:47:11.000000000 +0000
11422 @@ -0,0 +1,19 @@
11423 +#ifndef _VSERVER_INODE_H
11424 +#define _VSERVER_INODE_H
11425 +
11426 +#include <uapi/vserver/inode.h>
11427 +
11428 +
11429 +#ifdef CONFIG_VSERVER_PROC_SECURE
11430 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
11431 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11432 +#else
11433 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
11434 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11435 +#endif
11436 +
11437 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
11438 +
11439 +#else  /* _VSERVER_INODE_H */
11440 +#warning duplicate inclusion
11441 +#endif /* _VSERVER_INODE_H */
11442 diff -NurpP --minimal linux-3.9.5/include/linux/vserver/inode_cmd.h linux-3.9.5-vs2.3.6.5/include/linux/vserver/inode_cmd.h
11443 --- linux-3.9.5/include/linux/vserver/inode_cmd.h       1970-01-01 00:00:00.000000000 +0000
11444 +++ linux-3.9.5-vs2.3.6.5/include/linux/vserver/inode_cmd.h     2013-05-31 14:47:11.000000000 +0000
11445 @@ -0,0 +1,36 @@
11446 +#ifndef _VSERVER_INODE_CMD_H
11447 +#define _VSERVER_INODE_CMD_H
11448 +
11449 +#include <uapi/vserver/inode_cmd.h>
11450 +
11451 +
11452 +
11453 +#ifdef CONFIG_COMPAT
11454 +
11455 +#include <asm/compat.h>
11456 +
11457 +struct vcmd_ctx_iattr_v1_x32 {
11458 +       compat_uptr_t name_ptr;
11459 +       uint32_t tag;
11460 +       uint32_t flags;
11461 +       uint32_t mask;
11462 +};
11463 +
11464 +#endif /* CONFIG_COMPAT */
11465 +
11466 +#include <linux/compiler.h>
11467 +
11468 +extern int vc_get_iattr(void __user *);
11469 +extern int vc_set_iattr(void __user *);
11470 +
11471 +extern int vc_fget_iattr(uint32_t, void __user *);
11472 +extern int vc_fset_iattr(uint32_t, void __user *);
11473 +
11474 +#ifdef CONFIG_COMPAT
11475 +
11476 +extern int vc_get_iattr_x32(void __user *);
11477 +extern int vc_set_iattr_x32(void __user *);
11478 +
11479 +#endif /* CONFIG_COMPAT */
11480 +
11481 +#endif /* _VSERVER_INODE_CMD_H */
11482 diff -NurpP --minimal linux-3.9.5/include/linux/vserver/limit.h linux-3.9.5-vs2.3.6.5/include/linux/vserver/limit.h
11483 --- linux-3.9.5/include/linux/vserver/limit.h   1970-01-01 00:00:00.000000000 +0000
11484 +++ linux-3.9.5-vs2.3.6.5/include/linux/vserver/limit.h 2013-05-31 14:47:11.000000000 +0000
11485 @@ -0,0 +1,61 @@
11486 +#ifndef _VSERVER_LIMIT_H
11487 +#define _VSERVER_LIMIT_H
11488 +
11489 +#include <uapi/vserver/limit.h>
11490 +
11491 +
11492 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
11493 +
11494 +/*     keep in sync with CRLIM_INFINITY */
11495 +
11496 +#define        VLIM_INFINITY   (~0ULL)
11497 +
11498 +#include <asm/atomic.h>
11499 +#include <asm/resource.h>
11500 +
11501 +#ifndef RLIM_INFINITY
11502 +#warning RLIM_INFINITY is undefined
11503 +#endif
11504 +
11505 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
11506 +
11507 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
11508 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
11509 +
11510 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
11511 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
11512 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
11513 +
11514 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
11515 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
11516 +
11517 +typedef atomic_long_t rlim_atomic_t;
11518 +typedef unsigned long rlim_t;
11519 +
11520 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
11521 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
11522 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
11523 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
11524 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
11525 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
11526 +
11527 +
11528 +#if    (RLIM_INFINITY == VLIM_INFINITY)
11529 +#define        VX_VLIM(r) ((long long)(long)(r))
11530 +#define        VX_RLIM(v) ((rlim_t)(v))
11531 +#else
11532 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
11533 +               ? VLIM_INFINITY : (long long)(r))
11534 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
11535 +               ? RLIM_INFINITY : (rlim_t)(v))
11536 +#endif
11537 +
11538 +struct sysinfo;
11539 +
11540 +void vx_vsi_meminfo(struct sysinfo *);
11541 +void vx_vsi_swapinfo(struct sysinfo *);
11542 +long vx_vsi_cached(struct sysinfo *);
11543 +
11544 +#define NUM_LIMITS     24
11545 +
11546 +#endif /* _VSERVER_LIMIT_H */
11547 diff -NurpP --minimal linux-3.9.5/include/linux/vserver/limit_cmd.h linux-3.9.5-vs2.3.6.5/include/linux/vserver/limit_cmd.h
11548 --- linux-3.9.5/include/linux/vserver/limit_cmd.h       1970-01-01 00:00:00.000000000 +0000
11549 +++ linux-3.9.5-vs2.3.6.5/include/linux/vserver/limit_cmd.h     2013-05-31 14:47:11.000000000 +0000
11550 @@ -0,0 +1,35 @@
11551 +#ifndef _VSERVER_LIMIT_CMD_H
11552 +#define _VSERVER_LIMIT_CMD_H
11553 +
11554 +#include <uapi/vserver/limit_cmd.h>
11555 +
11556 +
11557 +#ifdef CONFIG_IA32_EMULATION
11558 +
11559 +struct vcmd_ctx_rlimit_v0_x32 {
11560 +       uint32_t id;
11561 +       uint64_t minimum;
11562 +       uint64_t softlimit;
11563 +       uint64_t maximum;
11564 +} __attribute__ ((packed));
11565 +
11566 +#endif /* CONFIG_IA32_EMULATION */
11567 +
11568 +#include <linux/compiler.h>
11569 +
11570 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
11571 +extern int vc_get_rlimit(struct vx_info *, void __user *);
11572 +extern int vc_set_rlimit(struct vx_info *, void __user *);
11573 +extern int vc_reset_hits(struct vx_info *, void __user *);
11574 +extern int vc_reset_minmax(struct vx_info *, void __user *);
11575 +
11576 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
11577 +
11578 +#ifdef CONFIG_IA32_EMULATION
11579 +
11580 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
11581 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
11582 +
11583 +#endif /* CONFIG_IA32_EMULATION */
11584 +
11585 +#endif /* _VSERVER_LIMIT_CMD_H */
11586 diff -NurpP --minimal linux-3.9.5/include/linux/vserver/limit_def.h linux-3.9.5-vs2.3.6.5/include/linux/vserver/limit_def.h
11587 --- linux-3.9.5/include/linux/vserver/limit_def.h       1970-01-01 00:00:00.000000000 +0000
11588 +++ linux-3.9.5-vs2.3.6.5/include/linux/vserver/limit_def.h     2013-05-31 14:47:11.000000000 +0000
11589 @@ -0,0 +1,47 @@
11590 +#ifndef _VSERVER_LIMIT_DEF_H
11591 +#define _VSERVER_LIMIT_DEF_H
11592 +
11593 +#include <asm/atomic.h>
11594 +#include <asm/resource.h>
11595 +
11596 +#include "limit.h"
11597 +
11598 +
11599 +struct _vx_res_limit {
11600 +       rlim_t soft;            /* Context soft limit */
11601 +       rlim_t hard;            /* Context hard limit */
11602 +
11603 +       rlim_atomic_t rcur;     /* Current value */
11604 +       rlim_t rmin;            /* Context minimum */
11605 +       rlim_t rmax;            /* Context maximum */
11606 +
11607 +       atomic_t lhit;          /* Limit hits */
11608 +};
11609 +
11610 +/* context sub struct */
11611 +
11612 +struct _vx_limit {
11613 +       struct _vx_res_limit res[NUM_LIMITS];
11614 +};
11615 +
11616 +#ifdef CONFIG_VSERVER_DEBUG
11617 +
11618 +static inline void __dump_vx_limit(struct _vx_limit *limit)
11619 +{
11620 +       int i;
11621 +
11622 +       printk("\t_vx_limit:");
11623 +       for (i = 0; i < NUM_LIMITS; i++) {
11624 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
11625 +                       i, (unsigned long)__rlim_get(limit, i),
11626 +                       (unsigned long)__rlim_rmin(limit, i),
11627 +                       (unsigned long)__rlim_rmax(limit, i),
11628 +                       (long)__rlim_soft(limit, i),
11629 +                       (long)__rlim_hard(limit, i),
11630 +                       atomic_read(&__rlim_lhit(limit, i)));
11631 +       }
11632 +}
11633 +
11634 +#endif
11635 +
11636 +#endif /* _VSERVER_LIMIT_DEF_H */
11637 diff -NurpP --minimal linux-3.9.5/include/linux/vserver/limit_int.h linux-3.9.5-vs2.3.6.5/include/linux/vserver/limit_int.h
11638 --- linux-3.9.5/include/linux/vserver/limit_int.h       1970-01-01 00:00:00.000000000 +0000
11639 +++ linux-3.9.5-vs2.3.6.5/include/linux/vserver/limit_int.h     2013-05-31 14:47:11.000000000 +0000
11640 @@ -0,0 +1,193 @@
11641 +#ifndef _VSERVER_LIMIT_INT_H
11642 +#define _VSERVER_LIMIT_INT_H
11643 +
11644 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
11645 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
11646 +
11647 +extern const char *vlimit_name[NUM_LIMITS];
11648 +
11649 +static inline void __vx_acc_cres(struct vx_info *vxi,
11650 +       int res, int dir, void *_data, char *_file, int _line)
11651 +{
11652 +       if (VXD_RCRES_COND(res))
11653 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
11654 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11655 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11656 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
11657 +       if (!vxi)
11658 +               return;
11659 +
11660 +       if (dir > 0)
11661 +               __rlim_inc(&vxi->limit, res);
11662 +       else
11663 +               __rlim_dec(&vxi->limit, res);
11664 +}
11665 +
11666 +static inline void __vx_add_cres(struct vx_info *vxi,
11667 +       int res, int amount, void *_data, char *_file, int _line)
11668 +{
11669 +       if (VXD_RCRES_COND(res))
11670 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
11671 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11672 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11673 +                       amount, _data, _file, _line);
11674 +       if (amount == 0)
11675 +               return;
11676 +       if (!vxi)
11677 +               return;
11678 +       __rlim_add(&vxi->limit, res, amount);
11679 +}
11680 +
11681 +static inline
11682 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
11683 +{
11684 +       int cond = (value > __rlim_rmax(limit, res));
11685 +
11686 +       if (cond)
11687 +               __rlim_rmax(limit, res) = value;
11688 +       return cond;
11689 +}
11690 +
11691 +static inline
11692 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
11693 +{
11694 +       int cond = (value < __rlim_rmin(limit, res));
11695 +
11696 +       if (cond)
11697 +               __rlim_rmin(limit, res) = value;
11698 +       return cond;
11699 +}
11700 +
11701 +static inline
11702 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
11703 +{
11704 +       if (!__vx_cres_adjust_max(limit, res, value))
11705 +               __vx_cres_adjust_min(limit, res, value);
11706 +}
11707 +
11708 +
11709 +/*     return values:
11710 +        +1 ... no limit hit
11711 +        -1 ... over soft limit
11712 +         0 ... over hard limit         */
11713 +
11714 +static inline int __vx_cres_avail(struct vx_info *vxi,
11715 +       int res, int num, char *_file, int _line)
11716 +{
11717 +       struct _vx_limit *limit;
11718 +       rlim_t value;
11719 +
11720 +       if (VXD_RLIMIT_COND(res))
11721 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
11722 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11723 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
11724 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
11725 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11726 +                       num, _file, _line);
11727 +       if (!vxi)
11728 +               return 1;
11729 +
11730 +       limit = &vxi->limit;
11731 +       value = __rlim_get(limit, res);
11732 +
11733 +       if (!__vx_cres_adjust_max(limit, res, value))
11734 +               __vx_cres_adjust_min(limit, res, value);
11735 +
11736 +       if (num == 0)
11737 +               return 1;
11738 +
11739 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
11740 +               return -1;
11741 +       if (value + num <= __rlim_soft(limit, res))
11742 +               return -1;
11743 +
11744 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
11745 +               return 1;
11746 +       if (value + num <= __rlim_hard(limit, res))
11747 +               return 1;
11748 +
11749 +       __rlim_hit(limit, res);
11750 +       return 0;
11751 +}
11752 +
11753 +
11754 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
11755 +
11756 +static inline
11757 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
11758 +{
11759 +       rlim_t value, sum = 0;
11760 +       int res;
11761 +
11762 +       while ((res = *array++)) {
11763 +               value = __rlim_get(limit, res);
11764 +               __vx_cres_fixup(limit, res, value);
11765 +               sum += value;
11766 +       }
11767 +       return sum;
11768 +}
11769 +
11770 +static inline
11771 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
11772 +{
11773 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
11774 +       int res = *array;
11775 +
11776 +       if (value == __rlim_get(limit, res))
11777 +               return value;
11778 +
11779 +       __rlim_set(limit, res, value);
11780 +       /* now adjust min/max */
11781 +       if (!__vx_cres_adjust_max(limit, res, value))
11782 +               __vx_cres_adjust_min(limit, res, value);
11783 +
11784 +       return value;
11785 +}
11786 +
11787 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
11788 +       const int *array, int num, char *_file, int _line)
11789 +{
11790 +       struct _vx_limit *limit;
11791 +       rlim_t value = 0;
11792 +       int res;
11793 +
11794 +       if (num == 0)
11795 +               return 1;
11796 +       if (!vxi)
11797 +               return 1;
11798 +
11799 +       limit = &vxi->limit;
11800 +       res = *array;
11801 +       value = __vx_cres_array_sum(limit, array + 1);
11802 +
11803 +       __rlim_set(limit, res, value);
11804 +       __vx_cres_fixup(limit, res, value);
11805 +
11806 +       return __vx_cres_avail(vxi, res, num, _file, _line);
11807 +}
11808 +
11809 +
11810 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
11811 +{
11812 +       rlim_t value;
11813 +       int res;
11814 +
11815 +       /* complex resources first */
11816 +       if ((id < 0) || (id == RLIMIT_RSS))
11817 +               __vx_cres_array_fixup(limit, VLA_RSS);
11818 +
11819 +       for (res = 0; res < NUM_LIMITS; res++) {
11820 +               if ((id > 0) && (res != id))
11821 +                       continue;
11822 +
11823 +               value = __rlim_get(limit, res);
11824 +               __vx_cres_fixup(limit, res, value);
11825 +
11826 +               /* not supposed to happen, maybe warn? */
11827 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
11828 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
11829 +       }
11830 +}
11831 +
11832 +
11833 +#endif /* _VSERVER_LIMIT_INT_H */
11834 diff -NurpP --minimal linux-3.9.5/include/linux/vserver/monitor.h linux-3.9.5-vs2.3.6.5/include/linux/vserver/monitor.h
11835 --- linux-3.9.5/include/linux/vserver/monitor.h 1970-01-01 00:00:00.000000000 +0000
11836 +++ linux-3.9.5-vs2.3.6.5/include/linux/vserver/monitor.h       2013-05-31 14:47:11.000000000 +0000
11837 @@ -0,0 +1,6 @@
11838 +#ifndef _VSERVER_MONITOR_H
11839 +#define _VSERVER_MONITOR_H
11840 +
11841 +#include <uapi/vserver/monitor.h>
11842 +
11843 +#endif /* _VSERVER_MONITOR_H */
11844 diff -NurpP --minimal linux-3.9.5/include/linux/vserver/network.h linux-3.9.5-vs2.3.6.5/include/linux/vserver/network.h
11845 --- linux-3.9.5/include/linux/vserver/network.h 1970-01-01 00:00:00.000000000 +0000
11846 +++ linux-3.9.5-vs2.3.6.5/include/linux/vserver/network.h       2013-06-12 23:49:09.000000000 +0000
11847 @@ -0,0 +1,76 @@
11848 +#ifndef _VSERVER_NETWORK_H
11849 +#define _VSERVER_NETWORK_H
11850 +
11851 +
11852 +#include <linux/list.h>
11853 +#include <linux/spinlock.h>
11854 +#include <linux/rcupdate.h>
11855 +#include <linux/in.h>
11856 +#include <linux/in6.h>
11857 +#include <asm/atomic.h>
11858 +#include <uapi/vserver/network.h>
11859 +
11860 +struct nx_addr_v4 {
11861 +       struct nx_addr_v4 *next;
11862 +       struct in_addr ip[2];
11863 +       struct in_addr mask;
11864 +       uint16_t type;
11865 +       uint16_t flags;
11866 +};
11867 +
11868 +struct nx_addr_v6 {
11869 +       struct nx_addr_v6 *next;
11870 +       struct in6_addr ip;
11871 +       struct in6_addr mask;
11872 +       uint32_t prefix;
11873 +       uint16_t type;
11874 +       uint16_t flags;
11875 +};
11876 +
11877 +struct nx_info {
11878 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
11879 +       vnid_t nx_id;                   /* vnet id */
11880 +       atomic_t nx_usecnt;             /* usage count */
11881 +       atomic_t nx_tasks;              /* tasks count */
11882 +       int nx_state;                   /* context state */
11883 +
11884 +       uint64_t nx_flags;              /* network flag word */
11885 +       uint64_t nx_ncaps;              /* network capabilities */
11886 +
11887 +       spinlock_t addr_lock;           /* protect address changes */
11888 +       struct in_addr v4_lback;        /* Loopback address */
11889 +       struct in_addr v4_bcast;        /* Broadcast address */
11890 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
11891 +#ifdef CONFIG_IPV6
11892 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
11893 +#endif
11894 +       char nx_name[65];               /* network context name */
11895 +};
11896 +
11897 +
11898 +/* status flags */
11899 +
11900 +#define NXS_HASHED      0x0001
11901 +#define NXS_SHUTDOWN    0x0100
11902 +#define NXS_RELEASED    0x8000
11903 +
11904 +extern struct nx_info *lookup_nx_info(int);
11905 +
11906 +extern int get_nid_list(int, unsigned int *, int);
11907 +extern int nid_is_hashed(vnid_t);
11908 +
11909 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
11910 +
11911 +extern long vs_net_change(struct nx_info *, unsigned int);
11912 +
11913 +struct sock;
11914 +
11915 +
11916 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
11917 +#ifdef  CONFIG_IPV6
11918 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
11919 +#else
11920 +#define NX_IPV6(n)     (0)
11921 +#endif
11922 +
11923 +#endif /* _VSERVER_NETWORK_H */
11924 diff -NurpP --minimal linux-3.9.5/include/linux/vserver/network_cmd.h linux-3.9.5-vs2.3.6.5/include/linux/vserver/network_cmd.h
11925 --- linux-3.9.5/include/linux/vserver/network_cmd.h     1970-01-01 00:00:00.000000000 +0000
11926 +++ linux-3.9.5-vs2.3.6.5/include/linux/vserver/network_cmd.h   2013-05-31 14:47:11.000000000 +0000
11927 @@ -0,0 +1,37 @@
11928 +#ifndef _VSERVER_NETWORK_CMD_H
11929 +#define _VSERVER_NETWORK_CMD_H
11930 +
11931 +#include <uapi/vserver/network_cmd.h>
11932 +
11933 +extern int vc_task_nid(uint32_t);
11934 +
11935 +extern int vc_nx_info(struct nx_info *, void __user *);
11936 +
11937 +extern int vc_net_create(uint32_t, void __user *);
11938 +extern int vc_net_migrate(struct nx_info *, void __user *);
11939 +
11940 +extern int vc_net_add(struct nx_info *, void __user *);
11941 +extern int vc_net_remove(struct nx_info *, void __user *);
11942 +
11943 +extern int vc_net_add_ipv4_v1(struct nx_info *, void __user *);
11944 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
11945 +
11946 +extern int vc_net_rem_ipv4_v1(struct nx_info *, void __user *);
11947 +extern int vc_net_rem_ipv4(struct nx_info *, void __user *);
11948 +
11949 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
11950 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
11951 +
11952 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
11953 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
11954 +
11955 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
11956 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
11957 +
11958 +extern int vc_get_nflags(struct nx_info *, void __user *);
11959 +extern int vc_set_nflags(struct nx_info *, void __user *);
11960 +
11961 +extern int vc_get_ncaps(struct nx_info *, void __user *);
11962 +extern int vc_set_ncaps(struct nx_info *, void __user *);
11963 +
11964 +#endif /* _VSERVER_CONTEXT_CMD_H */
11965 diff -NurpP --minimal linux-3.9.5/include/linux/vserver/percpu.h linux-3.9.5-vs2.3.6.5/include/linux/vserver/percpu.h
11966 --- linux-3.9.5/include/linux/vserver/percpu.h  1970-01-01 00:00:00.000000000 +0000
11967 +++ linux-3.9.5-vs2.3.6.5/include/linux/vserver/percpu.h        2013-05-31 14:47:11.000000000 +0000
11968 @@ -0,0 +1,14 @@
11969 +#ifndef _VSERVER_PERCPU_H
11970 +#define _VSERVER_PERCPU_H
11971 +
11972 +#include "cvirt_def.h"
11973 +#include "sched_def.h"
11974 +
11975 +struct _vx_percpu {
11976 +       struct _vx_cvirt_pc cvirt;
11977 +       struct _vx_sched_pc sched;
11978 +};
11979 +
11980 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
11981 +
11982 +#endif /* _VSERVER_PERCPU_H */
11983 diff -NurpP --minimal linux-3.9.5/include/linux/vserver/pid.h linux-3.9.5-vs2.3.6.5/include/linux/vserver/pid.h
11984 --- linux-3.9.5/include/linux/vserver/pid.h     1970-01-01 00:00:00.000000000 +0000
11985 +++ linux-3.9.5-vs2.3.6.5/include/linux/vserver/pid.h   2013-05-31 14:47:11.000000000 +0000
11986 @@ -0,0 +1,51 @@
11987 +#ifndef _VSERVER_PID_H
11988 +#define _VSERVER_PID_H
11989 +
11990 +/* pid faking stuff */
11991 +
11992 +#define vx_info_map_pid(v, p) \
11993 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
11994 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
11995 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
11996 +#define vx_map_tgid(p) vx_map_pid(p)
11997 +
11998 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
11999 +       const char *func, const char *file, int line)
12000 +{
12001 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12002 +               vxfprintk(VXD_CBIT(cvirt, 2),
12003 +                       "vx_map_tgid: %p/%llx: %d -> %d",
12004 +                       vxi, (long long)vxi->vx_flags, pid,
12005 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
12006 +                       func, file, line);
12007 +               if (pid == 0)
12008 +                       return 0;
12009 +               if (pid == vxi->vx_initpid)
12010 +                       return 1;
12011 +       }
12012 +       return pid;
12013 +}
12014 +
12015 +#define vx_info_rmap_pid(v, p) \
12016 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
12017 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
12018 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
12019 +
12020 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
12021 +       const char *func, const char *file, int line)
12022 +{
12023 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12024 +               vxfprintk(VXD_CBIT(cvirt, 2),
12025 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
12026 +                       vxi, (long long)vxi->vx_flags, pid,
12027 +                       (pid == 1) ? vxi->vx_initpid : pid,
12028 +                       func, file, line);
12029 +               if ((pid == 1) && vxi->vx_initpid)
12030 +                       return vxi->vx_initpid;
12031 +               if (pid == vxi->vx_initpid)
12032 +                       return ~0U;
12033 +       }
12034 +       return pid;
12035 +}
12036 +
12037 +#endif
12038 diff -NurpP --minimal linux-3.9.5/include/linux/vserver/sched.h linux-3.9.5-vs2.3.6.5/include/linux/vserver/sched.h
12039 --- linux-3.9.5/include/linux/vserver/sched.h   1970-01-01 00:00:00.000000000 +0000
12040 +++ linux-3.9.5-vs2.3.6.5/include/linux/vserver/sched.h 2013-05-31 14:47:11.000000000 +0000
12041 @@ -0,0 +1,23 @@
12042 +#ifndef _VSERVER_SCHED_H
12043 +#define _VSERVER_SCHED_H
12044 +
12045 +
12046 +#ifdef __KERNEL__
12047 +
12048 +struct timespec;
12049 +
12050 +void vx_vsi_uptime(struct timespec *, struct timespec *);
12051 +
12052 +
12053 +struct vx_info;
12054 +
12055 +void vx_update_load(struct vx_info *);
12056 +
12057 +
12058 +void vx_update_sched_param(struct _vx_sched *sched,
12059 +       struct _vx_sched_pc *sched_pc);
12060 +
12061 +#endif /* __KERNEL__ */
12062 +#else  /* _VSERVER_SCHED_H */
12063 +#warning duplicate inclusion
12064 +#endif /* _VSERVER_SCHED_H */
12065 diff -NurpP --minimal linux-3.9.5/include/linux/vserver/sched_cmd.h linux-3.9.5-vs2.3.6.5/include/linux/vserver/sched_cmd.h
12066 --- linux-3.9.5/include/linux/vserver/sched_cmd.h       1970-01-01 00:00:00.000000000 +0000
12067 +++ linux-3.9.5-vs2.3.6.5/include/linux/vserver/sched_cmd.h     2013-05-31 14:47:11.000000000 +0000
12068 @@ -0,0 +1,11 @@
12069 +#ifndef _VSERVER_SCHED_CMD_H
12070 +#define _VSERVER_SCHED_CMD_H
12071 +
12072 +
12073 +#include <linux/compiler.h>
12074 +#include <uapi/vserver/sched_cmd.h>
12075 +
12076 +extern int vc_set_prio_bias(struct vx_info *, void __user *);
12077 +extern int vc_get_prio_bias(struct vx_info *, void __user *);
12078 +
12079 +#endif /* _VSERVER_SCHED_CMD_H */
12080 diff -NurpP --minimal linux-3.9.5/include/linux/vserver/sched_def.h linux-3.9.5-vs2.3.6.5/include/linux/vserver/sched_def.h
12081 --- linux-3.9.5/include/linux/vserver/sched_def.h       1970-01-01 00:00:00.000000000 +0000
12082 +++ linux-3.9.5-vs2.3.6.5/include/linux/vserver/sched_def.h     2013-05-31 14:47:11.000000000 +0000
12083 @@ -0,0 +1,38 @@
12084 +#ifndef _VSERVER_SCHED_DEF_H
12085 +#define _VSERVER_SCHED_DEF_H
12086 +
12087 +#include <linux/spinlock.h>
12088 +#include <linux/jiffies.h>
12089 +#include <linux/cpumask.h>
12090 +#include <asm/atomic.h>
12091 +#include <asm/param.h>
12092 +
12093 +
12094 +/* context sub struct */
12095 +
12096 +struct _vx_sched {
12097 +       int prio_bias;                  /* bias offset for priority */
12098 +
12099 +       cpumask_t update;               /* CPUs which should update */
12100 +};
12101 +
12102 +struct _vx_sched_pc {
12103 +       int prio_bias;                  /* bias offset for priority */
12104 +
12105 +       uint64_t user_ticks;            /* token tick events */
12106 +       uint64_t sys_ticks;             /* token tick events */
12107 +       uint64_t hold_ticks;            /* token ticks paused */
12108 +};
12109 +
12110 +
12111 +#ifdef CONFIG_VSERVER_DEBUG
12112 +
12113 +static inline void __dump_vx_sched(struct _vx_sched *sched)
12114 +{
12115 +       printk("\t_vx_sched:\n");
12116 +       printk("\t priority = %4d\n", sched->prio_bias);
12117 +}
12118 +
12119 +#endif
12120 +
12121 +#endif /* _VSERVER_SCHED_DEF_H */
12122 diff -NurpP --minimal linux-3.9.5/include/linux/vserver/signal.h linux-3.9.5-vs2.3.6.5/include/linux/vserver/signal.h
12123 --- linux-3.9.5/include/linux/vserver/signal.h  1970-01-01 00:00:00.000000000 +0000
12124 +++ linux-3.9.5-vs2.3.6.5/include/linux/vserver/signal.h        2013-05-31 14:47:11.000000000 +0000
12125 @@ -0,0 +1,14 @@
12126 +#ifndef _VSERVER_SIGNAL_H
12127 +#define _VSERVER_SIGNAL_H
12128 +
12129 +
12130 +#ifdef __KERNEL__
12131 +
12132 +struct vx_info;
12133 +
12134 +int vx_info_kill(struct vx_info *, int, int);
12135 +
12136 +#endif /* __KERNEL__ */
12137 +#else  /* _VSERVER_SIGNAL_H */
12138 +#warning duplicate inclusion
12139 +#endif /* _VSERVER_SIGNAL_H */
12140 diff -NurpP --minimal linux-3.9.5/include/linux/vserver/signal_cmd.h linux-3.9.5-vs2.3.6.5/include/linux/vserver/signal_cmd.h
12141 --- linux-3.9.5/include/linux/vserver/signal_cmd.h      1970-01-01 00:00:00.000000000 +0000
12142 +++ linux-3.9.5-vs2.3.6.5/include/linux/vserver/signal_cmd.h    2013-05-31 14:47:11.000000000 +0000
12143 @@ -0,0 +1,14 @@
12144 +#ifndef _VSERVER_SIGNAL_CMD_H
12145 +#define _VSERVER_SIGNAL_CMD_H
12146 +
12147 +#include <uapi/vserver/signal_cmd.h>
12148 +
12149 +
12150 +extern int vc_ctx_kill(struct vx_info *, void __user *);
12151 +extern int vc_wait_exit(struct vx_info *, void __user *);
12152 +
12153 +
12154 +extern int vc_get_pflags(uint32_t pid, void __user *);
12155 +extern int vc_set_pflags(uint32_t pid, void __user *);
12156 +
12157 +#endif /* _VSERVER_SIGNAL_CMD_H */
12158 diff -NurpP --minimal linux-3.9.5/include/linux/vserver/space.h linux-3.9.5-vs2.3.6.5/include/linux/vserver/space.h
12159 --- linux-3.9.5/include/linux/vserver/space.h   1970-01-01 00:00:00.000000000 +0000
12160 +++ linux-3.9.5-vs2.3.6.5/include/linux/vserver/space.h 2013-05-31 14:47:11.000000000 +0000
12161 @@ -0,0 +1,12 @@
12162 +#ifndef _VSERVER_SPACE_H
12163 +#define _VSERVER_SPACE_H
12164 +
12165 +#include <linux/types.h>
12166 +
12167 +struct vx_info;
12168 +
12169 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
12170 +
12171 +#else  /* _VSERVER_SPACE_H */
12172 +#warning duplicate inclusion
12173 +#endif /* _VSERVER_SPACE_H */
12174 diff -NurpP --minimal linux-3.9.5/include/linux/vserver/space_cmd.h linux-3.9.5-vs2.3.6.5/include/linux/vserver/space_cmd.h
12175 --- linux-3.9.5/include/linux/vserver/space_cmd.h       1970-01-01 00:00:00.000000000 +0000
12176 +++ linux-3.9.5-vs2.3.6.5/include/linux/vserver/space_cmd.h     2013-05-31 14:47:11.000000000 +0000
12177 @@ -0,0 +1,13 @@
12178 +#ifndef _VSERVER_SPACE_CMD_H
12179 +#define _VSERVER_SPACE_CMD_H
12180 +
12181 +#include <uapi/vserver/space_cmd.h>
12182 +
12183 +
12184 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
12185 +extern int vc_set_space_v1(struct vx_info *, void __user *);
12186 +extern int vc_enter_space(struct vx_info *, void __user *);
12187 +extern int vc_set_space(struct vx_info *, void __user *);
12188 +extern int vc_get_space_mask(void __user *, int);
12189 +
12190 +#endif /* _VSERVER_SPACE_CMD_H */
12191 diff -NurpP --minimal linux-3.9.5/include/linux/vserver/switch.h linux-3.9.5-vs2.3.6.5/include/linux/vserver/switch.h
12192 --- linux-3.9.5/include/linux/vserver/switch.h  1970-01-01 00:00:00.000000000 +0000
12193 +++ linux-3.9.5-vs2.3.6.5/include/linux/vserver/switch.h        2013-05-31 14:47:11.000000000 +0000
12194 @@ -0,0 +1,8 @@
12195 +#ifndef _VSERVER_SWITCH_H
12196 +#define _VSERVER_SWITCH_H
12197 +
12198 +
12199 +#include <linux/errno.h>
12200 +#include <uapi/vserver/switch.h>
12201 +
12202 +#endif /* _VSERVER_SWITCH_H */
12203 diff -NurpP --minimal linux-3.9.5/include/linux/vserver/tag.h linux-3.9.5-vs2.3.6.5/include/linux/vserver/tag.h
12204 --- linux-3.9.5/include/linux/vserver/tag.h     1970-01-01 00:00:00.000000000 +0000
12205 +++ linux-3.9.5-vs2.3.6.5/include/linux/vserver/tag.h   2013-06-12 23:49:09.000000000 +0000
12206 @@ -0,0 +1,160 @@
12207 +#ifndef _DX_TAG_H
12208 +#define _DX_TAG_H
12209 +
12210 +#include <linux/types.h>
12211 +#include <linux/uidgid.h>
12212 +
12213 +
12214 +#define DX_TAG(in)     (IS_TAGGED(in))
12215 +
12216 +
12217 +#ifdef CONFIG_TAG_NFSD
12218 +#define DX_TAG_NFSD    1
12219 +#else
12220 +#define DX_TAG_NFSD    0
12221 +#endif
12222 +
12223 +
12224 +#ifdef CONFIG_TAGGING_NONE
12225 +
12226 +#define MAX_UID                0xFFFFFFFF
12227 +#define MAX_GID                0xFFFFFFFF
12228 +
12229 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
12230 +
12231 +#define TAGINO_UID(cond, uid, tag)     (uid)
12232 +#define TAGINO_GID(cond, gid, tag)     (gid)
12233 +
12234 +#endif
12235 +
12236 +
12237 +#ifdef CONFIG_TAGGING_GID16
12238 +
12239 +#define MAX_UID                0xFFFFFFFF
12240 +#define MAX_GID                0x0000FFFF
12241 +
12242 +#define INOTAG_TAG(cond, uid, gid, tag)        \
12243 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
12244 +
12245 +#define TAGINO_UID(cond, uid, tag)     (uid)
12246 +#define TAGINO_GID(cond, gid, tag)     \
12247 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
12248 +
12249 +#endif
12250 +
12251 +
12252 +#ifdef CONFIG_TAGGING_ID24
12253 +
12254 +#define MAX_UID                0x00FFFFFF
12255 +#define MAX_GID                0x00FFFFFF
12256 +
12257 +#define INOTAG_TAG(cond, uid, gid, tag)        \
12258 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
12259 +
12260 +#define TAGINO_UID(cond, uid, tag)     \
12261 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
12262 +#define TAGINO_GID(cond, gid, tag)     \
12263 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
12264 +
12265 +#endif
12266 +
12267 +
12268 +#ifdef CONFIG_TAGGING_UID16
12269 +
12270 +#define MAX_UID                0x0000FFFF
12271 +#define MAX_GID                0xFFFFFFFF
12272 +
12273 +#define INOTAG_TAG(cond, uid, gid, tag)        \
12274 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
12275 +
12276 +#define TAGINO_UID(cond, uid, tag)     \
12277 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
12278 +#define TAGINO_GID(cond, gid, tag)     (gid)
12279 +
12280 +#endif
12281 +
12282 +
12283 +#ifdef CONFIG_TAGGING_INTERN
12284 +
12285 +#define MAX_UID                0xFFFFFFFF
12286 +#define MAX_GID                0xFFFFFFFF
12287 +
12288 +#define INOTAG_TAG(cond, uid, gid, tag)        \
12289 +       ((cond) ? (tag) : 0)
12290 +
12291 +#define TAGINO_UID(cond, uid, tag)     (uid)
12292 +#define TAGINO_GID(cond, gid, tag)     (gid)
12293 +
12294 +#endif
12295 +
12296 +
12297 +#ifndef CONFIG_TAGGING_NONE
12298 +#define dx_current_fstag(sb)   \
12299 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
12300 +#else
12301 +#define dx_current_fstag(sb)   (0)
12302 +#endif
12303 +
12304 +#ifndef CONFIG_TAGGING_INTERN
12305 +#define TAGINO_TAG(cond, tag)  (0)
12306 +#else
12307 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
12308 +#endif
12309 +
12310 +#define TAGINO_KUID(cond, kuid, ktag)  \
12311 +       KUIDT_INIT(TAGINO_UID(cond, __kuid_val(kuid), __ktag_val(ktag)))
12312 +#define TAGINO_KGID(cond, kgid, ktag)  \
12313 +       KGIDT_INIT(TAGINO_GID(cond, __kgid_val(kgid), __ktag_val(ktag)))
12314 +#define TAGINO_KTAG(cond, ktag)                \
12315 +       KTAGT_INIT(TAGINO_TAG(cond, __ktag_val(ktag)))
12316 +
12317 +
12318 +#define INOTAG_UID(cond, uid, gid)     \
12319 +       ((cond) ? ((uid) & MAX_UID) : (uid))
12320 +#define INOTAG_GID(cond, uid, gid)     \
12321 +       ((cond) ? ((gid) & MAX_GID) : (gid))
12322 +
12323 +#define INOTAG_KUID(cond, kuid, kgid)  \
12324 +       KUIDT_INIT(INOTAG_UID(cond, __kuid_val(kuid), __kgid_val(kgid)))
12325 +#define INOTAG_KGID(cond, kuid, kgid)  \
12326 +       KGIDT_INIT(INOTAG_GID(cond, __kuid_val(kuid), __kgid_val(kgid)))
12327 +#define INOTAG_KTAG(cond, kuid, kgid, ktag) \
12328 +       KTAGT_INIT(INOTAG_TAG(cond, \
12329 +               __kuid_val(kuid), __kgid_val(kgid), __ktag_val(ktag)))
12330 +
12331 +
12332 +static inline uid_t dx_map_uid(uid_t uid)
12333 +{
12334 +       if ((uid > MAX_UID) && (uid != -1))
12335 +               uid = -2;
12336 +       return (uid & MAX_UID);
12337 +}
12338 +
12339 +static inline gid_t dx_map_gid(gid_t gid)
12340 +{
12341 +       if ((gid > MAX_GID) && (gid != -1))
12342 +               gid = -2;
12343 +       return (gid & MAX_GID);
12344 +}
12345 +
12346 +struct peer_tag {
12347 +       int32_t xid;
12348 +       int32_t nid;
12349 +};
12350 +
12351 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
12352 +
12353 +int dx_parse_tag(char *string, vtag_t *tag, int remove, int *mnt_flags,
12354 +                unsigned long *flags);
12355 +
12356 +#ifdef CONFIG_PROPAGATE
12357 +
12358 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
12359 +
12360 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
12361 +
12362 +#else
12363 +#define dx_propagate_tag(n, i) do { } while (0)
12364 +#endif
12365 +
12366 +#endif /* _DX_TAG_H */
12367 diff -NurpP --minimal linux-3.9.5/include/linux/vserver/tag_cmd.h linux-3.9.5-vs2.3.6.5/include/linux/vserver/tag_cmd.h
12368 --- linux-3.9.5/include/linux/vserver/tag_cmd.h 1970-01-01 00:00:00.000000000 +0000
12369 +++ linux-3.9.5-vs2.3.6.5/include/linux/vserver/tag_cmd.h       2013-05-31 14:47:11.000000000 +0000
12370 @@ -0,0 +1,10 @@
12371 +#ifndef _VSERVER_TAG_CMD_H
12372 +#define _VSERVER_TAG_CMD_H
12373 +
12374 +#include <uapi/vserver/tag_cmd.h>
12375 +
12376 +extern int vc_task_tag(uint32_t);
12377 +
12378 +extern int vc_tag_migrate(uint32_t);
12379 +
12380 +#endif /* _VSERVER_TAG_CMD_H */
12381 diff -NurpP --minimal linux-3.9.5/include/net/addrconf.h linux-3.9.5-vs2.3.6.5/include/net/addrconf.h
12382 --- linux-3.9.5/include/net/addrconf.h  2013-05-31 13:45:28.000000000 +0000
12383 +++ linux-3.9.5-vs2.3.6.5/include/net/addrconf.h        2013-05-31 17:17:53.000000000 +0000
12384 @@ -85,7 +85,8 @@ extern int                    ipv6_dev_get_saddr(struct n
12385                                                const struct net_device *dev,
12386                                                const struct in6_addr *daddr,
12387                                                unsigned int srcprefs,
12388 -                                              struct in6_addr *saddr);
12389 +                                              struct in6_addr *saddr,
12390 +                                              struct nx_info *nxi);
12391  extern int                     ipv6_get_lladdr(struct net_device *dev,
12392                                                 struct in6_addr *addr,
12393                                                 unsigned char banned_flags);
12394 diff -NurpP --minimal linux-3.9.5/include/net/af_unix.h linux-3.9.5-vs2.3.6.5/include/net/af_unix.h
12395 --- linux-3.9.5/include/net/af_unix.h   2013-02-19 13:58:52.000000000 +0000
12396 +++ linux-3.9.5-vs2.3.6.5/include/net/af_unix.h 2013-05-31 17:17:53.000000000 +0000
12397 @@ -4,6 +4,7 @@
12398  #include <linux/socket.h>
12399  #include <linux/un.h>
12400  #include <linux/mutex.h>
12401 +#include <linux/vs_base.h>
12402  #include <net/sock.h>
12403  
12404  extern void unix_inflight(struct file *fp);
12405 diff -NurpP --minimal linux-3.9.5/include/net/inet_timewait_sock.h linux-3.9.5-vs2.3.6.5/include/net/inet_timewait_sock.h
12406 --- linux-3.9.5/include/net/inet_timewait_sock.h        2013-05-31 13:45:28.000000000 +0000
12407 +++ linux-3.9.5-vs2.3.6.5/include/net/inet_timewait_sock.h      2013-05-31 17:18:34.000000000 +0000
12408 @@ -116,6 +116,10 @@ struct inet_timewait_sock {
12409  #define tw_dport               __tw_common.skc_dport
12410  #define tw_num                 __tw_common.skc_num
12411  #define tw_portpair            __tw_common.skc_portpair
12412 +#define tw_xid                 __tw_common.skc_xid
12413 +#define tw_vx_info             __tw_common.skc_vx_info
12414 +#define tw_nid                 __tw_common.skc_nid
12415 +#define tw_nx_info             __tw_common.skc_nx_info
12416  
12417         int                     tw_timeout;
12418         volatile unsigned char  tw_substate;
12419 diff -NurpP --minimal linux-3.9.5/include/net/ip6_route.h linux-3.9.5-vs2.3.6.5/include/net/ip6_route.h
12420 --- linux-3.9.5/include/net/ip6_route.h 2013-05-31 13:45:28.000000000 +0000
12421 +++ linux-3.9.5-vs2.3.6.5/include/net/ip6_route.h       2013-05-31 17:17:53.000000000 +0000
12422 @@ -95,7 +95,8 @@ extern int                    ip6_route_get_saddr(struct
12423                                                     struct rt6_info *rt,
12424                                                     const struct in6_addr *daddr,
12425                                                     unsigned int prefs,
12426 -                                                   struct in6_addr *saddr);
12427 +                                                   struct in6_addr *saddr,
12428 +                                                   struct nx_info *nxi);
12429  
12430  extern struct rt6_info         *rt6_lookup(struct net *net,
12431                                             const struct in6_addr *daddr,
12432 diff -NurpP --minimal linux-3.9.5/include/net/route.h linux-3.9.5-vs2.3.6.5/include/net/route.h
12433 --- linux-3.9.5/include/net/route.h     2013-02-19 13:58:52.000000000 +0000
12434 +++ linux-3.9.5-vs2.3.6.5/include/net/route.h   2013-05-31 17:17:53.000000000 +0000
12435 @@ -207,6 +207,9 @@ static inline void ip_rt_put(struct rtab
12436         dst_release(&rt->dst);
12437  }
12438  
12439 +#include <linux/vs_base.h>
12440 +#include <linux/vs_inet.h>
12441 +
12442  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
12443  
12444  extern const __u8 ip_tos2prio[16];
12445 @@ -256,6 +259,9 @@ static inline void ip_route_connect_init
12446                            protocol, flow_flags, dst, src, dport, sport);
12447  }
12448  
12449 +extern struct rtable *ip_v4_find_src(struct net *net, struct nx_info *,
12450 +       struct flowi4 *);
12451 +
12452  static inline struct rtable *ip_route_connect(struct flowi4 *fl4,
12453                                               __be32 dst, __be32 src, u32 tos,
12454                                               int oif, u8 protocol,
12455 @@ -264,11 +270,25 @@ static inline struct rtable *ip_route_co
12456  {
12457         struct net *net = sock_net(sk);
12458         struct rtable *rt;
12459 +       struct nx_info *nx_info = current_nx_info();
12460  
12461         ip_route_connect_init(fl4, dst, src, tos, oif, protocol,
12462                               sport, dport, sk, can_sleep);
12463  
12464 -       if (!dst || !src) {
12465 +       if (sk)
12466 +               nx_info = sk->sk_nx_info;
12467 +
12468 +       vxdprintk(VXD_CBIT(net, 4),
12469 +               "ip_route_connect(%p) %p,%p;%lx",
12470 +               sk, nx_info, sk->sk_socket,
12471 +               (sk->sk_socket?sk->sk_socket->flags:0));
12472 +
12473 +       rt = ip_v4_find_src(net, nx_info, fl4);
12474 +       if (IS_ERR(rt))
12475 +               return rt;
12476 +       ip_rt_put(rt);
12477 +
12478 +       if (!fl4->daddr || !fl4->saddr) {
12479                 rt = __ip_route_output_key(net, fl4);
12480                 if (IS_ERR(rt))
12481                         return rt;
12482 diff -NurpP --minimal linux-3.9.5/include/net/sock.h linux-3.9.5-vs2.3.6.5/include/net/sock.h
12483 --- linux-3.9.5/include/net/sock.h      2013-06-11 12:22:40.000000000 +0000
12484 +++ linux-3.9.5-vs2.3.6.5/include/net/sock.h    2013-06-12 23:49:09.000000000 +0000
12485 @@ -191,6 +191,10 @@ struct sock_common {
12486  #ifdef CONFIG_NET_NS
12487         struct net              *skc_net;
12488  #endif
12489 +       vxid_t                  skc_xid;
12490 +       struct vx_info          *skc_vx_info;
12491 +       vnid_t                  skc_nid;
12492 +       struct nx_info          *skc_nx_info;
12493         /*
12494          * fields between dontcopy_begin/dontcopy_end
12495          * are not copied in sock_copy()
12496 @@ -304,6 +308,10 @@ struct sock {
12497  #define sk_bind_node           __sk_common.skc_bind_node
12498  #define sk_prot                        __sk_common.skc_prot
12499  #define sk_net                 __sk_common.skc_net
12500 +#define sk_xid                 __sk_common.skc_xid
12501 +#define sk_vx_info             __sk_common.skc_vx_info
12502 +#define sk_nid                 __sk_common.skc_nid
12503 +#define sk_nx_info             __sk_common.skc_nx_info
12504         socket_lock_t           sk_lock;
12505         struct sk_buff_head     sk_receive_queue;
12506         /*
12507 diff -NurpP --minimal linux-3.9.5/include/uapi/Kbuild linux-3.9.5-vs2.3.6.5/include/uapi/Kbuild
12508 --- linux-3.9.5/include/uapi/Kbuild     2012-12-11 03:30:57.000000000 +0000
12509 +++ linux-3.9.5-vs2.3.6.5/include/uapi/Kbuild   2013-05-31 14:47:11.000000000 +0000
12510 @@ -12,3 +12,4 @@ header-y += video/
12511  header-y += drm/
12512  header-y += xen/
12513  header-y += scsi/
12514 +header-y += vserver/
12515 diff -NurpP --minimal linux-3.9.5/include/uapi/linux/capability.h linux-3.9.5-vs2.3.6.5/include/uapi/linux/capability.h
12516 --- linux-3.9.5/include/uapi/linux/capability.h 2012-12-11 03:30:57.000000000 +0000
12517 +++ linux-3.9.5-vs2.3.6.5/include/uapi/linux/capability.h       2013-05-31 14:47:11.000000000 +0000
12518 @@ -259,6 +259,7 @@ struct vfs_cap_data {
12519     arbitrary SCSI commands */
12520  /* Allow setting encryption key on loopback filesystem */
12521  /* Allow setting zone reclaim policy */
12522 +/* Allow the selection of a security context */
12523  
12524  #define CAP_SYS_ADMIN        21
12525  
12526 @@ -345,7 +346,12 @@ struct vfs_cap_data {
12527  
12528  #define CAP_LAST_CAP         CAP_BLOCK_SUSPEND
12529  
12530 -#define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
12531 +/* Allow context manipulations */
12532 +/* Allow changing context info on files */
12533 +
12534 +#define CAP_CONTEXT         63
12535 +
12536 +#define cap_valid(x) ((x) >= 0 && ((x) <= CAP_LAST_CAP || (x) == CAP_CONTEXT))
12537  
12538  /*
12539   * Bit location of each capability (used by user-space library and kernel)
12540 diff -NurpP --minimal linux-3.9.5/include/uapi/linux/fs.h linux-3.9.5-vs2.3.6.5/include/uapi/linux/fs.h
12541 --- linux-3.9.5/include/uapi/linux/fs.h 2013-05-31 13:45:29.000000000 +0000
12542 +++ linux-3.9.5-vs2.3.6.5/include/uapi/linux/fs.h       2013-05-31 23:07:43.000000000 +0000
12543 @@ -86,6 +86,9 @@ struct inodes_stat_t {
12544  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
12545  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
12546  #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
12547 +#define MS_TAGGED      (1<<8)  /* use generic inode tagging */
12548 +#define MS_NOTAGCHECK  (1<<9)  /* don't check tags */
12549 +#define MS_TAGID       (1<<25) /* use specific tag for this mount */
12550  
12551  /* These sb flags are internal to the kernel */
12552  #define MS_SNAP_STABLE (1<<27) /* Snapshot pages during writeback, if needed */
12553 @@ -192,11 +195,14 @@ struct inodes_stat_t {
12554  #define FS_EXTENT_FL                   0x00080000 /* Extents */
12555  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
12556  #define FS_NOCOW_FL                    0x00800000 /* Do not cow file */
12557 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
12558  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
12559  
12560 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
12561 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
12562 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
12563 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
12564  
12565 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
12566 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
12567  
12568  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
12569  #define SYNC_FILE_RANGE_WRITE          2
12570 diff -NurpP --minimal linux-3.9.5/include/uapi/linux/gfs2_ondisk.h linux-3.9.5-vs2.3.6.5/include/uapi/linux/gfs2_ondisk.h
12571 --- linux-3.9.5/include/uapi/linux/gfs2_ondisk.h        2012-12-11 03:30:57.000000000 +0000
12572 +++ linux-3.9.5-vs2.3.6.5/include/uapi/linux/gfs2_ondisk.h      2013-05-31 14:47:11.000000000 +0000
12573 @@ -225,6 +225,9 @@ enum {
12574         gfs2fl_Sync             = 8,
12575         gfs2fl_System           = 9,
12576         gfs2fl_TopLevel         = 10,
12577 +       gfs2fl_IXUnlink         = 16,
12578 +       gfs2fl_Barrier          = 17,
12579 +       gfs2fl_Cow              = 18,
12580         gfs2fl_TruncInProg      = 29,
12581         gfs2fl_InheritDirectio  = 30,
12582         gfs2fl_InheritJdata     = 31,
12583 @@ -242,6 +245,9 @@ enum {
12584  #define GFS2_DIF_SYNC                  0x00000100
12585  #define GFS2_DIF_SYSTEM                        0x00000200 /* New in gfs2 */
12586  #define GFS2_DIF_TOPDIR                        0x00000400 /* New in gfs2 */
12587 +#define GFS2_DIF_IXUNLINK               0x00010000
12588 +#define GFS2_DIF_BARRIER                0x00020000
12589 +#define GFS2_DIF_COW                    0x00040000
12590  #define GFS2_DIF_TRUNC_IN_PROG         0x20000000 /* New in gfs2 */
12591  #define GFS2_DIF_INHERIT_DIRECTIO      0x40000000 /* only in gfs1 */
12592  #define GFS2_DIF_INHERIT_JDATA         0x80000000
12593 diff -NurpP --minimal linux-3.9.5/include/uapi/linux/if_tun.h linux-3.9.5-vs2.3.6.5/include/uapi/linux/if_tun.h
12594 --- linux-3.9.5/include/uapi/linux/if_tun.h     2013-02-19 13:58:55.000000000 +0000
12595 +++ linux-3.9.5-vs2.3.6.5/include/uapi/linux/if_tun.h   2013-05-31 15:00:16.000000000 +0000
12596 @@ -56,6 +56,7 @@
12597  #define TUNGETVNETHDRSZ _IOR('T', 215, int)
12598  #define TUNSETVNETHDRSZ _IOW('T', 216, int)
12599  #define TUNSETQUEUE  _IOW('T', 217, int)
12600 +#define TUNSETNID     _IOW('T', 218, int)
12601  
12602  /* TUNSETIFF ifr flags */
12603  #define IFF_TUN                0x0001
12604 diff -NurpP --minimal linux-3.9.5/include/uapi/linux/major.h linux-3.9.5-vs2.3.6.5/include/uapi/linux/major.h
12605 --- linux-3.9.5/include/uapi/linux/major.h      2012-12-11 03:30:57.000000000 +0000
12606 +++ linux-3.9.5-vs2.3.6.5/include/uapi/linux/major.h    2013-05-31 14:47:11.000000000 +0000
12607 @@ -15,6 +15,7 @@
12608  #define HD_MAJOR               IDE0_MAJOR
12609  #define PTY_SLAVE_MAJOR                3
12610  #define TTY_MAJOR              4
12611 +#define VROOT_MAJOR            4
12612  #define TTYAUX_MAJOR           5
12613  #define LP_MAJOR               6
12614  #define VCS_MAJOR              7
12615 diff -NurpP --minimal linux-3.9.5/include/uapi/linux/nfs_mount.h linux-3.9.5-vs2.3.6.5/include/uapi/linux/nfs_mount.h
12616 --- linux-3.9.5/include/uapi/linux/nfs_mount.h  2012-12-11 03:30:57.000000000 +0000
12617 +++ linux-3.9.5-vs2.3.6.5/include/uapi/linux/nfs_mount.h        2013-05-31 14:47:11.000000000 +0000
12618 @@ -63,7 +63,8 @@ struct nfs_mount_data {
12619  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
12620  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
12621  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
12622 -#define NFS_MOUNT_FLAGMASK     0xFFFF
12623 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
12624 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
12625  
12626  /* The following are for internal use only */
12627  #define NFS_MOUNT_LOOKUP_CACHE_NONEG   0x10000
12628 diff -NurpP --minimal linux-3.9.5/include/uapi/linux/reboot.h linux-3.9.5-vs2.3.6.5/include/uapi/linux/reboot.h
12629 --- linux-3.9.5/include/uapi/linux/reboot.h     2012-12-11 03:30:57.000000000 +0000
12630 +++ linux-3.9.5-vs2.3.6.5/include/uapi/linux/reboot.h   2013-05-31 14:47:11.000000000 +0000
12631 @@ -33,7 +33,7 @@
12632  #define        LINUX_REBOOT_CMD_RESTART2       0xA1B2C3D4
12633  #define        LINUX_REBOOT_CMD_SW_SUSPEND     0xD000FCE2
12634  #define        LINUX_REBOOT_CMD_KEXEC          0x45584543
12635 -
12636 +#define        LINUX_REBOOT_CMD_OOM            0xDEADBEEF
12637  
12638  
12639  #endif /* _UAPI_LINUX_REBOOT_H */
12640 diff -NurpP --minimal linux-3.9.5/include/uapi/linux/sysctl.h linux-3.9.5-vs2.3.6.5/include/uapi/linux/sysctl.h
12641 --- linux-3.9.5/include/uapi/linux/sysctl.h     2012-12-11 03:30:57.000000000 +0000
12642 +++ linux-3.9.5-vs2.3.6.5/include/uapi/linux/sysctl.h   2013-05-31 14:47:11.000000000 +0000
12643 @@ -60,6 +60,7 @@ enum
12644         CTL_ABI=9,              /* Binary emulation */
12645         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
12646         CTL_ARLAN=254,          /* arlan wireless driver */
12647 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
12648         CTL_S390DBF=5677,       /* s390 debug */
12649         CTL_SUNRPC=7249,        /* sunrpc debug */
12650         CTL_PM=9899,            /* frv power management */
12651 @@ -94,6 +95,7 @@ enum
12652  
12653         KERN_PANIC=15,          /* int: panic timeout */
12654         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
12655 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
12656  
12657         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
12658         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
12659 diff -NurpP --minimal linux-3.9.5/include/uapi/vserver/Kbuild linux-3.9.5-vs2.3.6.5/include/uapi/vserver/Kbuild
12660 --- linux-3.9.5/include/uapi/vserver/Kbuild     1970-01-01 00:00:00.000000000 +0000
12661 +++ linux-3.9.5-vs2.3.6.5/include/uapi/vserver/Kbuild   2013-05-31 14:47:11.000000000 +0000
12662 @@ -0,0 +1,9 @@
12663 +
12664 +header-y += context_cmd.h network_cmd.h space_cmd.h \
12665 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
12666 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
12667 +       debug_cmd.h device_cmd.h
12668 +
12669 +header-y += switch.h context.h network.h monitor.h \
12670 +       limit.h inode.h device.h
12671 +
12672 diff -NurpP --minimal linux-3.9.5/include/uapi/vserver/cacct_cmd.h linux-3.9.5-vs2.3.6.5/include/uapi/vserver/cacct_cmd.h
12673 --- linux-3.9.5/include/uapi/vserver/cacct_cmd.h        1970-01-01 00:00:00.000000000 +0000
12674 +++ linux-3.9.5-vs2.3.6.5/include/uapi/vserver/cacct_cmd.h      2013-05-31 14:47:11.000000000 +0000
12675 @@ -0,0 +1,15 @@
12676 +#ifndef _UAPI_VS_CACCT_CMD_H
12677 +#define _UAPI_VS_CACCT_CMD_H
12678 +
12679 +
12680 +/* virtual host info name commands */
12681 +
12682 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
12683 +
12684 +struct vcmd_sock_stat_v0 {
12685 +       uint32_t field;
12686 +       uint32_t count[3];
12687 +       uint64_t total[3];
12688 +};
12689 +
12690 +#endif /* _UAPI_VS_CACCT_CMD_H */
12691 diff -NurpP --minimal linux-3.9.5/include/uapi/vserver/context.h linux-3.9.5-vs2.3.6.5/include/uapi/vserver/context.h
12692 --- linux-3.9.5/include/uapi/vserver/context.h  1970-01-01 00:00:00.000000000 +0000
12693 +++ linux-3.9.5-vs2.3.6.5/include/uapi/vserver/context.h        2013-05-31 19:44:13.000000000 +0000
12694 @@ -0,0 +1,81 @@
12695 +#ifndef _UAPI_VS_CONTEXT_H
12696 +#define _UAPI_VS_CONTEXT_H
12697 +
12698 +#include <linux/types.h>
12699 +#include <linux/capability.h>
12700 +
12701 +
12702 +/* context flags */
12703 +
12704 +#define VXF_INFO_SCHED         0x00000002
12705 +#define VXF_INFO_NPROC         0x00000004
12706 +#define VXF_INFO_PRIVATE       0x00000008
12707 +
12708 +#define VXF_INFO_INIT          0x00000010
12709 +#define VXF_INFO_HIDE          0x00000020
12710 +#define VXF_INFO_ULIMIT                0x00000040
12711 +#define VXF_INFO_NSPACE                0x00000080
12712 +
12713 +#define VXF_SCHED_HARD         0x00000100
12714 +#define VXF_SCHED_PRIO         0x00000200
12715 +#define VXF_SCHED_PAUSE                0x00000400
12716 +
12717 +#define VXF_VIRT_MEM           0x00010000
12718 +#define VXF_VIRT_UPTIME                0x00020000
12719 +#define VXF_VIRT_CPU           0x00040000
12720 +#define VXF_VIRT_LOAD          0x00080000
12721 +#define VXF_VIRT_TIME          0x00100000
12722 +
12723 +#define VXF_HIDE_MOUNT         0x01000000
12724 +/* was VXF_HIDE_NETIF          0x02000000 */
12725 +#define VXF_HIDE_VINFO         0x04000000
12726 +
12727 +#define VXF_STATE_SETUP                (1ULL << 32)
12728 +#define VXF_STATE_INIT         (1ULL << 33)
12729 +#define VXF_STATE_ADMIN                (1ULL << 34)
12730 +
12731 +#define VXF_SC_HELPER          (1ULL << 36)
12732 +#define VXF_REBOOT_KILL                (1ULL << 37)
12733 +#define VXF_PERSISTENT         (1ULL << 38)
12734 +
12735 +#define VXF_FORK_RSS           (1ULL << 48)
12736 +#define VXF_PROLIFIC           (1ULL << 49)
12737 +
12738 +#define VXF_IGNEG_NICE         (1ULL << 52)
12739 +
12740 +#define VXF_ONE_TIME           (0x0007ULL << 32)
12741 +
12742 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
12743 +
12744 +
12745 +/* context migration */
12746 +
12747 +#define VXM_SET_INIT           0x00000001
12748 +#define VXM_SET_REAPER         0x00000002
12749 +
12750 +/* context caps */
12751 +
12752 +#define VXC_SET_UTSNAME                0x00000001
12753 +#define VXC_SET_RLIMIT         0x00000002
12754 +#define VXC_FS_SECURITY                0x00000004
12755 +#define VXC_FS_TRUSTED         0x00000008
12756 +#define VXC_TIOCSTI            0x00000010
12757 +
12758 +/* was VXC_RAW_ICMP            0x00000100 */
12759 +#define VXC_SYSLOG             0x00001000
12760 +#define VXC_OOM_ADJUST         0x00002000
12761 +#define VXC_AUDIT_CONTROL      0x00004000
12762 +
12763 +/* #define VXC_SECURE_MOUNT    0x00010000
12764 +#define VXC_SECURE_REMOUNT     0x00020000 */
12765 +#define VXC_BINARY_MOUNT       0x00040000
12766 +#define VXC_DEV_MOUNT          0x00080000
12767 +
12768 +#define VXC_QUOTA_CTL          0x00100000
12769 +#define VXC_ADMIN_MAPPER       0x00200000
12770 +#define VXC_ADMIN_CLOOP                0x00400000
12771 +
12772 +#define VXC_KTHREAD            0x01000000
12773 +#define VXC_NAMESPACE          0x02000000
12774 +
12775 +#endif /* _UAPI_VS_CONTEXT_H */
12776 diff -NurpP --minimal linux-3.9.5/include/uapi/vserver/context_cmd.h linux-3.9.5-vs2.3.6.5/include/uapi/vserver/context_cmd.h
12777 --- linux-3.9.5/include/uapi/vserver/context_cmd.h      1970-01-01 00:00:00.000000000 +0000
12778 +++ linux-3.9.5-vs2.3.6.5/include/uapi/vserver/context_cmd.h    2013-05-31 14:47:11.000000000 +0000
12779 @@ -0,0 +1,115 @@
12780 +#ifndef _UAPI_VS_CONTEXT_CMD_H
12781 +#define _UAPI_VS_CONTEXT_CMD_H
12782 +
12783 +
12784 +/* vinfo commands */
12785 +
12786 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
12787 +
12788 +
12789 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
12790 +
12791 +struct vcmd_vx_info_v0 {
12792 +       uint32_t xid;
12793 +       uint32_t initpid;
12794 +       /* more to come */
12795 +};
12796 +
12797 +
12798 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
12799 +
12800 +struct vcmd_ctx_stat_v0 {
12801 +       uint32_t usecnt;
12802 +       uint32_t tasks;
12803 +       /* more to come */
12804 +};
12805 +
12806 +
12807 +/* context commands */
12808 +
12809 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
12810 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
12811 +
12812 +struct vcmd_ctx_create {
12813 +       uint64_t flagword;
12814 +};
12815 +
12816 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
12817 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
12818 +
12819 +struct vcmd_ctx_migrate {
12820 +       uint64_t flagword;
12821 +};
12822 +
12823 +
12824 +
12825 +/* flag commands */
12826 +
12827 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
12828 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
12829 +
12830 +struct vcmd_ctx_flags_v0 {
12831 +       uint64_t flagword;
12832 +       uint64_t mask;
12833 +};
12834 +
12835 +
12836 +
12837 +/* context caps commands */
12838 +
12839 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
12840 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
12841 +
12842 +struct vcmd_ctx_caps_v1 {
12843 +       uint64_t ccaps;
12844 +       uint64_t cmask;
12845 +};
12846 +
12847 +
12848 +
12849 +/* bcaps commands */
12850 +
12851 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
12852 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
12853 +
12854 +struct vcmd_bcaps {
12855 +       uint64_t bcaps;
12856 +       uint64_t bmask;
12857 +};
12858 +
12859 +
12860 +
12861 +/* umask commands */
12862 +
12863 +#define VCMD_get_umask         VC_CMD(FLAGS, 13, 0)
12864 +#define VCMD_set_umask         VC_CMD(FLAGS, 14, 0)
12865 +
12866 +struct vcmd_umask {
12867 +       uint64_t umask;
12868 +       uint64_t mask;
12869 +};
12870 +
12871 +
12872 +
12873 +/* wmask commands */
12874 +
12875 +#define VCMD_get_wmask         VC_CMD(FLAGS, 15, 0)
12876 +#define VCMD_set_wmask         VC_CMD(FLAGS, 16, 0)
12877 +
12878 +struct vcmd_wmask {
12879 +       uint64_t wmask;
12880 +       uint64_t mask;
12881 +};
12882 +
12883 +
12884 +
12885 +/* OOM badness */
12886 +
12887 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
12888 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
12889 +
12890 +struct vcmd_badness_v0 {
12891 +       int64_t bias;
12892 +};
12893 +
12894 +#endif /* _UAPI_VS_CONTEXT_CMD_H */
12895 diff -NurpP --minimal linux-3.9.5/include/uapi/vserver/cvirt_cmd.h linux-3.9.5-vs2.3.6.5/include/uapi/vserver/cvirt_cmd.h
12896 --- linux-3.9.5/include/uapi/vserver/cvirt_cmd.h        1970-01-01 00:00:00.000000000 +0000
12897 +++ linux-3.9.5-vs2.3.6.5/include/uapi/vserver/cvirt_cmd.h      2013-05-31 14:47:11.000000000 +0000
12898 @@ -0,0 +1,41 @@
12899 +#ifndef _UAPI_VS_CVIRT_CMD_H
12900 +#define _UAPI_VS_CVIRT_CMD_H
12901 +
12902 +
12903 +/* virtual host info name commands */
12904 +
12905 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
12906 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
12907 +
12908 +struct vcmd_vhi_name_v0 {
12909 +       uint32_t field;
12910 +       char name[65];
12911 +};
12912 +
12913 +
12914 +enum vhi_name_field {
12915 +       VHIN_CONTEXT = 0,
12916 +       VHIN_SYSNAME,
12917 +       VHIN_NODENAME,
12918 +       VHIN_RELEASE,
12919 +       VHIN_VERSION,
12920 +       VHIN_MACHINE,
12921 +       VHIN_DOMAINNAME,
12922 +};
12923 +
12924 +
12925 +
12926 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
12927 +
12928 +struct vcmd_virt_stat_v0 {
12929 +       uint64_t offset;
12930 +       uint64_t uptime;
12931 +       uint32_t nr_threads;
12932 +       uint32_t nr_running;
12933 +       uint32_t nr_uninterruptible;
12934 +       uint32_t nr_onhold;
12935 +       uint32_t nr_forks;
12936 +       uint32_t load[3];
12937 +};
12938 +
12939 +#endif /* _UAPI_VS_CVIRT_CMD_H */
12940 diff -NurpP --minimal linux-3.9.5/include/uapi/vserver/debug_cmd.h linux-3.9.5-vs2.3.6.5/include/uapi/vserver/debug_cmd.h
12941 --- linux-3.9.5/include/uapi/vserver/debug_cmd.h        1970-01-01 00:00:00.000000000 +0000
12942 +++ linux-3.9.5-vs2.3.6.5/include/uapi/vserver/debug_cmd.h      2013-05-31 14:47:11.000000000 +0000
12943 @@ -0,0 +1,24 @@
12944 +#ifndef _UAPI_VS_DEBUG_CMD_H
12945 +#define _UAPI_VS_DEBUG_CMD_H
12946 +
12947 +
12948 +/* debug commands */
12949 +
12950 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
12951 +
12952 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
12953 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
12954 +
12955 +struct  vcmd_read_history_v0 {
12956 +       uint32_t index;
12957 +       uint32_t count;
12958 +       char __user *data;
12959 +};
12960 +
12961 +struct  vcmd_read_monitor_v0 {
12962 +       uint32_t index;
12963 +       uint32_t count;
12964 +       char __user *data;
12965 +};
12966 +
12967 +#endif /* _UAPI_VS_DEBUG_CMD_H */
12968 diff -NurpP --minimal linux-3.9.5/include/uapi/vserver/device.h linux-3.9.5-vs2.3.6.5/include/uapi/vserver/device.h
12969 --- linux-3.9.5/include/uapi/vserver/device.h   1970-01-01 00:00:00.000000000 +0000
12970 +++ linux-3.9.5-vs2.3.6.5/include/uapi/vserver/device.h 2013-05-31 14:47:11.000000000 +0000
12971 @@ -0,0 +1,12 @@
12972 +#ifndef _UAPI_VS_DEVICE_H
12973 +#define _UAPI_VS_DEVICE_H
12974 +
12975 +
12976 +#define DATTR_CREATE   0x00000001
12977 +#define DATTR_OPEN     0x00000002
12978 +
12979 +#define DATTR_REMAP    0x00000010
12980 +
12981 +#define DATTR_MASK     0x00000013
12982 +
12983 +#endif /* _UAPI_VS_DEVICE_H */
12984 diff -NurpP --minimal linux-3.9.5/include/uapi/vserver/device_cmd.h linux-3.9.5-vs2.3.6.5/include/uapi/vserver/device_cmd.h
12985 --- linux-3.9.5/include/uapi/vserver/device_cmd.h       1970-01-01 00:00:00.000000000 +0000
12986 +++ linux-3.9.5-vs2.3.6.5/include/uapi/vserver/device_cmd.h     2013-05-31 14:47:11.000000000 +0000
12987 @@ -0,0 +1,16 @@
12988 +#ifndef _UAPI_VS_DEVICE_CMD_H
12989 +#define _UAPI_VS_DEVICE_CMD_H
12990 +
12991 +
12992 +/*  device vserver commands */
12993 +
12994 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
12995 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
12996 +
12997 +struct vcmd_set_mapping_v0 {
12998 +       const char __user *device;
12999 +       const char __user *target;
13000 +       uint32_t flags;
13001 +};
13002 +
13003 +#endif /* _UAPI_VS_DEVICE_CMD_H */
13004 diff -NurpP --minimal linux-3.9.5/include/uapi/vserver/dlimit_cmd.h linux-3.9.5-vs2.3.6.5/include/uapi/vserver/dlimit_cmd.h
13005 --- linux-3.9.5/include/uapi/vserver/dlimit_cmd.h       1970-01-01 00:00:00.000000000 +0000
13006 +++ linux-3.9.5-vs2.3.6.5/include/uapi/vserver/dlimit_cmd.h     2013-05-31 14:47:11.000000000 +0000
13007 @@ -0,0 +1,67 @@
13008 +#ifndef _UAPI_VS_DLIMIT_CMD_H
13009 +#define _UAPI_VS_DLIMIT_CMD_H
13010 +
13011 +
13012 +/*  dlimit vserver commands */
13013 +
13014 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
13015 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
13016 +
13017 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
13018 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
13019 +
13020 +struct vcmd_ctx_dlimit_base_v0 {
13021 +       const char __user *name;
13022 +       uint32_t flags;
13023 +};
13024 +
13025 +struct vcmd_ctx_dlimit_v0 {
13026 +       const char __user *name;
13027 +       uint32_t space_used;                    /* used space in kbytes */
13028 +       uint32_t space_total;                   /* maximum space in kbytes */
13029 +       uint32_t inodes_used;                   /* used inodes */
13030 +       uint32_t inodes_total;                  /* maximum inodes */
13031 +       uint32_t reserved;                      /* reserved for root in % */
13032 +       uint32_t flags;
13033 +};
13034 +
13035 +#define CDLIM_UNSET            ((uint32_t)0UL)
13036 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
13037 +#define CDLIM_KEEP             ((uint32_t)~1UL)
13038 +
13039 +#define DLIME_UNIT     0
13040 +#define DLIME_KILO     1
13041 +#define DLIME_MEGA     2
13042 +#define DLIME_GIGA     3
13043 +
13044 +#define DLIMF_SHIFT    0x10
13045 +
13046 +#define DLIMS_USED     0
13047 +#define DLIMS_TOTAL    2
13048 +
13049 +static inline
13050 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
13051 +{
13052 +       int exp = (flags & DLIMF_SHIFT) ?
13053 +               (flags >> shift) & DLIME_GIGA : DLIME_KILO;
13054 +       return ((uint64_t)val) << (10 * exp);
13055 +}
13056 +
13057 +static inline
13058 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
13059 +{
13060 +       int exp = 0;
13061 +
13062 +       if (*flags & DLIMF_SHIFT) {
13063 +               while (val > (1LL << 32) && (exp < 3)) {
13064 +                       val >>= 10;
13065 +                       exp++;
13066 +               }
13067 +               *flags &= ~(DLIME_GIGA << shift);
13068 +               *flags |= exp << shift;
13069 +       } else
13070 +               val >>= 10;
13071 +       return val;
13072 +}
13073 +
13074 +#endif /* _UAPI_VS_DLIMIT_CMD_H */
13075 diff -NurpP --minimal linux-3.9.5/include/uapi/vserver/inode.h linux-3.9.5-vs2.3.6.5/include/uapi/vserver/inode.h
13076 --- linux-3.9.5/include/uapi/vserver/inode.h    1970-01-01 00:00:00.000000000 +0000
13077 +++ linux-3.9.5-vs2.3.6.5/include/uapi/vserver/inode.h  2013-05-31 14:47:11.000000000 +0000
13078 @@ -0,0 +1,23 @@
13079 +#ifndef _UAPI_VS_INODE_H
13080 +#define _UAPI_VS_INODE_H
13081 +
13082 +
13083 +#define IATTR_TAG      0x01000000
13084 +
13085 +#define IATTR_ADMIN    0x00000001
13086 +#define IATTR_WATCH    0x00000002
13087 +#define IATTR_HIDE     0x00000004
13088 +#define IATTR_FLAGS    0x00000007
13089 +
13090 +#define IATTR_BARRIER  0x00010000
13091 +#define IATTR_IXUNLINK 0x00020000
13092 +#define IATTR_IMMUTABLE 0x00040000
13093 +#define IATTR_COW      0x00080000
13094 +
13095 +
13096 +/* inode ioctls */
13097 +
13098 +#define FIOC_GETXFLG   _IOR('x', 5, long)
13099 +#define FIOC_SETXFLG   _IOW('x', 6, long)
13100 +
13101 +#endif /* _UAPI_VS_INODE_H */
13102 diff -NurpP --minimal linux-3.9.5/include/uapi/vserver/inode_cmd.h linux-3.9.5-vs2.3.6.5/include/uapi/vserver/inode_cmd.h
13103 --- linux-3.9.5/include/uapi/vserver/inode_cmd.h        1970-01-01 00:00:00.000000000 +0000
13104 +++ linux-3.9.5-vs2.3.6.5/include/uapi/vserver/inode_cmd.h      2013-05-31 14:47:11.000000000 +0000
13105 @@ -0,0 +1,26 @@
13106 +#ifndef _UAPI_VS_INODE_CMD_H
13107 +#define _UAPI_VS_INODE_CMD_H
13108 +
13109 +
13110 +/*  inode vserver commands */
13111 +
13112 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
13113 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
13114 +
13115 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
13116 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
13117 +
13118 +struct vcmd_ctx_iattr_v1 {
13119 +       const char __user *name;
13120 +       uint32_t tag;
13121 +       uint32_t flags;
13122 +       uint32_t mask;
13123 +};
13124 +
13125 +struct vcmd_ctx_fiattr_v0 {
13126 +       uint32_t tag;
13127 +       uint32_t flags;
13128 +       uint32_t mask;
13129 +};
13130 +
13131 +#endif /* _UAPI_VS_INODE_CMD_H */
13132 diff -NurpP --minimal linux-3.9.5/include/uapi/vserver/limit.h linux-3.9.5-vs2.3.6.5/include/uapi/vserver/limit.h
13133 --- linux-3.9.5/include/uapi/vserver/limit.h    1970-01-01 00:00:00.000000000 +0000
13134 +++ linux-3.9.5-vs2.3.6.5/include/uapi/vserver/limit.h  2013-05-31 14:47:11.000000000 +0000
13135 @@ -0,0 +1,14 @@
13136 +#ifndef _UAPI_VS_LIMIT_H
13137 +#define _UAPI_VS_LIMIT_H
13138 +
13139 +
13140 +#define VLIMIT_NSOCK   16
13141 +#define VLIMIT_OPENFD  17
13142 +#define VLIMIT_ANON    18
13143 +#define VLIMIT_SHMEM   19
13144 +#define VLIMIT_SEMARY  20
13145 +#define VLIMIT_NSEMS   21
13146 +#define VLIMIT_DENTRY  22
13147 +#define VLIMIT_MAPPED  23
13148 +
13149 +#endif /* _UAPI_VS_LIMIT_H */
13150 diff -NurpP --minimal linux-3.9.5/include/uapi/vserver/limit_cmd.h linux-3.9.5-vs2.3.6.5/include/uapi/vserver/limit_cmd.h
13151 --- linux-3.9.5/include/uapi/vserver/limit_cmd.h        1970-01-01 00:00:00.000000000 +0000
13152 +++ linux-3.9.5-vs2.3.6.5/include/uapi/vserver/limit_cmd.h      2013-05-31 14:47:11.000000000 +0000
13153 @@ -0,0 +1,40 @@
13154 +#ifndef _UAPI_VS_LIMIT_CMD_H
13155 +#define _UAPI_VS_LIMIT_CMD_H
13156 +
13157 +
13158 +/*  rlimit vserver commands */
13159 +
13160 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
13161 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
13162 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
13163 +#define VCMD_reset_hits                VC_CMD(RLIMIT, 7, 0)
13164 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
13165 +
13166 +struct vcmd_ctx_rlimit_v0 {
13167 +       uint32_t id;
13168 +       uint64_t minimum;
13169 +       uint64_t softlimit;
13170 +       uint64_t maximum;
13171 +};
13172 +
13173 +struct vcmd_ctx_rlimit_mask_v0 {
13174 +       uint32_t minimum;
13175 +       uint32_t softlimit;
13176 +       uint32_t maximum;
13177 +};
13178 +
13179 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
13180 +
13181 +struct vcmd_rlimit_stat_v0 {
13182 +       uint32_t id;
13183 +       uint32_t hits;
13184 +       uint64_t value;
13185 +       uint64_t minimum;
13186 +       uint64_t maximum;
13187 +};
13188 +
13189 +#define CRLIM_UNSET            (0ULL)
13190 +#define CRLIM_INFINITY         (~0ULL)
13191 +#define CRLIM_KEEP             (~1ULL)
13192 +
13193 +#endif /* _UAPI_VS_LIMIT_CMD_H */
13194 diff -NurpP --minimal linux-3.9.5/include/uapi/vserver/monitor.h linux-3.9.5-vs2.3.6.5/include/uapi/vserver/monitor.h
13195 --- linux-3.9.5/include/uapi/vserver/monitor.h  1970-01-01 00:00:00.000000000 +0000
13196 +++ linux-3.9.5-vs2.3.6.5/include/uapi/vserver/monitor.h        2013-05-31 14:47:11.000000000 +0000
13197 @@ -0,0 +1,96 @@
13198 +#ifndef _UAPI_VS_MONITOR_H
13199 +#define _UAPI_VS_MONITOR_H
13200 +
13201 +#include <linux/types.h>
13202 +
13203 +
13204 +enum {
13205 +       VXM_UNUSED = 0,
13206 +
13207 +       VXM_SYNC = 0x10,
13208 +
13209 +       VXM_UPDATE = 0x20,
13210 +       VXM_UPDATE_1,
13211 +       VXM_UPDATE_2,
13212 +
13213 +       VXM_RQINFO_1 = 0x24,
13214 +       VXM_RQINFO_2,
13215 +
13216 +       VXM_ACTIVATE = 0x40,
13217 +       VXM_DEACTIVATE,
13218 +       VXM_IDLE,
13219 +
13220 +       VXM_HOLD = 0x44,
13221 +       VXM_UNHOLD,
13222 +
13223 +       VXM_MIGRATE = 0x48,
13224 +       VXM_RESCHED,
13225 +
13226 +       /* all other bits are flags */
13227 +       VXM_SCHED = 0x80,
13228 +};
13229 +
13230 +struct _vxm_update_1 {
13231 +       uint32_t tokens_max;
13232 +       uint32_t fill_rate;
13233 +       uint32_t interval;
13234 +};
13235 +
13236 +struct _vxm_update_2 {
13237 +       uint32_t tokens_min;
13238 +       uint32_t fill_rate;
13239 +       uint32_t interval;
13240 +};
13241 +
13242 +struct _vxm_rqinfo_1 {
13243 +       uint16_t running;
13244 +       uint16_t onhold;
13245 +       uint16_t iowait;
13246 +       uint16_t uintr;
13247 +       uint32_t idle_tokens;
13248 +};
13249 +
13250 +struct _vxm_rqinfo_2 {
13251 +       uint32_t norm_time;
13252 +       uint32_t idle_time;
13253 +       uint32_t idle_skip;
13254 +};
13255 +
13256 +struct _vxm_sched {
13257 +       uint32_t tokens;
13258 +       uint32_t norm_time;
13259 +       uint32_t idle_time;
13260 +};
13261 +
13262 +struct _vxm_task {
13263 +       uint16_t pid;
13264 +       uint16_t state;
13265 +};
13266 +
13267 +struct _vxm_event {
13268 +       uint32_t jif;
13269 +       union {
13270 +               uint32_t seq;
13271 +               uint32_t sec;
13272 +       };
13273 +       union {
13274 +               uint32_t tokens;
13275 +               uint32_t nsec;
13276 +               struct _vxm_task tsk;
13277 +       };
13278 +};
13279 +
13280 +struct _vx_mon_entry {
13281 +       uint16_t type;
13282 +       uint16_t xid;
13283 +       union {
13284 +               struct _vxm_event ev;
13285 +               struct _vxm_sched sd;
13286 +               struct _vxm_update_1 u1;
13287 +               struct _vxm_update_2 u2;
13288 +               struct _vxm_rqinfo_1 q1;
13289 +               struct _vxm_rqinfo_2 q2;
13290 +       };
13291 +};
13292 +
13293 +#endif /* _UAPI_VS_MONITOR_H */
13294 diff -NurpP --minimal linux-3.9.5/include/uapi/vserver/network.h linux-3.9.5-vs2.3.6.5/include/uapi/vserver/network.h
13295 --- linux-3.9.5/include/uapi/vserver/network.h  1970-01-01 00:00:00.000000000 +0000
13296 +++ linux-3.9.5-vs2.3.6.5/include/uapi/vserver/network.h        2013-05-31 14:47:11.000000000 +0000
13297 @@ -0,0 +1,76 @@
13298 +#ifndef _UAPI_VS_NETWORK_H
13299 +#define _UAPI_VS_NETWORK_H
13300 +
13301 +#include <linux/types.h>
13302 +
13303 +
13304 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
13305 +
13306 +
13307 +/* network flags */
13308 +
13309 +#define NXF_INFO_PRIVATE       0x00000008
13310 +
13311 +#define NXF_SINGLE_IP          0x00000100
13312 +#define NXF_LBACK_REMAP                0x00000200
13313 +#define NXF_LBACK_ALLOW                0x00000400
13314 +
13315 +#define NXF_HIDE_NETIF         0x02000000
13316 +#define NXF_HIDE_LBACK         0x04000000
13317 +
13318 +#define NXF_STATE_SETUP                (1ULL << 32)
13319 +#define NXF_STATE_ADMIN                (1ULL << 34)
13320 +
13321 +#define NXF_SC_HELPER          (1ULL << 36)
13322 +#define NXF_PERSISTENT         (1ULL << 38)
13323 +
13324 +#define NXF_ONE_TIME           (0x0005ULL << 32)
13325 +
13326 +
13327 +#define        NXF_INIT_SET            (__nxf_init_set())
13328 +
13329 +static inline uint64_t __nxf_init_set(void) {
13330 +       return    NXF_STATE_ADMIN
13331 +#ifdef CONFIG_VSERVER_AUTO_LBACK
13332 +               | NXF_LBACK_REMAP
13333 +               | NXF_HIDE_LBACK
13334 +#endif
13335 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
13336 +               | NXF_SINGLE_IP
13337 +#endif
13338 +               | NXF_HIDE_NETIF;
13339 +}
13340 +
13341 +
13342 +/* network caps */
13343 +
13344 +#define NXC_TUN_CREATE         0x00000001
13345 +
13346 +#define NXC_RAW_ICMP           0x00000100
13347 +
13348 +#define NXC_MULTICAST          0x00001000
13349 +
13350 +
13351 +/* address types */
13352 +
13353 +#define NXA_TYPE_IPV4          0x0001
13354 +#define NXA_TYPE_IPV6          0x0002
13355 +
13356 +#define NXA_TYPE_NONE          0x0000
13357 +#define NXA_TYPE_ANY           0x00FF
13358 +
13359 +#define NXA_TYPE_ADDR          0x0010
13360 +#define NXA_TYPE_MASK          0x0020
13361 +#define NXA_TYPE_RANGE         0x0040
13362 +
13363 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
13364 +
13365 +#define NXA_MOD_BCAST          0x0100
13366 +#define NXA_MOD_LBACK          0x0200
13367 +
13368 +#define NXA_LOOPBACK           0x1000
13369 +
13370 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
13371 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
13372 +
13373 +#endif /* _UAPI_VS_NETWORK_H */
13374 diff -NurpP --minimal linux-3.9.5/include/uapi/vserver/network_cmd.h linux-3.9.5-vs2.3.6.5/include/uapi/vserver/network_cmd.h
13375 --- linux-3.9.5/include/uapi/vserver/network_cmd.h      1970-01-01 00:00:00.000000000 +0000
13376 +++ linux-3.9.5-vs2.3.6.5/include/uapi/vserver/network_cmd.h    2013-05-31 14:47:11.000000000 +0000
13377 @@ -0,0 +1,123 @@
13378 +#ifndef _UAPI_VS_NETWORK_CMD_H
13379 +#define _UAPI_VS_NETWORK_CMD_H
13380 +
13381 +
13382 +/* vinfo commands */
13383 +
13384 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
13385 +
13386 +
13387 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
13388 +
13389 +struct vcmd_nx_info_v0 {
13390 +       uint32_t nid;
13391 +       /* more to come */
13392 +};
13393 +
13394 +
13395 +#include <linux/in.h>
13396 +#include <linux/in6.h>
13397 +
13398 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
13399 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
13400 +
13401 +struct  vcmd_net_create {
13402 +       uint64_t flagword;
13403 +};
13404 +
13405 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
13406 +
13407 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
13408 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
13409 +
13410 +struct vcmd_net_addr_v0 {
13411 +       uint16_t type;
13412 +       uint16_t count;
13413 +       struct in_addr ip[4];
13414 +       struct in_addr mask[4];
13415 +};
13416 +
13417 +#define VCMD_net_add_ipv4_v1   VC_CMD(NETALT, 1, 1)
13418 +#define VCMD_net_rem_ipv4_v1   VC_CMD(NETALT, 2, 1)
13419 +
13420 +struct vcmd_net_addr_ipv4_v1 {
13421 +       uint16_t type;
13422 +       uint16_t flags;
13423 +       struct in_addr ip;
13424 +       struct in_addr mask;
13425 +};
13426 +
13427 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 2)
13428 +#define VCMD_net_rem_ipv4      VC_CMD(NETALT, 2, 2)
13429 +
13430 +struct vcmd_net_addr_ipv4_v2 {
13431 +       uint16_t type;
13432 +       uint16_t flags;
13433 +       struct in_addr ip;
13434 +       struct in_addr ip2;
13435 +       struct in_addr mask;
13436 +};
13437 +
13438 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
13439 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
13440 +
13441 +struct vcmd_net_addr_ipv6_v1 {
13442 +       uint16_t type;
13443 +       uint16_t flags;
13444 +       uint32_t prefix;
13445 +       struct in6_addr ip;
13446 +       struct in6_addr mask;
13447 +};
13448 +
13449 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
13450 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
13451 +
13452 +struct vcmd_match_ipv4_v0 {
13453 +       uint16_t type;
13454 +       uint16_t flags;
13455 +       uint16_t parent;
13456 +       uint16_t prefix;
13457 +       struct in_addr ip;
13458 +       struct in_addr ip2;
13459 +       struct in_addr mask;
13460 +};
13461 +
13462 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
13463 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
13464 +
13465 +struct vcmd_match_ipv6_v0 {
13466 +       uint16_t type;
13467 +       uint16_t flags;
13468 +       uint16_t parent;
13469 +       uint16_t prefix;
13470 +       struct in6_addr ip;
13471 +       struct in6_addr ip2;
13472 +       struct in6_addr mask;
13473 +};
13474 +
13475 +
13476 +
13477 +
13478 +/* flag commands */
13479 +
13480 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
13481 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
13482 +
13483 +struct vcmd_net_flags_v0 {
13484 +       uint64_t flagword;
13485 +       uint64_t mask;
13486 +};
13487 +
13488 +
13489 +
13490 +/* network caps commands */
13491 +
13492 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
13493 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
13494 +
13495 +struct vcmd_net_caps_v0 {
13496 +       uint64_t ncaps;
13497 +       uint64_t cmask;
13498 +};
13499 +
13500 +#endif /* _UAPI_VS_NETWORK_CMD_H */
13501 diff -NurpP --minimal linux-3.9.5/include/uapi/vserver/sched_cmd.h linux-3.9.5-vs2.3.6.5/include/uapi/vserver/sched_cmd.h
13502 --- linux-3.9.5/include/uapi/vserver/sched_cmd.h        1970-01-01 00:00:00.000000000 +0000
13503 +++ linux-3.9.5-vs2.3.6.5/include/uapi/vserver/sched_cmd.h      2013-05-31 14:47:11.000000000 +0000
13504 @@ -0,0 +1,13 @@
13505 +#ifndef _UAPI_VS_SCHED_CMD_H
13506 +#define _UAPI_VS_SCHED_CMD_H
13507 +
13508 +
13509 +struct vcmd_prio_bias {
13510 +       int32_t cpu_id;
13511 +       int32_t prio_bias;
13512 +};
13513 +
13514 +#define VCMD_set_prio_bias     VC_CMD(SCHED, 4, 0)
13515 +#define VCMD_get_prio_bias     VC_CMD(SCHED, 5, 0)
13516 +
13517 +#endif /* _UAPI_VS_SCHED_CMD_H */
13518 diff -NurpP --minimal linux-3.9.5/include/uapi/vserver/signal_cmd.h linux-3.9.5-vs2.3.6.5/include/uapi/vserver/signal_cmd.h
13519 --- linux-3.9.5/include/uapi/vserver/signal_cmd.h       1970-01-01 00:00:00.000000000 +0000
13520 +++ linux-3.9.5-vs2.3.6.5/include/uapi/vserver/signal_cmd.h     2013-05-31 14:47:11.000000000 +0000
13521 @@ -0,0 +1,31 @@
13522 +#ifndef _UAPI_VS_SIGNAL_CMD_H
13523 +#define _UAPI_VS_SIGNAL_CMD_H
13524 +
13525 +
13526 +/*  signalling vserver commands */
13527 +
13528 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
13529 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
13530 +
13531 +struct vcmd_ctx_kill_v0 {
13532 +       int32_t pid;
13533 +       int32_t sig;
13534 +};
13535 +
13536 +struct vcmd_wait_exit_v0 {
13537 +       int32_t reboot_cmd;
13538 +       int32_t exit_code;
13539 +};
13540 +
13541 +
13542 +/*  process alteration commands */
13543 +
13544 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
13545 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
13546 +
13547 +struct vcmd_pflags_v0 {
13548 +       uint32_t flagword;
13549 +       uint32_t mask;
13550 +};
13551 +
13552 +#endif /* _UAPI_VS_SIGNAL_CMD_H */
13553 diff -NurpP --minimal linux-3.9.5/include/uapi/vserver/space_cmd.h linux-3.9.5-vs2.3.6.5/include/uapi/vserver/space_cmd.h
13554 --- linux-3.9.5/include/uapi/vserver/space_cmd.h        1970-01-01 00:00:00.000000000 +0000
13555 +++ linux-3.9.5-vs2.3.6.5/include/uapi/vserver/space_cmd.h      2013-05-31 14:47:11.000000000 +0000
13556 @@ -0,0 +1,28 @@
13557 +#ifndef _UAPI_VS_SPACE_CMD_H
13558 +#define _UAPI_VS_SPACE_CMD_H
13559 +
13560 +
13561 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
13562 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
13563 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
13564 +
13565 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
13566 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
13567 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
13568 +
13569 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
13570 +
13571 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
13572 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
13573 +
13574 +
13575 +struct vcmd_space_mask_v1 {
13576 +       uint64_t mask;
13577 +};
13578 +
13579 +struct vcmd_space_mask_v2 {
13580 +       uint64_t mask;
13581 +       uint32_t index;
13582 +};
13583 +
13584 +#endif /* _UAPI_VS_SPACE_CMD_H */
13585 diff -NurpP --minimal linux-3.9.5/include/uapi/vserver/switch.h linux-3.9.5-vs2.3.6.5/include/uapi/vserver/switch.h
13586 --- linux-3.9.5/include/uapi/vserver/switch.h   1970-01-01 00:00:00.000000000 +0000
13587 +++ linux-3.9.5-vs2.3.6.5/include/uapi/vserver/switch.h 2013-05-31 14:47:11.000000000 +0000
13588 @@ -0,0 +1,90 @@
13589 +#ifndef _UAPI_VS_SWITCH_H
13590 +#define _UAPI_VS_SWITCH_H
13591 +
13592 +#include <linux/types.h>
13593 +
13594 +
13595 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
13596 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
13597 +#define VC_VERSION(c)          ((c) & 0xFFF)
13598 +
13599 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
13600 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
13601 +
13602 +/*
13603 +
13604 +  Syscall Matrix V2.8
13605 +
13606 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
13607 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
13608 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
13609 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13610 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
13611 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
13612 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13613 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
13614 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
13615 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13616 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
13617 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
13618 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13619 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
13620 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
13621 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13622 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
13623 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
13624 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13625 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
13626 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
13627 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
13628 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
13629 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
13630 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13631 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
13632 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
13633 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13634 +
13635 +*/
13636 +
13637 +#define VC_CAT_VERSION         0
13638 +
13639 +#define VC_CAT_VSETUP          1
13640 +#define VC_CAT_VHOST           2
13641 +
13642 +#define VC_CAT_DEVICE          6
13643 +
13644 +#define VC_CAT_VPROC           9
13645 +#define VC_CAT_PROCALT         10
13646 +#define VC_CAT_PROCMIG         11
13647 +#define VC_CAT_PROCTRL         12
13648 +
13649 +#define VC_CAT_SCHED           14
13650 +#define VC_CAT_MEMCTRL         20
13651 +
13652 +#define VC_CAT_VNET            25
13653 +#define VC_CAT_NETALT          26
13654 +#define VC_CAT_NETMIG          27
13655 +#define VC_CAT_NETCTRL         28
13656 +
13657 +#define VC_CAT_TAGMIG          35
13658 +#define VC_CAT_DLIMIT          36
13659 +#define VC_CAT_INODE           38
13660 +
13661 +#define VC_CAT_VSTAT           40
13662 +#define VC_CAT_VINFO           46
13663 +#define VC_CAT_EVENT           48
13664 +
13665 +#define VC_CAT_FLAGS           52
13666 +#define VC_CAT_VSPACE          54
13667 +#define VC_CAT_DEBUG           56
13668 +#define VC_CAT_RLIMIT          60
13669 +
13670 +#define VC_CAT_SYSTEST         61
13671 +#define VC_CAT_COMPAT          63
13672 +
13673 +/*  query version */
13674 +
13675 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
13676 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
13677 +
13678 +#endif /* _UAPI_VS_SWITCH_H */
13679 diff -NurpP --minimal linux-3.9.5/include/uapi/vserver/tag_cmd.h linux-3.9.5-vs2.3.6.5/include/uapi/vserver/tag_cmd.h
13680 --- linux-3.9.5/include/uapi/vserver/tag_cmd.h  1970-01-01 00:00:00.000000000 +0000
13681 +++ linux-3.9.5-vs2.3.6.5/include/uapi/vserver/tag_cmd.h        2013-05-31 14:47:11.000000000 +0000
13682 @@ -0,0 +1,14 @@
13683 +#ifndef _UAPI_VS_TAG_CMD_H
13684 +#define _UAPI_VS_TAG_CMD_H
13685 +
13686 +
13687 +/* vinfo commands */
13688 +
13689 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
13690 +
13691 +
13692 +/* context commands */
13693 +
13694 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
13695 +
13696 +#endif /* _UAPI_VS_TAG_CMD_H */
13697 diff -NurpP --minimal linux-3.9.5/init/Kconfig linux-3.9.5-vs2.3.6.5/init/Kconfig
13698 --- linux-3.9.5/init/Kconfig    2013-05-31 13:45:29.000000000 +0000
13699 +++ linux-3.9.5-vs2.3.6.5/init/Kconfig  2013-05-31 14:47:11.000000000 +0000
13700 @@ -760,6 +760,7 @@ config NUMA_BALANCING
13701  menuconfig CGROUPS
13702         boolean "Control Group support"
13703         depends on EVENTFD
13704 +       default y
13705         help
13706           This option adds support for grouping sets of processes together, for
13707           use with process control subsystems such as Cpusets, CFS, memory
13708 @@ -1022,6 +1023,7 @@ config IPC_NS
13709  config USER_NS
13710         bool "User namespace"
13711         depends on UIDGID_CONVERTED
13712 +       depends on VSERVER_DISABLED
13713         select UIDGID_STRICT_TYPE_CHECKS
13714  
13715         default n
13716 diff -NurpP --minimal linux-3.9.5/init/main.c linux-3.9.5-vs2.3.6.5/init/main.c
13717 --- linux-3.9.5/init/main.c     2013-05-31 13:45:29.000000000 +0000
13718 +++ linux-3.9.5-vs2.3.6.5/init/main.c   2013-05-31 15:09:17.000000000 +0000
13719 @@ -72,6 +72,7 @@
13720  #include <linux/ptrace.h>
13721  #include <linux/blkdev.h>
13722  #include <linux/elevator.h>
13723 +#include <linux/vserver/percpu.h>
13724  
13725  #include <asm/io.h>
13726  #include <asm/bugs.h>
13727 diff -NurpP --minimal linux-3.9.5/ipc/mqueue.c linux-3.9.5-vs2.3.6.5/ipc/mqueue.c
13728 --- linux-3.9.5/ipc/mqueue.c    2013-05-31 13:45:29.000000000 +0000
13729 +++ linux-3.9.5-vs2.3.6.5/ipc/mqueue.c  2013-05-31 14:47:11.000000000 +0000
13730 @@ -35,6 +35,8 @@
13731  #include <linux/ipc_namespace.h>
13732  #include <linux/user_namespace.h>
13733  #include <linux/slab.h>
13734 +#include <linux/vs_context.h>
13735 +#include <linux/vs_limit.h>
13736  
13737  #include <net/sock.h>
13738  #include "util.h"
13739 @@ -76,6 +78,7 @@ struct mqueue_inode_info {
13740         struct pid* notify_owner;
13741         struct user_namespace *notify_user_ns;
13742         struct user_struct *user;       /* user who created, for accounting */
13743 +       struct vx_info *vxi;
13744         struct sock *notify_sock;
13745         struct sk_buff *notify_cookie;
13746  
13747 @@ -234,6 +237,7 @@ static struct inode *mqueue_get_inode(st
13748         if (S_ISREG(mode)) {
13749                 struct mqueue_inode_info *info;
13750                 unsigned long mq_bytes, mq_treesize;
13751 +               struct vx_info *vxi = current_vx_info();
13752  
13753                 inode->i_fop = &mqueue_file_operations;
13754                 inode->i_size = FILENT_SIZE;
13755 @@ -247,6 +251,7 @@ static struct inode *mqueue_get_inode(st
13756                 info->notify_user_ns = NULL;
13757                 info->qsize = 0;
13758                 info->user = NULL;      /* set when all is ok */
13759 +               info->vxi = NULL;
13760                 info->msg_tree = RB_ROOT;
13761                 info->node_cache = NULL;
13762                 memset(&info->attr, 0, sizeof(info->attr));
13763 @@ -280,17 +285,20 @@ static struct inode *mqueue_get_inode(st
13764  
13765                 spin_lock(&mq_lock);
13766                 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
13767 -                   u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
13768 +                   u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE) ||
13769 +                   !vx_ipcmsg_avail(vxi, mq_bytes)) {
13770                         spin_unlock(&mq_lock);
13771                         /* mqueue_evict_inode() releases info->messages */
13772                         ret = -EMFILE;
13773                         goto out_inode;
13774                 }
13775                 u->mq_bytes += mq_bytes;
13776 +               vx_ipcmsg_add(vxi, u, mq_bytes);
13777                 spin_unlock(&mq_lock);
13778  
13779                 /* all is ok */
13780                 info->user = get_uid(u);
13781 +               info->vxi = get_vx_info(vxi);
13782         } else if (S_ISDIR(mode)) {
13783                 inc_nlink(inode);
13784                 /* Some things misbehave if size == 0 on a directory */
13785 @@ -402,8 +410,11 @@ static void mqueue_evict_inode(struct in
13786  
13787         user = info->user;
13788         if (user) {
13789 +               struct vx_info *vxi = info->vxi;
13790 +
13791                 spin_lock(&mq_lock);
13792                 user->mq_bytes -= mq_bytes;
13793 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
13794                 /*
13795                  * get_ns_from_inode() ensures that the
13796                  * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
13797 @@ -413,6 +424,7 @@ static void mqueue_evict_inode(struct in
13798                 if (ipc_ns)
13799                         ipc_ns->mq_queues_count--;
13800                 spin_unlock(&mq_lock);
13801 +               put_vx_info(vxi);
13802                 free_uid(user);
13803         }
13804         if (ipc_ns)
13805 diff -NurpP --minimal linux-3.9.5/ipc/msg.c linux-3.9.5-vs2.3.6.5/ipc/msg.c
13806 --- linux-3.9.5/ipc/msg.c       2013-05-31 13:45:29.000000000 +0000
13807 +++ linux-3.9.5-vs2.3.6.5/ipc/msg.c     2013-05-31 14:47:11.000000000 +0000
13808 @@ -37,6 +37,7 @@
13809  #include <linux/rwsem.h>
13810  #include <linux/nsproxy.h>
13811  #include <linux/ipc_namespace.h>
13812 +#include <linux/vs_base.h>
13813  
13814  #include <asm/current.h>
13815  #include <asm/uaccess.h>
13816 @@ -190,6 +191,7 @@ static int newque(struct ipc_namespace *
13817  
13818         msq->q_perm.mode = msgflg & S_IRWXUGO;
13819         msq->q_perm.key = key;
13820 +       msq->q_perm.xid = vx_current_xid();
13821  
13822         msq->q_perm.security = NULL;
13823         retval = security_msg_queue_alloc(msq);
13824 diff -NurpP --minimal linux-3.9.5/ipc/sem.c linux-3.9.5-vs2.3.6.5/ipc/sem.c
13825 --- linux-3.9.5/ipc/sem.c       2012-12-11 03:30:57.000000000 +0000
13826 +++ linux-3.9.5-vs2.3.6.5/ipc/sem.c     2013-05-31 14:47:11.000000000 +0000
13827 @@ -86,6 +86,8 @@
13828  #include <linux/rwsem.h>
13829  #include <linux/nsproxy.h>
13830  #include <linux/ipc_namespace.h>
13831 +#include <linux/vs_base.h>
13832 +#include <linux/vs_limit.h>
13833  
13834  #include <asm/uaccess.h>
13835  #include "util.h"
13836 @@ -306,6 +308,7 @@ static int newary(struct ipc_namespace *
13837  
13838         sma->sem_perm.mode = (semflg & S_IRWXUGO);
13839         sma->sem_perm.key = key;
13840 +       sma->sem_perm.xid = vx_current_xid();
13841  
13842         sma->sem_perm.security = NULL;
13843         retval = security_sem_alloc(sma);
13844 @@ -321,6 +324,9 @@ static int newary(struct ipc_namespace *
13845                 return id;
13846         }
13847         ns->used_sems += nsems;
13848 +       /* FIXME: obsoleted? */
13849 +       vx_semary_inc(sma);
13850 +       vx_nsems_add(sma, nsems);
13851  
13852         sma->sem_base = (struct sem *) &sma[1];
13853  
13854 @@ -770,6 +776,9 @@ static void freeary(struct ipc_namespace
13855  
13856         wake_up_sem_queue_do(&tasks);
13857         ns->used_sems -= sma->sem_nsems;
13858 +       /* FIXME: obsoleted? */
13859 +       vx_nsems_sub(sma, sma->sem_nsems);
13860 +       vx_semary_dec(sma);
13861         security_sem_free(sma);
13862         ipc_rcu_putref(sma);
13863  }
13864 diff -NurpP --minimal linux-3.9.5/ipc/shm.c linux-3.9.5-vs2.3.6.5/ipc/shm.c
13865 --- linux-3.9.5/ipc/shm.c       2013-06-11 12:22:40.000000000 +0000
13866 +++ linux-3.9.5-vs2.3.6.5/ipc/shm.c     2013-05-31 14:47:11.000000000 +0000
13867 @@ -39,6 +39,8 @@
13868  #include <linux/nsproxy.h>
13869  #include <linux/mount.h>
13870  #include <linux/ipc_namespace.h>
13871 +#include <linux/vs_context.h>
13872 +#include <linux/vs_limit.h>
13873  
13874  #include <asm/uaccess.h>
13875  
13876 @@ -187,7 +189,12 @@ static void shm_open(struct vm_area_stru
13877   */
13878  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
13879  {
13880 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
13881 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
13882 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
13883 +
13884 +       vx_ipcshm_sub(vxi, shp, numpages);
13885 +       ns->shm_tot -= numpages;
13886 +
13887         shm_rmid(ns, shp);
13888         shm_unlock(shp);
13889         if (!is_file_hugepages(shp->shm_file))
13890 @@ -197,6 +204,7 @@ static void shm_destroy(struct ipc_names
13891                                                 shp->mlock_user);
13892         fput (shp->shm_file);
13893         security_shm_free(shp);
13894 +       put_vx_info(vxi);
13895         ipc_rcu_putref(shp);
13896  }
13897  
13898 @@ -474,11 +482,15 @@ static int newseg(struct ipc_namespace *
13899         if (ns->shm_tot + numpages > ns->shm_ctlall)
13900                 return -ENOSPC;
13901  
13902 +       if (!vx_ipcshm_avail(current_vx_info(), numpages))
13903 +               return -ENOSPC;
13904 +
13905         shp = ipc_rcu_alloc(sizeof(*shp));
13906         if (!shp)
13907                 return -ENOMEM;
13908  
13909         shp->shm_perm.key = key;
13910 +       shp->shm_perm.xid = vx_current_xid();
13911         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
13912         shp->mlock_user = NULL;
13913  
13914 @@ -544,6 +556,7 @@ static int newseg(struct ipc_namespace *
13915         ns->shm_tot += numpages;
13916         error = shp->shm_perm.id;
13917         shm_unlock(shp);
13918 +       vx_ipcshm_add(current_vx_info(), key, numpages);
13919         return error;
13920  
13921  no_id:
13922 diff -NurpP --minimal linux-3.9.5/kernel/Makefile linux-3.9.5-vs2.3.6.5/kernel/Makefile
13923 --- linux-3.9.5/kernel/Makefile 2013-06-11 12:22:40.000000000 +0000
13924 +++ linux-3.9.5-vs2.3.6.5/kernel/Makefile       2013-05-31 14:47:11.000000000 +0000
13925 @@ -24,6 +24,7 @@ endif
13926  
13927  obj-y += sched/
13928  obj-y += power/
13929 +obj-y += vserver/
13930  
13931  obj-$(CONFIG_CHECKPOINT_RESTORE) += kcmp.o
13932  obj-$(CONFIG_FREEZER) += freezer.o
13933 diff -NurpP --minimal linux-3.9.5/kernel/auditsc.c linux-3.9.5-vs2.3.6.5/kernel/auditsc.c
13934 --- linux-3.9.5/kernel/auditsc.c        2013-06-11 12:22:40.000000000 +0000
13935 +++ linux-3.9.5-vs2.3.6.5/kernel/auditsc.c      2013-05-31 14:47:11.000000000 +0000
13936 @@ -2315,7 +2315,7 @@ int audit_set_loginuid(kuid_t loginuid)
13937         if (audit_loginuid_set(task))
13938                 return -EPERM;
13939  #else /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
13940 -       if (!capable(CAP_AUDIT_CONTROL))
13941 +       if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
13942                 return -EPERM;
13943  #endif  /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
13944  
13945 diff -NurpP --minimal linux-3.9.5/kernel/capability.c linux-3.9.5-vs2.3.6.5/kernel/capability.c
13946 --- linux-3.9.5/kernel/capability.c     2013-05-31 13:45:29.000000000 +0000
13947 +++ linux-3.9.5-vs2.3.6.5/kernel/capability.c   2013-05-31 14:47:11.000000000 +0000
13948 @@ -15,6 +15,7 @@
13949  #include <linux/syscalls.h>
13950  #include <linux/pid_namespace.h>
13951  #include <linux/user_namespace.h>
13952 +#include <linux/vs_context.h>
13953  #include <asm/uaccess.h>
13954  
13955  /*
13956 @@ -116,6 +117,7 @@ static int cap_validate_magic(cap_user_h
13957         return 0;
13958  }
13959  
13960 +
13961  /*
13962   * The only thing that can change the capabilities of the current
13963   * process is the current process. As such, we can't be in this code
13964 @@ -349,6 +351,8 @@ bool has_ns_capability_noaudit(struct ta
13965         return (ret == 0);
13966  }
13967  
13968 +#include <linux/vserver/base.h>
13969 +
13970  /**
13971   * has_capability_noaudit - Does a task have a capability (unaudited) in the
13972   * initial user ns
13973 diff -NurpP --minimal linux-3.9.5/kernel/compat.c linux-3.9.5-vs2.3.6.5/kernel/compat.c
13974 --- linux-3.9.5/kernel/compat.c 2013-05-31 13:45:29.000000000 +0000
13975 +++ linux-3.9.5-vs2.3.6.5/kernel/compat.c       2013-05-31 14:47:11.000000000 +0000
13976 @@ -27,6 +27,7 @@
13977  #include <linux/times.h>
13978  #include <linux/ptrace.h>
13979  #include <linux/gfp.h>
13980 +#include <linux/vs_time.h>
13981  
13982  #include <asm/uaccess.h>
13983  
13984 @@ -1059,7 +1060,7 @@ asmlinkage long compat_sys_stime(compat_
13985         if (err)
13986                 return err;
13987  
13988 -       do_settimeofday(&tv);
13989 +       vx_settimeofday(&tv);
13990         return 0;
13991  }
13992  
13993 diff -NurpP --minimal linux-3.9.5/kernel/cred.c linux-3.9.5-vs2.3.6.5/kernel/cred.c
13994 --- linux-3.9.5/kernel/cred.c   2013-02-19 13:58:56.000000000 +0000
13995 +++ linux-3.9.5-vs2.3.6.5/kernel/cred.c 2013-05-31 14:47:11.000000000 +0000
13996 @@ -56,31 +56,6 @@ struct cred init_cred = {
13997         .group_info             = &init_groups,
13998  };
13999  
14000 -static inline void set_cred_subscribers(struct cred *cred, int n)
14001 -{
14002 -#ifdef CONFIG_DEBUG_CREDENTIALS
14003 -       atomic_set(&cred->subscribers, n);
14004 -#endif
14005 -}
14006 -
14007 -static inline int read_cred_subscribers(const struct cred *cred)
14008 -{
14009 -#ifdef CONFIG_DEBUG_CREDENTIALS
14010 -       return atomic_read(&cred->subscribers);
14011 -#else
14012 -       return 0;
14013 -#endif
14014 -}
14015 -
14016 -static inline void alter_cred_subscribers(const struct cred *_cred, int n)
14017 -{
14018 -#ifdef CONFIG_DEBUG_CREDENTIALS
14019 -       struct cred *cred = (struct cred *) _cred;
14020 -
14021 -       atomic_add(n, &cred->subscribers);
14022 -#endif
14023 -}
14024 -
14025  /*
14026   * The RCU callback to actually dispose of a set of credentials
14027   */
14028 @@ -232,21 +207,16 @@ error:
14029   *
14030   * Call commit_creds() or abort_creds() to clean up.
14031   */
14032 -struct cred *prepare_creds(void)
14033 +struct cred *__prepare_creds(const struct cred *old)
14034  {
14035 -       struct task_struct *task = current;
14036 -       const struct cred *old;
14037         struct cred *new;
14038  
14039 -       validate_process_creds();
14040 -
14041         new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
14042         if (!new)
14043                 return NULL;
14044  
14045         kdebug("prepare_creds() alloc %p", new);
14046  
14047 -       old = task->cred;
14048         memcpy(new, old, sizeof(struct cred));
14049  
14050         atomic_set(&new->usage, 1);
14051 @@ -275,6 +245,13 @@ error:
14052         abort_creds(new);
14053         return NULL;
14054  }
14055 +
14056 +struct cred *prepare_creds(void)
14057 +{
14058 +       validate_process_creds();
14059 +
14060 +       return __prepare_creds(current->cred);
14061 +}
14062  EXPORT_SYMBOL(prepare_creds);
14063  
14064  /*
14065 diff -NurpP --minimal linux-3.9.5/kernel/exit.c linux-3.9.5-vs2.3.6.5/kernel/exit.c
14066 --- linux-3.9.5/kernel/exit.c   2013-05-31 13:45:29.000000000 +0000
14067 +++ linux-3.9.5-vs2.3.6.5/kernel/exit.c 2013-05-31 14:47:11.000000000 +0000
14068 @@ -48,6 +48,10 @@
14069  #include <linux/fs_struct.h>
14070  #include <linux/init_task.h>
14071  #include <linux/perf_event.h>
14072 +#include <linux/vs_limit.h>
14073 +#include <linux/vs_context.h>
14074 +#include <linux/vs_network.h>
14075 +#include <linux/vs_pid.h>
14076  #include <trace/events/sched.h>
14077  #include <linux/hw_breakpoint.h>
14078  #include <linux/oom.h>
14079 @@ -514,15 +518,25 @@ static struct task_struct *find_new_reap
14080         __acquires(&tasklist_lock)
14081  {
14082         struct pid_namespace *pid_ns = task_active_pid_ns(father);
14083 -       struct task_struct *thread;
14084 +       struct vx_info *vxi = task_get_vx_info(father);
14085 +       struct task_struct *thread = father;
14086 +       struct task_struct *reaper;
14087  
14088 -       thread = father;
14089         while_each_thread(father, thread) {
14090                 if (thread->flags & PF_EXITING)
14091                         continue;
14092                 if (unlikely(pid_ns->child_reaper == father))
14093                         pid_ns->child_reaper = thread;
14094 -               return thread;
14095 +               reaper = thread;
14096 +               goto out_put;
14097 +       }
14098 +
14099 +       reaper = pid_ns->child_reaper;
14100 +       if (vxi) {
14101 +               BUG_ON(!vxi->vx_reaper);
14102 +               if (vxi->vx_reaper != init_pid_ns.child_reaper &&
14103 +                   vxi->vx_reaper != father)
14104 +                       reaper = vxi->vx_reaper;
14105         }
14106  
14107         if (unlikely(pid_ns->child_reaper == father)) {
14108 @@ -560,7 +574,9 @@ static struct task_struct *find_new_reap
14109                 }
14110         }
14111  
14112 -       return pid_ns->child_reaper;
14113 +out_put:
14114 +       put_vx_info(vxi);
14115 +       return reaper;
14116  }
14117  
14118  /*
14119 @@ -611,10 +627,15 @@ static void forget_original_parent(struc
14120         list_for_each_entry_safe(p, n, &father->children, sibling) {
14121                 struct task_struct *t = p;
14122                 do {
14123 -                       t->real_parent = reaper;
14124 +                       struct task_struct *new_parent = reaper;
14125 +
14126 +                       if (unlikely(p == reaper))
14127 +                               new_parent = task_active_pid_ns(p)->child_reaper;
14128 +
14129 +                       t->real_parent = new_parent;
14130                         if (t->parent == father) {
14131                                 BUG_ON(t->ptrace);
14132 -                               t->parent = t->real_parent;
14133 +                               t->parent = new_parent;
14134                         }
14135                         if (t->pdeath_signal)
14136                                 group_send_sig_info(t->pdeath_signal,
14137 @@ -821,6 +842,9 @@ void do_exit(long code)
14138          */
14139         ptrace_put_breakpoints(tsk);
14140  
14141 +       /* needs to stay before exit_notify() */
14142 +       exit_vx_info_early(tsk, code);
14143 +
14144         exit_notify(tsk, group_dead);
14145  #ifdef CONFIG_NUMA
14146         task_lock(tsk);
14147 @@ -874,10 +898,15 @@ void do_exit(long code)
14148         smp_mb();
14149         raw_spin_unlock_wait(&tsk->pi_lock);
14150  
14151 +       /* needs to stay after exit_notify() */
14152 +       exit_vx_info(tsk, code);
14153 +       exit_nx_info(tsk);
14154 +
14155         /* causes final put_task_struct in finish_task_switch(). */
14156         tsk->state = TASK_DEAD;
14157         tsk->flags |= PF_NOFREEZE;      /* tell freezer to ignore us */
14158         schedule();
14159 +       printk("bad task: %p [%lx]\n", current, current->state);
14160         BUG();
14161         /* Avoid "noreturn function does return".  */
14162         for (;;)
14163 diff -NurpP --minimal linux-3.9.5/kernel/fork.c linux-3.9.5-vs2.3.6.5/kernel/fork.c
14164 --- linux-3.9.5/kernel/fork.c   2013-05-31 13:45:29.000000000 +0000
14165 +++ linux-3.9.5-vs2.3.6.5/kernel/fork.c 2013-05-31 14:47:11.000000000 +0000
14166 @@ -70,6 +70,9 @@
14167  #include <linux/khugepaged.h>
14168  #include <linux/signalfd.h>
14169  #include <linux/uprobes.h>
14170 +#include <linux/vs_context.h>
14171 +#include <linux/vs_network.h>
14172 +#include <linux/vs_limit.h>
14173  
14174  #include <asm/pgtable.h>
14175  #include <asm/pgalloc.h>
14176 @@ -210,6 +213,8 @@ void free_task(struct task_struct *tsk)
14177         arch_release_thread_info(tsk->stack);
14178         free_thread_info(tsk->stack);
14179         rt_mutex_debug_task_free(tsk);
14180 +       clr_vx_info(&tsk->vx_info);
14181 +       clr_nx_info(&tsk->nx_info);
14182         ftrace_graph_exit_task(tsk);
14183         put_seccomp_filter(tsk);
14184         arch_release_task_struct(tsk);
14185 @@ -547,6 +552,7 @@ static struct mm_struct *mm_init(struct
14186         if (likely(!mm_alloc_pgd(mm))) {
14187                 mm->def_flags = 0;
14188                 mmu_notifier_mm_init(mm);
14189 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
14190                 return mm;
14191         }
14192  
14193 @@ -599,6 +605,7 @@ void __mmdrop(struct mm_struct *mm)
14194         destroy_context(mm);
14195         mmu_notifier_mm_destroy(mm);
14196         check_mm(mm);
14197 +       clr_vx_info(&mm->mm_vx_info);
14198         free_mm(mm);
14199  }
14200  EXPORT_SYMBOL_GPL(__mmdrop);
14201 @@ -818,6 +825,7 @@ struct mm_struct *dup_mm(struct task_str
14202                 goto fail_nomem;
14203  
14204         memcpy(mm, oldmm, sizeof(*mm));
14205 +       mm->mm_vx_info = NULL;
14206         mm_init_cpumask(mm);
14207  
14208  #ifdef CONFIG_TRANSPARENT_HUGEPAGE
14209 @@ -859,6 +867,7 @@ fail_nocontext:
14210          * If init_new_context() failed, we cannot use mmput() to free the mm
14211          * because it calls destroy_context()
14212          */
14213 +       clr_vx_info(&mm->mm_vx_info);
14214         mm_free_pgd(mm);
14215         free_mm(mm);
14216         return NULL;
14217 @@ -1137,6 +1146,8 @@ static struct task_struct *copy_process(
14218  {
14219         int retval;
14220         struct task_struct *p;
14221 +       struct vx_info *vxi;
14222 +       struct nx_info *nxi;
14223  
14224         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
14225                 return ERR_PTR(-EINVAL);
14226 @@ -1195,7 +1206,12 @@ static struct task_struct *copy_process(
14227         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
14228         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
14229  #endif
14230 +       init_vx_info(&p->vx_info, current_vx_info());
14231 +       init_nx_info(&p->nx_info, current_nx_info());
14232 +
14233         retval = -EAGAIN;
14234 +       if (!vx_nproc_avail(1))
14235 +               goto bad_fork_free;
14236         if (atomic_read(&p->real_cred->user->processes) >=
14237                         task_rlimit(p, RLIMIT_NPROC)) {
14238                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
14239 @@ -1472,6 +1488,18 @@ static struct task_struct *copy_process(
14240  
14241         total_forks++;
14242         spin_unlock(&current->sighand->siglock);
14243 +
14244 +       /* p is copy of current */
14245 +       vxi = p->vx_info;
14246 +       if (vxi) {
14247 +               claim_vx_info(vxi, p);
14248 +               atomic_inc(&vxi->cvirt.nr_threads);
14249 +               atomic_inc(&vxi->cvirt.total_forks);
14250 +               vx_nproc_inc(p);
14251 +       }
14252 +       nxi = p->nx_info;
14253 +       if (nxi)
14254 +               claim_nx_info(nxi, p);
14255         write_unlock_irq(&tasklist_lock);
14256         proc_fork_connector(p);
14257         cgroup_post_fork(p);
14258 diff -NurpP --minimal linux-3.9.5/kernel/kthread.c linux-3.9.5-vs2.3.6.5/kernel/kthread.c
14259 --- linux-3.9.5/kernel/kthread.c        2013-05-31 13:45:30.000000000 +0000
14260 +++ linux-3.9.5-vs2.3.6.5/kernel/kthread.c      2013-05-31 14:47:11.000000000 +0000
14261 @@ -17,6 +17,7 @@
14262  #include <linux/slab.h>
14263  #include <linux/freezer.h>
14264  #include <linux/ptrace.h>
14265 +#include <linux/vs_pid.h>
14266  #include <trace/events/sched.h>
14267  
14268  static DEFINE_SPINLOCK(kthread_create_lock);
14269 diff -NurpP --minimal linux-3.9.5/kernel/nsproxy.c linux-3.9.5-vs2.3.6.5/kernel/nsproxy.c
14270 --- linux-3.9.5/kernel/nsproxy.c        2013-05-31 13:45:30.000000000 +0000
14271 +++ linux-3.9.5-vs2.3.6.5/kernel/nsproxy.c      2013-05-31 19:28:43.000000000 +0000
14272 @@ -20,11 +20,14 @@
14273  #include <linux/mnt_namespace.h>
14274  #include <linux/utsname.h>
14275  #include <linux/pid_namespace.h>
14276 +#include <linux/vserver/global.h>
14277 +#include <linux/vserver/debug.h>
14278  #include <net/net_namespace.h>
14279  #include <linux/ipc_namespace.h>
14280  #include <linux/proc_fs.h>
14281  #include <linux/file.h>
14282  #include <linux/syscalls.h>
14283 +#include "../fs/mount.h"
14284  
14285  static struct kmem_cache *nsproxy_cachep;
14286  
14287 @@ -46,8 +49,11 @@ static inline struct nsproxy *create_nsp
14288         struct nsproxy *nsproxy;
14289  
14290         nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
14291 -       if (nsproxy)
14292 +       if (nsproxy) {
14293                 atomic_set(&nsproxy->count, 1);
14294 +               atomic_inc(&vs_global_nsproxy);
14295 +       }
14296 +       vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
14297         return nsproxy;
14298  }
14299  
14300 @@ -56,9 +62,12 @@ static inline struct nsproxy *create_nsp
14301   * Return the newly created nsproxy.  Do not attach this to the task,
14302   * leave it to the caller to do proper locking and attach it to task.
14303   */
14304 -static struct nsproxy *create_new_namespaces(unsigned long flags,
14305 -       struct task_struct *tsk, struct user_namespace *user_ns,
14306 -       struct fs_struct *new_fs)
14307 +static struct nsproxy *unshare_namespaces(
14308 +       unsigned long flags,
14309 +       struct nsproxy *orig,
14310 +       struct fs_struct *new_fs,
14311 +       struct user_namespace *new_user,
14312 +       struct pid_namespace *new_pid)
14313  {
14314         struct nsproxy *new_nsp;
14315         int err;
14316 @@ -67,31 +76,31 @@ static struct nsproxy *create_new_namesp
14317         if (!new_nsp)
14318                 return ERR_PTR(-ENOMEM);
14319  
14320 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, user_ns, new_fs);
14321 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_user, new_fs);
14322         if (IS_ERR(new_nsp->mnt_ns)) {
14323                 err = PTR_ERR(new_nsp->mnt_ns);
14324                 goto out_ns;
14325         }
14326  
14327 -       new_nsp->uts_ns = copy_utsname(flags, user_ns, tsk->nsproxy->uts_ns);
14328 +       new_nsp->uts_ns = copy_utsname(flags, new_user, orig->uts_ns);
14329         if (IS_ERR(new_nsp->uts_ns)) {
14330                 err = PTR_ERR(new_nsp->uts_ns);
14331                 goto out_uts;
14332         }
14333  
14334 -       new_nsp->ipc_ns = copy_ipcs(flags, user_ns, tsk->nsproxy->ipc_ns);
14335 +       new_nsp->ipc_ns = copy_ipcs(flags, new_user, orig->ipc_ns);
14336         if (IS_ERR(new_nsp->ipc_ns)) {
14337                 err = PTR_ERR(new_nsp->ipc_ns);
14338                 goto out_ipc;
14339         }
14340  
14341 -       new_nsp->pid_ns = copy_pid_ns(flags, user_ns, tsk->nsproxy->pid_ns);
14342 +       new_nsp->pid_ns = copy_pid_ns(flags, new_user, new_pid);
14343         if (IS_ERR(new_nsp->pid_ns)) {
14344                 err = PTR_ERR(new_nsp->pid_ns);
14345                 goto out_pid;
14346         }
14347  
14348 -       new_nsp->net_ns = copy_net_ns(flags, user_ns, tsk->nsproxy->net_ns);
14349 +       new_nsp->net_ns = copy_net_ns(flags, new_user, orig->net_ns);
14350         if (IS_ERR(new_nsp->net_ns)) {
14351                 err = PTR_ERR(new_nsp->net_ns);
14352                 goto out_net;
14353 @@ -116,6 +125,41 @@ out_ns:
14354         return ERR_PTR(err);
14355  }
14356  
14357 +static struct nsproxy *create_new_namespaces(unsigned long flags,
14358 +       struct task_struct *tsk, struct user_namespace *user_ns,
14359 +       struct fs_struct *new_fs)
14360 +
14361 +{
14362 +       return unshare_namespaces(flags, tsk->nsproxy,
14363 +               new_fs, user_ns, task_active_pid_ns(tsk));
14364 +}
14365 +
14366 +/*
14367 + * copies the nsproxy, setting refcount to 1, and grabbing a
14368 + * reference to all contained namespaces.
14369 + */
14370 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
14371 +{
14372 +       struct nsproxy *ns = create_nsproxy();
14373 +
14374 +       if (ns) {
14375 +               memcpy(ns, orig, sizeof(struct nsproxy));
14376 +               atomic_set(&ns->count, 1);
14377 +
14378 +               if (ns->mnt_ns)
14379 +                       get_mnt_ns(ns->mnt_ns);
14380 +               if (ns->uts_ns)
14381 +                       get_uts_ns(ns->uts_ns);
14382 +               if (ns->ipc_ns)
14383 +                       get_ipc_ns(ns->ipc_ns);
14384 +               if (ns->pid_ns)
14385 +                       get_pid_ns(ns->pid_ns);
14386 +               if (ns->net_ns)
14387 +                       get_net(ns->net_ns);
14388 +       }
14389 +       return ns;
14390 +}
14391 +
14392  /*
14393   * called from clone.  This now handles copy for nsproxy and all
14394   * namespaces therein.
14395 @@ -124,9 +168,12 @@ int copy_namespaces(unsigned long flags,
14396  {
14397         struct nsproxy *old_ns = tsk->nsproxy;
14398         struct user_namespace *user_ns = task_cred_xxx(tsk, user_ns);
14399 -       struct nsproxy *new_ns;
14400 +       struct nsproxy *new_ns = NULL;
14401         int err = 0;
14402  
14403 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
14404 +               flags, tsk, old_ns);
14405 +
14406         if (!old_ns)
14407                 return 0;
14408  
14409 @@ -136,7 +183,7 @@ int copy_namespaces(unsigned long flags,
14410                                 CLONE_NEWPID | CLONE_NEWNET)))
14411                 return 0;
14412  
14413 -       if (!ns_capable(user_ns, CAP_SYS_ADMIN)) {
14414 +       if (!vx_ns_can_unshare(user_ns, CAP_SYS_ADMIN, flags)) {
14415                 err = -EPERM;
14416                 goto out;
14417         }
14418 @@ -163,6 +210,9 @@ int copy_namespaces(unsigned long flags,
14419  
14420  out:
14421         put_nsproxy(old_ns);
14422 +       vxdprintk(VXD_CBIT(space, 3),
14423 +               "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
14424 +               flags, tsk, old_ns, err, new_ns);
14425         return err;
14426  }
14427  
14428 @@ -176,7 +226,9 @@ void free_nsproxy(struct nsproxy *ns)
14429                 put_ipc_ns(ns->ipc_ns);
14430         if (ns->pid_ns)
14431                 put_pid_ns(ns->pid_ns);
14432 -       put_net(ns->net_ns);
14433 +       if (ns->net_ns)
14434 +               put_net(ns->net_ns);
14435 +       atomic_dec(&vs_global_nsproxy);
14436         kmem_cache_free(nsproxy_cachep, ns);
14437  }
14438  
14439 @@ -190,12 +242,16 @@ int unshare_nsproxy_namespaces(unsigned
14440         struct user_namespace *user_ns;
14441         int err = 0;
14442  
14443 +       vxdprintk(VXD_CBIT(space, 4),
14444 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
14445 +               unshare_flags, current->nsproxy);
14446 +
14447         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
14448                                CLONE_NEWNET | CLONE_NEWPID)))
14449                 return 0;
14450  
14451         user_ns = new_cred ? new_cred->user_ns : current_user_ns();
14452 -       if (!ns_capable(user_ns, CAP_SYS_ADMIN))
14453 +       if (!vx_ns_can_unshare(user_ns, CAP_SYS_ADMIN, unshare_flags))
14454                 return -EPERM;
14455  
14456         *new_nsp = create_new_namespaces(unshare_flags, current, user_ns,
14457 diff -NurpP --minimal linux-3.9.5/kernel/pid.c linux-3.9.5-vs2.3.6.5/kernel/pid.c
14458 --- linux-3.9.5/kernel/pid.c    2013-05-31 13:45:30.000000000 +0000
14459 +++ linux-3.9.5-vs2.3.6.5/kernel/pid.c  2013-05-31 15:24:34.000000000 +0000
14460 @@ -37,6 +37,7 @@
14461  #include <linux/init_task.h>
14462  #include <linux/syscalls.h>
14463  #include <linux/proc_fs.h>
14464 +#include <linux/vs_pid.h>
14465  
14466  #define pid_hashfn(nr, ns)     \
14467         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
14468 @@ -364,7 +365,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
14469  
14470  struct pid *find_vpid(int nr)
14471  {
14472 -       return find_pid_ns(nr, task_active_pid_ns(current));
14473 +       return find_pid_ns(vx_rmap_pid(nr), task_active_pid_ns(current));
14474  }
14475  EXPORT_SYMBOL_GPL(find_vpid);
14476  
14477 @@ -424,6 +425,9 @@ void transfer_pid(struct task_struct *ol
14478  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
14479  {
14480         struct task_struct *result = NULL;
14481 +
14482 +       if (type == PIDTYPE_REALPID)
14483 +               type = PIDTYPE_PID;
14484         if (pid) {
14485                 struct hlist_node *first;
14486                 first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]),
14487 @@ -443,7 +447,7 @@ struct task_struct *find_task_by_pid_ns(
14488         rcu_lockdep_assert(rcu_read_lock_held(),
14489                            "find_task_by_pid_ns() needs rcu_read_lock()"
14490                            " protection");
14491 -       return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
14492 +       return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
14493  }
14494  
14495  struct task_struct *find_task_by_vpid(pid_t vnr)
14496 @@ -487,7 +491,7 @@ struct pid *find_get_pid(pid_t nr)
14497  }
14498  EXPORT_SYMBOL_GPL(find_get_pid);
14499  
14500 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
14501 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
14502  {
14503         struct upid *upid;
14504         pid_t nr = 0;
14505 @@ -501,6 +505,11 @@ pid_t pid_nr_ns(struct pid *pid, struct
14506  }
14507  EXPORT_SYMBOL_GPL(pid_nr_ns);
14508  
14509 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
14510 +{
14511 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
14512 +}
14513 +
14514  pid_t pid_vnr(struct pid *pid)
14515  {
14516         return pid_nr_ns(pid, task_active_pid_ns(current));
14517 diff -NurpP --minimal linux-3.9.5/kernel/pid_namespace.c linux-3.9.5-vs2.3.6.5/kernel/pid_namespace.c
14518 --- linux-3.9.5/kernel/pid_namespace.c  2013-05-31 13:45:30.000000000 +0000
14519 +++ linux-3.9.5-vs2.3.6.5/kernel/pid_namespace.c        2013-05-31 17:59:48.000000000 +0000
14520 @@ -18,6 +18,7 @@
14521  #include <linux/proc_fs.h>
14522  #include <linux/reboot.h>
14523  #include <linux/export.h>
14524 +#include <linux/vserver/global.h>
14525  
14526  #define BITS_PER_PAGE          (PAGE_SIZE*8)
14527  
14528 @@ -112,6 +113,7 @@ static struct pid_namespace *create_pid_
14529                 goto out_free_map;
14530  
14531         kref_init(&ns->kref);
14532 +       atomic_inc(&vs_global_pid_ns);
14533         ns->level = level;
14534         ns->parent = get_pid_ns(parent_pid_ns);
14535         ns->user_ns = get_user_ns(user_ns);
14536 @@ -142,6 +144,7 @@ static void destroy_pid_namespace(struct
14537         for (i = 0; i < PIDMAP_ENTRIES; i++)
14538                 kfree(ns->pidmap[i].page);
14539         put_user_ns(ns->user_ns);
14540 +       atomic_dec(&vs_global_pid_ns);
14541         kmem_cache_free(pid_ns_cachep, ns);
14542  }
14543  
14544 diff -NurpP --minimal linux-3.9.5/kernel/posix-timers.c linux-3.9.5-vs2.3.6.5/kernel/posix-timers.c
14545 --- linux-3.9.5/kernel/posix-timers.c   2013-05-31 13:45:30.000000000 +0000
14546 +++ linux-3.9.5-vs2.3.6.5/kernel/posix-timers.c 2013-05-31 14:47:11.000000000 +0000
14547 @@ -47,6 +47,7 @@
14548  #include <linux/wait.h>
14549  #include <linux/workqueue.h>
14550  #include <linux/export.h>
14551 +#include <linux/vs_context.h>
14552  
14553  /*
14554   * Management arrays for POSIX timers.  Timers are kept in slab memory
14555 @@ -340,6 +341,7 @@ int posix_timer_event(struct k_itimer *t
14556  {
14557         struct task_struct *task;
14558         int shared, ret = -1;
14559 +
14560         /*
14561          * FIXME: if ->sigq is queued we can race with
14562          * dequeue_signal()->do_schedule_next_timer().
14563 @@ -356,10 +358,18 @@ int posix_timer_event(struct k_itimer *t
14564         rcu_read_lock();
14565         task = pid_task(timr->it_pid, PIDTYPE_PID);
14566         if (task) {
14567 +               struct vx_info_save vxis;
14568 +               struct vx_info *vxi;
14569 +
14570 +               vxi = get_vx_info(task->vx_info);
14571 +               enter_vx_info(vxi, &vxis);
14572                 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
14573                 ret = send_sigqueue(timr->sigq, task, shared);
14574 +               leave_vx_info(&vxis);
14575 +               put_vx_info(vxi);
14576         }
14577         rcu_read_unlock();
14578 +
14579         /* If we failed to send the signal the timer stops. */
14580         return ret > 0;
14581  }
14582 diff -NurpP --minimal linux-3.9.5/kernel/printk.c linux-3.9.5-vs2.3.6.5/kernel/printk.c
14583 --- linux-3.9.5/kernel/printk.c 2013-05-31 13:45:30.000000000 +0000
14584 +++ linux-3.9.5-vs2.3.6.5/kernel/printk.c       2013-05-31 15:23:35.000000000 +0000
14585 @@ -43,6 +43,7 @@
14586  #include <linux/rculist.h>
14587  #include <linux/poll.h>
14588  #include <linux/irq_work.h>
14589 +#include <linux/vs_cvirt.h>
14590  
14591  #include <asm/uaccess.h>
14592  
14593 @@ -841,7 +842,7 @@ static int check_syslog_permissions(int
14594                 return 0;
14595  
14596         if (syslog_action_restricted(type)) {
14597 -               if (capable(CAP_SYSLOG))
14598 +               if (vx_capable(CAP_SYSLOG, VXC_SYSLOG))
14599                         return 0;
14600                 /* For historical reasons, accept CAP_SYS_ADMIN too, with a warning */
14601                 if (capable(CAP_SYS_ADMIN)) {
14602 @@ -1135,12 +1136,9 @@ int do_syslog(int type, char __user *buf
14603         if (error)
14604                 return error;
14605  
14606 -       switch (type) {
14607 -       case SYSLOG_ACTION_CLOSE:       /* Close log */
14608 -               break;
14609 -       case SYSLOG_ACTION_OPEN:        /* Open log */
14610 -               break;
14611 -       case SYSLOG_ACTION_READ:        /* Read from log */
14612 +       if ((type == SYSLOG_ACTION_READ) ||
14613 +           (type == SYSLOG_ACTION_READ_ALL) ||
14614 +           (type == SYSLOG_ACTION_READ_CLEAR)) {
14615                 error = -EINVAL;
14616                 if (!buf || len < 0)
14617                         goto out;
14618 @@ -1151,6 +1149,16 @@ int do_syslog(int type, char __user *buf
14619                         error = -EFAULT;
14620                         goto out;
14621                 }
14622 +       }
14623 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
14624 +               return vx_do_syslog(type, buf, len);
14625 +
14626 +       switch (type) {
14627 +       case SYSLOG_ACTION_CLOSE:       /* Close log */
14628 +               break;
14629 +       case SYSLOG_ACTION_OPEN:        /* Open log */
14630 +               break;
14631 +       case SYSLOG_ACTION_READ:        /* Read from log */
14632                 error = wait_event_interruptible(log_wait,
14633                                                  syslog_seq != log_next_seq);
14634                 if (error)
14635 @@ -1163,16 +1171,6 @@ int do_syslog(int type, char __user *buf
14636                 /* FALL THRU */
14637         /* Read last kernel messages */
14638         case SYSLOG_ACTION_READ_ALL:
14639 -               error = -EINVAL;
14640 -               if (!buf || len < 0)
14641 -                       goto out;
14642 -               error = 0;
14643 -               if (!len)
14644 -                       goto out;
14645 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
14646 -                       error = -EFAULT;
14647 -                       goto out;
14648 -               }
14649                 error = syslog_print_all(buf, len, clear);
14650                 break;
14651         /* Clear ring buffer */
14652 diff -NurpP --minimal linux-3.9.5/kernel/ptrace.c linux-3.9.5-vs2.3.6.5/kernel/ptrace.c
14653 --- linux-3.9.5/kernel/ptrace.c 2013-05-31 13:45:30.000000000 +0000
14654 +++ linux-3.9.5-vs2.3.6.5/kernel/ptrace.c       2013-05-31 15:22:34.000000000 +0000
14655 @@ -22,6 +22,7 @@
14656  #include <linux/syscalls.h>
14657  #include <linux/uaccess.h>
14658  #include <linux/regset.h>
14659 +#include <linux/vs_context.h>
14660  #include <linux/hw_breakpoint.h>
14661  #include <linux/cn_proc.h>
14662  
14663 @@ -261,6 +262,11 @@ ok:
14664         }
14665         rcu_read_unlock();
14666  
14667 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_WATCH_P|VS_IDENT))
14668 +               return -EPERM;
14669 +       if (!vx_check(task->xid, VS_IDENT) &&
14670 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
14671 +               return -EACCES;
14672         return security_ptrace_access_check(task, mode);
14673  }
14674  
14675 diff -NurpP --minimal linux-3.9.5/kernel/sched/core.c linux-3.9.5-vs2.3.6.5/kernel/sched/core.c
14676 --- linux-3.9.5/kernel/sched/core.c     2013-05-31 13:45:30.000000000 +0000
14677 +++ linux-3.9.5-vs2.3.6.5/kernel/sched/core.c   2013-05-31 15:17:22.000000000 +0000
14678 @@ -73,6 +73,8 @@
14679  #include <linux/init_task.h>
14680  #include <linux/binfmts.h>
14681  #include <linux/context_tracking.h>
14682 +#include <linux/vs_sched.h>
14683 +#include <linux/vs_cvirt.h>
14684  
14685  #include <asm/switch_to.h>
14686  #include <asm/tlb.h>
14687 @@ -2091,9 +2093,17 @@ EXPORT_SYMBOL(avenrun); /* should be rem
14688   */
14689  void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
14690  {
14691 -       loads[0] = (avenrun[0] + offset) << shift;
14692 -       loads[1] = (avenrun[1] + offset) << shift;
14693 -       loads[2] = (avenrun[2] + offset) << shift;
14694 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
14695 +               struct vx_info *vxi = current_vx_info();
14696 +
14697 +               loads[0] = (vxi->cvirt.load[0] + offset) << shift;
14698 +               loads[1] = (vxi->cvirt.load[1] + offset) << shift;
14699 +               loads[2] = (vxi->cvirt.load[2] + offset) << shift;
14700 +       } else {
14701 +               loads[0] = (avenrun[0] + offset) << shift;
14702 +               loads[1] = (avenrun[1] + offset) << shift;
14703 +               loads[2] = (avenrun[2] + offset) << shift;
14704 +       }
14705  }
14706  
14707  static long calc_load_fold_active(struct rq *this_rq)
14708 @@ -3704,7 +3714,7 @@ SYSCALL_DEFINE1(nice, int, increment)
14709                 nice = 19;
14710  
14711         if (increment < 0 && !can_nice(current, nice))
14712 -               return -EPERM;
14713 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
14714  
14715         retval = security_task_setnice(current, nice);
14716         if (retval)
14717 diff -NurpP --minimal linux-3.9.5/kernel/sched/cputime.c linux-3.9.5-vs2.3.6.5/kernel/sched/cputime.c
14718 --- linux-3.9.5/kernel/sched/cputime.c  2013-06-11 12:22:40.000000000 +0000
14719 +++ linux-3.9.5-vs2.3.6.5/kernel/sched/cputime.c        2013-05-31 15:17:55.000000000 +0000
14720 @@ -4,6 +4,7 @@
14721  #include <linux/kernel_stat.h>
14722  #include <linux/static_key.h>
14723  #include <linux/context_tracking.h>
14724 +#include <linux/vs_sched.h>
14725  #include "sched.h"
14726  
14727  
14728 @@ -151,14 +152,17 @@ static inline void task_group_account_fi
14729  void account_user_time(struct task_struct *p, cputime_t cputime,
14730                        cputime_t cputime_scaled)
14731  {
14732 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
14733 +       int nice = (TASK_NICE(p) > 0);
14734         int index;
14735  
14736         /* Add user time to process. */
14737         p->utime += cputime;
14738         p->utimescaled += cputime_scaled;
14739 +       vx_account_user(vxi, cputime, nice);
14740         account_group_user_time(p, cputime);
14741  
14742 -       index = (TASK_NICE(p) > 0) ? CPUTIME_NICE : CPUTIME_USER;
14743 +       index = (nice) ? CPUTIME_NICE : CPUTIME_USER;
14744  
14745         /* Add user time to cpustat. */
14746         task_group_account_field(p, index, (__force u64) cputime);
14747 @@ -205,9 +209,12 @@ static inline
14748  void __account_system_time(struct task_struct *p, cputime_t cputime,
14749                         cputime_t cputime_scaled, int index)
14750  {
14751 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
14752 +
14753         /* Add system time to process. */
14754         p->stime += cputime;
14755         p->stimescaled += cputime_scaled;
14756 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
14757         account_group_system_time(p, cputime);
14758  
14759         /* Add system time to cpustat. */
14760 diff -NurpP --minimal linux-3.9.5/kernel/sched/fair.c linux-3.9.5-vs2.3.6.5/kernel/sched/fair.c
14761 --- linux-3.9.5/kernel/sched/fair.c     2013-05-31 13:45:30.000000000 +0000
14762 +++ linux-3.9.5-vs2.3.6.5/kernel/sched/fair.c   2013-05-31 15:19:37.000000000 +0000
14763 @@ -29,6 +29,7 @@
14764  #include <linux/mempolicy.h>
14765  #include <linux/migrate.h>
14766  #include <linux/task_work.h>
14767 +#include <linux/vs_cvirt.h>
14768  
14769  #include <trace/events/sched.h>
14770  
14771 @@ -1714,6 +1715,8 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
14772                 __enqueue_entity(cfs_rq, se);
14773         se->on_rq = 1;
14774  
14775 +       if (entity_is_task(se))
14776 +               vx_activate_task(task_of(se));
14777         if (cfs_rq->nr_running == 1) {
14778                 list_add_leaf_cfs_rq(cfs_rq);
14779                 check_enqueue_throttle(cfs_rq);
14780 @@ -1795,6 +1798,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
14781         if (se != cfs_rq->curr)
14782                 __dequeue_entity(cfs_rq, se);
14783         se->on_rq = 0;
14784 +       if (entity_is_task(se))
14785 +               vx_deactivate_task(task_of(se));
14786         account_entity_dequeue(cfs_rq, se);
14787  
14788         /*
14789 diff -NurpP --minimal linux-3.9.5/kernel/signal.c linux-3.9.5-vs2.3.6.5/kernel/signal.c
14790 --- linux-3.9.5/kernel/signal.c 2013-05-31 13:45:30.000000000 +0000
14791 +++ linux-3.9.5-vs2.3.6.5/kernel/signal.c       2013-05-31 15:20:05.000000000 +0000
14792 @@ -32,6 +32,8 @@
14793  #include <linux/user_namespace.h>
14794  #include <linux/uprobes.h>
14795  #include <linux/compat.h>
14796 +#include <linux/vs_context.h>
14797 +#include <linux/vs_pid.h>
14798  #define CREATE_TRACE_POINTS
14799  #include <trace/events/signal.h>
14800  
14801 @@ -789,9 +791,18 @@ static int check_kill_permission(int sig
14802         struct pid *sid;
14803         int error;
14804  
14805 +       vxdprintk(VXD_CBIT(misc, 7),
14806 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
14807 +               sig, info, t, vx_task_xid(t), t->pid);
14808 +
14809         if (!valid_signal(sig))
14810                 return -EINVAL;
14811  
14812 +/*     FIXME: needed? if so, why?
14813 +       if ((info != SEND_SIG_NOINFO) &&
14814 +               (is_si_special(info) || !si_fromuser(info)))
14815 +               goto skip;      */
14816 +
14817         if (!si_fromuser(info))
14818                 return 0;
14819  
14820 @@ -815,6 +826,20 @@ static int check_kill_permission(int sig
14821                 }
14822         }
14823  
14824 +       error = -EPERM;
14825 +       if (t->pid == 1 && current->xid)
14826 +               return error;
14827 +
14828 +       error = -ESRCH;
14829 +       /* FIXME: we shouldn't return ESRCH ever, to avoid
14830 +                 loops, maybe ENOENT or EACCES? */
14831 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
14832 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
14833 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
14834 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
14835 +               return error;
14836 +       }
14837 +/* skip: */
14838         return security_task_kill(t, info, sig, 0);
14839  }
14840  
14841 @@ -1351,7 +1376,7 @@ int kill_pid_info(int sig, struct siginf
14842         rcu_read_lock();
14843  retry:
14844         p = pid_task(pid, PIDTYPE_PID);
14845 -       if (p) {
14846 +       if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
14847                 error = group_send_sig_info(sig, info, p);
14848                 if (unlikely(error == -ESRCH))
14849                         /*
14850 @@ -1399,7 +1424,7 @@ int kill_pid_info_as_cred(int sig, struc
14851  
14852         rcu_read_lock();
14853         p = pid_task(pid, PIDTYPE_PID);
14854 -       if (!p) {
14855 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
14856                 ret = -ESRCH;
14857                 goto out_unlock;
14858         }
14859 @@ -1451,8 +1476,10 @@ static int kill_something_info(int sig,
14860                 struct task_struct * p;
14861  
14862                 for_each_process(p) {
14863 -                       if (task_pid_vnr(p) > 1 &&
14864 -                                       !same_thread_group(p, current)) {
14865 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
14866 +                               task_pid_vnr(p) > 1 &&
14867 +                               !same_thread_group(p, current) &&
14868 +                               !vx_current_initpid(p->pid)) {
14869                                 int err = group_send_sig_info(sig, info, p);
14870                                 ++count;
14871                                 if (err != -EPERM)
14872 @@ -2306,6 +2333,11 @@ relock:
14873                                 !sig_kernel_only(signr))
14874                         continue;
14875  
14876 +               /* virtual init is protected against user signals */
14877 +               if ((info->si_code == SI_USER) &&
14878 +                       vx_current_initpid(current->pid))
14879 +                       continue;
14880 +
14881                 if (sig_kernel_stop(signr)) {
14882                         /*
14883                          * The default action is to stop all threads in
14884 diff -NurpP --minimal linux-3.9.5/kernel/softirq.c linux-3.9.5-vs2.3.6.5/kernel/softirq.c
14885 --- linux-3.9.5/kernel/softirq.c        2013-05-31 13:45:30.000000000 +0000
14886 +++ linux-3.9.5-vs2.3.6.5/kernel/softirq.c      2013-05-31 14:47:11.000000000 +0000
14887 @@ -25,6 +25,7 @@
14888  #include <linux/smp.h>
14889  #include <linux/smpboot.h>
14890  #include <linux/tick.h>
14891 +#include <linux/vs_context.h>
14892  
14893  #define CREATE_TRACE_POINTS
14894  #include <trace/events/irq.h>
14895 diff -NurpP --minimal linux-3.9.5/kernel/sys.c linux-3.9.5-vs2.3.6.5/kernel/sys.c
14896 --- linux-3.9.5/kernel/sys.c    2013-05-31 13:45:30.000000000 +0000
14897 +++ linux-3.9.5-vs2.3.6.5/kernel/sys.c  2013-05-31 15:23:14.000000000 +0000
14898 @@ -50,6 +50,7 @@
14899  #include <linux/binfmts.h>
14900  
14901  #include <linux/kmsg_dump.h>
14902 +#include <linux/vs_pid.h>
14903  /* Move somewhere else to avoid recompiling? */
14904  #include <generated/utsrelease.h>
14905  
14906 @@ -155,7 +156,10 @@ static int set_one_prio(struct task_stru
14907                 goto out;
14908         }
14909         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
14910 -               error = -EACCES;
14911 +               if (vx_flags(VXF_IGNEG_NICE, 0))
14912 +                       error = 0;
14913 +               else
14914 +                       error = -EACCES;
14915                 goto out;
14916         }
14917         no_nice = security_task_setnice(p, niceval);
14918 @@ -206,6 +210,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
14919                         else
14920                                 pgrp = task_pgrp(current);
14921                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
14922 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
14923 +                                       continue;
14924                                 error = set_one_prio(p, niceval, error);
14925                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
14926                         break;
14927 @@ -271,6 +277,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
14928                         else
14929                                 pgrp = task_pgrp(current);
14930                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
14931 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
14932 +                                       continue;
14933                                 niceval = 20 - task_nice(p);
14934                                 if (niceval > retval)
14935                                         retval = niceval;
14936 @@ -424,6 +432,8 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
14937  
14938  static DEFINE_MUTEX(reboot_mutex);
14939  
14940 +long vs_reboot(unsigned int, void __user *);
14941 +
14942  /*
14943   * Reboot system call: for obvious reasons only root may call it,
14944   * and even root needs to set up some magic numbers in the registers
14945 @@ -466,6 +476,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
14946         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
14947                 cmd = LINUX_REBOOT_CMD_HALT;
14948  
14949 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
14950 +               return vs_reboot(cmd, arg);
14951 +
14952         mutex_lock(&reboot_mutex);
14953         switch (cmd) {
14954         case LINUX_REBOOT_CMD_RESTART:
14955 @@ -1373,7 +1386,8 @@ SYSCALL_DEFINE2(sethostname, char __user
14956         int errno;
14957         char tmp[__NEW_UTS_LEN];
14958  
14959 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
14960 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
14961 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
14962                 return -EPERM;
14963  
14964         if (len < 0 || len > __NEW_UTS_LEN)
14965 @@ -1424,7 +1438,8 @@ SYSCALL_DEFINE2(setdomainname, char __us
14966         int errno;
14967         char tmp[__NEW_UTS_LEN];
14968  
14969 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
14970 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
14971 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
14972                 return -EPERM;
14973         if (len < 0 || len > __NEW_UTS_LEN)
14974                 return -EINVAL;
14975 @@ -1543,7 +1558,7 @@ int do_prlimit(struct task_struct *tsk,
14976                 /* Keep the capable check against init_user_ns until
14977                    cgroups can contain all limits */
14978                 if (new_rlim->rlim_max > rlim->rlim_max &&
14979 -                               !capable(CAP_SYS_RESOURCE))
14980 +                       !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
14981                         retval = -EPERM;
14982                 if (!retval)
14983                         retval = security_task_setrlimit(tsk->group_leader,
14984 @@ -1596,7 +1611,8 @@ static int check_prlimit_permission(stru
14985             gid_eq(cred->gid, tcred->sgid) &&
14986             gid_eq(cred->gid, tcred->gid))
14987                 return 0;
14988 -       if (ns_capable(tcred->user_ns, CAP_SYS_RESOURCE))
14989 +       if (vx_ns_capable(tcred->user_ns,
14990 +               CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
14991                 return 0;
14992  
14993         return -EPERM;
14994 diff -NurpP --minimal linux-3.9.5/kernel/sysctl.c linux-3.9.5-vs2.3.6.5/kernel/sysctl.c
14995 --- linux-3.9.5/kernel/sysctl.c 2013-05-31 13:45:30.000000000 +0000
14996 +++ linux-3.9.5-vs2.3.6.5/kernel/sysctl.c       2013-05-31 15:28:39.000000000 +0000
14997 @@ -83,6 +83,7 @@
14998  #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
14999  #include <linux/lockdep.h>
15000  #endif
15001 +extern char vshelper_path[];
15002  #ifdef CONFIG_CHR_DEV_SG
15003  #include <scsi/sg.h>
15004  #endif
15005 @@ -629,6 +630,13 @@ static struct ctl_table kern_table[] = {
15006                 .mode           = 0644,
15007                 .proc_handler   = proc_dostring,
15008         },
15009 +       {
15010 +               .procname       = "vshelper",
15011 +               .data           = &vshelper_path,
15012 +               .maxlen         = 256,
15013 +               .mode           = 0644,
15014 +               .proc_handler   = &proc_dostring,
15015 +       },
15016  
15017  #ifdef CONFIG_CHR_DEV_SG
15018         {
15019 diff -NurpP --minimal linux-3.9.5/kernel/sysctl_binary.c linux-3.9.5-vs2.3.6.5/kernel/sysctl_binary.c
15020 --- linux-3.9.5/kernel/sysctl_binary.c  2013-05-31 13:45:30.000000000 +0000
15021 +++ linux-3.9.5-vs2.3.6.5/kernel/sysctl_binary.c        2013-05-31 14:47:11.000000000 +0000
15022 @@ -73,6 +73,7 @@ static const struct bin_table bin_kern_t
15023  
15024         { CTL_INT,      KERN_PANIC,                     "panic" },
15025         { CTL_INT,      KERN_REALROOTDEV,               "real-root-dev" },
15026 +       { CTL_STR,      KERN_VSHELPER,                  "vshelper" },
15027  
15028         { CTL_STR,      KERN_SPARC_REBOOT,              "reboot-cmd" },
15029         { CTL_INT,      KERN_CTLALTDEL,                 "ctrl-alt-del" },
15030 diff -NurpP --minimal linux-3.9.5/kernel/time/timekeeping.c linux-3.9.5-vs2.3.6.5/kernel/time/timekeeping.c
15031 --- linux-3.9.5/kernel/time/timekeeping.c       2013-05-31 13:45:30.000000000 +0000
15032 +++ linux-3.9.5-vs2.3.6.5/kernel/time/timekeeping.c     2013-05-31 15:24:55.000000000 +0000
15033 @@ -22,6 +22,7 @@
15034  #include <linux/tick.h>
15035  #include <linux/stop_machine.h>
15036  #include <linux/pvclock_gtod.h>
15037 +#include <linux/vs_time.h>
15038  
15039  
15040  static struct timekeeper timekeeper;
15041 @@ -594,6 +595,7 @@ void getrawmonotonic(struct timespec *ts
15042         } while (read_seqretry(&tk->lock, seq));
15043  
15044         timespec_add_ns(ts, nsecs);
15045 +       vx_adjust_timespec(ts);
15046  }
15047  EXPORT_SYMBOL(getrawmonotonic);
15048  
15049 diff -NurpP --minimal linux-3.9.5/kernel/time.c linux-3.9.5-vs2.3.6.5/kernel/time.c
15050 --- linux-3.9.5/kernel/time.c   2013-05-31 13:45:30.000000000 +0000
15051 +++ linux-3.9.5-vs2.3.6.5/kernel/time.c 2013-05-31 14:47:11.000000000 +0000
15052 @@ -37,6 +37,7 @@
15053  #include <linux/fs.h>
15054  #include <linux/math64.h>
15055  #include <linux/ptrace.h>
15056 +#include <linux/vs_time.h>
15057  
15058  #include <asm/uaccess.h>
15059  #include <asm/unistd.h>
15060 @@ -92,7 +93,7 @@ SYSCALL_DEFINE1(stime, time_t __user *,
15061         if (err)
15062                 return err;
15063  
15064 -       do_settimeofday(&tv);
15065 +       vx_settimeofday(&tv);
15066         return 0;
15067  }
15068  
15069 @@ -180,7 +181,7 @@ int do_sys_settimeofday(const struct tim
15070                 }
15071         }
15072         if (tv)
15073 -               return do_settimeofday(tv);
15074 +               return vx_settimeofday(tv);
15075         return 0;
15076  }
15077  
15078 diff -NurpP --minimal linux-3.9.5/kernel/timer.c linux-3.9.5-vs2.3.6.5/kernel/timer.c
15079 --- linux-3.9.5/kernel/timer.c  2013-06-11 12:22:40.000000000 +0000
15080 +++ linux-3.9.5-vs2.3.6.5/kernel/timer.c        2013-05-31 14:47:11.000000000 +0000
15081 @@ -41,6 +41,10 @@
15082  #include <linux/sched.h>
15083  #include <linux/sched/sysctl.h>
15084  #include <linux/slab.h>
15085 +#include <linux/vs_base.h>
15086 +#include <linux/vs_cvirt.h>
15087 +#include <linux/vs_pid.h>
15088 +#include <linux/vserver/sched.h>
15089  
15090  #include <asm/uaccess.h>
15091  #include <asm/unistd.h>
15092 diff -NurpP --minimal linux-3.9.5/kernel/user_namespace.c linux-3.9.5-vs2.3.6.5/kernel/user_namespace.c
15093 --- linux-3.9.5/kernel/user_namespace.c 2013-05-31 13:45:30.000000000 +0000
15094 +++ linux-3.9.5-vs2.3.6.5/kernel/user_namespace.c       2013-05-31 17:44:56.000000000 +0000
15095 @@ -22,6 +22,7 @@
15096  #include <linux/ctype.h>
15097  #include <linux/projid.h>
15098  #include <linux/fs_struct.h>
15099 +#include <linux/vserver/global.h>
15100  
15101  static struct kmem_cache *user_ns_cachep __read_mostly;
15102  
15103 @@ -91,6 +92,7 @@ int create_user_ns(struct cred *new)
15104  
15105         atomic_set(&ns->count, 1);
15106         /* Leave the new->user_ns reference with the new user namespace. */
15107 +       atomic_inc(&vs_global_user_ns);
15108         ns->parent = parent_ns;
15109         ns->owner = owner;
15110         ns->group = group;
15111 @@ -835,6 +837,8 @@ static void *userns_get(struct task_stru
15112  
15113  static void userns_put(void *ns)
15114  {
15115 +       /* FIXME: maybe move into destroyer? */
15116 +       atomic_dec(&vs_global_user_ns);
15117         put_user_ns(ns);
15118  }
15119  
15120 diff -NurpP --minimal linux-3.9.5/kernel/utsname.c linux-3.9.5-vs2.3.6.5/kernel/utsname.c
15121 --- linux-3.9.5/kernel/utsname.c        2013-05-31 13:45:30.000000000 +0000
15122 +++ linux-3.9.5-vs2.3.6.5/kernel/utsname.c      2013-05-31 15:15:55.000000000 +0000
15123 @@ -16,14 +16,17 @@
15124  #include <linux/slab.h>
15125  #include <linux/user_namespace.h>
15126  #include <linux/proc_fs.h>
15127 +#include <linux/vserver/global.h>
15128  
15129  static struct uts_namespace *create_uts_ns(void)
15130  {
15131         struct uts_namespace *uts_ns;
15132  
15133         uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
15134 -       if (uts_ns)
15135 +       if (uts_ns) {
15136                 kref_init(&uts_ns->kref);
15137 +               atomic_inc(&vs_global_uts_ns);
15138 +       }
15139         return uts_ns;
15140  }
15141  
15142 @@ -85,6 +88,7 @@ void free_uts_ns(struct kref *kref)
15143         ns = container_of(kref, struct uts_namespace, kref);
15144         put_user_ns(ns->user_ns);
15145         proc_free_inum(ns->proc_inum);
15146 +       atomic_dec(&vs_global_uts_ns);
15147         kfree(ns);
15148  }
15149  
15150 diff -NurpP --minimal linux-3.9.5/kernel/vserver/Kconfig linux-3.9.5-vs2.3.6.5/kernel/vserver/Kconfig
15151 --- linux-3.9.5/kernel/vserver/Kconfig  1970-01-01 00:00:00.000000000 +0000
15152 +++ linux-3.9.5-vs2.3.6.5/kernel/vserver/Kconfig        2013-05-31 14:47:11.000000000 +0000
15153 @@ -0,0 +1,233 @@
15154 +#
15155 +# Linux VServer configuration
15156 +#
15157 +
15158 +menu "Linux VServer"
15159 +
15160 +config VSERVER_AUTO_LBACK
15161 +       bool    "Automatically Assign Loopback IP"
15162 +       default y
15163 +       help
15164 +         Automatically assign a guest specific loopback
15165 +         IP and add it to the kernel network stack on
15166 +         startup.
15167 +
15168 +config VSERVER_AUTO_SINGLE
15169 +       bool    "Automatic Single IP Special Casing"
15170 +       depends on EXPERIMENTAL
15171 +       default y
15172 +       help
15173 +         This allows network contexts with a single IP to
15174 +         automatically remap 0.0.0.0 bindings to that IP,
15175 +         avoiding further network checks and improving
15176 +         performance.
15177 +
15178 +         (note: such guests do not allow to change the ip
15179 +          on the fly and do not show loopback addresses)
15180 +
15181 +config VSERVER_COWBL
15182 +       bool    "Enable COW Immutable Link Breaking"
15183 +       default y
15184 +       help
15185 +         This enables the COW (Copy-On-Write) link break code.
15186 +         It allows you to treat unified files like normal files
15187 +         when writing to them (which will implicitely break the
15188 +         link and create a copy of the unified file)
15189 +
15190 +config VSERVER_VTIME
15191 +       bool    "Enable Virtualized Guest Time"
15192 +       depends on EXPERIMENTAL
15193 +       default n
15194 +       help
15195 +         This enables per guest time offsets to allow for
15196 +         adjusting the system clock individually per guest.
15197 +         this adds some overhead to the time functions and
15198 +         therefore should not be enabled without good reason.
15199 +
15200 +config VSERVER_DEVICE
15201 +       bool    "Enable Guest Device Mapping"
15202 +       depends on EXPERIMENTAL
15203 +       default n
15204 +       help
15205 +         This enables generic device remapping.
15206 +
15207 +config VSERVER_PROC_SECURE
15208 +       bool    "Enable Proc Security"
15209 +       depends on PROC_FS
15210 +       default y
15211 +       help
15212 +         This configures ProcFS security to initially hide
15213 +         non-process entries for all contexts except the main and
15214 +         spectator context (i.e. for all guests), which is a secure
15215 +         default.
15216 +
15217 +         (note: on 1.2x the entries were visible by default)
15218 +
15219 +choice
15220 +       prompt  "Persistent Inode Tagging"
15221 +       default TAGGING_ID24
15222 +       help
15223 +         This adds persistent context information to filesystems
15224 +         mounted with the tagxid option. Tagging is a requirement
15225 +         for per-context disk limits and per-context quota.
15226 +
15227 +
15228 +config TAGGING_NONE
15229 +       bool    "Disabled"
15230 +       help
15231 +         do not store per-context information in inodes.
15232 +
15233 +config TAGGING_UID16
15234 +       bool    "UID16/GID32"
15235 +       help
15236 +         reduces UID to 16 bit, but leaves GID at 32 bit.
15237 +
15238 +config TAGGING_GID16
15239 +       bool    "UID32/GID16"
15240 +       help
15241 +         reduces GID to 16 bit, but leaves UID at 32 bit.
15242 +
15243 +config TAGGING_ID24
15244 +       bool    "UID24/GID24"
15245 +       help
15246 +         uses the upper 8bit from UID and GID for XID tagging
15247 +         which leaves 24bit for UID/GID each, which should be
15248 +         more than sufficient for normal use.
15249 +
15250 +config TAGGING_INTERN
15251 +       bool    "UID32/GID32"
15252 +       help
15253 +         this uses otherwise reserved inode fields in the on
15254 +         disk representation, which limits the use to a few
15255 +         filesystems (currently ext2 and ext3)
15256 +
15257 +endchoice
15258 +
15259 +config TAG_NFSD
15260 +       bool    "Tag NFSD User Auth and Files"
15261 +       default n
15262 +       help
15263 +         Enable this if you do want the in-kernel NFS
15264 +         Server to use the tagging specified above.
15265 +         (will require patched clients too)
15266 +
15267 +config VSERVER_PRIVACY
15268 +       bool    "Honor Privacy Aspects of Guests"
15269 +       default n
15270 +       help
15271 +         When enabled, most context checks will disallow
15272 +         access to structures assigned to a specific context,
15273 +         like ptys or loop devices.
15274 +
15275 +config VSERVER_CONTEXTS
15276 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
15277 +       range 1 65533
15278 +       default "768"   if 64BIT
15279 +       default "256"
15280 +       help
15281 +         This setting will optimize certain data structures
15282 +         and memory allocations according to the expected
15283 +         maximum.
15284 +
15285 +         note: this is not a strict upper limit.
15286 +
15287 +config VSERVER_WARN
15288 +       bool    "VServer Warnings"
15289 +       default y
15290 +       help
15291 +         This enables various runtime warnings, which will
15292 +         notify about potential manipulation attempts or
15293 +         resource shortage. It is generally considered to
15294 +         be a good idea to have that enabled.
15295 +
15296 +config VSERVER_WARN_DEVPTS
15297 +       bool    "VServer DevPTS Warnings"
15298 +       depends on VSERVER_WARN
15299 +       default y
15300 +       help
15301 +         This enables DevPTS related warnings, issued when a
15302 +         process inside a context tries to lookup or access
15303 +         a dynamic pts from the host or a different context.
15304 +
15305 +config VSERVER_DEBUG
15306 +       bool    "VServer Debugging Code"
15307 +       default n
15308 +       help
15309 +         Set this to yes if you want to be able to activate
15310 +         debugging output at runtime. It adds a very small
15311 +         overhead to all vserver related functions and
15312 +         increases the kernel size by about 20k.
15313 +
15314 +config VSERVER_HISTORY
15315 +       bool    "VServer History Tracing"
15316 +       depends on VSERVER_DEBUG
15317 +       default n
15318 +       help
15319 +         Set this to yes if you want to record the history of
15320 +         linux-vserver activities, so they can be replayed in
15321 +         the event of a kernel panic or oops.
15322 +
15323 +config VSERVER_HISTORY_SIZE
15324 +       int     "Per-CPU History Size (32-65536)"
15325 +       depends on VSERVER_HISTORY
15326 +       range 32 65536
15327 +       default 64
15328 +       help
15329 +         This allows you to specify the number of entries in
15330 +         the per-CPU history buffer.
15331 +
15332 +config VSERVER_EXTRA_MNT_CHECK
15333 +       bool    "Extra Checks for Reachability"
15334 +       default n
15335 +       help
15336 +         Set this to yes if you want to do extra checks for
15337 +         vfsmount reachability in the proc filesystem code.
15338 +         This shouldn't be required on any setup utilizing
15339 +         mnt namespaces.
15340 +
15341 +choice
15342 +       prompt  "Quotes used in debug and warn messages"
15343 +       default QUOTES_ISO8859
15344 +
15345 +config QUOTES_ISO8859
15346 +       bool    "Extended ASCII (ISO 8859) angle quotes"
15347 +       help
15348 +         This uses the extended ASCII characters \xbb
15349 +         and \xab for quoting file and process names.
15350 +
15351 +config QUOTES_UTF8
15352 +       bool    "UTF-8 angle quotes"
15353 +       help
15354 +         This uses the the UTF-8 sequences for angle
15355 +         quotes to quote file and process names.
15356 +
15357 +config QUOTES_ASCII
15358 +       bool    "ASCII single quotes"
15359 +       help
15360 +         This uses the ASCII single quote character
15361 +         (\x27) to quote file and process names.
15362 +
15363 +endchoice
15364 +
15365 +endmenu
15366 +
15367 +
15368 +config VSERVER
15369 +       bool
15370 +       default y
15371 +       select NAMESPACES
15372 +       select UTS_NS
15373 +       select IPC_NS
15374 +#      select USER_NS
15375 +       select SYSVIPC
15376 +
15377 +config VSERVER_SECURITY
15378 +       bool
15379 +       depends on SECURITY
15380 +       default y
15381 +       select SECURITY_CAPABILITIES
15382 +
15383 +config VSERVER_DISABLED
15384 +       bool
15385 +       default n
15386 +
15387 diff -NurpP --minimal linux-3.9.5/kernel/vserver/Makefile linux-3.9.5-vs2.3.6.5/kernel/vserver/Makefile
15388 --- linux-3.9.5/kernel/vserver/Makefile 1970-01-01 00:00:00.000000000 +0000
15389 +++ linux-3.9.5-vs2.3.6.5/kernel/vserver/Makefile       2013-05-31 14:47:11.000000000 +0000
15390 @@ -0,0 +1,18 @@
15391 +#
15392 +# Makefile for the Linux vserver routines.
15393 +#
15394 +
15395 +
15396 +obj-y          += vserver.o
15397 +
15398 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
15399 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
15400 +                  dlimit.o tag.o
15401 +
15402 +vserver-$(CONFIG_INET) += inet.o
15403 +vserver-$(CONFIG_PROC_FS) += proc.o
15404 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
15405 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
15406 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
15407 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
15408 +
15409 diff -NurpP --minimal linux-3.9.5/kernel/vserver/cacct.c linux-3.9.5-vs2.3.6.5/kernel/vserver/cacct.c
15410 --- linux-3.9.5/kernel/vserver/cacct.c  1970-01-01 00:00:00.000000000 +0000
15411 +++ linux-3.9.5-vs2.3.6.5/kernel/vserver/cacct.c        2013-05-31 14:47:11.000000000 +0000
15412 @@ -0,0 +1,42 @@
15413 +/*
15414 + *  linux/kernel/vserver/cacct.c
15415 + *
15416 + *  Virtual Server: Context Accounting
15417 + *
15418 + *  Copyright (C) 2006-2007 Herbert Pötzl
15419 + *
15420 + *  V0.01  added accounting stats
15421 + *
15422 + */
15423 +
15424 +#include <linux/types.h>
15425 +#include <linux/vs_context.h>
15426 +#include <linux/vserver/cacct_cmd.h>
15427 +#include <linux/vserver/cacct_int.h>
15428 +
15429 +#include <asm/errno.h>
15430 +#include <asm/uaccess.h>
15431 +
15432 +
15433 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
15434 +{
15435 +       struct vcmd_sock_stat_v0 vc_data;
15436 +       int j, field;
15437 +
15438 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15439 +               return -EFAULT;
15440 +
15441 +       field = vc_data.field;
15442 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
15443 +               return -EINVAL;
15444 +
15445 +       for (j = 0; j < 3; j++) {
15446 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
15447 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
15448 +       }
15449 +
15450 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15451 +               return -EFAULT;
15452 +       return 0;
15453 +}
15454 +
15455 diff -NurpP --minimal linux-3.9.5/kernel/vserver/cacct_init.h linux-3.9.5-vs2.3.6.5/kernel/vserver/cacct_init.h
15456 --- linux-3.9.5/kernel/vserver/cacct_init.h     1970-01-01 00:00:00.000000000 +0000
15457 +++ linux-3.9.5-vs2.3.6.5/kernel/vserver/cacct_init.h   2013-05-31 14:47:11.000000000 +0000
15458 @@ -0,0 +1,25 @@
15459 +
15460 +
15461 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
15462 +{
15463 +       int i, j;
15464 +
15465 +
15466 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
15467 +               for (j = 0; j < 3; j++) {
15468 +                       atomic_long_set(&cacct->sock[i][j].count, 0);
15469 +                       atomic_long_set(&cacct->sock[i][j].total, 0);
15470 +               }
15471 +       }
15472 +       for (i = 0; i < 8; i++)
15473 +               atomic_set(&cacct->slab[i], 0);
15474 +       for (i = 0; i < 5; i++)
15475 +               for (j = 0; j < 4; j++)
15476 +                       atomic_set(&cacct->page[i][j], 0);
15477 +}
15478 +
15479 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
15480 +{
15481 +       return;
15482 +}
15483 +
15484 diff -NurpP --minimal linux-3.9.5/kernel/vserver/cacct_proc.h linux-3.9.5-vs2.3.6.5/kernel/vserver/cacct_proc.h
15485 --- linux-3.9.5/kernel/vserver/cacct_proc.h     1970-01-01 00:00:00.000000000 +0000
15486 +++ linux-3.9.5-vs2.3.6.5/kernel/vserver/cacct_proc.h   2013-05-31 14:47:11.000000000 +0000
15487 @@ -0,0 +1,53 @@
15488 +#ifndef _VX_CACCT_PROC_H
15489 +#define _VX_CACCT_PROC_H
15490 +
15491 +#include <linux/vserver/cacct_int.h>
15492 +
15493 +
15494 +#define VX_SOCKA_TOP   \
15495 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
15496 +
15497 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
15498 +{
15499 +       int i, j, length = 0;
15500 +       static char *type[VXA_SOCK_SIZE] = {
15501 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
15502 +       };
15503 +
15504 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
15505 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
15506 +               length += sprintf(buffer + length, "%s:", type[i]);
15507 +               for (j = 0; j < 3; j++) {
15508 +                       length += sprintf(buffer + length,
15509 +                               "\t%10lu/%-10lu",
15510 +                               vx_sock_count(cacct, i, j),
15511 +                               vx_sock_total(cacct, i, j));
15512 +               }
15513 +               buffer[length++] = '\n';
15514 +       }
15515 +
15516 +       length += sprintf(buffer + length, "\n");
15517 +       length += sprintf(buffer + length,
15518 +               "slab:\t %8u %8u %8u %8u\n",
15519 +               atomic_read(&cacct->slab[1]),
15520 +               atomic_read(&cacct->slab[4]),
15521 +               atomic_read(&cacct->slab[0]),
15522 +               atomic_read(&cacct->slab[2]));
15523 +
15524 +       length += sprintf(buffer + length, "\n");
15525 +       for (i = 0; i < 5; i++) {
15526 +               length += sprintf(buffer + length,
15527 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
15528 +                       atomic_read(&cacct->page[i][0]),
15529 +                       atomic_read(&cacct->page[i][1]),
15530 +                       atomic_read(&cacct->page[i][2]),
15531 +                       atomic_read(&cacct->page[i][3]),
15532 +                       atomic_read(&cacct->page[i][4]),
15533 +                       atomic_read(&cacct->page[i][5]),
15534 +                       atomic_read(&cacct->page[i][6]),
15535 +                       atomic_read(&cacct->page[i][7]));
15536 +       }
15537 +       return length;
15538 +}
15539 +
15540 +#endif /* _VX_CACCT_PROC_H */
15541 diff -NurpP --minimal linux-3.9.5/kernel/vserver/context.c linux-3.9.5-vs2.3.6.5/kernel/vserver/context.c
15542 --- linux-3.9.5/kernel/vserver/context.c        1970-01-01 00:00:00.000000000 +0000
15543 +++ linux-3.9.5-vs2.3.6.5/kernel/vserver/context.c      2013-06-12 23:49:09.000000000 +0000
15544 @@ -0,0 +1,1119 @@
15545 +/*
15546 + *  linux/kernel/vserver/context.c
15547 + *
15548 + *  Virtual Server: Context Support
15549 + *
15550 + *  Copyright (C) 2003-2011  Herbert Pötzl
15551 + *
15552 + *  V0.01  context helper
15553 + *  V0.02  vx_ctx_kill syscall command
15554 + *  V0.03  replaced context_info calls
15555 + *  V0.04  redesign of struct (de)alloc
15556 + *  V0.05  rlimit basic implementation
15557 + *  V0.06  task_xid and info commands
15558 + *  V0.07  context flags and caps
15559 + *  V0.08  switch to RCU based hash
15560 + *  V0.09  revert to non RCU for now
15561 + *  V0.10  and back to working RCU hash
15562 + *  V0.11  and back to locking again
15563 + *  V0.12  referenced context store
15564 + *  V0.13  separate per cpu data
15565 + *  V0.14  changed vcmds to vxi arg
15566 + *  V0.15  added context stat
15567 + *  V0.16  have __create claim() the vxi
15568 + *  V0.17  removed older and legacy stuff
15569 + *  V0.18  added user credentials
15570 + *  V0.19  added warn mask
15571 + *
15572 + */
15573 +
15574 +#include <linux/slab.h>
15575 +#include <linux/types.h>
15576 +#include <linux/security.h>
15577 +#include <linux/pid_namespace.h>
15578 +#include <linux/capability.h>
15579 +
15580 +#include <linux/vserver/context.h>
15581 +#include <linux/vserver/network.h>
15582 +#include <linux/vserver/debug.h>
15583 +#include <linux/vserver/limit.h>
15584 +#include <linux/vserver/limit_int.h>
15585 +#include <linux/vserver/space.h>
15586 +#include <linux/init_task.h>
15587 +#include <linux/fs_struct.h>
15588 +#include <linux/cred.h>
15589 +
15590 +#include <linux/vs_context.h>
15591 +#include <linux/vs_limit.h>
15592 +#include <linux/vs_pid.h>
15593 +#include <linux/vserver/context_cmd.h>
15594 +
15595 +#include "cvirt_init.h"
15596 +#include "cacct_init.h"
15597 +#include "limit_init.h"
15598 +#include "sched_init.h"
15599 +
15600 +
15601 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
15602 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
15603 +
15604 +
15605 +/*     now inactive context structures */
15606 +
15607 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
15608 +
15609 +static DEFINE_SPINLOCK(vx_info_inactive_lock);
15610 +
15611 +
15612 +/*     __alloc_vx_info()
15613 +
15614 +       * allocate an initialized vx_info struct
15615 +       * doesn't make it visible (hash)                        */
15616 +
15617 +static struct vx_info *__alloc_vx_info(vxid_t xid)
15618 +{
15619 +       struct vx_info *new = NULL;
15620 +       int cpu, index;
15621 +
15622 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
15623 +
15624 +       /* would this benefit from a slab cache? */
15625 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
15626 +       if (!new)
15627 +               return 0;
15628 +
15629 +       memset(new, 0, sizeof(struct vx_info));
15630 +#ifdef CONFIG_SMP
15631 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
15632 +       if (!new->ptr_pc)
15633 +               goto error;
15634 +#endif
15635 +       new->vx_id = xid;
15636 +       INIT_HLIST_NODE(&new->vx_hlist);
15637 +       atomic_set(&new->vx_usecnt, 0);
15638 +       atomic_set(&new->vx_tasks, 0);
15639 +       new->vx_parent = NULL;
15640 +       new->vx_state = 0;
15641 +       init_waitqueue_head(&new->vx_wait);
15642 +
15643 +       /* prepare reaper */
15644 +       get_task_struct(init_pid_ns.child_reaper);
15645 +       new->vx_reaper = init_pid_ns.child_reaper;
15646 +       new->vx_badness_bias = 0;
15647 +
15648 +       /* rest of init goes here */
15649 +       vx_info_init_limit(&new->limit);
15650 +       vx_info_init_sched(&new->sched);
15651 +       vx_info_init_cvirt(&new->cvirt);
15652 +       vx_info_init_cacct(&new->cacct);
15653 +
15654 +       /* per cpu data structures */
15655 +       for_each_possible_cpu(cpu) {
15656 +               vx_info_init_sched_pc(
15657 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
15658 +               vx_info_init_cvirt_pc(
15659 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
15660 +       }
15661 +
15662 +       new->vx_flags = VXF_INIT_SET;
15663 +       new->vx_bcaps = CAP_FULL_SET;   // maybe ~CAP_SETPCAP
15664 +       new->vx_ccaps = 0;
15665 +       new->vx_umask = 0;
15666 +       new->vx_wmask = 0;
15667 +
15668 +       new->reboot_cmd = 0;
15669 +       new->exit_code = 0;
15670 +
15671 +       // preconfig spaces
15672 +       for (index = 0; index < VX_SPACES; index++) {
15673 +               struct _vx_space *space = &new->space[index];
15674 +
15675 +               // filesystem
15676 +               spin_lock(&init_fs.lock);
15677 +               init_fs.users++;
15678 +               spin_unlock(&init_fs.lock);
15679 +               space->vx_fs = &init_fs;
15680 +
15681 +               /* FIXME: do we want defaults? */
15682 +               // space->vx_real_cred = 0;
15683 +               // space->vx_cred = 0;
15684 +       }
15685 +
15686 +
15687 +       vxdprintk(VXD_CBIT(xid, 0),
15688 +               "alloc_vx_info(%d) = %p", xid, new);
15689 +       vxh_alloc_vx_info(new);
15690 +       atomic_inc(&vx_global_ctotal);
15691 +       return new;
15692 +#ifdef CONFIG_SMP
15693 +error:
15694 +       kfree(new);
15695 +       return 0;
15696 +#endif
15697 +}
15698 +
15699 +/*     __dealloc_vx_info()
15700 +
15701 +       * final disposal of vx_info                             */
15702 +
15703 +static void __dealloc_vx_info(struct vx_info *vxi)
15704 +{
15705 +#ifdef CONFIG_VSERVER_WARN
15706 +       struct vx_info_save vxis;
15707 +       int cpu;
15708 +#endif
15709 +       vxdprintk(VXD_CBIT(xid, 0),
15710 +               "dealloc_vx_info(%p)", vxi);
15711 +       vxh_dealloc_vx_info(vxi);
15712 +
15713 +#ifdef CONFIG_VSERVER_WARN
15714 +       enter_vx_info(vxi, &vxis);
15715 +       vx_info_exit_limit(&vxi->limit);
15716 +       vx_info_exit_sched(&vxi->sched);
15717 +       vx_info_exit_cvirt(&vxi->cvirt);
15718 +       vx_info_exit_cacct(&vxi->cacct);
15719 +
15720 +       for_each_possible_cpu(cpu) {
15721 +               vx_info_exit_sched_pc(
15722 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
15723 +               vx_info_exit_cvirt_pc(
15724 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
15725 +       }
15726 +       leave_vx_info(&vxis);
15727 +#endif
15728 +
15729 +       vxi->vx_id = -1;
15730 +       vxi->vx_state |= VXS_RELEASED;
15731 +
15732 +#ifdef CONFIG_SMP
15733 +       free_percpu(vxi->ptr_pc);
15734 +#endif
15735 +       kfree(vxi);
15736 +       atomic_dec(&vx_global_ctotal);
15737 +}
15738 +
15739 +static void __shutdown_vx_info(struct vx_info *vxi)
15740 +{
15741 +       struct nsproxy *nsproxy;
15742 +       struct fs_struct *fs;
15743 +       struct cred *cred;
15744 +       int index, kill;
15745 +
15746 +       might_sleep();
15747 +
15748 +       vxi->vx_state |= VXS_SHUTDOWN;
15749 +       vs_state_change(vxi, VSC_SHUTDOWN);
15750 +
15751 +       for (index = 0; index < VX_SPACES; index++) {
15752 +               struct _vx_space *space = &vxi->space[index];
15753 +
15754 +               nsproxy = xchg(&space->vx_nsproxy, NULL);
15755 +               if (nsproxy)
15756 +                       put_nsproxy(nsproxy);
15757 +
15758 +               fs = xchg(&space->vx_fs, NULL);
15759 +               spin_lock(&fs->lock);
15760 +               kill = !--fs->users;
15761 +               spin_unlock(&fs->lock);
15762 +               if (kill)
15763 +                       free_fs_struct(fs);
15764 +
15765 +               cred = (struct cred *)xchg(&space->vx_cred, NULL);
15766 +               if (cred)
15767 +                       abort_creds(cred);
15768 +       }
15769 +}
15770 +
15771 +/* exported stuff */
15772 +
15773 +void free_vx_info(struct vx_info *vxi)
15774 +{
15775 +       unsigned long flags;
15776 +       unsigned index;
15777 +
15778 +       /* check for reference counts first */
15779 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
15780 +       BUG_ON(atomic_read(&vxi->vx_tasks));
15781 +
15782 +       /* context must not be hashed */
15783 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
15784 +
15785 +       /* context shutdown is mandatory */
15786 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
15787 +
15788 +       /* spaces check */
15789 +       for (index = 0; index < VX_SPACES; index++) {
15790 +               struct _vx_space *space = &vxi->space[index];
15791 +
15792 +               BUG_ON(space->vx_nsproxy);
15793 +               BUG_ON(space->vx_fs);
15794 +               // BUG_ON(space->vx_real_cred);
15795 +               // BUG_ON(space->vx_cred);
15796 +       }
15797 +
15798 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
15799 +       hlist_del(&vxi->vx_hlist);
15800 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
15801 +
15802 +       __dealloc_vx_info(vxi);
15803 +}
15804 +
15805 +
15806 +/*     hash table for vx_info hash */
15807 +
15808 +#define VX_HASH_SIZE   13
15809 +
15810 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
15811 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
15812 +
15813 +static DEFINE_SPINLOCK(vx_info_hash_lock);
15814 +
15815 +
15816 +static inline unsigned int __hashval(vxid_t xid)
15817 +{
15818 +       return (xid % VX_HASH_SIZE);
15819 +}
15820 +
15821 +
15822 +
15823 +/*     __hash_vx_info()
15824 +
15825 +       * add the vxi to the global hash table
15826 +       * requires the hash_lock to be held                     */
15827 +
15828 +static inline void __hash_vx_info(struct vx_info *vxi)
15829 +{
15830 +       struct hlist_head *head;
15831 +
15832 +       vxd_assert_lock(&vx_info_hash_lock);
15833 +       vxdprintk(VXD_CBIT(xid, 4),
15834 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
15835 +       vxh_hash_vx_info(vxi);
15836 +
15837 +       /* context must not be hashed */
15838 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
15839 +
15840 +       vxi->vx_state |= VXS_HASHED;
15841 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
15842 +       hlist_add_head(&vxi->vx_hlist, head);
15843 +       atomic_inc(&vx_global_cactive);
15844 +}
15845 +
15846 +/*     __unhash_vx_info()
15847 +
15848 +       * remove the vxi from the global hash table
15849 +       * requires the hash_lock to be held                     */
15850 +
15851 +static inline void __unhash_vx_info(struct vx_info *vxi)
15852 +{
15853 +       unsigned long flags;
15854 +
15855 +       vxd_assert_lock(&vx_info_hash_lock);
15856 +       vxdprintk(VXD_CBIT(xid, 4),
15857 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
15858 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
15859 +       vxh_unhash_vx_info(vxi);
15860 +
15861 +       /* context must be hashed */
15862 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
15863 +       /* but without tasks */
15864 +       BUG_ON(atomic_read(&vxi->vx_tasks));
15865 +
15866 +       vxi->vx_state &= ~VXS_HASHED;
15867 +       hlist_del_init(&vxi->vx_hlist);
15868 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
15869 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
15870 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
15871 +       atomic_dec(&vx_global_cactive);
15872 +}
15873 +
15874 +
15875 +/*     __lookup_vx_info()
15876 +
15877 +       * requires the hash_lock to be held
15878 +       * doesn't increment the vx_refcnt                       */
15879 +
15880 +static inline struct vx_info *__lookup_vx_info(vxid_t xid)
15881 +{
15882 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
15883 +       struct hlist_node *pos;
15884 +       struct vx_info *vxi;
15885 +
15886 +       vxd_assert_lock(&vx_info_hash_lock);
15887 +       hlist_for_each(pos, head) {
15888 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
15889 +
15890 +               if (vxi->vx_id == xid)
15891 +                       goto found;
15892 +       }
15893 +       vxi = NULL;
15894 +found:
15895 +       vxdprintk(VXD_CBIT(xid, 0),
15896 +               "__lookup_vx_info(#%u): %p[#%u]",
15897 +               xid, vxi, vxi ? vxi->vx_id : 0);
15898 +       vxh_lookup_vx_info(vxi, xid);
15899 +       return vxi;
15900 +}
15901 +
15902 +
15903 +/*     __create_vx_info()
15904 +
15905 +       * create the requested context
15906 +       * get(), claim() and hash it                            */
15907 +
15908 +static struct vx_info *__create_vx_info(int id)
15909 +{
15910 +       struct vx_info *new, *vxi = NULL;
15911 +
15912 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
15913 +
15914 +       if (!(new = __alloc_vx_info(id)))
15915 +               return ERR_PTR(-ENOMEM);
15916 +
15917 +       /* required to make dynamic xids unique */
15918 +       spin_lock(&vx_info_hash_lock);
15919 +
15920 +       /* static context requested */
15921 +       if ((vxi = __lookup_vx_info(id))) {
15922 +               vxdprintk(VXD_CBIT(xid, 0),
15923 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
15924 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
15925 +                       vxi = ERR_PTR(-EBUSY);
15926 +               else
15927 +                       vxi = ERR_PTR(-EEXIST);
15928 +               goto out_unlock;
15929 +       }
15930 +       /* new context */
15931 +       vxdprintk(VXD_CBIT(xid, 0),
15932 +               "create_vx_info(%d) = %p (new)", id, new);
15933 +       claim_vx_info(new, NULL);
15934 +       __hash_vx_info(get_vx_info(new));
15935 +       vxi = new, new = NULL;
15936 +
15937 +out_unlock:
15938 +       spin_unlock(&vx_info_hash_lock);
15939 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
15940 +       if (new)
15941 +               __dealloc_vx_info(new);
15942 +       return vxi;
15943 +}
15944 +
15945 +
15946 +/*     exported stuff                                          */
15947 +
15948 +
15949 +void unhash_vx_info(struct vx_info *vxi)
15950 +{
15951 +       spin_lock(&vx_info_hash_lock);
15952 +       __unhash_vx_info(vxi);
15953 +       spin_unlock(&vx_info_hash_lock);
15954 +       __shutdown_vx_info(vxi);
15955 +       __wakeup_vx_info(vxi);
15956 +}
15957 +
15958 +
15959 +/*     lookup_vx_info()
15960 +
15961 +       * search for a vx_info and get() it
15962 +       * negative id means current                             */
15963 +
15964 +struct vx_info *lookup_vx_info(int id)
15965 +{
15966 +       struct vx_info *vxi = NULL;
15967 +
15968 +       if (id < 0) {
15969 +               vxi = get_vx_info(current_vx_info());
15970 +       } else if (id > 1) {
15971 +               spin_lock(&vx_info_hash_lock);
15972 +               vxi = get_vx_info(__lookup_vx_info(id));
15973 +               spin_unlock(&vx_info_hash_lock);
15974 +       }
15975 +       return vxi;
15976 +}
15977 +
15978 +/*     xid_is_hashed()
15979 +
15980 +       * verify that xid is still hashed                       */
15981 +
15982 +int xid_is_hashed(vxid_t xid)
15983 +{
15984 +       int hashed;
15985 +
15986 +       spin_lock(&vx_info_hash_lock);
15987 +       hashed = (__lookup_vx_info(xid) != NULL);
15988 +       spin_unlock(&vx_info_hash_lock);
15989 +       return hashed;
15990 +}
15991 +
15992 +#ifdef CONFIG_PROC_FS
15993 +
15994 +/*     get_xid_list()
15995 +
15996 +       * get a subset of hashed xids for proc
15997 +       * assumes size is at least one                          */
15998 +
15999 +int get_xid_list(int index, unsigned int *xids, int size)
16000 +{
16001 +       int hindex, nr_xids = 0;
16002 +
16003 +       /* only show current and children */
16004 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
16005 +               if (index > 0)
16006 +                       return 0;
16007 +               xids[nr_xids] = vx_current_xid();
16008 +               return 1;
16009 +       }
16010 +
16011 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
16012 +               struct hlist_head *head = &vx_info_hash[hindex];
16013 +               struct hlist_node *pos;
16014 +
16015 +               spin_lock(&vx_info_hash_lock);
16016 +               hlist_for_each(pos, head) {
16017 +                       struct vx_info *vxi;
16018 +
16019 +                       if (--index > 0)
16020 +                               continue;
16021 +
16022 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16023 +                       xids[nr_xids] = vxi->vx_id;
16024 +                       if (++nr_xids >= size) {
16025 +                               spin_unlock(&vx_info_hash_lock);
16026 +                               goto out;
16027 +                       }
16028 +               }
16029 +               /* keep the lock time short */
16030 +               spin_unlock(&vx_info_hash_lock);
16031 +       }
16032 +out:
16033 +       return nr_xids;
16034 +}
16035 +#endif
16036 +
16037 +#ifdef CONFIG_VSERVER_DEBUG
16038 +
16039 +void   dump_vx_info_inactive(int level)
16040 +{
16041 +       struct hlist_node *entry, *next;
16042 +
16043 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
16044 +               struct vx_info *vxi =
16045 +                       list_entry(entry, struct vx_info, vx_hlist);
16046 +
16047 +               dump_vx_info(vxi, level);
16048 +       }
16049 +}
16050 +
16051 +#endif
16052 +
16053 +#if 0
16054 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
16055 +{
16056 +       struct user_struct *new_user, *old_user;
16057 +
16058 +       if (!p || !vxi)
16059 +               BUG();
16060 +
16061 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
16062 +               return -EACCES;
16063 +
16064 +       new_user = alloc_uid(vxi->vx_id, p->uid);
16065 +       if (!new_user)
16066 +               return -ENOMEM;
16067 +
16068 +       old_user = p->user;
16069 +       if (new_user != old_user) {
16070 +               atomic_inc(&new_user->processes);
16071 +               atomic_dec(&old_user->processes);
16072 +               p->user = new_user;
16073 +       }
16074 +       free_uid(old_user);
16075 +       return 0;
16076 +}
16077 +#endif
16078 +
16079 +#if 0
16080 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
16081 +{
16082 +       // p->cap_effective &= vxi->vx_cap_bset;
16083 +       p->cap_effective =
16084 +               cap_intersect(p->cap_effective, vxi->cap_bset);
16085 +       // p->cap_inheritable &= vxi->vx_cap_bset;
16086 +       p->cap_inheritable =
16087 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
16088 +       // p->cap_permitted &= vxi->vx_cap_bset;
16089 +       p->cap_permitted =
16090 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
16091 +}
16092 +#endif
16093 +
16094 +
16095 +#include <linux/file.h>
16096 +#include <linux/fdtable.h>
16097 +
16098 +static int vx_openfd_task(struct task_struct *tsk)
16099 +{
16100 +       struct files_struct *files = tsk->files;
16101 +       struct fdtable *fdt;
16102 +       const unsigned long *bptr;
16103 +       int count, total;
16104 +
16105 +       /* no rcu_read_lock() because of spin_lock() */
16106 +       spin_lock(&files->file_lock);
16107 +       fdt = files_fdtable(files);
16108 +       bptr = fdt->open_fds;
16109 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
16110 +       for (total = 0; count > 0; count--) {
16111 +               if (*bptr)
16112 +                       total += hweight_long(*bptr);
16113 +               bptr++;
16114 +       }
16115 +       spin_unlock(&files->file_lock);
16116 +       return total;
16117 +}
16118 +
16119 +
16120 +/*     for *space compatibility */
16121 +
16122 +asmlinkage long sys_unshare(unsigned long);
16123 +
16124 +/*
16125 + *     migrate task to new context
16126 + *     gets vxi, puts old_vxi on change
16127 + *     optionally unshares namespaces (hack)
16128 + */
16129 +
16130 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
16131 +{
16132 +       struct vx_info *old_vxi;
16133 +       int ret = 0;
16134 +
16135 +       if (!p || !vxi)
16136 +               BUG();
16137 +
16138 +       vxdprintk(VXD_CBIT(xid, 5),
16139 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
16140 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
16141 +
16142 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
16143 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16144 +               return -EACCES;
16145 +
16146 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
16147 +               return -EFAULT;
16148 +
16149 +       old_vxi = task_get_vx_info(p);
16150 +       if (old_vxi == vxi)
16151 +               goto out;
16152 +
16153 +//     if (!(ret = vx_migrate_user(p, vxi))) {
16154 +       {
16155 +               int openfd;
16156 +
16157 +               task_lock(p);
16158 +               openfd = vx_openfd_task(p);
16159 +
16160 +               if (old_vxi) {
16161 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
16162 +                       atomic_dec(&old_vxi->cvirt.nr_running);
16163 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
16164 +                       /* FIXME: what about the struct files here? */
16165 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
16166 +                       /* account for the executable */
16167 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
16168 +               }
16169 +               atomic_inc(&vxi->cvirt.nr_threads);
16170 +               atomic_inc(&vxi->cvirt.nr_running);
16171 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
16172 +               /* FIXME: what about the struct files here? */
16173 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
16174 +               /* account for the executable */
16175 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
16176 +
16177 +               if (old_vxi) {
16178 +                       release_vx_info(old_vxi, p);
16179 +                       clr_vx_info(&p->vx_info);
16180 +               }
16181 +               claim_vx_info(vxi, p);
16182 +               set_vx_info(&p->vx_info, vxi);
16183 +               p->xid = vxi->vx_id;
16184 +
16185 +               vxdprintk(VXD_CBIT(xid, 5),
16186 +                       "moved task %p into vxi:%p[#%d]",
16187 +                       p, vxi, vxi->vx_id);
16188 +
16189 +               // vx_mask_cap_bset(vxi, p);
16190 +               task_unlock(p);
16191 +
16192 +               /* hack for *spaces to provide compatibility */
16193 +               if (unshare) {
16194 +                       struct nsproxy *old_nsp, *new_nsp;
16195 +
16196 +                       ret = unshare_nsproxy_namespaces(
16197 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
16198 +                               &new_nsp, NULL, NULL);
16199 +                       if (ret)
16200 +                               goto out;
16201 +
16202 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
16203 +                       vx_set_space(vxi,
16204 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
16205 +                       put_nsproxy(old_nsp);
16206 +               }
16207 +       }
16208 +out:
16209 +       put_vx_info(old_vxi);
16210 +       return ret;
16211 +}
16212 +
16213 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
16214 +{
16215 +       struct task_struct *old_reaper;
16216 +       struct vx_info *reaper_vxi;
16217 +
16218 +       if (!vxi)
16219 +               return -EINVAL;
16220 +
16221 +       vxdprintk(VXD_CBIT(xid, 6),
16222 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
16223 +               vxi, vxi->vx_id, p, p->xid, p->pid);
16224 +
16225 +       old_reaper = vxi->vx_reaper;
16226 +       if (old_reaper == p)
16227 +               return 0;
16228 +
16229 +       reaper_vxi = task_get_vx_info(p);
16230 +       if (reaper_vxi && reaper_vxi != vxi) {
16231 +               vxwprintk(1,
16232 +                       "Unsuitable reaper [" VS_Q("%s") ",%u:#%u] "
16233 +                       "for [xid #%u]",
16234 +                       p->comm, p->pid, p->xid, vx_current_xid());
16235 +               goto out;
16236 +       }
16237 +
16238 +       /* set new child reaper */
16239 +       get_task_struct(p);
16240 +       vxi->vx_reaper = p;
16241 +       put_task_struct(old_reaper);
16242 +out:
16243 +       put_vx_info(reaper_vxi);
16244 +       return 0;
16245 +}
16246 +
16247 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
16248 +{
16249 +       if (!vxi)
16250 +               return -EINVAL;
16251 +
16252 +       vxdprintk(VXD_CBIT(xid, 6),
16253 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
16254 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16255 +
16256 +       vxi->vx_flags &= ~VXF_STATE_INIT;
16257 +       // vxi->vx_initpid = p->tgid;
16258 +       vxi->vx_initpid = p->pid;
16259 +       return 0;
16260 +}
16261 +
16262 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
16263 +{
16264 +       vxdprintk(VXD_CBIT(xid, 6),
16265 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
16266 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16267 +
16268 +       vxi->exit_code = code;
16269 +       vxi->vx_initpid = 0;
16270 +}
16271 +
16272 +
16273 +void vx_set_persistent(struct vx_info *vxi)
16274 +{
16275 +       vxdprintk(VXD_CBIT(xid, 6),
16276 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
16277 +
16278 +       get_vx_info(vxi);
16279 +       claim_vx_info(vxi, NULL);
16280 +}
16281 +
16282 +void vx_clear_persistent(struct vx_info *vxi)
16283 +{
16284 +       vxdprintk(VXD_CBIT(xid, 6),
16285 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
16286 +
16287 +       release_vx_info(vxi, NULL);
16288 +       put_vx_info(vxi);
16289 +}
16290 +
16291 +void vx_update_persistent(struct vx_info *vxi)
16292 +{
16293 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
16294 +               vx_set_persistent(vxi);
16295 +       else
16296 +               vx_clear_persistent(vxi);
16297 +}
16298 +
16299 +
16300 +/*     task must be current or locked          */
16301 +
16302 +void   exit_vx_info(struct task_struct *p, int code)
16303 +{
16304 +       struct vx_info *vxi = p->vx_info;
16305 +
16306 +       if (vxi) {
16307 +               atomic_dec(&vxi->cvirt.nr_threads);
16308 +               vx_nproc_dec(p);
16309 +
16310 +               vxi->exit_code = code;
16311 +               release_vx_info(vxi, p);
16312 +       }
16313 +}
16314 +
16315 +void   exit_vx_info_early(struct task_struct *p, int code)
16316 +{
16317 +       struct vx_info *vxi = p->vx_info;
16318 +
16319 +       if (vxi) {
16320 +               if (vxi->vx_initpid == p->pid)
16321 +                       vx_exit_init(vxi, p, code);
16322 +               if (vxi->vx_reaper == p)
16323 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
16324 +       }
16325 +}
16326 +
16327 +
16328 +/* vserver syscall commands below here */
16329 +
16330 +/* taks xid and vx_info functions */
16331 +
16332 +#include <asm/uaccess.h>
16333 +
16334 +
16335 +int vc_task_xid(uint32_t id)
16336 +{
16337 +       vxid_t xid;
16338 +
16339 +       if (id) {
16340 +               struct task_struct *tsk;
16341 +
16342 +               rcu_read_lock();
16343 +               tsk = find_task_by_real_pid(id);
16344 +               xid = (tsk) ? tsk->xid : -ESRCH;
16345 +               rcu_read_unlock();
16346 +       } else
16347 +               xid = vx_current_xid();
16348 +       return xid;
16349 +}
16350 +
16351 +
16352 +int vc_vx_info(struct vx_info *vxi, void __user *data)
16353 +{
16354 +       struct vcmd_vx_info_v0 vc_data;
16355 +
16356 +       vc_data.xid = vxi->vx_id;
16357 +       vc_data.initpid = vxi->vx_initpid;
16358 +
16359 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16360 +               return -EFAULT;
16361 +       return 0;
16362 +}
16363 +
16364 +
16365 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
16366 +{
16367 +       struct vcmd_ctx_stat_v0 vc_data;
16368 +
16369 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
16370 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
16371 +
16372 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16373 +               return -EFAULT;
16374 +       return 0;
16375 +}
16376 +
16377 +
16378 +/* context functions */
16379 +
16380 +int vc_ctx_create(uint32_t xid, void __user *data)
16381 +{
16382 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
16383 +       struct vx_info *new_vxi;
16384 +       int ret;
16385 +
16386 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16387 +               return -EFAULT;
16388 +
16389 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
16390 +               return -EINVAL;
16391 +
16392 +       new_vxi = __create_vx_info(xid);
16393 +       if (IS_ERR(new_vxi))
16394 +               return PTR_ERR(new_vxi);
16395 +
16396 +       /* initial flags */
16397 +       new_vxi->vx_flags = vc_data.flagword;
16398 +
16399 +       ret = -ENOEXEC;
16400 +       if (vs_state_change(new_vxi, VSC_STARTUP))
16401 +               goto out;
16402 +
16403 +       ret = vx_migrate_task(current, new_vxi, (!data));
16404 +       if (ret)
16405 +               goto out;
16406 +
16407 +       /* return context id on success */
16408 +       ret = new_vxi->vx_id;
16409 +
16410 +       /* get a reference for persistent contexts */
16411 +       if ((vc_data.flagword & VXF_PERSISTENT))
16412 +               vx_set_persistent(new_vxi);
16413 +out:
16414 +       release_vx_info(new_vxi, NULL);
16415 +       put_vx_info(new_vxi);
16416 +       return ret;
16417 +}
16418 +
16419 +
16420 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
16421 +{
16422 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
16423 +       int ret;
16424 +
16425 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16426 +               return -EFAULT;
16427 +
16428 +       ret = vx_migrate_task(current, vxi, 0);
16429 +       if (ret)
16430 +               return ret;
16431 +       if (vc_data.flagword & VXM_SET_INIT)
16432 +               ret = vx_set_init(vxi, current);
16433 +       if (ret)
16434 +               return ret;
16435 +       if (vc_data.flagword & VXM_SET_REAPER)
16436 +               ret = vx_set_reaper(vxi, current);
16437 +       return ret;
16438 +}
16439 +
16440 +
16441 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
16442 +{
16443 +       struct vcmd_ctx_flags_v0 vc_data;
16444 +
16445 +       vc_data.flagword = vxi->vx_flags;
16446 +
16447 +       /* special STATE flag handling */
16448 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
16449 +
16450 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16451 +               return -EFAULT;
16452 +       return 0;
16453 +}
16454 +
16455 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
16456 +{
16457 +       struct vcmd_ctx_flags_v0 vc_data;
16458 +       uint64_t mask, trigger;
16459 +
16460 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16461 +               return -EFAULT;
16462 +
16463 +       /* special STATE flag handling */
16464 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
16465 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
16466 +
16467 +       if (vxi == current_vx_info()) {
16468 +               /* if (trigger & VXF_STATE_SETUP)
16469 +                       vx_mask_cap_bset(vxi, current); */
16470 +               if (trigger & VXF_STATE_INIT) {
16471 +                       int ret;
16472 +
16473 +                       ret = vx_set_init(vxi, current);
16474 +                       if (ret)
16475 +                               return ret;
16476 +                       ret = vx_set_reaper(vxi, current);
16477 +                       if (ret)
16478 +                               return ret;
16479 +               }
16480 +       }
16481 +
16482 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
16483 +               vc_data.flagword, mask);
16484 +       if (trigger & VXF_PERSISTENT)
16485 +               vx_update_persistent(vxi);
16486 +
16487 +       return 0;
16488 +}
16489 +
16490 +
16491 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
16492 +{
16493 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
16494 +
16495 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
16496 +       return v;
16497 +}
16498 +
16499 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
16500 +{
16501 +       kernel_cap_t c = __cap_empty_set;
16502 +
16503 +       c.cap[0] = v & 0xFFFFFFFF;
16504 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
16505 +
16506 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
16507 +       return c;
16508 +}
16509 +
16510 +
16511 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
16512 +{
16513 +       if (bcaps)
16514 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
16515 +       if (ccaps)
16516 +               *ccaps = vxi->vx_ccaps;
16517 +
16518 +       return 0;
16519 +}
16520 +
16521 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
16522 +{
16523 +       struct vcmd_ctx_caps_v1 vc_data;
16524 +       int ret;
16525 +
16526 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
16527 +       if (ret)
16528 +               return ret;
16529 +       vc_data.cmask = ~0ULL;
16530 +
16531 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16532 +               return -EFAULT;
16533 +       return 0;
16534 +}
16535 +
16536 +static int do_set_caps(struct vx_info *vxi,
16537 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
16538 +{
16539 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
16540 +
16541 +#if 0
16542 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
16543 +               bcaps, bmask, ccaps, cmask);
16544 +#endif
16545 +       vxi->vx_bcaps = cap_t_from_caps(
16546 +               vs_mask_flags(bcold, bcaps, bmask));
16547 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
16548 +
16549 +       return 0;
16550 +}
16551 +
16552 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
16553 +{
16554 +       struct vcmd_ctx_caps_v1 vc_data;
16555 +
16556 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16557 +               return -EFAULT;
16558 +
16559 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
16560 +}
16561 +
16562 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
16563 +{
16564 +       struct vcmd_bcaps vc_data;
16565 +       int ret;
16566 +
16567 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
16568 +       if (ret)
16569 +               return ret;
16570 +       vc_data.bmask = ~0ULL;
16571 +
16572 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16573 +               return -EFAULT;
16574 +       return 0;
16575 +}
16576 +
16577 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
16578 +{
16579 +       struct vcmd_bcaps vc_data;
16580 +
16581 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16582 +               return -EFAULT;
16583 +
16584 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
16585 +}
16586 +
16587 +
16588 +int vc_get_umask(struct vx_info *vxi, void __user *data)
16589 +{
16590 +       struct vcmd_umask vc_data;
16591 +
16592 +       vc_data.umask = vxi->vx_umask;
16593 +       vc_data.mask = ~0ULL;
16594 +
16595 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16596 +               return -EFAULT;
16597 +       return 0;
16598 +}
16599 +
16600 +int vc_set_umask(struct vx_info *vxi, void __user *data)
16601 +{
16602 +       struct vcmd_umask vc_data;
16603 +
16604 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16605 +               return -EFAULT;
16606 +
16607 +       vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
16608 +               vc_data.umask, vc_data.mask);
16609 +       return 0;
16610 +}
16611 +
16612 +
16613 +int vc_get_wmask(struct vx_info *vxi, void __user *data)
16614 +{
16615 +       struct vcmd_wmask vc_data;
16616 +
16617 +       vc_data.wmask = vxi->vx_wmask;
16618 +       vc_data.mask = ~0ULL;
16619 +
16620 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16621 +               return -EFAULT;
16622 +       return 0;
16623 +}
16624 +
16625 +int vc_set_wmask(struct vx_info *vxi, void __user *data)
16626 +{
16627 +       struct vcmd_wmask vc_data;
16628 +
16629 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16630 +               return -EFAULT;
16631 +
16632 +       vxi->vx_wmask = vs_mask_flags(vxi->vx_wmask,
16633 +               vc_data.wmask, vc_data.mask);
16634 +       return 0;
16635 +}
16636 +
16637 +
16638 +int vc_get_badness(struct vx_info *vxi, void __user *data)
16639 +{
16640 +       struct vcmd_badness_v0 vc_data;
16641 +
16642 +       vc_data.bias = vxi->vx_badness_bias;
16643 +
16644 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16645 +               return -EFAULT;
16646 +       return 0;
16647 +}
16648 +
16649 +int vc_set_badness(struct vx_info *vxi, void __user *data)
16650 +{
16651 +       struct vcmd_badness_v0 vc_data;
16652 +
16653 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16654 +               return -EFAULT;
16655 +
16656 +       vxi->vx_badness_bias = vc_data.bias;
16657 +       return 0;
16658 +}
16659 +
16660 +#include <linux/module.h>
16661 +
16662 +EXPORT_SYMBOL_GPL(free_vx_info);
16663 +
16664 diff -NurpP --minimal linux-3.9.5/kernel/vserver/cvirt.c linux-3.9.5-vs2.3.6.5/kernel/vserver/cvirt.c
16665 --- linux-3.9.5/kernel/vserver/cvirt.c  1970-01-01 00:00:00.000000000 +0000
16666 +++ linux-3.9.5-vs2.3.6.5/kernel/vserver/cvirt.c        2013-05-31 14:47:11.000000000 +0000
16667 @@ -0,0 +1,313 @@
16668 +/*
16669 + *  linux/kernel/vserver/cvirt.c
16670 + *
16671 + *  Virtual Server: Context Virtualization
16672 + *
16673 + *  Copyright (C) 2004-2007  Herbert Pötzl
16674 + *
16675 + *  V0.01  broken out from limit.c
16676 + *  V0.02  added utsname stuff
16677 + *  V0.03  changed vcmds to vxi arg
16678 + *
16679 + */
16680 +
16681 +#include <linux/types.h>
16682 +#include <linux/utsname.h>
16683 +#include <linux/vs_cvirt.h>
16684 +#include <linux/vserver/switch.h>
16685 +#include <linux/vserver/cvirt_cmd.h>
16686 +
16687 +#include <asm/uaccess.h>
16688 +
16689 +
16690 +void vx_vsi_boottime(struct timespec *boottime)
16691 +{
16692 +       struct vx_info *vxi = current_vx_info();
16693 +
16694 +       set_normalized_timespec(boottime,
16695 +               boottime->tv_sec + vxi->cvirt.bias_uptime.tv_sec,
16696 +               boottime->tv_nsec + vxi->cvirt.bias_uptime.tv_nsec);
16697 +       return;
16698 +}
16699 +
16700 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
16701 +{
16702 +       struct vx_info *vxi = current_vx_info();
16703 +
16704 +       set_normalized_timespec(uptime,
16705 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
16706 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
16707 +       if (!idle)
16708 +               return;
16709 +       set_normalized_timespec(idle,
16710 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
16711 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
16712 +       return;
16713 +}
16714 +
16715 +uint64_t vx_idle_jiffies(void)
16716 +{
16717 +       return init_task.utime + init_task.stime;
16718 +}
16719 +
16720 +
16721 +
16722 +static inline uint32_t __update_loadavg(uint32_t load,
16723 +       int wsize, int delta, int n)
16724 +{
16725 +       unsigned long long calc, prev;
16726 +
16727 +       /* just set it to n */
16728 +       if (unlikely(delta >= wsize))
16729 +               return (n << FSHIFT);
16730 +
16731 +       calc = delta * n;
16732 +       calc <<= FSHIFT;
16733 +       prev = (wsize - delta);
16734 +       prev *= load;
16735 +       calc += prev;
16736 +       do_div(calc, wsize);
16737 +       return calc;
16738 +}
16739 +
16740 +
16741 +void vx_update_load(struct vx_info *vxi)
16742 +{
16743 +       uint32_t now, last, delta;
16744 +       unsigned int nr_running, nr_uninterruptible;
16745 +       unsigned int total;
16746 +       unsigned long flags;
16747 +
16748 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
16749 +
16750 +       now = jiffies;
16751 +       last = vxi->cvirt.load_last;
16752 +       delta = now - last;
16753 +
16754 +       if (delta < 5*HZ)
16755 +               goto out;
16756 +
16757 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
16758 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
16759 +       total = nr_running + nr_uninterruptible;
16760 +
16761 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
16762 +               60*HZ, delta, total);
16763 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
16764 +               5*60*HZ, delta, total);
16765 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
16766 +               15*60*HZ, delta, total);
16767 +
16768 +       vxi->cvirt.load_last = now;
16769 +out:
16770 +       atomic_inc(&vxi->cvirt.load_updates);
16771 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
16772 +}
16773 +
16774 +
16775 +/*
16776 + * Commands to do_syslog:
16777 + *
16778 + *      0 -- Close the log.  Currently a NOP.
16779 + *      1 -- Open the log. Currently a NOP.
16780 + *      2 -- Read from the log.
16781 + *      3 -- Read all messages remaining in the ring buffer.
16782 + *      4 -- Read and clear all messages remaining in the ring buffer
16783 + *      5 -- Clear ring buffer.
16784 + *      6 -- Disable printk's to console
16785 + *      7 -- Enable printk's to console
16786 + *      8 -- Set level of messages printed to console
16787 + *      9 -- Return number of unread characters in the log buffer
16788 + *     10 -- Return size of the log buffer
16789 + */
16790 +int vx_do_syslog(int type, char __user *buf, int len)
16791 +{
16792 +       int error = 0;
16793 +       int do_clear = 0;
16794 +       struct vx_info *vxi = current_vx_info();
16795 +       struct _vx_syslog *log;
16796 +
16797 +       if (!vxi)
16798 +               return -EINVAL;
16799 +       log = &vxi->cvirt.syslog;
16800 +
16801 +       switch (type) {
16802 +       case 0:         /* Close log */
16803 +       case 1:         /* Open log */
16804 +               break;
16805 +       case 2:         /* Read from log */
16806 +               error = wait_event_interruptible(log->log_wait,
16807 +                       (log->log_start - log->log_end));
16808 +               if (error)
16809 +                       break;
16810 +               spin_lock_irq(&log->logbuf_lock);
16811 +               spin_unlock_irq(&log->logbuf_lock);
16812 +               break;
16813 +       case 4:         /* Read/clear last kernel messages */
16814 +               do_clear = 1;
16815 +               /* fall through */
16816 +       case 3:         /* Read last kernel messages */
16817 +               return 0;
16818 +
16819 +       case 5:         /* Clear ring buffer */
16820 +               return 0;
16821 +
16822 +       case 6:         /* Disable logging to console */
16823 +       case 7:         /* Enable logging to console */
16824 +       case 8:         /* Set level of messages printed to console */
16825 +               break;
16826 +
16827 +       case 9:         /* Number of chars in the log buffer */
16828 +               return 0;
16829 +       case 10:        /* Size of the log buffer */
16830 +               return 0;
16831 +       default:
16832 +               error = -EINVAL;
16833 +               break;
16834 +       }
16835 +       return error;
16836 +}
16837 +
16838 +
16839 +/* virtual host info names */
16840 +
16841 +static char *vx_vhi_name(struct vx_info *vxi, int id)
16842 +{
16843 +       struct nsproxy *nsproxy;
16844 +       struct uts_namespace *uts;
16845 +
16846 +       if (id == VHIN_CONTEXT)
16847 +               return vxi->vx_name;
16848 +
16849 +       nsproxy = vxi->space[0].vx_nsproxy;
16850 +       if (!nsproxy)
16851 +               return NULL;
16852 +
16853 +       uts = nsproxy->uts_ns;
16854 +       if (!uts)
16855 +               return NULL;
16856 +
16857 +       switch (id) {
16858 +       case VHIN_SYSNAME:
16859 +               return uts->name.sysname;
16860 +       case VHIN_NODENAME:
16861 +               return uts->name.nodename;
16862 +       case VHIN_RELEASE:
16863 +               return uts->name.release;
16864 +       case VHIN_VERSION:
16865 +               return uts->name.version;
16866 +       case VHIN_MACHINE:
16867 +               return uts->name.machine;
16868 +       case VHIN_DOMAINNAME:
16869 +               return uts->name.domainname;
16870 +       default:
16871 +               return NULL;
16872 +       }
16873 +       return NULL;
16874 +}
16875 +
16876 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
16877 +{
16878 +       struct vcmd_vhi_name_v0 vc_data;
16879 +       char *name;
16880 +
16881 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16882 +               return -EFAULT;
16883 +
16884 +       name = vx_vhi_name(vxi, vc_data.field);
16885 +       if (!name)
16886 +               return -EINVAL;
16887 +
16888 +       memcpy(name, vc_data.name, 65);
16889 +       return 0;
16890 +}
16891 +
16892 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
16893 +{
16894 +       struct vcmd_vhi_name_v0 vc_data;
16895 +       char *name;
16896 +
16897 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16898 +               return -EFAULT;
16899 +
16900 +       name = vx_vhi_name(vxi, vc_data.field);
16901 +       if (!name)
16902 +               return -EINVAL;
16903 +
16904 +       memcpy(vc_data.name, name, 65);
16905 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16906 +               return -EFAULT;
16907 +       return 0;
16908 +}
16909 +
16910 +
16911 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
16912 +{
16913 +       struct vcmd_virt_stat_v0 vc_data;
16914 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
16915 +       struct timespec uptime;
16916 +
16917 +       do_posix_clock_monotonic_gettime(&uptime);
16918 +       set_normalized_timespec(&uptime,
16919 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
16920 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
16921 +
16922 +       vc_data.offset = timespec_to_ns(&cvirt->bias_ts);
16923 +       vc_data.uptime = timespec_to_ns(&uptime);
16924 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
16925 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
16926 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
16927 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
16928 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
16929 +       vc_data.load[0] = cvirt->load[0];
16930 +       vc_data.load[1] = cvirt->load[1];
16931 +       vc_data.load[2] = cvirt->load[2];
16932 +
16933 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16934 +               return -EFAULT;
16935 +       return 0;
16936 +}
16937 +
16938 +
16939 +#ifdef CONFIG_VSERVER_VTIME
16940 +
16941 +/* virtualized time base */
16942 +
16943 +void vx_adjust_timespec(struct timespec *ts)
16944 +{
16945 +       struct vx_info *vxi;
16946 +
16947 +       if (!vx_flags(VXF_VIRT_TIME, 0))
16948 +               return;
16949 +
16950 +       vxi = current_vx_info();
16951 +       ts->tv_sec += vxi->cvirt.bias_ts.tv_sec;
16952 +       ts->tv_nsec += vxi->cvirt.bias_ts.tv_nsec;
16953 +
16954 +       if (ts->tv_nsec >= NSEC_PER_SEC) {
16955 +               ts->tv_sec++;
16956 +               ts->tv_nsec -= NSEC_PER_SEC;
16957 +       } else if (ts->tv_nsec < 0) {
16958 +               ts->tv_sec--;
16959 +               ts->tv_nsec += NSEC_PER_SEC;
16960 +       }
16961 +}
16962 +
16963 +int vx_settimeofday(const struct timespec *ts)
16964 +{
16965 +       struct timespec ats, delta;
16966 +       struct vx_info *vxi;
16967 +
16968 +       if (!vx_flags(VXF_VIRT_TIME, 0))
16969 +               return do_settimeofday(ts);
16970 +
16971 +       getnstimeofday(&ats);
16972 +       delta = timespec_sub(*ts, ats);
16973 +
16974 +       vxi = current_vx_info();
16975 +       vxi->cvirt.bias_ts = timespec_add(vxi->cvirt.bias_ts, delta);
16976 +       return 0;
16977 +}
16978 +
16979 +#endif
16980 +
16981 diff -NurpP --minimal linux-3.9.5/kernel/vserver/cvirt_init.h linux-3.9.5-vs2.3.6.5/kernel/vserver/cvirt_init.h
16982 --- linux-3.9.5/kernel/vserver/cvirt_init.h     1970-01-01 00:00:00.000000000 +0000
16983 +++ linux-3.9.5-vs2.3.6.5/kernel/vserver/cvirt_init.h   2013-05-31 14:47:11.000000000 +0000
16984 @@ -0,0 +1,70 @@
16985 +
16986 +
16987 +extern uint64_t vx_idle_jiffies(void);
16988 +
16989 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
16990 +{
16991 +       uint64_t idle_jiffies = vx_idle_jiffies();
16992 +       uint64_t nsuptime;
16993 +
16994 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
16995 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
16996 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
16997 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
16998 +       cvirt->bias_ts.tv_sec = 0;
16999 +       cvirt->bias_ts.tv_nsec = 0;
17000 +
17001 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
17002 +       atomic_set(&cvirt->nr_threads, 0);
17003 +       atomic_set(&cvirt->nr_running, 0);
17004 +       atomic_set(&cvirt->nr_uninterruptible, 0);
17005 +       atomic_set(&cvirt->nr_onhold, 0);
17006 +
17007 +       spin_lock_init(&cvirt->load_lock);
17008 +       cvirt->load_last = jiffies;
17009 +       atomic_set(&cvirt->load_updates, 0);
17010 +       cvirt->load[0] = 0;
17011 +       cvirt->load[1] = 0;
17012 +       cvirt->load[2] = 0;
17013 +       atomic_set(&cvirt->total_forks, 0);
17014 +
17015 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
17016 +       init_waitqueue_head(&cvirt->syslog.log_wait);
17017 +       cvirt->syslog.log_start = 0;
17018 +       cvirt->syslog.log_end = 0;
17019 +       cvirt->syslog.con_start = 0;
17020 +       cvirt->syslog.logged_chars = 0;
17021 +}
17022 +
17023 +static inline
17024 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17025 +{
17026 +       // cvirt_pc->cpustat = { 0 };
17027 +}
17028 +
17029 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
17030 +{
17031 +#ifdef CONFIG_VSERVER_WARN
17032 +       int value;
17033 +#endif
17034 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
17035 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
17036 +               cvirt, value);
17037 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
17038 +               "!!! cvirt: %p[nr_running] = %d on exit.",
17039 +               cvirt, value);
17040 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
17041 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
17042 +               cvirt, value);
17043 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
17044 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
17045 +               cvirt, value);
17046 +       return;
17047 +}
17048 +
17049 +static inline
17050 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17051 +{
17052 +       return;
17053 +}
17054 +
17055 diff -NurpP --minimal linux-3.9.5/kernel/vserver/cvirt_proc.h linux-3.9.5-vs2.3.6.5/kernel/vserver/cvirt_proc.h
17056 --- linux-3.9.5/kernel/vserver/cvirt_proc.h     1970-01-01 00:00:00.000000000 +0000
17057 +++ linux-3.9.5-vs2.3.6.5/kernel/vserver/cvirt_proc.h   2013-05-31 19:38:26.000000000 +0000
17058 @@ -0,0 +1,123 @@
17059 +#ifndef _VX_CVIRT_PROC_H
17060 +#define _VX_CVIRT_PROC_H
17061 +
17062 +#include <linux/nsproxy.h>
17063 +#include <linux/mnt_namespace.h>
17064 +#include <linux/ipc_namespace.h>
17065 +#include <linux/utsname.h>
17066 +#include <linux/ipc.h>
17067 +
17068 +extern int vx_info_mnt_namespace(struct mnt_namespace *, char *);
17069 +
17070 +static inline
17071 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
17072 +{
17073 +       struct mnt_namespace *ns;
17074 +       struct uts_namespace *uts;
17075 +       struct ipc_namespace *ipc;
17076 +       int length = 0;
17077 +
17078 +       if (!nsproxy)
17079 +               goto out;
17080 +
17081 +       length += sprintf(buffer + length,
17082 +               "NSProxy:\t%p [%p,%p,%p]\n",
17083 +               nsproxy, nsproxy->mnt_ns,
17084 +               nsproxy->uts_ns, nsproxy->ipc_ns);
17085 +
17086 +       ns = nsproxy->mnt_ns;
17087 +       if (!ns)
17088 +               goto skip_ns;
17089 +
17090 +       length += vx_info_mnt_namespace(ns, buffer + length);
17091 +
17092 +skip_ns:
17093 +
17094 +       uts = nsproxy->uts_ns;
17095 +       if (!uts)
17096 +               goto skip_uts;
17097 +
17098 +       length += sprintf(buffer + length,
17099 +               "SysName:\t%.*s\n"
17100 +               "NodeName:\t%.*s\n"
17101 +               "Release:\t%.*s\n"
17102 +               "Version:\t%.*s\n"
17103 +               "Machine:\t%.*s\n"
17104 +               "DomainName:\t%.*s\n",
17105 +               __NEW_UTS_LEN, uts->name.sysname,
17106 +               __NEW_UTS_LEN, uts->name.nodename,
17107 +               __NEW_UTS_LEN, uts->name.release,
17108 +               __NEW_UTS_LEN, uts->name.version,
17109 +               __NEW_UTS_LEN, uts->name.machine,
17110 +               __NEW_UTS_LEN, uts->name.domainname);
17111 +skip_uts:
17112 +
17113 +       ipc = nsproxy->ipc_ns;
17114 +       if (!ipc)
17115 +               goto skip_ipc;
17116 +
17117 +       length += sprintf(buffer + length,
17118 +               "SEMS:\t\t%d %d %d %d  %d\n"
17119 +               "MSG:\t\t%d %d %d\n"
17120 +               "SHM:\t\t%lu %lu  %d %ld\n",
17121 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
17122 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
17123 +               ipc->used_sems,
17124 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
17125 +               (unsigned long)ipc->shm_ctlmax,
17126 +               (unsigned long)ipc->shm_ctlall,
17127 +               ipc->shm_ctlmni, ipc->shm_tot);
17128 +skip_ipc:
17129 +out:
17130 +       return length;
17131 +}
17132 +
17133 +
17134 +#include <linux/sched.h>
17135 +
17136 +#define LOAD_INT(x) ((x) >> FSHIFT)
17137 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
17138 +
17139 +static inline
17140 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
17141 +{
17142 +       int length = 0;
17143 +       int a, b, c;
17144 +
17145 +       length += sprintf(buffer + length,
17146 +               "BiasUptime:\t%lu.%02lu\n",
17147 +               (unsigned long)cvirt->bias_uptime.tv_sec,
17148 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
17149 +
17150 +       a = cvirt->load[0] + (FIXED_1 / 200);
17151 +       b = cvirt->load[1] + (FIXED_1 / 200);
17152 +       c = cvirt->load[2] + (FIXED_1 / 200);
17153 +       length += sprintf(buffer + length,
17154 +               "nr_threads:\t%d\n"
17155 +               "nr_running:\t%d\n"
17156 +               "nr_unintr:\t%d\n"
17157 +               "nr_onhold:\t%d\n"
17158 +               "load_updates:\t%d\n"
17159 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
17160 +               "total_forks:\t%d\n",
17161 +               atomic_read(&cvirt->nr_threads),
17162 +               atomic_read(&cvirt->nr_running),
17163 +               atomic_read(&cvirt->nr_uninterruptible),
17164 +               atomic_read(&cvirt->nr_onhold),
17165 +               atomic_read(&cvirt->load_updates),
17166 +               LOAD_INT(a), LOAD_FRAC(a),
17167 +               LOAD_INT(b), LOAD_FRAC(b),
17168 +               LOAD_INT(c), LOAD_FRAC(c),
17169 +               atomic_read(&cvirt->total_forks));
17170 +       return length;
17171 +}
17172 +
17173 +static inline
17174 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
17175 +       char *buffer, int cpu)
17176 +{
17177 +       int length = 0;
17178 +       return length;
17179 +}
17180 +
17181 +#endif /* _VX_CVIRT_PROC_H */
17182 diff -NurpP --minimal linux-3.9.5/kernel/vserver/debug.c linux-3.9.5-vs2.3.6.5/kernel/vserver/debug.c
17183 --- linux-3.9.5/kernel/vserver/debug.c  1970-01-01 00:00:00.000000000 +0000
17184 +++ linux-3.9.5-vs2.3.6.5/kernel/vserver/debug.c        2013-05-31 14:47:11.000000000 +0000
17185 @@ -0,0 +1,32 @@
17186 +/*
17187 + *  kernel/vserver/debug.c
17188 + *
17189 + *  Copyright (C) 2005-2007 Herbert Pötzl
17190 + *
17191 + *  V0.01  vx_info dump support
17192 + *
17193 + */
17194 +
17195 +#include <linux/module.h>
17196 +
17197 +#include <linux/vserver/context.h>
17198 +
17199 +
17200 +void   dump_vx_info(struct vx_info *vxi, int level)
17201 +{
17202 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
17203 +               atomic_read(&vxi->vx_usecnt),
17204 +               atomic_read(&vxi->vx_tasks),
17205 +               vxi->vx_state);
17206 +       if (level > 0) {
17207 +               __dump_vx_limit(&vxi->limit);
17208 +               __dump_vx_sched(&vxi->sched);
17209 +               __dump_vx_cvirt(&vxi->cvirt);
17210 +               __dump_vx_cacct(&vxi->cacct);
17211 +       }
17212 +       printk("---\n");
17213 +}
17214 +
17215 +
17216 +EXPORT_SYMBOL_GPL(dump_vx_info);
17217 +
17218 diff -NurpP --minimal linux-3.9.5/kernel/vserver/device.c linux-3.9.5-vs2.3.6.5/kernel/vserver/device.c
17219 --- linux-3.9.5/kernel/vserver/device.c 1970-01-01 00:00:00.000000000 +0000
17220 +++ linux-3.9.5-vs2.3.6.5/kernel/vserver/device.c       2013-06-12 23:49:09.000000000 +0000
17221 @@ -0,0 +1,443 @@
17222 +/*
17223 + *  linux/kernel/vserver/device.c
17224 + *
17225 + *  Linux-VServer: Device Support
17226 + *
17227 + *  Copyright (C) 2006  Herbert Pötzl
17228 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
17229 + *
17230 + *  V0.01  device mapping basics
17231 + *  V0.02  added defaults
17232 + *
17233 + */
17234 +
17235 +#include <linux/slab.h>
17236 +#include <linux/rcupdate.h>
17237 +#include <linux/fs.h>
17238 +#include <linux/namei.h>
17239 +#include <linux/hash.h>
17240 +
17241 +#include <asm/errno.h>
17242 +#include <asm/uaccess.h>
17243 +#include <linux/vserver/base.h>
17244 +#include <linux/vserver/debug.h>
17245 +#include <linux/vserver/context.h>
17246 +#include <linux/vserver/device.h>
17247 +#include <linux/vserver/device_cmd.h>
17248 +
17249 +
17250 +#define DMAP_HASH_BITS 4
17251 +
17252 +
17253 +struct vs_mapping {
17254 +       union {
17255 +               struct hlist_node hlist;
17256 +               struct list_head list;
17257 +       } u;
17258 +#define dm_hlist       u.hlist
17259 +#define dm_list                u.list
17260 +       vxid_t xid;
17261 +       dev_t device;
17262 +       struct vx_dmap_target target;
17263 +};
17264 +
17265 +
17266 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
17267 +
17268 +static DEFINE_SPINLOCK(dmap_main_hash_lock);
17269 +
17270 +static struct vx_dmap_target dmap_defaults[2] = {
17271 +       { .flags = DATTR_OPEN },
17272 +       { .flags = DATTR_OPEN },
17273 +};
17274 +
17275 +
17276 +struct kmem_cache *dmap_cachep __read_mostly;
17277 +
17278 +int __init dmap_cache_init(void)
17279 +{
17280 +       dmap_cachep = kmem_cache_create("dmap_cache",
17281 +               sizeof(struct vs_mapping), 0,
17282 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
17283 +       return 0;
17284 +}
17285 +
17286 +__initcall(dmap_cache_init);
17287 +
17288 +
17289 +static inline unsigned int __hashval(dev_t dev, int bits)
17290 +{
17291 +       return hash_long((unsigned long)dev, bits);
17292 +}
17293 +
17294 +
17295 +/*     __hash_mapping()
17296 + *     add the mapping to the hash table
17297 + */
17298 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
17299 +{
17300 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17301 +       struct hlist_head *head, *hash = dmap_main_hash;
17302 +       int device = vdm->device;
17303 +
17304 +       spin_lock(hash_lock);
17305 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
17306 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
17307 +
17308 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
17309 +       hlist_add_head(&vdm->dm_hlist, head);
17310 +       spin_unlock(hash_lock);
17311 +}
17312 +
17313 +
17314 +static inline int __mode_to_default(umode_t mode)
17315 +{
17316 +       switch (mode) {
17317 +       case S_IFBLK:
17318 +               return 0;
17319 +       case S_IFCHR:
17320 +               return 1;
17321 +       default:
17322 +               BUG();
17323 +       }
17324 +}
17325 +
17326 +
17327 +/*     __set_default()
17328 + *     set a default
17329 + */
17330 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
17331 +       struct vx_dmap_target *vdmt)
17332 +{
17333 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17334 +       spin_lock(hash_lock);
17335 +
17336 +       if (vxi)
17337 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
17338 +       else
17339 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
17340 +
17341 +
17342 +       spin_unlock(hash_lock);
17343 +
17344 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
17345 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
17346 +}
17347 +
17348 +
17349 +/*     __remove_default()
17350 + *     remove a default
17351 + */
17352 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
17353 +{
17354 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17355 +       spin_lock(hash_lock);
17356 +
17357 +       if (vxi)
17358 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
17359 +       else    /* remove == reset */
17360 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
17361 +
17362 +       spin_unlock(hash_lock);
17363 +       return 0;
17364 +}
17365 +
17366 +
17367 +/*     __find_mapping()
17368 + *     find a mapping in the hash table
17369 + *
17370 + *     caller must hold hash_lock
17371 + */
17372 +static inline int __find_mapping(vxid_t xid, dev_t device, umode_t mode,
17373 +       struct vs_mapping **local, struct vs_mapping **global)
17374 +{
17375 +       struct hlist_head *hash = dmap_main_hash;
17376 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
17377 +       struct hlist_node *pos;
17378 +       struct vs_mapping *vdm;
17379 +
17380 +       *local = NULL;
17381 +       if (global)
17382 +               *global = NULL;
17383 +
17384 +       hlist_for_each(pos, head) {
17385 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
17386 +
17387 +               if ((vdm->device == device) &&
17388 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
17389 +                       if (vdm->xid == xid) {
17390 +                               *local = vdm;
17391 +                               return 1;
17392 +                       } else if (global && vdm->xid == 0)
17393 +                               *global = vdm;
17394 +               }
17395 +       }
17396 +
17397 +       if (global && *global)
17398 +               return 0;
17399 +       else
17400 +               return -ENOENT;
17401 +}
17402 +
17403 +
17404 +/*     __lookup_mapping()
17405 + *     find a mapping and store the result in target and flags
17406 + */
17407 +static inline int __lookup_mapping(struct vx_info *vxi,
17408 +       dev_t device, dev_t *target, int *flags, umode_t mode)
17409 +{
17410 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17411 +       struct vs_mapping *vdm, *global;
17412 +       struct vx_dmap_target *vdmt;
17413 +       int ret = 0;
17414 +       vxid_t xid = vxi->vx_id;
17415 +       int index;
17416 +
17417 +       spin_lock(hash_lock);
17418 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
17419 +               ret = 1;
17420 +               vdmt = &vdm->target;
17421 +               goto found;
17422 +       }
17423 +
17424 +       index = __mode_to_default(mode);
17425 +       if (vxi && vxi->dmap.targets[index].flags) {
17426 +               ret = 2;
17427 +               vdmt = &vxi->dmap.targets[index];
17428 +       } else if (global) {
17429 +               ret = 3;
17430 +               vdmt = &global->target;
17431 +               goto found;
17432 +       } else {
17433 +               ret = 4;
17434 +               vdmt = &dmap_defaults[index];
17435 +       }
17436 +
17437 +found:
17438 +       if (target && (vdmt->flags & DATTR_REMAP))
17439 +               *target = vdmt->target;
17440 +       else if (target)
17441 +               *target = device;
17442 +       if (flags)
17443 +               *flags = vdmt->flags;
17444 +
17445 +       spin_unlock(hash_lock);
17446 +
17447 +       return ret;
17448 +}
17449 +
17450 +
17451 +/*     __remove_mapping()
17452 + *     remove a mapping from the hash table
17453 + */
17454 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
17455 +       umode_t mode)
17456 +{
17457 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17458 +       struct vs_mapping *vdm = NULL;
17459 +       int ret = 0;
17460 +
17461 +       spin_lock(hash_lock);
17462 +
17463 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
17464 +               NULL);
17465 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
17466 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
17467 +       if (ret < 0)
17468 +               goto out;
17469 +       hlist_del(&vdm->dm_hlist);
17470 +
17471 +out:
17472 +       spin_unlock(hash_lock);
17473 +       if (vdm)
17474 +               kmem_cache_free(dmap_cachep, vdm);
17475 +       return ret;
17476 +}
17477 +
17478 +
17479 +
17480 +int vs_map_device(struct vx_info *vxi,
17481 +       dev_t device, dev_t *target, umode_t mode)
17482 +{
17483 +       int ret, flags = DATTR_MASK;
17484 +
17485 +       if (!vxi) {
17486 +               if (target)
17487 +                       *target = device;
17488 +               goto out;
17489 +       }
17490 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
17491 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
17492 +               device, target ? *target : 0, flags, mode, ret);
17493 +out:
17494 +       return (flags & DATTR_MASK);
17495 +}
17496 +
17497 +
17498 +
17499 +static int do_set_mapping(struct vx_info *vxi,
17500 +       dev_t device, dev_t target, int flags, umode_t mode)
17501 +{
17502 +       if (device) {
17503 +               struct vs_mapping *new;
17504 +
17505 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
17506 +               if (!new)
17507 +                       return -ENOMEM;
17508 +
17509 +               INIT_HLIST_NODE(&new->dm_hlist);
17510 +               new->device = device;
17511 +               new->target.target = target;
17512 +               new->target.flags = flags | mode;
17513 +               new->xid = (vxi ? vxi->vx_id : 0);
17514 +
17515 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
17516 +               __hash_mapping(vxi, new);
17517 +       } else {
17518 +               struct vx_dmap_target new = {
17519 +                       .target = target,
17520 +                       .flags = flags | mode,
17521 +               };
17522 +               __set_default(vxi, mode, &new);
17523 +       }
17524 +       return 0;
17525 +}
17526 +
17527 +
17528 +static int do_unset_mapping(struct vx_info *vxi,
17529 +       dev_t device, dev_t target, int flags, umode_t mode)
17530 +{
17531 +       int ret = -EINVAL;
17532 +
17533 +       if (device) {
17534 +               ret = __remove_mapping(vxi, device, mode);
17535 +               if (ret < 0)
17536 +                       goto out;
17537 +       } else {
17538 +               ret = __remove_default(vxi, mode);
17539 +               if (ret < 0)
17540 +                       goto out;
17541 +       }
17542 +
17543 +out:
17544 +       return ret;
17545 +}
17546 +
17547 +
17548 +static inline int __user_device(const char __user *name, dev_t *dev,
17549 +       umode_t *mode)
17550 +{
17551 +       struct nameidata nd;
17552 +       int ret;
17553 +
17554 +       if (!name) {
17555 +               *dev = 0;
17556 +               return 0;
17557 +       }
17558 +       ret = user_lpath(name, &nd.path);
17559 +       if (ret)
17560 +               return ret;
17561 +       if (nd.path.dentry->d_inode) {
17562 +               *dev = nd.path.dentry->d_inode->i_rdev;
17563 +               *mode = nd.path.dentry->d_inode->i_mode;
17564 +       }
17565 +       path_put(&nd.path);
17566 +       return 0;
17567 +}
17568 +
17569 +static inline int __mapping_mode(dev_t device, dev_t target,
17570 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
17571 +{
17572 +       if (device)
17573 +               *mode = device_mode & S_IFMT;
17574 +       else if (target)
17575 +               *mode = target_mode & S_IFMT;
17576 +       else
17577 +               return -EINVAL;
17578 +
17579 +       /* if both given, device and target mode have to match */
17580 +       if (device && target &&
17581 +               ((device_mode ^ target_mode) & S_IFMT))
17582 +               return -EINVAL;
17583 +       return 0;
17584 +}
17585 +
17586 +
17587 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
17588 +       const char __user *target_path, int flags, int set)
17589 +{
17590 +       dev_t device = ~0, target = ~0;
17591 +       umode_t device_mode = 0, target_mode = 0, mode;
17592 +       int ret;
17593 +
17594 +       ret = __user_device(device_path, &device, &device_mode);
17595 +       if (ret)
17596 +               return ret;
17597 +       ret = __user_device(target_path, &target, &target_mode);
17598 +       if (ret)
17599 +               return ret;
17600 +
17601 +       ret = __mapping_mode(device, target,
17602 +               device_mode, target_mode, &mode);
17603 +       if (ret)
17604 +               return ret;
17605 +
17606 +       if (set)
17607 +               return do_set_mapping(vxi, device, target,
17608 +                       flags, mode);
17609 +       else
17610 +               return do_unset_mapping(vxi, device, target,
17611 +                       flags, mode);
17612 +}
17613 +
17614 +
17615 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
17616 +{
17617 +       struct vcmd_set_mapping_v0 vc_data;
17618 +
17619 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17620 +               return -EFAULT;
17621 +
17622 +       return do_mapping(vxi, vc_data.device, vc_data.target,
17623 +               vc_data.flags, 1);
17624 +}
17625 +
17626 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
17627 +{
17628 +       struct vcmd_set_mapping_v0 vc_data;
17629 +
17630 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17631 +               return -EFAULT;
17632 +
17633 +       return do_mapping(vxi, vc_data.device, vc_data.target,
17634 +               vc_data.flags, 0);
17635 +}
17636 +
17637 +
17638 +#ifdef CONFIG_COMPAT
17639 +
17640 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
17641 +{
17642 +       struct vcmd_set_mapping_v0_x32 vc_data;
17643 +
17644 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17645 +               return -EFAULT;
17646 +
17647 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
17648 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
17649 +}
17650 +
17651 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
17652 +{
17653 +       struct vcmd_set_mapping_v0_x32 vc_data;
17654 +
17655 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17656 +               return -EFAULT;
17657 +
17658 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
17659 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
17660 +}
17661 +
17662 +#endif /* CONFIG_COMPAT */
17663 +
17664 +
17665 diff -NurpP --minimal linux-3.9.5/kernel/vserver/dlimit.c linux-3.9.5-vs2.3.6.5/kernel/vserver/dlimit.c
17666 --- linux-3.9.5/kernel/vserver/dlimit.c 1970-01-01 00:00:00.000000000 +0000
17667 +++ linux-3.9.5-vs2.3.6.5/kernel/vserver/dlimit.c       2013-06-12 23:49:09.000000000 +0000
17668 @@ -0,0 +1,528 @@
17669 +/*
17670 + *  linux/kernel/vserver/dlimit.c
17671 + *
17672 + *  Virtual Server: Context Disk Limits
17673 + *
17674 + *  Copyright (C) 2004-2009  Herbert Pötzl
17675 + *
17676 + *  V0.01  initial version
17677 + *  V0.02  compat32 splitup
17678 + *  V0.03  extended interface
17679 + *
17680 + */
17681 +
17682 +#include <linux/statfs.h>
17683 +#include <linux/sched.h>
17684 +#include <linux/namei.h>
17685 +#include <linux/vs_tag.h>
17686 +#include <linux/vs_dlimit.h>
17687 +#include <linux/vserver/dlimit_cmd.h>
17688 +#include <linux/slab.h>
17689 +// #include <linux/gfp.h>
17690 +
17691 +#include <asm/uaccess.h>
17692 +
17693 +/*     __alloc_dl_info()
17694 +
17695 +       * allocate an initialized dl_info struct
17696 +       * doesn't make it visible (hash)                        */
17697 +
17698 +static struct dl_info *__alloc_dl_info(struct super_block *sb, vtag_t tag)
17699 +{
17700 +       struct dl_info *new = NULL;
17701 +
17702 +       vxdprintk(VXD_CBIT(dlim, 5),
17703 +               "alloc_dl_info(%p,%d)*", sb, tag);
17704 +
17705 +       /* would this benefit from a slab cache? */
17706 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
17707 +       if (!new)
17708 +               return 0;
17709 +
17710 +       memset(new, 0, sizeof(struct dl_info));
17711 +       new->dl_tag = tag;
17712 +       new->dl_sb = sb;
17713 +       // INIT_RCU_HEAD(&new->dl_rcu);
17714 +       INIT_HLIST_NODE(&new->dl_hlist);
17715 +       spin_lock_init(&new->dl_lock);
17716 +       atomic_set(&new->dl_refcnt, 0);
17717 +       atomic_set(&new->dl_usecnt, 0);
17718 +
17719 +       /* rest of init goes here */
17720 +
17721 +       vxdprintk(VXD_CBIT(dlim, 4),
17722 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
17723 +       return new;
17724 +}
17725 +
17726 +/*     __dealloc_dl_info()
17727 +
17728 +       * final disposal of dl_info                             */
17729 +
17730 +static void __dealloc_dl_info(struct dl_info *dli)
17731 +{
17732 +       vxdprintk(VXD_CBIT(dlim, 4),
17733 +               "dealloc_dl_info(%p)", dli);
17734 +
17735 +       dli->dl_hlist.next = LIST_POISON1;
17736 +       dli->dl_tag = -1;
17737 +       dli->dl_sb = 0;
17738 +
17739 +       BUG_ON(atomic_read(&dli->dl_usecnt));
17740 +       BUG_ON(atomic_read(&dli->dl_refcnt));
17741 +
17742 +       kfree(dli);
17743 +}
17744 +
17745 +
17746 +/*     hash table for dl_info hash */
17747 +
17748 +#define DL_HASH_SIZE   13
17749 +
17750 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
17751 +
17752 +static DEFINE_SPINLOCK(dl_info_hash_lock);
17753 +
17754 +
17755 +static inline unsigned int __hashval(struct super_block *sb, vtag_t tag)
17756 +{
17757 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
17758 +}
17759 +
17760 +
17761 +
17762 +/*     __hash_dl_info()
17763 +
17764 +       * add the dli to the global hash table
17765 +       * requires the hash_lock to be held                     */
17766 +
17767 +static inline void __hash_dl_info(struct dl_info *dli)
17768 +{
17769 +       struct hlist_head *head;
17770 +
17771 +       vxdprintk(VXD_CBIT(dlim, 6),
17772 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
17773 +       get_dl_info(dli);
17774 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
17775 +       hlist_add_head_rcu(&dli->dl_hlist, head);
17776 +}
17777 +
17778 +/*     __unhash_dl_info()
17779 +
17780 +       * remove the dli from the global hash table
17781 +       * requires the hash_lock to be held                     */
17782 +
17783 +static inline void __unhash_dl_info(struct dl_info *dli)
17784 +{
17785 +       vxdprintk(VXD_CBIT(dlim, 6),
17786 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
17787 +       hlist_del_rcu(&dli->dl_hlist);
17788 +       put_dl_info(dli);
17789 +}
17790 +
17791 +
17792 +/*     __lookup_dl_info()
17793 +
17794 +       * requires the rcu_read_lock()
17795 +       * doesn't increment the dl_refcnt                       */
17796 +
17797 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, vtag_t tag)
17798 +{
17799 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
17800 +       struct dl_info *dli;
17801 +
17802 +       hlist_for_each_entry_rcu(dli, head, dl_hlist) {
17803 +               if (dli->dl_tag == tag && dli->dl_sb == sb)
17804 +                       return dli;
17805 +       }
17806 +       return NULL;
17807 +}
17808 +
17809 +
17810 +struct dl_info *locate_dl_info(struct super_block *sb, vtag_t tag)
17811 +{
17812 +       struct dl_info *dli;
17813 +
17814 +       rcu_read_lock();
17815 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
17816 +       vxdprintk(VXD_CBIT(dlim, 7),
17817 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
17818 +       rcu_read_unlock();
17819 +       return dli;
17820 +}
17821 +
17822 +void rcu_free_dl_info(struct rcu_head *head)
17823 +{
17824 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
17825 +       int usecnt, refcnt;
17826 +
17827 +       BUG_ON(!dli || !head);
17828 +
17829 +       usecnt = atomic_read(&dli->dl_usecnt);
17830 +       BUG_ON(usecnt < 0);
17831 +
17832 +       refcnt = atomic_read(&dli->dl_refcnt);
17833 +       BUG_ON(refcnt < 0);
17834 +
17835 +       vxdprintk(VXD_CBIT(dlim, 3),
17836 +               "rcu_free_dl_info(%p)", dli);
17837 +       if (!usecnt)
17838 +               __dealloc_dl_info(dli);
17839 +       else
17840 +               printk("!!! rcu didn't free\n");
17841 +}
17842 +
17843 +
17844 +
17845 +
17846 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
17847 +       uint32_t flags, int add)
17848 +{
17849 +       struct path path;
17850 +       int ret;
17851 +
17852 +       ret = user_lpath(name, &path);
17853 +       if (!ret) {
17854 +               struct super_block *sb;
17855 +               struct dl_info *dli;
17856 +
17857 +               ret = -EINVAL;
17858 +               if (!path.dentry->d_inode)
17859 +                       goto out_release;
17860 +               if (!(sb = path.dentry->d_inode->i_sb))
17861 +                       goto out_release;
17862 +
17863 +               if (add) {
17864 +                       dli = __alloc_dl_info(sb, id);
17865 +                       spin_lock(&dl_info_hash_lock);
17866 +
17867 +                       ret = -EEXIST;
17868 +                       if (__lookup_dl_info(sb, id))
17869 +                               goto out_unlock;
17870 +                       __hash_dl_info(dli);
17871 +                       dli = NULL;
17872 +               } else {
17873 +                       spin_lock(&dl_info_hash_lock);
17874 +                       dli = __lookup_dl_info(sb, id);
17875 +
17876 +                       ret = -ESRCH;
17877 +                       if (!dli)
17878 +                               goto out_unlock;
17879 +                       __unhash_dl_info(dli);
17880 +               }
17881 +               ret = 0;
17882 +       out_unlock:
17883 +               spin_unlock(&dl_info_hash_lock);
17884 +               if (add && dli)
17885 +                       __dealloc_dl_info(dli);
17886 +       out_release:
17887 +               path_put(&path);
17888 +       }
17889 +       return ret;
17890 +}
17891 +
17892 +int vc_add_dlimit(uint32_t id, void __user *data)
17893 +{
17894 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
17895 +
17896 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17897 +               return -EFAULT;
17898 +
17899 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
17900 +}
17901 +
17902 +int vc_rem_dlimit(uint32_t id, void __user *data)
17903 +{
17904 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
17905 +
17906 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17907 +               return -EFAULT;
17908 +
17909 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
17910 +}
17911 +
17912 +#ifdef CONFIG_COMPAT
17913 +
17914 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
17915 +{
17916 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
17917 +
17918 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17919 +               return -EFAULT;
17920 +
17921 +       return do_addrem_dlimit(id,
17922 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
17923 +}
17924 +
17925 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
17926 +{
17927 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
17928 +
17929 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17930 +               return -EFAULT;
17931 +
17932 +       return do_addrem_dlimit(id,
17933 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
17934 +}
17935 +
17936 +#endif /* CONFIG_COMPAT */
17937 +
17938 +
17939 +static inline
17940 +int do_set_dlimit(uint32_t id, const char __user *name,
17941 +       uint32_t space_used, uint32_t space_total,
17942 +       uint32_t inodes_used, uint32_t inodes_total,
17943 +       uint32_t reserved, uint32_t flags)
17944 +{
17945 +       struct path path;
17946 +       int ret;
17947 +
17948 +       ret = user_lpath(name, &path);
17949 +       if (!ret) {
17950 +               struct super_block *sb;
17951 +               struct dl_info *dli;
17952 +
17953 +               ret = -EINVAL;
17954 +               if (!path.dentry->d_inode)
17955 +                       goto out_release;
17956 +               if (!(sb = path.dentry->d_inode->i_sb))
17957 +                       goto out_release;
17958 +
17959 +               /* sanity checks */
17960 +               if ((reserved != CDLIM_KEEP &&
17961 +                       reserved > 100) ||
17962 +                       (inodes_used != CDLIM_KEEP &&
17963 +                       inodes_used > inodes_total) ||
17964 +                       (space_used != CDLIM_KEEP &&
17965 +                       space_used > space_total))
17966 +                       goto out_release;
17967 +
17968 +               ret = -ESRCH;
17969 +               dli = locate_dl_info(sb, id);
17970 +               if (!dli)
17971 +                       goto out_release;
17972 +
17973 +               spin_lock(&dli->dl_lock);
17974 +
17975 +               if (inodes_used != CDLIM_KEEP)
17976 +                       dli->dl_inodes_used = inodes_used;
17977 +               if (inodes_total != CDLIM_KEEP)
17978 +                       dli->dl_inodes_total = inodes_total;
17979 +               if (space_used != CDLIM_KEEP)
17980 +                       dli->dl_space_used = dlimit_space_32to64(
17981 +                               space_used, flags, DLIMS_USED);
17982 +
17983 +               if (space_total == CDLIM_INFINITY)
17984 +                       dli->dl_space_total = DLIM_INFINITY;
17985 +               else if (space_total != CDLIM_KEEP)
17986 +                       dli->dl_space_total = dlimit_space_32to64(
17987 +                               space_total, flags, DLIMS_TOTAL);
17988 +
17989 +               if (reserved != CDLIM_KEEP)
17990 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
17991 +
17992 +               spin_unlock(&dli->dl_lock);
17993 +
17994 +               put_dl_info(dli);
17995 +               ret = 0;
17996 +
17997 +       out_release:
17998 +               path_put(&path);
17999 +       }
18000 +       return ret;
18001 +}
18002 +
18003 +int vc_set_dlimit(uint32_t id, void __user *data)
18004 +{
18005 +       struct vcmd_ctx_dlimit_v0 vc_data;
18006 +
18007 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18008 +               return -EFAULT;
18009 +
18010 +       return do_set_dlimit(id, vc_data.name,
18011 +               vc_data.space_used, vc_data.space_total,
18012 +               vc_data.inodes_used, vc_data.inodes_total,
18013 +               vc_data.reserved, vc_data.flags);
18014 +}
18015 +
18016 +#ifdef CONFIG_COMPAT
18017 +
18018 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
18019 +{
18020 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18021 +
18022 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18023 +               return -EFAULT;
18024 +
18025 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
18026 +               vc_data.space_used, vc_data.space_total,
18027 +               vc_data.inodes_used, vc_data.inodes_total,
18028 +               vc_data.reserved, vc_data.flags);
18029 +}
18030 +
18031 +#endif /* CONFIG_COMPAT */
18032 +
18033 +
18034 +static inline
18035 +int do_get_dlimit(uint32_t id, const char __user *name,
18036 +       uint32_t *space_used, uint32_t *space_total,
18037 +       uint32_t *inodes_used, uint32_t *inodes_total,
18038 +       uint32_t *reserved, uint32_t *flags)
18039 +{
18040 +       struct path path;
18041 +       int ret;
18042 +
18043 +       ret = user_lpath(name, &path);
18044 +       if (!ret) {
18045 +               struct super_block *sb;
18046 +               struct dl_info *dli;
18047 +
18048 +               ret = -EINVAL;
18049 +               if (!path.dentry->d_inode)
18050 +                       goto out_release;
18051 +               if (!(sb = path.dentry->d_inode->i_sb))
18052 +                       goto out_release;
18053 +
18054 +               ret = -ESRCH;
18055 +               dli = locate_dl_info(sb, id);
18056 +               if (!dli)
18057 +                       goto out_release;
18058 +
18059 +               spin_lock(&dli->dl_lock);
18060 +               *inodes_used = dli->dl_inodes_used;
18061 +               *inodes_total = dli->dl_inodes_total;
18062 +
18063 +               *space_used = dlimit_space_64to32(
18064 +                       dli->dl_space_used, flags, DLIMS_USED);
18065 +
18066 +               if (dli->dl_space_total == DLIM_INFINITY)
18067 +                       *space_total = CDLIM_INFINITY;
18068 +               else
18069 +                       *space_total = dlimit_space_64to32(
18070 +                               dli->dl_space_total, flags, DLIMS_TOTAL);
18071 +
18072 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
18073 +               spin_unlock(&dli->dl_lock);
18074 +
18075 +               put_dl_info(dli);
18076 +               ret = -EFAULT;
18077 +
18078 +               ret = 0;
18079 +       out_release:
18080 +               path_put(&path);
18081 +       }
18082 +       return ret;
18083 +}
18084 +
18085 +
18086 +int vc_get_dlimit(uint32_t id, void __user *data)
18087 +{
18088 +       struct vcmd_ctx_dlimit_v0 vc_data;
18089 +       int ret;
18090 +
18091 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18092 +               return -EFAULT;
18093 +
18094 +       ret = do_get_dlimit(id, vc_data.name,
18095 +               &vc_data.space_used, &vc_data.space_total,
18096 +               &vc_data.inodes_used, &vc_data.inodes_total,
18097 +               &vc_data.reserved, &vc_data.flags);
18098 +       if (ret)
18099 +               return ret;
18100 +
18101 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18102 +               return -EFAULT;
18103 +       return 0;
18104 +}
18105 +
18106 +#ifdef CONFIG_COMPAT
18107 +
18108 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
18109 +{
18110 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18111 +       int ret;
18112 +
18113 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18114 +               return -EFAULT;
18115 +
18116 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
18117 +               &vc_data.space_used, &vc_data.space_total,
18118 +               &vc_data.inodes_used, &vc_data.inodes_total,
18119 +               &vc_data.reserved, &vc_data.flags);
18120 +       if (ret)
18121 +               return ret;
18122 +
18123 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18124 +               return -EFAULT;
18125 +       return 0;
18126 +}
18127 +
18128 +#endif /* CONFIG_COMPAT */
18129 +
18130 +
18131 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
18132 +{
18133 +       struct dl_info *dli;
18134 +       __u64 blimit, bfree, bavail;
18135 +       __u32 ifree;
18136 +
18137 +       dli = locate_dl_info(sb, dx_current_tag());
18138 +       if (!dli)
18139 +               return;
18140 +
18141 +       spin_lock(&dli->dl_lock);
18142 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
18143 +               goto no_ilim;
18144 +
18145 +       /* reduce max inodes available to limit */
18146 +       if (buf->f_files > dli->dl_inodes_total)
18147 +               buf->f_files = dli->dl_inodes_total;
18148 +
18149 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
18150 +       /* reduce free inodes to min */
18151 +       if (ifree < buf->f_ffree)
18152 +               buf->f_ffree = ifree;
18153 +
18154 +no_ilim:
18155 +       if (dli->dl_space_total == DLIM_INFINITY)
18156 +               goto no_blim;
18157 +
18158 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
18159 +
18160 +       if (dli->dl_space_total < dli->dl_space_used)
18161 +               bfree = 0;
18162 +       else
18163 +               bfree = (dli->dl_space_total - dli->dl_space_used)
18164 +                       >> sb->s_blocksize_bits;
18165 +
18166 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
18167 +       if (bavail < dli->dl_space_used)
18168 +               bavail = 0;
18169 +       else
18170 +               bavail = (bavail - dli->dl_space_used)
18171 +                       >> sb->s_blocksize_bits;
18172 +
18173 +       /* reduce max space available to limit */
18174 +       if (buf->f_blocks > blimit)
18175 +               buf->f_blocks = blimit;
18176 +
18177 +       /* reduce free space to min */
18178 +       if (bfree < buf->f_bfree)
18179 +               buf->f_bfree = bfree;
18180 +
18181 +       /* reduce avail space to min */
18182 +       if (bavail < buf->f_bavail)
18183 +               buf->f_bavail = bavail;
18184 +
18185 +no_blim:
18186 +       spin_unlock(&dli->dl_lock);
18187 +       put_dl_info(dli);
18188 +
18189 +       return;
18190 +}
18191 +
18192 +#include <linux/module.h>
18193 +
18194 +EXPORT_SYMBOL_GPL(locate_dl_info);
18195 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
18196 +
18197 diff -NurpP --minimal linux-3.9.5/kernel/vserver/helper.c linux-3.9.5-vs2.3.6.5/kernel/vserver/helper.c
18198 --- linux-3.9.5/kernel/vserver/helper.c 1970-01-01 00:00:00.000000000 +0000
18199 +++ linux-3.9.5-vs2.3.6.5/kernel/vserver/helper.c       2013-06-01 08:27:59.000000000 +0000
18200 @@ -0,0 +1,230 @@
18201 +/*
18202 + *  linux/kernel/vserver/helper.c
18203 + *
18204 + *  Virtual Context Support
18205 + *
18206 + *  Copyright (C) 2004-2007  Herbert Pötzl
18207 + *
18208 + *  V0.01  basic helper
18209 + *
18210 + */
18211 +
18212 +#include <linux/kmod.h>
18213 +#include <linux/reboot.h>
18214 +#include <linux/vs_context.h>
18215 +#include <linux/vs_network.h>
18216 +#include <linux/vserver/signal.h>
18217 +
18218 +
18219 +char vshelper_path[255] = "/sbin/vshelper";
18220 +
18221 +static int vshelper_init(struct subprocess_info *info, struct cred *new_cred)
18222 +{
18223 +       current->flags &= ~PF_THREAD_BOUND;
18224 +       return 0;
18225 +}
18226 +
18227 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
18228 +{
18229 +       int ret;
18230 +
18231 +       if ((ret = call_usermodehelper_fns(name, argv, envp,
18232 +               sync ? UMH_WAIT_PROC : UMH_WAIT_EXEC,
18233 +               vshelper_init, NULL, NULL))) {
18234 +               printk(KERN_WARNING "%s: (%s %s) returned %s with %d\n",
18235 +                       name, argv[1], argv[2],
18236 +                       sync ? "sync" : "async", ret);
18237 +       }
18238 +       vxdprintk(VXD_CBIT(switch, 4),
18239 +               "%s: (%s %s) returned %s with %d",
18240 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
18241 +       return ret;
18242 +}
18243 +
18244 +/*
18245 + *      vshelper path is set via /proc/sys
18246 + *      invoked by vserver sys_reboot(), with
18247 + *      the following arguments
18248 + *
18249 + *      argv [0] = vshelper_path;
18250 + *      argv [1] = action: "restart", "halt", "poweroff", ...
18251 + *      argv [2] = context identifier
18252 + *
18253 + *      envp [*] = type-specific parameters
18254 + */
18255 +
18256 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
18257 +{
18258 +       char id_buf[8], cmd_buf[16];
18259 +       char uid_buf[16], pid_buf[16];
18260 +       int ret;
18261 +
18262 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18263 +       char *envp[] = {"HOME=/", "TERM=linux",
18264 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
18265 +                       uid_buf, pid_buf, cmd_buf, 0};
18266 +
18267 +       if (vx_info_state(vxi, VXS_HELPER))
18268 +               return -EAGAIN;
18269 +       vxi->vx_state |= VXS_HELPER;
18270 +
18271 +       snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
18272 +
18273 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18274 +       snprintf(uid_buf, sizeof(uid_buf), "VS_UID=%d",
18275 +               from_kuid(&init_user_ns, current_uid()));
18276 +       snprintf(pid_buf, sizeof(pid_buf), "VS_PID=%d", current->pid);
18277 +
18278 +       switch (cmd) {
18279 +       case LINUX_REBOOT_CMD_RESTART:
18280 +               argv[1] = "restart";
18281 +               break;
18282 +
18283 +       case LINUX_REBOOT_CMD_HALT:
18284 +               argv[1] = "halt";
18285 +               break;
18286 +
18287 +       case LINUX_REBOOT_CMD_POWER_OFF:
18288 +               argv[1] = "poweroff";
18289 +               break;
18290 +
18291 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
18292 +               argv[1] = "swsusp";
18293 +               break;
18294 +
18295 +       case LINUX_REBOOT_CMD_OOM:
18296 +               argv[1] = "oom";
18297 +               break;
18298 +
18299 +       default:
18300 +               vxi->vx_state &= ~VXS_HELPER;
18301 +               return 0;
18302 +       }
18303 +
18304 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
18305 +       vxi->vx_state &= ~VXS_HELPER;
18306 +       __wakeup_vx_info(vxi);
18307 +       return (ret) ? -EPERM : 0;
18308 +}
18309 +
18310 +
18311 +long vs_reboot(unsigned int cmd, void __user *arg)
18312 +{
18313 +       struct vx_info *vxi = current_vx_info();
18314 +       long ret = 0;
18315 +
18316 +       vxdprintk(VXD_CBIT(misc, 5),
18317 +               "vs_reboot(%p[#%d],%u)",
18318 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18319 +
18320 +       ret = vs_reboot_helper(vxi, cmd, arg);
18321 +       if (ret)
18322 +               return ret;
18323 +
18324 +       vxi->reboot_cmd = cmd;
18325 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18326 +               switch (cmd) {
18327 +               case LINUX_REBOOT_CMD_RESTART:
18328 +               case LINUX_REBOOT_CMD_HALT:
18329 +               case LINUX_REBOOT_CMD_POWER_OFF:
18330 +                       vx_info_kill(vxi, 0, SIGKILL);
18331 +                       vx_info_kill(vxi, 1, SIGKILL);
18332 +               default:
18333 +                       break;
18334 +               }
18335 +       }
18336 +       return 0;
18337 +}
18338 +
18339 +long vs_oom_action(unsigned int cmd)
18340 +{
18341 +       struct vx_info *vxi = current_vx_info();
18342 +       long ret = 0;
18343 +
18344 +       vxdprintk(VXD_CBIT(misc, 5),
18345 +               "vs_oom_action(%p[#%d],%u)",
18346 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18347 +
18348 +       ret = vs_reboot_helper(vxi, cmd, NULL);
18349 +       if (ret)
18350 +               return ret;
18351 +
18352 +       vxi->reboot_cmd = cmd;
18353 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18354 +               vx_info_kill(vxi, 0, SIGKILL);
18355 +               vx_info_kill(vxi, 1, SIGKILL);
18356 +       }
18357 +       return 0;
18358 +}
18359 +
18360 +/*
18361 + *      argv [0] = vshelper_path;
18362 + *      argv [1] = action: "startup", "shutdown"
18363 + *      argv [2] = context identifier
18364 + *
18365 + *      envp [*] = type-specific parameters
18366 + */
18367 +
18368 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
18369 +{
18370 +       char id_buf[8], cmd_buf[16];
18371 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18372 +       char *envp[] = {"HOME=/", "TERM=linux",
18373 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18374 +
18375 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
18376 +               return 0;
18377 +
18378 +       snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
18379 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18380 +
18381 +       switch (cmd) {
18382 +       case VSC_STARTUP:
18383 +               argv[1] = "startup";
18384 +               break;
18385 +       case VSC_SHUTDOWN:
18386 +               argv[1] = "shutdown";
18387 +               break;
18388 +       default:
18389 +               return 0;
18390 +       }
18391 +
18392 +       return do_vshelper(vshelper_path, argv, envp, 1);
18393 +}
18394 +
18395 +
18396 +/*
18397 + *      argv [0] = vshelper_path;
18398 + *      argv [1] = action: "netup", "netdown"
18399 + *      argv [2] = context identifier
18400 + *
18401 + *      envp [*] = type-specific parameters
18402 + */
18403 +
18404 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
18405 +{
18406 +       char id_buf[8], cmd_buf[16];
18407 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18408 +       char *envp[] = {"HOME=/", "TERM=linux",
18409 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18410 +
18411 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
18412 +               return 0;
18413 +
18414 +       snprintf(id_buf, sizeof(id_buf), "%d", nxi->nx_id);
18415 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18416 +
18417 +       switch (cmd) {
18418 +       case VSC_NETUP:
18419 +               argv[1] = "netup";
18420 +               break;
18421 +       case VSC_NETDOWN:
18422 +               argv[1] = "netdown";
18423 +               break;
18424 +       default:
18425 +               return 0;
18426 +       }
18427 +
18428 +       return do_vshelper(vshelper_path, argv, envp, 1);
18429 +}
18430 +
18431 diff -NurpP --minimal linux-3.9.5/kernel/vserver/history.c linux-3.9.5-vs2.3.6.5/kernel/vserver/history.c
18432 --- linux-3.9.5/kernel/vserver/history.c        1970-01-01 00:00:00.000000000 +0000
18433 +++ linux-3.9.5-vs2.3.6.5/kernel/vserver/history.c      2013-05-31 14:47:11.000000000 +0000
18434 @@ -0,0 +1,258 @@
18435 +/*
18436 + *  kernel/vserver/history.c
18437 + *
18438 + *  Virtual Context History Backtrace
18439 + *
18440 + *  Copyright (C) 2004-2007  Herbert Pötzl
18441 + *
18442 + *  V0.01  basic structure
18443 + *  V0.02  hash/unhash and trace
18444 + *  V0.03  preemption fixes
18445 + *
18446 + */
18447 +
18448 +#include <linux/module.h>
18449 +#include <asm/uaccess.h>
18450 +
18451 +#include <linux/vserver/context.h>
18452 +#include <linux/vserver/debug.h>
18453 +#include <linux/vserver/debug_cmd.h>
18454 +#include <linux/vserver/history.h>
18455 +
18456 +
18457 +#ifdef CONFIG_VSERVER_HISTORY
18458 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
18459 +#else
18460 +#define VXH_SIZE       64
18461 +#endif
18462 +
18463 +struct _vx_history {
18464 +       unsigned int counter;
18465 +
18466 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
18467 +};
18468 +
18469 +
18470 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
18471 +
18472 +unsigned volatile int vxh_active = 1;
18473 +
18474 +static atomic_t sequence = ATOMIC_INIT(0);
18475 +
18476 +
18477 +/*     vxh_advance()
18478 +
18479 +       * requires disabled preemption                          */
18480 +
18481 +struct _vx_hist_entry *vxh_advance(void *loc)
18482 +{
18483 +       unsigned int cpu = smp_processor_id();
18484 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
18485 +       struct _vx_hist_entry *entry;
18486 +       unsigned int index;
18487 +
18488 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
18489 +       entry = &hist->entry[index];
18490 +
18491 +       entry->seq = atomic_inc_return(&sequence);
18492 +       entry->loc = loc;
18493 +       return entry;
18494 +}
18495 +
18496 +EXPORT_SYMBOL_GPL(vxh_advance);
18497 +
18498 +
18499 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
18500 +
18501 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
18502 +
18503 +
18504 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
18505 +
18506 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
18507 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
18508 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
18509 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
18510 +
18511 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
18512 +{
18513 +       switch (e->type) {
18514 +       case VXH_THROW_OOPS:
18515 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
18516 +               break;
18517 +
18518 +       case VXH_GET_VX_INFO:
18519 +       case VXH_PUT_VX_INFO:
18520 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
18521 +                       VXH_LOC_ARGS(e),
18522 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
18523 +                       VXH_VXI_ARGS(e));
18524 +               break;
18525 +
18526 +       case VXH_INIT_VX_INFO:
18527 +       case VXH_SET_VX_INFO:
18528 +       case VXH_CLR_VX_INFO:
18529 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
18530 +                       VXH_LOC_ARGS(e),
18531 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
18532 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
18533 +                       VXH_VXI_ARGS(e), e->sc.data);
18534 +               break;
18535 +
18536 +       case VXH_CLAIM_VX_INFO:
18537 +       case VXH_RELEASE_VX_INFO:
18538 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
18539 +                       VXH_LOC_ARGS(e),
18540 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
18541 +                       VXH_VXI_ARGS(e), e->sc.data);
18542 +               break;
18543 +
18544 +       case VXH_ALLOC_VX_INFO:
18545 +       case VXH_DEALLOC_VX_INFO:
18546 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
18547 +                       VXH_LOC_ARGS(e),
18548 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
18549 +                       VXH_VXI_ARGS(e));
18550 +               break;
18551 +
18552 +       case VXH_HASH_VX_INFO:
18553 +       case VXH_UNHASH_VX_INFO:
18554 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
18555 +                       VXH_LOC_ARGS(e),
18556 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
18557 +                       VXH_VXI_ARGS(e));
18558 +               break;
18559 +
18560 +       case VXH_LOC_VX_INFO:
18561 +       case VXH_LOOKUP_VX_INFO:
18562 +       case VXH_CREATE_VX_INFO:
18563 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
18564 +                       VXH_LOC_ARGS(e),
18565 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
18566 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
18567 +                       e->ll.arg, VXH_VXI_ARGS(e));
18568 +               break;
18569 +       }
18570 +}
18571 +
18572 +static void __vxh_dump_history(void)
18573 +{
18574 +       unsigned int i, cpu;
18575 +
18576 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
18577 +               atomic_read(&sequence), NR_CPUS);
18578 +
18579 +       for (i = 0; i < VXH_SIZE; i++) {
18580 +               for_each_online_cpu(cpu) {
18581 +                       struct _vx_history *hist =
18582 +                               &per_cpu(vx_history_buffer, cpu);
18583 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
18584 +                       struct _vx_hist_entry *entry = &hist->entry[index];
18585 +
18586 +                       vxh_dump_entry(entry, cpu);
18587 +               }
18588 +       }
18589 +}
18590 +
18591 +void   vxh_dump_history(void)
18592 +{
18593 +       vxh_active = 0;
18594 +#ifdef CONFIG_SMP
18595 +       local_irq_enable();
18596 +       smp_send_stop();
18597 +       local_irq_disable();
18598 +#endif
18599 +       __vxh_dump_history();
18600 +}
18601 +
18602 +
18603 +/* vserver syscall commands below here */
18604 +
18605 +
18606 +int vc_dump_history(uint32_t id)
18607 +{
18608 +       vxh_active = 0;
18609 +       __vxh_dump_history();
18610 +       vxh_active = 1;
18611 +
18612 +       return 0;
18613 +}
18614 +
18615 +
18616 +int do_read_history(struct __user _vx_hist_entry *data,
18617 +       int cpu, uint32_t *index, uint32_t *count)
18618 +{
18619 +       int pos, ret = 0;
18620 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
18621 +       int end = hist->counter;
18622 +       int start = end - VXH_SIZE + 2;
18623 +       int idx = *index;
18624 +
18625 +       /* special case: get current pos */
18626 +       if (!*count) {
18627 +               *index = end;
18628 +               return 0;
18629 +       }
18630 +
18631 +       /* have we lost some data? */
18632 +       if (idx < start)
18633 +               idx = start;
18634 +
18635 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
18636 +               struct _vx_hist_entry *entry =
18637 +                       &hist->entry[idx % VXH_SIZE];
18638 +
18639 +               /* send entry to userspace */
18640 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
18641 +               if (ret)
18642 +                       break;
18643 +       }
18644 +       /* save new index and count */
18645 +       *index = idx;
18646 +       *count = pos;
18647 +       return ret ? ret : (*index < end);
18648 +}
18649 +
18650 +int vc_read_history(uint32_t id, void __user *data)
18651 +{
18652 +       struct vcmd_read_history_v0 vc_data;
18653 +       int ret;
18654 +
18655 +       if (id >= NR_CPUS)
18656 +               return -EINVAL;
18657 +
18658 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18659 +               return -EFAULT;
18660 +
18661 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
18662 +               id, &vc_data.index, &vc_data.count);
18663 +
18664 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18665 +               return -EFAULT;
18666 +       return ret;
18667 +}
18668 +
18669 +#ifdef CONFIG_COMPAT
18670 +
18671 +int vc_read_history_x32(uint32_t id, void __user *data)
18672 +{
18673 +       struct vcmd_read_history_v0_x32 vc_data;
18674 +       int ret;
18675 +
18676 +       if (id >= NR_CPUS)
18677 +               return -EINVAL;
18678 +
18679 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18680 +               return -EFAULT;
18681 +
18682 +       ret = do_read_history((struct __user _vx_hist_entry *)
18683 +               compat_ptr(vc_data.data_ptr),
18684 +               id, &vc_data.index, &vc_data.count);
18685 +
18686 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18687 +               return -EFAULT;
18688 +       return ret;
18689 +}
18690 +
18691 +#endif /* CONFIG_COMPAT */
18692 +
18693 diff -NurpP --minimal linux-3.9.5/kernel/vserver/inet.c linux-3.9.5-vs2.3.6.5/kernel/vserver/inet.c
18694 --- linux-3.9.5/kernel/vserver/inet.c   1970-01-01 00:00:00.000000000 +0000
18695 +++ linux-3.9.5-vs2.3.6.5/kernel/vserver/inet.c 2013-05-31 22:43:05.000000000 +0000
18696 @@ -0,0 +1,236 @@
18697 +
18698 +#include <linux/in.h>
18699 +#include <linux/inetdevice.h>
18700 +#include <linux/export.h>
18701 +#include <linux/vs_inet.h>
18702 +#include <linux/vs_inet6.h>
18703 +#include <linux/vserver/debug.h>
18704 +#include <net/route.h>
18705 +#include <net/addrconf.h>
18706 +
18707 +
18708 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
18709 +{
18710 +       int ret = 0;
18711 +
18712 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
18713 +               ret = 1;
18714 +       else {
18715 +               struct nx_addr_v4 *ptr;
18716 +               unsigned long irqflags;
18717 +
18718 +               spin_lock_irqsave(&nxi1->addr_lock, irqflags);
18719 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
18720 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
18721 +                               ret = 1;
18722 +                               break;
18723 +                       }
18724 +               }
18725 +               spin_unlock_irqrestore(&nxi1->addr_lock, irqflags);
18726 +       }
18727 +
18728 +       vxdprintk(VXD_CBIT(net, 2),
18729 +               "nx_v4_addr_conflict(%p,%p): %d",
18730 +               nxi1, nxi2, ret);
18731 +
18732 +       return ret;
18733 +}
18734 +
18735 +
18736 +#ifdef CONFIG_IPV6
18737 +
18738 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
18739 +{
18740 +       int ret = 0;
18741 +
18742 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
18743 +               ret = 1;
18744 +       else {
18745 +               struct nx_addr_v6 *ptr;
18746 +               unsigned long irqflags;
18747 +
18748 +               spin_lock_irqsave(&nxi1->addr_lock, irqflags);
18749 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
18750 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
18751 +                               ret = 1;
18752 +                               break;
18753 +                       }
18754 +               }
18755 +               spin_unlock_irqrestore(&nxi1->addr_lock, irqflags);
18756 +       }
18757 +
18758 +       vxdprintk(VXD_CBIT(net, 2),
18759 +               "nx_v6_addr_conflict(%p,%p): %d",
18760 +               nxi1, nxi2, ret);
18761 +
18762 +       return ret;
18763 +}
18764 +
18765 +#endif
18766 +
18767 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18768 +{
18769 +       struct in_device *in_dev;
18770 +       struct in_ifaddr **ifap;
18771 +       struct in_ifaddr *ifa;
18772 +       int ret = 0;
18773 +
18774 +       if (!dev)
18775 +               goto out;
18776 +       in_dev = in_dev_get(dev);
18777 +       if (!in_dev)
18778 +               goto out;
18779 +
18780 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
18781 +               ifap = &ifa->ifa_next) {
18782 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
18783 +                       ret = 1;
18784 +                       break;
18785 +               }
18786 +       }
18787 +       in_dev_put(in_dev);
18788 +out:
18789 +       return ret;
18790 +}
18791 +
18792 +
18793 +#ifdef CONFIG_IPV6
18794 +
18795 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18796 +{
18797 +       struct inet6_dev *in_dev;
18798 +       struct inet6_ifaddr *ifa;
18799 +       int ret = 0;
18800 +
18801 +       if (!dev)
18802 +               goto out;
18803 +       in_dev = in6_dev_get(dev);
18804 +       if (!in_dev)
18805 +               goto out;
18806 +
18807 +       // for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
18808 +       list_for_each_entry(ifa, &in_dev->addr_list, if_list) {
18809 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
18810 +                       ret = 1;
18811 +                       break;
18812 +               }
18813 +       }
18814 +       in6_dev_put(in_dev);
18815 +out:
18816 +       return ret;
18817 +}
18818 +
18819 +#endif
18820 +
18821 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18822 +{
18823 +       int ret = 1;
18824 +
18825 +       if (!nxi)
18826 +               goto out;
18827 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
18828 +               goto out;
18829 +#ifdef CONFIG_IPV6
18830 +       ret = 2;
18831 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
18832 +               goto out;
18833 +#endif
18834 +       ret = 0;
18835 +out:
18836 +       vxdprintk(VXD_CBIT(net, 3),
18837 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
18838 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
18839 +       return ret;
18840 +}
18841 +
18842 +struct rtable *ip_v4_find_src(struct net *net, struct nx_info *nxi,
18843 +       struct flowi4 *fl4)
18844 +{
18845 +       struct rtable *rt;
18846 +
18847 +       if (!nxi)
18848 +               return NULL;
18849 +
18850 +       /* FIXME: handle lback only case */
18851 +       if (!NX_IPV4(nxi))
18852 +               return ERR_PTR(-EPERM);
18853 +
18854 +       vxdprintk(VXD_CBIT(net, 4),
18855 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
18856 +               nxi, nxi ? nxi->nx_id : 0,
18857 +               NIPQUAD(fl4->saddr), NIPQUAD(fl4->daddr));
18858 +
18859 +       /* single IP is unconditional */
18860 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
18861 +               (fl4->saddr == INADDR_ANY))
18862 +               fl4->saddr = nxi->v4.ip[0].s_addr;
18863 +
18864 +       if (fl4->saddr == INADDR_ANY) {
18865 +               struct nx_addr_v4 *ptr;
18866 +               __be32 found = 0;
18867 +
18868 +               rt = __ip_route_output_key(net, fl4);
18869 +               if (!IS_ERR(rt)) {
18870 +                       found = fl4->saddr;
18871 +                       ip_rt_put(rt);
18872 +                       vxdprintk(VXD_CBIT(net, 4),
18873 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
18874 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(found));
18875 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
18876 +                               goto found;
18877 +               }
18878 +
18879 +               WARN_ON_ONCE(in_irq());
18880 +               spin_lock_bh(&nxi->addr_lock);
18881 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
18882 +                       __be32 primary = ptr->ip[0].s_addr;
18883 +                       __be32 mask = ptr->mask.s_addr;
18884 +                       __be32 neta = primary & mask;
18885 +
18886 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
18887 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
18888 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
18889 +                               NIPQUAD(mask), NIPQUAD(neta));
18890 +                       if ((found & mask) != neta)
18891 +                               continue;
18892 +
18893 +                       fl4->saddr = primary;
18894 +                       rt = __ip_route_output_key(net, fl4);
18895 +                       vxdprintk(VXD_CBIT(net, 4),
18896 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
18897 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(primary));
18898 +                       if (!IS_ERR(rt)) {
18899 +                               found = fl4->saddr;
18900 +                               ip_rt_put(rt);
18901 +                               if (found == primary)
18902 +                                       goto found_unlock;
18903 +                       }
18904 +               }
18905 +               /* still no source ip? */
18906 +               found = ipv4_is_loopback(fl4->daddr)
18907 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
18908 +       found_unlock:
18909 +               spin_unlock_bh(&nxi->addr_lock);
18910 +       found:
18911 +               /* assign src ip to flow */
18912 +               fl4->saddr = found;
18913 +
18914 +       } else {
18915 +               if (!v4_addr_in_nx_info(nxi, fl4->saddr, NXA_MASK_BIND))
18916 +                       return ERR_PTR(-EPERM);
18917 +       }
18918 +
18919 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
18920 +               if (ipv4_is_loopback(fl4->daddr))
18921 +                       fl4->daddr = nxi->v4_lback.s_addr;
18922 +               if (ipv4_is_loopback(fl4->saddr))
18923 +                       fl4->saddr = nxi->v4_lback.s_addr;
18924 +       } else if (ipv4_is_loopback(fl4->daddr) &&
18925 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
18926 +               return ERR_PTR(-EPERM);
18927 +
18928 +       return NULL;
18929 +}
18930 +
18931 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
18932 +
18933 diff -NurpP --minimal linux-3.9.5/kernel/vserver/init.c linux-3.9.5-vs2.3.6.5/kernel/vserver/init.c
18934 --- linux-3.9.5/kernel/vserver/init.c   1970-01-01 00:00:00.000000000 +0000
18935 +++ linux-3.9.5-vs2.3.6.5/kernel/vserver/init.c 2013-05-31 14:47:11.000000000 +0000
18936 @@ -0,0 +1,45 @@
18937 +/*
18938 + *  linux/kernel/init.c
18939 + *
18940 + *  Virtual Server Init
18941 + *
18942 + *  Copyright (C) 2004-2007  Herbert Pötzl
18943 + *
18944 + *  V0.01  basic structure
18945 + *
18946 + */
18947 +
18948 +#include <linux/init.h>
18949 +
18950 +int    vserver_register_sysctl(void);
18951 +void   vserver_unregister_sysctl(void);
18952 +
18953 +
18954 +static int __init init_vserver(void)
18955 +{
18956 +       int ret = 0;
18957 +
18958 +#ifdef CONFIG_VSERVER_DEBUG
18959 +       vserver_register_sysctl();
18960 +#endif
18961 +       return ret;
18962 +}
18963 +
18964 +
18965 +static void __exit exit_vserver(void)
18966 +{
18967 +
18968 +#ifdef CONFIG_VSERVER_DEBUG
18969 +       vserver_unregister_sysctl();
18970 +#endif
18971 +       return;
18972 +}
18973 +
18974 +/* FIXME: GFP_ZONETYPES gone
18975 +long vx_slab[GFP_ZONETYPES]; */
18976 +long vx_area;
18977 +
18978 +
18979 +module_init(init_vserver);
18980 +module_exit(exit_vserver);
18981 +
18982 diff -NurpP --minimal linux-3.9.5/kernel/vserver/inode.c linux-3.9.5-vs2.3.6.5/kernel/vserver/inode.c
18983 --- linux-3.9.5/kernel/vserver/inode.c  1970-01-01 00:00:00.000000000 +0000
18984 +++ linux-3.9.5-vs2.3.6.5/kernel/vserver/inode.c        2013-06-12 23:49:09.000000000 +0000
18985 @@ -0,0 +1,437 @@
18986 +/*
18987 + *  linux/kernel/vserver/inode.c
18988 + *
18989 + *  Virtual Server: File System Support
18990 + *
18991 + *  Copyright (C) 2004-2007  Herbert Pötzl
18992 + *
18993 + *  V0.01  separated from vcontext V0.05
18994 + *  V0.02  moved to tag (instead of xid)
18995 + *
18996 + */
18997 +
18998 +#include <linux/tty.h>
18999 +#include <linux/proc_fs.h>
19000 +#include <linux/devpts_fs.h>
19001 +#include <linux/fs.h>
19002 +#include <linux/file.h>
19003 +#include <linux/mount.h>
19004 +#include <linux/parser.h>
19005 +#include <linux/namei.h>
19006 +#include <linux/vserver/inode.h>
19007 +#include <linux/vserver/inode_cmd.h>
19008 +#include <linux/vs_base.h>
19009 +#include <linux/vs_tag.h>
19010 +
19011 +#include <asm/uaccess.h>
19012 +
19013 +
19014 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19015 +{
19016 +       struct proc_dir_entry *entry;
19017 +
19018 +       if (!in || !in->i_sb)
19019 +               return -ESRCH;
19020 +
19021 +       *flags = IATTR_TAG
19022 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
19023 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
19024 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
19025 +               | (IS_COW(in) ? IATTR_COW : 0);
19026 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
19027 +
19028 +       if (S_ISDIR(in->i_mode))
19029 +               *mask |= IATTR_BARRIER;
19030 +
19031 +       if (IS_TAGGED(in)) {
19032 +               *tag = i_tag_read(in);
19033 +               *mask |= IATTR_TAG;
19034 +       }
19035 +
19036 +       switch (in->i_sb->s_magic) {
19037 +       case PROC_SUPER_MAGIC:
19038 +               entry = PROC_I(in)->pde;
19039 +
19040 +               /* check for specific inodes? */
19041 +               if (entry)
19042 +                       *mask |= IATTR_FLAGS;
19043 +               if (entry)
19044 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
19045 +               else
19046 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
19047 +               break;
19048 +
19049 +       case DEVPTS_SUPER_MAGIC:
19050 +               *tag = i_tag_read(in);
19051 +               *mask |= IATTR_TAG;
19052 +               break;
19053 +
19054 +       default:
19055 +               break;
19056 +       }
19057 +       return 0;
19058 +}
19059 +
19060 +int vc_get_iattr(void __user *data)
19061 +{
19062 +       struct path path;
19063 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
19064 +       int ret;
19065 +
19066 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19067 +               return -EFAULT;
19068 +
19069 +       ret = user_lpath(vc_data.name, &path);
19070 +       if (!ret) {
19071 +               ret = __vc_get_iattr(path.dentry->d_inode,
19072 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19073 +               path_put(&path);
19074 +       }
19075 +       if (ret)
19076 +               return ret;
19077 +
19078 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19079 +               ret = -EFAULT;
19080 +       return ret;
19081 +}
19082 +
19083 +#ifdef CONFIG_COMPAT
19084 +
19085 +int vc_get_iattr_x32(void __user *data)
19086 +{
19087 +       struct path path;
19088 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
19089 +       int ret;
19090 +
19091 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19092 +               return -EFAULT;
19093 +
19094 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19095 +       if (!ret) {
19096 +               ret = __vc_get_iattr(path.dentry->d_inode,
19097 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19098 +               path_put(&path);
19099 +       }
19100 +       if (ret)
19101 +               return ret;
19102 +
19103 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19104 +               ret = -EFAULT;
19105 +       return ret;
19106 +}
19107 +
19108 +#endif /* CONFIG_COMPAT */
19109 +
19110 +
19111 +int vc_fget_iattr(uint32_t fd, void __user *data)
19112 +{
19113 +       struct file *filp;
19114 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
19115 +       int ret;
19116 +
19117 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19118 +               return -EFAULT;
19119 +
19120 +       filp = fget(fd);
19121 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19122 +               return -EBADF;
19123 +
19124 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
19125 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
19126 +
19127 +       fput(filp);
19128 +
19129 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19130 +               ret = -EFAULT;
19131 +       return ret;
19132 +}
19133 +
19134 +
19135 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19136 +{
19137 +       struct inode *in = de->d_inode;
19138 +       int error = 0, is_proc = 0, has_tag = 0;
19139 +       struct iattr attr = { 0 };
19140 +
19141 +       if (!in || !in->i_sb)
19142 +               return -ESRCH;
19143 +
19144 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
19145 +       if ((*mask & IATTR_FLAGS) && !is_proc)
19146 +               return -EINVAL;
19147 +
19148 +       has_tag = IS_TAGGED(in) ||
19149 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
19150 +       if ((*mask & IATTR_TAG) && !has_tag)
19151 +               return -EINVAL;
19152 +
19153 +       mutex_lock(&in->i_mutex);
19154 +       if (*mask & IATTR_TAG) {
19155 +               attr.ia_tag = make_ktag(&init_user_ns, *tag);
19156 +               attr.ia_valid |= ATTR_TAG;
19157 +       }
19158 +
19159 +       if (*mask & IATTR_FLAGS) {
19160 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
19161 +               unsigned int iflags = PROC_I(in)->vx_flags;
19162 +
19163 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
19164 +                       | (*flags & IATTR_FLAGS);
19165 +               PROC_I(in)->vx_flags = iflags;
19166 +               if (entry)
19167 +                       entry->vx_flags = iflags;
19168 +       }
19169 +
19170 +       if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
19171 +               IATTR_BARRIER | IATTR_COW)) {
19172 +               int iflags = in->i_flags;
19173 +               int vflags = in->i_vflags;
19174 +
19175 +               if (*mask & IATTR_IMMUTABLE) {
19176 +                       if (*flags & IATTR_IMMUTABLE)
19177 +                               iflags |= S_IMMUTABLE;
19178 +                       else
19179 +                               iflags &= ~S_IMMUTABLE;
19180 +               }
19181 +               if (*mask & IATTR_IXUNLINK) {
19182 +                       if (*flags & IATTR_IXUNLINK)
19183 +                               iflags |= S_IXUNLINK;
19184 +                       else
19185 +                               iflags &= ~S_IXUNLINK;
19186 +               }
19187 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
19188 +                       if (*flags & IATTR_BARRIER)
19189 +                               vflags |= V_BARRIER;
19190 +                       else
19191 +                               vflags &= ~V_BARRIER;
19192 +               }
19193 +               if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
19194 +                       if (*flags & IATTR_COW)
19195 +                               vflags |= V_COW;
19196 +                       else
19197 +                               vflags &= ~V_COW;
19198 +               }
19199 +               if (in->i_op && in->i_op->sync_flags) {
19200 +                       error = in->i_op->sync_flags(in, iflags, vflags);
19201 +                       if (error)
19202 +                               goto out;
19203 +               }
19204 +       }
19205 +
19206 +       if (attr.ia_valid) {
19207 +               if (in->i_op && in->i_op->setattr)
19208 +                       error = in->i_op->setattr(de, &attr);
19209 +               else {
19210 +                       error = inode_change_ok(in, &attr);
19211 +                       if (!error) {
19212 +                               setattr_copy(in, &attr);
19213 +                               mark_inode_dirty(in);
19214 +                       }
19215 +               }
19216 +       }
19217 +
19218 +out:
19219 +       mutex_unlock(&in->i_mutex);
19220 +       return error;
19221 +}
19222 +
19223 +int vc_set_iattr(void __user *data)
19224 +{
19225 +       struct path path;
19226 +       struct vcmd_ctx_iattr_v1 vc_data;
19227 +       int ret;
19228 +
19229 +       if (!capable(CAP_LINUX_IMMUTABLE))
19230 +               return -EPERM;
19231 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19232 +               return -EFAULT;
19233 +
19234 +       ret = user_lpath(vc_data.name, &path);
19235 +       if (!ret) {
19236 +               ret = __vc_set_iattr(path.dentry,
19237 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19238 +               path_put(&path);
19239 +       }
19240 +
19241 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19242 +               ret = -EFAULT;
19243 +       return ret;
19244 +}
19245 +
19246 +#ifdef CONFIG_COMPAT
19247 +
19248 +int vc_set_iattr_x32(void __user *data)
19249 +{
19250 +       struct path path;
19251 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
19252 +       int ret;
19253 +
19254 +       if (!capable(CAP_LINUX_IMMUTABLE))
19255 +               return -EPERM;
19256 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19257 +               return -EFAULT;
19258 +
19259 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19260 +       if (!ret) {
19261 +               ret = __vc_set_iattr(path.dentry,
19262 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19263 +               path_put(&path);
19264 +       }
19265 +
19266 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19267 +               ret = -EFAULT;
19268 +       return ret;
19269 +}
19270 +
19271 +#endif /* CONFIG_COMPAT */
19272 +
19273 +int vc_fset_iattr(uint32_t fd, void __user *data)
19274 +{
19275 +       struct file *filp;
19276 +       struct vcmd_ctx_fiattr_v0 vc_data;
19277 +       int ret;
19278 +
19279 +       if (!capable(CAP_LINUX_IMMUTABLE))
19280 +               return -EPERM;
19281 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19282 +               return -EFAULT;
19283 +
19284 +       filp = fget(fd);
19285 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19286 +               return -EBADF;
19287 +
19288 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
19289 +               &vc_data.flags, &vc_data.mask);
19290 +
19291 +       fput(filp);
19292 +
19293 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19294 +               return -EFAULT;
19295 +       return ret;
19296 +}
19297 +
19298 +
19299 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
19300 +
19301 +static match_table_t tokens = {
19302 +       {Opt_notagcheck, "notagcheck"},
19303 +#ifdef CONFIG_PROPAGATE
19304 +       {Opt_notag, "notag"},
19305 +       {Opt_tag, "tag"},
19306 +       {Opt_tagid, "tagid=%u"},
19307 +#endif
19308 +       {Opt_err, NULL}
19309 +};
19310 +
19311 +
19312 +static void __dx_parse_remove(char *string, char *opt)
19313 +{
19314 +       char *p = strstr(string, opt);
19315 +       char *q = p;
19316 +
19317 +       if (p) {
19318 +               while (*q != '\0' && *q != ',')
19319 +                       q++;
19320 +               while (*q)
19321 +                       *p++ = *q++;
19322 +               while (*p)
19323 +                       *p++ = '\0';
19324 +       }
19325 +}
19326 +
19327 +int dx_parse_tag(char *string, vtag_t *tag, int remove, int *mnt_flags,
19328 +                unsigned long *flags)
19329 +{
19330 +       int set = 0;
19331 +       substring_t args[MAX_OPT_ARGS];
19332 +       int token;
19333 +       char *s, *p, *opts;
19334 +#if defined(CONFIG_PROPAGATE) || defined(CONFIG_VSERVER_DEBUG)
19335 +       int option = 0;
19336 +#endif
19337 +
19338 +       if (!string)
19339 +               return 0;
19340 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
19341 +       if (!s)
19342 +               return 0;
19343 +
19344 +       opts = s;
19345 +       while ((p = strsep(&opts, ",")) != NULL) {
19346 +               token = match_token(p, tokens, args);
19347 +
19348 +               switch (token) {
19349 +#ifdef CONFIG_PROPAGATE
19350 +               case Opt_tag:
19351 +                       if (tag)
19352 +                               *tag = 0;
19353 +                       if (remove)
19354 +                               __dx_parse_remove(s, "tag");
19355 +                       *mnt_flags |= MNT_TAGID;
19356 +                       set |= MNT_TAGID;
19357 +                       break;
19358 +               case Opt_notag:
19359 +                       if (remove)
19360 +                               __dx_parse_remove(s, "notag");
19361 +                       *mnt_flags |= MNT_NOTAG;
19362 +                       set |= MNT_NOTAG;
19363 +                       break;
19364 +               case Opt_tagid:
19365 +                       if (tag && !match_int(args, &option))
19366 +                               *tag = option;
19367 +                       if (remove)
19368 +                               __dx_parse_remove(s, "tagid");
19369 +                       *mnt_flags |= MNT_TAGID;
19370 +                       set |= MNT_TAGID;
19371 +                       break;
19372 +#endif /* CONFIG_PROPAGATE */
19373 +               case Opt_notagcheck:
19374 +                       if (remove)
19375 +                               __dx_parse_remove(s, "notagcheck");
19376 +                       *flags |= MS_NOTAGCHECK;
19377 +                       set |= MS_NOTAGCHECK;
19378 +                       break;
19379 +               }
19380 +               vxdprintk(VXD_CBIT(tag, 7),
19381 +                       "dx_parse_tag(" VS_Q("%s") "): %d:#%d",
19382 +                       p, token, option);
19383 +       }
19384 +       if (set)
19385 +               strcpy(string, s);
19386 +       kfree(s);
19387 +       return set;
19388 +}
19389 +
19390 +#ifdef CONFIG_PROPAGATE
19391 +
19392 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
19393 +{
19394 +       vtag_t new_tag = 0;
19395 +       struct vfsmount *mnt;
19396 +       int propagate;
19397 +
19398 +       if (!nd)
19399 +               return;
19400 +       mnt = nd->path.mnt;
19401 +       if (!mnt)
19402 +               return;
19403 +
19404 +       propagate = (mnt->mnt_flags & MNT_TAGID);
19405 +       if (propagate)
19406 +               new_tag = mnt->mnt_tag;
19407 +
19408 +       vxdprintk(VXD_CBIT(tag, 7),
19409 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
19410 +               inode, inode->i_ino, inode->i_tag,
19411 +               new_tag, (propagate) ? 1 : 0);
19412 +
19413 +       if (propagate)
19414 +               i_tag_write(inode, new_tag);
19415 +}
19416 +
19417 +#include <linux/module.h>
19418 +
19419 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
19420 +
19421 +#endif /* CONFIG_PROPAGATE */
19422 +
19423 diff -NurpP --minimal linux-3.9.5/kernel/vserver/limit.c linux-3.9.5-vs2.3.6.5/kernel/vserver/limit.c
19424 --- linux-3.9.5/kernel/vserver/limit.c  1970-01-01 00:00:00.000000000 +0000
19425 +++ linux-3.9.5-vs2.3.6.5/kernel/vserver/limit.c        2013-05-31 14:47:11.000000000 +0000
19426 @@ -0,0 +1,345 @@
19427 +/*
19428 + *  linux/kernel/vserver/limit.c
19429 + *
19430 + *  Virtual Server: Context Limits
19431 + *
19432 + *  Copyright (C) 2004-2010  Herbert Pötzl
19433 + *
19434 + *  V0.01  broken out from vcontext V0.05
19435 + *  V0.02  changed vcmds to vxi arg
19436 + *  V0.03  added memory cgroup support
19437 + *
19438 + */
19439 +
19440 +#include <linux/sched.h>
19441 +#include <linux/module.h>
19442 +#include <linux/memcontrol.h>
19443 +#include <linux/res_counter.h>
19444 +#include <linux/vs_limit.h>
19445 +#include <linux/vserver/limit.h>
19446 +#include <linux/vserver/limit_cmd.h>
19447 +
19448 +#include <asm/uaccess.h>
19449 +
19450 +
19451 +const char *vlimit_name[NUM_LIMITS] = {
19452 +       [RLIMIT_CPU]            = "CPU",
19453 +       [RLIMIT_NPROC]          = "NPROC",
19454 +       [RLIMIT_NOFILE]         = "NOFILE",
19455 +       [RLIMIT_LOCKS]          = "LOCKS",
19456 +       [RLIMIT_SIGPENDING]     = "SIGP",
19457 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
19458 +
19459 +       [VLIMIT_NSOCK]          = "NSOCK",
19460 +       [VLIMIT_OPENFD]         = "OPENFD",
19461 +       [VLIMIT_SHMEM]          = "SHMEM",
19462 +       [VLIMIT_DENTRY]         = "DENTRY",
19463 +};
19464 +
19465 +EXPORT_SYMBOL_GPL(vlimit_name);
19466 +
19467 +#define MASK_ENTRY(x)  (1 << (x))
19468 +
19469 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
19470 +               /* minimum */
19471 +       0
19472 +       ,       /* softlimit */
19473 +       0
19474 +       ,       /* maximum */
19475 +       MASK_ENTRY( RLIMIT_NPROC        ) |
19476 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
19477 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
19478 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
19479 +
19480 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
19481 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
19482 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
19483 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
19484 +       0
19485 +};
19486 +               /* accounting only */
19487 +uint32_t account_mask =
19488 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
19489 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
19490 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
19491 +       0;
19492 +
19493 +
19494 +static int is_valid_vlimit(int id)
19495 +{
19496 +       uint32_t mask = vlimit_mask.minimum |
19497 +               vlimit_mask.softlimit | vlimit_mask.maximum;
19498 +       return mask & (1 << id);
19499 +}
19500 +
19501 +static int is_accounted_vlimit(int id)
19502 +{
19503 +       if (is_valid_vlimit(id))
19504 +               return 1;
19505 +       return account_mask & (1 << id);
19506 +}
19507 +
19508 +
19509 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
19510 +{
19511 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
19512 +       return VX_VLIM(limit);
19513 +}
19514 +
19515 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
19516 +{
19517 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
19518 +       return VX_VLIM(limit);
19519 +}
19520 +
19521 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
19522 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
19523 +{
19524 +       if (!is_valid_vlimit(id))
19525 +               return -EINVAL;
19526 +
19527 +       if (minimum)
19528 +               *minimum = CRLIM_UNSET;
19529 +       if (softlimit)
19530 +               *softlimit = vc_get_soft(vxi, id);
19531 +       if (maximum)
19532 +               *maximum = vc_get_hard(vxi, id);
19533 +       return 0;
19534 +}
19535 +
19536 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
19537 +{
19538 +       struct vcmd_ctx_rlimit_v0 vc_data;
19539 +       int ret;
19540 +
19541 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19542 +               return -EFAULT;
19543 +
19544 +       ret = do_get_rlimit(vxi, vc_data.id,
19545 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
19546 +       if (ret)
19547 +               return ret;
19548 +
19549 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19550 +               return -EFAULT;
19551 +       return 0;
19552 +}
19553 +
19554 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
19555 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
19556 +{
19557 +       if (!is_valid_vlimit(id))
19558 +               return -EINVAL;
19559 +
19560 +       if (maximum != CRLIM_KEEP)
19561 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
19562 +       if (softlimit != CRLIM_KEEP)
19563 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
19564 +
19565 +       /* clamp soft limit */
19566 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
19567 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
19568 +
19569 +       return 0;
19570 +}
19571 +
19572 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
19573 +{
19574 +       struct vcmd_ctx_rlimit_v0 vc_data;
19575 +
19576 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19577 +               return -EFAULT;
19578 +
19579 +       return do_set_rlimit(vxi, vc_data.id,
19580 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
19581 +}
19582 +
19583 +#ifdef CONFIG_IA32_EMULATION
19584 +
19585 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
19586 +{
19587 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
19588 +
19589 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19590 +               return -EFAULT;
19591 +
19592 +       return do_set_rlimit(vxi, vc_data.id,
19593 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
19594 +}
19595 +
19596 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
19597 +{
19598 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
19599 +       int ret;
19600 +
19601 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19602 +               return -EFAULT;
19603 +
19604 +       ret = do_get_rlimit(vxi, vc_data.id,
19605 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
19606 +       if (ret)
19607 +               return ret;
19608 +
19609 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19610 +               return -EFAULT;
19611 +       return 0;
19612 +}
19613 +
19614 +#endif /* CONFIG_IA32_EMULATION */
19615 +
19616 +
19617 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
19618 +{
19619 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
19620 +               return -EFAULT;
19621 +       return 0;
19622 +}
19623 +
19624 +
19625 +static inline void vx_reset_hits(struct _vx_limit *limit)
19626 +{
19627 +       int lim;
19628 +
19629 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19630 +               atomic_set(&__rlim_lhit(limit, lim), 0);
19631 +       }
19632 +}
19633 +
19634 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
19635 +{
19636 +       vx_reset_hits(&vxi->limit);
19637 +       return 0;
19638 +}
19639 +
19640 +static inline void vx_reset_minmax(struct _vx_limit *limit)
19641 +{
19642 +       rlim_t value;
19643 +       int lim;
19644 +
19645 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19646 +               value = __rlim_get(limit, lim);
19647 +               __rlim_rmax(limit, lim) = value;
19648 +               __rlim_rmin(limit, lim) = value;
19649 +       }
19650 +}
19651 +
19652 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
19653 +{
19654 +       vx_reset_minmax(&vxi->limit);
19655 +       return 0;
19656 +}
19657 +
19658 +
19659 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
19660 +{
19661 +       struct vcmd_rlimit_stat_v0 vc_data;
19662 +       struct _vx_limit *limit = &vxi->limit;
19663 +       int id;
19664 +
19665 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19666 +               return -EFAULT;
19667 +
19668 +       id = vc_data.id;
19669 +       if (!is_accounted_vlimit(id))
19670 +               return -EINVAL;
19671 +
19672 +       vx_limit_fixup(limit, id);
19673 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
19674 +       vc_data.value = __rlim_get(limit, id);
19675 +       vc_data.minimum = __rlim_rmin(limit, id);
19676 +       vc_data.maximum = __rlim_rmax(limit, id);
19677 +
19678 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19679 +               return -EFAULT;
19680 +       return 0;
19681 +}
19682 +
19683 +
19684 +void vx_vsi_meminfo(struct sysinfo *val)
19685 +{
19686 +#ifdef CONFIG_MEMCG
19687 +       struct mem_cgroup *mcg;
19688 +       u64 res_limit, res_usage;
19689 +
19690 +       rcu_read_lock();
19691 +       mcg = mem_cgroup_from_task(current);
19692 +       rcu_read_unlock();
19693 +       if (!mcg)
19694 +               goto out;
19695 +
19696 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
19697 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
19698 +
19699 +       if (res_limit != RESOURCE_MAX)
19700 +               val->totalram = (res_limit >> PAGE_SHIFT);
19701 +       val->freeram = val->totalram - (res_usage >> PAGE_SHIFT);
19702 +       val->bufferram = 0;
19703 +       val->totalhigh = 0;
19704 +       val->freehigh = 0;
19705 +out:
19706 +#endif /* CONFIG_MEMCG */
19707 +       return;
19708 +}
19709 +
19710 +void vx_vsi_swapinfo(struct sysinfo *val)
19711 +{
19712 +#ifdef CONFIG_MEMCG
19713 +#ifdef CONFIG_MEMCG_SWAP
19714 +       struct mem_cgroup *mcg;
19715 +       u64 res_limit, res_usage, memsw_limit, memsw_usage;
19716 +       s64 swap_limit, swap_usage;
19717 +
19718 +       rcu_read_lock();
19719 +       mcg = mem_cgroup_from_task(current);
19720 +       rcu_read_unlock();
19721 +       if (!mcg)
19722 +               goto out;
19723 +
19724 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
19725 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
19726 +       memsw_limit = mem_cgroup_memsw_read_u64(mcg, RES_LIMIT);
19727 +       memsw_usage = mem_cgroup_memsw_read_u64(mcg, RES_USAGE);
19728 +
19729 +       /* memory unlimited */
19730 +       if (res_limit == RESOURCE_MAX)
19731 +               goto out;
19732 +
19733 +       swap_limit = memsw_limit - res_limit;
19734 +       /* we have a swap limit? */
19735 +       if (memsw_limit != RESOURCE_MAX)
19736 +               val->totalswap = swap_limit >> PAGE_SHIFT;
19737 +
19738 +       /* calculate swap part */
19739 +       swap_usage = (memsw_usage > res_usage) ?
19740 +               memsw_usage - res_usage : 0;
19741 +
19742 +       /* total shown minus usage gives free swap */
19743 +       val->freeswap = (swap_usage < swap_limit) ?
19744 +               val->totalswap - (swap_usage >> PAGE_SHIFT) : 0;
19745 +out:
19746 +#else  /* !CONFIG_MEMCG_SWAP */
19747 +       val->totalswap = 0;
19748 +       val->freeswap = 0;
19749 +#endif /* !CONFIG_MEMCG_SWAP */
19750 +#endif /* CONFIG_MEMCG */
19751 +       return;
19752 +}
19753 +
19754 +long vx_vsi_cached(struct sysinfo *val)
19755 +{
19756 +       long cache = 0;
19757 +#ifdef CONFIG_MEMCG
19758 +       struct mem_cgroup *mcg;
19759 +
19760 +       rcu_read_lock();
19761 +       mcg = mem_cgroup_from_task(current);
19762 +       rcu_read_unlock();
19763 +       if (!mcg)
19764 +               goto out;
19765 +
19766 +       cache = mem_cgroup_stat_read_cache(mcg);
19767 +out:
19768 +#endif
19769 +       return cache;
19770 +}
19771 +
19772 diff -NurpP --minimal linux-3.9.5/kernel/vserver/limit_init.h linux-3.9.5-vs2.3.6.5/kernel/vserver/limit_init.h
19773 --- linux-3.9.5/kernel/vserver/limit_init.h     1970-01-01 00:00:00.000000000 +0000
19774 +++ linux-3.9.5-vs2.3.6.5/kernel/vserver/limit_init.h   2013-05-31 14:47:11.000000000 +0000
19775 @@ -0,0 +1,31 @@
19776 +
19777 +
19778 +static inline void vx_info_init_limit(struct _vx_limit *limit)
19779 +{
19780 +       int lim;
19781 +
19782 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19783 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
19784 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
19785 +               __rlim_set(limit, lim, 0);
19786 +               atomic_set(&__rlim_lhit(limit, lim), 0);
19787 +               __rlim_rmin(limit, lim) = 0;
19788 +               __rlim_rmax(limit, lim) = 0;
19789 +       }
19790 +}
19791 +
19792 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
19793 +{
19794 +       rlim_t value;
19795 +       int lim;
19796 +
19797 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19798 +               if ((1 << lim) & VLIM_NOCHECK)
19799 +                       continue;
19800 +               value = __rlim_get(limit, lim);
19801 +               vxwprintk_xid(value,
19802 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
19803 +                       limit, vlimit_name[lim], lim, (long)value);
19804 +       }
19805 +}
19806 +
19807 diff -NurpP --minimal linux-3.9.5/kernel/vserver/limit_proc.h linux-3.9.5-vs2.3.6.5/kernel/vserver/limit_proc.h
19808 --- linux-3.9.5/kernel/vserver/limit_proc.h     1970-01-01 00:00:00.000000000 +0000
19809 +++ linux-3.9.5-vs2.3.6.5/kernel/vserver/limit_proc.h   2013-05-31 14:47:11.000000000 +0000
19810 @@ -0,0 +1,57 @@
19811 +#ifndef _VX_LIMIT_PROC_H
19812 +#define _VX_LIMIT_PROC_H
19813 +
19814 +#include <linux/vserver/limit_int.h>
19815 +
19816 +
19817 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
19818 +#define VX_LIMIT_TOP   \
19819 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
19820 +
19821 +#define VX_LIMIT_ARG(r)                                \
19822 +       (unsigned long)__rlim_get(limit, r),    \
19823 +       (unsigned long)__rlim_rmin(limit, r),   \
19824 +       (unsigned long)__rlim_rmax(limit, r),   \
19825 +       VX_VLIM(__rlim_soft(limit, r)),         \
19826 +       VX_VLIM(__rlim_hard(limit, r)),         \
19827 +       atomic_read(&__rlim_lhit(limit, r))
19828 +
19829 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
19830 +{
19831 +       vx_limit_fixup(limit, -1);
19832 +       return sprintf(buffer, VX_LIMIT_TOP
19833 +               "PROC"  VX_LIMIT_FMT
19834 +               "VM"    VX_LIMIT_FMT
19835 +               "VML"   VX_LIMIT_FMT
19836 +               "RSS"   VX_LIMIT_FMT
19837 +               "ANON"  VX_LIMIT_FMT
19838 +               "RMAP"  VX_LIMIT_FMT
19839 +               "FILES" VX_LIMIT_FMT
19840 +               "OFD"   VX_LIMIT_FMT
19841 +               "LOCKS" VX_LIMIT_FMT
19842 +               "SOCK"  VX_LIMIT_FMT
19843 +               "MSGQ"  VX_LIMIT_FMT
19844 +               "SHM"   VX_LIMIT_FMT
19845 +               "SEMA"  VX_LIMIT_FMT
19846 +               "SEMS"  VX_LIMIT_FMT
19847 +               "DENT"  VX_LIMIT_FMT,
19848 +               VX_LIMIT_ARG(RLIMIT_NPROC),
19849 +               VX_LIMIT_ARG(RLIMIT_AS),
19850 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
19851 +               VX_LIMIT_ARG(RLIMIT_RSS),
19852 +               VX_LIMIT_ARG(VLIMIT_ANON),
19853 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
19854 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
19855 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
19856 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
19857 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
19858 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
19859 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
19860 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
19861 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
19862 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
19863 +}
19864 +
19865 +#endif /* _VX_LIMIT_PROC_H */
19866 +
19867 +
19868 diff -NurpP --minimal linux-3.9.5/kernel/vserver/network.c linux-3.9.5-vs2.3.6.5/kernel/vserver/network.c
19869 --- linux-3.9.5/kernel/vserver/network.c        1970-01-01 00:00:00.000000000 +0000
19870 +++ linux-3.9.5-vs2.3.6.5/kernel/vserver/network.c      2013-06-12 23:49:09.000000000 +0000
19871 @@ -0,0 +1,1053 @@
19872 +/*
19873 + *  linux/kernel/vserver/network.c
19874 + *
19875 + *  Virtual Server: Network Support
19876 + *
19877 + *  Copyright (C) 2003-2007  Herbert Pötzl
19878 + *
19879 + *  V0.01  broken out from vcontext V0.05
19880 + *  V0.02  cleaned up implementation
19881 + *  V0.03  added equiv nx commands
19882 + *  V0.04  switch to RCU based hash
19883 + *  V0.05  and back to locking again
19884 + *  V0.06  changed vcmds to nxi arg
19885 + *  V0.07  have __create claim() the nxi
19886 + *
19887 + */
19888 +
19889 +#include <linux/err.h>
19890 +#include <linux/slab.h>
19891 +#include <linux/rcupdate.h>
19892 +#include <net/ipv6.h>
19893 +
19894 +#include <linux/vs_network.h>
19895 +#include <linux/vs_pid.h>
19896 +#include <linux/vserver/network_cmd.h>
19897 +
19898 +
19899 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
19900 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
19901 +
19902 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
19903 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
19904 +
19905 +
19906 +static int __init init_network(void)
19907 +{
19908 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
19909 +               sizeof(struct nx_addr_v4), 0,
19910 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19911 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
19912 +               sizeof(struct nx_addr_v6), 0,
19913 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19914 +       return 0;
19915 +}
19916 +
19917 +
19918 +/*     __alloc_nx_addr_v4()                                    */
19919 +
19920 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
19921 +{
19922 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
19923 +               nx_addr_v4_cachep, GFP_KERNEL);
19924 +
19925 +       if (!IS_ERR(nxa))
19926 +               memset(nxa, 0, sizeof(*nxa));
19927 +       return nxa;
19928 +}
19929 +
19930 +/*     __dealloc_nx_addr_v4()                                  */
19931 +
19932 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
19933 +{
19934 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
19935 +}
19936 +
19937 +/*     __dealloc_nx_addr_v4_all()                              */
19938 +
19939 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
19940 +{
19941 +       while (nxa) {
19942 +               struct nx_addr_v4 *next = nxa->next;
19943 +
19944 +               __dealloc_nx_addr_v4(nxa);
19945 +               nxa = next;
19946 +       }
19947 +}
19948 +
19949 +
19950 +#ifdef CONFIG_IPV6
19951 +
19952 +/*     __alloc_nx_addr_v6()                                    */
19953 +
19954 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
19955 +{
19956 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
19957 +               nx_addr_v6_cachep, GFP_KERNEL);
19958 +
19959 +       if (!IS_ERR(nxa))
19960 +               memset(nxa, 0, sizeof(*nxa));
19961 +       return nxa;
19962 +}
19963 +
19964 +/*     __dealloc_nx_addr_v6()                                  */
19965 +
19966 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
19967 +{
19968 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
19969 +}
19970 +
19971 +/*     __dealloc_nx_addr_v6_all()                              */
19972 +
19973 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
19974 +{
19975 +       while (nxa) {
19976 +               struct nx_addr_v6 *next = nxa->next;
19977 +
19978 +               __dealloc_nx_addr_v6(nxa);
19979 +               nxa = next;
19980 +       }
19981 +}
19982 +
19983 +#endif /* CONFIG_IPV6 */
19984 +
19985 +/*     __alloc_nx_info()
19986 +
19987 +       * allocate an initialized nx_info struct
19988 +       * doesn't make it visible (hash)                        */
19989 +
19990 +static struct nx_info *__alloc_nx_info(vnid_t nid)
19991 +{
19992 +       struct nx_info *new = NULL;
19993 +
19994 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
19995 +
19996 +       /* would this benefit from a slab cache? */
19997 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
19998 +       if (!new)
19999 +               return 0;
20000 +
20001 +       memset(new, 0, sizeof(struct nx_info));
20002 +       new->nx_id = nid;
20003 +       INIT_HLIST_NODE(&new->nx_hlist);
20004 +       atomic_set(&new->nx_usecnt, 0);
20005 +       atomic_set(&new->nx_tasks, 0);
20006 +       spin_lock_init(&new->addr_lock);
20007 +       new->nx_state = 0;
20008 +
20009 +       new->nx_flags = NXF_INIT_SET;
20010 +
20011 +       /* rest of init goes here */
20012 +
20013 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
20014 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
20015 +
20016 +       vxdprintk(VXD_CBIT(nid, 0),
20017 +               "alloc_nx_info(%d) = %p", nid, new);
20018 +       atomic_inc(&nx_global_ctotal);
20019 +       return new;
20020 +}
20021 +
20022 +/*     __dealloc_nx_info()
20023 +
20024 +       * final disposal of nx_info                             */
20025 +
20026 +static void __dealloc_nx_info(struct nx_info *nxi)
20027 +{
20028 +       vxdprintk(VXD_CBIT(nid, 0),
20029 +               "dealloc_nx_info(%p)", nxi);
20030 +
20031 +       nxi->nx_hlist.next = LIST_POISON1;
20032 +       nxi->nx_id = -1;
20033 +
20034 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20035 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20036 +
20037 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
20038 +#ifdef CONFIG_IPV6
20039 +       __dealloc_nx_addr_v6_all(nxi->v6.next);
20040 +#endif
20041 +
20042 +       nxi->nx_state |= NXS_RELEASED;
20043 +       kfree(nxi);
20044 +       atomic_dec(&nx_global_ctotal);
20045 +}
20046 +
20047 +static void __shutdown_nx_info(struct nx_info *nxi)
20048 +{
20049 +       nxi->nx_state |= NXS_SHUTDOWN;
20050 +       vs_net_change(nxi, VSC_NETDOWN);
20051 +}
20052 +
20053 +/*     exported stuff                                          */
20054 +
20055 +void free_nx_info(struct nx_info *nxi)
20056 +{
20057 +       /* context shutdown is mandatory */
20058 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
20059 +
20060 +       /* context must not be hashed */
20061 +       BUG_ON(nxi->nx_state & NXS_HASHED);
20062 +
20063 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20064 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20065 +
20066 +       __dealloc_nx_info(nxi);
20067 +}
20068 +
20069 +
20070 +void __nx_set_lback(struct nx_info *nxi)
20071 +{
20072 +       int nid = nxi->nx_id;
20073 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
20074 +
20075 +       nxi->v4_lback.s_addr = lback;
20076 +}
20077 +
20078 +extern int __nx_inet_add_lback(__be32 addr);
20079 +extern int __nx_inet_del_lback(__be32 addr);
20080 +
20081 +
20082 +/*     hash table for nx_info hash */
20083 +
20084 +#define NX_HASH_SIZE   13
20085 +
20086 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
20087 +
20088 +static DEFINE_SPINLOCK(nx_info_hash_lock);
20089 +
20090 +
20091 +static inline unsigned int __hashval(vnid_t nid)
20092 +{
20093 +       return (nid % NX_HASH_SIZE);
20094 +}
20095 +
20096 +
20097 +
20098 +/*     __hash_nx_info()
20099 +
20100 +       * add the nxi to the global hash table
20101 +       * requires the hash_lock to be held                     */
20102 +
20103 +static inline void __hash_nx_info(struct nx_info *nxi)
20104 +{
20105 +       struct hlist_head *head;
20106 +
20107 +       vxd_assert_lock(&nx_info_hash_lock);
20108 +       vxdprintk(VXD_CBIT(nid, 4),
20109 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
20110 +
20111 +       /* context must not be hashed */
20112 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
20113 +
20114 +       nxi->nx_state |= NXS_HASHED;
20115 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
20116 +       hlist_add_head(&nxi->nx_hlist, head);
20117 +       atomic_inc(&nx_global_cactive);
20118 +}
20119 +
20120 +/*     __unhash_nx_info()
20121 +
20122 +       * remove the nxi from the global hash table
20123 +       * requires the hash_lock to be held                     */
20124 +
20125 +static inline void __unhash_nx_info(struct nx_info *nxi)
20126 +{
20127 +       vxd_assert_lock(&nx_info_hash_lock);
20128 +       vxdprintk(VXD_CBIT(nid, 4),
20129 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
20130 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
20131 +
20132 +       /* context must be hashed */
20133 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
20134 +       /* but without tasks */
20135 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20136 +
20137 +       nxi->nx_state &= ~NXS_HASHED;
20138 +       hlist_del(&nxi->nx_hlist);
20139 +       atomic_dec(&nx_global_cactive);
20140 +}
20141 +
20142 +
20143 +/*     __lookup_nx_info()
20144 +
20145 +       * requires the hash_lock to be held
20146 +       * doesn't increment the nx_refcnt                       */
20147 +
20148 +static inline struct nx_info *__lookup_nx_info(vnid_t nid)
20149 +{
20150 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
20151 +       struct hlist_node *pos;
20152 +       struct nx_info *nxi;
20153 +
20154 +       vxd_assert_lock(&nx_info_hash_lock);
20155 +       hlist_for_each(pos, head) {
20156 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20157 +
20158 +               if (nxi->nx_id == nid)
20159 +                       goto found;
20160 +       }
20161 +       nxi = NULL;
20162 +found:
20163 +       vxdprintk(VXD_CBIT(nid, 0),
20164 +               "__lookup_nx_info(#%u): %p[#%u]",
20165 +               nid, nxi, nxi ? nxi->nx_id : 0);
20166 +       return nxi;
20167 +}
20168 +
20169 +
20170 +/*     __create_nx_info()
20171 +
20172 +       * create the requested context
20173 +       * get(), claim() and hash it                            */
20174 +
20175 +static struct nx_info *__create_nx_info(int id)
20176 +{
20177 +       struct nx_info *new, *nxi = NULL;
20178 +
20179 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
20180 +
20181 +       if (!(new = __alloc_nx_info(id)))
20182 +               return ERR_PTR(-ENOMEM);
20183 +
20184 +       /* required to make dynamic xids unique */
20185 +       spin_lock(&nx_info_hash_lock);
20186 +
20187 +       /* static context requested */
20188 +       if ((nxi = __lookup_nx_info(id))) {
20189 +               vxdprintk(VXD_CBIT(nid, 0),
20190 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
20191 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20192 +                       nxi = ERR_PTR(-EBUSY);
20193 +               else
20194 +                       nxi = ERR_PTR(-EEXIST);
20195 +               goto out_unlock;
20196 +       }
20197 +       /* new context */
20198 +       vxdprintk(VXD_CBIT(nid, 0),
20199 +               "create_nx_info(%d) = %p (new)", id, new);
20200 +       claim_nx_info(new, NULL);
20201 +       __nx_set_lback(new);
20202 +       __hash_nx_info(get_nx_info(new));
20203 +       nxi = new, new = NULL;
20204 +
20205 +out_unlock:
20206 +       spin_unlock(&nx_info_hash_lock);
20207 +       if (new)
20208 +               __dealloc_nx_info(new);
20209 +       return nxi;
20210 +}
20211 +
20212 +
20213 +
20214 +/*     exported stuff                                          */
20215 +
20216 +
20217 +void unhash_nx_info(struct nx_info *nxi)
20218 +{
20219 +       __shutdown_nx_info(nxi);
20220 +       spin_lock(&nx_info_hash_lock);
20221 +       __unhash_nx_info(nxi);
20222 +       spin_unlock(&nx_info_hash_lock);
20223 +}
20224 +
20225 +/*     lookup_nx_info()
20226 +
20227 +       * search for a nx_info and get() it
20228 +       * negative id means current                             */
20229 +
20230 +struct nx_info *lookup_nx_info(int id)
20231 +{
20232 +       struct nx_info *nxi = NULL;
20233 +
20234 +       if (id < 0) {
20235 +               nxi = get_nx_info(current_nx_info());
20236 +       } else if (id > 1) {
20237 +               spin_lock(&nx_info_hash_lock);
20238 +               nxi = get_nx_info(__lookup_nx_info(id));
20239 +               spin_unlock(&nx_info_hash_lock);
20240 +       }
20241 +       return nxi;
20242 +}
20243 +
20244 +/*     nid_is_hashed()
20245 +
20246 +       * verify that nid is still hashed                       */
20247 +
20248 +int nid_is_hashed(vnid_t nid)
20249 +{
20250 +       int hashed;
20251 +
20252 +       spin_lock(&nx_info_hash_lock);
20253 +       hashed = (__lookup_nx_info(nid) != NULL);
20254 +       spin_unlock(&nx_info_hash_lock);
20255 +       return hashed;
20256 +}
20257 +
20258 +
20259 +#ifdef CONFIG_PROC_FS
20260 +
20261 +/*     get_nid_list()
20262 +
20263 +       * get a subset of hashed nids for proc
20264 +       * assumes size is at least one                          */
20265 +
20266 +int get_nid_list(int index, unsigned int *nids, int size)
20267 +{
20268 +       int hindex, nr_nids = 0;
20269 +
20270 +       /* only show current and children */
20271 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
20272 +               if (index > 0)
20273 +                       return 0;
20274 +               nids[nr_nids] = nx_current_nid();
20275 +               return 1;
20276 +       }
20277 +
20278 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
20279 +               struct hlist_head *head = &nx_info_hash[hindex];
20280 +               struct hlist_node *pos;
20281 +
20282 +               spin_lock(&nx_info_hash_lock);
20283 +               hlist_for_each(pos, head) {
20284 +                       struct nx_info *nxi;
20285 +
20286 +                       if (--index > 0)
20287 +                               continue;
20288 +
20289 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20290 +                       nids[nr_nids] = nxi->nx_id;
20291 +                       if (++nr_nids >= size) {
20292 +                               spin_unlock(&nx_info_hash_lock);
20293 +                               goto out;
20294 +                       }
20295 +               }
20296 +               /* keep the lock time short */
20297 +               spin_unlock(&nx_info_hash_lock);
20298 +       }
20299 +out:
20300 +       return nr_nids;
20301 +}
20302 +#endif
20303 +
20304 +
20305 +/*
20306 + *     migrate task to new network
20307 + *     gets nxi, puts old_nxi on change
20308 + */
20309 +
20310 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
20311 +{
20312 +       struct nx_info *old_nxi;
20313 +       int ret = 0;
20314 +
20315 +       if (!p || !nxi)
20316 +               BUG();
20317 +
20318 +       vxdprintk(VXD_CBIT(nid, 5),
20319 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
20320 +               p, nxi, nxi->nx_id,
20321 +               atomic_read(&nxi->nx_usecnt),
20322 +               atomic_read(&nxi->nx_tasks));
20323 +
20324 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
20325 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20326 +               return -EACCES;
20327 +
20328 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
20329 +               return -EFAULT;
20330 +
20331 +       /* maybe disallow this completely? */
20332 +       old_nxi = task_get_nx_info(p);
20333 +       if (old_nxi == nxi)
20334 +               goto out;
20335 +
20336 +       task_lock(p);
20337 +       if (old_nxi)
20338 +               clr_nx_info(&p->nx_info);
20339 +       claim_nx_info(nxi, p);
20340 +       set_nx_info(&p->nx_info, nxi);
20341 +       p->nid = nxi->nx_id;
20342 +       task_unlock(p);
20343 +
20344 +       vxdprintk(VXD_CBIT(nid, 5),
20345 +               "moved task %p into nxi:%p[#%d]",
20346 +               p, nxi, nxi->nx_id);
20347 +
20348 +       if (old_nxi)
20349 +               release_nx_info(old_nxi, p);
20350 +       ret = 0;
20351 +out:
20352 +       put_nx_info(old_nxi);
20353 +       return ret;
20354 +}
20355 +
20356 +
20357 +void nx_set_persistent(struct nx_info *nxi)
20358 +{
20359 +       vxdprintk(VXD_CBIT(nid, 6),
20360 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
20361 +
20362 +       get_nx_info(nxi);
20363 +       claim_nx_info(nxi, NULL);
20364 +}
20365 +
20366 +void nx_clear_persistent(struct nx_info *nxi)
20367 +{
20368 +       vxdprintk(VXD_CBIT(nid, 6),
20369 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
20370 +
20371 +       release_nx_info(nxi, NULL);
20372 +       put_nx_info(nxi);
20373 +}
20374 +
20375 +void nx_update_persistent(struct nx_info *nxi)
20376 +{
20377 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
20378 +               nx_set_persistent(nxi);
20379 +       else
20380 +               nx_clear_persistent(nxi);
20381 +}
20382 +
20383 +/* vserver syscall commands below here */
20384 +
20385 +/* taks nid and nx_info functions */
20386 +
20387 +#include <asm/uaccess.h>
20388 +
20389 +
20390 +int vc_task_nid(uint32_t id)
20391 +{
20392 +       vnid_t nid;
20393 +
20394 +       if (id) {
20395 +               struct task_struct *tsk;
20396 +
20397 +               rcu_read_lock();
20398 +               tsk = find_task_by_real_pid(id);
20399 +               nid = (tsk) ? tsk->nid : -ESRCH;
20400 +               rcu_read_unlock();
20401 +       } else
20402 +               nid = nx_current_nid();
20403 +       return nid;
20404 +}
20405 +
20406 +
20407 +int vc_nx_info(struct nx_info *nxi, void __user *data)
20408 +{
20409 +       struct vcmd_nx_info_v0 vc_data;
20410 +
20411 +       vc_data.nid = nxi->nx_id;
20412 +
20413 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20414 +               return -EFAULT;
20415 +       return 0;
20416 +}
20417 +
20418 +
20419 +/* network functions */
20420 +
20421 +int vc_net_create(uint32_t nid, void __user *data)
20422 +{
20423 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
20424 +       struct nx_info *new_nxi;
20425 +       int ret;
20426 +
20427 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20428 +               return -EFAULT;
20429 +
20430 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
20431 +               return -EINVAL;
20432 +
20433 +       new_nxi = __create_nx_info(nid);
20434 +       if (IS_ERR(new_nxi))
20435 +               return PTR_ERR(new_nxi);
20436 +
20437 +       /* initial flags */
20438 +       new_nxi->nx_flags = vc_data.flagword;
20439 +
20440 +       ret = -ENOEXEC;
20441 +       if (vs_net_change(new_nxi, VSC_NETUP))
20442 +               goto out;
20443 +
20444 +       ret = nx_migrate_task(current, new_nxi);
20445 +       if (ret)
20446 +               goto out;
20447 +
20448 +       /* return context id on success */
20449 +       ret = new_nxi->nx_id;
20450 +
20451 +       /* get a reference for persistent contexts */
20452 +       if ((vc_data.flagword & NXF_PERSISTENT))
20453 +               nx_set_persistent(new_nxi);
20454 +out:
20455 +       release_nx_info(new_nxi, NULL);
20456 +       put_nx_info(new_nxi);
20457 +       return ret;
20458 +}
20459 +
20460 +
20461 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
20462 +{
20463 +       return nx_migrate_task(current, nxi);
20464 +}
20465 +
20466 +
20467 +static inline
20468 +struct nx_addr_v4 *__find_v4_addr(struct nx_info *nxi,
20469 +       __be32 ip, __be32 ip2, __be32 mask, uint16_t type, uint16_t flags,
20470 +       struct nx_addr_v4 **prev)
20471 +{
20472 +       struct nx_addr_v4 *nxa = &nxi->v4;
20473 +
20474 +       for (; nxa; nxa = nxa->next) {
20475 +               if ((nxa->ip[0].s_addr == ip) &&
20476 +                   (nxa->ip[1].s_addr == ip2) &&
20477 +                   (nxa->mask.s_addr == mask) &&
20478 +                   (nxa->type == type) &&
20479 +                   (nxa->flags == flags))
20480 +                   return nxa;
20481 +
20482 +               /* save previous entry */
20483 +               if (prev)
20484 +                       *prev = nxa;
20485 +       }
20486 +       return NULL;
20487 +}
20488 +
20489 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
20490 +       uint16_t type, uint16_t flags)
20491 +{
20492 +       struct nx_addr_v4 *nxa = NULL;
20493 +       struct nx_addr_v4 *new = __alloc_nx_addr_v4();
20494 +       unsigned long irqflags;
20495 +       int ret = -EEXIST;
20496 +
20497 +       if (IS_ERR(new))
20498 +               return PTR_ERR(new);
20499 +
20500 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
20501 +       if (__find_v4_addr(nxi, ip, ip2, mask, type, flags, &nxa))
20502 +               goto out_unlock;
20503 +
20504 +       if (NX_IPV4(nxi)) {
20505 +               nxa->next = new;
20506 +               nxa = new;
20507 +               new = NULL;
20508 +
20509 +               /* remove single ip for ip list */
20510 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
20511 +       }
20512 +
20513 +       nxa->ip[0].s_addr = ip;
20514 +       nxa->ip[1].s_addr = ip2;
20515 +       nxa->mask.s_addr = mask;
20516 +       nxa->type = type;
20517 +       nxa->flags = flags;
20518 +       ret = 0;
20519 +out_unlock:
20520 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20521 +       if (new)
20522 +               __dealloc_nx_addr_v4(new);
20523 +       return ret;
20524 +}
20525 +
20526 +int do_remove_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
20527 +       uint16_t type, uint16_t flags)
20528 +{
20529 +       struct nx_addr_v4 *nxa = NULL;
20530 +       struct nx_addr_v4 *old = NULL;
20531 +       unsigned long irqflags;
20532 +       int ret = 0;
20533 +
20534 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
20535 +       switch (type) {
20536 +       case NXA_TYPE_ADDR:
20537 +               old = __find_v4_addr(nxi, ip, ip2, mask, type, flags, &nxa);
20538 +               if (old) {
20539 +                       if (nxa) {
20540 +                               nxa->next = old->next;
20541 +                               old->next = NULL;
20542 +                       } else {
20543 +                               if (old->next) {
20544 +                                       nxa = old;
20545 +                                       old = old->next;
20546 +                                       *nxa = *old;
20547 +                                       old->next = NULL;
20548 +                               } else {
20549 +                                       memset(old, 0, sizeof(*old));
20550 +                                       old = NULL;
20551 +                               }
20552 +                       }
20553 +               } else
20554 +                       ret = -ESRCH;
20555 +               break;
20556 +
20557 +       case NXA_TYPE_ANY:
20558 +               nxa = &nxi->v4;
20559 +               old = nxa->next;
20560 +               memset(nxa, 0, sizeof(*nxa));
20561 +               break;
20562 +
20563 +       default:
20564 +               ret = -EINVAL;
20565 +       }
20566 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20567 +       __dealloc_nx_addr_v4_all(old);
20568 +       return ret;
20569 +}
20570 +
20571 +
20572 +int vc_net_add(struct nx_info *nxi, void __user *data)
20573 +{
20574 +       struct vcmd_net_addr_v0 vc_data;
20575 +       int index, ret = 0;
20576 +
20577 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20578 +               return -EFAULT;
20579 +
20580 +       switch (vc_data.type) {
20581 +       case NXA_TYPE_IPV4:
20582 +               if ((vc_data.count < 1) || (vc_data.count > 4))
20583 +                       return -EINVAL;
20584 +
20585 +               index = 0;
20586 +               while (index < vc_data.count) {
20587 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
20588 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
20589 +                       if (ret)
20590 +                               return ret;
20591 +                       index++;
20592 +               }
20593 +               ret = index;
20594 +               break;
20595 +
20596 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
20597 +               nxi->v4_bcast = vc_data.ip[0];
20598 +               ret = 1;
20599 +               break;
20600 +
20601 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
20602 +               nxi->v4_lback = vc_data.ip[0];
20603 +               ret = 1;
20604 +               break;
20605 +
20606 +       default:
20607 +               ret = -EINVAL;
20608 +               break;
20609 +       }
20610 +       return ret;
20611 +}
20612 +
20613 +int vc_net_remove(struct nx_info *nxi, void __user *data)
20614 +{
20615 +       struct vcmd_net_addr_v0 vc_data;
20616 +
20617 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20618 +               return -EFAULT;
20619 +
20620 +       switch (vc_data.type) {
20621 +       case NXA_TYPE_ANY:
20622 +               return do_remove_v4_addr(nxi, 0, 0, 0, vc_data.type, 0);
20623 +       default:
20624 +               return -EINVAL;
20625 +       }
20626 +       return 0;
20627 +}
20628 +
20629 +
20630 +int vc_net_add_ipv4_v1(struct nx_info *nxi, void __user *data)
20631 +{
20632 +       struct vcmd_net_addr_ipv4_v1 vc_data;
20633 +
20634 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20635 +               return -EFAULT;
20636 +
20637 +       switch (vc_data.type) {
20638 +       case NXA_TYPE_ADDR:
20639 +       case NXA_TYPE_MASK:
20640 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
20641 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20642 +
20643 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
20644 +               nxi->v4_bcast = vc_data.ip;
20645 +               break;
20646 +
20647 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
20648 +               nxi->v4_lback = vc_data.ip;
20649 +               break;
20650 +
20651 +       default:
20652 +               return -EINVAL;
20653 +       }
20654 +       return 0;
20655 +}
20656 +
20657 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
20658 +{
20659 +       struct vcmd_net_addr_ipv4_v2 vc_data;
20660 +
20661 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20662 +               return -EFAULT;
20663 +
20664 +       switch (vc_data.type) {
20665 +       case NXA_TYPE_ADDR:
20666 +       case NXA_TYPE_MASK:
20667 +       case NXA_TYPE_RANGE:
20668 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
20669 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20670 +
20671 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
20672 +               nxi->v4_bcast = vc_data.ip;
20673 +               break;
20674 +
20675 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
20676 +               nxi->v4_lback = vc_data.ip;
20677 +               break;
20678 +
20679 +       default:
20680 +               return -EINVAL;
20681 +       }
20682 +       return 0;
20683 +}
20684 +
20685 +int vc_net_rem_ipv4_v1(struct nx_info *nxi, void __user *data)
20686 +{
20687 +       struct vcmd_net_addr_ipv4_v1 vc_data;
20688 +
20689 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20690 +               return -EFAULT;
20691 +
20692 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, 0,
20693 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20694 +}
20695 +
20696 +int vc_net_rem_ipv4(struct nx_info *nxi, void __user *data)
20697 +{
20698 +       struct vcmd_net_addr_ipv4_v2 vc_data;
20699 +
20700 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20701 +               return -EFAULT;
20702 +
20703 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
20704 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20705 +}
20706 +
20707 +#ifdef CONFIG_IPV6
20708 +
20709 +static inline
20710 +struct nx_addr_v6 *__find_v6_addr(struct nx_info *nxi,
20711 +       struct in6_addr *ip, struct in6_addr *mask,
20712 +       uint32_t prefix, uint16_t type, uint16_t flags,
20713 +       struct nx_addr_v6 **prev)
20714 +{
20715 +       struct nx_addr_v6 *nxa = &nxi->v6;
20716 +
20717 +       for (; nxa; nxa = nxa->next) {
20718 +               if (ipv6_addr_equal(&nxa->ip, ip) &&
20719 +                   ipv6_addr_equal(&nxa->mask, mask) &&
20720 +                   (nxa->prefix == prefix) &&
20721 +                   (nxa->type == type) &&
20722 +                   (nxa->flags == flags))
20723 +                   return nxa;
20724 +
20725 +               /* save previous entry */
20726 +               if (prev)
20727 +                       *prev = nxa;
20728 +       }
20729 +       return NULL;
20730 +}
20731 +
20732 +
20733 +int do_add_v6_addr(struct nx_info *nxi,
20734 +       struct in6_addr *ip, struct in6_addr *mask,
20735 +       uint32_t prefix, uint16_t type, uint16_t flags)
20736 +{
20737 +       struct nx_addr_v6 *nxa = NULL;
20738 +       struct nx_addr_v6 *new = __alloc_nx_addr_v6();
20739 +       unsigned long irqflags;
20740 +       int ret = -EEXIST;
20741 +
20742 +       if (IS_ERR(new))
20743 +               return PTR_ERR(new);
20744 +
20745 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
20746 +       if (__find_v6_addr(nxi, ip, mask, prefix, type, flags, &nxa))
20747 +               goto out_unlock;
20748 +
20749 +       if (NX_IPV6(nxi)) {
20750 +               nxa->next = new;
20751 +               nxa = new;
20752 +               new = NULL;
20753 +       }
20754 +
20755 +       nxa->ip = *ip;
20756 +       nxa->mask = *mask;
20757 +       nxa->prefix = prefix;
20758 +       nxa->type = type;
20759 +       nxa->flags = flags;
20760 +       ret = 0;
20761 +out_unlock:
20762 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20763 +       if (new)
20764 +               __dealloc_nx_addr_v6(new);
20765 +       return ret;
20766 +}
20767 +
20768 +int do_remove_v6_addr(struct nx_info *nxi,
20769 +       struct in6_addr *ip, struct in6_addr *mask,
20770 +       uint32_t prefix, uint16_t type, uint16_t flags)
20771 +{
20772 +       struct nx_addr_v6 *nxa = NULL;
20773 +       struct nx_addr_v6 *old = NULL;
20774 +       unsigned long irqflags;
20775 +       int ret = 0;
20776 +
20777 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
20778 +       switch (type) {
20779 +       case NXA_TYPE_ADDR:
20780 +               old = __find_v6_addr(nxi, ip, mask, prefix, type, flags, &nxa);
20781 +               if (old) {
20782 +                       if (nxa) {
20783 +                               nxa->next = old->next;
20784 +                               old->next = NULL;
20785 +                       } else {
20786 +                               if (old->next) {
20787 +                                       nxa = old;
20788 +                                       old = old->next;
20789 +                                       *nxa = *old;
20790 +                                       old->next = NULL;
20791 +                               } else {
20792 +                                       memset(old, 0, sizeof(*old));
20793 +                                       old = NULL;
20794 +                               }
20795 +                       }
20796 +               } else
20797 +                       ret = -ESRCH;
20798 +               break;
20799 +
20800 +       case NXA_TYPE_ANY:
20801 +               nxa = &nxi->v6;
20802 +               old = nxa->next;
20803 +               memset(nxa, 0, sizeof(*nxa));
20804 +               break;
20805 +
20806 +       default:
20807 +               ret = -EINVAL;
20808 +       }
20809 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20810 +       __dealloc_nx_addr_v6_all(old);
20811 +       return ret;
20812 +}
20813 +
20814 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
20815 +{
20816 +       struct vcmd_net_addr_ipv6_v1 vc_data;
20817 +
20818 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20819 +               return -EFAULT;
20820 +
20821 +       switch (vc_data.type) {
20822 +       case NXA_TYPE_ADDR:
20823 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
20824 +               /* fallthrough */
20825 +       case NXA_TYPE_MASK:
20826 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
20827 +                       vc_data.prefix, vc_data.type, vc_data.flags);
20828 +       default:
20829 +               return -EINVAL;
20830 +       }
20831 +       return 0;
20832 +}
20833 +
20834 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
20835 +{
20836 +       struct vcmd_net_addr_ipv6_v1 vc_data;
20837 +
20838 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20839 +               return -EFAULT;
20840 +
20841 +       switch (vc_data.type) {
20842 +       case NXA_TYPE_ADDR:
20843 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
20844 +               /* fallthrough */
20845 +       case NXA_TYPE_MASK:
20846 +               return do_remove_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
20847 +                       vc_data.prefix, vc_data.type, vc_data.flags);
20848 +       case NXA_TYPE_ANY:
20849 +               return do_remove_v6_addr(nxi, NULL, NULL, 0, vc_data.type, 0);
20850 +       default:
20851 +               return -EINVAL;
20852 +       }
20853 +       return 0;
20854 +}
20855 +
20856 +#endif /* CONFIG_IPV6 */
20857 +
20858 +
20859 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
20860 +{
20861 +       struct vcmd_net_flags_v0 vc_data;
20862 +
20863 +       vc_data.flagword = nxi->nx_flags;
20864 +
20865 +       /* special STATE flag handling */
20866 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
20867 +
20868 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20869 +               return -EFAULT;
20870 +       return 0;
20871 +}
20872 +
20873 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
20874 +{
20875 +       struct vcmd_net_flags_v0 vc_data;
20876 +       uint64_t mask, trigger;
20877 +
20878 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20879 +               return -EFAULT;
20880 +
20881 +       /* special STATE flag handling */
20882 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
20883 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
20884 +
20885 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
20886 +               vc_data.flagword, mask);
20887 +       if (trigger & NXF_PERSISTENT)
20888 +               nx_update_persistent(nxi);
20889 +
20890 +       return 0;
20891 +}
20892 +
20893 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
20894 +{
20895 +       struct vcmd_net_caps_v0 vc_data;
20896 +
20897 +       vc_data.ncaps = nxi->nx_ncaps;
20898 +       vc_data.cmask = ~0ULL;
20899 +
20900 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20901 +               return -EFAULT;
20902 +       return 0;
20903 +}
20904 +
20905 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
20906 +{
20907 +       struct vcmd_net_caps_v0 vc_data;
20908 +
20909 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20910 +               return -EFAULT;
20911 +
20912 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
20913 +               vc_data.ncaps, vc_data.cmask);
20914 +       return 0;
20915 +}
20916 +
20917 +
20918 +#include <linux/module.h>
20919 +
20920 +module_init(init_network);
20921 +
20922 +EXPORT_SYMBOL_GPL(free_nx_info);
20923 +EXPORT_SYMBOL_GPL(unhash_nx_info);
20924 +
20925 diff -NurpP --minimal linux-3.9.5/kernel/vserver/proc.c linux-3.9.5-vs2.3.6.5/kernel/vserver/proc.c
20926 --- linux-3.9.5/kernel/vserver/proc.c   1970-01-01 00:00:00.000000000 +0000
20927 +++ linux-3.9.5-vs2.3.6.5/kernel/vserver/proc.c 2013-06-12 23:49:09.000000000 +0000
20928 @@ -0,0 +1,1110 @@
20929 +/*
20930 + *  linux/kernel/vserver/proc.c
20931 + *
20932 + *  Virtual Context Support
20933 + *
20934 + *  Copyright (C) 2003-2011  Herbert Pötzl
20935 + *
20936 + *  V0.01  basic structure
20937 + *  V0.02  adaptation vs1.3.0
20938 + *  V0.03  proc permissions
20939 + *  V0.04  locking/generic
20940 + *  V0.05  next generation procfs
20941 + *  V0.06  inode validation
20942 + *  V0.07  generic rewrite vid
20943 + *  V0.08  remove inode type
20944 + *  V0.09  added u/wmask info
20945 + *
20946 + */
20947 +
20948 +#include <linux/proc_fs.h>
20949 +#include <linux/fs_struct.h>
20950 +#include <linux/mount.h>
20951 +#include <linux/namei.h>
20952 +#include <asm/unistd.h>
20953 +
20954 +#include <linux/vs_context.h>
20955 +#include <linux/vs_network.h>
20956 +#include <linux/vs_cvirt.h>
20957 +
20958 +#include <linux/in.h>
20959 +#include <linux/inetdevice.h>
20960 +#include <linux/vs_inet.h>
20961 +#include <linux/vs_inet6.h>
20962 +
20963 +#include <linux/vserver/global.h>
20964 +
20965 +#include "cvirt_proc.h"
20966 +#include "cacct_proc.h"
20967 +#include "limit_proc.h"
20968 +#include "sched_proc.h"
20969 +#include "vci_config.h"
20970 +
20971 +
20972 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
20973 +{
20974 +       unsigned __capi;
20975 +
20976 +       CAP_FOR_EACH_U32(__capi) {
20977 +               buffer += sprintf(buffer, "%08x",
20978 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
20979 +       }
20980 +       return buffer;
20981 +}
20982 +
20983 +
20984 +static struct proc_dir_entry *proc_virtual;
20985 +
20986 +static struct proc_dir_entry *proc_virtnet;
20987 +
20988 +
20989 +/* first the actual feeds */
20990 +
20991 +
20992 +static int proc_vci(char *buffer)
20993 +{
20994 +       return sprintf(buffer,
20995 +               "VCIVersion:\t%04x:%04x\n"
20996 +               "VCISyscall:\t%d\n"
20997 +               "VCIKernel:\t%08x\n",
20998 +               VCI_VERSION >> 16,
20999 +               VCI_VERSION & 0xFFFF,
21000 +               __NR_vserver,
21001 +               vci_kernel_config());
21002 +}
21003 +
21004 +static int proc_virtual_info(char *buffer)
21005 +{
21006 +       return proc_vci(buffer);
21007 +}
21008 +
21009 +static int proc_virtual_status(char *buffer)
21010 +{
21011 +       return sprintf(buffer,
21012 +               "#CTotal:\t%d\n"
21013 +               "#CActive:\t%d\n"
21014 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
21015 +               "#InitTask:\t%d\t%d %d\n",
21016 +               atomic_read(&vx_global_ctotal),
21017 +               atomic_read(&vx_global_cactive),
21018 +               atomic_read(&vs_global_nsproxy),
21019 +               atomic_read(&vs_global_fs),
21020 +               atomic_read(&vs_global_mnt_ns),
21021 +               atomic_read(&vs_global_uts_ns),
21022 +               atomic_read(&nr_ipc_ns),
21023 +               atomic_read(&vs_global_user_ns),
21024 +               atomic_read(&vs_global_pid_ns),
21025 +               atomic_read(&init_task.usage),
21026 +               atomic_read(&init_task.nsproxy->count),
21027 +               init_task.fs->users);
21028 +}
21029 +
21030 +
21031 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
21032 +{
21033 +       int length;
21034 +
21035 +       length = sprintf(buffer,
21036 +               "ID:\t%d\n"
21037 +               "Info:\t%p\n"
21038 +               "Init:\t%d\n"
21039 +               "OOM:\t%lld\n",
21040 +               vxi->vx_id,
21041 +               vxi,
21042 +               vxi->vx_initpid,
21043 +               vxi->vx_badness_bias);
21044 +       return length;
21045 +}
21046 +
21047 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
21048 +{
21049 +       char *orig = buffer;
21050 +
21051 +       buffer += sprintf(buffer,
21052 +               "UseCnt:\t%d\n"
21053 +               "Tasks:\t%d\n"
21054 +               "Flags:\t%016llx\n",
21055 +               atomic_read(&vxi->vx_usecnt),
21056 +               atomic_read(&vxi->vx_tasks),
21057 +               (unsigned long long)vxi->vx_flags);
21058 +
21059 +       buffer += sprintf(buffer, "BCaps:\t");
21060 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
21061 +       buffer += sprintf(buffer, "\n");
21062 +
21063 +       buffer += sprintf(buffer,
21064 +               "CCaps:\t%016llx\n"
21065 +               "Umask:\t%16llx\n"
21066 +               "Wmask:\t%16llx\n"
21067 +               "Spaces:\t%08lx %08lx\n",
21068 +               (unsigned long long)vxi->vx_ccaps,
21069 +               (unsigned long long)vxi->vx_umask,
21070 +               (unsigned long long)vxi->vx_wmask,
21071 +               vxi->space[0].vx_nsmask, vxi->space[1].vx_nsmask);
21072 +       return buffer - orig;
21073 +}
21074 +
21075 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
21076 +{
21077 +       return vx_info_proc_limit(&vxi->limit, buffer);
21078 +}
21079 +
21080 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
21081 +{
21082 +       int cpu, length;
21083 +
21084 +       length = vx_info_proc_sched(&vxi->sched, buffer);
21085 +       for_each_online_cpu(cpu) {
21086 +               length += vx_info_proc_sched_pc(
21087 +                       &vx_per_cpu(vxi, sched_pc, cpu),
21088 +                       buffer + length, cpu);
21089 +       }
21090 +       return length;
21091 +}
21092 +
21093 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
21094 +{
21095 +       return vx_info_proc_nsproxy(vxi->space[0].vx_nsproxy, buffer);
21096 +}
21097 +
21098 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
21099 +{
21100 +       return vx_info_proc_nsproxy(vxi->space[1].vx_nsproxy, buffer);
21101 +}
21102 +
21103 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
21104 +{
21105 +       int cpu, length;
21106 +
21107 +       vx_update_load(vxi);
21108 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
21109 +       for_each_online_cpu(cpu) {
21110 +               length += vx_info_proc_cvirt_pc(
21111 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
21112 +                       buffer + length, cpu);
21113 +       }
21114 +       return length;
21115 +}
21116 +
21117 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
21118 +{
21119 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
21120 +}
21121 +
21122 +
21123 +static int proc_virtnet_info(char *buffer)
21124 +{
21125 +       return proc_vci(buffer);
21126 +}
21127 +
21128 +static int proc_virtnet_status(char *buffer)
21129 +{
21130 +       return sprintf(buffer,
21131 +               "#CTotal:\t%d\n"
21132 +               "#CActive:\t%d\n",
21133 +               atomic_read(&nx_global_ctotal),
21134 +               atomic_read(&nx_global_cactive));
21135 +}
21136 +
21137 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
21138 +{
21139 +       struct nx_addr_v4 *v4a;
21140 +#ifdef CONFIG_IPV6
21141 +       struct nx_addr_v6 *v6a;
21142 +#endif
21143 +       int length, i;
21144 +
21145 +       length = sprintf(buffer,
21146 +               "ID:\t%d\n"
21147 +               "Info:\t%p\n"
21148 +               "Bcast:\t" NIPQUAD_FMT "\n"
21149 +               "Lback:\t" NIPQUAD_FMT "\n",
21150 +               nxi->nx_id,
21151 +               nxi,
21152 +               NIPQUAD(nxi->v4_bcast.s_addr),
21153 +               NIPQUAD(nxi->v4_lback.s_addr));
21154 +
21155 +       if (!NX_IPV4(nxi))
21156 +               goto skip_v4;
21157 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
21158 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
21159 +                       i, NXAV4(v4a));
21160 +skip_v4:
21161 +#ifdef CONFIG_IPV6
21162 +       if (!NX_IPV6(nxi))
21163 +               goto skip_v6;
21164 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
21165 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
21166 +                       i, NXAV6(v6a));
21167 +skip_v6:
21168 +#endif
21169 +       return length;
21170 +}
21171 +
21172 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
21173 +{
21174 +       int length;
21175 +
21176 +       length = sprintf(buffer,
21177 +               "UseCnt:\t%d\n"
21178 +               "Tasks:\t%d\n"
21179 +               "Flags:\t%016llx\n"
21180 +               "NCaps:\t%016llx\n",
21181 +               atomic_read(&nxi->nx_usecnt),
21182 +               atomic_read(&nxi->nx_tasks),
21183 +               (unsigned long long)nxi->nx_flags,
21184 +               (unsigned long long)nxi->nx_ncaps);
21185 +       return length;
21186 +}
21187 +
21188 +
21189 +
21190 +/* here the inode helpers */
21191 +
21192 +struct vs_entry {
21193 +       int len;
21194 +       char *name;
21195 +       mode_t mode;
21196 +       struct inode_operations *iop;
21197 +       struct file_operations *fop;
21198 +       union proc_op op;
21199 +};
21200 +
21201 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
21202 +{
21203 +       struct inode *inode = new_inode(sb);
21204 +
21205 +       if (!inode)
21206 +               goto out;
21207 +
21208 +       inode->i_mode = p->mode;
21209 +       if (p->iop)
21210 +               inode->i_op = p->iop;
21211 +       if (p->fop)
21212 +               inode->i_fop = p->fop;
21213 +
21214 +       set_nlink(inode, (p->mode & S_IFDIR) ? 2 : 1);
21215 +       inode->i_flags |= S_IMMUTABLE;
21216 +
21217 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
21218 +
21219 +       i_uid_write(inode, 0);
21220 +       i_gid_write(inode, 0);
21221 +       i_tag_write(inode, 0);
21222 +out:
21223 +       return inode;
21224 +}
21225 +
21226 +static struct dentry *vs_proc_instantiate(struct inode *dir,
21227 +       struct dentry *dentry, int id, void *ptr)
21228 +{
21229 +       struct vs_entry *p = ptr;
21230 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
21231 +       struct dentry *error = ERR_PTR(-EINVAL);
21232 +
21233 +       if (!inode)
21234 +               goto out;
21235 +
21236 +       PROC_I(inode)->op = p->op;
21237 +       PROC_I(inode)->fd = id;
21238 +       d_add(dentry, inode);
21239 +       error = NULL;
21240 +out:
21241 +       return error;
21242 +}
21243 +
21244 +/* Lookups */
21245 +
21246 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
21247 +
21248 +/*
21249 + * Fill a directory entry.
21250 + *
21251 + * If possible create the dcache entry and derive our inode number and
21252 + * file type from dcache entry.
21253 + *
21254 + * Since all of the proc inode numbers are dynamically generated, the inode
21255 + * numbers do not exist until the inode is cache.  This means creating the
21256 + * the dcache entry in readdir is necessary to keep the inode numbers
21257 + * reported by readdir in sync with the inode numbers reported
21258 + * by stat.
21259 + */
21260 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
21261 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
21262 +{
21263 +       struct dentry *child, *dir = filp->f_dentry;
21264 +       struct inode *inode;
21265 +       struct qstr qname;
21266 +       ino_t ino = 0;
21267 +       unsigned type = DT_UNKNOWN;
21268 +
21269 +       qname.name = name;
21270 +       qname.len  = len;
21271 +       qname.hash = full_name_hash(name, len);
21272 +
21273 +       child = d_lookup(dir, &qname);
21274 +       if (!child) {
21275 +               struct dentry *new;
21276 +               new = d_alloc(dir, &qname);
21277 +               if (new) {
21278 +                       child = instantiate(dir->d_inode, new, id, ptr);
21279 +                       if (child)
21280 +                               dput(new);
21281 +                       else
21282 +                               child = new;
21283 +               }
21284 +       }
21285 +       if (!child || IS_ERR(child) || !child->d_inode)
21286 +               goto end_instantiate;
21287 +       inode = child->d_inode;
21288 +       if (inode) {
21289 +               ino = inode->i_ino;
21290 +               type = inode->i_mode >> 12;
21291 +       }
21292 +       dput(child);
21293 +end_instantiate:
21294 +       if (!ino)
21295 +               ino = find_inode_number(dir, &qname);
21296 +       if (!ino)
21297 +               ino = 1;
21298 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
21299 +}
21300 +
21301 +
21302 +
21303 +/* get and revalidate vx_info/xid */
21304 +
21305 +static inline
21306 +struct vx_info *get_proc_vx_info(struct inode *inode)
21307 +{
21308 +       return lookup_vx_info(PROC_I(inode)->fd);
21309 +}
21310 +
21311 +static int proc_xid_revalidate(struct dentry *dentry, unsigned int flags)
21312 +{
21313 +       struct inode *inode = dentry->d_inode;
21314 +       vxid_t xid = PROC_I(inode)->fd;
21315 +
21316 +       if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
21317 +               return -ECHILD;
21318 +
21319 +       if (!xid || xid_is_hashed(xid))
21320 +               return 1;
21321 +       d_drop(dentry);
21322 +       return 0;
21323 +}
21324 +
21325 +
21326 +/* get and revalidate nx_info/nid */
21327 +
21328 +static int proc_nid_revalidate(struct dentry *dentry, unsigned int flags)
21329 +{
21330 +       struct inode *inode = dentry->d_inode;
21331 +       vnid_t nid = PROC_I(inode)->fd;
21332 +
21333 +       if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
21334 +               return -ECHILD;
21335 +
21336 +       if (!nid || nid_is_hashed(nid))
21337 +               return 1;
21338 +       d_drop(dentry);
21339 +       return 0;
21340 +}
21341 +
21342 +
21343 +
21344 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
21345 +
21346 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
21347 +                         size_t count, loff_t *ppos)
21348 +{
21349 +       struct inode *inode = file->f_dentry->d_inode;
21350 +       unsigned long page;
21351 +       ssize_t length = 0;
21352 +
21353 +       if (count > PROC_BLOCK_SIZE)
21354 +               count = PROC_BLOCK_SIZE;
21355 +
21356 +       /* fade that out as soon as stable */
21357 +       WARN_ON(PROC_I(inode)->fd);
21358 +
21359 +       if (!(page = __get_free_page(GFP_KERNEL)))
21360 +               return -ENOMEM;
21361 +
21362 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
21363 +       length = PROC_I(inode)->op.proc_vs_read((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 +       return length;
21371 +}
21372 +
21373 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
21374 +                         size_t count, loff_t *ppos)
21375 +{
21376 +       struct inode *inode = file->f_dentry->d_inode;
21377 +       struct vx_info *vxi = NULL;
21378 +       vxid_t xid = PROC_I(inode)->fd;
21379 +       unsigned long page;
21380 +       ssize_t length = 0;
21381 +
21382 +       if (count > PROC_BLOCK_SIZE)
21383 +               count = PROC_BLOCK_SIZE;
21384 +
21385 +       /* fade that out as soon as stable */
21386 +       WARN_ON(!xid);
21387 +       vxi = lookup_vx_info(xid);
21388 +       if (!vxi)
21389 +               goto out;
21390 +
21391 +       length = -ENOMEM;
21392 +       if (!(page = __get_free_page(GFP_KERNEL)))
21393 +               goto out_put;
21394 +
21395 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
21396 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
21397 +
21398 +       if (length >= 0)
21399 +               length = simple_read_from_buffer(buf, count, ppos,
21400 +                       (char *)page, length);
21401 +
21402 +       free_page(page);
21403 +out_put:
21404 +       put_vx_info(vxi);
21405 +out:
21406 +       return length;
21407 +}
21408 +
21409 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
21410 +                         size_t count, loff_t *ppos)
21411 +{
21412 +       struct inode *inode = file->f_dentry->d_inode;
21413 +       struct nx_info *nxi = NULL;
21414 +       vnid_t nid = PROC_I(inode)->fd;
21415 +       unsigned long page;
21416 +       ssize_t length = 0;
21417 +
21418 +       if (count > PROC_BLOCK_SIZE)
21419 +               count = PROC_BLOCK_SIZE;
21420 +
21421 +       /* fade that out as soon as stable */
21422 +       WARN_ON(!nid);
21423 +       nxi = lookup_nx_info(nid);
21424 +       if (!nxi)
21425 +               goto out;
21426 +
21427 +       length = -ENOMEM;
21428 +       if (!(page = __get_free_page(GFP_KERNEL)))
21429 +               goto out_put;
21430 +
21431 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
21432 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
21433 +
21434 +       if (length >= 0)
21435 +               length = simple_read_from_buffer(buf, count, ppos,
21436 +                       (char *)page, length);
21437 +
21438 +       free_page(page);
21439 +out_put:
21440 +       put_nx_info(nxi);
21441 +out:
21442 +       return length;
21443 +}
21444 +
21445 +
21446 +
21447 +/* here comes the lower level */
21448 +
21449 +
21450 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
21451 +       .len  = sizeof(NAME) - 1,       \
21452 +       .name = (NAME),                 \
21453 +       .mode = MODE,                   \
21454 +       .iop  = IOP,                    \
21455 +       .fop  = FOP,                    \
21456 +       .op   = OP,                     \
21457 +}
21458 +
21459 +
21460 +#define DIR(NAME, MODE, OTYPE)                         \
21461 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
21462 +               &proc_ ## OTYPE ## _inode_operations,   \
21463 +               &proc_ ## OTYPE ## _file_operations, { } )
21464 +
21465 +#define INF(NAME, MODE, OTYPE)                         \
21466 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21467 +               &proc_vs_info_file_operations,          \
21468 +               { .proc_vs_read = &proc_##OTYPE } )
21469 +
21470 +#define VINF(NAME, MODE, OTYPE)                                \
21471 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21472 +               &proc_vx_info_file_operations,          \
21473 +               { .proc_vxi_read = &proc_##OTYPE } )
21474 +
21475 +#define NINF(NAME, MODE, OTYPE)                                \
21476 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21477 +               &proc_nx_info_file_operations,          \
21478 +               { .proc_nxi_read = &proc_##OTYPE } )
21479 +
21480 +
21481 +static struct file_operations proc_vs_info_file_operations = {
21482 +       .read =         proc_vs_info_read,
21483 +};
21484 +
21485 +static struct file_operations proc_vx_info_file_operations = {
21486 +       .read =         proc_vx_info_read,
21487 +};
21488 +
21489 +static struct dentry_operations proc_xid_dentry_operations = {
21490 +       .d_revalidate = proc_xid_revalidate,
21491 +};
21492 +
21493 +static struct vs_entry vx_base_stuff[] = {
21494 +       VINF("info",    S_IRUGO, vxi_info),
21495 +       VINF("status",  S_IRUGO, vxi_status),
21496 +       VINF("limit",   S_IRUGO, vxi_limit),
21497 +       VINF("sched",   S_IRUGO, vxi_sched),
21498 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
21499 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
21500 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
21501 +       VINF("cacct",   S_IRUGO, vxi_cacct),
21502 +       {}
21503 +};
21504 +
21505 +
21506 +
21507 +
21508 +static struct dentry *proc_xid_instantiate(struct inode *dir,
21509 +       struct dentry *dentry, int id, void *ptr)
21510 +{
21511 +       dentry->d_op = &proc_xid_dentry_operations;
21512 +       return vs_proc_instantiate(dir, dentry, id, ptr);
21513 +}
21514 +
21515 +static struct dentry *proc_xid_lookup(struct inode *dir,
21516 +       struct dentry *dentry, unsigned int flags)
21517 +{
21518 +       struct vs_entry *p = vx_base_stuff;
21519 +       struct dentry *error = ERR_PTR(-ENOENT);
21520 +
21521 +       for (; p->name; p++) {
21522 +               if (p->len != dentry->d_name.len)
21523 +                       continue;
21524 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21525 +                       break;
21526 +       }
21527 +       if (!p->name)
21528 +               goto out;
21529 +
21530 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
21531 +out:
21532 +       return error;
21533 +}
21534 +
21535 +static int proc_xid_readdir(struct file *filp,
21536 +       void *dirent, filldir_t filldir)
21537 +{
21538 +       struct dentry *dentry = filp->f_dentry;
21539 +       struct inode *inode = dentry->d_inode;
21540 +       struct vs_entry *p = vx_base_stuff;
21541 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
21542 +       int pos, index;
21543 +       u64 ino;
21544 +
21545 +       pos = filp->f_pos;
21546 +       switch (pos) {
21547 +       case 0:
21548 +               ino = inode->i_ino;
21549 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21550 +                       goto out;
21551 +               pos++;
21552 +               /* fall through */
21553 +       case 1:
21554 +               ino = parent_ino(dentry);
21555 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21556 +                       goto out;
21557 +               pos++;
21558 +               /* fall through */
21559 +       default:
21560 +               index = pos - 2;
21561 +               if (index >= size)
21562 +                       goto out;
21563 +               for (p += index; p->name; p++) {
21564 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21565 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
21566 +                               goto out;
21567 +                       pos++;
21568 +               }
21569 +       }
21570 +out:
21571 +       filp->f_pos = pos;
21572 +       return 1;
21573 +}
21574 +
21575 +
21576 +
21577 +static struct file_operations proc_nx_info_file_operations = {
21578 +       .read =         proc_nx_info_read,
21579 +};
21580 +
21581 +static struct dentry_operations proc_nid_dentry_operations = {
21582 +       .d_revalidate = proc_nid_revalidate,
21583 +};
21584 +
21585 +static struct vs_entry nx_base_stuff[] = {
21586 +       NINF("info",    S_IRUGO, nxi_info),
21587 +       NINF("status",  S_IRUGO, nxi_status),
21588 +       {}
21589 +};
21590 +
21591 +
21592 +static struct dentry *proc_nid_instantiate(struct inode *dir,
21593 +       struct dentry *dentry, int id, void *ptr)
21594 +{
21595 +       dentry->d_op = &proc_nid_dentry_operations;
21596 +       return vs_proc_instantiate(dir, dentry, id, ptr);
21597 +}
21598 +
21599 +static struct dentry *proc_nid_lookup(struct inode *dir,
21600 +       struct dentry *dentry, unsigned int flags)
21601 +{
21602 +       struct vs_entry *p = nx_base_stuff;
21603 +       struct dentry *error = ERR_PTR(-ENOENT);
21604 +
21605 +       for (; p->name; p++) {
21606 +               if (p->len != dentry->d_name.len)
21607 +                       continue;
21608 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21609 +                       break;
21610 +       }
21611 +       if (!p->name)
21612 +               goto out;
21613 +
21614 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
21615 +out:
21616 +       return error;
21617 +}
21618 +
21619 +static int proc_nid_readdir(struct file *filp,
21620 +       void *dirent, filldir_t filldir)
21621 +{
21622 +       struct dentry *dentry = filp->f_dentry;
21623 +       struct inode *inode = dentry->d_inode;
21624 +       struct vs_entry *p = nx_base_stuff;
21625 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
21626 +       int pos, index;
21627 +       u64 ino;
21628 +
21629 +       pos = filp->f_pos;
21630 +       switch (pos) {
21631 +       case 0:
21632 +               ino = inode->i_ino;
21633 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21634 +                       goto out;
21635 +               pos++;
21636 +               /* fall through */
21637 +       case 1:
21638 +               ino = parent_ino(dentry);
21639 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21640 +                       goto out;
21641 +               pos++;
21642 +               /* fall through */
21643 +       default:
21644 +               index = pos - 2;
21645 +               if (index >= size)
21646 +                       goto out;
21647 +               for (p += index; p->name; p++) {
21648 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21649 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
21650 +                               goto out;
21651 +                       pos++;
21652 +               }
21653 +       }
21654 +out:
21655 +       filp->f_pos = pos;
21656 +       return 1;
21657 +}
21658 +
21659 +
21660 +#define MAX_MULBY10    ((~0U - 9) / 10)
21661 +
21662 +static inline int atovid(const char *str, int len)
21663 +{
21664 +       int vid, c;
21665 +
21666 +       vid = 0;
21667 +       while (len-- > 0) {
21668 +               c = *str - '0';
21669 +               str++;
21670 +               if (c > 9)
21671 +                       return -1;
21672 +               if (vid >= MAX_MULBY10)
21673 +                       return -1;
21674 +               vid *= 10;
21675 +               vid += c;
21676 +               if (!vid)
21677 +                       return -1;
21678 +       }
21679 +       return vid;
21680 +}
21681 +
21682 +/* now the upper level (virtual) */
21683 +
21684 +
21685 +static struct file_operations proc_xid_file_operations = {
21686 +       .read =         generic_read_dir,
21687 +       .readdir =      proc_xid_readdir,
21688 +};
21689 +
21690 +static struct inode_operations proc_xid_inode_operations = {
21691 +       .lookup =       proc_xid_lookup,
21692 +};
21693 +
21694 +static struct vs_entry vx_virtual_stuff[] = {
21695 +       INF("info",     S_IRUGO, virtual_info),
21696 +       INF("status",   S_IRUGO, virtual_status),
21697 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
21698 +};
21699 +
21700 +
21701 +static struct dentry *proc_virtual_lookup(struct inode *dir,
21702 +       struct dentry *dentry, unsigned int flags)
21703 +{
21704 +       struct vs_entry *p = vx_virtual_stuff;
21705 +       struct dentry *error = ERR_PTR(-ENOENT);
21706 +       int id = 0;
21707 +
21708 +       for (; p->name; p++) {
21709 +               if (p->len != dentry->d_name.len)
21710 +                       continue;
21711 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21712 +                       break;
21713 +       }
21714 +       if (p->name)
21715 +               goto instantiate;
21716 +
21717 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
21718 +       if ((id < 0) || !xid_is_hashed(id))
21719 +               goto out;
21720 +
21721 +instantiate:
21722 +       error = proc_xid_instantiate(dir, dentry, id, p);
21723 +out:
21724 +       return error;
21725 +}
21726 +
21727 +static struct file_operations proc_nid_file_operations = {
21728 +       .read =         generic_read_dir,
21729 +       .readdir =      proc_nid_readdir,
21730 +};
21731 +
21732 +static struct inode_operations proc_nid_inode_operations = {
21733 +       .lookup =       proc_nid_lookup,
21734 +};
21735 +
21736 +static struct vs_entry nx_virtnet_stuff[] = {
21737 +       INF("info",     S_IRUGO, virtnet_info),
21738 +       INF("status",   S_IRUGO, virtnet_status),
21739 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
21740 +};
21741 +
21742 +
21743 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
21744 +       struct dentry *dentry, unsigned int flags)
21745 +{
21746 +       struct vs_entry *p = nx_virtnet_stuff;
21747 +       struct dentry *error = ERR_PTR(-ENOENT);
21748 +       int id = 0;
21749 +
21750 +       for (; p->name; p++) {
21751 +               if (p->len != dentry->d_name.len)
21752 +                       continue;
21753 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21754 +                       break;
21755 +       }
21756 +       if (p->name)
21757 +               goto instantiate;
21758 +
21759 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
21760 +       if ((id < 0) || !nid_is_hashed(id))
21761 +               goto out;
21762 +
21763 +instantiate:
21764 +       error = proc_nid_instantiate(dir, dentry, id, p);
21765 +out:
21766 +       return error;
21767 +}
21768 +
21769 +
21770 +#define PROC_MAXVIDS 32
21771 +
21772 +int proc_virtual_readdir(struct file *filp,
21773 +       void *dirent, filldir_t filldir)
21774 +{
21775 +       struct dentry *dentry = filp->f_dentry;
21776 +       struct inode *inode = dentry->d_inode;
21777 +       struct vs_entry *p = vx_virtual_stuff;
21778 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
21779 +       int pos, index;
21780 +       unsigned int xid_array[PROC_MAXVIDS];
21781 +       char buf[PROC_NUMBUF];
21782 +       unsigned int nr_xids, i;
21783 +       u64 ino;
21784 +
21785 +       pos = filp->f_pos;
21786 +       switch (pos) {
21787 +       case 0:
21788 +               ino = inode->i_ino;
21789 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21790 +                       goto out;
21791 +               pos++;
21792 +               /* fall through */
21793 +       case 1:
21794 +               ino = parent_ino(dentry);
21795 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21796 +                       goto out;
21797 +               pos++;
21798 +               /* fall through */
21799 +       default:
21800 +               index = pos - 2;
21801 +               if (index >= size)
21802 +                       goto entries;
21803 +               for (p += index; p->name; p++) {
21804 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21805 +                               vs_proc_instantiate, 0, p))
21806 +                               goto out;
21807 +                       pos++;
21808 +               }
21809 +       entries:
21810 +               index = pos - size;
21811 +               p = &vx_virtual_stuff[size - 1];
21812 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
21813 +               for (i = 0; i < nr_xids; i++) {
21814 +                       int n, xid = xid_array[i];
21815 +                       unsigned int j = PROC_NUMBUF;
21816 +
21817 +                       n = xid;
21818 +                       do
21819 +                               buf[--j] = '0' + (n % 10);
21820 +                       while (n /= 10);
21821 +
21822 +                       if (proc_fill_cache(filp, dirent, filldir,
21823 +                               buf + j, PROC_NUMBUF - j,
21824 +                               vs_proc_instantiate, xid, p))
21825 +                               goto out;
21826 +                       pos++;
21827 +               }
21828 +       }
21829 +out:
21830 +       filp->f_pos = pos;
21831 +       return 0;
21832 +}
21833 +
21834 +static int proc_virtual_getattr(struct vfsmount *mnt,
21835 +       struct dentry *dentry, struct kstat *stat)
21836 +{
21837 +       struct inode *inode = dentry->d_inode;
21838 +
21839 +       generic_fillattr(inode, stat);
21840 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
21841 +       return 0;
21842 +}
21843 +
21844 +static struct file_operations proc_virtual_dir_operations = {
21845 +       .read =         generic_read_dir,
21846 +       .readdir =      proc_virtual_readdir,
21847 +};
21848 +
21849 +static struct inode_operations proc_virtual_dir_inode_operations = {
21850 +       .getattr =      proc_virtual_getattr,
21851 +       .lookup =       proc_virtual_lookup,
21852 +};
21853 +
21854 +
21855 +
21856 +
21857 +
21858 +int proc_virtnet_readdir(struct file *filp,
21859 +       void *dirent, filldir_t filldir)
21860 +{
21861 +       struct dentry *dentry = filp->f_dentry;
21862 +       struct inode *inode = dentry->d_inode;
21863 +       struct vs_entry *p = nx_virtnet_stuff;
21864 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
21865 +       int pos, index;
21866 +       unsigned int nid_array[PROC_MAXVIDS];
21867 +       char buf[PROC_NUMBUF];
21868 +       unsigned int nr_nids, i;
21869 +       u64 ino;
21870 +
21871 +       pos = filp->f_pos;
21872 +       switch (pos) {
21873 +       case 0:
21874 +               ino = inode->i_ino;
21875 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21876 +                       goto out;
21877 +               pos++;
21878 +               /* fall through */
21879 +       case 1:
21880 +               ino = parent_ino(dentry);
21881 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21882 +                       goto out;
21883 +               pos++;
21884 +               /* fall through */
21885 +       default:
21886 +               index = pos - 2;
21887 +               if (index >= size)
21888 +                       goto entries;
21889 +               for (p += index; p->name; p++) {
21890 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21891 +                               vs_proc_instantiate, 0, p))
21892 +                               goto out;
21893 +                       pos++;
21894 +               }
21895 +       entries:
21896 +               index = pos - size;
21897 +               p = &nx_virtnet_stuff[size - 1];
21898 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
21899 +               for (i = 0; i < nr_nids; i++) {
21900 +                       int n, nid = nid_array[i];
21901 +                       unsigned int j = PROC_NUMBUF;
21902 +
21903 +                       n = nid;
21904 +                       do
21905 +                               buf[--j] = '0' + (n % 10);
21906 +                       while (n /= 10);
21907 +
21908 +                       if (proc_fill_cache(filp, dirent, filldir,
21909 +                               buf + j, PROC_NUMBUF - j,
21910 +                               vs_proc_instantiate, nid, p))
21911 +                               goto out;
21912 +                       pos++;
21913 +               }
21914 +       }
21915 +out:
21916 +       filp->f_pos = pos;
21917 +       return 0;
21918 +}
21919 +
21920 +static int proc_virtnet_getattr(struct vfsmount *mnt,
21921 +       struct dentry *dentry, struct kstat *stat)
21922 +{
21923 +       struct inode *inode = dentry->d_inode;
21924 +
21925 +       generic_fillattr(inode, stat);
21926 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
21927 +       return 0;
21928 +}
21929 +
21930 +static struct file_operations proc_virtnet_dir_operations = {
21931 +       .read =         generic_read_dir,
21932 +       .readdir =      proc_virtnet_readdir,
21933 +};
21934 +
21935 +static struct inode_operations proc_virtnet_dir_inode_operations = {
21936 +       .getattr =      proc_virtnet_getattr,
21937 +       .lookup =       proc_virtnet_lookup,
21938 +};
21939 +
21940 +
21941 +
21942 +void proc_vx_init(void)
21943 +{
21944 +       struct proc_dir_entry *ent;
21945 +
21946 +       ent = proc_mkdir("virtual", 0);
21947 +       if (ent) {
21948 +               ent->proc_fops = &proc_virtual_dir_operations;
21949 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
21950 +       }
21951 +       proc_virtual = ent;
21952 +
21953 +       ent = proc_mkdir("virtnet", 0);
21954 +       if (ent) {
21955 +               ent->proc_fops = &proc_virtnet_dir_operations;
21956 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
21957 +       }
21958 +       proc_virtnet = ent;
21959 +}
21960 +
21961 +
21962 +
21963 +
21964 +/* per pid info */
21965 +
21966 +
21967 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
21968 +{
21969 +       struct vx_info *vxi;
21970 +       char *orig = buffer;
21971 +
21972 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
21973 +
21974 +       vxi = task_get_vx_info(p);
21975 +       if (!vxi)
21976 +               goto out;
21977 +
21978 +       buffer += sprintf(buffer, "BCaps:\t");
21979 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
21980 +       buffer += sprintf(buffer, "\n");
21981 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
21982 +               (unsigned long long)vxi->vx_ccaps);
21983 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
21984 +               (unsigned long long)vxi->vx_flags);
21985 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
21986 +
21987 +       put_vx_info(vxi);
21988 +out:
21989 +       return buffer - orig;
21990 +}
21991 +
21992 +
21993 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
21994 +{
21995 +       struct nx_info *nxi;
21996 +       struct nx_addr_v4 *v4a;
21997 +#ifdef CONFIG_IPV6
21998 +       struct nx_addr_v6 *v6a;
21999 +#endif
22000 +       char *orig = buffer;
22001 +       int i;
22002 +
22003 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
22004 +
22005 +       nxi = task_get_nx_info(p);
22006 +       if (!nxi)
22007 +               goto out;
22008 +
22009 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
22010 +               (unsigned long long)nxi->nx_ncaps);
22011 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
22012 +               (unsigned long long)nxi->nx_flags);
22013 +
22014 +       buffer += sprintf(buffer,
22015 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
22016 +               NIPQUAD(nxi->v4_bcast.s_addr));
22017 +       buffer += sprintf (buffer,
22018 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
22019 +               NIPQUAD(nxi->v4_lback.s_addr));
22020 +       if (!NX_IPV4(nxi))
22021 +               goto skip_v4;
22022 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
22023 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
22024 +                       i, NXAV4(v4a));
22025 +skip_v4:
22026 +#ifdef CONFIG_IPV6
22027 +       if (!NX_IPV6(nxi))
22028 +               goto skip_v6;
22029 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
22030 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
22031 +                       i, NXAV6(v6a));
22032 +skip_v6:
22033 +#endif
22034 +       put_nx_info(nxi);
22035 +out:
22036 +       return buffer - orig;
22037 +}
22038 +
22039 diff -NurpP --minimal linux-3.9.5/kernel/vserver/sched.c linux-3.9.5-vs2.3.6.5/kernel/vserver/sched.c
22040 --- linux-3.9.5/kernel/vserver/sched.c  1970-01-01 00:00:00.000000000 +0000
22041 +++ linux-3.9.5-vs2.3.6.5/kernel/vserver/sched.c        2013-05-31 14:47:11.000000000 +0000
22042 @@ -0,0 +1,83 @@
22043 +/*
22044 + *  linux/kernel/vserver/sched.c
22045 + *
22046 + *  Virtual Server: Scheduler Support
22047 + *
22048 + *  Copyright (C) 2004-2010  Herbert Pötzl
22049 + *
22050 + *  V0.01  adapted Sam Vilains version to 2.6.3
22051 + *  V0.02  removed legacy interface
22052 + *  V0.03  changed vcmds to vxi arg
22053 + *  V0.04  removed older and legacy interfaces
22054 + *  V0.05  removed scheduler code/commands
22055 + *
22056 + */
22057 +
22058 +#include <linux/vs_context.h>
22059 +#include <linux/vs_sched.h>
22060 +#include <linux/cpumask.h>
22061 +#include <linux/vserver/sched_cmd.h>
22062 +
22063 +#include <asm/uaccess.h>
22064 +
22065 +
22066 +void vx_update_sched_param(struct _vx_sched *sched,
22067 +       struct _vx_sched_pc *sched_pc)
22068 +{
22069 +       sched_pc->prio_bias = sched->prio_bias;
22070 +}
22071 +
22072 +static int do_set_prio_bias(struct vx_info *vxi, struct vcmd_prio_bias *data)
22073 +{
22074 +       int cpu;
22075 +
22076 +       if (data->prio_bias > MAX_PRIO_BIAS)
22077 +               data->prio_bias = MAX_PRIO_BIAS;
22078 +       if (data->prio_bias < MIN_PRIO_BIAS)
22079 +               data->prio_bias = MIN_PRIO_BIAS;
22080 +
22081 +       if (data->cpu_id != ~0) {
22082 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
22083 +               cpumask_and(&vxi->sched.update, &vxi->sched.update,
22084 +                       cpu_online_mask);
22085 +       } else
22086 +               cpumask_copy(&vxi->sched.update, cpu_online_mask);
22087 +
22088 +       for_each_cpu_mask(cpu, vxi->sched.update)
22089 +               vx_update_sched_param(&vxi->sched,
22090 +                       &vx_per_cpu(vxi, sched_pc, cpu));
22091 +       return 0;
22092 +}
22093 +
22094 +int vc_set_prio_bias(struct vx_info *vxi, void __user *data)
22095 +{
22096 +       struct vcmd_prio_bias vc_data;
22097 +
22098 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22099 +               return -EFAULT;
22100 +
22101 +       return do_set_prio_bias(vxi, &vc_data);
22102 +}
22103 +
22104 +int vc_get_prio_bias(struct vx_info *vxi, void __user *data)
22105 +{
22106 +       struct vcmd_prio_bias vc_data;
22107 +       struct _vx_sched_pc *pcd;
22108 +       int cpu;
22109 +
22110 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22111 +               return -EFAULT;
22112 +
22113 +       cpu = vc_data.cpu_id;
22114 +
22115 +       if (!cpu_possible(cpu))
22116 +               return -EINVAL;
22117 +
22118 +       pcd = &vx_per_cpu(vxi, sched_pc, cpu);
22119 +       vc_data.prio_bias = pcd->prio_bias;
22120 +
22121 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22122 +               return -EFAULT;
22123 +       return 0;
22124 +}
22125 +
22126 diff -NurpP --minimal linux-3.9.5/kernel/vserver/sched_init.h linux-3.9.5-vs2.3.6.5/kernel/vserver/sched_init.h
22127 --- linux-3.9.5/kernel/vserver/sched_init.h     1970-01-01 00:00:00.000000000 +0000
22128 +++ linux-3.9.5-vs2.3.6.5/kernel/vserver/sched_init.h   2013-05-31 14:47:11.000000000 +0000
22129 @@ -0,0 +1,27 @@
22130 +
22131 +static inline void vx_info_init_sched(struct _vx_sched *sched)
22132 +{
22133 +       /* scheduling; hard code starting values as constants */
22134 +       sched->prio_bias = 0;
22135 +}
22136 +
22137 +static inline
22138 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22139 +{
22140 +       sched_pc->prio_bias = 0;
22141 +
22142 +       sched_pc->user_ticks = 0;
22143 +       sched_pc->sys_ticks = 0;
22144 +       sched_pc->hold_ticks = 0;
22145 +}
22146 +
22147 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
22148 +{
22149 +       return;
22150 +}
22151 +
22152 +static inline
22153 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22154 +{
22155 +       return;
22156 +}
22157 diff -NurpP --minimal linux-3.9.5/kernel/vserver/sched_proc.h linux-3.9.5-vs2.3.6.5/kernel/vserver/sched_proc.h
22158 --- linux-3.9.5/kernel/vserver/sched_proc.h     1970-01-01 00:00:00.000000000 +0000
22159 +++ linux-3.9.5-vs2.3.6.5/kernel/vserver/sched_proc.h   2013-05-31 14:47:11.000000000 +0000
22160 @@ -0,0 +1,32 @@
22161 +#ifndef _VX_SCHED_PROC_H
22162 +#define _VX_SCHED_PROC_H
22163 +
22164 +
22165 +static inline
22166 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
22167 +{
22168 +       int length = 0;
22169 +
22170 +       length += sprintf(buffer,
22171 +               "PrioBias:\t%8d\n",
22172 +               sched->prio_bias);
22173 +       return length;
22174 +}
22175 +
22176 +static inline
22177 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
22178 +       char *buffer, int cpu)
22179 +{
22180 +       int length = 0;
22181 +
22182 +       length += sprintf(buffer + length,
22183 +               "cpu %d: %lld %lld %lld", cpu,
22184 +               (unsigned long long)sched_pc->user_ticks,
22185 +               (unsigned long long)sched_pc->sys_ticks,
22186 +               (unsigned long long)sched_pc->hold_ticks);
22187 +       length += sprintf(buffer + length,
22188 +               " %d\n", sched_pc->prio_bias);
22189 +       return length;
22190 +}
22191 +
22192 +#endif /* _VX_SCHED_PROC_H */
22193 diff -NurpP --minimal linux-3.9.5/kernel/vserver/signal.c linux-3.9.5-vs2.3.6.5/kernel/vserver/signal.c
22194 --- linux-3.9.5/kernel/vserver/signal.c 1970-01-01 00:00:00.000000000 +0000
22195 +++ linux-3.9.5-vs2.3.6.5/kernel/vserver/signal.c       2013-05-31 14:47:11.000000000 +0000
22196 @@ -0,0 +1,134 @@
22197 +/*
22198 + *  linux/kernel/vserver/signal.c
22199 + *
22200 + *  Virtual Server: Signal Support
22201 + *
22202 + *  Copyright (C) 2003-2007  Herbert Pötzl
22203 + *
22204 + *  V0.01  broken out from vcontext V0.05
22205 + *  V0.02  changed vcmds to vxi arg
22206 + *  V0.03  adjusted siginfo for kill
22207 + *
22208 + */
22209 +
22210 +#include <asm/uaccess.h>
22211 +
22212 +#include <linux/vs_context.h>
22213 +#include <linux/vs_pid.h>
22214 +#include <linux/vserver/signal_cmd.h>
22215 +
22216 +
22217 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
22218 +{
22219 +       int retval, count = 0;
22220 +       struct task_struct *p;
22221 +       struct siginfo *sip = SEND_SIG_PRIV;
22222 +
22223 +       retval = -ESRCH;
22224 +       vxdprintk(VXD_CBIT(misc, 4),
22225 +               "vx_info_kill(%p[#%d],%d,%d)*",
22226 +               vxi, vxi->vx_id, pid, sig);
22227 +       read_lock(&tasklist_lock);
22228 +       switch (pid) {
22229 +       case  0:
22230 +       case -1:
22231 +               for_each_process(p) {
22232 +                       int err = 0;
22233 +
22234 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
22235 +                               (pid && vxi->vx_initpid == p->pid))
22236 +                               continue;
22237 +
22238 +                       err = group_send_sig_info(sig, sip, p);
22239 +                       ++count;
22240 +                       if (err != -EPERM)
22241 +                               retval = err;
22242 +               }
22243 +               break;
22244 +
22245 +       case 1:
22246 +               if (vxi->vx_initpid) {
22247 +                       pid = vxi->vx_initpid;
22248 +                       /* for now, only SIGINT to private init ... */
22249 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22250 +                               /* ... as long as there are tasks left */
22251 +                               (atomic_read(&vxi->vx_tasks) > 1))
22252 +                               sig = SIGINT;
22253 +               }
22254 +               /* fallthrough */
22255 +       default:
22256 +               rcu_read_lock();
22257 +               p = find_task_by_real_pid(pid);
22258 +               rcu_read_unlock();
22259 +               if (p) {
22260 +                       if (vx_task_xid(p) == vxi->vx_id)
22261 +                               retval = group_send_sig_info(sig, sip, p);
22262 +               }
22263 +               break;
22264 +       }
22265 +       read_unlock(&tasklist_lock);
22266 +       vxdprintk(VXD_CBIT(misc, 4),
22267 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
22268 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
22269 +       return retval;
22270 +}
22271 +
22272 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
22273 +{
22274 +       struct vcmd_ctx_kill_v0 vc_data;
22275 +
22276 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22277 +               return -EFAULT;
22278 +
22279 +       /* special check to allow guest shutdown */
22280 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22281 +               /* forbid killall pid=0 when init is present */
22282 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
22283 +               (vc_data.pid > 1)))
22284 +               return -EACCES;
22285 +
22286 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
22287 +}
22288 +
22289 +
22290 +static int __wait_exit(struct vx_info *vxi)
22291 +{
22292 +       DECLARE_WAITQUEUE(wait, current);
22293 +       int ret = 0;
22294 +
22295 +       add_wait_queue(&vxi->vx_wait, &wait);
22296 +       set_current_state(TASK_INTERRUPTIBLE);
22297 +
22298 +wait:
22299 +       if (vx_info_state(vxi,
22300 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
22301 +               goto out;
22302 +       if (signal_pending(current)) {
22303 +               ret = -ERESTARTSYS;
22304 +               goto out;
22305 +       }
22306 +       schedule();
22307 +       goto wait;
22308 +
22309 +out:
22310 +       set_current_state(TASK_RUNNING);
22311 +       remove_wait_queue(&vxi->vx_wait, &wait);
22312 +       return ret;
22313 +}
22314 +
22315 +
22316 +
22317 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
22318 +{
22319 +       struct vcmd_wait_exit_v0 vc_data;
22320 +       int ret;
22321 +
22322 +       ret = __wait_exit(vxi);
22323 +       vc_data.reboot_cmd = vxi->reboot_cmd;
22324 +       vc_data.exit_code = vxi->exit_code;
22325 +
22326 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22327 +               ret = -EFAULT;
22328 +       return ret;
22329 +}
22330 +
22331 diff -NurpP --minimal linux-3.9.5/kernel/vserver/space.c linux-3.9.5-vs2.3.6.5/kernel/vserver/space.c
22332 --- linux-3.9.5/kernel/vserver/space.c  1970-01-01 00:00:00.000000000 +0000
22333 +++ linux-3.9.5-vs2.3.6.5/kernel/vserver/space.c        2013-05-31 14:47:11.000000000 +0000
22334 @@ -0,0 +1,436 @@
22335 +/*
22336 + *  linux/kernel/vserver/space.c
22337 + *
22338 + *  Virtual Server: Context Space Support
22339 + *
22340 + *  Copyright (C) 2003-2010  Herbert Pötzl
22341 + *
22342 + *  V0.01  broken out from context.c 0.07
22343 + *  V0.02  added task locking for namespace
22344 + *  V0.03  broken out vx_enter_namespace
22345 + *  V0.04  added *space support and commands
22346 + *  V0.05  added credential support
22347 + *
22348 + */
22349 +
22350 +#include <linux/utsname.h>
22351 +#include <linux/nsproxy.h>
22352 +#include <linux/err.h>
22353 +#include <linux/fs_struct.h>
22354 +#include <linux/cred.h>
22355 +#include <asm/uaccess.h>
22356 +
22357 +#include <linux/vs_context.h>
22358 +#include <linux/vserver/space.h>
22359 +#include <linux/vserver/space_cmd.h>
22360 +
22361 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
22362 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
22363 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
22364 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
22365 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
22366 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
22367 +
22368 +
22369 +/* namespace functions */
22370 +
22371 +#include <linux/mnt_namespace.h>
22372 +#include <linux/user_namespace.h>
22373 +#include <linux/pid_namespace.h>
22374 +#include <linux/ipc_namespace.h>
22375 +#include <net/net_namespace.h>
22376 +#include "../fs/mount.h"
22377 +
22378 +
22379 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
22380 +       .mask = CLONE_FS |
22381 +               CLONE_NEWNS |
22382 +#ifdef CONFIG_UTS_NS
22383 +               CLONE_NEWUTS |
22384 +#endif
22385 +#ifdef CONFIG_IPC_NS
22386 +               CLONE_NEWIPC |
22387 +#endif
22388 +#ifdef CONFIG_USER_NS
22389 +               CLONE_NEWUSER |
22390 +#endif
22391 +               0
22392 +};
22393 +
22394 +static const struct vcmd_space_mask_v1 space_mask = {
22395 +       .mask = CLONE_FS |
22396 +               CLONE_NEWNS |
22397 +#ifdef CONFIG_UTS_NS
22398 +               CLONE_NEWUTS |
22399 +#endif
22400 +#ifdef CONFIG_IPC_NS
22401 +               CLONE_NEWIPC |
22402 +#endif
22403 +#ifdef CONFIG_USER_NS
22404 +               CLONE_NEWUSER |
22405 +#endif
22406 +#ifdef CONFIG_PID_NS
22407 +               CLONE_NEWPID |
22408 +#endif
22409 +#ifdef CONFIG_NET_NS
22410 +               CLONE_NEWNET |
22411 +#endif
22412 +               0
22413 +};
22414 +
22415 +static const struct vcmd_space_mask_v1 default_space_mask = {
22416 +       .mask = CLONE_FS |
22417 +               CLONE_NEWNS |
22418 +#ifdef CONFIG_UTS_NS
22419 +               CLONE_NEWUTS |
22420 +#endif
22421 +#ifdef CONFIG_IPC_NS
22422 +               CLONE_NEWIPC |
22423 +#endif
22424 +#ifdef CONFIG_USER_NS
22425 +               CLONE_NEWUSER |
22426 +#endif
22427 +#ifdef CONFIG_PID_NS
22428 +//             CLONE_NEWPID |
22429 +#endif
22430 +               0
22431 +};
22432 +
22433 +/*
22434 + *     build a new nsproxy mix
22435 + *      assumes that both proxies are 'const'
22436 + *     does not touch nsproxy refcounts
22437 + *     will hold a reference on the result.
22438 + */
22439 +
22440 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
22441 +       struct nsproxy *new_nsproxy, unsigned long mask)
22442 +{
22443 +       struct mnt_namespace *old_ns;
22444 +       struct uts_namespace *old_uts;
22445 +       struct ipc_namespace *old_ipc;
22446 +#ifdef CONFIG_PID_NS
22447 +       struct pid_namespace *old_pid;
22448 +#endif
22449 +#ifdef CONFIG_NET_NS
22450 +       struct net *old_net;
22451 +#endif
22452 +       struct nsproxy *nsproxy;
22453 +
22454 +       nsproxy = copy_nsproxy(old_nsproxy);
22455 +       if (!nsproxy)
22456 +               goto out;
22457 +
22458 +       if (mask & CLONE_NEWNS) {
22459 +               old_ns = nsproxy->mnt_ns;
22460 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
22461 +               if (nsproxy->mnt_ns)
22462 +                       get_mnt_ns(nsproxy->mnt_ns);
22463 +       } else
22464 +               old_ns = NULL;
22465 +
22466 +       if (mask & CLONE_NEWUTS) {
22467 +               old_uts = nsproxy->uts_ns;
22468 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
22469 +               if (nsproxy->uts_ns)
22470 +                       get_uts_ns(nsproxy->uts_ns);
22471 +       } else
22472 +               old_uts = NULL;
22473 +
22474 +       if (mask & CLONE_NEWIPC) {
22475 +               old_ipc = nsproxy->ipc_ns;
22476 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
22477 +               if (nsproxy->ipc_ns)
22478 +                       get_ipc_ns(nsproxy->ipc_ns);
22479 +       } else
22480 +               old_ipc = NULL;
22481 +
22482 +#ifdef CONFIG_PID_NS
22483 +       if (mask & CLONE_NEWPID) {
22484 +               old_pid = nsproxy->pid_ns;
22485 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
22486 +               if (nsproxy->pid_ns)
22487 +                       get_pid_ns(nsproxy->pid_ns);
22488 +       } else
22489 +               old_pid = NULL;
22490 +#endif
22491 +#ifdef CONFIG_NET_NS
22492 +       if (mask & CLONE_NEWNET) {
22493 +               old_net = nsproxy->net_ns;
22494 +               nsproxy->net_ns = new_nsproxy->net_ns;
22495 +               if (nsproxy->net_ns)
22496 +                       get_net(nsproxy->net_ns);
22497 +       } else
22498 +               old_net = NULL;
22499 +#endif
22500 +       if (old_ns)
22501 +               put_mnt_ns(old_ns);
22502 +       if (old_uts)
22503 +               put_uts_ns(old_uts);
22504 +       if (old_ipc)
22505 +               put_ipc_ns(old_ipc);
22506 +#ifdef CONFIG_PID_NS
22507 +       if (old_pid)
22508 +               put_pid_ns(old_pid);
22509 +#endif
22510 +#ifdef CONFIG_NET_NS
22511 +       if (old_net)
22512 +               put_net(old_net);
22513 +#endif
22514 +out:
22515 +       return nsproxy;
22516 +}
22517 +
22518 +
22519 +/*
22520 + *     merge two nsproxy structs into a new one.
22521 + *     will hold a reference on the result.
22522 + */
22523 +
22524 +static inline
22525 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
22526 +       struct nsproxy *proxy, unsigned long mask)
22527 +{
22528 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
22529 +
22530 +       if (!proxy)
22531 +               return NULL;
22532 +
22533 +       if (mask) {
22534 +               /* vs_mix_nsproxy returns with reference */
22535 +               return vs_mix_nsproxy(old ? old : &null_proxy,
22536 +                       proxy, mask);
22537 +       }
22538 +       get_nsproxy(proxy);
22539 +       return proxy;
22540 +}
22541 +
22542 +
22543 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
22544 +{
22545 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
22546 +       struct fs_struct *fs_cur, *fs = NULL;
22547 +       struct _vx_space *space;
22548 +       int ret, kill = 0;
22549 +
22550 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
22551 +               vxi, vxi->vx_id, mask, index);
22552 +
22553 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
22554 +               return -EACCES;
22555 +
22556 +       if (index >= VX_SPACES)
22557 +               return -EINVAL;
22558 +
22559 +       space = &vxi->space[index];
22560 +
22561 +       if (!mask)
22562 +               mask = space->vx_nsmask;
22563 +
22564 +       if ((mask & space->vx_nsmask) != mask)
22565 +               return -EINVAL;
22566 +
22567 +       if (mask & CLONE_FS) {
22568 +               fs = copy_fs_struct(space->vx_fs);
22569 +               if (!fs)
22570 +                       return -ENOMEM;
22571 +       }
22572 +       proxy = space->vx_nsproxy;
22573 +
22574 +       vxdprintk(VXD_CBIT(space, 9),
22575 +               "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
22576 +               vxi, vxi->vx_id, mask, index, proxy, fs);
22577 +
22578 +       task_lock(current);
22579 +       fs_cur = current->fs;
22580 +
22581 +       if (mask & CLONE_FS) {
22582 +               spin_lock(&fs_cur->lock);
22583 +               current->fs = fs;
22584 +               kill = !--fs_cur->users;
22585 +               spin_unlock(&fs_cur->lock);
22586 +       }
22587 +
22588 +       proxy_cur = current->nsproxy;
22589 +       get_nsproxy(proxy_cur);
22590 +       task_unlock(current);
22591 +
22592 +       if (kill)
22593 +               free_fs_struct(fs_cur);
22594 +
22595 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
22596 +       if (IS_ERR(proxy_new)) {
22597 +               ret = PTR_ERR(proxy_new);
22598 +               goto out_put;
22599 +       }
22600 +
22601 +       proxy_new = xchg(&current->nsproxy, proxy_new);
22602 +
22603 +       if (mask & CLONE_NEWUSER) {
22604 +               struct cred *cred;
22605 +
22606 +               vxdprintk(VXD_CBIT(space, 10),
22607 +                       "vx_enter_space(%p[#%u],%p) cred (%p,%p)",
22608 +                       vxi, vxi->vx_id, space->vx_cred,
22609 +                       current->real_cred, current->cred);
22610 +
22611 +               if (space->vx_cred) {
22612 +                       cred = __prepare_creds(space->vx_cred);
22613 +                       if (cred)
22614 +                               commit_creds(cred);
22615 +               }
22616 +       }
22617 +
22618 +       ret = 0;
22619 +
22620 +       if (proxy_new)
22621 +               put_nsproxy(proxy_new);
22622 +out_put:
22623 +       if (proxy_cur)
22624 +               put_nsproxy(proxy_cur);
22625 +       return ret;
22626 +}
22627 +
22628 +
22629 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
22630 +{
22631 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
22632 +       struct fs_struct *fs_vxi, *fs = NULL;
22633 +       struct _vx_space *space;
22634 +       int ret, kill = 0;
22635 +
22636 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
22637 +               vxi, vxi->vx_id, mask, index);
22638 +
22639 +       if ((mask & space_mask.mask) != mask)
22640 +               return -EINVAL;
22641 +
22642 +       if (index >= VX_SPACES)
22643 +               return -EINVAL;
22644 +
22645 +       space = &vxi->space[index];
22646 +
22647 +       proxy_vxi = space->vx_nsproxy;
22648 +       fs_vxi = space->vx_fs;
22649 +
22650 +       if (mask & CLONE_FS) {
22651 +               fs = copy_fs_struct(current->fs);
22652 +               if (!fs)
22653 +                       return -ENOMEM;
22654 +       }
22655 +
22656 +       task_lock(current);
22657 +
22658 +       if (mask & CLONE_FS) {
22659 +               spin_lock(&fs_vxi->lock);
22660 +               space->vx_fs = fs;
22661 +               kill = !--fs_vxi->users;
22662 +               spin_unlock(&fs_vxi->lock);
22663 +       }
22664 +
22665 +       proxy_cur = current->nsproxy;
22666 +       get_nsproxy(proxy_cur);
22667 +       task_unlock(current);
22668 +
22669 +       if (kill)
22670 +               free_fs_struct(fs_vxi);
22671 +
22672 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
22673 +       if (IS_ERR(proxy_new)) {
22674 +               ret = PTR_ERR(proxy_new);
22675 +               goto out_put;
22676 +       }
22677 +
22678 +       proxy_new = xchg(&space->vx_nsproxy, proxy_new);
22679 +       space->vx_nsmask |= mask;
22680 +
22681 +       if (mask & CLONE_NEWUSER) {
22682 +               struct cred *cred;
22683 +
22684 +               vxdprintk(VXD_CBIT(space, 10),
22685 +                       "vx_set_space(%p[#%u],%p) cred (%p,%p)",
22686 +                       vxi, vxi->vx_id, space->vx_cred,
22687 +                       current->real_cred, current->cred);
22688 +
22689 +               cred = prepare_creds();
22690 +               cred = (struct cred *)xchg(&space->vx_cred, cred);
22691 +               if (cred)
22692 +                       abort_creds(cred);
22693 +       }
22694 +
22695 +       ret = 0;
22696 +
22697 +       if (proxy_new)
22698 +               put_nsproxy(proxy_new);
22699 +out_put:
22700 +       if (proxy_cur)
22701 +               put_nsproxy(proxy_cur);
22702 +       return ret;
22703 +}
22704 +
22705 +
22706 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
22707 +{
22708 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22709 +
22710 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22711 +               return -EFAULT;
22712 +
22713 +       return vx_enter_space(vxi, vc_data.mask, 0);
22714 +}
22715 +
22716 +int vc_enter_space(struct vx_info *vxi, void __user *data)
22717 +{
22718 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22719 +
22720 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22721 +               return -EFAULT;
22722 +
22723 +       if (vc_data.index >= VX_SPACES)
22724 +               return -EINVAL;
22725 +
22726 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
22727 +}
22728 +
22729 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
22730 +{
22731 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22732 +
22733 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22734 +               return -EFAULT;
22735 +
22736 +       return vx_set_space(vxi, vc_data.mask, 0);
22737 +}
22738 +
22739 +int vc_set_space(struct vx_info *vxi, void __user *data)
22740 +{
22741 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22742 +
22743 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22744 +               return -EFAULT;
22745 +
22746 +       if (vc_data.index >= VX_SPACES)
22747 +               return -EINVAL;
22748 +
22749 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
22750 +}
22751 +
22752 +int vc_get_space_mask(void __user *data, int type)
22753 +{
22754 +       const struct vcmd_space_mask_v1 *mask;
22755 +
22756 +       if (type == 0)
22757 +               mask = &space_mask_v0;
22758 +       else if (type == 1)
22759 +               mask = &space_mask;
22760 +       else
22761 +               mask = &default_space_mask;
22762 +
22763 +       vxdprintk(VXD_CBIT(space, 10),
22764 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
22765 +
22766 +       if (copy_to_user(data, mask, sizeof(*mask)))
22767 +               return -EFAULT;
22768 +       return 0;
22769 +}
22770 +
22771 diff -NurpP --minimal linux-3.9.5/kernel/vserver/switch.c linux-3.9.5-vs2.3.6.5/kernel/vserver/switch.c
22772 --- linux-3.9.5/kernel/vserver/switch.c 1970-01-01 00:00:00.000000000 +0000
22773 +++ linux-3.9.5-vs2.3.6.5/kernel/vserver/switch.c       2013-05-31 14:47:11.000000000 +0000
22774 @@ -0,0 +1,556 @@
22775 +/*
22776 + *  linux/kernel/vserver/switch.c
22777 + *
22778 + *  Virtual Server: Syscall Switch
22779 + *
22780 + *  Copyright (C) 2003-2011  Herbert Pötzl
22781 + *
22782 + *  V0.01  syscall switch
22783 + *  V0.02  added signal to context
22784 + *  V0.03  added rlimit functions
22785 + *  V0.04  added iattr, task/xid functions
22786 + *  V0.05  added debug/history stuff
22787 + *  V0.06  added compat32 layer
22788 + *  V0.07  vcmd args and perms
22789 + *  V0.08  added status commands
22790 + *  V0.09  added tag commands
22791 + *  V0.10  added oom bias
22792 + *  V0.11  added device commands
22793 + *  V0.12  added warn mask
22794 + *
22795 + */
22796 +
22797 +#include <linux/vs_context.h>
22798 +#include <linux/vs_network.h>
22799 +#include <linux/vserver/switch.h>
22800 +
22801 +#include "vci_config.h"
22802 +
22803 +
22804 +static inline
22805 +int vc_get_version(uint32_t id)
22806 +{
22807 +       return VCI_VERSION;
22808 +}
22809 +
22810 +static inline
22811 +int vc_get_vci(uint32_t id)
22812 +{
22813 +       return vci_kernel_config();
22814 +}
22815 +
22816 +#include <linux/vserver/context_cmd.h>
22817 +#include <linux/vserver/cvirt_cmd.h>
22818 +#include <linux/vserver/cacct_cmd.h>
22819 +#include <linux/vserver/limit_cmd.h>
22820 +#include <linux/vserver/network_cmd.h>
22821 +#include <linux/vserver/sched_cmd.h>
22822 +#include <linux/vserver/debug_cmd.h>
22823 +#include <linux/vserver/inode_cmd.h>
22824 +#include <linux/vserver/dlimit_cmd.h>
22825 +#include <linux/vserver/signal_cmd.h>
22826 +#include <linux/vserver/space_cmd.h>
22827 +#include <linux/vserver/tag_cmd.h>
22828 +#include <linux/vserver/device_cmd.h>
22829 +
22830 +#include <linux/vserver/inode.h>
22831 +#include <linux/vserver/dlimit.h>
22832 +
22833 +
22834 +#ifdef CONFIG_COMPAT
22835 +#define __COMPAT(name, id, data, compat)       \
22836 +       (compat) ? name ## _x32(id, data) : name(id, data)
22837 +#define __COMPAT_NO_ID(name, data, compat)     \
22838 +       (compat) ? name ## _x32(data) : name(data)
22839 +#else
22840 +#define __COMPAT(name, id, data, compat)       \
22841 +       name(id, data)
22842 +#define __COMPAT_NO_ID(name, data, compat)     \
22843 +       name(data)
22844 +#endif
22845 +
22846 +
22847 +static inline
22848 +long do_vcmd(uint32_t cmd, uint32_t id,
22849 +       struct vx_info *vxi, struct nx_info *nxi,
22850 +       void __user *data, int compat)
22851 +{
22852 +       switch (cmd) {
22853 +
22854 +       case VCMD_get_version:
22855 +               return vc_get_version(id);
22856 +       case VCMD_get_vci:
22857 +               return vc_get_vci(id);
22858 +
22859 +       case VCMD_task_xid:
22860 +               return vc_task_xid(id);
22861 +       case VCMD_vx_info:
22862 +               return vc_vx_info(vxi, data);
22863 +
22864 +       case VCMD_task_nid:
22865 +               return vc_task_nid(id);
22866 +       case VCMD_nx_info:
22867 +               return vc_nx_info(nxi, data);
22868 +
22869 +       case VCMD_task_tag:
22870 +               return vc_task_tag(id);
22871 +
22872 +       case VCMD_set_space_v1:
22873 +               return vc_set_space_v1(vxi, data);
22874 +       /* this is version 2 */
22875 +       case VCMD_set_space:
22876 +               return vc_set_space(vxi, data);
22877 +
22878 +       case VCMD_get_space_mask_v0:
22879 +               return vc_get_space_mask(data, 0);
22880 +       /* this is version 1 */
22881 +       case VCMD_get_space_mask:
22882 +               return vc_get_space_mask(data, 1);
22883 +
22884 +       case VCMD_get_space_default:
22885 +               return vc_get_space_mask(data, -1);
22886 +
22887 +       case VCMD_set_umask:
22888 +               return vc_set_umask(vxi, data);
22889 +
22890 +       case VCMD_get_umask:
22891 +               return vc_get_umask(vxi, data);
22892 +
22893 +       case VCMD_set_wmask:
22894 +               return vc_set_wmask(vxi, data);
22895 +
22896 +       case VCMD_get_wmask:
22897 +               return vc_get_wmask(vxi, data);
22898 +#ifdef CONFIG_IA32_EMULATION
22899 +       case VCMD_get_rlimit:
22900 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
22901 +       case VCMD_set_rlimit:
22902 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
22903 +#else
22904 +       case VCMD_get_rlimit:
22905 +               return vc_get_rlimit(vxi, data);
22906 +       case VCMD_set_rlimit:
22907 +               return vc_set_rlimit(vxi, data);
22908 +#endif
22909 +       case VCMD_get_rlimit_mask:
22910 +               return vc_get_rlimit_mask(id, data);
22911 +       case VCMD_reset_hits:
22912 +               return vc_reset_hits(vxi, data);
22913 +       case VCMD_reset_minmax:
22914 +               return vc_reset_minmax(vxi, data);
22915 +
22916 +       case VCMD_get_vhi_name:
22917 +               return vc_get_vhi_name(vxi, data);
22918 +       case VCMD_set_vhi_name:
22919 +               return vc_set_vhi_name(vxi, data);
22920 +
22921 +       case VCMD_ctx_stat:
22922 +               return vc_ctx_stat(vxi, data);
22923 +       case VCMD_virt_stat:
22924 +               return vc_virt_stat(vxi, data);
22925 +       case VCMD_sock_stat:
22926 +               return vc_sock_stat(vxi, data);
22927 +       case VCMD_rlimit_stat:
22928 +               return vc_rlimit_stat(vxi, data);
22929 +
22930 +       case VCMD_set_cflags:
22931 +               return vc_set_cflags(vxi, data);
22932 +       case VCMD_get_cflags:
22933 +               return vc_get_cflags(vxi, data);
22934 +
22935 +       /* this is version 1 */
22936 +       case VCMD_set_ccaps:
22937 +               return vc_set_ccaps(vxi, data);
22938 +       /* this is version 1 */
22939 +       case VCMD_get_ccaps:
22940 +               return vc_get_ccaps(vxi, data);
22941 +       case VCMD_set_bcaps:
22942 +               return vc_set_bcaps(vxi, data);
22943 +       case VCMD_get_bcaps:
22944 +               return vc_get_bcaps(vxi, data);
22945 +
22946 +       case VCMD_set_badness:
22947 +               return vc_set_badness(vxi, data);
22948 +       case VCMD_get_badness:
22949 +               return vc_get_badness(vxi, data);
22950 +
22951 +       case VCMD_set_nflags:
22952 +               return vc_set_nflags(nxi, data);
22953 +       case VCMD_get_nflags:
22954 +               return vc_get_nflags(nxi, data);
22955 +
22956 +       case VCMD_set_ncaps:
22957 +               return vc_set_ncaps(nxi, data);
22958 +       case VCMD_get_ncaps:
22959 +               return vc_get_ncaps(nxi, data);
22960 +
22961 +       case VCMD_set_prio_bias:
22962 +               return vc_set_prio_bias(vxi, data);
22963 +       case VCMD_get_prio_bias:
22964 +               return vc_get_prio_bias(vxi, data);
22965 +       case VCMD_add_dlimit:
22966 +               return __COMPAT(vc_add_dlimit, id, data, compat);
22967 +       case VCMD_rem_dlimit:
22968 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
22969 +       case VCMD_set_dlimit:
22970 +               return __COMPAT(vc_set_dlimit, id, data, compat);
22971 +       case VCMD_get_dlimit:
22972 +               return __COMPAT(vc_get_dlimit, id, data, compat);
22973 +
22974 +       case VCMD_ctx_kill:
22975 +               return vc_ctx_kill(vxi, data);
22976 +
22977 +       case VCMD_wait_exit:
22978 +               return vc_wait_exit(vxi, data);
22979 +
22980 +       case VCMD_get_iattr:
22981 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
22982 +       case VCMD_set_iattr:
22983 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
22984 +
22985 +       case VCMD_fget_iattr:
22986 +               return vc_fget_iattr(id, data);
22987 +       case VCMD_fset_iattr:
22988 +               return vc_fset_iattr(id, data);
22989 +
22990 +       case VCMD_enter_space_v0:
22991 +               return vc_enter_space_v1(vxi, NULL);
22992 +       case VCMD_enter_space_v1:
22993 +               return vc_enter_space_v1(vxi, data);
22994 +       /* this is version 2 */
22995 +       case VCMD_enter_space:
22996 +               return vc_enter_space(vxi, data);
22997 +
22998 +       case VCMD_ctx_create_v0:
22999 +               return vc_ctx_create(id, NULL);
23000 +       case VCMD_ctx_create:
23001 +               return vc_ctx_create(id, data);
23002 +       case VCMD_ctx_migrate_v0:
23003 +               return vc_ctx_migrate(vxi, NULL);
23004 +       case VCMD_ctx_migrate:
23005 +               return vc_ctx_migrate(vxi, data);
23006 +
23007 +       case VCMD_net_create_v0:
23008 +               return vc_net_create(id, NULL);
23009 +       case VCMD_net_create:
23010 +               return vc_net_create(id, data);
23011 +       case VCMD_net_migrate:
23012 +               return vc_net_migrate(nxi, data);
23013 +
23014 +       case VCMD_tag_migrate:
23015 +               return vc_tag_migrate(id);
23016 +
23017 +       case VCMD_net_add:
23018 +               return vc_net_add(nxi, data);
23019 +       case VCMD_net_remove:
23020 +               return vc_net_remove(nxi, data);
23021 +
23022 +       case VCMD_net_add_ipv4_v1:
23023 +               return vc_net_add_ipv4_v1(nxi, data);
23024 +       /* this is version 2 */
23025 +       case VCMD_net_add_ipv4:
23026 +               return vc_net_add_ipv4(nxi, data);
23027 +
23028 +       case VCMD_net_rem_ipv4_v1:
23029 +               return vc_net_rem_ipv4_v1(nxi, data);
23030 +       /* this is version 2 */
23031 +       case VCMD_net_rem_ipv4:
23032 +               return vc_net_rem_ipv4(nxi, data);
23033 +#ifdef CONFIG_IPV6
23034 +       case VCMD_net_add_ipv6:
23035 +               return vc_net_add_ipv6(nxi, data);
23036 +       case VCMD_net_remove_ipv6:
23037 +               return vc_net_remove_ipv6(nxi, data);
23038 +#endif
23039 +/*     case VCMD_add_match_ipv4:
23040 +               return vc_add_match_ipv4(nxi, data);
23041 +       case VCMD_get_match_ipv4:
23042 +               return vc_get_match_ipv4(nxi, data);
23043 +#ifdef CONFIG_IPV6
23044 +       case VCMD_add_match_ipv6:
23045 +               return vc_add_match_ipv6(nxi, data);
23046 +       case VCMD_get_match_ipv6:
23047 +               return vc_get_match_ipv6(nxi, data);
23048 +#endif */
23049 +
23050 +#ifdef CONFIG_VSERVER_DEVICE
23051 +       case VCMD_set_mapping:
23052 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
23053 +       case VCMD_unset_mapping:
23054 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
23055 +#endif
23056 +#ifdef CONFIG_VSERVER_HISTORY
23057 +       case VCMD_dump_history:
23058 +               return vc_dump_history(id);
23059 +       case VCMD_read_history:
23060 +               return __COMPAT(vc_read_history, id, data, compat);
23061 +#endif
23062 +       default:
23063 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
23064 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
23065 +       }
23066 +       return -ENOSYS;
23067 +}
23068 +
23069 +
23070 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
23071 +       case VCMD_ ## vcmd: perm = _perm;               \
23072 +               args = _args; flags = _flags; break
23073 +
23074 +
23075 +#define VCA_NONE       0x00
23076 +#define VCA_VXI                0x01
23077 +#define VCA_NXI                0x02
23078 +
23079 +#define VCF_NONE       0x00
23080 +#define VCF_INFO       0x01
23081 +#define VCF_ADMIN      0x02
23082 +#define VCF_ARES       0x06    /* includes admin */
23083 +#define VCF_SETUP      0x08
23084 +
23085 +#define VCF_ZIDOK      0x10    /* zero id okay */
23086 +
23087 +
23088 +static inline
23089 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
23090 +{
23091 +       long ret;
23092 +       int permit = -1, state = 0;
23093 +       int perm = -1, args = 0, flags = 0;
23094 +       struct vx_info *vxi = NULL;
23095 +       struct nx_info *nxi = NULL;
23096 +
23097 +       switch (cmd) {
23098 +       /* unpriviledged commands */
23099 +       __VCMD(get_version,      0, VCA_NONE,   0);
23100 +       __VCMD(get_vci,          0, VCA_NONE,   0);
23101 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
23102 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
23103 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
23104 +       __VCMD(get_space_default,0, VCA_NONE,   0);
23105 +
23106 +       /* info commands */
23107 +       __VCMD(task_xid,         2, VCA_NONE,   0);
23108 +       __VCMD(reset_hits,       2, VCA_VXI,    0);
23109 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
23110 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
23111 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
23112 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
23113 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
23114 +       __VCMD(get_umask,        3, VCA_VXI,    VCF_INFO);
23115 +       __VCMD(get_wmask,        3, VCA_VXI,    VCF_INFO);
23116 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
23117 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
23118 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
23119 +
23120 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
23121 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
23122 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
23123 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
23124 +
23125 +       __VCMD(task_nid,         2, VCA_NONE,   0);
23126 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
23127 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
23128 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
23129 +
23130 +       __VCMD(task_tag,         2, VCA_NONE,   0);
23131 +
23132 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
23133 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
23134 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
23135 +       __VCMD(get_prio_bias,    3, VCA_VXI,    VCF_INFO);
23136 +
23137 +       /* lower admin commands */
23138 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
23139 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
23140 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
23141 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
23142 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
23143 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
23144 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
23145 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
23146 +
23147 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
23148 +       __VCMD(net_create,       5, VCA_NONE,   0);
23149 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
23150 +
23151 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
23152 +
23153 +       /* higher admin commands */
23154 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
23155 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23156 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23157 +
23158 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23159 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23160 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23161 +       __VCMD(set_umask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23162 +       __VCMD(set_wmask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23163 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23164 +
23165 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23166 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23167 +       __VCMD(set_prio_bias,    7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23168 +
23169 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23170 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23171 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23172 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23173 +       __VCMD(net_add_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23174 +       __VCMD(net_rem_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23175 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23176 +       __VCMD(net_rem_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23177 +#ifdef CONFIG_IPV6
23178 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23179 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23180 +#endif
23181 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
23182 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
23183 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
23184 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
23185 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
23186 +
23187 +#ifdef CONFIG_VSERVER_DEVICE
23188 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23189 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23190 +#endif
23191 +       /* debug level admin commands */
23192 +#ifdef CONFIG_VSERVER_HISTORY
23193 +       __VCMD(dump_history,     9, VCA_NONE,   0);
23194 +       __VCMD(read_history,     9, VCA_NONE,   0);
23195 +#endif
23196 +
23197 +       default:
23198 +               perm = -1;
23199 +       }
23200 +
23201 +       vxdprintk(VXD_CBIT(switch, 0),
23202 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
23203 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23204 +               VC_VERSION(cmd), id, data, compat,
23205 +               perm, args, flags);
23206 +
23207 +       ret = -ENOSYS;
23208 +       if (perm < 0)
23209 +               goto out;
23210 +
23211 +       state = 1;
23212 +       if (!capable(CAP_CONTEXT))
23213 +               goto out;
23214 +
23215 +       state = 2;
23216 +       /* moved here from the individual commands */
23217 +       ret = -EPERM;
23218 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
23219 +               goto out;
23220 +
23221 +       state = 3;
23222 +       /* vcmd involves resource management  */
23223 +       ret = -EPERM;
23224 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
23225 +               goto out;
23226 +
23227 +       state = 4;
23228 +       /* various legacy exceptions */
23229 +       switch (cmd) {
23230 +       /* will go away when spectator is a cap */
23231 +       case VCMD_ctx_migrate_v0:
23232 +       case VCMD_ctx_migrate:
23233 +               if (id == 1) {
23234 +                       current->xid = 1;
23235 +                       ret = 1;
23236 +                       goto out;
23237 +               }
23238 +               break;
23239 +
23240 +       /* will go away when spectator is a cap */
23241 +       case VCMD_net_migrate:
23242 +               if (id == 1) {
23243 +                       current->nid = 1;
23244 +                       ret = 1;
23245 +                       goto out;
23246 +               }
23247 +               break;
23248 +       }
23249 +
23250 +       /* vcmds are fine by default */
23251 +       permit = 1;
23252 +
23253 +       /* admin type vcmds require admin ... */
23254 +       if (flags & VCF_ADMIN)
23255 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
23256 +
23257 +       /* ... but setup type vcmds override that */
23258 +       if (!permit && (flags & VCF_SETUP))
23259 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
23260 +
23261 +       state = 5;
23262 +       ret = -EPERM;
23263 +       if (!permit)
23264 +               goto out;
23265 +
23266 +       state = 6;
23267 +       if (!id && (flags & VCF_ZIDOK))
23268 +               goto skip_id;
23269 +
23270 +       ret = -ESRCH;
23271 +       if (args & VCA_VXI) {
23272 +               vxi = lookup_vx_info(id);
23273 +               if (!vxi)
23274 +                       goto out;
23275 +
23276 +               if ((flags & VCF_ADMIN) &&
23277 +                       /* special case kill for shutdown */
23278 +                       (cmd != VCMD_ctx_kill) &&
23279 +                       /* can context be administrated? */
23280 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
23281 +                       ret = -EACCES;
23282 +                       goto out_vxi;
23283 +               }
23284 +       }
23285 +       state = 7;
23286 +       if (args & VCA_NXI) {
23287 +               nxi = lookup_nx_info(id);
23288 +               if (!nxi)
23289 +                       goto out_vxi;
23290 +
23291 +               if ((flags & VCF_ADMIN) &&
23292 +                       /* can context be administrated? */
23293 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
23294 +                       ret = -EACCES;
23295 +                       goto out_nxi;
23296 +               }
23297 +       }
23298 +skip_id:
23299 +       state = 8;
23300 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
23301 +
23302 +out_nxi:
23303 +       if ((args & VCA_NXI) && nxi)
23304 +               put_nx_info(nxi);
23305 +out_vxi:
23306 +       if ((args & VCA_VXI) && vxi)
23307 +               put_vx_info(vxi);
23308 +out:
23309 +       vxdprintk(VXD_CBIT(switch, 1),
23310 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
23311 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23312 +               VC_VERSION(cmd), ret, ret, state, permit);
23313 +       return ret;
23314 +}
23315 +
23316 +asmlinkage long
23317 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
23318 +{
23319 +       return do_vserver(cmd, id, data, 0);
23320 +}
23321 +
23322 +#ifdef CONFIG_COMPAT
23323 +
23324 +asmlinkage long
23325 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
23326 +{
23327 +       return do_vserver(cmd, id, data, 1);
23328 +}
23329 +
23330 +#endif /* CONFIG_COMPAT */
23331 diff -NurpP --minimal linux-3.9.5/kernel/vserver/sysctl.c linux-3.9.5-vs2.3.6.5/kernel/vserver/sysctl.c
23332 --- linux-3.9.5/kernel/vserver/sysctl.c 1970-01-01 00:00:00.000000000 +0000
23333 +++ linux-3.9.5-vs2.3.6.5/kernel/vserver/sysctl.c       2013-05-31 14:47:11.000000000 +0000
23334 @@ -0,0 +1,247 @@
23335 +/*
23336 + *  kernel/vserver/sysctl.c
23337 + *
23338 + *  Virtual Context Support
23339 + *
23340 + *  Copyright (C) 2004-2007  Herbert Pötzl
23341 + *
23342 + *  V0.01  basic structure
23343 + *
23344 + */
23345 +
23346 +#include <linux/module.h>
23347 +#include <linux/ctype.h>
23348 +#include <linux/sysctl.h>
23349 +#include <linux/parser.h>
23350 +#include <asm/uaccess.h>
23351 +
23352 +enum {
23353 +       CTL_DEBUG_ERROR         = 0,
23354 +       CTL_DEBUG_SWITCH        = 1,
23355 +       CTL_DEBUG_XID,
23356 +       CTL_DEBUG_NID,
23357 +       CTL_DEBUG_TAG,
23358 +       CTL_DEBUG_NET,
23359 +       CTL_DEBUG_LIMIT,
23360 +       CTL_DEBUG_CRES,
23361 +       CTL_DEBUG_DLIM,
23362 +       CTL_DEBUG_QUOTA,
23363 +       CTL_DEBUG_CVIRT,
23364 +       CTL_DEBUG_SPACE,
23365 +       CTL_DEBUG_PERM,
23366 +       CTL_DEBUG_MISC,
23367 +};
23368 +
23369 +
23370 +unsigned int vs_debug_switch   = 0;
23371 +unsigned int vs_debug_xid      = 0;
23372 +unsigned int vs_debug_nid      = 0;
23373 +unsigned int vs_debug_tag      = 0;
23374 +unsigned int vs_debug_net      = 0;
23375 +unsigned int vs_debug_limit    = 0;
23376 +unsigned int vs_debug_cres     = 0;
23377 +unsigned int vs_debug_dlim     = 0;
23378 +unsigned int vs_debug_quota    = 0;
23379 +unsigned int vs_debug_cvirt    = 0;
23380 +unsigned int vs_debug_space    = 0;
23381 +unsigned int vs_debug_perm     = 0;
23382 +unsigned int vs_debug_misc     = 0;
23383 +
23384 +
23385 +static struct ctl_table_header *vserver_table_header;
23386 +static ctl_table vserver_root_table[];
23387 +
23388 +
23389 +void vserver_register_sysctl(void)
23390 +{
23391 +       if (!vserver_table_header) {
23392 +               vserver_table_header = register_sysctl_table(vserver_root_table);
23393 +       }
23394 +
23395 +}
23396 +
23397 +void vserver_unregister_sysctl(void)
23398 +{
23399 +       if (vserver_table_header) {
23400 +               unregister_sysctl_table(vserver_table_header);
23401 +               vserver_table_header = NULL;
23402 +       }
23403 +}
23404 +
23405 +
23406 +static int proc_dodebug(ctl_table *table, int write,
23407 +       void __user *buffer, size_t *lenp, loff_t *ppos)
23408 +{
23409 +       char            tmpbuf[20], *p, c;
23410 +       unsigned int    value;
23411 +       size_t          left, len;
23412 +
23413 +       if ((*ppos && !write) || !*lenp) {
23414 +               *lenp = 0;
23415 +               return 0;
23416 +       }
23417 +
23418 +       left = *lenp;
23419 +
23420 +       if (write) {
23421 +               if (!access_ok(VERIFY_READ, buffer, left))
23422 +                       return -EFAULT;
23423 +               p = (char *)buffer;
23424 +               while (left && __get_user(c, p) >= 0 && isspace(c))
23425 +                       left--, p++;
23426 +               if (!left)
23427 +                       goto done;
23428 +
23429 +               if (left > sizeof(tmpbuf) - 1)
23430 +                       return -EINVAL;
23431 +               if (copy_from_user(tmpbuf, p, left))
23432 +                       return -EFAULT;
23433 +               tmpbuf[left] = '\0';
23434 +
23435 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
23436 +                       value = 10 * value + (*p - '0');
23437 +               if (*p && !isspace(*p))
23438 +                       return -EINVAL;
23439 +               while (left && isspace(*p))
23440 +                       left--, p++;
23441 +               *(unsigned int *)table->data = value;
23442 +       } else {
23443 +               if (!access_ok(VERIFY_WRITE, buffer, left))
23444 +                       return -EFAULT;
23445 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
23446 +               if (len > left)
23447 +                       len = left;
23448 +               if (__copy_to_user(buffer, tmpbuf, len))
23449 +                       return -EFAULT;
23450 +               if ((left -= len) > 0) {
23451 +                       if (put_user('\n', (char *)buffer + len))
23452 +                               return -EFAULT;
23453 +                       left--;
23454 +               }
23455 +       }
23456 +
23457 +done:
23458 +       *lenp -= left;
23459 +       *ppos += *lenp;
23460 +       return 0;
23461 +}
23462 +
23463 +static int zero;
23464 +
23465 +#define        CTL_ENTRY(ctl, name)                            \
23466 +       {                                               \
23467 +               .procname       = #name,                \
23468 +               .data           = &vs_ ## name,         \
23469 +               .maxlen         = sizeof(int),          \
23470 +               .mode           = 0644,                 \
23471 +               .proc_handler   = &proc_dodebug,        \
23472 +               .extra1         = &zero,                \
23473 +               .extra2         = &zero,                \
23474 +       }
23475 +
23476 +static ctl_table vserver_debug_table[] = {
23477 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
23478 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
23479 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
23480 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
23481 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
23482 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
23483 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
23484 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
23485 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
23486 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
23487 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
23488 +       CTL_ENTRY(CTL_DEBUG_PERM,       debug_perm),
23489 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
23490 +       { 0 }
23491 +};
23492 +
23493 +static ctl_table vserver_root_table[] = {
23494 +       {
23495 +               .procname       = "vserver",
23496 +               .mode           = 0555,
23497 +               .child          = vserver_debug_table
23498 +       },
23499 +       { 0 }
23500 +};
23501 +
23502 +
23503 +static match_table_t tokens = {
23504 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
23505 +       { CTL_DEBUG_XID,        "xid=%x"        },
23506 +       { CTL_DEBUG_NID,        "nid=%x"        },
23507 +       { CTL_DEBUG_TAG,        "tag=%x"        },
23508 +       { CTL_DEBUG_NET,        "net=%x"        },
23509 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
23510 +       { CTL_DEBUG_CRES,       "cres=%x"       },
23511 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
23512 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
23513 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
23514 +       { CTL_DEBUG_SPACE,      "space=%x"      },
23515 +       { CTL_DEBUG_PERM,       "perm=%x"       },
23516 +       { CTL_DEBUG_MISC,       "misc=%x"       },
23517 +       { CTL_DEBUG_ERROR,      NULL            }
23518 +};
23519 +
23520 +#define        HANDLE_CASE(id, name, val)                              \
23521 +       case CTL_DEBUG_ ## id:                                  \
23522 +               vs_debug_ ## name = val;                        \
23523 +               printk("vs_debug_" #name "=0x%x\n", val);       \
23524 +               break
23525 +
23526 +
23527 +static int __init vs_debug_setup(char *str)
23528 +{
23529 +       char *p;
23530 +       int token;
23531 +
23532 +       printk("vs_debug_setup(%s)\n", str);
23533 +       while ((p = strsep(&str, ",")) != NULL) {
23534 +               substring_t args[MAX_OPT_ARGS];
23535 +               unsigned int value;
23536 +
23537 +               if (!*p)
23538 +                       continue;
23539 +
23540 +               token = match_token(p, tokens, args);
23541 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
23542 +
23543 +               switch (token) {
23544 +               HANDLE_CASE(SWITCH, switch, value);
23545 +               HANDLE_CASE(XID,    xid,    value);
23546 +               HANDLE_CASE(NID,    nid,    value);
23547 +               HANDLE_CASE(TAG,    tag,    value);
23548 +               HANDLE_CASE(NET,    net,    value);
23549 +               HANDLE_CASE(LIMIT,  limit,  value);
23550 +               HANDLE_CASE(CRES,   cres,   value);
23551 +               HANDLE_CASE(DLIM,   dlim,   value);
23552 +               HANDLE_CASE(QUOTA,  quota,  value);
23553 +               HANDLE_CASE(CVIRT,  cvirt,  value);
23554 +               HANDLE_CASE(SPACE,  space,  value);
23555 +               HANDLE_CASE(PERM,   perm,   value);
23556 +               HANDLE_CASE(MISC,   misc,   value);
23557 +               default:
23558 +                       return -EINVAL;
23559 +                       break;
23560 +               }
23561 +       }
23562 +       return 1;
23563 +}
23564 +
23565 +__setup("vsdebug=", vs_debug_setup);
23566 +
23567 +
23568 +
23569 +EXPORT_SYMBOL_GPL(vs_debug_switch);
23570 +EXPORT_SYMBOL_GPL(vs_debug_xid);
23571 +EXPORT_SYMBOL_GPL(vs_debug_nid);
23572 +EXPORT_SYMBOL_GPL(vs_debug_net);
23573 +EXPORT_SYMBOL_GPL(vs_debug_limit);
23574 +EXPORT_SYMBOL_GPL(vs_debug_cres);
23575 +EXPORT_SYMBOL_GPL(vs_debug_dlim);
23576 +EXPORT_SYMBOL_GPL(vs_debug_quota);
23577 +EXPORT_SYMBOL_GPL(vs_debug_cvirt);
23578 +EXPORT_SYMBOL_GPL(vs_debug_space);
23579 +EXPORT_SYMBOL_GPL(vs_debug_perm);
23580 +EXPORT_SYMBOL_GPL(vs_debug_misc);
23581 +
23582 diff -NurpP --minimal linux-3.9.5/kernel/vserver/tag.c linux-3.9.5-vs2.3.6.5/kernel/vserver/tag.c
23583 --- linux-3.9.5/kernel/vserver/tag.c    1970-01-01 00:00:00.000000000 +0000
23584 +++ linux-3.9.5-vs2.3.6.5/kernel/vserver/tag.c  2013-06-12 23:49:09.000000000 +0000
23585 @@ -0,0 +1,63 @@
23586 +/*
23587 + *  linux/kernel/vserver/tag.c
23588 + *
23589 + *  Virtual Server: Shallow Tag Space
23590 + *
23591 + *  Copyright (C) 2007  Herbert Pötzl
23592 + *
23593 + *  V0.01  basic implementation
23594 + *
23595 + */
23596 +
23597 +#include <linux/sched.h>
23598 +#include <linux/vserver/debug.h>
23599 +#include <linux/vs_pid.h>
23600 +#include <linux/vs_tag.h>
23601 +
23602 +#include <linux/vserver/tag_cmd.h>
23603 +
23604 +
23605 +int dx_migrate_task(struct task_struct *p, vtag_t tag)
23606 +{
23607 +       if (!p)
23608 +               BUG();
23609 +
23610 +       vxdprintk(VXD_CBIT(tag, 5),
23611 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
23612 +
23613 +       task_lock(p);
23614 +       p->tag = tag;
23615 +       task_unlock(p);
23616 +
23617 +       vxdprintk(VXD_CBIT(tag, 5),
23618 +               "moved task %p into [#%d]", p, tag);
23619 +       return 0;
23620 +}
23621 +
23622 +/* vserver syscall commands below here */
23623 +
23624 +/* taks xid and vx_info functions */
23625 +
23626 +
23627 +int vc_task_tag(uint32_t id)
23628 +{
23629 +       vtag_t tag;
23630 +
23631 +       if (id) {
23632 +               struct task_struct *tsk;
23633 +               rcu_read_lock();
23634 +               tsk = find_task_by_real_pid(id);
23635 +               tag = (tsk) ? tsk->tag : -ESRCH;
23636 +               rcu_read_unlock();
23637 +       } else
23638 +               tag = dx_current_tag();
23639 +       return tag;
23640 +}
23641 +
23642 +
23643 +int vc_tag_migrate(uint32_t tag)
23644 +{
23645 +       return dx_migrate_task(current, tag & 0xFFFF);
23646 +}
23647 +
23648 +
23649 diff -NurpP --minimal linux-3.9.5/kernel/vserver/vci_config.h linux-3.9.5-vs2.3.6.5/kernel/vserver/vci_config.h
23650 --- linux-3.9.5/kernel/vserver/vci_config.h     1970-01-01 00:00:00.000000000 +0000
23651 +++ linux-3.9.5-vs2.3.6.5/kernel/vserver/vci_config.h   2013-05-31 14:47:11.000000000 +0000
23652 @@ -0,0 +1,80 @@
23653 +
23654 +/*  interface version */
23655 +
23656 +#define VCI_VERSION            0x00020308
23657 +
23658 +
23659 +enum {
23660 +       VCI_KCBIT_NO_DYNAMIC = 0,
23661 +
23662 +       VCI_KCBIT_PROC_SECURE = 4,
23663 +       /* VCI_KCBIT_HARDCPU = 5, */
23664 +       /* VCI_KCBIT_IDLELIMIT = 6, */
23665 +       /* VCI_KCBIT_IDLETIME = 7, */
23666 +
23667 +       VCI_KCBIT_COWBL = 8,
23668 +       VCI_KCBIT_FULLCOWBL = 9,
23669 +       VCI_KCBIT_SPACES = 10,
23670 +       VCI_KCBIT_NETV2 = 11,
23671 +       VCI_KCBIT_MEMCG = 12,
23672 +       VCI_KCBIT_MEMCG_SWAP = 13,
23673 +
23674 +       VCI_KCBIT_DEBUG = 16,
23675 +       VCI_KCBIT_HISTORY = 20,
23676 +       VCI_KCBIT_TAGGED = 24,
23677 +       VCI_KCBIT_PPTAG = 28,
23678 +
23679 +       VCI_KCBIT_MORE = 31,
23680 +};
23681 +
23682 +
23683 +static inline uint32_t vci_kernel_config(void)
23684 +{
23685 +       return
23686 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
23687 +
23688 +       /* configured features */
23689 +#ifdef CONFIG_VSERVER_PROC_SECURE
23690 +       (1 << VCI_KCBIT_PROC_SECURE) |
23691 +#endif
23692 +#ifdef CONFIG_VSERVER_COWBL
23693 +       (1 << VCI_KCBIT_COWBL) |
23694 +       (1 << VCI_KCBIT_FULLCOWBL) |
23695 +#endif
23696 +       (1 << VCI_KCBIT_SPACES) |
23697 +       (1 << VCI_KCBIT_NETV2) |
23698 +#ifdef CONFIG_MEMCG
23699 +       (1 << VCI_KCBIT_MEMCG) |
23700 +#endif
23701 +#ifdef CONFIG_MEMCG_SWAP
23702 +       (1 << VCI_KCBIT_MEMCG_SWAP) |
23703 +#endif
23704 +
23705 +       /* debug options */
23706 +#ifdef CONFIG_VSERVER_DEBUG
23707 +       (1 << VCI_KCBIT_DEBUG) |
23708 +#endif
23709 +#ifdef CONFIG_VSERVER_HISTORY
23710 +       (1 << VCI_KCBIT_HISTORY) |
23711 +#endif
23712 +
23713 +       /* inode context tagging */
23714 +#if    defined(CONFIG_TAGGING_NONE)
23715 +       (0 << VCI_KCBIT_TAGGED) |
23716 +#elif  defined(CONFIG_TAGGING_UID16)
23717 +       (1 << VCI_KCBIT_TAGGED) |
23718 +#elif  defined(CONFIG_TAGGING_GID16)
23719 +       (2 << VCI_KCBIT_TAGGED) |
23720 +#elif  defined(CONFIG_TAGGING_ID24)
23721 +       (3 << VCI_KCBIT_TAGGED) |
23722 +#elif  defined(CONFIG_TAGGING_INTERN)
23723 +       (4 << VCI_KCBIT_TAGGED) |
23724 +#elif  defined(CONFIG_TAGGING_RUNTIME)
23725 +       (5 << VCI_KCBIT_TAGGED) |
23726 +#else
23727 +       (7 << VCI_KCBIT_TAGGED) |
23728 +#endif
23729 +       (1 << VCI_KCBIT_PPTAG) |
23730 +       0;
23731 +}
23732 +
23733 diff -NurpP --minimal linux-3.9.5/mm/memcontrol.c linux-3.9.5-vs2.3.6.5/mm/memcontrol.c
23734 --- linux-3.9.5/mm/memcontrol.c 2013-06-11 12:22:40.000000000 +0000
23735 +++ linux-3.9.5-vs2.3.6.5/mm/memcontrol.c       2013-06-13 00:14:32.000000000 +0000
23736 @@ -1046,6 +1046,31 @@ struct mem_cgroup *mem_cgroup_from_task(
23737         return mem_cgroup_from_css(task_subsys_state(p, mem_cgroup_subsys_id));
23738  }
23739  
23740 +u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member)
23741 +{
23742 +       return res_counter_read_u64(&mem->res, member);
23743 +}
23744 +
23745 +u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member)
23746 +{
23747 +       return res_counter_read_u64(&mem->memsw, member);
23748 +}
23749 +
23750 +s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem)
23751 +{
23752 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_CACHE);
23753 +}
23754 +
23755 +s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem)
23756 +{
23757 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_RSS);
23758 +}
23759 +
23760 +s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem)
23761 +{
23762 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_FILE_MAPPED);
23763 +}
23764 +
23765  struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
23766  {
23767         struct mem_cgroup *memcg = NULL;
23768 diff -NurpP --minimal linux-3.9.5/mm/oom_kill.c linux-3.9.5-vs2.3.6.5/mm/oom_kill.c
23769 --- linux-3.9.5/mm/oom_kill.c   2013-05-31 13:45:31.000000000 +0000
23770 +++ linux-3.9.5-vs2.3.6.5/mm/oom_kill.c 2013-05-31 14:47:11.000000000 +0000
23771 @@ -35,6 +35,8 @@
23772  #include <linux/freezer.h>
23773  #include <linux/ftrace.h>
23774  #include <linux/ratelimit.h>
23775 +#include <linux/reboot.h>
23776 +#include <linux/vs_context.h>
23777  
23778  #define CREATE_TRACE_POINTS
23779  #include <trace/events/oom.h>
23780 @@ -113,11 +115,18 @@ struct task_struct *find_lock_task_mm(st
23781  static bool oom_unkillable_task(struct task_struct *p,
23782                 const struct mem_cgroup *memcg, const nodemask_t *nodemask)
23783  {
23784 -       if (is_global_init(p))
23785 +       unsigned xid = vx_current_xid();
23786 +
23787 +       /* skip the init task, global and per guest */
23788 +       if (task_is_init(p))
23789                 return true;
23790         if (p->flags & PF_KTHREAD)
23791                 return true;
23792  
23793 +       /* skip other guest and host processes if oom in guest */
23794 +       if (xid && vx_task_xid(p) != xid)
23795 +               return true;
23796 +
23797         /* When mem_cgroup_out_of_memory() and p is not member of the group */
23798         if (memcg && !task_in_mem_cgroup(p, memcg))
23799                 return true;
23800 @@ -426,8 +435,8 @@ void oom_kill_process(struct task_struct
23801                 dump_header(p, gfp_mask, order, memcg, nodemask);
23802  
23803         task_lock(p);
23804 -       pr_err("%s: Kill process %d (%s) score %d or sacrifice child\n",
23805 -               message, task_pid_nr(p), p->comm, points);
23806 +       pr_err("%s: Kill process %d:#%u (%s) score %d or sacrifice child\n",
23807 +               message, task_pid_nr(p), p->xid, p->comm, points);
23808         task_unlock(p);
23809  
23810         /*
23811 @@ -472,8 +481,8 @@ void oom_kill_process(struct task_struct
23812  
23813         /* mm cannot safely be dereferenced after task_unlock(victim) */
23814         mm = victim->mm;
23815 -       pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23816 -               task_pid_nr(victim), victim->comm, K(victim->mm->total_vm),
23817 +       pr_err("Killed process %d:#%u (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23818 +               task_pid_nr(victim), victim->xid, victim->comm, K(victim->mm->total_vm),
23819                 K(get_mm_counter(victim->mm, MM_ANONPAGES)),
23820                 K(get_mm_counter(victim->mm, MM_FILEPAGES)));
23821         task_unlock(victim);
23822 @@ -543,6 +552,8 @@ int unregister_oom_notifier(struct notif
23823  }
23824  EXPORT_SYMBOL_GPL(unregister_oom_notifier);
23825  
23826 +long vs_oom_action(unsigned int);
23827 +
23828  /*
23829   * Try to acquire the OOM killer lock for the zones in zonelist.  Returns zero
23830   * if a parallel OOM killing is already taking place that includes a zone in
23831 @@ -655,7 +666,12 @@ void out_of_memory(struct zonelist *zone
23832         /* Found nothing?!?! Either we hang forever, or we panic. */
23833         if (!p) {
23834                 dump_header(NULL, gfp_mask, order, NULL, mpol_mask);
23835 -               panic("Out of memory and no killable processes...\n");
23836 +
23837 +               /* avoid panic for guest OOM */
23838 +               if (vx_current_xid())
23839 +                       vs_oom_action(LINUX_REBOOT_CMD_OOM);
23840 +               else
23841 +                       panic("Out of memory and no killable processes...\n");
23842         }
23843         if (PTR_ERR(p) != -1UL) {
23844                 oom_kill_process(p, gfp_mask, order, points, totalpages, NULL,
23845 diff -NurpP --minimal linux-3.9.5/mm/page_alloc.c linux-3.9.5-vs2.3.6.5/mm/page_alloc.c
23846 --- linux-3.9.5/mm/page_alloc.c 2013-05-31 13:45:31.000000000 +0000
23847 +++ linux-3.9.5-vs2.3.6.5/mm/page_alloc.c       2013-05-31 15:08:50.000000000 +0000
23848 @@ -59,6 +59,8 @@
23849  #include <linux/migrate.h>
23850  #include <linux/page-debug-flags.h>
23851  #include <linux/sched/rt.h>
23852 +#include <linux/vs_base.h>
23853 +#include <linux/vs_limit.h>
23854  
23855  #include <asm/tlbflush.h>
23856  #include <asm/div64.h>
23857 @@ -2873,6 +2875,9 @@ void si_meminfo(struct sysinfo *val)
23858         val->totalhigh = totalhigh_pages;
23859         val->freehigh = nr_free_highpages();
23860         val->mem_unit = PAGE_SIZE;
23861 +
23862 +       if (vx_flags(VXF_VIRT_MEM, 0))
23863 +               vx_vsi_meminfo(val);
23864  }
23865  
23866  EXPORT_SYMBOL(si_meminfo);
23867 @@ -2893,6 +2898,9 @@ void si_meminfo_node(struct sysinfo *val
23868         val->freehigh = 0;
23869  #endif
23870         val->mem_unit = PAGE_SIZE;
23871 +
23872 +       if (vx_flags(VXF_VIRT_MEM, 0))
23873 +               vx_vsi_meminfo(val);
23874  }
23875  #endif
23876  
23877 diff -NurpP --minimal linux-3.9.5/mm/pgtable-generic.c linux-3.9.5-vs2.3.6.5/mm/pgtable-generic.c
23878 --- linux-3.9.5/mm/pgtable-generic.c    2013-02-19 13:58:57.000000000 +0000
23879 +++ linux-3.9.5-vs2.3.6.5/mm/pgtable-generic.c  2013-05-31 14:47:11.000000000 +0000
23880 @@ -6,6 +6,8 @@
23881   *  Copyright (C) 2010  Linus Torvalds
23882   */
23883  
23884 +#include <linux/mm.h>
23885 +
23886  #include <linux/pagemap.h>
23887  #include <asm/tlb.h>
23888  #include <asm-generic/pgtable.h>
23889 diff -NurpP --minimal linux-3.9.5/mm/shmem.c linux-3.9.5-vs2.3.6.5/mm/shmem.c
23890 --- linux-3.9.5/mm/shmem.c      2013-05-31 13:45:31.000000000 +0000
23891 +++ linux-3.9.5-vs2.3.6.5/mm/shmem.c    2013-05-31 14:47:11.000000000 +0000
23892 @@ -1909,7 +1909,7 @@ static int shmem_statfs(struct dentry *d
23893  {
23894         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
23895  
23896 -       buf->f_type = TMPFS_MAGIC;
23897 +       buf->f_type = TMPFS_SUPER_MAGIC;
23898         buf->f_bsize = PAGE_CACHE_SIZE;
23899         buf->f_namelen = NAME_MAX;
23900         if (sbinfo->max_blocks) {
23901 @@ -2606,7 +2606,7 @@ int shmem_fill_super(struct super_block
23902         sb->s_maxbytes = MAX_LFS_FILESIZE;
23903         sb->s_blocksize = PAGE_CACHE_SIZE;
23904         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
23905 -       sb->s_magic = TMPFS_MAGIC;
23906 +       sb->s_magic = TMPFS_SUPER_MAGIC;
23907         sb->s_op = &shmem_ops;
23908         sb->s_time_gran = 1;
23909  #ifdef CONFIG_TMPFS_XATTR
23910 diff -NurpP --minimal linux-3.9.5/mm/slab.c linux-3.9.5-vs2.3.6.5/mm/slab.c
23911 --- linux-3.9.5/mm/slab.c       2013-05-31 13:45:31.000000000 +0000
23912 +++ linux-3.9.5-vs2.3.6.5/mm/slab.c     2013-05-31 14:47:11.000000000 +0000
23913 @@ -429,6 +429,8 @@ static void kmem_list3_init(struct kmem_
23914  #define STATS_INC_FREEMISS(x)  do { } while (0)
23915  #endif
23916  
23917 +#include "slab_vs.h"
23918 +
23919  #if DEBUG
23920  
23921  /*
23922 @@ -3438,6 +3440,7 @@ retry:
23923  
23924         obj = slab_get_obj(cachep, slabp, nodeid);
23925         check_slabp(cachep, slabp);
23926 +       vx_slab_alloc(cachep, flags);
23927         l3->free_objects--;
23928         /* move slabp to correct slabp list: */
23929         list_del(&slabp->list);
23930 @@ -3517,6 +3520,7 @@ slab_alloc_node(struct kmem_cache *cache
23931         /* ___cache_alloc_node can fall back to other nodes */
23932         ptr = ____cache_alloc_node(cachep, flags, nodeid);
23933    out:
23934 +       vx_slab_alloc(cachep, flags);
23935         local_irq_restore(save_flags);
23936         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
23937         kmemleak_alloc_recursive(ptr, cachep->object_size, 1, cachep->flags,
23938 @@ -3709,6 +3713,7 @@ static inline void __cache_free(struct k
23939         check_irq_off();
23940         kmemleak_free_recursive(objp, cachep->flags);
23941         objp = cache_free_debugcheck(cachep, objp, caller);
23942 +       vx_slab_free(cachep);
23943  
23944         kmemcheck_slab_free(cachep, objp, cachep->object_size);
23945  
23946 diff -NurpP --minimal linux-3.9.5/mm/slab_vs.h linux-3.9.5-vs2.3.6.5/mm/slab_vs.h
23947 --- linux-3.9.5/mm/slab_vs.h    1970-01-01 00:00:00.000000000 +0000
23948 +++ linux-3.9.5-vs2.3.6.5/mm/slab_vs.h  2013-05-31 14:47:11.000000000 +0000
23949 @@ -0,0 +1,29 @@
23950 +
23951 +#include <linux/vserver/context.h>
23952 +
23953 +#include <linux/vs_context.h>
23954 +
23955 +static inline
23956 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
23957 +{
23958 +       int what = gfp_zone(cachep->allocflags);
23959 +       struct vx_info *vxi = current_vx_info();
23960 +
23961 +       if (!vxi)
23962 +               return;
23963 +
23964 +       atomic_add(cachep->size, &vxi->cacct.slab[what]);
23965 +}
23966 +
23967 +static inline
23968 +void vx_slab_free(struct kmem_cache *cachep)
23969 +{
23970 +       int what = gfp_zone(cachep->allocflags);
23971 +       struct vx_info *vxi = current_vx_info();
23972 +
23973 +       if (!vxi)
23974 +               return;
23975 +
23976 +       atomic_sub(cachep->size, &vxi->cacct.slab[what]);
23977 +}
23978 +
23979 diff -NurpP --minimal linux-3.9.5/mm/swapfile.c linux-3.9.5-vs2.3.6.5/mm/swapfile.c
23980 --- linux-3.9.5/mm/swapfile.c   2013-05-31 13:45:31.000000000 +0000
23981 +++ linux-3.9.5-vs2.3.6.5/mm/swapfile.c 2013-05-31 14:47:11.000000000 +0000
23982 @@ -39,6 +39,7 @@
23983  #include <asm/tlbflush.h>
23984  #include <linux/swapops.h>
23985  #include <linux/page_cgroup.h>
23986 +#include <linux/vs_base.h>
23987  
23988  static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
23989                                  unsigned char);
23990 @@ -1767,6 +1768,16 @@ static int swap_show(struct seq_file *sw
23991  
23992         if (si == SEQ_START_TOKEN) {
23993                 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
23994 +               if (vx_flags(VXF_VIRT_MEM, 0)) {
23995 +                       struct sysinfo si;
23996 +
23997 +                       vx_vsi_swapinfo(&si);
23998 +                       if (si.totalswap < (1 << 10))
23999 +                               return 0;
24000 +                       seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
24001 +                               "hdv0", "partition", si.totalswap >> 10,
24002 +                               (si.totalswap - si.freeswap) >> 10, -1);
24003 +               }
24004                 return 0;
24005         }
24006  
24007 @@ -2195,6 +2206,8 @@ void si_swapinfo(struct sysinfo *val)
24008         val->freeswap = atomic_long_read(&nr_swap_pages) + nr_to_be_unused;
24009         val->totalswap = total_swap_pages + nr_to_be_unused;
24010         spin_unlock(&swap_lock);
24011 +       if (vx_flags(VXF_VIRT_MEM, 0))
24012 +               vx_vsi_swapinfo(val);
24013  }
24014  
24015  /*
24016 diff -NurpP --minimal linux-3.9.5/net/bridge/br_multicast.c linux-3.9.5-vs2.3.6.5/net/bridge/br_multicast.c
24017 --- linux-3.9.5/net/bridge/br_multicast.c       2013-05-31 13:45:31.000000000 +0000
24018 +++ linux-3.9.5-vs2.3.6.5/net/bridge/br_multicast.c     2013-05-31 17:17:53.000000000 +0000
24019 @@ -443,7 +443,7 @@ static struct sk_buff *br_ip6_multicast_
24020         ip6h->hop_limit = 1;
24021         ipv6_addr_set(&ip6h->daddr, htonl(0xff020000), 0, 0, htonl(1));
24022         if (ipv6_dev_get_saddr(dev_net(br->dev), br->dev, &ip6h->daddr, 0,
24023 -                              &ip6h->saddr)) {
24024 +                              &ip6h->saddr, NULL)) {
24025                 kfree_skb(skb);
24026                 return NULL;
24027         }
24028 diff -NurpP --minimal linux-3.9.5/net/core/dev.c linux-3.9.5-vs2.3.6.5/net/core/dev.c
24029 --- linux-3.9.5/net/core/dev.c  2013-06-11 12:22:40.000000000 +0000
24030 +++ linux-3.9.5-vs2.3.6.5/net/core/dev.c        2013-05-31 18:37:38.000000000 +0000
24031 @@ -122,6 +122,7 @@
24032  #include <linux/in.h>
24033  #include <linux/jhash.h>
24034  #include <linux/random.h>
24035 +#include <linux/vs_inet.h>
24036  #include <trace/events/napi.h>
24037  #include <trace/events/net.h>
24038  #include <trace/events/skb.h>
24039 @@ -662,7 +663,8 @@ struct net_device *__dev_get_by_name(str
24040         struct hlist_head *head = dev_name_hash(net, name);
24041  
24042         hlist_for_each_entry(dev, head, name_hlist)
24043 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24044 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24045 +                   nx_dev_visible(current_nx_info(), dev))
24046                         return dev;
24047  
24048         return NULL;
24049 @@ -687,7 +689,8 @@ struct net_device *dev_get_by_name_rcu(s
24050         struct hlist_head *head = dev_name_hash(net, name);
24051  
24052         hlist_for_each_entry_rcu(dev, head, name_hlist)
24053 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24054 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24055 +                   nx_dev_visible(current_nx_info(), dev))
24056                         return dev;
24057  
24058         return NULL;
24059 @@ -737,7 +740,8 @@ struct net_device *__dev_get_by_index(st
24060         struct hlist_head *head = dev_index_hash(net, ifindex);
24061  
24062         hlist_for_each_entry(dev, head, index_hlist)
24063 -               if (dev->ifindex == ifindex)
24064 +               if ((dev->ifindex == ifindex) &&
24065 +                   nx_dev_visible(current_nx_info(), dev))
24066                         return dev;
24067  
24068         return NULL;
24069 @@ -755,7 +759,7 @@ EXPORT_SYMBOL(__dev_get_by_index);
24070   *     about locking. The caller must hold RCU lock.
24071   */
24072  
24073 -struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
24074 +struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex)
24075  {
24076         struct net_device *dev;
24077         struct hlist_head *head = dev_index_hash(net, ifindex);
24078 @@ -766,6 +770,16 @@ struct net_device *dev_get_by_index_rcu(
24079  
24080         return NULL;
24081  }
24082 +EXPORT_SYMBOL(dev_get_by_index_real_rcu);
24083 +
24084 +struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
24085 +{
24086 +       struct net_device *dev = dev_get_by_index_real_rcu(net, ifindex);
24087 +
24088 +       if (nx_dev_visible(current_nx_info(), dev))
24089 +               return dev;
24090 +       return NULL;
24091 +}
24092  EXPORT_SYMBOL(dev_get_by_index_rcu);
24093  
24094  
24095 @@ -814,7 +828,8 @@ struct net_device *dev_getbyhwaddr_rcu(s
24096  
24097         for_each_netdev_rcu(net, dev)
24098                 if (dev->type == type &&
24099 -                   !memcmp(dev->dev_addr, ha, dev->addr_len))
24100 +                   !memcmp(dev->dev_addr, ha, dev->addr_len) &&
24101 +                   nx_dev_visible(current_nx_info(), dev))
24102                         return dev;
24103  
24104         return NULL;
24105 @@ -826,9 +841,11 @@ struct net_device *__dev_getfirstbyhwtyp
24106         struct net_device *dev;
24107  
24108         ASSERT_RTNL();
24109 -       for_each_netdev(net, dev)
24110 -               if (dev->type == type)
24111 +       for_each_netdev(net, dev) {
24112 +               if ((dev->type == type) &&
24113 +                   nx_dev_visible(current_nx_info(), dev))
24114                         return dev;
24115 +       }
24116  
24117         return NULL;
24118  }
24119 @@ -840,7 +857,8 @@ struct net_device *dev_getfirstbyhwtype(
24120  
24121         rcu_read_lock();
24122         for_each_netdev_rcu(net, dev)
24123 -               if (dev->type == type) {
24124 +               if ((dev->type == type) &&
24125 +                   nx_dev_visible(current_nx_info(), dev)) {
24126                         dev_hold(dev);
24127                         ret = dev;
24128                         break;
24129 @@ -868,7 +886,8 @@ struct net_device *dev_get_by_flags_rcu(
24130  
24131         ret = NULL;
24132         for_each_netdev_rcu(net, dev) {
24133 -               if (((dev->flags ^ if_flags) & mask) == 0) {
24134 +               if ((((dev->flags ^ if_flags) & mask) == 0) &&
24135 +                       nx_dev_visible(current_nx_info(), dev)) {
24136                         ret = dev;
24137                         break;
24138                 }
24139 @@ -946,6 +965,8 @@ static int __dev_alloc_name(struct net *
24140                                 continue;
24141                         if (i < 0 || i >= max_netdevices)
24142                                 continue;
24143 +                       if (!nx_dev_visible(current_nx_info(), d))
24144 +                               continue;
24145  
24146                         /*  avoid cases where sscanf is not exact inverse of printf */
24147                         snprintf(buf, IFNAMSIZ, name, i);
24148 diff -NurpP --minimal linux-3.9.5/net/core/net-procfs.c linux-3.9.5-vs2.3.6.5/net/core/net-procfs.c
24149 --- linux-3.9.5/net/core/net-procfs.c   2013-05-31 13:45:32.000000000 +0000
24150 +++ linux-3.9.5-vs2.3.6.5/net/core/net-procfs.c 2013-06-01 10:40:52.000000000 +0000
24151 @@ -1,6 +1,7 @@
24152  #include <linux/netdevice.h>
24153  #include <linux/proc_fs.h>
24154  #include <linux/seq_file.h>
24155 +#include <linux/vs_inet.h>
24156  #include <net/wext.h>
24157  
24158  #define BUCKET_SPACE (32 - NETDEV_HASHBITS - 1)
24159 @@ -77,8 +78,13 @@ static void dev_seq_stop(struct seq_file
24160  static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
24161  {
24162         struct rtnl_link_stats64 temp;
24163 -       const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
24164 +       const struct rtnl_link_stats64 *stats;
24165 +
24166 +       /* device visible inside network context? */
24167 +       if (!nx_dev_visible(current_nx_info(), dev))
24168 +               return;
24169  
24170 +       stats = dev_get_stats(dev, &temp);
24171         seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
24172                    "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
24173                    dev->name, stats->rx_bytes, stats->rx_packets,
24174 diff -NurpP --minimal linux-3.9.5/net/core/rtnetlink.c linux-3.9.5-vs2.3.6.5/net/core/rtnetlink.c
24175 --- linux-3.9.5/net/core/rtnetlink.c    2013-05-31 13:45:32.000000000 +0000
24176 +++ linux-3.9.5-vs2.3.6.5/net/core/rtnetlink.c  2013-05-31 17:17:54.000000000 +0000
24177 @@ -1085,6 +1085,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
24178                 hlist_for_each_entry_rcu(dev, head, index_hlist) {
24179                         if (idx < s_idx)
24180                                 goto cont;
24181 +                       if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
24182 +                               continue;
24183                         if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
24184                                              NETLINK_CB(cb->skb).portid,
24185                                              cb->nlh->nlmsg_seq, 0,
24186 @@ -1974,6 +1976,9 @@ void rtmsg_ifinfo(int type, struct net_d
24187         int err = -ENOBUFS;
24188         size_t if_info_size;
24189  
24190 +       if (!nx_dev_visible(current_nx_info(), dev))
24191 +               return;
24192 +
24193         skb = nlmsg_new((if_info_size = if_nlmsg_size(dev, 0)), GFP_KERNEL);
24194         if (skb == NULL)
24195                 goto errout;
24196 diff -NurpP --minimal linux-3.9.5/net/core/sock.c linux-3.9.5-vs2.3.6.5/net/core/sock.c
24197 --- linux-3.9.5/net/core/sock.c 2013-06-11 12:22:40.000000000 +0000
24198 +++ linux-3.9.5-vs2.3.6.5/net/core/sock.c       2013-05-31 17:17:54.000000000 +0000
24199 @@ -132,6 +132,10 @@
24200  #include <net/netprio_cgroup.h>
24201  
24202  #include <linux/filter.h>
24203 +#include <linux/vs_socket.h>
24204 +#include <linux/vs_limit.h>
24205 +#include <linux/vs_context.h>
24206 +#include <linux/vs_network.h>
24207  
24208  #include <trace/events/sock.h>
24209  
24210 @@ -1257,6 +1261,8 @@ static struct sock *sk_prot_alloc(struct
24211                         goto out_free_sec;
24212                 sk_tx_queue_clear(sk);
24213         }
24214 +               sock_vx_init(sk);
24215 +               sock_nx_init(sk);
24216  
24217         return sk;
24218  
24219 @@ -1367,6 +1373,11 @@ static void __sk_free(struct sock *sk)
24220                 put_cred(sk->sk_peer_cred);
24221         put_pid(sk->sk_peer_pid);
24222         put_net(sock_net(sk));
24223 +       vx_sock_dec(sk);
24224 +       clr_vx_info(&sk->sk_vx_info);
24225 +       sk->sk_xid = -1;
24226 +       clr_nx_info(&sk->sk_nx_info);
24227 +       sk->sk_nid = -1;
24228         sk_prot_free(sk->sk_prot_creator, sk);
24229  }
24230  
24231 @@ -1427,6 +1438,8 @@ struct sock *sk_clone_lock(const struct
24232  
24233                 /* SANITY */
24234                 get_net(sock_net(newsk));
24235 +               sock_vx_init(newsk);
24236 +               sock_nx_init(newsk);
24237                 sk_node_init(&newsk->sk_node);
24238                 sock_lock_init(newsk);
24239                 bh_lock_sock(newsk);
24240 @@ -1483,6 +1496,12 @@ struct sock *sk_clone_lock(const struct
24241                 smp_wmb();
24242                 atomic_set(&newsk->sk_refcnt, 2);
24243  
24244 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
24245 +               newsk->sk_xid = sk->sk_xid;
24246 +               vx_sock_inc(newsk);
24247 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
24248 +               newsk->sk_nid = sk->sk_nid;
24249 +
24250                 /*
24251                  * Increment the counter in the same struct proto as the master
24252                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
24253 @@ -2278,6 +2297,12 @@ void sock_init_data(struct socket *sock,
24254  
24255         sk->sk_stamp = ktime_set(-1L, 0);
24256  
24257 +       set_vx_info(&sk->sk_vx_info, current_vx_info());
24258 +       sk->sk_xid = vx_current_xid();
24259 +       vx_sock_inc(sk);
24260 +       set_nx_info(&sk->sk_nx_info, current_nx_info());
24261 +       sk->sk_nid = nx_current_nid();
24262 +
24263         /*
24264          * Before updating sk_refcnt, we must commit prior changes to memory
24265          * (Documentation/RCU/rculist_nulls.txt for details)
24266 diff -NurpP --minimal linux-3.9.5/net/ipv4/af_inet.c linux-3.9.5-vs2.3.6.5/net/ipv4/af_inet.c
24267 --- linux-3.9.5/net/ipv4/af_inet.c      2013-05-31 13:45:32.000000000 +0000
24268 +++ linux-3.9.5-vs2.3.6.5/net/ipv4/af_inet.c    2013-06-03 17:22:33.000000000 +0000
24269 @@ -118,6 +118,7 @@
24270  #ifdef CONFIG_IP_MROUTE
24271  #include <linux/mroute.h>
24272  #endif
24273 +#include <linux/vs_limit.h>
24274  
24275  
24276  /* The inetsw table contains everything that inet_create needs to
24277 @@ -336,10 +337,13 @@ lookup_protocol:
24278         }
24279  
24280         err = -EPERM;
24281 +       if ((protocol == IPPROTO_ICMP) &&
24282 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
24283 +               goto override;
24284         if (sock->type == SOCK_RAW && !kern &&
24285             !ns_capable(net->user_ns, CAP_NET_RAW))
24286                 goto out_rcu_unlock;
24287 -
24288 +override:
24289         sock->ops = answer->ops;
24290         answer_prot = answer->prot;
24291         answer_no_check = answer->no_check;
24292 @@ -460,6 +464,7 @@ int inet_bind(struct socket *sock, struc
24293         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
24294         struct sock *sk = sock->sk;
24295         struct inet_sock *inet = inet_sk(sk);
24296 +       struct nx_v4_sock_addr nsa;
24297         struct net *net = sock_net(sk);
24298         unsigned short snum;
24299         int chk_addr_ret;
24300 @@ -484,7 +489,11 @@ int inet_bind(struct socket *sock, struc
24301                         goto out;
24302         }
24303  
24304 -       chk_addr_ret = inet_addr_type(net, addr->sin_addr.s_addr);
24305 +       err = v4_map_sock_addr(inet, addr, &nsa);
24306 +       if (err)
24307 +               goto out;
24308 +
24309 +       chk_addr_ret = inet_addr_type(net, nsa.saddr);
24310  
24311         /* Not specified by any standard per-se, however it breaks too
24312          * many applications when removed.  It is unfortunate since
24313 @@ -496,7 +505,7 @@ int inet_bind(struct socket *sock, struc
24314         err = -EADDRNOTAVAIL;
24315         if (!sysctl_ip_nonlocal_bind &&
24316             !(inet->freebind || inet->transparent) &&
24317 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
24318 +           nsa.saddr != htonl(INADDR_ANY) &&
24319             chk_addr_ret != RTN_LOCAL &&
24320             chk_addr_ret != RTN_MULTICAST &&
24321             chk_addr_ret != RTN_BROADCAST)
24322 @@ -522,7 +531,7 @@ int inet_bind(struct socket *sock, struc
24323         if (sk->sk_state != TCP_CLOSE || inet->inet_num)
24324                 goto out_release_sock;
24325  
24326 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24327 +       v4_set_sock_addr(inet, &nsa);
24328         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24329                 inet->inet_saddr = 0;  /* Use device */
24330  
24331 @@ -741,11 +750,13 @@ int inet_getname(struct socket *sock, st
24332                      peer == 1))
24333                         return -ENOTCONN;
24334                 sin->sin_port = inet->inet_dport;
24335 -               sin->sin_addr.s_addr = inet->inet_daddr;
24336 +               sin->sin_addr.s_addr =
24337 +                       nx_map_sock_lback(sk->sk_nx_info, inet->inet_daddr);
24338         } else {
24339                 __be32 addr = inet->inet_rcv_saddr;
24340                 if (!addr)
24341                         addr = inet->inet_saddr;
24342 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
24343                 sin->sin_port = inet->inet_sport;
24344                 sin->sin_addr.s_addr = addr;
24345         }
24346 diff -NurpP --minimal linux-3.9.5/net/ipv4/arp.c linux-3.9.5-vs2.3.6.5/net/ipv4/arp.c
24347 --- linux-3.9.5/net/ipv4/arp.c  2013-05-31 13:45:32.000000000 +0000
24348 +++ linux-3.9.5-vs2.3.6.5/net/ipv4/arp.c        2013-05-31 17:17:54.000000000 +0000
24349 @@ -1317,6 +1317,7 @@ static void arp_format_neigh_entry(struc
24350         struct net_device *dev = n->dev;
24351         int hatype = dev->type;
24352  
24353 +       /* FIXME: check for network context */
24354         read_lock(&n->lock);
24355         /* Convert hardware address to XX:XX:XX:XX ... form. */
24356  #if IS_ENABLED(CONFIG_AX25)
24357 @@ -1348,6 +1349,7 @@ static void arp_format_pneigh_entry(stru
24358         int hatype = dev ? dev->type : 0;
24359         char tbuf[16];
24360  
24361 +       /* FIXME: check for network context */
24362         sprintf(tbuf, "%pI4", n->key);
24363         seq_printf(seq, "%-16s 0x%-10x0x%-10x%s     *        %s\n",
24364                    tbuf, hatype, ATF_PUBL | ATF_PERM, "00:00:00:00:00:00",
24365 diff -NurpP --minimal linux-3.9.5/net/ipv4/devinet.c linux-3.9.5-vs2.3.6.5/net/ipv4/devinet.c
24366 --- linux-3.9.5/net/ipv4/devinet.c      2013-05-31 13:45:32.000000000 +0000
24367 +++ linux-3.9.5-vs2.3.6.5/net/ipv4/devinet.c    2013-05-31 17:17:54.000000000 +0000
24368 @@ -522,6 +522,7 @@ struct in_device *inetdev_by_index(struc
24369  }
24370  EXPORT_SYMBOL(inetdev_by_index);
24371  
24372 +
24373  /* Called only from RTNL semaphored context. No locks. */
24374  
24375  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
24376 @@ -940,6 +941,8 @@ int devinet_ioctl(struct net *net, unsig
24377  
24378         in_dev = __in_dev_get_rtnl(dev);
24379         if (in_dev) {
24380 +               struct nx_info *nxi = current_nx_info();
24381 +
24382                 if (tryaddrmatch) {
24383                         /* Matthias Andree */
24384                         /* compare label and address (4.4BSD style) */
24385 @@ -948,6 +951,8 @@ int devinet_ioctl(struct net *net, unsig
24386                            This is checked above. */
24387                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24388                              ifap = &ifa->ifa_next) {
24389 +                               if (!nx_v4_ifa_visible(nxi, ifa))
24390 +                                       continue;
24391                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
24392                                     sin_orig.sin_addr.s_addr ==
24393                                                         ifa->ifa_local) {
24394 @@ -960,9 +965,12 @@ int devinet_ioctl(struct net *net, unsig
24395                    comparing just the label */
24396                 if (!ifa) {
24397                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24398 -                            ifap = &ifa->ifa_next)
24399 +                            ifap = &ifa->ifa_next) {
24400 +                               if (!nx_v4_ifa_visible(nxi, ifa))
24401 +                                       continue;
24402                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
24403                                         break;
24404 +                       }
24405                 }
24406         }
24407  
24408 @@ -1116,6 +1124,8 @@ static int inet_gifconf(struct net_devic
24409                 goto out;
24410  
24411         for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
24412 +               if (!nx_v4_ifa_visible(current_nx_info(), ifa))
24413 +                       continue;
24414                 if (!buf) {
24415                         done += sizeof(ifr);
24416                         continue;
24417 @@ -1519,6 +1529,7 @@ static int inet_dump_ifaddr(struct sk_bu
24418         struct net_device *dev;
24419         struct in_device *in_dev;
24420         struct in_ifaddr *ifa;
24421 +       struct sock *sk = skb->sk;
24422         struct hlist_head *head;
24423  
24424         s_h = cb->args[0];
24425 @@ -1540,6 +1551,8 @@ static int inet_dump_ifaddr(struct sk_bu
24426  
24427                         for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
24428                              ifa = ifa->ifa_next, ip_idx++) {
24429 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
24430 +                               continue;
24431                                 if (ip_idx < s_ip_idx)
24432                                         continue;
24433                                 if (inet_fill_ifaddr(skb, ifa,
24434 diff -NurpP --minimal linux-3.9.5/net/ipv4/fib_trie.c linux-3.9.5-vs2.3.6.5/net/ipv4/fib_trie.c
24435 --- linux-3.9.5/net/ipv4/fib_trie.c     2013-05-31 13:45:32.000000000 +0000
24436 +++ linux-3.9.5-vs2.3.6.5/net/ipv4/fib_trie.c   2013-05-31 17:17:54.000000000 +0000
24437 @@ -2548,6 +2548,7 @@ static int fib_route_seq_show(struct seq
24438                             || fa->fa_type == RTN_MULTICAST)
24439                                 continue;
24440  
24441 +                       /* FIXME: check for network context? */
24442                         if (fi)
24443                                 seq_printf(seq,
24444                                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t"
24445 diff -NurpP --minimal linux-3.9.5/net/ipv4/inet_connection_sock.c linux-3.9.5-vs2.3.6.5/net/ipv4/inet_connection_sock.c
24446 --- linux-3.9.5/net/ipv4/inet_connection_sock.c 2013-05-31 13:45:32.000000000 +0000
24447 +++ linux-3.9.5-vs2.3.6.5/net/ipv4/inet_connection_sock.c       2013-05-31 18:29:56.000000000 +0000
24448 @@ -53,6 +53,37 @@ void inet_get_local_port_range(int *low,
24449  }
24450  EXPORT_SYMBOL(inet_get_local_port_range);
24451  
24452 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24453 +{
24454 +       __be32  sk1_rcv_saddr = sk_rcv_saddr(sk1),
24455 +               sk2_rcv_saddr = sk_rcv_saddr(sk2);
24456 +
24457 +       if (inet_v6_ipv6only(sk2))
24458 +               return 0;
24459 +
24460 +       if (sk1_rcv_saddr &&
24461 +           sk2_rcv_saddr &&
24462 +           sk1_rcv_saddr == sk2_rcv_saddr)
24463 +               return 1;
24464 +
24465 +       if (sk1_rcv_saddr &&
24466 +           !sk2_rcv_saddr &&
24467 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
24468 +               return 1;
24469 +
24470 +       if (sk2_rcv_saddr &&
24471 +           !sk1_rcv_saddr &&
24472 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
24473 +               return 1;
24474 +
24475 +       if (!sk1_rcv_saddr &&
24476 +           !sk2_rcv_saddr &&
24477 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
24478 +               return 1;
24479 +
24480 +       return 0;
24481 +}
24482 +
24483  int inet_csk_bind_conflict(const struct sock *sk,
24484                            const struct inet_bind_bucket *tb, bool relax)
24485  {
24486 @@ -79,17 +110,12 @@ int inet_csk_bind_conflict(const struct
24487                             (!reuseport || !sk2->sk_reuseport ||
24488                             (sk2->sk_state != TCP_TIME_WAIT &&
24489                              !uid_eq(uid, sock_i_uid(sk2))))) {
24490 -                               const __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
24491 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr(sk) ||
24492 -                                   sk2_rcv_saddr == sk_rcv_saddr(sk))
24493 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
24494                                         break;
24495                         }
24496                         if (!relax && reuse && sk2->sk_reuse &&
24497                             sk2->sk_state != TCP_LISTEN) {
24498 -                               const __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
24499 -
24500 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr(sk) ||
24501 -                                   sk2_rcv_saddr == sk_rcv_saddr(sk))
24502 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
24503                                         break;
24504                         }
24505                 }
24506 diff -NurpP --minimal linux-3.9.5/net/ipv4/inet_diag.c linux-3.9.5-vs2.3.6.5/net/ipv4/inet_diag.c
24507 --- linux-3.9.5/net/ipv4/inet_diag.c    2013-02-19 13:58:58.000000000 +0000
24508 +++ linux-3.9.5-vs2.3.6.5/net/ipv4/inet_diag.c  2013-05-31 17:17:54.000000000 +0000
24509 @@ -31,6 +31,8 @@
24510  
24511  #include <linux/inet.h>
24512  #include <linux/stddef.h>
24513 +#include <linux/vs_network.h>
24514 +#include <linux/vs_inet.h>
24515  
24516  #include <linux/inet_diag.h>
24517  #include <linux/sock_diag.h>
24518 @@ -106,8 +108,10 @@ int inet_sk_diag_fill(struct sock *sk, s
24519  
24520         r->id.idiag_sport = inet->inet_sport;
24521         r->id.idiag_dport = inet->inet_dport;
24522 -       r->id.idiag_src[0] = inet->inet_rcv_saddr;
24523 -       r->id.idiag_dst[0] = inet->inet_daddr;
24524 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info,
24525 +               inet->inet_rcv_saddr);
24526 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info,
24527 +               inet->inet_daddr);
24528  
24529         if (nla_put_u8(skb, INET_DIAG_SHUTDOWN, sk->sk_shutdown))
24530                 goto errout;
24531 @@ -242,8 +246,8 @@ static int inet_twsk_diag_fill(struct in
24532         sock_diag_save_cookie(tw, r->id.idiag_cookie);
24533         r->id.idiag_sport     = tw->tw_sport;
24534         r->id.idiag_dport     = tw->tw_dport;
24535 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
24536 -       r->id.idiag_dst[0]    = tw->tw_daddr;
24537 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
24538 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
24539         r->idiag_state        = tw->tw_substate;
24540         r->idiag_timer        = 3;
24541         r->idiag_expires      = DIV_ROUND_UP(tmo * 1000, HZ);
24542 @@ -287,12 +291,14 @@ int inet_diag_dump_one_icsk(struct inet_
24543  
24544         err = -EINVAL;
24545         if (req->sdiag_family == AF_INET) {
24546 +               /* TODO: lback */
24547                 sk = inet_lookup(net, hashinfo, req->id.idiag_dst[0],
24548                                  req->id.idiag_dport, req->id.idiag_src[0],
24549                                  req->id.idiag_sport, req->id.idiag_if);
24550         }
24551  #if IS_ENABLED(CONFIG_IPV6)
24552         else if (req->sdiag_family == AF_INET6) {
24553 +               /* TODO: lback */
24554                 sk = inet6_lookup(net, hashinfo,
24555                                   (struct in6_addr *)req->id.idiag_dst,
24556                                   req->id.idiag_dport,
24557 @@ -494,6 +500,7 @@ int inet_diag_bc_sk(const struct nlattr
24558         } else
24559  #endif
24560         {
24561 +                       /* TODO: lback */
24562                 entry.saddr = &inet->inet_rcv_saddr;
24563                 entry.daddr = &inet->inet_daddr;
24564         }
24565 @@ -652,6 +659,7 @@ static int inet_twsk_diag_dump(struct in
24566                 } else
24567  #endif
24568                 {
24569 +                       /* TODO: lback */
24570                         entry.saddr = &tw->tw_rcv_saddr;
24571                         entry.daddr = &tw->tw_daddr;
24572                 }
24573 @@ -730,8 +738,8 @@ static int inet_diag_fill_req(struct sk_
24574  
24575         r->id.idiag_sport = inet->inet_sport;
24576         r->id.idiag_dport = ireq->rmt_port;
24577 -       r->id.idiag_src[0] = ireq->loc_addr;
24578 -       r->id.idiag_dst[0] = ireq->rmt_addr;
24579 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
24580 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
24581         r->idiag_expires = jiffies_to_msecs(tmo);
24582         r->idiag_rqueue = 0;
24583         r->idiag_wqueue = 0;
24584 @@ -794,6 +802,7 @@ static int inet_diag_dump_reqs(struct sk
24585                             r->id.idiag_dport)
24586                                 continue;
24587  
24588 +                       /* TODO: lback */
24589                         if (bc) {
24590                                 inet_diag_req_addrs(sk, req, &entry);
24591                                 entry.dport = ntohs(ireq->rmt_port);
24592 @@ -850,6 +859,8 @@ void inet_diag_dump_icsk(struct inet_has
24593                                 if (!net_eq(sock_net(sk), net))
24594                                         continue;
24595  
24596 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24597 +                                       continue;
24598                                 if (num < s_num) {
24599                                         num++;
24600                                         continue;
24601 @@ -922,6 +933,8 @@ skip_listen_ht:
24602  
24603                         if (!net_eq(sock_net(sk), net))
24604                                 continue;
24605 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24606 +                               continue;
24607                         if (num < s_num)
24608                                 goto next_normal;
24609                         if (!(r->idiag_states & (1 << sk->sk_state)))
24610 @@ -950,7 +963,8 @@ next_normal:
24611                                     &head->twchain) {
24612                                 if (!net_eq(twsk_net(tw), net))
24613                                         continue;
24614 -
24615 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
24616 +                                       continue;
24617                                 if (num < s_num)
24618                                         goto next_dying;
24619                                 if (r->sdiag_family != AF_UNSPEC &&
24620 diff -NurpP --minimal linux-3.9.5/net/ipv4/inet_hashtables.c linux-3.9.5-vs2.3.6.5/net/ipv4/inet_hashtables.c
24621 --- linux-3.9.5/net/ipv4/inet_hashtables.c      2013-05-31 13:45:32.000000000 +0000
24622 +++ linux-3.9.5-vs2.3.6.5/net/ipv4/inet_hashtables.c    2013-05-31 18:20:50.000000000 +0000
24623 @@ -22,6 +22,7 @@
24624  #include <net/inet_connection_sock.h>
24625  #include <net/inet_hashtables.h>
24626  #include <net/secure_seq.h>
24627 +#include <net/route.h>
24628  #include <net/ip.h>
24629  
24630  /*
24631 @@ -156,6 +157,11 @@ static inline int compute_score(struct s
24632                         if (rcv_saddr != daddr)
24633                                 return -1;
24634                         score += 4;
24635 +               } else {
24636 +                       /* block non nx_info ips */
24637 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
24638 +                               daddr, NXA_MASK_BIND))
24639 +                               return -1;
24640                 }
24641                 if (sk->sk_bound_dev_if) {
24642                         if (sk->sk_bound_dev_if != dif)
24643 @@ -173,7 +179,6 @@ static inline int compute_score(struct s
24644   * wildcarded during the search since they can never be otherwise.
24645   */
24646  
24647 -
24648  struct sock *__inet_lookup_listener(struct net *net,
24649                                     struct inet_hashinfo *hashinfo,
24650                                     const __be32 saddr, __be16 sport,
24651 @@ -209,6 +214,7 @@ begin:
24652                         phash = next_pseudo_random32(phash);
24653                 }
24654         }
24655 +
24656         /*
24657          * if the nulls value we got at the end of this lookup is
24658          * not the expected one, we must restart lookup.
24659 diff -NurpP --minimal linux-3.9.5/net/ipv4/netfilter.c linux-3.9.5-vs2.3.6.5/net/ipv4/netfilter.c
24660 --- linux-3.9.5/net/ipv4/netfilter.c    2012-12-11 03:30:57.000000000 +0000
24661 +++ linux-3.9.5-vs2.3.6.5/net/ipv4/netfilter.c  2013-05-31 17:17:54.000000000 +0000
24662 @@ -6,7 +6,7 @@
24663  #include <linux/skbuff.h>
24664  #include <linux/gfp.h>
24665  #include <linux/export.h>
24666 -#include <net/route.h>
24667 +// #include <net/route.h>
24668  #include <net/xfrm.h>
24669  #include <net/ip.h>
24670  #include <net/netfilter/nf_queue.h>
24671 diff -NurpP --minimal linux-3.9.5/net/ipv4/raw.c linux-3.9.5-vs2.3.6.5/net/ipv4/raw.c
24672 --- linux-3.9.5/net/ipv4/raw.c  2013-05-31 13:45:32.000000000 +0000
24673 +++ linux-3.9.5-vs2.3.6.5/net/ipv4/raw.c        2013-05-31 18:19:38.000000000 +0000
24674 @@ -116,7 +116,7 @@ static struct sock *__raw_v4_lookup(stru
24675  
24676                 if (net_eq(sock_net(sk), net) && inet->inet_num == num  &&
24677                     !(inet->inet_daddr && inet->inet_daddr != raddr)    &&
24678 -                   !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
24679 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
24680                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
24681                         goto found; /* gotcha */
24682         }
24683 @@ -395,6 +395,12 @@ static int raw_send_hdrinc(struct sock *
24684                 icmp_out_count(net, ((struct icmphdr *)
24685                         skb_transport_header(skb))->type);
24686  
24687 +       err = -EPERM;
24688 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
24689 +               sk->sk_nx_info &&
24690 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
24691 +               goto error_free;
24692 +
24693         err = NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT, skb, NULL,
24694                       rt->dst.dev, dst_output);
24695         if (err > 0)
24696 @@ -580,6 +586,16 @@ static int raw_sendmsg(struct kiocb *ioc
24697                         goto done;
24698         }
24699  
24700 +       if (sk->sk_nx_info) {
24701 +               rt = ip_v4_find_src(sock_net(sk), sk->sk_nx_info, &fl4);
24702 +               if (IS_ERR(rt)) {
24703 +                       err = PTR_ERR(rt);
24704 +                       rt = NULL;
24705 +                       goto done;
24706 +               }
24707 +               ip_rt_put(rt);
24708 +       }
24709 +
24710         security_sk_classify_flow(sk, flowi4_to_flowi(&fl4));
24711         rt = ip_route_output_flow(sock_net(sk), &fl4, sk);
24712         if (IS_ERR(rt)) {
24713 @@ -656,17 +672,19 @@ static int raw_bind(struct sock *sk, str
24714  {
24715         struct inet_sock *inet = inet_sk(sk);
24716         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
24717 +       struct nx_v4_sock_addr nsa = { 0 };
24718         int ret = -EINVAL;
24719         int chk_addr_ret;
24720  
24721         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
24722                 goto out;
24723 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
24724 +       v4_map_sock_addr(inet, addr, &nsa);
24725 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
24726         ret = -EADDRNOTAVAIL;
24727 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
24728 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
24729             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
24730                 goto out;
24731 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24732 +       v4_set_sock_addr(inet, &nsa);
24733         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24734                 inet->inet_saddr = 0;  /* Use device */
24735         sk_dst_reset(sk);
24736 @@ -718,7 +736,8 @@ static int raw_recvmsg(struct kiocb *ioc
24737         /* Copy the address. */
24738         if (sin) {
24739                 sin->sin_family = AF_INET;
24740 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
24741 +               sin->sin_addr.s_addr =
24742 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
24743                 sin->sin_port = 0;
24744                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
24745         }
24746 @@ -913,7 +932,8 @@ static struct sock *raw_get_first(struct
24747         for (state->bucket = 0; state->bucket < RAW_HTABLE_SIZE;
24748                         ++state->bucket) {
24749                 sk_for_each(sk, &state->h->ht[state->bucket])
24750 -                       if (sock_net(sk) == seq_file_net(seq))
24751 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
24752 +                           nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24753                                 goto found;
24754         }
24755         sk = NULL;
24756 @@ -929,7 +949,8 @@ static struct sock *raw_get_next(struct
24757                 sk = sk_next(sk);
24758  try_again:
24759                 ;
24760 -       } while (sk && sock_net(sk) != seq_file_net(seq));
24761 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
24762 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
24763  
24764         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
24765                 sk = sk_head(&state->h->ht[state->bucket]);
24766 diff -NurpP --minimal linux-3.9.5/net/ipv4/route.c linux-3.9.5-vs2.3.6.5/net/ipv4/route.c
24767 --- linux-3.9.5/net/ipv4/route.c        2013-05-31 13:45:32.000000000 +0000
24768 +++ linux-3.9.5-vs2.3.6.5/net/ipv4/route.c      2013-05-31 17:17:54.000000000 +0000
24769 @@ -1998,7 +1998,7 @@ struct rtable *__ip_route_output_key(str
24770  
24771  
24772         if (fl4->flowi4_oif) {
24773 -               dev_out = dev_get_by_index_rcu(net, fl4->flowi4_oif);
24774 +               dev_out = dev_get_by_index_real_rcu(net, fl4->flowi4_oif);
24775                 rth = ERR_PTR(-ENODEV);
24776                 if (dev_out == NULL)
24777                         goto out;
24778 diff -NurpP --minimal linux-3.9.5/net/ipv4/tcp.c linux-3.9.5-vs2.3.6.5/net/ipv4/tcp.c
24779 --- linux-3.9.5/net/ipv4/tcp.c  2013-05-31 13:45:32.000000000 +0000
24780 +++ linux-3.9.5-vs2.3.6.5/net/ipv4/tcp.c        2013-05-31 17:17:54.000000000 +0000
24781 @@ -268,6 +268,7 @@
24782  #include <linux/crypto.h>
24783  #include <linux/time.h>
24784  #include <linux/slab.h>
24785 +#include <linux/in.h>
24786  
24787  #include <net/icmp.h>
24788  #include <net/inet_common.h>
24789 diff -NurpP --minimal linux-3.9.5/net/ipv4/tcp_ipv4.c linux-3.9.5-vs2.3.6.5/net/ipv4/tcp_ipv4.c
24790 --- linux-3.9.5/net/ipv4/tcp_ipv4.c     2013-05-31 13:45:32.000000000 +0000
24791 +++ linux-3.9.5-vs2.3.6.5/net/ipv4/tcp_ipv4.c   2013-05-31 17:17:54.000000000 +0000
24792 @@ -2260,6 +2260,12 @@ static void *listening_get_next(struct s
24793                 req = req->dl_next;
24794                 while (1) {
24795                         while (req) {
24796 +                               vxdprintk(VXD_CBIT(net, 6),
24797 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
24798 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
24799 +                               if (req->sk &&
24800 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
24801 +                                       continue;
24802                                 if (req->rsk_ops->family == st->family) {
24803                                         cur = req;
24804                                         goto out;
24805 @@ -2284,6 +2290,10 @@ get_req:
24806         }
24807  get_sk:
24808         sk_nulls_for_each_from(sk, node) {
24809 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
24810 +                       sk, sk->sk_nid, nx_current_nid());
24811 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24812 +                       continue;
24813                 if (!net_eq(sock_net(sk), net))
24814                         continue;
24815                 if (sk->sk_family == st->family) {
24816 @@ -2360,6 +2370,11 @@ static void *established_get_first(struc
24817  
24818                 spin_lock_bh(lock);
24819                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
24820 +                       vxdprintk(VXD_CBIT(net, 6),
24821 +                               "sk,egf: %p [#%d] (from %d)",
24822 +                               sk, sk->sk_nid, nx_current_nid());
24823 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24824 +                               continue;
24825                         if (sk->sk_family != st->family ||
24826                             !net_eq(sock_net(sk), net)) {
24827                                 continue;
24828 @@ -2370,6 +2385,11 @@ static void *established_get_first(struc
24829                 st->state = TCP_SEQ_STATE_TIME_WAIT;
24830                 inet_twsk_for_each(tw, node,
24831                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
24832 +                       vxdprintk(VXD_CBIT(net, 6),
24833 +                               "tw: %p [#%d] (from %d)",
24834 +                               tw, tw->tw_nid, nx_current_nid());
24835 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
24836 +                               continue;
24837                         if (tw->tw_family != st->family ||
24838                             !net_eq(twsk_net(tw), net)) {
24839                                 continue;
24840 @@ -2399,7 +2419,9 @@ static void *established_get_next(struct
24841                 tw = cur;
24842                 tw = tw_next(tw);
24843  get_tw:
24844 -               while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
24845 +               while (tw && (tw->tw_family != st->family ||
24846 +                       !net_eq(twsk_net(tw), net) ||
24847 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
24848                         tw = tw_next(tw);
24849                 }
24850                 if (tw) {
24851 @@ -2423,6 +2445,11 @@ get_tw:
24852                 sk = sk_nulls_next(sk);
24853  
24854         sk_nulls_for_each_from(sk, node) {
24855 +               vxdprintk(VXD_CBIT(net, 6),
24856 +                       "sk,egn: %p [#%d] (from %d)",
24857 +                       sk, sk->sk_nid, nx_current_nid());
24858 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24859 +                       continue;
24860                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
24861                         goto found;
24862         }
24863 @@ -2628,9 +2655,9 @@ static void get_openreq4(const struct so
24864         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
24865                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %pK%n",
24866                 i,
24867 -               ireq->loc_addr,
24868 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
24869                 ntohs(inet_sk(sk)->inet_sport),
24870 -               ireq->rmt_addr,
24871 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
24872                 ntohs(ireq->rmt_port),
24873                 TCP_SYN_RECV,
24874                 0, 0, /* could print option size, but that is af dependent. */
24875 @@ -2653,8 +2680,8 @@ static void get_tcp4_sock(struct sock *s
24876         const struct inet_connection_sock *icsk = inet_csk(sk);
24877         const struct inet_sock *inet = inet_sk(sk);
24878         struct fastopen_queue *fastopenq = icsk->icsk_accept_queue.fastopenq;
24879 -       __be32 dest = inet->inet_daddr;
24880 -       __be32 src = inet->inet_rcv_saddr;
24881 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
24882 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
24883         __u16 destp = ntohs(inet->inet_dport);
24884         __u16 srcp = ntohs(inet->inet_sport);
24885         int rx_queue;
24886 @@ -2710,8 +2737,8 @@ static void get_timewait4_sock(const str
24887         __u16 destp, srcp;
24888         long delta = tw->tw_ttd - jiffies;
24889  
24890 -       dest  = tw->tw_daddr;
24891 -       src   = tw->tw_rcv_saddr;
24892 +       dest  = nx_map_sock_lback(current_nx_info(), tw->tw_daddr);
24893 +       src   = nx_map_sock_lback(current_nx_info(), tw->tw_rcv_saddr);
24894         destp = ntohs(tw->tw_dport);
24895         srcp  = ntohs(tw->tw_sport);
24896  
24897 diff -NurpP --minimal linux-3.9.5/net/ipv4/tcp_minisocks.c linux-3.9.5-vs2.3.6.5/net/ipv4/tcp_minisocks.c
24898 --- linux-3.9.5/net/ipv4/tcp_minisocks.c        2013-06-11 12:22:40.000000000 +0000
24899 +++ linux-3.9.5-vs2.3.6.5/net/ipv4/tcp_minisocks.c      2013-05-31 17:17:54.000000000 +0000
24900 @@ -23,6 +23,9 @@
24901  #include <linux/slab.h>
24902  #include <linux/sysctl.h>
24903  #include <linux/workqueue.h>
24904 +#include <linux/vs_limit.h>
24905 +#include <linux/vs_socket.h>
24906 +#include <linux/vs_context.h>
24907  #include <net/tcp.h>
24908  #include <net/inet_common.h>
24909  #include <net/xfrm.h>
24910 @@ -291,6 +294,11 @@ void tcp_time_wait(struct sock *sk, int
24911                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
24912                 tcptw->tw_ts_offset     = tp->tsoffset;
24913  
24914 +               tw->tw_xid              = sk->sk_xid;
24915 +               tw->tw_vx_info          = NULL;
24916 +               tw->tw_nid              = sk->sk_nid;
24917 +               tw->tw_nx_info          = NULL;
24918 +
24919  #if IS_ENABLED(CONFIG_IPV6)
24920                 if (tw->tw_family == PF_INET6) {
24921                         struct ipv6_pinfo *np = inet6_sk(sk);
24922 diff -NurpP --minimal linux-3.9.5/net/ipv4/udp.c linux-3.9.5-vs2.3.6.5/net/ipv4/udp.c
24923 --- linux-3.9.5/net/ipv4/udp.c  2013-05-31 13:45:32.000000000 +0000
24924 +++ linux-3.9.5-vs2.3.6.5/net/ipv4/udp.c        2013-05-31 18:26:00.000000000 +0000
24925 @@ -306,14 +306,7 @@ fail:
24926  }
24927  EXPORT_SYMBOL(udp_lib_get_port);
24928  
24929 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24930 -{
24931 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
24932 -
24933 -       return  (!ipv6_only_sock(sk2)  &&
24934 -                (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr ||
24935 -                  inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
24936 -}
24937 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
24938  
24939  static unsigned int udp4_portaddr_hash(struct net *net, __be32 saddr,
24940                                        unsigned int port)
24941 @@ -348,6 +341,11 @@ static inline int compute_score(struct s
24942                         if (inet->inet_rcv_saddr != daddr)
24943                                 return -1;
24944                         score += 4;
24945 +               } else {
24946 +                       /* block non nx_info ips */
24947 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
24948 +                               daddr, NXA_MASK_BIND))
24949 +                               return -1;
24950                 }
24951                 if (inet->inet_daddr) {
24952                         if (inet->inet_daddr != saddr)
24953 @@ -458,6 +456,7 @@ begin:
24954         return result;
24955  }
24956  
24957 +
24958  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
24959   * harder than this. -DaveM
24960   */
24961 @@ -504,6 +503,11 @@ begin:
24962         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
24963                 score = compute_score(sk, net, saddr, hnum, sport,
24964                                       daddr, dport, dif);
24965 +               /* FIXME: disabled?
24966 +               if (score == 9) {
24967 +                       result = sk;
24968 +                       break;
24969 +               } else */
24970                 if (score > badness) {
24971                         result = sk;
24972                         badness = score;
24973 @@ -528,6 +532,7 @@ begin:
24974         if (get_nulls_value(node) != slot)
24975                 goto begin;
24976  
24977 +
24978         if (result) {
24979                 if (unlikely(!atomic_inc_not_zero_hint(&result->sk_refcnt, 2)))
24980                         result = NULL;
24981 @@ -537,6 +542,7 @@ begin:
24982                         goto begin;
24983                 }
24984         }
24985 +
24986         rcu_read_unlock();
24987         return result;
24988  }
24989 @@ -580,8 +586,7 @@ static inline struct sock *udp_v4_mcast_
24990                     udp_sk(s)->udp_port_hash != hnum ||
24991                     (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
24992                     (inet->inet_dport != rmt_port && inet->inet_dport) ||
24993 -                   (inet->inet_rcv_saddr &&
24994 -                    inet->inet_rcv_saddr != loc_addr) ||
24995 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
24996                     ipv6_only_sock(s) ||
24997                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
24998                         continue;
24999 @@ -964,6 +969,16 @@ int udp_sendmsg(struct kiocb *iocb, stru
25000                                    inet_sk_flowi_flags(sk)|FLOWI_FLAG_CAN_SLEEP,
25001                                    faddr, saddr, dport, inet->inet_sport);
25002  
25003 +               if (sk->sk_nx_info) {
25004 +                       rt = ip_v4_find_src(net, sk->sk_nx_info, fl4);
25005 +                       if (IS_ERR(rt)) {
25006 +                               err = PTR_ERR(rt);
25007 +                               rt = NULL;
25008 +                               goto out;
25009 +                       }
25010 +                       ip_rt_put(rt);
25011 +               }
25012 +
25013                 security_sk_classify_flow(sk, flowi4_to_flowi(fl4));
25014                 rt = ip_route_output_flow(net, fl4, sk);
25015                 if (IS_ERR(rt)) {
25016 @@ -1269,7 +1284,8 @@ try_again:
25017         if (sin) {
25018                 sin->sin_family = AF_INET;
25019                 sin->sin_port = udp_hdr(skb)->source;
25020 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
25021 +               sin->sin_addr.s_addr = nx_map_sock_lback(
25022 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
25023                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
25024         }
25025         if (inet->cmsg_flags)
25026 @@ -2025,6 +2041,8 @@ static struct sock *udp_get_first(struct
25027                 sk_nulls_for_each(sk, node, &hslot->head) {
25028                         if (!net_eq(sock_net(sk), net))
25029                                 continue;
25030 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25031 +                               continue;
25032                         if (sk->sk_family == state->family)
25033                                 goto found;
25034                 }
25035 @@ -2042,7 +2060,9 @@ static struct sock *udp_get_next(struct
25036  
25037         do {
25038                 sk = sk_nulls_next(sk);
25039 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
25040 +       } while (sk && (!net_eq(sock_net(sk), net) ||
25041 +               sk->sk_family != state->family ||
25042 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
25043  
25044         if (!sk) {
25045                 if (state->bucket <= state->udp_table->mask)
25046 @@ -2138,8 +2158,8 @@ static void udp4_format_sock(struct sock
25047                 int bucket, int *len)
25048  {
25049         struct inet_sock *inet = inet_sk(sp);
25050 -       __be32 dest = inet->inet_daddr;
25051 -       __be32 src  = inet->inet_rcv_saddr;
25052 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
25053 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
25054         __u16 destp       = ntohs(inet->inet_dport);
25055         __u16 srcp        = ntohs(inet->inet_sport);
25056  
25057 diff -NurpP --minimal linux-3.9.5/net/ipv6/Kconfig linux-3.9.5-vs2.3.6.5/net/ipv6/Kconfig
25058 --- linux-3.9.5/net/ipv6/Kconfig        2013-05-31 13:45:32.000000000 +0000
25059 +++ linux-3.9.5-vs2.3.6.5/net/ipv6/Kconfig      2013-05-31 17:17:54.000000000 +0000
25060 @@ -4,8 +4,8 @@
25061  
25062  #   IPv6 as module will cause a CRASH if you try to unload it
25063  menuconfig IPV6
25064 -       tristate "The IPv6 protocol"
25065 -       default m
25066 +       bool "The IPv6 protocol"
25067 +       default n
25068         ---help---
25069           This is complemental support for the IP version 6.
25070           You will still be able to do traditional IPv4 networking as well.
25071 diff -NurpP --minimal linux-3.9.5/net/ipv6/addrconf.c linux-3.9.5-vs2.3.6.5/net/ipv6/addrconf.c
25072 --- linux-3.9.5/net/ipv6/addrconf.c     2013-05-31 13:45:32.000000000 +0000
25073 +++ linux-3.9.5-vs2.3.6.5/net/ipv6/addrconf.c   2013-05-31 20:07:39.000000000 +0000
25074 @@ -93,6 +93,8 @@
25075  #include <linux/proc_fs.h>
25076  #include <linux/seq_file.h>
25077  #include <linux/export.h>
25078 +#include <linux/vs_network.h>
25079 +#include <linux/vs_inet6.h>
25080  
25081  /* Set to 3 to get tracing... */
25082  #define ACONF_DEBUG 2
25083 @@ -1250,7 +1252,7 @@ out:
25084  
25085  int ipv6_dev_get_saddr(struct net *net, const struct net_device *dst_dev,
25086                        const struct in6_addr *daddr, unsigned int prefs,
25087 -                      struct in6_addr *saddr)
25088 +                      struct in6_addr *saddr, struct nx_info *nxi)
25089  {
25090         struct ipv6_saddr_score scores[2],
25091                                 *score = &scores[0], *hiscore = &scores[1];
25092 @@ -1322,6 +1324,8 @@ int ipv6_dev_get_saddr(struct net *net,
25093                                                dev->name);
25094                                 continue;
25095                         }
25096 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
25097 +                               continue;
25098  
25099                         score->rule = -1;
25100                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
25101 @@ -3311,7 +3315,10 @@ static void if6_seq_stop(struct seq_file
25102  static int if6_seq_show(struct seq_file *seq, void *v)
25103  {
25104         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
25105 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25106 +
25107 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
25108 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
25109 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25110                    &ifp->addr,
25111                    ifp->idev->dev->ifindex,
25112                    ifp->prefix_len,
25113 @@ -3815,6 +3822,11 @@ static int in6_dump_addrs(struct inet6_d
25114         struct ifacaddr6 *ifaca;
25115         int err = 1;
25116         int ip_idx = *p_ip_idx;
25117 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25118 +
25119 +       /* disable ipv6 on non v6 guests */
25120 +       if (nxi && !nx_info_has_v6(nxi))
25121 +               return skb->len;
25122  
25123         read_lock_bh(&idev->lock);
25124         switch (type) {
25125 @@ -3825,6 +3837,8 @@ static int in6_dump_addrs(struct inet6_d
25126                 list_for_each_entry(ifa, &idev->addr_list, if_list) {
25127                         if (++ip_idx < s_ip_idx)
25128                                 continue;
25129 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
25130 +                                       continue;
25131                         err = inet6_fill_ifaddr(skb, ifa,
25132                                                 NETLINK_CB(cb->skb).portid,
25133                                                 cb->nlh->nlmsg_seq,
25134 @@ -3841,6 +3855,8 @@ static int in6_dump_addrs(struct inet6_d
25135                      ifmca = ifmca->next, ip_idx++) {
25136                         if (ip_idx < s_ip_idx)
25137                                 continue;
25138 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
25139 +                                       continue;
25140                         err = inet6_fill_ifmcaddr(skb, ifmca,
25141                                                   NETLINK_CB(cb->skb).portid,
25142                                                   cb->nlh->nlmsg_seq,
25143 @@ -3856,6 +3872,8 @@ static int in6_dump_addrs(struct inet6_d
25144                      ifaca = ifaca->aca_next, ip_idx++) {
25145                         if (ip_idx < s_ip_idx)
25146                                 continue;
25147 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
25148 +                                       continue;
25149                         err = inet6_fill_ifacaddr(skb, ifaca,
25150                                                   NETLINK_CB(cb->skb).portid,
25151                                                   cb->nlh->nlmsg_seq,
25152 @@ -3884,6 +3902,10 @@ static int inet6_dump_addr(struct sk_buf
25153         struct inet6_dev *idev;
25154         struct hlist_head *head;
25155  
25156 +       /* FIXME: maybe disable ipv6 on non v6 guests?
25157 +       if (skb->sk && skb->sk->sk_vx_info)
25158 +               return skb->len; */
25159 +
25160         s_h = cb->args[0];
25161         s_idx = idx = cb->args[1];
25162         s_ip_idx = ip_idx = cb->args[2];
25163 @@ -4238,6 +4260,7 @@ static int inet6_dump_ifinfo(struct sk_b
25164         struct net_device *dev;
25165         struct inet6_dev *idev;
25166         struct hlist_head *head;
25167 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25168  
25169         s_h = cb->args[0];
25170         s_idx = cb->args[1];
25171 @@ -4249,6 +4272,8 @@ static int inet6_dump_ifinfo(struct sk_b
25172                 hlist_for_each_entry_rcu(dev, head, index_hlist) {
25173                         if (idx < s_idx)
25174                                 goto cont;
25175 +                       if (!v6_dev_in_nx_info(dev, nxi))
25176 +                               goto cont;
25177                         idev = __in6_dev_get(dev);
25178                         if (!idev)
25179                                 goto cont;
25180 diff -NurpP --minimal linux-3.9.5/net/ipv6/af_inet6.c linux-3.9.5-vs2.3.6.5/net/ipv6/af_inet6.c
25181 --- linux-3.9.5/net/ipv6/af_inet6.c     2013-05-31 13:45:32.000000000 +0000
25182 +++ linux-3.9.5-vs2.3.6.5/net/ipv6/af_inet6.c   2013-05-31 20:04:41.000000000 +0000
25183 @@ -43,6 +43,8 @@
25184  #include <linux/netdevice.h>
25185  #include <linux/icmpv6.h>
25186  #include <linux/netfilter_ipv6.h>
25187 +#include <linux/vs_inet.h>
25188 +#include <linux/vs_inet6.h>
25189  
25190  #include <net/ip.h>
25191  #include <net/ipv6.h>
25192 @@ -160,10 +162,13 @@ lookup_protocol:
25193         }
25194  
25195         err = -EPERM;
25196 +       if ((protocol == IPPROTO_ICMPV6) &&
25197 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
25198 +               goto override;
25199         if (sock->type == SOCK_RAW && !kern &&
25200             !ns_capable(net->user_ns, CAP_NET_RAW))
25201                 goto out_rcu_unlock;
25202 -
25203 +override:
25204         sock->ops = answer->ops;
25205         answer_prot = answer->prot;
25206         answer_no_check = answer->no_check;
25207 @@ -263,6 +268,7 @@ int inet6_bind(struct socket *sock, stru
25208         struct inet_sock *inet = inet_sk(sk);
25209         struct ipv6_pinfo *np = inet6_sk(sk);
25210         struct net *net = sock_net(sk);
25211 +       struct nx_v6_sock_addr nsa;
25212         __be32 v4addr = 0;
25213         unsigned short snum;
25214         int addr_type = 0;
25215 @@ -278,6 +284,10 @@ int inet6_bind(struct socket *sock, stru
25216         if (addr->sin6_family != AF_INET6)
25217                 return -EAFNOSUPPORT;
25218  
25219 +       err = v6_map_sock_addr(inet, addr, &nsa);
25220 +       if (err)
25221 +               return err;
25222 +
25223         addr_type = ipv6_addr_type(&addr->sin6_addr);
25224         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
25225                 return -EINVAL;
25226 @@ -309,6 +319,7 @@ int inet6_bind(struct socket *sock, stru
25227                 /* Reproduce AF_INET checks to make the bindings consistent */
25228                 v4addr = addr->sin6_addr.s6_addr32[3];
25229                 chk_addr_ret = inet_addr_type(net, v4addr);
25230 +
25231                 if (!sysctl_ip_nonlocal_bind &&
25232                     !(inet->freebind || inet->transparent) &&
25233                     v4addr != htonl(INADDR_ANY) &&
25234 @@ -318,6 +329,10 @@ int inet6_bind(struct socket *sock, stru
25235                         err = -EADDRNOTAVAIL;
25236                         goto out;
25237                 }
25238 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
25239 +                       err = -EADDRNOTAVAIL;
25240 +                       goto out;
25241 +               }
25242         } else {
25243                 if (addr_type != IPV6_ADDR_ANY) {
25244                         struct net_device *dev = NULL;
25245 @@ -344,6 +359,11 @@ int inet6_bind(struct socket *sock, stru
25246                                 }
25247                         }
25248  
25249 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25250 +                               err = -EADDRNOTAVAIL;
25251 +                               goto out_unlock;
25252 +                       }
25253 +
25254                         /* ipv4 addr of the socket is invalid.  Only the
25255                          * unspecified and mapped address have a v4 equivalent.
25256                          */
25257 @@ -360,6 +380,9 @@ int inet6_bind(struct socket *sock, stru
25258                 }
25259         }
25260  
25261 +       /* what's that for? */
25262 +       v6_set_sock_addr(inet, &nsa);
25263 +
25264         inet->inet_rcv_saddr = v4addr;
25265         inet->inet_saddr = v4addr;
25266  
25267 @@ -461,9 +484,11 @@ int inet6_getname(struct socket *sock, s
25268                         return -ENOTCONN;
25269                 sin->sin6_port = inet->inet_dport;
25270                 sin->sin6_addr = np->daddr;
25271 +               /* FIXME: remap lback? */
25272                 if (np->sndflow)
25273                         sin->sin6_flowinfo = np->flow_label;
25274         } else {
25275 +               /* FIXME: remap lback? */
25276                 if (ipv6_addr_any(&np->rcv_saddr))
25277                         sin->sin6_addr = np->saddr;
25278                 else
25279 diff -NurpP --minimal linux-3.9.5/net/ipv6/datagram.c linux-3.9.5-vs2.3.6.5/net/ipv6/datagram.c
25280 --- linux-3.9.5/net/ipv6/datagram.c     2013-05-31 13:45:32.000000000 +0000
25281 +++ linux-3.9.5-vs2.3.6.5/net/ipv6/datagram.c   2013-05-31 17:17:54.000000000 +0000
25282 @@ -648,7 +648,7 @@ int ip6_datagram_send_ctl(struct net *ne
25283  
25284                         rcu_read_lock();
25285                         if (fl6->flowi6_oif) {
25286 -                               dev = dev_get_by_index_rcu(net, fl6->flowi6_oif);
25287 +                               dev = dev_get_by_index_real_rcu(net, fl6->flowi6_oif);
25288                                 if (!dev) {
25289                                         rcu_read_unlock();
25290                                         return -ENODEV;
25291 diff -NurpP --minimal linux-3.9.5/net/ipv6/fib6_rules.c linux-3.9.5-vs2.3.6.5/net/ipv6/fib6_rules.c
25292 --- linux-3.9.5/net/ipv6/fib6_rules.c   2013-02-19 13:58:58.000000000 +0000
25293 +++ linux-3.9.5-vs2.3.6.5/net/ipv6/fib6_rules.c 2013-05-31 17:17:54.000000000 +0000
25294 @@ -90,7 +90,7 @@ static int fib6_rule_action(struct fib_r
25295                                                ip6_dst_idev(&rt->dst)->dev,
25296                                                &flp6->daddr,
25297                                                rt6_flags2srcprefs(flags),
25298 -                                              &saddr))
25299 +                                              &saddr, NULL))
25300                                 goto again;
25301                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
25302                                                r->src.plen))
25303 diff -NurpP --minimal linux-3.9.5/net/ipv6/inet6_hashtables.c linux-3.9.5-vs2.3.6.5/net/ipv6/inet6_hashtables.c
25304 --- linux-3.9.5/net/ipv6/inet6_hashtables.c     2013-05-31 13:45:32.000000000 +0000
25305 +++ linux-3.9.5-vs2.3.6.5/net/ipv6/inet6_hashtables.c   2013-05-31 17:17:54.000000000 +0000
25306 @@ -16,6 +16,7 @@
25307  
25308  #include <linux/module.h>
25309  #include <linux/random.h>
25310 +#include <linux/vs_inet6.h>
25311  
25312  #include <net/inet_connection_sock.h>
25313  #include <net/inet_hashtables.h>
25314 @@ -83,7 +84,6 @@ struct sock *__inet6_lookup_established(
25315         unsigned int slot = hash & hashinfo->ehash_mask;
25316         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
25317  
25318 -
25319         rcu_read_lock();
25320  begin:
25321         sk_nulls_for_each_rcu(sk, node, &head->chain) {
25322 @@ -97,7 +97,7 @@ begin:
25323                                 sock_put(sk);
25324                                 goto begin;
25325                         }
25326 -               goto out;
25327 +                       goto out;
25328                 }
25329         }
25330         if (get_nulls_value(node) != slot)
25331 @@ -147,6 +147,9 @@ static inline int compute_score(struct s
25332                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25333                                 return -1;
25334                         score++;
25335 +               } else {
25336 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25337 +                               return -1;
25338                 }
25339                 if (sk->sk_bound_dev_if) {
25340                         if (sk->sk_bound_dev_if != dif)
25341 diff -NurpP --minimal linux-3.9.5/net/ipv6/ip6_output.c linux-3.9.5-vs2.3.6.5/net/ipv6/ip6_output.c
25342 --- linux-3.9.5/net/ipv6/ip6_output.c   2013-05-31 13:45:32.000000000 +0000
25343 +++ linux-3.9.5-vs2.3.6.5/net/ipv6/ip6_output.c 2013-05-31 17:17:54.000000000 +0000
25344 @@ -877,7 +877,8 @@ static int ip6_dst_lookup_tail(struct so
25345                 struct rt6_info *rt = (struct rt6_info *) *dst;
25346                 err = ip6_route_get_saddr(net, rt, &fl6->daddr,
25347                                           sk ? inet6_sk(sk)->srcprefs : 0,
25348 -                                         &fl6->saddr);
25349 +                                         &fl6->saddr,
25350 +                                         sk ? sk->sk_nx_info : NULL);
25351                 if (err)
25352                         goto out_err_release;
25353         }
25354 diff -NurpP --minimal linux-3.9.5/net/ipv6/ndisc.c linux-3.9.5-vs2.3.6.5/net/ipv6/ndisc.c
25355 --- linux-3.9.5/net/ipv6/ndisc.c        2013-05-31 13:45:32.000000000 +0000
25356 +++ linux-3.9.5-vs2.3.6.5/net/ipv6/ndisc.c      2013-05-31 17:17:54.000000000 +0000
25357 @@ -485,7 +485,7 @@ static void ndisc_send_na(struct net_dev
25358         } else {
25359                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
25360                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
25361 -                                      &tmpaddr))
25362 +                                      &tmpaddr, NULL))
25363                         return;
25364                 src_addr = &tmpaddr;
25365         }
25366 diff -NurpP --minimal linux-3.9.5/net/ipv6/netfilter/ip6t_MASQUERADE.c linux-3.9.5-vs2.3.6.5/net/ipv6/netfilter/ip6t_MASQUERADE.c
25367 --- linux-3.9.5/net/ipv6/netfilter/ip6t_MASQUERADE.c    2012-12-11 03:30:57.000000000 +0000
25368 +++ linux-3.9.5-vs2.3.6.5/net/ipv6/netfilter/ip6t_MASQUERADE.c  2013-05-31 17:17:54.000000000 +0000
25369 @@ -34,7 +34,7 @@ masquerade_tg6(struct sk_buff *skb, cons
25370                             ctinfo == IP_CT_RELATED_REPLY));
25371  
25372         if (ipv6_dev_get_saddr(dev_net(par->out), par->out,
25373 -                              &ipv6_hdr(skb)->daddr, 0, &src) < 0)
25374 +                              &ipv6_hdr(skb)->daddr, 0, &src, NULL) < 0)
25375                 return NF_DROP;
25376  
25377         nfct_nat(ct)->masq_index = par->out->ifindex;
25378 diff -NurpP --minimal linux-3.9.5/net/ipv6/raw.c linux-3.9.5-vs2.3.6.5/net/ipv6/raw.c
25379 --- linux-3.9.5/net/ipv6/raw.c  2013-05-31 13:45:32.000000000 +0000
25380 +++ linux-3.9.5-vs2.3.6.5/net/ipv6/raw.c        2013-05-31 17:17:54.000000000 +0000
25381 @@ -30,6 +30,7 @@
25382  #include <linux/icmpv6.h>
25383  #include <linux/netfilter.h>
25384  #include <linux/netfilter_ipv6.h>
25385 +#include <linux/vs_inet6.h>
25386  #include <linux/skbuff.h>
25387  #include <linux/compat.h>
25388  #include <asm/uaccess.h>
25389 @@ -283,6 +284,13 @@ static int rawv6_bind(struct sock *sk, s
25390                                 goto out_unlock;
25391                 }
25392  
25393 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25394 +                       err = -EADDRNOTAVAIL;
25395 +                       if (dev)
25396 +                               dev_put(dev);
25397 +                       goto out;
25398 +               }
25399 +
25400                 /* ipv4 addr of the socket is invalid.  Only the
25401                  * unspecified and mapped address have a v4 equivalent.
25402                  */
25403 diff -NurpP --minimal linux-3.9.5/net/ipv6/route.c linux-3.9.5-vs2.3.6.5/net/ipv6/route.c
25404 --- linux-3.9.5/net/ipv6/route.c        2013-05-31 13:45:32.000000000 +0000
25405 +++ linux-3.9.5-vs2.3.6.5/net/ipv6/route.c      2013-05-31 18:10:38.000000000 +0000
25406 @@ -58,6 +58,7 @@
25407  #include <net/netevent.h>
25408  #include <net/netlink.h>
25409  #include <net/nexthop.h>
25410 +#include <linux/vs_inet6.h>
25411  
25412  #include <asm/uaccess.h>
25413  
25414 @@ -2079,15 +2080,17 @@ int ip6_route_get_saddr(struct net *net,
25415                         struct rt6_info *rt,
25416                         const struct in6_addr *daddr,
25417                         unsigned int prefs,
25418 -                       struct in6_addr *saddr)
25419 +                       struct in6_addr *saddr,
25420 +                       struct nx_info *nxi)
25421  {
25422         struct inet6_dev *idev = ip6_dst_idev((struct dst_entry*)rt);
25423         int err = 0;
25424 -       if (rt->rt6i_prefsrc.plen)
25425 +       if (rt->rt6i_prefsrc.plen && (!nxi ||
25426 +           v6_addr_in_nx_info(nxi, &rt->rt6i_prefsrc.addr, NXA_TYPE_ADDR)))
25427                 *saddr = rt->rt6i_prefsrc.addr;
25428         else
25429                 err = ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
25430 -                                        daddr, prefs, saddr);
25431 +                                        daddr, prefs, saddr, nxi);
25432         return err;
25433  }
25434  
25435 @@ -2507,7 +2510,8 @@ static int rt6_fill_node(struct net *net
25436                                 goto nla_put_failure;
25437         } else if (dst) {
25438                 struct in6_addr saddr_buf;
25439 -               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf) == 0 &&
25440 +               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf,
25441 +                   (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0 &&
25442                     nla_put(skb, RTA_PREFSRC, 16, &saddr_buf))
25443                         goto nla_put_failure;
25444         }
25445 @@ -2719,6 +2723,7 @@ static int rt6_info_route(struct rt6_inf
25446  {
25447         struct seq_file *m = p_arg;
25448  
25449 +       /* FIXME: check for network context? */
25450         seq_printf(m, "%pi6 %02x ", &rt->rt6i_dst.addr, rt->rt6i_dst.plen);
25451  
25452  #ifdef CONFIG_IPV6_SUBTREES
25453 diff -NurpP --minimal linux-3.9.5/net/ipv6/tcp_ipv6.c linux-3.9.5-vs2.3.6.5/net/ipv6/tcp_ipv6.c
25454 --- linux-3.9.5/net/ipv6/tcp_ipv6.c     2013-06-11 12:22:40.000000000 +0000
25455 +++ linux-3.9.5-vs2.3.6.5/net/ipv6/tcp_ipv6.c   2013-05-31 17:17:54.000000000 +0000
25456 @@ -71,6 +71,7 @@
25457  
25458  #include <linux/crypto.h>
25459  #include <linux/scatterlist.h>
25460 +#include <linux/vs_inet6.h>
25461  
25462  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
25463  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
25464 @@ -164,8 +165,15 @@ static int tcp_v6_connect(struct sock *s
25465          *      connect() to INADDR_ANY means loopback (BSD'ism).
25466          */
25467  
25468 -       if(ipv6_addr_any(&usin->sin6_addr))
25469 -               usin->sin6_addr.s6_addr[15] = 0x1;
25470 +       if(ipv6_addr_any(&usin->sin6_addr)) {
25471 +               struct nx_info *nxi =  sk->sk_nx_info;
25472 +
25473 +               if (nxi && nx_info_has_v6(nxi))
25474 +                       /* FIXME: remap lback? */
25475 +                       usin->sin6_addr = nxi->v6.ip;
25476 +               else
25477 +                       usin->sin6_addr.s6_addr[15] = 0x1;
25478 +       }
25479  
25480         addr_type = ipv6_addr_type(&usin->sin6_addr);
25481  
25482 diff -NurpP --minimal linux-3.9.5/net/ipv6/udp.c linux-3.9.5-vs2.3.6.5/net/ipv6/udp.c
25483 --- linux-3.9.5/net/ipv6/udp.c  2013-06-11 12:22:40.000000000 +0000
25484 +++ linux-3.9.5-vs2.3.6.5/net/ipv6/udp.c        2013-05-31 18:16:01.000000000 +0000
25485 @@ -46,42 +46,68 @@
25486  #include <net/ip6_checksum.h>
25487  #include <net/xfrm.h>
25488  #include <net/inet6_hashtables.h>
25489 +#include <linux/vs_inet6.h>
25490  
25491  #include <linux/proc_fs.h>
25492  #include <linux/seq_file.h>
25493  #include <trace/events/skb.h>
25494  #include "udp_impl.h"
25495  
25496 -int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
25497 +int ipv6_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25498  {
25499 -       const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
25500 +       const struct in6_addr *sk1_rcv_saddr6 = &inet6_sk(sk1)->rcv_saddr;
25501         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
25502 -       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk);
25503 +       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk1);
25504         __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
25505 -       int sk_ipv6only = ipv6_only_sock(sk);
25506 +       int sk1_ipv6only = ipv6_only_sock(sk1);
25507         int sk2_ipv6only = inet_v6_ipv6only(sk2);
25508 -       int addr_type = ipv6_addr_type(sk_rcv_saddr6);
25509 +       int addr_type = ipv6_addr_type(sk1_rcv_saddr6);
25510         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
25511  
25512         /* if both are mapped, treat as IPv4 */
25513 -       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
25514 -               return (!sk2_ipv6only &&
25515 +       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
25516 +               if (!sk2_ipv6only &&
25517                         (!sk1_rcv_saddr || !sk2_rcv_saddr ||
25518 -                         sk1_rcv_saddr == sk2_rcv_saddr));
25519 +                         sk1_rcv_saddr == sk2_rcv_saddr))
25520 +                       goto vs_v4;
25521 +               else
25522 +                       return 0;
25523 +       }
25524  
25525         if (addr_type2 == IPV6_ADDR_ANY &&
25526             !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
25527 -               return 1;
25528 +               goto vs;
25529  
25530         if (addr_type == IPV6_ADDR_ANY &&
25531 -           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
25532 -               return 1;
25533 +           !(sk1_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
25534 +               goto vs;
25535  
25536         if (sk2_rcv_saddr6 &&
25537 -           ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
25538 -               return 1;
25539 +           ipv6_addr_equal(sk1_rcv_saddr6, sk2_rcv_saddr6))
25540 +               goto vs;
25541  
25542         return 0;
25543 +
25544 +vs_v4:
25545 +       if (!sk1_rcv_saddr && !sk2_rcv_saddr)
25546 +               return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25547 +       if (!sk2_rcv_saddr)
25548 +               return v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, -1);
25549 +       if (!sk1_rcv_saddr)
25550 +               return v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, -1);
25551 +       return 1;
25552 +vs:
25553 +       if (addr_type2 == IPV6_ADDR_ANY && addr_type == IPV6_ADDR_ANY)
25554 +               return nx_v6_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25555 +       else if (addr_type2 == IPV6_ADDR_ANY)
25556 +               return v6_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr6, -1);
25557 +       else if (addr_type == IPV6_ADDR_ANY) {
25558 +               if (addr_type2 == IPV6_ADDR_MAPPED)
25559 +                       return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25560 +               else
25561 +                       return v6_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr6, -1);
25562 +       }
25563 +       return 1;
25564  }
25565  
25566  static unsigned int udp6_portaddr_hash(struct net *net,
25567 @@ -145,6 +171,10 @@ static inline int compute_score(struct s
25568                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25569                                 return -1;
25570                         score++;
25571 +               } else {
25572 +                       /* block non nx_info ips */
25573 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25574 +                               return -1;
25575                 }
25576                 if (!ipv6_addr_any(&np->daddr)) {
25577                         if (!ipv6_addr_equal(&np->daddr, saddr))
25578 diff -NurpP --minimal linux-3.9.5/net/ipv6/xfrm6_policy.c linux-3.9.5-vs2.3.6.5/net/ipv6/xfrm6_policy.c
25579 --- linux-3.9.5/net/ipv6/xfrm6_policy.c 2013-06-11 12:22:40.000000000 +0000
25580 +++ linux-3.9.5-vs2.3.6.5/net/ipv6/xfrm6_policy.c       2013-05-31 17:17:54.000000000 +0000
25581 @@ -63,7 +63,7 @@ static int xfrm6_get_saddr(struct net *n
25582         dev = ip6_dst_idev(dst)->dev;
25583         ipv6_dev_get_saddr(dev_net(dev), dev,
25584                            (struct in6_addr *)&daddr->a6, 0,
25585 -                          (struct in6_addr *)&saddr->a6);
25586 +                          (struct in6_addr *)&saddr->a6, NULL);
25587         dst_release(dst);
25588         return 0;
25589  }
25590 diff -NurpP --minimal linux-3.9.5/net/netfilter/ipvs/ip_vs_xmit.c linux-3.9.5-vs2.3.6.5/net/netfilter/ipvs/ip_vs_xmit.c
25591 --- linux-3.9.5/net/netfilter/ipvs/ip_vs_xmit.c 2013-02-19 13:58:59.000000000 +0000
25592 +++ linux-3.9.5-vs2.3.6.5/net/netfilter/ipvs/ip_vs_xmit.c       2013-05-31 17:17:54.000000000 +0000
25593 @@ -273,7 +273,7 @@ __ip_vs_route_output_v6(struct net *net,
25594                 return dst;
25595         if (ipv6_addr_any(&fl6.saddr) &&
25596             ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
25597 -                              &fl6.daddr, 0, &fl6.saddr) < 0)
25598 +                              &fl6.daddr, 0, &fl6.saddr, NULL) < 0)
25599                 goto out_err;
25600         if (do_xfrm) {
25601                 dst = xfrm_lookup(net, dst, flowi6_to_flowi(&fl6), NULL, 0);
25602 diff -NurpP --minimal linux-3.9.5/net/netlink/af_netlink.c linux-3.9.5-vs2.3.6.5/net/netlink/af_netlink.c
25603 --- linux-3.9.5/net/netlink/af_netlink.c        2013-05-31 13:45:33.000000000 +0000
25604 +++ linux-3.9.5-vs2.3.6.5/net/netlink/af_netlink.c      2013-05-31 17:17:54.000000000 +0000
25605 @@ -55,6 +55,9 @@
25606  #include <linux/types.h>
25607  #include <linux/audit.h>
25608  #include <linux/mutex.h>
25609 +#include <linux/vs_context.h>
25610 +#include <linux/vs_network.h>
25611 +#include <linux/vs_limit.h>
25612  
25613  #include <net/net_namespace.h>
25614  #include <net/sock.h>
25615 @@ -1976,6 +1979,8 @@ static struct sock *netlink_seq_socket_i
25616                         sk_for_each(s, &hash->table[j]) {
25617                                 if (sock_net(s) != seq_file_net(seq))
25618                                         continue;
25619 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25620 +                                       continue;
25621                                 if (off == pos) {
25622                                         iter->link = i;
25623                                         iter->hash_idx = j;
25624 @@ -2010,7 +2015,8 @@ static void *netlink_seq_next(struct seq
25625         s = v;
25626         do {
25627                 s = sk_next(s);
25628 -       } while (s && sock_net(s) != seq_file_net(seq));
25629 +       } while (s && (sock_net(s) != seq_file_net(seq) ||
25630 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
25631         if (s)
25632                 return s;
25633  
25634 @@ -2022,7 +2028,8 @@ static void *netlink_seq_next(struct seq
25635  
25636                 for (; j <= hash->mask; j++) {
25637                         s = sk_head(&hash->table[j]);
25638 -                       while (s && sock_net(s) != seq_file_net(seq))
25639 +                       while (s && (sock_net(s) != seq_file_net(seq) ||
25640 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
25641                                 s = sk_next(s);
25642                         if (s) {
25643                                 iter->link = i;
25644 diff -NurpP --minimal linux-3.9.5/net/socket.c linux-3.9.5-vs2.3.6.5/net/socket.c
25645 --- linux-3.9.5/net/socket.c    2013-05-31 13:45:33.000000000 +0000
25646 +++ linux-3.9.5-vs2.3.6.5/net/socket.c  2013-05-31 17:17:54.000000000 +0000
25647 @@ -98,6 +98,10 @@
25648  
25649  #include <net/sock.h>
25650  #include <linux/netfilter.h>
25651 +#include <linux/vs_base.h>
25652 +#include <linux/vs_socket.h>
25653 +#include <linux/vs_inet.h>
25654 +#include <linux/vs_inet6.h>
25655  
25656  #include <linux/if_tun.h>
25657  #include <linux/ipv6_route.h>
25658 @@ -617,13 +621,29 @@ static inline int __sock_sendmsg_nosec(s
25659                                        struct msghdr *msg, size_t size)
25660  {
25661         struct sock_iocb *si = kiocb_to_siocb(iocb);
25662 +       size_t len;
25663  
25664         si->sock = sock;
25665         si->scm = NULL;
25666         si->msg = msg;
25667         si->size = size;
25668  
25669 -       return sock->ops->sendmsg(iocb, sock, msg, size);
25670 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
25671 +       if (sock->sk) {
25672 +               if (len == size)
25673 +                       vx_sock_send(sock->sk, size);
25674 +               else
25675 +                       vx_sock_fail(sock->sk, size);
25676 +       }
25677 +       vxdprintk(VXD_CBIT(net, 7),
25678 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%zu",
25679 +               sock, sock->sk,
25680 +               (sock->sk)?sock->sk->sk_nx_info:0,
25681 +               (sock->sk)?sock->sk->sk_vx_info:0,
25682 +               (sock->sk)?sock->sk->sk_xid:0,
25683 +               (sock->sk)?sock->sk->sk_nid:0,
25684 +               (unsigned int)size, len);
25685 +       return len;
25686  }
25687  
25688  static inline int __sock_sendmsg(struct kiocb *iocb, struct socket *sock,
25689 @@ -779,6 +799,7 @@ static inline int __sock_recvmsg_nosec(s
25690                                        struct msghdr *msg, size_t size, int flags)
25691  {
25692         struct sock_iocb *si = kiocb_to_siocb(iocb);
25693 +       int len;
25694  
25695         si->sock = sock;
25696         si->scm = NULL;
25697 @@ -786,7 +807,18 @@ static inline int __sock_recvmsg_nosec(s
25698         si->size = size;
25699         si->flags = flags;
25700  
25701 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
25702 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
25703 +       if ((len >= 0) && sock->sk)
25704 +               vx_sock_recv(sock->sk, len);
25705 +       vxdprintk(VXD_CBIT(net, 7),
25706 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
25707 +               sock, sock->sk,
25708 +               (sock->sk)?sock->sk->sk_nx_info:0,
25709 +               (sock->sk)?sock->sk->sk_vx_info:0,
25710 +               (sock->sk)?sock->sk->sk_xid:0,
25711 +               (sock->sk)?sock->sk->sk_nid:0,
25712 +               (unsigned int)size, len);
25713 +       return len;
25714  }
25715  
25716  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
25717 @@ -1269,6 +1301,13 @@ int __sock_create(struct net *net, int f
25718         if (type < 0 || type >= SOCK_MAX)
25719                 return -EINVAL;
25720  
25721 +       if (!nx_check(0, VS_ADMIN)) {
25722 +               if (family == PF_INET && !current_nx_info_has_v4())
25723 +                       return -EAFNOSUPPORT;
25724 +               if (family == PF_INET6 && !current_nx_info_has_v6())
25725 +                       return -EAFNOSUPPORT;
25726 +       }
25727 +
25728         /* Compatibility.
25729  
25730            This uglymoron is moved from INET layer to here to avoid
25731 @@ -1403,6 +1442,7 @@ SYSCALL_DEFINE3(socket, int, family, int
25732         if (retval < 0)
25733                 goto out;
25734  
25735 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
25736         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
25737         if (retval < 0)
25738                 goto out_release;
25739 @@ -1444,10 +1484,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
25740         err = sock_create(family, type, protocol, &sock1);
25741         if (err < 0)
25742                 goto out;
25743 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
25744  
25745         err = sock_create(family, type, protocol, &sock2);
25746         if (err < 0)
25747                 goto out_release_1;
25748 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
25749  
25750         err = sock1->ops->socketpair(sock1, sock2);
25751         if (err < 0)
25752 diff -NurpP --minimal linux-3.9.5/net/sunrpc/auth.c linux-3.9.5-vs2.3.6.5/net/sunrpc/auth.c
25753 --- linux-3.9.5/net/sunrpc/auth.c       2013-05-31 13:45:33.000000000 +0000
25754 +++ linux-3.9.5-vs2.3.6.5/net/sunrpc/auth.c     2013-06-03 20:11:37.000000000 +0000
25755 @@ -15,6 +15,7 @@
25756  #include <linux/sunrpc/clnt.h>
25757  #include <linux/sunrpc/gss_api.h>
25758  #include <linux/spinlock.h>
25759 +#include <linux/vs_tag.h>
25760  
25761  #ifdef RPC_DEBUG
25762  # define RPCDBG_FACILITY       RPCDBG_AUTH
25763 @@ -480,6 +481,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
25764         memset(&acred, 0, sizeof(acred));
25765         acred.uid = cred->fsuid;
25766         acred.gid = cred->fsgid;
25767 +       acred.tag = make_ktag(&init_user_ns, dx_current_tag());
25768         acred.group_info = get_group_info(((struct cred *)cred)->group_info);
25769  
25770         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
25771 @@ -520,6 +522,7 @@ rpcauth_bind_root_cred(struct rpc_task *
25772         struct auth_cred acred = {
25773                 .uid = GLOBAL_ROOT_UID,
25774                 .gid = GLOBAL_ROOT_GID,
25775 +               .tag = KTAGT_INIT(dx_current_tag()),
25776         };
25777  
25778         dprintk("RPC: %5u looking up %s cred\n",
25779 diff -NurpP --minimal linux-3.9.5/net/sunrpc/auth_unix.c linux-3.9.5-vs2.3.6.5/net/sunrpc/auth_unix.c
25780 --- linux-3.9.5/net/sunrpc/auth_unix.c  2013-05-31 13:45:33.000000000 +0000
25781 +++ linux-3.9.5-vs2.3.6.5/net/sunrpc/auth_unix.c        2013-06-03 19:35:29.000000000 +0000
25782 @@ -13,11 +13,13 @@
25783  #include <linux/sunrpc/clnt.h>
25784  #include <linux/sunrpc/auth.h>
25785  #include <linux/user_namespace.h>
25786 +#include <linux/vs_tag.h>
25787  
25788  #define NFS_NGROUPS    16
25789  
25790  struct unx_cred {
25791         struct rpc_cred         uc_base;
25792 +       ktag_t                  uc_tag;
25793         kgid_t                  uc_gid;
25794         kgid_t                  uc_gids[NFS_NGROUPS];
25795  };
25796 @@ -80,6 +82,7 @@ unx_create_cred(struct rpc_auth *auth, s
25797                 groups = NFS_NGROUPS;
25798  
25799         cred->uc_gid = acred->gid;
25800 +       cred->uc_tag = acred->tag;
25801         for (i = 0; i < groups; i++)
25802                 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
25803         if (i < NFS_NGROUPS)
25804 @@ -121,7 +124,9 @@ unx_match(struct auth_cred *acred, struc
25805         unsigned int i;
25806  
25807  
25808 -       if (!uid_eq(cred->uc_uid, acred->uid) || !gid_eq(cred->uc_gid, acred->gid))
25809 +       if (!uid_eq(cred->uc_uid, acred->uid) ||
25810 +           !gid_eq(cred->uc_gid, acred->gid) ||
25811 +           !tag_eq(cred->uc_tag, acred->tag))
25812                 return 0;
25813  
25814         if (acred->group_info != NULL)
25815 @@ -146,7 +151,7 @@ unx_marshal(struct rpc_task *task, __be3
25816         struct rpc_clnt *clnt = task->tk_client;
25817         struct unx_cred *cred = container_of(task->tk_rqstp->rq_cred, struct unx_cred, uc_base);
25818         __be32          *base, *hold;
25819 -       int             i;
25820 +       int             i, tag;
25821  
25822         *p++ = htonl(RPC_AUTH_UNIX);
25823         base = p++;
25824 @@ -157,8 +162,11 @@ unx_marshal(struct rpc_task *task, __be3
25825          */
25826         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
25827  
25828 -       *p++ = htonl((u32) from_kuid(&init_user_ns, cred->uc_uid));
25829 -       *p++ = htonl((u32) from_kgid(&init_user_ns, cred->uc_gid));
25830 +       tag = task->tk_client->cl_tag;
25831 +       *p++ = htonl((u32) from_kuid(&init_user_ns,
25832 +               TAGINO_KUID(tag, cred->uc_uid, cred->uc_tag)));
25833 +       *p++ = htonl((u32) from_kgid(&init_user_ns,
25834 +               TAGINO_KGID(tag, cred->uc_gid, cred->uc_tag)));
25835         hold = p++;
25836         for (i = 0; i < 16 && gid_valid(cred->uc_gids[i]); i++)
25837                 *p++ = htonl((u32) from_kgid(&init_user_ns, cred->uc_gids[i]));
25838 diff -NurpP --minimal linux-3.9.5/net/sunrpc/clnt.c linux-3.9.5-vs2.3.6.5/net/sunrpc/clnt.c
25839 --- linux-3.9.5/net/sunrpc/clnt.c       2013-05-31 13:45:33.000000000 +0000
25840 +++ linux-3.9.5-vs2.3.6.5/net/sunrpc/clnt.c     2013-05-31 17:17:54.000000000 +0000
25841 @@ -31,6 +31,7 @@
25842  #include <linux/in6.h>
25843  #include <linux/un.h>
25844  #include <linux/rcupdate.h>
25845 +#include <linux/vs_cvirt.h>
25846  
25847  #include <linux/sunrpc/clnt.h>
25848  #include <linux/sunrpc/addr.h>
25849 @@ -482,6 +483,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
25850         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
25851                 clnt->cl_chatty = 1;
25852  
25853 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
25854 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
25855 +               clnt->cl_tag = 1; */
25856         return clnt;
25857  }
25858  EXPORT_SYMBOL_GPL(rpc_create);
25859 diff -NurpP --minimal linux-3.9.5/net/unix/af_unix.c linux-3.9.5-vs2.3.6.5/net/unix/af_unix.c
25860 --- linux-3.9.5/net/unix/af_unix.c      2013-05-31 13:45:33.000000000 +0000
25861 +++ linux-3.9.5-vs2.3.6.5/net/unix/af_unix.c    2013-05-31 17:17:54.000000000 +0000
25862 @@ -114,6 +114,8 @@
25863  #include <linux/mount.h>
25864  #include <net/checksum.h>
25865  #include <linux/security.h>
25866 +#include <linux/vs_context.h>
25867 +#include <linux/vs_limit.h>
25868  
25869  struct hlist_head unix_socket_table[2 * UNIX_HASH_SIZE];
25870  EXPORT_SYMBOL_GPL(unix_socket_table);
25871 @@ -270,6 +272,8 @@ static struct sock *__unix_find_socket_b
25872                 if (!net_eq(sock_net(s), net))
25873                         continue;
25874  
25875 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25876 +                       continue;
25877                 if (u->addr->len == len &&
25878                     !memcmp(u->addr->name, sunname, len))
25879                         goto found;
25880 @@ -2256,6 +2260,8 @@ static struct sock *unix_from_bucket(str
25881         for (sk = sk_head(&unix_socket_table[bucket]); sk; sk = sk_next(sk)) {
25882                 if (sock_net(sk) != seq_file_net(seq))
25883                         continue;
25884 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25885 +                       continue;
25886                 if (++count == offset)
25887                         break;
25888         }
25889 @@ -2273,6 +2279,8 @@ static struct sock *unix_next_socket(str
25890                 sk = sk_next(sk);
25891                 if (!sk)
25892                         goto next_bucket;
25893 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25894 +                       continue;
25895                 if (sock_net(sk) == seq_file_net(seq))
25896                         return sk;
25897         }
25898 diff -NurpP --minimal linux-3.9.5/scripts/checksyscalls.sh linux-3.9.5-vs2.3.6.5/scripts/checksyscalls.sh
25899 --- linux-3.9.5/scripts/checksyscalls.sh        2012-12-11 03:30:57.000000000 +0000
25900 +++ linux-3.9.5-vs2.3.6.5/scripts/checksyscalls.sh      2013-05-31 14:47:11.000000000 +0000
25901 @@ -193,7 +193,6 @@ cat << EOF
25902  #define __IGNORE_afs_syscall
25903  #define __IGNORE_getpmsg
25904  #define __IGNORE_putpmsg
25905 -#define __IGNORE_vserver
25906  EOF
25907  }
25908  
25909 diff -NurpP --minimal linux-3.9.5/security/commoncap.c linux-3.9.5-vs2.3.6.5/security/commoncap.c
25910 --- linux-3.9.5/security/commoncap.c    2013-05-31 13:45:34.000000000 +0000
25911 +++ linux-3.9.5-vs2.3.6.5/security/commoncap.c  2013-05-31 15:07:02.000000000 +0000
25912 @@ -76,6 +76,7 @@ int cap_netlink_send(struct sock *sk, st
25913  int cap_capable(const struct cred *cred, struct user_namespace *targ_ns,
25914                 int cap, int audit)
25915  {
25916 +       struct vx_info *vxi = current_vx_info(); /* FIXME: get vxi from cred? */
25917         struct user_namespace *ns = targ_ns;
25918  
25919         /* See if cred has the capability in the target user namespace
25920 @@ -84,8 +85,12 @@ int cap_capable(const struct cred *cred,
25921          */
25922         for (;;) {
25923                 /* Do we have the necessary capabilities? */
25924 -               if (ns == cred->user_ns)
25925 -                       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
25926 +               if (ns == cred->user_ns) {
25927 +                       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
25928 +                           cap_raised(cred->cap_effective, cap))
25929 +                               return 0;
25930 +                       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
25931 +               }
25932  
25933                 /* Have we tried all of the parent namespaces? */
25934                 if (ns == &init_user_ns)
25935 @@ -628,7 +633,7 @@ int cap_inode_setxattr(struct dentry *de
25936  
25937         if (!strncmp(name, XATTR_SECURITY_PREFIX,
25938                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
25939 -           !capable(CAP_SYS_ADMIN))
25940 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
25941                 return -EPERM;
25942         return 0;
25943  }
25944 @@ -654,7 +659,7 @@ int cap_inode_removexattr(struct dentry
25945  
25946         if (!strncmp(name, XATTR_SECURITY_PREFIX,
25947                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
25948 -           !capable(CAP_SYS_ADMIN))
25949 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
25950                 return -EPERM;
25951         return 0;
25952  }
25953 diff -NurpP --minimal linux-3.9.5/security/selinux/hooks.c linux-3.9.5-vs2.3.6.5/security/selinux/hooks.c
25954 --- linux-3.9.5/security/selinux/hooks.c        2013-05-31 13:45:34.000000000 +0000
25955 +++ linux-3.9.5-vs2.3.6.5/security/selinux/hooks.c      2013-05-31 14:47:11.000000000 +0000
25956 @@ -67,7 +67,6 @@
25957  #include <linux/dccp.h>
25958  #include <linux/quota.h>
25959  #include <linux/un.h>          /* for Unix socket types */
25960 -#include <net/af_unix.h>       /* for Unix socket types */
25961  #include <linux/parser.h>
25962  #include <linux/nfs_mount.h>
25963  #include <net/ipv6.h>
This page took 2.375685 seconds and 4 git commands to generate.