]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
- rel 3; vserver patch up to patch-3.9.4-vs2.3.6.3.diff
[packages/kernel.git] / kernel-vserver-2.3.patch
1 diff -NurpP --minimal linux-3.9.4/Documentation/vserver/debug.txt linux-3.9.4-vs2.3.6.3/Documentation/vserver/debug.txt
2 --- linux-3.9.4/Documentation/vserver/debug.txt 1970-01-01 00:00:00.000000000 +0000
3 +++ linux-3.9.4-vs2.3.6.3/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.4/arch/alpha/Kconfig linux-3.9.4-vs2.3.6.3/arch/alpha/Kconfig
160 --- linux-3.9.4/arch/alpha/Kconfig      2013-05-31 13:44:28.000000000 +0000
161 +++ linux-3.9.4-vs2.3.6.3/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.4/arch/alpha/kernel/systbls.S linux-3.9.4-vs2.3.6.3/arch/alpha/kernel/systbls.S
172 --- linux-3.9.4/arch/alpha/kernel/systbls.S     2013-02-19 13:56:11.000000000 +0000
173 +++ linux-3.9.4-vs2.3.6.3/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.4/arch/alpha/kernel/traps.c linux-3.9.4-vs2.3.6.3/arch/alpha/kernel/traps.c
184 --- linux-3.9.4/arch/alpha/kernel/traps.c       2013-05-31 13:44:28.000000000 +0000
185 +++ linux-3.9.4-vs2.3.6.3/arch/alpha/kernel/traps.c     2013-05-31 14:47:11.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.4/arch/arm/Kconfig linux-3.9.4-vs2.3.6.3/arch/arm/Kconfig
197 --- linux-3.9.4/arch/arm/Kconfig        2013-05-31 13:44:29.000000000 +0000
198 +++ linux-3.9.4-vs2.3.6.3/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.4/arch/arm/kernel/calls.S linux-3.9.4-vs2.3.6.3/arch/arm/kernel/calls.S
209 --- linux-3.9.4/arch/arm/kernel/calls.S 2013-05-31 13:44:29.000000000 +0000
210 +++ linux-3.9.4-vs2.3.6.3/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.4/arch/arm/kernel/process.c linux-3.9.4-vs2.3.6.3/arch/arm/kernel/process.c
221 --- linux-3.9.4/arch/arm/kernel/process.c       2013-05-31 13:44:29.000000000 +0000
222 +++ linux-3.9.4-vs2.3.6.3/arch/arm/kernel/process.c     2013-05-31 14:47:11.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.4/arch/arm/kernel/traps.c linux-3.9.4-vs2.3.6.3/arch/arm/kernel/traps.c
234 --- linux-3.9.4/arch/arm/kernel/traps.c 2013-05-31 13:44:29.000000000 +0000
235 +++ linux-3.9.4-vs2.3.6.3/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.4/arch/cris/Kconfig linux-3.9.4-vs2.3.6.3/arch/cris/Kconfig
248 --- linux-3.9.4/arch/cris/Kconfig       2013-05-31 13:44:37.000000000 +0000
249 +++ linux-3.9.4-vs2.3.6.3/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.4/arch/h8300/Kconfig linux-3.9.4-vs2.3.6.3/arch/h8300/Kconfig
260 --- linux-3.9.4/arch/h8300/Kconfig      2013-05-31 13:44:38.000000000 +0000
261 +++ linux-3.9.4-vs2.3.6.3/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.4/arch/ia64/Kconfig linux-3.9.4-vs2.3.6.3/arch/ia64/Kconfig
272 --- linux-3.9.4/arch/ia64/Kconfig       2013-05-31 13:44:38.000000000 +0000
273 +++ linux-3.9.4-vs2.3.6.3/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.4/arch/ia64/kernel/entry.S linux-3.9.4-vs2.3.6.3/arch/ia64/kernel/entry.S
284 --- linux-3.9.4/arch/ia64/kernel/entry.S        2013-05-31 13:44:38.000000000 +0000
285 +++ linux-3.9.4-vs2.3.6.3/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.4/arch/ia64/kernel/process.c linux-3.9.4-vs2.3.6.3/arch/ia64/kernel/process.c
296 --- linux-3.9.4/arch/ia64/kernel/process.c      2013-05-31 13:44:38.000000000 +0000
297 +++ linux-3.9.4-vs2.3.6.3/arch/ia64/kernel/process.c    2013-05-31 14:47:11.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.4/arch/ia64/kernel/ptrace.c linux-3.9.4-vs2.3.6.3/arch/ia64/kernel/ptrace.c
310 --- linux-3.9.4/arch/ia64/kernel/ptrace.c       2013-02-19 13:56:51.000000000 +0000
311 +++ linux-3.9.4-vs2.3.6.3/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.4/arch/ia64/kernel/traps.c linux-3.9.4-vs2.3.6.3/arch/ia64/kernel/traps.c
321 --- linux-3.9.4/arch/ia64/kernel/traps.c        2013-05-31 13:44:38.000000000 +0000
322 +++ linux-3.9.4-vs2.3.6.3/arch/ia64/kernel/traps.c      2013-05-31 14:47:11.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.4/arch/m32r/kernel/traps.c linux-3.9.4-vs2.3.6.3/arch/m32r/kernel/traps.c
348 --- linux-3.9.4/arch/m32r/kernel/traps.c        2012-12-11 03:30:57.000000000 +0000
349 +++ linux-3.9.4-vs2.3.6.3/arch/m32r/kernel/traps.c      2013-05-31 14:47:11.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.4/arch/m68k/Kconfig linux-3.9.4-vs2.3.6.3/arch/m68k/Kconfig
363 --- linux-3.9.4/arch/m68k/Kconfig       2013-05-31 13:44:38.000000000 +0000
364 +++ linux-3.9.4-vs2.3.6.3/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.4/arch/mips/Kconfig linux-3.9.4-vs2.3.6.3/arch/mips/Kconfig
375 --- linux-3.9.4/arch/mips/Kconfig       2013-05-31 13:44:39.000000000 +0000
376 +++ linux-3.9.4-vs2.3.6.3/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.4/arch/mips/kernel/ptrace.c linux-3.9.4-vs2.3.6.3/arch/mips/kernel/ptrace.c
387 --- linux-3.9.4/arch/mips/kernel/ptrace.c       2013-05-31 13:44:42.000000000 +0000
388 +++ linux-3.9.4-vs2.3.6.3/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.4/arch/mips/kernel/scall32-o32.S linux-3.9.4-vs2.3.6.3/arch/mips/kernel/scall32-o32.S
408 --- linux-3.9.4/arch/mips/kernel/scall32-o32.S  2013-05-31 13:44:42.000000000 +0000
409 +++ linux-3.9.4-vs2.3.6.3/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.4/arch/mips/kernel/scall64-64.S linux-3.9.4-vs2.3.6.3/arch/mips/kernel/scall64-64.S
420 --- linux-3.9.4/arch/mips/kernel/scall64-64.S   2013-05-31 13:44:42.000000000 +0000
421 +++ linux-3.9.4-vs2.3.6.3/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.4/arch/mips/kernel/scall64-n32.S linux-3.9.4-vs2.3.6.3/arch/mips/kernel/scall64-n32.S
432 --- linux-3.9.4/arch/mips/kernel/scall64-n32.S  2013-05-31 13:44:42.000000000 +0000
433 +++ linux-3.9.4-vs2.3.6.3/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.4/arch/mips/kernel/scall64-o32.S linux-3.9.4-vs2.3.6.3/arch/mips/kernel/scall64-o32.S
444 --- linux-3.9.4/arch/mips/kernel/scall64-o32.S  2013-05-31 13:44:42.000000000 +0000
445 +++ linux-3.9.4-vs2.3.6.3/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.4/arch/mips/kernel/traps.c linux-3.9.4-vs2.3.6.3/arch/mips/kernel/traps.c
456 --- linux-3.9.4/arch/mips/kernel/traps.c        2013-05-31 13:44:42.000000000 +0000
457 +++ linux-3.9.4-vs2.3.6.3/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.4/arch/parisc/Kconfig linux-3.9.4-vs2.3.6.3/arch/parisc/Kconfig
473 --- linux-3.9.4/arch/parisc/Kconfig     2013-05-31 13:44:44.000000000 +0000
474 +++ linux-3.9.4-vs2.3.6.3/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.4/arch/parisc/kernel/syscall_table.S linux-3.9.4-vs2.3.6.3/arch/parisc/kernel/syscall_table.S
485 --- linux-3.9.4/arch/parisc/kernel/syscall_table.S      2013-05-31 13:44:44.000000000 +0000
486 +++ linux-3.9.4-vs2.3.6.3/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.4/arch/parisc/kernel/traps.c linux-3.9.4-vs2.3.6.3/arch/parisc/kernel/traps.c
497 --- linux-3.9.4/arch/parisc/kernel/traps.c      2013-05-31 13:44:44.000000000 +0000
498 +++ linux-3.9.4-vs2.3.6.3/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.4/arch/parisc/mm/fault.c linux-3.9.4-vs2.3.6.3/arch/parisc/mm/fault.c
523 --- linux-3.9.4/arch/parisc/mm/fault.c  2013-05-31 13:44:44.000000000 +0000
524 +++ linux-3.9.4-vs2.3.6.3/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.4/arch/powerpc/Kconfig linux-3.9.4-vs2.3.6.3/arch/powerpc/Kconfig
538 --- linux-3.9.4/arch/powerpc/Kconfig    2013-05-31 13:44:44.000000000 +0000
539 +++ linux-3.9.4-vs2.3.6.3/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.4/arch/powerpc/include/uapi/asm/unistd.h linux-3.9.4-vs2.3.6.3/arch/powerpc/include/uapi/asm/unistd.h
550 --- linux-3.9.4/arch/powerpc/include/uapi/asm/unistd.h  2013-05-31 13:44:44.000000000 +0000
551 +++ linux-3.9.4-vs2.3.6.3/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.4/arch/powerpc/kernel/process.c linux-3.9.4-vs2.3.6.3/arch/powerpc/kernel/process.c
562 --- linux-3.9.4/arch/powerpc/kernel/process.c   2013-05-31 13:44:44.000000000 +0000
563 +++ linux-3.9.4-vs2.3.6.3/arch/powerpc/kernel/process.c 2013-05-31 14:47:11.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.4/arch/powerpc/kernel/traps.c linux-3.9.4-vs2.3.6.3/arch/powerpc/kernel/traps.c
577 --- linux-3.9.4/arch/powerpc/kernel/traps.c     2013-05-31 14:22:26.000000000 +0000
578 +++ linux-3.9.4-vs2.3.6.3/arch/powerpc/kernel/traps.c   2013-05-31 14:47:11.000000000 +0000
579 @@ -1167,8 +1167,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.4/arch/s390/Kconfig linux-3.9.4-vs2.3.6.3/arch/s390/Kconfig
592 --- linux-3.9.4/arch/s390/Kconfig       2013-05-31 13:44:45.000000000 +0000
593 +++ linux-3.9.4-vs2.3.6.3/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.4/arch/s390/include/asm/tlb.h linux-3.9.4-vs2.3.6.3/arch/s390/include/asm/tlb.h
604 --- linux-3.9.4/arch/s390/include/asm/tlb.h     2012-12-11 03:30:57.000000000 +0000
605 +++ linux-3.9.4-vs2.3.6.3/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.4/arch/s390/include/uapi/asm/unistd.h linux-3.9.4-vs2.3.6.3/arch/s390/include/uapi/asm/unistd.h
615 --- linux-3.9.4/arch/s390/include/uapi/asm/unistd.h     2013-02-19 13:57:16.000000000 +0000
616 +++ linux-3.9.4-vs2.3.6.3/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.4/arch/s390/kernel/ptrace.c linux-3.9.4-vs2.3.6.3/arch/s390/kernel/ptrace.c
627 --- linux-3.9.4/arch/s390/kernel/ptrace.c       2012-12-11 03:30:57.000000000 +0000
628 +++ linux-3.9.4-vs2.3.6.3/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.4/arch/s390/kernel/syscalls.S linux-3.9.4-vs2.3.6.3/arch/s390/kernel/syscalls.S
638 --- linux-3.9.4/arch/s390/kernel/syscalls.S     2013-05-31 13:44:45.000000000 +0000
639 +++ linux-3.9.4-vs2.3.6.3/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.4/arch/sh/Kconfig linux-3.9.4-vs2.3.6.3/arch/sh/Kconfig
650 --- linux-3.9.4/arch/sh/Kconfig 2013-05-31 13:44:45.000000000 +0000
651 +++ linux-3.9.4-vs2.3.6.3/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.4/arch/sh/kernel/irq.c linux-3.9.4-vs2.3.6.3/arch/sh/kernel/irq.c
662 --- linux-3.9.4/arch/sh/kernel/irq.c    2012-12-11 03:30:57.000000000 +0000
663 +++ linux-3.9.4-vs2.3.6.3/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.4/arch/sparc/Kconfig linux-3.9.4-vs2.3.6.3/arch/sparc/Kconfig
673 --- linux-3.9.4/arch/sparc/Kconfig      2013-05-31 13:44:47.000000000 +0000
674 +++ linux-3.9.4-vs2.3.6.3/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.4/arch/sparc/include/uapi/asm/unistd.h linux-3.9.4-vs2.3.6.3/arch/sparc/include/uapi/asm/unistd.h
685 --- linux-3.9.4/arch/sparc/include/uapi/asm/unistd.h    2013-02-19 13:57:17.000000000 +0000
686 +++ linux-3.9.4-vs2.3.6.3/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.4/arch/sparc/kernel/systbls_32.S linux-3.9.4-vs2.3.6.3/arch/sparc/kernel/systbls_32.S
697 --- linux-3.9.4/arch/sparc/kernel/systbls_32.S  2013-05-31 13:44:48.000000000 +0000
698 +++ linux-3.9.4-vs2.3.6.3/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.4/arch/sparc/kernel/systbls_64.S linux-3.9.4-vs2.3.6.3/arch/sparc/kernel/systbls_64.S
709 --- linux-3.9.4/arch/sparc/kernel/systbls_64.S  2013-05-31 13:44:48.000000000 +0000
710 +++ linux-3.9.4-vs2.3.6.3/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.4/arch/um/Kconfig.rest linux-3.9.4-vs2.3.6.3/arch/um/Kconfig.rest
730 --- linux-3.9.4/arch/um/Kconfig.rest    2012-12-11 03:30:57.000000000 +0000
731 +++ linux-3.9.4-vs2.3.6.3/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.4/arch/x86/Kconfig linux-3.9.4-vs2.3.6.3/arch/x86/Kconfig
742 --- linux-3.9.4/arch/x86/Kconfig        2013-05-31 14:22:26.000000000 +0000
743 +++ linux-3.9.4-vs2.3.6.3/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.4/arch/x86/syscalls/syscall_32.tbl linux-3.9.4-vs2.3.6.3/arch/x86/syscalls/syscall_32.tbl
754 --- linux-3.9.4/arch/x86/syscalls/syscall_32.tbl        2013-05-31 13:44:50.000000000 +0000
755 +++ linux-3.9.4-vs2.3.6.3/arch/x86/syscalls/syscall_32.tbl      2013-05-31 14:47:11.000000000 +0000
756 @@ -279,7 +279,7 @@
757  270    i386    tgkill                  sys_tgkill
758  271    i386    utimes                  sys_utimes                      compat_sys_utimes
759  272    i386    fadvise64_64            sys_fadvise64_64                sys32_fadvise64_64
760 -273    i386    vserver
761 +273    i386    vserver                 sys_vserver                     sys32_vserver
762  274    i386    mbind                   sys_mbind
763  275    i386    get_mempolicy           sys_get_mempolicy               compat_sys_get_mempolicy
764  276    i386    set_mempolicy           sys_set_mempolicy
765 diff -NurpP --minimal linux-3.9.4/arch/x86/syscalls/syscall_64.tbl linux-3.9.4-vs2.3.6.3/arch/x86/syscalls/syscall_64.tbl
766 --- linux-3.9.4/arch/x86/syscalls/syscall_64.tbl        2013-05-31 13:44:50.000000000 +0000
767 +++ linux-3.9.4-vs2.3.6.3/arch/x86/syscalls/syscall_64.tbl      2013-05-31 14:47:11.000000000 +0000
768 @@ -242,7 +242,7 @@
769  233    common  epoll_ctl               sys_epoll_ctl
770  234    common  tgkill                  sys_tgkill
771  235    common  utimes                  sys_utimes
772 -236    64      vserver
773 +236    64      vserver                 sys_vserver
774  237    common  mbind                   sys_mbind
775  238    common  set_mempolicy           sys_set_mempolicy
776  239    common  get_mempolicy           sys_get_mempolicy
777 diff -NurpP --minimal linux-3.9.4/drivers/block/Kconfig linux-3.9.4-vs2.3.6.3/drivers/block/Kconfig
778 --- linux-3.9.4/drivers/block/Kconfig   2013-05-31 13:44:51.000000000 +0000
779 +++ linux-3.9.4-vs2.3.6.3/drivers/block/Kconfig 2013-05-31 14:47:11.000000000 +0000
780 @@ -278,6 +278,13 @@ config BLK_DEV_CRYPTOLOOP
781  
782  source "drivers/block/drbd/Kconfig"
783  
784 +config BLK_DEV_VROOT
785 +       tristate "Virtual Root device support"
786 +       depends on QUOTACTL
787 +       ---help---
788 +         Saying Y here will allow you to use quota/fs ioctls on a shared
789 +         partition within a virtual server without compromising security.
790 +
791  config BLK_DEV_NBD
792         tristate "Network block device support"
793         depends on NET
794 diff -NurpP --minimal linux-3.9.4/drivers/block/Makefile linux-3.9.4-vs2.3.6.3/drivers/block/Makefile
795 --- linux-3.9.4/drivers/block/Makefile  2013-05-31 13:44:51.000000000 +0000
796 +++ linux-3.9.4-vs2.3.6.3/drivers/block/Makefile        2013-05-31 14:47:11.000000000 +0000
797 @@ -33,6 +33,7 @@ obj-$(CONFIG_VIRTIO_BLK)      += virtio_blk.o
798  obj-$(CONFIG_VIODASD)          += viodasd.o
799  obj-$(CONFIG_BLK_DEV_SX8)      += sx8.o
800  obj-$(CONFIG_BLK_DEV_HD)       += hd.o
801 +obj-$(CONFIG_BLK_DEV_VROOT)    += vroot.o
802  
803  obj-$(CONFIG_XEN_BLKDEV_FRONTEND)      += xen-blkfront.o
804  obj-$(CONFIG_XEN_BLKDEV_BACKEND)       += xen-blkback/
805 diff -NurpP --minimal linux-3.9.4/drivers/block/loop.c linux-3.9.4-vs2.3.6.3/drivers/block/loop.c
806 --- linux-3.9.4/drivers/block/loop.c    2013-05-31 13:44:51.000000000 +0000
807 +++ linux-3.9.4-vs2.3.6.3/drivers/block/loop.c  2013-05-31 14:47:11.000000000 +0000
808 @@ -76,6 +76,7 @@
809  #include <linux/sysfs.h>
810  #include <linux/miscdevice.h>
811  #include <linux/falloc.h>
812 +#include <linux/vs_context.h>
813  
814  #include <asm/uaccess.h>
815  
816 @@ -882,6 +883,7 @@ static int loop_set_fd(struct loop_devic
817         lo->lo_blocksize = lo_blocksize;
818         lo->lo_device = bdev;
819         lo->lo_flags = lo_flags;
820 +       lo->lo_xid = vx_current_xid();
821         lo->lo_backing_file = file;
822         lo->transfer = transfer_none;
823         lo->ioctl = NULL;
824 @@ -1033,6 +1035,7 @@ static int loop_clr_fd(struct loop_devic
825         lo->lo_sizelimit = 0;
826         lo->lo_encrypt_key_size = 0;
827         lo->lo_thread = NULL;
828 +       lo->lo_xid = 0;
829         memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
830         memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
831         memset(lo->lo_file_name, 0, LO_NAME_SIZE);
832 @@ -1076,7 +1079,7 @@ loop_set_status(struct loop_device *lo,
833  
834         if (lo->lo_encrypt_key_size &&
835             !uid_eq(lo->lo_key_owner, uid) &&
836 -           !capable(CAP_SYS_ADMIN))
837 +           !vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP))
838                 return -EPERM;
839         if (lo->lo_state != Lo_bound)
840                 return -ENXIO;
841 @@ -1166,7 +1169,8 @@ loop_get_status(struct loop_device *lo,
842         memcpy(info->lo_crypt_name, lo->lo_crypt_name, LO_NAME_SIZE);
843         info->lo_encrypt_type =
844                 lo->lo_encryption ? lo->lo_encryption->number : 0;
845 -       if (lo->lo_encrypt_key_size && capable(CAP_SYS_ADMIN)) {
846 +       if (lo->lo_encrypt_key_size &&
847 +               vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP)) {
848                 info->lo_encrypt_key_size = lo->lo_encrypt_key_size;
849                 memcpy(info->lo_encrypt_key, lo->lo_encrypt_key,
850                        lo->lo_encrypt_key_size);
851 @@ -1508,6 +1512,11 @@ static int lo_open(struct block_device *
852                 goto out;
853         }
854  
855 +       if (!vx_check(lo->lo_xid, VS_IDENT|VS_HOSTID|VS_ADMIN_P)) {
856 +               err = -EACCES;
857 +               goto out;
858 +       }
859 +
860         mutex_lock(&lo->lo_ctl_mutex);
861         lo->lo_refcnt++;
862         mutex_unlock(&lo->lo_ctl_mutex);
863 diff -NurpP --minimal linux-3.9.4/drivers/block/vroot.c linux-3.9.4-vs2.3.6.3/drivers/block/vroot.c
864 --- linux-3.9.4/drivers/block/vroot.c   1970-01-01 00:00:00.000000000 +0000
865 +++ linux-3.9.4-vs2.3.6.3/drivers/block/vroot.c 2013-05-31 14:47:11.000000000 +0000
866 @@ -0,0 +1,291 @@
867 +/*
868 + *  linux/drivers/block/vroot.c
869 + *
870 + *  written by Herbert Pötzl, 9/11/2002
871 + *  ported to 2.6.10 by Herbert Pötzl, 30/12/2004
872 + *
873 + *  based on the loop.c code by Theodore Ts'o.
874 + *
875 + * Copyright (C) 2002-2007 by Herbert Pötzl.
876 + * Redistribution of this file is permitted under the
877 + * GNU General Public License.
878 + *
879 + */
880 +
881 +#include <linux/module.h>
882 +#include <linux/moduleparam.h>
883 +#include <linux/file.h>
884 +#include <linux/major.h>
885 +#include <linux/blkdev.h>
886 +#include <linux/slab.h>
887 +
888 +#include <linux/vroot.h>
889 +#include <linux/vs_context.h>
890 +
891 +
892 +static int max_vroot = 8;
893 +
894 +static struct vroot_device *vroot_dev;
895 +static struct gendisk **disks;
896 +
897 +
898 +static int vroot_set_dev(
899 +       struct vroot_device *vr,
900 +       struct block_device *bdev,
901 +       unsigned int arg)
902 +{
903 +       struct block_device *real_bdev;
904 +       struct file *file;
905 +       struct inode *inode;
906 +       int error;
907 +
908 +       error = -EBUSY;
909 +       if (vr->vr_state != Vr_unbound)
910 +               goto out;
911 +
912 +       error = -EBADF;
913 +       file = fget(arg);
914 +       if (!file)
915 +               goto out;
916 +
917 +       error = -EINVAL;
918 +       inode = file->f_dentry->d_inode;
919 +
920 +
921 +       if (S_ISBLK(inode->i_mode)) {
922 +               real_bdev = inode->i_bdev;
923 +               vr->vr_device = real_bdev;
924 +               __iget(real_bdev->bd_inode);
925 +       } else
926 +               goto out_fput;
927 +
928 +       vxdprintk(VXD_CBIT(misc, 0),
929 +               "vroot[%d]_set_dev: dev=" VXF_DEV,
930 +               vr->vr_number, VXD_DEV(real_bdev));
931 +
932 +       vr->vr_state = Vr_bound;
933 +       error = 0;
934 +
935 + out_fput:
936 +       fput(file);
937 + out:
938 +       return error;
939 +}
940 +
941 +static int vroot_clr_dev(
942 +       struct vroot_device *vr,
943 +       struct block_device *bdev)
944 +{
945 +       struct block_device *real_bdev;
946 +
947 +       if (vr->vr_state != Vr_bound)
948 +               return -ENXIO;
949 +       if (vr->vr_refcnt > 1)  /* we needed one fd for the ioctl */
950 +               return -EBUSY;
951 +
952 +       real_bdev = vr->vr_device;
953 +
954 +       vxdprintk(VXD_CBIT(misc, 0),
955 +               "vroot[%d]_clr_dev: dev=" VXF_DEV,
956 +               vr->vr_number, VXD_DEV(real_bdev));
957 +
958 +       bdput(real_bdev);
959 +       vr->vr_state = Vr_unbound;
960 +       vr->vr_device = NULL;
961 +       return 0;
962 +}
963 +
964 +
965 +static int vr_ioctl(struct block_device *bdev, fmode_t mode,
966 +       unsigned int cmd, unsigned long arg)
967 +{
968 +       struct vroot_device *vr = bdev->bd_disk->private_data;
969 +       int err;
970 +
971 +       down(&vr->vr_ctl_mutex);
972 +       switch (cmd) {
973 +       case VROOT_SET_DEV:
974 +               err = vroot_set_dev(vr, bdev, arg);
975 +               break;
976 +       case VROOT_CLR_DEV:
977 +               err = vroot_clr_dev(vr, bdev);
978 +               break;
979 +       default:
980 +               err = -EINVAL;
981 +               break;
982 +       }
983 +       up(&vr->vr_ctl_mutex);
984 +       return err;
985 +}
986 +
987 +static int vr_open(struct block_device *bdev, fmode_t mode)
988 +{
989 +       struct vroot_device *vr = bdev->bd_disk->private_data;
990 +
991 +       down(&vr->vr_ctl_mutex);
992 +       vr->vr_refcnt++;
993 +       up(&vr->vr_ctl_mutex);
994 +       return 0;
995 +}
996 +
997 +static int vr_release(struct gendisk *disk, fmode_t mode)
998 +{
999 +       struct vroot_device *vr = disk->private_data;
1000 +
1001 +       down(&vr->vr_ctl_mutex);
1002 +       --vr->vr_refcnt;
1003 +       up(&vr->vr_ctl_mutex);
1004 +       return 0;
1005 +}
1006 +
1007 +static struct block_device_operations vr_fops = {
1008 +       .owner =        THIS_MODULE,
1009 +       .open =         vr_open,
1010 +       .release =      vr_release,
1011 +       .ioctl =        vr_ioctl,
1012 +};
1013 +
1014 +static void vroot_make_request(struct request_queue *q, struct bio *bio)
1015 +{
1016 +       printk("vroot_make_request %p, %p\n", q, bio);
1017 +       bio_io_error(bio);
1018 +}
1019 +
1020 +struct block_device *__vroot_get_real_bdev(struct block_device *bdev)
1021 +{
1022 +       struct inode *inode = bdev->bd_inode;
1023 +       struct vroot_device *vr;
1024 +       struct block_device *real_bdev;
1025 +       int minor = iminor(inode);
1026 +
1027 +       vr = &vroot_dev[minor];
1028 +       real_bdev = vr->vr_device;
1029 +
1030 +       vxdprintk(VXD_CBIT(misc, 0),
1031 +               "vroot[%d]_get_real_bdev: dev=" VXF_DEV,
1032 +               vr->vr_number, VXD_DEV(real_bdev));
1033 +
1034 +       if (vr->vr_state != Vr_bound)
1035 +               return ERR_PTR(-ENXIO);
1036 +
1037 +       __iget(real_bdev->bd_inode);
1038 +       return real_bdev;
1039 +}
1040 +
1041 +
1042 +
1043 +/*
1044 + * And now the modules code and kernel interface.
1045 + */
1046 +
1047 +module_param(max_vroot, int, 0);
1048 +
1049 +MODULE_PARM_DESC(max_vroot, "Maximum number of vroot devices (1-256)");
1050 +MODULE_LICENSE("GPL");
1051 +MODULE_ALIAS_BLOCKDEV_MAJOR(VROOT_MAJOR);
1052 +
1053 +MODULE_AUTHOR ("Herbert Pötzl");
1054 +MODULE_DESCRIPTION ("Virtual Root Device Mapper");
1055 +
1056 +
1057 +int __init vroot_init(void)
1058 +{
1059 +       int err, i;
1060 +
1061 +       if (max_vroot < 1 || max_vroot > 256) {
1062 +               max_vroot = MAX_VROOT_DEFAULT;
1063 +               printk(KERN_WARNING "vroot: invalid max_vroot "
1064 +                       "(must be between 1 and 256), "
1065 +                       "using default (%d)\n", max_vroot);
1066 +       }
1067 +
1068 +       if (register_blkdev(VROOT_MAJOR, "vroot"))
1069 +               return -EIO;
1070 +
1071 +       err = -ENOMEM;
1072 +       vroot_dev = kmalloc(max_vroot * sizeof(struct vroot_device), GFP_KERNEL);
1073 +       if (!vroot_dev)
1074 +               goto out_mem1;
1075 +       memset(vroot_dev, 0, max_vroot * sizeof(struct vroot_device));
1076 +
1077 +       disks = kmalloc(max_vroot * sizeof(struct gendisk *), GFP_KERNEL);
1078 +       if (!disks)
1079 +               goto out_mem2;
1080 +
1081 +       for (i = 0; i < max_vroot; i++) {
1082 +               disks[i] = alloc_disk(1);
1083 +               if (!disks[i])
1084 +                       goto out_mem3;
1085 +               disks[i]->queue = blk_alloc_queue(GFP_KERNEL);
1086 +               if (!disks[i]->queue)
1087 +                       goto out_mem3;
1088 +               blk_queue_make_request(disks[i]->queue, vroot_make_request);
1089 +       }
1090 +
1091 +       for (i = 0; i < max_vroot; i++) {
1092 +               struct vroot_device *vr = &vroot_dev[i];
1093 +               struct gendisk *disk = disks[i];
1094 +
1095 +               memset(vr, 0, sizeof(*vr));
1096 +               sema_init(&vr->vr_ctl_mutex, 1);
1097 +               vr->vr_number = i;
1098 +               disk->major = VROOT_MAJOR;
1099 +               disk->first_minor = i;
1100 +               disk->fops = &vr_fops;
1101 +               sprintf(disk->disk_name, "vroot%d", i);
1102 +               disk->private_data = vr;
1103 +       }
1104 +
1105 +       err = register_vroot_grb(&__vroot_get_real_bdev);
1106 +       if (err)
1107 +               goto out_mem3;
1108 +
1109 +       for (i = 0; i < max_vroot; i++)
1110 +               add_disk(disks[i]);
1111 +       printk(KERN_INFO "vroot: loaded (max %d devices)\n", max_vroot);
1112 +       return 0;
1113 +
1114 +out_mem3:
1115 +       while (i--)
1116 +               put_disk(disks[i]);
1117 +       kfree(disks);
1118 +out_mem2:
1119 +       kfree(vroot_dev);
1120 +out_mem1:
1121 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1122 +       printk(KERN_ERR "vroot: ran out of memory\n");
1123 +       return err;
1124 +}
1125 +
1126 +void vroot_exit(void)
1127 +{
1128 +       int i;
1129 +
1130 +       if (unregister_vroot_grb(&__vroot_get_real_bdev))
1131 +               printk(KERN_WARNING "vroot: cannot unregister grb\n");
1132 +
1133 +       for (i = 0; i < max_vroot; i++) {
1134 +               del_gendisk(disks[i]);
1135 +               put_disk(disks[i]);
1136 +       }
1137 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1138 +
1139 +       kfree(disks);
1140 +       kfree(vroot_dev);
1141 +}
1142 +
1143 +module_init(vroot_init);
1144 +module_exit(vroot_exit);
1145 +
1146 +#ifndef MODULE
1147 +
1148 +static int __init max_vroot_setup(char *str)
1149 +{
1150 +       max_vroot = simple_strtol(str, NULL, 0);
1151 +       return 1;
1152 +}
1153 +
1154 +__setup("max_vroot=", max_vroot_setup);
1155 +
1156 +#endif
1157 +
1158 diff -NurpP --minimal linux-3.9.4/drivers/infiniband/Kconfig linux-3.9.4-vs2.3.6.3/drivers/infiniband/Kconfig
1159 --- linux-3.9.4/drivers/infiniband/Kconfig      2012-12-11 03:30:57.000000000 +0000
1160 +++ linux-3.9.4-vs2.3.6.3/drivers/infiniband/Kconfig    2013-05-31 14:47:11.000000000 +0000
1161 @@ -39,7 +39,7 @@ config INFINIBAND_USER_MEM
1162  config INFINIBAND_ADDR_TRANS
1163         bool
1164         depends on INET
1165 -       depends on !(INFINIBAND = y && IPV6 = m)
1166 +       depends on !(INFINIBAND = y && IPV6 = y)
1167         default y
1168  
1169  source "drivers/infiniband/hw/mthca/Kconfig"
1170 diff -NurpP --minimal linux-3.9.4/drivers/infiniband/core/addr.c linux-3.9.4-vs2.3.6.3/drivers/infiniband/core/addr.c
1171 --- linux-3.9.4/drivers/infiniband/core/addr.c  2012-12-11 03:30:57.000000000 +0000
1172 +++ linux-3.9.4-vs2.3.6.3/drivers/infiniband/core/addr.c        2013-05-31 14:47:11.000000000 +0000
1173 @@ -261,7 +261,7 @@ static int addr6_resolve(struct sockaddr
1174  
1175         if (ipv6_addr_any(&fl6.saddr)) {
1176                 ret = ipv6_dev_get_saddr(&init_net, ip6_dst_idev(dst)->dev,
1177 -                                        &fl6.daddr, 0, &fl6.saddr);
1178 +                                        &fl6.daddr, 0, &fl6.saddr, NULL);
1179                 if (ret)
1180                         goto put;
1181  
1182 diff -NurpP --minimal linux-3.9.4/drivers/md/dm-ioctl.c linux-3.9.4-vs2.3.6.3/drivers/md/dm-ioctl.c
1183 --- linux-3.9.4/drivers/md/dm-ioctl.c   2013-05-31 13:44:59.000000000 +0000
1184 +++ linux-3.9.4-vs2.3.6.3/drivers/md/dm-ioctl.c 2013-05-31 14:47:11.000000000 +0000
1185 @@ -16,6 +16,7 @@
1186  #include <linux/dm-ioctl.h>
1187  #include <linux/hdreg.h>
1188  #include <linux/compat.h>
1189 +#include <linux/vs_context.h>
1190  
1191  #include <asm/uaccess.h>
1192  
1193 @@ -106,7 +107,8 @@ static struct hash_cell *__get_name_cell
1194         unsigned int h = hash_str(str);
1195  
1196         list_for_each_entry (hc, _name_buckets + h, name_list)
1197 -               if (!strcmp(hc->name, str)) {
1198 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1199 +                       !strcmp(hc->name, str)) {
1200                         dm_get(hc->md);
1201                         return hc;
1202                 }
1203 @@ -120,7 +122,8 @@ static struct hash_cell *__get_uuid_cell
1204         unsigned int h = hash_str(str);
1205  
1206         list_for_each_entry (hc, _uuid_buckets + h, uuid_list)
1207 -               if (!strcmp(hc->uuid, str)) {
1208 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1209 +                       !strcmp(hc->uuid, str)) {
1210                         dm_get(hc->md);
1211                         return hc;
1212                 }
1213 @@ -131,13 +134,15 @@ static struct hash_cell *__get_uuid_cell
1214  static struct hash_cell *__get_dev_cell(uint64_t dev)
1215  {
1216         struct mapped_device *md;
1217 -       struct hash_cell *hc;
1218 +       struct hash_cell *hc = NULL;
1219  
1220         md = dm_get_md(huge_decode_dev(dev));
1221         if (!md)
1222                 return NULL;
1223  
1224 -       hc = dm_get_mdptr(md);
1225 +       if (vx_check(dm_get_xid(md), VS_WATCH_P | VS_IDENT))
1226 +               hc = dm_get_mdptr(md);
1227 +
1228         if (!hc) {
1229                 dm_put(md);
1230                 return NULL;
1231 @@ -445,6 +450,9 @@ typedef int (*ioctl_fn)(struct dm_ioctl
1232  
1233  static int remove_all(struct dm_ioctl *param, size_t param_size)
1234  {
1235 +       if (!vx_check(0, VS_ADMIN))
1236 +               return -EPERM;
1237 +
1238         dm_hash_remove_all(1);
1239         param->data_size = 0;
1240         return 0;
1241 @@ -492,6 +500,8 @@ static int list_devices(struct dm_ioctl
1242          */
1243         for (i = 0; i < NUM_BUCKETS; i++) {
1244                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1245 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1246 +                               continue;
1247                         needed += sizeof(struct dm_name_list);
1248                         needed += strlen(hc->name) + 1;
1249                         needed += ALIGN_MASK;
1250 @@ -515,6 +525,8 @@ static int list_devices(struct dm_ioctl
1251          */
1252         for (i = 0; i < NUM_BUCKETS; i++) {
1253                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1254 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1255 +                               continue;
1256                         if (old_nl)
1257                                 old_nl->next = (uint32_t) ((void *) nl -
1258                                                            (void *) old_nl);
1259 @@ -1722,8 +1734,8 @@ static int ctl_ioctl(uint command, struc
1260         size_t input_param_size;
1261         struct dm_ioctl param_kernel;
1262  
1263 -       /* only root can play with this */
1264 -       if (!capable(CAP_SYS_ADMIN))
1265 +       /* only root and certain contexts can play with this */
1266 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_MAPPER))
1267                 return -EACCES;
1268  
1269         if (_IOC_TYPE(command) != DM_IOCTL)
1270 diff -NurpP --minimal linux-3.9.4/drivers/md/dm.c linux-3.9.4-vs2.3.6.3/drivers/md/dm.c
1271 --- linux-3.9.4/drivers/md/dm.c 2013-05-31 13:44:59.000000000 +0000
1272 +++ linux-3.9.4-vs2.3.6.3/drivers/md/dm.c       2013-05-31 14:47:11.000000000 +0000
1273 @@ -19,6 +19,7 @@
1274  #include <linux/idr.h>
1275  #include <linux/hdreg.h>
1276  #include <linux/delay.h>
1277 +#include <linux/vs_base.h>
1278  
1279  #include <trace/events/block.h>
1280  
1281 @@ -125,6 +126,7 @@ struct mapped_device {
1282         rwlock_t map_lock;
1283         atomic_t holders;
1284         atomic_t open_count;
1285 +       xid_t xid;
1286  
1287         unsigned long flags;
1288  
1289 @@ -317,6 +319,7 @@ int dm_deleting_md(struct mapped_device
1290  static int dm_blk_open(struct block_device *bdev, fmode_t mode)
1291  {
1292         struct mapped_device *md;
1293 +       int ret = -ENXIO;
1294  
1295         spin_lock(&_minor_lock);
1296  
1297 @@ -325,18 +328,19 @@ static int dm_blk_open(struct block_devi
1298                 goto out;
1299  
1300         if (test_bit(DMF_FREEING, &md->flags) ||
1301 -           dm_deleting_md(md)) {
1302 -               md = NULL;
1303 +           dm_deleting_md(md))
1304 +               goto out;
1305 +
1306 +       ret = -EACCES;
1307 +       if (!vx_check(md->xid, VS_IDENT|VS_HOSTID))
1308                 goto out;
1309 -       }
1310  
1311         dm_get(md);
1312         atomic_inc(&md->open_count);
1313 -
1314 +       ret = 0;
1315  out:
1316         spin_unlock(&_minor_lock);
1317 -
1318 -       return md ? 0 : -ENXIO;
1319 +       return ret;
1320  }
1321  
1322  static int dm_blk_close(struct gendisk *disk, fmode_t mode)
1323 @@ -547,6 +551,14 @@ int dm_set_geometry(struct mapped_device
1324         return 0;
1325  }
1326  
1327 +/*
1328 + * Get the xid associated with a dm device
1329 + */
1330 +xid_t dm_get_xid(struct mapped_device *md)
1331 +{
1332 +       return md->xid;
1333 +}
1334 +
1335  /*-----------------------------------------------------------------
1336   * CRUD START:
1337   *   A more elegant soln is in the works that uses the queue
1338 @@ -1884,6 +1896,7 @@ static struct mapped_device *alloc_dev(i
1339         INIT_LIST_HEAD(&md->uevent_list);
1340         spin_lock_init(&md->uevent_lock);
1341  
1342 +       md->xid = vx_current_xid();
1343         md->queue = blk_alloc_queue(GFP_KERNEL);
1344         if (!md->queue)
1345                 goto bad_queue;
1346 diff -NurpP --minimal linux-3.9.4/drivers/md/dm.h linux-3.9.4-vs2.3.6.3/drivers/md/dm.h
1347 --- linux-3.9.4/drivers/md/dm.h 2013-02-19 13:57:51.000000000 +0000
1348 +++ linux-3.9.4-vs2.3.6.3/drivers/md/dm.h       2013-05-31 14:47:11.000000000 +0000
1349 @@ -46,6 +46,8 @@ struct dm_dev_internal {
1350  struct dm_table;
1351  struct dm_md_mempools;
1352  
1353 +xid_t dm_get_xid(struct mapped_device *md);
1354 +
1355  /*-----------------------------------------------------------------
1356   * Internal table functions.
1357   *---------------------------------------------------------------*/
1358 diff -NurpP --minimal linux-3.9.4/drivers/net/tun.c linux-3.9.4-vs2.3.6.3/drivers/net/tun.c
1359 --- linux-3.9.4/drivers/net/tun.c       2013-05-31 14:22:27.000000000 +0000
1360 +++ linux-3.9.4-vs2.3.6.3/drivers/net/tun.c     2013-05-31 20:01:45.000000000 +0000
1361 @@ -64,6 +64,7 @@
1362  #include <linux/nsproxy.h>
1363  #include <linux/virtio_net.h>
1364  #include <linux/rcupdate.h>
1365 +#include <linux/vs_network.h>
1366  #include <net/net_namespace.h>
1367  #include <net/netns/generic.h>
1368  #include <net/rtnetlink.h>
1369 @@ -164,6 +165,7 @@ struct tun_struct {
1370         unsigned int            flags;
1371         kuid_t                  owner;
1372         kgid_t                  group;
1373 +       nid_t                   nid;
1374  
1375         struct net_device       *dev;
1376         netdev_features_t       set_features;
1377 @@ -380,6 +382,7 @@ static inline bool tun_not_capable(struc
1378         return ((uid_valid(tun->owner) && !uid_eq(cred->euid, tun->owner)) ||
1379                   (gid_valid(tun->group) && !in_egroup_p(tun->group))) &&
1380                 !ns_capable(net->user_ns, CAP_NET_ADMIN);
1381 +               /* !cap_raised(current_cap(), CAP_NET_ADMIN) */
1382  }
1383  
1384  static void tun_set_real_num_queues(struct tun_struct *tun)
1385 @@ -1404,6 +1407,7 @@ static void tun_setup(struct net_device
1386  
1387         tun->owner = INVALID_UID;
1388         tun->group = INVALID_GID;
1389 +       tun->nid = nx_current_nid();
1390  
1391         dev->ethtool_ops = &tun_ethtool_ops;
1392         dev->destructor = tun_free_netdev;
1393 @@ -1591,6 +1595,9 @@ static int tun_set_iff(struct net *net,
1394                 if (err < 0)
1395                         return err;
1396  
1397 +               if (!nx_check(tun->nid, VS_IDENT | VS_HOSTID | VS_ADMIN_P))
1398 +                       return -EPERM;
1399 +
1400                 err = tun_attach(tun, file);
1401                 if (err < 0)
1402                         return err;
1403 @@ -1605,7 +1612,7 @@ static int tun_set_iff(struct net *net,
1404                 int queues = ifr->ifr_flags & IFF_MULTI_QUEUE ?
1405                              MAX_TAP_QUEUES : 1;
1406  
1407 -               if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
1408 +               if (!vx_ns_capable(net->user_ns, CAP_NET_ADMIN, NXC_TUN_CREATE))
1409                         return -EPERM;
1410                 err = security_tun_dev_create();
1411                 if (err < 0)
1412 @@ -1950,6 +1957,16 @@ static long __tun_chr_ioctl(struct file
1413                           from_kgid(&init_user_ns, tun->group));
1414                 break;
1415  
1416 +       case TUNSETNID:
1417 +               if (!capable(CAP_CONTEXT))
1418 +                       return -EPERM;
1419 +
1420 +               /* Set nid owner of the device */
1421 +               tun->nid = (nid_t) arg;
1422 +
1423 +               tun_debug(KERN_INFO, tun, "nid owner set to %u\n", tun->nid);
1424 +               break;
1425 +
1426         case TUNSETLINK:
1427                 /* Only allow setting the type when the interface is down */
1428                 if (tun->dev->flags & IFF_UP) {
1429 diff -NurpP --minimal linux-3.9.4/drivers/staging/csr/csr_wifi_hip_xbv.c linux-3.9.4-vs2.3.6.3/drivers/staging/csr/csr_wifi_hip_xbv.c
1430 --- linux-3.9.4/drivers/staging/csr/csr_wifi_hip_xbv.c  2013-02-19 13:58:32.000000000 +0000
1431 +++ linux-3.9.4-vs2.3.6.3/drivers/staging/csr/csr_wifi_hip_xbv.c        2013-05-31 14:47:11.000000000 +0000
1432 @@ -55,7 +55,7 @@ typedef struct
1433  {
1434      char t_name[4];
1435      u32     t_len;
1436 -} tag_t;
1437 +} ctag_t;
1438  
1439  
1440  #define TAG_EQ(i, v)    (((i)[0] == (v)[0]) &&  \
1441 @@ -90,7 +90,7 @@ typedef struct
1442      u32 ptr;
1443  } xbv_stack_t;
1444  
1445 -static s32 read_tag(card_t *card, ct_t *ct, tag_t *tag);
1446 +static s32 read_tag(card_t *card, ct_t *ct, ctag_t *tag);
1447  static s32 read_bytes(card_t *card, ct_t *ct, void *buf, u32 len);
1448  static s32 read_uint(card_t *card, ct_t *ct, u32 *u, u32 len);
1449  static s32 xbv_check(xbv1_t *fwinfo, const xbv_stack_t *stack,
1450 @@ -160,7 +160,7 @@ static u32 write_fwdl_to_ptdl(void *buf,
1451  CsrResult xbv1_parse(card_t *card, fwreadfn_t readfn, void *dlpriv, xbv1_t *fwinfo)
1452  {
1453      ct_t ct;
1454 -    tag_t tag;
1455 +    ctag_t tag;
1456      xbv_stack_t stack;
1457  
1458      ct.dlpriv = dlpriv;
1459 @@ -505,7 +505,7 @@ static u32 xbv2uint(u8 *ptr, s32 len)
1460  }
1461  
1462  
1463 -static s32 read_tag(card_t *card, ct_t *ct, tag_t *tag)
1464 +static s32 read_tag(card_t *card, ct_t *ct, ctag_t *tag)
1465  {
1466      u8 buf[8];
1467      s32 n;
1468 diff -NurpP --minimal linux-3.9.4/drivers/tty/sysrq.c linux-3.9.4-vs2.3.6.3/drivers/tty/sysrq.c
1469 --- linux-3.9.4/drivers/tty/sysrq.c     2013-05-31 13:45:19.000000000 +0000
1470 +++ linux-3.9.4-vs2.3.6.3/drivers/tty/sysrq.c   2013-05-31 15:08:19.000000000 +0000
1471 @@ -43,6 +43,7 @@
1472  #include <linux/input.h>
1473  #include <linux/uaccess.h>
1474  #include <linux/moduleparam.h>
1475 +#include <linux/vserver/debug.h>
1476  
1477  #include <asm/ptrace.h>
1478  #include <asm/irq_regs.h>
1479 @@ -401,6 +402,21 @@ static struct sysrq_key_op sysrq_unrt_op
1480         .enable_mask    = SYSRQ_ENABLE_RTNICE,
1481  };
1482  
1483 +
1484 +#ifdef CONFIG_VSERVER_DEBUG
1485 +static void sysrq_handle_vxinfo(int key)
1486 +{
1487 +       dump_vx_info_inactive((key == 'x') ? 0 : 1);
1488 +}
1489 +
1490 +static struct sysrq_key_op sysrq_showvxinfo_op = {
1491 +       .handler        = sysrq_handle_vxinfo,
1492 +       .help_msg       = "conteXt",
1493 +       .action_msg     = "Show Context Info",
1494 +       .enable_mask    = SYSRQ_ENABLE_DUMP,
1495 +};
1496 +#endif
1497 +
1498  /* Key Operations table and lock */
1499  static DEFINE_SPINLOCK(sysrq_key_table_lock);
1500  
1501 @@ -456,7 +472,11 @@ static struct sysrq_key_op *sysrq_key_ta
1502         &sysrq_showstate_blocked_op,    /* w */
1503         /* x: May be registered on ppc/powerpc for xmon */
1504         /* x: May be registered on sparc64 for global PMU dump */
1505 +#ifdef CONFIG_VSERVER_DEBUG
1506 +       &sysrq_showvxinfo_op,           /* x */
1507 +#else
1508         NULL,                           /* x */
1509 +#endif
1510         /* y: May be registered on sparc64 for global register dump */
1511         NULL,                           /* y */
1512         &sysrq_ftrace_dump_op,          /* z */
1513 @@ -471,6 +491,8 @@ static int sysrq_key_table_key2index(int
1514                 retval = key - '0';
1515         else if ((key >= 'a') && (key <= 'z'))
1516                 retval = key + 10 - 'a';
1517 +       else if ((key >= 'A') && (key <= 'Z'))
1518 +               retval = key + 10 - 'A';
1519         else
1520                 retval = -1;
1521         return retval;
1522 diff -NurpP --minimal linux-3.9.4/drivers/tty/tty_io.c linux-3.9.4-vs2.3.6.3/drivers/tty/tty_io.c
1523 --- linux-3.9.4/drivers/tty/tty_io.c    2013-05-31 14:22:27.000000000 +0000
1524 +++ linux-3.9.4-vs2.3.6.3/drivers/tty/tty_io.c  2013-05-31 14:47:11.000000000 +0000
1525 @@ -104,6 +104,7 @@
1526  
1527  #include <linux/kmod.h>
1528  #include <linux/nsproxy.h>
1529 +#include <linux/vs_pid.h>
1530  
1531  #undef TTY_DEBUG_HANGUP
1532  
1533 @@ -2144,7 +2145,8 @@ static int tiocsti(struct tty_struct *tt
1534         char ch, mbz = 0;
1535         struct tty_ldisc *ld;
1536  
1537 -       if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN))
1538 +       if (((current->signal->tty != tty) &&
1539 +               !vx_capable(CAP_SYS_ADMIN, VXC_TIOCSTI)))
1540                 return -EPERM;
1541         if (get_user(ch, p))
1542                 return -EFAULT;
1543 @@ -2432,6 +2434,7 @@ static int tiocspgrp(struct tty_struct *
1544                 return -ENOTTY;
1545         if (get_user(pgrp_nr, p))
1546                 return -EFAULT;
1547 +       pgrp_nr = vx_rmap_pid(pgrp_nr);
1548         if (pgrp_nr < 0)
1549                 return -EINVAL;
1550         rcu_read_lock();
1551 diff -NurpP --minimal linux-3.9.4/fs/attr.c linux-3.9.4-vs2.3.6.3/fs/attr.c
1552 --- linux-3.9.4/fs/attr.c       2013-02-19 13:58:46.000000000 +0000
1553 +++ linux-3.9.4-vs2.3.6.3/fs/attr.c     2013-05-31 14:47:11.000000000 +0000
1554 @@ -15,6 +15,9 @@
1555  #include <linux/security.h>
1556  #include <linux/evm.h>
1557  #include <linux/ima.h>
1558 +#include <linux/proc_fs.h>
1559 +#include <linux/devpts_fs.h>
1560 +#include <linux/vs_tag.h>
1561  
1562  /**
1563   * inode_change_ok - check if attribute changes to an inode are allowed
1564 @@ -77,6 +80,10 @@ int inode_change_ok(const struct inode *
1565                         return -EPERM;
1566         }
1567  
1568 +       /* check for inode tag permission */
1569 +       if (dx_permission(inode, MAY_WRITE))
1570 +               return -EACCES;
1571 +
1572         return 0;
1573  }
1574  EXPORT_SYMBOL(inode_change_ok);
1575 @@ -147,6 +154,8 @@ void setattr_copy(struct inode *inode, c
1576                 inode->i_uid = attr->ia_uid;
1577         if (ia_valid & ATTR_GID)
1578                 inode->i_gid = attr->ia_gid;
1579 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
1580 +               inode->i_tag = attr->ia_tag;
1581         if (ia_valid & ATTR_ATIME)
1582                 inode->i_atime = timespec_trunc(attr->ia_atime,
1583                                                 inode->i_sb->s_time_gran);
1584 @@ -177,7 +186,8 @@ int notify_change(struct dentry * dentry
1585  
1586         WARN_ON_ONCE(!mutex_is_locked(&inode->i_mutex));
1587  
1588 -       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_TIMES_SET)) {
1589 +       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID |
1590 +               ATTR_TAG | ATTR_TIMES_SET)) {
1591                 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
1592                         return -EPERM;
1593         }
1594 diff -NurpP --minimal linux-3.9.4/fs/block_dev.c linux-3.9.4-vs2.3.6.3/fs/block_dev.c
1595 --- linux-3.9.4/fs/block_dev.c  2013-05-31 13:45:22.000000000 +0000
1596 +++ linux-3.9.4-vs2.3.6.3/fs/block_dev.c        2013-05-31 14:47:11.000000000 +0000
1597 @@ -27,6 +27,7 @@
1598  #include <linux/namei.h>
1599  #include <linux/log2.h>
1600  #include <linux/cleancache.h>
1601 +#include <linux/vs_device.h>
1602  #include <asm/uaccess.h>
1603  #include "internal.h"
1604  
1605 @@ -528,6 +529,7 @@ struct block_device *bdget(dev_t dev)
1606                 bdev->bd_invalidated = 0;
1607                 inode->i_mode = S_IFBLK;
1608                 inode->i_rdev = dev;
1609 +               inode->i_mdev = dev;
1610                 inode->i_bdev = bdev;
1611                 inode->i_data.a_ops = &def_blk_aops;
1612                 mapping_set_gfp_mask(&inode->i_data, GFP_USER);
1613 @@ -575,6 +577,11 @@ EXPORT_SYMBOL(bdput);
1614  static struct block_device *bd_acquire(struct inode *inode)
1615  {
1616         struct block_device *bdev;
1617 +       dev_t mdev;
1618 +
1619 +       if (!vs_map_blkdev(inode->i_rdev, &mdev, DATTR_OPEN))
1620 +               return NULL;
1621 +       inode->i_mdev = mdev;
1622  
1623         spin_lock(&bdev_lock);
1624         bdev = inode->i_bdev;
1625 @@ -585,7 +592,7 @@ static struct block_device *bd_acquire(s
1626         }
1627         spin_unlock(&bdev_lock);
1628  
1629 -       bdev = bdget(inode->i_rdev);
1630 +       bdev = bdget(mdev);
1631         if (bdev) {
1632                 spin_lock(&bdev_lock);
1633                 if (!inode->i_bdev) {
1634 diff -NurpP --minimal linux-3.9.4/fs/btrfs/ctree.h linux-3.9.4-vs2.3.6.3/fs/btrfs/ctree.h
1635 --- linux-3.9.4/fs/btrfs/ctree.h        2013-05-31 13:45:22.000000000 +0000
1636 +++ linux-3.9.4-vs2.3.6.3/fs/btrfs/ctree.h      2013-05-31 14:47:11.000000000 +0000
1637 @@ -705,11 +705,14 @@ struct btrfs_inode_item {
1638         /* modification sequence number for NFS */
1639         __le64 sequence;
1640  
1641 +       __le16 tag;
1642         /*
1643          * a little future expansion, for more than this we can
1644          * just grow the inode item and version it
1645          */
1646 -       __le64 reserved[4];
1647 +       __le16 reserved16;
1648 +       __le32 reserved32;
1649 +       __le64 reserved[3];
1650         struct btrfs_timespec atime;
1651         struct btrfs_timespec ctime;
1652         struct btrfs_timespec mtime;
1653 @@ -1901,6 +1904,8 @@ struct btrfs_ioctl_defrag_range_args {
1654  #define BTRFS_MOUNT_CHECK_INTEGRITY_INCLUDING_EXTENT_DATA (1 << 21)
1655  #define BTRFS_MOUNT_PANIC_ON_FATAL_ERROR       (1 << 22)
1656  
1657 +#define BTRFS_MOUNT_TAGGED             (1 << 24)
1658 +
1659  #define btrfs_clear_opt(o, opt)                ((o) &= ~BTRFS_MOUNT_##opt)
1660  #define btrfs_set_opt(o, opt)          ((o) |= BTRFS_MOUNT_##opt)
1661  #define btrfs_raw_test_opt(o, opt)     ((o) & BTRFS_MOUNT_##opt)
1662 @@ -2170,6 +2175,7 @@ BTRFS_SETGET_FUNCS(inode_block_group, st
1663  BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
1664  BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
1665  BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
1666 +BTRFS_SETGET_FUNCS(inode_tag, struct btrfs_inode_item, tag, 16);
1667  BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
1668  BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
1669  BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
1670 @@ -2223,6 +2229,10 @@ BTRFS_SETGET_FUNCS(extent_flags, struct
1671  
1672  BTRFS_SETGET_FUNCS(extent_refs_v0, struct btrfs_extent_item_v0, refs, 32);
1673  
1674 +#define BTRFS_INODE_IXUNLINK           (1 << 24)
1675 +#define BTRFS_INODE_BARRIER            (1 << 25)
1676 +#define BTRFS_INODE_COW                        (1 << 26)
1677 +
1678  
1679  BTRFS_SETGET_FUNCS(tree_block_level, struct btrfs_tree_block_info, level, 8);
1680  
1681 @@ -3581,6 +3591,7 @@ extern const struct dentry_operations bt
1682  long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
1683  void btrfs_update_iflags(struct inode *inode);
1684  void btrfs_inherit_iflags(struct inode *inode, struct inode *dir);
1685 +int btrfs_sync_flags(struct inode *inode, int, int);
1686  int btrfs_defrag_file(struct inode *inode, struct file *file,
1687                       struct btrfs_ioctl_defrag_range_args *range,
1688                       u64 newer_than, unsigned long max_pages);
1689 diff -NurpP --minimal linux-3.9.4/fs/btrfs/disk-io.c linux-3.9.4-vs2.3.6.3/fs/btrfs/disk-io.c
1690 --- linux-3.9.4/fs/btrfs/disk-io.c      2013-05-31 13:45:22.000000000 +0000
1691 +++ linux-3.9.4-vs2.3.6.3/fs/btrfs/disk-io.c    2013-05-31 14:47:11.000000000 +0000
1692 @@ -2258,6 +2258,9 @@ int open_ctree(struct super_block *sb,
1693                 goto fail_alloc;
1694         }
1695  
1696 +       if (btrfs_test_opt(tree_root, TAGGED))
1697 +               sb->s_flags |= MS_TAGGED;
1698 +
1699         features = btrfs_super_incompat_flags(disk_super) &
1700                 ~BTRFS_FEATURE_INCOMPAT_SUPP;
1701         if (features) {
1702 diff -NurpP --minimal linux-3.9.4/fs/btrfs/inode.c linux-3.9.4-vs2.3.6.3/fs/btrfs/inode.c
1703 --- linux-3.9.4/fs/btrfs/inode.c        2013-05-31 14:22:27.000000000 +0000
1704 +++ linux-3.9.4-vs2.3.6.3/fs/btrfs/inode.c      2013-06-03 19:37:03.000000000 +0000
1705 @@ -41,6 +41,7 @@
1706  #include <linux/mount.h>
1707  #include <linux/btrfs.h>
1708  #include <linux/blkdev.h>
1709 +#include <linux/vs_tag.h>
1710  #include "compat.h"
1711  #include "ctree.h"
1712  #include "disk-io.h"
1713 @@ -3312,6 +3313,9 @@ static void btrfs_read_locked_inode(stru
1714         struct btrfs_key location;
1715         int maybe_acls;
1716         u32 rdev;
1717 +       kuid_t kuid;
1718 +       kgid_t kgid;
1719 +       ktag_t ktag;
1720         int ret;
1721         bool filled = false;
1722  
1723 @@ -3339,8 +3343,14 @@ static void btrfs_read_locked_inode(stru
1724                                     struct btrfs_inode_item);
1725         inode->i_mode = btrfs_inode_mode(leaf, inode_item);
1726         set_nlink(inode, btrfs_inode_nlink(leaf, inode_item));
1727 -       i_uid_write(inode, btrfs_inode_uid(leaf, inode_item));
1728 -       i_gid_write(inode, btrfs_inode_gid(leaf, inode_item));
1729 +
1730 +       kuid = make_kuid(&init_user_ns, btrfs_inode_uid(leaf, inode_item));
1731 +       kgid = make_kgid(&init_user_ns, btrfs_inode_gid(leaf, inode_item));
1732 +       ktag = make_ktag(&init_user_ns, btrfs_inode_tag(leaf, inode_item));
1733 +
1734 +       inode->i_uid = INOTAG_KUID(DX_TAG(inode), kuid, kgid);
1735 +       inode->i_gid = INOTAG_KGID(DX_TAG(inode), kuid, kgid);
1736 +       inode->i_tag = INOTAG_KTAG(DX_TAG(inode), kuid, kgid, ktag);
1737         btrfs_i_size_write(inode, btrfs_inode_size(leaf, inode_item));
1738  
1739         tspec = btrfs_inode_atime(inode_item);
1740 @@ -3431,11 +3441,18 @@ static void fill_inode_item(struct btrfs
1741                             struct inode *inode)
1742  {
1743         struct btrfs_map_token token;
1744 +       uid_t uid = from_kuid(&init_user_ns,
1745 +               TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag));
1746 +       gid_t gid = from_kgid(&init_user_ns,
1747 +               TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag));
1748  
1749         btrfs_init_map_token(&token);
1750  
1751 -       btrfs_set_token_inode_uid(leaf, item, i_uid_read(inode), &token);
1752 -       btrfs_set_token_inode_gid(leaf, item, i_gid_read(inode), &token);
1753 +       btrfs_set_token_inode_uid(leaf, item, uid, &token);
1754 +       btrfs_set_token_inode_gid(leaf, item, gid, &token);
1755 +#ifdef CONFIG_TAGGING_INTERN
1756 +       btrfs_set_token_inode_tag(leaf, item, i_tag_read(inode), &token);
1757 +#endif
1758         btrfs_set_token_inode_size(leaf, item, BTRFS_I(inode)->disk_i_size,
1759                                    &token);
1760         btrfs_set_token_inode_mode(leaf, item, inode->i_mode, &token);
1761 @@ -8683,11 +8700,13 @@ static const struct inode_operations btr
1762         .listxattr      = btrfs_listxattr,
1763         .removexattr    = btrfs_removexattr,
1764         .permission     = btrfs_permission,
1765 +       .sync_flags     = btrfs_sync_flags,
1766         .get_acl        = btrfs_get_acl,
1767  };
1768  static const struct inode_operations btrfs_dir_ro_inode_operations = {
1769         .lookup         = btrfs_lookup,
1770         .permission     = btrfs_permission,
1771 +       .sync_flags     = btrfs_sync_flags,
1772         .get_acl        = btrfs_get_acl,
1773  };
1774  
1775 diff -NurpP --minimal linux-3.9.4/fs/btrfs/ioctl.c linux-3.9.4-vs2.3.6.3/fs/btrfs/ioctl.c
1776 --- linux-3.9.4/fs/btrfs/ioctl.c        2013-05-31 14:22:27.000000000 +0000
1777 +++ linux-3.9.4-vs2.3.6.3/fs/btrfs/ioctl.c      2013-05-31 14:47:11.000000000 +0000
1778 @@ -75,10 +75,13 @@ static unsigned int btrfs_flags_to_ioctl
1779  {
1780         unsigned int iflags = 0;
1781  
1782 -       if (flags & BTRFS_INODE_SYNC)
1783 -               iflags |= FS_SYNC_FL;
1784         if (flags & BTRFS_INODE_IMMUTABLE)
1785                 iflags |= FS_IMMUTABLE_FL;
1786 +       if (flags & BTRFS_INODE_IXUNLINK)
1787 +               iflags |= FS_IXUNLINK_FL;
1788 +
1789 +       if (flags & BTRFS_INODE_SYNC)
1790 +               iflags |= FS_SYNC_FL;
1791         if (flags & BTRFS_INODE_APPEND)
1792                 iflags |= FS_APPEND_FL;
1793         if (flags & BTRFS_INODE_NODUMP)
1794 @@ -95,28 +98,78 @@ static unsigned int btrfs_flags_to_ioctl
1795         else if (flags & BTRFS_INODE_NOCOMPRESS)
1796                 iflags |= FS_NOCOMP_FL;
1797  
1798 +       if (flags & BTRFS_INODE_BARRIER)
1799 +               iflags |= FS_BARRIER_FL;
1800 +       if (flags & BTRFS_INODE_COW)
1801 +               iflags |= FS_COW_FL;
1802         return iflags;
1803  }
1804  
1805  /*
1806 - * Update inode->i_flags based on the btrfs internal flags.
1807 + * Update inode->i_(v)flags based on the btrfs internal flags.
1808   */
1809  void btrfs_update_iflags(struct inode *inode)
1810  {
1811         struct btrfs_inode *ip = BTRFS_I(inode);
1812  
1813 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
1814 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
1815 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
1816  
1817 -       if (ip->flags & BTRFS_INODE_SYNC)
1818 -               inode->i_flags |= S_SYNC;
1819         if (ip->flags & BTRFS_INODE_IMMUTABLE)
1820                 inode->i_flags |= S_IMMUTABLE;
1821 +       if (ip->flags & BTRFS_INODE_IXUNLINK)
1822 +               inode->i_flags |= S_IXUNLINK;
1823 +
1824 +       if (ip->flags & BTRFS_INODE_SYNC)
1825 +               inode->i_flags |= S_SYNC;
1826         if (ip->flags & BTRFS_INODE_APPEND)
1827                 inode->i_flags |= S_APPEND;
1828         if (ip->flags & BTRFS_INODE_NOATIME)
1829                 inode->i_flags |= S_NOATIME;
1830         if (ip->flags & BTRFS_INODE_DIRSYNC)
1831                 inode->i_flags |= S_DIRSYNC;
1832 +
1833 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
1834 +
1835 +       if (ip->flags & BTRFS_INODE_BARRIER)
1836 +               inode->i_vflags |= V_BARRIER;
1837 +       if (ip->flags & BTRFS_INODE_COW)
1838 +               inode->i_vflags |= V_COW;
1839 +}
1840 +
1841 +/*
1842 + * Update btrfs internal flags from inode->i_(v)flags.
1843 + */
1844 +void btrfs_update_flags(struct inode *inode)
1845 +{
1846 +       struct btrfs_inode *ip = BTRFS_I(inode);
1847 +
1848 +       unsigned int flags = inode->i_flags;
1849 +       unsigned int vflags = inode->i_vflags;
1850 +
1851 +       ip->flags &= ~(BTRFS_INODE_SYNC | BTRFS_INODE_APPEND |
1852 +                       BTRFS_INODE_IMMUTABLE | BTRFS_INODE_IXUNLINK |
1853 +                       BTRFS_INODE_NOATIME | BTRFS_INODE_DIRSYNC |
1854 +                       BTRFS_INODE_BARRIER | BTRFS_INODE_COW);
1855 +
1856 +       if (flags & S_IMMUTABLE)
1857 +               ip->flags |= BTRFS_INODE_IMMUTABLE;
1858 +       if (flags & S_IXUNLINK)
1859 +               ip->flags |= BTRFS_INODE_IXUNLINK;
1860 +
1861 +       if (flags & S_SYNC)
1862 +               ip->flags |= BTRFS_INODE_SYNC;
1863 +       if (flags & S_APPEND)
1864 +               ip->flags |= BTRFS_INODE_APPEND;
1865 +       if (flags & S_NOATIME)
1866 +               ip->flags |= BTRFS_INODE_NOATIME;
1867 +       if (flags & S_DIRSYNC)
1868 +               ip->flags |= BTRFS_INODE_DIRSYNC;
1869 +
1870 +       if (vflags & V_BARRIER)
1871 +               ip->flags |= BTRFS_INODE_BARRIER;
1872 +       if (vflags & V_COW)
1873 +               ip->flags |= BTRFS_INODE_COW;
1874  }
1875  
1876  /*
1877 @@ -132,6 +185,7 @@ void btrfs_inherit_iflags(struct inode *
1878                 return;
1879  
1880         flags = BTRFS_I(dir)->flags;
1881 +       flags &= ~BTRFS_INODE_BARRIER;
1882  
1883         if (flags & BTRFS_INODE_NOCOMPRESS) {
1884                 BTRFS_I(inode)->flags &= ~BTRFS_INODE_COMPRESS;
1885 @@ -150,6 +204,30 @@ void btrfs_inherit_iflags(struct inode *
1886         btrfs_update_iflags(inode);
1887  }
1888  
1889 +int btrfs_sync_flags(struct inode *inode, int flags, int vflags)
1890 +{
1891 +       struct btrfs_inode *ip = BTRFS_I(inode);
1892 +       struct btrfs_root *root = ip->root;
1893 +       struct btrfs_trans_handle *trans;
1894 +       int ret;
1895 +
1896 +       trans = btrfs_join_transaction(root);
1897 +       BUG_ON(!trans);
1898 +
1899 +       inode->i_flags = flags;
1900 +       inode->i_vflags = vflags;
1901 +       btrfs_update_flags(inode);
1902 +
1903 +       ret = btrfs_update_inode(trans, root, inode);
1904 +       BUG_ON(ret);
1905 +
1906 +       btrfs_update_iflags(inode);
1907 +       inode->i_ctime = CURRENT_TIME;
1908 +       btrfs_end_transaction(trans, root);
1909 +
1910 +       return 0;
1911 +}
1912 +
1913  static int btrfs_ioctl_getflags(struct file *file, void __user *arg)
1914  {
1915         struct btrfs_inode *ip = BTRFS_I(file_inode(file));
1916 @@ -212,21 +290,27 @@ static int btrfs_ioctl_setflags(struct f
1917  
1918         flags = btrfs_mask_flags(inode->i_mode, flags);
1919         oldflags = btrfs_flags_to_ioctl(ip->flags);
1920 -       if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) {
1921 +       if ((flags ^ oldflags) & (FS_APPEND_FL |
1922 +               FS_IMMUTABLE_FL | FS_IXUNLINK_FL)) {
1923                 if (!capable(CAP_LINUX_IMMUTABLE)) {
1924                         ret = -EPERM;
1925                         goto out_unlock;
1926                 }
1927         }
1928  
1929 -       if (flags & FS_SYNC_FL)
1930 -               ip->flags |= BTRFS_INODE_SYNC;
1931 -       else
1932 -               ip->flags &= ~BTRFS_INODE_SYNC;
1933         if (flags & FS_IMMUTABLE_FL)
1934                 ip->flags |= BTRFS_INODE_IMMUTABLE;
1935         else
1936                 ip->flags &= ~BTRFS_INODE_IMMUTABLE;
1937 +       if (flags & FS_IXUNLINK_FL)
1938 +               ip->flags |= BTRFS_INODE_IXUNLINK;
1939 +       else
1940 +               ip->flags &= ~BTRFS_INODE_IXUNLINK;
1941 +
1942 +       if (flags & FS_SYNC_FL)
1943 +               ip->flags |= BTRFS_INODE_SYNC;
1944 +       else
1945 +               ip->flags &= ~BTRFS_INODE_SYNC;
1946         if (flags & FS_APPEND_FL)
1947                 ip->flags |= BTRFS_INODE_APPEND;
1948         else
1949 diff -NurpP --minimal linux-3.9.4/fs/btrfs/super.c linux-3.9.4-vs2.3.6.3/fs/btrfs/super.c
1950 --- linux-3.9.4/fs/btrfs/super.c        2013-05-31 13:45:22.000000000 +0000
1951 +++ linux-3.9.4-vs2.3.6.3/fs/btrfs/super.c      2013-05-31 14:47:11.000000000 +0000
1952 @@ -321,7 +321,7 @@ enum {
1953         Opt_no_space_cache, Opt_recovery, Opt_skip_balance,
1954         Opt_check_integrity, Opt_check_integrity_including_extent_data,
1955         Opt_check_integrity_print_mask, Opt_fatal_errors,
1956 -       Opt_err,
1957 +       Opt_tag, Opt_notag, Opt_tagid, Opt_err,
1958  };
1959  
1960  static match_table_t tokens = {
1961 @@ -361,6 +361,9 @@ static match_table_t tokens = {
1962         {Opt_check_integrity_including_extent_data, "check_int_data"},
1963         {Opt_check_integrity_print_mask, "check_int_print_mask=%d"},
1964         {Opt_fatal_errors, "fatal_errors=%s"},
1965 +       {Opt_tag, "tag"},
1966 +       {Opt_notag, "notag"},
1967 +       {Opt_tagid, "tagid=%u"},
1968         {Opt_err, NULL},
1969  };
1970  
1971 @@ -626,6 +629,22 @@ int btrfs_parse_options(struct btrfs_roo
1972                                 goto out;
1973                         }
1974                         break;
1975 +#ifndef CONFIG_TAGGING_NONE
1976 +               case Opt_tag:
1977 +                       printk(KERN_INFO "btrfs: use tagging\n");
1978 +                       btrfs_set_opt(info->mount_opt, TAGGED);
1979 +                       break;
1980 +               case Opt_notag:
1981 +                       printk(KERN_INFO "btrfs: disabled tagging\n");
1982 +                       btrfs_clear_opt(info->mount_opt, TAGGED);
1983 +                       break;
1984 +#endif
1985 +#ifdef CONFIG_PROPAGATE
1986 +               case Opt_tagid:
1987 +                       /* use args[0] */
1988 +                       btrfs_set_opt(info->mount_opt, TAGGED);
1989 +                       break;
1990 +#endif
1991                 case Opt_err:
1992                         printk(KERN_INFO "btrfs: unrecognized mount option "
1993                                "'%s'\n", p);
1994 @@ -1258,6 +1277,12 @@ static int btrfs_remount(struct super_bl
1995         btrfs_resize_thread_pool(fs_info,
1996                 fs_info->thread_pool_size, old_thread_pool_size);
1997  
1998 +       if (btrfs_test_opt(root, TAGGED) && !(sb->s_flags & MS_TAGGED)) {
1999 +               printk("btrfs: %s: tagging not permitted on remount.\n",
2000 +                       sb->s_id);
2001 +               return -EINVAL;
2002 +       }
2003 +
2004         if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
2005                 goto out;
2006  
2007 diff -NurpP --minimal linux-3.9.4/fs/char_dev.c linux-3.9.4-vs2.3.6.3/fs/char_dev.c
2008 --- linux-3.9.4/fs/char_dev.c   2012-12-11 03:30:57.000000000 +0000
2009 +++ linux-3.9.4-vs2.3.6.3/fs/char_dev.c 2013-05-31 14:47:11.000000000 +0000
2010 @@ -21,6 +21,8 @@
2011  #include <linux/mutex.h>
2012  #include <linux/backing-dev.h>
2013  #include <linux/tty.h>
2014 +#include <linux/vs_context.h>
2015 +#include <linux/vs_device.h>
2016  
2017  #include "internal.h"
2018  
2019 @@ -371,14 +373,21 @@ static int chrdev_open(struct inode *ino
2020         struct cdev *p;
2021         struct cdev *new = NULL;
2022         int ret = 0;
2023 +       dev_t mdev;
2024 +
2025 +       if (!vs_map_chrdev(inode->i_rdev, &mdev, DATTR_OPEN))
2026 +               return -EPERM;
2027 +       inode->i_mdev = mdev;
2028  
2029         spin_lock(&cdev_lock);
2030         p = inode->i_cdev;
2031         if (!p) {
2032                 struct kobject *kobj;
2033                 int idx;
2034 +
2035                 spin_unlock(&cdev_lock);
2036 -               kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
2037 +
2038 +               kobj = kobj_lookup(cdev_map, mdev, &idx);
2039                 if (!kobj)
2040                         return -ENXIO;
2041                 new = container_of(kobj, struct cdev, kobj);
2042 diff -NurpP --minimal linux-3.9.4/fs/dcache.c linux-3.9.4-vs2.3.6.3/fs/dcache.c
2043 --- linux-3.9.4/fs/dcache.c     2013-05-31 14:22:27.000000000 +0000
2044 +++ linux-3.9.4-vs2.3.6.3/fs/dcache.c   2013-05-31 14:47:11.000000000 +0000
2045 @@ -37,6 +37,7 @@
2046  #include <linux/rculist_bl.h>
2047  #include <linux/prefetch.h>
2048  #include <linux/ratelimit.h>
2049 +#include <linux/vs_limit.h>
2050  #include "internal.h"
2051  #include "mount.h"
2052  
2053 @@ -593,6 +594,8 @@ int d_invalidate(struct dentry * dentry)
2054                 spin_lock(&dentry->d_lock);
2055         }
2056  
2057 +       vx_dentry_dec(dentry);
2058 +
2059         /*
2060          * Somebody else still using it?
2061          *
2062 @@ -622,6 +625,7 @@ EXPORT_SYMBOL(d_invalidate);
2063  static inline void __dget_dlock(struct dentry *dentry)
2064  {
2065         dentry->d_count++;
2066 +       vx_dentry_inc(dentry);
2067  }
2068  
2069  static inline void __dget(struct dentry *dentry)
2070 @@ -1252,6 +1256,9 @@ struct dentry *__d_alloc(struct super_bl
2071         struct dentry *dentry;
2072         char *dname;
2073  
2074 +       if (!vx_dentry_avail(1))
2075 +               return NULL;
2076 +
2077         dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
2078         if (!dentry)
2079                 return NULL;
2080 @@ -1284,6 +1291,7 @@ struct dentry *__d_alloc(struct super_bl
2081  
2082         dentry->d_count = 1;
2083         dentry->d_flags = 0;
2084 +       vx_dentry_inc(dentry);
2085         spin_lock_init(&dentry->d_lock);
2086         seqcount_init(&dentry->d_seq);
2087         dentry->d_inode = NULL;
2088 @@ -1984,6 +1992,7 @@ struct dentry *__d_lookup(const struct d
2089                 }
2090  
2091                 dentry->d_count++;
2092 +               vx_dentry_inc(dentry);
2093                 found = dentry;
2094                 spin_unlock(&dentry->d_lock);
2095                 break;
2096 diff -NurpP --minimal linux-3.9.4/fs/devpts/inode.c linux-3.9.4-vs2.3.6.3/fs/devpts/inode.c
2097 --- linux-3.9.4/fs/devpts/inode.c       2013-05-31 13:45:23.000000000 +0000
2098 +++ linux-3.9.4-vs2.3.6.3/fs/devpts/inode.c     2013-05-31 15:42:25.000000000 +0000
2099 @@ -25,6 +25,7 @@
2100  #include <linux/parser.h>
2101  #include <linux/fsnotify.h>
2102  #include <linux/seq_file.h>
2103 +#include <linux/vs_base.h>
2104  
2105  #define DEVPTS_DEFAULT_MODE 0600
2106  /*
2107 @@ -36,6 +37,21 @@
2108  #define DEVPTS_DEFAULT_PTMX_MODE 0000
2109  #define PTMX_MINOR     2
2110  
2111 +static int devpts_permission(struct inode *inode, int mask)
2112 +{
2113 +       int ret = -EACCES;
2114 +
2115 +       /* devpts is xid tagged */
2116 +       if (vx_check((xid_t)i_tag_read(inode), VS_WATCH_P | VS_IDENT))
2117 +               ret = generic_permission(inode, mask);
2118 +       return ret;
2119 +}
2120 +
2121 +static struct inode_operations devpts_file_inode_operations = {
2122 +       .permission     = devpts_permission,
2123 +};
2124 +
2125 +
2126  /*
2127   * sysctl support for setting limits on the number of Unix98 ptys allocated.
2128   * Otherwise one can eat up all kernel memory by opening /dev/ptmx repeatedly.
2129 @@ -345,6 +361,34 @@ static int devpts_show_options(struct se
2130         return 0;
2131  }
2132  
2133 +static int devpts_filter(struct dentry *de)
2134 +{
2135 +       xid_t xid = 0;
2136 +
2137 +       /* devpts is xid tagged */
2138 +       if (de && de->d_inode)
2139 +               xid = (xid_t)i_tag_read(de->d_inode);
2140 +#ifdef CONFIG_VSERVER_WARN_DEVPTS
2141 +       else
2142 +               vxwprintk_task(1, "devpts " VS_Q("%.*s") " without inode.",
2143 +                       de->d_name.len, de->d_name.name);
2144 +#endif
2145 +       return vx_check(xid, VS_WATCH_P | VS_IDENT);
2146 +}
2147 +
2148 +static int devpts_readdir(struct file * filp, void * dirent, filldir_t filldir)
2149 +{
2150 +       return dcache_readdir_filter(filp, dirent, filldir, devpts_filter);
2151 +}
2152 +
2153 +static struct file_operations devpts_dir_operations = {
2154 +       .open           = dcache_dir_open,
2155 +       .release        = dcache_dir_close,
2156 +       .llseek         = dcache_dir_lseek,
2157 +       .read           = generic_read_dir,
2158 +       .readdir        = devpts_readdir,
2159 +};
2160 +
2161  static const struct super_operations devpts_sops = {
2162         .statfs         = simple_statfs,
2163         .remount_fs     = devpts_remount,
2164 @@ -388,8 +432,10 @@ devpts_fill_super(struct super_block *s,
2165         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2166         inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
2167         inode->i_op = &simple_dir_inode_operations;
2168 -       inode->i_fop = &simple_dir_operations;
2169 +       inode->i_fop = &devpts_dir_operations;
2170         set_nlink(inode, 2);
2171 +       /* devpts is xid tagged */
2172 +       i_tag_write(inode, (tag_t)vx_current_xid());
2173  
2174         s->s_root = d_make_root(inode);
2175         if (s->s_root)
2176 @@ -592,6 +638,9 @@ struct inode *devpts_pty_new(struct inod
2177         inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
2178         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2179         init_special_inode(inode, S_IFCHR|opts->mode, device);
2180 +       /* devpts is xid tagged */
2181 +       i_tag_write(inode, (tag_t)vx_current_xid());
2182 +       inode->i_op = &devpts_file_inode_operations;
2183         inode->i_private = priv;
2184  
2185         sprintf(s, "%d", index);
2186 diff -NurpP --minimal linux-3.9.4/fs/ext2/balloc.c linux-3.9.4-vs2.3.6.3/fs/ext2/balloc.c
2187 --- linux-3.9.4/fs/ext2/balloc.c        2013-05-31 13:45:23.000000000 +0000
2188 +++ linux-3.9.4-vs2.3.6.3/fs/ext2/balloc.c      2013-05-31 14:47:11.000000000 +0000
2189 @@ -693,7 +693,6 @@ ext2_try_to_allocate(struct super_block
2190                         start = 0;
2191                 end = EXT2_BLOCKS_PER_GROUP(sb);
2192         }
2193 -
2194         BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
2195  
2196  repeat:
2197 diff -NurpP --minimal linux-3.9.4/fs/ext2/ext2.h linux-3.9.4-vs2.3.6.3/fs/ext2/ext2.h
2198 --- linux-3.9.4/fs/ext2/ext2.h  2012-12-11 03:30:57.000000000 +0000
2199 +++ linux-3.9.4-vs2.3.6.3/fs/ext2/ext2.h        2013-05-31 14:47:11.000000000 +0000
2200 @@ -244,8 +244,12 @@ struct ext2_group_desc
2201  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
2202  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
2203  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
2204 +#define EXT2_IXUNLINK_FL               FS_IXUNLINK_FL  /* Immutable invert on unlink */
2205  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
2206  
2207 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
2208 +#define EXT2_COW_FL                    FS_COW_FL       /* Copy on Write marker */
2209 +
2210  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
2211  #define EXT2_FL_USER_MODIFIABLE                FS_FL_USER_MODIFIABLE   /* User modifiable flags */
2212  
2213 @@ -329,7 +333,8 @@ struct ext2_inode {
2214                         __u16   i_pad1;
2215                         __le16  l_i_uid_high;   /* these 2 fields    */
2216                         __le16  l_i_gid_high;   /* were reserved2[0] */
2217 -                       __u32   l_i_reserved2;
2218 +                       __le16  l_i_tag;        /* Context Tag */
2219 +                       __u16   l_i_reserved2;
2220                 } linux2;
2221                 struct {
2222                         __u8    h_i_frag;       /* Fragment number */
2223 @@ -357,6 +362,7 @@ struct ext2_inode {
2224  #define i_gid_low      i_gid
2225  #define i_uid_high     osd2.linux2.l_i_uid_high
2226  #define i_gid_high     osd2.linux2.l_i_gid_high
2227 +#define i_raw_tag      osd2.linux2.l_i_tag
2228  #define i_reserved2    osd2.linux2.l_i_reserved2
2229  
2230  /*
2231 @@ -384,6 +390,7 @@ struct ext2_inode {
2232  #define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
2233  #define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
2234  #define EXT2_MOUNT_RESERVATION         0x080000  /* Preallocation */
2235 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
2236  
2237  
2238  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
2239 @@ -757,6 +764,7 @@ extern void ext2_set_inode_flags(struct
2240  extern void ext2_get_inode_flags(struct ext2_inode_info *);
2241  extern int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2242                        u64 start, u64 len);
2243 +extern int ext2_sync_flags(struct inode *, int, int);
2244  
2245  /* ioctl.c */
2246  extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
2247 diff -NurpP --minimal linux-3.9.4/fs/ext2/file.c linux-3.9.4-vs2.3.6.3/fs/ext2/file.c
2248 --- linux-3.9.4/fs/ext2/file.c  2012-12-11 03:30:57.000000000 +0000
2249 +++ linux-3.9.4-vs2.3.6.3/fs/ext2/file.c        2013-05-31 14:47:11.000000000 +0000
2250 @@ -104,4 +104,5 @@ const struct inode_operations ext2_file_
2251         .setattr        = ext2_setattr,
2252         .get_acl        = ext2_get_acl,
2253         .fiemap         = ext2_fiemap,
2254 +       .sync_flags     = ext2_sync_flags,
2255  };
2256 diff -NurpP --minimal linux-3.9.4/fs/ext2/ialloc.c linux-3.9.4-vs2.3.6.3/fs/ext2/ialloc.c
2257 --- linux-3.9.4/fs/ext2/ialloc.c        2013-05-31 13:45:23.000000000 +0000
2258 +++ linux-3.9.4-vs2.3.6.3/fs/ext2/ialloc.c      2013-06-03 18:58:16.000000000 +0000
2259 @@ -17,6 +17,7 @@
2260  #include <linux/backing-dev.h>
2261  #include <linux/buffer_head.h>
2262  #include <linux/random.h>
2263 +#include <linux/vs_tag.h>
2264  #include "ext2.h"
2265  #include "xattr.h"
2266  #include "acl.h"
2267 @@ -546,6 +547,7 @@ got:
2268                 inode->i_mode = mode;
2269                 inode->i_uid = current_fsuid();
2270                 inode->i_gid = dir->i_gid;
2271 +               i_tag_write(inode, dx_current_fstag(sb));
2272         } else
2273                 inode_init_owner(inode, dir, mode);
2274  
2275 diff -NurpP --minimal linux-3.9.4/fs/ext2/inode.c linux-3.9.4-vs2.3.6.3/fs/ext2/inode.c
2276 --- linux-3.9.4/fs/ext2/inode.c 2013-05-31 13:45:23.000000000 +0000
2277 +++ linux-3.9.4-vs2.3.6.3/fs/ext2/inode.c       2013-06-03 19:42:51.000000000 +0000
2278 @@ -31,6 +31,7 @@
2279  #include <linux/mpage.h>
2280  #include <linux/fiemap.h>
2281  #include <linux/namei.h>
2282 +#include <linux/vs_tag.h>
2283  #include "ext2.h"
2284  #include "acl.h"
2285  #include "xip.h"
2286 @@ -1179,7 +1180,7 @@ static void ext2_truncate_blocks(struct
2287                 return;
2288         if (ext2_inode_is_fast_symlink(inode))
2289                 return;
2290 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2291 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2292                 return;
2293         __ext2_truncate_blocks(inode, offset);
2294  }
2295 @@ -1270,36 +1271,61 @@ void ext2_set_inode_flags(struct inode *
2296  {
2297         unsigned int flags = EXT2_I(inode)->i_flags;
2298  
2299 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2300 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2301 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2302 +
2303 +
2304 +       if (flags & EXT2_IMMUTABLE_FL)
2305 +               inode->i_flags |= S_IMMUTABLE;
2306 +       if (flags & EXT2_IXUNLINK_FL)
2307 +               inode->i_flags |= S_IXUNLINK;
2308 +
2309         if (flags & EXT2_SYNC_FL)
2310                 inode->i_flags |= S_SYNC;
2311         if (flags & EXT2_APPEND_FL)
2312                 inode->i_flags |= S_APPEND;
2313 -       if (flags & EXT2_IMMUTABLE_FL)
2314 -               inode->i_flags |= S_IMMUTABLE;
2315         if (flags & EXT2_NOATIME_FL)
2316                 inode->i_flags |= S_NOATIME;
2317         if (flags & EXT2_DIRSYNC_FL)
2318                 inode->i_flags |= S_DIRSYNC;
2319 +
2320 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2321 +
2322 +       if (flags & EXT2_BARRIER_FL)
2323 +               inode->i_vflags |= V_BARRIER;
2324 +       if (flags & EXT2_COW_FL)
2325 +               inode->i_vflags |= V_COW;
2326  }
2327  
2328  /* Propagate flags from i_flags to EXT2_I(inode)->i_flags */
2329  void ext2_get_inode_flags(struct ext2_inode_info *ei)
2330  {
2331         unsigned int flags = ei->vfs_inode.i_flags;
2332 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2333 +
2334 +       ei->i_flags &= ~(EXT2_SYNC_FL | EXT2_APPEND_FL |
2335 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL |
2336 +                       EXT2_NOATIME_FL | EXT2_DIRSYNC_FL |
2337 +                       EXT2_BARRIER_FL | EXT2_COW_FL);
2338 +
2339 +       if (flags & S_IMMUTABLE)
2340 +               ei->i_flags |= EXT2_IMMUTABLE_FL;
2341 +       if (flags & S_IXUNLINK)
2342 +               ei->i_flags |= EXT2_IXUNLINK_FL;
2343  
2344 -       ei->i_flags &= ~(EXT2_SYNC_FL|EXT2_APPEND_FL|
2345 -                       EXT2_IMMUTABLE_FL|EXT2_NOATIME_FL|EXT2_DIRSYNC_FL);
2346         if (flags & S_SYNC)
2347                 ei->i_flags |= EXT2_SYNC_FL;
2348         if (flags & S_APPEND)
2349                 ei->i_flags |= EXT2_APPEND_FL;
2350 -       if (flags & S_IMMUTABLE)
2351 -               ei->i_flags |= EXT2_IMMUTABLE_FL;
2352         if (flags & S_NOATIME)
2353                 ei->i_flags |= EXT2_NOATIME_FL;
2354         if (flags & S_DIRSYNC)
2355                 ei->i_flags |= EXT2_DIRSYNC_FL;
2356 +
2357 +       if (vflags & V_BARRIER)
2358 +               ei->i_flags |= EXT2_BARRIER_FL;
2359 +       if (vflags & V_COW)
2360 +               ei->i_flags |= EXT2_COW_FL;
2361  }
2362  
2363  struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
2364 @@ -1335,8 +1361,10 @@ struct inode *ext2_iget (struct super_bl
2365                 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2366                 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2367         }
2368 -       i_uid_write(inode, i_uid);
2369 -       i_gid_write(inode, i_gid);
2370 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
2371 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
2372 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
2373 +               le16_to_cpu(raw_inode->i_raw_tag)));
2374         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2375         inode->i_size = le32_to_cpu(raw_inode->i_size);
2376         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2377 @@ -1434,8 +1462,10 @@ static int __ext2_write_inode(struct ino
2378         struct ext2_inode_info *ei = EXT2_I(inode);
2379         struct super_block *sb = inode->i_sb;
2380         ino_t ino = inode->i_ino;
2381 -       uid_t uid = i_uid_read(inode);
2382 -       gid_t gid = i_gid_read(inode);
2383 +       uid_t uid = from_kuid(&init_user_ns,
2384 +               TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag));
2385 +       gid_t gid = from_kgid(&init_user_ns,
2386 +               TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag));
2387         struct buffer_head * bh;
2388         struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2389         int n;
2390 @@ -1471,6 +1501,9 @@ static int __ext2_write_inode(struct ino
2391                 raw_inode->i_uid_high = 0;
2392                 raw_inode->i_gid_high = 0;
2393         }
2394 +#ifdef CONFIG_TAGGING_INTERN
2395 +       raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
2396 +#endif
2397         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2398         raw_inode->i_size = cpu_to_le32(inode->i_size);
2399         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2400 @@ -1551,7 +1584,8 @@ int ext2_setattr(struct dentry *dentry,
2401         if (is_quota_modification(inode, iattr))
2402                 dquot_initialize(inode);
2403         if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
2404 -           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
2405 +           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid)) ||
2406 +           (iattr->ia_valid & ATTR_TAG && !tag_eq(iattr->ia_tag, inode->i_tag))) {
2407                 error = dquot_transfer(inode, iattr);
2408                 if (error)
2409                         return error;
2410 diff -NurpP --minimal linux-3.9.4/fs/ext2/ioctl.c linux-3.9.4-vs2.3.6.3/fs/ext2/ioctl.c
2411 --- linux-3.9.4/fs/ext2/ioctl.c 2013-05-31 13:45:23.000000000 +0000
2412 +++ linux-3.9.4-vs2.3.6.3/fs/ext2/ioctl.c       2013-05-31 14:47:11.000000000 +0000
2413 @@ -17,6 +17,16 @@
2414  #include <asm/uaccess.h>
2415  
2416  
2417 +int ext2_sync_flags(struct inode *inode, int flags, int vflags)
2418 +{
2419 +       inode->i_flags = flags;
2420 +       inode->i_vflags = vflags;
2421 +       ext2_get_inode_flags(EXT2_I(inode));
2422 +       inode->i_ctime = CURRENT_TIME_SEC;
2423 +       mark_inode_dirty(inode);
2424 +       return 0;
2425 +}
2426 +
2427  long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2428  {
2429         struct inode *inode = file_inode(filp);
2430 @@ -51,6 +61,11 @@ long ext2_ioctl(struct file *filp, unsig
2431  
2432                 flags = ext2_mask_flags(inode->i_mode, flags);
2433  
2434 +               if (IS_BARRIER(inode)) {
2435 +                       vxwprintk_task(1, "messing with the barrier.");
2436 +                       return -EACCES;
2437 +               }
2438 +
2439                 mutex_lock(&inode->i_mutex);
2440                 /* Is it quota file? Do not allow user to mess with it */
2441                 if (IS_NOQUOTA(inode)) {
2442 @@ -66,7 +81,9 @@ long ext2_ioctl(struct file *filp, unsig
2443                  *
2444                  * This test looks nicer. Thanks to Pauline Middelink
2445                  */
2446 -               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
2447 +               if ((oldflags & EXT2_IMMUTABLE_FL) ||
2448 +                       ((flags ^ oldflags) & (EXT2_APPEND_FL |
2449 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
2450                         if (!capable(CAP_LINUX_IMMUTABLE)) {
2451                                 mutex_unlock(&inode->i_mutex);
2452                                 ret = -EPERM;
2453 @@ -74,7 +91,7 @@ long ext2_ioctl(struct file *filp, unsig
2454                         }
2455                 }
2456  
2457 -               flags = flags & EXT2_FL_USER_MODIFIABLE;
2458 +               flags &= EXT2_FL_USER_MODIFIABLE;
2459                 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
2460                 ei->i_flags = flags;
2461  
2462 diff -NurpP --minimal linux-3.9.4/fs/ext2/namei.c linux-3.9.4-vs2.3.6.3/fs/ext2/namei.c
2463 --- linux-3.9.4/fs/ext2/namei.c 2012-12-11 03:30:57.000000000 +0000
2464 +++ linux-3.9.4-vs2.3.6.3/fs/ext2/namei.c       2013-05-31 14:47:11.000000000 +0000
2465 @@ -32,6 +32,7 @@
2466  
2467  #include <linux/pagemap.h>
2468  #include <linux/quotaops.h>
2469 +#include <linux/vs_tag.h>
2470  #include "ext2.h"
2471  #include "xattr.h"
2472  #include "acl.h"
2473 @@ -73,6 +74,7 @@ static struct dentry *ext2_lookup(struct
2474                                         (unsigned long) ino);
2475                         return ERR_PTR(-EIO);
2476                 }
2477 +               dx_propagate_tag(nd, inode);
2478         }
2479         return d_splice_alias(inode, dentry);
2480  }
2481 @@ -397,6 +399,7 @@ const struct inode_operations ext2_dir_i
2482         .removexattr    = generic_removexattr,
2483  #endif
2484         .setattr        = ext2_setattr,
2485 +       .sync_flags     = ext2_sync_flags,
2486         .get_acl        = ext2_get_acl,
2487  };
2488  
2489 diff -NurpP --minimal linux-3.9.4/fs/ext2/super.c linux-3.9.4-vs2.3.6.3/fs/ext2/super.c
2490 --- linux-3.9.4/fs/ext2/super.c 2013-05-31 13:45:23.000000000 +0000
2491 +++ linux-3.9.4-vs2.3.6.3/fs/ext2/super.c       2013-05-31 14:47:11.000000000 +0000
2492 @@ -395,7 +395,8 @@ enum {
2493         Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
2494         Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
2495         Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
2496 -       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
2497 +       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
2498 +       Opt_tag, Opt_notag, Opt_tagid
2499  };
2500  
2501  static const match_table_t tokens = {
2502 @@ -423,6 +424,9 @@ static const match_table_t tokens = {
2503         {Opt_acl, "acl"},
2504         {Opt_noacl, "noacl"},
2505         {Opt_xip, "xip"},
2506 +       {Opt_tag, "tag"},
2507 +       {Opt_notag, "notag"},
2508 +       {Opt_tagid, "tagid=%u"},
2509         {Opt_grpquota, "grpquota"},
2510         {Opt_ignore, "noquota"},
2511         {Opt_quota, "quota"},
2512 @@ -506,6 +510,20 @@ static int parse_options(char *options,
2513                 case Opt_nouid32:
2514                         set_opt (sbi->s_mount_opt, NO_UID32);
2515                         break;
2516 +#ifndef CONFIG_TAGGING_NONE
2517 +               case Opt_tag:
2518 +                       set_opt (sbi->s_mount_opt, TAGGED);
2519 +                       break;
2520 +               case Opt_notag:
2521 +                       clear_opt (sbi->s_mount_opt, TAGGED);
2522 +                       break;
2523 +#endif
2524 +#ifdef CONFIG_PROPAGATE
2525 +               case Opt_tagid:
2526 +                       /* use args[0] */
2527 +                       set_opt (sbi->s_mount_opt, TAGGED);
2528 +                       break;
2529 +#endif
2530                 case Opt_nocheck:
2531                         clear_opt (sbi->s_mount_opt, CHECK);
2532                         break;
2533 @@ -864,6 +882,8 @@ static int ext2_fill_super(struct super_
2534         if (!parse_options((char *) data, sb))
2535                 goto failed_mount;
2536  
2537 +       if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
2538 +               sb->s_flags |= MS_TAGGED;
2539         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2540                 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
2541                  MS_POSIXACL : 0);
2542 @@ -1269,6 +1289,14 @@ static int ext2_remount (struct super_bl
2543                 err = -EINVAL;
2544                 goto restore_opts;
2545         }
2546 +
2547 +       if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
2548 +               !(sb->s_flags & MS_TAGGED)) {
2549 +               printk("EXT2-fs: %s: tagging not permitted on remount.\n",
2550 +                      sb->s_id);
2551 +               err = -EINVAL;
2552 +               goto restore_opts;
2553 +       }
2554  
2555         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2556                 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
2557 diff -NurpP --minimal linux-3.9.4/fs/ext3/ext3.h linux-3.9.4-vs2.3.6.3/fs/ext3/ext3.h
2558 --- linux-3.9.4/fs/ext3/ext3.h  2012-12-11 03:30:57.000000000 +0000
2559 +++ linux-3.9.4-vs2.3.6.3/fs/ext3/ext3.h        2013-05-31 14:47:11.000000000 +0000
2560 @@ -151,10 +151,14 @@ struct ext3_group_desc
2561  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
2562  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
2563  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
2564 +#define EXT3_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
2565  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
2566  
2567 -#define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
2568 -#define EXT3_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
2569 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
2570 +#define EXT3_COW_FL                    0x20000000 /* Copy on Write marker */
2571 +
2572 +#define EXT3_FL_USER_VISIBLE           0x0103DFFF /* User visible flags */
2573 +#define EXT3_FL_USER_MODIFIABLE                0x010380FF /* User modifiable flags */
2574  
2575  /* Flags that should be inherited by new inodes from their parent. */
2576  #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
2577 @@ -290,7 +294,8 @@ struct ext3_inode {
2578                         __u16   i_pad1;
2579                         __le16  l_i_uid_high;   /* these 2 fields    */
2580                         __le16  l_i_gid_high;   /* were reserved2[0] */
2581 -                       __u32   l_i_reserved2;
2582 +                       __le16  l_i_tag;        /* Context Tag */
2583 +                       __u16   l_i_reserved2;
2584                 } linux2;
2585                 struct {
2586                         __u8    h_i_frag;       /* Fragment number */
2587 @@ -320,6 +325,7 @@ struct ext3_inode {
2588  #define i_gid_low      i_gid
2589  #define i_uid_high     osd2.linux2.l_i_uid_high
2590  #define i_gid_high     osd2.linux2.l_i_gid_high
2591 +#define i_raw_tag      osd2.linux2.l_i_tag
2592  #define i_reserved2    osd2.linux2.l_i_reserved2
2593  
2594  /*
2595 @@ -364,6 +370,7 @@ struct ext3_inode {
2596  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
2597  #define EXT3_MOUNT_DATA_ERR_ABORT      0x400000 /* Abort on file data write
2598                                                   * error in ordered mode */
2599 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
2600  
2601  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
2602  #ifndef _LINUX_EXT2_FS_H
2603 @@ -1061,6 +1068,7 @@ extern void ext3_get_inode_flags(struct
2604  extern void ext3_set_aops(struct inode *inode);
2605  extern int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2606                        u64 start, u64 len);
2607 +extern int ext3_sync_flags(struct inode *, int, int);
2608  
2609  /* ioctl.c */
2610  extern long ext3_ioctl(struct file *, unsigned int, unsigned long);
2611 diff -NurpP --minimal linux-3.9.4/fs/ext3/file.c linux-3.9.4-vs2.3.6.3/fs/ext3/file.c
2612 --- linux-3.9.4/fs/ext3/file.c  2012-12-11 03:30:57.000000000 +0000
2613 +++ linux-3.9.4-vs2.3.6.3/fs/ext3/file.c        2013-05-31 14:47:11.000000000 +0000
2614 @@ -76,5 +76,6 @@ const struct inode_operations ext3_file_
2615  #endif
2616         .get_acl        = ext3_get_acl,
2617         .fiemap         = ext3_fiemap,
2618 +       .sync_flags     = ext3_sync_flags,
2619  };
2620  
2621 diff -NurpP --minimal linux-3.9.4/fs/ext3/ialloc.c linux-3.9.4-vs2.3.6.3/fs/ext3/ialloc.c
2622 --- linux-3.9.4/fs/ext3/ialloc.c        2012-12-11 03:30:57.000000000 +0000
2623 +++ linux-3.9.4-vs2.3.6.3/fs/ext3/ialloc.c      2013-06-03 19:43:33.000000000 +0000
2624 @@ -14,6 +14,7 @@
2625  
2626  #include <linux/quotaops.h>
2627  #include <linux/random.h>
2628 +#include <linux/vs_tag.h>
2629  
2630  #include "ext3.h"
2631  #include "xattr.h"
2632 @@ -469,6 +470,7 @@ got:
2633                 inode->i_mode = mode;
2634                 inode->i_uid = current_fsuid();
2635                 inode->i_gid = dir->i_gid;
2636 +               i_tag_write(inode, dx_current_fstag(sb));
2637         } else
2638                 inode_init_owner(inode, dir, mode);
2639  
2640 diff -NurpP --minimal linux-3.9.4/fs/ext3/inode.c linux-3.9.4-vs2.3.6.3/fs/ext3/inode.c
2641 --- linux-3.9.4/fs/ext3/inode.c 2013-05-31 13:45:23.000000000 +0000
2642 +++ linux-3.9.4-vs2.3.6.3/fs/ext3/inode.c       2013-06-03 19:44:35.000000000 +0000
2643 @@ -27,6 +27,8 @@
2644  #include <linux/writeback.h>
2645  #include <linux/mpage.h>
2646  #include <linux/namei.h>
2647 +#include <linux/vs_tag.h>
2648 +
2649  #include "ext3.h"
2650  #include "xattr.h"
2651  #include "acl.h"
2652 @@ -2851,36 +2853,60 @@ void ext3_set_inode_flags(struct inode *
2653  {
2654         unsigned int flags = EXT3_I(inode)->i_flags;
2655  
2656 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2657 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2658 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2659 +
2660 +       if (flags & EXT3_IMMUTABLE_FL)
2661 +               inode->i_flags |= S_IMMUTABLE;
2662 +       if (flags & EXT3_IXUNLINK_FL)
2663 +               inode->i_flags |= S_IXUNLINK;
2664 +
2665         if (flags & EXT3_SYNC_FL)
2666                 inode->i_flags |= S_SYNC;
2667         if (flags & EXT3_APPEND_FL)
2668                 inode->i_flags |= S_APPEND;
2669 -       if (flags & EXT3_IMMUTABLE_FL)
2670 -               inode->i_flags |= S_IMMUTABLE;
2671         if (flags & EXT3_NOATIME_FL)
2672                 inode->i_flags |= S_NOATIME;
2673         if (flags & EXT3_DIRSYNC_FL)
2674                 inode->i_flags |= S_DIRSYNC;
2675 +
2676 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2677 +
2678 +       if (flags & EXT3_BARRIER_FL)
2679 +               inode->i_vflags |= V_BARRIER;
2680 +       if (flags & EXT3_COW_FL)
2681 +               inode->i_vflags |= V_COW;
2682  }
2683  
2684  /* Propagate flags from i_flags to EXT3_I(inode)->i_flags */
2685  void ext3_get_inode_flags(struct ext3_inode_info *ei)
2686  {
2687         unsigned int flags = ei->vfs_inode.i_flags;
2688 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2689 +
2690 +       ei->i_flags &= ~(EXT3_SYNC_FL | EXT3_APPEND_FL |
2691 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL |
2692 +                       EXT3_NOATIME_FL | EXT3_DIRSYNC_FL |
2693 +                       EXT3_BARRIER_FL | EXT3_COW_FL);
2694 +
2695 +       if (flags & S_IMMUTABLE)
2696 +               ei->i_flags |= EXT3_IMMUTABLE_FL;
2697 +       if (flags & S_IXUNLINK)
2698 +               ei->i_flags |= EXT3_IXUNLINK_FL;
2699  
2700 -       ei->i_flags &= ~(EXT3_SYNC_FL|EXT3_APPEND_FL|
2701 -                       EXT3_IMMUTABLE_FL|EXT3_NOATIME_FL|EXT3_DIRSYNC_FL);
2702         if (flags & S_SYNC)
2703                 ei->i_flags |= EXT3_SYNC_FL;
2704         if (flags & S_APPEND)
2705                 ei->i_flags |= EXT3_APPEND_FL;
2706 -       if (flags & S_IMMUTABLE)
2707 -               ei->i_flags |= EXT3_IMMUTABLE_FL;
2708         if (flags & S_NOATIME)
2709                 ei->i_flags |= EXT3_NOATIME_FL;
2710         if (flags & S_DIRSYNC)
2711                 ei->i_flags |= EXT3_DIRSYNC_FL;
2712 +
2713 +       if (vflags & V_BARRIER)
2714 +               ei->i_flags |= EXT3_BARRIER_FL;
2715 +       if (vflags & V_COW)
2716 +               ei->i_flags |= EXT3_COW_FL;
2717  }
2718  
2719  struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
2720 @@ -2918,8 +2944,10 @@ struct inode *ext3_iget(struct super_blo
2721                 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2722                 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2723         }
2724 -       i_uid_write(inode, i_uid);
2725 -       i_gid_write(inode, i_gid);
2726 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
2727 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
2728 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
2729 +               le16_to_cpu(raw_inode->i_raw_tag)));
2730         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2731         inode->i_size = le32_to_cpu(raw_inode->i_size);
2732         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2733 @@ -3091,8 +3119,10 @@ again:
2734  
2735         ext3_get_inode_flags(ei);
2736         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
2737 -       i_uid = i_uid_read(inode);
2738 -       i_gid = i_gid_read(inode);
2739 +       i_uid = from_kuid(&init_user_ns,
2740 +               TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag));
2741 +       i_gid = from_kgid(&init_user_ns,
2742 +               TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag));
2743         if(!(test_opt(inode->i_sb, NO_UID32))) {
2744                 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(i_uid));
2745                 raw_inode->i_gid_low = cpu_to_le16(low_16_bits(i_gid));
2746 @@ -3117,6 +3147,9 @@ again:
2747                 raw_inode->i_uid_high = 0;
2748                 raw_inode->i_gid_high = 0;
2749         }
2750 +#ifdef CONFIG_TAGGING_INTERN
2751 +       raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
2752 +#endif
2753         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2754         disksize = cpu_to_le32(ei->i_disksize);
2755         if (disksize != raw_inode->i_size) {
2756 @@ -3285,7 +3318,8 @@ int ext3_setattr(struct dentry *dentry,
2757         if (is_quota_modification(inode, attr))
2758                 dquot_initialize(inode);
2759         if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) ||
2760 -           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) {
2761 +           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid)) ||
2762 +           (ia_valid & ATTR_TAG && !tag_eq(attr->ia_tag, inode->i_tag))) {
2763                 handle_t *handle;
2764  
2765                 /* (user+group)*(old+new) structure, inode write (sb,
2766 @@ -3307,6 +3341,8 @@ int ext3_setattr(struct dentry *dentry,
2767                         inode->i_uid = attr->ia_uid;
2768                 if (attr->ia_valid & ATTR_GID)
2769                         inode->i_gid = attr->ia_gid;
2770 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2771 +                       inode->i_tag = attr->ia_tag;
2772                 error = ext3_mark_inode_dirty(handle, inode);
2773                 ext3_journal_stop(handle);
2774         }
2775 diff -NurpP --minimal linux-3.9.4/fs/ext3/ioctl.c linux-3.9.4-vs2.3.6.3/fs/ext3/ioctl.c
2776 --- linux-3.9.4/fs/ext3/ioctl.c 2013-05-31 13:45:23.000000000 +0000
2777 +++ linux-3.9.4-vs2.3.6.3/fs/ext3/ioctl.c       2013-05-31 14:47:11.000000000 +0000
2778 @@ -12,6 +12,34 @@
2779  #include <asm/uaccess.h>
2780  #include "ext3.h"
2781  
2782 +
2783 +int ext3_sync_flags(struct inode *inode, int flags, int vflags)
2784 +{
2785 +       handle_t *handle = NULL;
2786 +       struct ext3_iloc iloc;
2787 +       int err;
2788 +
2789 +       handle = ext3_journal_start(inode, 1);
2790 +       if (IS_ERR(handle))
2791 +               return PTR_ERR(handle);
2792 +
2793 +       if (IS_SYNC(inode))
2794 +               handle->h_sync = 1;
2795 +       err = ext3_reserve_inode_write(handle, inode, &iloc);
2796 +       if (err)
2797 +               goto flags_err;
2798 +
2799 +       inode->i_flags = flags;
2800 +       inode->i_vflags = vflags;
2801 +       ext3_get_inode_flags(EXT3_I(inode));
2802 +       inode->i_ctime = CURRENT_TIME_SEC;
2803 +
2804 +       err = ext3_mark_iloc_dirty(handle, inode, &iloc);
2805 +flags_err:
2806 +       ext3_journal_stop(handle);
2807 +       return err;
2808 +}
2809 +
2810  long ext3_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2811  {
2812         struct inode *inode = file_inode(filp);
2813 @@ -45,6 +73,11 @@ long ext3_ioctl(struct file *filp, unsig
2814  
2815                 flags = ext3_mask_flags(inode->i_mode, flags);
2816  
2817 +               if (IS_BARRIER(inode)) {
2818 +                       vxwprintk_task(1, "messing with the barrier.");
2819 +                       return -EACCES;
2820 +               }
2821 +
2822                 mutex_lock(&inode->i_mutex);
2823  
2824                 /* Is it quota file? Do not allow user to mess with it */
2825 @@ -63,7 +96,9 @@ long ext3_ioctl(struct file *filp, unsig
2826                  *
2827                  * This test looks nicer. Thanks to Pauline Middelink
2828                  */
2829 -               if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
2830 +               if ((oldflags & EXT3_IMMUTABLE_FL) ||
2831 +                       ((flags ^ oldflags) & (EXT3_APPEND_FL |
2832 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL))) {
2833                         if (!capable(CAP_LINUX_IMMUTABLE))
2834                                 goto flags_out;
2835                 }
2836 @@ -88,7 +123,7 @@ long ext3_ioctl(struct file *filp, unsig
2837                 if (err)
2838                         goto flags_err;
2839  
2840 -               flags = flags & EXT3_FL_USER_MODIFIABLE;
2841 +               flags &= EXT3_FL_USER_MODIFIABLE;
2842                 flags |= oldflags & ~EXT3_FL_USER_MODIFIABLE;
2843                 ei->i_flags = flags;
2844  
2845 diff -NurpP --minimal linux-3.9.4/fs/ext3/namei.c linux-3.9.4-vs2.3.6.3/fs/ext3/namei.c
2846 --- linux-3.9.4/fs/ext3/namei.c 2013-05-31 13:45:23.000000000 +0000
2847 +++ linux-3.9.4-vs2.3.6.3/fs/ext3/namei.c       2013-05-31 14:47:11.000000000 +0000
2848 @@ -25,6 +25,8 @@
2849   */
2850  
2851  #include <linux/quotaops.h>
2852 +#include <linux/vs_tag.h>
2853 +
2854  #include "ext3.h"
2855  #include "namei.h"
2856  #include "xattr.h"
2857 @@ -918,6 +920,7 @@ restart:
2858                                         submit_bh(READ | REQ_META | REQ_PRIO,
2859                                                   bh);
2860                                 }
2861 +               dx_propagate_tag(nd, inode);
2862                         }
2863                 }
2864                 if ((bh = bh_use[ra_ptr++]) == NULL)
2865 @@ -2527,6 +2530,7 @@ const struct inode_operations ext3_dir_i
2866         .listxattr      = ext3_listxattr,
2867         .removexattr    = generic_removexattr,
2868  #endif
2869 +       .sync_flags     = ext3_sync_flags,
2870         .get_acl        = ext3_get_acl,
2871  };
2872  
2873 diff -NurpP --minimal linux-3.9.4/fs/ext3/super.c linux-3.9.4-vs2.3.6.3/fs/ext3/super.c
2874 --- linux-3.9.4/fs/ext3/super.c 2013-05-31 13:45:23.000000000 +0000
2875 +++ linux-3.9.4-vs2.3.6.3/fs/ext3/super.c       2013-05-31 14:47:11.000000000 +0000
2876 @@ -816,7 +816,8 @@ enum {
2877         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
2878         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota,
2879         Opt_noquota, Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err,
2880 -       Opt_resize, Opt_usrquota, Opt_grpquota
2881 +       Opt_resize, Opt_usrquota, Opt_grpquota,
2882 +       Opt_tag, Opt_notag, Opt_tagid
2883  };
2884  
2885  static const match_table_t tokens = {
2886 @@ -873,6 +874,9 @@ static const match_table_t tokens = {
2887         {Opt_barrier, "barrier"},
2888         {Opt_nobarrier, "nobarrier"},
2889         {Opt_resize, "resize"},
2890 +       {Opt_tag, "tag"},
2891 +       {Opt_notag, "notag"},
2892 +       {Opt_tagid, "tagid=%u"},
2893         {Opt_err, NULL},
2894  };
2895  
2896 @@ -1040,6 +1044,20 @@ static int parse_options (char *options,
2897                 case Opt_nouid32:
2898                         set_opt (sbi->s_mount_opt, NO_UID32);
2899                         break;
2900 +#ifndef CONFIG_TAGGING_NONE
2901 +               case Opt_tag:
2902 +                       set_opt (sbi->s_mount_opt, TAGGED);
2903 +                       break;
2904 +               case Opt_notag:
2905 +                       clear_opt (sbi->s_mount_opt, TAGGED);
2906 +                       break;
2907 +#endif
2908 +#ifdef CONFIG_PROPAGATE
2909 +               case Opt_tagid:
2910 +                       /* use args[0] */
2911 +                       set_opt (sbi->s_mount_opt, TAGGED);
2912 +                       break;
2913 +#endif
2914                 case Opt_nocheck:
2915                         clear_opt (sbi->s_mount_opt, CHECK);
2916                         break;
2917 @@ -1737,6 +1755,9 @@ static int ext3_fill_super (struct super
2918                             NULL, 0))
2919                 goto failed_mount;
2920  
2921 +       if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
2922 +               sb->s_flags |= MS_TAGGED;
2923 +
2924         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2925                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2926  
2927 @@ -2633,6 +2654,14 @@ static int ext3_remount (struct super_bl
2928         if (test_opt(sb, ABORT))
2929                 ext3_abort(sb, __func__, "Abort forced by user");
2930  
2931 +       if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
2932 +               !(sb->s_flags & MS_TAGGED)) {
2933 +               printk("EXT3-fs: %s: tagging not permitted on remount.\n",
2934 +                       sb->s_id);
2935 +               err = -EINVAL;
2936 +               goto restore_opts;
2937 +       }
2938 +
2939         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2940                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2941  
2942 diff -NurpP --minimal linux-3.9.4/fs/ext4/ext4.h linux-3.9.4-vs2.3.6.3/fs/ext4/ext4.h
2943 --- linux-3.9.4/fs/ext4/ext4.h  2013-05-31 13:45:23.000000000 +0000
2944 +++ linux-3.9.4-vs2.3.6.3/fs/ext4/ext4.h        2013-05-31 16:22:49.000000000 +0000
2945 @@ -399,7 +399,10 @@ struct flex_groups {
2946  #define EXT4_EXTENTS_FL                        0x00080000 /* Inode uses extents */
2947  #define EXT4_EA_INODE_FL               0x00200000 /* Inode used for large EA */
2948  #define EXT4_EOFBLOCKS_FL              0x00400000 /* Blocks allocated beyond EOF */
2949 +#define EXT4_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
2950 +#define EXT4_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
2951  #define EXT4_INLINE_DATA_FL            0x10000000 /* Inode has inline data. */
2952 +#define EXT4_COW_FL                    0x20000000 /* Copy on Write marker */
2953  #define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
2954  
2955  #define EXT4_FL_USER_VISIBLE           0x004BDFFF /* User visible flags */
2956 @@ -674,7 +677,7 @@ struct ext4_inode {
2957                         __le16  l_i_uid_high;   /* these 2 fields */
2958                         __le16  l_i_gid_high;   /* were reserved2[0] */
2959                         __le16  l_i_checksum_lo;/* crc32c(uuid+inum+inode) LE */
2960 -                       __le16  l_i_reserved;
2961 +                       __le16  l_i_tag;        /* Context Tag */
2962                 } linux2;
2963                 struct {
2964                         __le16  h_i_reserved1;  /* Obsoleted fragment number/size which are removed in ext4 */
2965 @@ -792,6 +795,7 @@ do {                                                                               \
2966  #define i_gid_low      i_gid
2967  #define i_uid_high     osd2.linux2.l_i_uid_high
2968  #define i_gid_high     osd2.linux2.l_i_gid_high
2969 +#define i_raw_tag      osd2.linux2.l_i_tag
2970  #define i_checksum_lo  osd2.linux2.l_i_checksum_lo
2971  
2972  #elif defined(__GNU__)
2973 @@ -969,6 +973,7 @@ struct ext4_inode_info {
2974  #define EXT4_MOUNT_POSIX_ACL           0x08000 /* POSIX Access Control Lists */
2975  #define EXT4_MOUNT_NO_AUTO_DA_ALLOC    0x10000 /* No auto delalloc mapping */
2976  #define EXT4_MOUNT_BARRIER             0x20000 /* Use block barriers */
2977 +#define EXT4_MOUNT_TAGGED              0x40000 /* Enable Context Tags */
2978  #define EXT4_MOUNT_QUOTA               0x80000 /* Some quota option set */
2979  #define EXT4_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
2980  #define EXT4_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
2981 @@ -2527,6 +2532,7 @@ extern struct buffer_head *ext4_get_firs
2982  extern int ext4_inline_data_fiemap(struct inode *inode,
2983                                    struct fiemap_extent_info *fieinfo,
2984                                    int *has_inline);
2985 +extern int ext4_sync_flags(struct inode *, int, int);
2986  extern int ext4_try_to_evict_inline_data(handle_t *handle,
2987                                          struct inode *inode,
2988                                          int needed);
2989 diff -NurpP --minimal linux-3.9.4/fs/ext4/file.c linux-3.9.4-vs2.3.6.3/fs/ext4/file.c
2990 --- linux-3.9.4/fs/ext4/file.c  2013-05-31 13:45:23.000000000 +0000
2991 +++ linux-3.9.4-vs2.3.6.3/fs/ext4/file.c        2013-05-31 14:47:11.000000000 +0000
2992 @@ -650,5 +650,6 @@ const struct inode_operations ext4_file_
2993         .removexattr    = generic_removexattr,
2994         .get_acl        = ext4_get_acl,
2995         .fiemap         = ext4_fiemap,
2996 +       .sync_flags     = ext4_sync_flags,
2997  };
2998  
2999 diff -NurpP --minimal linux-3.9.4/fs/ext4/ialloc.c linux-3.9.4-vs2.3.6.3/fs/ext4/ialloc.c
3000 --- linux-3.9.4/fs/ext4/ialloc.c        2013-05-31 13:45:23.000000000 +0000
3001 +++ linux-3.9.4-vs2.3.6.3/fs/ext4/ialloc.c      2013-06-03 19:45:15.000000000 +0000
3002 @@ -22,6 +22,7 @@
3003  #include <linux/random.h>
3004  #include <linux/bitops.h>
3005  #include <linux/blkdev.h>
3006 +#include <linux/vs_tag.h>
3007  #include <asm/byteorder.h>
3008  
3009  #include "ext4.h"
3010 @@ -859,6 +860,7 @@ got:
3011                 inode->i_mode = mode;
3012                 inode->i_uid = current_fsuid();
3013                 inode->i_gid = dir->i_gid;
3014 +               i_tag_write(inode, dx_current_fstag(sb));
3015         } else
3016                 inode_init_owner(inode, dir, mode);
3017  
3018 diff -NurpP --minimal linux-3.9.4/fs/ext4/inode.c linux-3.9.4-vs2.3.6.3/fs/ext4/inode.c
3019 --- linux-3.9.4/fs/ext4/inode.c 2013-05-31 14:22:27.000000000 +0000
3020 +++ linux-3.9.4-vs2.3.6.3/fs/ext4/inode.c       2013-06-03 19:45:35.000000000 +0000
3021 @@ -37,6 +37,7 @@
3022  #include <linux/printk.h>
3023  #include <linux/slab.h>
3024  #include <linux/ratelimit.h>
3025 +#include <linux/vs_tag.h>
3026  
3027  #include "ext4_jbd2.h"
3028  #include "xattr.h"
3029 @@ -3870,41 +3871,64 @@ void ext4_set_inode_flags(struct inode *
3030  {
3031         unsigned int flags = EXT4_I(inode)->i_flags;
3032  
3033 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3034 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3035 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3036 +
3037 +       if (flags & EXT4_IMMUTABLE_FL)
3038 +               inode->i_flags |= S_IMMUTABLE;
3039 +       if (flags & EXT4_IXUNLINK_FL)
3040 +               inode->i_flags |= S_IXUNLINK;
3041 +
3042         if (flags & EXT4_SYNC_FL)
3043                 inode->i_flags |= S_SYNC;
3044         if (flags & EXT4_APPEND_FL)
3045                 inode->i_flags |= S_APPEND;
3046 -       if (flags & EXT4_IMMUTABLE_FL)
3047 -               inode->i_flags |= S_IMMUTABLE;
3048         if (flags & EXT4_NOATIME_FL)
3049                 inode->i_flags |= S_NOATIME;
3050         if (flags & EXT4_DIRSYNC_FL)
3051                 inode->i_flags |= S_DIRSYNC;
3052 +
3053 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3054 +
3055 +       if (flags & EXT4_BARRIER_FL)
3056 +               inode->i_vflags |= V_BARRIER;
3057 +       if (flags & EXT4_COW_FL)
3058 +               inode->i_vflags |= V_COW;
3059  }
3060  
3061  /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
3062  void ext4_get_inode_flags(struct ext4_inode_info *ei)
3063  {
3064 -       unsigned int vfs_fl;
3065 +       unsigned int vfs_fl, vfs_vf;
3066         unsigned long old_fl, new_fl;
3067  
3068         do {
3069                 vfs_fl = ei->vfs_inode.i_flags;
3070 +               vfs_vf = ei->vfs_inode.i_vflags;
3071                 old_fl = ei->i_flags;
3072                 new_fl = old_fl & ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
3073                                 EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|
3074 -                               EXT4_DIRSYNC_FL);
3075 +                               EXT4_DIRSYNC_FL|EXT4_BARRIER_FL|
3076 +                               EXT4_COW_FL);
3077 +
3078 +               if (vfs_fl & S_IMMUTABLE)
3079 +                       new_fl |= EXT4_IMMUTABLE_FL;
3080 +               if (vfs_fl & S_IXUNLINK)
3081 +                       new_fl |= EXT4_IXUNLINK_FL;
3082 +
3083                 if (vfs_fl & S_SYNC)
3084                         new_fl |= EXT4_SYNC_FL;
3085                 if (vfs_fl & S_APPEND)
3086                         new_fl |= EXT4_APPEND_FL;
3087 -               if (vfs_fl & S_IMMUTABLE)
3088 -                       new_fl |= EXT4_IMMUTABLE_FL;
3089                 if (vfs_fl & S_NOATIME)
3090                         new_fl |= EXT4_NOATIME_FL;
3091                 if (vfs_fl & S_DIRSYNC)
3092                         new_fl |= EXT4_DIRSYNC_FL;
3093 +
3094 +               if (vfs_vf & V_BARRIER)
3095 +                       new_fl |= EXT4_BARRIER_FL;
3096 +               if (vfs_vf & V_COW)
3097 +                       new_fl |= EXT4_COW_FL;
3098         } while (cmpxchg(&ei->i_flags, old_fl, new_fl) != old_fl);
3099  }
3100  
3101 @@ -4009,8 +4033,10 @@ struct inode *ext4_iget(struct super_blo
3102                 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3103                 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3104         }
3105 -       i_uid_write(inode, i_uid);
3106 -       i_gid_write(inode, i_gid);
3107 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
3108 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
3109 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
3110 +               le16_to_cpu(raw_inode->i_raw_tag)));
3111         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
3112  
3113         ext4_clear_state_flags(ei);     /* Only relevant on 32-bit archs */
3114 @@ -4233,8 +4259,10 @@ static int ext4_do_update_inode(handle_t
3115  
3116         ext4_get_inode_flags(ei);
3117         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3118 -       i_uid = i_uid_read(inode);
3119 -       i_gid = i_gid_read(inode);
3120 +       i_uid = from_kuid(&init_user_ns,
3121 +               TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag));
3122 +       i_gid = from_kgid(&init_user_ns,
3123 +               TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag));
3124         if (!(test_opt(inode->i_sb, NO_UID32))) {
3125                 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(i_uid));
3126                 raw_inode->i_gid_low = cpu_to_le16(low_16_bits(i_gid));
3127 @@ -4257,6 +4285,9 @@ static int ext4_do_update_inode(handle_t
3128                 raw_inode->i_uid_high = 0;
3129                 raw_inode->i_gid_high = 0;
3130         }
3131 +#ifdef CONFIG_TAGGING_INTERN
3132 +       raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
3133 +#endif
3134         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3135  
3136         EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
3137 @@ -4487,7 +4518,8 @@ int ext4_setattr(struct dentry *dentry,
3138         if (is_quota_modification(inode, attr))
3139                 dquot_initialize(inode);
3140         if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) ||
3141 -           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) {
3142 +           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid)) ||
3143 +           (ia_valid & ATTR_TAG && !tag_eq(attr->ia_tag, inode->i_tag))) {
3144                 handle_t *handle;
3145  
3146                 /* (user+group)*(old+new) structure, inode write (sb,
3147 @@ -4510,6 +4542,8 @@ int ext4_setattr(struct dentry *dentry,
3148                         inode->i_uid = attr->ia_uid;
3149                 if (attr->ia_valid & ATTR_GID)
3150                         inode->i_gid = attr->ia_gid;
3151 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3152 +                       inode->i_tag = attr->ia_tag;
3153                 error = ext4_mark_inode_dirty(handle, inode);
3154                 ext4_journal_stop(handle);
3155         }
3156 diff -NurpP --minimal linux-3.9.4/fs/ext4/ioctl.c linux-3.9.4-vs2.3.6.3/fs/ext4/ioctl.c
3157 --- linux-3.9.4/fs/ext4/ioctl.c 2013-05-31 13:45:23.000000000 +0000
3158 +++ linux-3.9.4-vs2.3.6.3/fs/ext4/ioctl.c       2013-05-31 19:50:08.000000000 +0000
3159 @@ -14,12 +14,40 @@
3160  #include <linux/compat.h>
3161  #include <linux/mount.h>
3162  #include <linux/file.h>
3163 +#include <linux/vs_tag.h>
3164  #include <asm/uaccess.h>
3165  #include "ext4_jbd2.h"
3166  #include "ext4.h"
3167  
3168  #define MAX_32_NUM ((((unsigned long long) 1) << 32) - 1)
3169  
3170 +int ext4_sync_flags(struct inode *inode, int flags, int vflags)
3171 +{
3172 +       handle_t *handle = NULL;
3173 +       struct ext4_iloc iloc;
3174 +       int err;
3175 +
3176 +       handle = ext4_journal_start(inode, EXT4_HT_INODE, 1);
3177 +       if (IS_ERR(handle))
3178 +               return PTR_ERR(handle);
3179 +
3180 +       if (IS_SYNC(inode))
3181 +               ext4_handle_sync(handle);
3182 +       err = ext4_reserve_inode_write(handle, inode, &iloc);
3183 +       if (err)
3184 +               goto flags_err;
3185 +
3186 +       inode->i_flags = flags;
3187 +       inode->i_vflags = vflags;
3188 +       ext4_get_inode_flags(EXT4_I(inode));
3189 +       inode->i_ctime = ext4_current_time(inode);
3190 +
3191 +       err = ext4_mark_iloc_dirty(handle, inode, &iloc);
3192 +flags_err:
3193 +       ext4_journal_stop(handle);
3194 +       return err;
3195 +}
3196 +
3197  long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3198  {
3199         struct inode *inode = file_inode(filp);
3200 @@ -53,6 +81,11 @@ long ext4_ioctl(struct file *filp, unsig
3201  
3202                 flags = ext4_mask_flags(inode->i_mode, flags);
3203  
3204 +               if (IS_BARRIER(inode)) {
3205 +                       vxwprintk_task(1, "messing with the barrier.");
3206 +                       return -EACCES;
3207 +               }
3208 +
3209                 err = -EPERM;
3210                 mutex_lock(&inode->i_mutex);
3211                 /* Is it quota file? Do not allow user to mess with it */
3212 @@ -70,7 +103,9 @@ long ext4_ioctl(struct file *filp, unsig
3213                  *
3214                  * This test looks nicer. Thanks to Pauline Middelink
3215                  */
3216 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
3217 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
3218 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
3219 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
3220                         if (!capable(CAP_LINUX_IMMUTABLE))
3221                                 goto flags_out;
3222                 }
3223 diff -NurpP --minimal linux-3.9.4/fs/ext4/namei.c linux-3.9.4-vs2.3.6.3/fs/ext4/namei.c
3224 --- linux-3.9.4/fs/ext4/namei.c 2013-05-31 13:45:23.000000000 +0000
3225 +++ linux-3.9.4-vs2.3.6.3/fs/ext4/namei.c       2013-05-31 14:47:11.000000000 +0000
3226 @@ -34,6 +34,7 @@
3227  #include <linux/quotaops.h>
3228  #include <linux/buffer_head.h>
3229  #include <linux/bio.h>
3230 +#include <linux/vs_tag.h>
3231  #include "ext4.h"
3232  #include "ext4_jbd2.h"
3233  
3234 @@ -1290,6 +1291,7 @@ restart:
3235                                         ll_rw_block(READ | REQ_META | REQ_PRIO,
3236                                                     1, &bh);
3237                         }
3238 +               dx_propagate_tag(nd, inode);
3239                 }
3240                 if ((bh = bh_use[ra_ptr++]) == NULL)
3241                         goto next;
3242 @@ -3190,6 +3192,7 @@ const struct inode_operations ext4_dir_i
3243         .removexattr    = generic_removexattr,
3244         .get_acl        = ext4_get_acl,
3245         .fiemap         = ext4_fiemap,
3246 +       .sync_flags     = ext4_sync_flags,
3247  };
3248  
3249  const struct inode_operations ext4_special_inode_operations = {
3250 diff -NurpP --minimal linux-3.9.4/fs/ext4/super.c linux-3.9.4-vs2.3.6.3/fs/ext4/super.c
3251 --- linux-3.9.4/fs/ext4/super.c 2013-05-31 14:22:27.000000000 +0000
3252 +++ linux-3.9.4-vs2.3.6.3/fs/ext4/super.c       2013-05-31 14:47:11.000000000 +0000
3253 @@ -1131,7 +1131,7 @@ enum {
3254         Opt_inode_readahead_blks, Opt_journal_ioprio,
3255         Opt_dioread_nolock, Opt_dioread_lock,
3256         Opt_discard, Opt_nodiscard, Opt_init_itable, Opt_noinit_itable,
3257 -       Opt_max_dir_size_kb,
3258 +       Opt_max_dir_size_kb, Opt_tag, Opt_notag, Opt_tagid
3259  };
3260  
3261  static const match_table_t tokens = {
3262 @@ -1211,6 +1211,9 @@ static const match_table_t tokens = {
3263         {Opt_removed, "reservation"},   /* mount option from ext2/3 */
3264         {Opt_removed, "noreservation"}, /* mount option from ext2/3 */
3265         {Opt_removed, "journal=%u"},    /* mount option from ext2/3 */
3266 +       {Opt_tag, "tag"},
3267 +       {Opt_notag, "notag"},
3268 +       {Opt_tagid, "tagid=%u"},
3269         {Opt_err, NULL},
3270  };
3271  
3272 @@ -1441,6 +1444,20 @@ static int handle_mount_opt(struct super
3273         case Opt_i_version:
3274                 sb->s_flags |= MS_I_VERSION;
3275                 return 1;
3276 +#ifndef CONFIG_TAGGING_NONE
3277 +       case Opt_tag:
3278 +               set_opt(sb, TAGGED);
3279 +               return 1;
3280 +       case Opt_notag:
3281 +               clear_opt(sb, TAGGED);
3282 +               return 1;
3283 +#endif
3284 +#ifdef CONFIG_PROPAGATE
3285 +       case Opt_tagid:
3286 +               /* use args[0] */
3287 +               set_opt(sb, TAGGED);
3288 +               return 1;
3289 +#endif
3290         }
3291  
3292         for (m = ext4_mount_opts; m->token != Opt_err; m++)
3293 @@ -3401,6 +3418,9 @@ static int ext4_fill_super(struct super_
3294                         clear_opt(sb, DELALLOC);
3295         }
3296  
3297 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
3298 +               sb->s_flags |= MS_TAGGED;
3299 +
3300         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3301                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3302  
3303 @@ -4587,6 +4607,14 @@ static int ext4_remount(struct super_blo
3304         if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
3305                 ext4_abort(sb, "Abort forced by user");
3306  
3307 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
3308 +               !(sb->s_flags & MS_TAGGED)) {
3309 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
3310 +                       sb->s_id);
3311 +               err = -EINVAL;
3312 +               goto restore_opts;
3313 +       }
3314 +
3315         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3316                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3317  
3318 diff -NurpP --minimal linux-3.9.4/fs/fcntl.c linux-3.9.4-vs2.3.6.3/fs/fcntl.c
3319 --- linux-3.9.4/fs/fcntl.c      2013-05-31 13:45:23.000000000 +0000
3320 +++ linux-3.9.4-vs2.3.6.3/fs/fcntl.c    2013-05-31 14:47:11.000000000 +0000
3321 @@ -21,6 +21,7 @@
3322  #include <linux/rcupdate.h>
3323  #include <linux/pid_namespace.h>
3324  #include <linux/user_namespace.h>
3325 +#include <linux/vs_limit.h>
3326  
3327  #include <asm/poll.h>
3328  #include <asm/siginfo.h>
3329 @@ -378,6 +379,8 @@ SYSCALL_DEFINE3(fcntl64, unsigned int, f
3330  
3331         if (!f.file)
3332                 goto out;
3333 +       if (!vx_files_avail(1))
3334 +               goto out;
3335  
3336         if (unlikely(f.file->f_mode & FMODE_PATH)) {
3337                 if (!check_fcntl_cmd(cmd))
3338 diff -NurpP --minimal linux-3.9.4/fs/file.c linux-3.9.4-vs2.3.6.3/fs/file.c
3339 --- linux-3.9.4/fs/file.c       2013-05-31 13:45:23.000000000 +0000
3340 +++ linux-3.9.4-vs2.3.6.3/fs/file.c     2013-05-31 14:47:11.000000000 +0000
3341 @@ -22,6 +22,7 @@
3342  #include <linux/spinlock.h>
3343  #include <linux/rcupdate.h>
3344  #include <linux/workqueue.h>
3345 +#include <linux/vs_limit.h>
3346  
3347  struct fdtable_defer {
3348         spinlock_t lock;
3349 @@ -364,6 +365,8 @@ struct files_struct *dup_fd(struct files
3350                 struct file *f = *old_fds++;
3351                 if (f) {
3352                         get_file(f);
3353 +                       /* TODO: sum it first for check and performance */
3354 +                       vx_openfd_inc(open_files - i);
3355                 } else {
3356                         /*
3357                          * The fd may be claimed in the fd bitmap but not yet
3358 @@ -429,9 +432,11 @@ static void close_files(struct files_str
3359                                         filp_close(file, files);
3360                                         cond_resched();
3361                                 }
3362 +                               vx_openfd_dec(i);
3363                         }
3364                         i++;
3365                         set >>= 1;
3366 +                       cond_resched();
3367                 }
3368         }
3369  }
3370 @@ -567,6 +572,7 @@ repeat:
3371         else
3372                 __clear_close_on_exec(fd, fdt);
3373         error = fd;
3374 +       vx_openfd_inc(fd);
3375  #if 1
3376         /* Sanity check */
3377         if (rcu_dereference_raw(fdt->fd[fd]) != NULL) {
3378 @@ -597,6 +603,7 @@ static void __put_unused_fd(struct files
3379         __clear_open_fd(fd, fdt);
3380         if (fd < files->next_fd)
3381                 files->next_fd = fd;
3382 +       vx_openfd_dec(fd);
3383  }
3384  
3385  void put_unused_fd(unsigned int fd)
3386 @@ -876,6 +883,8 @@ static int do_dup2(struct files_struct *
3387  
3388         if (tofree)
3389                 filp_close(tofree, files);
3390 +       else
3391 +               vx_openfd_inc(fd);      /* fd was unused */
3392  
3393         return fd;
3394  
3395 diff -NurpP --minimal linux-3.9.4/fs/file_table.c linux-3.9.4-vs2.3.6.3/fs/file_table.c
3396 --- linux-3.9.4/fs/file_table.c 2013-05-31 13:45:23.000000000 +0000
3397 +++ linux-3.9.4-vs2.3.6.3/fs/file_table.c       2013-05-31 14:47:11.000000000 +0000
3398 @@ -26,6 +26,8 @@
3399  #include <linux/hardirq.h>
3400  #include <linux/task_work.h>
3401  #include <linux/ima.h>
3402 +#include <linux/vs_limit.h>
3403 +#include <linux/vs_context.h>
3404  
3405  #include <linux/atomic.h>
3406  
3407 @@ -140,6 +142,8 @@ struct file *get_empty_filp(void)
3408         spin_lock_init(&f->f_lock);
3409         eventpoll_init_file(f);
3410         /* f->f_version: 0 */
3411 +       f->f_xid = vx_current_xid();
3412 +       vx_files_inc(f);
3413         return f;
3414  
3415  over:
3416 @@ -257,6 +261,8 @@ static void __fput(struct file *file)
3417                 i_readcount_dec(inode);
3418         if (file->f_mode & FMODE_WRITE)
3419                 drop_file_write_access(file);
3420 +       vx_files_dec(file);
3421 +       file->f_xid = 0;
3422         file->f_path.dentry = NULL;
3423         file->f_path.mnt = NULL;
3424         file->f_inode = NULL;
3425 @@ -344,6 +350,8 @@ void put_filp(struct file *file)
3426  {
3427         if (atomic_long_dec_and_test(&file->f_count)) {
3428                 security_file_free(file);
3429 +               vx_files_dec(file);
3430 +               file->f_xid = 0;
3431                 file_sb_list_del(file);
3432                 file_free(file);
3433         }
3434 diff -NurpP --minimal linux-3.9.4/fs/fs_struct.c linux-3.9.4-vs2.3.6.3/fs/fs_struct.c
3435 --- linux-3.9.4/fs/fs_struct.c  2013-05-31 13:45:23.000000000 +0000
3436 +++ linux-3.9.4-vs2.3.6.3/fs/fs_struct.c        2013-05-31 14:47:11.000000000 +0000
3437 @@ -4,6 +4,7 @@
3438  #include <linux/path.h>
3439  #include <linux/slab.h>
3440  #include <linux/fs_struct.h>
3441 +#include <linux/vserver/global.h>
3442  #include "internal.h"
3443  
3444  /*
3445 @@ -87,6 +88,7 @@ void free_fs_struct(struct fs_struct *fs
3446  {
3447         path_put(&fs->root);
3448         path_put(&fs->pwd);
3449 +       atomic_dec(&vs_global_fs);
3450         kmem_cache_free(fs_cachep, fs);
3451  }
3452  
3453 @@ -124,6 +126,7 @@ struct fs_struct *copy_fs_struct(struct
3454                 fs->pwd = old->pwd;
3455                 path_get(&fs->pwd);
3456                 spin_unlock(&old->lock);
3457 +               atomic_inc(&vs_global_fs);
3458         }
3459         return fs;
3460  }
3461 diff -NurpP --minimal linux-3.9.4/fs/gfs2/file.c linux-3.9.4-vs2.3.6.3/fs/gfs2/file.c
3462 --- linux-3.9.4/fs/gfs2/file.c  2013-05-31 13:45:23.000000000 +0000
3463 +++ linux-3.9.4-vs2.3.6.3/fs/gfs2/file.c        2013-05-31 19:54:27.000000000 +0000
3464 @@ -143,6 +143,9 @@ static const u32 fsflags_to_gfs2[32] = {
3465         [12] = GFS2_DIF_EXHASH,
3466         [14] = GFS2_DIF_INHERIT_JDATA,
3467         [17] = GFS2_DIF_TOPDIR,
3468 +       [27] = GFS2_DIF_IXUNLINK,
3469 +       [26] = GFS2_DIF_BARRIER,
3470 +       [29] = GFS2_DIF_COW,
3471  };
3472  
3473  static const u32 gfs2_to_fsflags[32] = {
3474 @@ -153,6 +156,9 @@ static const u32 gfs2_to_fsflags[32] = {
3475         [gfs2fl_ExHash] = FS_INDEX_FL,
3476         [gfs2fl_TopLevel] = FS_TOPDIR_FL,
3477         [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL,
3478 +       [gfs2fl_IXUnlink] = FS_IXUNLINK_FL,
3479 +       [gfs2fl_Barrier] = FS_BARRIER_FL,
3480 +       [gfs2fl_Cow] = FS_COW_FL,
3481  };
3482  
3483  static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
3484 @@ -183,12 +189,18 @@ void gfs2_set_inode_flags(struct inode *
3485  {
3486         struct gfs2_inode *ip = GFS2_I(inode);
3487         unsigned int flags = inode->i_flags;
3488 +       unsigned int vflags = inode->i_vflags;
3489 +
3490 +       flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3491 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC | S_NOSEC);
3492  
3493 -       flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC|S_NOSEC);
3494         if ((ip->i_eattr == 0) && !is_sxid(inode->i_mode))
3495                 inode->i_flags |= S_NOSEC;
3496         if (ip->i_diskflags & GFS2_DIF_IMMUTABLE)
3497                 flags |= S_IMMUTABLE;
3498 +       if (ip->i_diskflags & GFS2_DIF_IXUNLINK)
3499 +               flags |= S_IXUNLINK;
3500 +
3501         if (ip->i_diskflags & GFS2_DIF_APPENDONLY)
3502                 flags |= S_APPEND;
3503         if (ip->i_diskflags & GFS2_DIF_NOATIME)
3504 @@ -196,6 +208,43 @@ void gfs2_set_inode_flags(struct inode *
3505         if (ip->i_diskflags & GFS2_DIF_SYNC)
3506                 flags |= S_SYNC;
3507         inode->i_flags = flags;
3508 +
3509 +       vflags &= ~(V_BARRIER | V_COW);
3510 +
3511 +       if (ip->i_diskflags & GFS2_DIF_BARRIER)
3512 +               vflags |= V_BARRIER;
3513 +       if (ip->i_diskflags & GFS2_DIF_COW)
3514 +               vflags |= V_COW;
3515 +       inode->i_vflags = vflags;
3516 +}
3517 +
3518 +void gfs2_get_inode_flags(struct inode *inode)
3519 +{
3520 +       struct gfs2_inode *ip = GFS2_I(inode);
3521 +       unsigned int flags = inode->i_flags;
3522 +       unsigned int vflags = inode->i_vflags;
3523 +
3524 +       ip->i_diskflags &= ~(GFS2_DIF_APPENDONLY |
3525 +                       GFS2_DIF_NOATIME | GFS2_DIF_SYNC |
3526 +                       GFS2_DIF_IMMUTABLE | GFS2_DIF_IXUNLINK |
3527 +                       GFS2_DIF_BARRIER | GFS2_DIF_COW);
3528 +
3529 +       if (flags & S_IMMUTABLE)
3530 +               ip->i_diskflags |= GFS2_DIF_IMMUTABLE;
3531 +       if (flags & S_IXUNLINK)
3532 +               ip->i_diskflags |= GFS2_DIF_IXUNLINK;
3533 +
3534 +       if (flags & S_APPEND)
3535 +               ip->i_diskflags |= GFS2_DIF_APPENDONLY;
3536 +       if (flags & S_NOATIME)
3537 +               ip->i_diskflags |= GFS2_DIF_NOATIME;
3538 +       if (flags & S_SYNC)
3539 +               ip->i_diskflags |= GFS2_DIF_SYNC;
3540 +
3541 +       if (vflags & V_BARRIER)
3542 +               ip->i_diskflags |= GFS2_DIF_BARRIER;
3543 +       if (vflags & V_COW)
3544 +               ip->i_diskflags |= GFS2_DIF_COW;
3545  }
3546  
3547  /* Flags that can be set by user space */
3548 @@ -309,6 +358,37 @@ static int gfs2_set_flags(struct file *f
3549         return do_gfs2_set_flags(filp, gfsflags, ~GFS2_DIF_JDATA);
3550  }
3551  
3552 +int gfs2_sync_flags(struct inode *inode, int flags, int vflags)
3553 +{
3554 +       struct gfs2_inode *ip = GFS2_I(inode);
3555 +       struct gfs2_sbd *sdp = GFS2_SB(inode);
3556 +       struct buffer_head *bh;
3557 +       struct gfs2_holder gh;
3558 +       int error;
3559 +
3560 +       error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
3561 +       if (error)
3562 +               return error;
3563 +       error = gfs2_trans_begin(sdp, RES_DINODE, 0);
3564 +       if (error)
3565 +               goto out;
3566 +       error = gfs2_meta_inode_buffer(ip, &bh);
3567 +       if (error)
3568 +               goto out_trans_end;
3569 +       gfs2_trans_add_meta(ip->i_gl, bh);
3570 +       inode->i_flags = flags;
3571 +       inode->i_vflags = vflags;
3572 +       gfs2_get_inode_flags(inode);
3573 +       gfs2_dinode_out(ip, bh->b_data);
3574 +       brelse(bh);
3575 +       gfs2_set_aops(inode);
3576 +out_trans_end:
3577 +       gfs2_trans_end(sdp);
3578 +out:
3579 +       gfs2_glock_dq_uninit(&gh);
3580 +       return error;
3581 +}
3582 +
3583  static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3584  {
3585         switch(cmd) {
3586 diff -NurpP --minimal linux-3.9.4/fs/gfs2/inode.h linux-3.9.4-vs2.3.6.3/fs/gfs2/inode.h
3587 --- linux-3.9.4/fs/gfs2/inode.h 2012-12-11 03:30:57.000000000 +0000
3588 +++ linux-3.9.4-vs2.3.6.3/fs/gfs2/inode.h       2013-05-31 14:47:11.000000000 +0000
3589 @@ -117,6 +117,7 @@ extern const struct file_operations gfs2
3590  extern const struct file_operations gfs2_dir_fops_nolock;
3591  
3592  extern void gfs2_set_inode_flags(struct inode *inode);
3593 +extern int gfs2_sync_flags(struct inode *inode, int flags, int vflags);
3594   
3595  #ifdef CONFIG_GFS2_FS_LOCKING_DLM
3596  extern const struct file_operations gfs2_file_fops;
3597 diff -NurpP --minimal linux-3.9.4/fs/hostfs/hostfs.h linux-3.9.4-vs2.3.6.3/fs/hostfs/hostfs.h
3598 --- linux-3.9.4/fs/hostfs/hostfs.h      2012-12-11 03:30:57.000000000 +0000
3599 +++ linux-3.9.4-vs2.3.6.3/fs/hostfs/hostfs.h    2013-05-31 14:47:11.000000000 +0000
3600 @@ -42,6 +42,7 @@ struct hostfs_iattr {
3601         unsigned short  ia_mode;
3602         uid_t           ia_uid;
3603         gid_t           ia_gid;
3604 +       tag_t           ia_tag;
3605         loff_t          ia_size;
3606         struct timespec ia_atime;
3607         struct timespec ia_mtime;
3608 diff -NurpP --minimal linux-3.9.4/fs/inode.c linux-3.9.4-vs2.3.6.3/fs/inode.c
3609 --- linux-3.9.4/fs/inode.c      2013-05-31 13:45:24.000000000 +0000
3610 +++ linux-3.9.4-vs2.3.6.3/fs/inode.c    2013-06-03 18:32:17.000000000 +0000
3611 @@ -17,6 +17,7 @@
3612  #include <linux/prefetch.h>
3613  #include <linux/buffer_head.h> /* for inode_has_buffers */
3614  #include <linux/ratelimit.h>
3615 +#include <linux/vs_tag.h>
3616  #include "internal.h"
3617  
3618  /*
3619 @@ -128,6 +129,8 @@ int inode_init_always(struct super_block
3620         struct address_space *const mapping = &inode->i_data;
3621  
3622         inode->i_sb = sb;
3623 +
3624 +       /* essential because of inode slab reuse */
3625         inode->i_blkbits = sb->s_blocksize_bits;
3626         inode->i_flags = 0;
3627         atomic_set(&inode->i_count, 1);
3628 @@ -137,6 +140,7 @@ int inode_init_always(struct super_block
3629         inode->i_opflags = 0;
3630         i_uid_write(inode, 0);
3631         i_gid_write(inode, 0);
3632 +       i_tag_write(inode, 0);
3633         atomic_set(&inode->i_writecount, 0);
3634         inode->i_size = 0;
3635         inode->i_blocks = 0;
3636 @@ -149,6 +153,7 @@ int inode_init_always(struct super_block
3637         inode->i_bdev = NULL;
3638         inode->i_cdev = NULL;
3639         inode->i_rdev = 0;
3640 +       inode->i_mdev = 0;
3641         inode->dirtied_when = 0;
3642  
3643         if (security_inode_alloc(inode))
3644 @@ -483,6 +488,8 @@ void __insert_inode_hash(struct inode *i
3645  }
3646  EXPORT_SYMBOL(__insert_inode_hash);
3647  
3648 +EXPORT_SYMBOL_GPL(__iget);
3649 +
3650  /**
3651   *     __remove_inode_hash - remove an inode from the hash
3652   *     @inode: inode to unhash
3653 @@ -1799,9 +1806,11 @@ void init_special_inode(struct inode *in
3654         if (S_ISCHR(mode)) {
3655                 inode->i_fop = &def_chr_fops;
3656                 inode->i_rdev = rdev;
3657 +               inode->i_mdev = rdev;
3658         } else if (S_ISBLK(mode)) {
3659                 inode->i_fop = &def_blk_fops;
3660                 inode->i_rdev = rdev;
3661 +               inode->i_mdev = rdev;
3662         } else if (S_ISFIFO(mode))
3663                 inode->i_fop = &def_fifo_fops;
3664         else if (S_ISSOCK(mode))
3665 @@ -1830,6 +1839,7 @@ void inode_init_owner(struct inode *inod
3666         } else
3667                 inode->i_gid = current_fsgid();
3668         inode->i_mode = mode;
3669 +       i_tag_write(inode, dx_current_fstag(inode->i_sb));
3670  }
3671  EXPORT_SYMBOL(inode_init_owner);
3672  
3673 diff -NurpP --minimal linux-3.9.4/fs/ioctl.c linux-3.9.4-vs2.3.6.3/fs/ioctl.c
3674 --- linux-3.9.4/fs/ioctl.c      2013-05-31 13:45:24.000000000 +0000
3675 +++ linux-3.9.4-vs2.3.6.3/fs/ioctl.c    2013-05-31 14:47:11.000000000 +0000
3676 @@ -15,6 +15,9 @@
3677  #include <linux/writeback.h>
3678  #include <linux/buffer_head.h>
3679  #include <linux/falloc.h>
3680 +#include <linux/proc_fs.h>
3681 +#include <linux/vserver/inode.h>
3682 +#include <linux/vs_tag.h>
3683  
3684  #include <asm/ioctls.h>
3685  
3686 diff -NurpP --minimal linux-3.9.4/fs/ioprio.c linux-3.9.4-vs2.3.6.3/fs/ioprio.c
3687 --- linux-3.9.4/fs/ioprio.c     2012-12-11 03:30:57.000000000 +0000
3688 +++ linux-3.9.4-vs2.3.6.3/fs/ioprio.c   2013-05-31 14:47:11.000000000 +0000
3689 @@ -28,6 +28,7 @@
3690  #include <linux/syscalls.h>
3691  #include <linux/security.h>
3692  #include <linux/pid_namespace.h>
3693 +#include <linux/vs_base.h>
3694  
3695  int set_task_ioprio(struct task_struct *task, int ioprio)
3696  {
3697 @@ -105,6 +106,8 @@ SYSCALL_DEFINE3(ioprio_set, int, which,
3698                         else
3699                                 pgrp = find_vpid(who);
3700                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3701 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3702 +                                       continue;
3703                                 ret = set_task_ioprio(p, ioprio);
3704                                 if (ret)
3705                                         break;
3706 @@ -198,6 +201,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which,
3707                         else
3708                                 pgrp = find_vpid(who);
3709                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3710 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3711 +                                       continue;
3712                                 tmpio = get_task_ioprio(p);
3713                                 if (tmpio < 0)
3714                                         continue;
3715 diff -NurpP --minimal linux-3.9.4/fs/jfs/file.c linux-3.9.4-vs2.3.6.3/fs/jfs/file.c
3716 --- linux-3.9.4/fs/jfs/file.c   2013-02-19 13:58:48.000000000 +0000
3717 +++ linux-3.9.4-vs2.3.6.3/fs/jfs/file.c 2013-05-31 14:47:11.000000000 +0000
3718 @@ -109,7 +109,8 @@ int jfs_setattr(struct dentry *dentry, s
3719         if (is_quota_modification(inode, iattr))
3720                 dquot_initialize(inode);
3721         if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
3722 -           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
3723 +           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid)) ||
3724 +           (iattr->ia_valid & ATTR_TAG && !tag_eq(iattr->ia_tag, inode->i_tag))) {
3725                 rc = dquot_transfer(inode, iattr);
3726                 if (rc)
3727                         return rc;
3728 @@ -144,6 +145,7 @@ const struct inode_operations jfs_file_i
3729  #ifdef CONFIG_JFS_POSIX_ACL
3730         .get_acl        = jfs_get_acl,
3731  #endif
3732 +       .sync_flags     = jfs_sync_flags,
3733  };
3734  
3735  const struct file_operations jfs_file_operations = {
3736 diff -NurpP --minimal linux-3.9.4/fs/jfs/ioctl.c linux-3.9.4-vs2.3.6.3/fs/jfs/ioctl.c
3737 --- linux-3.9.4/fs/jfs/ioctl.c  2013-05-31 13:45:24.000000000 +0000
3738 +++ linux-3.9.4-vs2.3.6.3/fs/jfs/ioctl.c        2013-05-31 14:47:11.000000000 +0000
3739 @@ -12,6 +12,7 @@
3740  #include <linux/time.h>
3741  #include <linux/sched.h>
3742  #include <linux/blkdev.h>
3743 +#include <linux/mount.h>
3744  #include <asm/current.h>
3745  #include <asm/uaccess.h>
3746  
3747 @@ -56,6 +57,16 @@ static long jfs_map_ext2(unsigned long f
3748  }
3749  
3750  
3751 +int jfs_sync_flags(struct inode *inode, int flags, int vflags)
3752 +{
3753 +       inode->i_flags = flags;
3754 +       inode->i_vflags = vflags;
3755 +       jfs_get_inode_flags(JFS_IP(inode));
3756 +       inode->i_ctime = CURRENT_TIME_SEC;
3757 +       mark_inode_dirty(inode);
3758 +       return 0;
3759 +}
3760 +
3761  long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3762  {
3763         struct inode *inode = file_inode(filp);
3764 @@ -89,6 +100,11 @@ long jfs_ioctl(struct file *filp, unsign
3765                 if (!S_ISDIR(inode->i_mode))
3766                         flags &= ~JFS_DIRSYNC_FL;
3767  
3768 +               if (IS_BARRIER(inode)) {
3769 +                       vxwprintk_task(1, "messing with the barrier.");
3770 +                       return -EACCES;
3771 +               }
3772 +
3773                 /* Is it quota file? Do not allow user to mess with it */
3774                 if (IS_NOQUOTA(inode)) {
3775                         err = -EPERM;
3776 @@ -106,8 +122,8 @@ long jfs_ioctl(struct file *filp, unsign
3777                  * the relevant capability.
3778                  */
3779                 if ((oldflags & JFS_IMMUTABLE_FL) ||
3780 -                       ((flags ^ oldflags) &
3781 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
3782 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
3783 +                       JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
3784                         if (!capable(CAP_LINUX_IMMUTABLE)) {
3785                                 mutex_unlock(&inode->i_mutex);
3786                                 err = -EPERM;
3787 @@ -115,7 +131,7 @@ long jfs_ioctl(struct file *filp, unsign
3788                         }
3789                 }
3790  
3791 -               flags = flags & JFS_FL_USER_MODIFIABLE;
3792 +               flags &= JFS_FL_USER_MODIFIABLE;
3793                 flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
3794                 jfs_inode->mode2 = flags;
3795  
3796 diff -NurpP --minimal linux-3.9.4/fs/jfs/jfs_dinode.h linux-3.9.4-vs2.3.6.3/fs/jfs/jfs_dinode.h
3797 --- linux-3.9.4/fs/jfs/jfs_dinode.h     2012-12-11 03:30:57.000000000 +0000
3798 +++ linux-3.9.4-vs2.3.6.3/fs/jfs/jfs_dinode.h   2013-05-31 14:47:11.000000000 +0000
3799 @@ -161,9 +161,13 @@ struct dinode {
3800  
3801  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
3802  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
3803 +#define JFS_IXUNLINK_FL                0x08000000 /* Immutable invert on unlink */
3804  
3805 -#define JFS_FL_USER_VISIBLE    0x03F80000
3806 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
3807 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
3808 +#define JFS_COW_FL             0x20000000 /* Copy on Write marker */
3809 +
3810 +#define JFS_FL_USER_VISIBLE    0x07F80000
3811 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
3812  #define JFS_FL_INHERIT         0x03C80000
3813  
3814  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
3815 diff -NurpP --minimal linux-3.9.4/fs/jfs/jfs_filsys.h linux-3.9.4-vs2.3.6.3/fs/jfs/jfs_filsys.h
3816 --- linux-3.9.4/fs/jfs/jfs_filsys.h     2012-12-11 03:30:57.000000000 +0000
3817 +++ linux-3.9.4-vs2.3.6.3/fs/jfs/jfs_filsys.h   2013-05-31 14:47:11.000000000 +0000
3818 @@ -266,6 +266,7 @@
3819  #define JFS_NAME_MAX   255
3820  #define JFS_PATH_MAX   BPSIZE
3821  
3822 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
3823  
3824  /*
3825   *     file system state (superblock state)
3826 diff -NurpP --minimal linux-3.9.4/fs/jfs/jfs_imap.c linux-3.9.4-vs2.3.6.3/fs/jfs/jfs_imap.c
3827 --- linux-3.9.4/fs/jfs/jfs_imap.c       2012-12-11 03:30:57.000000000 +0000
3828 +++ linux-3.9.4-vs2.3.6.3/fs/jfs/jfs_imap.c     2013-06-03 19:53:45.000000000 +0000
3829 @@ -46,6 +46,7 @@
3830  #include <linux/pagemap.h>
3831  #include <linux/quotaops.h>
3832  #include <linux/slab.h>
3833 +#include <linux/vs_tag.h>
3834  
3835  #include "jfs_incore.h"
3836  #include "jfs_inode.h"
3837 @@ -3058,6 +3059,8 @@ static int copy_from_dinode(struct dinod
3838  {
3839         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
3840         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
3841 +       kuid_t kuid;
3842 +       kgid_t kgid;
3843  
3844         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
3845         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
3846 @@ -3078,14 +3081,18 @@ static int copy_from_dinode(struct dinod
3847         }
3848         set_nlink(ip, le32_to_cpu(dip->di_nlink));
3849  
3850 -       jfs_ip->saved_uid = make_kuid(&init_user_ns, le32_to_cpu(dip->di_uid));
3851 +       kuid = make_kuid(&init_user_ns, le32_to_cpu(dip->di_uid));
3852 +       kgid = make_kgid(&init_user_ns, le32_to_cpu(dip->di_gid));
3853 +       ip->i_tag = INOTAG_KTAG(DX_TAG(ip), kuid, kgid, GLOBAL_ROOT_TAG);
3854 +
3855 +       jfs_ip->saved_uid = INOTAG_KUID(DX_TAG(ip), kuid, kgid);
3856         if (!uid_valid(sbi->uid))
3857                 ip->i_uid = jfs_ip->saved_uid;
3858         else {
3859                 ip->i_uid = sbi->uid;
3860         }
3861  
3862 -       jfs_ip->saved_gid = make_kgid(&init_user_ns, le32_to_cpu(dip->di_gid));
3863 +       jfs_ip->saved_gid = INOTAG_KGID(DX_TAG(ip), kuid, kgid);
3864         if (!gid_valid(sbi->gid))
3865                 ip->i_gid = jfs_ip->saved_gid;
3866         else {
3867 @@ -3150,16 +3157,14 @@ static void copy_to_dinode(struct dinode
3868         dip->di_size = cpu_to_le64(ip->i_size);
3869         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
3870         dip->di_nlink = cpu_to_le32(ip->i_nlink);
3871 -       if (!uid_valid(sbi->uid))
3872 -               dip->di_uid = cpu_to_le32(i_uid_read(ip));
3873 -       else
3874 -               dip->di_uid =cpu_to_le32(from_kuid(&init_user_ns,
3875 -                                                  jfs_ip->saved_uid));
3876 -       if (!gid_valid(sbi->gid))
3877 -               dip->di_gid = cpu_to_le32(i_gid_read(ip));
3878 -       else
3879 -               dip->di_gid = cpu_to_le32(from_kgid(&init_user_ns,
3880 -                                                   jfs_ip->saved_gid));
3881 +       dip->di_uid = cpu_to_le32(from_kuid(&init_user_ns,
3882 +               TAGINO_KUID(DX_TAG(ip),
3883 +               !uid_valid(sbi->uid) ? ip->i_uid : jfs_ip->saved_uid,
3884 +               ip->i_tag)));
3885 +       dip->di_gid = cpu_to_le32(from_kgid(&init_user_ns,
3886 +               TAGINO_KGID(DX_TAG(ip),
3887 +               !gid_valid(sbi->gid) ? ip->i_gid : jfs_ip->saved_gid,
3888 +               ip->i_tag)));
3889         jfs_get_inode_flags(jfs_ip);
3890         /*
3891          * mode2 is only needed for storing the higher order bits.
3892 diff -NurpP --minimal linux-3.9.4/fs/jfs/jfs_inode.c linux-3.9.4-vs2.3.6.3/fs/jfs/jfs_inode.c
3893 --- linux-3.9.4/fs/jfs/jfs_inode.c      2012-12-11 03:30:57.000000000 +0000
3894 +++ linux-3.9.4-vs2.3.6.3/fs/jfs/jfs_inode.c    2013-05-31 14:47:11.000000000 +0000
3895 @@ -18,6 +18,7 @@
3896  
3897  #include <linux/fs.h>
3898  #include <linux/quotaops.h>
3899 +#include <linux/vs_tag.h>
3900  #include "jfs_incore.h"
3901  #include "jfs_inode.h"
3902  #include "jfs_filsys.h"
3903 @@ -30,29 +31,46 @@ void jfs_set_inode_flags(struct inode *i
3904  {
3905         unsigned int flags = JFS_IP(inode)->mode2;
3906  
3907 -       inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
3908 -               S_NOATIME | S_DIRSYNC | S_SYNC);
3909 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3910 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3911  
3912         if (flags & JFS_IMMUTABLE_FL)
3913                 inode->i_flags |= S_IMMUTABLE;
3914 +       if (flags & JFS_IXUNLINK_FL)
3915 +               inode->i_flags |= S_IXUNLINK;
3916 +
3917 +       if (flags & JFS_SYNC_FL)
3918 +               inode->i_flags |= S_SYNC;
3919         if (flags & JFS_APPEND_FL)
3920                 inode->i_flags |= S_APPEND;
3921         if (flags & JFS_NOATIME_FL)
3922                 inode->i_flags |= S_NOATIME;
3923         if (flags & JFS_DIRSYNC_FL)
3924                 inode->i_flags |= S_DIRSYNC;
3925 -       if (flags & JFS_SYNC_FL)
3926 -               inode->i_flags |= S_SYNC;
3927 +
3928 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3929 +
3930 +       if (flags & JFS_BARRIER_FL)
3931 +               inode->i_vflags |= V_BARRIER;
3932 +       if (flags & JFS_COW_FL)
3933 +               inode->i_vflags |= V_COW;
3934  }
3935  
3936  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
3937  {
3938         unsigned int flags = jfs_ip->vfs_inode.i_flags;
3939 +       unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
3940 +
3941 +       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
3942 +                          JFS_APPEND_FL | JFS_NOATIME_FL |
3943 +                          JFS_DIRSYNC_FL | JFS_SYNC_FL |
3944 +                          JFS_BARRIER_FL | JFS_COW_FL);
3945  
3946 -       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
3947 -                          JFS_DIRSYNC_FL | JFS_SYNC_FL);
3948         if (flags & S_IMMUTABLE)
3949                 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
3950 +       if (flags & S_IXUNLINK)
3951 +               jfs_ip->mode2 |= JFS_IXUNLINK_FL;
3952 +
3953         if (flags & S_APPEND)
3954                 jfs_ip->mode2 |= JFS_APPEND_FL;
3955         if (flags & S_NOATIME)
3956 @@ -61,6 +79,11 @@ void jfs_get_inode_flags(struct jfs_inod
3957                 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
3958         if (flags & S_SYNC)
3959                 jfs_ip->mode2 |= JFS_SYNC_FL;
3960 +
3961 +       if (vflags & V_BARRIER)
3962 +               jfs_ip->mode2 |= JFS_BARRIER_FL;
3963 +       if (vflags & V_COW)
3964 +               jfs_ip->mode2 |= JFS_COW_FL;
3965  }
3966  
3967  /*
3968 diff -NurpP --minimal linux-3.9.4/fs/jfs/jfs_inode.h linux-3.9.4-vs2.3.6.3/fs/jfs/jfs_inode.h
3969 --- linux-3.9.4/fs/jfs/jfs_inode.h      2012-12-11 03:30:57.000000000 +0000
3970 +++ linux-3.9.4-vs2.3.6.3/fs/jfs/jfs_inode.h    2013-05-31 14:47:11.000000000 +0000
3971 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
3972  extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
3973         int fh_len, int fh_type);
3974  extern void jfs_set_inode_flags(struct inode *);
3975 +extern int jfs_sync_flags(struct inode *, int, int);
3976  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
3977  extern int jfs_setattr(struct dentry *, struct iattr *);
3978  
3979 diff -NurpP --minimal linux-3.9.4/fs/jfs/namei.c linux-3.9.4-vs2.3.6.3/fs/jfs/namei.c
3980 --- linux-3.9.4/fs/jfs/namei.c  2012-12-11 03:30:57.000000000 +0000
3981 +++ linux-3.9.4-vs2.3.6.3/fs/jfs/namei.c        2013-05-31 14:47:11.000000000 +0000
3982 @@ -22,6 +22,7 @@
3983  #include <linux/ctype.h>
3984  #include <linux/quotaops.h>
3985  #include <linux/exportfs.h>
3986 +#include <linux/vs_tag.h>
3987  #include "jfs_incore.h"
3988  #include "jfs_superblock.h"
3989  #include "jfs_inode.h"
3990 @@ -1461,6 +1462,7 @@ static struct dentry *jfs_lookup(struct
3991                         jfs_err("jfs_lookup: iget failed on inum %d", (uint)inum);
3992         }
3993  
3994 +       dx_propagate_tag(nd, ip);
3995         return d_splice_alias(ip, dentry);
3996  }
3997  
3998 @@ -1525,6 +1527,7 @@ const struct inode_operations jfs_dir_in
3999  #ifdef CONFIG_JFS_POSIX_ACL
4000         .get_acl        = jfs_get_acl,
4001  #endif
4002 +       .sync_flags     = jfs_sync_flags,
4003  };
4004  
4005  const struct file_operations jfs_dir_operations = {
4006 diff -NurpP --minimal linux-3.9.4/fs/jfs/super.c linux-3.9.4-vs2.3.6.3/fs/jfs/super.c
4007 --- linux-3.9.4/fs/jfs/super.c  2013-05-31 13:45:24.000000000 +0000
4008 +++ linux-3.9.4-vs2.3.6.3/fs/jfs/super.c        2013-05-31 14:47:11.000000000 +0000
4009 @@ -199,7 +199,8 @@ enum {
4010         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
4011         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
4012         Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
4013 -       Opt_discard, Opt_nodiscard, Opt_discard_minblk
4014 +       Opt_discard, Opt_nodiscard, Opt_discard_minblk,
4015 +       Opt_tag, Opt_notag, Opt_tagid
4016  };
4017  
4018  static const match_table_t tokens = {
4019 @@ -209,6 +210,10 @@ static const match_table_t tokens = {
4020         {Opt_resize, "resize=%u"},
4021         {Opt_resize_nosize, "resize"},
4022         {Opt_errors, "errors=%s"},
4023 +       {Opt_tag, "tag"},
4024 +       {Opt_notag, "notag"},
4025 +       {Opt_tagid, "tagid=%u"},
4026 +       {Opt_tag, "tagxid"},
4027         {Opt_ignore, "noquota"},
4028         {Opt_ignore, "quota"},
4029         {Opt_usrquota, "usrquota"},
4030 @@ -385,7 +390,20 @@ static int parse_options(char *options,
4031                         }
4032                         break;
4033                 }
4034 -
4035 +#ifndef CONFIG_TAGGING_NONE
4036 +               case Opt_tag:
4037 +                       *flag |= JFS_TAGGED;
4038 +                       break;
4039 +               case Opt_notag:
4040 +                       *flag &= JFS_TAGGED;
4041 +                       break;
4042 +#endif
4043 +#ifdef CONFIG_PROPAGATE
4044 +               case Opt_tagid:
4045 +                       /* use args[0] */
4046 +                       *flag |= JFS_TAGGED;
4047 +                       break;
4048 +#endif
4049                 default:
4050                         printk("jfs: Unrecognized mount option \"%s\" "
4051                                         " or missing value\n", p);
4052 @@ -417,6 +435,12 @@ static int jfs_remount(struct super_bloc
4053                 return -EINVAL;
4054         }
4055  
4056 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
4057 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
4058 +                       sb->s_id);
4059 +               return -EINVAL;
4060 +       }
4061 +
4062         if (newLVSize) {
4063                 if (sb->s_flags & MS_RDONLY) {
4064                         pr_err("JFS: resize requires volume" \
4065 @@ -502,6 +526,9 @@ static int jfs_fill_super(struct super_b
4066  #ifdef CONFIG_JFS_POSIX_ACL
4067         sb->s_flags |= MS_POSIXACL;
4068  #endif
4069 +       /* map mount option tagxid */
4070 +       if (sbi->flag & JFS_TAGGED)
4071 +               sb->s_flags |= MS_TAGGED;
4072  
4073         if (newLVSize) {
4074                 pr_err("resize option for remount only\n");
4075 diff -NurpP --minimal linux-3.9.4/fs/libfs.c linux-3.9.4-vs2.3.6.3/fs/libfs.c
4076 --- linux-3.9.4/fs/libfs.c      2013-02-19 13:58:48.000000000 +0000
4077 +++ linux-3.9.4-vs2.3.6.3/fs/libfs.c    2013-05-31 14:47:11.000000000 +0000
4078 @@ -135,7 +135,8 @@ static inline unsigned char dt_type(stru
4079   * both impossible due to the lock on directory.
4080   */
4081  
4082 -int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
4083 +static inline int do_dcache_readdir_filter(struct file *filp,
4084 +       void *dirent, filldir_t filldir, int (*filter)(struct dentry *dentry))
4085  {
4086         struct dentry *dentry = filp->f_path.dentry;
4087         struct dentry *cursor = filp->private_data;
4088 @@ -166,6 +167,8 @@ int dcache_readdir(struct file * filp, v
4089                         for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
4090                                 struct dentry *next;
4091                                 next = list_entry(p, struct dentry, d_u.d_child);
4092 +                               if (filter && !filter(next))
4093 +                                       continue;
4094                                 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
4095                                 if (!simple_positive(next)) {
4096                                         spin_unlock(&next->d_lock);
4097 @@ -192,6 +195,17 @@ int dcache_readdir(struct file * filp, v
4098         return 0;
4099  }
4100  
4101 +int dcache_readdir(struct file *filp, void *dirent, filldir_t filldir)
4102 +{
4103 +       return do_dcache_readdir_filter(filp, dirent, filldir, NULL);
4104 +}
4105 +
4106 +int dcache_readdir_filter(struct file *filp, void *dirent, filldir_t filldir,
4107 +       int (*filter)(struct dentry *))
4108 +{
4109 +       return do_dcache_readdir_filter(filp, dirent, filldir, filter);
4110 +}
4111 +
4112  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
4113  {
4114         return -EISDIR;
4115 @@ -981,6 +995,7 @@ EXPORT_SYMBOL(dcache_dir_close);
4116  EXPORT_SYMBOL(dcache_dir_lseek);
4117  EXPORT_SYMBOL(dcache_dir_open);
4118  EXPORT_SYMBOL(dcache_readdir);
4119 +EXPORT_SYMBOL(dcache_readdir_filter);
4120  EXPORT_SYMBOL(generic_read_dir);
4121  EXPORT_SYMBOL(mount_pseudo);
4122  EXPORT_SYMBOL(simple_write_begin);
4123 diff -NurpP --minimal linux-3.9.4/fs/locks.c linux-3.9.4-vs2.3.6.3/fs/locks.c
4124 --- linux-3.9.4/fs/locks.c      2013-05-31 13:45:24.000000000 +0000
4125 +++ linux-3.9.4-vs2.3.6.3/fs/locks.c    2013-05-31 15:53:57.000000000 +0000
4126 @@ -126,6 +126,8 @@
4127  #include <linux/time.h>
4128  #include <linux/rcupdate.h>
4129  #include <linux/pid_namespace.h>
4130 +#include <linux/vs_base.h>
4131 +#include <linux/vs_limit.h>
4132  
4133  #include <asm/uaccess.h>
4134  
4135 @@ -184,11 +186,17 @@ static void locks_init_lock_heads(struct
4136  /* Allocate an empty lock structure. */
4137  struct file_lock *locks_alloc_lock(void)
4138  {
4139 -       struct file_lock *fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4140 +       struct file_lock *fl;
4141  
4142 -       if (fl)
4143 -               locks_init_lock_heads(fl);
4144 +       if (!vx_locks_avail(1))
4145 +               return NULL;
4146  
4147 +       fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4148 +
4149 +       if (fl) {
4150 +               locks_init_lock_heads(fl);
4151 +               fl->fl_xid = -1;
4152 +       }
4153         return fl;
4154  }
4155  EXPORT_SYMBOL_GPL(locks_alloc_lock);
4156 @@ -212,6 +220,7 @@ void locks_free_lock(struct file_lock *f
4157         BUG_ON(!list_empty(&fl->fl_block));
4158         BUG_ON(!list_empty(&fl->fl_link));
4159  
4160 +       vx_locks_dec(fl);
4161         locks_release_private(fl);
4162         kmem_cache_free(filelock_cache, fl);
4163  }
4164 @@ -221,6 +230,7 @@ void locks_init_lock(struct file_lock *f
4165  {
4166         memset(fl, 0, sizeof(struct file_lock));
4167         locks_init_lock_heads(fl);
4168 +       fl->fl_xid = -1;
4169  }
4170  
4171  EXPORT_SYMBOL(locks_init_lock);
4172 @@ -261,6 +271,7 @@ void locks_copy_lock(struct file_lock *n
4173         new->fl_file = fl->fl_file;
4174         new->fl_ops = fl->fl_ops;
4175         new->fl_lmops = fl->fl_lmops;
4176 +       new->fl_xid = fl->fl_xid;
4177  
4178         locks_copy_private(new, fl);
4179  }
4180 @@ -299,6 +310,11 @@ static int flock_make_lock(struct file *
4181         fl->fl_flags = FL_FLOCK;
4182         fl->fl_type = type;
4183         fl->fl_end = OFFSET_MAX;
4184 +
4185 +       vxd_assert(filp->f_xid == vx_current_xid(),
4186 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4187 +       fl->fl_xid = filp->f_xid;
4188 +       vx_locks_inc(fl);
4189         
4190         *lock = fl;
4191         return 0;
4192 @@ -438,6 +454,7 @@ static int lease_init(struct file *filp,
4193  
4194         fl->fl_owner = current->files;
4195         fl->fl_pid = current->tgid;
4196 +       fl->fl_xid = vx_current_xid();
4197  
4198         fl->fl_file = filp;
4199         fl->fl_flags = FL_LEASE;
4200 @@ -457,6 +474,11 @@ static struct file_lock *lease_alloc(str
4201         if (fl == NULL)
4202                 return ERR_PTR(error);
4203  
4204 +       fl->fl_xid = vx_current_xid();
4205 +       if (filp)
4206 +               vxd_assert(filp->f_xid == fl->fl_xid,
4207 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
4208 +       vx_locks_inc(fl);
4209         error = lease_init(filp, type, fl);
4210         if (error) {
4211                 locks_free_lock(fl);
4212 @@ -753,6 +775,7 @@ static int flock_lock_file(struct file *
4213                 lock_flocks();
4214         }
4215  
4216 +       new_fl->fl_xid = -1;
4217  find_conflict:
4218         for_each_lock(inode, before) {
4219                 struct file_lock *fl = *before;
4220 @@ -773,6 +796,7 @@ find_conflict:
4221                 goto out;
4222         locks_copy_lock(new_fl, request);
4223         locks_insert_lock(before, new_fl);
4224 +       vx_locks_inc(new_fl);
4225         new_fl = NULL;
4226         error = 0;
4227  
4228 @@ -783,7 +807,8 @@ out:
4229         return error;
4230  }
4231  
4232 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
4233 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
4234 +       struct file_lock *conflock, xid_t xid)
4235  {
4236         struct file_lock *fl;
4237         struct file_lock *new_fl = NULL;
4238 @@ -793,6 +818,8 @@ static int __posix_lock_file(struct inod
4239         struct file_lock **before;
4240         int error, added = 0;
4241  
4242 +       vxd_assert(xid == vx_current_xid(),
4243 +               "xid(%d) == current(%d)", xid, vx_current_xid());
4244         /*
4245          * We may need two file_lock structures for this operation,
4246          * so we get them in advance to avoid races.
4247 @@ -803,7 +830,11 @@ static int __posix_lock_file(struct inod
4248             (request->fl_type != F_UNLCK ||
4249              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
4250                 new_fl = locks_alloc_lock();
4251 +               new_fl->fl_xid = xid;
4252 +               vx_locks_inc(new_fl);
4253                 new_fl2 = locks_alloc_lock();
4254 +               new_fl2->fl_xid = xid;
4255 +               vx_locks_inc(new_fl2);
4256         }
4257  
4258         lock_flocks();
4259 @@ -1002,7 +1033,8 @@ static int __posix_lock_file(struct inod
4260  int posix_lock_file(struct file *filp, struct file_lock *fl,
4261                         struct file_lock *conflock)
4262  {
4263 -       return __posix_lock_file(file_inode(filp), fl, conflock);
4264 +       return __posix_lock_file(file_inode(filp),
4265 +               fl, conflock, filp->f_xid);
4266  }
4267  EXPORT_SYMBOL(posix_lock_file);
4268  
4269 @@ -1092,7 +1124,7 @@ int locks_mandatory_area(int read_write,
4270         fl.fl_end = offset + count - 1;
4271  
4272         for (;;) {
4273 -               error = __posix_lock_file(inode, &fl, NULL);
4274 +               error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
4275                 if (error != FILE_LOCK_DEFERRED)
4276                         break;
4277                 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
4278 @@ -1397,6 +1429,7 @@ int generic_add_lease(struct file *filp,
4279                 goto out;
4280  
4281         locks_insert_lock(before, lease);
4282 +       vx_locks_inc(lease);
4283         return 0;
4284  
4285  out:
4286 @@ -1836,6 +1869,11 @@ int fcntl_setlk(unsigned int fd, struct
4287         if (file_lock == NULL)
4288                 return -ENOLCK;
4289  
4290 +       vxd_assert(filp->f_xid == vx_current_xid(),
4291 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4292 +       file_lock->fl_xid = filp->f_xid;
4293 +       vx_locks_inc(file_lock);
4294 +
4295         /*
4296          * This might block, so we do it before checking the inode.
4297          */
4298 @@ -1954,6 +1992,11 @@ int fcntl_setlk64(unsigned int fd, struc
4299         if (file_lock == NULL)
4300                 return -ENOLCK;
4301  
4302 +       vxd_assert(filp->f_xid == vx_current_xid(),
4303 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4304 +       file_lock->fl_xid = filp->f_xid;
4305 +       vx_locks_inc(file_lock);
4306 +
4307         /*
4308          * This might block, so we do it before checking the inode.
4309          */
4310 @@ -2219,8 +2262,11 @@ static int locks_show(struct seq_file *f
4311  
4312         lock_get_status(f, fl, *((loff_t *)f->private), "");
4313  
4314 -       list_for_each_entry(bfl, &fl->fl_block, fl_block)
4315 +       list_for_each_entry(bfl, &fl->fl_block, fl_block) {
4316 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
4317 +                       continue;
4318                 lock_get_status(f, bfl, *((loff_t *)f->private), " ->");
4319 +       }
4320  
4321         return 0;
4322  }
4323 diff -NurpP --minimal linux-3.9.4/fs/mount.h linux-3.9.4-vs2.3.6.3/fs/mount.h
4324 --- linux-3.9.4/fs/mount.h      2013-02-19 13:58:48.000000000 +0000
4325 +++ linux-3.9.4-vs2.3.6.3/fs/mount.h    2013-05-31 14:47:11.000000000 +0000
4326 @@ -49,6 +49,7 @@ struct mount {
4327         int mnt_expiry_mark;            /* true if marked for expiry */
4328         int mnt_pinned;
4329         int mnt_ghosts;
4330 +       tag_t mnt_tag;                  /* tagging used for vfsmount */
4331  };
4332  
4333  #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
4334 diff -NurpP --minimal linux-3.9.4/fs/namei.c linux-3.9.4-vs2.3.6.3/fs/namei.c
4335 --- linux-3.9.4/fs/namei.c      2013-05-31 14:22:27.000000000 +0000
4336 +++ linux-3.9.4-vs2.3.6.3/fs/namei.c    2013-06-01 09:00:16.000000000 +0000
4337 @@ -34,6 +34,14 @@
4338  #include <linux/device_cgroup.h>
4339  #include <linux/fs_struct.h>
4340  #include <linux/posix_acl.h>
4341 +#include <linux/proc_fs.h>
4342 +#include <linux/vserver/inode.h>
4343 +#include <linux/vs_base.h>
4344 +#include <linux/vs_tag.h>
4345 +#include <linux/vs_cowbl.h>
4346 +#include <linux/vs_device.h>
4347 +#include <linux/vs_context.h>
4348 +#include <linux/pid_namespace.h>
4349  #include <asm/uaccess.h>
4350  
4351  #include "internal.h"
4352 @@ -266,6 +274,89 @@ static int check_acl(struct inode *inode
4353         return -EAGAIN;
4354  }
4355  
4356 +static inline int dx_barrier(const struct inode *inode)
4357 +{
4358 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
4359 +               vxwprintk_task(1, "did hit the barrier.");
4360 +               return 1;
4361 +       }
4362 +       return 0;
4363 +}
4364 +
4365 +static int __dx_permission(const struct inode *inode, int mask)
4366 +{
4367 +       if (dx_barrier(inode))
4368 +               return -EACCES;
4369 +
4370 +       if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
4371 +               /* devpts is xid tagged */
4372 +               if (S_ISDIR(inode->i_mode) ||
4373 +                   vx_check((xid_t)i_tag_read(inode), VS_IDENT | VS_WATCH_P))
4374 +                       return 0;
4375 +
4376 +               /* just pretend we didn't find anything */
4377 +               return -ENOENT;
4378 +       }
4379 +       else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
4380 +               struct proc_dir_entry *de = PDE(inode);
4381 +
4382 +               if (de && !vx_hide_check(0, de->vx_flags))
4383 +                       goto out;
4384 +
4385 +               if ((mask & (MAY_WRITE | MAY_APPEND))) {
4386 +                       struct pid *pid;
4387 +                       struct task_struct *tsk;
4388 +
4389 +                       if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
4390 +                           vx_flags(VXF_STATE_SETUP, 0))
4391 +                               return 0;
4392 +
4393 +                       pid = PROC_I(inode)->pid;
4394 +                       if (!pid)
4395 +                               goto out;
4396 +
4397 +                       rcu_read_lock();
4398 +                       tsk = pid_task(pid, PIDTYPE_PID);
4399 +                       vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
4400 +                                 tsk, (tsk ? vx_task_xid(tsk) : 0));
4401 +                       if (tsk &&
4402 +                               vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P)) {
4403 +                               rcu_read_unlock();
4404 +                               return 0;
4405 +                       }
4406 +                       rcu_read_unlock();
4407 +               }
4408 +               else {
4409 +                       /* FIXME: Should we block some entries here? */
4410 +                       return 0;
4411 +               }
4412 +       }
4413 +       else {
4414 +               if (dx_notagcheck(inode->i_sb) ||
4415 +                   dx_check((xid_t)i_tag_read(inode),
4416 +                       DX_HOSTID | DX_ADMIN | DX_WATCH | DX_IDENT))
4417 +                       return 0;
4418 +       }
4419 +
4420 +out:
4421 +       return -EACCES;
4422 +}
4423 +
4424 +int dx_permission(const struct inode *inode, int mask)
4425 +{
4426 +       int ret = __dx_permission(inode, mask);
4427 +       if (unlikely(ret)) {
4428 +#ifndef        CONFIG_VSERVER_WARN_DEVPTS
4429 +               if (inode->i_sb->s_magic != DEVPTS_SUPER_MAGIC)
4430 +#endif
4431 +                   vxwprintk_task(1,
4432 +                       "denied [0x%x] access to inode %s:%p[#%d,%lu]",
4433 +                       mask, inode->i_sb->s_id, inode,
4434 +                       i_tag_read(inode), inode->i_ino);
4435 +       }
4436 +       return ret;
4437 +}
4438 +
4439  /*
4440   * This does the basic permission checking
4441   */
4442 @@ -388,10 +479,14 @@ int __inode_permission(struct inode *ino
4443                 /*
4444                  * Nobody gets write access to an immutable file.
4445                  */
4446 -               if (IS_IMMUTABLE(inode))
4447 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
4448                         return -EACCES;
4449         }
4450  
4451 +       retval = dx_permission(inode, mask);
4452 +       if (retval)
4453 +               return retval;
4454 +
4455         retval = do_inode_permission(inode, mask);
4456         if (retval)
4457                 return retval;
4458 @@ -1238,7 +1333,8 @@ static void follow_dotdot(struct nameida
4459  
4460                 if (nd->path.dentry == nd->root.dentry &&
4461                     nd->path.mnt == nd->root.mnt) {
4462 -                       break;
4463 +                       /* for sane '/' avoid follow_mount() */
4464 +                       return;
4465                 }
4466                 if (nd->path.dentry != nd->path.mnt->mnt_root) {
4467                         /* rare case of legitimate dget_parent()... */
4468 @@ -1383,6 +1479,9 @@ static int lookup_fast(struct nameidata
4469                                 goto unlazy;
4470                         }
4471                 }
4472 +
4473 +               /* FIXME: check dx permission */
4474 +
4475                 path->mnt = mnt;
4476                 path->dentry = dentry;
4477                 if (unlikely(!__follow_mount_rcu(nd, path, inode)))
4478 @@ -1413,6 +1512,8 @@ unlazy:
4479                 }
4480         }
4481  
4482 +       /* FIXME: check dx permission */
4483 +
4484         path->mnt = mnt;
4485         path->dentry = dentry;
4486         err = follow_managed(path, nd->flags);
4487 @@ -2237,7 +2338,7 @@ static int may_delete(struct inode *dir,
4488         if (IS_APPEND(dir))
4489                 return -EPERM;
4490         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
4491 -           IS_IMMUTABLE(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4492 +               IS_IXORUNLINK(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4493                 return -EPERM;
4494         if (isdir) {
4495                 if (!S_ISDIR(victim->d_inode->i_mode))
4496 @@ -2316,19 +2417,25 @@ int vfs_create(struct inode *dir, struct
4497                 bool want_excl)
4498  {
4499         int error = may_create(dir, dentry);
4500 -       if (error)
4501 +       if (error) {
4502 +               vxdprintk(VXD_CBIT(misc, 3), "may_create failed with %d", error);
4503                 return error;
4504 +       }
4505  
4506         if (!dir->i_op->create)
4507                 return -EACCES; /* shouldn't it be ENOSYS? */
4508         mode &= S_IALLUGO;
4509         mode |= S_IFREG;
4510         error = security_inode_create(dir, dentry, mode);
4511 -       if (error)
4512 +       if (error) {
4513 +               vxdprintk(VXD_CBIT(misc, 3), "security_inode_create failed with %d", error);
4514                 return error;
4515 +       }
4516         error = dir->i_op->create(dir, dentry, mode, want_excl);
4517         if (!error)
4518                 fsnotify_create(dir, dentry);
4519 +       else
4520 +               vxdprintk(VXD_CBIT(misc, 3), "i_op->create failed with %d", error);
4521         return error;
4522  }
4523  
4524 @@ -2363,6 +2470,15 @@ static int may_open(struct path *path, i
4525                 break;
4526         }
4527  
4528 +#ifdef CONFIG_VSERVER_COWBL
4529 +       if (IS_COW(inode) &&
4530 +               ((flag & O_ACCMODE) != O_RDONLY)) {
4531 +               if (IS_COW_LINK(inode))
4532 +                       return -EMLINK;
4533 +               inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
4534 +               mark_inode_dirty(inode);
4535 +       }
4536 +#endif
4537         error = inode_permission(inode, acc_mode);
4538         if (error)
4539                 return error;
4540 @@ -2865,6 +2981,16 @@ finish_open:
4541         }
4542  finish_open_created:
4543         error = may_open(&nd->path, acc_mode, open_flag);
4544 +#ifdef CONFIG_VSERVER_COWBL
4545 +       if (error == -EMLINK) {
4546 +               struct dentry *dentry;
4547 +               dentry = cow_break_link(name->name);
4548 +               if (IS_ERR(dentry))
4549 +                       error = PTR_ERR(dentry);
4550 +               else
4551 +                       dput(dentry);
4552 +       }
4553 +#endif
4554         if (error)
4555                 goto out;
4556         file->f_path.mnt = nd->path.mnt;
4557 @@ -2929,6 +3055,7 @@ static struct file *path_openat(int dfd,
4558         int opened = 0;
4559         int error;
4560  
4561 +restart:
4562         file = get_empty_filp();
4563         if (IS_ERR(file))
4564                 return file;
4565 @@ -2965,6 +3092,16 @@ static struct file *path_openat(int dfd,
4566                 error = do_last(nd, &path, file, op, &opened, pathname);
4567                 put_link(nd, &link, cookie);
4568         }
4569 +
4570 +#ifdef CONFIG_VSERVER_COWBL
4571 +       if (error == -EMLINK) {
4572 +               if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4573 +                       path_put(&nd->root);
4574 +               if (base)
4575 +                       fput(base);
4576 +               goto restart;
4577 +       }
4578 +#endif
4579  out:
4580         if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4581                 path_put(&nd->root);
4582 @@ -3079,6 +3216,11 @@ struct dentry *kern_path_create(int dfd,
4583                 goto fail;
4584         }
4585         *path = nd.path;
4586 +       vxdprintk(VXD_CBIT(misc, 3), "kern_path_create path.dentry = %p (%.*s), dentry = %p (%.*s), d_inode = %p",
4587 +               path->dentry, path->dentry->d_name.len,
4588 +               path->dentry->d_name.name, dentry,
4589 +               dentry->d_name.len, dentry->d_name.name,
4590 +               path->dentry->d_inode);
4591         return dentry;
4592  fail:
4593         dput(dentry);
4594 @@ -3573,7 +3715,7 @@ int vfs_link(struct dentry *old_dentry,
4595         /*
4596          * A link to an append-only or immutable file cannot be created.
4597          */
4598 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
4599 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
4600                 return -EPERM;
4601         if (!dir->i_op->link)
4602                 return -EPERM;
4603 @@ -3976,6 +4118,286 @@ int vfs_follow_link(struct nameidata *nd
4604         return __vfs_follow_link(nd, link);
4605  }
4606  
4607 +
4608 +#ifdef CONFIG_VSERVER_COWBL
4609 +
4610 +static inline
4611 +long do_cow_splice(struct file *in, struct file *out, size_t len)
4612 +{
4613 +       loff_t ppos = 0;
4614 +
4615 +       return do_splice_direct(in, &ppos, out, len, 0);
4616 +}
4617 +
4618 +struct dentry *cow_break_link(const char *pathname)
4619 +{
4620 +       int ret, mode, pathlen, redo = 0, drop = 1;
4621 +       struct nameidata old_nd, dir_nd;
4622 +       struct path dir_path, *old_path, *new_path;
4623 +       struct dentry *dir, *old_dentry, *new_dentry = NULL;
4624 +       struct file *old_file;
4625 +       struct file *new_file;
4626 +       char *to, *path, pad='\251';
4627 +       loff_t size;
4628 +
4629 +       vxdprintk(VXD_CBIT(misc, 1),
4630 +               "cow_break_link(" VS_Q("%s") ")", pathname);
4631 +
4632 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
4633 +       ret = -ENOMEM;
4634 +       if (!path)
4635 +               goto out;
4636 +
4637 +       /* old_nd.path will have refs to dentry and mnt */
4638 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4639 +       vxdprintk(VXD_CBIT(misc, 2),
4640 +               "do_path_lookup(old): %d", ret);
4641 +       if (ret < 0)
4642 +               goto out_free_path;
4643 +
4644 +       /* dentry/mnt refs handed over to old_path */
4645 +       old_path = &old_nd.path;
4646 +       /* no explicit reference for old_dentry here */
4647 +       old_dentry = old_path->dentry;
4648 +
4649 +       mode = old_dentry->d_inode->i_mode;
4650 +       to = d_path(old_path, path, PATH_MAX-2);
4651 +       pathlen = strlen(to);
4652 +       vxdprintk(VXD_CBIT(misc, 2),
4653 +               "old path " VS_Q("%s") " [%p:" VS_Q("%.*s") ":%d]", to,
4654 +               old_dentry,
4655 +               old_dentry->d_name.len, old_dentry->d_name.name,
4656 +               old_dentry->d_name.len);
4657 +
4658 +       to[pathlen + 1] = 0;
4659 +retry:
4660 +       new_dentry = NULL;
4661 +       to[pathlen] = pad--;
4662 +       ret = -ELOOP;
4663 +       if (pad <= '\240')
4664 +               goto out_rel_old;
4665 +
4666 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy " VS_Q("%s"), to);
4667 +
4668 +       /* dir_nd.path will have refs to dentry and mnt */
4669 +       ret = do_path_lookup(AT_FDCWD, to,
4670 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
4671 +       vxdprintk(VXD_CBIT(misc, 2), "do_path_lookup(new): %d", ret);
4672 +       if (ret < 0)
4673 +               goto retry;
4674 +
4675 +       /* this puppy downs the dir inode mutex if successful.
4676 +          dir_path will hold refs to dentry and mnt and
4677 +          we'll have write access to the mnt */
4678 +       new_dentry = kern_path_create(AT_FDCWD, to, &dir_path, 0);
4679 +       if (!new_dentry || IS_ERR(new_dentry)) {
4680 +               path_put(&dir_nd.path);
4681 +               vxdprintk(VXD_CBIT(misc, 2),
4682 +                       "kern_path_create(new) failed with %ld",
4683 +                       PTR_ERR(new_dentry));
4684 +               goto retry;
4685 +       }
4686 +       vxdprintk(VXD_CBIT(misc, 2),
4687 +               "kern_path_create(new): %p [" VS_Q("%.*s") ":%d]",
4688 +               new_dentry,
4689 +               new_dentry->d_name.len, new_dentry->d_name.name,
4690 +               new_dentry->d_name.len);
4691 +
4692 +       /* take a reference on new_dentry */
4693 +       dget(new_dentry);
4694 +
4695 +       /* dentry/mnt refs handed over to new_path */
4696 +       new_path = &dir_path;
4697 +
4698 +       /* dentry for old/new dir */
4699 +       dir = dir_nd.path.dentry;
4700 +
4701 +       /* give up reference on dir */
4702 +       dput(new_path->dentry);
4703 +
4704 +       /* new_dentry already has a reference */
4705 +       new_path->dentry = new_dentry;
4706 +
4707 +       ret = vfs_create(dir->d_inode, new_dentry, mode, 1);
4708 +       vxdprintk(VXD_CBIT(misc, 2),
4709 +               "vfs_create(new): %d", ret);
4710 +       if (ret == -EEXIST) {
4711 +               path_put(&dir_nd.path);
4712 +               mutex_unlock(&dir->d_inode->i_mutex);
4713 +               mnt_drop_write(new_path->mnt);
4714 +               path_put(new_path);
4715 +               new_dentry = NULL;
4716 +               goto retry;
4717 +       }
4718 +       else if (ret < 0)
4719 +               goto out_unlock_new;
4720 +
4721 +       /* drop out early, ret passes ENOENT */
4722 +       ret = -ENOENT;
4723 +       if ((redo = d_unhashed(old_dentry)))
4724 +               goto out_unlock_new;
4725 +
4726 +       /* doesn't change refs for old_path */
4727 +       old_file = dentry_open(old_path, O_RDONLY, current_cred());
4728 +       vxdprintk(VXD_CBIT(misc, 2),
4729 +               "dentry_open(old): %p", old_file);
4730 +       if (IS_ERR(old_file)) {
4731 +               ret = PTR_ERR(old_file);
4732 +               goto out_unlock_new;
4733 +       }
4734 +
4735 +       /* doesn't change refs for new_path */
4736 +       new_file = dentry_open(new_path, O_WRONLY, current_cred());
4737 +       vxdprintk(VXD_CBIT(misc, 2),
4738 +               "dentry_open(new): %p", new_file);
4739 +       if (IS_ERR(new_file)) {
4740 +               ret = PTR_ERR(new_file);
4741 +               goto out_fput_old;
4742 +       }
4743 +
4744 +       /* unlock the inode mutex from kern_path_create() */
4745 +       mutex_unlock(&dir->d_inode->i_mutex);
4746 +
4747 +       /* drop write access to mnt */
4748 +       mnt_drop_write(new_path->mnt);
4749 +
4750 +       drop = 0;
4751 +
4752 +       size = i_size_read(old_file->f_dentry->d_inode);
4753 +       ret = do_cow_splice(old_file, new_file, size);
4754 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
4755 +       if (ret < 0) {
4756 +               goto out_fput_both;
4757 +       } else if (ret < size) {
4758 +               ret = -ENOSPC;
4759 +               goto out_fput_both;
4760 +       } else {
4761 +               struct inode *old_inode = old_dentry->d_inode;
4762 +               struct inode *new_inode = new_dentry->d_inode;
4763 +               struct iattr attr = {
4764 +                       .ia_uid = old_inode->i_uid,
4765 +                       .ia_gid = old_inode->i_gid,
4766 +                       .ia_valid = ATTR_UID | ATTR_GID
4767 +                       };
4768 +
4769 +               setattr_copy(new_inode, &attr);
4770 +               mark_inode_dirty(new_inode);
4771 +       }
4772 +
4773 +       /* lock rename mutex */
4774 +       mutex_lock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4775 +
4776 +       /* drop out late */
4777 +       ret = -ENOENT;
4778 +       if ((redo = d_unhashed(old_dentry)))
4779 +               goto out_unlock;
4780 +
4781 +       vxdprintk(VXD_CBIT(misc, 2),
4782 +               "vfs_rename: [" VS_Q("%*s") ":%d] -> [" VS_Q("%*s") ":%d]",
4783 +               new_dentry->d_name.len, new_dentry->d_name.name,
4784 +               new_dentry->d_name.len,
4785 +               old_dentry->d_name.len, old_dentry->d_name.name,
4786 +               old_dentry->d_name.len);
4787 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_dentry,
4788 +               old_dentry->d_parent->d_inode, old_dentry);
4789 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
4790 +
4791 +out_unlock:
4792 +       mutex_unlock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4793 +
4794 +out_fput_both:
4795 +       vxdprintk(VXD_CBIT(misc, 3),
4796 +               "fput(new_file=%p[#%ld])", new_file,
4797 +               atomic_long_read(&new_file->f_count));
4798 +       fput(new_file);
4799 +
4800 +out_fput_old:
4801 +       vxdprintk(VXD_CBIT(misc, 3),
4802 +               "fput(old_file=%p[#%ld])", old_file,
4803 +               atomic_long_read(&old_file->f_count));
4804 +       fput(old_file);
4805 +
4806 +out_unlock_new:
4807 +       /* drop references from dir_nd.path */
4808 +       path_put(&dir_nd.path);
4809 +
4810 +       if (drop) {
4811 +               /* unlock the inode mutex from kern_path_create() */
4812 +               mutex_unlock(&dir->d_inode->i_mutex);
4813 +
4814 +               /* drop write access to mnt */
4815 +               mnt_drop_write(new_path->mnt);
4816 +       }
4817 +
4818 +       if (!ret)
4819 +               goto out_redo;
4820 +
4821 +       /* error path cleanup */
4822 +       vfs_unlink(dir->d_inode, new_dentry);
4823 +
4824 +out_redo:
4825 +       if (!redo)
4826 +               goto out_rel_both;
4827 +
4828 +       /* lookup dentry once again
4829 +          old_nd.path will be freed as old_path in out_rel_old */
4830 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4831 +       if (ret)
4832 +               goto out_rel_both;
4833 +
4834 +       /* drop reference on new_dentry */
4835 +       dput(new_dentry);
4836 +       new_dentry = old_path->dentry;
4837 +       dget(new_dentry);
4838 +       vxdprintk(VXD_CBIT(misc, 2),
4839 +               "do_path_lookup(redo): %p [" VS_Q("%.*s") ":%d]",
4840 +               new_dentry,
4841 +               new_dentry->d_name.len, new_dentry->d_name.name,
4842 +               new_dentry->d_name.len);
4843 +
4844 +out_rel_both:
4845 +       if (new_path)
4846 +               path_put(new_path);
4847 +out_rel_old:
4848 +       path_put(old_path);
4849 +out_free_path:
4850 +       kfree(path);
4851 +out:
4852 +       if (ret) {
4853 +               dput(new_dentry);
4854 +               new_dentry = ERR_PTR(ret);
4855 +       }
4856 +       vxdprintk(VXD_CBIT(misc, 3),
4857 +               "cow_break_link returning with %p", new_dentry);
4858 +       return new_dentry;
4859 +}
4860 +
4861 +#endif
4862 +
4863 +int    vx_info_mnt_namespace(struct mnt_namespace *ns, char *buffer)
4864 +{
4865 +       struct path path;
4866 +       struct vfsmount *vmnt;
4867 +       char *pstr, *root;
4868 +       int length = 0;
4869 +
4870 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
4871 +       if (!pstr)
4872 +               return 0;
4873 +
4874 +       vmnt = &ns->root->mnt;
4875 +       path.mnt = vmnt;
4876 +       path.dentry = vmnt->mnt_root;
4877 +       root = d_path(&path, pstr, PATH_MAX - 2);
4878 +       length = sprintf(buffer + length,
4879 +               "Namespace:\t%p [#%u]\n"
4880 +               "RootPath:\t%s\n",
4881 +               ns, atomic_read(&ns->count),
4882 +               root);
4883 +       kfree(pstr);
4884 +       return length;
4885 +}
4886 +
4887  /* get the link contents into pagecache */
4888  static char *page_getlink(struct dentry * dentry, struct page **ppage)
4889  {
4890 @@ -4099,3 +4521,4 @@ EXPORT_SYMBOL(vfs_symlink);
4891  EXPORT_SYMBOL(vfs_unlink);
4892  EXPORT_SYMBOL(dentry_unhash);
4893  EXPORT_SYMBOL(generic_readlink);
4894 +EXPORT_SYMBOL(vx_info_mnt_namespace);
4895 diff -NurpP --minimal linux-3.9.4/fs/namespace.c linux-3.9.4-vs2.3.6.3/fs/namespace.c
4896 --- linux-3.9.4/fs/namespace.c  2013-05-31 14:22:27.000000000 +0000
4897 +++ linux-3.9.4-vs2.3.6.3/fs/namespace.c        2013-05-31 18:47:18.000000000 +0000
4898 @@ -22,6 +22,11 @@
4899  #include <linux/fsnotify.h>    /* fsnotify_vfsmount_delete */
4900  #include <linux/uaccess.h>
4901  #include <linux/proc_fs.h>
4902 +#include <linux/vs_base.h>
4903 +#include <linux/vs_context.h>
4904 +#include <linux/vs_tag.h>
4905 +#include <linux/vserver/space.h>
4906 +#include <linux/vserver/global.h>
4907  #include "pnode.h"
4908  #include "internal.h"
4909  
4910 @@ -751,6 +756,10 @@ vfs_kern_mount(struct file_system_type *
4911         if (!type)
4912                 return ERR_PTR(-ENODEV);
4913  
4914 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
4915 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
4916 +               return ERR_PTR(-EPERM);
4917 +
4918         mnt = alloc_vfsmnt(name);
4919         if (!mnt)
4920                 return ERR_PTR(-ENOMEM);
4921 @@ -807,6 +816,7 @@ static struct mount *clone_mnt(struct mo
4922         mnt->mnt.mnt_root = dget(root);
4923         mnt->mnt_mountpoint = mnt->mnt.mnt_root;
4924         mnt->mnt_parent = mnt;
4925 +               mnt->mnt_tag = old->mnt_tag;
4926         br_write_lock(&vfsmount_lock);
4927         list_add_tail(&mnt->mnt_instance, &sb->s_mounts);
4928         br_write_unlock(&vfsmount_lock);
4929 @@ -1639,6 +1649,7 @@ static int do_change_type(struct path *p
4930                 if (err)
4931                         goto out_unlock;
4932         }
4933 +       // mnt->mnt_flags = mnt_flags;
4934  
4935         br_write_lock(&vfsmount_lock);
4936         for (m = mnt; m; m = (recurse ? next_mnt(m, mnt) : NULL))
4937 @@ -1654,12 +1665,14 @@ static int do_change_type(struct path *p
4938   * do loopback mount.
4939   */
4940  static int do_loopback(struct path *path, const char *old_name,
4941 -                               int recurse)
4942 +       tag_t tag, unsigned long flags, int mnt_flags)
4943  {
4944         LIST_HEAD(umount_list);
4945         struct path old_path;
4946         struct mount *mnt = NULL, *old;
4947 +       int recurse = flags & MS_REC;
4948         int err;
4949 +
4950         if (!old_name || !*old_name)
4951                 return -EINVAL;
4952         err = kern_path(old_name, LOOKUP_FOLLOW|LOOKUP_AUTOMOUNT, &old_path);
4953 @@ -1733,7 +1746,7 @@ static int change_mount_flags(struct vfs
4954   * on it - tough luck.
4955   */
4956  static int do_remount(struct path *path, int flags, int mnt_flags,
4957 -                     void *data)
4958 +       void *data, xid_t xid)
4959  {
4960         int err;
4961         struct super_block *sb = path->mnt->mnt_sb;
4962 @@ -2046,7 +2059,6 @@ void mark_mounts_for_expiry(struct list_
4963         }
4964         br_write_unlock(&vfsmount_lock);
4965         up_write(&namespace_sem);
4966 -
4967         release_mounts(&umounts);
4968  }
4969  
4970 @@ -2218,6 +2230,7 @@ long do_mount(const char *dev_name, cons
4971         struct path path;
4972         int retval = 0;
4973         int mnt_flags = 0;
4974 +       tag_t tag = 0;
4975  
4976         /* Discard magic */
4977         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
4978 @@ -2247,6 +2260,12 @@ long do_mount(const char *dev_name, cons
4979         if (!(flags & MS_NOATIME))
4980                 mnt_flags |= MNT_RELATIME;
4981  
4982 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
4983 +               /* FIXME: bind and re-mounts get the tag flag? */
4984 +               if (flags & (MS_BIND|MS_REMOUNT))
4985 +                       flags |= MS_TAGID;
4986 +       }
4987 +
4988         /* Separate the per-mountpoint flags */
4989         if (flags & MS_NOSUID)
4990                 mnt_flags |= MNT_NOSUID;
4991 @@ -2263,15 +2282,17 @@ long do_mount(const char *dev_name, cons
4992         if (flags & MS_RDONLY)
4993                 mnt_flags |= MNT_READONLY;
4994  
4995 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_DEV_MOUNT))
4996 +               mnt_flags |= MNT_NODEV;
4997         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_BORN |
4998                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
4999                    MS_STRICTATIME);
5000  
5001         if (flags & MS_REMOUNT)
5002                 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
5003 -                                   data_page);
5004 +                                   data_page, tag);
5005         else if (flags & MS_BIND)
5006 -               retval = do_loopback(&path, dev_name, flags & MS_REC);
5007 +               retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
5008         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
5009                 retval = do_change_type(&path, flags);
5010         else if (flags & MS_MOVE)
5011 @@ -2380,6 +2401,7 @@ static struct mnt_namespace *dup_mnt_ns(
5012                 q = next_mnt(q, new);
5013         }
5014         up_write(&namespace_sem);
5015 +       atomic_inc(&vs_global_mnt_ns);
5016  
5017         if (rootmnt)
5018                 mntput(rootmnt);
5019 @@ -2575,9 +2597,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
5020         error = -EINVAL;
5021         new_mnt = real_mount(new.mnt);
5022         root_mnt = real_mount(root.mnt);
5023 -       if (IS_MNT_SHARED(real_mount(old.mnt)) ||
5024 +       if ((IS_MNT_SHARED(real_mount(old.mnt)) ||
5025                 IS_MNT_SHARED(new_mnt->mnt_parent) ||
5026 -               IS_MNT_SHARED(root_mnt->mnt_parent))
5027 +               IS_MNT_SHARED(root_mnt->mnt_parent)) &&
5028 +               !vx_flags(VXF_STATE_SETUP, 0))
5029                 goto out4;
5030         if (!check_mnt(root_mnt) || !check_mnt(new_mnt))
5031                 goto out4;
5032 @@ -2703,6 +2726,7 @@ void put_mnt_ns(struct mnt_namespace *ns
5033         br_write_unlock(&vfsmount_lock);
5034         up_write(&namespace_sem);
5035         release_mounts(&umount_list);
5036 +       atomic_dec(&vs_global_mnt_ns);
5037         free_mnt_ns(ns);
5038  }
5039  
5040 diff -NurpP --minimal linux-3.9.4/fs/nfs/client.c linux-3.9.4-vs2.3.6.3/fs/nfs/client.c
5041 --- linux-3.9.4/fs/nfs/client.c 2013-05-31 13:45:24.000000000 +0000
5042 +++ linux-3.9.4-vs2.3.6.3/fs/nfs/client.c       2013-05-31 14:47:11.000000000 +0000
5043 @@ -682,6 +682,9 @@ int nfs_init_server_rpcclient(struct nfs
5044         if (server->flags & NFS_MOUNT_SOFT)
5045                 server->client->cl_softrtry = 1;
5046  
5047 +       server->client->cl_tag = 0;
5048 +       if (server->flags & NFS_MOUNT_TAGGED)
5049 +               server->client->cl_tag = 1;
5050         return 0;
5051  }
5052  EXPORT_SYMBOL_GPL(nfs_init_server_rpcclient);
5053 @@ -861,6 +864,10 @@ static void nfs_server_set_fsinfo(struct
5054                 server->acdirmin = server->acdirmax = 0;
5055         }
5056  
5057 +       /* FIXME: needs fsinfo
5058 +       if (server->flags & NFS_MOUNT_TAGGED)
5059 +               sb->s_flags |= MS_TAGGED;       */
5060 +
5061         server->maxfilesize = fsinfo->maxfilesize;
5062  
5063         server->time_delta = fsinfo->time_delta;
5064 diff -NurpP --minimal linux-3.9.4/fs/nfs/dir.c linux-3.9.4-vs2.3.6.3/fs/nfs/dir.c
5065 --- linux-3.9.4/fs/nfs/dir.c    2013-05-31 13:45:24.000000000 +0000
5066 +++ linux-3.9.4-vs2.3.6.3/fs/nfs/dir.c  2013-05-31 14:47:11.000000000 +0000
5067 @@ -36,6 +36,7 @@
5068  #include <linux/sched.h>
5069  #include <linux/kmemleak.h>
5070  #include <linux/xattr.h>
5071 +#include <linux/vs_tag.h>
5072  
5073  #include "delegation.h"
5074  #include "iostat.h"
5075 @@ -1300,6 +1301,7 @@ struct dentry *nfs_lookup(struct inode *
5076         /* Success: notify readdir to use READDIRPLUS */
5077         nfs_advise_use_readdirplus(dir);
5078  
5079 +       dx_propagate_tag(nd, inode);
5080  no_entry:
5081         res = d_materialise_unique(dentry, inode);
5082         if (res != NULL) {
5083 diff -NurpP --minimal linux-3.9.4/fs/nfs/inode.c linux-3.9.4-vs2.3.6.3/fs/nfs/inode.c
5084 --- linux-3.9.4/fs/nfs/inode.c  2013-05-31 13:45:24.000000000 +0000
5085 +++ linux-3.9.4-vs2.3.6.3/fs/nfs/inode.c        2013-06-03 19:32:53.000000000 +0000
5086 @@ -39,6 +39,7 @@
5087  #include <linux/compat.h>
5088  #include <linux/freezer.h>
5089  #include <linux/crc32.h>
5090 +#include <linux/vs_tag.h>
5091  
5092  #include <asm/uaccess.h>
5093  
5094 @@ -290,6 +291,8 @@ nfs_fhget(struct super_block *sb, struct
5095         if (inode->i_state & I_NEW) {
5096                 struct nfs_inode *nfsi = NFS_I(inode);
5097                 unsigned long now = jiffies;
5098 +               kuid_t kuid;
5099 +               kgid_t kgid;
5100  
5101                 /* We set i_ino for the few things that still rely on it,
5102                  * such as stat(2) */
5103 @@ -334,8 +337,8 @@ nfs_fhget(struct super_block *sb, struct
5104                 inode->i_version = 0;
5105                 inode->i_size = 0;
5106                 clear_nlink(inode);
5107 -               inode->i_uid = make_kuid(&init_user_ns, -2);
5108 -               inode->i_gid = make_kgid(&init_user_ns, -2);
5109 +               kuid = make_kuid(&init_user_ns, -2);
5110 +               kgid = make_kgid(&init_user_ns, -2);
5111                 inode->i_blocks = 0;
5112                 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
5113                 nfsi->write_io = 0;
5114 @@ -369,11 +372,11 @@ nfs_fhget(struct super_block *sb, struct
5115                 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
5116                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5117                 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
5118 -                       inode->i_uid = fattr->uid;
5119 +                       kuid = fattr->uid;
5120                 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
5121                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5122                 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
5123 -                       inode->i_gid = fattr->gid;
5124 +                       kgid = fattr->gid;
5125                 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
5126                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5127                 if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED)
5128 @@ -384,6 +387,11 @@ nfs_fhget(struct super_block *sb, struct
5129                          */
5130                         inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
5131                 }
5132 +               inode->i_uid = INOTAG_KUID(DX_TAG(inode), kuid, kgid);
5133 +               inode->i_gid = INOTAG_KGID(DX_TAG(inode), kuid, kgid);
5134 +               inode->i_tag = INOTAG_KTAG(DX_TAG(inode), kuid, kgid, GLOBAL_ROOT_TAG);
5135 +                               /* maybe fattr->xid someday */
5136 +
5137                 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
5138                 nfsi->attrtimeo_timestamp = now;
5139                 nfsi->access_cache = RB_ROOT;
5140 @@ -505,6 +513,8 @@ void nfs_setattr_update_inode(struct ino
5141                         inode->i_uid = attr->ia_uid;
5142                 if ((attr->ia_valid & ATTR_GID) != 0)
5143                         inode->i_gid = attr->ia_gid;
5144 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5145 +                       inode->i_tag = attr->ia_tag;
5146                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5147                 spin_unlock(&inode->i_lock);
5148         }
5149 @@ -980,7 +990,9 @@ static int nfs_check_inode_attributes(st
5150         struct nfs_inode *nfsi = NFS_I(inode);
5151         loff_t cur_size, new_isize;
5152         unsigned long invalid = 0;
5153 -
5154 +       kuid_t kuid;
5155 +       kgid_t kgid;
5156 +       ktag_t ktag;
5157  
5158         if (nfs_have_delegated_attributes(inode))
5159                 return 0;
5160 @@ -1005,13 +1017,18 @@ static int nfs_check_inode_attributes(st
5161                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5162         }
5163  
5164 +       kuid = INOTAG_KUID(DX_TAG(inode), fattr->uid, fattr->gid);
5165 +       kgid = INOTAG_KGID(DX_TAG(inode), fattr->uid, fattr->gid);
5166 +       ktag = INOTAG_KTAG(DX_TAG(inode), fattr->uid, fattr->gid, GLOBAL_ROOT_TAG);
5167 +
5168         /* Have any file permissions changed? */
5169         if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
5170                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5171 -       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && !uid_eq(inode->i_uid, fattr->uid))
5172 +       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && !uid_eq(inode->i_uid, kuid))
5173                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5174 -       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && !gid_eq(inode->i_gid, fattr->gid))
5175 +       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && !gid_eq(inode->i_gid, kgid))
5176                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5177 +               /* maybe check for tag too? */
5178  
5179         /* Has the link count changed? */
5180         if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
5181 @@ -1317,6 +1334,9 @@ static int nfs_update_inode(struct inode
5182         unsigned long invalid = 0;
5183         unsigned long now = jiffies;
5184         unsigned long save_cache_validity;
5185 +       kuid_t kuid;
5186 +       kgid_t kgid;
5187 +       ktag_t ktag;
5188  
5189         dfprintk(VFS, "NFS: %s(%s/%ld fh_crc=0x%08x ct=%d info=0x%x)\n",
5190                         __func__, inode->i_sb->s_id, inode->i_ino,
5191 @@ -1418,6 +1438,9 @@ static int nfs_update_inode(struct inode
5192                                 | NFS_INO_REVAL_PAGECACHE
5193                                 | NFS_INO_REVAL_FORCED);
5194  
5195 +       kuid = TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag);
5196 +       kgid = TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag);
5197 +       ktag = TAGINO_KTAG(DX_TAG(inode), inode->i_tag);
5198  
5199         if (fattr->valid & NFS_ATTR_FATTR_ATIME)
5200                 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5201 @@ -1460,6 +1483,10 @@ static int nfs_update_inode(struct inode
5202                                 | NFS_INO_INVALID_ACL
5203                                 | NFS_INO_REVAL_FORCED);
5204  
5205 +       inode->i_uid = INOTAG_KUID(DX_TAG(inode), kuid, kgid);
5206 +       inode->i_gid = INOTAG_KGID(DX_TAG(inode), kuid, kgid);
5207 +       inode->i_tag = INOTAG_KTAG(DX_TAG(inode), kuid, kgid, ktag);
5208 +
5209         if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
5210                 if (inode->i_nlink != fattr->nlink) {
5211                         invalid |= NFS_INO_INVALID_ATTR;
5212 diff -NurpP --minimal linux-3.9.4/fs/nfs/nfs3xdr.c linux-3.9.4-vs2.3.6.3/fs/nfs/nfs3xdr.c
5213 --- linux-3.9.4/fs/nfs/nfs3xdr.c        2013-05-31 13:45:24.000000000 +0000
5214 +++ linux-3.9.4-vs2.3.6.3/fs/nfs/nfs3xdr.c      2013-06-03 19:33:10.000000000 +0000
5215 @@ -20,6 +20,7 @@
5216  #include <linux/nfs3.h>
5217  #include <linux/nfs_fs.h>
5218  #include <linux/nfsacl.h>
5219 +#include <linux/vs_tag.h>
5220  #include "internal.h"
5221  
5222  #define NFSDBG_FACILITY                NFSDBG_XDR
5223 @@ -558,7 +559,8 @@ static __be32 *xdr_decode_nfstime3(__be3
5224   *             set_mtime       mtime;
5225   *     };
5226   */
5227 -static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr)
5228 +static void encode_sattr3(struct xdr_stream *xdr,
5229 +       const struct iattr *attr, int tag)
5230  {
5231         u32 nbytes;
5232         __be32 *p;
5233 @@ -590,15 +592,19 @@ static void encode_sattr3(struct xdr_str
5234         } else
5235                 *p++ = xdr_zero;
5236  
5237 -       if (attr->ia_valid & ATTR_UID) {
5238 +       if (attr->ia_valid & ATTR_UID ||
5239 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5240                 *p++ = xdr_one;
5241 -               *p++ = cpu_to_be32(from_kuid(&init_user_ns, attr->ia_uid));
5242 +               *p++ = cpu_to_be32(from_kuid(&init_user_ns,
5243 +                       TAGINO_KUID(tag, attr->ia_uid, attr->ia_tag)));
5244         } else
5245                 *p++ = xdr_zero;
5246  
5247 -       if (attr->ia_valid & ATTR_GID) {
5248 +       if (attr->ia_valid & ATTR_GID ||
5249 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5250                 *p++ = xdr_one;
5251 -               *p++ = cpu_to_be32(from_kgid(&init_user_ns, attr->ia_gid));
5252 +               *p++ = cpu_to_be32(from_kgid(&init_user_ns,
5253 +                       TAGINO_KGID(tag, attr->ia_gid, attr->ia_tag)));
5254         } else
5255                 *p++ = xdr_zero;
5256  
5257 @@ -887,7 +893,7 @@ static void nfs3_xdr_enc_setattr3args(st
5258                                       const struct nfs3_sattrargs *args)
5259  {
5260         encode_nfs_fh3(xdr, args->fh);
5261 -       encode_sattr3(xdr, args->sattr);
5262 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5263         encode_sattrguard3(xdr, args);
5264  }
5265  
5266 @@ -1037,13 +1043,13 @@ static void nfs3_xdr_enc_write3args(stru
5267   *     };
5268   */
5269  static void encode_createhow3(struct xdr_stream *xdr,
5270 -                             const struct nfs3_createargs *args)
5271 +       const struct nfs3_createargs *args, int tag)
5272  {
5273         encode_uint32(xdr, args->createmode);
5274         switch (args->createmode) {
5275         case NFS3_CREATE_UNCHECKED:
5276         case NFS3_CREATE_GUARDED:
5277 -               encode_sattr3(xdr, args->sattr);
5278 +               encode_sattr3(xdr, args->sattr, tag);
5279                 break;
5280         case NFS3_CREATE_EXCLUSIVE:
5281                 encode_createverf3(xdr, args->verifier);
5282 @@ -1058,7 +1064,7 @@ static void nfs3_xdr_enc_create3args(str
5283                                      const struct nfs3_createargs *args)
5284  {
5285         encode_diropargs3(xdr, args->fh, args->name, args->len);
5286 -       encode_createhow3(xdr, args);
5287 +       encode_createhow3(xdr, args, req->rq_task->tk_client->cl_tag);
5288  }
5289  
5290  /*
5291 @@ -1074,7 +1080,7 @@ static void nfs3_xdr_enc_mkdir3args(stru
5292                                     const struct nfs3_mkdirargs *args)
5293  {
5294         encode_diropargs3(xdr, args->fh, args->name, args->len);
5295 -       encode_sattr3(xdr, args->sattr);
5296 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5297  }
5298  
5299  /*
5300 @@ -1091,9 +1097,9 @@ static void nfs3_xdr_enc_mkdir3args(stru
5301   *     };
5302   */
5303  static void encode_symlinkdata3(struct xdr_stream *xdr,
5304 -                               const struct nfs3_symlinkargs *args)
5305 +       const struct nfs3_symlinkargs *args, int tag)
5306  {
5307 -       encode_sattr3(xdr, args->sattr);
5308 +       encode_sattr3(xdr, args->sattr, tag);
5309         encode_nfspath3(xdr, args->pages, args->pathlen);
5310  }
5311  
5312 @@ -1102,7 +1108,7 @@ static void nfs3_xdr_enc_symlink3args(st
5313                                       const struct nfs3_symlinkargs *args)
5314  {
5315         encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen);
5316 -       encode_symlinkdata3(xdr, args);
5317 +       encode_symlinkdata3(xdr, args, req->rq_task->tk_client->cl_tag);
5318  }
5319  
5320  /*
5321 @@ -1130,24 +1136,24 @@ static void nfs3_xdr_enc_symlink3args(st
5322   *     };
5323   */
5324  static void encode_devicedata3(struct xdr_stream *xdr,
5325 -                              const struct nfs3_mknodargs *args)
5326 +       const struct nfs3_mknodargs *args, int tag)
5327  {
5328 -       encode_sattr3(xdr, args->sattr);
5329 +       encode_sattr3(xdr, args->sattr, tag);
5330         encode_specdata3(xdr, args->rdev);
5331  }
5332  
5333  static void encode_mknoddata3(struct xdr_stream *xdr,
5334 -                             const struct nfs3_mknodargs *args)
5335 +       const struct nfs3_mknodargs *args, int tag)
5336  {
5337         encode_ftype3(xdr, args->type);
5338         switch (args->type) {
5339         case NF3CHR:
5340         case NF3BLK:
5341 -               encode_devicedata3(xdr, args);
5342 +               encode_devicedata3(xdr, args, tag);
5343                 break;
5344         case NF3SOCK:
5345         case NF3FIFO:
5346 -               encode_sattr3(xdr, args->sattr);
5347 +               encode_sattr3(xdr, args->sattr, tag);
5348                 break;
5349         case NF3REG:
5350         case NF3DIR:
5351 @@ -1162,7 +1168,7 @@ static void nfs3_xdr_enc_mknod3args(stru
5352                                     const struct nfs3_mknodargs *args)
5353  {
5354         encode_diropargs3(xdr, args->fh, args->name, args->len);
5355 -       encode_mknoddata3(xdr, args);
5356 +       encode_mknoddata3(xdr, args, req->rq_task->tk_client->cl_tag);
5357  }
5358  
5359  /*
5360 diff -NurpP --minimal linux-3.9.4/fs/nfs/super.c linux-3.9.4-vs2.3.6.3/fs/nfs/super.c
5361 --- linux-3.9.4/fs/nfs/super.c  2013-05-31 13:45:24.000000000 +0000
5362 +++ linux-3.9.4-vs2.3.6.3/fs/nfs/super.c        2013-05-31 15:41:34.000000000 +0000
5363 @@ -55,6 +55,7 @@
5364  #include <linux/parser.h>
5365  #include <linux/nsproxy.h>
5366  #include <linux/rcupdate.h>
5367 +#include <linux/vs_tag.h>
5368  
5369  #include <asm/uaccess.h>
5370  
5371 @@ -103,6 +104,7 @@ enum {
5372         Opt_mountport,
5373         Opt_mountvers,
5374         Opt_minorversion,
5375 +       Opt_tagid,
5376  
5377         /* Mount options that take string arguments */
5378         Opt_nfsvers,
5379 @@ -115,6 +117,9 @@ enum {
5380         /* Special mount options */
5381         Opt_userspace, Opt_deprecated, Opt_sloppy,
5382  
5383 +       /* Linux-VServer tagging options */
5384 +       Opt_tag, Opt_notag,
5385 +
5386         Opt_err
5387  };
5388  
5389 @@ -184,6 +189,10 @@ static const match_table_t nfs_mount_opt
5390         { Opt_fscache_uniq, "fsc=%s" },
5391         { Opt_local_lock, "local_lock=%s" },
5392  
5393 +       { Opt_tag, "tag" },
5394 +       { Opt_notag, "notag" },
5395 +       { Opt_tagid, "tagid=%u" },
5396 +
5397         /* The following needs to be listed after all other options */
5398         { Opt_nfsvers, "v%s" },
5399  
5400 @@ -635,6 +644,7 @@ static void nfs_show_mount_options(struc
5401                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
5402                 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
5403                 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
5404 +               { NFS_MOUNT_TAGGED, ",tag", "" },
5405                 { 0, NULL, NULL }
5406         };
5407         const struct proc_nfs_info *nfs_infop;
5408 @@ -1261,6 +1271,14 @@ static int nfs_parse_mount_options(char
5409                 case Opt_nomigration:
5410                         mnt->options &= NFS_OPTION_MIGRATION;
5411                         break;
5412 +#ifndef CONFIG_TAGGING_NONE
5413 +               case Opt_tag:
5414 +                       mnt->flags |= NFS_MOUNT_TAGGED;
5415 +                       break;
5416 +               case Opt_notag:
5417 +                       mnt->flags &= ~NFS_MOUNT_TAGGED;
5418 +                       break;
5419 +#endif
5420  
5421                 /*
5422                  * options that take numeric values
5423 @@ -1347,6 +1365,12 @@ static int nfs_parse_mount_options(char
5424                                 goto out_invalid_value;
5425                         mnt->minorversion = option;
5426                         break;
5427 +#ifdef CONFIG_PROPAGATE
5428 +               case Opt_tagid:
5429 +                       /* use args[0] */
5430 +                       nfs_data.flags |= NFS_MOUNT_TAGGED;
5431 +                       break;
5432 +#endif
5433  
5434                 /*
5435                  * options that take text values
5436 diff -NurpP --minimal linux-3.9.4/fs/nfsd/auth.c linux-3.9.4-vs2.3.6.3/fs/nfsd/auth.c
5437 --- linux-3.9.4/fs/nfsd/auth.c  2013-05-31 13:45:24.000000000 +0000
5438 +++ linux-3.9.4-vs2.3.6.3/fs/nfsd/auth.c        2013-05-31 14:47:11.000000000 +0000
5439 @@ -2,6 +2,7 @@
5440  
5441  #include <linux/sched.h>
5442  #include <linux/user_namespace.h>
5443 +#include <linux/vs_tag.h>
5444  #include "nfsd.h"
5445  #include "auth.h"
5446  
5447 @@ -37,6 +38,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
5448  
5449         new->fsuid = rqstp->rq_cred.cr_uid;
5450         new->fsgid = rqstp->rq_cred.cr_gid;
5451 +       /* FIXME: this desperately needs a tag :)
5452 +       new->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
5453 +                       */
5454  
5455         rqgi = rqstp->rq_cred.cr_group_info;
5456  
5457 diff -NurpP --minimal linux-3.9.4/fs/nfsd/nfs3xdr.c linux-3.9.4-vs2.3.6.3/fs/nfsd/nfs3xdr.c
5458 --- linux-3.9.4/fs/nfsd/nfs3xdr.c       2013-05-31 13:45:24.000000000 +0000
5459 +++ linux-3.9.4-vs2.3.6.3/fs/nfsd/nfs3xdr.c     2013-06-03 19:57:43.000000000 +0000
5460 @@ -8,6 +8,7 @@
5461  
5462  #include <linux/namei.h>
5463  #include <linux/sunrpc/svc_xprt.h>
5464 +#include <linux/vs_tag.h>
5465  #include "xdr3.h"
5466  #include "auth.h"
5467  #include "netns.h"
5468 @@ -98,6 +99,8 @@ static __be32 *
5469  decode_sattr3(__be32 *p, struct iattr *iap)
5470  {
5471         u32     tmp;
5472 +       kuid_t  kuid = GLOBAL_ROOT_UID;
5473 +       kgid_t  kgid = GLOBAL_ROOT_GID;
5474  
5475         iap->ia_valid = 0;
5476  
5477 @@ -106,15 +109,18 @@ decode_sattr3(__be32 *p, struct iattr *i
5478                 iap->ia_mode = ntohl(*p++);
5479         }
5480         if (*p++) {
5481 -               iap->ia_uid = make_kuid(&init_user_ns, ntohl(*p++));
5482 +               kuid = make_kuid(&init_user_ns, ntohl(*p++));
5483                 if (uid_valid(iap->ia_uid))
5484                         iap->ia_valid |= ATTR_UID;
5485         }
5486         if (*p++) {
5487 -               iap->ia_gid = make_kgid(&init_user_ns, ntohl(*p++));
5488 +               kgid = make_kgid(&init_user_ns, ntohl(*p++));
5489                 if (gid_valid(iap->ia_gid))
5490                         iap->ia_valid |= ATTR_GID;
5491         }
5492 +       iap->ia_uid = INOTAG_KUID(DX_TAG_NFSD, kuid, kgid);
5493 +       iap->ia_gid = INOTAG_KGID(DX_TAG_NFSD, kuid, kgid);
5494 +       iap->ia_tag = INOTAG_KTAG(DX_TAG_NFSD, kuid, kgid, GLOBAL_ROOT_TAG);
5495         if (*p++) {
5496                 u64     newsize;
5497  
5498 @@ -170,8 +176,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
5499         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
5500         *p++ = htonl((u32) stat->mode);
5501         *p++ = htonl((u32) stat->nlink);
5502 -       *p++ = htonl((u32) from_kuid(&init_user_ns, stat->uid));
5503 -       *p++ = htonl((u32) from_kgid(&init_user_ns, stat->gid));
5504 +       *p++ = htonl((u32) from_kuid(&init_user_ns,
5505 +               TAGINO_KUID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5506 +               stat->uid, stat->tag)));
5507 +       *p++ = htonl((u32) from_kgid(&init_user_ns,
5508 +               TAGINO_KGID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5509 +               stat->gid, stat->tag)));
5510         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
5511                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
5512         } else {
5513 diff -NurpP --minimal linux-3.9.4/fs/nfsd/nfs4xdr.c linux-3.9.4-vs2.3.6.3/fs/nfsd/nfs4xdr.c
5514 --- linux-3.9.4/fs/nfsd/nfs4xdr.c       2013-05-31 14:22:27.000000000 +0000
5515 +++ linux-3.9.4-vs2.3.6.3/fs/nfsd/nfs4xdr.c     2013-06-03 19:33:44.000000000 +0000
5516 @@ -46,6 +46,7 @@
5517  #include <linux/utsname.h>
5518  #include <linux/pagemap.h>
5519  #include <linux/sunrpc/svcauth_gss.h>
5520 +#include <linux/vs_tag.h>
5521  
5522  #include "idmap.h"
5523  #include "acl.h"
5524 @@ -2349,14 +2350,18 @@ out_acl:
5525                 WRITE32(stat.nlink);
5526         }
5527         if (bmval1 & FATTR4_WORD1_OWNER) {
5528 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
5529 +               status = nfsd4_encode_user(rqstp,
5530 +                       TAGINO_KUID(DX_TAG(dentry->d_inode),
5531 +                       stat.uid, stat.tag), &p, &buflen);
5532                 if (status == nfserr_resource)
5533                         goto out_resource;
5534                 if (status)
5535                         goto out;
5536         }
5537         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
5538 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
5539 +               status = nfsd4_encode_group(rqstp,
5540 +                       TAGINO_KGID(DX_TAG(dentry->d_inode),
5541 +                       stat.gid, stat.tag), &p, &buflen);
5542                 if (status == nfserr_resource)
5543                         goto out_resource;
5544                 if (status)
5545 diff -NurpP --minimal linux-3.9.4/fs/nfsd/nfsxdr.c linux-3.9.4-vs2.3.6.3/fs/nfsd/nfsxdr.c
5546 --- linux-3.9.4/fs/nfsd/nfsxdr.c        2013-05-31 13:45:24.000000000 +0000
5547 +++ linux-3.9.4-vs2.3.6.3/fs/nfsd/nfsxdr.c      2013-06-03 19:56:35.000000000 +0000
5548 @@ -7,6 +7,7 @@
5549  #include "vfs.h"
5550  #include "xdr.h"
5551  #include "auth.h"
5552 +#include <linux/vs_tag.h>
5553  
5554  #define NFSDDBG_FACILITY               NFSDDBG_XDR
5555  
5556 @@ -89,6 +90,8 @@ static __be32 *
5557  decode_sattr(__be32 *p, struct iattr *iap)
5558  {
5559         u32     tmp, tmp1;
5560 +       kuid_t  kuid = GLOBAL_ROOT_UID;
5561 +       kgid_t  kgid = GLOBAL_ROOT_GID;
5562  
5563         iap->ia_valid = 0;
5564  
5565 @@ -101,15 +104,18 @@ decode_sattr(__be32 *p, struct iattr *ia
5566                 iap->ia_mode = tmp;
5567         }
5568         if ((tmp = ntohl(*p++)) != (u32)-1) {
5569 -               iap->ia_uid = make_kuid(&init_user_ns, tmp);
5570 +               kuid = make_kuid(&init_user_ns, tmp);
5571                 if (uid_valid(iap->ia_uid))
5572                         iap->ia_valid |= ATTR_UID;
5573         }
5574         if ((tmp = ntohl(*p++)) != (u32)-1) {
5575 -               iap->ia_gid = make_kgid(&init_user_ns, tmp);
5576 +               kgid = make_kgid(&init_user_ns, tmp);
5577                 if (gid_valid(iap->ia_gid))
5578                         iap->ia_valid |= ATTR_GID;
5579         }
5580 +       iap->ia_uid = INOTAG_KUID(DX_TAG_NFSD, kuid, kgid);
5581 +       iap->ia_gid = INOTAG_KGID(DX_TAG_NFSD, kuid, kgid);
5582 +       iap->ia_tag = INOTAG_KTAG(DX_TAG_NFSD, kuid, kgid, GLOBAL_ROOT_TAG);
5583         if ((tmp = ntohl(*p++)) != (u32)-1) {
5584                 iap->ia_valid |= ATTR_SIZE;
5585                 iap->ia_size = tmp;
5586 @@ -154,8 +160,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
5587         *p++ = htonl(nfs_ftypes[type >> 12]);
5588         *p++ = htonl((u32) stat->mode);
5589         *p++ = htonl((u32) stat->nlink);
5590 -       *p++ = htonl((u32) from_kuid(&init_user_ns, stat->uid));
5591 -       *p++ = htonl((u32) from_kgid(&init_user_ns, stat->gid));
5592 +       *p++ = htonl((u32) from_kuid(&init_user_ns,
5593 +               TAGINO_KUID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
5594 +       *p++ = htonl((u32) from_kgid(&init_user_ns,
5595 +               TAGINO_KGID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
5596  
5597         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
5598                 *p++ = htonl(NFS_MAXPATHLEN);
5599 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/dlmglue.c linux-3.9.4-vs2.3.6.3/fs/ocfs2/dlmglue.c
5600 --- linux-3.9.4/fs/ocfs2/dlmglue.c      2013-05-31 13:45:24.000000000 +0000
5601 +++ linux-3.9.4-vs2.3.6.3/fs/ocfs2/dlmglue.c    2013-06-03 19:59:20.000000000 +0000
5602 @@ -2047,6 +2047,7 @@ static void __ocfs2_stuff_meta_lvb(struc
5603         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
5604         lvb->lvb_iuid      = cpu_to_be32(i_uid_read(inode));
5605         lvb->lvb_igid      = cpu_to_be32(i_gid_read(inode));
5606 +       lvb->lvb_itag      = cpu_to_be16(i_tag_read(inode));
5607         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
5608         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
5609         lvb->lvb_iatime_packed  =
5610 @@ -2097,6 +2098,7 @@ static void ocfs2_refresh_inode_from_lvb
5611  
5612         i_uid_write(inode, be32_to_cpu(lvb->lvb_iuid));
5613         i_gid_write(inode, be32_to_cpu(lvb->lvb_igid));
5614 +       i_tag_write(inode, be16_to_cpu(lvb->lvb_itag));
5615         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
5616         set_nlink(inode, be16_to_cpu(lvb->lvb_inlink));
5617         ocfs2_unpack_timespec(&inode->i_atime,
5618 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/dlmglue.h linux-3.9.4-vs2.3.6.3/fs/ocfs2/dlmglue.h
5619 --- linux-3.9.4/fs/ocfs2/dlmglue.h      2012-12-11 03:30:57.000000000 +0000
5620 +++ linux-3.9.4-vs2.3.6.3/fs/ocfs2/dlmglue.h    2013-05-31 14:47:11.000000000 +0000
5621 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
5622         __be16       lvb_inlink;
5623         __be32       lvb_iattr;
5624         __be32       lvb_igeneration;
5625 -       __be32       lvb_reserved2;
5626 +       __be16       lvb_itag;
5627 +       __be16       lvb_reserved2;
5628  };
5629  
5630  #define OCFS2_QINFO_LVB_VERSION 1
5631 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/file.c linux-3.9.4-vs2.3.6.3/fs/ocfs2/file.c
5632 --- linux-3.9.4/fs/ocfs2/file.c 2013-05-31 13:45:24.000000000 +0000
5633 +++ linux-3.9.4-vs2.3.6.3/fs/ocfs2/file.c       2013-05-31 14:47:11.000000000 +0000
5634 @@ -1124,7 +1124,7 @@ int ocfs2_setattr(struct dentry *dentry,
5635                 attr->ia_valid &= ~ATTR_SIZE;
5636  
5637  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
5638 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
5639 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
5640         if (!(attr->ia_valid & OCFS2_VALID_ATTRS))
5641                 return 0;
5642  
5643 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/inode.c linux-3.9.4-vs2.3.6.3/fs/ocfs2/inode.c
5644 --- linux-3.9.4/fs/ocfs2/inode.c        2013-05-31 13:45:24.000000000 +0000
5645 +++ linux-3.9.4-vs2.3.6.3/fs/ocfs2/inode.c      2013-05-31 20:39:47.000000000 +0000
5646 @@ -28,6 +28,7 @@
5647  #include <linux/highmem.h>
5648  #include <linux/pagemap.h>
5649  #include <linux/quotaops.h>
5650 +#include <linux/vs_tag.h>
5651  
5652  #include <asm/byteorder.h>
5653  
5654 @@ -78,11 +79,13 @@ void ocfs2_set_inode_flags(struct inode
5655  {
5656         unsigned int flags = OCFS2_I(inode)->ip_attr;
5657  
5658 -       inode->i_flags &= ~(S_IMMUTABLE |
5659 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
5660                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
5661  
5662         if (flags & OCFS2_IMMUTABLE_FL)
5663                 inode->i_flags |= S_IMMUTABLE;
5664 +       if (flags & OCFS2_IXUNLINK_FL)
5665 +               inode->i_flags |= S_IXUNLINK;
5666  
5667         if (flags & OCFS2_SYNC_FL)
5668                 inode->i_flags |= S_SYNC;
5669 @@ -92,25 +95,44 @@ void ocfs2_set_inode_flags(struct inode
5670                 inode->i_flags |= S_NOATIME;
5671         if (flags & OCFS2_DIRSYNC_FL)
5672                 inode->i_flags |= S_DIRSYNC;
5673 +
5674 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
5675 +
5676 +       if (flags & OCFS2_BARRIER_FL)
5677 +               inode->i_vflags |= V_BARRIER;
5678 +       if (flags & OCFS2_COW_FL)
5679 +               inode->i_vflags |= V_COW;
5680  }
5681  
5682  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
5683  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
5684  {
5685         unsigned int flags = oi->vfs_inode.i_flags;
5686 +       unsigned int vflags = oi->vfs_inode.i_vflags;
5687 +
5688 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
5689 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
5690 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
5691 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
5692 +
5693 +       if (flags & S_IMMUTABLE)
5694 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5695 +       if (flags & S_IXUNLINK)
5696 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
5697  
5698 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
5699 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
5700         if (flags & S_SYNC)
5701                 oi->ip_attr |= OCFS2_SYNC_FL;
5702         if (flags & S_APPEND)
5703                 oi->ip_attr |= OCFS2_APPEND_FL;
5704 -       if (flags & S_IMMUTABLE)
5705 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5706         if (flags & S_NOATIME)
5707                 oi->ip_attr |= OCFS2_NOATIME_FL;
5708         if (flags & S_DIRSYNC)
5709                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
5710 +
5711 +       if (vflags & V_BARRIER)
5712 +               oi->ip_attr |= OCFS2_BARRIER_FL;
5713 +       if (vflags & V_COW)
5714 +               oi->ip_attr |= OCFS2_COW_FL;
5715  }
5716  
5717  struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
5718 @@ -241,6 +263,8 @@ void ocfs2_populate_inode(struct inode *
5719         struct super_block *sb;
5720         struct ocfs2_super *osb;
5721         int use_plocks = 1;
5722 +       uid_t uid;
5723 +       gid_t gid;
5724  
5725         sb = inode->i_sb;
5726         osb = OCFS2_SB(sb);
5727 @@ -269,8 +293,12 @@ void ocfs2_populate_inode(struct inode *
5728         inode->i_generation = le32_to_cpu(fe->i_generation);
5729         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
5730         inode->i_mode = le16_to_cpu(fe->i_mode);
5731 -       i_uid_write(inode, le32_to_cpu(fe->i_uid));
5732 -       i_gid_write(inode, le32_to_cpu(fe->i_gid));
5733 +       uid = le32_to_cpu(fe->i_uid);
5734 +       gid = le32_to_cpu(fe->i_gid);
5735 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), uid, gid));
5736 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), uid, gid));
5737 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), uid, gid,
5738 +               /* le16_to_cpu(raw_inode->i_raw_tag) */ 0));
5739  
5740         /* Fast symlinks will have i_size but no allocated clusters. */
5741         if (S_ISLNK(inode->i_mode) && !fe->i_clusters) {
5742 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/inode.h linux-3.9.4-vs2.3.6.3/fs/ocfs2/inode.h
5743 --- linux-3.9.4/fs/ocfs2/inode.h        2012-12-11 03:30:57.000000000 +0000
5744 +++ linux-3.9.4-vs2.3.6.3/fs/ocfs2/inode.h      2013-05-31 14:47:11.000000000 +0000
5745 @@ -154,6 +154,7 @@ struct buffer_head *ocfs2_bread(struct i
5746  
5747  void ocfs2_set_inode_flags(struct inode *inode);
5748  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
5749 +int ocfs2_sync_flags(struct inode *inode, int, int);
5750  
5751  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
5752  {
5753 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/ioctl.c linux-3.9.4-vs2.3.6.3/fs/ocfs2/ioctl.c
5754 --- linux-3.9.4/fs/ocfs2/ioctl.c        2013-05-31 13:45:24.000000000 +0000
5755 +++ linux-3.9.4-vs2.3.6.3/fs/ocfs2/ioctl.c      2013-05-31 14:47:11.000000000 +0000
5756 @@ -76,7 +76,41 @@ static int ocfs2_get_inode_attr(struct i
5757         return status;
5758  }
5759  
5760 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5761 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
5762 +{
5763 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
5764 +       struct buffer_head *bh = NULL;
5765 +       handle_t *handle = NULL;
5766 +       int status;
5767 +
5768 +       status = ocfs2_inode_lock(inode, &bh, 1);
5769 +       if (status < 0) {
5770 +               mlog_errno(status);
5771 +               return status;
5772 +       }
5773 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5774 +       if (IS_ERR(handle)) {
5775 +               status = PTR_ERR(handle);
5776 +               mlog_errno(status);
5777 +               goto bail_unlock;
5778 +       }
5779 +
5780 +       inode->i_flags = flags;
5781 +       inode->i_vflags = vflags;
5782 +       ocfs2_get_inode_flags(OCFS2_I(inode));
5783 +
5784 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
5785 +       if (status < 0)
5786 +               mlog_errno(status);
5787 +
5788 +       ocfs2_commit_trans(osb, handle);
5789 +bail_unlock:
5790 +       ocfs2_inode_unlock(inode, 1);
5791 +       brelse(bh);
5792 +       return status;
5793 +}
5794 +
5795 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5796                                 unsigned mask)
5797  {
5798         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
5799 @@ -101,6 +135,11 @@ static int ocfs2_set_inode_attr(struct i
5800         if (!S_ISDIR(inode->i_mode))
5801                 flags &= ~OCFS2_DIRSYNC_FL;
5802  
5803 +       if (IS_BARRIER(inode)) {
5804 +               vxwprintk_task(1, "messing with the barrier.");
5805 +               goto bail_unlock;
5806 +       }
5807 +
5808         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5809         if (IS_ERR(handle)) {
5810                 status = PTR_ERR(handle);
5811 @@ -879,6 +918,7 @@ bail:
5812         return status;
5813  }
5814  
5815 +
5816  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
5817  {
5818         struct inode *inode = file_inode(filp);
5819 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/namei.c linux-3.9.4-vs2.3.6.3/fs/ocfs2/namei.c
5820 --- linux-3.9.4/fs/ocfs2/namei.c        2013-05-31 13:45:24.000000000 +0000
5821 +++ linux-3.9.4-vs2.3.6.3/fs/ocfs2/namei.c      2013-06-03 20:00:35.000000000 +0000
5822 @@ -41,6 +41,7 @@
5823  #include <linux/slab.h>
5824  #include <linux/highmem.h>
5825  #include <linux/quotaops.h>
5826 +#include <linux/vs_tag.h>
5827  
5828  #include <cluster/masklog.h>
5829  
5830 @@ -475,6 +476,7 @@ static int __ocfs2_mknod_locked(struct i
5831         struct ocfs2_dinode *fe = NULL;
5832         struct ocfs2_extent_list *fel;
5833         u16 feat;
5834 +       ktag_t ktag;
5835  
5836         *new_fe_bh = NULL;
5837  
5838 @@ -512,8 +514,13 @@ static int __ocfs2_mknod_locked(struct i
5839         fe->i_suballoc_loc = cpu_to_le64(suballoc_loc);
5840         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
5841         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
5842 -       fe->i_uid = cpu_to_le32(i_uid_read(inode));
5843 -       fe->i_gid = cpu_to_le32(i_gid_read(inode));
5844 +
5845 +       ktag = make_ktag(&init_user_ns, dx_current_fstag(osb->sb));
5846 +       fe->i_uid = cpu_to_le32(from_kuid(&init_user_ns,
5847 +               TAGINO_KUID(DX_TAG(inode), inode->i_uid, ktag)));
5848 +       fe->i_gid = cpu_to_le32(from_kgid(&init_user_ns,
5849 +               TAGINO_KGID(DX_TAG(inode), inode->i_gid, ktag)));
5850 +       inode->i_tag = ktag; /* is this correct? */
5851         fe->i_mode = cpu_to_le16(inode->i_mode);
5852         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
5853                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
5854 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/ocfs2.h linux-3.9.4-vs2.3.6.3/fs/ocfs2/ocfs2.h
5855 --- linux-3.9.4/fs/ocfs2/ocfs2.h        2012-12-11 03:30:57.000000000 +0000
5856 +++ linux-3.9.4-vs2.3.6.3/fs/ocfs2/ocfs2.h      2013-05-31 14:47:11.000000000 +0000
5857 @@ -272,6 +272,7 @@ enum ocfs2_mount_options
5858                                                      writes */
5859         OCFS2_MOUNT_HB_NONE = 1 << 13, /* No heartbeat */
5860         OCFS2_MOUNT_HB_GLOBAL = 1 << 14, /* Global heartbeat */
5861 +       OCFS2_MOUNT_TAGGED = 1 << 15, /* use tagging */
5862  };
5863  
5864  #define OCFS2_OSB_SOFT_RO                      0x0001
5865 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/ocfs2_fs.h linux-3.9.4-vs2.3.6.3/fs/ocfs2/ocfs2_fs.h
5866 --- linux-3.9.4/fs/ocfs2/ocfs2_fs.h     2012-12-11 03:30:57.000000000 +0000
5867 +++ linux-3.9.4-vs2.3.6.3/fs/ocfs2/ocfs2_fs.h   2013-05-31 14:47:11.000000000 +0000
5868 @@ -266,6 +266,11 @@
5869  #define OCFS2_TOPDIR_FL                        FS_TOPDIR_FL    /* Top of directory hierarchies*/
5870  #define OCFS2_RESERVED_FL              FS_RESERVED_FL  /* reserved for ext2 lib */
5871  
5872 +#define OCFS2_IXUNLINK_FL              FS_IXUNLINK_FL  /* Immutable invert on unlink */
5873 +
5874 +#define OCFS2_BARRIER_FL               FS_BARRIER_FL   /* Barrier for chroot() */
5875 +#define OCFS2_COW_FL                   FS_COW_FL       /* Copy on Write marker */
5876 +
5877  #define OCFS2_FL_VISIBLE               FS_FL_USER_VISIBLE      /* User visible flags */
5878  #define OCFS2_FL_MODIFIABLE            FS_FL_USER_MODIFIABLE   /* User modifiable flags */
5879  
5880 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/super.c linux-3.9.4-vs2.3.6.3/fs/ocfs2/super.c
5881 --- linux-3.9.4/fs/ocfs2/super.c        2013-05-31 13:45:25.000000000 +0000
5882 +++ linux-3.9.4-vs2.3.6.3/fs/ocfs2/super.c      2013-05-31 14:47:11.000000000 +0000
5883 @@ -185,6 +185,7 @@ enum {
5884         Opt_coherency_full,
5885         Opt_resv_level,
5886         Opt_dir_resv_level,
5887 +       Opt_tag, Opt_notag, Opt_tagid,
5888         Opt_err,
5889  };
5890  
5891 @@ -216,6 +217,9 @@ static const match_table_t tokens = {
5892         {Opt_coherency_full, "coherency=full"},
5893         {Opt_resv_level, "resv_level=%u"},
5894         {Opt_dir_resv_level, "dir_resv_level=%u"},
5895 +       {Opt_tag, "tag"},
5896 +       {Opt_notag, "notag"},
5897 +       {Opt_tagid, "tagid=%u"},
5898         {Opt_err, NULL}
5899  };
5900  
5901 @@ -662,6 +666,13 @@ static int ocfs2_remount(struct super_bl
5902                 goto out;
5903         }
5904  
5905 +       if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
5906 +           (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
5907 +               ret = -EINVAL;
5908 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
5909 +               goto out;
5910 +       }
5911 +
5912         /* We're going to/from readonly mode. */
5913         if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
5914                 /* Disable quota accounting before remounting RO */
5915 @@ -1177,6 +1188,9 @@ static int ocfs2_fill_super(struct super
5916  
5917         ocfs2_complete_mount_recovery(osb);
5918  
5919 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
5920 +               sb->s_flags |= MS_TAGGED;
5921 +
5922         if (ocfs2_mount_local(osb))
5923                 snprintf(nodestr, sizeof(nodestr), "local");
5924         else
5925 @@ -1504,6 +1518,20 @@ static int ocfs2_parse_options(struct su
5926                             option < OCFS2_MAX_RESV_LEVEL)
5927                                 mopt->dir_resv_level = option;
5928                         break;
5929 +#ifndef CONFIG_TAGGING_NONE
5930 +               case Opt_tag:
5931 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5932 +                       break;
5933 +               case Opt_notag:
5934 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
5935 +                       break;
5936 +#endif
5937 +#ifdef CONFIG_PROPAGATE
5938 +               case Opt_tagid:
5939 +                       /* use args[0] */
5940 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5941 +                       break;
5942 +#endif
5943                 default:
5944                         mlog(ML_ERROR,
5945                              "Unrecognized mount option \"%s\" "
5946 diff -NurpP --minimal linux-3.9.4/fs/open.c linux-3.9.4-vs2.3.6.3/fs/open.c
5947 --- linux-3.9.4/fs/open.c       2013-05-31 13:45:25.000000000 +0000
5948 +++ linux-3.9.4-vs2.3.6.3/fs/open.c     2013-06-01 08:41:29.000000000 +0000
5949 @@ -31,6 +31,11 @@
5950  #include <linux/ima.h>
5951  #include <linux/dnotify.h>
5952  #include <linux/compat.h>
5953 +#include <linux/vs_base.h>
5954 +#include <linux/vs_limit.h>
5955 +#include <linux/vs_tag.h>
5956 +#include <linux/vs_cowbl.h>
5957 +#include <linux/vserver/dlimit.h>
5958  
5959  #include "internal.h"
5960  
5961 @@ -67,6 +72,11 @@ long vfs_truncate(struct path *path, lof
5962         struct inode *inode;
5963         long error;
5964  
5965 +#ifdef CONFIG_VSERVER_COWBL
5966 +       error = cow_check_and_break(path);
5967 +       if (error)
5968 +               goto out;
5969 +#endif
5970         inode = path->dentry->d_inode;
5971  
5972         /* For directories it's -EISDIR, for other non-regulars - -EINVAL */
5973 @@ -532,6 +542,13 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
5974         unsigned int lookup_flags = LOOKUP_FOLLOW;
5975  retry:
5976         error = user_path_at(dfd, filename, lookup_flags, &path);
5977 +#ifdef CONFIG_VSERVER_COWBL
5978 +       if (!error) {
5979 +               error = cow_check_and_break(&path);
5980 +               if (error)
5981 +                       path_put(&path);
5982 +       }
5983 +#endif
5984         if (!error) {
5985                 error = chmod_common(&path, mode);
5986                 path_put(&path);
5987 @@ -564,13 +581,15 @@ static int chown_common(struct path *pat
5988                 if (!uid_valid(uid))
5989                         return -EINVAL;
5990                 newattrs.ia_valid |= ATTR_UID;
5991 -               newattrs.ia_uid = uid;
5992 +               newattrs.ia_uid = make_kuid(&init_user_ns,
5993 +                       dx_map_uid(user));
5994         }
5995         if (group != (gid_t) -1) {
5996                 if (!gid_valid(gid))
5997                         return -EINVAL;
5998                 newattrs.ia_valid |= ATTR_GID;
5999 -               newattrs.ia_gid = gid;
6000 +               newattrs.ia_gid = make_kgid(&init_user_ns,
6001 +                       dx_map_gid(group));
6002         }
6003         if (!S_ISDIR(inode->i_mode))
6004                 newattrs.ia_valid |=
6005 @@ -604,6 +623,18 @@ retry:
6006         error = mnt_want_write(path.mnt);
6007         if (error)
6008                 goto out_release;
6009 +#ifdef CONFIG_VSERVER_COWBL
6010 +       error = cow_check_and_break(&path);
6011 +       if (!error)
6012 +#endif
6013 +#ifdef CONFIG_VSERVER_COWBL
6014 +       error = cow_check_and_break(&path);
6015 +       if (!error)
6016 +#endif
6017 +#ifdef CONFIG_VSERVER_COWBL
6018 +       error = cow_check_and_break(&path);
6019 +       if (!error)
6020 +#endif
6021         error = chown_common(&path, user, group);
6022         mnt_drop_write(path.mnt);
6023  out_release:
6024 diff -NurpP --minimal linux-3.9.4/fs/proc/array.c linux-3.9.4-vs2.3.6.3/fs/proc/array.c
6025 --- linux-3.9.4/fs/proc/array.c 2013-05-31 13:45:25.000000000 +0000
6026 +++ linux-3.9.4-vs2.3.6.3/fs/proc/array.c       2013-05-31 14:47:11.000000000 +0000
6027 @@ -82,6 +82,8 @@
6028  #include <linux/ptrace.h>
6029  #include <linux/tracehook.h>
6030  #include <linux/user_namespace.h>
6031 +#include <linux/vs_context.h>
6032 +#include <linux/vs_network.h>
6033  
6034  #include <asm/pgtable.h>
6035  #include <asm/processor.h>
6036 @@ -173,6 +175,9 @@ static inline void task_state(struct seq
6037         rcu_read_lock();
6038         ppid = pid_alive(p) ?
6039                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
6040 +       if (unlikely(vx_current_initpid(p->pid)))
6041 +               ppid = 0;
6042 +
6043         tpid = 0;
6044         if (pid_alive(p)) {
6045                 struct task_struct *tracer = ptrace_parent(p);
6046 @@ -297,7 +302,7 @@ static inline void task_sig(struct seq_f
6047  }
6048  
6049  static void render_cap_t(struct seq_file *m, const char *header,
6050 -                       kernel_cap_t *a)
6051 +                       struct vx_info *vxi, kernel_cap_t *a)
6052  {
6053         unsigned __capi;
6054  
6055 @@ -331,10 +336,11 @@ static inline void task_cap(struct seq_f
6056         NORM_CAPS(cap_effective);
6057         NORM_CAPS(cap_bset);
6058  
6059 -       render_cap_t(m, "CapInh:\t", &cap_inheritable);
6060 -       render_cap_t(m, "CapPrm:\t", &cap_permitted);
6061 -       render_cap_t(m, "CapEff:\t", &cap_effective);
6062 -       render_cap_t(m, "CapBnd:\t", &cap_bset);
6063 +       /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
6064 +       render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
6065 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
6066 +       render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
6067 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
6068  }
6069  
6070  static inline void task_seccomp(struct seq_file *m, struct task_struct *p)
6071 @@ -363,6 +369,42 @@ static void task_cpus_allowed(struct seq
6072         seq_putc(m, '\n');
6073  }
6074  
6075 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6076 +                       struct pid *pid, struct task_struct *task)
6077 +{
6078 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
6079 +                       "Count:\t%u\n"
6080 +                       "uts:\t%p(%c)\n"
6081 +                       "ipc:\t%p(%c)\n"
6082 +                       "mnt:\t%p(%c)\n"
6083 +                       "pid:\t%p(%c)\n"
6084 +                       "net:\t%p(%c)\n",
6085 +                       task->nsproxy,
6086 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6087 +                       atomic_read(&task->nsproxy->count),
6088 +                       task->nsproxy->uts_ns,
6089 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6090 +                       task->nsproxy->ipc_ns,
6091 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6092 +                       task->nsproxy->mnt_ns,
6093 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6094 +                       task->nsproxy->pid_ns,
6095 +                       (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
6096 +                       task->nsproxy->net_ns,
6097 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6098 +       return 0;
6099 +}
6100 +
6101 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6102 +{
6103 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6104 +               return;
6105 +
6106 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6107 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6108 +}
6109 +
6110 +
6111  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6112                         struct pid *pid, struct task_struct *task)
6113  {
6114 @@ -380,6 +422,7 @@ int proc_pid_status(struct seq_file *m,
6115         task_seccomp(m, task);
6116         task_cpus_allowed(m, task);
6117         cpuset_task_status_allowed(m, task);
6118 +       task_vs_id(m, task);
6119         task_context_switch_counts(m, task);
6120         return 0;
6121  }
6122 @@ -489,6 +532,17 @@ static int do_task_stat(struct seq_file
6123         /* convert nsec -> ticks */
6124         start_time = nsec_to_clock_t(start_time);
6125  
6126 +       /* fixup start time for virt uptime */
6127 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6128 +               unsigned long long bias =
6129 +                       current->vx_info->cvirt.bias_clock;
6130 +
6131 +               if (start_time > bias)
6132 +                       start_time -= bias;
6133 +               else
6134 +                       start_time = 0;
6135 +       }
6136 +
6137         seq_printf(m, "%d (%s) %c", pid_nr_ns(pid, ns), tcomm, state);
6138         seq_put_decimal_ll(m, ' ', ppid);
6139         seq_put_decimal_ll(m, ' ', pgid);
6140 diff -NurpP --minimal linux-3.9.4/fs/proc/base.c linux-3.9.4-vs2.3.6.3/fs/proc/base.c
6141 --- linux-3.9.4/fs/proc/base.c  2013-05-31 13:45:25.000000000 +0000
6142 +++ linux-3.9.4-vs2.3.6.3/fs/proc/base.c        2013-05-31 14:47:11.000000000 +0000
6143 @@ -86,6 +86,8 @@
6144  #include <linux/fs_struct.h>
6145  #include <linux/slab.h>
6146  #include <linux/flex_array.h>
6147 +#include <linux/vs_context.h>
6148 +#include <linux/vs_network.h>
6149  #ifdef CONFIG_HARDWALL
6150  #include <asm/hardwall.h>
6151  #endif
6152 @@ -944,11 +946,15 @@ static ssize_t oom_adj_write(struct file
6153                 oom_adj = (oom_adj * OOM_SCORE_ADJ_MAX) / -OOM_DISABLE;
6154  
6155         if (oom_adj < task->signal->oom_score_adj &&
6156 -           !capable(CAP_SYS_RESOURCE)) {
6157 +           !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
6158                 err = -EACCES;
6159                 goto err_sighand;
6160         }
6161  
6162 +       /* prevent guest processes from circumventing the oom killer */
6163 +       if (vx_current_xid() && (oom_adj == OOM_DISABLE))
6164 +               oom_adj = OOM_ADJUST_MIN;
6165 +
6166         /*
6167          * /proc/pid/oom_adj is provided for legacy purposes, ask users to use
6168          * /proc/pid/oom_score_adj instead.
6169 @@ -1528,6 +1534,8 @@ struct inode *proc_pid_make_inode(struct
6170                 inode->i_gid = cred->egid;
6171                 rcu_read_unlock();
6172         }
6173 +       /* procfs is xid tagged */
6174 +       i_tag_write(inode, (tag_t)vx_task_xid(task));
6175         security_task_to_inode(task, inode);
6176  
6177  out:
6178 @@ -1573,6 +1581,8 @@ int pid_getattr(struct vfsmount *mnt, st
6179  
6180  /* dentry stuff */
6181  
6182 +static unsigned name_to_int(struct dentry *dentry);
6183 +
6184  /*
6185   *     Exceptional case: normally we are not allowed to unhash a busy
6186   * directory. In this case, however, we can do it - no aliasing problems
6187 @@ -1601,6 +1611,12 @@ int pid_revalidate(struct dentry *dentry
6188         task = get_proc_task(inode);
6189  
6190         if (task) {
6191 +               unsigned pid = name_to_int(dentry);
6192 +
6193 +               if (pid != ~0U && pid != vx_map_pid(task->pid)) {
6194 +                       put_task_struct(task);
6195 +                       goto drop;
6196 +               }
6197                 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
6198                     task_dumpable(task)) {
6199                         rcu_read_lock();
6200 @@ -1617,6 +1633,7 @@ int pid_revalidate(struct dentry *dentry
6201                 put_task_struct(task);
6202                 return 1;
6203         }
6204 +drop:
6205         d_drop(dentry);
6206         return 0;
6207  }
6208 @@ -2059,6 +2076,13 @@ static struct dentry *proc_pident_lookup
6209         if (!task)
6210                 goto out_no_task;
6211  
6212 +       /* TODO: maybe we can come up with a generic approach? */
6213 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
6214 +               (dentry->d_name.len == 5) &&
6215 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
6216 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
6217 +               goto out;
6218 +
6219         /*
6220          * Yes, it does not scale. And it should not. Don't add
6221          * new entries into /proc/<tgid>/ without very good reasons.
6222 @@ -2493,6 +2517,9 @@ static int proc_pid_personality(struct s
6223  static const struct file_operations proc_task_operations;
6224  static const struct inode_operations proc_task_inode_operations;
6225  
6226 +extern int proc_pid_vx_info(struct task_struct *, char *);
6227 +extern int proc_pid_nx_info(struct task_struct *, char *);
6228 +
6229  static const struct pid_entry tgid_base_stuff[] = {
6230         DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
6231         DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
6232 @@ -2559,6 +2586,8 @@ static const struct pid_entry tgid_base_
6233  #ifdef CONFIG_CGROUPS
6234         REG("cgroup",  S_IRUGO, proc_cgroup_operations),
6235  #endif
6236 +       INF("vinfo",      S_IRUGO, proc_pid_vx_info),
6237 +       INF("ninfo",      S_IRUGO, proc_pid_nx_info),
6238         INF("oom_score",  S_IRUGO, proc_oom_score),
6239         REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adj_operations),
6240         REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations),
6241 @@ -2583,6 +2612,7 @@ static const struct pid_entry tgid_base_
6242         REG("gid_map",    S_IRUGO|S_IWUSR, proc_gid_map_operations),
6243         REG("projid_map", S_IRUGO|S_IWUSR, proc_projid_map_operations),
6244  #endif
6245 +       ONE("nsproxy",  S_IRUGO, proc_pid_nsproxy),
6246  };
6247  
6248  static int proc_tgid_base_readdir(struct file * filp,
6249 @@ -2770,7 +2800,7 @@ retry:
6250         iter.task = NULL;
6251         pid = find_ge_pid(iter.tgid, ns);
6252         if (pid) {
6253 -               iter.tgid = pid_nr_ns(pid, ns);
6254 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
6255                 iter.task = pid_task(pid, PIDTYPE_PID);
6256                 /* What we to know is if the pid we have find is the
6257                  * pid of a thread_group_leader.  Testing for task
6258 @@ -2800,7 +2830,7 @@ static int proc_pid_fill_cache(struct fi
6259         struct tgid_iter iter)
6260  {
6261         char name[PROC_NUMBUF];
6262 -       int len = snprintf(name, sizeof(name), "%d", iter.tgid);
6263 +       int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
6264         return proc_fill_cache(filp, dirent, filldir, name, len,
6265                                 proc_pid_instantiate, iter.task, NULL);
6266  }
6267 @@ -2833,6 +2863,8 @@ int proc_pid_readdir(struct file * filp,
6268                         __filldir = fake_filldir;
6269  
6270                 filp->f_pos = iter.tgid + TGID_OFFSET;
6271 +               if (!vx_proc_task_visible(iter.task))
6272 +                       continue;
6273                 if (proc_pid_fill_cache(filp, dirent, __filldir, iter) < 0) {
6274                         put_task_struct(iter.task);
6275                         goto out;
6276 @@ -2993,6 +3025,8 @@ static struct dentry *proc_task_lookup(s
6277         tid = name_to_int(dentry);
6278         if (tid == ~0U)
6279                 goto out;
6280 +       if (vx_current_initpid(tid))
6281 +               goto out;
6282  
6283         ns = dentry->d_sb->s_fs_info;
6284         rcu_read_lock();
6285 diff -NurpP --minimal linux-3.9.4/fs/proc/generic.c linux-3.9.4-vs2.3.6.3/fs/proc/generic.c
6286 --- linux-3.9.4/fs/proc/generic.c       2013-05-31 13:45:25.000000000 +0000
6287 +++ linux-3.9.4-vs2.3.6.3/fs/proc/generic.c     2013-05-31 16:13:42.000000000 +0000
6288 @@ -23,6 +23,7 @@
6289  #include <linux/bitops.h>
6290  #include <linux/spinlock.h>
6291  #include <linux/completion.h>
6292 +#include <linux/vserver/inode.h>
6293  #include <asm/uaccess.h>
6294  
6295  #include "internal.h"
6296 @@ -409,6 +410,8 @@ struct dentry *proc_lookup_de(struct pro
6297         for (de = de->subdir; de ; de = de->next) {
6298                 if (de->namelen != dentry->d_name.len)
6299                         continue;
6300 +               if (!vx_hide_check(0, de->vx_flags))
6301 +                       continue;
6302                 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
6303                         pde_get(de);
6304                         spin_unlock(&proc_subdir_lock);
6305 @@ -417,6 +420,8 @@ struct dentry *proc_lookup_de(struct pro
6306                                 return ERR_PTR(-ENOMEM);
6307                         d_set_d_op(dentry, &proc_dentry_operations);
6308                         d_add(dentry, inode);
6309 +                       /* generic proc entries belong to the host */
6310 +                       i_tag_write(inode, 0);
6311                         return NULL;
6312                 }
6313         }
6314 @@ -485,6 +490,8 @@ int proc_readdir_de(struct proc_dir_entr
6315  
6316                                 /* filldir passes info to user space */
6317                                 pde_get(de);
6318 +                               if (!vx_hide_check(0, de->vx_flags))
6319 +                                       goto skip;
6320                                 spin_unlock(&proc_subdir_lock);
6321                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
6322                                             de->low_ino, de->mode >> 12) < 0) {
6323 @@ -492,6 +499,7 @@ int proc_readdir_de(struct proc_dir_entr
6324                                         goto out;
6325                                 }
6326                                 spin_lock(&proc_subdir_lock);
6327 +                       skip:
6328                                 filp->f_pos++;
6329                                 next = de->next;
6330                                 pde_put(de);
6331 @@ -603,6 +611,7 @@ static struct proc_dir_entry *__proc_cre
6332         ent->namelen = len;
6333         ent->mode = mode;
6334         ent->nlink = nlink;
6335 +       ent->vx_flags = IATTR_PROC_DEFAULT;
6336         atomic_set(&ent->count, 1);
6337         spin_lock_init(&ent->pde_unload_lock);
6338         INIT_LIST_HEAD(&ent->pde_openers);
6339 @@ -626,7 +635,8 @@ struct proc_dir_entry *proc_symlink(cons
6340                                 kfree(ent->data);
6341                                 kfree(ent);
6342                                 ent = NULL;
6343 -                       }
6344 +                       } else
6345 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
6346                 } else {
6347                         kfree(ent);
6348                         ent = NULL;
6349 diff -NurpP --minimal linux-3.9.4/fs/proc/inode.c linux-3.9.4-vs2.3.6.3/fs/proc/inode.c
6350 --- linux-3.9.4/fs/proc/inode.c 2013-05-31 13:45:25.000000000 +0000
6351 +++ linux-3.9.4-vs2.3.6.3/fs/proc/inode.c       2013-05-31 14:47:11.000000000 +0000
6352 @@ -458,6 +458,8 @@ struct inode *proc_get_inode(struct supe
6353                         inode->i_uid = de->uid;
6354                         inode->i_gid = de->gid;
6355                 }
6356 +               if (de->vx_flags)
6357 +                       PROC_I(inode)->vx_flags = de->vx_flags;
6358                 if (de->size)
6359                         inode->i_size = de->size;
6360                 if (de->nlink)
6361 diff -NurpP --minimal linux-3.9.4/fs/proc/internal.h linux-3.9.4-vs2.3.6.3/fs/proc/internal.h
6362 --- linux-3.9.4/fs/proc/internal.h      2013-05-31 13:45:25.000000000 +0000
6363 +++ linux-3.9.4-vs2.3.6.3/fs/proc/internal.h    2013-05-31 16:04:34.000000000 +0000
6364 @@ -12,6 +12,8 @@
6365  #include <linux/sched.h>
6366  #include <linux/proc_fs.h>
6367  #include <linux/binfmts.h>
6368 +#include <linux/vs_pid.h>
6369 +
6370  struct  ctl_table_header;
6371  struct  mempolicy;
6372  
6373 @@ -56,6 +58,9 @@ extern int proc_pid_status(struct seq_fi
6374                                 struct pid *pid, struct task_struct *task);
6375  extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
6376                                 struct pid *pid, struct task_struct *task);
6377 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6378 +                               struct pid *pid, struct task_struct *task);
6379 +
6380  extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
6381  
6382  extern const struct file_operations proc_tid_children_operations;
6383 @@ -89,11 +94,16 @@ static inline struct pid *proc_pid(struc
6384         return PROC_I(inode)->pid;
6385  }
6386  
6387 -static inline struct task_struct *get_proc_task(struct inode *inode)
6388 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
6389  {
6390         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
6391  }
6392  
6393 +static inline struct task_struct *get_proc_task(struct inode *inode)
6394 +{
6395 +       return vx_get_proc_task(inode, proc_pid(inode));
6396 +}
6397 +
6398  static inline int proc_fd(struct inode *inode)
6399  {
6400         return PROC_I(inode)->fd;
6401 diff -NurpP --minimal linux-3.9.4/fs/proc/loadavg.c linux-3.9.4-vs2.3.6.3/fs/proc/loadavg.c
6402 --- linux-3.9.4/fs/proc/loadavg.c       2012-12-11 03:30:57.000000000 +0000
6403 +++ linux-3.9.4-vs2.3.6.3/fs/proc/loadavg.c     2013-05-31 14:47:11.000000000 +0000
6404 @@ -12,15 +12,27 @@
6405  
6406  static int loadavg_proc_show(struct seq_file *m, void *v)
6407  {
6408 +       unsigned long running;
6409 +       unsigned int threads;
6410         unsigned long avnrun[3];
6411  
6412         get_avenrun(avnrun, FIXED_1/200, 0);
6413  
6414 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
6415 +               struct vx_info *vxi = current_vx_info();
6416 +
6417 +               running = atomic_read(&vxi->cvirt.nr_running);
6418 +               threads = atomic_read(&vxi->cvirt.nr_threads);
6419 +       } else {
6420 +               running = nr_running();
6421 +               threads = nr_threads;
6422 +       }
6423 +
6424         seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
6425                 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
6426                 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
6427                 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
6428 -               nr_running(), nr_threads,
6429 +               running, threads,
6430                 task_active_pid_ns(current)->last_pid);
6431         return 0;
6432  }
6433 diff -NurpP --minimal linux-3.9.4/fs/proc/meminfo.c linux-3.9.4-vs2.3.6.3/fs/proc/meminfo.c
6434 --- linux-3.9.4/fs/proc/meminfo.c       2013-05-31 13:45:25.000000000 +0000
6435 +++ linux-3.9.4-vs2.3.6.3/fs/proc/meminfo.c     2013-05-31 16:05:39.000000000 +0000
6436 @@ -39,7 +39,8 @@ static int meminfo_proc_show(struct seq_
6437         allowed = ((totalram_pages - hugetlb_total_pages())
6438                 * sysctl_overcommit_ratio / 100) + total_swap_pages;
6439  
6440 -       cached = global_page_state(NR_FILE_PAGES) -
6441 +       cached = vx_flags(VXF_VIRT_MEM, 0) ?
6442 +               vx_vsi_cached(&i) : global_page_state(NR_FILE_PAGES) -
6443                         total_swapcache_pages() - i.bufferram;
6444         if (cached < 0)
6445                 cached = 0;
6446 diff -NurpP --minimal linux-3.9.4/fs/proc/root.c linux-3.9.4-vs2.3.6.3/fs/proc/root.c
6447 --- linux-3.9.4/fs/proc/root.c  2013-05-31 13:45:25.000000000 +0000
6448 +++ linux-3.9.4-vs2.3.6.3/fs/proc/root.c        2013-05-31 14:47:11.000000000 +0000
6449 @@ -20,9 +20,14 @@
6450  #include <linux/mount.h>
6451  #include <linux/pid_namespace.h>
6452  #include <linux/parser.h>
6453 +#include <linux/vserver/inode.h>
6454  
6455  #include "internal.h"
6456  
6457 +struct proc_dir_entry *proc_virtual;
6458 +
6459 +extern void proc_vx_init(void);
6460 +
6461  static int proc_test_super(struct super_block *sb, void *data)
6462  {
6463         return sb->s_fs_info == data;
6464 @@ -182,6 +187,7 @@ void __init proc_root_init(void)
6465  #endif
6466         proc_mkdir("bus", NULL);
6467         proc_sys_init();
6468 +       proc_vx_init();
6469  }
6470  
6471  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
6472 @@ -248,6 +254,7 @@ struct proc_dir_entry proc_root = {
6473         .proc_iops      = &proc_root_inode_operations, 
6474         .proc_fops      = &proc_root_operations,
6475         .parent         = &proc_root,
6476 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
6477         .name           = "/proc",
6478  };
6479  
6480 diff -NurpP --minimal linux-3.9.4/fs/proc/self.c linux-3.9.4-vs2.3.6.3/fs/proc/self.c
6481 --- linux-3.9.4/fs/proc/self.c  2013-02-19 13:58:49.000000000 +0000
6482 +++ linux-3.9.4-vs2.3.6.3/fs/proc/self.c        2013-05-31 20:57:54.000000000 +0000
6483 @@ -1,6 +1,7 @@
6484  #include <linux/proc_fs.h>
6485  #include <linux/sched.h>
6486  #include <linux/namei.h>
6487 +#include <linux/vserver/inode.h>
6488  
6489  /*
6490   * /proc/self:
6491 @@ -56,4 +57,5 @@ void __init proc_self_init(void)
6492         mode = S_IFLNK | S_IRWXUGO;
6493         proc_self_symlink = proc_create("self", mode, NULL, NULL );
6494         proc_self_symlink->proc_iops = &proc_self_inode_operations;
6495 +       proc_self_symlink->vx_flags = IATTR_PROC_SYMLINK;
6496  }
6497 diff -NurpP --minimal linux-3.9.4/fs/proc/stat.c linux-3.9.4-vs2.3.6.3/fs/proc/stat.c
6498 --- linux-3.9.4/fs/proc/stat.c  2012-12-11 03:30:57.000000000 +0000
6499 +++ linux-3.9.4-vs2.3.6.3/fs/proc/stat.c        2013-05-31 14:47:11.000000000 +0000
6500 @@ -9,8 +9,10 @@
6501  #include <linux/slab.h>
6502  #include <linux/time.h>
6503  #include <linux/irqnr.h>
6504 +#include <linux/vserver/cvirt.h>
6505  #include <asm/cputime.h>
6506  #include <linux/tick.h>
6507 +#include <linux/cpuset.h>
6508  
6509  #ifndef arch_irq_stat_cpu
6510  #define arch_irq_stat_cpu(cpu) 0
6511 @@ -87,14 +89,26 @@ static int show_stat(struct seq_file *p,
6512         u64 sum_softirq = 0;
6513         unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
6514         struct timespec boottime;
6515 +       cpumask_var_t cpus_allowed;
6516 +       bool virt_cpu = vx_flags(VXF_VIRT_CPU, 0);
6517  
6518         user = nice = system = idle = iowait =
6519                 irq = softirq = steal = 0;
6520         guest = guest_nice = 0;
6521         getboottime(&boottime);
6522 +
6523 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6524 +               vx_vsi_boottime(&boottime);
6525 +
6526 +       if (virt_cpu)
6527 +               cpuset_cpus_allowed(current, cpus_allowed);
6528 +
6529         jif = boottime.tv_sec;
6530  
6531         for_each_possible_cpu(i) {
6532 +               if (virt_cpu && !cpumask_test_cpu(i, cpus_allowed))
6533 +                       continue;
6534 +
6535                 user += kcpustat_cpu(i).cpustat[CPUTIME_USER];
6536                 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
6537                 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
6538 @@ -131,6 +145,9 @@ static int show_stat(struct seq_file *p,
6539         seq_putc(p, '\n');
6540  
6541         for_each_online_cpu(i) {
6542 +               if (virt_cpu && !cpumask_test_cpu(i, cpus_allowed))
6543 +                       continue;
6544 +
6545                 /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
6546                 user = kcpustat_cpu(i).cpustat[CPUTIME_USER];
6547                 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
6548 diff -NurpP --minimal linux-3.9.4/fs/proc/uptime.c linux-3.9.4-vs2.3.6.3/fs/proc/uptime.c
6549 --- linux-3.9.4/fs/proc/uptime.c        2012-12-11 03:30:57.000000000 +0000
6550 +++ linux-3.9.4-vs2.3.6.3/fs/proc/uptime.c      2013-05-31 14:47:11.000000000 +0000
6551 @@ -5,6 +5,7 @@
6552  #include <linux/seq_file.h>
6553  #include <linux/time.h>
6554  #include <linux/kernel_stat.h>
6555 +#include <linux/vserver/cvirt.h>
6556  #include <asm/cputime.h>
6557  
6558  static int uptime_proc_show(struct seq_file *m, void *v)
6559 @@ -25,6 +26,10 @@ static int uptime_proc_show(struct seq_f
6560         nsec = cputime64_to_jiffies64(idletime) * TICK_NSEC;
6561         idle.tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem);
6562         idle.tv_nsec = rem;
6563 +
6564 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6565 +               vx_vsi_uptime(&uptime, &idle);
6566 +
6567         seq_printf(m, "%lu.%02lu %lu.%02lu\n",
6568                         (unsigned long) uptime.tv_sec,
6569                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
6570 diff -NurpP --minimal linux-3.9.4/fs/proc_namespace.c linux-3.9.4-vs2.3.6.3/fs/proc_namespace.c
6571 --- linux-3.9.4/fs/proc_namespace.c     2012-12-11 03:30:57.000000000 +0000
6572 +++ linux-3.9.4-vs2.3.6.3/fs/proc_namespace.c   2013-05-31 17:17:53.000000000 +0000
6573 @@ -44,6 +44,8 @@ static int show_sb_opts(struct seq_file
6574                 { MS_SYNCHRONOUS, ",sync" },
6575                 { MS_DIRSYNC, ",dirsync" },
6576                 { MS_MANDLOCK, ",mand" },
6577 +               { MS_TAGGED, ",tag" },
6578 +               { MS_NOTAGCHECK, ",notagcheck" },
6579                 { 0, NULL }
6580         };
6581         const struct proc_fs_info *fs_infop;
6582 @@ -80,6 +82,40 @@ static inline void mangle(struct seq_fil
6583         seq_escape(m, s, " \t\n\\");
6584  }
6585  
6586 +#ifdef CONFIG_VSERVER_EXTRA_MNT_CHECK
6587 +
6588 +static int mnt_is_reachable(struct vfsmount *vfsmnt)
6589 +{
6590 +       struct path root;
6591 +       struct dentry *point;
6592 +       struct mount *mnt = real_mount(vfsmnt);
6593 +       struct mount *root_mnt;
6594 +       int ret;
6595 +
6596 +       if (mnt == mnt->mnt_ns->root)
6597 +               return 1;
6598 +
6599 +       br_read_lock(&vfsmount_lock);
6600 +       root = current->fs->root;
6601 +       root_mnt = real_mount(root.mnt);
6602 +       point = root.dentry;
6603 +
6604 +       while ((mnt != mnt->mnt_parent) && (mnt != root_mnt)) {
6605 +               point = mnt->mnt_mountpoint;
6606 +               mnt = mnt->mnt_parent;
6607 +       }
6608 +
6609 +       ret = (mnt == root_mnt) && is_subdir(point, root.dentry);
6610 +
6611 +       br_read_unlock(&vfsmount_lock);
6612 +
6613 +       return ret;
6614 +}
6615 +
6616 +#else
6617 +#define        mnt_is_reachable(v)     (1)
6618 +#endif
6619 +
6620  static void show_type(struct seq_file *m, struct super_block *sb)
6621  {
6622         mangle(m, sb->s_type->name);
6623 @@ -96,6 +132,17 @@ static int show_vfsmnt(struct seq_file *
6624         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
6625         struct super_block *sb = mnt_path.dentry->d_sb;
6626  
6627 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6628 +               return SEQ_SKIP;
6629 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6630 +               return SEQ_SKIP;
6631 +
6632 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6633 +               mnt == current->fs->root.mnt) {
6634 +               seq_puts(m, "/dev/root / ");
6635 +               goto type;
6636 +       }
6637 +
6638         if (sb->s_op->show_devname) {
6639                 err = sb->s_op->show_devname(m, mnt_path.dentry);
6640                 if (err)
6641 @@ -106,6 +153,7 @@ static int show_vfsmnt(struct seq_file *
6642         seq_putc(m, ' ');
6643         seq_path(m, &mnt_path, " \t\n\\");
6644         seq_putc(m, ' ');
6645 +type:
6646         show_type(m, sb);
6647         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
6648         err = show_sb_opts(m, sb);
6649 @@ -128,6 +176,11 @@ static int show_mountinfo(struct seq_fil
6650         struct path root = p->root;
6651         int err = 0;
6652  
6653 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6654 +               return SEQ_SKIP;
6655 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6656 +               return SEQ_SKIP;
6657 +
6658         seq_printf(m, "%i %i %u:%u ", r->mnt_id, r->mnt_parent->mnt_id,
6659                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
6660         if (sb->s_op->show_path)
6661 @@ -187,6 +240,17 @@ static int show_vfsstat(struct seq_file
6662         struct super_block *sb = mnt_path.dentry->d_sb;
6663         int err = 0;
6664  
6665 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6666 +               return SEQ_SKIP;
6667 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6668 +               return SEQ_SKIP;
6669 +
6670 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6671 +               mnt == current->fs->root.mnt) {
6672 +               seq_puts(m, "device /dev/root mounted on / ");
6673 +               goto type;
6674 +       }
6675 +
6676         /* device */
6677         if (sb->s_op->show_devname) {
6678                 seq_puts(m, "device ");
6679 @@ -203,7 +267,7 @@ static int show_vfsstat(struct seq_file
6680         seq_puts(m, " mounted on ");
6681         seq_path(m, &mnt_path, " \t\n\\");
6682         seq_putc(m, ' ');
6683 -
6684 +type:
6685         /* file system type */
6686         seq_puts(m, "with fstype ");
6687         show_type(m, sb);
6688 diff -NurpP --minimal linux-3.9.4/fs/quota/dquot.c linux-3.9.4-vs2.3.6.3/fs/quota/dquot.c
6689 --- linux-3.9.4/fs/quota/dquot.c        2013-05-31 13:45:25.000000000 +0000
6690 +++ linux-3.9.4-vs2.3.6.3/fs/quota/dquot.c      2013-05-31 14:47:11.000000000 +0000
6691 @@ -1585,6 +1585,9 @@ int __dquot_alloc_space(struct inode *in
6692         struct dquot **dquots = inode->i_dquot;
6693         int reserve = flags & DQUOT_SPACE_RESERVE;
6694  
6695 +       if ((ret = dl_alloc_space(inode, number)))
6696 +               return ret;
6697 +
6698         /*
6699          * First test before acquiring mutex - solves deadlocks when we
6700          * re-enter the quota code and are already holding the mutex
6701 @@ -1640,6 +1643,9 @@ int dquot_alloc_inode(const struct inode
6702         struct dquot_warn warn[MAXQUOTAS];
6703         struct dquot * const *dquots = inode->i_dquot;
6704  
6705 +       if ((ret = dl_alloc_inode(inode)))
6706 +               return ret;
6707 +
6708         /* First test before acquiring mutex - solves deadlocks when we
6709           * re-enter the quota code and are already holding the mutex */
6710         if (!dquot_active(inode))
6711 @@ -1711,6 +1717,8 @@ void __dquot_free_space(struct inode *in
6712         struct dquot **dquots = inode->i_dquot;
6713         int reserve = flags & DQUOT_SPACE_RESERVE;
6714  
6715 +       dl_free_space(inode, number);
6716 +
6717         /* First test before acquiring mutex - solves deadlocks when we
6718           * re-enter the quota code and are already holding the mutex */
6719         if (!dquot_active(inode)) {
6720 @@ -1755,6 +1763,8 @@ void dquot_free_inode(const struct inode
6721         struct dquot_warn warn[MAXQUOTAS];
6722         struct dquot * const *dquots = inode->i_dquot;
6723  
6724 +       dl_free_inode(inode);
6725 +
6726         /* First test before acquiring mutex - solves deadlocks when we
6727           * re-enter the quota code and are already holding the mutex */
6728         if (!dquot_active(inode))
6729 diff -NurpP --minimal linux-3.9.4/fs/quota/quota.c linux-3.9.4-vs2.3.6.3/fs/quota/quota.c
6730 --- linux-3.9.4/fs/quota/quota.c        2013-02-19 13:58:49.000000000 +0000
6731 +++ linux-3.9.4-vs2.3.6.3/fs/quota/quota.c      2013-05-31 14:47:11.000000000 +0000
6732 @@ -8,6 +8,7 @@
6733  #include <linux/fs.h>
6734  #include <linux/namei.h>
6735  #include <linux/slab.h>
6736 +#include <linux/vs_context.h>
6737  #include <asm/current.h>
6738  #include <linux/uaccess.h>
6739  #include <linux/kernel.h>
6740 @@ -37,7 +38,7 @@ static int check_quotactl_permission(str
6741                         break;
6742                 /*FALLTHROUGH*/
6743         default:
6744 -               if (!capable(CAP_SYS_ADMIN))
6745 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
6746                         return -EPERM;
6747         }
6748  
6749 @@ -309,6 +310,46 @@ static int do_quotactl(struct super_bloc
6750  
6751  #ifdef CONFIG_BLOCK
6752  
6753 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6754 +
6755 +#include <linux/vroot.h>
6756 +#include <linux/major.h>
6757 +#include <linux/module.h>
6758 +#include <linux/kallsyms.h>
6759 +#include <linux/vserver/debug.h>
6760 +
6761 +static vroot_grb_func *vroot_get_real_bdev = NULL;
6762 +
6763 +static DEFINE_SPINLOCK(vroot_grb_lock);
6764 +
6765 +int register_vroot_grb(vroot_grb_func *func) {
6766 +       int ret = -EBUSY;
6767 +
6768 +       spin_lock(&vroot_grb_lock);
6769 +       if (!vroot_get_real_bdev) {
6770 +               vroot_get_real_bdev = func;
6771 +               ret = 0;
6772 +       }
6773 +       spin_unlock(&vroot_grb_lock);
6774 +       return ret;
6775 +}
6776 +EXPORT_SYMBOL(register_vroot_grb);
6777 +
6778 +int unregister_vroot_grb(vroot_grb_func *func) {
6779 +       int ret = -EINVAL;
6780 +
6781 +       spin_lock(&vroot_grb_lock);
6782 +       if (vroot_get_real_bdev) {
6783 +               vroot_get_real_bdev = NULL;
6784 +               ret = 0;
6785 +       }
6786 +       spin_unlock(&vroot_grb_lock);
6787 +       return ret;
6788 +}
6789 +EXPORT_SYMBOL(unregister_vroot_grb);
6790 +
6791 +#endif
6792 +
6793  /* Return 1 if 'cmd' will block on frozen filesystem */
6794  static int quotactl_cmd_write(int cmd)
6795  {
6796 @@ -343,6 +384,22 @@ static struct super_block *quotactl_bloc
6797         putname(tmp);
6798         if (IS_ERR(bdev))
6799                 return ERR_CAST(bdev);
6800 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6801 +       if (bdev && bdev->bd_inode &&
6802 +               imajor(bdev->bd_inode) == VROOT_MAJOR) {
6803 +               struct block_device *bdnew = (void *)-EINVAL;
6804 +
6805 +               if (vroot_get_real_bdev)
6806 +                       bdnew = vroot_get_real_bdev(bdev);
6807 +               else
6808 +                       vxdprintk(VXD_CBIT(misc, 0),
6809 +                                       "vroot_get_real_bdev not set");
6810 +               bdput(bdev);
6811 +               if (IS_ERR(bdnew))
6812 +                       return ERR_PTR(PTR_ERR(bdnew));
6813 +               bdev = bdnew;
6814 +       }
6815 +#endif
6816         if (quotactl_cmd_write(cmd))
6817                 sb = get_super_thawed(bdev);
6818         else
6819 diff -NurpP --minimal linux-3.9.4/fs/stat.c linux-3.9.4-vs2.3.6.3/fs/stat.c
6820 --- linux-3.9.4/fs/stat.c       2013-05-31 13:45:25.000000000 +0000
6821 +++ linux-3.9.4-vs2.3.6.3/fs/stat.c     2013-06-01 08:53:01.000000000 +0000
6822 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
6823         stat->nlink = inode->i_nlink;
6824         stat->uid = inode->i_uid;
6825         stat->gid = inode->i_gid;
6826 +       stat->tag = inode->i_tag;
6827         stat->rdev = inode->i_rdev;
6828         stat->size = i_size_read(inode);
6829         stat->atime = inode->i_atime;
6830 diff -NurpP --minimal linux-3.9.4/fs/statfs.c linux-3.9.4-vs2.3.6.3/fs/statfs.c
6831 --- linux-3.9.4/fs/statfs.c     2013-02-19 13:58:49.000000000 +0000
6832 +++ linux-3.9.4-vs2.3.6.3/fs/statfs.c   2013-05-31 14:47:11.000000000 +0000
6833 @@ -7,6 +7,8 @@
6834  #include <linux/statfs.h>
6835  #include <linux/security.h>
6836  #include <linux/uaccess.h>
6837 +#include <linux/vs_base.h>
6838 +#include <linux/vs_dlimit.h>
6839  #include "internal.h"
6840  
6841  static int flags_by_mnt(int mnt_flags)
6842 @@ -60,6 +62,8 @@ static int statfs_by_dentry(struct dentr
6843         retval = dentry->d_sb->s_op->statfs(dentry, buf);
6844         if (retval == 0 && buf->f_frsize == 0)
6845                 buf->f_frsize = buf->f_bsize;
6846 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
6847 +               vx_vsi_statfs(dentry->d_sb, buf);
6848         return retval;
6849  }
6850  
6851 diff -NurpP --minimal linux-3.9.4/fs/super.c linux-3.9.4-vs2.3.6.3/fs/super.c
6852 --- linux-3.9.4/fs/super.c      2013-05-31 13:45:25.000000000 +0000
6853 +++ linux-3.9.4-vs2.3.6.3/fs/super.c    2013-05-31 14:47:11.000000000 +0000
6854 @@ -34,6 +34,8 @@
6855  #include <linux/cleancache.h>
6856  #include <linux/fsnotify.h>
6857  #include <linux/lockdep.h>
6858 +#include <linux/magic.h>
6859 +#include <linux/vs_context.h>
6860  #include "internal.h"
6861  
6862  
6863 @@ -1117,6 +1119,13 @@ mount_fs(struct file_system_type *type,
6864         WARN_ON(sb->s_bdi == &default_backing_dev_info);
6865         sb->s_flags |= MS_BORN;
6866  
6867 +       error = -EPERM;
6868 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) &&
6869 +               !sb->s_bdev &&
6870 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
6871 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
6872 +               goto out_sb;
6873 +
6874         error = security_sb_kern_mount(sb, flags, secdata);
6875         if (error)
6876                 goto out_sb;
6877 diff -NurpP --minimal linux-3.9.4/fs/sysfs/mount.c linux-3.9.4-vs2.3.6.3/fs/sysfs/mount.c
6878 --- linux-3.9.4/fs/sysfs/mount.c        2013-05-31 13:45:25.000000000 +0000
6879 +++ linux-3.9.4-vs2.3.6.3/fs/sysfs/mount.c      2013-05-31 14:47:11.000000000 +0000
6880 @@ -48,7 +48,7 @@ static int sysfs_fill_super(struct super
6881  
6882         sb->s_blocksize = PAGE_CACHE_SIZE;
6883         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
6884 -       sb->s_magic = SYSFS_MAGIC;
6885 +       sb->s_magic = SYSFS_SUPER_MAGIC;
6886         sb->s_op = &sysfs_ops;
6887         sb->s_time_gran = 1;
6888  
6889 diff -NurpP --minimal linux-3.9.4/fs/utimes.c linux-3.9.4-vs2.3.6.3/fs/utimes.c
6890 --- linux-3.9.4/fs/utimes.c     2013-02-19 13:58:49.000000000 +0000
6891 +++ linux-3.9.4-vs2.3.6.3/fs/utimes.c   2013-05-31 22:40:16.000000000 +0000
6892 @@ -8,6 +8,8 @@
6893  #include <linux/stat.h>
6894  #include <linux/utime.h>
6895  #include <linux/syscalls.h>
6896 +#include <linux/mount.h>
6897 +#include <linux/vs_cowbl.h>
6898  #include <asm/uaccess.h>
6899  #include <asm/unistd.h>
6900  
6901 @@ -52,12 +54,18 @@ static int utimes_common(struct path *pa
6902  {
6903         int error;
6904         struct iattr newattrs;
6905 -       struct inode *inode = path->dentry->d_inode;
6906 +       struct inode *inode;
6907 +
6908 +       error = cow_check_and_break(path);
6909 +       if (error)
6910 +               goto out;
6911  
6912         error = mnt_want_write(path->mnt);
6913         if (error)
6914                 goto out;
6915  
6916 +       inode = path->dentry->d_inode;
6917 +
6918         if (times && times[0].tv_nsec == UTIME_NOW &&
6919                      times[1].tv_nsec == UTIME_NOW)
6920                 times = NULL;
6921 diff -NurpP --minimal linux-3.9.4/fs/xattr.c linux-3.9.4-vs2.3.6.3/fs/xattr.c
6922 --- linux-3.9.4/fs/xattr.c      2013-02-19 13:58:49.000000000 +0000
6923 +++ linux-3.9.4-vs2.3.6.3/fs/xattr.c    2013-05-31 14:47:11.000000000 +0000
6924 @@ -21,6 +21,7 @@
6925  #include <linux/audit.h>
6926  #include <linux/vmalloc.h>
6927  #include <linux/posix_acl_xattr.h>
6928 +#include <linux/mount.h>
6929  
6930  #include <asm/uaccess.h>
6931  
6932 @@ -52,7 +53,7 @@ xattr_permission(struct inode *inode, co
6933          * The trusted.* namespace can only be accessed by privileged users.
6934          */
6935         if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN)) {
6936 -               if (!capable(CAP_SYS_ADMIN))
6937 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_FS_TRUSTED))
6938                         return (mask & MAY_WRITE) ? -EPERM : -ENODATA;
6939                 return 0;
6940         }
6941 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_dinode.h linux-3.9.4-vs2.3.6.3/fs/xfs/xfs_dinode.h
6942 --- linux-3.9.4/fs/xfs/xfs_dinode.h     2012-12-11 03:30:57.000000000 +0000
6943 +++ linux-3.9.4-vs2.3.6.3/fs/xfs/xfs_dinode.h   2013-05-31 14:47:11.000000000 +0000
6944 @@ -51,7 +51,9 @@ typedef struct xfs_dinode {
6945         __be32          di_nlink;       /* number of links to file */
6946         __be16          di_projid_lo;   /* lower part of owner's project id */
6947         __be16          di_projid_hi;   /* higher part owner's project id */
6948 -       __u8            di_pad[6];      /* unused, zeroed space */
6949 +       __u8            di_pad[2];      /* unused, zeroed space */
6950 +       __be16          di_tag;         /* context tagging */
6951 +       __be16          di_vflags;      /* vserver specific flags */
6952         __be16          di_flushiter;   /* incremented on flush */
6953         xfs_timestamp_t di_atime;       /* time last accessed */
6954         xfs_timestamp_t di_mtime;       /* time last modified */
6955 @@ -184,6 +186,8 @@ static inline void xfs_dinode_put_rdev(s
6956  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
6957  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
6958  #define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
6959 +#define XFS_DIFLAG_IXUNLINK_BIT     15 /* Immutable inver on unlink */
6960 +
6961  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
6962  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
6963  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
6964 @@ -199,6 +203,7 @@ static inline void xfs_dinode_put_rdev(s
6965  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
6966  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
6967  #define XFS_DIFLAG_FILESTREAM    (1 << XFS_DIFLAG_FILESTREAM_BIT)
6968 +#define XFS_DIFLAG_IXUNLINK      (1 << XFS_DIFLAG_IXUNLINK_BIT)
6969  
6970  #ifdef CONFIG_XFS_RT
6971  #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
6972 @@ -211,6 +216,10 @@ static inline void xfs_dinode_put_rdev(s
6973          XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
6974          XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
6975          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
6976 -        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
6977 +        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM | \
6978 +        XFS_DIFLAG_IXUNLINK)
6979 +
6980 +#define XFS_DIVFLAG_BARRIER    0x01
6981 +#define XFS_DIVFLAG_COW                0x02
6982  
6983  #endif /* __XFS_DINODE_H__ */
6984 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_fs.h linux-3.9.4-vs2.3.6.3/fs/xfs/xfs_fs.h
6985 --- linux-3.9.4/fs/xfs/xfs_fs.h 2013-02-19 13:58:49.000000000 +0000
6986 +++ linux-3.9.4-vs2.3.6.3/fs/xfs/xfs_fs.h       2013-05-31 14:47:11.000000000 +0000
6987 @@ -67,6 +67,9 @@ struct fsxattr {
6988  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
6989  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
6990  #define XFS_XFLAG_FILESTREAM   0x00004000      /* use filestream allocator */
6991 +#define XFS_XFLAG_IXUNLINK     0x00008000      /* immutable invert on unlink */
6992 +#define XFS_XFLAG_BARRIER      0x10000000      /* chroot() barrier */
6993 +#define XFS_XFLAG_COW          0x20000000      /* copy on write mark */
6994  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
6995  
6996  /*
6997 @@ -303,7 +306,8 @@ typedef struct xfs_bstat {
6998  #define        bs_projid       bs_projid_lo    /* (previously just bs_projid)  */
6999         __u16           bs_forkoff;     /* inode fork offset in bytes   */
7000         __u16           bs_projid_hi;   /* higher part of project id    */
7001 -       unsigned char   bs_pad[10];     /* pad space, unused            */
7002 +       unsigned char   bs_pad[8];      /* pad space, unused            */
7003 +       __u16           bs_tag;         /* context tagging              */
7004         __u32           bs_dmevmask;    /* DMIG event mask              */
7005         __u16           bs_dmstate;     /* DMIG state info              */
7006         __u16           bs_aextents;    /* attribute number of extents  */
7007 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_ialloc.c linux-3.9.4-vs2.3.6.3/fs/xfs/xfs_ialloc.c
7008 --- linux-3.9.4/fs/xfs/xfs_ialloc.c     2013-05-31 13:45:25.000000000 +0000
7009 +++ linux-3.9.4-vs2.3.6.3/fs/xfs/xfs_ialloc.c   2013-05-31 14:47:11.000000000 +0000
7010 @@ -37,7 +37,6 @@
7011  #include "xfs_error.h"
7012  #include "xfs_bmap.h"
7013  
7014 -
7015  /*
7016   * Allocation group level functions.
7017   */
7018 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_inode.c linux-3.9.4-vs2.3.6.3/fs/xfs/xfs_inode.c
7019 --- linux-3.9.4/fs/xfs/xfs_inode.c      2013-05-31 13:45:25.000000000 +0000
7020 +++ linux-3.9.4-vs2.3.6.3/fs/xfs/xfs_inode.c    2013-06-03 19:35:13.000000000 +0000
7021 @@ -16,6 +16,7 @@
7022   * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
7023   */
7024  #include <linux/log2.h>
7025 +#include <linux/vs_tag.h>
7026  
7027  #include "xfs.h"
7028  #include "xfs_fs.h"
7029 @@ -835,15 +836,25 @@ xfs_iformat_btree(
7030  STATIC void
7031  xfs_dinode_from_disk(
7032         xfs_icdinode_t          *to,
7033 -       xfs_dinode_t            *from)
7034 +       xfs_dinode_t            *from,
7035 +       int                     tagged)
7036  {
7037 +       uint32_t uid, gid, tag;
7038 +
7039         to->di_magic = be16_to_cpu(from->di_magic);
7040         to->di_mode = be16_to_cpu(from->di_mode);
7041         to->di_version = from ->di_version;
7042         to->di_format = from->di_format;
7043         to->di_onlink = be16_to_cpu(from->di_onlink);
7044 -       to->di_uid = be32_to_cpu(from->di_uid);
7045 -       to->di_gid = be32_to_cpu(from->di_gid);
7046 +
7047 +       uid = be32_to_cpu(from->di_uid);
7048 +       gid = be32_to_cpu(from->di_gid);
7049 +       tag = be16_to_cpu(from->di_tag);
7050 +
7051 +       to->di_uid = INOTAG_UID(tagged, uid, gid);
7052 +       to->di_gid = INOTAG_GID(tagged, uid, gid);
7053 +       to->di_tag = INOTAG_TAG(tagged, uid, gid, tag);
7054 +
7055         to->di_nlink = be32_to_cpu(from->di_nlink);
7056         to->di_projid_lo = be16_to_cpu(from->di_projid_lo);
7057         to->di_projid_hi = be16_to_cpu(from->di_projid_hi);
7058 @@ -865,21 +876,26 @@ xfs_dinode_from_disk(
7059         to->di_dmevmask = be32_to_cpu(from->di_dmevmask);
7060         to->di_dmstate  = be16_to_cpu(from->di_dmstate);
7061         to->di_flags    = be16_to_cpu(from->di_flags);
7062 +       to->di_vflags   = be16_to_cpu(from->di_vflags);
7063         to->di_gen      = be32_to_cpu(from->di_gen);
7064  }
7065  
7066  void
7067  xfs_dinode_to_disk(
7068         xfs_dinode_t            *to,
7069 -       xfs_icdinode_t          *from)
7070 +       xfs_icdinode_t          *from,
7071 +       int                     tagged)
7072  {
7073         to->di_magic = cpu_to_be16(from->di_magic);
7074         to->di_mode = cpu_to_be16(from->di_mode);
7075         to->di_version = from ->di_version;
7076         to->di_format = from->di_format;
7077         to->di_onlink = cpu_to_be16(from->di_onlink);
7078 -       to->di_uid = cpu_to_be32(from->di_uid);
7079 -       to->di_gid = cpu_to_be32(from->di_gid);
7080 +
7081 +       to->di_uid = cpu_to_be32(TAGINO_UID(tagged, from->di_uid, from->di_tag));
7082 +       to->di_gid = cpu_to_be32(TAGINO_GID(tagged, from->di_gid, from->di_tag));
7083 +       to->di_tag = cpu_to_be16(TAGINO_TAG(tagged, from->di_tag));
7084 +
7085         to->di_nlink = cpu_to_be32(from->di_nlink);
7086         to->di_projid_lo = cpu_to_be16(from->di_projid_lo);
7087         to->di_projid_hi = cpu_to_be16(from->di_projid_hi);
7088 @@ -901,12 +917,14 @@ xfs_dinode_to_disk(
7089         to->di_dmevmask = cpu_to_be32(from->di_dmevmask);
7090         to->di_dmstate = cpu_to_be16(from->di_dmstate);
7091         to->di_flags = cpu_to_be16(from->di_flags);
7092 +       to->di_vflags = cpu_to_be16(from->di_vflags);
7093         to->di_gen = cpu_to_be32(from->di_gen);
7094  }
7095  
7096  STATIC uint
7097  _xfs_dic2xflags(
7098 -       __uint16_t              di_flags)
7099 +       __uint16_t              di_flags,
7100 +       __uint16_t              di_vflags)
7101  {
7102         uint                    flags = 0;
7103  
7104 @@ -917,6 +935,8 @@ _xfs_dic2xflags(
7105                         flags |= XFS_XFLAG_PREALLOC;
7106                 if (di_flags & XFS_DIFLAG_IMMUTABLE)
7107                         flags |= XFS_XFLAG_IMMUTABLE;
7108 +               if (di_flags & XFS_DIFLAG_IXUNLINK)
7109 +                       flags |= XFS_XFLAG_IXUNLINK;
7110                 if (di_flags & XFS_DIFLAG_APPEND)
7111                         flags |= XFS_XFLAG_APPEND;
7112                 if (di_flags & XFS_DIFLAG_SYNC)
7113 @@ -941,6 +961,10 @@ _xfs_dic2xflags(
7114                         flags |= XFS_XFLAG_FILESTREAM;
7115         }
7116  
7117 +       if (di_vflags & XFS_DIVFLAG_BARRIER)
7118 +               flags |= FS_BARRIER_FL;
7119 +       if (di_vflags & XFS_DIVFLAG_COW)
7120 +               flags |= FS_COW_FL;
7121         return flags;
7122  }
7123  
7124 @@ -950,7 +974,7 @@ xfs_ip2xflags(
7125  {
7126         xfs_icdinode_t          *dic = &ip->i_d;
7127  
7128 -       return _xfs_dic2xflags(dic->di_flags) |
7129 +       return _xfs_dic2xflags(dic->di_flags, dic->di_vflags) |
7130                                 (XFS_IFORK_Q(ip) ? XFS_XFLAG_HASATTR : 0);
7131  }
7132  
7133 @@ -958,7 +982,8 @@ uint
7134  xfs_dic2xflags(
7135         xfs_dinode_t            *dip)
7136  {
7137 -       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags)) |
7138 +       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags),
7139 +                               be16_to_cpu(dip->di_vflags)) |
7140                                 (XFS_DFORK_Q(dip) ? XFS_XFLAG_HASATTR : 0);
7141  }
7142  
7143 @@ -1012,7 +1037,8 @@ xfs_iread(
7144          * Otherwise, just get the truly permanent information.
7145          */
7146         if (dip->di_mode) {
7147 -               xfs_dinode_from_disk(&ip->i_d, dip);
7148 +               xfs_dinode_from_disk(&ip->i_d, dip,
7149 +                       mp->m_flags & XFS_MOUNT_TAGGED);
7150                 error = xfs_iformat(ip, dip);
7151                 if (error)  {
7152  #ifdef DEBUG
7153 @@ -1199,6 +1225,7 @@ xfs_ialloc(
7154         ASSERT(ip->i_d.di_nlink == nlink);
7155         ip->i_d.di_uid = current_fsuid();
7156         ip->i_d.di_gid = current_fsgid();
7157 +       ip->i_d.di_tag = current_fstag(&ip->i_vnode);
7158         xfs_set_projid(ip, prid);
7159         memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
7160  
7161 @@ -1258,6 +1285,7 @@ xfs_ialloc(
7162         ip->i_d.di_dmevmask = 0;
7163         ip->i_d.di_dmstate = 0;
7164         ip->i_d.di_flags = 0;
7165 +       ip->i_d.di_vflags = 0;
7166         flags = XFS_ILOG_CORE;
7167         switch (mode & S_IFMT) {
7168         case S_IFIFO:
7169 @@ -1952,6 +1980,7 @@ xfs_ifree(
7170         }
7171         ip->i_d.di_mode = 0;            /* mark incore inode as free */
7172         ip->i_d.di_flags = 0;
7173 +       ip->i_d.di_vflags = 0;
7174         ip->i_d.di_dmevmask = 0;
7175         ip->i_d.di_forkoff = 0;         /* mark the attr fork not in use */
7176         ip->i_d.di_format = XFS_DINODE_FMT_EXTENTS;
7177 @@ -2118,7 +2147,6 @@ xfs_iroot_realloc(
7178         return;
7179  }
7180  
7181 -
7182  /*
7183   * This is called when the amount of space needed for if_data
7184   * is increased or decreased.  The change in size is indicated by
7185 @@ -2800,7 +2828,8 @@ xfs_iflush_int(
7186          * because if the inode is dirty at all the core must
7187          * be.
7188          */
7189 -       xfs_dinode_to_disk(dip, &ip->i_d);
7190 +       xfs_dinode_to_disk(dip, &ip->i_d,
7191 +               mp->m_flags & XFS_MOUNT_TAGGED);
7192  
7193         /* Wrap, we never let the log put out DI_MAX_FLUSH */
7194         if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
7195 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_inode.h linux-3.9.4-vs2.3.6.3/fs/xfs/xfs_inode.h
7196 --- linux-3.9.4/fs/xfs/xfs_inode.h      2013-05-31 13:45:25.000000000 +0000
7197 +++ linux-3.9.4-vs2.3.6.3/fs/xfs/xfs_inode.h    2013-05-31 14:47:11.000000000 +0000
7198 @@ -134,7 +134,9 @@ typedef struct xfs_icdinode {
7199         __uint32_t      di_nlink;       /* number of links to file */
7200         __uint16_t      di_projid_lo;   /* lower part of owner's project id */
7201         __uint16_t      di_projid_hi;   /* higher part of owner's project id */
7202 -       __uint8_t       di_pad[6];      /* unused, zeroed space */
7203 +       __uint8_t       di_pad[2];      /* unused, zeroed space */
7204 +       __uint16_t      di_tag;         /* context tagging */
7205 +       __uint16_t      di_vflags;      /* vserver specific flags */
7206         __uint16_t      di_flushiter;   /* incremented on flush */
7207         xfs_ictimestamp_t di_atime;     /* time last accessed */
7208         xfs_ictimestamp_t di_mtime;     /* time last modified */
7209 @@ -556,7 +558,7 @@ int         xfs_imap_to_bp(struct xfs_mount *,
7210  int            xfs_iread(struct xfs_mount *, struct xfs_trans *,
7211                           struct xfs_inode *, uint);
7212  void           xfs_dinode_to_disk(struct xfs_dinode *,
7213 -                                  struct xfs_icdinode *);
7214 +                                  struct xfs_icdinode *, int);
7215  void           xfs_idestroy_fork(struct xfs_inode *, int);
7216  void           xfs_idata_realloc(struct xfs_inode *, int, int);
7217  void           xfs_iroot_realloc(struct xfs_inode *, int, int);
7218 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_ioctl.c linux-3.9.4-vs2.3.6.3/fs/xfs/xfs_ioctl.c
7219 --- linux-3.9.4/fs/xfs/xfs_ioctl.c      2013-05-31 13:45:25.000000000 +0000
7220 +++ linux-3.9.4-vs2.3.6.3/fs/xfs/xfs_ioctl.c    2013-05-31 14:47:11.000000000 +0000
7221 @@ -26,7 +26,7 @@
7222  #include "xfs_bmap_btree.h"
7223  #include "xfs_dinode.h"
7224  #include "xfs_inode.h"
7225 -#include "xfs_ioctl.h"
7226 +// #include "xfs_ioctl.h"
7227  #include "xfs_rtalloc.h"
7228  #include "xfs_itable.h"
7229  #include "xfs_error.h"
7230 @@ -763,6 +763,10 @@ xfs_merge_ioc_xflags(
7231                 xflags |= XFS_XFLAG_IMMUTABLE;
7232         else
7233                 xflags &= ~XFS_XFLAG_IMMUTABLE;
7234 +       if (flags & FS_IXUNLINK_FL)
7235 +               xflags |= XFS_XFLAG_IXUNLINK;
7236 +       else
7237 +               xflags &= ~XFS_XFLAG_IXUNLINK;
7238         if (flags & FS_APPEND_FL)
7239                 xflags |= XFS_XFLAG_APPEND;
7240         else
7241 @@ -791,6 +795,8 @@ xfs_di2lxflags(
7242  
7243         if (di_flags & XFS_DIFLAG_IMMUTABLE)
7244                 flags |= FS_IMMUTABLE_FL;
7245 +       if (di_flags & XFS_DIFLAG_IXUNLINK)
7246 +               flags |= FS_IXUNLINK_FL;
7247         if (di_flags & XFS_DIFLAG_APPEND)
7248                 flags |= FS_APPEND_FL;
7249         if (di_flags & XFS_DIFLAG_SYNC)
7250 @@ -851,6 +857,8 @@ xfs_set_diflags(
7251         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
7252         if (xflags & XFS_XFLAG_IMMUTABLE)
7253                 di_flags |= XFS_DIFLAG_IMMUTABLE;
7254 +       if (xflags & XFS_XFLAG_IXUNLINK)
7255 +               di_flags |= XFS_DIFLAG_IXUNLINK;
7256         if (xflags & XFS_XFLAG_APPEND)
7257                 di_flags |= XFS_DIFLAG_APPEND;
7258         if (xflags & XFS_XFLAG_SYNC)
7259 @@ -893,6 +901,10 @@ xfs_diflags_to_linux(
7260                 inode->i_flags |= S_IMMUTABLE;
7261         else
7262                 inode->i_flags &= ~S_IMMUTABLE;
7263 +       if (xflags & XFS_XFLAG_IXUNLINK)
7264 +               inode->i_flags |= S_IXUNLINK;
7265 +       else
7266 +               inode->i_flags &= ~S_IXUNLINK;
7267         if (xflags & XFS_XFLAG_APPEND)
7268                 inode->i_flags |= S_APPEND;
7269         else
7270 @@ -1397,10 +1409,18 @@ xfs_file_ioctl(
7271         case XFS_IOC_FSGETXATTRA:
7272                 return xfs_ioc_fsgetxattr(ip, 1, arg);
7273         case XFS_IOC_FSSETXATTR:
7274 +               if (IS_BARRIER(inode)) {
7275 +                       vxwprintk_task(1, "messing with the barrier.");
7276 +                       return -XFS_ERROR(EACCES);
7277 +               }
7278                 return xfs_ioc_fssetxattr(ip, filp, arg);
7279         case XFS_IOC_GETXFLAGS:
7280                 return xfs_ioc_getxflags(ip, arg);
7281         case XFS_IOC_SETXFLAGS:
7282 +               if (IS_BARRIER(inode)) {
7283 +                       vxwprintk_task(1, "messing with the barrier.");
7284 +                       return -XFS_ERROR(EACCES);
7285 +               }
7286                 return xfs_ioc_setxflags(ip, filp, arg);
7287  
7288         case XFS_IOC_FSSETDM: {
7289 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_ioctl.h linux-3.9.4-vs2.3.6.3/fs/xfs/xfs_ioctl.h
7290 --- linux-3.9.4/fs/xfs/xfs_ioctl.h      2012-12-11 03:30:57.000000000 +0000
7291 +++ linux-3.9.4-vs2.3.6.3/fs/xfs/xfs_ioctl.h    2013-05-31 14:47:11.000000000 +0000
7292 @@ -70,6 +70,12 @@ xfs_handle_to_dentry(
7293         void __user             *uhandle,
7294         u32                     hlen);
7295  
7296 +extern int
7297 +xfs_sync_flags(
7298 +       struct inode            *inode,
7299 +       int                     flags,
7300 +       int                     vflags);
7301 +
7302  extern long
7303  xfs_file_ioctl(
7304         struct file             *filp,
7305 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_iops.c linux-3.9.4-vs2.3.6.3/fs/xfs/xfs_iops.c
7306 --- linux-3.9.4/fs/xfs/xfs_iops.c       2013-02-19 13:58:49.000000000 +0000
7307 +++ linux-3.9.4-vs2.3.6.3/fs/xfs/xfs_iops.c     2013-05-31 14:47:11.000000000 +0000
7308 @@ -28,6 +28,7 @@
7309  #include "xfs_bmap_btree.h"
7310  #include "xfs_dinode.h"
7311  #include "xfs_inode.h"
7312 +#include "xfs_ioctl.h"
7313  #include "xfs_bmap.h"
7314  #include "xfs_rtalloc.h"
7315  #include "xfs_error.h"
7316 @@ -47,6 +48,7 @@
7317  #include <linux/security.h>
7318  #include <linux/fiemap.h>
7319  #include <linux/slab.h>
7320 +#include <linux/vs_tag.h>
7321  
7322  static int
7323  xfs_initxattrs(
7324 @@ -422,6 +424,7 @@ xfs_vn_getattr(
7325         stat->nlink = ip->i_d.di_nlink;
7326         stat->uid = ip->i_d.di_uid;
7327         stat->gid = ip->i_d.di_gid;
7328 +       stat->tag = ip->i_d.di_tag;
7329         stat->ino = ip->i_ino;
7330         stat->atime = inode->i_atime;
7331         stat->mtime = inode->i_mtime;
7332 @@ -1037,6 +1040,7 @@ static const struct inode_operations xfs
7333         .listxattr              = xfs_vn_listxattr,
7334         .fiemap                 = xfs_vn_fiemap,
7335         .update_time            = xfs_vn_update_time,
7336 +       .sync_flags             = xfs_sync_flags,
7337  };
7338  
7339  static const struct inode_operations xfs_dir_inode_operations = {
7340 @@ -1063,6 +1067,7 @@ static const struct inode_operations xfs
7341         .removexattr            = generic_removexattr,
7342         .listxattr              = xfs_vn_listxattr,
7343         .update_time            = xfs_vn_update_time,
7344 +       .sync_flags             = xfs_sync_flags,
7345  };
7346  
7347  static const struct inode_operations xfs_dir_ci_inode_operations = {
7348 @@ -1114,6 +1119,10 @@ xfs_diflags_to_iflags(
7349                 inode->i_flags |= S_IMMUTABLE;
7350         else
7351                 inode->i_flags &= ~S_IMMUTABLE;
7352 +       if (ip->i_d.di_flags & XFS_DIFLAG_IXUNLINK)
7353 +               inode->i_flags |= S_IXUNLINK;
7354 +       else
7355 +               inode->i_flags &= ~S_IXUNLINK;
7356         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
7357                 inode->i_flags |= S_APPEND;
7358         else
7359 @@ -1126,6 +1135,15 @@ xfs_diflags_to_iflags(
7360                 inode->i_flags |= S_NOATIME;
7361         else
7362                 inode->i_flags &= ~S_NOATIME;
7363 +
7364 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_BARRIER)
7365 +               inode->i_vflags |= V_BARRIER;
7366 +       else
7367 +               inode->i_vflags &= ~V_BARRIER;
7368 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_COW)
7369 +               inode->i_vflags |= V_COW;
7370 +       else
7371 +               inode->i_vflags &= ~V_COW;
7372  }
7373  
7374  /*
7375 @@ -1157,6 +1175,7 @@ xfs_setup_inode(
7376         set_nlink(inode, ip->i_d.di_nlink);
7377         inode->i_uid    = ip->i_d.di_uid;
7378         inode->i_gid    = ip->i_d.di_gid;
7379 +       inode->i_tag    = ip->i_d.di_tag;
7380  
7381         switch (inode->i_mode & S_IFMT) {
7382         case S_IFBLK:
7383 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_itable.c linux-3.9.4-vs2.3.6.3/fs/xfs/xfs_itable.c
7384 --- linux-3.9.4/fs/xfs/xfs_itable.c     2013-02-19 13:58:49.000000000 +0000
7385 +++ linux-3.9.4-vs2.3.6.3/fs/xfs/xfs_itable.c   2013-05-31 14:47:11.000000000 +0000
7386 @@ -97,6 +97,7 @@ xfs_bulkstat_one_int(
7387         buf->bs_mode = dic->di_mode;
7388         buf->bs_uid = dic->di_uid;
7389         buf->bs_gid = dic->di_gid;
7390 +       buf->bs_tag = dic->di_tag;
7391         buf->bs_size = dic->di_size;
7392         buf->bs_atime.tv_sec = dic->di_atime.t_sec;
7393         buf->bs_atime.tv_nsec = dic->di_atime.t_nsec;
7394 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_linux.h linux-3.9.4-vs2.3.6.3/fs/xfs/xfs_linux.h
7395 --- linux-3.9.4/fs/xfs/xfs_linux.h      2013-02-19 13:58:49.000000000 +0000
7396 +++ linux-3.9.4-vs2.3.6.3/fs/xfs/xfs_linux.h    2013-05-31 14:47:11.000000000 +0000
7397 @@ -123,6 +123,7 @@
7398  
7399  #define current_cpu()          (raw_smp_processor_id())
7400  #define current_pid()          (current->pid)
7401 +#define current_fstag(vp)      (dx_current_fstag((vp)->i_sb))
7402  #define current_test_flags(f)  (current->flags & (f))
7403  #define current_set_flags_nested(sp, f)                \
7404                 (*(sp) = current->flags, current->flags |= (f))
7405 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_log_recover.c linux-3.9.4-vs2.3.6.3/fs/xfs/xfs_log_recover.c
7406 --- linux-3.9.4/fs/xfs/xfs_log_recover.c        2013-05-31 13:45:25.000000000 +0000
7407 +++ linux-3.9.4-vs2.3.6.3/fs/xfs/xfs_log_recover.c      2013-05-31 14:47:11.000000000 +0000
7408 @@ -2361,7 +2361,8 @@ xlog_recover_inode_pass2(
7409         }
7410  
7411         /* The core is in in-core format */
7412 -       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr);
7413 +       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr,
7414 +               mp->m_flags & XFS_MOUNT_TAGGED);
7415  
7416         /* the rest is in on-disk format */
7417         if (item->ri_buf[1].i_len > sizeof(struct xfs_icdinode)) {
7418 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_mount.h linux-3.9.4-vs2.3.6.3/fs/xfs/xfs_mount.h
7419 --- linux-3.9.4/fs/xfs/xfs_mount.h      2013-05-31 13:45:25.000000000 +0000
7420 +++ linux-3.9.4-vs2.3.6.3/fs/xfs/xfs_mount.h    2013-05-31 14:47:11.000000000 +0000
7421 @@ -254,6 +254,7 @@ typedef struct xfs_mount {
7422                                                    allocator */
7423  #define XFS_MOUNT_NOATTR2      (1ULL << 25)    /* disable use of attr2 format */
7424  
7425 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
7426  
7427  /*
7428   * Default minimum read and write sizes.
7429 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_super.c linux-3.9.4-vs2.3.6.3/fs/xfs/xfs_super.c
7430 --- linux-3.9.4/fs/xfs/xfs_super.c      2013-05-31 13:45:25.000000000 +0000
7431 +++ linux-3.9.4-vs2.3.6.3/fs/xfs/xfs_super.c    2013-05-31 14:47:11.000000000 +0000
7432 @@ -114,6 +114,9 @@ mempool_t *xfs_ioend_pool;
7433  #define MNTOPT_NODELAYLOG  "nodelaylog"        /* Delayed logging disabled */
7434  #define MNTOPT_DISCARD    "discard"    /* Discard unused blocks */
7435  #define MNTOPT_NODISCARD   "nodiscard" /* Do not discard unused blocks */
7436 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
7437 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
7438 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
7439  
7440  /*
7441   * Table driven mount option parser.
7442 @@ -126,6 +129,8 @@ enum {
7443         Opt_nobarrier,
7444         Opt_inode64,
7445         Opt_inode32,
7446 +       Opt_tag,
7447 +       Opt_notag,
7448         Opt_err
7449  };
7450  
7451 @@ -134,6 +139,9 @@ static const match_table_t tokens = {
7452         {Opt_nobarrier, "nobarrier"},
7453         {Opt_inode64, "inode64"},
7454         {Opt_inode32, "inode32"},
7455 +       {Opt_tag, "tagxid"},
7456 +       {Opt_tag, "tag"},
7457 +       {Opt_notag, "notag"},
7458         {Opt_err, NULL}
7459  };
7460  
7461 @@ -392,6 +400,19 @@ xfs_parseargs(
7462                 } else if (!strcmp(this_char, "irixsgid")) {
7463                         xfs_warn(mp,
7464         "irixsgid is now a sysctl(2) variable, option is deprecated.");
7465 +#ifndef CONFIG_TAGGING_NONE
7466 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7467 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7468 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
7469 +                       mp->m_flags &= ~XFS_MOUNT_TAGGED;
7470 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
7471 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7472 +#endif
7473 +#ifdef CONFIG_PROPAGATE
7474 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7475 +                       /* use value */
7476 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7477 +#endif
7478                 } else {
7479                         xfs_warn(mp, "unknown mount option [%s].", this_char);
7480                         return EINVAL;
7481 @@ -1238,6 +1259,16 @@ xfs_fs_remount(
7482                 case Opt_inode32:
7483                         mp->m_maxagi = xfs_set_inode32(mp);
7484                         break;
7485 +               case Opt_tag:
7486 +                       if (!(sb->s_flags & MS_TAGGED)) {
7487 +                               printk(KERN_INFO
7488 +                                       "XFS: %s: tagging not permitted on remount.\n",
7489 +                                       sb->s_id);
7490 +                               return -EINVAL;
7491 +                       }
7492 +                       break;
7493 +               case Opt_notag:
7494 +                       break;
7495                 default:
7496                         /*
7497                          * Logically we would return an error here to prevent
7498 @@ -1458,6 +1489,9 @@ xfs_fs_fill_super(
7499         if (error)
7500                 goto out_free_sb;
7501  
7502 +       if (mp->m_flags & XFS_MOUNT_TAGGED)
7503 +               sb->s_flags |= MS_TAGGED;
7504 +
7505         /*
7506          * we must configure the block size in the superblock before we run the
7507          * full mount process as the mount process can lookup and cache inodes.
7508 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_vnodeops.c linux-3.9.4-vs2.3.6.3/fs/xfs/xfs_vnodeops.c
7509 --- linux-3.9.4/fs/xfs/xfs_vnodeops.c   2013-05-31 13:45:25.000000000 +0000
7510 +++ linux-3.9.4-vs2.3.6.3/fs/xfs/xfs_vnodeops.c 2013-05-31 14:47:11.000000000 +0000
7511 @@ -104,6 +104,77 @@ xfs_readlink_bmap(
7512         return error;
7513  }
7514  
7515 +
7516 +STATIC void
7517 +xfs_get_inode_flags(
7518 +       xfs_inode_t     *ip)
7519 +{
7520 +       struct inode    *inode = VFS_I(ip);
7521 +       unsigned int    flags = inode->i_flags;
7522 +       unsigned int    vflags = inode->i_vflags;
7523 +
7524 +       if (flags & S_IMMUTABLE)
7525 +               ip->i_d.di_flags |= XFS_DIFLAG_IMMUTABLE;
7526 +       else
7527 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IMMUTABLE;
7528 +       if (flags & S_IXUNLINK)
7529 +               ip->i_d.di_flags |= XFS_DIFLAG_IXUNLINK;
7530 +       else
7531 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IXUNLINK;
7532 +
7533 +       if (vflags & V_BARRIER)
7534 +               ip->i_d.di_vflags |= XFS_DIVFLAG_BARRIER;
7535 +       else
7536 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_BARRIER;
7537 +       if (vflags & V_COW)
7538 +               ip->i_d.di_vflags |= XFS_DIVFLAG_COW;
7539 +       else
7540 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_COW;
7541 +}
7542 +
7543 +int
7544 +xfs_sync_flags(
7545 +       struct inode            *inode,
7546 +       int                     flags,
7547 +       int                     vflags)
7548 +{
7549 +       struct xfs_inode        *ip = XFS_I(inode);
7550 +       struct xfs_mount        *mp = ip->i_mount;
7551 +       struct xfs_trans        *tp;
7552 +       unsigned int            lock_flags = 0;
7553 +       int                     code;
7554 +
7555 +       tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
7556 +       code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
7557 +       if (code)
7558 +               goto error_out;
7559 +
7560 +       xfs_ilock(ip, XFS_ILOCK_EXCL);
7561 +       xfs_trans_ijoin(tp, ip, 0);
7562 +
7563 +       inode->i_flags = flags;
7564 +       inode->i_vflags = vflags;
7565 +       xfs_get_inode_flags(ip);
7566 +
7567 +       xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
7568 +       xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG);
7569 +
7570 +       XFS_STATS_INC(xs_ig_attrchg);
7571 +
7572 +       if (mp->m_flags & XFS_MOUNT_WSYNC)
7573 +               xfs_trans_set_sync(tp);
7574 +       code = xfs_trans_commit(tp, 0);
7575 +       xfs_iunlock(ip, XFS_ILOCK_EXCL);
7576 +       return code;
7577 +
7578 +error_out:
7579 +       xfs_trans_cancel(tp, 0);
7580 +       if (lock_flags)
7581 +               xfs_iunlock(ip, XFS_ILOCK_EXCL);
7582 +       return code;
7583 +}
7584 +
7585 +
7586  int
7587  xfs_readlink(
7588         xfs_inode_t     *ip,
7589 diff -NurpP --minimal linux-3.9.4/include/linux/cred.h linux-3.9.4-vs2.3.6.3/include/linux/cred.h
7590 --- linux-3.9.4/include/linux/cred.h    2013-02-19 13:58:50.000000000 +0000
7591 +++ linux-3.9.4-vs2.3.6.3/include/linux/cred.h  2013-05-31 14:47:11.000000000 +0000
7592 @@ -143,6 +143,7 @@ extern void exit_creds(struct task_struc
7593  extern int copy_creds(struct task_struct *, unsigned long);
7594  extern const struct cred *get_task_cred(struct task_struct *);
7595  extern struct cred *cred_alloc_blank(void);
7596 +extern struct cred *__prepare_creds(const struct cred *);
7597  extern struct cred *prepare_creds(void);
7598  extern struct cred *prepare_exec_creds(void);
7599  extern int commit_creds(struct cred *);
7600 @@ -196,6 +197,31 @@ static inline void validate_process_cred
7601  }
7602  #endif
7603  
7604 +static inline void set_cred_subscribers(struct cred *cred, int n)
7605 +{
7606 +#ifdef CONFIG_DEBUG_CREDENTIALS
7607 +       atomic_set(&cred->subscribers, n);
7608 +#endif
7609 +}
7610 +
7611 +static inline int read_cred_subscribers(const struct cred *cred)
7612 +{
7613 +#ifdef CONFIG_DEBUG_CREDENTIALS
7614 +       return atomic_read(&cred->subscribers);
7615 +#else
7616 +       return 0;
7617 +#endif
7618 +}
7619 +
7620 +static inline void alter_cred_subscribers(const struct cred *_cred, int n)
7621 +{
7622 +#ifdef CONFIG_DEBUG_CREDENTIALS
7623 +       struct cred *cred = (struct cred *) _cred;
7624 +
7625 +       atomic_add(n, &cred->subscribers);
7626 +#endif
7627 +}
7628 +
7629  /**
7630   * get_new_cred - Get a reference on a new set of credentials
7631   * @cred: The new credentials to reference
7632 diff -NurpP --minimal linux-3.9.4/include/linux/devpts_fs.h linux-3.9.4-vs2.3.6.3/include/linux/devpts_fs.h
7633 --- linux-3.9.4/include/linux/devpts_fs.h       2013-02-19 13:58:50.000000000 +0000
7634 +++ linux-3.9.4-vs2.3.6.3/include/linux/devpts_fs.h     2013-05-31 14:47:11.000000000 +0000
7635 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
7636  
7637  #endif
7638  
7639 -
7640  #endif /* _LINUX_DEVPTS_FS_H */
7641 diff -NurpP --minimal linux-3.9.4/include/linux/fs.h linux-3.9.4-vs2.3.6.3/include/linux/fs.h
7642 --- linux-3.9.4/include/linux/fs.h      2013-05-31 13:45:27.000000000 +0000
7643 +++ linux-3.9.4-vs2.3.6.3/include/linux/fs.h    2013-05-31 14:47:11.000000000 +0000
7644 @@ -211,6 +211,7 @@ typedef void (dio_iodone_t)(struct kiocb
7645  #define ATTR_KILL_PRIV (1 << 14)
7646  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
7647  #define ATTR_TIMES_SET (1 << 16)
7648 +#define ATTR_TAG       (1 << 17)
7649  
7650  /*
7651   * This is the Inode Attributes structure, used for notify_change().  It
7652 @@ -226,6 +227,7 @@ struct iattr {
7653         umode_t         ia_mode;
7654         kuid_t          ia_uid;
7655         kgid_t          ia_gid;
7656 +       ktag_t          ia_tag;
7657         loff_t          ia_size;
7658         struct timespec ia_atime;
7659         struct timespec ia_mtime;
7660 @@ -523,7 +525,9 @@ struct inode {
7661         unsigned short          i_opflags;
7662         kuid_t                  i_uid;
7663         kgid_t                  i_gid;
7664 -       unsigned int            i_flags;
7665 +       ktag_t                  i_tag;
7666 +       unsigned short          i_flags;
7667 +       unsigned short          i_vflags;
7668  
7669  #ifdef CONFIG_FS_POSIX_ACL
7670         struct posix_acl        *i_acl;
7671 @@ -552,6 +556,7 @@ struct inode {
7672                 unsigned int __i_nlink;
7673         };
7674         dev_t                   i_rdev;
7675 +       dev_t                   i_mdev;
7676         loff_t                  i_size;
7677         struct timespec         i_atime;
7678         struct timespec         i_mtime;
7679 @@ -702,6 +707,11 @@ static inline gid_t i_gid_read(const str
7680         return from_kgid(&init_user_ns, inode->i_gid);
7681  }
7682  
7683 +static inline tag_t i_tag_read(const struct inode *inode)
7684 +{
7685 +       return from_ktag(&init_user_ns, inode->i_tag);
7686 +}
7687 +
7688  static inline void i_uid_write(struct inode *inode, uid_t uid)
7689  {
7690         inode->i_uid = make_kuid(&init_user_ns, uid);
7691 @@ -712,14 +722,19 @@ static inline void i_gid_write(struct in
7692         inode->i_gid = make_kgid(&init_user_ns, gid);
7693  }
7694  
7695 +static inline void i_tag_write(struct inode *inode, tag_t tag)
7696 +{
7697 +       inode->i_tag = make_ktag(&init_user_ns, tag);
7698 +}
7699 +
7700  static inline unsigned iminor(const struct inode *inode)
7701  {
7702 -       return MINOR(inode->i_rdev);
7703 +       return MINOR(inode->i_mdev);
7704  }
7705  
7706  static inline unsigned imajor(const struct inode *inode)
7707  {
7708 -       return MAJOR(inode->i_rdev);
7709 +       return MAJOR(inode->i_mdev);
7710  }
7711  
7712  extern struct block_device *I_BDEV(struct inode *inode);
7713 @@ -786,6 +801,7 @@ struct file {
7714         loff_t                  f_pos;
7715         struct fown_struct      f_owner;
7716         const struct cred       *f_cred;
7717 +       xid_t                   f_xid;
7718         struct file_ra_state    f_ra;
7719  
7720         u64                     f_version;
7721 @@ -937,6 +953,7 @@ struct file_lock {
7722         struct file *fl_file;
7723         loff_t fl_start;
7724         loff_t fl_end;
7725 +       xid_t fl_xid;
7726  
7727         struct fasync_struct *  fl_fasync; /* for lease break notifications */
7728         /* for lease breaks: */
7729 @@ -1567,6 +1584,7 @@ struct inode_operations {
7730         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
7731         ssize_t (*listxattr) (struct dentry *, char *, size_t);
7732         int (*removexattr) (struct dentry *, const char *);
7733 +       int (*sync_flags) (struct inode *, int, int);
7734         int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
7735                       u64 len);
7736         int (*update_time)(struct inode *, struct timespec *, int);
7737 @@ -1579,6 +1597,7 @@ ssize_t rw_copy_check_uvector(int type,
7738                               unsigned long nr_segs, unsigned long fast_segs,
7739                               struct iovec *fast_pointer,
7740                               struct iovec **ret_pointer);
7741 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
7742  
7743  extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
7744  extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *);
7745 @@ -1632,6 +1651,14 @@ struct super_operations {
7746  #define S_IMA          1024    /* Inode has an associated IMA struct */
7747  #define S_AUTOMOUNT    2048    /* Automount/referral quasi-directory */
7748  #define S_NOSEC                4096    /* no suid or xattr security attributes */
7749 +#define S_IXUNLINK     8192    /* Immutable Invert on unlink */
7750 +
7751 +/* Linux-VServer related Inode flags */
7752 +
7753 +#define V_VALID                1
7754 +#define V_XATTR                2
7755 +#define V_BARRIER      4       /* Barrier for chroot() */
7756 +#define V_COW          8       /* Copy on Write */
7757  
7758  /*
7759   * Note that nosuid etc flags are inode-specific: setting some file-system
7760 @@ -1656,10 +1683,13 @@ struct super_operations {
7761  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
7762  #define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
7763  #define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
7764 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
7765  
7766  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
7767  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
7768  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
7769 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
7770 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
7771  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
7772  
7773  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
7774 @@ -1670,6 +1700,16 @@ struct super_operations {
7775  #define IS_AUTOMOUNT(inode)    ((inode)->i_flags & S_AUTOMOUNT)
7776  #define IS_NOSEC(inode)                ((inode)->i_flags & S_NOSEC)
7777  
7778 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
7779 +
7780 +#ifdef CONFIG_VSERVER_COWBL
7781 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
7782 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
7783 +#else
7784 +#  define IS_COW(inode)                (0)
7785 +#  define IS_COW_LINK(inode)   (0)
7786 +#endif
7787 +
7788  /*
7789   * Inode state bits.  Protected by inode->i_lock
7790   *
7791 @@ -1898,6 +1938,9 @@ extern int rw_verify_area(int, struct fi
7792  extern int locks_mandatory_locked(struct inode *);
7793  extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t);
7794  
7795 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
7796 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
7797 +
7798  /*
7799   * Candidates for mandatory locking have the setgid bit set
7800   * but no group execute bit -  an otherwise meaningless combination.
7801 @@ -2509,6 +2552,7 @@ extern int dcache_dir_open(struct inode
7802  extern int dcache_dir_close(struct inode *, struct file *);
7803  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
7804  extern int dcache_readdir(struct file *, void *, filldir_t);
7805 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
7806  extern int simple_setattr(struct dentry *, struct iattr *);
7807  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
7808  extern int simple_statfs(struct dentry *, struct kstatfs *);
7809 diff -NurpP --minimal linux-3.9.4/include/linux/init_task.h linux-3.9.4-vs2.3.6.3/include/linux/init_task.h
7810 --- linux-3.9.4/include/linux/init_task.h       2013-05-31 13:45:27.000000000 +0000
7811 +++ linux-3.9.4-vs2.3.6.3/include/linux/init_task.h     2013-05-31 14:53:41.000000000 +0000
7812 @@ -222,6 +222,10 @@ extern struct task_group root_task_group
7813         INIT_TASK_RCU_PREEMPT(tsk)                                      \
7814         INIT_CPUSET_SEQ                                                 \
7815         INIT_VTIME(tsk)                                                 \
7816 +       .xid            = 0,                                            \
7817 +       .vx_info        = NULL,                                         \
7818 +       .nid            = 0,                                            \
7819 +       .nx_info        = NULL,                                         \
7820  }
7821  
7822  
7823 diff -NurpP --minimal linux-3.9.4/include/linux/ipc.h linux-3.9.4-vs2.3.6.3/include/linux/ipc.h
7824 --- linux-3.9.4/include/linux/ipc.h     2012-12-11 03:30:57.000000000 +0000
7825 +++ linux-3.9.4-vs2.3.6.3/include/linux/ipc.h   2013-05-31 14:47:11.000000000 +0000
7826 @@ -16,6 +16,7 @@ struct kern_ipc_perm
7827         key_t           key;
7828         kuid_t          uid;
7829         kgid_t          gid;
7830 +       xid_t           xid;
7831         kuid_t          cuid;
7832         kgid_t          cgid;
7833         umode_t         mode; 
7834 diff -NurpP --minimal linux-3.9.4/include/linux/loop.h linux-3.9.4-vs2.3.6.3/include/linux/loop.h
7835 --- linux-3.9.4/include/linux/loop.h    2013-02-19 13:58:51.000000000 +0000
7836 +++ linux-3.9.4-vs2.3.6.3/include/linux/loop.h  2013-05-31 14:47:11.000000000 +0000
7837 @@ -41,6 +41,7 @@ struct loop_device {
7838         struct loop_func_table *lo_encryption;
7839         __u32           lo_init[2];
7840         kuid_t          lo_key_owner;   /* Who set the key */
7841 +       xid_t           lo_xid;
7842         int             (*ioctl)(struct loop_device *, int cmd, 
7843                                  unsigned long arg); 
7844  
7845 diff -NurpP --minimal linux-3.9.4/include/linux/memcontrol.h linux-3.9.4-vs2.3.6.3/include/linux/memcontrol.h
7846 --- linux-3.9.4/include/linux/memcontrol.h      2013-05-31 13:45:28.000000000 +0000
7847 +++ linux-3.9.4-vs2.3.6.3/include/linux/memcontrol.h    2013-05-31 14:47:11.000000000 +0000
7848 @@ -86,6 +86,13 @@ extern struct mem_cgroup *try_get_mem_cg
7849  extern struct mem_cgroup *parent_mem_cgroup(struct mem_cgroup *memcg);
7850  extern struct mem_cgroup *mem_cgroup_from_cont(struct cgroup *cont);
7851  
7852 +extern u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member);
7853 +extern u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member);
7854 +
7855 +extern s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem);
7856 +extern s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem);
7857 +extern s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem);
7858 +
7859  static inline
7860  bool mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *memcg)
7861  {
7862 diff -NurpP --minimal linux-3.9.4/include/linux/mm_types.h linux-3.9.4-vs2.3.6.3/include/linux/mm_types.h
7863 --- linux-3.9.4/include/linux/mm_types.h        2013-05-31 13:45:28.000000000 +0000
7864 +++ linux-3.9.4-vs2.3.6.3/include/linux/mm_types.h      2013-05-31 14:47:11.000000000 +0000
7865 @@ -380,6 +380,7 @@ struct mm_struct {
7866  
7867         /* Architecture-specific MM context */
7868         mm_context_t context;
7869 +       struct vx_info *mm_vx_info;
7870  
7871         unsigned long flags; /* Must use atomic bitops to access the bits */
7872  
7873 diff -NurpP --minimal linux-3.9.4/include/linux/mount.h linux-3.9.4-vs2.3.6.3/include/linux/mount.h
7874 --- linux-3.9.4/include/linux/mount.h   2013-05-31 13:45:28.000000000 +0000
7875 +++ linux-3.9.4-vs2.3.6.3/include/linux/mount.h 2013-05-31 14:47:11.000000000 +0000
7876 @@ -49,6 +49,9 @@ struct mnt_namespace;
7877  
7878  #define MNT_LOCK_READONLY      0x400000
7879  
7880 +#define MNT_TAGID      0x10000
7881 +#define MNT_NOTAG      0x20000
7882 +
7883  struct vfsmount {
7884         struct dentry *mnt_root;        /* root of the mounted tree */
7885         struct super_block *mnt_sb;     /* pointer to superblock */
7886 diff -NurpP --minimal linux-3.9.4/include/linux/net.h linux-3.9.4-vs2.3.6.3/include/linux/net.h
7887 --- linux-3.9.4/include/linux/net.h     2012-12-11 03:30:57.000000000 +0000
7888 +++ linux-3.9.4-vs2.3.6.3/include/linux/net.h   2013-05-31 14:47:11.000000000 +0000
7889 @@ -38,6 +38,7 @@ struct net;
7890  #define SOCK_PASSCRED          3
7891  #define SOCK_PASSSEC           4
7892  #define SOCK_EXTERNALLY_ALLOCATED 5
7893 +#define SOCK_USER_SOCKET       6
7894  
7895  #ifndef ARCH_HAS_SOCKET_TYPES
7896  /**
7897 diff -NurpP --minimal linux-3.9.4/include/linux/netdevice.h linux-3.9.4-vs2.3.6.3/include/linux/netdevice.h
7898 --- linux-3.9.4/include/linux/netdevice.h       2013-05-31 13:45:28.000000000 +0000
7899 +++ linux-3.9.4-vs2.3.6.3/include/linux/netdevice.h     2013-05-31 14:47:11.000000000 +0000
7900 @@ -1688,6 +1688,7 @@ extern void               netdev_resync_ops(struct ne
7901  
7902  extern struct net_device       *dev_get_by_index(struct net *net, int ifindex);
7903  extern struct net_device       *__dev_get_by_index(struct net *net, int ifindex);
7904 +extern struct net_device       *dev_get_by_index_real_rcu(struct net *net, int ifindex);
7905  extern struct net_device       *dev_get_by_index_rcu(struct net *net, int ifindex);
7906  extern int             dev_restart(struct net_device *dev);
7907  #ifdef CONFIG_NETPOLL_TRAP
7908 diff -NurpP --minimal linux-3.9.4/include/linux/nsproxy.h linux-3.9.4-vs2.3.6.3/include/linux/nsproxy.h
7909 --- linux-3.9.4/include/linux/nsproxy.h 2013-02-19 13:58:51.000000000 +0000
7910 +++ linux-3.9.4-vs2.3.6.3/include/linux/nsproxy.h       2013-05-31 17:17:53.000000000 +0000
7911 @@ -3,6 +3,7 @@
7912  
7913  #include <linux/spinlock.h>
7914  #include <linux/sched.h>
7915 +#include <linux/vserver/debug.h>
7916  
7917  struct mnt_namespace;
7918  struct uts_namespace;
7919 @@ -63,6 +64,7 @@ static inline struct nsproxy *task_nspro
7920  }
7921  
7922  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
7923 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
7924  void exit_task_namespaces(struct task_struct *tsk);
7925  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
7926  void free_nsproxy(struct nsproxy *ns);
7927 @@ -70,16 +72,26 @@ int unshare_nsproxy_namespaces(unsigned
7928         struct cred *, struct fs_struct *);
7929  int __init nsproxy_cache_init(void);
7930  
7931 -static inline void put_nsproxy(struct nsproxy *ns)
7932 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
7933 +
7934 +static inline void __get_nsproxy(struct nsproxy *ns,
7935 +       const char *_file, int _line)
7936  {
7937 -       if (atomic_dec_and_test(&ns->count)) {
7938 -               free_nsproxy(ns);
7939 -       }
7940 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
7941 +               ns, atomic_read(&ns->count), _file, _line);
7942 +       atomic_inc(&ns->count);
7943  }
7944  
7945 -static inline void get_nsproxy(struct nsproxy *ns)
7946 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
7947 +
7948 +static inline void __put_nsproxy(struct nsproxy *ns,
7949 +       const char *_file, int _line)
7950  {
7951 -       atomic_inc(&ns->count);
7952 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
7953 +               ns, atomic_read(&ns->count), _file, _line);
7954 +       if (atomic_dec_and_test(&ns->count)) {
7955 +               free_nsproxy(ns);
7956 +       }
7957  }
7958  
7959  #endif
7960 diff -NurpP --minimal linux-3.9.4/include/linux/pid.h linux-3.9.4-vs2.3.6.3/include/linux/pid.h
7961 --- linux-3.9.4/include/linux/pid.h     2013-05-31 13:45:28.000000000 +0000
7962 +++ linux-3.9.4-vs2.3.6.3/include/linux/pid.h   2013-05-31 14:47:11.000000000 +0000
7963 @@ -8,7 +8,8 @@ enum pid_type
7964         PIDTYPE_PID,
7965         PIDTYPE_PGID,
7966         PIDTYPE_SID,
7967 -       PIDTYPE_MAX
7968 +       PIDTYPE_MAX,
7969 +       PIDTYPE_REALPID
7970  };
7971  
7972  /*
7973 @@ -172,6 +173,7 @@ static inline pid_t pid_nr(struct pid *p
7974  }
7975  
7976  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
7977 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
7978  pid_t pid_vnr(struct pid *pid);
7979  
7980  #define do_each_pid_task(pid, type, task)                              \
7981 diff -NurpP --minimal linux-3.9.4/include/linux/proc_fs.h linux-3.9.4-vs2.3.6.3/include/linux/proc_fs.h
7982 --- linux-3.9.4/include/linux/proc_fs.h 2013-05-31 13:45:28.000000000 +0000
7983 +++ linux-3.9.4-vs2.3.6.3/include/linux/proc_fs.h       2013-05-31 14:47:11.000000000 +0000
7984 @@ -58,6 +58,7 @@ struct proc_dir_entry {
7985         nlink_t nlink;
7986         kuid_t uid;
7987         kgid_t gid;
7988 +       int vx_flags;
7989         loff_t size;
7990         const struct inode_operations *proc_iops;
7991         /*
7992 @@ -274,12 +275,18 @@ extern const struct proc_ns_operations p
7993  extern const struct proc_ns_operations userns_operations;
7994  extern const struct proc_ns_operations mntns_operations;
7995  
7996 +struct vx_info;
7997 +struct nx_info;
7998 +
7999  union proc_op {
8000         int (*proc_get_link)(struct dentry *, struct path *);
8001         int (*proc_read)(struct task_struct *task, char *page);
8002         int (*proc_show)(struct seq_file *m,
8003                 struct pid_namespace *ns, struct pid *pid,
8004                 struct task_struct *task);
8005 +       int (*proc_vs_read)(char *page);
8006 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
8007 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
8008  };
8009  
8010  struct ctl_table_header;
8011 @@ -287,6 +294,7 @@ struct ctl_table;
8012  
8013  struct proc_inode {
8014         struct pid *pid;
8015 +       int vx_flags;
8016         int fd;
8017         union proc_op op;
8018         struct proc_dir_entry *pde;
8019 diff -NurpP --minimal linux-3.9.4/include/linux/quotaops.h linux-3.9.4-vs2.3.6.3/include/linux/quotaops.h
8020 --- linux-3.9.4/include/linux/quotaops.h        2012-12-11 03:30:57.000000000 +0000
8021 +++ linux-3.9.4-vs2.3.6.3/include/linux/quotaops.h      2013-05-31 14:47:11.000000000 +0000
8022 @@ -8,6 +8,7 @@
8023  #define _LINUX_QUOTAOPS_
8024  
8025  #include <linux/fs.h>
8026 +#include <linux/vs_dlimit.h>
8027  
8028  #define DQUOT_SPACE_WARN       0x1
8029  #define DQUOT_SPACE_RESERVE    0x2
8030 @@ -205,11 +206,12 @@ static inline void dquot_drop(struct ino
8031  
8032  static inline int dquot_alloc_inode(const struct inode *inode)
8033  {
8034 -       return 0;
8035 +       return dl_alloc_inode(inode);
8036  }
8037  
8038  static inline void dquot_free_inode(const struct inode *inode)
8039  {
8040 +       dl_free_inode(inode);
8041  }
8042  
8043  static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
8044 @@ -220,6 +222,10 @@ static inline int dquot_transfer(struct
8045  static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
8046                 int flags)
8047  {
8048 +       int ret = 0;
8049 +
8050 +       if ((ret = dl_alloc_space(inode, number)))
8051 +               return ret;
8052         if (!(flags & DQUOT_SPACE_RESERVE))
8053                 inode_add_bytes(inode, number);
8054         return 0;
8055 @@ -230,6 +236,7 @@ static inline void __dquot_free_space(st
8056  {
8057         if (!(flags & DQUOT_SPACE_RESERVE))
8058                 inode_sub_bytes(inode, number);
8059 +       dl_free_space(inode, number);
8060  }
8061  
8062  static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
8063 diff -NurpP --minimal linux-3.9.4/include/linux/sched.h linux-3.9.4-vs2.3.6.3/include/linux/sched.h
8064 --- linux-3.9.4/include/linux/sched.h   2013-05-31 14:22:27.000000000 +0000
8065 +++ linux-3.9.4-vs2.3.6.3/include/linux/sched.h 2013-06-03 17:32:54.000000000 +0000
8066 @@ -1398,6 +1398,14 @@ struct task_struct {
8067  #endif
8068         struct seccomp seccomp;
8069  
8070 +/* vserver context data */
8071 +       struct vx_info *vx_info;
8072 +       struct nx_info *nx_info;
8073 +
8074 +       xid_t xid;
8075 +       nid_t nid;
8076 +       tag_t tag;
8077 +
8078  /* Thread group tracking */
8079         u32 parent_exec_id;
8080         u32 self_exec_id;
8081 @@ -1637,6 +1645,11 @@ struct pid_namespace;
8082  pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
8083                         struct pid_namespace *ns);
8084  
8085 +#include <linux/vserver/base.h>
8086 +#include <linux/vserver/context.h>
8087 +#include <linux/vserver/debug.h>
8088 +#include <linux/vserver/pid.h>
8089 +
8090  static inline pid_t task_pid_nr(struct task_struct *tsk)
8091  {
8092         return tsk->pid;
8093 @@ -1650,7 +1663,8 @@ static inline pid_t task_pid_nr_ns(struc
8094  
8095  static inline pid_t task_pid_vnr(struct task_struct *tsk)
8096  {
8097 -       return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
8098 +       // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
8099 +       return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
8100  }
8101  
8102  
8103 @@ -1663,7 +1677,7 @@ pid_t task_tgid_nr_ns(struct task_struct
8104  
8105  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
8106  {
8107 -       return pid_vnr(task_tgid(tsk));
8108 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
8109  }
8110  
8111  
8112 diff -NurpP --minimal linux-3.9.4/include/linux/shmem_fs.h linux-3.9.4-vs2.3.6.3/include/linux/shmem_fs.h
8113 --- linux-3.9.4/include/linux/shmem_fs.h        2012-12-11 03:30:57.000000000 +0000
8114 +++ linux-3.9.4-vs2.3.6.3/include/linux/shmem_fs.h      2013-05-31 14:47:11.000000000 +0000
8115 @@ -9,6 +9,9 @@
8116  
8117  /* inode in-kernel data */
8118  
8119 +#define TMPFS_SUPER_MAGIC      0x01021994
8120 +
8121 +
8122  struct shmem_inode_info {
8123         spinlock_t              lock;
8124         unsigned long           flags;
8125 diff -NurpP --minimal linux-3.9.4/include/linux/stat.h linux-3.9.4-vs2.3.6.3/include/linux/stat.h
8126 --- linux-3.9.4/include/linux/stat.h    2012-12-11 03:30:57.000000000 +0000
8127 +++ linux-3.9.4-vs2.3.6.3/include/linux/stat.h  2013-06-01 08:53:13.000000000 +0000
8128 @@ -25,6 +25,7 @@ struct kstat {
8129         unsigned int    nlink;
8130         kuid_t          uid;
8131         kgid_t          gid;
8132 +       ktag_t          tag;
8133         dev_t           rdev;
8134         loff_t          size;
8135         struct timespec  atime;
8136 diff -NurpP --minimal linux-3.9.4/include/linux/sunrpc/auth.h linux-3.9.4-vs2.3.6.3/include/linux/sunrpc/auth.h
8137 --- linux-3.9.4/include/linux/sunrpc/auth.h     2013-05-31 13:45:28.000000000 +0000
8138 +++ linux-3.9.4-vs2.3.6.3/include/linux/sunrpc/auth.h   2013-05-31 14:52:57.000000000 +0000
8139 @@ -26,6 +26,7 @@
8140  struct auth_cred {
8141         kuid_t  uid;
8142         kgid_t  gid;
8143 +       ktag_t  tag;
8144         struct group_info *group_info;
8145         const char *principal;
8146         unsigned char machine_cred : 1;
8147 diff -NurpP --minimal linux-3.9.4/include/linux/sunrpc/clnt.h linux-3.9.4-vs2.3.6.3/include/linux/sunrpc/clnt.h
8148 --- linux-3.9.4/include/linux/sunrpc/clnt.h     2013-05-31 13:45:28.000000000 +0000
8149 +++ linux-3.9.4-vs2.3.6.3/include/linux/sunrpc/clnt.h   2013-05-31 14:47:11.000000000 +0000
8150 @@ -49,7 +49,8 @@ struct rpc_clnt {
8151         unsigned int            cl_softrtry : 1,/* soft timeouts */
8152                                 cl_discrtry : 1,/* disconnect before retry */
8153                                 cl_autobind : 1,/* use getport() */
8154 -                               cl_chatty   : 1;/* be verbose */
8155 +                               cl_chatty   : 1,/* be verbose */
8156 +                               cl_tag      : 1;/* context tagging */
8157  
8158         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
8159         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
8160 diff -NurpP --minimal linux-3.9.4/include/linux/sysfs.h linux-3.9.4-vs2.3.6.3/include/linux/sysfs.h
8161 --- linux-3.9.4/include/linux/sysfs.h   2013-05-31 13:45:28.000000000 +0000
8162 +++ linux-3.9.4-vs2.3.6.3/include/linux/sysfs.h 2013-05-31 14:47:11.000000000 +0000
8163 @@ -19,6 +19,8 @@
8164  #include <linux/kobject_ns.h>
8165  #include <linux/atomic.h>
8166  
8167 +#define SYSFS_SUPER_MAGIC      0x62656572
8168 +
8169  struct kobject;
8170  struct module;
8171  enum kobj_ns_type;
8172 diff -NurpP --minimal linux-3.9.4/include/linux/types.h linux-3.9.4-vs2.3.6.3/include/linux/types.h
8173 --- linux-3.9.4/include/linux/types.h   2013-02-19 13:58:52.000000000 +0000
8174 +++ linux-3.9.4-vs2.3.6.3/include/linux/types.h 2013-05-31 14:47:11.000000000 +0000
8175 @@ -32,6 +32,9 @@ typedef __kernel_uid32_t      uid_t;
8176  typedef __kernel_gid32_t       gid_t;
8177  typedef __kernel_uid16_t        uid16_t;
8178  typedef __kernel_gid16_t        gid16_t;
8179 +typedef unsigned int           xid_t;
8180 +typedef unsigned int           nid_t;
8181 +typedef unsigned int           tag_t;
8182  
8183  typedef unsigned long          uintptr_t;
8184  
8185 diff -NurpP --minimal linux-3.9.4/include/linux/uidgid.h linux-3.9.4-vs2.3.6.3/include/linux/uidgid.h
8186 --- linux-3.9.4/include/linux/uidgid.h  2012-12-11 03:30:57.000000000 +0000
8187 +++ linux-3.9.4-vs2.3.6.3/include/linux/uidgid.h        2013-05-31 14:47:11.000000000 +0000
8188 @@ -23,13 +23,17 @@ typedef struct {
8189         uid_t val;
8190  } kuid_t;
8191  
8192 -
8193  typedef struct {
8194         gid_t val;
8195  } kgid_t;
8196  
8197 +typedef struct {
8198 +       tag_t val;
8199 +} ktag_t;
8200 +
8201  #define KUIDT_INIT(value) (kuid_t){ value }
8202  #define KGIDT_INIT(value) (kgid_t){ value }
8203 +#define KTAGT_INIT(value) (ktag_t){ value }
8204  
8205  static inline uid_t __kuid_val(kuid_t uid)
8206  {
8207 @@ -41,10 +45,16 @@ static inline gid_t __kgid_val(kgid_t gi
8208         return gid.val;
8209  }
8210  
8211 +static inline tag_t __ktag_val(ktag_t tag)
8212 +{
8213 +       return tag.val;
8214 +}
8215 +
8216  #else
8217  
8218  typedef uid_t kuid_t;
8219  typedef gid_t kgid_t;
8220 +typedef tag_t ktag_t;
8221  
8222  static inline uid_t __kuid_val(kuid_t uid)
8223  {
8224 @@ -56,16 +66,24 @@ static inline gid_t __kgid_val(kgid_t gi
8225         return gid;
8226  }
8227  
8228 +static inline tag_t __ktag_val(ktag_t tag)
8229 +{
8230 +       return tag;
8231 +}
8232 +
8233  #define KUIDT_INIT(value) ((kuid_t) value )
8234  #define KGIDT_INIT(value) ((kgid_t) value )
8235 +#define KTAGT_INIT(value) ((ktag_t) value )
8236  
8237  #endif
8238  
8239  #define GLOBAL_ROOT_UID KUIDT_INIT(0)
8240  #define GLOBAL_ROOT_GID KGIDT_INIT(0)
8241 +#define GLOBAL_ROOT_TAG KTAGT_INIT(0)
8242  
8243  #define INVALID_UID KUIDT_INIT(-1)
8244  #define INVALID_GID KGIDT_INIT(-1)
8245 +#define INVALID_TAG KTAGT_INIT(-1)
8246  
8247  static inline bool uid_eq(kuid_t left, kuid_t right)
8248  {
8249 @@ -77,6 +95,11 @@ static inline bool gid_eq(kgid_t left, k
8250         return __kgid_val(left) == __kgid_val(right);
8251  }
8252  
8253 +static inline bool tag_eq(ktag_t left, ktag_t right)
8254 +{
8255 +       return __ktag_val(left) == __ktag_val(right);
8256 +}
8257 +
8258  static inline bool uid_gt(kuid_t left, kuid_t right)
8259  {
8260         return __kuid_val(left) > __kuid_val(right);
8261 @@ -127,13 +150,21 @@ static inline bool gid_valid(kgid_t gid)
8262         return !gid_eq(gid, INVALID_GID);
8263  }
8264  
8265 +static inline bool tag_valid(ktag_t tag)
8266 +{
8267 +       return !tag_eq(tag, INVALID_TAG);
8268 +}
8269 +
8270  #ifdef CONFIG_USER_NS
8271  
8272  extern kuid_t make_kuid(struct user_namespace *from, uid_t uid);
8273  extern kgid_t make_kgid(struct user_namespace *from, gid_t gid);
8274 +extern krag_t make_ktag(struct user_namespace *from, gid_t gid);
8275  
8276  extern uid_t from_kuid(struct user_namespace *to, kuid_t uid);
8277  extern gid_t from_kgid(struct user_namespace *to, kgid_t gid);
8278 +extern tag_t from_ktag(struct user_namespace *to, ktag_t tag);
8279 +
8280  extern uid_t from_kuid_munged(struct user_namespace *to, kuid_t uid);
8281  extern gid_t from_kgid_munged(struct user_namespace *to, kgid_t gid);
8282  
8283 @@ -159,6 +190,11 @@ static inline kgid_t make_kgid(struct us
8284         return KGIDT_INIT(gid);
8285  }
8286  
8287 +static inline ktag_t make_ktag(struct user_namespace *from, tag_t tag)
8288 +{
8289 +       return KTAGT_INIT(tag);
8290 +}
8291 +
8292  static inline uid_t from_kuid(struct user_namespace *to, kuid_t kuid)
8293  {
8294         return __kuid_val(kuid);
8295 @@ -169,6 +205,11 @@ static inline gid_t from_kgid(struct use
8296         return __kgid_val(kgid);
8297  }
8298  
8299 +static inline tag_t from_ktag(struct user_namespace *to, ktag_t ktag)
8300 +{
8301 +       return __ktag_val(ktag);
8302 +}
8303 +
8304  static inline uid_t from_kuid_munged(struct user_namespace *to, kuid_t kuid)
8305  {
8306         uid_t uid = from_kuid(to, kuid);
8307 diff -NurpP --minimal linux-3.9.4/include/linux/vroot.h linux-3.9.4-vs2.3.6.3/include/linux/vroot.h
8308 --- linux-3.9.4/include/linux/vroot.h   1970-01-01 00:00:00.000000000 +0000
8309 +++ linux-3.9.4-vs2.3.6.3/include/linux/vroot.h 2013-05-31 14:47:11.000000000 +0000
8310 @@ -0,0 +1,51 @@
8311 +
8312 +/*
8313 + * include/linux/vroot.h
8314 + *
8315 + * written by Herbert Pötzl, 9/11/2002
8316 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
8317 + *
8318 + * Copyright (C) 2002-2007 by Herbert Pötzl.
8319 + * Redistribution of this file is permitted under the
8320 + * GNU General Public License.
8321 + */
8322 +
8323 +#ifndef _LINUX_VROOT_H
8324 +#define _LINUX_VROOT_H
8325 +
8326 +
8327 +#ifdef __KERNEL__
8328 +
8329 +/* Possible states of device */
8330 +enum {
8331 +       Vr_unbound,
8332 +       Vr_bound,
8333 +};
8334 +
8335 +struct vroot_device {
8336 +       int             vr_number;
8337 +       int             vr_refcnt;
8338 +
8339 +       struct semaphore        vr_ctl_mutex;
8340 +       struct block_device    *vr_device;
8341 +       int                     vr_state;
8342 +};
8343 +
8344 +
8345 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
8346 +
8347 +extern int register_vroot_grb(vroot_grb_func *);
8348 +extern int unregister_vroot_grb(vroot_grb_func *);
8349 +
8350 +#endif /* __KERNEL__ */
8351 +
8352 +#define MAX_VROOT_DEFAULT      8
8353 +
8354 +/*
8355 + * IOCTL commands --- we will commandeer 0x56 ('V')
8356 + */
8357 +
8358 +#define VROOT_SET_DEV          0x5600
8359 +#define VROOT_CLR_DEV          0x5601
8360 +
8361 +#endif /* _LINUX_VROOT_H */
8362 diff -NurpP --minimal linux-3.9.4/include/linux/vs_base.h linux-3.9.4-vs2.3.6.3/include/linux/vs_base.h
8363 --- linux-3.9.4/include/linux/vs_base.h 1970-01-01 00:00:00.000000000 +0000
8364 +++ linux-3.9.4-vs2.3.6.3/include/linux/vs_base.h       2013-05-31 14:47:11.000000000 +0000
8365 @@ -0,0 +1,10 @@
8366 +#ifndef _VS_BASE_H
8367 +#define _VS_BASE_H
8368 +
8369 +#include "vserver/base.h"
8370 +#include "vserver/check.h"
8371 +#include "vserver/debug.h"
8372 +
8373 +#else
8374 +#warning duplicate inclusion
8375 +#endif
8376 diff -NurpP --minimal linux-3.9.4/include/linux/vs_context.h linux-3.9.4-vs2.3.6.3/include/linux/vs_context.h
8377 --- linux-3.9.4/include/linux/vs_context.h      1970-01-01 00:00:00.000000000 +0000
8378 +++ linux-3.9.4-vs2.3.6.3/include/linux/vs_context.h    2013-05-31 14:47:11.000000000 +0000
8379 @@ -0,0 +1,242 @@
8380 +#ifndef _VS_CONTEXT_H
8381 +#define _VS_CONTEXT_H
8382 +
8383 +#include "vserver/base.h"
8384 +#include "vserver/check.h"
8385 +#include "vserver/context.h"
8386 +#include "vserver/history.h"
8387 +#include "vserver/debug.h"
8388 +
8389 +#include <linux/sched.h>
8390 +
8391 +
8392 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
8393 +
8394 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
8395 +       const char *_file, int _line, void *_here)
8396 +{
8397 +       if (!vxi)
8398 +               return NULL;
8399 +
8400 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
8401 +               vxi, vxi ? vxi->vx_id : 0,
8402 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8403 +               _file, _line);
8404 +       __vxh_get_vx_info(vxi, _here);
8405 +
8406 +       atomic_inc(&vxi->vx_usecnt);
8407 +       return vxi;
8408 +}
8409 +
8410 +
8411 +extern void free_vx_info(struct vx_info *);
8412 +
8413 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
8414 +
8415 +static inline void __put_vx_info(struct vx_info *vxi,
8416 +       const char *_file, int _line, void *_here)
8417 +{
8418 +       if (!vxi)
8419 +               return;
8420 +
8421 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
8422 +               vxi, vxi ? vxi->vx_id : 0,
8423 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8424 +               _file, _line);
8425 +       __vxh_put_vx_info(vxi, _here);
8426 +
8427 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
8428 +               free_vx_info(vxi);
8429 +}
8430 +
8431 +
8432 +#define init_vx_info(p, i) \
8433 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
8434 +
8435 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
8436 +       const char *_file, int _line, void *_here)
8437 +{
8438 +       if (vxi) {
8439 +               vxlprintk(VXD_CBIT(xid, 3),
8440 +                       "init_vx_info(%p[#%d.%d])",
8441 +                       vxi, vxi ? vxi->vx_id : 0,
8442 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8443 +                       _file, _line);
8444 +               __vxh_init_vx_info(vxi, vxp, _here);
8445 +
8446 +               atomic_inc(&vxi->vx_usecnt);
8447 +       }
8448 +       *vxp = vxi;
8449 +}
8450 +
8451 +
8452 +#define set_vx_info(p, i) \
8453 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
8454 +
8455 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
8456 +       const char *_file, int _line, void *_here)
8457 +{
8458 +       struct vx_info *vxo;
8459 +
8460 +       if (!vxi)
8461 +               return;
8462 +
8463 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
8464 +               vxi, vxi ? vxi->vx_id : 0,
8465 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8466 +               _file, _line);
8467 +       __vxh_set_vx_info(vxi, vxp, _here);
8468 +
8469 +       atomic_inc(&vxi->vx_usecnt);
8470 +       vxo = xchg(vxp, vxi);
8471 +       BUG_ON(vxo);
8472 +}
8473 +
8474 +
8475 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
8476 +
8477 +static inline void __clr_vx_info(struct vx_info **vxp,
8478 +       const char *_file, int _line, void *_here)
8479 +{
8480 +       struct vx_info *vxo;
8481 +
8482 +       vxo = xchg(vxp, NULL);
8483 +       if (!vxo)
8484 +               return;
8485 +
8486 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
8487 +               vxo, vxo ? vxo->vx_id : 0,
8488 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
8489 +               _file, _line);
8490 +       __vxh_clr_vx_info(vxo, vxp, _here);
8491 +
8492 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
8493 +               free_vx_info(vxo);
8494 +}
8495 +
8496 +
8497 +#define claim_vx_info(v, p) \
8498 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
8499 +
8500 +static inline void __claim_vx_info(struct vx_info *vxi,
8501 +       struct task_struct *task,
8502 +       const char *_file, int _line, void *_here)
8503 +{
8504 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
8505 +               vxi, vxi ? vxi->vx_id : 0,
8506 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8507 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
8508 +               task, _file, _line);
8509 +       __vxh_claim_vx_info(vxi, task, _here);
8510 +
8511 +       atomic_inc(&vxi->vx_tasks);
8512 +}
8513 +
8514 +
8515 +extern void unhash_vx_info(struct vx_info *);
8516 +
8517 +#define release_vx_info(v, p) \
8518 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
8519 +
8520 +static inline void __release_vx_info(struct vx_info *vxi,
8521 +       struct task_struct *task,
8522 +       const char *_file, int _line, void *_here)
8523 +{
8524 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
8525 +               vxi, vxi ? vxi->vx_id : 0,
8526 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8527 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
8528 +               task, _file, _line);
8529 +       __vxh_release_vx_info(vxi, task, _here);
8530 +
8531 +       might_sleep();
8532 +
8533 +       if (atomic_dec_and_test(&vxi->vx_tasks))
8534 +               unhash_vx_info(vxi);
8535 +}
8536 +
8537 +
8538 +#define task_get_vx_info(p) \
8539 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
8540 +
8541 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
8542 +       const char *_file, int _line, void *_here)
8543 +{
8544 +       struct vx_info *vxi;
8545 +
8546 +       task_lock(p);
8547 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
8548 +               p, _file, _line);
8549 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
8550 +       task_unlock(p);
8551 +       return vxi;
8552 +}
8553 +
8554 +
8555 +static inline void __wakeup_vx_info(struct vx_info *vxi)
8556 +{
8557 +       if (waitqueue_active(&vxi->vx_wait))
8558 +               wake_up_interruptible(&vxi->vx_wait);
8559 +}
8560 +
8561 +
8562 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
8563 +
8564 +static inline void __enter_vx_info(struct vx_info *vxi,
8565 +       struct vx_info_save *vxis, const char *_file, int _line)
8566 +{
8567 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
8568 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
8569 +               current->xid, current->vx_info, _file, _line);
8570 +       vxis->vxi = xchg(&current->vx_info, vxi);
8571 +       vxis->xid = current->xid;
8572 +       current->xid = vxi ? vxi->vx_id : 0;
8573 +}
8574 +
8575 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
8576 +
8577 +static inline void __leave_vx_info(struct vx_info_save *vxis,
8578 +       const char *_file, int _line)
8579 +{
8580 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
8581 +               vxis, vxis->xid, vxis->vxi, current,
8582 +               current->xid, current->vx_info, _file, _line);
8583 +       (void)xchg(&current->vx_info, vxis->vxi);
8584 +       current->xid = vxis->xid;
8585 +}
8586 +
8587 +
8588 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
8589 +{
8590 +       vxis->vxi = xchg(&current->vx_info, NULL);
8591 +       vxis->xid = xchg(&current->xid, (xid_t)0);
8592 +}
8593 +
8594 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
8595 +{
8596 +       (void)xchg(&current->xid, vxis->xid);
8597 +       (void)xchg(&current->vx_info, vxis->vxi);
8598 +}
8599 +
8600 +#define task_is_init(p) \
8601 +       __task_is_init(p, __FILE__, __LINE__, __HERE__)
8602 +
8603 +static inline int __task_is_init(struct task_struct *p,
8604 +       const char *_file, int _line, void *_here)
8605 +{
8606 +       int is_init = is_global_init(p);
8607 +
8608 +       task_lock(p);
8609 +       if (p->vx_info)
8610 +               is_init = p->vx_info->vx_initpid == p->pid;
8611 +       task_unlock(p);
8612 +       return is_init;
8613 +}
8614 +
8615 +extern void exit_vx_info(struct task_struct *, int);
8616 +extern void exit_vx_info_early(struct task_struct *, int);
8617 +
8618 +
8619 +#else
8620 +#warning duplicate inclusion
8621 +#endif
8622 diff -NurpP --minimal linux-3.9.4/include/linux/vs_cowbl.h linux-3.9.4-vs2.3.6.3/include/linux/vs_cowbl.h
8623 --- linux-3.9.4/include/linux/vs_cowbl.h        1970-01-01 00:00:00.000000000 +0000
8624 +++ linux-3.9.4-vs2.3.6.3/include/linux/vs_cowbl.h      2013-05-31 14:47:11.000000000 +0000
8625 @@ -0,0 +1,48 @@
8626 +#ifndef _VS_COWBL_H
8627 +#define _VS_COWBL_H
8628 +
8629 +#include <linux/fs.h>
8630 +#include <linux/dcache.h>
8631 +#include <linux/namei.h>
8632 +#include <linux/slab.h>
8633 +
8634 +extern struct dentry *cow_break_link(const char *pathname);
8635 +
8636 +static inline int cow_check_and_break(struct path *path)
8637 +{
8638 +       struct inode *inode = path->dentry->d_inode;
8639 +       int error = 0;
8640 +
8641 +       /* do we need this check? */
8642 +       if (IS_RDONLY(inode))
8643 +               return -EROFS;
8644 +
8645 +       if (IS_COW(inode)) {
8646 +               if (IS_COW_LINK(inode)) {
8647 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
8648 +                       char *pp, *buf;
8649 +
8650 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
8651 +                       if (!buf) {
8652 +                               return -ENOMEM;
8653 +                       }
8654 +                       pp = d_path(path, buf, PATH_MAX);
8655 +                       new_dentry = cow_break_link(pp);
8656 +                       kfree(buf);
8657 +                       if (!IS_ERR(new_dentry)) {
8658 +                               path->dentry = new_dentry;
8659 +                               dput(old_dentry);
8660 +                       } else
8661 +                               error = PTR_ERR(new_dentry);
8662 +               } else {
8663 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
8664 +                       inode->i_ctime = CURRENT_TIME;
8665 +                       mark_inode_dirty(inode);
8666 +               }
8667 +       }
8668 +       return error;
8669 +}
8670 +
8671 +#else
8672 +#warning duplicate inclusion
8673 +#endif
8674 diff -NurpP --minimal linux-3.9.4/include/linux/vs_cvirt.h linux-3.9.4-vs2.3.6.3/include/linux/vs_cvirt.h
8675 --- linux-3.9.4/include/linux/vs_cvirt.h        1970-01-01 00:00:00.000000000 +0000
8676 +++ linux-3.9.4-vs2.3.6.3/include/linux/vs_cvirt.h      2013-05-31 14:47:11.000000000 +0000
8677 @@ -0,0 +1,50 @@
8678 +#ifndef _VS_CVIRT_H
8679 +#define _VS_CVIRT_H
8680 +
8681 +#include "vserver/cvirt.h"
8682 +#include "vserver/context.h"
8683 +#include "vserver/base.h"
8684 +#include "vserver/check.h"
8685 +#include "vserver/debug.h"
8686 +
8687 +
8688 +static inline void vx_activate_task(struct task_struct *p)
8689 +{
8690 +       struct vx_info *vxi;
8691 +
8692 +       if ((vxi = p->vx_info)) {
8693 +               vx_update_load(vxi);
8694 +               atomic_inc(&vxi->cvirt.nr_running);
8695 +       }
8696 +}
8697 +
8698 +static inline void vx_deactivate_task(struct task_struct *p)
8699 +{
8700 +       struct vx_info *vxi;
8701 +
8702 +       if ((vxi = p->vx_info)) {
8703 +               vx_update_load(vxi);
8704 +               atomic_dec(&vxi->cvirt.nr_running);
8705 +       }
8706 +}
8707 +
8708 +static inline void vx_uninterruptible_inc(struct task_struct *p)
8709 +{
8710 +       struct vx_info *vxi;
8711 +
8712 +       if ((vxi = p->vx_info))
8713 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
8714 +}
8715 +
8716 +static inline void vx_uninterruptible_dec(struct task_struct *p)
8717 +{
8718 +       struct vx_info *vxi;
8719 +
8720 +       if ((vxi = p->vx_info))
8721 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
8722 +}
8723 +
8724 +
8725 +#else
8726 +#warning duplicate inclusion
8727 +#endif
8728 diff -NurpP --minimal linux-3.9.4/include/linux/vs_device.h linux-3.9.4-vs2.3.6.3/include/linux/vs_device.h
8729 --- linux-3.9.4/include/linux/vs_device.h       1970-01-01 00:00:00.000000000 +0000
8730 +++ linux-3.9.4-vs2.3.6.3/include/linux/vs_device.h     2013-05-31 14:47:11.000000000 +0000
8731 @@ -0,0 +1,45 @@
8732 +#ifndef _VS_DEVICE_H
8733 +#define _VS_DEVICE_H
8734 +
8735 +#include "vserver/base.h"
8736 +#include "vserver/device.h"
8737 +#include "vserver/debug.h"
8738 +
8739 +
8740 +#ifdef CONFIG_VSERVER_DEVICE
8741 +
8742 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
8743 +
8744 +#define vs_device_perm(v, d, m, p) \
8745 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
8746 +
8747 +#else
8748 +
8749 +static inline
8750 +int vs_map_device(struct vx_info *vxi,
8751 +       dev_t device, dev_t *target, umode_t mode)
8752 +{
8753 +       if (target)
8754 +               *target = device;
8755 +       return ~0;
8756 +}
8757 +
8758 +#define vs_device_perm(v, d, m, p) ((p) == (p))
8759 +
8760 +#endif
8761 +
8762 +
8763 +#define vs_map_chrdev(d, t, p) \
8764 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
8765 +#define vs_map_blkdev(d, t, p) \
8766 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
8767 +
8768 +#define vs_chrdev_perm(d, p) \
8769 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
8770 +#define vs_blkdev_perm(d, p) \
8771 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
8772 +
8773 +
8774 +#else
8775 +#warning duplicate inclusion
8776 +#endif
8777 diff -NurpP --minimal linux-3.9.4/include/linux/vs_dlimit.h linux-3.9.4-vs2.3.6.3/include/linux/vs_dlimit.h
8778 --- linux-3.9.4/include/linux/vs_dlimit.h       1970-01-01 00:00:00.000000000 +0000
8779 +++ linux-3.9.4-vs2.3.6.3/include/linux/vs_dlimit.h     2013-05-31 14:47:11.000000000 +0000
8780 @@ -0,0 +1,215 @@
8781 +#ifndef _VS_DLIMIT_H
8782 +#define _VS_DLIMIT_H
8783 +
8784 +#include <linux/fs.h>
8785 +
8786 +#include "vserver/dlimit.h"
8787 +#include "vserver/base.h"
8788 +#include "vserver/debug.h"
8789 +
8790 +
8791 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
8792 +
8793 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
8794 +       const char *_file, int _line)
8795 +{
8796 +       if (!dli)
8797 +               return NULL;
8798 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
8799 +               dli, dli ? dli->dl_tag : 0,
8800 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
8801 +               _file, _line);
8802 +       atomic_inc(&dli->dl_usecnt);
8803 +       return dli;
8804 +}
8805 +
8806 +
8807 +#define free_dl_info(i) \
8808 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
8809 +
8810 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
8811 +
8812 +static inline void __put_dl_info(struct dl_info *dli,
8813 +       const char *_file, int _line)
8814 +{
8815 +       if (!dli)
8816 +               return;
8817 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
8818 +               dli, dli ? dli->dl_tag : 0,
8819 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
8820 +               _file, _line);
8821 +       if (atomic_dec_and_test(&dli->dl_usecnt))
8822 +               free_dl_info(dli);
8823 +}
8824 +
8825 +
8826 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
8827 +
8828 +static inline int __dl_alloc_space(struct super_block *sb,
8829 +       tag_t tag, dlsize_t nr, const char *file, int line)
8830 +{
8831 +       struct dl_info *dli = NULL;
8832 +       int ret = 0;
8833 +
8834 +       if (nr == 0)
8835 +               goto out;
8836 +       dli = locate_dl_info(sb, tag);
8837 +       if (!dli)
8838 +               goto out;
8839 +
8840 +       spin_lock(&dli->dl_lock);
8841 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
8842 +       if (!ret)
8843 +               dli->dl_space_used += nr;
8844 +       spin_unlock(&dli->dl_lock);
8845 +       put_dl_info(dli);
8846 +out:
8847 +       vxlprintk(VXD_CBIT(dlim, 1),
8848 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
8849 +               sb, tag, __dlimit_char(dli), (long long)nr,
8850 +               ret, file, line);
8851 +       return ret ? -ENOSPC : 0;
8852 +}
8853 +
8854 +static inline void __dl_free_space(struct super_block *sb,
8855 +       tag_t tag, dlsize_t nr, const char *_file, int _line)
8856 +{
8857 +       struct dl_info *dli = NULL;
8858 +
8859 +       if (nr == 0)
8860 +               goto out;
8861 +       dli = locate_dl_info(sb, tag);
8862 +       if (!dli)
8863 +               goto out;
8864 +
8865 +       spin_lock(&dli->dl_lock);
8866 +       if (dli->dl_space_used > nr)
8867 +               dli->dl_space_used -= nr;
8868 +       else
8869 +               dli->dl_space_used = 0;
8870 +       spin_unlock(&dli->dl_lock);
8871 +       put_dl_info(dli);
8872 +out:
8873 +       vxlprintk(VXD_CBIT(dlim, 1),
8874 +               "FREE  (%p,#%d)%c %lld bytes",
8875 +               sb, tag, __dlimit_char(dli), (long long)nr,
8876 +               _file, _line);
8877 +}
8878 +
8879 +static inline int __dl_alloc_inode(struct super_block *sb,
8880 +       tag_t tag, const char *_file, int _line)
8881 +{
8882 +       struct dl_info *dli;
8883 +       int ret = 0;
8884 +
8885 +       dli = locate_dl_info(sb, tag);
8886 +       if (!dli)
8887 +               goto out;
8888 +
8889 +       spin_lock(&dli->dl_lock);
8890 +       dli->dl_inodes_used++;
8891 +       ret = (dli->dl_inodes_used > dli->dl_inodes_total);
8892 +       spin_unlock(&dli->dl_lock);
8893 +       put_dl_info(dli);
8894 +out:
8895 +       vxlprintk(VXD_CBIT(dlim, 0),
8896 +               "ALLOC (%p,#%d)%c inode (%d)",
8897 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
8898 +       return ret ? -ENOSPC : 0;
8899 +}
8900 +
8901 +static inline void __dl_free_inode(struct super_block *sb,
8902 +       tag_t tag, const char *_file, int _line)
8903 +{
8904 +       struct dl_info *dli;
8905 +
8906 +       dli = locate_dl_info(sb, tag);
8907 +       if (!dli)
8908 +               goto out;
8909 +
8910 +       spin_lock(&dli->dl_lock);
8911 +       if (dli->dl_inodes_used > 1)
8912 +               dli->dl_inodes_used--;
8913 +       else
8914 +               dli->dl_inodes_used = 0;
8915 +       spin_unlock(&dli->dl_lock);
8916 +       put_dl_info(dli);
8917 +out:
8918 +       vxlprintk(VXD_CBIT(dlim, 0),
8919 +               "FREE  (%p,#%d)%c inode",
8920 +               sb, tag, __dlimit_char(dli), _file, _line);
8921 +}
8922 +
8923 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
8924 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
8925 +       const char *_file, int _line)
8926 +{
8927 +       struct dl_info *dli;
8928 +       uint64_t broot, bfree;
8929 +
8930 +       dli = locate_dl_info(sb, tag);
8931 +       if (!dli)
8932 +               return;
8933 +
8934 +       spin_lock(&dli->dl_lock);
8935 +       broot = (dli->dl_space_total -
8936 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
8937 +               >> sb->s_blocksize_bits;
8938 +       bfree = (dli->dl_space_total - dli->dl_space_used)
8939 +                       >> sb->s_blocksize_bits;
8940 +       spin_unlock(&dli->dl_lock);
8941 +
8942 +       vxlprintk(VXD_CBIT(dlim, 2),
8943 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
8944 +               (long long)bfree, (long long)broot,
8945 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
8946 +               _file, _line);
8947 +       if (free_blocks) {
8948 +               if (*free_blocks > bfree)
8949 +                       *free_blocks = bfree;
8950 +       }
8951 +       if (root_blocks) {
8952 +               if (*root_blocks > broot)
8953 +                       *root_blocks = broot;
8954 +       }
8955 +       put_dl_info(dli);
8956 +}
8957 +
8958 +#define dl_prealloc_space(in, bytes) \
8959 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8960 +               __FILE__, __LINE__ )
8961 +
8962 +#define dl_alloc_space(in, bytes) \
8963 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8964 +               __FILE__, __LINE__ )
8965 +
8966 +#define dl_reserve_space(in, bytes) \
8967 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8968 +               __FILE__, __LINE__ )
8969 +
8970 +#define dl_claim_space(in, bytes) (0)
8971 +
8972 +#define dl_release_space(in, bytes) \
8973 +       __dl_free_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8974 +               __FILE__, __LINE__ )
8975 +
8976 +#define dl_free_space(in, bytes) \
8977 +       __dl_free_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8978 +               __FILE__, __LINE__ )
8979 +
8980 +
8981 +
8982 +#define dl_alloc_inode(in) \
8983 +       __dl_alloc_inode((in)->i_sb, i_tag_read(in), __FILE__, __LINE__ )
8984 +
8985 +#define dl_free_inode(in) \
8986 +       __dl_free_inode((in)->i_sb, i_tag_read(in), __FILE__, __LINE__ )
8987 +
8988 +
8989 +#define dl_adjust_block(sb, tag, fb, rb) \
8990 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
8991 +
8992 +
8993 +#else
8994 +#warning duplicate inclusion
8995 +#endif
8996 diff -NurpP --minimal linux-3.9.4/include/linux/vs_inet.h linux-3.9.4-vs2.3.6.3/include/linux/vs_inet.h
8997 --- linux-3.9.4/include/linux/vs_inet.h 1970-01-01 00:00:00.000000000 +0000
8998 +++ linux-3.9.4-vs2.3.6.3/include/linux/vs_inet.h       2013-05-31 14:47:11.000000000 +0000
8999 @@ -0,0 +1,364 @@
9000 +#ifndef _VS_INET_H
9001 +#define _VS_INET_H
9002 +
9003 +#include "vserver/base.h"
9004 +#include "vserver/network.h"
9005 +#include "vserver/debug.h"
9006 +
9007 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
9008 +
9009 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
9010 +                       NIPQUAD((a)->mask), (a)->type
9011 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
9012 +
9013 +#define NIPQUAD(addr) \
9014 +       ((unsigned char *)&addr)[0], \
9015 +       ((unsigned char *)&addr)[1], \
9016 +       ((unsigned char *)&addr)[2], \
9017 +       ((unsigned char *)&addr)[3]
9018 +
9019 +#define NIPQUAD_FMT "%u.%u.%u.%u"
9020 +
9021 +
9022 +static inline
9023 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
9024 +{
9025 +       __be32 ip = nxa->ip[0].s_addr;
9026 +       __be32 mask = nxa->mask.s_addr;
9027 +       __be32 bcast = ip | ~mask;
9028 +       int ret = 0;
9029 +
9030 +       switch (nxa->type & tmask) {
9031 +       case NXA_TYPE_MASK:
9032 +               ret = (ip == (addr & mask));
9033 +               break;
9034 +       case NXA_TYPE_ADDR:
9035 +               ret = 3;
9036 +               if (addr == ip)
9037 +                       break;
9038 +               /* fall through to broadcast */
9039 +       case NXA_MOD_BCAST:
9040 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
9041 +               break;
9042 +       case NXA_TYPE_RANGE:
9043 +               ret = ((nxa->ip[0].s_addr <= addr) &&
9044 +                       (nxa->ip[1].s_addr > addr));
9045 +               break;
9046 +       case NXA_TYPE_ANY:
9047 +               ret = 2;
9048 +               break;
9049 +       }
9050 +
9051 +       vxdprintk(VXD_CBIT(net, 0),
9052 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
9053 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
9054 +       return ret;
9055 +}
9056 +
9057 +static inline
9058 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
9059 +{
9060 +       struct nx_addr_v4 *nxa;
9061 +       unsigned long irqflags;
9062 +       int ret = 1;
9063 +
9064 +       if (!nxi)
9065 +               goto out;
9066 +
9067 +       ret = 2;
9068 +       /* allow 127.0.0.1 when remapping lback */
9069 +       if ((tmask & NXA_LOOPBACK) &&
9070 +               (addr == IPI_LOOPBACK) &&
9071 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9072 +               goto out;
9073 +       ret = 3;
9074 +       /* check for lback address */
9075 +       if ((tmask & NXA_MOD_LBACK) &&
9076 +               (nxi->v4_lback.s_addr == addr))
9077 +               goto out;
9078 +       ret = 4;
9079 +       /* check for broadcast address */
9080 +       if ((tmask & NXA_MOD_BCAST) &&
9081 +               (nxi->v4_bcast.s_addr == addr))
9082 +               goto out;
9083 +       ret = 5;
9084 +
9085 +       /* check for v4 addresses */
9086 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
9087 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
9088 +               if (v4_addr_match(nxa, addr, tmask))
9089 +                       goto out_unlock;
9090 +       ret = 0;
9091 +out_unlock:
9092 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
9093 +out:
9094 +       vxdprintk(VXD_CBIT(net, 0),
9095 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
9096 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
9097 +       return ret;
9098 +}
9099 +
9100 +static inline
9101 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
9102 +{
9103 +       /* FIXME: needs full range checks */
9104 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
9105 +}
9106 +
9107 +static inline
9108 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
9109 +{
9110 +       struct nx_addr_v4 *ptr;
9111 +       unsigned long irqflags;
9112 +       int ret = 1;
9113 +
9114 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
9115 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
9116 +               if (v4_nx_addr_match(ptr, nxa, mask))
9117 +                       goto out_unlock;
9118 +       ret = 0;
9119 +out_unlock:
9120 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
9121 +       return ret;
9122 +}
9123 +
9124 +#include <net/inet_sock.h>
9125 +
9126 +/*
9127 + *     Check if a given address matches for a socket
9128 + *
9129 + *     nxi:            the socket's nx_info if any
9130 + *     addr:           to be verified address
9131 + */
9132 +static inline
9133 +int v4_sock_addr_match (
9134 +       struct nx_info *nxi,
9135 +       struct inet_sock *inet,
9136 +       __be32 addr)
9137 +{
9138 +       __be32 saddr = inet->inet_rcv_saddr;
9139 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
9140 +
9141 +       if (addr && (saddr == addr || bcast == addr))
9142 +               return 1;
9143 +       if (!saddr)
9144 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
9145 +       return 0;
9146 +}
9147 +
9148 +
9149 +/* inet related checks and helpers */
9150 +
9151 +
9152 +struct in_ifaddr;
9153 +struct net_device;
9154 +struct sock;
9155 +
9156 +#ifdef CONFIG_INET
9157 +
9158 +#include <linux/netdevice.h>
9159 +#include <linux/inetdevice.h>
9160 +#include <net/inet_sock.h>
9161 +#include <net/inet_timewait_sock.h>
9162 +
9163 +
9164 +int dev_in_nx_info(struct net_device *, struct nx_info *);
9165 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
9166 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
9167 +
9168 +
9169 +/*
9170 + *     check if address is covered by socket
9171 + *
9172 + *     sk:     the socket to check against
9173 + *     addr:   the address in question (must be != 0)
9174 + */
9175 +
9176 +static inline
9177 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
9178 +{
9179 +       struct nx_info *nxi = sk->sk_nx_info;
9180 +       __be32 saddr = sk_rcv_saddr(sk);
9181 +
9182 +       vxdprintk(VXD_CBIT(net, 5),
9183 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
9184 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
9185 +               (sk->sk_socket?sk->sk_socket->flags:0));
9186 +
9187 +       if (saddr) {            /* direct address match */
9188 +               return v4_addr_match(nxa, saddr, -1);
9189 +       } else if (nxi) {       /* match against nx_info */
9190 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
9191 +       } else {                /* unrestricted any socket */
9192 +               return 1;
9193 +       }
9194 +}
9195 +
9196 +
9197 +
9198 +static inline
9199 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
9200 +{
9201 +       vxdprintk(VXD_CBIT(net, 1),
9202 +               "nx_dev_visible(%p[#%u],%p " VS_Q("%s") ") %d",
9203 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
9204 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
9205 +
9206 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9207 +               return 1;
9208 +       if (dev_in_nx_info(dev, nxi))
9209 +               return 1;
9210 +       return 0;
9211 +}
9212 +
9213 +
9214 +static inline
9215 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
9216 +{
9217 +       if (!nxi)
9218 +               return 1;
9219 +       if (!ifa)
9220 +               return 0;
9221 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
9222 +}
9223 +
9224 +static inline
9225 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
9226 +{
9227 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
9228 +               nxi, nxi ? nxi->nx_id : 0, ifa,
9229 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
9230 +
9231 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9232 +               return 1;
9233 +       if (v4_ifa_in_nx_info(ifa, nxi))
9234 +               return 1;
9235 +       return 0;
9236 +}
9237 +
9238 +
9239 +struct nx_v4_sock_addr {
9240 +       __be32 saddr;   /* Address used for validation */
9241 +       __be32 baddr;   /* Address used for socket bind */
9242 +};
9243 +
9244 +static inline
9245 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
9246 +       struct nx_v4_sock_addr *nsa)
9247 +{
9248 +       struct sock *sk = &inet->sk;
9249 +       struct nx_info *nxi = sk->sk_nx_info;
9250 +       __be32 saddr = addr->sin_addr.s_addr;
9251 +       __be32 baddr = saddr;
9252 +
9253 +       vxdprintk(VXD_CBIT(net, 3),
9254 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
9255 +               sk, sk->sk_nx_info, sk->sk_socket,
9256 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
9257 +               NIPQUAD(saddr));
9258 +
9259 +       if (nxi) {
9260 +               if (saddr == INADDR_ANY) {
9261 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
9262 +                               baddr = nxi->v4.ip[0].s_addr;
9263 +               } else if (saddr == IPI_LOOPBACK) {
9264 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9265 +                               baddr = nxi->v4_lback.s_addr;
9266 +               } else if (!ipv4_is_multicast(saddr) ||
9267 +                       !nx_info_ncaps(nxi, NXC_MULTICAST)) {
9268 +                       /* normal address bind */
9269 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
9270 +                               return -EADDRNOTAVAIL;
9271 +               }
9272 +       }
9273 +
9274 +       vxdprintk(VXD_CBIT(net, 3),
9275 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
9276 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
9277 +
9278 +       nsa->saddr = saddr;
9279 +       nsa->baddr = baddr;
9280 +       return 0;
9281 +}
9282 +
9283 +static inline
9284 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
9285 +{
9286 +       inet->inet_saddr = nsa->baddr;
9287 +       inet->inet_rcv_saddr = nsa->baddr;
9288 +}
9289 +
9290 +
9291 +/*
9292 + *      helper to simplify inet_lookup_listener
9293 + *
9294 + *      nxi:   the socket's nx_info if any
9295 + *      addr:  to be verified address
9296 + *      saddr: socket address
9297 + */
9298 +static inline int v4_inet_addr_match (
9299 +       struct nx_info *nxi,
9300 +       __be32 addr,
9301 +       __be32 saddr)
9302 +{
9303 +       if (addr && (saddr == addr))
9304 +               return 1;
9305 +       if (!saddr)
9306 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
9307 +       return 0;
9308 +}
9309 +
9310 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
9311 +{
9312 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
9313 +               (addr == nxi->v4_lback.s_addr))
9314 +               return IPI_LOOPBACK;
9315 +       return addr;
9316 +}
9317 +
9318 +static inline
9319 +int nx_info_has_v4(struct nx_info *nxi)
9320 +{
9321 +       if (!nxi)
9322 +               return 1;
9323 +       if (NX_IPV4(nxi))
9324 +               return 1;
9325 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9326 +               return 1;
9327 +       return 0;
9328 +}
9329 +
9330 +#else /* CONFIG_INET */
9331 +
9332 +static inline
9333 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
9334 +{
9335 +       return 1;
9336 +}
9337 +
9338 +static inline
9339 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
9340 +{
9341 +       return 1;
9342 +}
9343 +
9344 +static inline
9345 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
9346 +{
9347 +       return 1;
9348 +}
9349 +
9350 +static inline
9351 +int nx_info_has_v4(struct nx_info *nxi)
9352 +{
9353 +       return 0;
9354 +}
9355 +
9356 +#endif /* CONFIG_INET */
9357 +
9358 +#define current_nx_info_has_v4() \
9359 +       nx_info_has_v4(current_nx_info())
9360 +
9361 +#else
9362 +// #warning duplicate inclusion
9363 +#endif
9364 diff -NurpP --minimal linux-3.9.4/include/linux/vs_inet6.h linux-3.9.4-vs2.3.6.3/include/linux/vs_inet6.h
9365 --- linux-3.9.4/include/linux/vs_inet6.h        1970-01-01 00:00:00.000000000 +0000
9366 +++ linux-3.9.4-vs2.3.6.3/include/linux/vs_inet6.h      2013-05-31 14:47:11.000000000 +0000
9367 @@ -0,0 +1,257 @@
9368 +#ifndef _VS_INET6_H
9369 +#define _VS_INET6_H
9370 +
9371 +#include "vserver/base.h"
9372 +#include "vserver/network.h"
9373 +#include "vserver/debug.h"
9374 +
9375 +#include <net/ipv6.h>
9376 +
9377 +#define NXAV6(a)       &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
9378 +#define NXAV6_FMT      "[%pI6/%pI6/%d:%04x]"
9379 +
9380 +
9381 +#ifdef CONFIG_IPV6
9382 +
9383 +static inline
9384 +int v6_addr_match(struct nx_addr_v6 *nxa,
9385 +       const struct in6_addr *addr, uint16_t mask)
9386 +{
9387 +       int ret = 0;
9388 +
9389 +       switch (nxa->type & mask) {
9390 +       case NXA_TYPE_MASK:
9391 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
9392 +               break;
9393 +       case NXA_TYPE_ADDR:
9394 +               ret = ipv6_addr_equal(&nxa->ip, addr);
9395 +               break;
9396 +       case NXA_TYPE_ANY:
9397 +               ret = 1;
9398 +               break;
9399 +       }
9400 +       vxdprintk(VXD_CBIT(net, 0),
9401 +               "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
9402 +               nxa, NXAV6(nxa), addr, mask, ret);
9403 +       return ret;
9404 +}
9405 +
9406 +static inline
9407 +int v6_addr_in_nx_info(struct nx_info *nxi,
9408 +       const struct in6_addr *addr, uint16_t mask)
9409 +{
9410 +       struct nx_addr_v6 *nxa;
9411 +       unsigned long irqflags;
9412 +       int ret = 1;
9413 +
9414 +       if (!nxi)
9415 +               goto out;
9416 +
9417 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
9418 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
9419 +               if (v6_addr_match(nxa, addr, mask))
9420 +                       goto out_unlock;
9421 +       ret = 0;
9422 +out_unlock:
9423 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
9424 +out:
9425 +       vxdprintk(VXD_CBIT(net, 0),
9426 +               "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
9427 +               nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
9428 +       return ret;
9429 +}
9430 +
9431 +static inline
9432 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
9433 +{
9434 +       /* FIXME: needs full range checks */
9435 +       return v6_addr_match(nxa, &addr->ip, mask);
9436 +}
9437 +
9438 +static inline
9439 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
9440 +{
9441 +       struct nx_addr_v6 *ptr;
9442 +       unsigned long irqflags;
9443 +       int ret = 1;
9444 +
9445 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
9446 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
9447 +               if (v6_nx_addr_match(ptr, nxa, mask))
9448 +                       goto out_unlock;
9449 +       ret = 0;
9450 +out_unlock:
9451 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
9452 +       return ret;
9453 +}
9454 +
9455 +
9456 +/*
9457 + *     Check if a given address matches for a socket
9458 + *
9459 + *     nxi:            the socket's nx_info if any
9460 + *     addr:           to be verified address
9461 + */
9462 +static inline
9463 +int v6_sock_addr_match (
9464 +       struct nx_info *nxi,
9465 +       struct inet_sock *inet,
9466 +       struct in6_addr *addr)
9467 +{
9468 +       struct sock *sk = &inet->sk;
9469 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
9470 +
9471 +       if (!ipv6_addr_any(addr) &&
9472 +               ipv6_addr_equal(saddr, addr))
9473 +               return 1;
9474 +       if (ipv6_addr_any(saddr))
9475 +               return v6_addr_in_nx_info(nxi, addr, -1);
9476 +       return 0;
9477 +}
9478 +
9479 +/*
9480 + *     check if address is covered by socket
9481 + *
9482 + *     sk:     the socket to check against
9483 + *     addr:   the address in question (must be != 0)
9484 + */
9485 +
9486 +static inline
9487 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
9488 +{
9489 +       struct nx_info *nxi = sk->sk_nx_info;
9490 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
9491 +
9492 +       vxdprintk(VXD_CBIT(net, 5),
9493 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
9494 +               sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
9495 +               (sk->sk_socket?sk->sk_socket->flags:0));
9496 +
9497 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
9498 +               return v6_addr_match(nxa, saddr, -1);
9499 +       } else if (nxi) {               /* match against nx_info */
9500 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
9501 +       } else {                        /* unrestricted any socket */
9502 +               return 1;
9503 +       }
9504 +}
9505 +
9506 +
9507 +/* inet related checks and helpers */
9508 +
9509 +
9510 +struct in_ifaddr;
9511 +struct net_device;
9512 +struct sock;
9513 +
9514 +
9515 +#include <linux/netdevice.h>
9516 +#include <linux/inetdevice.h>
9517 +#include <net/inet_timewait_sock.h>
9518 +
9519 +
9520 +int dev_in_nx_info(struct net_device *, struct nx_info *);
9521 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
9522 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
9523 +
9524 +
9525 +
9526 +static inline
9527 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
9528 +{
9529 +       if (!nxi)
9530 +               return 1;
9531 +       if (!ifa)
9532 +               return 0;
9533 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
9534 +}
9535 +
9536 +static inline
9537 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
9538 +{
9539 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
9540 +               nxi, nxi ? nxi->nx_id : 0, ifa,
9541 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
9542 +
9543 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9544 +               return 1;
9545 +       if (v6_ifa_in_nx_info(ifa, nxi))
9546 +               return 1;
9547 +       return 0;
9548 +}
9549 +
9550 +
9551 +struct nx_v6_sock_addr {
9552 +       struct in6_addr saddr;  /* Address used for validation */
9553 +       struct in6_addr baddr;  /* Address used for socket bind */
9554 +};
9555 +
9556 +static inline
9557 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
9558 +       struct nx_v6_sock_addr *nsa)
9559 +{
9560 +       // struct sock *sk = &inet->sk;
9561 +       // struct nx_info *nxi = sk->sk_nx_info;
9562 +       struct in6_addr saddr = addr->sin6_addr;
9563 +       struct in6_addr baddr = saddr;
9564 +
9565 +       nsa->saddr = saddr;
9566 +       nsa->baddr = baddr;
9567 +       return 0;
9568 +}
9569 +
9570 +static inline
9571 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
9572 +{
9573 +       // struct sock *sk = &inet->sk;
9574 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
9575 +
9576 +       // *saddr = nsa->baddr;
9577 +       // inet->inet_saddr = nsa->baddr;
9578 +}
9579 +
9580 +static inline
9581 +int nx_info_has_v6(struct nx_info *nxi)
9582 +{
9583 +       if (!nxi)
9584 +               return 1;
9585 +       if (NX_IPV6(nxi))
9586 +               return 1;
9587 +       return 0;
9588 +}
9589 +
9590 +#else /* CONFIG_IPV6 */
9591 +
9592 +static inline
9593 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
9594 +{
9595 +       return 1;
9596 +}
9597 +
9598 +
9599 +static inline
9600 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
9601 +{
9602 +       return 1;
9603 +}
9604 +
9605 +static inline
9606 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
9607 +{
9608 +       return 1;
9609 +}
9610 +
9611 +static inline
9612 +int nx_info_has_v6(struct nx_info *nxi)
9613 +{
9614 +       return 0;
9615 +}
9616 +
9617 +#endif /* CONFIG_IPV6 */
9618 +
9619 +#define current_nx_info_has_v6() \
9620 +       nx_info_has_v6(current_nx_info())
9621 +
9622 +#else
9623 +#warning duplicate inclusion
9624 +#endif
9625 diff -NurpP --minimal linux-3.9.4/include/linux/vs_limit.h linux-3.9.4-vs2.3.6.3/include/linux/vs_limit.h
9626 --- linux-3.9.4/include/linux/vs_limit.h        1970-01-01 00:00:00.000000000 +0000
9627 +++ linux-3.9.4-vs2.3.6.3/include/linux/vs_limit.h      2013-05-31 14:47:11.000000000 +0000
9628 @@ -0,0 +1,140 @@
9629 +#ifndef _VS_LIMIT_H
9630 +#define _VS_LIMIT_H
9631 +
9632 +#include "vserver/limit.h"
9633 +#include "vserver/base.h"
9634 +#include "vserver/context.h"
9635 +#include "vserver/debug.h"
9636 +#include "vserver/context.h"
9637 +#include "vserver/limit_int.h"
9638 +
9639 +
9640 +#define vx_acc_cres(v, d, p, r) \
9641 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
9642 +
9643 +#define vx_acc_cres_cond(x, d, p, r) \
9644 +       __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
9645 +       r, d, p, __FILE__, __LINE__)
9646 +
9647 +
9648 +#define vx_add_cres(v, a, p, r) \
9649 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
9650 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
9651 +
9652 +#define vx_add_cres_cond(x, a, p, r) \
9653 +       __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
9654 +       r, a, p, __FILE__, __LINE__)
9655 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
9656 +
9657 +
9658 +/* process and file limits */
9659 +
9660 +#define vx_nproc_inc(p) \
9661 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
9662 +
9663 +#define vx_nproc_dec(p) \
9664 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
9665 +
9666 +#define vx_files_inc(f) \
9667 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
9668 +
9669 +#define vx_files_dec(f) \
9670 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
9671 +
9672 +#define vx_locks_inc(l) \
9673 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
9674 +
9675 +#define vx_locks_dec(l) \
9676 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
9677 +
9678 +#define vx_openfd_inc(f) \
9679 +       vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
9680 +
9681 +#define vx_openfd_dec(f) \
9682 +       vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
9683 +
9684 +
9685 +#define vx_cres_avail(v, n, r) \
9686 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
9687 +
9688 +
9689 +#define vx_nproc_avail(n) \
9690 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
9691 +
9692 +#define vx_files_avail(n) \
9693 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
9694 +
9695 +#define vx_locks_avail(n) \
9696 +       vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
9697 +
9698 +#define vx_openfd_avail(n) \
9699 +       vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
9700 +
9701 +
9702 +/* dentry limits */
9703 +
9704 +#define vx_dentry_inc(d) do {                                          \
9705 +       if ((d)->d_count == 1)                                          \
9706 +               vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY);    \
9707 +       } while (0)
9708 +
9709 +#define vx_dentry_dec(d) do {                                          \
9710 +       if ((d)->d_count == 0)                                          \
9711 +               vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY);    \
9712 +       } while (0)
9713 +
9714 +#define vx_dentry_avail(n) \
9715 +       vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
9716 +
9717 +
9718 +/* socket limits */
9719 +
9720 +#define vx_sock_inc(s) \
9721 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
9722 +
9723 +#define vx_sock_dec(s) \
9724 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
9725 +
9726 +#define vx_sock_avail(n) \
9727 +       vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
9728 +
9729 +
9730 +/* ipc resource limits */
9731 +
9732 +#define vx_ipcmsg_add(v, u, a) \
9733 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
9734 +
9735 +#define vx_ipcmsg_sub(v, u, a) \
9736 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
9737 +
9738 +#define vx_ipcmsg_avail(v, a) \
9739 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
9740 +
9741 +
9742 +#define vx_ipcshm_add(v, k, a) \
9743 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
9744 +
9745 +#define vx_ipcshm_sub(v, k, a) \
9746 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
9747 +
9748 +#define vx_ipcshm_avail(v, a) \
9749 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
9750 +
9751 +
9752 +#define vx_semary_inc(a) \
9753 +       vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
9754 +
9755 +#define vx_semary_dec(a) \
9756 +       vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
9757 +
9758 +
9759 +#define vx_nsems_add(a,n) \
9760 +       vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
9761 +
9762 +#define vx_nsems_sub(a,n) \
9763 +       vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
9764 +
9765 +
9766 +#else
9767 +#warning duplicate inclusion
9768 +#endif
9769 diff -NurpP --minimal linux-3.9.4/include/linux/vs_network.h linux-3.9.4-vs2.3.6.3/include/linux/vs_network.h
9770 --- linux-3.9.4/include/linux/vs_network.h      1970-01-01 00:00:00.000000000 +0000
9771 +++ linux-3.9.4-vs2.3.6.3/include/linux/vs_network.h    2013-05-31 14:47:11.000000000 +0000
9772 @@ -0,0 +1,169 @@
9773 +#ifndef _NX_VS_NETWORK_H
9774 +#define _NX_VS_NETWORK_H
9775 +
9776 +#include "vserver/context.h"
9777 +#include "vserver/network.h"
9778 +#include "vserver/base.h"
9779 +#include "vserver/check.h"
9780 +#include "vserver/debug.h"
9781 +
9782 +#include <linux/sched.h>
9783 +
9784 +
9785 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
9786 +
9787 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
9788 +       const char *_file, int _line)
9789 +{
9790 +       if (!nxi)
9791 +               return NULL;
9792 +
9793 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
9794 +               nxi, nxi ? nxi->nx_id : 0,
9795 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9796 +               _file, _line);
9797 +
9798 +       atomic_inc(&nxi->nx_usecnt);
9799 +       return nxi;
9800 +}
9801 +
9802 +
9803 +extern void free_nx_info(struct nx_info *);
9804 +
9805 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
9806 +
9807 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
9808 +{
9809 +       if (!nxi)
9810 +               return;
9811 +
9812 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
9813 +               nxi, nxi ? nxi->nx_id : 0,
9814 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9815 +               _file, _line);
9816 +
9817 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
9818 +               free_nx_info(nxi);
9819 +}
9820 +
9821 +
9822 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
9823 +
9824 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
9825 +               const char *_file, int _line)
9826 +{
9827 +       if (nxi) {
9828 +               vxlprintk(VXD_CBIT(nid, 3),
9829 +                       "init_nx_info(%p[#%d.%d])",
9830 +                       nxi, nxi ? nxi->nx_id : 0,
9831 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9832 +                       _file, _line);
9833 +
9834 +               atomic_inc(&nxi->nx_usecnt);
9835 +       }
9836 +       *nxp = nxi;
9837 +}
9838 +
9839 +
9840 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
9841 +
9842 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
9843 +       const char *_file, int _line)
9844 +{
9845 +       struct nx_info *nxo;
9846 +
9847 +       if (!nxi)
9848 +               return;
9849 +
9850 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
9851 +               nxi, nxi ? nxi->nx_id : 0,
9852 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9853 +               _file, _line);
9854 +
9855 +       atomic_inc(&nxi->nx_usecnt);
9856 +       nxo = xchg(nxp, nxi);
9857 +       BUG_ON(nxo);
9858 +}
9859 +
9860 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
9861 +
9862 +static inline void __clr_nx_info(struct nx_info **nxp,
9863 +       const char *_file, int _line)
9864 +{
9865 +       struct nx_info *nxo;
9866 +
9867 +       nxo = xchg(nxp, NULL);
9868 +       if (!nxo)
9869 +               return;
9870 +
9871 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
9872 +               nxo, nxo ? nxo->nx_id : 0,
9873 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
9874 +               _file, _line);
9875 +
9876 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
9877 +               free_nx_info(nxo);
9878 +}
9879 +
9880 +
9881 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
9882 +
9883 +static inline void __claim_nx_info(struct nx_info *nxi,
9884 +       struct task_struct *task, const char *_file, int _line)
9885 +{
9886 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
9887 +               nxi, nxi ? nxi->nx_id : 0,
9888 +               nxi?atomic_read(&nxi->nx_usecnt):0,
9889 +               nxi?atomic_read(&nxi->nx_tasks):0,
9890 +               task, _file, _line);
9891 +
9892 +       atomic_inc(&nxi->nx_tasks);
9893 +}
9894 +
9895 +
9896 +extern void unhash_nx_info(struct nx_info *);
9897 +
9898 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
9899 +
9900 +static inline void __release_nx_info(struct nx_info *nxi,
9901 +       struct task_struct *task, const char *_file, int _line)
9902 +{
9903 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
9904 +               nxi, nxi ? nxi->nx_id : 0,
9905 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9906 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
9907 +               task, _file, _line);
9908 +
9909 +       might_sleep();
9910 +
9911 +       if (atomic_dec_and_test(&nxi->nx_tasks))
9912 +               unhash_nx_info(nxi);
9913 +}
9914 +
9915 +
9916 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
9917 +
9918 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
9919 +       const char *_file, int _line)
9920 +{
9921 +       struct nx_info *nxi;
9922 +
9923 +       task_lock(p);
9924 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
9925 +               p, _file, _line);
9926 +       nxi = __get_nx_info(p->nx_info, _file, _line);
9927 +       task_unlock(p);
9928 +       return nxi;
9929 +}
9930 +
9931 +
9932 +static inline void exit_nx_info(struct task_struct *p)
9933 +{
9934 +       if (p->nx_info)
9935 +               release_nx_info(p->nx_info, p);
9936 +}
9937 +
9938 +
9939 +#else
9940 +#warning duplicate inclusion
9941 +#endif
9942 diff -NurpP --minimal linux-3.9.4/include/linux/vs_pid.h linux-3.9.4-vs2.3.6.3/include/linux/vs_pid.h
9943 --- linux-3.9.4/include/linux/vs_pid.h  1970-01-01 00:00:00.000000000 +0000
9944 +++ linux-3.9.4-vs2.3.6.3/include/linux/vs_pid.h        2013-05-31 14:47:11.000000000 +0000
9945 @@ -0,0 +1,50 @@
9946 +#ifndef _VS_PID_H
9947 +#define _VS_PID_H
9948 +
9949 +#include "vserver/base.h"
9950 +#include "vserver/check.h"
9951 +#include "vserver/context.h"
9952 +#include "vserver/debug.h"
9953 +#include "vserver/pid.h"
9954 +#include <linux/pid_namespace.h>
9955 +
9956 +
9957 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
9958 +
9959 +static inline
9960 +int vx_proc_task_visible(struct task_struct *task)
9961 +{
9962 +       if ((task->pid == 1) &&
9963 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
9964 +               /* show a blend through init */
9965 +               goto visible;
9966 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
9967 +               goto visible;
9968 +       return 0;
9969 +visible:
9970 +       return 1;
9971 +}
9972 +
9973 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
9974 +
9975 +
9976 +static inline
9977 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
9978 +{
9979 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
9980 +
9981 +       if (task && !vx_proc_task_visible(task)) {
9982 +               vxdprintk(VXD_CBIT(misc, 6),
9983 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
9984 +                       task, task->xid, task->pid,
9985 +                       current, current->xid, current->pid);
9986 +               put_task_struct(task);
9987 +               task = NULL;
9988 +       }
9989 +       return task;
9990 +}
9991 +
9992 +
9993 +#else
9994 +#warning duplicate inclusion
9995 +#endif
9996 diff -NurpP --minimal linux-3.9.4/include/linux/vs_sched.h linux-3.9.4-vs2.3.6.3/include/linux/vs_sched.h
9997 --- linux-3.9.4/include/linux/vs_sched.h        1970-01-01 00:00:00.000000000 +0000
9998 +++ linux-3.9.4-vs2.3.6.3/include/linux/vs_sched.h      2013-05-31 14:47:11.000000000 +0000
9999 @@ -0,0 +1,40 @@
10000 +#ifndef _VS_SCHED_H
10001 +#define _VS_SCHED_H
10002 +
10003 +#include "vserver/base.h"
10004 +#include "vserver/context.h"
10005 +#include "vserver/sched.h"
10006 +
10007 +
10008 +#define MAX_PRIO_BIAS           20
10009 +#define MIN_PRIO_BIAS          -20
10010 +
10011 +static inline
10012 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
10013 +{
10014 +       struct vx_info *vxi = p->vx_info;
10015 +
10016 +       if (vxi)
10017 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
10018 +       return prio;
10019 +}
10020 +
10021 +static inline void vx_account_user(struct vx_info *vxi,
10022 +       cputime_t cputime, int nice)
10023 +{
10024 +       if (!vxi)
10025 +               return;
10026 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
10027 +}
10028 +
10029 +static inline void vx_account_system(struct vx_info *vxi,
10030 +       cputime_t cputime, int idle)
10031 +{
10032 +       if (!vxi)
10033 +               return;
10034 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
10035 +}
10036 +
10037 +#else
10038 +#warning duplicate inclusion
10039 +#endif
10040 diff -NurpP --minimal linux-3.9.4/include/linux/vs_socket.h linux-3.9.4-vs2.3.6.3/include/linux/vs_socket.h
10041 --- linux-3.9.4/include/linux/vs_socket.h       1970-01-01 00:00:00.000000000 +0000
10042 +++ linux-3.9.4-vs2.3.6.3/include/linux/vs_socket.h     2013-05-31 14:47:11.000000000 +0000
10043 @@ -0,0 +1,67 @@
10044 +#ifndef _VS_SOCKET_H
10045 +#define _VS_SOCKET_H
10046 +
10047 +#include "vserver/debug.h"
10048 +#include "vserver/base.h"
10049 +#include "vserver/cacct.h"
10050 +#include "vserver/context.h"
10051 +#include "vserver/tag.h"
10052 +
10053 +
10054 +/* socket accounting */
10055 +
10056 +#include <linux/socket.h>
10057 +
10058 +static inline int vx_sock_type(int family)
10059 +{
10060 +       switch (family) {
10061 +       case PF_UNSPEC:
10062 +               return VXA_SOCK_UNSPEC;
10063 +       case PF_UNIX:
10064 +               return VXA_SOCK_UNIX;
10065 +       case PF_INET:
10066 +               return VXA_SOCK_INET;
10067 +       case PF_INET6:
10068 +               return VXA_SOCK_INET6;
10069 +       case PF_PACKET:
10070 +               return VXA_SOCK_PACKET;
10071 +       default:
10072 +               return VXA_SOCK_OTHER;
10073 +       }
10074 +}
10075 +
10076 +#define vx_acc_sock(v, f, p, s) \
10077 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
10078 +
10079 +static inline void __vx_acc_sock(struct vx_info *vxi,
10080 +       int family, int pos, int size, char *file, int line)
10081 +{
10082 +       if (vxi) {
10083 +               int type = vx_sock_type(family);
10084 +
10085 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
10086 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
10087 +       }
10088 +}
10089 +
10090 +#define vx_sock_recv(sk, s) \
10091 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
10092 +#define vx_sock_send(sk, s) \
10093 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
10094 +#define vx_sock_fail(sk, s) \
10095 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
10096 +
10097 +
10098 +#define sock_vx_init(s) do {           \
10099 +       (s)->sk_xid = 0;                \
10100 +       (s)->sk_vx_info = NULL;         \
10101 +       } while (0)
10102 +
10103 +#define sock_nx_init(s) do {           \
10104 +       (s)->sk_nid = 0;                \
10105 +       (s)->sk_nx_info = NULL;         \
10106 +       } while (0)
10107 +
10108 +#else
10109 +#warning duplicate inclusion
10110 +#endif
10111 diff -NurpP --minimal linux-3.9.4/include/linux/vs_tag.h linux-3.9.4-vs2.3.6.3/include/linux/vs_tag.h
10112 --- linux-3.9.4/include/linux/vs_tag.h  1970-01-01 00:00:00.000000000 +0000
10113 +++ linux-3.9.4-vs2.3.6.3/include/linux/vs_tag.h        2013-05-31 14:47:11.000000000 +0000
10114 @@ -0,0 +1,47 @@
10115 +#ifndef _VS_TAG_H
10116 +#define _VS_TAG_H
10117 +
10118 +#include <linux/vserver/tag.h>
10119 +
10120 +/* check conditions */
10121 +
10122 +#define DX_ADMIN       0x0001
10123 +#define DX_WATCH       0x0002
10124 +#define DX_HOSTID      0x0008
10125 +
10126 +#define DX_IDENT       0x0010
10127 +
10128 +#define DX_ARG_MASK    0x0010
10129 +
10130 +
10131 +#define dx_task_tag(t) ((t)->tag)
10132 +
10133 +#define dx_current_tag() dx_task_tag(current)
10134 +
10135 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
10136 +
10137 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
10138 +
10139 +
10140 +/*
10141 + * check current context for ADMIN/WATCH and
10142 + * optionally against supplied argument
10143 + */
10144 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
10145 +{
10146 +       if (mode & DX_ARG_MASK) {
10147 +               if ((mode & DX_IDENT) && (id == cid))
10148 +                       return 1;
10149 +       }
10150 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
10151 +               ((mode & DX_WATCH) && (cid == 1)) ||
10152 +               ((mode & DX_HOSTID) && (id == 0)));
10153 +}
10154 +
10155 +struct inode;
10156 +int dx_permission(const struct inode *inode, int mask);
10157 +
10158 +
10159 +#else
10160 +#warning duplicate inclusion
10161 +#endif
10162 diff -NurpP --minimal linux-3.9.4/include/linux/vs_time.h linux-3.9.4-vs2.3.6.3/include/linux/vs_time.h
10163 --- linux-3.9.4/include/linux/vs_time.h 1970-01-01 00:00:00.000000000 +0000
10164 +++ linux-3.9.4-vs2.3.6.3/include/linux/vs_time.h       2013-05-31 14:47:11.000000000 +0000
10165 @@ -0,0 +1,19 @@
10166 +#ifndef _VS_TIME_H
10167 +#define _VS_TIME_H
10168 +
10169 +
10170 +/* time faking stuff */
10171 +
10172 +#ifdef CONFIG_VSERVER_VTIME
10173 +
10174 +extern void vx_adjust_timespec(struct timespec *ts);
10175 +extern int vx_settimeofday(const struct timespec *ts);
10176 +
10177 +#else
10178 +#define        vx_adjust_timespec(t)   do { } while (0)
10179 +#define        vx_settimeofday(t)      do_settimeofday(t)
10180 +#endif
10181 +
10182 +#else
10183 +#warning duplicate inclusion
10184 +#endif
10185 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/base.h linux-3.9.4-vs2.3.6.3/include/linux/vserver/base.h
10186 --- linux-3.9.4/include/linux/vserver/base.h    1970-01-01 00:00:00.000000000 +0000
10187 +++ linux-3.9.4-vs2.3.6.3/include/linux/vserver/base.h  2013-05-31 17:55:09.000000000 +0000
10188 @@ -0,0 +1,181 @@
10189 +#ifndef _VSERVER_BASE_H
10190 +#define _VSERVER_BASE_H
10191 +
10192 +
10193 +/* context state changes */
10194 +
10195 +enum {
10196 +       VSC_STARTUP = 1,
10197 +       VSC_SHUTDOWN,
10198 +
10199 +       VSC_NETUP,
10200 +       VSC_NETDOWN,
10201 +};
10202 +
10203 +
10204 +
10205 +#define vx_task_xid(t) ((t)->xid)
10206 +
10207 +#define vx_current_xid() vx_task_xid(current)
10208 +
10209 +#define current_vx_info() (current->vx_info)
10210 +
10211 +
10212 +#define nx_task_nid(t) ((t)->nid)
10213 +
10214 +#define nx_current_nid() nx_task_nid(current)
10215 +
10216 +#define current_nx_info() (current->nx_info)
10217 +
10218 +
10219 +/* generic flag merging */
10220 +
10221 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
10222 +
10223 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
10224 +
10225 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
10226 +
10227 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
10228 +
10229 +
10230 +/* context flags */
10231 +
10232 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
10233 +
10234 +#define vx_current_flags()     __vx_flags(current_vx_info())
10235 +
10236 +#define vx_info_flags(v, m, f) \
10237 +       vs_check_flags(__vx_flags(v), m, f)
10238 +
10239 +#define task_vx_flags(t, m, f) \
10240 +       ((t) && vx_info_flags((t)->vx_info, m, f))
10241 +
10242 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
10243 +
10244 +
10245 +/* context caps */
10246 +
10247 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
10248 +
10249 +#define vx_current_ccaps()     __vx_ccaps(current_vx_info())
10250 +
10251 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
10252 +
10253 +#define vx_ccaps(c)    vx_info_ccaps(current_vx_info(), (c))
10254 +
10255 +
10256 +
10257 +/* network flags */
10258 +
10259 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
10260 +
10261 +#define nx_current_flags()     __nx_flags(current_nx_info())
10262 +
10263 +#define nx_info_flags(n, m, f) \
10264 +       vs_check_flags(__nx_flags(n), m, f)
10265 +
10266 +#define task_nx_flags(t, m, f) \
10267 +       ((t) && nx_info_flags((t)->nx_info, m, f))
10268 +
10269 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
10270 +
10271 +
10272 +/* network caps */
10273 +
10274 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
10275 +
10276 +#define nx_current_ncaps()     __nx_ncaps(current_nx_info())
10277 +
10278 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
10279 +
10280 +#define nx_ncaps(c)    nx_info_ncaps(current_nx_info(), c)
10281 +
10282 +
10283 +/* context mask capabilities */
10284 +
10285 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
10286 +
10287 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
10288 +
10289 +#define vx_mcaps(c)    vx_info_mcaps(current_vx_info(), c)
10290 +
10291 +
10292 +/* context bcap mask */
10293 +
10294 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
10295 +
10296 +#define vx_current_bcaps()     __vx_bcaps(current_vx_info())
10297 +
10298 +
10299 +/* mask given bcaps */
10300 +
10301 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
10302 +
10303 +#define vx_mbcaps(c)           vx_info_mbcaps(current_vx_info(), c)
10304 +
10305 +
10306 +/* masked cap_bset */
10307 +
10308 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
10309 +
10310 +#define vx_current_cap_bset()  vx_info_cap_bset(current_vx_info())
10311 +
10312 +#if 0
10313 +#define vx_info_mbcap(v, b) \
10314 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
10315 +       vx_info_bcaps(v, b) : (b))
10316 +
10317 +#define task_vx_mbcap(t, b) \
10318 +       vx_info_mbcap((t)->vx_info, (t)->b)
10319 +
10320 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
10321 +#endif
10322 +
10323 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
10324 +
10325 +#define vx_capable(b, c) (capable(b) || \
10326 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10327 +
10328 +#define vx_ns_capable(n, b, c) (ns_capable(n, b) || \
10329 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10330 +
10331 +#define nx_capable(b, c) (capable(b) || \
10332 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
10333 +
10334 +#define vx_task_initpid(t, n) \
10335 +       ((t)->vx_info && \
10336 +       ((t)->vx_info->vx_initpid == (n)))
10337 +
10338 +#define vx_current_initpid(n)  vx_task_initpid(current, n)
10339 +
10340 +
10341 +/* context unshare mask */
10342 +
10343 +#define __vx_umask(v)          ((v)->vx_umask)
10344 +
10345 +#define vx_current_umask()     __vx_umask(current_vx_info())
10346 +
10347 +#define vx_can_unshare(b, f) (capable(b) || \
10348 +       (cap_raised(current_cap(), b) && \
10349 +       !((f) & ~vx_current_umask())))
10350 +
10351 +#define vx_ns_can_unshare(n, b, f) (ns_capable(n, b) || \
10352 +       (cap_raised(current_cap(), b) && \
10353 +       !((f) & ~vx_current_umask())))
10354 +
10355 +#define __vx_wmask(v)          ((v)->vx_wmask)
10356 +
10357 +#define vx_current_wmask()     __vx_wmask(current_vx_info())
10358 +
10359 +
10360 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
10361 +
10362 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
10363 +
10364 +
10365 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
10366 +
10367 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
10368 +
10369 +#endif
10370 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/cacct.h linux-3.9.4-vs2.3.6.3/include/linux/vserver/cacct.h
10371 --- linux-3.9.4/include/linux/vserver/cacct.h   1970-01-01 00:00:00.000000000 +0000
10372 +++ linux-3.9.4-vs2.3.6.3/include/linux/vserver/cacct.h 2013-05-31 14:47:11.000000000 +0000
10373 @@ -0,0 +1,15 @@
10374 +#ifndef _VSERVER_CACCT_H
10375 +#define _VSERVER_CACCT_H
10376 +
10377 +
10378 +enum sock_acc_field {
10379 +       VXA_SOCK_UNSPEC = 0,
10380 +       VXA_SOCK_UNIX,
10381 +       VXA_SOCK_INET,
10382 +       VXA_SOCK_INET6,
10383 +       VXA_SOCK_PACKET,
10384 +       VXA_SOCK_OTHER,
10385 +       VXA_SOCK_SIZE   /* array size */
10386 +};
10387 +
10388 +#endif /* _VSERVER_CACCT_H */
10389 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/cacct_cmd.h linux-3.9.4-vs2.3.6.3/include/linux/vserver/cacct_cmd.h
10390 --- linux-3.9.4/include/linux/vserver/cacct_cmd.h       1970-01-01 00:00:00.000000000 +0000
10391 +++ linux-3.9.4-vs2.3.6.3/include/linux/vserver/cacct_cmd.h     2013-05-31 14:47:11.000000000 +0000
10392 @@ -0,0 +1,10 @@
10393 +#ifndef _VSERVER_CACCT_CMD_H
10394 +#define _VSERVER_CACCT_CMD_H
10395 +
10396 +
10397 +#include <linux/compiler.h>
10398 +#include <uapi/vserver/cacct_cmd.h>
10399 +
10400 +extern int vc_sock_stat(struct vx_info *, void __user *);
10401 +
10402 +#endif /* _VSERVER_CACCT_CMD_H */
10403 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/cacct_def.h linux-3.9.4-vs2.3.6.3/include/linux/vserver/cacct_def.h
10404 --- linux-3.9.4/include/linux/vserver/cacct_def.h       1970-01-01 00:00:00.000000000 +0000
10405 +++ linux-3.9.4-vs2.3.6.3/include/linux/vserver/cacct_def.h     2013-05-31 14:47:11.000000000 +0000
10406 @@ -0,0 +1,43 @@
10407 +#ifndef _VSERVER_CACCT_DEF_H
10408 +#define _VSERVER_CACCT_DEF_H
10409 +
10410 +#include <asm/atomic.h>
10411 +#include <linux/vserver/cacct.h>
10412 +
10413 +
10414 +struct _vx_sock_acc {
10415 +       atomic_long_t count;
10416 +       atomic_long_t total;
10417 +};
10418 +
10419 +/* context sub struct */
10420 +
10421 +struct _vx_cacct {
10422 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
10423 +       atomic_t slab[8];
10424 +       atomic_t page[6][8];
10425 +};
10426 +
10427 +#ifdef CONFIG_VSERVER_DEBUG
10428 +
10429 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
10430 +{
10431 +       int i, j;
10432 +
10433 +       printk("\t_vx_cacct:");
10434 +       for (i = 0; i < 6; i++) {
10435 +               struct _vx_sock_acc *ptr = cacct->sock[i];
10436 +
10437 +               printk("\t [%d] =", i);
10438 +               for (j = 0; j < 3; j++) {
10439 +                       printk(" [%d] = %8lu, %8lu", j,
10440 +                               atomic_long_read(&ptr[j].count),
10441 +                               atomic_long_read(&ptr[j].total));
10442 +               }
10443 +               printk("\n");
10444 +       }
10445 +}
10446 +
10447 +#endif
10448 +
10449 +#endif /* _VSERVER_CACCT_DEF_H */
10450 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/cacct_int.h linux-3.9.4-vs2.3.6.3/include/linux/vserver/cacct_int.h
10451 --- linux-3.9.4/include/linux/vserver/cacct_int.h       1970-01-01 00:00:00.000000000 +0000
10452 +++ linux-3.9.4-vs2.3.6.3/include/linux/vserver/cacct_int.h     2013-05-31 14:47:11.000000000 +0000
10453 @@ -0,0 +1,17 @@
10454 +#ifndef _VSERVER_CACCT_INT_H
10455 +#define _VSERVER_CACCT_INT_H
10456 +
10457 +static inline
10458 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
10459 +{
10460 +       return atomic_long_read(&cacct->sock[type][pos].count);
10461 +}
10462 +
10463 +
10464 +static inline
10465 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
10466 +{
10467 +       return atomic_long_read(&cacct->sock[type][pos].total);
10468 +}
10469 +
10470 +#endif /* _VSERVER_CACCT_INT_H */
10471 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/check.h linux-3.9.4-vs2.3.6.3/include/linux/vserver/check.h
10472 --- linux-3.9.4/include/linux/vserver/check.h   1970-01-01 00:00:00.000000000 +0000
10473 +++ linux-3.9.4-vs2.3.6.3/include/linux/vserver/check.h 2013-05-31 14:47:11.000000000 +0000
10474 @@ -0,0 +1,89 @@
10475 +#ifndef _VSERVER_CHECK_H
10476 +#define _VSERVER_CHECK_H
10477 +
10478 +
10479 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
10480 +
10481 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
10482 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
10483 +#else
10484 +#define MIN_D_CONTEXT  65536
10485 +#endif
10486 +
10487 +/* check conditions */
10488 +
10489 +#define VS_ADMIN       0x0001
10490 +#define VS_WATCH       0x0002
10491 +#define VS_HIDE                0x0004
10492 +#define VS_HOSTID      0x0008
10493 +
10494 +#define VS_IDENT       0x0010
10495 +#define VS_EQUIV       0x0020
10496 +#define VS_PARENT      0x0040
10497 +#define VS_CHILD       0x0080
10498 +
10499 +#define VS_ARG_MASK    0x00F0
10500 +
10501 +#define VS_DYNAMIC     0x0100
10502 +#define VS_STATIC      0x0200
10503 +
10504 +#define VS_ATR_MASK    0x0F00
10505 +
10506 +#ifdef CONFIG_VSERVER_PRIVACY
10507 +#define VS_ADMIN_P     (0)
10508 +#define VS_WATCH_P     (0)
10509 +#else
10510 +#define VS_ADMIN_P     VS_ADMIN
10511 +#define VS_WATCH_P     VS_WATCH
10512 +#endif
10513 +
10514 +#define VS_HARDIRQ     0x1000
10515 +#define VS_SOFTIRQ     0x2000
10516 +#define VS_IRQ         0x4000
10517 +
10518 +#define VS_IRQ_MASK    0xF000
10519 +
10520 +#include <linux/hardirq.h>
10521 +
10522 +/*
10523 + * check current context for ADMIN/WATCH and
10524 + * optionally against supplied argument
10525 + */
10526 +static inline int __vs_check(int cid, int id, unsigned int mode)
10527 +{
10528 +       if (mode & VS_ARG_MASK) {
10529 +               if ((mode & VS_IDENT) && (id == cid))
10530 +                       return 1;
10531 +       }
10532 +       if (mode & VS_ATR_MASK) {
10533 +               if ((mode & VS_DYNAMIC) &&
10534 +                       (id >= MIN_D_CONTEXT) &&
10535 +                       (id <= MAX_S_CONTEXT))
10536 +                       return 1;
10537 +               if ((mode & VS_STATIC) &&
10538 +                       (id > 1) && (id < MIN_D_CONTEXT))
10539 +                       return 1;
10540 +       }
10541 +       if (mode & VS_IRQ_MASK) {
10542 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
10543 +                       return 1;
10544 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
10545 +                       return 1;
10546 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
10547 +                       return 1;
10548 +       }
10549 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
10550 +               ((mode & VS_WATCH) && (cid == 1)) ||
10551 +               ((mode & VS_HOSTID) && (id == 0)));
10552 +}
10553 +
10554 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
10555 +
10556 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
10557 +
10558 +
10559 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
10560 +
10561 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
10562 +
10563 +#endif
10564 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/context.h linux-3.9.4-vs2.3.6.3/include/linux/vserver/context.h
10565 --- linux-3.9.4/include/linux/vserver/context.h 1970-01-01 00:00:00.000000000 +0000
10566 +++ linux-3.9.4-vs2.3.6.3/include/linux/vserver/context.h       2013-05-31 14:47:11.000000000 +0000
10567 @@ -0,0 +1,110 @@
10568 +#ifndef _VSERVER_CONTEXT_H
10569 +#define _VSERVER_CONTEXT_H
10570 +
10571 +
10572 +#include <linux/list.h>
10573 +#include <linux/spinlock.h>
10574 +#include <linux/rcupdate.h>
10575 +#include <uapi/vserver/context.h>
10576 +
10577 +#include "limit_def.h"
10578 +#include "sched_def.h"
10579 +#include "cvirt_def.h"
10580 +#include "cacct_def.h"
10581 +#include "device_def.h"
10582 +
10583 +#define VX_SPACES      2
10584 +
10585 +struct _vx_info_pc {
10586 +       struct _vx_sched_pc sched_pc;
10587 +       struct _vx_cvirt_pc cvirt_pc;
10588 +};
10589 +
10590 +struct _vx_space {
10591 +       unsigned long vx_nsmask;                /* assignment mask */
10592 +       struct nsproxy *vx_nsproxy;             /* private namespaces */
10593 +       struct fs_struct *vx_fs;                /* private namespace fs */
10594 +       const struct cred *vx_cred;             /* task credentials */
10595 +};
10596 +
10597 +struct vx_info {
10598 +       struct hlist_node vx_hlist;             /* linked list of contexts */
10599 +       xid_t vx_id;                            /* context id */
10600 +       atomic_t vx_usecnt;                     /* usage count */
10601 +       atomic_t vx_tasks;                      /* tasks count */
10602 +       struct vx_info *vx_parent;              /* parent context */
10603 +       int vx_state;                           /* context state */
10604 +
10605 +       struct _vx_space space[VX_SPACES];      /* namespace store */
10606 +
10607 +       uint64_t vx_flags;                      /* context flags */
10608 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
10609 +       uint64_t vx_umask;                      /* unshare mask (guest) */
10610 +       uint64_t vx_wmask;                      /* warn mask (guest) */
10611 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
10612 +
10613 +       struct task_struct *vx_reaper;          /* guest reaper process */
10614 +       pid_t vx_initpid;                       /* PID of guest init */
10615 +       int64_t vx_badness_bias;                /* OOM points bias */
10616 +
10617 +       struct _vx_limit limit;                 /* vserver limits */
10618 +       struct _vx_sched sched;                 /* vserver scheduler */
10619 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
10620 +       struct _vx_cacct cacct;                 /* context accounting */
10621 +
10622 +       struct _vx_device dmap;                 /* default device map targets */
10623 +
10624 +#ifndef CONFIG_SMP
10625 +       struct _vx_info_pc info_pc;             /* per cpu data */
10626 +#else
10627 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
10628 +#endif
10629 +
10630 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
10631 +       int reboot_cmd;                         /* last sys_reboot() cmd */
10632 +       int exit_code;                          /* last process exit code */
10633 +
10634 +       char vx_name[65];                       /* vserver name */
10635 +};
10636 +
10637 +#ifndef CONFIG_SMP
10638 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
10639 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
10640 +#else
10641 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
10642 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
10643 +#endif
10644 +
10645 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
10646 +
10647 +
10648 +struct vx_info_save {
10649 +       struct vx_info *vxi;
10650 +       xid_t xid;
10651 +};
10652 +
10653 +
10654 +/* status flags */
10655 +
10656 +#define VXS_HASHED     0x0001
10657 +#define VXS_PAUSED     0x0010
10658 +#define VXS_SHUTDOWN   0x0100
10659 +#define VXS_HELPER     0x1000
10660 +#define VXS_RELEASED   0x8000
10661 +
10662 +
10663 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
10664 +extern void release_vx_info(struct vx_info *, struct task_struct *);
10665 +
10666 +extern struct vx_info *lookup_vx_info(int);
10667 +extern struct vx_info *lookup_or_create_vx_info(int);
10668 +
10669 +extern int get_xid_list(int, unsigned int *, int);
10670 +extern int xid_is_hashed(xid_t);
10671 +
10672 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
10673 +
10674 +extern long vs_state_change(struct vx_info *, unsigned int);
10675 +
10676 +
10677 +#endif /* _VSERVER_CONTEXT_H */
10678 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/context_cmd.h linux-3.9.4-vs2.3.6.3/include/linux/vserver/context_cmd.h
10679 --- linux-3.9.4/include/linux/vserver/context_cmd.h     1970-01-01 00:00:00.000000000 +0000
10680 +++ linux-3.9.4-vs2.3.6.3/include/linux/vserver/context_cmd.h   2013-05-31 14:47:11.000000000 +0000
10681 @@ -0,0 +1,33 @@
10682 +#ifndef _VSERVER_CONTEXT_CMD_H
10683 +#define _VSERVER_CONTEXT_CMD_H
10684 +
10685 +#include <uapi/vserver/context_cmd.h>
10686 +
10687 +extern int vc_task_xid(uint32_t);
10688 +
10689 +extern int vc_vx_info(struct vx_info *, void __user *);
10690 +
10691 +extern int vc_ctx_stat(struct vx_info *, void __user *);
10692 +
10693 +extern int vc_ctx_create(uint32_t, void __user *);
10694 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
10695 +
10696 +extern int vc_get_cflags(struct vx_info *, void __user *);
10697 +extern int vc_set_cflags(struct vx_info *, void __user *);
10698 +
10699 +extern int vc_get_ccaps(struct vx_info *, void __user *);
10700 +extern int vc_set_ccaps(struct vx_info *, void __user *);
10701 +
10702 +extern int vc_get_bcaps(struct vx_info *, void __user *);
10703 +extern int vc_set_bcaps(struct vx_info *, void __user *);
10704 +
10705 +extern int vc_get_umask(struct vx_info *, void __user *);
10706 +extern int vc_set_umask(struct vx_info *, void __user *);
10707 +
10708 +extern int vc_get_wmask(struct vx_info *, void __user *);
10709 +extern int vc_set_wmask(struct vx_info *, void __user *);
10710 +
10711 +extern int vc_get_badness(struct vx_info *, void __user *);
10712 +extern int vc_set_badness(struct vx_info *, void __user *);
10713 +
10714 +#endif /* _VSERVER_CONTEXT_CMD_H */
10715 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/cvirt.h linux-3.9.4-vs2.3.6.3/include/linux/vserver/cvirt.h
10716 --- linux-3.9.4/include/linux/vserver/cvirt.h   1970-01-01 00:00:00.000000000 +0000
10717 +++ linux-3.9.4-vs2.3.6.3/include/linux/vserver/cvirt.h 2013-05-31 14:47:11.000000000 +0000
10718 @@ -0,0 +1,18 @@
10719 +#ifndef _VSERVER_CVIRT_H
10720 +#define _VSERVER_CVIRT_H
10721 +
10722 +struct timespec;
10723 +
10724 +void vx_vsi_boottime(struct timespec *);
10725 +
10726 +void vx_vsi_uptime(struct timespec *, struct timespec *);
10727 +
10728 +
10729 +struct vx_info;
10730 +
10731 +void vx_update_load(struct vx_info *);
10732 +
10733 +
10734 +int vx_do_syslog(int, char __user *, int);
10735 +
10736 +#endif /* _VSERVER_CVIRT_H */
10737 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/cvirt_cmd.h linux-3.9.4-vs2.3.6.3/include/linux/vserver/cvirt_cmd.h
10738 --- linux-3.9.4/include/linux/vserver/cvirt_cmd.h       1970-01-01 00:00:00.000000000 +0000
10739 +++ linux-3.9.4-vs2.3.6.3/include/linux/vserver/cvirt_cmd.h     2013-05-31 14:47:11.000000000 +0000
10740 @@ -0,0 +1,13 @@
10741 +#ifndef _VSERVER_CVIRT_CMD_H
10742 +#define _VSERVER_CVIRT_CMD_H
10743 +
10744 +
10745 +#include <linux/compiler.h>
10746 +#include <uapi/vserver/cvirt_cmd.h>
10747 +
10748 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
10749 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
10750 +
10751 +extern int vc_virt_stat(struct vx_info *, void __user *);
10752 +
10753 +#endif /* _VSERVER_CVIRT_CMD_H */
10754 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/cvirt_def.h linux-3.9.4-vs2.3.6.3/include/linux/vserver/cvirt_def.h
10755 --- linux-3.9.4/include/linux/vserver/cvirt_def.h       1970-01-01 00:00:00.000000000 +0000
10756 +++ linux-3.9.4-vs2.3.6.3/include/linux/vserver/cvirt_def.h     2013-05-31 14:47:11.000000000 +0000
10757 @@ -0,0 +1,80 @@
10758 +#ifndef _VSERVER_CVIRT_DEF_H
10759 +#define _VSERVER_CVIRT_DEF_H
10760 +
10761 +#include <linux/jiffies.h>
10762 +#include <linux/spinlock.h>
10763 +#include <linux/wait.h>
10764 +#include <linux/time.h>
10765 +#include <asm/atomic.h>
10766 +
10767 +
10768 +struct _vx_usage_stat {
10769 +       uint64_t user;
10770 +       uint64_t nice;
10771 +       uint64_t system;
10772 +       uint64_t softirq;
10773 +       uint64_t irq;
10774 +       uint64_t idle;
10775 +       uint64_t iowait;
10776 +};
10777 +
10778 +struct _vx_syslog {
10779 +       wait_queue_head_t log_wait;
10780 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
10781 +
10782 +       unsigned long log_start;        /* next char to be read by syslog() */
10783 +       unsigned long con_start;        /* next char to be sent to consoles */
10784 +       unsigned long log_end;  /* most-recently-written-char + 1 */
10785 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
10786 +
10787 +       char log_buf[1024];
10788 +};
10789 +
10790 +
10791 +/* context sub struct */
10792 +
10793 +struct _vx_cvirt {
10794 +       atomic_t nr_threads;            /* number of current threads */
10795 +       atomic_t nr_running;            /* number of running threads */
10796 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
10797 +
10798 +       atomic_t nr_onhold;             /* processes on hold */
10799 +       uint32_t onhold_last;           /* jiffies when put on hold */
10800 +
10801 +       struct timespec bias_ts;        /* time offset to the host */
10802 +       struct timespec bias_idle;
10803 +       struct timespec bias_uptime;    /* context creation point */
10804 +       uint64_t bias_clock;            /* offset in clock_t */
10805 +
10806 +       spinlock_t load_lock;           /* lock for the load averages */
10807 +       atomic_t load_updates;          /* nr of load updates done so far */
10808 +       uint32_t load_last;             /* last time load was calculated */
10809 +       uint32_t load[3];               /* load averages 1,5,15 */
10810 +
10811 +       atomic_t total_forks;           /* number of forks so far */
10812 +
10813 +       struct _vx_syslog syslog;
10814 +};
10815 +
10816 +struct _vx_cvirt_pc {
10817 +       struct _vx_usage_stat cpustat;
10818 +};
10819 +
10820 +
10821 +#ifdef CONFIG_VSERVER_DEBUG
10822 +
10823 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
10824 +{
10825 +       printk("\t_vx_cvirt:\n");
10826 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
10827 +               atomic_read(&cvirt->nr_threads),
10828 +               atomic_read(&cvirt->nr_running),
10829 +               atomic_read(&cvirt->nr_uninterruptible),
10830 +               atomic_read(&cvirt->nr_onhold));
10831 +       /* add rest here */
10832 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
10833 +}
10834 +
10835 +#endif
10836 +
10837 +#endif /* _VSERVER_CVIRT_DEF_H */
10838 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/debug.h linux-3.9.4-vs2.3.6.3/include/linux/vserver/debug.h
10839 --- linux-3.9.4/include/linux/vserver/debug.h   1970-01-01 00:00:00.000000000 +0000
10840 +++ linux-3.9.4-vs2.3.6.3/include/linux/vserver/debug.h 2013-06-03 18:27:34.000000000 +0000
10841 @@ -0,0 +1,146 @@
10842 +#ifndef _VSERVER_DEBUG_H
10843 +#define _VSERVER_DEBUG_H
10844 +
10845 +
10846 +#define VXD_CBIT(n, m) (vs_debug_ ## n & (1 << (m)))
10847 +#define VXD_CMIN(n, m) (vs_debug_ ## n > (m))
10848 +#define VXD_MASK(n, m) (vs_debug_ ## n & (m))
10849 +
10850 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
10851 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
10852 +#define VXF_DEV                "%p[%lu,%d:%d]"
10853 +
10854 +#if    defined(CONFIG_QUOTES_UTF8)
10855 +#define        VS_Q_LQM        "\xc2\xbb"
10856 +#define        VS_Q_RQM        "\xc2\xab"
10857 +#elif  defined(CONFIG_QUOTES_ASCII)
10858 +#define        VS_Q_LQM        "\x27"
10859 +#define        VS_Q_RQM        "\x27"
10860 +#else
10861 +#define        VS_Q_LQM        "\xbb"
10862 +#define        VS_Q_RQM        "\xab"
10863 +#endif
10864 +
10865 +#define        VS_Q(f)         VS_Q_LQM f VS_Q_RQM
10866 +
10867 +
10868 +#define vxd_path(p)                                            \
10869 +       ({ static char _buffer[PATH_MAX];                       \
10870 +          d_path(p, _buffer, sizeof(_buffer)); })
10871 +
10872 +#define vxd_cond_path(n)                                       \
10873 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
10874 +
10875 +
10876 +#ifdef CONFIG_VSERVER_DEBUG
10877 +
10878 +extern unsigned int vs_debug_switch;
10879 +extern unsigned int vs_debug_xid;
10880 +extern unsigned int vs_debug_nid;
10881 +extern unsigned int vs_debug_tag;
10882 +extern unsigned int vs_debug_net;
10883 +extern unsigned int vs_debug_limit;
10884 +extern unsigned int vs_debug_cres;
10885 +extern unsigned int vs_debug_dlim;
10886 +extern unsigned int vs_debug_quota;
10887 +extern unsigned int vs_debug_cvirt;
10888 +extern unsigned int vs_debug_space;
10889 +extern unsigned int vs_debug_perm;
10890 +extern unsigned int vs_debug_misc;
10891 +
10892 +
10893 +#define VX_LOGLEVEL    "vxD: "
10894 +#define VX_PROC_FMT    "%p: "
10895 +#define VX_PROCESS     current
10896 +
10897 +#define vxdprintk(c, f, x...)                                  \
10898 +       do {                                                    \
10899 +               if (c)                                          \
10900 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
10901 +                               VX_PROCESS , ##x);              \
10902 +       } while (0)
10903 +
10904 +#define vxlprintk(c, f, x...)                                  \
10905 +       do {                                                    \
10906 +               if (c)                                          \
10907 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
10908 +       } while (0)
10909 +
10910 +#define vxfprintk(c, f, x...)                                  \
10911 +       do {                                                    \
10912 +               if (c)                                          \
10913 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
10914 +       } while (0)
10915 +
10916 +
10917 +struct vx_info;
10918 +
10919 +void dump_vx_info(struct vx_info *, int);
10920 +void dump_vx_info_inactive(int);
10921 +
10922 +#else  /* CONFIG_VSERVER_DEBUG */
10923 +
10924 +#define vs_debug_switch        0
10925 +#define vs_debug_xid   0
10926 +#define vs_debug_nid   0
10927 +#define vs_debug_tag   0
10928 +#define vs_debug_net   0
10929 +#define vs_debug_limit 0
10930 +#define vs_debug_cres  0
10931 +#define vs_debug_dlim  0
10932 +#define vs_debug_quota 0
10933 +#define vs_debug_cvirt 0
10934 +#define vs_debug_space 0
10935 +#define vs_debug_perm  0
10936 +#define vs_debug_misc  0
10937 +
10938 +#define vxdprintk(x...) do { } while (0)
10939 +#define vxlprintk(x...) do { } while (0)
10940 +#define vxfprintk(x...) do { } while (0)
10941 +
10942 +#endif /* CONFIG_VSERVER_DEBUG */
10943 +
10944 +
10945 +#ifdef CONFIG_VSERVER_WARN
10946 +
10947 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
10948 +#define VX_WARN_TASK   "[" VS_Q("%s") ",%u:#%u|%u|%u] "
10949 +#define VX_WARN_XID    "[xid #%u] "
10950 +#define VX_WARN_NID    "[nid #%u] "
10951 +#define VX_WARN_TAG    "[tag #%u] "
10952 +
10953 +#define vxwprintk(c, f, x...)                                  \
10954 +       do {                                                    \
10955 +               if (c)                                          \
10956 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
10957 +       } while (0)
10958 +
10959 +#else  /* CONFIG_VSERVER_WARN */
10960 +
10961 +#define vxwprintk(x...) do { } while (0)
10962 +
10963 +#endif /* CONFIG_VSERVER_WARN */
10964 +
10965 +#define vxwprintk_task(c, f, x...)                             \
10966 +       vxwprintk(c, VX_WARN_TASK f,                            \
10967 +               current->comm, current->pid,                    \
10968 +               current->xid, current->nid,                     \
10969 +               current->tag, ##x)
10970 +#define vxwprintk_xid(c, f, x...)                              \
10971 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
10972 +#define vxwprintk_nid(c, f, x...)                              \
10973 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
10974 +#define vxwprintk_tag(c, f, x...)                              \
10975 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
10976 +
10977 +#ifdef CONFIG_VSERVER_DEBUG
10978 +#define vxd_assert_lock(l)     assert_spin_locked(l)
10979 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
10980 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
10981 +#else
10982 +#define vxd_assert_lock(l)     do { } while (0)
10983 +#define vxd_assert(c, f, x...) do { } while (0)
10984 +#endif
10985 +
10986 +
10987 +#endif /* _VSERVER_DEBUG_H */
10988 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/debug_cmd.h linux-3.9.4-vs2.3.6.3/include/linux/vserver/debug_cmd.h
10989 --- linux-3.9.4/include/linux/vserver/debug_cmd.h       1970-01-01 00:00:00.000000000 +0000
10990 +++ linux-3.9.4-vs2.3.6.3/include/linux/vserver/debug_cmd.h     2013-05-31 14:47:11.000000000 +0000
10991 @@ -0,0 +1,37 @@
10992 +#ifndef _VSERVER_DEBUG_CMD_H
10993 +#define _VSERVER_DEBUG_CMD_H
10994 +
10995 +#include <uapi/vserver/debug_cmd.h>
10996 +
10997 +
10998 +#ifdef CONFIG_COMPAT
10999 +
11000 +#include <asm/compat.h>
11001 +
11002 +struct vcmd_read_history_v0_x32 {
11003 +       uint32_t index;
11004 +       uint32_t count;
11005 +       compat_uptr_t data_ptr;
11006 +};
11007 +
11008 +struct vcmd_read_monitor_v0_x32 {
11009 +       uint32_t index;
11010 +       uint32_t count;
11011 +       compat_uptr_t data_ptr;
11012 +};
11013 +
11014 +#endif  /* CONFIG_COMPAT */
11015 +
11016 +extern int vc_dump_history(uint32_t);
11017 +
11018 +extern int vc_read_history(uint32_t, void __user *);
11019 +extern int vc_read_monitor(uint32_t, void __user *);
11020 +
11021 +#ifdef CONFIG_COMPAT
11022 +
11023 +extern int vc_read_history_x32(uint32_t, void __user *);
11024 +extern int vc_read_monitor_x32(uint32_t, void __user *);
11025 +
11026 +#endif  /* CONFIG_COMPAT */
11027 +
11028 +#endif /* _VSERVER_DEBUG_CMD_H */
11029 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/device.h linux-3.9.4-vs2.3.6.3/include/linux/vserver/device.h
11030 --- linux-3.9.4/include/linux/vserver/device.h  1970-01-01 00:00:00.000000000 +0000
11031 +++ linux-3.9.4-vs2.3.6.3/include/linux/vserver/device.h        2013-05-31 14:47:11.000000000 +0000
11032 @@ -0,0 +1,9 @@
11033 +#ifndef _VSERVER_DEVICE_H
11034 +#define _VSERVER_DEVICE_H
11035 +
11036 +
11037 +#include <uapi/vserver/device.h>
11038 +
11039 +#else  /* _VSERVER_DEVICE_H */
11040 +#warning duplicate inclusion
11041 +#endif /* _VSERVER_DEVICE_H */
11042 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/device_cmd.h linux-3.9.4-vs2.3.6.3/include/linux/vserver/device_cmd.h
11043 --- linux-3.9.4/include/linux/vserver/device_cmd.h      1970-01-01 00:00:00.000000000 +0000
11044 +++ linux-3.9.4-vs2.3.6.3/include/linux/vserver/device_cmd.h    2013-05-31 14:47:11.000000000 +0000
11045 @@ -0,0 +1,31 @@
11046 +#ifndef _VSERVER_DEVICE_CMD_H
11047 +#define _VSERVER_DEVICE_CMD_H
11048 +
11049 +#include <uapi/vserver/device_cmd.h>
11050 +
11051 +
11052 +#ifdef CONFIG_COMPAT
11053 +
11054 +#include <asm/compat.h>
11055 +
11056 +struct vcmd_set_mapping_v0_x32 {
11057 +       compat_uptr_t device_ptr;
11058 +       compat_uptr_t target_ptr;
11059 +       uint32_t flags;
11060 +};
11061 +
11062 +#endif /* CONFIG_COMPAT */
11063 +
11064 +#include <linux/compiler.h>
11065 +
11066 +extern int vc_set_mapping(struct vx_info *, void __user *);
11067 +extern int vc_unset_mapping(struct vx_info *, void __user *);
11068 +
11069 +#ifdef CONFIG_COMPAT
11070 +
11071 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
11072 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
11073 +
11074 +#endif /* CONFIG_COMPAT */
11075 +
11076 +#endif /* _VSERVER_DEVICE_CMD_H */
11077 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/device_def.h linux-3.9.4-vs2.3.6.3/include/linux/vserver/device_def.h
11078 --- linux-3.9.4/include/linux/vserver/device_def.h      1970-01-01 00:00:00.000000000 +0000
11079 +++ linux-3.9.4-vs2.3.6.3/include/linux/vserver/device_def.h    2013-05-31 14:47:11.000000000 +0000
11080 @@ -0,0 +1,17 @@
11081 +#ifndef _VSERVER_DEVICE_DEF_H
11082 +#define _VSERVER_DEVICE_DEF_H
11083 +
11084 +#include <linux/types.h>
11085 +
11086 +struct vx_dmap_target {
11087 +       dev_t target;
11088 +       uint32_t flags;
11089 +};
11090 +
11091 +struct _vx_device {
11092 +#ifdef CONFIG_VSERVER_DEVICE
11093 +       struct vx_dmap_target targets[2];
11094 +#endif
11095 +};
11096 +
11097 +#endif /* _VSERVER_DEVICE_DEF_H */
11098 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/dlimit.h linux-3.9.4-vs2.3.6.3/include/linux/vserver/dlimit.h
11099 --- linux-3.9.4/include/linux/vserver/dlimit.h  1970-01-01 00:00:00.000000000 +0000
11100 +++ linux-3.9.4-vs2.3.6.3/include/linux/vserver/dlimit.h        2013-05-31 14:47:11.000000000 +0000
11101 @@ -0,0 +1,54 @@
11102 +#ifndef _VSERVER_DLIMIT_H
11103 +#define _VSERVER_DLIMIT_H
11104 +
11105 +#include "switch.h"
11106 +
11107 +
11108 +#ifdef __KERNEL__
11109 +
11110 +/*      keep in sync with CDLIM_INFINITY       */
11111 +
11112 +#define DLIM_INFINITY          (~0ULL)
11113 +
11114 +#include <linux/spinlock.h>
11115 +#include <linux/rcupdate.h>
11116 +
11117 +struct super_block;
11118 +
11119 +struct dl_info {
11120 +       struct hlist_node dl_hlist;             /* linked list of contexts */
11121 +       struct rcu_head dl_rcu;                 /* the rcu head */
11122 +       tag_t dl_tag;                           /* context tag */
11123 +       atomic_t dl_usecnt;                     /* usage count */
11124 +       atomic_t dl_refcnt;                     /* reference count */
11125 +
11126 +       struct super_block *dl_sb;              /* associated superblock */
11127 +
11128 +       spinlock_t dl_lock;                     /* protect the values */
11129 +
11130 +       unsigned long long dl_space_used;       /* used space in bytes */
11131 +       unsigned long long dl_space_total;      /* maximum space in bytes */
11132 +       unsigned long dl_inodes_used;           /* used inodes */
11133 +       unsigned long dl_inodes_total;          /* maximum inodes */
11134 +
11135 +       unsigned int dl_nrlmult;                /* non root limit mult */
11136 +};
11137 +
11138 +struct rcu_head;
11139 +
11140 +extern void rcu_free_dl_info(struct rcu_head *);
11141 +extern void unhash_dl_info(struct dl_info *);
11142 +
11143 +extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
11144 +
11145 +
11146 +struct kstatfs;
11147 +
11148 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
11149 +
11150 +typedef uint64_t dlsize_t;
11151 +
11152 +#endif /* __KERNEL__ */
11153 +#else  /* _VSERVER_DLIMIT_H */
11154 +#warning duplicate inclusion
11155 +#endif /* _VSERVER_DLIMIT_H */
11156 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/dlimit_cmd.h linux-3.9.4-vs2.3.6.3/include/linux/vserver/dlimit_cmd.h
11157 --- linux-3.9.4/include/linux/vserver/dlimit_cmd.h      1970-01-01 00:00:00.000000000 +0000
11158 +++ linux-3.9.4-vs2.3.6.3/include/linux/vserver/dlimit_cmd.h    2013-05-31 14:47:11.000000000 +0000
11159 @@ -0,0 +1,46 @@
11160 +#ifndef _VSERVER_DLIMIT_CMD_H
11161 +#define _VSERVER_DLIMIT_CMD_H
11162 +
11163 +#include <uapi/vserver/dlimit_cmd.h>
11164 +
11165 +
11166 +#ifdef CONFIG_COMPAT
11167 +
11168 +#include <asm/compat.h>
11169 +
11170 +struct vcmd_ctx_dlimit_base_v0_x32 {
11171 +       compat_uptr_t name_ptr;
11172 +       uint32_t flags;
11173 +};
11174 +
11175 +struct vcmd_ctx_dlimit_v0_x32 {
11176 +       compat_uptr_t name_ptr;
11177 +       uint32_t space_used;                    /* used space in kbytes */
11178 +       uint32_t space_total;                   /* maximum space in kbytes */
11179 +       uint32_t inodes_used;                   /* used inodes */
11180 +       uint32_t inodes_total;                  /* maximum inodes */
11181 +       uint32_t reserved;                      /* reserved for root in % */
11182 +       uint32_t flags;
11183 +};
11184 +
11185 +#endif /* CONFIG_COMPAT */
11186 +
11187 +#include <linux/compiler.h>
11188 +
11189 +extern int vc_add_dlimit(uint32_t, void __user *);
11190 +extern int vc_rem_dlimit(uint32_t, void __user *);
11191 +
11192 +extern int vc_set_dlimit(uint32_t, void __user *);
11193 +extern int vc_get_dlimit(uint32_t, void __user *);
11194 +
11195 +#ifdef CONFIG_COMPAT
11196 +
11197 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
11198 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
11199 +
11200 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
11201 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
11202 +
11203 +#endif /* CONFIG_COMPAT */
11204 +
11205 +#endif /* _VSERVER_DLIMIT_CMD_H */
11206 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/global.h linux-3.9.4-vs2.3.6.3/include/linux/vserver/global.h
11207 --- linux-3.9.4/include/linux/vserver/global.h  1970-01-01 00:00:00.000000000 +0000
11208 +++ linux-3.9.4-vs2.3.6.3/include/linux/vserver/global.h        2013-05-31 14:47:11.000000000 +0000
11209 @@ -0,0 +1,19 @@
11210 +#ifndef _VSERVER_GLOBAL_H
11211 +#define _VSERVER_GLOBAL_H
11212 +
11213 +
11214 +extern atomic_t vx_global_ctotal;
11215 +extern atomic_t vx_global_cactive;
11216 +
11217 +extern atomic_t nx_global_ctotal;
11218 +extern atomic_t nx_global_cactive;
11219 +
11220 +extern atomic_t vs_global_nsproxy;
11221 +extern atomic_t vs_global_fs;
11222 +extern atomic_t vs_global_mnt_ns;
11223 +extern atomic_t vs_global_uts_ns;
11224 +extern atomic_t vs_global_user_ns;
11225 +extern atomic_t vs_global_pid_ns;
11226 +
11227 +
11228 +#endif /* _VSERVER_GLOBAL_H */
11229 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/history.h linux-3.9.4-vs2.3.6.3/include/linux/vserver/history.h
11230 --- linux-3.9.4/include/linux/vserver/history.h 1970-01-01 00:00:00.000000000 +0000
11231 +++ linux-3.9.4-vs2.3.6.3/include/linux/vserver/history.h       2013-05-31 14:47:11.000000000 +0000
11232 @@ -0,0 +1,197 @@
11233 +#ifndef _VSERVER_HISTORY_H
11234 +#define _VSERVER_HISTORY_H
11235 +
11236 +
11237 +enum {
11238 +       VXH_UNUSED = 0,
11239 +       VXH_THROW_OOPS = 1,
11240 +
11241 +       VXH_GET_VX_INFO,
11242 +       VXH_PUT_VX_INFO,
11243 +       VXH_INIT_VX_INFO,
11244 +       VXH_SET_VX_INFO,
11245 +       VXH_CLR_VX_INFO,
11246 +       VXH_CLAIM_VX_INFO,
11247 +       VXH_RELEASE_VX_INFO,
11248 +       VXH_ALLOC_VX_INFO,
11249 +       VXH_DEALLOC_VX_INFO,
11250 +       VXH_HASH_VX_INFO,
11251 +       VXH_UNHASH_VX_INFO,
11252 +       VXH_LOC_VX_INFO,
11253 +       VXH_LOOKUP_VX_INFO,
11254 +       VXH_CREATE_VX_INFO,
11255 +};
11256 +
11257 +struct _vxhe_vxi {
11258 +       struct vx_info *ptr;
11259 +       unsigned xid;
11260 +       unsigned usecnt;
11261 +       unsigned tasks;
11262 +};
11263 +
11264 +struct _vxhe_set_clr {
11265 +       void *data;
11266 +};
11267 +
11268 +struct _vxhe_loc_lookup {
11269 +       unsigned arg;
11270 +};
11271 +
11272 +struct _vx_hist_entry {
11273 +       void *loc;
11274 +       unsigned short seq;
11275 +       unsigned short type;
11276 +       struct _vxhe_vxi vxi;
11277 +       union {
11278 +               struct _vxhe_set_clr sc;
11279 +               struct _vxhe_loc_lookup ll;
11280 +       };
11281 +};
11282 +
11283 +#ifdef CONFIG_VSERVER_HISTORY
11284 +
11285 +extern unsigned volatile int vxh_active;
11286 +
11287 +struct _vx_hist_entry *vxh_advance(void *loc);
11288 +
11289 +
11290 +static inline
11291 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
11292 +{
11293 +       entry->vxi.ptr = vxi;
11294 +       if (vxi) {
11295 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
11296 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
11297 +               entry->vxi.xid = vxi->vx_id;
11298 +       }
11299 +}
11300 +
11301 +
11302 +#define        __HERE__ current_text_addr()
11303 +
11304 +#define __VXH_BODY(__type, __data, __here)     \
11305 +       struct _vx_hist_entry *entry;           \
11306 +                                               \
11307 +       preempt_disable();                      \
11308 +       entry = vxh_advance(__here);            \
11309 +       __data;                                 \
11310 +       entry->type = __type;                   \
11311 +       preempt_enable();
11312 +
11313 +
11314 +       /* pass vxi only */
11315 +
11316 +#define __VXH_SMPL                             \
11317 +       __vxh_copy_vxi(entry, vxi)
11318 +
11319 +static inline
11320 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
11321 +{
11322 +       __VXH_BODY(__type, __VXH_SMPL, __here)
11323 +}
11324 +
11325 +       /* pass vxi and data (void *) */
11326 +
11327 +#define __VXH_DATA                             \
11328 +       __vxh_copy_vxi(entry, vxi);             \
11329 +       entry->sc.data = data
11330 +
11331 +static inline
11332 +void   __vxh_data(struct vx_info *vxi, void *data,
11333 +                       int __type, void *__here)
11334 +{
11335 +       __VXH_BODY(__type, __VXH_DATA, __here)
11336 +}
11337 +
11338 +       /* pass vxi and arg (long) */
11339 +
11340 +#define __VXH_LONG                             \
11341 +       __vxh_copy_vxi(entry, vxi);             \
11342 +       entry->ll.arg = arg
11343 +
11344 +static inline
11345 +void   __vxh_long(struct vx_info *vxi, long arg,
11346 +                       int __type, void *__here)
11347 +{
11348 +       __VXH_BODY(__type, __VXH_LONG, __here)
11349 +}
11350 +
11351 +
11352 +static inline
11353 +void   __vxh_throw_oops(void *__here)
11354 +{
11355 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
11356 +       /* prevent further acquisition */
11357 +       vxh_active = 0;
11358 +}
11359 +
11360 +
11361 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
11362 +
11363 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
11364 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
11365 +
11366 +#define __vxh_init_vx_info(v, d, h) \
11367 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
11368 +#define __vxh_set_vx_info(v, d, h) \
11369 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
11370 +#define __vxh_clr_vx_info(v, d, h) \
11371 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
11372 +
11373 +#define __vxh_claim_vx_info(v, d, h) \
11374 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
11375 +#define __vxh_release_vx_info(v, d, h) \
11376 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
11377 +
11378 +#define vxh_alloc_vx_info(v) \
11379 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
11380 +#define vxh_dealloc_vx_info(v) \
11381 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
11382 +
11383 +#define vxh_hash_vx_info(v) \
11384 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
11385 +#define vxh_unhash_vx_info(v) \
11386 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
11387 +
11388 +#define vxh_loc_vx_info(v, l) \
11389 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
11390 +#define vxh_lookup_vx_info(v, l) \
11391 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
11392 +#define vxh_create_vx_info(v, l) \
11393 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
11394 +
11395 +extern void vxh_dump_history(void);
11396 +
11397 +
11398 +#else  /* CONFIG_VSERVER_HISTORY */
11399 +
11400 +#define        __HERE__        0
11401 +
11402 +#define vxh_throw_oops()               do { } while (0)
11403 +
11404 +#define __vxh_get_vx_info(v, h)                do { } while (0)
11405 +#define __vxh_put_vx_info(v, h)                do { } while (0)
11406 +
11407 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
11408 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
11409 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
11410 +
11411 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
11412 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
11413 +
11414 +#define vxh_alloc_vx_info(v)           do { } while (0)
11415 +#define vxh_dealloc_vx_info(v)         do { } while (0)
11416 +
11417 +#define vxh_hash_vx_info(v)            do { } while (0)
11418 +#define vxh_unhash_vx_info(v)          do { } while (0)
11419 +
11420 +#define vxh_loc_vx_info(v, l)          do { } while (0)
11421 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
11422 +#define vxh_create_vx_info(v, l)       do { } while (0)
11423 +
11424 +#define vxh_dump_history()             do { } while (0)
11425 +
11426 +
11427 +#endif /* CONFIG_VSERVER_HISTORY */
11428 +
11429 +#endif /* _VSERVER_HISTORY_H */
11430 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/inode.h linux-3.9.4-vs2.3.6.3/include/linux/vserver/inode.h
11431 --- linux-3.9.4/include/linux/vserver/inode.h   1970-01-01 00:00:00.000000000 +0000
11432 +++ linux-3.9.4-vs2.3.6.3/include/linux/vserver/inode.h 2013-05-31 14:47:11.000000000 +0000
11433 @@ -0,0 +1,19 @@
11434 +#ifndef _VSERVER_INODE_H
11435 +#define _VSERVER_INODE_H
11436 +
11437 +#include <uapi/vserver/inode.h>
11438 +
11439 +
11440 +#ifdef CONFIG_VSERVER_PROC_SECURE
11441 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
11442 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11443 +#else
11444 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
11445 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11446 +#endif
11447 +
11448 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
11449 +
11450 +#else  /* _VSERVER_INODE_H */
11451 +#warning duplicate inclusion
11452 +#endif /* _VSERVER_INODE_H */
11453 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/inode_cmd.h linux-3.9.4-vs2.3.6.3/include/linux/vserver/inode_cmd.h
11454 --- linux-3.9.4/include/linux/vserver/inode_cmd.h       1970-01-01 00:00:00.000000000 +0000
11455 +++ linux-3.9.4-vs2.3.6.3/include/linux/vserver/inode_cmd.h     2013-05-31 14:47:11.000000000 +0000
11456 @@ -0,0 +1,36 @@
11457 +#ifndef _VSERVER_INODE_CMD_H
11458 +#define _VSERVER_INODE_CMD_H
11459 +
11460 +#include <uapi/vserver/inode_cmd.h>
11461 +
11462 +
11463 +
11464 +#ifdef CONFIG_COMPAT
11465 +
11466 +#include <asm/compat.h>
11467 +
11468 +struct vcmd_ctx_iattr_v1_x32 {
11469 +       compat_uptr_t name_ptr;
11470 +       uint32_t tag;
11471 +       uint32_t flags;
11472 +       uint32_t mask;
11473 +};
11474 +
11475 +#endif /* CONFIG_COMPAT */
11476 +
11477 +#include <linux/compiler.h>
11478 +
11479 +extern int vc_get_iattr(void __user *);
11480 +extern int vc_set_iattr(void __user *);
11481 +
11482 +extern int vc_fget_iattr(uint32_t, void __user *);
11483 +extern int vc_fset_iattr(uint32_t, void __user *);
11484 +
11485 +#ifdef CONFIG_COMPAT
11486 +
11487 +extern int vc_get_iattr_x32(void __user *);
11488 +extern int vc_set_iattr_x32(void __user *);
11489 +
11490 +#endif /* CONFIG_COMPAT */
11491 +
11492 +#endif /* _VSERVER_INODE_CMD_H */
11493 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/limit.h linux-3.9.4-vs2.3.6.3/include/linux/vserver/limit.h
11494 --- linux-3.9.4/include/linux/vserver/limit.h   1970-01-01 00:00:00.000000000 +0000
11495 +++ linux-3.9.4-vs2.3.6.3/include/linux/vserver/limit.h 2013-05-31 14:47:11.000000000 +0000
11496 @@ -0,0 +1,61 @@
11497 +#ifndef _VSERVER_LIMIT_H
11498 +#define _VSERVER_LIMIT_H
11499 +
11500 +#include <uapi/vserver/limit.h>
11501 +
11502 +
11503 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
11504 +
11505 +/*     keep in sync with CRLIM_INFINITY */
11506 +
11507 +#define        VLIM_INFINITY   (~0ULL)
11508 +
11509 +#include <asm/atomic.h>
11510 +#include <asm/resource.h>
11511 +
11512 +#ifndef RLIM_INFINITY
11513 +#warning RLIM_INFINITY is undefined
11514 +#endif
11515 +
11516 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
11517 +
11518 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
11519 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
11520 +
11521 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
11522 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
11523 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
11524 +
11525 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
11526 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
11527 +
11528 +typedef atomic_long_t rlim_atomic_t;
11529 +typedef unsigned long rlim_t;
11530 +
11531 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
11532 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
11533 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
11534 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
11535 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
11536 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
11537 +
11538 +
11539 +#if    (RLIM_INFINITY == VLIM_INFINITY)
11540 +#define        VX_VLIM(r) ((long long)(long)(r))
11541 +#define        VX_RLIM(v) ((rlim_t)(v))
11542 +#else
11543 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
11544 +               ? VLIM_INFINITY : (long long)(r))
11545 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
11546 +               ? RLIM_INFINITY : (rlim_t)(v))
11547 +#endif
11548 +
11549 +struct sysinfo;
11550 +
11551 +void vx_vsi_meminfo(struct sysinfo *);
11552 +void vx_vsi_swapinfo(struct sysinfo *);
11553 +long vx_vsi_cached(struct sysinfo *);
11554 +
11555 +#define NUM_LIMITS     24
11556 +
11557 +#endif /* _VSERVER_LIMIT_H */
11558 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/limit_cmd.h linux-3.9.4-vs2.3.6.3/include/linux/vserver/limit_cmd.h
11559 --- linux-3.9.4/include/linux/vserver/limit_cmd.h       1970-01-01 00:00:00.000000000 +0000
11560 +++ linux-3.9.4-vs2.3.6.3/include/linux/vserver/limit_cmd.h     2013-05-31 14:47:11.000000000 +0000
11561 @@ -0,0 +1,35 @@
11562 +#ifndef _VSERVER_LIMIT_CMD_H
11563 +#define _VSERVER_LIMIT_CMD_H
11564 +
11565 +#include <uapi/vserver/limit_cmd.h>
11566 +
11567 +
11568 +#ifdef CONFIG_IA32_EMULATION
11569 +
11570 +struct vcmd_ctx_rlimit_v0_x32 {
11571 +       uint32_t id;
11572 +       uint64_t minimum;
11573 +       uint64_t softlimit;
11574 +       uint64_t maximum;
11575 +} __attribute__ ((packed));
11576 +
11577 +#endif /* CONFIG_IA32_EMULATION */
11578 +
11579 +#include <linux/compiler.h>
11580 +
11581 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
11582 +extern int vc_get_rlimit(struct vx_info *, void __user *);
11583 +extern int vc_set_rlimit(struct vx_info *, void __user *);
11584 +extern int vc_reset_hits(struct vx_info *, void __user *);
11585 +extern int vc_reset_minmax(struct vx_info *, void __user *);
11586 +
11587 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
11588 +
11589 +#ifdef CONFIG_IA32_EMULATION
11590 +
11591 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
11592 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
11593 +
11594 +#endif /* CONFIG_IA32_EMULATION */
11595 +
11596 +#endif /* _VSERVER_LIMIT_CMD_H */
11597 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/limit_def.h linux-3.9.4-vs2.3.6.3/include/linux/vserver/limit_def.h
11598 --- linux-3.9.4/include/linux/vserver/limit_def.h       1970-01-01 00:00:00.000000000 +0000
11599 +++ linux-3.9.4-vs2.3.6.3/include/linux/vserver/limit_def.h     2013-05-31 14:47:11.000000000 +0000
11600 @@ -0,0 +1,47 @@
11601 +#ifndef _VSERVER_LIMIT_DEF_H
11602 +#define _VSERVER_LIMIT_DEF_H
11603 +
11604 +#include <asm/atomic.h>
11605 +#include <asm/resource.h>
11606 +
11607 +#include "limit.h"
11608 +
11609 +
11610 +struct _vx_res_limit {
11611 +       rlim_t soft;            /* Context soft limit */
11612 +       rlim_t hard;            /* Context hard limit */
11613 +
11614 +       rlim_atomic_t rcur;     /* Current value */
11615 +       rlim_t rmin;            /* Context minimum */
11616 +       rlim_t rmax;            /* Context maximum */
11617 +
11618 +       atomic_t lhit;          /* Limit hits */
11619 +};
11620 +
11621 +/* context sub struct */
11622 +
11623 +struct _vx_limit {
11624 +       struct _vx_res_limit res[NUM_LIMITS];
11625 +};
11626 +
11627 +#ifdef CONFIG_VSERVER_DEBUG
11628 +
11629 +static inline void __dump_vx_limit(struct _vx_limit *limit)
11630 +{
11631 +       int i;
11632 +
11633 +       printk("\t_vx_limit:");
11634 +       for (i = 0; i < NUM_LIMITS; i++) {
11635 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
11636 +                       i, (unsigned long)__rlim_get(limit, i),
11637 +                       (unsigned long)__rlim_rmin(limit, i),
11638 +                       (unsigned long)__rlim_rmax(limit, i),
11639 +                       (long)__rlim_soft(limit, i),
11640 +                       (long)__rlim_hard(limit, i),
11641 +                       atomic_read(&__rlim_lhit(limit, i)));
11642 +       }
11643 +}
11644 +
11645 +#endif
11646 +
11647 +#endif /* _VSERVER_LIMIT_DEF_H */
11648 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/limit_int.h linux-3.9.4-vs2.3.6.3/include/linux/vserver/limit_int.h
11649 --- linux-3.9.4/include/linux/vserver/limit_int.h       1970-01-01 00:00:00.000000000 +0000
11650 +++ linux-3.9.4-vs2.3.6.3/include/linux/vserver/limit_int.h     2013-05-31 14:47:11.000000000 +0000
11651 @@ -0,0 +1,193 @@
11652 +#ifndef _VSERVER_LIMIT_INT_H
11653 +#define _VSERVER_LIMIT_INT_H
11654 +
11655 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
11656 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
11657 +
11658 +extern const char *vlimit_name[NUM_LIMITS];
11659 +
11660 +static inline void __vx_acc_cres(struct vx_info *vxi,
11661 +       int res, int dir, void *_data, char *_file, int _line)
11662 +{
11663 +       if (VXD_RCRES_COND(res))
11664 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
11665 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11666 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11667 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
11668 +       if (!vxi)
11669 +               return;
11670 +
11671 +       if (dir > 0)
11672 +               __rlim_inc(&vxi->limit, res);
11673 +       else
11674 +               __rlim_dec(&vxi->limit, res);
11675 +}
11676 +
11677 +static inline void __vx_add_cres(struct vx_info *vxi,
11678 +       int res, int amount, void *_data, char *_file, int _line)
11679 +{
11680 +       if (VXD_RCRES_COND(res))
11681 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
11682 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11683 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11684 +                       amount, _data, _file, _line);
11685 +       if (amount == 0)
11686 +               return;
11687 +       if (!vxi)
11688 +               return;
11689 +       __rlim_add(&vxi->limit, res, amount);
11690 +}
11691 +
11692 +static inline
11693 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
11694 +{
11695 +       int cond = (value > __rlim_rmax(limit, res));
11696 +
11697 +       if (cond)
11698 +               __rlim_rmax(limit, res) = value;
11699 +       return cond;
11700 +}
11701 +
11702 +static inline
11703 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
11704 +{
11705 +       int cond = (value < __rlim_rmin(limit, res));
11706 +
11707 +       if (cond)
11708 +               __rlim_rmin(limit, res) = value;
11709 +       return cond;
11710 +}
11711 +
11712 +static inline
11713 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
11714 +{
11715 +       if (!__vx_cres_adjust_max(limit, res, value))
11716 +               __vx_cres_adjust_min(limit, res, value);
11717 +}
11718 +
11719 +
11720 +/*     return values:
11721 +        +1 ... no limit hit
11722 +        -1 ... over soft limit
11723 +         0 ... over hard limit         */
11724 +
11725 +static inline int __vx_cres_avail(struct vx_info *vxi,
11726 +       int res, int num, char *_file, int _line)
11727 +{
11728 +       struct _vx_limit *limit;
11729 +       rlim_t value;
11730 +
11731 +       if (VXD_RLIMIT_COND(res))
11732 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
11733 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11734 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
11735 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
11736 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11737 +                       num, _file, _line);
11738 +       if (!vxi)
11739 +               return 1;
11740 +
11741 +       limit = &vxi->limit;
11742 +       value = __rlim_get(limit, res);
11743 +
11744 +       if (!__vx_cres_adjust_max(limit, res, value))
11745 +               __vx_cres_adjust_min(limit, res, value);
11746 +
11747 +       if (num == 0)
11748 +               return 1;
11749 +
11750 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
11751 +               return -1;
11752 +       if (value + num <= __rlim_soft(limit, res))
11753 +               return -1;
11754 +
11755 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
11756 +               return 1;
11757 +       if (value + num <= __rlim_hard(limit, res))
11758 +               return 1;
11759 +
11760 +       __rlim_hit(limit, res);
11761 +       return 0;
11762 +}
11763 +
11764 +
11765 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
11766 +
11767 +static inline
11768 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
11769 +{
11770 +       rlim_t value, sum = 0;
11771 +       int res;
11772 +
11773 +       while ((res = *array++)) {
11774 +               value = __rlim_get(limit, res);
11775 +               __vx_cres_fixup(limit, res, value);
11776 +               sum += value;
11777 +       }
11778 +       return sum;
11779 +}
11780 +
11781 +static inline
11782 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
11783 +{
11784 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
11785 +       int res = *array;
11786 +
11787 +       if (value == __rlim_get(limit, res))
11788 +               return value;
11789 +
11790 +       __rlim_set(limit, res, value);
11791 +       /* now adjust min/max */
11792 +       if (!__vx_cres_adjust_max(limit, res, value))
11793 +               __vx_cres_adjust_min(limit, res, value);
11794 +
11795 +       return value;
11796 +}
11797 +
11798 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
11799 +       const int *array, int num, char *_file, int _line)
11800 +{
11801 +       struct _vx_limit *limit;
11802 +       rlim_t value = 0;
11803 +       int res;
11804 +
11805 +       if (num == 0)
11806 +               return 1;
11807 +       if (!vxi)
11808 +               return 1;
11809 +
11810 +       limit = &vxi->limit;
11811 +       res = *array;
11812 +       value = __vx_cres_array_sum(limit, array + 1);
11813 +
11814 +       __rlim_set(limit, res, value);
11815 +       __vx_cres_fixup(limit, res, value);
11816 +
11817 +       return __vx_cres_avail(vxi, res, num, _file, _line);
11818 +}
11819 +
11820 +
11821 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
11822 +{
11823 +       rlim_t value;
11824 +       int res;
11825 +
11826 +       /* complex resources first */
11827 +       if ((id < 0) || (id == RLIMIT_RSS))
11828 +               __vx_cres_array_fixup(limit, VLA_RSS);
11829 +
11830 +       for (res = 0; res < NUM_LIMITS; res++) {
11831 +               if ((id > 0) && (res != id))
11832 +                       continue;
11833 +
11834 +               value = __rlim_get(limit, res);
11835 +               __vx_cres_fixup(limit, res, value);
11836 +
11837 +               /* not supposed to happen, maybe warn? */
11838 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
11839 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
11840 +       }
11841 +}
11842 +
11843 +
11844 +#endif /* _VSERVER_LIMIT_INT_H */
11845 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/monitor.h linux-3.9.4-vs2.3.6.3/include/linux/vserver/monitor.h
11846 --- linux-3.9.4/include/linux/vserver/monitor.h 1970-01-01 00:00:00.000000000 +0000
11847 +++ linux-3.9.4-vs2.3.6.3/include/linux/vserver/monitor.h       2013-05-31 14:47:11.000000000 +0000
11848 @@ -0,0 +1,6 @@
11849 +#ifndef _VSERVER_MONITOR_H
11850 +#define _VSERVER_MONITOR_H
11851 +
11852 +#include <uapi/vserver/monitor.h>
11853 +
11854 +#endif /* _VSERVER_MONITOR_H */
11855 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/network.h linux-3.9.4-vs2.3.6.3/include/linux/vserver/network.h
11856 --- linux-3.9.4/include/linux/vserver/network.h 1970-01-01 00:00:00.000000000 +0000
11857 +++ linux-3.9.4-vs2.3.6.3/include/linux/vserver/network.h       2013-05-31 14:47:11.000000000 +0000
11858 @@ -0,0 +1,76 @@
11859 +#ifndef _VSERVER_NETWORK_H
11860 +#define _VSERVER_NETWORK_H
11861 +
11862 +
11863 +#include <linux/list.h>
11864 +#include <linux/spinlock.h>
11865 +#include <linux/rcupdate.h>
11866 +#include <linux/in.h>
11867 +#include <linux/in6.h>
11868 +#include <asm/atomic.h>
11869 +#include <uapi/vserver/network.h>
11870 +
11871 +struct nx_addr_v4 {
11872 +       struct nx_addr_v4 *next;
11873 +       struct in_addr ip[2];
11874 +       struct in_addr mask;
11875 +       uint16_t type;
11876 +       uint16_t flags;
11877 +};
11878 +
11879 +struct nx_addr_v6 {
11880 +       struct nx_addr_v6 *next;
11881 +       struct in6_addr ip;
11882 +       struct in6_addr mask;
11883 +       uint32_t prefix;
11884 +       uint16_t type;
11885 +       uint16_t flags;
11886 +};
11887 +
11888 +struct nx_info {
11889 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
11890 +       nid_t nx_id;                    /* vnet id */
11891 +       atomic_t nx_usecnt;             /* usage count */
11892 +       atomic_t nx_tasks;              /* tasks count */
11893 +       int nx_state;                   /* context state */
11894 +
11895 +       uint64_t nx_flags;              /* network flag word */
11896 +       uint64_t nx_ncaps;              /* network capabilities */
11897 +
11898 +       spinlock_t addr_lock;           /* protect address changes */
11899 +       struct in_addr v4_lback;        /* Loopback address */
11900 +       struct in_addr v4_bcast;        /* Broadcast address */
11901 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
11902 +#ifdef CONFIG_IPV6
11903 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
11904 +#endif
11905 +       char nx_name[65];               /* network context name */
11906 +};
11907 +
11908 +
11909 +/* status flags */
11910 +
11911 +#define NXS_HASHED      0x0001
11912 +#define NXS_SHUTDOWN    0x0100
11913 +#define NXS_RELEASED    0x8000
11914 +
11915 +extern struct nx_info *lookup_nx_info(int);
11916 +
11917 +extern int get_nid_list(int, unsigned int *, int);
11918 +extern int nid_is_hashed(nid_t);
11919 +
11920 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
11921 +
11922 +extern long vs_net_change(struct nx_info *, unsigned int);
11923 +
11924 +struct sock;
11925 +
11926 +
11927 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
11928 +#ifdef  CONFIG_IPV6
11929 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
11930 +#else
11931 +#define NX_IPV6(n)     (0)
11932 +#endif
11933 +
11934 +#endif /* _VSERVER_NETWORK_H */
11935 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/network_cmd.h linux-3.9.4-vs2.3.6.3/include/linux/vserver/network_cmd.h
11936 --- linux-3.9.4/include/linux/vserver/network_cmd.h     1970-01-01 00:00:00.000000000 +0000
11937 +++ linux-3.9.4-vs2.3.6.3/include/linux/vserver/network_cmd.h   2013-05-31 14:47:11.000000000 +0000
11938 @@ -0,0 +1,37 @@
11939 +#ifndef _VSERVER_NETWORK_CMD_H
11940 +#define _VSERVER_NETWORK_CMD_H
11941 +
11942 +#include <uapi/vserver/network_cmd.h>
11943 +
11944 +extern int vc_task_nid(uint32_t);
11945 +
11946 +extern int vc_nx_info(struct nx_info *, void __user *);
11947 +
11948 +extern int vc_net_create(uint32_t, void __user *);
11949 +extern int vc_net_migrate(struct nx_info *, void __user *);
11950 +
11951 +extern int vc_net_add(struct nx_info *, void __user *);
11952 +extern int vc_net_remove(struct nx_info *, void __user *);
11953 +
11954 +extern int vc_net_add_ipv4_v1(struct nx_info *, void __user *);
11955 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
11956 +
11957 +extern int vc_net_rem_ipv4_v1(struct nx_info *, void __user *);
11958 +extern int vc_net_rem_ipv4(struct nx_info *, void __user *);
11959 +
11960 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
11961 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
11962 +
11963 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
11964 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
11965 +
11966 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
11967 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
11968 +
11969 +extern int vc_get_nflags(struct nx_info *, void __user *);
11970 +extern int vc_set_nflags(struct nx_info *, void __user *);
11971 +
11972 +extern int vc_get_ncaps(struct nx_info *, void __user *);
11973 +extern int vc_set_ncaps(struct nx_info *, void __user *);
11974 +
11975 +#endif /* _VSERVER_CONTEXT_CMD_H */
11976 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/percpu.h linux-3.9.4-vs2.3.6.3/include/linux/vserver/percpu.h
11977 --- linux-3.9.4/include/linux/vserver/percpu.h  1970-01-01 00:00:00.000000000 +0000
11978 +++ linux-3.9.4-vs2.3.6.3/include/linux/vserver/percpu.h        2013-05-31 14:47:11.000000000 +0000
11979 @@ -0,0 +1,14 @@
11980 +#ifndef _VSERVER_PERCPU_H
11981 +#define _VSERVER_PERCPU_H
11982 +
11983 +#include "cvirt_def.h"
11984 +#include "sched_def.h"
11985 +
11986 +struct _vx_percpu {
11987 +       struct _vx_cvirt_pc cvirt;
11988 +       struct _vx_sched_pc sched;
11989 +};
11990 +
11991 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
11992 +
11993 +#endif /* _VSERVER_PERCPU_H */
11994 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/pid.h linux-3.9.4-vs2.3.6.3/include/linux/vserver/pid.h
11995 --- linux-3.9.4/include/linux/vserver/pid.h     1970-01-01 00:00:00.000000000 +0000
11996 +++ linux-3.9.4-vs2.3.6.3/include/linux/vserver/pid.h   2013-05-31 14:47:11.000000000 +0000
11997 @@ -0,0 +1,51 @@
11998 +#ifndef _VSERVER_PID_H
11999 +#define _VSERVER_PID_H
12000 +
12001 +/* pid faking stuff */
12002 +
12003 +#define vx_info_map_pid(v, p) \
12004 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
12005 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
12006 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
12007 +#define vx_map_tgid(p) vx_map_pid(p)
12008 +
12009 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
12010 +       const char *func, const char *file, int line)
12011 +{
12012 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12013 +               vxfprintk(VXD_CBIT(cvirt, 2),
12014 +                       "vx_map_tgid: %p/%llx: %d -> %d",
12015 +                       vxi, (long long)vxi->vx_flags, pid,
12016 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
12017 +                       func, file, line);
12018 +               if (pid == 0)
12019 +                       return 0;
12020 +               if (pid == vxi->vx_initpid)
12021 +                       return 1;
12022 +       }
12023 +       return pid;
12024 +}
12025 +
12026 +#define vx_info_rmap_pid(v, p) \
12027 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
12028 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
12029 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
12030 +
12031 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
12032 +       const char *func, const char *file, int line)
12033 +{
12034 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12035 +               vxfprintk(VXD_CBIT(cvirt, 2),
12036 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
12037 +                       vxi, (long long)vxi->vx_flags, pid,
12038 +                       (pid == 1) ? vxi->vx_initpid : pid,
12039 +                       func, file, line);
12040 +               if ((pid == 1) && vxi->vx_initpid)
12041 +                       return vxi->vx_initpid;
12042 +               if (pid == vxi->vx_initpid)
12043 +                       return ~0U;
12044 +       }
12045 +       return pid;
12046 +}
12047 +
12048 +#endif
12049 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/sched.h linux-3.9.4-vs2.3.6.3/include/linux/vserver/sched.h
12050 --- linux-3.9.4/include/linux/vserver/sched.h   1970-01-01 00:00:00.000000000 +0000
12051 +++ linux-3.9.4-vs2.3.6.3/include/linux/vserver/sched.h 2013-05-31 14:47:11.000000000 +0000
12052 @@ -0,0 +1,23 @@
12053 +#ifndef _VSERVER_SCHED_H
12054 +#define _VSERVER_SCHED_H
12055 +
12056 +
12057 +#ifdef __KERNEL__
12058 +
12059 +struct timespec;
12060 +
12061 +void vx_vsi_uptime(struct timespec *, struct timespec *);
12062 +
12063 +
12064 +struct vx_info;
12065 +
12066 +void vx_update_load(struct vx_info *);
12067 +
12068 +
12069 +void vx_update_sched_param(struct _vx_sched *sched,
12070 +       struct _vx_sched_pc *sched_pc);
12071 +
12072 +#endif /* __KERNEL__ */
12073 +#else  /* _VSERVER_SCHED_H */
12074 +#warning duplicate inclusion
12075 +#endif /* _VSERVER_SCHED_H */
12076 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/sched_cmd.h linux-3.9.4-vs2.3.6.3/include/linux/vserver/sched_cmd.h
12077 --- linux-3.9.4/include/linux/vserver/sched_cmd.h       1970-01-01 00:00:00.000000000 +0000
12078 +++ linux-3.9.4-vs2.3.6.3/include/linux/vserver/sched_cmd.h     2013-05-31 14:47:11.000000000 +0000
12079 @@ -0,0 +1,11 @@
12080 +#ifndef _VSERVER_SCHED_CMD_H
12081 +#define _VSERVER_SCHED_CMD_H
12082 +
12083 +
12084 +#include <linux/compiler.h>
12085 +#include <uapi/vserver/sched_cmd.h>
12086 +
12087 +extern int vc_set_prio_bias(struct vx_info *, void __user *);
12088 +extern int vc_get_prio_bias(struct vx_info *, void __user *);
12089 +
12090 +#endif /* _VSERVER_SCHED_CMD_H */
12091 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/sched_def.h linux-3.9.4-vs2.3.6.3/include/linux/vserver/sched_def.h
12092 --- linux-3.9.4/include/linux/vserver/sched_def.h       1970-01-01 00:00:00.000000000 +0000
12093 +++ linux-3.9.4-vs2.3.6.3/include/linux/vserver/sched_def.h     2013-05-31 14:47:11.000000000 +0000
12094 @@ -0,0 +1,38 @@
12095 +#ifndef _VSERVER_SCHED_DEF_H
12096 +#define _VSERVER_SCHED_DEF_H
12097 +
12098 +#include <linux/spinlock.h>
12099 +#include <linux/jiffies.h>
12100 +#include <linux/cpumask.h>
12101 +#include <asm/atomic.h>
12102 +#include <asm/param.h>
12103 +
12104 +
12105 +/* context sub struct */
12106 +
12107 +struct _vx_sched {
12108 +       int prio_bias;                  /* bias offset for priority */
12109 +
12110 +       cpumask_t update;               /* CPUs which should update */
12111 +};
12112 +
12113 +struct _vx_sched_pc {
12114 +       int prio_bias;                  /* bias offset for priority */
12115 +
12116 +       uint64_t user_ticks;            /* token tick events */
12117 +       uint64_t sys_ticks;             /* token tick events */
12118 +       uint64_t hold_ticks;            /* token ticks paused */
12119 +};
12120 +
12121 +
12122 +#ifdef CONFIG_VSERVER_DEBUG
12123 +
12124 +static inline void __dump_vx_sched(struct _vx_sched *sched)
12125 +{
12126 +       printk("\t_vx_sched:\n");
12127 +       printk("\t priority = %4d\n", sched->prio_bias);
12128 +}
12129 +
12130 +#endif
12131 +
12132 +#endif /* _VSERVER_SCHED_DEF_H */
12133 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/signal.h linux-3.9.4-vs2.3.6.3/include/linux/vserver/signal.h
12134 --- linux-3.9.4/include/linux/vserver/signal.h  1970-01-01 00:00:00.000000000 +0000
12135 +++ linux-3.9.4-vs2.3.6.3/include/linux/vserver/signal.h        2013-05-31 14:47:11.000000000 +0000
12136 @@ -0,0 +1,14 @@
12137 +#ifndef _VSERVER_SIGNAL_H
12138 +#define _VSERVER_SIGNAL_H
12139 +
12140 +
12141 +#ifdef __KERNEL__
12142 +
12143 +struct vx_info;
12144 +
12145 +int vx_info_kill(struct vx_info *, int, int);
12146 +
12147 +#endif /* __KERNEL__ */
12148 +#else  /* _VSERVER_SIGNAL_H */
12149 +#warning duplicate inclusion
12150 +#endif /* _VSERVER_SIGNAL_H */
12151 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/signal_cmd.h linux-3.9.4-vs2.3.6.3/include/linux/vserver/signal_cmd.h
12152 --- linux-3.9.4/include/linux/vserver/signal_cmd.h      1970-01-01 00:00:00.000000000 +0000
12153 +++ linux-3.9.4-vs2.3.6.3/include/linux/vserver/signal_cmd.h    2013-05-31 14:47:11.000000000 +0000
12154 @@ -0,0 +1,14 @@
12155 +#ifndef _VSERVER_SIGNAL_CMD_H
12156 +#define _VSERVER_SIGNAL_CMD_H
12157 +
12158 +#include <uapi/vserver/signal_cmd.h>
12159 +
12160 +
12161 +extern int vc_ctx_kill(struct vx_info *, void __user *);
12162 +extern int vc_wait_exit(struct vx_info *, void __user *);
12163 +
12164 +
12165 +extern int vc_get_pflags(uint32_t pid, void __user *);
12166 +extern int vc_set_pflags(uint32_t pid, void __user *);
12167 +
12168 +#endif /* _VSERVER_SIGNAL_CMD_H */
12169 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/space.h linux-3.9.4-vs2.3.6.3/include/linux/vserver/space.h
12170 --- linux-3.9.4/include/linux/vserver/space.h   1970-01-01 00:00:00.000000000 +0000
12171 +++ linux-3.9.4-vs2.3.6.3/include/linux/vserver/space.h 2013-05-31 14:47:11.000000000 +0000
12172 @@ -0,0 +1,12 @@
12173 +#ifndef _VSERVER_SPACE_H
12174 +#define _VSERVER_SPACE_H
12175 +
12176 +#include <linux/types.h>
12177 +
12178 +struct vx_info;
12179 +
12180 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
12181 +
12182 +#else  /* _VSERVER_SPACE_H */
12183 +#warning duplicate inclusion
12184 +#endif /* _VSERVER_SPACE_H */
12185 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/space_cmd.h linux-3.9.4-vs2.3.6.3/include/linux/vserver/space_cmd.h
12186 --- linux-3.9.4/include/linux/vserver/space_cmd.h       1970-01-01 00:00:00.000000000 +0000
12187 +++ linux-3.9.4-vs2.3.6.3/include/linux/vserver/space_cmd.h     2013-05-31 14:47:11.000000000 +0000
12188 @@ -0,0 +1,13 @@
12189 +#ifndef _VSERVER_SPACE_CMD_H
12190 +#define _VSERVER_SPACE_CMD_H
12191 +
12192 +#include <uapi/vserver/space_cmd.h>
12193 +
12194 +
12195 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
12196 +extern int vc_set_space_v1(struct vx_info *, void __user *);
12197 +extern int vc_enter_space(struct vx_info *, void __user *);
12198 +extern int vc_set_space(struct vx_info *, void __user *);
12199 +extern int vc_get_space_mask(void __user *, int);
12200 +
12201 +#endif /* _VSERVER_SPACE_CMD_H */
12202 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/switch.h linux-3.9.4-vs2.3.6.3/include/linux/vserver/switch.h
12203 --- linux-3.9.4/include/linux/vserver/switch.h  1970-01-01 00:00:00.000000000 +0000
12204 +++ linux-3.9.4-vs2.3.6.3/include/linux/vserver/switch.h        2013-05-31 14:47:11.000000000 +0000
12205 @@ -0,0 +1,8 @@
12206 +#ifndef _VSERVER_SWITCH_H
12207 +#define _VSERVER_SWITCH_H
12208 +
12209 +
12210 +#include <linux/errno.h>
12211 +#include <uapi/vserver/switch.h>
12212 +
12213 +#endif /* _VSERVER_SWITCH_H */
12214 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/tag.h linux-3.9.4-vs2.3.6.3/include/linux/vserver/tag.h
12215 --- linux-3.9.4/include/linux/vserver/tag.h     1970-01-01 00:00:00.000000000 +0000
12216 +++ linux-3.9.4-vs2.3.6.3/include/linux/vserver/tag.h   2013-06-03 20:23:02.000000000 +0000
12217 @@ -0,0 +1,160 @@
12218 +#ifndef _DX_TAG_H
12219 +#define _DX_TAG_H
12220 +
12221 +#include <linux/types.h>
12222 +#include <linux/uidgid.h>
12223 +
12224 +
12225 +#define DX_TAG(in)     (IS_TAGGED(in))
12226 +
12227 +
12228 +#ifdef CONFIG_TAG_NFSD
12229 +#define DX_TAG_NFSD    1
12230 +#else
12231 +#define DX_TAG_NFSD    0
12232 +#endif
12233 +
12234 +
12235 +#ifdef CONFIG_TAGGING_NONE
12236 +
12237 +#define MAX_UID                0xFFFFFFFF
12238 +#define MAX_GID                0xFFFFFFFF
12239 +
12240 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
12241 +
12242 +#define TAGINO_UID(cond, uid, tag)     (uid)
12243 +#define TAGINO_GID(cond, gid, tag)     (gid)
12244 +
12245 +#endif
12246 +
12247 +
12248 +#ifdef CONFIG_TAGGING_GID16
12249 +
12250 +#define MAX_UID                0xFFFFFFFF
12251 +#define MAX_GID                0x0000FFFF
12252 +
12253 +#define INOTAG_TAG(cond, uid, gid, tag)        \
12254 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
12255 +
12256 +#define TAGINO_UID(cond, uid, tag)     (uid)
12257 +#define TAGINO_GID(cond, gid, tag)     \
12258 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
12259 +
12260 +#endif
12261 +
12262 +
12263 +#ifdef CONFIG_TAGGING_ID24
12264 +
12265 +#define MAX_UID                0x00FFFFFF
12266 +#define MAX_GID                0x00FFFFFF
12267 +
12268 +#define INOTAG_TAG(cond, uid, gid, tag)        \
12269 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
12270 +
12271 +#define TAGINO_UID(cond, uid, tag)     \
12272 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
12273 +#define TAGINO_GID(cond, gid, tag)     \
12274 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
12275 +
12276 +#endif
12277 +
12278 +
12279 +#ifdef CONFIG_TAGGING_UID16
12280 +
12281 +#define MAX_UID                0x0000FFFF
12282 +#define MAX_GID                0xFFFFFFFF
12283 +
12284 +#define INOTAG_TAG(cond, uid, gid, tag)        \
12285 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
12286 +
12287 +#define TAGINO_UID(cond, uid, tag)     \
12288 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
12289 +#define TAGINO_GID(cond, gid, tag)     (gid)
12290 +
12291 +#endif
12292 +
12293 +
12294 +#ifdef CONFIG_TAGGING_INTERN
12295 +
12296 +#define MAX_UID                0xFFFFFFFF
12297 +#define MAX_GID                0xFFFFFFFF
12298 +
12299 +#define INOTAG_TAG(cond, uid, gid, tag)        \
12300 +       ((cond) ? (tag) : 0)
12301 +
12302 +#define TAGINO_UID(cond, uid, tag)     (uid)
12303 +#define TAGINO_GID(cond, gid, tag)     (gid)
12304 +
12305 +#endif
12306 +
12307 +
12308 +#ifndef CONFIG_TAGGING_NONE
12309 +#define dx_current_fstag(sb)   \
12310 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
12311 +#else
12312 +#define dx_current_fstag(sb)   (0)
12313 +#endif
12314 +
12315 +#ifndef CONFIG_TAGGING_INTERN
12316 +#define TAGINO_TAG(cond, tag)  (0)
12317 +#else
12318 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
12319 +#endif
12320 +
12321 +#define TAGINO_KUID(cond, kuid, ktag)  \
12322 +       KUIDT_INIT(TAGINO_UID(cond, __kuid_val(kuid), __ktag_val(ktag)))
12323 +#define TAGINO_KGID(cond, kgid, ktag)  \
12324 +       KGIDT_INIT(TAGINO_GID(cond, __kgid_val(kgid), __ktag_val(ktag)))
12325 +#define TAGINO_KTAG(cond, ktag)                \
12326 +       KTAGT_INIT(TAGINO_TAG(cond, __ktag_val(ktag)))
12327 +
12328 +
12329 +#define INOTAG_UID(cond, uid, gid)     \
12330 +       ((cond) ? ((uid) & MAX_UID) : (uid))
12331 +#define INOTAG_GID(cond, uid, gid)     \
12332 +       ((cond) ? ((gid) & MAX_GID) : (gid))
12333 +
12334 +#define INOTAG_KUID(cond, kuid, kgid)  \
12335 +       KUIDT_INIT(INOTAG_UID(cond, __kuid_val(kuid), __kgid_val(kgid)))
12336 +#define INOTAG_KGID(cond, kuid, kgid)  \
12337 +       KGIDT_INIT(INOTAG_GID(cond, __kuid_val(kuid), __kgid_val(kgid)))
12338 +#define INOTAG_KTAG(cond, kuid, kgid, ktag) \
12339 +       KTAGT_INIT(INOTAG_TAG(cond, \
12340 +               __kuid_val(kuid), __kgid_val(kgid), __ktag_val(ktag)))
12341 +
12342 +
12343 +static inline uid_t dx_map_uid(uid_t uid)
12344 +{
12345 +       if ((uid > MAX_UID) && (uid != -1))
12346 +               uid = -2;
12347 +       return (uid & MAX_UID);
12348 +}
12349 +
12350 +static inline gid_t dx_map_gid(gid_t gid)
12351 +{
12352 +       if ((gid > MAX_GID) && (gid != -1))
12353 +               gid = -2;
12354 +       return (gid & MAX_GID);
12355 +}
12356 +
12357 +struct peer_tag {
12358 +       int32_t xid;
12359 +       int32_t nid;
12360 +};
12361 +
12362 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
12363 +
12364 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
12365 +                unsigned long *flags);
12366 +
12367 +#ifdef CONFIG_PROPAGATE
12368 +
12369 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
12370 +
12371 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
12372 +
12373 +#else
12374 +#define dx_propagate_tag(n, i) do { } while (0)
12375 +#endif
12376 +
12377 +#endif /* _DX_TAG_H */
12378 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/tag_cmd.h linux-3.9.4-vs2.3.6.3/include/linux/vserver/tag_cmd.h
12379 --- linux-3.9.4/include/linux/vserver/tag_cmd.h 1970-01-01 00:00:00.000000000 +0000
12380 +++ linux-3.9.4-vs2.3.6.3/include/linux/vserver/tag_cmd.h       2013-05-31 14:47:11.000000000 +0000
12381 @@ -0,0 +1,10 @@
12382 +#ifndef _VSERVER_TAG_CMD_H
12383 +#define _VSERVER_TAG_CMD_H
12384 +
12385 +#include <uapi/vserver/tag_cmd.h>
12386 +
12387 +extern int vc_task_tag(uint32_t);
12388 +
12389 +extern int vc_tag_migrate(uint32_t);
12390 +
12391 +#endif /* _VSERVER_TAG_CMD_H */
12392 diff -NurpP --minimal linux-3.9.4/include/net/addrconf.h linux-3.9.4-vs2.3.6.3/include/net/addrconf.h
12393 --- linux-3.9.4/include/net/addrconf.h  2013-05-31 13:45:28.000000000 +0000
12394 +++ linux-3.9.4-vs2.3.6.3/include/net/addrconf.h        2013-05-31 17:17:53.000000000 +0000
12395 @@ -85,7 +85,8 @@ extern int                    ipv6_dev_get_saddr(struct n
12396                                                const struct net_device *dev,
12397                                                const struct in6_addr *daddr,
12398                                                unsigned int srcprefs,
12399 -                                              struct in6_addr *saddr);
12400 +                                              struct in6_addr *saddr,
12401 +                                              struct nx_info *nxi);
12402  extern int                     ipv6_get_lladdr(struct net_device *dev,
12403                                                 struct in6_addr *addr,
12404                                                 unsigned char banned_flags);
12405 diff -NurpP --minimal linux-3.9.4/include/net/af_unix.h linux-3.9.4-vs2.3.6.3/include/net/af_unix.h
12406 --- linux-3.9.4/include/net/af_unix.h   2013-02-19 13:58:52.000000000 +0000
12407 +++ linux-3.9.4-vs2.3.6.3/include/net/af_unix.h 2013-05-31 17:17:53.000000000 +0000
12408 @@ -4,6 +4,7 @@
12409  #include <linux/socket.h>
12410  #include <linux/un.h>
12411  #include <linux/mutex.h>
12412 +#include <linux/vs_base.h>
12413  #include <net/sock.h>
12414  
12415  extern void unix_inflight(struct file *fp);
12416 diff -NurpP --minimal linux-3.9.4/include/net/inet_timewait_sock.h linux-3.9.4-vs2.3.6.3/include/net/inet_timewait_sock.h
12417 --- linux-3.9.4/include/net/inet_timewait_sock.h        2013-05-31 13:45:28.000000000 +0000
12418 +++ linux-3.9.4-vs2.3.6.3/include/net/inet_timewait_sock.h      2013-05-31 17:18:34.000000000 +0000
12419 @@ -116,6 +116,10 @@ struct inet_timewait_sock {
12420  #define tw_dport               __tw_common.skc_dport
12421  #define tw_num                 __tw_common.skc_num
12422  #define tw_portpair            __tw_common.skc_portpair
12423 +#define tw_xid                 __tw_common.skc_xid
12424 +#define tw_vx_info             __tw_common.skc_vx_info
12425 +#define tw_nid                 __tw_common.skc_nid
12426 +#define tw_nx_info             __tw_common.skc_nx_info
12427  
12428         int                     tw_timeout;
12429         volatile unsigned char  tw_substate;
12430 diff -NurpP --minimal linux-3.9.4/include/net/ip6_route.h linux-3.9.4-vs2.3.6.3/include/net/ip6_route.h
12431 --- linux-3.9.4/include/net/ip6_route.h 2013-05-31 13:45:28.000000000 +0000
12432 +++ linux-3.9.4-vs2.3.6.3/include/net/ip6_route.h       2013-05-31 17:17:53.000000000 +0000
12433 @@ -95,7 +95,8 @@ extern int                    ip6_route_get_saddr(struct
12434                                                     struct rt6_info *rt,
12435                                                     const struct in6_addr *daddr,
12436                                                     unsigned int prefs,
12437 -                                                   struct in6_addr *saddr);
12438 +                                                   struct in6_addr *saddr,
12439 +                                                   struct nx_info *nxi);
12440  
12441  extern struct rt6_info         *rt6_lookup(struct net *net,
12442                                             const struct in6_addr *daddr,
12443 diff -NurpP --minimal linux-3.9.4/include/net/route.h linux-3.9.4-vs2.3.6.3/include/net/route.h
12444 --- linux-3.9.4/include/net/route.h     2013-02-19 13:58:52.000000000 +0000
12445 +++ linux-3.9.4-vs2.3.6.3/include/net/route.h   2013-05-31 17:17:53.000000000 +0000
12446 @@ -207,6 +207,9 @@ static inline void ip_rt_put(struct rtab
12447         dst_release(&rt->dst);
12448  }
12449  
12450 +#include <linux/vs_base.h>
12451 +#include <linux/vs_inet.h>
12452 +
12453  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
12454  
12455  extern const __u8 ip_tos2prio[16];
12456 @@ -256,6 +259,9 @@ static inline void ip_route_connect_init
12457                            protocol, flow_flags, dst, src, dport, sport);
12458  }
12459  
12460 +extern struct rtable *ip_v4_find_src(struct net *net, struct nx_info *,
12461 +       struct flowi4 *);
12462 +
12463  static inline struct rtable *ip_route_connect(struct flowi4 *fl4,
12464                                               __be32 dst, __be32 src, u32 tos,
12465                                               int oif, u8 protocol,
12466 @@ -264,11 +270,25 @@ static inline struct rtable *ip_route_co
12467  {
12468         struct net *net = sock_net(sk);
12469         struct rtable *rt;
12470 +       struct nx_info *nx_info = current_nx_info();
12471  
12472         ip_route_connect_init(fl4, dst, src, tos, oif, protocol,
12473                               sport, dport, sk, can_sleep);
12474  
12475 -       if (!dst || !src) {
12476 +       if (sk)
12477 +               nx_info = sk->sk_nx_info;
12478 +
12479 +       vxdprintk(VXD_CBIT(net, 4),
12480 +               "ip_route_connect(%p) %p,%p;%lx",
12481 +               sk, nx_info, sk->sk_socket,
12482 +               (sk->sk_socket?sk->sk_socket->flags:0));
12483 +
12484 +       rt = ip_v4_find_src(net, nx_info, fl4);
12485 +       if (IS_ERR(rt))
12486 +               return rt;
12487 +       ip_rt_put(rt);
12488 +
12489 +       if (!fl4->daddr || !fl4->saddr) {
12490                 rt = __ip_route_output_key(net, fl4);
12491                 if (IS_ERR(rt))
12492                         return rt;
12493 diff -NurpP --minimal linux-3.9.4/include/net/sock.h linux-3.9.4-vs2.3.6.3/include/net/sock.h
12494 --- linux-3.9.4/include/net/sock.h      2013-05-31 14:22:27.000000000 +0000
12495 +++ linux-3.9.4-vs2.3.6.3/include/net/sock.h    2013-05-31 17:17:53.000000000 +0000
12496 @@ -191,6 +191,10 @@ struct sock_common {
12497  #ifdef CONFIG_NET_NS
12498         struct net              *skc_net;
12499  #endif
12500 +       xid_t                   skc_xid;
12501 +       struct vx_info          *skc_vx_info;
12502 +       nid_t                   skc_nid;
12503 +       struct nx_info          *skc_nx_info;
12504         /*
12505          * fields between dontcopy_begin/dontcopy_end
12506          * are not copied in sock_copy()
12507 @@ -304,6 +308,10 @@ struct sock {
12508  #define sk_bind_node           __sk_common.skc_bind_node
12509  #define sk_prot                        __sk_common.skc_prot
12510  #define sk_net                 __sk_common.skc_net
12511 +#define sk_xid                 __sk_common.skc_xid
12512 +#define sk_vx_info             __sk_common.skc_vx_info
12513 +#define sk_nid                 __sk_common.skc_nid
12514 +#define sk_nx_info             __sk_common.skc_nx_info
12515         socket_lock_t           sk_lock;
12516         struct sk_buff_head     sk_receive_queue;
12517         /*
12518 diff -NurpP --minimal linux-3.9.4/include/uapi/Kbuild linux-3.9.4-vs2.3.6.3/include/uapi/Kbuild
12519 --- linux-3.9.4/include/uapi/Kbuild     2012-12-11 03:30:57.000000000 +0000
12520 +++ linux-3.9.4-vs2.3.6.3/include/uapi/Kbuild   2013-05-31 14:47:11.000000000 +0000
12521 @@ -12,3 +12,4 @@ header-y += video/
12522  header-y += drm/
12523  header-y += xen/
12524  header-y += scsi/
12525 +header-y += vserver/
12526 diff -NurpP --minimal linux-3.9.4/include/uapi/linux/capability.h linux-3.9.4-vs2.3.6.3/include/uapi/linux/capability.h
12527 --- linux-3.9.4/include/uapi/linux/capability.h 2012-12-11 03:30:57.000000000 +0000
12528 +++ linux-3.9.4-vs2.3.6.3/include/uapi/linux/capability.h       2013-05-31 14:47:11.000000000 +0000
12529 @@ -259,6 +259,7 @@ struct vfs_cap_data {
12530     arbitrary SCSI commands */
12531  /* Allow setting encryption key on loopback filesystem */
12532  /* Allow setting zone reclaim policy */
12533 +/* Allow the selection of a security context */
12534  
12535  #define CAP_SYS_ADMIN        21
12536  
12537 @@ -345,7 +346,12 @@ struct vfs_cap_data {
12538  
12539  #define CAP_LAST_CAP         CAP_BLOCK_SUSPEND
12540  
12541 -#define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
12542 +/* Allow context manipulations */
12543 +/* Allow changing context info on files */
12544 +
12545 +#define CAP_CONTEXT         63
12546 +
12547 +#define cap_valid(x) ((x) >= 0 && ((x) <= CAP_LAST_CAP || (x) == CAP_CONTEXT))
12548  
12549  /*
12550   * Bit location of each capability (used by user-space library and kernel)
12551 diff -NurpP --minimal linux-3.9.4/include/uapi/linux/fs.h linux-3.9.4-vs2.3.6.3/include/uapi/linux/fs.h
12552 --- linux-3.9.4/include/uapi/linux/fs.h 2013-05-31 13:45:29.000000000 +0000
12553 +++ linux-3.9.4-vs2.3.6.3/include/uapi/linux/fs.h       2013-05-31 23:07:43.000000000 +0000
12554 @@ -86,6 +86,9 @@ struct inodes_stat_t {
12555  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
12556  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
12557  #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
12558 +#define MS_TAGGED      (1<<8)  /* use generic inode tagging */
12559 +#define MS_NOTAGCHECK  (1<<9)  /* don't check tags */
12560 +#define MS_TAGID       (1<<25) /* use specific tag for this mount */
12561  
12562  /* These sb flags are internal to the kernel */
12563  #define MS_SNAP_STABLE (1<<27) /* Snapshot pages during writeback, if needed */
12564 @@ -192,11 +195,14 @@ struct inodes_stat_t {
12565  #define FS_EXTENT_FL                   0x00080000 /* Extents */
12566  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
12567  #define FS_NOCOW_FL                    0x00800000 /* Do not cow file */
12568 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
12569  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
12570  
12571 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
12572 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
12573 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
12574 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
12575  
12576 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
12577 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
12578  
12579  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
12580  #define SYNC_FILE_RANGE_WRITE          2
12581 diff -NurpP --minimal linux-3.9.4/include/uapi/linux/gfs2_ondisk.h linux-3.9.4-vs2.3.6.3/include/uapi/linux/gfs2_ondisk.h
12582 --- linux-3.9.4/include/uapi/linux/gfs2_ondisk.h        2012-12-11 03:30:57.000000000 +0000
12583 +++ linux-3.9.4-vs2.3.6.3/include/uapi/linux/gfs2_ondisk.h      2013-05-31 14:47:11.000000000 +0000
12584 @@ -225,6 +225,9 @@ enum {
12585         gfs2fl_Sync             = 8,
12586         gfs2fl_System           = 9,
12587         gfs2fl_TopLevel         = 10,
12588 +       gfs2fl_IXUnlink         = 16,
12589 +       gfs2fl_Barrier          = 17,
12590 +       gfs2fl_Cow              = 18,
12591         gfs2fl_TruncInProg      = 29,
12592         gfs2fl_InheritDirectio  = 30,
12593         gfs2fl_InheritJdata     = 31,
12594 @@ -242,6 +245,9 @@ enum {
12595  #define GFS2_DIF_SYNC                  0x00000100
12596  #define GFS2_DIF_SYSTEM                        0x00000200 /* New in gfs2 */
12597  #define GFS2_DIF_TOPDIR                        0x00000400 /* New in gfs2 */
12598 +#define GFS2_DIF_IXUNLINK               0x00010000
12599 +#define GFS2_DIF_BARRIER                0x00020000
12600 +#define GFS2_DIF_COW                    0x00040000
12601  #define GFS2_DIF_TRUNC_IN_PROG         0x20000000 /* New in gfs2 */
12602  #define GFS2_DIF_INHERIT_DIRECTIO      0x40000000 /* only in gfs1 */
12603  #define GFS2_DIF_INHERIT_JDATA         0x80000000
12604 diff -NurpP --minimal linux-3.9.4/include/uapi/linux/if_tun.h linux-3.9.4-vs2.3.6.3/include/uapi/linux/if_tun.h
12605 --- linux-3.9.4/include/uapi/linux/if_tun.h     2013-02-19 13:58:55.000000000 +0000
12606 +++ linux-3.9.4-vs2.3.6.3/include/uapi/linux/if_tun.h   2013-05-31 15:00:16.000000000 +0000
12607 @@ -56,6 +56,7 @@
12608  #define TUNGETVNETHDRSZ _IOR('T', 215, int)
12609  #define TUNSETVNETHDRSZ _IOW('T', 216, int)
12610  #define TUNSETQUEUE  _IOW('T', 217, int)
12611 +#define TUNSETNID     _IOW('T', 218, int)
12612  
12613  /* TUNSETIFF ifr flags */
12614  #define IFF_TUN                0x0001
12615 diff -NurpP --minimal linux-3.9.4/include/uapi/linux/major.h linux-3.9.4-vs2.3.6.3/include/uapi/linux/major.h
12616 --- linux-3.9.4/include/uapi/linux/major.h      2012-12-11 03:30:57.000000000 +0000
12617 +++ linux-3.9.4-vs2.3.6.3/include/uapi/linux/major.h    2013-05-31 14:47:11.000000000 +0000
12618 @@ -15,6 +15,7 @@
12619  #define HD_MAJOR               IDE0_MAJOR
12620  #define PTY_SLAVE_MAJOR                3
12621  #define TTY_MAJOR              4
12622 +#define VROOT_MAJOR            4
12623  #define TTYAUX_MAJOR           5
12624  #define LP_MAJOR               6
12625  #define VCS_MAJOR              7
12626 diff -NurpP --minimal linux-3.9.4/include/uapi/linux/nfs_mount.h linux-3.9.4-vs2.3.6.3/include/uapi/linux/nfs_mount.h
12627 --- linux-3.9.4/include/uapi/linux/nfs_mount.h  2012-12-11 03:30:57.000000000 +0000
12628 +++ linux-3.9.4-vs2.3.6.3/include/uapi/linux/nfs_mount.h        2013-05-31 14:47:11.000000000 +0000
12629 @@ -63,7 +63,8 @@ struct nfs_mount_data {
12630  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
12631  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
12632  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
12633 -#define NFS_MOUNT_FLAGMASK     0xFFFF
12634 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
12635 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
12636  
12637  /* The following are for internal use only */
12638  #define NFS_MOUNT_LOOKUP_CACHE_NONEG   0x10000
12639 diff -NurpP --minimal linux-3.9.4/include/uapi/linux/reboot.h linux-3.9.4-vs2.3.6.3/include/uapi/linux/reboot.h
12640 --- linux-3.9.4/include/uapi/linux/reboot.h     2012-12-11 03:30:57.000000000 +0000
12641 +++ linux-3.9.4-vs2.3.6.3/include/uapi/linux/reboot.h   2013-05-31 14:47:11.000000000 +0000
12642 @@ -33,7 +33,7 @@
12643  #define        LINUX_REBOOT_CMD_RESTART2       0xA1B2C3D4
12644  #define        LINUX_REBOOT_CMD_SW_SUSPEND     0xD000FCE2
12645  #define        LINUX_REBOOT_CMD_KEXEC          0x45584543
12646 -
12647 +#define        LINUX_REBOOT_CMD_OOM            0xDEADBEEF
12648  
12649  
12650  #endif /* _UAPI_LINUX_REBOOT_H */
12651 diff -NurpP --minimal linux-3.9.4/include/uapi/linux/sysctl.h linux-3.9.4-vs2.3.6.3/include/uapi/linux/sysctl.h
12652 --- linux-3.9.4/include/uapi/linux/sysctl.h     2012-12-11 03:30:57.000000000 +0000
12653 +++ linux-3.9.4-vs2.3.6.3/include/uapi/linux/sysctl.h   2013-05-31 14:47:11.000000000 +0000
12654 @@ -60,6 +60,7 @@ enum
12655         CTL_ABI=9,              /* Binary emulation */
12656         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
12657         CTL_ARLAN=254,          /* arlan wireless driver */
12658 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
12659         CTL_S390DBF=5677,       /* s390 debug */
12660         CTL_SUNRPC=7249,        /* sunrpc debug */
12661         CTL_PM=9899,            /* frv power management */
12662 @@ -94,6 +95,7 @@ enum
12663  
12664         KERN_PANIC=15,          /* int: panic timeout */
12665         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
12666 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
12667  
12668         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
12669         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
12670 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/Kbuild linux-3.9.4-vs2.3.6.3/include/uapi/vserver/Kbuild
12671 --- linux-3.9.4/include/uapi/vserver/Kbuild     1970-01-01 00:00:00.000000000 +0000
12672 +++ linux-3.9.4-vs2.3.6.3/include/uapi/vserver/Kbuild   2013-05-31 14:47:11.000000000 +0000
12673 @@ -0,0 +1,9 @@
12674 +
12675 +header-y += context_cmd.h network_cmd.h space_cmd.h \
12676 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
12677 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
12678 +       debug_cmd.h device_cmd.h
12679 +
12680 +header-y += switch.h context.h network.h monitor.h \
12681 +       limit.h inode.h device.h
12682 +
12683 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/cacct_cmd.h linux-3.9.4-vs2.3.6.3/include/uapi/vserver/cacct_cmd.h
12684 --- linux-3.9.4/include/uapi/vserver/cacct_cmd.h        1970-01-01 00:00:00.000000000 +0000
12685 +++ linux-3.9.4-vs2.3.6.3/include/uapi/vserver/cacct_cmd.h      2013-05-31 14:47:11.000000000 +0000
12686 @@ -0,0 +1,15 @@
12687 +#ifndef _UAPI_VS_CACCT_CMD_H
12688 +#define _UAPI_VS_CACCT_CMD_H
12689 +
12690 +
12691 +/* virtual host info name commands */
12692 +
12693 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
12694 +
12695 +struct vcmd_sock_stat_v0 {
12696 +       uint32_t field;
12697 +       uint32_t count[3];
12698 +       uint64_t total[3];
12699 +};
12700 +
12701 +#endif /* _UAPI_VS_CACCT_CMD_H */
12702 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/context.h linux-3.9.4-vs2.3.6.3/include/uapi/vserver/context.h
12703 --- linux-3.9.4/include/uapi/vserver/context.h  1970-01-01 00:00:00.000000000 +0000
12704 +++ linux-3.9.4-vs2.3.6.3/include/uapi/vserver/context.h        2013-05-31 19:44:13.000000000 +0000
12705 @@ -0,0 +1,81 @@
12706 +#ifndef _UAPI_VS_CONTEXT_H
12707 +#define _UAPI_VS_CONTEXT_H
12708 +
12709 +#include <linux/types.h>
12710 +#include <linux/capability.h>
12711 +
12712 +
12713 +/* context flags */
12714 +
12715 +#define VXF_INFO_SCHED         0x00000002
12716 +#define VXF_INFO_NPROC         0x00000004
12717 +#define VXF_INFO_PRIVATE       0x00000008
12718 +
12719 +#define VXF_INFO_INIT          0x00000010
12720 +#define VXF_INFO_HIDE          0x00000020
12721 +#define VXF_INFO_ULIMIT                0x00000040
12722 +#define VXF_INFO_NSPACE                0x00000080
12723 +
12724 +#define VXF_SCHED_HARD         0x00000100
12725 +#define VXF_SCHED_PRIO         0x00000200
12726 +#define VXF_SCHED_PAUSE                0x00000400
12727 +
12728 +#define VXF_VIRT_MEM           0x00010000
12729 +#define VXF_VIRT_UPTIME                0x00020000
12730 +#define VXF_VIRT_CPU           0x00040000
12731 +#define VXF_VIRT_LOAD          0x00080000
12732 +#define VXF_VIRT_TIME          0x00100000
12733 +
12734 +#define VXF_HIDE_MOUNT         0x01000000
12735 +/* was VXF_HIDE_NETIF          0x02000000 */
12736 +#define VXF_HIDE_VINFO         0x04000000
12737 +
12738 +#define VXF_STATE_SETUP                (1ULL << 32)
12739 +#define VXF_STATE_INIT         (1ULL << 33)
12740 +#define VXF_STATE_ADMIN                (1ULL << 34)
12741 +
12742 +#define VXF_SC_HELPER          (1ULL << 36)
12743 +#define VXF_REBOOT_KILL                (1ULL << 37)
12744 +#define VXF_PERSISTENT         (1ULL << 38)
12745 +
12746 +#define VXF_FORK_RSS           (1ULL << 48)
12747 +#define VXF_PROLIFIC           (1ULL << 49)
12748 +
12749 +#define VXF_IGNEG_NICE         (1ULL << 52)
12750 +
12751 +#define VXF_ONE_TIME           (0x0007ULL << 32)
12752 +
12753 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
12754 +
12755 +
12756 +/* context migration */
12757 +
12758 +#define VXM_SET_INIT           0x00000001
12759 +#define VXM_SET_REAPER         0x00000002
12760 +
12761 +/* context caps */
12762 +
12763 +#define VXC_SET_UTSNAME                0x00000001
12764 +#define VXC_SET_RLIMIT         0x00000002
12765 +#define VXC_FS_SECURITY                0x00000004
12766 +#define VXC_FS_TRUSTED         0x00000008
12767 +#define VXC_TIOCSTI            0x00000010
12768 +
12769 +/* was VXC_RAW_ICMP            0x00000100 */
12770 +#define VXC_SYSLOG             0x00001000
12771 +#define VXC_OOM_ADJUST         0x00002000
12772 +#define VXC_AUDIT_CONTROL      0x00004000
12773 +
12774 +/* #define VXC_SECURE_MOUNT    0x00010000
12775 +#define VXC_SECURE_REMOUNT     0x00020000 */
12776 +#define VXC_BINARY_MOUNT       0x00040000
12777 +#define VXC_DEV_MOUNT          0x00080000
12778 +
12779 +#define VXC_QUOTA_CTL          0x00100000
12780 +#define VXC_ADMIN_MAPPER       0x00200000
12781 +#define VXC_ADMIN_CLOOP                0x00400000
12782 +
12783 +#define VXC_KTHREAD            0x01000000
12784 +#define VXC_NAMESPACE          0x02000000
12785 +
12786 +#endif /* _UAPI_VS_CONTEXT_H */
12787 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/context_cmd.h linux-3.9.4-vs2.3.6.3/include/uapi/vserver/context_cmd.h
12788 --- linux-3.9.4/include/uapi/vserver/context_cmd.h      1970-01-01 00:00:00.000000000 +0000
12789 +++ linux-3.9.4-vs2.3.6.3/include/uapi/vserver/context_cmd.h    2013-05-31 14:47:11.000000000 +0000
12790 @@ -0,0 +1,115 @@
12791 +#ifndef _UAPI_VS_CONTEXT_CMD_H
12792 +#define _UAPI_VS_CONTEXT_CMD_H
12793 +
12794 +
12795 +/* vinfo commands */
12796 +
12797 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
12798 +
12799 +
12800 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
12801 +
12802 +struct vcmd_vx_info_v0 {
12803 +       uint32_t xid;
12804 +       uint32_t initpid;
12805 +       /* more to come */
12806 +};
12807 +
12808 +
12809 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
12810 +
12811 +struct vcmd_ctx_stat_v0 {
12812 +       uint32_t usecnt;
12813 +       uint32_t tasks;
12814 +       /* more to come */
12815 +};
12816 +
12817 +
12818 +/* context commands */
12819 +
12820 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
12821 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
12822 +
12823 +struct vcmd_ctx_create {
12824 +       uint64_t flagword;
12825 +};
12826 +
12827 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
12828 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
12829 +
12830 +struct vcmd_ctx_migrate {
12831 +       uint64_t flagword;
12832 +};
12833 +
12834 +
12835 +
12836 +/* flag commands */
12837 +
12838 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
12839 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
12840 +
12841 +struct vcmd_ctx_flags_v0 {
12842 +       uint64_t flagword;
12843 +       uint64_t mask;
12844 +};
12845 +
12846 +
12847 +
12848 +/* context caps commands */
12849 +
12850 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
12851 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
12852 +
12853 +struct vcmd_ctx_caps_v1 {
12854 +       uint64_t ccaps;
12855 +       uint64_t cmask;
12856 +};
12857 +
12858 +
12859 +
12860 +/* bcaps commands */
12861 +
12862 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
12863 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
12864 +
12865 +struct vcmd_bcaps {
12866 +       uint64_t bcaps;
12867 +       uint64_t bmask;
12868 +};
12869 +
12870 +
12871 +
12872 +/* umask commands */
12873 +
12874 +#define VCMD_get_umask         VC_CMD(FLAGS, 13, 0)
12875 +#define VCMD_set_umask         VC_CMD(FLAGS, 14, 0)
12876 +
12877 +struct vcmd_umask {
12878 +       uint64_t umask;
12879 +       uint64_t mask;
12880 +};
12881 +
12882 +
12883 +
12884 +/* wmask commands */
12885 +
12886 +#define VCMD_get_wmask         VC_CMD(FLAGS, 15, 0)
12887 +#define VCMD_set_wmask         VC_CMD(FLAGS, 16, 0)
12888 +
12889 +struct vcmd_wmask {
12890 +       uint64_t wmask;
12891 +       uint64_t mask;
12892 +};
12893 +
12894 +
12895 +
12896 +/* OOM badness */
12897 +
12898 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
12899 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
12900 +
12901 +struct vcmd_badness_v0 {
12902 +       int64_t bias;
12903 +};
12904 +
12905 +#endif /* _UAPI_VS_CONTEXT_CMD_H */
12906 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/cvirt_cmd.h linux-3.9.4-vs2.3.6.3/include/uapi/vserver/cvirt_cmd.h
12907 --- linux-3.9.4/include/uapi/vserver/cvirt_cmd.h        1970-01-01 00:00:00.000000000 +0000
12908 +++ linux-3.9.4-vs2.3.6.3/include/uapi/vserver/cvirt_cmd.h      2013-05-31 14:47:11.000000000 +0000
12909 @@ -0,0 +1,41 @@
12910 +#ifndef _UAPI_VS_CVIRT_CMD_H
12911 +#define _UAPI_VS_CVIRT_CMD_H
12912 +
12913 +
12914 +/* virtual host info name commands */
12915 +
12916 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
12917 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
12918 +
12919 +struct vcmd_vhi_name_v0 {
12920 +       uint32_t field;
12921 +       char name[65];
12922 +};
12923 +
12924 +
12925 +enum vhi_name_field {
12926 +       VHIN_CONTEXT = 0,
12927 +       VHIN_SYSNAME,
12928 +       VHIN_NODENAME,
12929 +       VHIN_RELEASE,
12930 +       VHIN_VERSION,
12931 +       VHIN_MACHINE,
12932 +       VHIN_DOMAINNAME,
12933 +};
12934 +
12935 +
12936 +
12937 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
12938 +
12939 +struct vcmd_virt_stat_v0 {
12940 +       uint64_t offset;
12941 +       uint64_t uptime;
12942 +       uint32_t nr_threads;
12943 +       uint32_t nr_running;
12944 +       uint32_t nr_uninterruptible;
12945 +       uint32_t nr_onhold;
12946 +       uint32_t nr_forks;
12947 +       uint32_t load[3];
12948 +};
12949 +
12950 +#endif /* _UAPI_VS_CVIRT_CMD_H */
12951 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/debug_cmd.h linux-3.9.4-vs2.3.6.3/include/uapi/vserver/debug_cmd.h
12952 --- linux-3.9.4/include/uapi/vserver/debug_cmd.h        1970-01-01 00:00:00.000000000 +0000
12953 +++ linux-3.9.4-vs2.3.6.3/include/uapi/vserver/debug_cmd.h      2013-05-31 14:47:11.000000000 +0000
12954 @@ -0,0 +1,24 @@
12955 +#ifndef _UAPI_VS_DEBUG_CMD_H
12956 +#define _UAPI_VS_DEBUG_CMD_H
12957 +
12958 +
12959 +/* debug commands */
12960 +
12961 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
12962 +
12963 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
12964 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
12965 +
12966 +struct  vcmd_read_history_v0 {
12967 +       uint32_t index;
12968 +       uint32_t count;
12969 +       char __user *data;
12970 +};
12971 +
12972 +struct  vcmd_read_monitor_v0 {
12973 +       uint32_t index;
12974 +       uint32_t count;
12975 +       char __user *data;
12976 +};
12977 +
12978 +#endif /* _UAPI_VS_DEBUG_CMD_H */
12979 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/device.h linux-3.9.4-vs2.3.6.3/include/uapi/vserver/device.h
12980 --- linux-3.9.4/include/uapi/vserver/device.h   1970-01-01 00:00:00.000000000 +0000
12981 +++ linux-3.9.4-vs2.3.6.3/include/uapi/vserver/device.h 2013-05-31 14:47:11.000000000 +0000
12982 @@ -0,0 +1,12 @@
12983 +#ifndef _UAPI_VS_DEVICE_H
12984 +#define _UAPI_VS_DEVICE_H
12985 +
12986 +
12987 +#define DATTR_CREATE   0x00000001
12988 +#define DATTR_OPEN     0x00000002
12989 +
12990 +#define DATTR_REMAP    0x00000010
12991 +
12992 +#define DATTR_MASK     0x00000013
12993 +
12994 +#endif /* _UAPI_VS_DEVICE_H */
12995 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/device_cmd.h linux-3.9.4-vs2.3.6.3/include/uapi/vserver/device_cmd.h
12996 --- linux-3.9.4/include/uapi/vserver/device_cmd.h       1970-01-01 00:00:00.000000000 +0000
12997 +++ linux-3.9.4-vs2.3.6.3/include/uapi/vserver/device_cmd.h     2013-05-31 14:47:11.000000000 +0000
12998 @@ -0,0 +1,16 @@
12999 +#ifndef _UAPI_VS_DEVICE_CMD_H
13000 +#define _UAPI_VS_DEVICE_CMD_H
13001 +
13002 +
13003 +/*  device vserver commands */
13004 +
13005 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
13006 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
13007 +
13008 +struct vcmd_set_mapping_v0 {
13009 +       const char __user *device;
13010 +       const char __user *target;
13011 +       uint32_t flags;
13012 +};
13013 +
13014 +#endif /* _UAPI_VS_DEVICE_CMD_H */
13015 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/dlimit_cmd.h linux-3.9.4-vs2.3.6.3/include/uapi/vserver/dlimit_cmd.h
13016 --- linux-3.9.4/include/uapi/vserver/dlimit_cmd.h       1970-01-01 00:00:00.000000000 +0000
13017 +++ linux-3.9.4-vs2.3.6.3/include/uapi/vserver/dlimit_cmd.h     2013-05-31 14:47:11.000000000 +0000
13018 @@ -0,0 +1,67 @@
13019 +#ifndef _UAPI_VS_DLIMIT_CMD_H
13020 +#define _UAPI_VS_DLIMIT_CMD_H
13021 +
13022 +
13023 +/*  dlimit vserver commands */
13024 +
13025 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
13026 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
13027 +
13028 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
13029 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
13030 +
13031 +struct vcmd_ctx_dlimit_base_v0 {
13032 +       const char __user *name;
13033 +       uint32_t flags;
13034 +};
13035 +
13036 +struct vcmd_ctx_dlimit_v0 {
13037 +       const char __user *name;
13038 +       uint32_t space_used;                    /* used space in kbytes */
13039 +       uint32_t space_total;                   /* maximum space in kbytes */
13040 +       uint32_t inodes_used;                   /* used inodes */
13041 +       uint32_t inodes_total;                  /* maximum inodes */
13042 +       uint32_t reserved;                      /* reserved for root in % */
13043 +       uint32_t flags;
13044 +};
13045 +
13046 +#define CDLIM_UNSET            ((uint32_t)0UL)
13047 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
13048 +#define CDLIM_KEEP             ((uint32_t)~1UL)
13049 +
13050 +#define DLIME_UNIT     0
13051 +#define DLIME_KILO     1
13052 +#define DLIME_MEGA     2
13053 +#define DLIME_GIGA     3
13054 +
13055 +#define DLIMF_SHIFT    0x10
13056 +
13057 +#define DLIMS_USED     0
13058 +#define DLIMS_TOTAL    2
13059 +
13060 +static inline
13061 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
13062 +{
13063 +       int exp = (flags & DLIMF_SHIFT) ?
13064 +               (flags >> shift) & DLIME_GIGA : DLIME_KILO;
13065 +       return ((uint64_t)val) << (10 * exp);
13066 +}
13067 +
13068 +static inline
13069 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
13070 +{
13071 +       int exp = 0;
13072 +
13073 +       if (*flags & DLIMF_SHIFT) {
13074 +               while (val > (1LL << 32) && (exp < 3)) {
13075 +                       val >>= 10;
13076 +                       exp++;
13077 +               }
13078 +               *flags &= ~(DLIME_GIGA << shift);
13079 +               *flags |= exp << shift;
13080 +       } else
13081 +               val >>= 10;
13082 +       return val;
13083 +}
13084 +
13085 +#endif /* _UAPI_VS_DLIMIT_CMD_H */
13086 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/inode.h linux-3.9.4-vs2.3.6.3/include/uapi/vserver/inode.h
13087 --- linux-3.9.4/include/uapi/vserver/inode.h    1970-01-01 00:00:00.000000000 +0000
13088 +++ linux-3.9.4-vs2.3.6.3/include/uapi/vserver/inode.h  2013-05-31 14:47:11.000000000 +0000
13089 @@ -0,0 +1,23 @@
13090 +#ifndef _UAPI_VS_INODE_H
13091 +#define _UAPI_VS_INODE_H
13092 +
13093 +
13094 +#define IATTR_TAG      0x01000000
13095 +
13096 +#define IATTR_ADMIN    0x00000001
13097 +#define IATTR_WATCH    0x00000002
13098 +#define IATTR_HIDE     0x00000004
13099 +#define IATTR_FLAGS    0x00000007
13100 +
13101 +#define IATTR_BARRIER  0x00010000
13102 +#define IATTR_IXUNLINK 0x00020000
13103 +#define IATTR_IMMUTABLE 0x00040000
13104 +#define IATTR_COW      0x00080000
13105 +
13106 +
13107 +/* inode ioctls */
13108 +
13109 +#define FIOC_GETXFLG   _IOR('x', 5, long)
13110 +#define FIOC_SETXFLG   _IOW('x', 6, long)
13111 +
13112 +#endif /* _UAPI_VS_INODE_H */
13113 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/inode_cmd.h linux-3.9.4-vs2.3.6.3/include/uapi/vserver/inode_cmd.h
13114 --- linux-3.9.4/include/uapi/vserver/inode_cmd.h        1970-01-01 00:00:00.000000000 +0000
13115 +++ linux-3.9.4-vs2.3.6.3/include/uapi/vserver/inode_cmd.h      2013-05-31 14:47:11.000000000 +0000
13116 @@ -0,0 +1,26 @@
13117 +#ifndef _UAPI_VS_INODE_CMD_H
13118 +#define _UAPI_VS_INODE_CMD_H
13119 +
13120 +
13121 +/*  inode vserver commands */
13122 +
13123 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
13124 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
13125 +
13126 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
13127 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
13128 +
13129 +struct vcmd_ctx_iattr_v1 {
13130 +       const char __user *name;
13131 +       uint32_t tag;
13132 +       uint32_t flags;
13133 +       uint32_t mask;
13134 +};
13135 +
13136 +struct vcmd_ctx_fiattr_v0 {
13137 +       uint32_t tag;
13138 +       uint32_t flags;
13139 +       uint32_t mask;
13140 +};
13141 +
13142 +#endif /* _UAPI_VS_INODE_CMD_H */
13143 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/limit.h linux-3.9.4-vs2.3.6.3/include/uapi/vserver/limit.h
13144 --- linux-3.9.4/include/uapi/vserver/limit.h    1970-01-01 00:00:00.000000000 +0000
13145 +++ linux-3.9.4-vs2.3.6.3/include/uapi/vserver/limit.h  2013-05-31 14:47:11.000000000 +0000
13146 @@ -0,0 +1,14 @@
13147 +#ifndef _UAPI_VS_LIMIT_H
13148 +#define _UAPI_VS_LIMIT_H
13149 +
13150 +
13151 +#define VLIMIT_NSOCK   16
13152 +#define VLIMIT_OPENFD  17
13153 +#define VLIMIT_ANON    18
13154 +#define VLIMIT_SHMEM   19
13155 +#define VLIMIT_SEMARY  20
13156 +#define VLIMIT_NSEMS   21
13157 +#define VLIMIT_DENTRY  22
13158 +#define VLIMIT_MAPPED  23
13159 +
13160 +#endif /* _UAPI_VS_LIMIT_H */
13161 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/limit_cmd.h linux-3.9.4-vs2.3.6.3/include/uapi/vserver/limit_cmd.h
13162 --- linux-3.9.4/include/uapi/vserver/limit_cmd.h        1970-01-01 00:00:00.000000000 +0000
13163 +++ linux-3.9.4-vs2.3.6.3/include/uapi/vserver/limit_cmd.h      2013-05-31 14:47:11.000000000 +0000
13164 @@ -0,0 +1,40 @@
13165 +#ifndef _UAPI_VS_LIMIT_CMD_H
13166 +#define _UAPI_VS_LIMIT_CMD_H
13167 +
13168 +
13169 +/*  rlimit vserver commands */
13170 +
13171 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
13172 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
13173 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
13174 +#define VCMD_reset_hits                VC_CMD(RLIMIT, 7, 0)
13175 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
13176 +
13177 +struct vcmd_ctx_rlimit_v0 {
13178 +       uint32_t id;
13179 +       uint64_t minimum;
13180 +       uint64_t softlimit;
13181 +       uint64_t maximum;
13182 +};
13183 +
13184 +struct vcmd_ctx_rlimit_mask_v0 {
13185 +       uint32_t minimum;
13186 +       uint32_t softlimit;
13187 +       uint32_t maximum;
13188 +};
13189 +
13190 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
13191 +
13192 +struct vcmd_rlimit_stat_v0 {
13193 +       uint32_t id;
13194 +       uint32_t hits;
13195 +       uint64_t value;
13196 +       uint64_t minimum;
13197 +       uint64_t maximum;
13198 +};
13199 +
13200 +#define CRLIM_UNSET            (0ULL)
13201 +#define CRLIM_INFINITY         (~0ULL)
13202 +#define CRLIM_KEEP             (~1ULL)
13203 +
13204 +#endif /* _UAPI_VS_LIMIT_CMD_H */
13205 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/monitor.h linux-3.9.4-vs2.3.6.3/include/uapi/vserver/monitor.h
13206 --- linux-3.9.4/include/uapi/vserver/monitor.h  1970-01-01 00:00:00.000000000 +0000
13207 +++ linux-3.9.4-vs2.3.6.3/include/uapi/vserver/monitor.h        2013-05-31 14:47:11.000000000 +0000
13208 @@ -0,0 +1,96 @@
13209 +#ifndef _UAPI_VS_MONITOR_H
13210 +#define _UAPI_VS_MONITOR_H
13211 +
13212 +#include <linux/types.h>
13213 +
13214 +
13215 +enum {
13216 +       VXM_UNUSED = 0,
13217 +
13218 +       VXM_SYNC = 0x10,
13219 +
13220 +       VXM_UPDATE = 0x20,
13221 +       VXM_UPDATE_1,
13222 +       VXM_UPDATE_2,
13223 +
13224 +       VXM_RQINFO_1 = 0x24,
13225 +       VXM_RQINFO_2,
13226 +
13227 +       VXM_ACTIVATE = 0x40,
13228 +       VXM_DEACTIVATE,
13229 +       VXM_IDLE,
13230 +
13231 +       VXM_HOLD = 0x44,
13232 +       VXM_UNHOLD,
13233 +
13234 +       VXM_MIGRATE = 0x48,
13235 +       VXM_RESCHED,
13236 +
13237 +       /* all other bits are flags */
13238 +       VXM_SCHED = 0x80,
13239 +};
13240 +
13241 +struct _vxm_update_1 {
13242 +       uint32_t tokens_max;
13243 +       uint32_t fill_rate;
13244 +       uint32_t interval;
13245 +};
13246 +
13247 +struct _vxm_update_2 {
13248 +       uint32_t tokens_min;
13249 +       uint32_t fill_rate;
13250 +       uint32_t interval;
13251 +};
13252 +
13253 +struct _vxm_rqinfo_1 {
13254 +       uint16_t running;
13255 +       uint16_t onhold;
13256 +       uint16_t iowait;
13257 +       uint16_t uintr;
13258 +       uint32_t idle_tokens;
13259 +};
13260 +
13261 +struct _vxm_rqinfo_2 {
13262 +       uint32_t norm_time;
13263 +       uint32_t idle_time;
13264 +       uint32_t idle_skip;
13265 +};
13266 +
13267 +struct _vxm_sched {
13268 +       uint32_t tokens;
13269 +       uint32_t norm_time;
13270 +       uint32_t idle_time;
13271 +};
13272 +
13273 +struct _vxm_task {
13274 +       uint16_t pid;
13275 +       uint16_t state;
13276 +};
13277 +
13278 +struct _vxm_event {
13279 +       uint32_t jif;
13280 +       union {
13281 +               uint32_t seq;
13282 +               uint32_t sec;
13283 +       };
13284 +       union {
13285 +               uint32_t tokens;
13286 +               uint32_t nsec;
13287 +               struct _vxm_task tsk;
13288 +       };
13289 +};
13290 +
13291 +struct _vx_mon_entry {
13292 +       uint16_t type;
13293 +       uint16_t xid;
13294 +       union {
13295 +               struct _vxm_event ev;
13296 +               struct _vxm_sched sd;
13297 +               struct _vxm_update_1 u1;
13298 +               struct _vxm_update_2 u2;
13299 +               struct _vxm_rqinfo_1 q1;
13300 +               struct _vxm_rqinfo_2 q2;
13301 +       };
13302 +};
13303 +
13304 +#endif /* _UAPI_VS_MONITOR_H */
13305 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/network.h linux-3.9.4-vs2.3.6.3/include/uapi/vserver/network.h
13306 --- linux-3.9.4/include/uapi/vserver/network.h  1970-01-01 00:00:00.000000000 +0000
13307 +++ linux-3.9.4-vs2.3.6.3/include/uapi/vserver/network.h        2013-05-31 14:47:11.000000000 +0000
13308 @@ -0,0 +1,76 @@
13309 +#ifndef _UAPI_VS_NETWORK_H
13310 +#define _UAPI_VS_NETWORK_H
13311 +
13312 +#include <linux/types.h>
13313 +
13314 +
13315 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
13316 +
13317 +
13318 +/* network flags */
13319 +
13320 +#define NXF_INFO_PRIVATE       0x00000008
13321 +
13322 +#define NXF_SINGLE_IP          0x00000100
13323 +#define NXF_LBACK_REMAP                0x00000200
13324 +#define NXF_LBACK_ALLOW                0x00000400
13325 +
13326 +#define NXF_HIDE_NETIF         0x02000000
13327 +#define NXF_HIDE_LBACK         0x04000000
13328 +
13329 +#define NXF_STATE_SETUP                (1ULL << 32)
13330 +#define NXF_STATE_ADMIN                (1ULL << 34)
13331 +
13332 +#define NXF_SC_HELPER          (1ULL << 36)
13333 +#define NXF_PERSISTENT         (1ULL << 38)
13334 +
13335 +#define NXF_ONE_TIME           (0x0005ULL << 32)
13336 +
13337 +
13338 +#define        NXF_INIT_SET            (__nxf_init_set())
13339 +
13340 +static inline uint64_t __nxf_init_set(void) {
13341 +       return    NXF_STATE_ADMIN
13342 +#ifdef CONFIG_VSERVER_AUTO_LBACK
13343 +               | NXF_LBACK_REMAP
13344 +               | NXF_HIDE_LBACK
13345 +#endif
13346 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
13347 +               | NXF_SINGLE_IP
13348 +#endif
13349 +               | NXF_HIDE_NETIF;
13350 +}
13351 +
13352 +
13353 +/* network caps */
13354 +
13355 +#define NXC_TUN_CREATE         0x00000001
13356 +
13357 +#define NXC_RAW_ICMP           0x00000100
13358 +
13359 +#define NXC_MULTICAST          0x00001000
13360 +
13361 +
13362 +/* address types */
13363 +
13364 +#define NXA_TYPE_IPV4          0x0001
13365 +#define NXA_TYPE_IPV6          0x0002
13366 +
13367 +#define NXA_TYPE_NONE          0x0000
13368 +#define NXA_TYPE_ANY           0x00FF
13369 +
13370 +#define NXA_TYPE_ADDR          0x0010
13371 +#define NXA_TYPE_MASK          0x0020
13372 +#define NXA_TYPE_RANGE         0x0040
13373 +
13374 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
13375 +
13376 +#define NXA_MOD_BCAST          0x0100
13377 +#define NXA_MOD_LBACK          0x0200
13378 +
13379 +#define NXA_LOOPBACK           0x1000
13380 +
13381 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
13382 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
13383 +
13384 +#endif /* _UAPI_VS_NETWORK_H */
13385 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/network_cmd.h linux-3.9.4-vs2.3.6.3/include/uapi/vserver/network_cmd.h
13386 --- linux-3.9.4/include/uapi/vserver/network_cmd.h      1970-01-01 00:00:00.000000000 +0000
13387 +++ linux-3.9.4-vs2.3.6.3/include/uapi/vserver/network_cmd.h    2013-05-31 14:47:11.000000000 +0000
13388 @@ -0,0 +1,123 @@
13389 +#ifndef _UAPI_VS_NETWORK_CMD_H
13390 +#define _UAPI_VS_NETWORK_CMD_H
13391 +
13392 +
13393 +/* vinfo commands */
13394 +
13395 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
13396 +
13397 +
13398 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
13399 +
13400 +struct vcmd_nx_info_v0 {
13401 +       uint32_t nid;
13402 +       /* more to come */
13403 +};
13404 +
13405 +
13406 +#include <linux/in.h>
13407 +#include <linux/in6.h>
13408 +
13409 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
13410 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
13411 +
13412 +struct  vcmd_net_create {
13413 +       uint64_t flagword;
13414 +};
13415 +
13416 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
13417 +
13418 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
13419 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
13420 +
13421 +struct vcmd_net_addr_v0 {
13422 +       uint16_t type;
13423 +       uint16_t count;
13424 +       struct in_addr ip[4];
13425 +       struct in_addr mask[4];
13426 +};
13427 +
13428 +#define VCMD_net_add_ipv4_v1   VC_CMD(NETALT, 1, 1)
13429 +#define VCMD_net_rem_ipv4_v1   VC_CMD(NETALT, 2, 1)
13430 +
13431 +struct vcmd_net_addr_ipv4_v1 {
13432 +       uint16_t type;
13433 +       uint16_t flags;
13434 +       struct in_addr ip;
13435 +       struct in_addr mask;
13436 +};
13437 +
13438 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 2)
13439 +#define VCMD_net_rem_ipv4      VC_CMD(NETALT, 2, 2)
13440 +
13441 +struct vcmd_net_addr_ipv4_v2 {
13442 +       uint16_t type;
13443 +       uint16_t flags;
13444 +       struct in_addr ip;
13445 +       struct in_addr ip2;
13446 +       struct in_addr mask;
13447 +};
13448 +
13449 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
13450 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
13451 +
13452 +struct vcmd_net_addr_ipv6_v1 {
13453 +       uint16_t type;
13454 +       uint16_t flags;
13455 +       uint32_t prefix;
13456 +       struct in6_addr ip;
13457 +       struct in6_addr mask;
13458 +};
13459 +
13460 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
13461 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
13462 +
13463 +struct vcmd_match_ipv4_v0 {
13464 +       uint16_t type;
13465 +       uint16_t flags;
13466 +       uint16_t parent;
13467 +       uint16_t prefix;
13468 +       struct in_addr ip;
13469 +       struct in_addr ip2;
13470 +       struct in_addr mask;
13471 +};
13472 +
13473 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
13474 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
13475 +
13476 +struct vcmd_match_ipv6_v0 {
13477 +       uint16_t type;
13478 +       uint16_t flags;
13479 +       uint16_t parent;
13480 +       uint16_t prefix;
13481 +       struct in6_addr ip;
13482 +       struct in6_addr ip2;
13483 +       struct in6_addr mask;
13484 +};
13485 +
13486 +
13487 +
13488 +
13489 +/* flag commands */
13490 +
13491 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
13492 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
13493 +
13494 +struct vcmd_net_flags_v0 {
13495 +       uint64_t flagword;
13496 +       uint64_t mask;
13497 +};
13498 +
13499 +
13500 +
13501 +/* network caps commands */
13502 +
13503 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
13504 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
13505 +
13506 +struct vcmd_net_caps_v0 {
13507 +       uint64_t ncaps;
13508 +       uint64_t cmask;
13509 +};
13510 +
13511 +#endif /* _UAPI_VS_NETWORK_CMD_H */
13512 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/sched_cmd.h linux-3.9.4-vs2.3.6.3/include/uapi/vserver/sched_cmd.h
13513 --- linux-3.9.4/include/uapi/vserver/sched_cmd.h        1970-01-01 00:00:00.000000000 +0000
13514 +++ linux-3.9.4-vs2.3.6.3/include/uapi/vserver/sched_cmd.h      2013-05-31 14:47:11.000000000 +0000
13515 @@ -0,0 +1,13 @@
13516 +#ifndef _UAPI_VS_SCHED_CMD_H
13517 +#define _UAPI_VS_SCHED_CMD_H
13518 +
13519 +
13520 +struct vcmd_prio_bias {
13521 +       int32_t cpu_id;
13522 +       int32_t prio_bias;
13523 +};
13524 +
13525 +#define VCMD_set_prio_bias     VC_CMD(SCHED, 4, 0)
13526 +#define VCMD_get_prio_bias     VC_CMD(SCHED, 5, 0)
13527 +
13528 +#endif /* _UAPI_VS_SCHED_CMD_H */
13529 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/signal_cmd.h linux-3.9.4-vs2.3.6.3/include/uapi/vserver/signal_cmd.h
13530 --- linux-3.9.4/include/uapi/vserver/signal_cmd.h       1970-01-01 00:00:00.000000000 +0000
13531 +++ linux-3.9.4-vs2.3.6.3/include/uapi/vserver/signal_cmd.h     2013-05-31 14:47:11.000000000 +0000
13532 @@ -0,0 +1,31 @@
13533 +#ifndef _UAPI_VS_SIGNAL_CMD_H
13534 +#define _UAPI_VS_SIGNAL_CMD_H
13535 +
13536 +
13537 +/*  signalling vserver commands */
13538 +
13539 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
13540 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
13541 +
13542 +struct vcmd_ctx_kill_v0 {
13543 +       int32_t pid;
13544 +       int32_t sig;
13545 +};
13546 +
13547 +struct vcmd_wait_exit_v0 {
13548 +       int32_t reboot_cmd;
13549 +       int32_t exit_code;
13550 +};
13551 +
13552 +
13553 +/*  process alteration commands */
13554 +
13555 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
13556 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
13557 +
13558 +struct vcmd_pflags_v0 {
13559 +       uint32_t flagword;
13560 +       uint32_t mask;
13561 +};
13562 +
13563 +#endif /* _UAPI_VS_SIGNAL_CMD_H */
13564 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/space_cmd.h linux-3.9.4-vs2.3.6.3/include/uapi/vserver/space_cmd.h
13565 --- linux-3.9.4/include/uapi/vserver/space_cmd.h        1970-01-01 00:00:00.000000000 +0000
13566 +++ linux-3.9.4-vs2.3.6.3/include/uapi/vserver/space_cmd.h      2013-05-31 14:47:11.000000000 +0000
13567 @@ -0,0 +1,28 @@
13568 +#ifndef _UAPI_VS_SPACE_CMD_H
13569 +#define _UAPI_VS_SPACE_CMD_H
13570 +
13571 +
13572 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
13573 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
13574 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
13575 +
13576 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
13577 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
13578 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
13579 +
13580 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
13581 +
13582 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
13583 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
13584 +
13585 +
13586 +struct vcmd_space_mask_v1 {
13587 +       uint64_t mask;
13588 +};
13589 +
13590 +struct vcmd_space_mask_v2 {
13591 +       uint64_t mask;
13592 +       uint32_t index;
13593 +};
13594 +
13595 +#endif /* _UAPI_VS_SPACE_CMD_H */
13596 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/switch.h linux-3.9.4-vs2.3.6.3/include/uapi/vserver/switch.h
13597 --- linux-3.9.4/include/uapi/vserver/switch.h   1970-01-01 00:00:00.000000000 +0000
13598 +++ linux-3.9.4-vs2.3.6.3/include/uapi/vserver/switch.h 2013-05-31 14:47:11.000000000 +0000
13599 @@ -0,0 +1,90 @@
13600 +#ifndef _UAPI_VS_SWITCH_H
13601 +#define _UAPI_VS_SWITCH_H
13602 +
13603 +#include <linux/types.h>
13604 +
13605 +
13606 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
13607 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
13608 +#define VC_VERSION(c)          ((c) & 0xFFF)
13609 +
13610 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
13611 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
13612 +
13613 +/*
13614 +
13615 +  Syscall Matrix V2.8
13616 +
13617 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
13618 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
13619 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
13620 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13621 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
13622 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
13623 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13624 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
13625 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
13626 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13627 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
13628 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
13629 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13630 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
13631 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
13632 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13633 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
13634 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
13635 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13636 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
13637 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
13638 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
13639 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
13640 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
13641 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13642 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
13643 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
13644 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13645 +
13646 +*/
13647 +
13648 +#define VC_CAT_VERSION         0
13649 +
13650 +#define VC_CAT_VSETUP          1
13651 +#define VC_CAT_VHOST           2
13652 +
13653 +#define VC_CAT_DEVICE          6
13654 +
13655 +#define VC_CAT_VPROC           9
13656 +#define VC_CAT_PROCALT         10
13657 +#define VC_CAT_PROCMIG         11
13658 +#define VC_CAT_PROCTRL         12
13659 +
13660 +#define VC_CAT_SCHED           14
13661 +#define VC_CAT_MEMCTRL         20
13662 +
13663 +#define VC_CAT_VNET            25
13664 +#define VC_CAT_NETALT          26
13665 +#define VC_CAT_NETMIG          27
13666 +#define VC_CAT_NETCTRL         28
13667 +
13668 +#define VC_CAT_TAGMIG          35
13669 +#define VC_CAT_DLIMIT          36
13670 +#define VC_CAT_INODE           38
13671 +
13672 +#define VC_CAT_VSTAT           40
13673 +#define VC_CAT_VINFO           46
13674 +#define VC_CAT_EVENT           48
13675 +
13676 +#define VC_CAT_FLAGS           52
13677 +#define VC_CAT_VSPACE          54
13678 +#define VC_CAT_DEBUG           56
13679 +#define VC_CAT_RLIMIT          60
13680 +
13681 +#define VC_CAT_SYSTEST         61
13682 +#define VC_CAT_COMPAT          63
13683 +
13684 +/*  query version */
13685 +
13686 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
13687 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
13688 +
13689 +#endif /* _UAPI_VS_SWITCH_H */
13690 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/tag_cmd.h linux-3.9.4-vs2.3.6.3/include/uapi/vserver/tag_cmd.h
13691 --- linux-3.9.4/include/uapi/vserver/tag_cmd.h  1970-01-01 00:00:00.000000000 +0000
13692 +++ linux-3.9.4-vs2.3.6.3/include/uapi/vserver/tag_cmd.h        2013-05-31 14:47:11.000000000 +0000
13693 @@ -0,0 +1,14 @@
13694 +#ifndef _UAPI_VS_TAG_CMD_H
13695 +#define _UAPI_VS_TAG_CMD_H
13696 +
13697 +
13698 +/* vinfo commands */
13699 +
13700 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
13701 +
13702 +
13703 +/* context commands */
13704 +
13705 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
13706 +
13707 +#endif /* _UAPI_VS_TAG_CMD_H */
13708 diff -NurpP --minimal linux-3.9.4/init/Kconfig linux-3.9.4-vs2.3.6.3/init/Kconfig
13709 --- linux-3.9.4/init/Kconfig    2013-05-31 13:45:29.000000000 +0000
13710 +++ linux-3.9.4-vs2.3.6.3/init/Kconfig  2013-05-31 14:47:11.000000000 +0000
13711 @@ -760,6 +760,7 @@ config NUMA_BALANCING
13712  menuconfig CGROUPS
13713         boolean "Control Group support"
13714         depends on EVENTFD
13715 +       default y
13716         help
13717           This option adds support for grouping sets of processes together, for
13718           use with process control subsystems such as Cpusets, CFS, memory
13719 @@ -1022,6 +1023,7 @@ config IPC_NS
13720  config USER_NS
13721         bool "User namespace"
13722         depends on UIDGID_CONVERTED
13723 +       depends on VSERVER_DISABLED
13724         select UIDGID_STRICT_TYPE_CHECKS
13725  
13726         default n
13727 diff -NurpP --minimal linux-3.9.4/init/main.c linux-3.9.4-vs2.3.6.3/init/main.c
13728 --- linux-3.9.4/init/main.c     2013-05-31 13:45:29.000000000 +0000
13729 +++ linux-3.9.4-vs2.3.6.3/init/main.c   2013-05-31 15:09:17.000000000 +0000
13730 @@ -72,6 +72,7 @@
13731  #include <linux/ptrace.h>
13732  #include <linux/blkdev.h>
13733  #include <linux/elevator.h>
13734 +#include <linux/vserver/percpu.h>
13735  
13736  #include <asm/io.h>
13737  #include <asm/bugs.h>
13738 diff -NurpP --minimal linux-3.9.4/ipc/mqueue.c linux-3.9.4-vs2.3.6.3/ipc/mqueue.c
13739 --- linux-3.9.4/ipc/mqueue.c    2013-05-31 13:45:29.000000000 +0000
13740 +++ linux-3.9.4-vs2.3.6.3/ipc/mqueue.c  2013-05-31 14:47:11.000000000 +0000
13741 @@ -35,6 +35,8 @@
13742  #include <linux/ipc_namespace.h>
13743  #include <linux/user_namespace.h>
13744  #include <linux/slab.h>
13745 +#include <linux/vs_context.h>
13746 +#include <linux/vs_limit.h>
13747  
13748  #include <net/sock.h>
13749  #include "util.h"
13750 @@ -76,6 +78,7 @@ struct mqueue_inode_info {
13751         struct pid* notify_owner;
13752         struct user_namespace *notify_user_ns;
13753         struct user_struct *user;       /* user who created, for accounting */
13754 +       struct vx_info *vxi;
13755         struct sock *notify_sock;
13756         struct sk_buff *notify_cookie;
13757  
13758 @@ -234,6 +237,7 @@ static struct inode *mqueue_get_inode(st
13759         if (S_ISREG(mode)) {
13760                 struct mqueue_inode_info *info;
13761                 unsigned long mq_bytes, mq_treesize;
13762 +               struct vx_info *vxi = current_vx_info();
13763  
13764                 inode->i_fop = &mqueue_file_operations;
13765                 inode->i_size = FILENT_SIZE;
13766 @@ -247,6 +251,7 @@ static struct inode *mqueue_get_inode(st
13767                 info->notify_user_ns = NULL;
13768                 info->qsize = 0;
13769                 info->user = NULL;      /* set when all is ok */
13770 +               info->vxi = NULL;
13771                 info->msg_tree = RB_ROOT;
13772                 info->node_cache = NULL;
13773                 memset(&info->attr, 0, sizeof(info->attr));
13774 @@ -280,17 +285,20 @@ static struct inode *mqueue_get_inode(st
13775  
13776                 spin_lock(&mq_lock);
13777                 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
13778 -                   u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
13779 +                   u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE) ||
13780 +                   !vx_ipcmsg_avail(vxi, mq_bytes)) {
13781                         spin_unlock(&mq_lock);
13782                         /* mqueue_evict_inode() releases info->messages */
13783                         ret = -EMFILE;
13784                         goto out_inode;
13785                 }
13786                 u->mq_bytes += mq_bytes;
13787 +               vx_ipcmsg_add(vxi, u, mq_bytes);
13788                 spin_unlock(&mq_lock);
13789  
13790                 /* all is ok */
13791                 info->user = get_uid(u);
13792 +               info->vxi = get_vx_info(vxi);
13793         } else if (S_ISDIR(mode)) {
13794                 inc_nlink(inode);
13795                 /* Some things misbehave if size == 0 on a directory */
13796 @@ -402,8 +410,11 @@ static void mqueue_evict_inode(struct in
13797  
13798         user = info->user;
13799         if (user) {
13800 +               struct vx_info *vxi = info->vxi;
13801 +
13802                 spin_lock(&mq_lock);
13803                 user->mq_bytes -= mq_bytes;
13804 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
13805                 /*
13806                  * get_ns_from_inode() ensures that the
13807                  * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
13808 @@ -413,6 +424,7 @@ static void mqueue_evict_inode(struct in
13809                 if (ipc_ns)
13810                         ipc_ns->mq_queues_count--;
13811                 spin_unlock(&mq_lock);
13812 +               put_vx_info(vxi);
13813                 free_uid(user);
13814         }
13815         if (ipc_ns)
13816 diff -NurpP --minimal linux-3.9.4/ipc/msg.c linux-3.9.4-vs2.3.6.3/ipc/msg.c
13817 --- linux-3.9.4/ipc/msg.c       2013-05-31 13:45:29.000000000 +0000
13818 +++ linux-3.9.4-vs2.3.6.3/ipc/msg.c     2013-05-31 14:47:11.000000000 +0000
13819 @@ -37,6 +37,7 @@
13820  #include <linux/rwsem.h>
13821  #include <linux/nsproxy.h>
13822  #include <linux/ipc_namespace.h>
13823 +#include <linux/vs_base.h>
13824  
13825  #include <asm/current.h>
13826  #include <asm/uaccess.h>
13827 @@ -190,6 +191,7 @@ static int newque(struct ipc_namespace *
13828  
13829         msq->q_perm.mode = msgflg & S_IRWXUGO;
13830         msq->q_perm.key = key;
13831 +       msq->q_perm.xid = vx_current_xid();
13832  
13833         msq->q_perm.security = NULL;
13834         retval = security_msg_queue_alloc(msq);
13835 diff -NurpP --minimal linux-3.9.4/ipc/sem.c linux-3.9.4-vs2.3.6.3/ipc/sem.c
13836 --- linux-3.9.4/ipc/sem.c       2012-12-11 03:30:57.000000000 +0000
13837 +++ linux-3.9.4-vs2.3.6.3/ipc/sem.c     2013-05-31 14:47:11.000000000 +0000
13838 @@ -86,6 +86,8 @@
13839  #include <linux/rwsem.h>
13840  #include <linux/nsproxy.h>
13841  #include <linux/ipc_namespace.h>
13842 +#include <linux/vs_base.h>
13843 +#include <linux/vs_limit.h>
13844  
13845  #include <asm/uaccess.h>
13846  #include "util.h"
13847 @@ -306,6 +308,7 @@ static int newary(struct ipc_namespace *
13848  
13849         sma->sem_perm.mode = (semflg & S_IRWXUGO);
13850         sma->sem_perm.key = key;
13851 +       sma->sem_perm.xid = vx_current_xid();
13852  
13853         sma->sem_perm.security = NULL;
13854         retval = security_sem_alloc(sma);
13855 @@ -321,6 +324,9 @@ static int newary(struct ipc_namespace *
13856                 return id;
13857         }
13858         ns->used_sems += nsems;
13859 +       /* FIXME: obsoleted? */
13860 +       vx_semary_inc(sma);
13861 +       vx_nsems_add(sma, nsems);
13862  
13863         sma->sem_base = (struct sem *) &sma[1];
13864  
13865 @@ -770,6 +776,9 @@ static void freeary(struct ipc_namespace
13866  
13867         wake_up_sem_queue_do(&tasks);
13868         ns->used_sems -= sma->sem_nsems;
13869 +       /* FIXME: obsoleted? */
13870 +       vx_nsems_sub(sma, sma->sem_nsems);
13871 +       vx_semary_dec(sma);
13872         security_sem_free(sma);
13873         ipc_rcu_putref(sma);
13874  }
13875 diff -NurpP --minimal linux-3.9.4/ipc/shm.c linux-3.9.4-vs2.3.6.3/ipc/shm.c
13876 --- linux-3.9.4/ipc/shm.c       2013-05-31 14:22:27.000000000 +0000
13877 +++ linux-3.9.4-vs2.3.6.3/ipc/shm.c     2013-05-31 14:47:11.000000000 +0000
13878 @@ -39,6 +39,8 @@
13879  #include <linux/nsproxy.h>
13880  #include <linux/mount.h>
13881  #include <linux/ipc_namespace.h>
13882 +#include <linux/vs_context.h>
13883 +#include <linux/vs_limit.h>
13884  
13885  #include <asm/uaccess.h>
13886  
13887 @@ -187,7 +189,12 @@ static void shm_open(struct vm_area_stru
13888   */
13889  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
13890  {
13891 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
13892 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
13893 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
13894 +
13895 +       vx_ipcshm_sub(vxi, shp, numpages);
13896 +       ns->shm_tot -= numpages;
13897 +
13898         shm_rmid(ns, shp);
13899         shm_unlock(shp);
13900         if (!is_file_hugepages(shp->shm_file))
13901 @@ -197,6 +204,7 @@ static void shm_destroy(struct ipc_names
13902                                                 shp->mlock_user);
13903         fput (shp->shm_file);
13904         security_shm_free(shp);
13905 +       put_vx_info(vxi);
13906         ipc_rcu_putref(shp);
13907  }
13908  
13909 @@ -474,11 +482,15 @@ static int newseg(struct ipc_namespace *
13910         if (ns->shm_tot + numpages > ns->shm_ctlall)
13911                 return -ENOSPC;
13912  
13913 +       if (!vx_ipcshm_avail(current_vx_info(), numpages))
13914 +               return -ENOSPC;
13915 +
13916         shp = ipc_rcu_alloc(sizeof(*shp));
13917         if (!shp)
13918                 return -ENOMEM;
13919  
13920         shp->shm_perm.key = key;
13921 +       shp->shm_perm.xid = vx_current_xid();
13922         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
13923         shp->mlock_user = NULL;
13924  
13925 @@ -544,6 +556,7 @@ static int newseg(struct ipc_namespace *
13926         ns->shm_tot += numpages;
13927         error = shp->shm_perm.id;
13928         shm_unlock(shp);
13929 +       vx_ipcshm_add(current_vx_info(), key, numpages);
13930         return error;
13931  
13932  no_id:
13933 diff -NurpP --minimal linux-3.9.4/kernel/Makefile linux-3.9.4-vs2.3.6.3/kernel/Makefile
13934 --- linux-3.9.4/kernel/Makefile 2013-05-31 14:22:27.000000000 +0000
13935 +++ linux-3.9.4-vs2.3.6.3/kernel/Makefile       2013-05-31 14:47:11.000000000 +0000
13936 @@ -24,6 +24,7 @@ endif
13937  
13938  obj-y += sched/
13939  obj-y += power/
13940 +obj-y += vserver/
13941  
13942  obj-$(CONFIG_CHECKPOINT_RESTORE) += kcmp.o
13943  obj-$(CONFIG_FREEZER) += freezer.o
13944 diff -NurpP --minimal linux-3.9.4/kernel/auditsc.c linux-3.9.4-vs2.3.6.3/kernel/auditsc.c
13945 --- linux-3.9.4/kernel/auditsc.c        2013-05-31 14:22:27.000000000 +0000
13946 +++ linux-3.9.4-vs2.3.6.3/kernel/auditsc.c      2013-05-31 14:47:11.000000000 +0000
13947 @@ -2315,7 +2315,7 @@ int audit_set_loginuid(kuid_t loginuid)
13948         if (audit_loginuid_set(task))
13949                 return -EPERM;
13950  #else /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
13951 -       if (!capable(CAP_AUDIT_CONTROL))
13952 +       if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
13953                 return -EPERM;
13954  #endif  /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
13955  
13956 diff -NurpP --minimal linux-3.9.4/kernel/capability.c linux-3.9.4-vs2.3.6.3/kernel/capability.c
13957 --- linux-3.9.4/kernel/capability.c     2013-05-31 13:45:29.000000000 +0000
13958 +++ linux-3.9.4-vs2.3.6.3/kernel/capability.c   2013-05-31 14:47:11.000000000 +0000
13959 @@ -15,6 +15,7 @@
13960  #include <linux/syscalls.h>
13961  #include <linux/pid_namespace.h>
13962  #include <linux/user_namespace.h>
13963 +#include <linux/vs_context.h>
13964  #include <asm/uaccess.h>
13965  
13966  /*
13967 @@ -116,6 +117,7 @@ static int cap_validate_magic(cap_user_h
13968         return 0;
13969  }
13970  
13971 +
13972  /*
13973   * The only thing that can change the capabilities of the current
13974   * process is the current process. As such, we can't be in this code
13975 @@ -349,6 +351,8 @@ bool has_ns_capability_noaudit(struct ta
13976         return (ret == 0);
13977  }
13978  
13979 +#include <linux/vserver/base.h>
13980 +
13981  /**
13982   * has_capability_noaudit - Does a task have a capability (unaudited) in the
13983   * initial user ns
13984 diff -NurpP --minimal linux-3.9.4/kernel/compat.c linux-3.9.4-vs2.3.6.3/kernel/compat.c
13985 --- linux-3.9.4/kernel/compat.c 2013-05-31 13:45:29.000000000 +0000
13986 +++ linux-3.9.4-vs2.3.6.3/kernel/compat.c       2013-05-31 14:47:11.000000000 +0000
13987 @@ -27,6 +27,7 @@
13988  #include <linux/times.h>
13989  #include <linux/ptrace.h>
13990  #include <linux/gfp.h>
13991 +#include <linux/vs_time.h>
13992  
13993  #include <asm/uaccess.h>
13994  
13995 @@ -1059,7 +1060,7 @@ asmlinkage long compat_sys_stime(compat_
13996         if (err)
13997                 return err;
13998  
13999 -       do_settimeofday(&tv);
14000 +       vx_settimeofday(&tv);
14001         return 0;
14002  }
14003  
14004 diff -NurpP --minimal linux-3.9.4/kernel/cred.c linux-3.9.4-vs2.3.6.3/kernel/cred.c
14005 --- linux-3.9.4/kernel/cred.c   2013-02-19 13:58:56.000000000 +0000
14006 +++ linux-3.9.4-vs2.3.6.3/kernel/cred.c 2013-05-31 14:47:11.000000000 +0000
14007 @@ -56,31 +56,6 @@ struct cred init_cred = {
14008         .group_info             = &init_groups,
14009  };
14010  
14011 -static inline void set_cred_subscribers(struct cred *cred, int n)
14012 -{
14013 -#ifdef CONFIG_DEBUG_CREDENTIALS
14014 -       atomic_set(&cred->subscribers, n);
14015 -#endif
14016 -}
14017 -
14018 -static inline int read_cred_subscribers(const struct cred *cred)
14019 -{
14020 -#ifdef CONFIG_DEBUG_CREDENTIALS
14021 -       return atomic_read(&cred->subscribers);
14022 -#else
14023 -       return 0;
14024 -#endif
14025 -}
14026 -
14027 -static inline void alter_cred_subscribers(const struct cred *_cred, int n)
14028 -{
14029 -#ifdef CONFIG_DEBUG_CREDENTIALS
14030 -       struct cred *cred = (struct cred *) _cred;
14031 -
14032 -       atomic_add(n, &cred->subscribers);
14033 -#endif
14034 -}
14035 -
14036  /*
14037   * The RCU callback to actually dispose of a set of credentials
14038   */
14039 @@ -232,21 +207,16 @@ error:
14040   *
14041   * Call commit_creds() or abort_creds() to clean up.
14042   */
14043 -struct cred *prepare_creds(void)
14044 +struct cred *__prepare_creds(const struct cred *old)
14045  {
14046 -       struct task_struct *task = current;
14047 -       const struct cred *old;
14048         struct cred *new;
14049  
14050 -       validate_process_creds();
14051 -
14052         new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
14053         if (!new)
14054                 return NULL;
14055  
14056         kdebug("prepare_creds() alloc %p", new);
14057  
14058 -       old = task->cred;
14059         memcpy(new, old, sizeof(struct cred));
14060  
14061         atomic_set(&new->usage, 1);
14062 @@ -275,6 +245,13 @@ error:
14063         abort_creds(new);
14064         return NULL;
14065  }
14066 +
14067 +struct cred *prepare_creds(void)
14068 +{
14069 +       validate_process_creds();
14070 +
14071 +       return __prepare_creds(current->cred);
14072 +}
14073  EXPORT_SYMBOL(prepare_creds);
14074  
14075  /*
14076 diff -NurpP --minimal linux-3.9.4/kernel/exit.c linux-3.9.4-vs2.3.6.3/kernel/exit.c
14077 --- linux-3.9.4/kernel/exit.c   2013-05-31 13:45:29.000000000 +0000
14078 +++ linux-3.9.4-vs2.3.6.3/kernel/exit.c 2013-05-31 14:47:11.000000000 +0000
14079 @@ -48,6 +48,10 @@
14080  #include <linux/fs_struct.h>
14081  #include <linux/init_task.h>
14082  #include <linux/perf_event.h>
14083 +#include <linux/vs_limit.h>
14084 +#include <linux/vs_context.h>
14085 +#include <linux/vs_network.h>
14086 +#include <linux/vs_pid.h>
14087  #include <trace/events/sched.h>
14088  #include <linux/hw_breakpoint.h>
14089  #include <linux/oom.h>
14090 @@ -514,15 +518,25 @@ static struct task_struct *find_new_reap
14091         __acquires(&tasklist_lock)
14092  {
14093         struct pid_namespace *pid_ns = task_active_pid_ns(father);
14094 -       struct task_struct *thread;
14095 +       struct vx_info *vxi = task_get_vx_info(father);
14096 +       struct task_struct *thread = father;
14097 +       struct task_struct *reaper;
14098  
14099 -       thread = father;
14100         while_each_thread(father, thread) {
14101                 if (thread->flags & PF_EXITING)
14102                         continue;
14103                 if (unlikely(pid_ns->child_reaper == father))
14104                         pid_ns->child_reaper = thread;
14105 -               return thread;
14106 +               reaper = thread;
14107 +               goto out_put;
14108 +       }
14109 +
14110 +       reaper = pid_ns->child_reaper;
14111 +       if (vxi) {
14112 +               BUG_ON(!vxi->vx_reaper);
14113 +               if (vxi->vx_reaper != init_pid_ns.child_reaper &&
14114 +                   vxi->vx_reaper != father)
14115 +                       reaper = vxi->vx_reaper;
14116         }
14117  
14118         if (unlikely(pid_ns->child_reaper == father)) {
14119 @@ -560,7 +574,9 @@ static struct task_struct *find_new_reap
14120                 }
14121         }
14122  
14123 -       return pid_ns->child_reaper;
14124 +out_put:
14125 +       put_vx_info(vxi);
14126 +       return reaper;
14127  }
14128  
14129  /*
14130 @@ -611,10 +627,15 @@ static void forget_original_parent(struc
14131         list_for_each_entry_safe(p, n, &father->children, sibling) {
14132                 struct task_struct *t = p;
14133                 do {
14134 -                       t->real_parent = reaper;
14135 +                       struct task_struct *new_parent = reaper;
14136 +
14137 +                       if (unlikely(p == reaper))
14138 +                               new_parent = task_active_pid_ns(p)->child_reaper;
14139 +
14140 +                       t->real_parent = new_parent;
14141                         if (t->parent == father) {
14142                                 BUG_ON(t->ptrace);
14143 -                               t->parent = t->real_parent;
14144 +                               t->parent = new_parent;
14145                         }
14146                         if (t->pdeath_signal)
14147                                 group_send_sig_info(t->pdeath_signal,
14148 @@ -821,6 +842,9 @@ void do_exit(long code)
14149          */
14150         ptrace_put_breakpoints(tsk);
14151  
14152 +       /* needs to stay before exit_notify() */
14153 +       exit_vx_info_early(tsk, code);
14154 +
14155         exit_notify(tsk, group_dead);
14156  #ifdef CONFIG_NUMA
14157         task_lock(tsk);
14158 @@ -874,10 +898,15 @@ void do_exit(long code)
14159         smp_mb();
14160         raw_spin_unlock_wait(&tsk->pi_lock);
14161  
14162 +       /* needs to stay after exit_notify() */
14163 +       exit_vx_info(tsk, code);
14164 +       exit_nx_info(tsk);
14165 +
14166         /* causes final put_task_struct in finish_task_switch(). */
14167         tsk->state = TASK_DEAD;
14168         tsk->flags |= PF_NOFREEZE;      /* tell freezer to ignore us */
14169         schedule();
14170 +       printk("bad task: %p [%lx]\n", current, current->state);
14171         BUG();
14172         /* Avoid "noreturn function does return".  */
14173         for (;;)
14174 diff -NurpP --minimal linux-3.9.4/kernel/fork.c linux-3.9.4-vs2.3.6.3/kernel/fork.c
14175 --- linux-3.9.4/kernel/fork.c   2013-05-31 13:45:29.000000000 +0000
14176 +++ linux-3.9.4-vs2.3.6.3/kernel/fork.c 2013-05-31 14:47:11.000000000 +0000
14177 @@ -70,6 +70,9 @@
14178  #include <linux/khugepaged.h>
14179  #include <linux/signalfd.h>
14180  #include <linux/uprobes.h>
14181 +#include <linux/vs_context.h>
14182 +#include <linux/vs_network.h>
14183 +#include <linux/vs_limit.h>
14184  
14185  #include <asm/pgtable.h>
14186  #include <asm/pgalloc.h>
14187 @@ -210,6 +213,8 @@ void free_task(struct task_struct *tsk)
14188         arch_release_thread_info(tsk->stack);
14189         free_thread_info(tsk->stack);
14190         rt_mutex_debug_task_free(tsk);
14191 +       clr_vx_info(&tsk->vx_info);
14192 +       clr_nx_info(&tsk->nx_info);
14193         ftrace_graph_exit_task(tsk);
14194         put_seccomp_filter(tsk);
14195         arch_release_task_struct(tsk);
14196 @@ -547,6 +552,7 @@ static struct mm_struct *mm_init(struct
14197         if (likely(!mm_alloc_pgd(mm))) {
14198                 mm->def_flags = 0;
14199                 mmu_notifier_mm_init(mm);
14200 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
14201                 return mm;
14202         }
14203  
14204 @@ -599,6 +605,7 @@ void __mmdrop(struct mm_struct *mm)
14205         destroy_context(mm);
14206         mmu_notifier_mm_destroy(mm);
14207         check_mm(mm);
14208 +       clr_vx_info(&mm->mm_vx_info);
14209         free_mm(mm);
14210  }
14211  EXPORT_SYMBOL_GPL(__mmdrop);
14212 @@ -818,6 +825,7 @@ struct mm_struct *dup_mm(struct task_str
14213                 goto fail_nomem;
14214  
14215         memcpy(mm, oldmm, sizeof(*mm));
14216 +       mm->mm_vx_info = NULL;
14217         mm_init_cpumask(mm);
14218  
14219  #ifdef CONFIG_TRANSPARENT_HUGEPAGE
14220 @@ -859,6 +867,7 @@ fail_nocontext:
14221          * If init_new_context() failed, we cannot use mmput() to free the mm
14222          * because it calls destroy_context()
14223          */
14224 +       clr_vx_info(&mm->mm_vx_info);
14225         mm_free_pgd(mm);
14226         free_mm(mm);
14227         return NULL;
14228 @@ -1137,6 +1146,8 @@ static struct task_struct *copy_process(
14229  {
14230         int retval;
14231         struct task_struct *p;
14232 +       struct vx_info *vxi;
14233 +       struct nx_info *nxi;
14234  
14235         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
14236                 return ERR_PTR(-EINVAL);
14237 @@ -1195,7 +1206,12 @@ static struct task_struct *copy_process(
14238         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
14239         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
14240  #endif
14241 +       init_vx_info(&p->vx_info, current_vx_info());
14242 +       init_nx_info(&p->nx_info, current_nx_info());
14243 +
14244         retval = -EAGAIN;
14245 +       if (!vx_nproc_avail(1))
14246 +               goto bad_fork_free;
14247         if (atomic_read(&p->real_cred->user->processes) >=
14248                         task_rlimit(p, RLIMIT_NPROC)) {
14249                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
14250 @@ -1472,6 +1488,18 @@ static struct task_struct *copy_process(
14251  
14252         total_forks++;
14253         spin_unlock(&current->sighand->siglock);
14254 +
14255 +       /* p is copy of current */
14256 +       vxi = p->vx_info;
14257 +       if (vxi) {
14258 +               claim_vx_info(vxi, p);
14259 +               atomic_inc(&vxi->cvirt.nr_threads);
14260 +               atomic_inc(&vxi->cvirt.total_forks);
14261 +               vx_nproc_inc(p);
14262 +       }
14263 +       nxi = p->nx_info;
14264 +       if (nxi)
14265 +               claim_nx_info(nxi, p);
14266         write_unlock_irq(&tasklist_lock);
14267         proc_fork_connector(p);
14268         cgroup_post_fork(p);
14269 diff -NurpP --minimal linux-3.9.4/kernel/kthread.c linux-3.9.4-vs2.3.6.3/kernel/kthread.c
14270 --- linux-3.9.4/kernel/kthread.c        2013-05-31 13:45:30.000000000 +0000
14271 +++ linux-3.9.4-vs2.3.6.3/kernel/kthread.c      2013-05-31 14:47:11.000000000 +0000
14272 @@ -17,6 +17,7 @@
14273  #include <linux/slab.h>
14274  #include <linux/freezer.h>
14275  #include <linux/ptrace.h>
14276 +#include <linux/vs_pid.h>
14277  #include <trace/events/sched.h>
14278  
14279  static DEFINE_SPINLOCK(kthread_create_lock);
14280 diff -NurpP --minimal linux-3.9.4/kernel/nsproxy.c linux-3.9.4-vs2.3.6.3/kernel/nsproxy.c
14281 --- linux-3.9.4/kernel/nsproxy.c        2013-05-31 13:45:30.000000000 +0000
14282 +++ linux-3.9.4-vs2.3.6.3/kernel/nsproxy.c      2013-05-31 19:28:43.000000000 +0000
14283 @@ -20,11 +20,14 @@
14284  #include <linux/mnt_namespace.h>
14285  #include <linux/utsname.h>
14286  #include <linux/pid_namespace.h>
14287 +#include <linux/vserver/global.h>
14288 +#include <linux/vserver/debug.h>
14289  #include <net/net_namespace.h>
14290  #include <linux/ipc_namespace.h>
14291  #include <linux/proc_fs.h>
14292  #include <linux/file.h>
14293  #include <linux/syscalls.h>
14294 +#include "../fs/mount.h"
14295  
14296  static struct kmem_cache *nsproxy_cachep;
14297  
14298 @@ -46,8 +49,11 @@ static inline struct nsproxy *create_nsp
14299         struct nsproxy *nsproxy;
14300  
14301         nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
14302 -       if (nsproxy)
14303 +       if (nsproxy) {
14304                 atomic_set(&nsproxy->count, 1);
14305 +               atomic_inc(&vs_global_nsproxy);
14306 +       }
14307 +       vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
14308         return nsproxy;
14309  }
14310  
14311 @@ -56,9 +62,12 @@ static inline struct nsproxy *create_nsp
14312   * Return the newly created nsproxy.  Do not attach this to the task,
14313   * leave it to the caller to do proper locking and attach it to task.
14314   */
14315 -static struct nsproxy *create_new_namespaces(unsigned long flags,
14316 -       struct task_struct *tsk, struct user_namespace *user_ns,
14317 -       struct fs_struct *new_fs)
14318 +static struct nsproxy *unshare_namespaces(
14319 +       unsigned long flags,
14320 +       struct nsproxy *orig,
14321 +       struct fs_struct *new_fs,
14322 +       struct user_namespace *new_user,
14323 +       struct pid_namespace *new_pid)
14324  {
14325         struct nsproxy *new_nsp;
14326         int err;
14327 @@ -67,31 +76,31 @@ static struct nsproxy *create_new_namesp
14328         if (!new_nsp)
14329                 return ERR_PTR(-ENOMEM);
14330  
14331 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, user_ns, new_fs);
14332 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_user, new_fs);
14333         if (IS_ERR(new_nsp->mnt_ns)) {
14334                 err = PTR_ERR(new_nsp->mnt_ns);
14335                 goto out_ns;
14336         }
14337  
14338 -       new_nsp->uts_ns = copy_utsname(flags, user_ns, tsk->nsproxy->uts_ns);
14339 +       new_nsp->uts_ns = copy_utsname(flags, new_user, orig->uts_ns);
14340         if (IS_ERR(new_nsp->uts_ns)) {
14341                 err = PTR_ERR(new_nsp->uts_ns);
14342                 goto out_uts;
14343         }
14344  
14345 -       new_nsp->ipc_ns = copy_ipcs(flags, user_ns, tsk->nsproxy->ipc_ns);
14346 +       new_nsp->ipc_ns = copy_ipcs(flags, new_user, orig->ipc_ns);
14347         if (IS_ERR(new_nsp->ipc_ns)) {
14348                 err = PTR_ERR(new_nsp->ipc_ns);
14349                 goto out_ipc;
14350         }
14351  
14352 -       new_nsp->pid_ns = copy_pid_ns(flags, user_ns, tsk->nsproxy->pid_ns);
14353 +       new_nsp->pid_ns = copy_pid_ns(flags, new_user, new_pid);
14354         if (IS_ERR(new_nsp->pid_ns)) {
14355                 err = PTR_ERR(new_nsp->pid_ns);
14356                 goto out_pid;
14357         }
14358  
14359 -       new_nsp->net_ns = copy_net_ns(flags, user_ns, tsk->nsproxy->net_ns);
14360 +       new_nsp->net_ns = copy_net_ns(flags, new_user, orig->net_ns);
14361         if (IS_ERR(new_nsp->net_ns)) {
14362                 err = PTR_ERR(new_nsp->net_ns);
14363                 goto out_net;
14364 @@ -116,6 +125,41 @@ out_ns:
14365         return ERR_PTR(err);
14366  }
14367  
14368 +static struct nsproxy *create_new_namespaces(unsigned long flags,
14369 +       struct task_struct *tsk, struct user_namespace *user_ns,
14370 +       struct fs_struct *new_fs)
14371 +
14372 +{
14373 +       return unshare_namespaces(flags, tsk->nsproxy,
14374 +               new_fs, user_ns, task_active_pid_ns(tsk));
14375 +}
14376 +
14377 +/*
14378 + * copies the nsproxy, setting refcount to 1, and grabbing a
14379 + * reference to all contained namespaces.
14380 + */
14381 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
14382 +{
14383 +       struct nsproxy *ns = create_nsproxy();
14384 +
14385 +       if (ns) {
14386 +               memcpy(ns, orig, sizeof(struct nsproxy));
14387 +               atomic_set(&ns->count, 1);
14388 +
14389 +               if (ns->mnt_ns)
14390 +                       get_mnt_ns(ns->mnt_ns);
14391 +               if (ns->uts_ns)
14392 +                       get_uts_ns(ns->uts_ns);
14393 +               if (ns->ipc_ns)
14394 +                       get_ipc_ns(ns->ipc_ns);
14395 +               if (ns->pid_ns)
14396 +                       get_pid_ns(ns->pid_ns);
14397 +               if (ns->net_ns)
14398 +                       get_net(ns->net_ns);
14399 +       }
14400 +       return ns;
14401 +}
14402 +
14403  /*
14404   * called from clone.  This now handles copy for nsproxy and all
14405   * namespaces therein.
14406 @@ -124,9 +168,12 @@ int copy_namespaces(unsigned long flags,
14407  {
14408         struct nsproxy *old_ns = tsk->nsproxy;
14409         struct user_namespace *user_ns = task_cred_xxx(tsk, user_ns);
14410 -       struct nsproxy *new_ns;
14411 +       struct nsproxy *new_ns = NULL;
14412         int err = 0;
14413  
14414 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
14415 +               flags, tsk, old_ns);
14416 +
14417         if (!old_ns)
14418                 return 0;
14419  
14420 @@ -136,7 +183,7 @@ int copy_namespaces(unsigned long flags,
14421                                 CLONE_NEWPID | CLONE_NEWNET)))
14422                 return 0;
14423  
14424 -       if (!ns_capable(user_ns, CAP_SYS_ADMIN)) {
14425 +       if (!vx_ns_can_unshare(user_ns, CAP_SYS_ADMIN, flags)) {
14426                 err = -EPERM;
14427                 goto out;
14428         }
14429 @@ -163,6 +210,9 @@ int copy_namespaces(unsigned long flags,
14430  
14431  out:
14432         put_nsproxy(old_ns);
14433 +       vxdprintk(VXD_CBIT(space, 3),
14434 +               "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
14435 +               flags, tsk, old_ns, err, new_ns);
14436         return err;
14437  }
14438  
14439 @@ -176,7 +226,9 @@ void free_nsproxy(struct nsproxy *ns)
14440                 put_ipc_ns(ns->ipc_ns);
14441         if (ns->pid_ns)
14442                 put_pid_ns(ns->pid_ns);
14443 -       put_net(ns->net_ns);
14444 +       if (ns->net_ns)
14445 +               put_net(ns->net_ns);
14446 +       atomic_dec(&vs_global_nsproxy);
14447         kmem_cache_free(nsproxy_cachep, ns);
14448  }
14449  
14450 @@ -190,12 +242,16 @@ int unshare_nsproxy_namespaces(unsigned
14451         struct user_namespace *user_ns;
14452         int err = 0;
14453  
14454 +       vxdprintk(VXD_CBIT(space, 4),
14455 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
14456 +               unshare_flags, current->nsproxy);
14457 +
14458         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
14459                                CLONE_NEWNET | CLONE_NEWPID)))
14460                 return 0;
14461  
14462         user_ns = new_cred ? new_cred->user_ns : current_user_ns();
14463 -       if (!ns_capable(user_ns, CAP_SYS_ADMIN))
14464 +       if (!vx_ns_can_unshare(user_ns, CAP_SYS_ADMIN, unshare_flags))
14465                 return -EPERM;
14466  
14467         *new_nsp = create_new_namespaces(unshare_flags, current, user_ns,
14468 diff -NurpP --minimal linux-3.9.4/kernel/pid.c linux-3.9.4-vs2.3.6.3/kernel/pid.c
14469 --- linux-3.9.4/kernel/pid.c    2013-05-31 13:45:30.000000000 +0000
14470 +++ linux-3.9.4-vs2.3.6.3/kernel/pid.c  2013-05-31 15:24:34.000000000 +0000
14471 @@ -37,6 +37,7 @@
14472  #include <linux/init_task.h>
14473  #include <linux/syscalls.h>
14474  #include <linux/proc_fs.h>
14475 +#include <linux/vs_pid.h>
14476  
14477  #define pid_hashfn(nr, ns)     \
14478         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
14479 @@ -364,7 +365,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
14480  
14481  struct pid *find_vpid(int nr)
14482  {
14483 -       return find_pid_ns(nr, task_active_pid_ns(current));
14484 +       return find_pid_ns(vx_rmap_pid(nr), task_active_pid_ns(current));
14485  }
14486  EXPORT_SYMBOL_GPL(find_vpid);
14487  
14488 @@ -424,6 +425,9 @@ void transfer_pid(struct task_struct *ol
14489  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
14490  {
14491         struct task_struct *result = NULL;
14492 +
14493 +       if (type == PIDTYPE_REALPID)
14494 +               type = PIDTYPE_PID;
14495         if (pid) {
14496                 struct hlist_node *first;
14497                 first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]),
14498 @@ -443,7 +447,7 @@ struct task_struct *find_task_by_pid_ns(
14499         rcu_lockdep_assert(rcu_read_lock_held(),
14500                            "find_task_by_pid_ns() needs rcu_read_lock()"
14501                            " protection");
14502 -       return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
14503 +       return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
14504  }
14505  
14506  struct task_struct *find_task_by_vpid(pid_t vnr)
14507 @@ -487,7 +491,7 @@ struct pid *find_get_pid(pid_t nr)
14508  }
14509  EXPORT_SYMBOL_GPL(find_get_pid);
14510  
14511 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
14512 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
14513  {
14514         struct upid *upid;
14515         pid_t nr = 0;
14516 @@ -501,6 +505,11 @@ pid_t pid_nr_ns(struct pid *pid, struct
14517  }
14518  EXPORT_SYMBOL_GPL(pid_nr_ns);
14519  
14520 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
14521 +{
14522 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
14523 +}
14524 +
14525  pid_t pid_vnr(struct pid *pid)
14526  {
14527         return pid_nr_ns(pid, task_active_pid_ns(current));
14528 diff -NurpP --minimal linux-3.9.4/kernel/pid_namespace.c linux-3.9.4-vs2.3.6.3/kernel/pid_namespace.c
14529 --- linux-3.9.4/kernel/pid_namespace.c  2013-05-31 13:45:30.000000000 +0000
14530 +++ linux-3.9.4-vs2.3.6.3/kernel/pid_namespace.c        2013-05-31 17:59:48.000000000 +0000
14531 @@ -18,6 +18,7 @@
14532  #include <linux/proc_fs.h>
14533  #include <linux/reboot.h>
14534  #include <linux/export.h>
14535 +#include <linux/vserver/global.h>
14536  
14537  #define BITS_PER_PAGE          (PAGE_SIZE*8)
14538  
14539 @@ -112,6 +113,7 @@ static struct pid_namespace *create_pid_
14540                 goto out_free_map;
14541  
14542         kref_init(&ns->kref);
14543 +       atomic_inc(&vs_global_pid_ns);
14544         ns->level = level;
14545         ns->parent = get_pid_ns(parent_pid_ns);
14546         ns->user_ns = get_user_ns(user_ns);
14547 @@ -142,6 +144,7 @@ static void destroy_pid_namespace(struct
14548         for (i = 0; i < PIDMAP_ENTRIES; i++)
14549                 kfree(ns->pidmap[i].page);
14550         put_user_ns(ns->user_ns);
14551 +       atomic_dec(&vs_global_pid_ns);
14552         kmem_cache_free(pid_ns_cachep, ns);
14553  }
14554  
14555 diff -NurpP --minimal linux-3.9.4/kernel/posix-timers.c linux-3.9.4-vs2.3.6.3/kernel/posix-timers.c
14556 --- linux-3.9.4/kernel/posix-timers.c   2013-05-31 13:45:30.000000000 +0000
14557 +++ linux-3.9.4-vs2.3.6.3/kernel/posix-timers.c 2013-05-31 14:47:11.000000000 +0000
14558 @@ -47,6 +47,7 @@
14559  #include <linux/wait.h>
14560  #include <linux/workqueue.h>
14561  #include <linux/export.h>
14562 +#include <linux/vs_context.h>
14563  
14564  /*
14565   * Management arrays for POSIX timers.  Timers are kept in slab memory
14566 @@ -340,6 +341,7 @@ int posix_timer_event(struct k_itimer *t
14567  {
14568         struct task_struct *task;
14569         int shared, ret = -1;
14570 +
14571         /*
14572          * FIXME: if ->sigq is queued we can race with
14573          * dequeue_signal()->do_schedule_next_timer().
14574 @@ -356,10 +358,18 @@ int posix_timer_event(struct k_itimer *t
14575         rcu_read_lock();
14576         task = pid_task(timr->it_pid, PIDTYPE_PID);
14577         if (task) {
14578 +               struct vx_info_save vxis;
14579 +               struct vx_info *vxi;
14580 +
14581 +               vxi = get_vx_info(task->vx_info);
14582 +               enter_vx_info(vxi, &vxis);
14583                 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
14584                 ret = send_sigqueue(timr->sigq, task, shared);
14585 +               leave_vx_info(&vxis);
14586 +               put_vx_info(vxi);
14587         }
14588         rcu_read_unlock();
14589 +
14590         /* If we failed to send the signal the timer stops. */
14591         return ret > 0;
14592  }
14593 diff -NurpP --minimal linux-3.9.4/kernel/printk.c linux-3.9.4-vs2.3.6.3/kernel/printk.c
14594 --- linux-3.9.4/kernel/printk.c 2013-05-31 13:45:30.000000000 +0000
14595 +++ linux-3.9.4-vs2.3.6.3/kernel/printk.c       2013-05-31 15:23:35.000000000 +0000
14596 @@ -43,6 +43,7 @@
14597  #include <linux/rculist.h>
14598  #include <linux/poll.h>
14599  #include <linux/irq_work.h>
14600 +#include <linux/vs_cvirt.h>
14601  
14602  #include <asm/uaccess.h>
14603  
14604 @@ -841,7 +842,7 @@ static int check_syslog_permissions(int
14605                 return 0;
14606  
14607         if (syslog_action_restricted(type)) {
14608 -               if (capable(CAP_SYSLOG))
14609 +               if (vx_capable(CAP_SYSLOG, VXC_SYSLOG))
14610                         return 0;
14611                 /* For historical reasons, accept CAP_SYS_ADMIN too, with a warning */
14612                 if (capable(CAP_SYS_ADMIN)) {
14613 @@ -1135,12 +1136,9 @@ int do_syslog(int type, char __user *buf
14614         if (error)
14615                 return error;
14616  
14617 -       switch (type) {
14618 -       case SYSLOG_ACTION_CLOSE:       /* Close log */
14619 -               break;
14620 -       case SYSLOG_ACTION_OPEN:        /* Open log */
14621 -               break;
14622 -       case SYSLOG_ACTION_READ:        /* Read from log */
14623 +       if ((type == SYSLOG_ACTION_READ) ||
14624 +           (type == SYSLOG_ACTION_READ_ALL) ||
14625 +           (type == SYSLOG_ACTION_READ_CLEAR)) {
14626                 error = -EINVAL;
14627                 if (!buf || len < 0)
14628                         goto out;
14629 @@ -1151,6 +1149,16 @@ int do_syslog(int type, char __user *buf
14630                         error = -EFAULT;
14631                         goto out;
14632                 }
14633 +       }
14634 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
14635 +               return vx_do_syslog(type, buf, len);
14636 +
14637 +       switch (type) {
14638 +       case SYSLOG_ACTION_CLOSE:       /* Close log */
14639 +               break;
14640 +       case SYSLOG_ACTION_OPEN:        /* Open log */
14641 +               break;
14642 +       case SYSLOG_ACTION_READ:        /* Read from log */
14643                 error = wait_event_interruptible(log_wait,
14644                                                  syslog_seq != log_next_seq);
14645                 if (error)
14646 @@ -1163,16 +1171,6 @@ int do_syslog(int type, char __user *buf
14647                 /* FALL THRU */
14648         /* Read last kernel messages */
14649         case SYSLOG_ACTION_READ_ALL:
14650 -               error = -EINVAL;
14651 -               if (!buf || len < 0)
14652 -                       goto out;
14653 -               error = 0;
14654 -               if (!len)
14655 -                       goto out;
14656 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
14657 -                       error = -EFAULT;
14658 -                       goto out;
14659 -               }
14660                 error = syslog_print_all(buf, len, clear);
14661                 break;
14662         /* Clear ring buffer */
14663 diff -NurpP --minimal linux-3.9.4/kernel/ptrace.c linux-3.9.4-vs2.3.6.3/kernel/ptrace.c
14664 --- linux-3.9.4/kernel/ptrace.c 2013-05-31 13:45:30.000000000 +0000
14665 +++ linux-3.9.4-vs2.3.6.3/kernel/ptrace.c       2013-05-31 15:22:34.000000000 +0000
14666 @@ -22,6 +22,7 @@
14667  #include <linux/syscalls.h>
14668  #include <linux/uaccess.h>
14669  #include <linux/regset.h>
14670 +#include <linux/vs_context.h>
14671  #include <linux/hw_breakpoint.h>
14672  #include <linux/cn_proc.h>
14673  
14674 @@ -261,6 +262,11 @@ ok:
14675         }
14676         rcu_read_unlock();
14677  
14678 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_WATCH_P|VS_IDENT))
14679 +               return -EPERM;
14680 +       if (!vx_check(task->xid, VS_IDENT) &&
14681 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
14682 +               return -EACCES;
14683         return security_ptrace_access_check(task, mode);
14684  }
14685  
14686 diff -NurpP --minimal linux-3.9.4/kernel/sched/core.c linux-3.9.4-vs2.3.6.3/kernel/sched/core.c
14687 --- linux-3.9.4/kernel/sched/core.c     2013-05-31 13:45:30.000000000 +0000
14688 +++ linux-3.9.4-vs2.3.6.3/kernel/sched/core.c   2013-05-31 15:17:22.000000000 +0000
14689 @@ -73,6 +73,8 @@
14690  #include <linux/init_task.h>
14691  #include <linux/binfmts.h>
14692  #include <linux/context_tracking.h>
14693 +#include <linux/vs_sched.h>
14694 +#include <linux/vs_cvirt.h>
14695  
14696  #include <asm/switch_to.h>
14697  #include <asm/tlb.h>
14698 @@ -2091,9 +2093,17 @@ EXPORT_SYMBOL(avenrun); /* should be rem
14699   */
14700  void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
14701  {
14702 -       loads[0] = (avenrun[0] + offset) << shift;
14703 -       loads[1] = (avenrun[1] + offset) << shift;
14704 -       loads[2] = (avenrun[2] + offset) << shift;
14705 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
14706 +               struct vx_info *vxi = current_vx_info();
14707 +
14708 +               loads[0] = (vxi->cvirt.load[0] + offset) << shift;
14709 +               loads[1] = (vxi->cvirt.load[1] + offset) << shift;
14710 +               loads[2] = (vxi->cvirt.load[2] + offset) << shift;
14711 +       } else {
14712 +               loads[0] = (avenrun[0] + offset) << shift;
14713 +               loads[1] = (avenrun[1] + offset) << shift;
14714 +               loads[2] = (avenrun[2] + offset) << shift;
14715 +       }
14716  }
14717  
14718  static long calc_load_fold_active(struct rq *this_rq)
14719 @@ -3704,7 +3714,7 @@ SYSCALL_DEFINE1(nice, int, increment)
14720                 nice = 19;
14721  
14722         if (increment < 0 && !can_nice(current, nice))
14723 -               return -EPERM;
14724 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
14725  
14726         retval = security_task_setnice(current, nice);
14727         if (retval)
14728 diff -NurpP --minimal linux-3.9.4/kernel/sched/cputime.c linux-3.9.4-vs2.3.6.3/kernel/sched/cputime.c
14729 --- linux-3.9.4/kernel/sched/cputime.c  2013-05-31 14:22:27.000000000 +0000
14730 +++ linux-3.9.4-vs2.3.6.3/kernel/sched/cputime.c        2013-05-31 15:17:55.000000000 +0000
14731 @@ -4,6 +4,7 @@
14732  #include <linux/kernel_stat.h>
14733  #include <linux/static_key.h>
14734  #include <linux/context_tracking.h>
14735 +#include <linux/vs_sched.h>
14736  #include "sched.h"
14737  
14738  
14739 @@ -151,14 +152,17 @@ static inline void task_group_account_fi
14740  void account_user_time(struct task_struct *p, cputime_t cputime,
14741                        cputime_t cputime_scaled)
14742  {
14743 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
14744 +       int nice = (TASK_NICE(p) > 0);
14745         int index;
14746  
14747         /* Add user time to process. */
14748         p->utime += cputime;
14749         p->utimescaled += cputime_scaled;
14750 +       vx_account_user(vxi, cputime, nice);
14751         account_group_user_time(p, cputime);
14752  
14753 -       index = (TASK_NICE(p) > 0) ? CPUTIME_NICE : CPUTIME_USER;
14754 +       index = (nice) ? CPUTIME_NICE : CPUTIME_USER;
14755  
14756         /* Add user time to cpustat. */
14757         task_group_account_field(p, index, (__force u64) cputime);
14758 @@ -205,9 +209,12 @@ static inline
14759  void __account_system_time(struct task_struct *p, cputime_t cputime,
14760                         cputime_t cputime_scaled, int index)
14761  {
14762 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
14763 +
14764         /* Add system time to process. */
14765         p->stime += cputime;
14766         p->stimescaled += cputime_scaled;
14767 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
14768         account_group_system_time(p, cputime);
14769  
14770         /* Add system time to cpustat. */
14771 diff -NurpP --minimal linux-3.9.4/kernel/sched/fair.c linux-3.9.4-vs2.3.6.3/kernel/sched/fair.c
14772 --- linux-3.9.4/kernel/sched/fair.c     2013-05-31 13:45:30.000000000 +0000
14773 +++ linux-3.9.4-vs2.3.6.3/kernel/sched/fair.c   2013-05-31 15:19:37.000000000 +0000
14774 @@ -29,6 +29,7 @@
14775  #include <linux/mempolicy.h>
14776  #include <linux/migrate.h>
14777  #include <linux/task_work.h>
14778 +#include <linux/vs_cvirt.h>
14779  
14780  #include <trace/events/sched.h>
14781  
14782 @@ -1714,6 +1715,8 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
14783                 __enqueue_entity(cfs_rq, se);
14784         se->on_rq = 1;
14785  
14786 +       if (entity_is_task(se))
14787 +               vx_activate_task(task_of(se));
14788         if (cfs_rq->nr_running == 1) {
14789                 list_add_leaf_cfs_rq(cfs_rq);
14790                 check_enqueue_throttle(cfs_rq);
14791 @@ -1795,6 +1798,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
14792         if (se != cfs_rq->curr)
14793                 __dequeue_entity(cfs_rq, se);
14794         se->on_rq = 0;
14795 +       if (entity_is_task(se))
14796 +               vx_deactivate_task(task_of(se));
14797         account_entity_dequeue(cfs_rq, se);
14798  
14799         /*
14800 diff -NurpP --minimal linux-3.9.4/kernel/signal.c linux-3.9.4-vs2.3.6.3/kernel/signal.c
14801 --- linux-3.9.4/kernel/signal.c 2013-05-31 13:45:30.000000000 +0000
14802 +++ linux-3.9.4-vs2.3.6.3/kernel/signal.c       2013-05-31 15:20:05.000000000 +0000
14803 @@ -32,6 +32,8 @@
14804  #include <linux/user_namespace.h>
14805  #include <linux/uprobes.h>
14806  #include <linux/compat.h>
14807 +#include <linux/vs_context.h>
14808 +#include <linux/vs_pid.h>
14809  #define CREATE_TRACE_POINTS
14810  #include <trace/events/signal.h>
14811  
14812 @@ -789,9 +791,18 @@ static int check_kill_permission(int sig
14813         struct pid *sid;
14814         int error;
14815  
14816 +       vxdprintk(VXD_CBIT(misc, 7),
14817 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
14818 +               sig, info, t, vx_task_xid(t), t->pid);
14819 +
14820         if (!valid_signal(sig))
14821                 return -EINVAL;
14822  
14823 +/*     FIXME: needed? if so, why?
14824 +       if ((info != SEND_SIG_NOINFO) &&
14825 +               (is_si_special(info) || !si_fromuser(info)))
14826 +               goto skip;      */
14827 +
14828         if (!si_fromuser(info))
14829                 return 0;
14830  
14831 @@ -815,6 +826,20 @@ static int check_kill_permission(int sig
14832                 }
14833         }
14834  
14835 +       error = -EPERM;
14836 +       if (t->pid == 1 && current->xid)
14837 +               return error;
14838 +
14839 +       error = -ESRCH;
14840 +       /* FIXME: we shouldn't return ESRCH ever, to avoid
14841 +                 loops, maybe ENOENT or EACCES? */
14842 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
14843 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
14844 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
14845 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
14846 +               return error;
14847 +       }
14848 +/* skip: */
14849         return security_task_kill(t, info, sig, 0);
14850  }
14851  
14852 @@ -1351,7 +1376,7 @@ int kill_pid_info(int sig, struct siginf
14853         rcu_read_lock();
14854  retry:
14855         p = pid_task(pid, PIDTYPE_PID);
14856 -       if (p) {
14857 +       if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
14858                 error = group_send_sig_info(sig, info, p);
14859                 if (unlikely(error == -ESRCH))
14860                         /*
14861 @@ -1399,7 +1424,7 @@ int kill_pid_info_as_cred(int sig, struc
14862  
14863         rcu_read_lock();
14864         p = pid_task(pid, PIDTYPE_PID);
14865 -       if (!p) {
14866 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
14867                 ret = -ESRCH;
14868                 goto out_unlock;
14869         }
14870 @@ -1451,8 +1476,10 @@ static int kill_something_info(int sig,
14871                 struct task_struct * p;
14872  
14873                 for_each_process(p) {
14874 -                       if (task_pid_vnr(p) > 1 &&
14875 -                                       !same_thread_group(p, current)) {
14876 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
14877 +                               task_pid_vnr(p) > 1 &&
14878 +                               !same_thread_group(p, current) &&
14879 +                               !vx_current_initpid(p->pid)) {
14880                                 int err = group_send_sig_info(sig, info, p);
14881                                 ++count;
14882                                 if (err != -EPERM)
14883 @@ -2306,6 +2333,11 @@ relock:
14884                                 !sig_kernel_only(signr))
14885                         continue;
14886  
14887 +               /* virtual init is protected against user signals */
14888 +               if ((info->si_code == SI_USER) &&
14889 +                       vx_current_initpid(current->pid))
14890 +                       continue;
14891 +
14892                 if (sig_kernel_stop(signr)) {
14893                         /*
14894                          * The default action is to stop all threads in
14895 diff -NurpP --minimal linux-3.9.4/kernel/softirq.c linux-3.9.4-vs2.3.6.3/kernel/softirq.c
14896 --- linux-3.9.4/kernel/softirq.c        2013-05-31 13:45:30.000000000 +0000
14897 +++ linux-3.9.4-vs2.3.6.3/kernel/softirq.c      2013-05-31 14:47:11.000000000 +0000
14898 @@ -25,6 +25,7 @@
14899  #include <linux/smp.h>
14900  #include <linux/smpboot.h>
14901  #include <linux/tick.h>
14902 +#include <linux/vs_context.h>
14903  
14904  #define CREATE_TRACE_POINTS
14905  #include <trace/events/irq.h>
14906 diff -NurpP --minimal linux-3.9.4/kernel/sys.c linux-3.9.4-vs2.3.6.3/kernel/sys.c
14907 --- linux-3.9.4/kernel/sys.c    2013-05-31 13:45:30.000000000 +0000
14908 +++ linux-3.9.4-vs2.3.6.3/kernel/sys.c  2013-05-31 15:23:14.000000000 +0000
14909 @@ -50,6 +50,7 @@
14910  #include <linux/binfmts.h>
14911  
14912  #include <linux/kmsg_dump.h>
14913 +#include <linux/vs_pid.h>
14914  /* Move somewhere else to avoid recompiling? */
14915  #include <generated/utsrelease.h>
14916  
14917 @@ -155,7 +156,10 @@ static int set_one_prio(struct task_stru
14918                 goto out;
14919         }
14920         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
14921 -               error = -EACCES;
14922 +               if (vx_flags(VXF_IGNEG_NICE, 0))
14923 +                       error = 0;
14924 +               else
14925 +                       error = -EACCES;
14926                 goto out;
14927         }
14928         no_nice = security_task_setnice(p, niceval);
14929 @@ -206,6 +210,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
14930                         else
14931                                 pgrp = task_pgrp(current);
14932                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
14933 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
14934 +                                       continue;
14935                                 error = set_one_prio(p, niceval, error);
14936                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
14937                         break;
14938 @@ -271,6 +277,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
14939                         else
14940                                 pgrp = task_pgrp(current);
14941                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
14942 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
14943 +                                       continue;
14944                                 niceval = 20 - task_nice(p);
14945                                 if (niceval > retval)
14946                                         retval = niceval;
14947 @@ -424,6 +432,8 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
14948  
14949  static DEFINE_MUTEX(reboot_mutex);
14950  
14951 +long vs_reboot(unsigned int, void __user *);
14952 +
14953  /*
14954   * Reboot system call: for obvious reasons only root may call it,
14955   * and even root needs to set up some magic numbers in the registers
14956 @@ -466,6 +476,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
14957         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
14958                 cmd = LINUX_REBOOT_CMD_HALT;
14959  
14960 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
14961 +               return vs_reboot(cmd, arg);
14962 +
14963         mutex_lock(&reboot_mutex);
14964         switch (cmd) {
14965         case LINUX_REBOOT_CMD_RESTART:
14966 @@ -1373,7 +1386,8 @@ SYSCALL_DEFINE2(sethostname, char __user
14967         int errno;
14968         char tmp[__NEW_UTS_LEN];
14969  
14970 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
14971 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
14972 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
14973                 return -EPERM;
14974  
14975         if (len < 0 || len > __NEW_UTS_LEN)
14976 @@ -1424,7 +1438,8 @@ SYSCALL_DEFINE2(setdomainname, char __us
14977         int errno;
14978         char tmp[__NEW_UTS_LEN];
14979  
14980 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
14981 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
14982 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
14983                 return -EPERM;
14984         if (len < 0 || len > __NEW_UTS_LEN)
14985                 return -EINVAL;
14986 @@ -1543,7 +1558,7 @@ int do_prlimit(struct task_struct *tsk,
14987                 /* Keep the capable check against init_user_ns until
14988                    cgroups can contain all limits */
14989                 if (new_rlim->rlim_max > rlim->rlim_max &&
14990 -                               !capable(CAP_SYS_RESOURCE))
14991 +                       !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
14992                         retval = -EPERM;
14993                 if (!retval)
14994                         retval = security_task_setrlimit(tsk->group_leader,
14995 @@ -1596,7 +1611,8 @@ static int check_prlimit_permission(stru
14996             gid_eq(cred->gid, tcred->sgid) &&
14997             gid_eq(cred->gid, tcred->gid))
14998                 return 0;
14999 -       if (ns_capable(tcred->user_ns, CAP_SYS_RESOURCE))
15000 +       if (vx_ns_capable(tcred->user_ns,
15001 +               CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
15002                 return 0;
15003  
15004         return -EPERM;
15005 diff -NurpP --minimal linux-3.9.4/kernel/sysctl.c linux-3.9.4-vs2.3.6.3/kernel/sysctl.c
15006 --- linux-3.9.4/kernel/sysctl.c 2013-05-31 13:45:30.000000000 +0000
15007 +++ linux-3.9.4-vs2.3.6.3/kernel/sysctl.c       2013-05-31 15:28:39.000000000 +0000
15008 @@ -83,6 +83,7 @@
15009  #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
15010  #include <linux/lockdep.h>
15011  #endif
15012 +extern char vshelper_path[];
15013  #ifdef CONFIG_CHR_DEV_SG
15014  #include <scsi/sg.h>
15015  #endif
15016 @@ -629,6 +630,13 @@ static struct ctl_table kern_table[] = {
15017                 .mode           = 0644,
15018                 .proc_handler   = proc_dostring,
15019         },
15020 +       {
15021 +               .procname       = "vshelper",
15022 +               .data           = &vshelper_path,
15023 +               .maxlen         = 256,
15024 +               .mode           = 0644,
15025 +               .proc_handler   = &proc_dostring,
15026 +       },
15027  
15028  #ifdef CONFIG_CHR_DEV_SG
15029         {
15030 diff -NurpP --minimal linux-3.9.4/kernel/sysctl_binary.c linux-3.9.4-vs2.3.6.3/kernel/sysctl_binary.c
15031 --- linux-3.9.4/kernel/sysctl_binary.c  2013-05-31 13:45:30.000000000 +0000
15032 +++ linux-3.9.4-vs2.3.6.3/kernel/sysctl_binary.c        2013-05-31 14:47:11.000000000 +0000
15033 @@ -73,6 +73,7 @@ static const struct bin_table bin_kern_t
15034  
15035         { CTL_INT,      KERN_PANIC,                     "panic" },
15036         { CTL_INT,      KERN_REALROOTDEV,               "real-root-dev" },
15037 +       { CTL_STR,      KERN_VSHELPER,                  "vshelper" },
15038  
15039         { CTL_STR,      KERN_SPARC_REBOOT,              "reboot-cmd" },
15040         { CTL_INT,      KERN_CTLALTDEL,                 "ctrl-alt-del" },
15041 diff -NurpP --minimal linux-3.9.4/kernel/time/timekeeping.c linux-3.9.4-vs2.3.6.3/kernel/time/timekeeping.c
15042 --- linux-3.9.4/kernel/time/timekeeping.c       2013-05-31 13:45:30.000000000 +0000
15043 +++ linux-3.9.4-vs2.3.6.3/kernel/time/timekeeping.c     2013-05-31 15:24:55.000000000 +0000
15044 @@ -22,6 +22,7 @@
15045  #include <linux/tick.h>
15046  #include <linux/stop_machine.h>
15047  #include <linux/pvclock_gtod.h>
15048 +#include <linux/vs_time.h>
15049  
15050  
15051  static struct timekeeper timekeeper;
15052 @@ -594,6 +595,7 @@ void getrawmonotonic(struct timespec *ts
15053         } while (read_seqretry(&tk->lock, seq));
15054  
15055         timespec_add_ns(ts, nsecs);
15056 +       vx_adjust_timespec(ts);
15057  }
15058  EXPORT_SYMBOL(getrawmonotonic);
15059  
15060 diff -NurpP --minimal linux-3.9.4/kernel/time.c linux-3.9.4-vs2.3.6.3/kernel/time.c
15061 --- linux-3.9.4/kernel/time.c   2013-05-31 13:45:30.000000000 +0000
15062 +++ linux-3.9.4-vs2.3.6.3/kernel/time.c 2013-05-31 14:47:11.000000000 +0000
15063 @@ -37,6 +37,7 @@
15064  #include <linux/fs.h>
15065  #include <linux/math64.h>
15066  #include <linux/ptrace.h>
15067 +#include <linux/vs_time.h>
15068  
15069  #include <asm/uaccess.h>
15070  #include <asm/unistd.h>
15071 @@ -92,7 +93,7 @@ SYSCALL_DEFINE1(stime, time_t __user *,
15072         if (err)
15073                 return err;
15074  
15075 -       do_settimeofday(&tv);
15076 +       vx_settimeofday(&tv);
15077         return 0;
15078  }
15079  
15080 @@ -180,7 +181,7 @@ int do_sys_settimeofday(const struct tim
15081                 }
15082         }
15083         if (tv)
15084 -               return do_settimeofday(tv);
15085 +               return vx_settimeofday(tv);
15086         return 0;
15087  }
15088  
15089 diff -NurpP --minimal linux-3.9.4/kernel/timer.c linux-3.9.4-vs2.3.6.3/kernel/timer.c
15090 --- linux-3.9.4/kernel/timer.c  2013-05-31 14:22:27.000000000 +0000
15091 +++ linux-3.9.4-vs2.3.6.3/kernel/timer.c        2013-05-31 14:47:11.000000000 +0000
15092 @@ -41,6 +41,10 @@
15093  #include <linux/sched.h>
15094  #include <linux/sched/sysctl.h>
15095  #include <linux/slab.h>
15096 +#include <linux/vs_base.h>
15097 +#include <linux/vs_cvirt.h>
15098 +#include <linux/vs_pid.h>
15099 +#include <linux/vserver/sched.h>
15100  
15101  #include <asm/uaccess.h>
15102  #include <asm/unistd.h>
15103 diff -NurpP --minimal linux-3.9.4/kernel/user_namespace.c linux-3.9.4-vs2.3.6.3/kernel/user_namespace.c
15104 --- linux-3.9.4/kernel/user_namespace.c 2013-05-31 13:45:30.000000000 +0000
15105 +++ linux-3.9.4-vs2.3.6.3/kernel/user_namespace.c       2013-05-31 17:44:56.000000000 +0000
15106 @@ -22,6 +22,7 @@
15107  #include <linux/ctype.h>
15108  #include <linux/projid.h>
15109  #include <linux/fs_struct.h>
15110 +#include <linux/vserver/global.h>
15111  
15112  static struct kmem_cache *user_ns_cachep __read_mostly;
15113  
15114 @@ -91,6 +92,7 @@ int create_user_ns(struct cred *new)
15115  
15116         atomic_set(&ns->count, 1);
15117         /* Leave the new->user_ns reference with the new user namespace. */
15118 +       atomic_inc(&vs_global_user_ns);
15119         ns->parent = parent_ns;
15120         ns->owner = owner;
15121         ns->group = group;
15122 @@ -835,6 +837,8 @@ static void *userns_get(struct task_stru
15123  
15124  static void userns_put(void *ns)
15125  {
15126 +       /* FIXME: maybe move into destroyer? */
15127 +       atomic_dec(&vs_global_user_ns);
15128         put_user_ns(ns);
15129  }
15130  
15131 diff -NurpP --minimal linux-3.9.4/kernel/utsname.c linux-3.9.4-vs2.3.6.3/kernel/utsname.c
15132 --- linux-3.9.4/kernel/utsname.c        2013-05-31 13:45:30.000000000 +0000
15133 +++ linux-3.9.4-vs2.3.6.3/kernel/utsname.c      2013-05-31 15:15:55.000000000 +0000
15134 @@ -16,14 +16,17 @@
15135  #include <linux/slab.h>
15136  #include <linux/user_namespace.h>
15137  #include <linux/proc_fs.h>
15138 +#include <linux/vserver/global.h>
15139  
15140  static struct uts_namespace *create_uts_ns(void)
15141  {
15142         struct uts_namespace *uts_ns;
15143  
15144         uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
15145 -       if (uts_ns)
15146 +       if (uts_ns) {
15147                 kref_init(&uts_ns->kref);
15148 +               atomic_inc(&vs_global_uts_ns);
15149 +       }
15150         return uts_ns;
15151  }
15152  
15153 @@ -85,6 +88,7 @@ void free_uts_ns(struct kref *kref)
15154         ns = container_of(kref, struct uts_namespace, kref);
15155         put_user_ns(ns->user_ns);
15156         proc_free_inum(ns->proc_inum);
15157 +       atomic_dec(&vs_global_uts_ns);
15158         kfree(ns);
15159  }
15160  
15161 diff -NurpP --minimal linux-3.9.4/kernel/vserver/Kconfig linux-3.9.4-vs2.3.6.3/kernel/vserver/Kconfig
15162 --- linux-3.9.4/kernel/vserver/Kconfig  1970-01-01 00:00:00.000000000 +0000
15163 +++ linux-3.9.4-vs2.3.6.3/kernel/vserver/Kconfig        2013-05-31 14:47:11.000000000 +0000
15164 @@ -0,0 +1,233 @@
15165 +#
15166 +# Linux VServer configuration
15167 +#
15168 +
15169 +menu "Linux VServer"
15170 +
15171 +config VSERVER_AUTO_LBACK
15172 +       bool    "Automatically Assign Loopback IP"
15173 +       default y
15174 +       help
15175 +         Automatically assign a guest specific loopback
15176 +         IP and add it to the kernel network stack on
15177 +         startup.
15178 +
15179 +config VSERVER_AUTO_SINGLE
15180 +       bool    "Automatic Single IP Special Casing"
15181 +       depends on EXPERIMENTAL
15182 +       default y
15183 +       help
15184 +         This allows network contexts with a single IP to
15185 +         automatically remap 0.0.0.0 bindings to that IP,
15186 +         avoiding further network checks and improving
15187 +         performance.
15188 +
15189 +         (note: such guests do not allow to change the ip
15190 +          on the fly and do not show loopback addresses)
15191 +
15192 +config VSERVER_COWBL
15193 +       bool    "Enable COW Immutable Link Breaking"
15194 +       default y
15195 +       help
15196 +         This enables the COW (Copy-On-Write) link break code.
15197 +         It allows you to treat unified files like normal files
15198 +         when writing to them (which will implicitely break the
15199 +         link and create a copy of the unified file)
15200 +
15201 +config VSERVER_VTIME
15202 +       bool    "Enable Virtualized Guest Time"
15203 +       depends on EXPERIMENTAL
15204 +       default n
15205 +       help
15206 +         This enables per guest time offsets to allow for
15207 +         adjusting the system clock individually per guest.
15208 +         this adds some overhead to the time functions and
15209 +         therefore should not be enabled without good reason.
15210 +
15211 +config VSERVER_DEVICE
15212 +       bool    "Enable Guest Device Mapping"
15213 +       depends on EXPERIMENTAL
15214 +       default n
15215 +       help
15216 +         This enables generic device remapping.
15217 +
15218 +config VSERVER_PROC_SECURE
15219 +       bool    "Enable Proc Security"
15220 +       depends on PROC_FS
15221 +       default y
15222 +       help
15223 +         This configures ProcFS security to initially hide
15224 +         non-process entries for all contexts except the main and
15225 +         spectator context (i.e. for all guests), which is a secure
15226 +         default.
15227 +
15228 +         (note: on 1.2x the entries were visible by default)
15229 +
15230 +choice
15231 +       prompt  "Persistent Inode Tagging"
15232 +       default TAGGING_ID24
15233 +       help
15234 +         This adds persistent context information to filesystems
15235 +         mounted with the tagxid option. Tagging is a requirement
15236 +         for per-context disk limits and per-context quota.
15237 +
15238 +
15239 +config TAGGING_NONE
15240 +       bool    "Disabled"
15241 +       help
15242 +         do not store per-context information in inodes.
15243 +
15244 +config TAGGING_UID16
15245 +       bool    "UID16/GID32"
15246 +       help
15247 +         reduces UID to 16 bit, but leaves GID at 32 bit.
15248 +
15249 +config TAGGING_GID16
15250 +       bool    "UID32/GID16"
15251 +       help
15252 +         reduces GID to 16 bit, but leaves UID at 32 bit.
15253 +
15254 +config TAGGING_ID24
15255 +       bool    "UID24/GID24"
15256 +       help
15257 +         uses the upper 8bit from UID and GID for XID tagging
15258 +         which leaves 24bit for UID/GID each, which should be
15259 +         more than sufficient for normal use.
15260 +
15261 +config TAGGING_INTERN
15262 +       bool    "UID32/GID32"
15263 +       help
15264 +         this uses otherwise reserved inode fields in the on
15265 +         disk representation, which limits the use to a few
15266 +         filesystems (currently ext2 and ext3)
15267 +
15268 +endchoice
15269 +
15270 +config TAG_NFSD
15271 +       bool    "Tag NFSD User Auth and Files"
15272 +       default n
15273 +       help
15274 +         Enable this if you do want the in-kernel NFS
15275 +         Server to use the tagging specified above.
15276 +         (will require patched clients too)
15277 +
15278 +config VSERVER_PRIVACY
15279 +       bool    "Honor Privacy Aspects of Guests"
15280 +       default n
15281 +       help
15282 +         When enabled, most context checks will disallow
15283 +         access to structures assigned to a specific context,
15284 +         like ptys or loop devices.
15285 +
15286 +config VSERVER_CONTEXTS
15287 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
15288 +       range 1 65533
15289 +       default "768"   if 64BIT
15290 +       default "256"
15291 +       help
15292 +         This setting will optimize certain data structures
15293 +         and memory allocations according to the expected
15294 +         maximum.
15295 +
15296 +         note: this is not a strict upper limit.
15297 +
15298 +config VSERVER_WARN
15299 +       bool    "VServer Warnings"
15300 +       default y
15301 +       help
15302 +         This enables various runtime warnings, which will
15303 +         notify about potential manipulation attempts or
15304 +         resource shortage. It is generally considered to
15305 +         be a good idea to have that enabled.
15306 +
15307 +config VSERVER_WARN_DEVPTS
15308 +       bool    "VServer DevPTS Warnings"
15309 +       depends on VSERVER_WARN
15310 +       default y
15311 +       help
15312 +         This enables DevPTS related warnings, issued when a
15313 +         process inside a context tries to lookup or access
15314 +         a dynamic pts from the host or a different context.
15315 +
15316 +config VSERVER_DEBUG
15317 +       bool    "VServer Debugging Code"
15318 +       default n
15319 +       help
15320 +         Set this to yes if you want to be able to activate
15321 +         debugging output at runtime. It adds a very small
15322 +         overhead to all vserver related functions and
15323 +         increases the kernel size by about 20k.
15324 +
15325 +config VSERVER_HISTORY
15326 +       bool    "VServer History Tracing"
15327 +       depends on VSERVER_DEBUG
15328 +       default n
15329 +       help
15330 +         Set this to yes if you want to record the history of
15331 +         linux-vserver activities, so they can be replayed in
15332 +         the event of a kernel panic or oops.
15333 +
15334 +config VSERVER_HISTORY_SIZE
15335 +       int     "Per-CPU History Size (32-65536)"
15336 +       depends on VSERVER_HISTORY
15337 +       range 32 65536
15338 +       default 64
15339 +       help
15340 +         This allows you to specify the number of entries in
15341 +         the per-CPU history buffer.
15342 +
15343 +config VSERVER_EXTRA_MNT_CHECK
15344 +       bool    "Extra Checks for Reachability"
15345 +       default n
15346 +       help
15347 +         Set this to yes if you want to do extra checks for
15348 +         vfsmount reachability in the proc filesystem code.
15349 +         This shouldn't be required on any setup utilizing
15350 +         mnt namespaces.
15351 +
15352 +choice
15353 +       prompt  "Quotes used in debug and warn messages"
15354 +       default QUOTES_ISO8859
15355 +
15356 +config QUOTES_ISO8859
15357 +       bool    "Extended ASCII (ISO 8859) angle quotes"
15358 +       help
15359 +         This uses the extended ASCII characters \xbb
15360 +         and \xab for quoting file and process names.
15361 +
15362 +config QUOTES_UTF8
15363 +       bool    "UTF-8 angle quotes"
15364 +       help
15365 +         This uses the the UTF-8 sequences for angle
15366 +         quotes to quote file and process names.
15367 +
15368 +config QUOTES_ASCII
15369 +       bool    "ASCII single quotes"
15370 +       help
15371 +         This uses the ASCII single quote character
15372 +         (\x27) to quote file and process names.
15373 +
15374 +endchoice
15375 +
15376 +endmenu
15377 +
15378 +
15379 +config VSERVER
15380 +       bool
15381 +       default y
15382 +       select NAMESPACES
15383 +       select UTS_NS
15384 +       select IPC_NS
15385 +#      select USER_NS
15386 +       select SYSVIPC
15387 +
15388 +config VSERVER_SECURITY
15389 +       bool
15390 +       depends on SECURITY
15391 +       default y
15392 +       select SECURITY_CAPABILITIES
15393 +
15394 +config VSERVER_DISABLED
15395 +       bool
15396 +       default n
15397 +
15398 diff -NurpP --minimal linux-3.9.4/kernel/vserver/Makefile linux-3.9.4-vs2.3.6.3/kernel/vserver/Makefile
15399 --- linux-3.9.4/kernel/vserver/Makefile 1970-01-01 00:00:00.000000000 +0000
15400 +++ linux-3.9.4-vs2.3.6.3/kernel/vserver/Makefile       2013-05-31 14:47:11.000000000 +0000
15401 @@ -0,0 +1,18 @@
15402 +#
15403 +# Makefile for the Linux vserver routines.
15404 +#
15405 +
15406 +
15407 +obj-y          += vserver.o
15408 +
15409 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
15410 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
15411 +                  dlimit.o tag.o
15412 +
15413 +vserver-$(CONFIG_INET) += inet.o
15414 +vserver-$(CONFIG_PROC_FS) += proc.o
15415 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
15416 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
15417 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
15418 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
15419 +
15420 diff -NurpP --minimal linux-3.9.4/kernel/vserver/cacct.c linux-3.9.4-vs2.3.6.3/kernel/vserver/cacct.c
15421 --- linux-3.9.4/kernel/vserver/cacct.c  1970-01-01 00:00:00.000000000 +0000
15422 +++ linux-3.9.4-vs2.3.6.3/kernel/vserver/cacct.c        2013-05-31 14:47:11.000000000 +0000
15423 @@ -0,0 +1,42 @@
15424 +/*
15425 + *  linux/kernel/vserver/cacct.c
15426 + *
15427 + *  Virtual Server: Context Accounting
15428 + *
15429 + *  Copyright (C) 2006-2007 Herbert Pötzl
15430 + *
15431 + *  V0.01  added accounting stats
15432 + *
15433 + */
15434 +
15435 +#include <linux/types.h>
15436 +#include <linux/vs_context.h>
15437 +#include <linux/vserver/cacct_cmd.h>
15438 +#include <linux/vserver/cacct_int.h>
15439 +
15440 +#include <asm/errno.h>
15441 +#include <asm/uaccess.h>
15442 +
15443 +
15444 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
15445 +{
15446 +       struct vcmd_sock_stat_v0 vc_data;
15447 +       int j, field;
15448 +
15449 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15450 +               return -EFAULT;
15451 +
15452 +       field = vc_data.field;
15453 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
15454 +               return -EINVAL;
15455 +
15456 +       for (j = 0; j < 3; j++) {
15457 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
15458 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
15459 +       }
15460 +
15461 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15462 +               return -EFAULT;
15463 +       return 0;
15464 +}
15465 +
15466 diff -NurpP --minimal linux-3.9.4/kernel/vserver/cacct_init.h linux-3.9.4-vs2.3.6.3/kernel/vserver/cacct_init.h
15467 --- linux-3.9.4/kernel/vserver/cacct_init.h     1970-01-01 00:00:00.000000000 +0000
15468 +++ linux-3.9.4-vs2.3.6.3/kernel/vserver/cacct_init.h   2013-05-31 14:47:11.000000000 +0000
15469 @@ -0,0 +1,25 @@
15470 +
15471 +
15472 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
15473 +{
15474 +       int i, j;
15475 +
15476 +
15477 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
15478 +               for (j = 0; j < 3; j++) {
15479 +                       atomic_long_set(&cacct->sock[i][j].count, 0);
15480 +                       atomic_long_set(&cacct->sock[i][j].total, 0);
15481 +               }
15482 +       }
15483 +       for (i = 0; i < 8; i++)
15484 +               atomic_set(&cacct->slab[i], 0);
15485 +       for (i = 0; i < 5; i++)
15486 +               for (j = 0; j < 4; j++)
15487 +                       atomic_set(&cacct->page[i][j], 0);
15488 +}
15489 +
15490 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
15491 +{
15492 +       return;
15493 +}
15494 +
15495 diff -NurpP --minimal linux-3.9.4/kernel/vserver/cacct_proc.h linux-3.9.4-vs2.3.6.3/kernel/vserver/cacct_proc.h
15496 --- linux-3.9.4/kernel/vserver/cacct_proc.h     1970-01-01 00:00:00.000000000 +0000
15497 +++ linux-3.9.4-vs2.3.6.3/kernel/vserver/cacct_proc.h   2013-05-31 14:47:11.000000000 +0000
15498 @@ -0,0 +1,53 @@
15499 +#ifndef _VX_CACCT_PROC_H
15500 +#define _VX_CACCT_PROC_H
15501 +
15502 +#include <linux/vserver/cacct_int.h>
15503 +
15504 +
15505 +#define VX_SOCKA_TOP   \
15506 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
15507 +
15508 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
15509 +{
15510 +       int i, j, length = 0;
15511 +       static char *type[VXA_SOCK_SIZE] = {
15512 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
15513 +       };
15514 +
15515 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
15516 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
15517 +               length += sprintf(buffer + length, "%s:", type[i]);
15518 +               for (j = 0; j < 3; j++) {
15519 +                       length += sprintf(buffer + length,
15520 +                               "\t%10lu/%-10lu",
15521 +                               vx_sock_count(cacct, i, j),
15522 +                               vx_sock_total(cacct, i, j));
15523 +               }
15524 +               buffer[length++] = '\n';
15525 +       }
15526 +
15527 +       length += sprintf(buffer + length, "\n");
15528 +       length += sprintf(buffer + length,
15529 +               "slab:\t %8u %8u %8u %8u\n",
15530 +               atomic_read(&cacct->slab[1]),
15531 +               atomic_read(&cacct->slab[4]),
15532 +               atomic_read(&cacct->slab[0]),
15533 +               atomic_read(&cacct->slab[2]));
15534 +
15535 +       length += sprintf(buffer + length, "\n");
15536 +       for (i = 0; i < 5; i++) {
15537 +               length += sprintf(buffer + length,
15538 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
15539 +                       atomic_read(&cacct->page[i][0]),
15540 +                       atomic_read(&cacct->page[i][1]),
15541 +                       atomic_read(&cacct->page[i][2]),
15542 +                       atomic_read(&cacct->page[i][3]),
15543 +                       atomic_read(&cacct->page[i][4]),
15544 +                       atomic_read(&cacct->page[i][5]),
15545 +                       atomic_read(&cacct->page[i][6]),
15546 +                       atomic_read(&cacct->page[i][7]));
15547 +       }
15548 +       return length;
15549 +}
15550 +
15551 +#endif /* _VX_CACCT_PROC_H */
15552 diff -NurpP --minimal linux-3.9.4/kernel/vserver/context.c linux-3.9.4-vs2.3.6.3/kernel/vserver/context.c
15553 --- linux-3.9.4/kernel/vserver/context.c        1970-01-01 00:00:00.000000000 +0000
15554 +++ linux-3.9.4-vs2.3.6.3/kernel/vserver/context.c      2013-05-31 19:34:32.000000000 +0000
15555 @@ -0,0 +1,1119 @@
15556 +/*
15557 + *  linux/kernel/vserver/context.c
15558 + *
15559 + *  Virtual Server: Context Support
15560 + *
15561 + *  Copyright (C) 2003-2011  Herbert Pötzl
15562 + *
15563 + *  V0.01  context helper
15564 + *  V0.02  vx_ctx_kill syscall command
15565 + *  V0.03  replaced context_info calls
15566 + *  V0.04  redesign of struct (de)alloc
15567 + *  V0.05  rlimit basic implementation
15568 + *  V0.06  task_xid and info commands
15569 + *  V0.07  context flags and caps
15570 + *  V0.08  switch to RCU based hash
15571 + *  V0.09  revert to non RCU for now
15572 + *  V0.10  and back to working RCU hash
15573 + *  V0.11  and back to locking again
15574 + *  V0.12  referenced context store
15575 + *  V0.13  separate per cpu data
15576 + *  V0.14  changed vcmds to vxi arg
15577 + *  V0.15  added context stat
15578 + *  V0.16  have __create claim() the vxi
15579 + *  V0.17  removed older and legacy stuff
15580 + *  V0.18  added user credentials
15581 + *  V0.19  added warn mask
15582 + *
15583 + */
15584 +
15585 +#include <linux/slab.h>
15586 +#include <linux/types.h>
15587 +#include <linux/security.h>
15588 +#include <linux/pid_namespace.h>
15589 +#include <linux/capability.h>
15590 +
15591 +#include <linux/vserver/context.h>
15592 +#include <linux/vserver/network.h>
15593 +#include <linux/vserver/debug.h>
15594 +#include <linux/vserver/limit.h>
15595 +#include <linux/vserver/limit_int.h>
15596 +#include <linux/vserver/space.h>
15597 +#include <linux/init_task.h>
15598 +#include <linux/fs_struct.h>
15599 +#include <linux/cred.h>
15600 +
15601 +#include <linux/vs_context.h>
15602 +#include <linux/vs_limit.h>
15603 +#include <linux/vs_pid.h>
15604 +#include <linux/vserver/context_cmd.h>
15605 +
15606 +#include "cvirt_init.h"
15607 +#include "cacct_init.h"
15608 +#include "limit_init.h"
15609 +#include "sched_init.h"
15610 +
15611 +
15612 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
15613 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
15614 +
15615 +
15616 +/*     now inactive context structures */
15617 +
15618 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
15619 +
15620 +static DEFINE_SPINLOCK(vx_info_inactive_lock);
15621 +
15622 +
15623 +/*     __alloc_vx_info()
15624 +
15625 +       * allocate an initialized vx_info struct
15626 +       * doesn't make it visible (hash)                        */
15627 +
15628 +static struct vx_info *__alloc_vx_info(xid_t xid)
15629 +{
15630 +       struct vx_info *new = NULL;
15631 +       int cpu, index;
15632 +
15633 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
15634 +
15635 +       /* would this benefit from a slab cache? */
15636 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
15637 +       if (!new)
15638 +               return 0;
15639 +
15640 +       memset(new, 0, sizeof(struct vx_info));
15641 +#ifdef CONFIG_SMP
15642 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
15643 +       if (!new->ptr_pc)
15644 +               goto error;
15645 +#endif
15646 +       new->vx_id = xid;
15647 +       INIT_HLIST_NODE(&new->vx_hlist);
15648 +       atomic_set(&new->vx_usecnt, 0);
15649 +       atomic_set(&new->vx_tasks, 0);
15650 +       new->vx_parent = NULL;
15651 +       new->vx_state = 0;
15652 +       init_waitqueue_head(&new->vx_wait);
15653 +
15654 +       /* prepare reaper */
15655 +       get_task_struct(init_pid_ns.child_reaper);
15656 +       new->vx_reaper = init_pid_ns.child_reaper;
15657 +       new->vx_badness_bias = 0;
15658 +
15659 +       /* rest of init goes here */
15660 +       vx_info_init_limit(&new->limit);
15661 +       vx_info_init_sched(&new->sched);
15662 +       vx_info_init_cvirt(&new->cvirt);
15663 +       vx_info_init_cacct(&new->cacct);
15664 +
15665 +       /* per cpu data structures */
15666 +       for_each_possible_cpu(cpu) {
15667 +               vx_info_init_sched_pc(
15668 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
15669 +               vx_info_init_cvirt_pc(
15670 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
15671 +       }
15672 +
15673 +       new->vx_flags = VXF_INIT_SET;
15674 +       new->vx_bcaps = CAP_FULL_SET;   // maybe ~CAP_SETPCAP
15675 +       new->vx_ccaps = 0;
15676 +       new->vx_umask = 0;
15677 +       new->vx_wmask = 0;
15678 +
15679 +       new->reboot_cmd = 0;
15680 +       new->exit_code = 0;
15681 +
15682 +       // preconfig spaces
15683 +       for (index = 0; index < VX_SPACES; index++) {
15684 +               struct _vx_space *space = &new->space[index];
15685 +
15686 +               // filesystem
15687 +               spin_lock(&init_fs.lock);
15688 +               init_fs.users++;
15689 +               spin_unlock(&init_fs.lock);
15690 +               space->vx_fs = &init_fs;
15691 +
15692 +               /* FIXME: do we want defaults? */
15693 +               // space->vx_real_cred = 0;
15694 +               // space->vx_cred = 0;
15695 +       }
15696 +
15697 +
15698 +       vxdprintk(VXD_CBIT(xid, 0),
15699 +               "alloc_vx_info(%d) = %p", xid, new);
15700 +       vxh_alloc_vx_info(new);
15701 +       atomic_inc(&vx_global_ctotal);
15702 +       return new;
15703 +#ifdef CONFIG_SMP
15704 +error:
15705 +       kfree(new);
15706 +       return 0;
15707 +#endif
15708 +}
15709 +
15710 +/*     __dealloc_vx_info()
15711 +
15712 +       * final disposal of vx_info                             */
15713 +
15714 +static void __dealloc_vx_info(struct vx_info *vxi)
15715 +{
15716 +#ifdef CONFIG_VSERVER_WARN
15717 +       struct vx_info_save vxis;
15718 +       int cpu;
15719 +#endif
15720 +       vxdprintk(VXD_CBIT(xid, 0),
15721 +               "dealloc_vx_info(%p)", vxi);
15722 +       vxh_dealloc_vx_info(vxi);
15723 +
15724 +#ifdef CONFIG_VSERVER_WARN
15725 +       enter_vx_info(vxi, &vxis);
15726 +       vx_info_exit_limit(&vxi->limit);
15727 +       vx_info_exit_sched(&vxi->sched);
15728 +       vx_info_exit_cvirt(&vxi->cvirt);
15729 +       vx_info_exit_cacct(&vxi->cacct);
15730 +
15731 +       for_each_possible_cpu(cpu) {
15732 +               vx_info_exit_sched_pc(
15733 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
15734 +               vx_info_exit_cvirt_pc(
15735 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
15736 +       }
15737 +       leave_vx_info(&vxis);
15738 +#endif
15739 +
15740 +       vxi->vx_id = -1;
15741 +       vxi->vx_state |= VXS_RELEASED;
15742 +
15743 +#ifdef CONFIG_SMP
15744 +       free_percpu(vxi->ptr_pc);
15745 +#endif
15746 +       kfree(vxi);
15747 +       atomic_dec(&vx_global_ctotal);
15748 +}
15749 +
15750 +static void __shutdown_vx_info(struct vx_info *vxi)
15751 +{
15752 +       struct nsproxy *nsproxy;
15753 +       struct fs_struct *fs;
15754 +       struct cred *cred;
15755 +       int index, kill;
15756 +
15757 +       might_sleep();
15758 +
15759 +       vxi->vx_state |= VXS_SHUTDOWN;
15760 +       vs_state_change(vxi, VSC_SHUTDOWN);
15761 +
15762 +       for (index = 0; index < VX_SPACES; index++) {
15763 +               struct _vx_space *space = &vxi->space[index];
15764 +
15765 +               nsproxy = xchg(&space->vx_nsproxy, NULL);
15766 +               if (nsproxy)
15767 +                       put_nsproxy(nsproxy);
15768 +
15769 +               fs = xchg(&space->vx_fs, NULL);
15770 +               spin_lock(&fs->lock);
15771 +               kill = !--fs->users;
15772 +               spin_unlock(&fs->lock);
15773 +               if (kill)
15774 +                       free_fs_struct(fs);
15775 +
15776 +               cred = (struct cred *)xchg(&space->vx_cred, NULL);
15777 +               if (cred)
15778 +                       abort_creds(cred);
15779 +       }
15780 +}
15781 +
15782 +/* exported stuff */
15783 +
15784 +void free_vx_info(struct vx_info *vxi)
15785 +{
15786 +       unsigned long flags;
15787 +       unsigned index;
15788 +
15789 +       /* check for reference counts first */
15790 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
15791 +       BUG_ON(atomic_read(&vxi->vx_tasks));
15792 +
15793 +       /* context must not be hashed */
15794 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
15795 +
15796 +       /* context shutdown is mandatory */
15797 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
15798 +
15799 +       /* spaces check */
15800 +       for (index = 0; index < VX_SPACES; index++) {
15801 +               struct _vx_space *space = &vxi->space[index];
15802 +
15803 +               BUG_ON(space->vx_nsproxy);
15804 +               BUG_ON(space->vx_fs);
15805 +               // BUG_ON(space->vx_real_cred);
15806 +               // BUG_ON(space->vx_cred);
15807 +       }
15808 +
15809 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
15810 +       hlist_del(&vxi->vx_hlist);
15811 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
15812 +
15813 +       __dealloc_vx_info(vxi);
15814 +}
15815 +
15816 +
15817 +/*     hash table for vx_info hash */
15818 +
15819 +#define VX_HASH_SIZE   13
15820 +
15821 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
15822 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
15823 +
15824 +static DEFINE_SPINLOCK(vx_info_hash_lock);
15825 +
15826 +
15827 +static inline unsigned int __hashval(xid_t xid)
15828 +{
15829 +       return (xid % VX_HASH_SIZE);
15830 +}
15831 +
15832 +
15833 +
15834 +/*     __hash_vx_info()
15835 +
15836 +       * add the vxi to the global hash table
15837 +       * requires the hash_lock to be held                     */
15838 +
15839 +static inline void __hash_vx_info(struct vx_info *vxi)
15840 +{
15841 +       struct hlist_head *head;
15842 +
15843 +       vxd_assert_lock(&vx_info_hash_lock);
15844 +       vxdprintk(VXD_CBIT(xid, 4),
15845 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
15846 +       vxh_hash_vx_info(vxi);
15847 +
15848 +       /* context must not be hashed */
15849 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
15850 +
15851 +       vxi->vx_state |= VXS_HASHED;
15852 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
15853 +       hlist_add_head(&vxi->vx_hlist, head);
15854 +       atomic_inc(&vx_global_cactive);
15855 +}
15856 +
15857 +/*     __unhash_vx_info()
15858 +
15859 +       * remove the vxi from the global hash table
15860 +       * requires the hash_lock to be held                     */
15861 +
15862 +static inline void __unhash_vx_info(struct vx_info *vxi)
15863 +{
15864 +       unsigned long flags;
15865 +
15866 +       vxd_assert_lock(&vx_info_hash_lock);
15867 +       vxdprintk(VXD_CBIT(xid, 4),
15868 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
15869 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
15870 +       vxh_unhash_vx_info(vxi);
15871 +
15872 +       /* context must be hashed */
15873 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
15874 +       /* but without tasks */
15875 +       BUG_ON(atomic_read(&vxi->vx_tasks));
15876 +
15877 +       vxi->vx_state &= ~VXS_HASHED;
15878 +       hlist_del_init(&vxi->vx_hlist);
15879 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
15880 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
15881 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
15882 +       atomic_dec(&vx_global_cactive);
15883 +}
15884 +
15885 +
15886 +/*     __lookup_vx_info()
15887 +
15888 +       * requires the hash_lock to be held
15889 +       * doesn't increment the vx_refcnt                       */
15890 +
15891 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
15892 +{
15893 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
15894 +       struct hlist_node *pos;
15895 +       struct vx_info *vxi;
15896 +
15897 +       vxd_assert_lock(&vx_info_hash_lock);
15898 +       hlist_for_each(pos, head) {
15899 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
15900 +
15901 +               if (vxi->vx_id == xid)
15902 +                       goto found;
15903 +       }
15904 +       vxi = NULL;
15905 +found:
15906 +       vxdprintk(VXD_CBIT(xid, 0),
15907 +               "__lookup_vx_info(#%u): %p[#%u]",
15908 +               xid, vxi, vxi ? vxi->vx_id : 0);
15909 +       vxh_lookup_vx_info(vxi, xid);
15910 +       return vxi;
15911 +}
15912 +
15913 +
15914 +/*     __create_vx_info()
15915 +
15916 +       * create the requested context
15917 +       * get(), claim() and hash it                            */
15918 +
15919 +static struct vx_info *__create_vx_info(int id)
15920 +{
15921 +       struct vx_info *new, *vxi = NULL;
15922 +
15923 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
15924 +
15925 +       if (!(new = __alloc_vx_info(id)))
15926 +               return ERR_PTR(-ENOMEM);
15927 +
15928 +       /* required to make dynamic xids unique */
15929 +       spin_lock(&vx_info_hash_lock);
15930 +
15931 +       /* static context requested */
15932 +       if ((vxi = __lookup_vx_info(id))) {
15933 +               vxdprintk(VXD_CBIT(xid, 0),
15934 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
15935 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
15936 +                       vxi = ERR_PTR(-EBUSY);
15937 +               else
15938 +                       vxi = ERR_PTR(-EEXIST);
15939 +               goto out_unlock;
15940 +       }
15941 +       /* new context */
15942 +       vxdprintk(VXD_CBIT(xid, 0),
15943 +               "create_vx_info(%d) = %p (new)", id, new);
15944 +       claim_vx_info(new, NULL);
15945 +       __hash_vx_info(get_vx_info(new));
15946 +       vxi = new, new = NULL;
15947 +
15948 +out_unlock:
15949 +       spin_unlock(&vx_info_hash_lock);
15950 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
15951 +       if (new)
15952 +               __dealloc_vx_info(new);
15953 +       return vxi;
15954 +}
15955 +
15956 +
15957 +/*     exported stuff                                          */
15958 +
15959 +
15960 +void unhash_vx_info(struct vx_info *vxi)
15961 +{
15962 +       spin_lock(&vx_info_hash_lock);
15963 +       __unhash_vx_info(vxi);
15964 +       spin_unlock(&vx_info_hash_lock);
15965 +       __shutdown_vx_info(vxi);
15966 +       __wakeup_vx_info(vxi);
15967 +}
15968 +
15969 +
15970 +/*     lookup_vx_info()
15971 +
15972 +       * search for a vx_info and get() it
15973 +       * negative id means current                             */
15974 +
15975 +struct vx_info *lookup_vx_info(int id)
15976 +{
15977 +       struct vx_info *vxi = NULL;
15978 +
15979 +       if (id < 0) {
15980 +               vxi = get_vx_info(current_vx_info());
15981 +       } else if (id > 1) {
15982 +               spin_lock(&vx_info_hash_lock);
15983 +               vxi = get_vx_info(__lookup_vx_info(id));
15984 +               spin_unlock(&vx_info_hash_lock);
15985 +       }
15986 +       return vxi;
15987 +}
15988 +
15989 +/*     xid_is_hashed()
15990 +
15991 +       * verify that xid is still hashed                       */
15992 +
15993 +int xid_is_hashed(xid_t xid)
15994 +{
15995 +       int hashed;
15996 +
15997 +       spin_lock(&vx_info_hash_lock);
15998 +       hashed = (__lookup_vx_info(xid) != NULL);
15999 +       spin_unlock(&vx_info_hash_lock);
16000 +       return hashed;
16001 +}
16002 +
16003 +#ifdef CONFIG_PROC_FS
16004 +
16005 +/*     get_xid_list()
16006 +
16007 +       * get a subset of hashed xids for proc
16008 +       * assumes size is at least one                          */
16009 +
16010 +int get_xid_list(int index, unsigned int *xids, int size)
16011 +{
16012 +       int hindex, nr_xids = 0;
16013 +
16014 +       /* only show current and children */
16015 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
16016 +               if (index > 0)
16017 +                       return 0;
16018 +               xids[nr_xids] = vx_current_xid();
16019 +               return 1;
16020 +       }
16021 +
16022 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
16023 +               struct hlist_head *head = &vx_info_hash[hindex];
16024 +               struct hlist_node *pos;
16025 +
16026 +               spin_lock(&vx_info_hash_lock);
16027 +               hlist_for_each(pos, head) {
16028 +                       struct vx_info *vxi;
16029 +
16030 +                       if (--index > 0)
16031 +                               continue;
16032 +
16033 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16034 +                       xids[nr_xids] = vxi->vx_id;
16035 +                       if (++nr_xids >= size) {
16036 +                               spin_unlock(&vx_info_hash_lock);
16037 +                               goto out;
16038 +                       }
16039 +               }
16040 +               /* keep the lock time short */
16041 +               spin_unlock(&vx_info_hash_lock);
16042 +       }
16043 +out:
16044 +       return nr_xids;
16045 +}
16046 +#endif
16047 +
16048 +#ifdef CONFIG_VSERVER_DEBUG
16049 +
16050 +void   dump_vx_info_inactive(int level)
16051 +{
16052 +       struct hlist_node *entry, *next;
16053 +
16054 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
16055 +               struct vx_info *vxi =
16056 +                       list_entry(entry, struct vx_info, vx_hlist);
16057 +
16058 +               dump_vx_info(vxi, level);
16059 +       }
16060 +}
16061 +
16062 +#endif
16063 +
16064 +#if 0
16065 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
16066 +{
16067 +       struct user_struct *new_user, *old_user;
16068 +
16069 +       if (!p || !vxi)
16070 +               BUG();
16071 +
16072 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
16073 +               return -EACCES;
16074 +
16075 +       new_user = alloc_uid(vxi->vx_id, p->uid);
16076 +       if (!new_user)
16077 +               return -ENOMEM;
16078 +
16079 +       old_user = p->user;
16080 +       if (new_user != old_user) {
16081 +               atomic_inc(&new_user->processes);
16082 +               atomic_dec(&old_user->processes);
16083 +               p->user = new_user;
16084 +       }
16085 +       free_uid(old_user);
16086 +       return 0;
16087 +}
16088 +#endif
16089 +
16090 +#if 0
16091 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
16092 +{
16093 +       // p->cap_effective &= vxi->vx_cap_bset;
16094 +       p->cap_effective =
16095 +               cap_intersect(p->cap_effective, vxi->cap_bset);
16096 +       // p->cap_inheritable &= vxi->vx_cap_bset;
16097 +       p->cap_inheritable =
16098 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
16099 +       // p->cap_permitted &= vxi->vx_cap_bset;
16100 +       p->cap_permitted =
16101 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
16102 +}
16103 +#endif
16104 +
16105 +
16106 +#include <linux/file.h>
16107 +#include <linux/fdtable.h>
16108 +
16109 +static int vx_openfd_task(struct task_struct *tsk)
16110 +{
16111 +       struct files_struct *files = tsk->files;
16112 +       struct fdtable *fdt;
16113 +       const unsigned long *bptr;
16114 +       int count, total;
16115 +
16116 +       /* no rcu_read_lock() because of spin_lock() */
16117 +       spin_lock(&files->file_lock);
16118 +       fdt = files_fdtable(files);
16119 +       bptr = fdt->open_fds;
16120 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
16121 +       for (total = 0; count > 0; count--) {
16122 +               if (*bptr)
16123 +                       total += hweight_long(*bptr);
16124 +               bptr++;
16125 +       }
16126 +       spin_unlock(&files->file_lock);
16127 +       return total;
16128 +}
16129 +
16130 +
16131 +/*     for *space compatibility */
16132 +
16133 +asmlinkage long sys_unshare(unsigned long);
16134 +
16135 +/*
16136 + *     migrate task to new context
16137 + *     gets vxi, puts old_vxi on change
16138 + *     optionally unshares namespaces (hack)
16139 + */
16140 +
16141 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
16142 +{
16143 +       struct vx_info *old_vxi;
16144 +       int ret = 0;
16145 +
16146 +       if (!p || !vxi)
16147 +               BUG();
16148 +
16149 +       vxdprintk(VXD_CBIT(xid, 5),
16150 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
16151 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
16152 +
16153 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
16154 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16155 +               return -EACCES;
16156 +
16157 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
16158 +               return -EFAULT;
16159 +
16160 +       old_vxi = task_get_vx_info(p);
16161 +       if (old_vxi == vxi)
16162 +               goto out;
16163 +
16164 +//     if (!(ret = vx_migrate_user(p, vxi))) {
16165 +       {
16166 +               int openfd;
16167 +
16168 +               task_lock(p);
16169 +               openfd = vx_openfd_task(p);
16170 +
16171 +               if (old_vxi) {
16172 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
16173 +                       atomic_dec(&old_vxi->cvirt.nr_running);
16174 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
16175 +                       /* FIXME: what about the struct files here? */
16176 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
16177 +                       /* account for the executable */
16178 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
16179 +               }
16180 +               atomic_inc(&vxi->cvirt.nr_threads);
16181 +               atomic_inc(&vxi->cvirt.nr_running);
16182 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
16183 +               /* FIXME: what about the struct files here? */
16184 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
16185 +               /* account for the executable */
16186 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
16187 +
16188 +               if (old_vxi) {
16189 +                       release_vx_info(old_vxi, p);
16190 +                       clr_vx_info(&p->vx_info);
16191 +               }
16192 +               claim_vx_info(vxi, p);
16193 +               set_vx_info(&p->vx_info, vxi);
16194 +               p->xid = vxi->vx_id;
16195 +
16196 +               vxdprintk(VXD_CBIT(xid, 5),
16197 +                       "moved task %p into vxi:%p[#%d]",
16198 +                       p, vxi, vxi->vx_id);
16199 +
16200 +               // vx_mask_cap_bset(vxi, p);
16201 +               task_unlock(p);
16202 +
16203 +               /* hack for *spaces to provide compatibility */
16204 +               if (unshare) {
16205 +                       struct nsproxy *old_nsp, *new_nsp;
16206 +
16207 +                       ret = unshare_nsproxy_namespaces(
16208 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
16209 +                               &new_nsp, NULL, NULL);
16210 +                       if (ret)
16211 +                               goto out;
16212 +
16213 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
16214 +                       vx_set_space(vxi,
16215 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
16216 +                       put_nsproxy(old_nsp);
16217 +               }
16218 +       }
16219 +out:
16220 +       put_vx_info(old_vxi);
16221 +       return ret;
16222 +}
16223 +
16224 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
16225 +{
16226 +       struct task_struct *old_reaper;
16227 +       struct vx_info *reaper_vxi;
16228 +
16229 +       if (!vxi)
16230 +               return -EINVAL;
16231 +
16232 +       vxdprintk(VXD_CBIT(xid, 6),
16233 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
16234 +               vxi, vxi->vx_id, p, p->xid, p->pid);
16235 +
16236 +       old_reaper = vxi->vx_reaper;
16237 +       if (old_reaper == p)
16238 +               return 0;
16239 +
16240 +       reaper_vxi = task_get_vx_info(p);
16241 +       if (reaper_vxi && reaper_vxi != vxi) {
16242 +               vxwprintk(1,
16243 +                       "Unsuitable reaper [" VS_Q("%s") ",%u:#%u] "
16244 +                       "for [xid #%u]",
16245 +                       p->comm, p->pid, p->xid, vx_current_xid());
16246 +               goto out;
16247 +       }
16248 +
16249 +       /* set new child reaper */
16250 +       get_task_struct(p);
16251 +       vxi->vx_reaper = p;
16252 +       put_task_struct(old_reaper);
16253 +out:
16254 +       put_vx_info(reaper_vxi);
16255 +       return 0;
16256 +}
16257 +
16258 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
16259 +{
16260 +       if (!vxi)
16261 +               return -EINVAL;
16262 +
16263 +       vxdprintk(VXD_CBIT(xid, 6),
16264 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
16265 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16266 +
16267 +       vxi->vx_flags &= ~VXF_STATE_INIT;
16268 +       // vxi->vx_initpid = p->tgid;
16269 +       vxi->vx_initpid = p->pid;
16270 +       return 0;
16271 +}
16272 +
16273 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
16274 +{
16275 +       vxdprintk(VXD_CBIT(xid, 6),
16276 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
16277 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16278 +
16279 +       vxi->exit_code = code;
16280 +       vxi->vx_initpid = 0;
16281 +}
16282 +
16283 +
16284 +void vx_set_persistent(struct vx_info *vxi)
16285 +{
16286 +       vxdprintk(VXD_CBIT(xid, 6),
16287 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
16288 +
16289 +       get_vx_info(vxi);
16290 +       claim_vx_info(vxi, NULL);
16291 +}
16292 +
16293 +void vx_clear_persistent(struct vx_info *vxi)
16294 +{
16295 +       vxdprintk(VXD_CBIT(xid, 6),
16296 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
16297 +
16298 +       release_vx_info(vxi, NULL);
16299 +       put_vx_info(vxi);
16300 +}
16301 +
16302 +void vx_update_persistent(struct vx_info *vxi)
16303 +{
16304 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
16305 +               vx_set_persistent(vxi);
16306 +       else
16307 +               vx_clear_persistent(vxi);
16308 +}
16309 +
16310 +
16311 +/*     task must be current or locked          */
16312 +
16313 +void   exit_vx_info(struct task_struct *p, int code)
16314 +{
16315 +       struct vx_info *vxi = p->vx_info;
16316 +
16317 +       if (vxi) {
16318 +               atomic_dec(&vxi->cvirt.nr_threads);
16319 +               vx_nproc_dec(p);
16320 +
16321 +               vxi->exit_code = code;
16322 +               release_vx_info(vxi, p);
16323 +       }
16324 +}
16325 +
16326 +void   exit_vx_info_early(struct task_struct *p, int code)
16327 +{
16328 +       struct vx_info *vxi = p->vx_info;
16329 +
16330 +       if (vxi) {
16331 +               if (vxi->vx_initpid == p->pid)
16332 +                       vx_exit_init(vxi, p, code);
16333 +               if (vxi->vx_reaper == p)
16334 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
16335 +       }
16336 +}
16337 +
16338 +
16339 +/* vserver syscall commands below here */
16340 +
16341 +/* taks xid and vx_info functions */
16342 +
16343 +#include <asm/uaccess.h>
16344 +
16345 +
16346 +int vc_task_xid(uint32_t id)
16347 +{
16348 +       xid_t xid;
16349 +
16350 +       if (id) {
16351 +               struct task_struct *tsk;
16352 +
16353 +               rcu_read_lock();
16354 +               tsk = find_task_by_real_pid(id);
16355 +               xid = (tsk) ? tsk->xid : -ESRCH;
16356 +               rcu_read_unlock();
16357 +       } else
16358 +               xid = vx_current_xid();
16359 +       return xid;
16360 +}
16361 +
16362 +
16363 +int vc_vx_info(struct vx_info *vxi, void __user *data)
16364 +{
16365 +       struct vcmd_vx_info_v0 vc_data;
16366 +
16367 +       vc_data.xid = vxi->vx_id;
16368 +       vc_data.initpid = vxi->vx_initpid;
16369 +
16370 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16371 +               return -EFAULT;
16372 +       return 0;
16373 +}
16374 +
16375 +
16376 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
16377 +{
16378 +       struct vcmd_ctx_stat_v0 vc_data;
16379 +
16380 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
16381 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
16382 +
16383 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16384 +               return -EFAULT;
16385 +       return 0;
16386 +}
16387 +
16388 +
16389 +/* context functions */
16390 +
16391 +int vc_ctx_create(uint32_t xid, void __user *data)
16392 +{
16393 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
16394 +       struct vx_info *new_vxi;
16395 +       int ret;
16396 +
16397 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16398 +               return -EFAULT;
16399 +
16400 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
16401 +               return -EINVAL;
16402 +
16403 +       new_vxi = __create_vx_info(xid);
16404 +       if (IS_ERR(new_vxi))
16405 +               return PTR_ERR(new_vxi);
16406 +
16407 +       /* initial flags */
16408 +       new_vxi->vx_flags = vc_data.flagword;
16409 +
16410 +       ret = -ENOEXEC;
16411 +       if (vs_state_change(new_vxi, VSC_STARTUP))
16412 +               goto out;
16413 +
16414 +       ret = vx_migrate_task(current, new_vxi, (!data));
16415 +       if (ret)
16416 +               goto out;
16417 +
16418 +       /* return context id on success */
16419 +       ret = new_vxi->vx_id;
16420 +
16421 +       /* get a reference for persistent contexts */
16422 +       if ((vc_data.flagword & VXF_PERSISTENT))
16423 +               vx_set_persistent(new_vxi);
16424 +out:
16425 +       release_vx_info(new_vxi, NULL);
16426 +       put_vx_info(new_vxi);
16427 +       return ret;
16428 +}
16429 +
16430 +
16431 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
16432 +{
16433 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
16434 +       int ret;
16435 +
16436 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16437 +               return -EFAULT;
16438 +
16439 +       ret = vx_migrate_task(current, vxi, 0);
16440 +       if (ret)
16441 +               return ret;
16442 +       if (vc_data.flagword & VXM_SET_INIT)
16443 +               ret = vx_set_init(vxi, current);
16444 +       if (ret)
16445 +               return ret;
16446 +       if (vc_data.flagword & VXM_SET_REAPER)
16447 +               ret = vx_set_reaper(vxi, current);
16448 +       return ret;
16449 +}
16450 +
16451 +
16452 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
16453 +{
16454 +       struct vcmd_ctx_flags_v0 vc_data;
16455 +
16456 +       vc_data.flagword = vxi->vx_flags;
16457 +
16458 +       /* special STATE flag handling */
16459 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
16460 +
16461 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16462 +               return -EFAULT;
16463 +       return 0;
16464 +}
16465 +
16466 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
16467 +{
16468 +       struct vcmd_ctx_flags_v0 vc_data;
16469 +       uint64_t mask, trigger;
16470 +
16471 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16472 +               return -EFAULT;
16473 +
16474 +       /* special STATE flag handling */
16475 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
16476 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
16477 +
16478 +       if (vxi == current_vx_info()) {
16479 +               /* if (trigger & VXF_STATE_SETUP)
16480 +                       vx_mask_cap_bset(vxi, current); */
16481 +               if (trigger & VXF_STATE_INIT) {
16482 +                       int ret;
16483 +
16484 +                       ret = vx_set_init(vxi, current);
16485 +                       if (ret)
16486 +                               return ret;
16487 +                       ret = vx_set_reaper(vxi, current);
16488 +                       if (ret)
16489 +                               return ret;
16490 +               }
16491 +       }
16492 +
16493 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
16494 +               vc_data.flagword, mask);
16495 +       if (trigger & VXF_PERSISTENT)
16496 +               vx_update_persistent(vxi);
16497 +
16498 +       return 0;
16499 +}
16500 +
16501 +
16502 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
16503 +{
16504 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
16505 +
16506 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
16507 +       return v;
16508 +}
16509 +
16510 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
16511 +{
16512 +       kernel_cap_t c = __cap_empty_set;
16513 +
16514 +       c.cap[0] = v & 0xFFFFFFFF;
16515 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
16516 +
16517 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
16518 +       return c;
16519 +}
16520 +
16521 +
16522 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
16523 +{
16524 +       if (bcaps)
16525 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
16526 +       if (ccaps)
16527 +               *ccaps = vxi->vx_ccaps;
16528 +
16529 +       return 0;
16530 +}
16531 +
16532 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
16533 +{
16534 +       struct vcmd_ctx_caps_v1 vc_data;
16535 +       int ret;
16536 +
16537 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
16538 +       if (ret)
16539 +               return ret;
16540 +       vc_data.cmask = ~0ULL;
16541 +
16542 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16543 +               return -EFAULT;
16544 +       return 0;
16545 +}
16546 +
16547 +static int do_set_caps(struct vx_info *vxi,
16548 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
16549 +{
16550 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
16551 +
16552 +#if 0
16553 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
16554 +               bcaps, bmask, ccaps, cmask);
16555 +#endif
16556 +       vxi->vx_bcaps = cap_t_from_caps(
16557 +               vs_mask_flags(bcold, bcaps, bmask));
16558 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
16559 +
16560 +       return 0;
16561 +}
16562 +
16563 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
16564 +{
16565 +       struct vcmd_ctx_caps_v1 vc_data;
16566 +
16567 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16568 +               return -EFAULT;
16569 +
16570 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
16571 +}
16572 +
16573 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
16574 +{
16575 +       struct vcmd_bcaps vc_data;
16576 +       int ret;
16577 +
16578 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
16579 +       if (ret)
16580 +               return ret;
16581 +       vc_data.bmask = ~0ULL;
16582 +
16583 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16584 +               return -EFAULT;
16585 +       return 0;
16586 +}
16587 +
16588 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
16589 +{
16590 +       struct vcmd_bcaps vc_data;
16591 +
16592 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16593 +               return -EFAULT;
16594 +
16595 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
16596 +}
16597 +
16598 +
16599 +int vc_get_umask(struct vx_info *vxi, void __user *data)
16600 +{
16601 +       struct vcmd_umask vc_data;
16602 +
16603 +       vc_data.umask = vxi->vx_umask;
16604 +       vc_data.mask = ~0ULL;
16605 +
16606 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16607 +               return -EFAULT;
16608 +       return 0;
16609 +}
16610 +
16611 +int vc_set_umask(struct vx_info *vxi, void __user *data)
16612 +{
16613 +       struct vcmd_umask vc_data;
16614 +
16615 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16616 +               return -EFAULT;
16617 +
16618 +       vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
16619 +               vc_data.umask, vc_data.mask);
16620 +       return 0;
16621 +}
16622 +
16623 +
16624 +int vc_get_wmask(struct vx_info *vxi, void __user *data)
16625 +{
16626 +       struct vcmd_wmask vc_data;
16627 +
16628 +       vc_data.wmask = vxi->vx_wmask;
16629 +       vc_data.mask = ~0ULL;
16630 +
16631 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16632 +               return -EFAULT;
16633 +       return 0;
16634 +}
16635 +
16636 +int vc_set_wmask(struct vx_info *vxi, void __user *data)
16637 +{
16638 +       struct vcmd_wmask vc_data;
16639 +
16640 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16641 +               return -EFAULT;
16642 +
16643 +       vxi->vx_wmask = vs_mask_flags(vxi->vx_wmask,
16644 +               vc_data.wmask, vc_data.mask);
16645 +       return 0;
16646 +}
16647 +
16648 +
16649 +int vc_get_badness(struct vx_info *vxi, void __user *data)
16650 +{
16651 +       struct vcmd_badness_v0 vc_data;
16652 +
16653 +       vc_data.bias = vxi->vx_badness_bias;
16654 +
16655 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16656 +               return -EFAULT;
16657 +       return 0;
16658 +}
16659 +
16660 +int vc_set_badness(struct vx_info *vxi, void __user *data)
16661 +{
16662 +       struct vcmd_badness_v0 vc_data;
16663 +
16664 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16665 +               return -EFAULT;
16666 +
16667 +       vxi->vx_badness_bias = vc_data.bias;
16668 +       return 0;
16669 +}
16670 +
16671 +#include <linux/module.h>
16672 +
16673 +EXPORT_SYMBOL_GPL(free_vx_info);
16674 +
16675 diff -NurpP --minimal linux-3.9.4/kernel/vserver/cvirt.c linux-3.9.4-vs2.3.6.3/kernel/vserver/cvirt.c
16676 --- linux-3.9.4/kernel/vserver/cvirt.c  1970-01-01 00:00:00.000000000 +0000
16677 +++ linux-3.9.4-vs2.3.6.3/kernel/vserver/cvirt.c        2013-05-31 14:47:11.000000000 +0000
16678 @@ -0,0 +1,313 @@
16679 +/*
16680 + *  linux/kernel/vserver/cvirt.c
16681 + *
16682 + *  Virtual Server: Context Virtualization
16683 + *
16684 + *  Copyright (C) 2004-2007  Herbert Pötzl
16685 + *
16686 + *  V0.01  broken out from limit.c
16687 + *  V0.02  added utsname stuff
16688 + *  V0.03  changed vcmds to vxi arg
16689 + *
16690 + */
16691 +
16692 +#include <linux/types.h>
16693 +#include <linux/utsname.h>
16694 +#include <linux/vs_cvirt.h>
16695 +#include <linux/vserver/switch.h>
16696 +#include <linux/vserver/cvirt_cmd.h>
16697 +
16698 +#include <asm/uaccess.h>
16699 +
16700 +
16701 +void vx_vsi_boottime(struct timespec *boottime)
16702 +{
16703 +       struct vx_info *vxi = current_vx_info();
16704 +
16705 +       set_normalized_timespec(boottime,
16706 +               boottime->tv_sec + vxi->cvirt.bias_uptime.tv_sec,
16707 +               boottime->tv_nsec + vxi->cvirt.bias_uptime.tv_nsec);
16708 +       return;
16709 +}
16710 +
16711 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
16712 +{
16713 +       struct vx_info *vxi = current_vx_info();
16714 +
16715 +       set_normalized_timespec(uptime,
16716 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
16717 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
16718 +       if (!idle)
16719 +               return;
16720 +       set_normalized_timespec(idle,
16721 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
16722 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
16723 +       return;
16724 +}
16725 +
16726 +uint64_t vx_idle_jiffies(void)
16727 +{
16728 +       return init_task.utime + init_task.stime;
16729 +}
16730 +
16731 +
16732 +
16733 +static inline uint32_t __update_loadavg(uint32_t load,
16734 +       int wsize, int delta, int n)
16735 +{
16736 +       unsigned long long calc, prev;
16737 +
16738 +       /* just set it to n */
16739 +       if (unlikely(delta >= wsize))
16740 +               return (n << FSHIFT);
16741 +
16742 +       calc = delta * n;
16743 +       calc <<= FSHIFT;
16744 +       prev = (wsize - delta);
16745 +       prev *= load;
16746 +       calc += prev;
16747 +       do_div(calc, wsize);
16748 +       return calc;
16749 +}
16750 +
16751 +
16752 +void vx_update_load(struct vx_info *vxi)
16753 +{
16754 +       uint32_t now, last, delta;
16755 +       unsigned int nr_running, nr_uninterruptible;
16756 +       unsigned int total;
16757 +       unsigned long flags;
16758 +
16759 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
16760 +
16761 +       now = jiffies;
16762 +       last = vxi->cvirt.load_last;
16763 +       delta = now - last;
16764 +
16765 +       if (delta < 5*HZ)
16766 +               goto out;
16767 +
16768 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
16769 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
16770 +       total = nr_running + nr_uninterruptible;
16771 +
16772 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
16773 +               60*HZ, delta, total);
16774 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
16775 +               5*60*HZ, delta, total);
16776 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
16777 +               15*60*HZ, delta, total);
16778 +
16779 +       vxi->cvirt.load_last = now;
16780 +out:
16781 +       atomic_inc(&vxi->cvirt.load_updates);
16782 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
16783 +}
16784 +
16785 +
16786 +/*
16787 + * Commands to do_syslog:
16788 + *
16789 + *      0 -- Close the log.  Currently a NOP.
16790 + *      1 -- Open the log. Currently a NOP.
16791 + *      2 -- Read from the log.
16792 + *      3 -- Read all messages remaining in the ring buffer.
16793 + *      4 -- Read and clear all messages remaining in the ring buffer
16794 + *      5 -- Clear ring buffer.
16795 + *      6 -- Disable printk's to console
16796 + *      7 -- Enable printk's to console
16797 + *      8 -- Set level of messages printed to console
16798 + *      9 -- Return number of unread characters in the log buffer
16799 + *     10 -- Return size of the log buffer
16800 + */
16801 +int vx_do_syslog(int type, char __user *buf, int len)
16802 +{
16803 +       int error = 0;
16804 +       int do_clear = 0;
16805 +       struct vx_info *vxi = current_vx_info();
16806 +       struct _vx_syslog *log;
16807 +
16808 +       if (!vxi)
16809 +               return -EINVAL;
16810 +       log = &vxi->cvirt.syslog;
16811 +
16812 +       switch (type) {
16813 +       case 0:         /* Close log */
16814 +       case 1:         /* Open log */
16815 +               break;
16816 +       case 2:         /* Read from log */
16817 +               error = wait_event_interruptible(log->log_wait,
16818 +                       (log->log_start - log->log_end));
16819 +               if (error)
16820 +                       break;
16821 +               spin_lock_irq(&log->logbuf_lock);
16822 +               spin_unlock_irq(&log->logbuf_lock);
16823 +               break;
16824 +       case 4:         /* Read/clear last kernel messages */
16825 +               do_clear = 1;
16826 +               /* fall through */
16827 +       case 3:         /* Read last kernel messages */
16828 +               return 0;
16829 +
16830 +       case 5:         /* Clear ring buffer */
16831 +               return 0;
16832 +
16833 +       case 6:         /* Disable logging to console */
16834 +       case 7:         /* Enable logging to console */
16835 +       case 8:         /* Set level of messages printed to console */
16836 +               break;
16837 +
16838 +       case 9:         /* Number of chars in the log buffer */
16839 +               return 0;
16840 +       case 10:        /* Size of the log buffer */
16841 +               return 0;
16842 +       default:
16843 +               error = -EINVAL;
16844 +               break;
16845 +       }
16846 +       return error;
16847 +}
16848 +
16849 +
16850 +/* virtual host info names */
16851 +
16852 +static char *vx_vhi_name(struct vx_info *vxi, int id)
16853 +{
16854 +       struct nsproxy *nsproxy;
16855 +       struct uts_namespace *uts;
16856 +
16857 +       if (id == VHIN_CONTEXT)
16858 +               return vxi->vx_name;
16859 +
16860 +       nsproxy = vxi->space[0].vx_nsproxy;
16861 +       if (!nsproxy)
16862 +               return NULL;
16863 +
16864 +       uts = nsproxy->uts_ns;
16865 +       if (!uts)
16866 +               return NULL;
16867 +
16868 +       switch (id) {
16869 +       case VHIN_SYSNAME:
16870 +               return uts->name.sysname;
16871 +       case VHIN_NODENAME:
16872 +               return uts->name.nodename;
16873 +       case VHIN_RELEASE:
16874 +               return uts->name.release;
16875 +       case VHIN_VERSION:
16876 +               return uts->name.version;
16877 +       case VHIN_MACHINE:
16878 +               return uts->name.machine;
16879 +       case VHIN_DOMAINNAME:
16880 +               return uts->name.domainname;
16881 +       default:
16882 +               return NULL;
16883 +       }
16884 +       return NULL;
16885 +}
16886 +
16887 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
16888 +{
16889 +       struct vcmd_vhi_name_v0 vc_data;
16890 +       char *name;
16891 +
16892 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16893 +               return -EFAULT;
16894 +
16895 +       name = vx_vhi_name(vxi, vc_data.field);
16896 +       if (!name)
16897 +               return -EINVAL;
16898 +
16899 +       memcpy(name, vc_data.name, 65);
16900 +       return 0;
16901 +}
16902 +
16903 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
16904 +{
16905 +       struct vcmd_vhi_name_v0 vc_data;
16906 +       char *name;
16907 +
16908 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16909 +               return -EFAULT;
16910 +
16911 +       name = vx_vhi_name(vxi, vc_data.field);
16912 +       if (!name)
16913 +               return -EINVAL;
16914 +
16915 +       memcpy(vc_data.name, name, 65);
16916 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16917 +               return -EFAULT;
16918 +       return 0;
16919 +}
16920 +
16921 +
16922 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
16923 +{
16924 +       struct vcmd_virt_stat_v0 vc_data;
16925 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
16926 +       struct timespec uptime;
16927 +
16928 +       do_posix_clock_monotonic_gettime(&uptime);
16929 +       set_normalized_timespec(&uptime,
16930 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
16931 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
16932 +
16933 +       vc_data.offset = timespec_to_ns(&cvirt->bias_ts);
16934 +       vc_data.uptime = timespec_to_ns(&uptime);
16935 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
16936 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
16937 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
16938 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
16939 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
16940 +       vc_data.load[0] = cvirt->load[0];
16941 +       vc_data.load[1] = cvirt->load[1];
16942 +       vc_data.load[2] = cvirt->load[2];
16943 +
16944 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16945 +               return -EFAULT;
16946 +       return 0;
16947 +}
16948 +
16949 +
16950 +#ifdef CONFIG_VSERVER_VTIME
16951 +
16952 +/* virtualized time base */
16953 +
16954 +void vx_adjust_timespec(struct timespec *ts)
16955 +{
16956 +       struct vx_info *vxi;
16957 +
16958 +       if (!vx_flags(VXF_VIRT_TIME, 0))
16959 +               return;
16960 +
16961 +       vxi = current_vx_info();
16962 +       ts->tv_sec += vxi->cvirt.bias_ts.tv_sec;
16963 +       ts->tv_nsec += vxi->cvirt.bias_ts.tv_nsec;
16964 +
16965 +       if (ts->tv_nsec >= NSEC_PER_SEC) {
16966 +               ts->tv_sec++;
16967 +               ts->tv_nsec -= NSEC_PER_SEC;
16968 +       } else if (ts->tv_nsec < 0) {
16969 +               ts->tv_sec--;
16970 +               ts->tv_nsec += NSEC_PER_SEC;
16971 +       }
16972 +}
16973 +
16974 +int vx_settimeofday(const struct timespec *ts)
16975 +{
16976 +       struct timespec ats, delta;
16977 +       struct vx_info *vxi;
16978 +
16979 +       if (!vx_flags(VXF_VIRT_TIME, 0))
16980 +               return do_settimeofday(ts);
16981 +
16982 +       getnstimeofday(&ats);
16983 +       delta = timespec_sub(*ts, ats);
16984 +
16985 +       vxi = current_vx_info();
16986 +       vxi->cvirt.bias_ts = timespec_add(vxi->cvirt.bias_ts, delta);
16987 +       return 0;
16988 +}
16989 +
16990 +#endif
16991 +
16992 diff -NurpP --minimal linux-3.9.4/kernel/vserver/cvirt_init.h linux-3.9.4-vs2.3.6.3/kernel/vserver/cvirt_init.h
16993 --- linux-3.9.4/kernel/vserver/cvirt_init.h     1970-01-01 00:00:00.000000000 +0000
16994 +++ linux-3.9.4-vs2.3.6.3/kernel/vserver/cvirt_init.h   2013-05-31 14:47:11.000000000 +0000
16995 @@ -0,0 +1,70 @@
16996 +
16997 +
16998 +extern uint64_t vx_idle_jiffies(void);
16999 +
17000 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
17001 +{
17002 +       uint64_t idle_jiffies = vx_idle_jiffies();
17003 +       uint64_t nsuptime;
17004 +
17005 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
17006 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
17007 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
17008 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
17009 +       cvirt->bias_ts.tv_sec = 0;
17010 +       cvirt->bias_ts.tv_nsec = 0;
17011 +
17012 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
17013 +       atomic_set(&cvirt->nr_threads, 0);
17014 +       atomic_set(&cvirt->nr_running, 0);
17015 +       atomic_set(&cvirt->nr_uninterruptible, 0);
17016 +       atomic_set(&cvirt->nr_onhold, 0);
17017 +
17018 +       spin_lock_init(&cvirt->load_lock);
17019 +       cvirt->load_last = jiffies;
17020 +       atomic_set(&cvirt->load_updates, 0);
17021 +       cvirt->load[0] = 0;
17022 +       cvirt->load[1] = 0;
17023 +       cvirt->load[2] = 0;
17024 +       atomic_set(&cvirt->total_forks, 0);
17025 +
17026 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
17027 +       init_waitqueue_head(&cvirt->syslog.log_wait);
17028 +       cvirt->syslog.log_start = 0;
17029 +       cvirt->syslog.log_end = 0;
17030 +       cvirt->syslog.con_start = 0;
17031 +       cvirt->syslog.logged_chars = 0;
17032 +}
17033 +
17034 +static inline
17035 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17036 +{
17037 +       // cvirt_pc->cpustat = { 0 };
17038 +}
17039 +
17040 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
17041 +{
17042 +#ifdef CONFIG_VSERVER_WARN
17043 +       int value;
17044 +#endif
17045 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
17046 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
17047 +               cvirt, value);
17048 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
17049 +               "!!! cvirt: %p[nr_running] = %d on exit.",
17050 +               cvirt, value);
17051 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
17052 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
17053 +               cvirt, value);
17054 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
17055 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
17056 +               cvirt, value);
17057 +       return;
17058 +}
17059 +
17060 +static inline
17061 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17062 +{
17063 +       return;
17064 +}
17065 +
17066 diff -NurpP --minimal linux-3.9.4/kernel/vserver/cvirt_proc.h linux-3.9.4-vs2.3.6.3/kernel/vserver/cvirt_proc.h
17067 --- linux-3.9.4/kernel/vserver/cvirt_proc.h     1970-01-01 00:00:00.000000000 +0000
17068 +++ linux-3.9.4-vs2.3.6.3/kernel/vserver/cvirt_proc.h   2013-05-31 19:38:26.000000000 +0000
17069 @@ -0,0 +1,123 @@
17070 +#ifndef _VX_CVIRT_PROC_H
17071 +#define _VX_CVIRT_PROC_H
17072 +
17073 +#include <linux/nsproxy.h>
17074 +#include <linux/mnt_namespace.h>
17075 +#include <linux/ipc_namespace.h>
17076 +#include <linux/utsname.h>
17077 +#include <linux/ipc.h>
17078 +
17079 +extern int vx_info_mnt_namespace(struct mnt_namespace *, char *);
17080 +
17081 +static inline
17082 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
17083 +{
17084 +       struct mnt_namespace *ns;
17085 +       struct uts_namespace *uts;
17086 +       struct ipc_namespace *ipc;
17087 +       int length = 0;
17088 +
17089 +       if (!nsproxy)
17090 +               goto out;
17091 +
17092 +       length += sprintf(buffer + length,
17093 +               "NSProxy:\t%p [%p,%p,%p]\n",
17094 +               nsproxy, nsproxy->mnt_ns,
17095 +               nsproxy->uts_ns, nsproxy->ipc_ns);
17096 +
17097 +       ns = nsproxy->mnt_ns;
17098 +       if (!ns)
17099 +               goto skip_ns;
17100 +
17101 +       length += vx_info_mnt_namespace(ns, buffer + length);
17102 +
17103 +skip_ns:
17104 +
17105 +       uts = nsproxy->uts_ns;
17106 +       if (!uts)
17107 +               goto skip_uts;
17108 +
17109 +       length += sprintf(buffer + length,
17110 +               "SysName:\t%.*s\n"
17111 +               "NodeName:\t%.*s\n"
17112 +               "Release:\t%.*s\n"
17113 +               "Version:\t%.*s\n"
17114 +               "Machine:\t%.*s\n"
17115 +               "DomainName:\t%.*s\n",
17116 +               __NEW_UTS_LEN, uts->name.sysname,
17117 +               __NEW_UTS_LEN, uts->name.nodename,
17118 +               __NEW_UTS_LEN, uts->name.release,
17119 +               __NEW_UTS_LEN, uts->name.version,
17120 +               __NEW_UTS_LEN, uts->name.machine,
17121 +               __NEW_UTS_LEN, uts->name.domainname);
17122 +skip_uts:
17123 +
17124 +       ipc = nsproxy->ipc_ns;
17125 +       if (!ipc)
17126 +               goto skip_ipc;
17127 +
17128 +       length += sprintf(buffer + length,
17129 +               "SEMS:\t\t%d %d %d %d  %d\n"
17130 +               "MSG:\t\t%d %d %d\n"
17131 +               "SHM:\t\t%lu %lu  %d %ld\n",
17132 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
17133 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
17134 +               ipc->used_sems,
17135 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
17136 +               (unsigned long)ipc->shm_ctlmax,
17137 +               (unsigned long)ipc->shm_ctlall,
17138 +               ipc->shm_ctlmni, ipc->shm_tot);
17139 +skip_ipc:
17140 +out:
17141 +       return length;
17142 +}
17143 +
17144 +
17145 +#include <linux/sched.h>
17146 +
17147 +#define LOAD_INT(x) ((x) >> FSHIFT)
17148 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
17149 +
17150 +static inline
17151 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
17152 +{
17153 +       int length = 0;
17154 +       int a, b, c;
17155 +
17156 +       length += sprintf(buffer + length,
17157 +               "BiasUptime:\t%lu.%02lu\n",
17158 +               (unsigned long)cvirt->bias_uptime.tv_sec,
17159 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
17160 +
17161 +       a = cvirt->load[0] + (FIXED_1 / 200);
17162 +       b = cvirt->load[1] + (FIXED_1 / 200);
17163 +       c = cvirt->load[2] + (FIXED_1 / 200);
17164 +       length += sprintf(buffer + length,
17165 +               "nr_threads:\t%d\n"
17166 +               "nr_running:\t%d\n"
17167 +               "nr_unintr:\t%d\n"
17168 +               "nr_onhold:\t%d\n"
17169 +               "load_updates:\t%d\n"
17170 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
17171 +               "total_forks:\t%d\n",
17172 +               atomic_read(&cvirt->nr_threads),
17173 +               atomic_read(&cvirt->nr_running),
17174 +               atomic_read(&cvirt->nr_uninterruptible),
17175 +               atomic_read(&cvirt->nr_onhold),
17176 +               atomic_read(&cvirt->load_updates),
17177 +               LOAD_INT(a), LOAD_FRAC(a),
17178 +               LOAD_INT(b), LOAD_FRAC(b),
17179 +               LOAD_INT(c), LOAD_FRAC(c),
17180 +               atomic_read(&cvirt->total_forks));
17181 +       return length;
17182 +}
17183 +
17184 +static inline
17185 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
17186 +       char *buffer, int cpu)
17187 +{
17188 +       int length = 0;
17189 +       return length;
17190 +}
17191 +
17192 +#endif /* _VX_CVIRT_PROC_H */
17193 diff -NurpP --minimal linux-3.9.4/kernel/vserver/debug.c linux-3.9.4-vs2.3.6.3/kernel/vserver/debug.c
17194 --- linux-3.9.4/kernel/vserver/debug.c  1970-01-01 00:00:00.000000000 +0000
17195 +++ linux-3.9.4-vs2.3.6.3/kernel/vserver/debug.c        2013-05-31 14:47:11.000000000 +0000
17196 @@ -0,0 +1,32 @@
17197 +/*
17198 + *  kernel/vserver/debug.c
17199 + *
17200 + *  Copyright (C) 2005-2007 Herbert Pötzl
17201 + *
17202 + *  V0.01  vx_info dump support
17203 + *
17204 + */
17205 +
17206 +#include <linux/module.h>
17207 +
17208 +#include <linux/vserver/context.h>
17209 +
17210 +
17211 +void   dump_vx_info(struct vx_info *vxi, int level)
17212 +{
17213 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
17214 +               atomic_read(&vxi->vx_usecnt),
17215 +               atomic_read(&vxi->vx_tasks),
17216 +               vxi->vx_state);
17217 +       if (level > 0) {
17218 +               __dump_vx_limit(&vxi->limit);
17219 +               __dump_vx_sched(&vxi->sched);
17220 +               __dump_vx_cvirt(&vxi->cvirt);
17221 +               __dump_vx_cacct(&vxi->cacct);
17222 +       }
17223 +       printk("---\n");
17224 +}
17225 +
17226 +
17227 +EXPORT_SYMBOL_GPL(dump_vx_info);
17228 +
17229 diff -NurpP --minimal linux-3.9.4/kernel/vserver/device.c linux-3.9.4-vs2.3.6.3/kernel/vserver/device.c
17230 --- linux-3.9.4/kernel/vserver/device.c 1970-01-01 00:00:00.000000000 +0000
17231 +++ linux-3.9.4-vs2.3.6.3/kernel/vserver/device.c       2013-05-31 14:47:11.000000000 +0000
17232 @@ -0,0 +1,443 @@
17233 +/*
17234 + *  linux/kernel/vserver/device.c
17235 + *
17236 + *  Linux-VServer: Device Support
17237 + *
17238 + *  Copyright (C) 2006  Herbert Pötzl
17239 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
17240 + *
17241 + *  V0.01  device mapping basics
17242 + *  V0.02  added defaults
17243 + *
17244 + */
17245 +
17246 +#include <linux/slab.h>
17247 +#include <linux/rcupdate.h>
17248 +#include <linux/fs.h>
17249 +#include <linux/namei.h>
17250 +#include <linux/hash.h>
17251 +
17252 +#include <asm/errno.h>
17253 +#include <asm/uaccess.h>
17254 +#include <linux/vserver/base.h>
17255 +#include <linux/vserver/debug.h>
17256 +#include <linux/vserver/context.h>
17257 +#include <linux/vserver/device.h>
17258 +#include <linux/vserver/device_cmd.h>
17259 +
17260 +
17261 +#define DMAP_HASH_BITS 4
17262 +
17263 +
17264 +struct vs_mapping {
17265 +       union {
17266 +               struct hlist_node hlist;
17267 +               struct list_head list;
17268 +       } u;
17269 +#define dm_hlist       u.hlist
17270 +#define dm_list                u.list
17271 +       xid_t xid;
17272 +       dev_t device;
17273 +       struct vx_dmap_target target;
17274 +};
17275 +
17276 +
17277 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
17278 +
17279 +static DEFINE_SPINLOCK(dmap_main_hash_lock);
17280 +
17281 +static struct vx_dmap_target dmap_defaults[2] = {
17282 +       { .flags = DATTR_OPEN },
17283 +       { .flags = DATTR_OPEN },
17284 +};
17285 +
17286 +
17287 +struct kmem_cache *dmap_cachep __read_mostly;
17288 +
17289 +int __init dmap_cache_init(void)
17290 +{
17291 +       dmap_cachep = kmem_cache_create("dmap_cache",
17292 +               sizeof(struct vs_mapping), 0,
17293 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
17294 +       return 0;
17295 +}
17296 +
17297 +__initcall(dmap_cache_init);
17298 +
17299 +
17300 +static inline unsigned int __hashval(dev_t dev, int bits)
17301 +{
17302 +       return hash_long((unsigned long)dev, bits);
17303 +}
17304 +
17305 +
17306 +/*     __hash_mapping()
17307 + *     add the mapping to the hash table
17308 + */
17309 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
17310 +{
17311 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17312 +       struct hlist_head *head, *hash = dmap_main_hash;
17313 +       int device = vdm->device;
17314 +
17315 +       spin_lock(hash_lock);
17316 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
17317 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
17318 +
17319 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
17320 +       hlist_add_head(&vdm->dm_hlist, head);
17321 +       spin_unlock(hash_lock);
17322 +}
17323 +
17324 +
17325 +static inline int __mode_to_default(umode_t mode)
17326 +{
17327 +       switch (mode) {
17328 +       case S_IFBLK:
17329 +               return 0;
17330 +       case S_IFCHR:
17331 +               return 1;
17332 +       default:
17333 +               BUG();
17334 +       }
17335 +}
17336 +
17337 +
17338 +/*     __set_default()
17339 + *     set a default
17340 + */
17341 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
17342 +       struct vx_dmap_target *vdmt)
17343 +{
17344 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17345 +       spin_lock(hash_lock);
17346 +
17347 +       if (vxi)
17348 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
17349 +       else
17350 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
17351 +
17352 +
17353 +       spin_unlock(hash_lock);
17354 +
17355 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
17356 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
17357 +}
17358 +
17359 +
17360 +/*     __remove_default()
17361 + *     remove a default
17362 + */
17363 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
17364 +{
17365 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17366 +       spin_lock(hash_lock);
17367 +
17368 +       if (vxi)
17369 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
17370 +       else    /* remove == reset */
17371 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
17372 +
17373 +       spin_unlock(hash_lock);
17374 +       return 0;
17375 +}
17376 +
17377 +
17378 +/*     __find_mapping()
17379 + *     find a mapping in the hash table
17380 + *
17381 + *     caller must hold hash_lock
17382 + */
17383 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
17384 +       struct vs_mapping **local, struct vs_mapping **global)
17385 +{
17386 +       struct hlist_head *hash = dmap_main_hash;
17387 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
17388 +       struct hlist_node *pos;
17389 +       struct vs_mapping *vdm;
17390 +
17391 +       *local = NULL;
17392 +       if (global)
17393 +               *global = NULL;
17394 +
17395 +       hlist_for_each(pos, head) {
17396 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
17397 +
17398 +               if ((vdm->device == device) &&
17399 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
17400 +                       if (vdm->xid == xid) {
17401 +                               *local = vdm;
17402 +                               return 1;
17403 +                       } else if (global && vdm->xid == 0)
17404 +                               *global = vdm;
17405 +               }
17406 +       }
17407 +
17408 +       if (global && *global)
17409 +               return 0;
17410 +       else
17411 +               return -ENOENT;
17412 +}
17413 +
17414 +
17415 +/*     __lookup_mapping()
17416 + *     find a mapping and store the result in target and flags
17417 + */
17418 +static inline int __lookup_mapping(struct vx_info *vxi,
17419 +       dev_t device, dev_t *target, int *flags, umode_t mode)
17420 +{
17421 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17422 +       struct vs_mapping *vdm, *global;
17423 +       struct vx_dmap_target *vdmt;
17424 +       int ret = 0;
17425 +       xid_t xid = vxi->vx_id;
17426 +       int index;
17427 +
17428 +       spin_lock(hash_lock);
17429 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
17430 +               ret = 1;
17431 +               vdmt = &vdm->target;
17432 +               goto found;
17433 +       }
17434 +
17435 +       index = __mode_to_default(mode);
17436 +       if (vxi && vxi->dmap.targets[index].flags) {
17437 +               ret = 2;
17438 +               vdmt = &vxi->dmap.targets[index];
17439 +       } else if (global) {
17440 +               ret = 3;
17441 +               vdmt = &global->target;
17442 +               goto found;
17443 +       } else {
17444 +               ret = 4;
17445 +               vdmt = &dmap_defaults[index];
17446 +       }
17447 +
17448 +found:
17449 +       if (target && (vdmt->flags & DATTR_REMAP))
17450 +               *target = vdmt->target;
17451 +       else if (target)
17452 +               *target = device;
17453 +       if (flags)
17454 +               *flags = vdmt->flags;
17455 +
17456 +       spin_unlock(hash_lock);
17457 +
17458 +       return ret;
17459 +}
17460 +
17461 +
17462 +/*     __remove_mapping()
17463 + *     remove a mapping from the hash table
17464 + */
17465 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
17466 +       umode_t mode)
17467 +{
17468 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17469 +       struct vs_mapping *vdm = NULL;
17470 +       int ret = 0;
17471 +
17472 +       spin_lock(hash_lock);
17473 +
17474 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
17475 +               NULL);
17476 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
17477 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
17478 +       if (ret < 0)
17479 +               goto out;
17480 +       hlist_del(&vdm->dm_hlist);
17481 +
17482 +out:
17483 +       spin_unlock(hash_lock);
17484 +       if (vdm)
17485 +               kmem_cache_free(dmap_cachep, vdm);
17486 +       return ret;
17487 +}
17488 +
17489 +
17490 +
17491 +int vs_map_device(struct vx_info *vxi,
17492 +       dev_t device, dev_t *target, umode_t mode)
17493 +{
17494 +       int ret, flags = DATTR_MASK;
17495 +
17496 +       if (!vxi) {
17497 +               if (target)
17498 +                       *target = device;
17499 +               goto out;
17500 +       }
17501 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
17502 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
17503 +               device, target ? *target : 0, flags, mode, ret);
17504 +out:
17505 +       return (flags & DATTR_MASK);
17506 +}
17507 +
17508 +
17509 +
17510 +static int do_set_mapping(struct vx_info *vxi,
17511 +       dev_t device, dev_t target, int flags, umode_t mode)
17512 +{
17513 +       if (device) {
17514 +               struct vs_mapping *new;
17515 +
17516 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
17517 +               if (!new)
17518 +                       return -ENOMEM;
17519 +
17520 +               INIT_HLIST_NODE(&new->dm_hlist);
17521 +               new->device = device;
17522 +               new->target.target = target;
17523 +               new->target.flags = flags | mode;
17524 +               new->xid = (vxi ? vxi->vx_id : 0);
17525 +
17526 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
17527 +               __hash_mapping(vxi, new);
17528 +       } else {
17529 +               struct vx_dmap_target new = {
17530 +                       .target = target,
17531 +                       .flags = flags | mode,
17532 +               };
17533 +               __set_default(vxi, mode, &new);
17534 +       }
17535 +       return 0;
17536 +}
17537 +
17538 +
17539 +static int do_unset_mapping(struct vx_info *vxi,
17540 +       dev_t device, dev_t target, int flags, umode_t mode)
17541 +{
17542 +       int ret = -EINVAL;
17543 +
17544 +       if (device) {
17545 +               ret = __remove_mapping(vxi, device, mode);
17546 +               if (ret < 0)
17547 +                       goto out;
17548 +       } else {
17549 +               ret = __remove_default(vxi, mode);
17550 +               if (ret < 0)
17551 +                       goto out;
17552 +       }
17553 +
17554 +out:
17555 +       return ret;
17556 +}
17557 +
17558 +
17559 +static inline int __user_device(const char __user *name, dev_t *dev,
17560 +       umode_t *mode)
17561 +{
17562 +       struct nameidata nd;
17563 +       int ret;
17564 +
17565 +       if (!name) {
17566 +               *dev = 0;
17567 +               return 0;
17568 +       }
17569 +       ret = user_lpath(name, &nd.path);
17570 +       if (ret)
17571 +               return ret;
17572 +       if (nd.path.dentry->d_inode) {
17573 +               *dev = nd.path.dentry->d_inode->i_rdev;
17574 +               *mode = nd.path.dentry->d_inode->i_mode;
17575 +       }
17576 +       path_put(&nd.path);
17577 +       return 0;
17578 +}
17579 +
17580 +static inline int __mapping_mode(dev_t device, dev_t target,
17581 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
17582 +{
17583 +       if (device)
17584 +               *mode = device_mode & S_IFMT;
17585 +       else if (target)
17586 +               *mode = target_mode & S_IFMT;
17587 +       else
17588 +               return -EINVAL;
17589 +
17590 +       /* if both given, device and target mode have to match */
17591 +       if (device && target &&
17592 +               ((device_mode ^ target_mode) & S_IFMT))
17593 +               return -EINVAL;
17594 +       return 0;
17595 +}
17596 +
17597 +
17598 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
17599 +       const char __user *target_path, int flags, int set)
17600 +{
17601 +       dev_t device = ~0, target = ~0;
17602 +       umode_t device_mode = 0, target_mode = 0, mode;
17603 +       int ret;
17604 +
17605 +       ret = __user_device(device_path, &device, &device_mode);
17606 +       if (ret)
17607 +               return ret;
17608 +       ret = __user_device(target_path, &target, &target_mode);
17609 +       if (ret)
17610 +               return ret;
17611 +
17612 +       ret = __mapping_mode(device, target,
17613 +               device_mode, target_mode, &mode);
17614 +       if (ret)
17615 +               return ret;
17616 +
17617 +       if (set)
17618 +               return do_set_mapping(vxi, device, target,
17619 +                       flags, mode);
17620 +       else
17621 +               return do_unset_mapping(vxi, device, target,
17622 +                       flags, mode);
17623 +}
17624 +
17625 +
17626 +int vc_set_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, 1);
17635 +}
17636 +
17637 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
17638 +{
17639 +       struct vcmd_set_mapping_v0 vc_data;
17640 +
17641 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17642 +               return -EFAULT;
17643 +
17644 +       return do_mapping(vxi, vc_data.device, vc_data.target,
17645 +               vc_data.flags, 0);
17646 +}
17647 +
17648 +
17649 +#ifdef CONFIG_COMPAT
17650 +
17651 +int vc_set_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, 1);
17660 +}
17661 +
17662 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
17663 +{
17664 +       struct vcmd_set_mapping_v0_x32 vc_data;
17665 +
17666 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17667 +               return -EFAULT;
17668 +
17669 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
17670 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
17671 +}
17672 +
17673 +#endif /* CONFIG_COMPAT */
17674 +
17675 +
17676 diff -NurpP --minimal linux-3.9.4/kernel/vserver/dlimit.c linux-3.9.4-vs2.3.6.3/kernel/vserver/dlimit.c
17677 --- linux-3.9.4/kernel/vserver/dlimit.c 1970-01-01 00:00:00.000000000 +0000
17678 +++ linux-3.9.4-vs2.3.6.3/kernel/vserver/dlimit.c       2013-05-31 19:37:39.000000000 +0000
17679 @@ -0,0 +1,528 @@
17680 +/*
17681 + *  linux/kernel/vserver/dlimit.c
17682 + *
17683 + *  Virtual Server: Context Disk Limits
17684 + *
17685 + *  Copyright (C) 2004-2009  Herbert Pötzl
17686 + *
17687 + *  V0.01  initial version
17688 + *  V0.02  compat32 splitup
17689 + *  V0.03  extended interface
17690 + *
17691 + */
17692 +
17693 +#include <linux/statfs.h>
17694 +#include <linux/sched.h>
17695 +#include <linux/namei.h>
17696 +#include <linux/vs_tag.h>
17697 +#include <linux/vs_dlimit.h>
17698 +#include <linux/vserver/dlimit_cmd.h>
17699 +#include <linux/slab.h>
17700 +// #include <linux/gfp.h>
17701 +
17702 +#include <asm/uaccess.h>
17703 +
17704 +/*     __alloc_dl_info()
17705 +
17706 +       * allocate an initialized dl_info struct
17707 +       * doesn't make it visible (hash)                        */
17708 +
17709 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
17710 +{
17711 +       struct dl_info *new = NULL;
17712 +
17713 +       vxdprintk(VXD_CBIT(dlim, 5),
17714 +               "alloc_dl_info(%p,%d)*", sb, tag);
17715 +
17716 +       /* would this benefit from a slab cache? */
17717 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
17718 +       if (!new)
17719 +               return 0;
17720 +
17721 +       memset(new, 0, sizeof(struct dl_info));
17722 +       new->dl_tag = tag;
17723 +       new->dl_sb = sb;
17724 +       // INIT_RCU_HEAD(&new->dl_rcu);
17725 +       INIT_HLIST_NODE(&new->dl_hlist);
17726 +       spin_lock_init(&new->dl_lock);
17727 +       atomic_set(&new->dl_refcnt, 0);
17728 +       atomic_set(&new->dl_usecnt, 0);
17729 +
17730 +       /* rest of init goes here */
17731 +
17732 +       vxdprintk(VXD_CBIT(dlim, 4),
17733 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
17734 +       return new;
17735 +}
17736 +
17737 +/*     __dealloc_dl_info()
17738 +
17739 +       * final disposal of dl_info                             */
17740 +
17741 +static void __dealloc_dl_info(struct dl_info *dli)
17742 +{
17743 +       vxdprintk(VXD_CBIT(dlim, 4),
17744 +               "dealloc_dl_info(%p)", dli);
17745 +
17746 +       dli->dl_hlist.next = LIST_POISON1;
17747 +       dli->dl_tag = -1;
17748 +       dli->dl_sb = 0;
17749 +
17750 +       BUG_ON(atomic_read(&dli->dl_usecnt));
17751 +       BUG_ON(atomic_read(&dli->dl_refcnt));
17752 +
17753 +       kfree(dli);
17754 +}
17755 +
17756 +
17757 +/*     hash table for dl_info hash */
17758 +
17759 +#define DL_HASH_SIZE   13
17760 +
17761 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
17762 +
17763 +static DEFINE_SPINLOCK(dl_info_hash_lock);
17764 +
17765 +
17766 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
17767 +{
17768 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
17769 +}
17770 +
17771 +
17772 +
17773 +/*     __hash_dl_info()
17774 +
17775 +       * add the dli to the global hash table
17776 +       * requires the hash_lock to be held                     */
17777 +
17778 +static inline void __hash_dl_info(struct dl_info *dli)
17779 +{
17780 +       struct hlist_head *head;
17781 +
17782 +       vxdprintk(VXD_CBIT(dlim, 6),
17783 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
17784 +       get_dl_info(dli);
17785 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
17786 +       hlist_add_head_rcu(&dli->dl_hlist, head);
17787 +}
17788 +
17789 +/*     __unhash_dl_info()
17790 +
17791 +       * remove the dli from the global hash table
17792 +       * requires the hash_lock to be held                     */
17793 +
17794 +static inline void __unhash_dl_info(struct dl_info *dli)
17795 +{
17796 +       vxdprintk(VXD_CBIT(dlim, 6),
17797 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
17798 +       hlist_del_rcu(&dli->dl_hlist);
17799 +       put_dl_info(dli);
17800 +}
17801 +
17802 +
17803 +/*     __lookup_dl_info()
17804 +
17805 +       * requires the rcu_read_lock()
17806 +       * doesn't increment the dl_refcnt                       */
17807 +
17808 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
17809 +{
17810 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
17811 +       struct dl_info *dli;
17812 +
17813 +       hlist_for_each_entry_rcu(dli, head, dl_hlist) {
17814 +               if (dli->dl_tag == tag && dli->dl_sb == sb)
17815 +                       return dli;
17816 +       }
17817 +       return NULL;
17818 +}
17819 +
17820 +
17821 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
17822 +{
17823 +       struct dl_info *dli;
17824 +
17825 +       rcu_read_lock();
17826 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
17827 +       vxdprintk(VXD_CBIT(dlim, 7),
17828 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
17829 +       rcu_read_unlock();
17830 +       return dli;
17831 +}
17832 +
17833 +void rcu_free_dl_info(struct rcu_head *head)
17834 +{
17835 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
17836 +       int usecnt, refcnt;
17837 +
17838 +       BUG_ON(!dli || !head);
17839 +
17840 +       usecnt = atomic_read(&dli->dl_usecnt);
17841 +       BUG_ON(usecnt < 0);
17842 +
17843 +       refcnt = atomic_read(&dli->dl_refcnt);
17844 +       BUG_ON(refcnt < 0);
17845 +
17846 +       vxdprintk(VXD_CBIT(dlim, 3),
17847 +               "rcu_free_dl_info(%p)", dli);
17848 +       if (!usecnt)
17849 +               __dealloc_dl_info(dli);
17850 +       else
17851 +               printk("!!! rcu didn't free\n");
17852 +}
17853 +
17854 +
17855 +
17856 +
17857 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
17858 +       uint32_t flags, int add)
17859 +{
17860 +       struct path path;
17861 +       int ret;
17862 +
17863 +       ret = user_lpath(name, &path);
17864 +       if (!ret) {
17865 +               struct super_block *sb;
17866 +               struct dl_info *dli;
17867 +
17868 +               ret = -EINVAL;
17869 +               if (!path.dentry->d_inode)
17870 +                       goto out_release;
17871 +               if (!(sb = path.dentry->d_inode->i_sb))
17872 +                       goto out_release;
17873 +
17874 +               if (add) {
17875 +                       dli = __alloc_dl_info(sb, id);
17876 +                       spin_lock(&dl_info_hash_lock);
17877 +
17878 +                       ret = -EEXIST;
17879 +                       if (__lookup_dl_info(sb, id))
17880 +                               goto out_unlock;
17881 +                       __hash_dl_info(dli);
17882 +                       dli = NULL;
17883 +               } else {
17884 +                       spin_lock(&dl_info_hash_lock);
17885 +                       dli = __lookup_dl_info(sb, id);
17886 +
17887 +                       ret = -ESRCH;
17888 +                       if (!dli)
17889 +                               goto out_unlock;
17890 +                       __unhash_dl_info(dli);
17891 +               }
17892 +               ret = 0;
17893 +       out_unlock:
17894 +               spin_unlock(&dl_info_hash_lock);
17895 +               if (add && dli)
17896 +                       __dealloc_dl_info(dli);
17897 +       out_release:
17898 +               path_put(&path);
17899 +       }
17900 +       return ret;
17901 +}
17902 +
17903 +int vc_add_dlimit(uint32_t id, void __user *data)
17904 +{
17905 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
17906 +
17907 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17908 +               return -EFAULT;
17909 +
17910 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
17911 +}
17912 +
17913 +int vc_rem_dlimit(uint32_t id, void __user *data)
17914 +{
17915 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
17916 +
17917 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17918 +               return -EFAULT;
17919 +
17920 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
17921 +}
17922 +
17923 +#ifdef CONFIG_COMPAT
17924 +
17925 +int vc_add_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, 1);
17934 +}
17935 +
17936 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
17937 +{
17938 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
17939 +
17940 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17941 +               return -EFAULT;
17942 +
17943 +       return do_addrem_dlimit(id,
17944 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
17945 +}
17946 +
17947 +#endif /* CONFIG_COMPAT */
17948 +
17949 +
17950 +static inline
17951 +int do_set_dlimit(uint32_t id, const char __user *name,
17952 +       uint32_t space_used, uint32_t space_total,
17953 +       uint32_t inodes_used, uint32_t inodes_total,
17954 +       uint32_t reserved, uint32_t flags)
17955 +{
17956 +       struct path path;
17957 +       int ret;
17958 +
17959 +       ret = user_lpath(name, &path);
17960 +       if (!ret) {
17961 +               struct super_block *sb;
17962 +               struct dl_info *dli;
17963 +
17964 +               ret = -EINVAL;
17965 +               if (!path.dentry->d_inode)
17966 +                       goto out_release;
17967 +               if (!(sb = path.dentry->d_inode->i_sb))
17968 +                       goto out_release;
17969 +
17970 +               /* sanity checks */
17971 +               if ((reserved != CDLIM_KEEP &&
17972 +                       reserved > 100) ||
17973 +                       (inodes_used != CDLIM_KEEP &&
17974 +                       inodes_used > inodes_total) ||
17975 +                       (space_used != CDLIM_KEEP &&
17976 +                       space_used > space_total))
17977 +                       goto out_release;
17978 +
17979 +               ret = -ESRCH;
17980 +               dli = locate_dl_info(sb, id);
17981 +               if (!dli)
17982 +                       goto out_release;
17983 +
17984 +               spin_lock(&dli->dl_lock);
17985 +
17986 +               if (inodes_used != CDLIM_KEEP)
17987 +                       dli->dl_inodes_used = inodes_used;
17988 +               if (inodes_total != CDLIM_KEEP)
17989 +                       dli->dl_inodes_total = inodes_total;
17990 +               if (space_used != CDLIM_KEEP)
17991 +                       dli->dl_space_used = dlimit_space_32to64(
17992 +                               space_used, flags, DLIMS_USED);
17993 +
17994 +               if (space_total == CDLIM_INFINITY)
17995 +                       dli->dl_space_total = DLIM_INFINITY;
17996 +               else if (space_total != CDLIM_KEEP)
17997 +                       dli->dl_space_total = dlimit_space_32to64(
17998 +                               space_total, flags, DLIMS_TOTAL);
17999 +
18000 +               if (reserved != CDLIM_KEEP)
18001 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
18002 +
18003 +               spin_unlock(&dli->dl_lock);
18004 +
18005 +               put_dl_info(dli);
18006 +               ret = 0;
18007 +
18008 +       out_release:
18009 +               path_put(&path);
18010 +       }
18011 +       return ret;
18012 +}
18013 +
18014 +int vc_set_dlimit(uint32_t id, void __user *data)
18015 +{
18016 +       struct vcmd_ctx_dlimit_v0 vc_data;
18017 +
18018 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18019 +               return -EFAULT;
18020 +
18021 +       return do_set_dlimit(id, vc_data.name,
18022 +               vc_data.space_used, vc_data.space_total,
18023 +               vc_data.inodes_used, vc_data.inodes_total,
18024 +               vc_data.reserved, vc_data.flags);
18025 +}
18026 +
18027 +#ifdef CONFIG_COMPAT
18028 +
18029 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
18030 +{
18031 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18032 +
18033 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18034 +               return -EFAULT;
18035 +
18036 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
18037 +               vc_data.space_used, vc_data.space_total,
18038 +               vc_data.inodes_used, vc_data.inodes_total,
18039 +               vc_data.reserved, vc_data.flags);
18040 +}
18041 +
18042 +#endif /* CONFIG_COMPAT */
18043 +
18044 +
18045 +static inline
18046 +int do_get_dlimit(uint32_t id, const char __user *name,
18047 +       uint32_t *space_used, uint32_t *space_total,
18048 +       uint32_t *inodes_used, uint32_t *inodes_total,
18049 +       uint32_t *reserved, uint32_t *flags)
18050 +{
18051 +       struct path path;
18052 +       int ret;
18053 +
18054 +       ret = user_lpath(name, &path);
18055 +       if (!ret) {
18056 +               struct super_block *sb;
18057 +               struct dl_info *dli;
18058 +
18059 +               ret = -EINVAL;
18060 +               if (!path.dentry->d_inode)
18061 +                       goto out_release;
18062 +               if (!(sb = path.dentry->d_inode->i_sb))
18063 +                       goto out_release;
18064 +
18065 +               ret = -ESRCH;
18066 +               dli = locate_dl_info(sb, id);
18067 +               if (!dli)
18068 +                       goto out_release;
18069 +
18070 +               spin_lock(&dli->dl_lock);
18071 +               *inodes_used = dli->dl_inodes_used;
18072 +               *inodes_total = dli->dl_inodes_total;
18073 +
18074 +               *space_used = dlimit_space_64to32(
18075 +                       dli->dl_space_used, flags, DLIMS_USED);
18076 +
18077 +               if (dli->dl_space_total == DLIM_INFINITY)
18078 +                       *space_total = CDLIM_INFINITY;
18079 +               else
18080 +                       *space_total = dlimit_space_64to32(
18081 +                               dli->dl_space_total, flags, DLIMS_TOTAL);
18082 +
18083 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
18084 +               spin_unlock(&dli->dl_lock);
18085 +
18086 +               put_dl_info(dli);
18087 +               ret = -EFAULT;
18088 +
18089 +               ret = 0;
18090 +       out_release:
18091 +               path_put(&path);
18092 +       }
18093 +       return ret;
18094 +}
18095 +
18096 +
18097 +int vc_get_dlimit(uint32_t id, void __user *data)
18098 +{
18099 +       struct vcmd_ctx_dlimit_v0 vc_data;
18100 +       int ret;
18101 +
18102 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18103 +               return -EFAULT;
18104 +
18105 +       ret = do_get_dlimit(id, vc_data.name,
18106 +               &vc_data.space_used, &vc_data.space_total,
18107 +               &vc_data.inodes_used, &vc_data.inodes_total,
18108 +               &vc_data.reserved, &vc_data.flags);
18109 +       if (ret)
18110 +               return ret;
18111 +
18112 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18113 +               return -EFAULT;
18114 +       return 0;
18115 +}
18116 +
18117 +#ifdef CONFIG_COMPAT
18118 +
18119 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
18120 +{
18121 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18122 +       int ret;
18123 +
18124 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18125 +               return -EFAULT;
18126 +
18127 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
18128 +               &vc_data.space_used, &vc_data.space_total,
18129 +               &vc_data.inodes_used, &vc_data.inodes_total,
18130 +               &vc_data.reserved, &vc_data.flags);
18131 +       if (ret)
18132 +               return ret;
18133 +
18134 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18135 +               return -EFAULT;
18136 +       return 0;
18137 +}
18138 +
18139 +#endif /* CONFIG_COMPAT */
18140 +
18141 +
18142 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
18143 +{
18144 +       struct dl_info *dli;
18145 +       __u64 blimit, bfree, bavail;
18146 +       __u32 ifree;
18147 +
18148 +       dli = locate_dl_info(sb, dx_current_tag());
18149 +       if (!dli)
18150 +               return;
18151 +
18152 +       spin_lock(&dli->dl_lock);
18153 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
18154 +               goto no_ilim;
18155 +
18156 +       /* reduce max inodes available to limit */
18157 +       if (buf->f_files > dli->dl_inodes_total)
18158 +               buf->f_files = dli->dl_inodes_total;
18159 +
18160 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
18161 +       /* reduce free inodes to min */
18162 +       if (ifree < buf->f_ffree)
18163 +               buf->f_ffree = ifree;
18164 +
18165 +no_ilim:
18166 +       if (dli->dl_space_total == DLIM_INFINITY)
18167 +               goto no_blim;
18168 +
18169 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
18170 +
18171 +       if (dli->dl_space_total < dli->dl_space_used)
18172 +               bfree = 0;
18173 +       else
18174 +               bfree = (dli->dl_space_total - dli->dl_space_used)
18175 +                       >> sb->s_blocksize_bits;
18176 +
18177 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
18178 +       if (bavail < dli->dl_space_used)
18179 +               bavail = 0;
18180 +       else
18181 +               bavail = (bavail - dli->dl_space_used)
18182 +                       >> sb->s_blocksize_bits;
18183 +
18184 +       /* reduce max space available to limit */
18185 +       if (buf->f_blocks > blimit)
18186 +               buf->f_blocks = blimit;
18187 +
18188 +       /* reduce free space to min */
18189 +       if (bfree < buf->f_bfree)
18190 +               buf->f_bfree = bfree;
18191 +
18192 +       /* reduce avail space to min */
18193 +       if (bavail < buf->f_bavail)
18194 +               buf->f_bavail = bavail;
18195 +
18196 +no_blim:
18197 +       spin_unlock(&dli->dl_lock);
18198 +       put_dl_info(dli);
18199 +
18200 +       return;
18201 +}
18202 +
18203 +#include <linux/module.h>
18204 +
18205 +EXPORT_SYMBOL_GPL(locate_dl_info);
18206 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
18207 +
18208 diff -NurpP --minimal linux-3.9.4/kernel/vserver/helper.c linux-3.9.4-vs2.3.6.3/kernel/vserver/helper.c
18209 --- linux-3.9.4/kernel/vserver/helper.c 1970-01-01 00:00:00.000000000 +0000
18210 +++ linux-3.9.4-vs2.3.6.3/kernel/vserver/helper.c       2013-06-01 08:27:59.000000000 +0000
18211 @@ -0,0 +1,230 @@
18212 +/*
18213 + *  linux/kernel/vserver/helper.c
18214 + *
18215 + *  Virtual Context Support
18216 + *
18217 + *  Copyright (C) 2004-2007  Herbert Pötzl
18218 + *
18219 + *  V0.01  basic helper
18220 + *
18221 + */
18222 +
18223 +#include <linux/kmod.h>
18224 +#include <linux/reboot.h>
18225 +#include <linux/vs_context.h>
18226 +#include <linux/vs_network.h>
18227 +#include <linux/vserver/signal.h>
18228 +
18229 +
18230 +char vshelper_path[255] = "/sbin/vshelper";
18231 +
18232 +static int vshelper_init(struct subprocess_info *info, struct cred *new_cred)
18233 +{
18234 +       current->flags &= ~PF_THREAD_BOUND;
18235 +       return 0;
18236 +}
18237 +
18238 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
18239 +{
18240 +       int ret;
18241 +
18242 +       if ((ret = call_usermodehelper_fns(name, argv, envp,
18243 +               sync ? UMH_WAIT_PROC : UMH_WAIT_EXEC,
18244 +               vshelper_init, NULL, NULL))) {
18245 +               printk(KERN_WARNING "%s: (%s %s) returned %s with %d\n",
18246 +                       name, argv[1], argv[2],
18247 +                       sync ? "sync" : "async", ret);
18248 +       }
18249 +       vxdprintk(VXD_CBIT(switch, 4),
18250 +               "%s: (%s %s) returned %s with %d",
18251 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
18252 +       return ret;
18253 +}
18254 +
18255 +/*
18256 + *      vshelper path is set via /proc/sys
18257 + *      invoked by vserver sys_reboot(), with
18258 + *      the following arguments
18259 + *
18260 + *      argv [0] = vshelper_path;
18261 + *      argv [1] = action: "restart", "halt", "poweroff", ...
18262 + *      argv [2] = context identifier
18263 + *
18264 + *      envp [*] = type-specific parameters
18265 + */
18266 +
18267 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
18268 +{
18269 +       char id_buf[8], cmd_buf[16];
18270 +       char uid_buf[16], pid_buf[16];
18271 +       int ret;
18272 +
18273 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18274 +       char *envp[] = {"HOME=/", "TERM=linux",
18275 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
18276 +                       uid_buf, pid_buf, cmd_buf, 0};
18277 +
18278 +       if (vx_info_state(vxi, VXS_HELPER))
18279 +               return -EAGAIN;
18280 +       vxi->vx_state |= VXS_HELPER;
18281 +
18282 +       snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
18283 +
18284 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18285 +       snprintf(uid_buf, sizeof(uid_buf), "VS_UID=%d",
18286 +               from_kuid(&init_user_ns, current_uid()));
18287 +       snprintf(pid_buf, sizeof(pid_buf), "VS_PID=%d", current->pid);
18288 +
18289 +       switch (cmd) {
18290 +       case LINUX_REBOOT_CMD_RESTART:
18291 +               argv[1] = "restart";
18292 +               break;
18293 +
18294 +       case LINUX_REBOOT_CMD_HALT:
18295 +               argv[1] = "halt";
18296 +               break;
18297 +
18298 +       case LINUX_REBOOT_CMD_POWER_OFF:
18299 +               argv[1] = "poweroff";
18300 +               break;
18301 +
18302 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
18303 +               argv[1] = "swsusp";
18304 +               break;
18305 +
18306 +       case LINUX_REBOOT_CMD_OOM:
18307 +               argv[1] = "oom";
18308 +               break;
18309 +
18310 +       default:
18311 +               vxi->vx_state &= ~VXS_HELPER;
18312 +               return 0;
18313 +       }
18314 +
18315 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
18316 +       vxi->vx_state &= ~VXS_HELPER;
18317 +       __wakeup_vx_info(vxi);
18318 +       return (ret) ? -EPERM : 0;
18319 +}
18320 +
18321 +
18322 +long vs_reboot(unsigned int cmd, void __user *arg)
18323 +{
18324 +       struct vx_info *vxi = current_vx_info();
18325 +       long ret = 0;
18326 +
18327 +       vxdprintk(VXD_CBIT(misc, 5),
18328 +               "vs_reboot(%p[#%d],%u)",
18329 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18330 +
18331 +       ret = vs_reboot_helper(vxi, cmd, arg);
18332 +       if (ret)
18333 +               return ret;
18334 +
18335 +       vxi->reboot_cmd = cmd;
18336 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18337 +               switch (cmd) {
18338 +               case LINUX_REBOOT_CMD_RESTART:
18339 +               case LINUX_REBOOT_CMD_HALT:
18340 +               case LINUX_REBOOT_CMD_POWER_OFF:
18341 +                       vx_info_kill(vxi, 0, SIGKILL);
18342 +                       vx_info_kill(vxi, 1, SIGKILL);
18343 +               default:
18344 +                       break;
18345 +               }
18346 +       }
18347 +       return 0;
18348 +}
18349 +
18350 +long vs_oom_action(unsigned int cmd)
18351 +{
18352 +       struct vx_info *vxi = current_vx_info();
18353 +       long ret = 0;
18354 +
18355 +       vxdprintk(VXD_CBIT(misc, 5),
18356 +               "vs_oom_action(%p[#%d],%u)",
18357 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18358 +
18359 +       ret = vs_reboot_helper(vxi, cmd, NULL);
18360 +       if (ret)
18361 +               return ret;
18362 +
18363 +       vxi->reboot_cmd = cmd;
18364 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18365 +               vx_info_kill(vxi, 0, SIGKILL);
18366 +               vx_info_kill(vxi, 1, SIGKILL);
18367 +       }
18368 +       return 0;
18369 +}
18370 +
18371 +/*
18372 + *      argv [0] = vshelper_path;
18373 + *      argv [1] = action: "startup", "shutdown"
18374 + *      argv [2] = context identifier
18375 + *
18376 + *      envp [*] = type-specific parameters
18377 + */
18378 +
18379 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
18380 +{
18381 +       char id_buf[8], cmd_buf[16];
18382 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18383 +       char *envp[] = {"HOME=/", "TERM=linux",
18384 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18385 +
18386 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
18387 +               return 0;
18388 +
18389 +       snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
18390 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18391 +
18392 +       switch (cmd) {
18393 +       case VSC_STARTUP:
18394 +               argv[1] = "startup";
18395 +               break;
18396 +       case VSC_SHUTDOWN:
18397 +               argv[1] = "shutdown";
18398 +               break;
18399 +       default:
18400 +               return 0;
18401 +       }
18402 +
18403 +       return do_vshelper(vshelper_path, argv, envp, 1);
18404 +}
18405 +
18406 +
18407 +/*
18408 + *      argv [0] = vshelper_path;
18409 + *      argv [1] = action: "netup", "netdown"
18410 + *      argv [2] = context identifier
18411 + *
18412 + *      envp [*] = type-specific parameters
18413 + */
18414 +
18415 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
18416 +{
18417 +       char id_buf[8], cmd_buf[16];
18418 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18419 +       char *envp[] = {"HOME=/", "TERM=linux",
18420 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18421 +
18422 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
18423 +               return 0;
18424 +
18425 +       snprintf(id_buf, sizeof(id_buf), "%d", nxi->nx_id);
18426 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18427 +
18428 +       switch (cmd) {
18429 +       case VSC_NETUP:
18430 +               argv[1] = "netup";
18431 +               break;
18432 +       case VSC_NETDOWN:
18433 +               argv[1] = "netdown";
18434 +               break;
18435 +       default:
18436 +               return 0;
18437 +       }
18438 +
18439 +       return do_vshelper(vshelper_path, argv, envp, 1);
18440 +}
18441 +
18442 diff -NurpP --minimal linux-3.9.4/kernel/vserver/history.c linux-3.9.4-vs2.3.6.3/kernel/vserver/history.c
18443 --- linux-3.9.4/kernel/vserver/history.c        1970-01-01 00:00:00.000000000 +0000
18444 +++ linux-3.9.4-vs2.3.6.3/kernel/vserver/history.c      2013-05-31 14:47:11.000000000 +0000
18445 @@ -0,0 +1,258 @@
18446 +/*
18447 + *  kernel/vserver/history.c
18448 + *
18449 + *  Virtual Context History Backtrace
18450 + *
18451 + *  Copyright (C) 2004-2007  Herbert Pötzl
18452 + *
18453 + *  V0.01  basic structure
18454 + *  V0.02  hash/unhash and trace
18455 + *  V0.03  preemption fixes
18456 + *
18457 + */
18458 +
18459 +#include <linux/module.h>
18460 +#include <asm/uaccess.h>
18461 +
18462 +#include <linux/vserver/context.h>
18463 +#include <linux/vserver/debug.h>
18464 +#include <linux/vserver/debug_cmd.h>
18465 +#include <linux/vserver/history.h>
18466 +
18467 +
18468 +#ifdef CONFIG_VSERVER_HISTORY
18469 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
18470 +#else
18471 +#define VXH_SIZE       64
18472 +#endif
18473 +
18474 +struct _vx_history {
18475 +       unsigned int counter;
18476 +
18477 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
18478 +};
18479 +
18480 +
18481 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
18482 +
18483 +unsigned volatile int vxh_active = 1;
18484 +
18485 +static atomic_t sequence = ATOMIC_INIT(0);
18486 +
18487 +
18488 +/*     vxh_advance()
18489 +
18490 +       * requires disabled preemption                          */
18491 +
18492 +struct _vx_hist_entry *vxh_advance(void *loc)
18493 +{
18494 +       unsigned int cpu = smp_processor_id();
18495 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
18496 +       struct _vx_hist_entry *entry;
18497 +       unsigned int index;
18498 +
18499 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
18500 +       entry = &hist->entry[index];
18501 +
18502 +       entry->seq = atomic_inc_return(&sequence);
18503 +       entry->loc = loc;
18504 +       return entry;
18505 +}
18506 +
18507 +EXPORT_SYMBOL_GPL(vxh_advance);
18508 +
18509 +
18510 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
18511 +
18512 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
18513 +
18514 +
18515 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
18516 +
18517 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
18518 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
18519 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
18520 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
18521 +
18522 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
18523 +{
18524 +       switch (e->type) {
18525 +       case VXH_THROW_OOPS:
18526 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
18527 +               break;
18528 +
18529 +       case VXH_GET_VX_INFO:
18530 +       case VXH_PUT_VX_INFO:
18531 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
18532 +                       VXH_LOC_ARGS(e),
18533 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
18534 +                       VXH_VXI_ARGS(e));
18535 +               break;
18536 +
18537 +       case VXH_INIT_VX_INFO:
18538 +       case VXH_SET_VX_INFO:
18539 +       case VXH_CLR_VX_INFO:
18540 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
18541 +                       VXH_LOC_ARGS(e),
18542 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
18543 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
18544 +                       VXH_VXI_ARGS(e), e->sc.data);
18545 +               break;
18546 +
18547 +       case VXH_CLAIM_VX_INFO:
18548 +       case VXH_RELEASE_VX_INFO:
18549 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
18550 +                       VXH_LOC_ARGS(e),
18551 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
18552 +                       VXH_VXI_ARGS(e), e->sc.data);
18553 +               break;
18554 +
18555 +       case VXH_ALLOC_VX_INFO:
18556 +       case VXH_DEALLOC_VX_INFO:
18557 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
18558 +                       VXH_LOC_ARGS(e),
18559 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
18560 +                       VXH_VXI_ARGS(e));
18561 +               break;
18562 +
18563 +       case VXH_HASH_VX_INFO:
18564 +       case VXH_UNHASH_VX_INFO:
18565 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
18566 +                       VXH_LOC_ARGS(e),
18567 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
18568 +                       VXH_VXI_ARGS(e));
18569 +               break;
18570 +
18571 +       case VXH_LOC_VX_INFO:
18572 +       case VXH_LOOKUP_VX_INFO:
18573 +       case VXH_CREATE_VX_INFO:
18574 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
18575 +                       VXH_LOC_ARGS(e),
18576 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
18577 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
18578 +                       e->ll.arg, VXH_VXI_ARGS(e));
18579 +               break;
18580 +       }
18581 +}
18582 +
18583 +static void __vxh_dump_history(void)
18584 +{
18585 +       unsigned int i, cpu;
18586 +
18587 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
18588 +               atomic_read(&sequence), NR_CPUS);
18589 +
18590 +       for (i = 0; i < VXH_SIZE; i++) {
18591 +               for_each_online_cpu(cpu) {
18592 +                       struct _vx_history *hist =
18593 +                               &per_cpu(vx_history_buffer, cpu);
18594 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
18595 +                       struct _vx_hist_entry *entry = &hist->entry[index];
18596 +
18597 +                       vxh_dump_entry(entry, cpu);
18598 +               }
18599 +       }
18600 +}
18601 +
18602 +void   vxh_dump_history(void)
18603 +{
18604 +       vxh_active = 0;
18605 +#ifdef CONFIG_SMP
18606 +       local_irq_enable();
18607 +       smp_send_stop();
18608 +       local_irq_disable();
18609 +#endif
18610 +       __vxh_dump_history();
18611 +}
18612 +
18613 +
18614 +/* vserver syscall commands below here */
18615 +
18616 +
18617 +int vc_dump_history(uint32_t id)
18618 +{
18619 +       vxh_active = 0;
18620 +       __vxh_dump_history();
18621 +       vxh_active = 1;
18622 +
18623 +       return 0;
18624 +}
18625 +
18626 +
18627 +int do_read_history(struct __user _vx_hist_entry *data,
18628 +       int cpu, uint32_t *index, uint32_t *count)
18629 +{
18630 +       int pos, ret = 0;
18631 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
18632 +       int end = hist->counter;
18633 +       int start = end - VXH_SIZE + 2;
18634 +       int idx = *index;
18635 +
18636 +       /* special case: get current pos */
18637 +       if (!*count) {
18638 +               *index = end;
18639 +               return 0;
18640 +       }
18641 +
18642 +       /* have we lost some data? */
18643 +       if (idx < start)
18644 +               idx = start;
18645 +
18646 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
18647 +               struct _vx_hist_entry *entry =
18648 +                       &hist->entry[idx % VXH_SIZE];
18649 +
18650 +               /* send entry to userspace */
18651 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
18652 +               if (ret)
18653 +                       break;
18654 +       }
18655 +       /* save new index and count */
18656 +       *index = idx;
18657 +       *count = pos;
18658 +       return ret ? ret : (*index < end);
18659 +}
18660 +
18661 +int vc_read_history(uint32_t id, void __user *data)
18662 +{
18663 +       struct vcmd_read_history_v0 vc_data;
18664 +       int ret;
18665 +
18666 +       if (id >= NR_CPUS)
18667 +               return -EINVAL;
18668 +
18669 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18670 +               return -EFAULT;
18671 +
18672 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
18673 +               id, &vc_data.index, &vc_data.count);
18674 +
18675 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18676 +               return -EFAULT;
18677 +       return ret;
18678 +}
18679 +
18680 +#ifdef CONFIG_COMPAT
18681 +
18682 +int vc_read_history_x32(uint32_t id, void __user *data)
18683 +{
18684 +       struct vcmd_read_history_v0_x32 vc_data;
18685 +       int ret;
18686 +
18687 +       if (id >= NR_CPUS)
18688 +               return -EINVAL;
18689 +
18690 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18691 +               return -EFAULT;
18692 +
18693 +       ret = do_read_history((struct __user _vx_hist_entry *)
18694 +               compat_ptr(vc_data.data_ptr),
18695 +               id, &vc_data.index, &vc_data.count);
18696 +
18697 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18698 +               return -EFAULT;
18699 +       return ret;
18700 +}
18701 +
18702 +#endif /* CONFIG_COMPAT */
18703 +
18704 diff -NurpP --minimal linux-3.9.4/kernel/vserver/inet.c linux-3.9.4-vs2.3.6.3/kernel/vserver/inet.c
18705 --- linux-3.9.4/kernel/vserver/inet.c   1970-01-01 00:00:00.000000000 +0000
18706 +++ linux-3.9.4-vs2.3.6.3/kernel/vserver/inet.c 2013-05-31 22:43:05.000000000 +0000
18707 @@ -0,0 +1,236 @@
18708 +
18709 +#include <linux/in.h>
18710 +#include <linux/inetdevice.h>
18711 +#include <linux/export.h>
18712 +#include <linux/vs_inet.h>
18713 +#include <linux/vs_inet6.h>
18714 +#include <linux/vserver/debug.h>
18715 +#include <net/route.h>
18716 +#include <net/addrconf.h>
18717 +
18718 +
18719 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
18720 +{
18721 +       int ret = 0;
18722 +
18723 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
18724 +               ret = 1;
18725 +       else {
18726 +               struct nx_addr_v4 *ptr;
18727 +               unsigned long irqflags;
18728 +
18729 +               spin_lock_irqsave(&nxi1->addr_lock, irqflags);
18730 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
18731 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
18732 +                               ret = 1;
18733 +                               break;
18734 +                       }
18735 +               }
18736 +               spin_unlock_irqrestore(&nxi1->addr_lock, irqflags);
18737 +       }
18738 +
18739 +       vxdprintk(VXD_CBIT(net, 2),
18740 +               "nx_v4_addr_conflict(%p,%p): %d",
18741 +               nxi1, nxi2, ret);
18742 +
18743 +       return ret;
18744 +}
18745 +
18746 +
18747 +#ifdef CONFIG_IPV6
18748 +
18749 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
18750 +{
18751 +       int ret = 0;
18752 +
18753 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
18754 +               ret = 1;
18755 +       else {
18756 +               struct nx_addr_v6 *ptr;
18757 +               unsigned long irqflags;
18758 +
18759 +               spin_lock_irqsave(&nxi1->addr_lock, irqflags);
18760 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
18761 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
18762 +                               ret = 1;
18763 +                               break;
18764 +                       }
18765 +               }
18766 +               spin_unlock_irqrestore(&nxi1->addr_lock, irqflags);
18767 +       }
18768 +
18769 +       vxdprintk(VXD_CBIT(net, 2),
18770 +               "nx_v6_addr_conflict(%p,%p): %d",
18771 +               nxi1, nxi2, ret);
18772 +
18773 +       return ret;
18774 +}
18775 +
18776 +#endif
18777 +
18778 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18779 +{
18780 +       struct in_device *in_dev;
18781 +       struct in_ifaddr **ifap;
18782 +       struct in_ifaddr *ifa;
18783 +       int ret = 0;
18784 +
18785 +       if (!dev)
18786 +               goto out;
18787 +       in_dev = in_dev_get(dev);
18788 +       if (!in_dev)
18789 +               goto out;
18790 +
18791 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
18792 +               ifap = &ifa->ifa_next) {
18793 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
18794 +                       ret = 1;
18795 +                       break;
18796 +               }
18797 +       }
18798 +       in_dev_put(in_dev);
18799 +out:
18800 +       return ret;
18801 +}
18802 +
18803 +
18804 +#ifdef CONFIG_IPV6
18805 +
18806 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18807 +{
18808 +       struct inet6_dev *in_dev;
18809 +       struct inet6_ifaddr *ifa;
18810 +       int ret = 0;
18811 +
18812 +       if (!dev)
18813 +               goto out;
18814 +       in_dev = in6_dev_get(dev);
18815 +       if (!in_dev)
18816 +               goto out;
18817 +
18818 +       // for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
18819 +       list_for_each_entry(ifa, &in_dev->addr_list, if_list) {
18820 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
18821 +                       ret = 1;
18822 +                       break;
18823 +               }
18824 +       }
18825 +       in6_dev_put(in_dev);
18826 +out:
18827 +       return ret;
18828 +}
18829 +
18830 +#endif
18831 +
18832 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18833 +{
18834 +       int ret = 1;
18835 +
18836 +       if (!nxi)
18837 +               goto out;
18838 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
18839 +               goto out;
18840 +#ifdef CONFIG_IPV6
18841 +       ret = 2;
18842 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
18843 +               goto out;
18844 +#endif
18845 +       ret = 0;
18846 +out:
18847 +       vxdprintk(VXD_CBIT(net, 3),
18848 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
18849 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
18850 +       return ret;
18851 +}
18852 +
18853 +struct rtable *ip_v4_find_src(struct net *net, struct nx_info *nxi,
18854 +       struct flowi4 *fl4)
18855 +{
18856 +       struct rtable *rt;
18857 +
18858 +       if (!nxi)
18859 +               return NULL;
18860 +
18861 +       /* FIXME: handle lback only case */
18862 +       if (!NX_IPV4(nxi))
18863 +               return ERR_PTR(-EPERM);
18864 +
18865 +       vxdprintk(VXD_CBIT(net, 4),
18866 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
18867 +               nxi, nxi ? nxi->nx_id : 0,
18868 +               NIPQUAD(fl4->saddr), NIPQUAD(fl4->daddr));
18869 +
18870 +       /* single IP is unconditional */
18871 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
18872 +               (fl4->saddr == INADDR_ANY))
18873 +               fl4->saddr = nxi->v4.ip[0].s_addr;
18874 +
18875 +       if (fl4->saddr == INADDR_ANY) {
18876 +               struct nx_addr_v4 *ptr;
18877 +               __be32 found = 0;
18878 +
18879 +               rt = __ip_route_output_key(net, fl4);
18880 +               if (!IS_ERR(rt)) {
18881 +                       found = fl4->saddr;
18882 +                       ip_rt_put(rt);
18883 +                       vxdprintk(VXD_CBIT(net, 4),
18884 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
18885 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(found));
18886 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
18887 +                               goto found;
18888 +               }
18889 +
18890 +               WARN_ON_ONCE(in_irq());
18891 +               spin_lock_bh(&nxi->addr_lock);
18892 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
18893 +                       __be32 primary = ptr->ip[0].s_addr;
18894 +                       __be32 mask = ptr->mask.s_addr;
18895 +                       __be32 neta = primary & mask;
18896 +
18897 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
18898 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
18899 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
18900 +                               NIPQUAD(mask), NIPQUAD(neta));
18901 +                       if ((found & mask) != neta)
18902 +                               continue;
18903 +
18904 +                       fl4->saddr = primary;
18905 +                       rt = __ip_route_output_key(net, fl4);
18906 +                       vxdprintk(VXD_CBIT(net, 4),
18907 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
18908 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(primary));
18909 +                       if (!IS_ERR(rt)) {
18910 +                               found = fl4->saddr;
18911 +                               ip_rt_put(rt);
18912 +                               if (found == primary)
18913 +                                       goto found_unlock;
18914 +                       }
18915 +               }
18916 +               /* still no source ip? */
18917 +               found = ipv4_is_loopback(fl4->daddr)
18918 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
18919 +       found_unlock:
18920 +               spin_unlock_bh(&nxi->addr_lock);
18921 +       found:
18922 +               /* assign src ip to flow */
18923 +               fl4->saddr = found;
18924 +
18925 +       } else {
18926 +               if (!v4_addr_in_nx_info(nxi, fl4->saddr, NXA_MASK_BIND))
18927 +                       return ERR_PTR(-EPERM);
18928 +       }
18929 +
18930 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
18931 +               if (ipv4_is_loopback(fl4->daddr))
18932 +                       fl4->daddr = nxi->v4_lback.s_addr;
18933 +               if (ipv4_is_loopback(fl4->saddr))
18934 +                       fl4->saddr = nxi->v4_lback.s_addr;
18935 +       } else if (ipv4_is_loopback(fl4->daddr) &&
18936 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
18937 +               return ERR_PTR(-EPERM);
18938 +
18939 +       return NULL;
18940 +}
18941 +
18942 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
18943 +
18944 diff -NurpP --minimal linux-3.9.4/kernel/vserver/init.c linux-3.9.4-vs2.3.6.3/kernel/vserver/init.c
18945 --- linux-3.9.4/kernel/vserver/init.c   1970-01-01 00:00:00.000000000 +0000
18946 +++ linux-3.9.4-vs2.3.6.3/kernel/vserver/init.c 2013-05-31 14:47:11.000000000 +0000
18947 @@ -0,0 +1,45 @@
18948 +/*
18949 + *  linux/kernel/init.c
18950 + *
18951 + *  Virtual Server Init
18952 + *
18953 + *  Copyright (C) 2004-2007  Herbert Pötzl
18954 + *
18955 + *  V0.01  basic structure
18956 + *
18957 + */
18958 +
18959 +#include <linux/init.h>
18960 +
18961 +int    vserver_register_sysctl(void);
18962 +void   vserver_unregister_sysctl(void);
18963 +
18964 +
18965 +static int __init init_vserver(void)
18966 +{
18967 +       int ret = 0;
18968 +
18969 +#ifdef CONFIG_VSERVER_DEBUG
18970 +       vserver_register_sysctl();
18971 +#endif
18972 +       return ret;
18973 +}
18974 +
18975 +
18976 +static void __exit exit_vserver(void)
18977 +{
18978 +
18979 +#ifdef CONFIG_VSERVER_DEBUG
18980 +       vserver_unregister_sysctl();
18981 +#endif
18982 +       return;
18983 +}
18984 +
18985 +/* FIXME: GFP_ZONETYPES gone
18986 +long vx_slab[GFP_ZONETYPES]; */
18987 +long vx_area;
18988 +
18989 +
18990 +module_init(init_vserver);
18991 +module_exit(exit_vserver);
18992 +
18993 diff -NurpP --minimal linux-3.9.4/kernel/vserver/inode.c linux-3.9.4-vs2.3.6.3/kernel/vserver/inode.c
18994 --- linux-3.9.4/kernel/vserver/inode.c  1970-01-01 00:00:00.000000000 +0000
18995 +++ linux-3.9.4-vs2.3.6.3/kernel/vserver/inode.c        2013-06-01 08:26:06.000000000 +0000
18996 @@ -0,0 +1,437 @@
18997 +/*
18998 + *  linux/kernel/vserver/inode.c
18999 + *
19000 + *  Virtual Server: File System Support
19001 + *
19002 + *  Copyright (C) 2004-2007  Herbert Pötzl
19003 + *
19004 + *  V0.01  separated from vcontext V0.05
19005 + *  V0.02  moved to tag (instead of xid)
19006 + *
19007 + */
19008 +
19009 +#include <linux/tty.h>
19010 +#include <linux/proc_fs.h>
19011 +#include <linux/devpts_fs.h>
19012 +#include <linux/fs.h>
19013 +#include <linux/file.h>
19014 +#include <linux/mount.h>
19015 +#include <linux/parser.h>
19016 +#include <linux/namei.h>
19017 +#include <linux/vserver/inode.h>
19018 +#include <linux/vserver/inode_cmd.h>
19019 +#include <linux/vs_base.h>
19020 +#include <linux/vs_tag.h>
19021 +
19022 +#include <asm/uaccess.h>
19023 +
19024 +
19025 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19026 +{
19027 +       struct proc_dir_entry *entry;
19028 +
19029 +       if (!in || !in->i_sb)
19030 +               return -ESRCH;
19031 +
19032 +       *flags = IATTR_TAG
19033 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
19034 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
19035 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
19036 +               | (IS_COW(in) ? IATTR_COW : 0);
19037 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
19038 +
19039 +       if (S_ISDIR(in->i_mode))
19040 +               *mask |= IATTR_BARRIER;
19041 +
19042 +       if (IS_TAGGED(in)) {
19043 +               *tag = i_tag_read(in);
19044 +               *mask |= IATTR_TAG;
19045 +       }
19046 +
19047 +       switch (in->i_sb->s_magic) {
19048 +       case PROC_SUPER_MAGIC:
19049 +               entry = PROC_I(in)->pde;
19050 +
19051 +               /* check for specific inodes? */
19052 +               if (entry)
19053 +                       *mask |= IATTR_FLAGS;
19054 +               if (entry)
19055 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
19056 +               else
19057 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
19058 +               break;
19059 +
19060 +       case DEVPTS_SUPER_MAGIC:
19061 +               *tag = i_tag_read(in);
19062 +               *mask |= IATTR_TAG;
19063 +               break;
19064 +
19065 +       default:
19066 +               break;
19067 +       }
19068 +       return 0;
19069 +}
19070 +
19071 +int vc_get_iattr(void __user *data)
19072 +{
19073 +       struct path path;
19074 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
19075 +       int ret;
19076 +
19077 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19078 +               return -EFAULT;
19079 +
19080 +       ret = user_lpath(vc_data.name, &path);
19081 +       if (!ret) {
19082 +               ret = __vc_get_iattr(path.dentry->d_inode,
19083 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19084 +               path_put(&path);
19085 +       }
19086 +       if (ret)
19087 +               return ret;
19088 +
19089 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19090 +               ret = -EFAULT;
19091 +       return ret;
19092 +}
19093 +
19094 +#ifdef CONFIG_COMPAT
19095 +
19096 +int vc_get_iattr_x32(void __user *data)
19097 +{
19098 +       struct path path;
19099 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
19100 +       int ret;
19101 +
19102 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19103 +               return -EFAULT;
19104 +
19105 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19106 +       if (!ret) {
19107 +               ret = __vc_get_iattr(path.dentry->d_inode,
19108 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19109 +               path_put(&path);
19110 +       }
19111 +       if (ret)
19112 +               return ret;
19113 +
19114 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19115 +               ret = -EFAULT;
19116 +       return ret;
19117 +}
19118 +
19119 +#endif /* CONFIG_COMPAT */
19120 +
19121 +
19122 +int vc_fget_iattr(uint32_t fd, void __user *data)
19123 +{
19124 +       struct file *filp;
19125 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
19126 +       int ret;
19127 +
19128 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19129 +               return -EFAULT;
19130 +
19131 +       filp = fget(fd);
19132 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19133 +               return -EBADF;
19134 +
19135 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
19136 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
19137 +
19138 +       fput(filp);
19139 +
19140 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19141 +               ret = -EFAULT;
19142 +       return ret;
19143 +}
19144 +
19145 +
19146 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19147 +{
19148 +       struct inode *in = de->d_inode;
19149 +       int error = 0, is_proc = 0, has_tag = 0;
19150 +       struct iattr attr = { 0 };
19151 +
19152 +       if (!in || !in->i_sb)
19153 +               return -ESRCH;
19154 +
19155 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
19156 +       if ((*mask & IATTR_FLAGS) && !is_proc)
19157 +               return -EINVAL;
19158 +
19159 +       has_tag = IS_TAGGED(in) ||
19160 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
19161 +       if ((*mask & IATTR_TAG) && !has_tag)
19162 +               return -EINVAL;
19163 +
19164 +       mutex_lock(&in->i_mutex);
19165 +       if (*mask & IATTR_TAG) {
19166 +               attr.ia_tag = make_ktag(&init_user_ns, *tag);
19167 +               attr.ia_valid |= ATTR_TAG;
19168 +       }
19169 +
19170 +       if (*mask & IATTR_FLAGS) {
19171 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
19172 +               unsigned int iflags = PROC_I(in)->vx_flags;
19173 +
19174 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
19175 +                       | (*flags & IATTR_FLAGS);
19176 +               PROC_I(in)->vx_flags = iflags;
19177 +               if (entry)
19178 +                       entry->vx_flags = iflags;
19179 +       }
19180 +
19181 +       if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
19182 +               IATTR_BARRIER | IATTR_COW)) {
19183 +               int iflags = in->i_flags;
19184 +               int vflags = in->i_vflags;
19185 +
19186 +               if (*mask & IATTR_IMMUTABLE) {
19187 +                       if (*flags & IATTR_IMMUTABLE)
19188 +                               iflags |= S_IMMUTABLE;
19189 +                       else
19190 +                               iflags &= ~S_IMMUTABLE;
19191 +               }
19192 +               if (*mask & IATTR_IXUNLINK) {
19193 +                       if (*flags & IATTR_IXUNLINK)
19194 +                               iflags |= S_IXUNLINK;
19195 +                       else
19196 +                               iflags &= ~S_IXUNLINK;
19197 +               }
19198 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
19199 +                       if (*flags & IATTR_BARRIER)
19200 +                               vflags |= V_BARRIER;
19201 +                       else
19202 +                               vflags &= ~V_BARRIER;
19203 +               }
19204 +               if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
19205 +                       if (*flags & IATTR_COW)
19206 +                               vflags |= V_COW;
19207 +                       else
19208 +                               vflags &= ~V_COW;
19209 +               }
19210 +               if (in->i_op && in->i_op->sync_flags) {
19211 +                       error = in->i_op->sync_flags(in, iflags, vflags);
19212 +                       if (error)
19213 +                               goto out;
19214 +               }
19215 +       }
19216 +
19217 +       if (attr.ia_valid) {
19218 +               if (in->i_op && in->i_op->setattr)
19219 +                       error = in->i_op->setattr(de, &attr);
19220 +               else {
19221 +                       error = inode_change_ok(in, &attr);
19222 +                       if (!error) {
19223 +                               setattr_copy(in, &attr);
19224 +                               mark_inode_dirty(in);
19225 +                       }
19226 +               }
19227 +       }
19228 +
19229 +out:
19230 +       mutex_unlock(&in->i_mutex);
19231 +       return error;
19232 +}
19233 +
19234 +int vc_set_iattr(void __user *data)
19235 +{
19236 +       struct path path;
19237 +       struct vcmd_ctx_iattr_v1 vc_data;
19238 +       int ret;
19239 +
19240 +       if (!capable(CAP_LINUX_IMMUTABLE))
19241 +               return -EPERM;
19242 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19243 +               return -EFAULT;
19244 +
19245 +       ret = user_lpath(vc_data.name, &path);
19246 +       if (!ret) {
19247 +               ret = __vc_set_iattr(path.dentry,
19248 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19249 +               path_put(&path);
19250 +       }
19251 +
19252 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19253 +               ret = -EFAULT;
19254 +       return ret;
19255 +}
19256 +
19257 +#ifdef CONFIG_COMPAT
19258 +
19259 +int vc_set_iattr_x32(void __user *data)
19260 +{
19261 +       struct path path;
19262 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
19263 +       int ret;
19264 +
19265 +       if (!capable(CAP_LINUX_IMMUTABLE))
19266 +               return -EPERM;
19267 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19268 +               return -EFAULT;
19269 +
19270 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19271 +       if (!ret) {
19272 +               ret = __vc_set_iattr(path.dentry,
19273 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19274 +               path_put(&path);
19275 +       }
19276 +
19277 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19278 +               ret = -EFAULT;
19279 +       return ret;
19280 +}
19281 +
19282 +#endif /* CONFIG_COMPAT */
19283 +
19284 +int vc_fset_iattr(uint32_t fd, void __user *data)
19285 +{
19286 +       struct file *filp;
19287 +       struct vcmd_ctx_fiattr_v0 vc_data;
19288 +       int ret;
19289 +
19290 +       if (!capable(CAP_LINUX_IMMUTABLE))
19291 +               return -EPERM;
19292 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19293 +               return -EFAULT;
19294 +
19295 +       filp = fget(fd);
19296 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19297 +               return -EBADF;
19298 +
19299 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
19300 +               &vc_data.flags, &vc_data.mask);
19301 +
19302 +       fput(filp);
19303 +
19304 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19305 +               return -EFAULT;
19306 +       return ret;
19307 +}
19308 +
19309 +
19310 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
19311 +
19312 +static match_table_t tokens = {
19313 +       {Opt_notagcheck, "notagcheck"},
19314 +#ifdef CONFIG_PROPAGATE
19315 +       {Opt_notag, "notag"},
19316 +       {Opt_tag, "tag"},
19317 +       {Opt_tagid, "tagid=%u"},
19318 +#endif
19319 +       {Opt_err, NULL}
19320 +};
19321 +
19322 +
19323 +static void __dx_parse_remove(char *string, char *opt)
19324 +{
19325 +       char *p = strstr(string, opt);
19326 +       char *q = p;
19327 +
19328 +       if (p) {
19329 +               while (*q != '\0' && *q != ',')
19330 +                       q++;
19331 +               while (*q)
19332 +                       *p++ = *q++;
19333 +               while (*p)
19334 +                       *p++ = '\0';
19335 +       }
19336 +}
19337 +
19338 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
19339 +                unsigned long *flags)
19340 +{
19341 +       int set = 0;
19342 +       substring_t args[MAX_OPT_ARGS];
19343 +       int token;
19344 +       char *s, *p, *opts;
19345 +#if defined(CONFIG_PROPAGATE) || defined(CONFIG_VSERVER_DEBUG)
19346 +       int option = 0;
19347 +#endif
19348 +
19349 +       if (!string)
19350 +               return 0;
19351 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
19352 +       if (!s)
19353 +               return 0;
19354 +
19355 +       opts = s;
19356 +       while ((p = strsep(&opts, ",")) != NULL) {
19357 +               token = match_token(p, tokens, args);
19358 +
19359 +               switch (token) {
19360 +#ifdef CONFIG_PROPAGATE
19361 +               case Opt_tag:
19362 +                       if (tag)
19363 +                               *tag = 0;
19364 +                       if (remove)
19365 +                               __dx_parse_remove(s, "tag");
19366 +                       *mnt_flags |= MNT_TAGID;
19367 +                       set |= MNT_TAGID;
19368 +                       break;
19369 +               case Opt_notag:
19370 +                       if (remove)
19371 +                               __dx_parse_remove(s, "notag");
19372 +                       *mnt_flags |= MNT_NOTAG;
19373 +                       set |= MNT_NOTAG;
19374 +                       break;
19375 +               case Opt_tagid:
19376 +                       if (tag && !match_int(args, &option))
19377 +                               *tag = option;
19378 +                       if (remove)
19379 +                               __dx_parse_remove(s, "tagid");
19380 +                       *mnt_flags |= MNT_TAGID;
19381 +                       set |= MNT_TAGID;
19382 +                       break;
19383 +#endif /* CONFIG_PROPAGATE */
19384 +               case Opt_notagcheck:
19385 +                       if (remove)
19386 +                               __dx_parse_remove(s, "notagcheck");
19387 +                       *flags |= MS_NOTAGCHECK;
19388 +                       set |= MS_NOTAGCHECK;
19389 +                       break;
19390 +               }
19391 +               vxdprintk(VXD_CBIT(tag, 7),
19392 +                       "dx_parse_tag(" VS_Q("%s") "): %d:#%d",
19393 +                       p, token, option);
19394 +       }
19395 +       if (set)
19396 +               strcpy(string, s);
19397 +       kfree(s);
19398 +       return set;
19399 +}
19400 +
19401 +#ifdef CONFIG_PROPAGATE
19402 +
19403 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
19404 +{
19405 +       tag_t new_tag = 0;
19406 +       struct vfsmount *mnt;
19407 +       int propagate;
19408 +
19409 +       if (!nd)
19410 +               return;
19411 +       mnt = nd->path.mnt;
19412 +       if (!mnt)
19413 +               return;
19414 +
19415 +       propagate = (mnt->mnt_flags & MNT_TAGID);
19416 +       if (propagate)
19417 +               new_tag = mnt->mnt_tag;
19418 +
19419 +       vxdprintk(VXD_CBIT(tag, 7),
19420 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
19421 +               inode, inode->i_ino, inode->i_tag,
19422 +               new_tag, (propagate) ? 1 : 0);
19423 +
19424 +       if (propagate)
19425 +               i_tag_write(inode, new_tag);
19426 +}
19427 +
19428 +#include <linux/module.h>
19429 +
19430 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
19431 +
19432 +#endif /* CONFIG_PROPAGATE */
19433 +
19434 diff -NurpP --minimal linux-3.9.4/kernel/vserver/limit.c linux-3.9.4-vs2.3.6.3/kernel/vserver/limit.c
19435 --- linux-3.9.4/kernel/vserver/limit.c  1970-01-01 00:00:00.000000000 +0000
19436 +++ linux-3.9.4-vs2.3.6.3/kernel/vserver/limit.c        2013-05-31 14:47:11.000000000 +0000
19437 @@ -0,0 +1,345 @@
19438 +/*
19439 + *  linux/kernel/vserver/limit.c
19440 + *
19441 + *  Virtual Server: Context Limits
19442 + *
19443 + *  Copyright (C) 2004-2010  Herbert Pötzl
19444 + *
19445 + *  V0.01  broken out from vcontext V0.05
19446 + *  V0.02  changed vcmds to vxi arg
19447 + *  V0.03  added memory cgroup support
19448 + *
19449 + */
19450 +
19451 +#include <linux/sched.h>
19452 +#include <linux/module.h>
19453 +#include <linux/memcontrol.h>
19454 +#include <linux/res_counter.h>
19455 +#include <linux/vs_limit.h>
19456 +#include <linux/vserver/limit.h>
19457 +#include <linux/vserver/limit_cmd.h>
19458 +
19459 +#include <asm/uaccess.h>
19460 +
19461 +
19462 +const char *vlimit_name[NUM_LIMITS] = {
19463 +       [RLIMIT_CPU]            = "CPU",
19464 +       [RLIMIT_NPROC]          = "NPROC",
19465 +       [RLIMIT_NOFILE]         = "NOFILE",
19466 +       [RLIMIT_LOCKS]          = "LOCKS",
19467 +       [RLIMIT_SIGPENDING]     = "SIGP",
19468 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
19469 +
19470 +       [VLIMIT_NSOCK]          = "NSOCK",
19471 +       [VLIMIT_OPENFD]         = "OPENFD",
19472 +       [VLIMIT_SHMEM]          = "SHMEM",
19473 +       [VLIMIT_DENTRY]         = "DENTRY",
19474 +};
19475 +
19476 +EXPORT_SYMBOL_GPL(vlimit_name);
19477 +
19478 +#define MASK_ENTRY(x)  (1 << (x))
19479 +
19480 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
19481 +               /* minimum */
19482 +       0
19483 +       ,       /* softlimit */
19484 +       0
19485 +       ,       /* maximum */
19486 +       MASK_ENTRY( RLIMIT_NPROC        ) |
19487 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
19488 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
19489 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
19490 +
19491 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
19492 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
19493 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
19494 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
19495 +       0
19496 +};
19497 +               /* accounting only */
19498 +uint32_t account_mask =
19499 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
19500 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
19501 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
19502 +       0;
19503 +
19504 +
19505 +static int is_valid_vlimit(int id)
19506 +{
19507 +       uint32_t mask = vlimit_mask.minimum |
19508 +               vlimit_mask.softlimit | vlimit_mask.maximum;
19509 +       return mask & (1 << id);
19510 +}
19511 +
19512 +static int is_accounted_vlimit(int id)
19513 +{
19514 +       if (is_valid_vlimit(id))
19515 +               return 1;
19516 +       return account_mask & (1 << id);
19517 +}
19518 +
19519 +
19520 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
19521 +{
19522 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
19523 +       return VX_VLIM(limit);
19524 +}
19525 +
19526 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
19527 +{
19528 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
19529 +       return VX_VLIM(limit);
19530 +}
19531 +
19532 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
19533 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
19534 +{
19535 +       if (!is_valid_vlimit(id))
19536 +               return -EINVAL;
19537 +
19538 +       if (minimum)
19539 +               *minimum = CRLIM_UNSET;
19540 +       if (softlimit)
19541 +               *softlimit = vc_get_soft(vxi, id);
19542 +       if (maximum)
19543 +               *maximum = vc_get_hard(vxi, id);
19544 +       return 0;
19545 +}
19546 +
19547 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
19548 +{
19549 +       struct vcmd_ctx_rlimit_v0 vc_data;
19550 +       int ret;
19551 +
19552 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19553 +               return -EFAULT;
19554 +
19555 +       ret = do_get_rlimit(vxi, vc_data.id,
19556 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
19557 +       if (ret)
19558 +               return ret;
19559 +
19560 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19561 +               return -EFAULT;
19562 +       return 0;
19563 +}
19564 +
19565 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
19566 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
19567 +{
19568 +       if (!is_valid_vlimit(id))
19569 +               return -EINVAL;
19570 +
19571 +       if (maximum != CRLIM_KEEP)
19572 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
19573 +       if (softlimit != CRLIM_KEEP)
19574 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
19575 +
19576 +       /* clamp soft limit */
19577 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
19578 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
19579 +
19580 +       return 0;
19581 +}
19582 +
19583 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
19584 +{
19585 +       struct vcmd_ctx_rlimit_v0 vc_data;
19586 +
19587 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19588 +               return -EFAULT;
19589 +
19590 +       return do_set_rlimit(vxi, vc_data.id,
19591 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
19592 +}
19593 +
19594 +#ifdef CONFIG_IA32_EMULATION
19595 +
19596 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
19597 +{
19598 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
19599 +
19600 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19601 +               return -EFAULT;
19602 +
19603 +       return do_set_rlimit(vxi, vc_data.id,
19604 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
19605 +}
19606 +
19607 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
19608 +{
19609 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
19610 +       int ret;
19611 +
19612 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19613 +               return -EFAULT;
19614 +
19615 +       ret = do_get_rlimit(vxi, vc_data.id,
19616 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
19617 +       if (ret)
19618 +               return ret;
19619 +
19620 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19621 +               return -EFAULT;
19622 +       return 0;
19623 +}
19624 +
19625 +#endif /* CONFIG_IA32_EMULATION */
19626 +
19627 +
19628 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
19629 +{
19630 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
19631 +               return -EFAULT;
19632 +       return 0;
19633 +}
19634 +
19635 +
19636 +static inline void vx_reset_hits(struct _vx_limit *limit)
19637 +{
19638 +       int lim;
19639 +
19640 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19641 +               atomic_set(&__rlim_lhit(limit, lim), 0);
19642 +       }
19643 +}
19644 +
19645 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
19646 +{
19647 +       vx_reset_hits(&vxi->limit);
19648 +       return 0;
19649 +}
19650 +
19651 +static inline void vx_reset_minmax(struct _vx_limit *limit)
19652 +{
19653 +       rlim_t value;
19654 +       int lim;
19655 +
19656 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19657 +               value = __rlim_get(limit, lim);
19658 +               __rlim_rmax(limit, lim) = value;
19659 +               __rlim_rmin(limit, lim) = value;
19660 +       }
19661 +}
19662 +
19663 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
19664 +{
19665 +       vx_reset_minmax(&vxi->limit);
19666 +       return 0;
19667 +}
19668 +
19669 +
19670 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
19671 +{
19672 +       struct vcmd_rlimit_stat_v0 vc_data;
19673 +       struct _vx_limit *limit = &vxi->limit;
19674 +       int id;
19675 +
19676 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19677 +               return -EFAULT;
19678 +
19679 +       id = vc_data.id;
19680 +       if (!is_accounted_vlimit(id))
19681 +               return -EINVAL;
19682 +
19683 +       vx_limit_fixup(limit, id);
19684 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
19685 +       vc_data.value = __rlim_get(limit, id);
19686 +       vc_data.minimum = __rlim_rmin(limit, id);
19687 +       vc_data.maximum = __rlim_rmax(limit, id);
19688 +
19689 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19690 +               return -EFAULT;
19691 +       return 0;
19692 +}
19693 +
19694 +
19695 +void vx_vsi_meminfo(struct sysinfo *val)
19696 +{
19697 +#ifdef CONFIG_MEMCG
19698 +       struct mem_cgroup *mcg;
19699 +       u64 res_limit, res_usage;
19700 +
19701 +       rcu_read_lock();
19702 +       mcg = mem_cgroup_from_task(current);
19703 +       rcu_read_unlock();
19704 +       if (!mcg)
19705 +               goto out;
19706 +
19707 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
19708 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
19709 +
19710 +       if (res_limit != RESOURCE_MAX)
19711 +               val->totalram = (res_limit >> PAGE_SHIFT);
19712 +       val->freeram = val->totalram - (res_usage >> PAGE_SHIFT);
19713 +       val->bufferram = 0;
19714 +       val->totalhigh = 0;
19715 +       val->freehigh = 0;
19716 +out:
19717 +#endif /* CONFIG_MEMCG */
19718 +       return;
19719 +}
19720 +
19721 +void vx_vsi_swapinfo(struct sysinfo *val)
19722 +{
19723 +#ifdef CONFIG_MEMCG
19724 +#ifdef CONFIG_MEMCG_SWAP
19725 +       struct mem_cgroup *mcg;
19726 +       u64 res_limit, res_usage, memsw_limit, memsw_usage;
19727 +       s64 swap_limit, swap_usage;
19728 +
19729 +       rcu_read_lock();
19730 +       mcg = mem_cgroup_from_task(current);
19731 +       rcu_read_unlock();
19732 +       if (!mcg)
19733 +               goto out;
19734 +
19735 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
19736 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
19737 +       memsw_limit = mem_cgroup_memsw_read_u64(mcg, RES_LIMIT);
19738 +       memsw_usage = mem_cgroup_memsw_read_u64(mcg, RES_USAGE);
19739 +
19740 +       /* memory unlimited */
19741 +       if (res_limit == RESOURCE_MAX)
19742 +               goto out;
19743 +
19744 +       swap_limit = memsw_limit - res_limit;
19745 +       /* we have a swap limit? */
19746 +       if (memsw_limit != RESOURCE_MAX)
19747 +               val->totalswap = swap_limit >> PAGE_SHIFT;
19748 +
19749 +       /* calculate swap part */
19750 +       swap_usage = (memsw_usage > res_usage) ?
19751 +               memsw_usage - res_usage : 0;
19752 +
19753 +       /* total shown minus usage gives free swap */
19754 +       val->freeswap = (swap_usage < swap_limit) ?
19755 +               val->totalswap - (swap_usage >> PAGE_SHIFT) : 0;
19756 +out:
19757 +#else  /* !CONFIG_MEMCG_SWAP */
19758 +       val->totalswap = 0;
19759 +       val->freeswap = 0;
19760 +#endif /* !CONFIG_MEMCG_SWAP */
19761 +#endif /* CONFIG_MEMCG */
19762 +       return;
19763 +}
19764 +
19765 +long vx_vsi_cached(struct sysinfo *val)
19766 +{
19767 +       long cache = 0;
19768 +#ifdef CONFIG_MEMCG
19769 +       struct mem_cgroup *mcg;
19770 +
19771 +       rcu_read_lock();
19772 +       mcg = mem_cgroup_from_task(current);
19773 +       rcu_read_unlock();
19774 +       if (!mcg)
19775 +               goto out;
19776 +
19777 +       cache = mem_cgroup_stat_read_cache(mcg);
19778 +out:
19779 +#endif
19780 +       return cache;
19781 +}
19782 +
19783 diff -NurpP --minimal linux-3.9.4/kernel/vserver/limit_init.h linux-3.9.4-vs2.3.6.3/kernel/vserver/limit_init.h
19784 --- linux-3.9.4/kernel/vserver/limit_init.h     1970-01-01 00:00:00.000000000 +0000
19785 +++ linux-3.9.4-vs2.3.6.3/kernel/vserver/limit_init.h   2013-05-31 14:47:11.000000000 +0000
19786 @@ -0,0 +1,31 @@
19787 +
19788 +
19789 +static inline void vx_info_init_limit(struct _vx_limit *limit)
19790 +{
19791 +       int lim;
19792 +
19793 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19794 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
19795 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
19796 +               __rlim_set(limit, lim, 0);
19797 +               atomic_set(&__rlim_lhit(limit, lim), 0);
19798 +               __rlim_rmin(limit, lim) = 0;
19799 +               __rlim_rmax(limit, lim) = 0;
19800 +       }
19801 +}
19802 +
19803 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
19804 +{
19805 +       rlim_t value;
19806 +       int lim;
19807 +
19808 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19809 +               if ((1 << lim) & VLIM_NOCHECK)
19810 +                       continue;
19811 +               value = __rlim_get(limit, lim);
19812 +               vxwprintk_xid(value,
19813 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
19814 +                       limit, vlimit_name[lim], lim, (long)value);
19815 +       }
19816 +}
19817 +
19818 diff -NurpP --minimal linux-3.9.4/kernel/vserver/limit_proc.h linux-3.9.4-vs2.3.6.3/kernel/vserver/limit_proc.h
19819 --- linux-3.9.4/kernel/vserver/limit_proc.h     1970-01-01 00:00:00.000000000 +0000
19820 +++ linux-3.9.4-vs2.3.6.3/kernel/vserver/limit_proc.h   2013-05-31 14:47:11.000000000 +0000
19821 @@ -0,0 +1,57 @@
19822 +#ifndef _VX_LIMIT_PROC_H
19823 +#define _VX_LIMIT_PROC_H
19824 +
19825 +#include <linux/vserver/limit_int.h>
19826 +
19827 +
19828 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
19829 +#define VX_LIMIT_TOP   \
19830 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
19831 +
19832 +#define VX_LIMIT_ARG(r)                                \
19833 +       (unsigned long)__rlim_get(limit, r),    \
19834 +       (unsigned long)__rlim_rmin(limit, r),   \
19835 +       (unsigned long)__rlim_rmax(limit, r),   \
19836 +       VX_VLIM(__rlim_soft(limit, r)),         \
19837 +       VX_VLIM(__rlim_hard(limit, r)),         \
19838 +       atomic_read(&__rlim_lhit(limit, r))
19839 +
19840 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
19841 +{
19842 +       vx_limit_fixup(limit, -1);
19843 +       return sprintf(buffer, VX_LIMIT_TOP
19844 +               "PROC"  VX_LIMIT_FMT
19845 +               "VM"    VX_LIMIT_FMT
19846 +               "VML"   VX_LIMIT_FMT
19847 +               "RSS"   VX_LIMIT_FMT
19848 +               "ANON"  VX_LIMIT_FMT
19849 +               "RMAP"  VX_LIMIT_FMT
19850 +               "FILES" VX_LIMIT_FMT
19851 +               "OFD"   VX_LIMIT_FMT
19852 +               "LOCKS" VX_LIMIT_FMT
19853 +               "SOCK"  VX_LIMIT_FMT
19854 +               "MSGQ"  VX_LIMIT_FMT
19855 +               "SHM"   VX_LIMIT_FMT
19856 +               "SEMA"  VX_LIMIT_FMT
19857 +               "SEMS"  VX_LIMIT_FMT
19858 +               "DENT"  VX_LIMIT_FMT,
19859 +               VX_LIMIT_ARG(RLIMIT_NPROC),
19860 +               VX_LIMIT_ARG(RLIMIT_AS),
19861 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
19862 +               VX_LIMIT_ARG(RLIMIT_RSS),
19863 +               VX_LIMIT_ARG(VLIMIT_ANON),
19864 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
19865 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
19866 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
19867 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
19868 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
19869 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
19870 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
19871 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
19872 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
19873 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
19874 +}
19875 +
19876 +#endif /* _VX_LIMIT_PROC_H */
19877 +
19878 +
19879 diff -NurpP --minimal linux-3.9.4/kernel/vserver/network.c linux-3.9.4-vs2.3.6.3/kernel/vserver/network.c
19880 --- linux-3.9.4/kernel/vserver/network.c        1970-01-01 00:00:00.000000000 +0000
19881 +++ linux-3.9.4-vs2.3.6.3/kernel/vserver/network.c      2013-05-31 14:47:11.000000000 +0000
19882 @@ -0,0 +1,1053 @@
19883 +/*
19884 + *  linux/kernel/vserver/network.c
19885 + *
19886 + *  Virtual Server: Network Support
19887 + *
19888 + *  Copyright (C) 2003-2007  Herbert Pötzl
19889 + *
19890 + *  V0.01  broken out from vcontext V0.05
19891 + *  V0.02  cleaned up implementation
19892 + *  V0.03  added equiv nx commands
19893 + *  V0.04  switch to RCU based hash
19894 + *  V0.05  and back to locking again
19895 + *  V0.06  changed vcmds to nxi arg
19896 + *  V0.07  have __create claim() the nxi
19897 + *
19898 + */
19899 +
19900 +#include <linux/err.h>
19901 +#include <linux/slab.h>
19902 +#include <linux/rcupdate.h>
19903 +#include <net/ipv6.h>
19904 +
19905 +#include <linux/vs_network.h>
19906 +#include <linux/vs_pid.h>
19907 +#include <linux/vserver/network_cmd.h>
19908 +
19909 +
19910 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
19911 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
19912 +
19913 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
19914 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
19915 +
19916 +
19917 +static int __init init_network(void)
19918 +{
19919 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
19920 +               sizeof(struct nx_addr_v4), 0,
19921 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19922 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
19923 +               sizeof(struct nx_addr_v6), 0,
19924 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19925 +       return 0;
19926 +}
19927 +
19928 +
19929 +/*     __alloc_nx_addr_v4()                                    */
19930 +
19931 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
19932 +{
19933 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
19934 +               nx_addr_v4_cachep, GFP_KERNEL);
19935 +
19936 +       if (!IS_ERR(nxa))
19937 +               memset(nxa, 0, sizeof(*nxa));
19938 +       return nxa;
19939 +}
19940 +
19941 +/*     __dealloc_nx_addr_v4()                                  */
19942 +
19943 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
19944 +{
19945 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
19946 +}
19947 +
19948 +/*     __dealloc_nx_addr_v4_all()                              */
19949 +
19950 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
19951 +{
19952 +       while (nxa) {
19953 +               struct nx_addr_v4 *next = nxa->next;
19954 +
19955 +               __dealloc_nx_addr_v4(nxa);
19956 +               nxa = next;
19957 +       }
19958 +}
19959 +
19960 +
19961 +#ifdef CONFIG_IPV6
19962 +
19963 +/*     __alloc_nx_addr_v6()                                    */
19964 +
19965 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
19966 +{
19967 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
19968 +               nx_addr_v6_cachep, GFP_KERNEL);
19969 +
19970 +       if (!IS_ERR(nxa))
19971 +               memset(nxa, 0, sizeof(*nxa));
19972 +       return nxa;
19973 +}
19974 +
19975 +/*     __dealloc_nx_addr_v6()                                  */
19976 +
19977 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
19978 +{
19979 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
19980 +}
19981 +
19982 +/*     __dealloc_nx_addr_v6_all()                              */
19983 +
19984 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
19985 +{
19986 +       while (nxa) {
19987 +               struct nx_addr_v6 *next = nxa->next;
19988 +
19989 +               __dealloc_nx_addr_v6(nxa);
19990 +               nxa = next;
19991 +       }
19992 +}
19993 +
19994 +#endif /* CONFIG_IPV6 */
19995 +
19996 +/*     __alloc_nx_info()
19997 +
19998 +       * allocate an initialized nx_info struct
19999 +       * doesn't make it visible (hash)                        */
20000 +
20001 +static struct nx_info *__alloc_nx_info(nid_t nid)
20002 +{
20003 +       struct nx_info *new = NULL;
20004 +
20005 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
20006 +
20007 +       /* would this benefit from a slab cache? */
20008 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
20009 +       if (!new)
20010 +               return 0;
20011 +
20012 +       memset(new, 0, sizeof(struct nx_info));
20013 +       new->nx_id = nid;
20014 +       INIT_HLIST_NODE(&new->nx_hlist);
20015 +       atomic_set(&new->nx_usecnt, 0);
20016 +       atomic_set(&new->nx_tasks, 0);
20017 +       spin_lock_init(&new->addr_lock);
20018 +       new->nx_state = 0;
20019 +
20020 +       new->nx_flags = NXF_INIT_SET;
20021 +
20022 +       /* rest of init goes here */
20023 +
20024 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
20025 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
20026 +
20027 +       vxdprintk(VXD_CBIT(nid, 0),
20028 +               "alloc_nx_info(%d) = %p", nid, new);
20029 +       atomic_inc(&nx_global_ctotal);
20030 +       return new;
20031 +}
20032 +
20033 +/*     __dealloc_nx_info()
20034 +
20035 +       * final disposal of nx_info                             */
20036 +
20037 +static void __dealloc_nx_info(struct nx_info *nxi)
20038 +{
20039 +       vxdprintk(VXD_CBIT(nid, 0),
20040 +               "dealloc_nx_info(%p)", nxi);
20041 +
20042 +       nxi->nx_hlist.next = LIST_POISON1;
20043 +       nxi->nx_id = -1;
20044 +
20045 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20046 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20047 +
20048 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
20049 +#ifdef CONFIG_IPV6
20050 +       __dealloc_nx_addr_v6_all(nxi->v6.next);
20051 +#endif
20052 +
20053 +       nxi->nx_state |= NXS_RELEASED;
20054 +       kfree(nxi);
20055 +       atomic_dec(&nx_global_ctotal);
20056 +}
20057 +
20058 +static void __shutdown_nx_info(struct nx_info *nxi)
20059 +{
20060 +       nxi->nx_state |= NXS_SHUTDOWN;
20061 +       vs_net_change(nxi, VSC_NETDOWN);
20062 +}
20063 +
20064 +/*     exported stuff                                          */
20065 +
20066 +void free_nx_info(struct nx_info *nxi)
20067 +{
20068 +       /* context shutdown is mandatory */
20069 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
20070 +
20071 +       /* context must not be hashed */
20072 +       BUG_ON(nxi->nx_state & NXS_HASHED);
20073 +
20074 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20075 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20076 +
20077 +       __dealloc_nx_info(nxi);
20078 +}
20079 +
20080 +
20081 +void __nx_set_lback(struct nx_info *nxi)
20082 +{
20083 +       int nid = nxi->nx_id;
20084 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
20085 +
20086 +       nxi->v4_lback.s_addr = lback;
20087 +}
20088 +
20089 +extern int __nx_inet_add_lback(__be32 addr);
20090 +extern int __nx_inet_del_lback(__be32 addr);
20091 +
20092 +
20093 +/*     hash table for nx_info hash */
20094 +
20095 +#define NX_HASH_SIZE   13
20096 +
20097 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
20098 +
20099 +static DEFINE_SPINLOCK(nx_info_hash_lock);
20100 +
20101 +
20102 +static inline unsigned int __hashval(nid_t nid)
20103 +{
20104 +       return (nid % NX_HASH_SIZE);
20105 +}
20106 +
20107 +
20108 +
20109 +/*     __hash_nx_info()
20110 +
20111 +       * add the nxi to the global hash table
20112 +       * requires the hash_lock to be held                     */
20113 +
20114 +static inline void __hash_nx_info(struct nx_info *nxi)
20115 +{
20116 +       struct hlist_head *head;
20117 +
20118 +       vxd_assert_lock(&nx_info_hash_lock);
20119 +       vxdprintk(VXD_CBIT(nid, 4),
20120 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
20121 +
20122 +       /* context must not be hashed */
20123 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
20124 +
20125 +       nxi->nx_state |= NXS_HASHED;
20126 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
20127 +       hlist_add_head(&nxi->nx_hlist, head);
20128 +       atomic_inc(&nx_global_cactive);
20129 +}
20130 +
20131 +/*     __unhash_nx_info()
20132 +
20133 +       * remove the nxi from the global hash table
20134 +       * requires the hash_lock to be held                     */
20135 +
20136 +static inline void __unhash_nx_info(struct nx_info *nxi)
20137 +{
20138 +       vxd_assert_lock(&nx_info_hash_lock);
20139 +       vxdprintk(VXD_CBIT(nid, 4),
20140 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
20141 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
20142 +
20143 +       /* context must be hashed */
20144 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
20145 +       /* but without tasks */
20146 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20147 +
20148 +       nxi->nx_state &= ~NXS_HASHED;
20149 +       hlist_del(&nxi->nx_hlist);
20150 +       atomic_dec(&nx_global_cactive);
20151 +}
20152 +
20153 +
20154 +/*     __lookup_nx_info()
20155 +
20156 +       * requires the hash_lock to be held
20157 +       * doesn't increment the nx_refcnt                       */
20158 +
20159 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
20160 +{
20161 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
20162 +       struct hlist_node *pos;
20163 +       struct nx_info *nxi;
20164 +
20165 +       vxd_assert_lock(&nx_info_hash_lock);
20166 +       hlist_for_each(pos, head) {
20167 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20168 +
20169 +               if (nxi->nx_id == nid)
20170 +                       goto found;
20171 +       }
20172 +       nxi = NULL;
20173 +found:
20174 +       vxdprintk(VXD_CBIT(nid, 0),
20175 +               "__lookup_nx_info(#%u): %p[#%u]",
20176 +               nid, nxi, nxi ? nxi->nx_id : 0);
20177 +       return nxi;
20178 +}
20179 +
20180 +
20181 +/*     __create_nx_info()
20182 +
20183 +       * create the requested context
20184 +       * get(), claim() and hash it                            */
20185 +
20186 +static struct nx_info *__create_nx_info(int id)
20187 +{
20188 +       struct nx_info *new, *nxi = NULL;
20189 +
20190 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
20191 +
20192 +       if (!(new = __alloc_nx_info(id)))
20193 +               return ERR_PTR(-ENOMEM);
20194 +
20195 +       /* required to make dynamic xids unique */
20196 +       spin_lock(&nx_info_hash_lock);
20197 +
20198 +       /* static context requested */
20199 +       if ((nxi = __lookup_nx_info(id))) {
20200 +               vxdprintk(VXD_CBIT(nid, 0),
20201 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
20202 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20203 +                       nxi = ERR_PTR(-EBUSY);
20204 +               else
20205 +                       nxi = ERR_PTR(-EEXIST);
20206 +               goto out_unlock;
20207 +       }
20208 +       /* new context */
20209 +       vxdprintk(VXD_CBIT(nid, 0),
20210 +               "create_nx_info(%d) = %p (new)", id, new);
20211 +       claim_nx_info(new, NULL);
20212 +       __nx_set_lback(new);
20213 +       __hash_nx_info(get_nx_info(new));
20214 +       nxi = new, new = NULL;
20215 +
20216 +out_unlock:
20217 +       spin_unlock(&nx_info_hash_lock);
20218 +       if (new)
20219 +               __dealloc_nx_info(new);
20220 +       return nxi;
20221 +}
20222 +
20223 +
20224 +
20225 +/*     exported stuff                                          */
20226 +
20227 +
20228 +void unhash_nx_info(struct nx_info *nxi)
20229 +{
20230 +       __shutdown_nx_info(nxi);
20231 +       spin_lock(&nx_info_hash_lock);
20232 +       __unhash_nx_info(nxi);
20233 +       spin_unlock(&nx_info_hash_lock);
20234 +}
20235 +
20236 +/*     lookup_nx_info()
20237 +
20238 +       * search for a nx_info and get() it
20239 +       * negative id means current                             */
20240 +
20241 +struct nx_info *lookup_nx_info(int id)
20242 +{
20243 +       struct nx_info *nxi = NULL;
20244 +
20245 +       if (id < 0) {
20246 +               nxi = get_nx_info(current_nx_info());
20247 +       } else if (id > 1) {
20248 +               spin_lock(&nx_info_hash_lock);
20249 +               nxi = get_nx_info(__lookup_nx_info(id));
20250 +               spin_unlock(&nx_info_hash_lock);
20251 +       }
20252 +       return nxi;
20253 +}
20254 +
20255 +/*     nid_is_hashed()
20256 +
20257 +       * verify that nid is still hashed                       */
20258 +
20259 +int nid_is_hashed(nid_t nid)
20260 +{
20261 +       int hashed;
20262 +
20263 +       spin_lock(&nx_info_hash_lock);
20264 +       hashed = (__lookup_nx_info(nid) != NULL);
20265 +       spin_unlock(&nx_info_hash_lock);
20266 +       return hashed;
20267 +}
20268 +
20269 +
20270 +#ifdef CONFIG_PROC_FS
20271 +
20272 +/*     get_nid_list()
20273 +
20274 +       * get a subset of hashed nids for proc
20275 +       * assumes size is at least one                          */
20276 +
20277 +int get_nid_list(int index, unsigned int *nids, int size)
20278 +{
20279 +       int hindex, nr_nids = 0;
20280 +
20281 +       /* only show current and children */
20282 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
20283 +               if (index > 0)
20284 +                       return 0;
20285 +               nids[nr_nids] = nx_current_nid();
20286 +               return 1;
20287 +       }
20288 +
20289 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
20290 +               struct hlist_head *head = &nx_info_hash[hindex];
20291 +               struct hlist_node *pos;
20292 +
20293 +               spin_lock(&nx_info_hash_lock);
20294 +               hlist_for_each(pos, head) {
20295 +                       struct nx_info *nxi;
20296 +
20297 +                       if (--index > 0)
20298 +                               continue;
20299 +
20300 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20301 +                       nids[nr_nids] = nxi->nx_id;
20302 +                       if (++nr_nids >= size) {
20303 +                               spin_unlock(&nx_info_hash_lock);
20304 +                               goto out;
20305 +                       }
20306 +               }
20307 +               /* keep the lock time short */
20308 +               spin_unlock(&nx_info_hash_lock);
20309 +       }
20310 +out:
20311 +       return nr_nids;
20312 +}
20313 +#endif
20314 +
20315 +
20316 +/*
20317 + *     migrate task to new network
20318 + *     gets nxi, puts old_nxi on change
20319 + */
20320 +
20321 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
20322 +{
20323 +       struct nx_info *old_nxi;
20324 +       int ret = 0;
20325 +
20326 +       if (!p || !nxi)
20327 +               BUG();
20328 +
20329 +       vxdprintk(VXD_CBIT(nid, 5),
20330 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
20331 +               p, nxi, nxi->nx_id,
20332 +               atomic_read(&nxi->nx_usecnt),
20333 +               atomic_read(&nxi->nx_tasks));
20334 +
20335 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
20336 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20337 +               return -EACCES;
20338 +
20339 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
20340 +               return -EFAULT;
20341 +
20342 +       /* maybe disallow this completely? */
20343 +       old_nxi = task_get_nx_info(p);
20344 +       if (old_nxi == nxi)
20345 +               goto out;
20346 +
20347 +       task_lock(p);
20348 +       if (old_nxi)
20349 +               clr_nx_info(&p->nx_info);
20350 +       claim_nx_info(nxi, p);
20351 +       set_nx_info(&p->nx_info, nxi);
20352 +       p->nid = nxi->nx_id;
20353 +       task_unlock(p);
20354 +
20355 +       vxdprintk(VXD_CBIT(nid, 5),
20356 +               "moved task %p into nxi:%p[#%d]",
20357 +               p, nxi, nxi->nx_id);
20358 +
20359 +       if (old_nxi)
20360 +               release_nx_info(old_nxi, p);
20361 +       ret = 0;
20362 +out:
20363 +       put_nx_info(old_nxi);
20364 +       return ret;
20365 +}
20366 +
20367 +
20368 +void nx_set_persistent(struct nx_info *nxi)
20369 +{
20370 +       vxdprintk(VXD_CBIT(nid, 6),
20371 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
20372 +
20373 +       get_nx_info(nxi);
20374 +       claim_nx_info(nxi, NULL);
20375 +}
20376 +
20377 +void nx_clear_persistent(struct nx_info *nxi)
20378 +{
20379 +       vxdprintk(VXD_CBIT(nid, 6),
20380 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
20381 +
20382 +       release_nx_info(nxi, NULL);
20383 +       put_nx_info(nxi);
20384 +}
20385 +
20386 +void nx_update_persistent(struct nx_info *nxi)
20387 +{
20388 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
20389 +               nx_set_persistent(nxi);
20390 +       else
20391 +               nx_clear_persistent(nxi);
20392 +}
20393 +
20394 +/* vserver syscall commands below here */
20395 +
20396 +/* taks nid and nx_info functions */
20397 +
20398 +#include <asm/uaccess.h>
20399 +
20400 +
20401 +int vc_task_nid(uint32_t id)
20402 +{
20403 +       nid_t nid;
20404 +
20405 +       if (id) {
20406 +               struct task_struct *tsk;
20407 +
20408 +               rcu_read_lock();
20409 +               tsk = find_task_by_real_pid(id);
20410 +               nid = (tsk) ? tsk->nid : -ESRCH;
20411 +               rcu_read_unlock();
20412 +       } else
20413 +               nid = nx_current_nid();
20414 +       return nid;
20415 +}
20416 +
20417 +
20418 +int vc_nx_info(struct nx_info *nxi, void __user *data)
20419 +{
20420 +       struct vcmd_nx_info_v0 vc_data;
20421 +
20422 +       vc_data.nid = nxi->nx_id;
20423 +
20424 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20425 +               return -EFAULT;
20426 +       return 0;
20427 +}
20428 +
20429 +
20430 +/* network functions */
20431 +
20432 +int vc_net_create(uint32_t nid, void __user *data)
20433 +{
20434 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
20435 +       struct nx_info *new_nxi;
20436 +       int ret;
20437 +
20438 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20439 +               return -EFAULT;
20440 +
20441 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
20442 +               return -EINVAL;
20443 +
20444 +       new_nxi = __create_nx_info(nid);
20445 +       if (IS_ERR(new_nxi))
20446 +               return PTR_ERR(new_nxi);
20447 +
20448 +       /* initial flags */
20449 +       new_nxi->nx_flags = vc_data.flagword;
20450 +
20451 +       ret = -ENOEXEC;
20452 +       if (vs_net_change(new_nxi, VSC_NETUP))
20453 +               goto out;
20454 +
20455 +       ret = nx_migrate_task(current, new_nxi);
20456 +       if (ret)
20457 +               goto out;
20458 +
20459 +       /* return context id on success */
20460 +       ret = new_nxi->nx_id;
20461 +
20462 +       /* get a reference for persistent contexts */
20463 +       if ((vc_data.flagword & NXF_PERSISTENT))
20464 +               nx_set_persistent(new_nxi);
20465 +out:
20466 +       release_nx_info(new_nxi, NULL);
20467 +       put_nx_info(new_nxi);
20468 +       return ret;
20469 +}
20470 +
20471 +
20472 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
20473 +{
20474 +       return nx_migrate_task(current, nxi);
20475 +}
20476 +
20477 +
20478 +static inline
20479 +struct nx_addr_v4 *__find_v4_addr(struct nx_info *nxi,
20480 +       __be32 ip, __be32 ip2, __be32 mask, uint16_t type, uint16_t flags,
20481 +       struct nx_addr_v4 **prev)
20482 +{
20483 +       struct nx_addr_v4 *nxa = &nxi->v4;
20484 +
20485 +       for (; nxa; nxa = nxa->next) {
20486 +               if ((nxa->ip[0].s_addr == ip) &&
20487 +                   (nxa->ip[1].s_addr == ip2) &&
20488 +                   (nxa->mask.s_addr == mask) &&
20489 +                   (nxa->type == type) &&
20490 +                   (nxa->flags == flags))
20491 +                   return nxa;
20492 +
20493 +               /* save previous entry */
20494 +               if (prev)
20495 +                       *prev = nxa;
20496 +       }
20497 +       return NULL;
20498 +}
20499 +
20500 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
20501 +       uint16_t type, uint16_t flags)
20502 +{
20503 +       struct nx_addr_v4 *nxa = NULL;
20504 +       struct nx_addr_v4 *new = __alloc_nx_addr_v4();
20505 +       unsigned long irqflags;
20506 +       int ret = -EEXIST;
20507 +
20508 +       if (IS_ERR(new))
20509 +               return PTR_ERR(new);
20510 +
20511 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
20512 +       if (__find_v4_addr(nxi, ip, ip2, mask, type, flags, &nxa))
20513 +               goto out_unlock;
20514 +
20515 +       if (NX_IPV4(nxi)) {
20516 +               nxa->next = new;
20517 +               nxa = new;
20518 +               new = NULL;
20519 +
20520 +               /* remove single ip for ip list */
20521 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
20522 +       }
20523 +
20524 +       nxa->ip[0].s_addr = ip;
20525 +       nxa->ip[1].s_addr = ip2;
20526 +       nxa->mask.s_addr = mask;
20527 +       nxa->type = type;
20528 +       nxa->flags = flags;
20529 +       ret = 0;
20530 +out_unlock:
20531 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20532 +       if (new)
20533 +               __dealloc_nx_addr_v4(new);
20534 +       return ret;
20535 +}
20536 +
20537 +int do_remove_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
20538 +       uint16_t type, uint16_t flags)
20539 +{
20540 +       struct nx_addr_v4 *nxa = NULL;
20541 +       struct nx_addr_v4 *old = NULL;
20542 +       unsigned long irqflags;
20543 +       int ret = 0;
20544 +
20545 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
20546 +       switch (type) {
20547 +       case NXA_TYPE_ADDR:
20548 +               old = __find_v4_addr(nxi, ip, ip2, mask, type, flags, &nxa);
20549 +               if (old) {
20550 +                       if (nxa) {
20551 +                               nxa->next = old->next;
20552 +                               old->next = NULL;
20553 +                       } else {
20554 +                               if (old->next) {
20555 +                                       nxa = old;
20556 +                                       old = old->next;
20557 +                                       *nxa = *old;
20558 +                                       old->next = NULL;
20559 +                               } else {
20560 +                                       memset(old, 0, sizeof(*old));
20561 +                                       old = NULL;
20562 +                               }
20563 +                       }
20564 +               } else
20565 +                       ret = -ESRCH;
20566 +               break;
20567 +
20568 +       case NXA_TYPE_ANY:
20569 +               nxa = &nxi->v4;
20570 +               old = nxa->next;
20571 +               memset(nxa, 0, sizeof(*nxa));
20572 +               break;
20573 +
20574 +       default:
20575 +               ret = -EINVAL;
20576 +       }
20577 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20578 +       __dealloc_nx_addr_v4_all(old);
20579 +       return ret;
20580 +}
20581 +
20582 +
20583 +int vc_net_add(struct nx_info *nxi, void __user *data)
20584 +{
20585 +       struct vcmd_net_addr_v0 vc_data;
20586 +       int index, ret = 0;
20587 +
20588 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20589 +               return -EFAULT;
20590 +
20591 +       switch (vc_data.type) {
20592 +       case NXA_TYPE_IPV4:
20593 +               if ((vc_data.count < 1) || (vc_data.count > 4))
20594 +                       return -EINVAL;
20595 +
20596 +               index = 0;
20597 +               while (index < vc_data.count) {
20598 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
20599 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
20600 +                       if (ret)
20601 +                               return ret;
20602 +                       index++;
20603 +               }
20604 +               ret = index;
20605 +               break;
20606 +
20607 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
20608 +               nxi->v4_bcast = vc_data.ip[0];
20609 +               ret = 1;
20610 +               break;
20611 +
20612 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
20613 +               nxi->v4_lback = vc_data.ip[0];
20614 +               ret = 1;
20615 +               break;
20616 +
20617 +       default:
20618 +               ret = -EINVAL;
20619 +               break;
20620 +       }
20621 +       return ret;
20622 +}
20623 +
20624 +int vc_net_remove(struct nx_info *nxi, void __user *data)
20625 +{
20626 +       struct vcmd_net_addr_v0 vc_data;
20627 +
20628 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20629 +               return -EFAULT;
20630 +
20631 +       switch (vc_data.type) {
20632 +       case NXA_TYPE_ANY:
20633 +               return do_remove_v4_addr(nxi, 0, 0, 0, vc_data.type, 0);
20634 +       default:
20635 +               return -EINVAL;
20636 +       }
20637 +       return 0;
20638 +}
20639 +
20640 +
20641 +int vc_net_add_ipv4_v1(struct nx_info *nxi, void __user *data)
20642 +{
20643 +       struct vcmd_net_addr_ipv4_v1 vc_data;
20644 +
20645 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20646 +               return -EFAULT;
20647 +
20648 +       switch (vc_data.type) {
20649 +       case NXA_TYPE_ADDR:
20650 +       case NXA_TYPE_MASK:
20651 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
20652 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20653 +
20654 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
20655 +               nxi->v4_bcast = vc_data.ip;
20656 +               break;
20657 +
20658 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
20659 +               nxi->v4_lback = vc_data.ip;
20660 +               break;
20661 +
20662 +       default:
20663 +               return -EINVAL;
20664 +       }
20665 +       return 0;
20666 +}
20667 +
20668 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
20669 +{
20670 +       struct vcmd_net_addr_ipv4_v2 vc_data;
20671 +
20672 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20673 +               return -EFAULT;
20674 +
20675 +       switch (vc_data.type) {
20676 +       case NXA_TYPE_ADDR:
20677 +       case NXA_TYPE_MASK:
20678 +       case NXA_TYPE_RANGE:
20679 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
20680 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20681 +
20682 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
20683 +               nxi->v4_bcast = vc_data.ip;
20684 +               break;
20685 +
20686 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
20687 +               nxi->v4_lback = vc_data.ip;
20688 +               break;
20689 +
20690 +       default:
20691 +               return -EINVAL;
20692 +       }
20693 +       return 0;
20694 +}
20695 +
20696 +int vc_net_rem_ipv4_v1(struct nx_info *nxi, void __user *data)
20697 +{
20698 +       struct vcmd_net_addr_ipv4_v1 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, 0,
20704 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20705 +}
20706 +
20707 +int vc_net_rem_ipv4(struct nx_info *nxi, void __user *data)
20708 +{
20709 +       struct vcmd_net_addr_ipv4_v2 vc_data;
20710 +
20711 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20712 +               return -EFAULT;
20713 +
20714 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
20715 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20716 +}
20717 +
20718 +#ifdef CONFIG_IPV6
20719 +
20720 +static inline
20721 +struct nx_addr_v6 *__find_v6_addr(struct nx_info *nxi,
20722 +       struct in6_addr *ip, struct in6_addr *mask,
20723 +       uint32_t prefix, uint16_t type, uint16_t flags,
20724 +       struct nx_addr_v6 **prev)
20725 +{
20726 +       struct nx_addr_v6 *nxa = &nxi->v6;
20727 +
20728 +       for (; nxa; nxa = nxa->next) {
20729 +               if (ipv6_addr_equal(&nxa->ip, ip) &&
20730 +                   ipv6_addr_equal(&nxa->mask, mask) &&
20731 +                   (nxa->prefix == prefix) &&
20732 +                   (nxa->type == type) &&
20733 +                   (nxa->flags == flags))
20734 +                   return nxa;
20735 +
20736 +               /* save previous entry */
20737 +               if (prev)
20738 +                       *prev = nxa;
20739 +       }
20740 +       return NULL;
20741 +}
20742 +
20743 +
20744 +int do_add_v6_addr(struct nx_info *nxi,
20745 +       struct in6_addr *ip, struct in6_addr *mask,
20746 +       uint32_t prefix, uint16_t type, uint16_t flags)
20747 +{
20748 +       struct nx_addr_v6 *nxa = NULL;
20749 +       struct nx_addr_v6 *new = __alloc_nx_addr_v6();
20750 +       unsigned long irqflags;
20751 +       int ret = -EEXIST;
20752 +
20753 +       if (IS_ERR(new))
20754 +               return PTR_ERR(new);
20755 +
20756 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
20757 +       if (__find_v6_addr(nxi, ip, mask, prefix, type, flags, &nxa))
20758 +               goto out_unlock;
20759 +
20760 +       if (NX_IPV6(nxi)) {
20761 +               nxa->next = new;
20762 +               nxa = new;
20763 +               new = NULL;
20764 +       }
20765 +
20766 +       nxa->ip = *ip;
20767 +       nxa->mask = *mask;
20768 +       nxa->prefix = prefix;
20769 +       nxa->type = type;
20770 +       nxa->flags = flags;
20771 +       ret = 0;
20772 +out_unlock:
20773 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20774 +       if (new)
20775 +               __dealloc_nx_addr_v6(new);
20776 +       return ret;
20777 +}
20778 +
20779 +int do_remove_v6_addr(struct nx_info *nxi,
20780 +       struct in6_addr *ip, struct in6_addr *mask,
20781 +       uint32_t prefix, uint16_t type, uint16_t flags)
20782 +{
20783 +       struct nx_addr_v6 *nxa = NULL;
20784 +       struct nx_addr_v6 *old = NULL;
20785 +       unsigned long irqflags;
20786 +       int ret = 0;
20787 +
20788 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
20789 +       switch (type) {
20790 +       case NXA_TYPE_ADDR:
20791 +               old = __find_v6_addr(nxi, ip, mask, prefix, type, flags, &nxa);
20792 +               if (old) {
20793 +                       if (nxa) {
20794 +                               nxa->next = old->next;
20795 +                               old->next = NULL;
20796 +                       } else {
20797 +                               if (old->next) {
20798 +                                       nxa = old;
20799 +                                       old = old->next;
20800 +                                       *nxa = *old;
20801 +                                       old->next = NULL;
20802 +                               } else {
20803 +                                       memset(old, 0, sizeof(*old));
20804 +                                       old = NULL;
20805 +                               }
20806 +                       }
20807 +               } else
20808 +                       ret = -ESRCH;
20809 +               break;
20810 +
20811 +       case NXA_TYPE_ANY:
20812 +               nxa = &nxi->v6;
20813 +               old = nxa->next;
20814 +               memset(nxa, 0, sizeof(*nxa));
20815 +               break;
20816 +
20817 +       default:
20818 +               ret = -EINVAL;
20819 +       }
20820 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20821 +       __dealloc_nx_addr_v6_all(old);
20822 +       return ret;
20823 +}
20824 +
20825 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
20826 +{
20827 +       struct vcmd_net_addr_ipv6_v1 vc_data;
20828 +
20829 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20830 +               return -EFAULT;
20831 +
20832 +       switch (vc_data.type) {
20833 +       case NXA_TYPE_ADDR:
20834 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
20835 +               /* fallthrough */
20836 +       case NXA_TYPE_MASK:
20837 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
20838 +                       vc_data.prefix, vc_data.type, vc_data.flags);
20839 +       default:
20840 +               return -EINVAL;
20841 +       }
20842 +       return 0;
20843 +}
20844 +
20845 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
20846 +{
20847 +       struct vcmd_net_addr_ipv6_v1 vc_data;
20848 +
20849 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20850 +               return -EFAULT;
20851 +
20852 +       switch (vc_data.type) {
20853 +       case NXA_TYPE_ADDR:
20854 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
20855 +               /* fallthrough */
20856 +       case NXA_TYPE_MASK:
20857 +               return do_remove_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
20858 +                       vc_data.prefix, vc_data.type, vc_data.flags);
20859 +       case NXA_TYPE_ANY:
20860 +               return do_remove_v6_addr(nxi, NULL, NULL, 0, vc_data.type, 0);
20861 +       default:
20862 +               return -EINVAL;
20863 +       }
20864 +       return 0;
20865 +}
20866 +
20867 +#endif /* CONFIG_IPV6 */
20868 +
20869 +
20870 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
20871 +{
20872 +       struct vcmd_net_flags_v0 vc_data;
20873 +
20874 +       vc_data.flagword = nxi->nx_flags;
20875 +
20876 +       /* special STATE flag handling */
20877 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
20878 +
20879 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20880 +               return -EFAULT;
20881 +       return 0;
20882 +}
20883 +
20884 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
20885 +{
20886 +       struct vcmd_net_flags_v0 vc_data;
20887 +       uint64_t mask, trigger;
20888 +
20889 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20890 +               return -EFAULT;
20891 +
20892 +       /* special STATE flag handling */
20893 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
20894 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
20895 +
20896 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
20897 +               vc_data.flagword, mask);
20898 +       if (trigger & NXF_PERSISTENT)
20899 +               nx_update_persistent(nxi);
20900 +
20901 +       return 0;
20902 +}
20903 +
20904 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
20905 +{
20906 +       struct vcmd_net_caps_v0 vc_data;
20907 +
20908 +       vc_data.ncaps = nxi->nx_ncaps;
20909 +       vc_data.cmask = ~0ULL;
20910 +
20911 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20912 +               return -EFAULT;
20913 +       return 0;
20914 +}
20915 +
20916 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
20917 +{
20918 +       struct vcmd_net_caps_v0 vc_data;
20919 +
20920 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20921 +               return -EFAULT;
20922 +
20923 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
20924 +               vc_data.ncaps, vc_data.cmask);
20925 +       return 0;
20926 +}
20927 +
20928 +
20929 +#include <linux/module.h>
20930 +
20931 +module_init(init_network);
20932 +
20933 +EXPORT_SYMBOL_GPL(free_nx_info);
20934 +EXPORT_SYMBOL_GPL(unhash_nx_info);
20935 +
20936 diff -NurpP --minimal linux-3.9.4/kernel/vserver/proc.c linux-3.9.4-vs2.3.6.3/kernel/vserver/proc.c
20937 --- linux-3.9.4/kernel/vserver/proc.c   1970-01-01 00:00:00.000000000 +0000
20938 +++ linux-3.9.4-vs2.3.6.3/kernel/vserver/proc.c 2013-06-01 08:30:38.000000000 +0000
20939 @@ -0,0 +1,1110 @@
20940 +/*
20941 + *  linux/kernel/vserver/proc.c
20942 + *
20943 + *  Virtual Context Support
20944 + *
20945 + *  Copyright (C) 2003-2011  Herbert Pötzl
20946 + *
20947 + *  V0.01  basic structure
20948 + *  V0.02  adaptation vs1.3.0
20949 + *  V0.03  proc permissions
20950 + *  V0.04  locking/generic
20951 + *  V0.05  next generation procfs
20952 + *  V0.06  inode validation
20953 + *  V0.07  generic rewrite vid
20954 + *  V0.08  remove inode type
20955 + *  V0.09  added u/wmask info
20956 + *
20957 + */
20958 +
20959 +#include <linux/proc_fs.h>
20960 +#include <linux/fs_struct.h>
20961 +#include <linux/mount.h>
20962 +#include <linux/namei.h>
20963 +#include <asm/unistd.h>
20964 +
20965 +#include <linux/vs_context.h>
20966 +#include <linux/vs_network.h>
20967 +#include <linux/vs_cvirt.h>
20968 +
20969 +#include <linux/in.h>
20970 +#include <linux/inetdevice.h>
20971 +#include <linux/vs_inet.h>
20972 +#include <linux/vs_inet6.h>
20973 +
20974 +#include <linux/vserver/global.h>
20975 +
20976 +#include "cvirt_proc.h"
20977 +#include "cacct_proc.h"
20978 +#include "limit_proc.h"
20979 +#include "sched_proc.h"
20980 +#include "vci_config.h"
20981 +
20982 +
20983 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
20984 +{
20985 +       unsigned __capi;
20986 +
20987 +       CAP_FOR_EACH_U32(__capi) {
20988 +               buffer += sprintf(buffer, "%08x",
20989 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
20990 +       }
20991 +       return buffer;
20992 +}
20993 +
20994 +
20995 +static struct proc_dir_entry *proc_virtual;
20996 +
20997 +static struct proc_dir_entry *proc_virtnet;
20998 +
20999 +
21000 +/* first the actual feeds */
21001 +
21002 +
21003 +static int proc_vci(char *buffer)
21004 +{
21005 +       return sprintf(buffer,
21006 +               "VCIVersion:\t%04x:%04x\n"
21007 +               "VCISyscall:\t%d\n"
21008 +               "VCIKernel:\t%08x\n",
21009 +               VCI_VERSION >> 16,
21010 +               VCI_VERSION & 0xFFFF,
21011 +               __NR_vserver,
21012 +               vci_kernel_config());
21013 +}
21014 +
21015 +static int proc_virtual_info(char *buffer)
21016 +{
21017 +       return proc_vci(buffer);
21018 +}
21019 +
21020 +static int proc_virtual_status(char *buffer)
21021 +{
21022 +       return sprintf(buffer,
21023 +               "#CTotal:\t%d\n"
21024 +               "#CActive:\t%d\n"
21025 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
21026 +               "#InitTask:\t%d\t%d %d\n",
21027 +               atomic_read(&vx_global_ctotal),
21028 +               atomic_read(&vx_global_cactive),
21029 +               atomic_read(&vs_global_nsproxy),
21030 +               atomic_read(&vs_global_fs),
21031 +               atomic_read(&vs_global_mnt_ns),
21032 +               atomic_read(&vs_global_uts_ns),
21033 +               atomic_read(&nr_ipc_ns),
21034 +               atomic_read(&vs_global_user_ns),
21035 +               atomic_read(&vs_global_pid_ns),
21036 +               atomic_read(&init_task.usage),
21037 +               atomic_read(&init_task.nsproxy->count),
21038 +               init_task.fs->users);
21039 +}
21040 +
21041 +
21042 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
21043 +{
21044 +       int length;
21045 +
21046 +       length = sprintf(buffer,
21047 +               "ID:\t%d\n"
21048 +               "Info:\t%p\n"
21049 +               "Init:\t%d\n"
21050 +               "OOM:\t%lld\n",
21051 +               vxi->vx_id,
21052 +               vxi,
21053 +               vxi->vx_initpid,
21054 +               vxi->vx_badness_bias);
21055 +       return length;
21056 +}
21057 +
21058 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
21059 +{
21060 +       char *orig = buffer;
21061 +
21062 +       buffer += sprintf(buffer,
21063 +               "UseCnt:\t%d\n"
21064 +               "Tasks:\t%d\n"
21065 +               "Flags:\t%016llx\n",
21066 +               atomic_read(&vxi->vx_usecnt),
21067 +               atomic_read(&vxi->vx_tasks),
21068 +               (unsigned long long)vxi->vx_flags);
21069 +
21070 +       buffer += sprintf(buffer, "BCaps:\t");
21071 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
21072 +       buffer += sprintf(buffer, "\n");
21073 +
21074 +       buffer += sprintf(buffer,
21075 +               "CCaps:\t%016llx\n"
21076 +               "Umask:\t%16llx\n"
21077 +               "Wmask:\t%16llx\n"
21078 +               "Spaces:\t%08lx %08lx\n",
21079 +               (unsigned long long)vxi->vx_ccaps,
21080 +               (unsigned long long)vxi->vx_umask,
21081 +               (unsigned long long)vxi->vx_wmask,
21082 +               vxi->space[0].vx_nsmask, vxi->space[1].vx_nsmask);
21083 +       return buffer - orig;
21084 +}
21085 +
21086 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
21087 +{
21088 +       return vx_info_proc_limit(&vxi->limit, buffer);
21089 +}
21090 +
21091 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
21092 +{
21093 +       int cpu, length;
21094 +
21095 +       length = vx_info_proc_sched(&vxi->sched, buffer);
21096 +       for_each_online_cpu(cpu) {
21097 +               length += vx_info_proc_sched_pc(
21098 +                       &vx_per_cpu(vxi, sched_pc, cpu),
21099 +                       buffer + length, cpu);
21100 +       }
21101 +       return length;
21102 +}
21103 +
21104 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
21105 +{
21106 +       return vx_info_proc_nsproxy(vxi->space[0].vx_nsproxy, buffer);
21107 +}
21108 +
21109 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
21110 +{
21111 +       return vx_info_proc_nsproxy(vxi->space[1].vx_nsproxy, buffer);
21112 +}
21113 +
21114 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
21115 +{
21116 +       int cpu, length;
21117 +
21118 +       vx_update_load(vxi);
21119 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
21120 +       for_each_online_cpu(cpu) {
21121 +               length += vx_info_proc_cvirt_pc(
21122 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
21123 +                       buffer + length, cpu);
21124 +       }
21125 +       return length;
21126 +}
21127 +
21128 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
21129 +{
21130 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
21131 +}
21132 +
21133 +
21134 +static int proc_virtnet_info(char *buffer)
21135 +{
21136 +       return proc_vci(buffer);
21137 +}
21138 +
21139 +static int proc_virtnet_status(char *buffer)
21140 +{
21141 +       return sprintf(buffer,
21142 +               "#CTotal:\t%d\n"
21143 +               "#CActive:\t%d\n",
21144 +               atomic_read(&nx_global_ctotal),
21145 +               atomic_read(&nx_global_cactive));
21146 +}
21147 +
21148 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
21149 +{
21150 +       struct nx_addr_v4 *v4a;
21151 +#ifdef CONFIG_IPV6
21152 +       struct nx_addr_v6 *v6a;
21153 +#endif
21154 +       int length, i;
21155 +
21156 +       length = sprintf(buffer,
21157 +               "ID:\t%d\n"
21158 +               "Info:\t%p\n"
21159 +               "Bcast:\t" NIPQUAD_FMT "\n"
21160 +               "Lback:\t" NIPQUAD_FMT "\n",
21161 +               nxi->nx_id,
21162 +               nxi,
21163 +               NIPQUAD(nxi->v4_bcast.s_addr),
21164 +               NIPQUAD(nxi->v4_lback.s_addr));
21165 +
21166 +       if (!NX_IPV4(nxi))
21167 +               goto skip_v4;
21168 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
21169 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
21170 +                       i, NXAV4(v4a));
21171 +skip_v4:
21172 +#ifdef CONFIG_IPV6
21173 +       if (!NX_IPV6(nxi))
21174 +               goto skip_v6;
21175 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
21176 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
21177 +                       i, NXAV6(v6a));
21178 +skip_v6:
21179 +#endif
21180 +       return length;
21181 +}
21182 +
21183 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
21184 +{
21185 +       int length;
21186 +
21187 +       length = sprintf(buffer,
21188 +               "UseCnt:\t%d\n"
21189 +               "Tasks:\t%d\n"
21190 +               "Flags:\t%016llx\n"
21191 +               "NCaps:\t%016llx\n",
21192 +               atomic_read(&nxi->nx_usecnt),
21193 +               atomic_read(&nxi->nx_tasks),
21194 +               (unsigned long long)nxi->nx_flags,
21195 +               (unsigned long long)nxi->nx_ncaps);
21196 +       return length;
21197 +}
21198 +
21199 +
21200 +
21201 +/* here the inode helpers */
21202 +
21203 +struct vs_entry {
21204 +       int len;
21205 +       char *name;
21206 +       mode_t mode;
21207 +       struct inode_operations *iop;
21208 +       struct file_operations *fop;
21209 +       union proc_op op;
21210 +};
21211 +
21212 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
21213 +{
21214 +       struct inode *inode = new_inode(sb);
21215 +
21216 +       if (!inode)
21217 +               goto out;
21218 +
21219 +       inode->i_mode = p->mode;
21220 +       if (p->iop)
21221 +               inode->i_op = p->iop;
21222 +       if (p->fop)
21223 +               inode->i_fop = p->fop;
21224 +
21225 +       set_nlink(inode, (p->mode & S_IFDIR) ? 2 : 1);
21226 +       inode->i_flags |= S_IMMUTABLE;
21227 +
21228 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
21229 +
21230 +       i_uid_write(inode, 0);
21231 +       i_gid_write(inode, 0);
21232 +       i_tag_write(inode, 0);
21233 +out:
21234 +       return inode;
21235 +}
21236 +
21237 +static struct dentry *vs_proc_instantiate(struct inode *dir,
21238 +       struct dentry *dentry, int id, void *ptr)
21239 +{
21240 +       struct vs_entry *p = ptr;
21241 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
21242 +       struct dentry *error = ERR_PTR(-EINVAL);
21243 +
21244 +       if (!inode)
21245 +               goto out;
21246 +
21247 +       PROC_I(inode)->op = p->op;
21248 +       PROC_I(inode)->fd = id;
21249 +       d_add(dentry, inode);
21250 +       error = NULL;
21251 +out:
21252 +       return error;
21253 +}
21254 +
21255 +/* Lookups */
21256 +
21257 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
21258 +
21259 +/*
21260 + * Fill a directory entry.
21261 + *
21262 + * If possible create the dcache entry and derive our inode number and
21263 + * file type from dcache entry.
21264 + *
21265 + * Since all of the proc inode numbers are dynamically generated, the inode
21266 + * numbers do not exist until the inode is cache.  This means creating the
21267 + * the dcache entry in readdir is necessary to keep the inode numbers
21268 + * reported by readdir in sync with the inode numbers reported
21269 + * by stat.
21270 + */
21271 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
21272 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
21273 +{
21274 +       struct dentry *child, *dir = filp->f_dentry;
21275 +       struct inode *inode;
21276 +       struct qstr qname;
21277 +       ino_t ino = 0;
21278 +       unsigned type = DT_UNKNOWN;
21279 +
21280 +       qname.name = name;
21281 +       qname.len  = len;
21282 +       qname.hash = full_name_hash(name, len);
21283 +
21284 +       child = d_lookup(dir, &qname);
21285 +       if (!child) {
21286 +               struct dentry *new;
21287 +               new = d_alloc(dir, &qname);
21288 +               if (new) {
21289 +                       child = instantiate(dir->d_inode, new, id, ptr);
21290 +                       if (child)
21291 +                               dput(new);
21292 +                       else
21293 +                               child = new;
21294 +               }
21295 +       }
21296 +       if (!child || IS_ERR(child) || !child->d_inode)
21297 +               goto end_instantiate;
21298 +       inode = child->d_inode;
21299 +       if (inode) {
21300 +               ino = inode->i_ino;
21301 +               type = inode->i_mode >> 12;
21302 +       }
21303 +       dput(child);
21304 +end_instantiate:
21305 +       if (!ino)
21306 +               ino = find_inode_number(dir, &qname);
21307 +       if (!ino)
21308 +               ino = 1;
21309 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
21310 +}
21311 +
21312 +
21313 +
21314 +/* get and revalidate vx_info/xid */
21315 +
21316 +static inline
21317 +struct vx_info *get_proc_vx_info(struct inode *inode)
21318 +{
21319 +       return lookup_vx_info(PROC_I(inode)->fd);
21320 +}
21321 +
21322 +static int proc_xid_revalidate(struct dentry *dentry, unsigned int flags)
21323 +{
21324 +       struct inode *inode = dentry->d_inode;
21325 +       xid_t xid = PROC_I(inode)->fd;
21326 +
21327 +       if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
21328 +               return -ECHILD;
21329 +
21330 +       if (!xid || xid_is_hashed(xid))
21331 +               return 1;
21332 +       d_drop(dentry);
21333 +       return 0;
21334 +}
21335 +
21336 +
21337 +/* get and revalidate nx_info/nid */
21338 +
21339 +static int proc_nid_revalidate(struct dentry *dentry, unsigned int flags)
21340 +{
21341 +       struct inode *inode = dentry->d_inode;
21342 +       nid_t nid = PROC_I(inode)->fd;
21343 +
21344 +       if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
21345 +               return -ECHILD;
21346 +
21347 +       if (!nid || nid_is_hashed(nid))
21348 +               return 1;
21349 +       d_drop(dentry);
21350 +       return 0;
21351 +}
21352 +
21353 +
21354 +
21355 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
21356 +
21357 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
21358 +                         size_t count, loff_t *ppos)
21359 +{
21360 +       struct inode *inode = file->f_dentry->d_inode;
21361 +       unsigned long page;
21362 +       ssize_t length = 0;
21363 +
21364 +       if (count > PROC_BLOCK_SIZE)
21365 +               count = PROC_BLOCK_SIZE;
21366 +
21367 +       /* fade that out as soon as stable */
21368 +       WARN_ON(PROC_I(inode)->fd);
21369 +
21370 +       if (!(page = __get_free_page(GFP_KERNEL)))
21371 +               return -ENOMEM;
21372 +
21373 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
21374 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
21375 +
21376 +       if (length >= 0)
21377 +               length = simple_read_from_buffer(buf, count, ppos,
21378 +                       (char *)page, length);
21379 +
21380 +       free_page(page);
21381 +       return length;
21382 +}
21383 +
21384 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
21385 +                         size_t count, loff_t *ppos)
21386 +{
21387 +       struct inode *inode = file->f_dentry->d_inode;
21388 +       struct vx_info *vxi = NULL;
21389 +       xid_t xid = PROC_I(inode)->fd;
21390 +       unsigned long page;
21391 +       ssize_t length = 0;
21392 +
21393 +       if (count > PROC_BLOCK_SIZE)
21394 +               count = PROC_BLOCK_SIZE;
21395 +
21396 +       /* fade that out as soon as stable */
21397 +       WARN_ON(!xid);
21398 +       vxi = lookup_vx_info(xid);
21399 +       if (!vxi)
21400 +               goto out;
21401 +
21402 +       length = -ENOMEM;
21403 +       if (!(page = __get_free_page(GFP_KERNEL)))
21404 +               goto out_put;
21405 +
21406 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
21407 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
21408 +
21409 +       if (length >= 0)
21410 +               length = simple_read_from_buffer(buf, count, ppos,
21411 +                       (char *)page, length);
21412 +
21413 +       free_page(page);
21414 +out_put:
21415 +       put_vx_info(vxi);
21416 +out:
21417 +       return length;
21418 +}
21419 +
21420 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
21421 +                         size_t count, loff_t *ppos)
21422 +{
21423 +       struct inode *inode = file->f_dentry->d_inode;
21424 +       struct nx_info *nxi = NULL;
21425 +       nid_t nid = PROC_I(inode)->fd;
21426 +       unsigned long page;
21427 +       ssize_t length = 0;
21428 +
21429 +       if (count > PROC_BLOCK_SIZE)
21430 +               count = PROC_BLOCK_SIZE;
21431 +
21432 +       /* fade that out as soon as stable */
21433 +       WARN_ON(!nid);
21434 +       nxi = lookup_nx_info(nid);
21435 +       if (!nxi)
21436 +               goto out;
21437 +
21438 +       length = -ENOMEM;
21439 +       if (!(page = __get_free_page(GFP_KERNEL)))
21440 +               goto out_put;
21441 +
21442 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
21443 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
21444 +
21445 +       if (length >= 0)
21446 +               length = simple_read_from_buffer(buf, count, ppos,
21447 +                       (char *)page, length);
21448 +
21449 +       free_page(page);
21450 +out_put:
21451 +       put_nx_info(nxi);
21452 +out:
21453 +       return length;
21454 +}
21455 +
21456 +
21457 +
21458 +/* here comes the lower level */
21459 +
21460 +
21461 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
21462 +       .len  = sizeof(NAME) - 1,       \
21463 +       .name = (NAME),                 \
21464 +       .mode = MODE,                   \
21465 +       .iop  = IOP,                    \
21466 +       .fop  = FOP,                    \
21467 +       .op   = OP,                     \
21468 +}
21469 +
21470 +
21471 +#define DIR(NAME, MODE, OTYPE)                         \
21472 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
21473 +               &proc_ ## OTYPE ## _inode_operations,   \
21474 +               &proc_ ## OTYPE ## _file_operations, { } )
21475 +
21476 +#define INF(NAME, MODE, OTYPE)                         \
21477 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21478 +               &proc_vs_info_file_operations,          \
21479 +               { .proc_vs_read = &proc_##OTYPE } )
21480 +
21481 +#define VINF(NAME, MODE, OTYPE)                                \
21482 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21483 +               &proc_vx_info_file_operations,          \
21484 +               { .proc_vxi_read = &proc_##OTYPE } )
21485 +
21486 +#define NINF(NAME, MODE, OTYPE)                                \
21487 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21488 +               &proc_nx_info_file_operations,          \
21489 +               { .proc_nxi_read = &proc_##OTYPE } )
21490 +
21491 +
21492 +static struct file_operations proc_vs_info_file_operations = {
21493 +       .read =         proc_vs_info_read,
21494 +};
21495 +
21496 +static struct file_operations proc_vx_info_file_operations = {
21497 +       .read =         proc_vx_info_read,
21498 +};
21499 +
21500 +static struct dentry_operations proc_xid_dentry_operations = {
21501 +       .d_revalidate = proc_xid_revalidate,
21502 +};
21503 +
21504 +static struct vs_entry vx_base_stuff[] = {
21505 +       VINF("info",    S_IRUGO, vxi_info),
21506 +       VINF("status",  S_IRUGO, vxi_status),
21507 +       VINF("limit",   S_IRUGO, vxi_limit),
21508 +       VINF("sched",   S_IRUGO, vxi_sched),
21509 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
21510 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
21511 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
21512 +       VINF("cacct",   S_IRUGO, vxi_cacct),
21513 +       {}
21514 +};
21515 +
21516 +
21517 +
21518 +
21519 +static struct dentry *proc_xid_instantiate(struct inode *dir,
21520 +       struct dentry *dentry, int id, void *ptr)
21521 +{
21522 +       dentry->d_op = &proc_xid_dentry_operations;
21523 +       return vs_proc_instantiate(dir, dentry, id, ptr);
21524 +}
21525 +
21526 +static struct dentry *proc_xid_lookup(struct inode *dir,
21527 +       struct dentry *dentry, unsigned int flags)
21528 +{
21529 +       struct vs_entry *p = vx_base_stuff;
21530 +       struct dentry *error = ERR_PTR(-ENOENT);
21531 +
21532 +       for (; p->name; p++) {
21533 +               if (p->len != dentry->d_name.len)
21534 +                       continue;
21535 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21536 +                       break;
21537 +       }
21538 +       if (!p->name)
21539 +               goto out;
21540 +
21541 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
21542 +out:
21543 +       return error;
21544 +}
21545 +
21546 +static int proc_xid_readdir(struct file *filp,
21547 +       void *dirent, filldir_t filldir)
21548 +{
21549 +       struct dentry *dentry = filp->f_dentry;
21550 +       struct inode *inode = dentry->d_inode;
21551 +       struct vs_entry *p = vx_base_stuff;
21552 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
21553 +       int pos, index;
21554 +       u64 ino;
21555 +
21556 +       pos = filp->f_pos;
21557 +       switch (pos) {
21558 +       case 0:
21559 +               ino = inode->i_ino;
21560 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21561 +                       goto out;
21562 +               pos++;
21563 +               /* fall through */
21564 +       case 1:
21565 +               ino = parent_ino(dentry);
21566 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21567 +                       goto out;
21568 +               pos++;
21569 +               /* fall through */
21570 +       default:
21571 +               index = pos - 2;
21572 +               if (index >= size)
21573 +                       goto out;
21574 +               for (p += index; p->name; p++) {
21575 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21576 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
21577 +                               goto out;
21578 +                       pos++;
21579 +               }
21580 +       }
21581 +out:
21582 +       filp->f_pos = pos;
21583 +       return 1;
21584 +}
21585 +
21586 +
21587 +
21588 +static struct file_operations proc_nx_info_file_operations = {
21589 +       .read =         proc_nx_info_read,
21590 +};
21591 +
21592 +static struct dentry_operations proc_nid_dentry_operations = {
21593 +       .d_revalidate = proc_nid_revalidate,
21594 +};
21595 +
21596 +static struct vs_entry nx_base_stuff[] = {
21597 +       NINF("info",    S_IRUGO, nxi_info),
21598 +       NINF("status",  S_IRUGO, nxi_status),
21599 +       {}
21600 +};
21601 +
21602 +
21603 +static struct dentry *proc_nid_instantiate(struct inode *dir,
21604 +       struct dentry *dentry, int id, void *ptr)
21605 +{
21606 +       dentry->d_op = &proc_nid_dentry_operations;
21607 +       return vs_proc_instantiate(dir, dentry, id, ptr);
21608 +}
21609 +
21610 +static struct dentry *proc_nid_lookup(struct inode *dir,
21611 +       struct dentry *dentry, unsigned int flags)
21612 +{
21613 +       struct vs_entry *p = nx_base_stuff;
21614 +       struct dentry *error = ERR_PTR(-ENOENT);
21615 +
21616 +       for (; p->name; p++) {
21617 +               if (p->len != dentry->d_name.len)
21618 +                       continue;
21619 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21620 +                       break;
21621 +       }
21622 +       if (!p->name)
21623 +               goto out;
21624 +
21625 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
21626 +out:
21627 +       return error;
21628 +}
21629 +
21630 +static int proc_nid_readdir(struct file *filp,
21631 +       void *dirent, filldir_t filldir)
21632 +{
21633 +       struct dentry *dentry = filp->f_dentry;
21634 +       struct inode *inode = dentry->d_inode;
21635 +       struct vs_entry *p = nx_base_stuff;
21636 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
21637 +       int pos, index;
21638 +       u64 ino;
21639 +
21640 +       pos = filp->f_pos;
21641 +       switch (pos) {
21642 +       case 0:
21643 +               ino = inode->i_ino;
21644 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21645 +                       goto out;
21646 +               pos++;
21647 +               /* fall through */
21648 +       case 1:
21649 +               ino = parent_ino(dentry);
21650 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21651 +                       goto out;
21652 +               pos++;
21653 +               /* fall through */
21654 +       default:
21655 +               index = pos - 2;
21656 +               if (index >= size)
21657 +                       goto out;
21658 +               for (p += index; p->name; p++) {
21659 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21660 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
21661 +                               goto out;
21662 +                       pos++;
21663 +               }
21664 +       }
21665 +out:
21666 +       filp->f_pos = pos;
21667 +       return 1;
21668 +}
21669 +
21670 +
21671 +#define MAX_MULBY10    ((~0U - 9) / 10)
21672 +
21673 +static inline int atovid(const char *str, int len)
21674 +{
21675 +       int vid, c;
21676 +
21677 +       vid = 0;
21678 +       while (len-- > 0) {
21679 +               c = *str - '0';
21680 +               str++;
21681 +               if (c > 9)
21682 +                       return -1;
21683 +               if (vid >= MAX_MULBY10)
21684 +                       return -1;
21685 +               vid *= 10;
21686 +               vid += c;
21687 +               if (!vid)
21688 +                       return -1;
21689 +       }
21690 +       return vid;
21691 +}
21692 +
21693 +/* now the upper level (virtual) */
21694 +
21695 +
21696 +static struct file_operations proc_xid_file_operations = {
21697 +       .read =         generic_read_dir,
21698 +       .readdir =      proc_xid_readdir,
21699 +};
21700 +
21701 +static struct inode_operations proc_xid_inode_operations = {
21702 +       .lookup =       proc_xid_lookup,
21703 +};
21704 +
21705 +static struct vs_entry vx_virtual_stuff[] = {
21706 +       INF("info",     S_IRUGO, virtual_info),
21707 +       INF("status",   S_IRUGO, virtual_status),
21708 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
21709 +};
21710 +
21711 +
21712 +static struct dentry *proc_virtual_lookup(struct inode *dir,
21713 +       struct dentry *dentry, unsigned int flags)
21714 +{
21715 +       struct vs_entry *p = vx_virtual_stuff;
21716 +       struct dentry *error = ERR_PTR(-ENOENT);
21717 +       int id = 0;
21718 +
21719 +       for (; p->name; p++) {
21720 +               if (p->len != dentry->d_name.len)
21721 +                       continue;
21722 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21723 +                       break;
21724 +       }
21725 +       if (p->name)
21726 +               goto instantiate;
21727 +
21728 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
21729 +       if ((id < 0) || !xid_is_hashed(id))
21730 +               goto out;
21731 +
21732 +instantiate:
21733 +       error = proc_xid_instantiate(dir, dentry, id, p);
21734 +out:
21735 +       return error;
21736 +}
21737 +
21738 +static struct file_operations proc_nid_file_operations = {
21739 +       .read =         generic_read_dir,
21740 +       .readdir =      proc_nid_readdir,
21741 +};
21742 +
21743 +static struct inode_operations proc_nid_inode_operations = {
21744 +       .lookup =       proc_nid_lookup,
21745 +};
21746 +
21747 +static struct vs_entry nx_virtnet_stuff[] = {
21748 +       INF("info",     S_IRUGO, virtnet_info),
21749 +       INF("status",   S_IRUGO, virtnet_status),
21750 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
21751 +};
21752 +
21753 +
21754 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
21755 +       struct dentry *dentry, unsigned int flags)
21756 +{
21757 +       struct vs_entry *p = nx_virtnet_stuff;
21758 +       struct dentry *error = ERR_PTR(-ENOENT);
21759 +       int id = 0;
21760 +
21761 +       for (; p->name; p++) {
21762 +               if (p->len != dentry->d_name.len)
21763 +                       continue;
21764 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21765 +                       break;
21766 +       }
21767 +       if (p->name)
21768 +               goto instantiate;
21769 +
21770 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
21771 +       if ((id < 0) || !nid_is_hashed(id))
21772 +               goto out;
21773 +
21774 +instantiate:
21775 +       error = proc_nid_instantiate(dir, dentry, id, p);
21776 +out:
21777 +       return error;
21778 +}
21779 +
21780 +
21781 +#define PROC_MAXVIDS 32
21782 +
21783 +int proc_virtual_readdir(struct file *filp,
21784 +       void *dirent, filldir_t filldir)
21785 +{
21786 +       struct dentry *dentry = filp->f_dentry;
21787 +       struct inode *inode = dentry->d_inode;
21788 +       struct vs_entry *p = vx_virtual_stuff;
21789 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
21790 +       int pos, index;
21791 +       unsigned int xid_array[PROC_MAXVIDS];
21792 +       char buf[PROC_NUMBUF];
21793 +       unsigned int nr_xids, i;
21794 +       u64 ino;
21795 +
21796 +       pos = filp->f_pos;
21797 +       switch (pos) {
21798 +       case 0:
21799 +               ino = inode->i_ino;
21800 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21801 +                       goto out;
21802 +               pos++;
21803 +               /* fall through */
21804 +       case 1:
21805 +               ino = parent_ino(dentry);
21806 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21807 +                       goto out;
21808 +               pos++;
21809 +               /* fall through */
21810 +       default:
21811 +               index = pos - 2;
21812 +               if (index >= size)
21813 +                       goto entries;
21814 +               for (p += index; p->name; p++) {
21815 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21816 +                               vs_proc_instantiate, 0, p))
21817 +                               goto out;
21818 +                       pos++;
21819 +               }
21820 +       entries:
21821 +               index = pos - size;
21822 +               p = &vx_virtual_stuff[size - 1];
21823 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
21824 +               for (i = 0; i < nr_xids; i++) {
21825 +                       int n, xid = xid_array[i];
21826 +                       unsigned int j = PROC_NUMBUF;
21827 +
21828 +                       n = xid;
21829 +                       do
21830 +                               buf[--j] = '0' + (n % 10);
21831 +                       while (n /= 10);
21832 +
21833 +                       if (proc_fill_cache(filp, dirent, filldir,
21834 +                               buf + j, PROC_NUMBUF - j,
21835 +                               vs_proc_instantiate, xid, p))
21836 +                               goto out;
21837 +                       pos++;
21838 +               }
21839 +       }
21840 +out:
21841 +       filp->f_pos = pos;
21842 +       return 0;
21843 +}
21844 +
21845 +static int proc_virtual_getattr(struct vfsmount *mnt,
21846 +       struct dentry *dentry, struct kstat *stat)
21847 +{
21848 +       struct inode *inode = dentry->d_inode;
21849 +
21850 +       generic_fillattr(inode, stat);
21851 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
21852 +       return 0;
21853 +}
21854 +
21855 +static struct file_operations proc_virtual_dir_operations = {
21856 +       .read =         generic_read_dir,
21857 +       .readdir =      proc_virtual_readdir,
21858 +};
21859 +
21860 +static struct inode_operations proc_virtual_dir_inode_operations = {
21861 +       .getattr =      proc_virtual_getattr,
21862 +       .lookup =       proc_virtual_lookup,
21863 +};
21864 +
21865 +
21866 +
21867 +
21868 +
21869 +int proc_virtnet_readdir(struct file *filp,
21870 +       void *dirent, filldir_t filldir)
21871 +{
21872 +       struct dentry *dentry = filp->f_dentry;
21873 +       struct inode *inode = dentry->d_inode;
21874 +       struct vs_entry *p = nx_virtnet_stuff;
21875 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
21876 +       int pos, index;
21877 +       unsigned int nid_array[PROC_MAXVIDS];
21878 +       char buf[PROC_NUMBUF];
21879 +       unsigned int nr_nids, i;
21880 +       u64 ino;
21881 +
21882 +       pos = filp->f_pos;
21883 +       switch (pos) {
21884 +       case 0:
21885 +               ino = inode->i_ino;
21886 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21887 +                       goto out;
21888 +               pos++;
21889 +               /* fall through */
21890 +       case 1:
21891 +               ino = parent_ino(dentry);
21892 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21893 +                       goto out;
21894 +               pos++;
21895 +               /* fall through */
21896 +       default:
21897 +               index = pos - 2;
21898 +               if (index >= size)
21899 +                       goto entries;
21900 +               for (p += index; p->name; p++) {
21901 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21902 +                               vs_proc_instantiate, 0, p))
21903 +                               goto out;
21904 +                       pos++;
21905 +               }
21906 +       entries:
21907 +               index = pos - size;
21908 +               p = &nx_virtnet_stuff[size - 1];
21909 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
21910 +               for (i = 0; i < nr_nids; i++) {
21911 +                       int n, nid = nid_array[i];
21912 +                       unsigned int j = PROC_NUMBUF;
21913 +
21914 +                       n = nid;
21915 +                       do
21916 +                               buf[--j] = '0' + (n % 10);
21917 +                       while (n /= 10);
21918 +
21919 +                       if (proc_fill_cache(filp, dirent, filldir,
21920 +                               buf + j, PROC_NUMBUF - j,
21921 +                               vs_proc_instantiate, nid, p))
21922 +                               goto out;
21923 +                       pos++;
21924 +               }
21925 +       }
21926 +out:
21927 +       filp->f_pos = pos;
21928 +       return 0;
21929 +}
21930 +
21931 +static int proc_virtnet_getattr(struct vfsmount *mnt,
21932 +       struct dentry *dentry, struct kstat *stat)
21933 +{
21934 +       struct inode *inode = dentry->d_inode;
21935 +
21936 +       generic_fillattr(inode, stat);
21937 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
21938 +       return 0;
21939 +}
21940 +
21941 +static struct file_operations proc_virtnet_dir_operations = {
21942 +       .read =         generic_read_dir,
21943 +       .readdir =      proc_virtnet_readdir,
21944 +};
21945 +
21946 +static struct inode_operations proc_virtnet_dir_inode_operations = {
21947 +       .getattr =      proc_virtnet_getattr,
21948 +       .lookup =       proc_virtnet_lookup,
21949 +};
21950 +
21951 +
21952 +
21953 +void proc_vx_init(void)
21954 +{
21955 +       struct proc_dir_entry *ent;
21956 +
21957 +       ent = proc_mkdir("virtual", 0);
21958 +       if (ent) {
21959 +               ent->proc_fops = &proc_virtual_dir_operations;
21960 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
21961 +       }
21962 +       proc_virtual = ent;
21963 +
21964 +       ent = proc_mkdir("virtnet", 0);
21965 +       if (ent) {
21966 +               ent->proc_fops = &proc_virtnet_dir_operations;
21967 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
21968 +       }
21969 +       proc_virtnet = ent;
21970 +}
21971 +
21972 +
21973 +
21974 +
21975 +/* per pid info */
21976 +
21977 +
21978 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
21979 +{
21980 +       struct vx_info *vxi;
21981 +       char *orig = buffer;
21982 +
21983 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
21984 +
21985 +       vxi = task_get_vx_info(p);
21986 +       if (!vxi)
21987 +               goto out;
21988 +
21989 +       buffer += sprintf(buffer, "BCaps:\t");
21990 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
21991 +       buffer += sprintf(buffer, "\n");
21992 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
21993 +               (unsigned long long)vxi->vx_ccaps);
21994 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
21995 +               (unsigned long long)vxi->vx_flags);
21996 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
21997 +
21998 +       put_vx_info(vxi);
21999 +out:
22000 +       return buffer - orig;
22001 +}
22002 +
22003 +
22004 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
22005 +{
22006 +       struct nx_info *nxi;
22007 +       struct nx_addr_v4 *v4a;
22008 +#ifdef CONFIG_IPV6
22009 +       struct nx_addr_v6 *v6a;
22010 +#endif
22011 +       char *orig = buffer;
22012 +       int i;
22013 +
22014 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
22015 +
22016 +       nxi = task_get_nx_info(p);
22017 +       if (!nxi)
22018 +               goto out;
22019 +
22020 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
22021 +               (unsigned long long)nxi->nx_ncaps);
22022 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
22023 +               (unsigned long long)nxi->nx_flags);
22024 +
22025 +       buffer += sprintf(buffer,
22026 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
22027 +               NIPQUAD(nxi->v4_bcast.s_addr));
22028 +       buffer += sprintf (buffer,
22029 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
22030 +               NIPQUAD(nxi->v4_lback.s_addr));
22031 +       if (!NX_IPV4(nxi))
22032 +               goto skip_v4;
22033 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
22034 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
22035 +                       i, NXAV4(v4a));
22036 +skip_v4:
22037 +#ifdef CONFIG_IPV6
22038 +       if (!NX_IPV6(nxi))
22039 +               goto skip_v6;
22040 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
22041 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
22042 +                       i, NXAV6(v6a));
22043 +skip_v6:
22044 +#endif
22045 +       put_nx_info(nxi);
22046 +out:
22047 +       return buffer - orig;
22048 +}
22049 +
22050 diff -NurpP --minimal linux-3.9.4/kernel/vserver/sched.c linux-3.9.4-vs2.3.6.3/kernel/vserver/sched.c
22051 --- linux-3.9.4/kernel/vserver/sched.c  1970-01-01 00:00:00.000000000 +0000
22052 +++ linux-3.9.4-vs2.3.6.3/kernel/vserver/sched.c        2013-05-31 14:47:11.000000000 +0000
22053 @@ -0,0 +1,83 @@
22054 +/*
22055 + *  linux/kernel/vserver/sched.c
22056 + *
22057 + *  Virtual Server: Scheduler Support
22058 + *
22059 + *  Copyright (C) 2004-2010  Herbert Pötzl
22060 + *
22061 + *  V0.01  adapted Sam Vilains version to 2.6.3
22062 + *  V0.02  removed legacy interface
22063 + *  V0.03  changed vcmds to vxi arg
22064 + *  V0.04  removed older and legacy interfaces
22065 + *  V0.05  removed scheduler code/commands
22066 + *
22067 + */
22068 +
22069 +#include <linux/vs_context.h>
22070 +#include <linux/vs_sched.h>
22071 +#include <linux/cpumask.h>
22072 +#include <linux/vserver/sched_cmd.h>
22073 +
22074 +#include <asm/uaccess.h>
22075 +
22076 +
22077 +void vx_update_sched_param(struct _vx_sched *sched,
22078 +       struct _vx_sched_pc *sched_pc)
22079 +{
22080 +       sched_pc->prio_bias = sched->prio_bias;
22081 +}
22082 +
22083 +static int do_set_prio_bias(struct vx_info *vxi, struct vcmd_prio_bias *data)
22084 +{
22085 +       int cpu;
22086 +
22087 +       if (data->prio_bias > MAX_PRIO_BIAS)
22088 +               data->prio_bias = MAX_PRIO_BIAS;
22089 +       if (data->prio_bias < MIN_PRIO_BIAS)
22090 +               data->prio_bias = MIN_PRIO_BIAS;
22091 +
22092 +       if (data->cpu_id != ~0) {
22093 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
22094 +               cpumask_and(&vxi->sched.update, &vxi->sched.update,
22095 +                       cpu_online_mask);
22096 +       } else
22097 +               cpumask_copy(&vxi->sched.update, cpu_online_mask);
22098 +
22099 +       for_each_cpu_mask(cpu, vxi->sched.update)
22100 +               vx_update_sched_param(&vxi->sched,
22101 +                       &vx_per_cpu(vxi, sched_pc, cpu));
22102 +       return 0;
22103 +}
22104 +
22105 +int vc_set_prio_bias(struct vx_info *vxi, void __user *data)
22106 +{
22107 +       struct vcmd_prio_bias vc_data;
22108 +
22109 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22110 +               return -EFAULT;
22111 +
22112 +       return do_set_prio_bias(vxi, &vc_data);
22113 +}
22114 +
22115 +int vc_get_prio_bias(struct vx_info *vxi, void __user *data)
22116 +{
22117 +       struct vcmd_prio_bias vc_data;
22118 +       struct _vx_sched_pc *pcd;
22119 +       int cpu;
22120 +
22121 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22122 +               return -EFAULT;
22123 +
22124 +       cpu = vc_data.cpu_id;
22125 +
22126 +       if (!cpu_possible(cpu))
22127 +               return -EINVAL;
22128 +
22129 +       pcd = &vx_per_cpu(vxi, sched_pc, cpu);
22130 +       vc_data.prio_bias = pcd->prio_bias;
22131 +
22132 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22133 +               return -EFAULT;
22134 +       return 0;
22135 +}
22136 +
22137 diff -NurpP --minimal linux-3.9.4/kernel/vserver/sched_init.h linux-3.9.4-vs2.3.6.3/kernel/vserver/sched_init.h
22138 --- linux-3.9.4/kernel/vserver/sched_init.h     1970-01-01 00:00:00.000000000 +0000
22139 +++ linux-3.9.4-vs2.3.6.3/kernel/vserver/sched_init.h   2013-05-31 14:47:11.000000000 +0000
22140 @@ -0,0 +1,27 @@
22141 +
22142 +static inline void vx_info_init_sched(struct _vx_sched *sched)
22143 +{
22144 +       /* scheduling; hard code starting values as constants */
22145 +       sched->prio_bias = 0;
22146 +}
22147 +
22148 +static inline
22149 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22150 +{
22151 +       sched_pc->prio_bias = 0;
22152 +
22153 +       sched_pc->user_ticks = 0;
22154 +       sched_pc->sys_ticks = 0;
22155 +       sched_pc->hold_ticks = 0;
22156 +}
22157 +
22158 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
22159 +{
22160 +       return;
22161 +}
22162 +
22163 +static inline
22164 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22165 +{
22166 +       return;
22167 +}
22168 diff -NurpP --minimal linux-3.9.4/kernel/vserver/sched_proc.h linux-3.9.4-vs2.3.6.3/kernel/vserver/sched_proc.h
22169 --- linux-3.9.4/kernel/vserver/sched_proc.h     1970-01-01 00:00:00.000000000 +0000
22170 +++ linux-3.9.4-vs2.3.6.3/kernel/vserver/sched_proc.h   2013-05-31 14:47:11.000000000 +0000
22171 @@ -0,0 +1,32 @@
22172 +#ifndef _VX_SCHED_PROC_H
22173 +#define _VX_SCHED_PROC_H
22174 +
22175 +
22176 +static inline
22177 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
22178 +{
22179 +       int length = 0;
22180 +
22181 +       length += sprintf(buffer,
22182 +               "PrioBias:\t%8d\n",
22183 +               sched->prio_bias);
22184 +       return length;
22185 +}
22186 +
22187 +static inline
22188 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
22189 +       char *buffer, int cpu)
22190 +{
22191 +       int length = 0;
22192 +
22193 +       length += sprintf(buffer + length,
22194 +               "cpu %d: %lld %lld %lld", cpu,
22195 +               (unsigned long long)sched_pc->user_ticks,
22196 +               (unsigned long long)sched_pc->sys_ticks,
22197 +               (unsigned long long)sched_pc->hold_ticks);
22198 +       length += sprintf(buffer + length,
22199 +               " %d\n", sched_pc->prio_bias);
22200 +       return length;
22201 +}
22202 +
22203 +#endif /* _VX_SCHED_PROC_H */
22204 diff -NurpP --minimal linux-3.9.4/kernel/vserver/signal.c linux-3.9.4-vs2.3.6.3/kernel/vserver/signal.c
22205 --- linux-3.9.4/kernel/vserver/signal.c 1970-01-01 00:00:00.000000000 +0000
22206 +++ linux-3.9.4-vs2.3.6.3/kernel/vserver/signal.c       2013-05-31 14:47:11.000000000 +0000
22207 @@ -0,0 +1,134 @@
22208 +/*
22209 + *  linux/kernel/vserver/signal.c
22210 + *
22211 + *  Virtual Server: Signal Support
22212 + *
22213 + *  Copyright (C) 2003-2007  Herbert Pötzl
22214 + *
22215 + *  V0.01  broken out from vcontext V0.05
22216 + *  V0.02  changed vcmds to vxi arg
22217 + *  V0.03  adjusted siginfo for kill
22218 + *
22219 + */
22220 +
22221 +#include <asm/uaccess.h>
22222 +
22223 +#include <linux/vs_context.h>
22224 +#include <linux/vs_pid.h>
22225 +#include <linux/vserver/signal_cmd.h>
22226 +
22227 +
22228 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
22229 +{
22230 +       int retval, count = 0;
22231 +       struct task_struct *p;
22232 +       struct siginfo *sip = SEND_SIG_PRIV;
22233 +
22234 +       retval = -ESRCH;
22235 +       vxdprintk(VXD_CBIT(misc, 4),
22236 +               "vx_info_kill(%p[#%d],%d,%d)*",
22237 +               vxi, vxi->vx_id, pid, sig);
22238 +       read_lock(&tasklist_lock);
22239 +       switch (pid) {
22240 +       case  0:
22241 +       case -1:
22242 +               for_each_process(p) {
22243 +                       int err = 0;
22244 +
22245 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
22246 +                               (pid && vxi->vx_initpid == p->pid))
22247 +                               continue;
22248 +
22249 +                       err = group_send_sig_info(sig, sip, p);
22250 +                       ++count;
22251 +                       if (err != -EPERM)
22252 +                               retval = err;
22253 +               }
22254 +               break;
22255 +
22256 +       case 1:
22257 +               if (vxi->vx_initpid) {
22258 +                       pid = vxi->vx_initpid;
22259 +                       /* for now, only SIGINT to private init ... */
22260 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22261 +                               /* ... as long as there are tasks left */
22262 +                               (atomic_read(&vxi->vx_tasks) > 1))
22263 +                               sig = SIGINT;
22264 +               }
22265 +               /* fallthrough */
22266 +       default:
22267 +               rcu_read_lock();
22268 +               p = find_task_by_real_pid(pid);
22269 +               rcu_read_unlock();
22270 +               if (p) {
22271 +                       if (vx_task_xid(p) == vxi->vx_id)
22272 +                               retval = group_send_sig_info(sig, sip, p);
22273 +               }
22274 +               break;
22275 +       }
22276 +       read_unlock(&tasklist_lock);
22277 +       vxdprintk(VXD_CBIT(misc, 4),
22278 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
22279 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
22280 +       return retval;
22281 +}
22282 +
22283 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
22284 +{
22285 +       struct vcmd_ctx_kill_v0 vc_data;
22286 +
22287 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22288 +               return -EFAULT;
22289 +
22290 +       /* special check to allow guest shutdown */
22291 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22292 +               /* forbid killall pid=0 when init is present */
22293 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
22294 +               (vc_data.pid > 1)))
22295 +               return -EACCES;
22296 +
22297 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
22298 +}
22299 +
22300 +
22301 +static int __wait_exit(struct vx_info *vxi)
22302 +{
22303 +       DECLARE_WAITQUEUE(wait, current);
22304 +       int ret = 0;
22305 +
22306 +       add_wait_queue(&vxi->vx_wait, &wait);
22307 +       set_current_state(TASK_INTERRUPTIBLE);
22308 +
22309 +wait:
22310 +       if (vx_info_state(vxi,
22311 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
22312 +               goto out;
22313 +       if (signal_pending(current)) {
22314 +               ret = -ERESTARTSYS;
22315 +               goto out;
22316 +       }
22317 +       schedule();
22318 +       goto wait;
22319 +
22320 +out:
22321 +       set_current_state(TASK_RUNNING);
22322 +       remove_wait_queue(&vxi->vx_wait, &wait);
22323 +       return ret;
22324 +}
22325 +
22326 +
22327 +
22328 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
22329 +{
22330 +       struct vcmd_wait_exit_v0 vc_data;
22331 +       int ret;
22332 +
22333 +       ret = __wait_exit(vxi);
22334 +       vc_data.reboot_cmd = vxi->reboot_cmd;
22335 +       vc_data.exit_code = vxi->exit_code;
22336 +
22337 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22338 +               ret = -EFAULT;
22339 +       return ret;
22340 +}
22341 +
22342 diff -NurpP --minimal linux-3.9.4/kernel/vserver/space.c linux-3.9.4-vs2.3.6.3/kernel/vserver/space.c
22343 --- linux-3.9.4/kernel/vserver/space.c  1970-01-01 00:00:00.000000000 +0000
22344 +++ linux-3.9.4-vs2.3.6.3/kernel/vserver/space.c        2013-05-31 14:47:11.000000000 +0000
22345 @@ -0,0 +1,436 @@
22346 +/*
22347 + *  linux/kernel/vserver/space.c
22348 + *
22349 + *  Virtual Server: Context Space Support
22350 + *
22351 + *  Copyright (C) 2003-2010  Herbert Pötzl
22352 + *
22353 + *  V0.01  broken out from context.c 0.07
22354 + *  V0.02  added task locking for namespace
22355 + *  V0.03  broken out vx_enter_namespace
22356 + *  V0.04  added *space support and commands
22357 + *  V0.05  added credential support
22358 + *
22359 + */
22360 +
22361 +#include <linux/utsname.h>
22362 +#include <linux/nsproxy.h>
22363 +#include <linux/err.h>
22364 +#include <linux/fs_struct.h>
22365 +#include <linux/cred.h>
22366 +#include <asm/uaccess.h>
22367 +
22368 +#include <linux/vs_context.h>
22369 +#include <linux/vserver/space.h>
22370 +#include <linux/vserver/space_cmd.h>
22371 +
22372 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
22373 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
22374 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
22375 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
22376 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
22377 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
22378 +
22379 +
22380 +/* namespace functions */
22381 +
22382 +#include <linux/mnt_namespace.h>
22383 +#include <linux/user_namespace.h>
22384 +#include <linux/pid_namespace.h>
22385 +#include <linux/ipc_namespace.h>
22386 +#include <net/net_namespace.h>
22387 +#include "../fs/mount.h"
22388 +
22389 +
22390 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
22391 +       .mask = CLONE_FS |
22392 +               CLONE_NEWNS |
22393 +#ifdef CONFIG_UTS_NS
22394 +               CLONE_NEWUTS |
22395 +#endif
22396 +#ifdef CONFIG_IPC_NS
22397 +               CLONE_NEWIPC |
22398 +#endif
22399 +#ifdef CONFIG_USER_NS
22400 +               CLONE_NEWUSER |
22401 +#endif
22402 +               0
22403 +};
22404 +
22405 +static const struct vcmd_space_mask_v1 space_mask = {
22406 +       .mask = CLONE_FS |
22407 +               CLONE_NEWNS |
22408 +#ifdef CONFIG_UTS_NS
22409 +               CLONE_NEWUTS |
22410 +#endif
22411 +#ifdef CONFIG_IPC_NS
22412 +               CLONE_NEWIPC |
22413 +#endif
22414 +#ifdef CONFIG_USER_NS
22415 +               CLONE_NEWUSER |
22416 +#endif
22417 +#ifdef CONFIG_PID_NS
22418 +               CLONE_NEWPID |
22419 +#endif
22420 +#ifdef CONFIG_NET_NS
22421 +               CLONE_NEWNET |
22422 +#endif
22423 +               0
22424 +};
22425 +
22426 +static const struct vcmd_space_mask_v1 default_space_mask = {
22427 +       .mask = CLONE_FS |
22428 +               CLONE_NEWNS |
22429 +#ifdef CONFIG_UTS_NS
22430 +               CLONE_NEWUTS |
22431 +#endif
22432 +#ifdef CONFIG_IPC_NS
22433 +               CLONE_NEWIPC |
22434 +#endif
22435 +#ifdef CONFIG_USER_NS
22436 +               CLONE_NEWUSER |
22437 +#endif
22438 +#ifdef CONFIG_PID_NS
22439 +//             CLONE_NEWPID |
22440 +#endif
22441 +               0
22442 +};
22443 +
22444 +/*
22445 + *     build a new nsproxy mix
22446 + *      assumes that both proxies are 'const'
22447 + *     does not touch nsproxy refcounts
22448 + *     will hold a reference on the result.
22449 + */
22450 +
22451 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
22452 +       struct nsproxy *new_nsproxy, unsigned long mask)
22453 +{
22454 +       struct mnt_namespace *old_ns;
22455 +       struct uts_namespace *old_uts;
22456 +       struct ipc_namespace *old_ipc;
22457 +#ifdef CONFIG_PID_NS
22458 +       struct pid_namespace *old_pid;
22459 +#endif
22460 +#ifdef CONFIG_NET_NS
22461 +       struct net *old_net;
22462 +#endif
22463 +       struct nsproxy *nsproxy;
22464 +
22465 +       nsproxy = copy_nsproxy(old_nsproxy);
22466 +       if (!nsproxy)
22467 +               goto out;
22468 +
22469 +       if (mask & CLONE_NEWNS) {
22470 +               old_ns = nsproxy->mnt_ns;
22471 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
22472 +               if (nsproxy->mnt_ns)
22473 +                       get_mnt_ns(nsproxy->mnt_ns);
22474 +       } else
22475 +               old_ns = NULL;
22476 +
22477 +       if (mask & CLONE_NEWUTS) {
22478 +               old_uts = nsproxy->uts_ns;
22479 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
22480 +               if (nsproxy->uts_ns)
22481 +                       get_uts_ns(nsproxy->uts_ns);
22482 +       } else
22483 +               old_uts = NULL;
22484 +
22485 +       if (mask & CLONE_NEWIPC) {
22486 +               old_ipc = nsproxy->ipc_ns;
22487 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
22488 +               if (nsproxy->ipc_ns)
22489 +                       get_ipc_ns(nsproxy->ipc_ns);
22490 +       } else
22491 +               old_ipc = NULL;
22492 +
22493 +#ifdef CONFIG_PID_NS
22494 +       if (mask & CLONE_NEWPID) {
22495 +               old_pid = nsproxy->pid_ns;
22496 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
22497 +               if (nsproxy->pid_ns)
22498 +                       get_pid_ns(nsproxy->pid_ns);
22499 +       } else
22500 +               old_pid = NULL;
22501 +#endif
22502 +#ifdef CONFIG_NET_NS
22503 +       if (mask & CLONE_NEWNET) {
22504 +               old_net = nsproxy->net_ns;
22505 +               nsproxy->net_ns = new_nsproxy->net_ns;
22506 +               if (nsproxy->net_ns)
22507 +                       get_net(nsproxy->net_ns);
22508 +       } else
22509 +               old_net = NULL;
22510 +#endif
22511 +       if (old_ns)
22512 +               put_mnt_ns(old_ns);
22513 +       if (old_uts)
22514 +               put_uts_ns(old_uts);
22515 +       if (old_ipc)
22516 +               put_ipc_ns(old_ipc);
22517 +#ifdef CONFIG_PID_NS
22518 +       if (old_pid)
22519 +               put_pid_ns(old_pid);
22520 +#endif
22521 +#ifdef CONFIG_NET_NS
22522 +       if (old_net)
22523 +               put_net(old_net);
22524 +#endif
22525 +out:
22526 +       return nsproxy;
22527 +}
22528 +
22529 +
22530 +/*
22531 + *     merge two nsproxy structs into a new one.
22532 + *     will hold a reference on the result.
22533 + */
22534 +
22535 +static inline
22536 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
22537 +       struct nsproxy *proxy, unsigned long mask)
22538 +{
22539 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
22540 +
22541 +       if (!proxy)
22542 +               return NULL;
22543 +
22544 +       if (mask) {
22545 +               /* vs_mix_nsproxy returns with reference */
22546 +               return vs_mix_nsproxy(old ? old : &null_proxy,
22547 +                       proxy, mask);
22548 +       }
22549 +       get_nsproxy(proxy);
22550 +       return proxy;
22551 +}
22552 +
22553 +
22554 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
22555 +{
22556 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
22557 +       struct fs_struct *fs_cur, *fs = NULL;
22558 +       struct _vx_space *space;
22559 +       int ret, kill = 0;
22560 +
22561 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
22562 +               vxi, vxi->vx_id, mask, index);
22563 +
22564 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
22565 +               return -EACCES;
22566 +
22567 +       if (index >= VX_SPACES)
22568 +               return -EINVAL;
22569 +
22570 +       space = &vxi->space[index];
22571 +
22572 +       if (!mask)
22573 +               mask = space->vx_nsmask;
22574 +
22575 +       if ((mask & space->vx_nsmask) != mask)
22576 +               return -EINVAL;
22577 +
22578 +       if (mask & CLONE_FS) {
22579 +               fs = copy_fs_struct(space->vx_fs);
22580 +               if (!fs)
22581 +                       return -ENOMEM;
22582 +       }
22583 +       proxy = space->vx_nsproxy;
22584 +
22585 +       vxdprintk(VXD_CBIT(space, 9),
22586 +               "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
22587 +               vxi, vxi->vx_id, mask, index, proxy, fs);
22588 +
22589 +       task_lock(current);
22590 +       fs_cur = current->fs;
22591 +
22592 +       if (mask & CLONE_FS) {
22593 +               spin_lock(&fs_cur->lock);
22594 +               current->fs = fs;
22595 +               kill = !--fs_cur->users;
22596 +               spin_unlock(&fs_cur->lock);
22597 +       }
22598 +
22599 +       proxy_cur = current->nsproxy;
22600 +       get_nsproxy(proxy_cur);
22601 +       task_unlock(current);
22602 +
22603 +       if (kill)
22604 +               free_fs_struct(fs_cur);
22605 +
22606 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
22607 +       if (IS_ERR(proxy_new)) {
22608 +               ret = PTR_ERR(proxy_new);
22609 +               goto out_put;
22610 +       }
22611 +
22612 +       proxy_new = xchg(&current->nsproxy, proxy_new);
22613 +
22614 +       if (mask & CLONE_NEWUSER) {
22615 +               struct cred *cred;
22616 +
22617 +               vxdprintk(VXD_CBIT(space, 10),
22618 +                       "vx_enter_space(%p[#%u],%p) cred (%p,%p)",
22619 +                       vxi, vxi->vx_id, space->vx_cred,
22620 +                       current->real_cred, current->cred);
22621 +
22622 +               if (space->vx_cred) {
22623 +                       cred = __prepare_creds(space->vx_cred);
22624 +                       if (cred)
22625 +                               commit_creds(cred);
22626 +               }
22627 +       }
22628 +
22629 +       ret = 0;
22630 +
22631 +       if (proxy_new)
22632 +               put_nsproxy(proxy_new);
22633 +out_put:
22634 +       if (proxy_cur)
22635 +               put_nsproxy(proxy_cur);
22636 +       return ret;
22637 +}
22638 +
22639 +
22640 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
22641 +{
22642 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
22643 +       struct fs_struct *fs_vxi, *fs = NULL;
22644 +       struct _vx_space *space;
22645 +       int ret, kill = 0;
22646 +
22647 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
22648 +               vxi, vxi->vx_id, mask, index);
22649 +
22650 +       if ((mask & space_mask.mask) != mask)
22651 +               return -EINVAL;
22652 +
22653 +       if (index >= VX_SPACES)
22654 +               return -EINVAL;
22655 +
22656 +       space = &vxi->space[index];
22657 +
22658 +       proxy_vxi = space->vx_nsproxy;
22659 +       fs_vxi = space->vx_fs;
22660 +
22661 +       if (mask & CLONE_FS) {
22662 +               fs = copy_fs_struct(current->fs);
22663 +               if (!fs)
22664 +                       return -ENOMEM;
22665 +       }
22666 +
22667 +       task_lock(current);
22668 +
22669 +       if (mask & CLONE_FS) {
22670 +               spin_lock(&fs_vxi->lock);
22671 +               space->vx_fs = fs;
22672 +               kill = !--fs_vxi->users;
22673 +               spin_unlock(&fs_vxi->lock);
22674 +       }
22675 +
22676 +       proxy_cur = current->nsproxy;
22677 +       get_nsproxy(proxy_cur);
22678 +       task_unlock(current);
22679 +
22680 +       if (kill)
22681 +               free_fs_struct(fs_vxi);
22682 +
22683 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
22684 +       if (IS_ERR(proxy_new)) {
22685 +               ret = PTR_ERR(proxy_new);
22686 +               goto out_put;
22687 +       }
22688 +
22689 +       proxy_new = xchg(&space->vx_nsproxy, proxy_new);
22690 +       space->vx_nsmask |= mask;
22691 +
22692 +       if (mask & CLONE_NEWUSER) {
22693 +               struct cred *cred;
22694 +
22695 +               vxdprintk(VXD_CBIT(space, 10),
22696 +                       "vx_set_space(%p[#%u],%p) cred (%p,%p)",
22697 +                       vxi, vxi->vx_id, space->vx_cred,
22698 +                       current->real_cred, current->cred);
22699 +
22700 +               cred = prepare_creds();
22701 +               cred = (struct cred *)xchg(&space->vx_cred, cred);
22702 +               if (cred)
22703 +                       abort_creds(cred);
22704 +       }
22705 +
22706 +       ret = 0;
22707 +
22708 +       if (proxy_new)
22709 +               put_nsproxy(proxy_new);
22710 +out_put:
22711 +       if (proxy_cur)
22712 +               put_nsproxy(proxy_cur);
22713 +       return ret;
22714 +}
22715 +
22716 +
22717 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
22718 +{
22719 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22720 +
22721 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22722 +               return -EFAULT;
22723 +
22724 +       return vx_enter_space(vxi, vc_data.mask, 0);
22725 +}
22726 +
22727 +int vc_enter_space(struct vx_info *vxi, void __user *data)
22728 +{
22729 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22730 +
22731 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22732 +               return -EFAULT;
22733 +
22734 +       if (vc_data.index >= VX_SPACES)
22735 +               return -EINVAL;
22736 +
22737 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
22738 +}
22739 +
22740 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
22741 +{
22742 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22743 +
22744 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22745 +               return -EFAULT;
22746 +
22747 +       return vx_set_space(vxi, vc_data.mask, 0);
22748 +}
22749 +
22750 +int vc_set_space(struct vx_info *vxi, void __user *data)
22751 +{
22752 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22753 +
22754 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22755 +               return -EFAULT;
22756 +
22757 +       if (vc_data.index >= VX_SPACES)
22758 +               return -EINVAL;
22759 +
22760 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
22761 +}
22762 +
22763 +int vc_get_space_mask(void __user *data, int type)
22764 +{
22765 +       const struct vcmd_space_mask_v1 *mask;
22766 +
22767 +       if (type == 0)
22768 +               mask = &space_mask_v0;
22769 +       else if (type == 1)
22770 +               mask = &space_mask;
22771 +       else
22772 +               mask = &default_space_mask;
22773 +
22774 +       vxdprintk(VXD_CBIT(space, 10),
22775 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
22776 +
22777 +       if (copy_to_user(data, mask, sizeof(*mask)))
22778 +               return -EFAULT;
22779 +       return 0;
22780 +}
22781 +
22782 diff -NurpP --minimal linux-3.9.4/kernel/vserver/switch.c linux-3.9.4-vs2.3.6.3/kernel/vserver/switch.c
22783 --- linux-3.9.4/kernel/vserver/switch.c 1970-01-01 00:00:00.000000000 +0000
22784 +++ linux-3.9.4-vs2.3.6.3/kernel/vserver/switch.c       2013-05-31 14:47:11.000000000 +0000
22785 @@ -0,0 +1,556 @@
22786 +/*
22787 + *  linux/kernel/vserver/switch.c
22788 + *
22789 + *  Virtual Server: Syscall Switch
22790 + *
22791 + *  Copyright (C) 2003-2011  Herbert Pötzl
22792 + *
22793 + *  V0.01  syscall switch
22794 + *  V0.02  added signal to context
22795 + *  V0.03  added rlimit functions
22796 + *  V0.04  added iattr, task/xid functions
22797 + *  V0.05  added debug/history stuff
22798 + *  V0.06  added compat32 layer
22799 + *  V0.07  vcmd args and perms
22800 + *  V0.08  added status commands
22801 + *  V0.09  added tag commands
22802 + *  V0.10  added oom bias
22803 + *  V0.11  added device commands
22804 + *  V0.12  added warn mask
22805 + *
22806 + */
22807 +
22808 +#include <linux/vs_context.h>
22809 +#include <linux/vs_network.h>
22810 +#include <linux/vserver/switch.h>
22811 +
22812 +#include "vci_config.h"
22813 +
22814 +
22815 +static inline
22816 +int vc_get_version(uint32_t id)
22817 +{
22818 +       return VCI_VERSION;
22819 +}
22820 +
22821 +static inline
22822 +int vc_get_vci(uint32_t id)
22823 +{
22824 +       return vci_kernel_config();
22825 +}
22826 +
22827 +#include <linux/vserver/context_cmd.h>
22828 +#include <linux/vserver/cvirt_cmd.h>
22829 +#include <linux/vserver/cacct_cmd.h>
22830 +#include <linux/vserver/limit_cmd.h>
22831 +#include <linux/vserver/network_cmd.h>
22832 +#include <linux/vserver/sched_cmd.h>
22833 +#include <linux/vserver/debug_cmd.h>
22834 +#include <linux/vserver/inode_cmd.h>
22835 +#include <linux/vserver/dlimit_cmd.h>
22836 +#include <linux/vserver/signal_cmd.h>
22837 +#include <linux/vserver/space_cmd.h>
22838 +#include <linux/vserver/tag_cmd.h>
22839 +#include <linux/vserver/device_cmd.h>
22840 +
22841 +#include <linux/vserver/inode.h>
22842 +#include <linux/vserver/dlimit.h>
22843 +
22844 +
22845 +#ifdef CONFIG_COMPAT
22846 +#define __COMPAT(name, id, data, compat)       \
22847 +       (compat) ? name ## _x32(id, data) : name(id, data)
22848 +#define __COMPAT_NO_ID(name, data, compat)     \
22849 +       (compat) ? name ## _x32(data) : name(data)
22850 +#else
22851 +#define __COMPAT(name, id, data, compat)       \
22852 +       name(id, data)
22853 +#define __COMPAT_NO_ID(name, data, compat)     \
22854 +       name(data)
22855 +#endif
22856 +
22857 +
22858 +static inline
22859 +long do_vcmd(uint32_t cmd, uint32_t id,
22860 +       struct vx_info *vxi, struct nx_info *nxi,
22861 +       void __user *data, int compat)
22862 +{
22863 +       switch (cmd) {
22864 +
22865 +       case VCMD_get_version:
22866 +               return vc_get_version(id);
22867 +       case VCMD_get_vci:
22868 +               return vc_get_vci(id);
22869 +
22870 +       case VCMD_task_xid:
22871 +               return vc_task_xid(id);
22872 +       case VCMD_vx_info:
22873 +               return vc_vx_info(vxi, data);
22874 +
22875 +       case VCMD_task_nid:
22876 +               return vc_task_nid(id);
22877 +       case VCMD_nx_info:
22878 +               return vc_nx_info(nxi, data);
22879 +
22880 +       case VCMD_task_tag:
22881 +               return vc_task_tag(id);
22882 +
22883 +       case VCMD_set_space_v1:
22884 +               return vc_set_space_v1(vxi, data);
22885 +       /* this is version 2 */
22886 +       case VCMD_set_space:
22887 +               return vc_set_space(vxi, data);
22888 +
22889 +       case VCMD_get_space_mask_v0:
22890 +               return vc_get_space_mask(data, 0);
22891 +       /* this is version 1 */
22892 +       case VCMD_get_space_mask:
22893 +               return vc_get_space_mask(data, 1);
22894 +
22895 +       case VCMD_get_space_default:
22896 +               return vc_get_space_mask(data, -1);
22897 +
22898 +       case VCMD_set_umask:
22899 +               return vc_set_umask(vxi, data);
22900 +
22901 +       case VCMD_get_umask:
22902 +               return vc_get_umask(vxi, data);
22903 +
22904 +       case VCMD_set_wmask:
22905 +               return vc_set_wmask(vxi, data);
22906 +
22907 +       case VCMD_get_wmask:
22908 +               return vc_get_wmask(vxi, data);
22909 +#ifdef CONFIG_IA32_EMULATION
22910 +       case VCMD_get_rlimit:
22911 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
22912 +       case VCMD_set_rlimit:
22913 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
22914 +#else
22915 +       case VCMD_get_rlimit:
22916 +               return vc_get_rlimit(vxi, data);
22917 +       case VCMD_set_rlimit:
22918 +               return vc_set_rlimit(vxi, data);
22919 +#endif
22920 +       case VCMD_get_rlimit_mask:
22921 +               return vc_get_rlimit_mask(id, data);
22922 +       case VCMD_reset_hits:
22923 +               return vc_reset_hits(vxi, data);
22924 +       case VCMD_reset_minmax:
22925 +               return vc_reset_minmax(vxi, data);
22926 +
22927 +       case VCMD_get_vhi_name:
22928 +               return vc_get_vhi_name(vxi, data);
22929 +       case VCMD_set_vhi_name:
22930 +               return vc_set_vhi_name(vxi, data);
22931 +
22932 +       case VCMD_ctx_stat:
22933 +               return vc_ctx_stat(vxi, data);
22934 +       case VCMD_virt_stat:
22935 +               return vc_virt_stat(vxi, data);
22936 +       case VCMD_sock_stat:
22937 +               return vc_sock_stat(vxi, data);
22938 +       case VCMD_rlimit_stat:
22939 +               return vc_rlimit_stat(vxi, data);
22940 +
22941 +       case VCMD_set_cflags:
22942 +               return vc_set_cflags(vxi, data);
22943 +       case VCMD_get_cflags:
22944 +               return vc_get_cflags(vxi, data);
22945 +
22946 +       /* this is version 1 */
22947 +       case VCMD_set_ccaps:
22948 +               return vc_set_ccaps(vxi, data);
22949 +       /* this is version 1 */
22950 +       case VCMD_get_ccaps:
22951 +               return vc_get_ccaps(vxi, data);
22952 +       case VCMD_set_bcaps:
22953 +               return vc_set_bcaps(vxi, data);
22954 +       case VCMD_get_bcaps:
22955 +               return vc_get_bcaps(vxi, data);
22956 +
22957 +       case VCMD_set_badness:
22958 +               return vc_set_badness(vxi, data);
22959 +       case VCMD_get_badness:
22960 +               return vc_get_badness(vxi, data);
22961 +
22962 +       case VCMD_set_nflags:
22963 +               return vc_set_nflags(nxi, data);
22964 +       case VCMD_get_nflags:
22965 +               return vc_get_nflags(nxi, data);
22966 +
22967 +       case VCMD_set_ncaps:
22968 +               return vc_set_ncaps(nxi, data);
22969 +       case VCMD_get_ncaps:
22970 +               return vc_get_ncaps(nxi, data);
22971 +
22972 +       case VCMD_set_prio_bias:
22973 +               return vc_set_prio_bias(vxi, data);
22974 +       case VCMD_get_prio_bias:
22975 +               return vc_get_prio_bias(vxi, data);
22976 +       case VCMD_add_dlimit:
22977 +               return __COMPAT(vc_add_dlimit, id, data, compat);
22978 +       case VCMD_rem_dlimit:
22979 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
22980 +       case VCMD_set_dlimit:
22981 +               return __COMPAT(vc_set_dlimit, id, data, compat);
22982 +       case VCMD_get_dlimit:
22983 +               return __COMPAT(vc_get_dlimit, id, data, compat);
22984 +
22985 +       case VCMD_ctx_kill:
22986 +               return vc_ctx_kill(vxi, data);
22987 +
22988 +       case VCMD_wait_exit:
22989 +               return vc_wait_exit(vxi, data);
22990 +
22991 +       case VCMD_get_iattr:
22992 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
22993 +       case VCMD_set_iattr:
22994 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
22995 +
22996 +       case VCMD_fget_iattr:
22997 +               return vc_fget_iattr(id, data);
22998 +       case VCMD_fset_iattr:
22999 +               return vc_fset_iattr(id, data);
23000 +
23001 +       case VCMD_enter_space_v0:
23002 +               return vc_enter_space_v1(vxi, NULL);
23003 +       case VCMD_enter_space_v1:
23004 +               return vc_enter_space_v1(vxi, data);
23005 +       /* this is version 2 */
23006 +       case VCMD_enter_space:
23007 +               return vc_enter_space(vxi, data);
23008 +
23009 +       case VCMD_ctx_create_v0:
23010 +               return vc_ctx_create(id, NULL);
23011 +       case VCMD_ctx_create:
23012 +               return vc_ctx_create(id, data);
23013 +       case VCMD_ctx_migrate_v0:
23014 +               return vc_ctx_migrate(vxi, NULL);
23015 +       case VCMD_ctx_migrate:
23016 +               return vc_ctx_migrate(vxi, data);
23017 +
23018 +       case VCMD_net_create_v0:
23019 +               return vc_net_create(id, NULL);
23020 +       case VCMD_net_create:
23021 +               return vc_net_create(id, data);
23022 +       case VCMD_net_migrate:
23023 +               return vc_net_migrate(nxi, data);
23024 +
23025 +       case VCMD_tag_migrate:
23026 +               return vc_tag_migrate(id);
23027 +
23028 +       case VCMD_net_add:
23029 +               return vc_net_add(nxi, data);
23030 +       case VCMD_net_remove:
23031 +               return vc_net_remove(nxi, data);
23032 +
23033 +       case VCMD_net_add_ipv4_v1:
23034 +               return vc_net_add_ipv4_v1(nxi, data);
23035 +       /* this is version 2 */
23036 +       case VCMD_net_add_ipv4:
23037 +               return vc_net_add_ipv4(nxi, data);
23038 +
23039 +       case VCMD_net_rem_ipv4_v1:
23040 +               return vc_net_rem_ipv4_v1(nxi, data);
23041 +       /* this is version 2 */
23042 +       case VCMD_net_rem_ipv4:
23043 +               return vc_net_rem_ipv4(nxi, data);
23044 +#ifdef CONFIG_IPV6
23045 +       case VCMD_net_add_ipv6:
23046 +               return vc_net_add_ipv6(nxi, data);
23047 +       case VCMD_net_remove_ipv6:
23048 +               return vc_net_remove_ipv6(nxi, data);
23049 +#endif
23050 +/*     case VCMD_add_match_ipv4:
23051 +               return vc_add_match_ipv4(nxi, data);
23052 +       case VCMD_get_match_ipv4:
23053 +               return vc_get_match_ipv4(nxi, data);
23054 +#ifdef CONFIG_IPV6
23055 +       case VCMD_add_match_ipv6:
23056 +               return vc_add_match_ipv6(nxi, data);
23057 +       case VCMD_get_match_ipv6:
23058 +               return vc_get_match_ipv6(nxi, data);
23059 +#endif */
23060 +
23061 +#ifdef CONFIG_VSERVER_DEVICE
23062 +       case VCMD_set_mapping:
23063 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
23064 +       case VCMD_unset_mapping:
23065 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
23066 +#endif
23067 +#ifdef CONFIG_VSERVER_HISTORY
23068 +       case VCMD_dump_history:
23069 +               return vc_dump_history(id);
23070 +       case VCMD_read_history:
23071 +               return __COMPAT(vc_read_history, id, data, compat);
23072 +#endif
23073 +       default:
23074 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
23075 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
23076 +       }
23077 +       return -ENOSYS;
23078 +}
23079 +
23080 +
23081 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
23082 +       case VCMD_ ## vcmd: perm = _perm;               \
23083 +               args = _args; flags = _flags; break
23084 +
23085 +
23086 +#define VCA_NONE       0x00
23087 +#define VCA_VXI                0x01
23088 +#define VCA_NXI                0x02
23089 +
23090 +#define VCF_NONE       0x00
23091 +#define VCF_INFO       0x01
23092 +#define VCF_ADMIN      0x02
23093 +#define VCF_ARES       0x06    /* includes admin */
23094 +#define VCF_SETUP      0x08
23095 +
23096 +#define VCF_ZIDOK      0x10    /* zero id okay */
23097 +
23098 +
23099 +static inline
23100 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
23101 +{
23102 +       long ret;
23103 +       int permit = -1, state = 0;
23104 +       int perm = -1, args = 0, flags = 0;
23105 +       struct vx_info *vxi = NULL;
23106 +       struct nx_info *nxi = NULL;
23107 +
23108 +       switch (cmd) {
23109 +       /* unpriviledged commands */
23110 +       __VCMD(get_version,      0, VCA_NONE,   0);
23111 +       __VCMD(get_vci,          0, VCA_NONE,   0);
23112 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
23113 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
23114 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
23115 +       __VCMD(get_space_default,0, VCA_NONE,   0);
23116 +
23117 +       /* info commands */
23118 +       __VCMD(task_xid,         2, VCA_NONE,   0);
23119 +       __VCMD(reset_hits,       2, VCA_VXI,    0);
23120 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
23121 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
23122 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
23123 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
23124 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
23125 +       __VCMD(get_umask,        3, VCA_VXI,    VCF_INFO);
23126 +       __VCMD(get_wmask,        3, VCA_VXI,    VCF_INFO);
23127 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
23128 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
23129 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
23130 +
23131 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
23132 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
23133 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
23134 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
23135 +
23136 +       __VCMD(task_nid,         2, VCA_NONE,   0);
23137 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
23138 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
23139 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
23140 +
23141 +       __VCMD(task_tag,         2, VCA_NONE,   0);
23142 +
23143 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
23144 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
23145 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
23146 +       __VCMD(get_prio_bias,    3, VCA_VXI,    VCF_INFO);
23147 +
23148 +       /* lower admin commands */
23149 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
23150 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
23151 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
23152 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
23153 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
23154 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
23155 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
23156 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
23157 +
23158 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
23159 +       __VCMD(net_create,       5, VCA_NONE,   0);
23160 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
23161 +
23162 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
23163 +
23164 +       /* higher admin commands */
23165 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
23166 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23167 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23168 +
23169 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23170 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23171 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23172 +       __VCMD(set_umask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23173 +       __VCMD(set_wmask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23174 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23175 +
23176 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23177 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23178 +       __VCMD(set_prio_bias,    7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23179 +
23180 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23181 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23182 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23183 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23184 +       __VCMD(net_add_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23185 +       __VCMD(net_rem_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23186 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23187 +       __VCMD(net_rem_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23188 +#ifdef CONFIG_IPV6
23189 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23190 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23191 +#endif
23192 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
23193 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
23194 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
23195 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
23196 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
23197 +
23198 +#ifdef CONFIG_VSERVER_DEVICE
23199 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23200 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23201 +#endif
23202 +       /* debug level admin commands */
23203 +#ifdef CONFIG_VSERVER_HISTORY
23204 +       __VCMD(dump_history,     9, VCA_NONE,   0);
23205 +       __VCMD(read_history,     9, VCA_NONE,   0);
23206 +#endif
23207 +
23208 +       default:
23209 +               perm = -1;
23210 +       }
23211 +
23212 +       vxdprintk(VXD_CBIT(switch, 0),
23213 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
23214 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23215 +               VC_VERSION(cmd), id, data, compat,
23216 +               perm, args, flags);
23217 +
23218 +       ret = -ENOSYS;
23219 +       if (perm < 0)
23220 +               goto out;
23221 +
23222 +       state = 1;
23223 +       if (!capable(CAP_CONTEXT))
23224 +               goto out;
23225 +
23226 +       state = 2;
23227 +       /* moved here from the individual commands */
23228 +       ret = -EPERM;
23229 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
23230 +               goto out;
23231 +
23232 +       state = 3;
23233 +       /* vcmd involves resource management  */
23234 +       ret = -EPERM;
23235 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
23236 +               goto out;
23237 +
23238 +       state = 4;
23239 +       /* various legacy exceptions */
23240 +       switch (cmd) {
23241 +       /* will go away when spectator is a cap */
23242 +       case VCMD_ctx_migrate_v0:
23243 +       case VCMD_ctx_migrate:
23244 +               if (id == 1) {
23245 +                       current->xid = 1;
23246 +                       ret = 1;
23247 +                       goto out;
23248 +               }
23249 +               break;
23250 +
23251 +       /* will go away when spectator is a cap */
23252 +       case VCMD_net_migrate:
23253 +               if (id == 1) {
23254 +                       current->nid = 1;
23255 +                       ret = 1;
23256 +                       goto out;
23257 +               }
23258 +               break;
23259 +       }
23260 +
23261 +       /* vcmds are fine by default */
23262 +       permit = 1;
23263 +
23264 +       /* admin type vcmds require admin ... */
23265 +       if (flags & VCF_ADMIN)
23266 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
23267 +
23268 +       /* ... but setup type vcmds override that */
23269 +       if (!permit && (flags & VCF_SETUP))
23270 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
23271 +
23272 +       state = 5;
23273 +       ret = -EPERM;
23274 +       if (!permit)
23275 +               goto out;
23276 +
23277 +       state = 6;
23278 +       if (!id && (flags & VCF_ZIDOK))
23279 +               goto skip_id;
23280 +
23281 +       ret = -ESRCH;
23282 +       if (args & VCA_VXI) {
23283 +               vxi = lookup_vx_info(id);
23284 +               if (!vxi)
23285 +                       goto out;
23286 +
23287 +               if ((flags & VCF_ADMIN) &&
23288 +                       /* special case kill for shutdown */
23289 +                       (cmd != VCMD_ctx_kill) &&
23290 +                       /* can context be administrated? */
23291 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
23292 +                       ret = -EACCES;
23293 +                       goto out_vxi;
23294 +               }
23295 +       }
23296 +       state = 7;
23297 +       if (args & VCA_NXI) {
23298 +               nxi = lookup_nx_info(id);
23299 +               if (!nxi)
23300 +                       goto out_vxi;
23301 +
23302 +               if ((flags & VCF_ADMIN) &&
23303 +                       /* can context be administrated? */
23304 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
23305 +                       ret = -EACCES;
23306 +                       goto out_nxi;
23307 +               }
23308 +       }
23309 +skip_id:
23310 +       state = 8;
23311 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
23312 +
23313 +out_nxi:
23314 +       if ((args & VCA_NXI) && nxi)
23315 +               put_nx_info(nxi);
23316 +out_vxi:
23317 +       if ((args & VCA_VXI) && vxi)
23318 +               put_vx_info(vxi);
23319 +out:
23320 +       vxdprintk(VXD_CBIT(switch, 1),
23321 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
23322 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23323 +               VC_VERSION(cmd), ret, ret, state, permit);
23324 +       return ret;
23325 +}
23326 +
23327 +asmlinkage long
23328 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
23329 +{
23330 +       return do_vserver(cmd, id, data, 0);
23331 +}
23332 +
23333 +#ifdef CONFIG_COMPAT
23334 +
23335 +asmlinkage long
23336 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
23337 +{
23338 +       return do_vserver(cmd, id, data, 1);
23339 +}
23340 +
23341 +#endif /* CONFIG_COMPAT */
23342 diff -NurpP --minimal linux-3.9.4/kernel/vserver/sysctl.c linux-3.9.4-vs2.3.6.3/kernel/vserver/sysctl.c
23343 --- linux-3.9.4/kernel/vserver/sysctl.c 1970-01-01 00:00:00.000000000 +0000
23344 +++ linux-3.9.4-vs2.3.6.3/kernel/vserver/sysctl.c       2013-05-31 14:47:11.000000000 +0000
23345 @@ -0,0 +1,247 @@
23346 +/*
23347 + *  kernel/vserver/sysctl.c
23348 + *
23349 + *  Virtual Context Support
23350 + *
23351 + *  Copyright (C) 2004-2007  Herbert Pötzl
23352 + *
23353 + *  V0.01  basic structure
23354 + *
23355 + */
23356 +
23357 +#include <linux/module.h>
23358 +#include <linux/ctype.h>
23359 +#include <linux/sysctl.h>
23360 +#include <linux/parser.h>
23361 +#include <asm/uaccess.h>
23362 +
23363 +enum {
23364 +       CTL_DEBUG_ERROR         = 0,
23365 +       CTL_DEBUG_SWITCH        = 1,
23366 +       CTL_DEBUG_XID,
23367 +       CTL_DEBUG_NID,
23368 +       CTL_DEBUG_TAG,
23369 +       CTL_DEBUG_NET,
23370 +       CTL_DEBUG_LIMIT,
23371 +       CTL_DEBUG_CRES,
23372 +       CTL_DEBUG_DLIM,
23373 +       CTL_DEBUG_QUOTA,
23374 +       CTL_DEBUG_CVIRT,
23375 +       CTL_DEBUG_SPACE,
23376 +       CTL_DEBUG_PERM,
23377 +       CTL_DEBUG_MISC,
23378 +};
23379 +
23380 +
23381 +unsigned int vs_debug_switch   = 0;
23382 +unsigned int vs_debug_xid      = 0;
23383 +unsigned int vs_debug_nid      = 0;
23384 +unsigned int vs_debug_tag      = 0;
23385 +unsigned int vs_debug_net      = 0;
23386 +unsigned int vs_debug_limit    = 0;
23387 +unsigned int vs_debug_cres     = 0;
23388 +unsigned int vs_debug_dlim     = 0;
23389 +unsigned int vs_debug_quota    = 0;
23390 +unsigned int vs_debug_cvirt    = 0;
23391 +unsigned int vs_debug_space    = 0;
23392 +unsigned int vs_debug_perm     = 0;
23393 +unsigned int vs_debug_misc     = 0;
23394 +
23395 +
23396 +static struct ctl_table_header *vserver_table_header;
23397 +static ctl_table vserver_root_table[];
23398 +
23399 +
23400 +void vserver_register_sysctl(void)
23401 +{
23402 +       if (!vserver_table_header) {
23403 +               vserver_table_header = register_sysctl_table(vserver_root_table);
23404 +       }
23405 +
23406 +}
23407 +
23408 +void vserver_unregister_sysctl(void)
23409 +{
23410 +       if (vserver_table_header) {
23411 +               unregister_sysctl_table(vserver_table_header);
23412 +               vserver_table_header = NULL;
23413 +       }
23414 +}
23415 +
23416 +
23417 +static int proc_dodebug(ctl_table *table, int write,
23418 +       void __user *buffer, size_t *lenp, loff_t *ppos)
23419 +{
23420 +       char            tmpbuf[20], *p, c;
23421 +       unsigned int    value;
23422 +       size_t          left, len;
23423 +
23424 +       if ((*ppos && !write) || !*lenp) {
23425 +               *lenp = 0;
23426 +               return 0;
23427 +       }
23428 +
23429 +       left = *lenp;
23430 +
23431 +       if (write) {
23432 +               if (!access_ok(VERIFY_READ, buffer, left))
23433 +                       return -EFAULT;
23434 +               p = (char *)buffer;
23435 +               while (left && __get_user(c, p) >= 0 && isspace(c))
23436 +                       left--, p++;
23437 +               if (!left)
23438 +                       goto done;
23439 +
23440 +               if (left > sizeof(tmpbuf) - 1)
23441 +                       return -EINVAL;
23442 +               if (copy_from_user(tmpbuf, p, left))
23443 +                       return -EFAULT;
23444 +               tmpbuf[left] = '\0';
23445 +
23446 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
23447 +                       value = 10 * value + (*p - '0');
23448 +               if (*p && !isspace(*p))
23449 +                       return -EINVAL;
23450 +               while (left && isspace(*p))
23451 +                       left--, p++;
23452 +               *(unsigned int *)table->data = value;
23453 +       } else {
23454 +               if (!access_ok(VERIFY_WRITE, buffer, left))
23455 +                       return -EFAULT;
23456 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
23457 +               if (len > left)
23458 +                       len = left;
23459 +               if (__copy_to_user(buffer, tmpbuf, len))
23460 +                       return -EFAULT;
23461 +               if ((left -= len) > 0) {
23462 +                       if (put_user('\n', (char *)buffer + len))
23463 +                               return -EFAULT;
23464 +                       left--;
23465 +               }
23466 +       }
23467 +
23468 +done:
23469 +       *lenp -= left;
23470 +       *ppos += *lenp;
23471 +       return 0;
23472 +}
23473 +
23474 +static int zero;
23475 +
23476 +#define        CTL_ENTRY(ctl, name)                            \
23477 +       {                                               \
23478 +               .procname       = #name,                \
23479 +               .data           = &vs_ ## name,         \
23480 +               .maxlen         = sizeof(int),          \
23481 +               .mode           = 0644,                 \
23482 +               .proc_handler   = &proc_dodebug,        \
23483 +               .extra1         = &zero,                \
23484 +               .extra2         = &zero,                \
23485 +       }
23486 +
23487 +static ctl_table vserver_debug_table[] = {
23488 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
23489 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
23490 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
23491 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
23492 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
23493 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
23494 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
23495 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
23496 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
23497 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
23498 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
23499 +       CTL_ENTRY(CTL_DEBUG_PERM,       debug_perm),
23500 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
23501 +       { 0 }
23502 +};
23503 +
23504 +static ctl_table vserver_root_table[] = {
23505 +       {
23506 +               .procname       = "vserver",
23507 +               .mode           = 0555,
23508 +               .child          = vserver_debug_table
23509 +       },
23510 +       { 0 }
23511 +};
23512 +
23513 +
23514 +static match_table_t tokens = {
23515 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
23516 +       { CTL_DEBUG_XID,        "xid=%x"        },
23517 +       { CTL_DEBUG_NID,        "nid=%x"        },
23518 +       { CTL_DEBUG_TAG,        "tag=%x"        },
23519 +       { CTL_DEBUG_NET,        "net=%x"        },
23520 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
23521 +       { CTL_DEBUG_CRES,       "cres=%x"       },
23522 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
23523 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
23524 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
23525 +       { CTL_DEBUG_SPACE,      "space=%x"      },
23526 +       { CTL_DEBUG_PERM,       "perm=%x"       },
23527 +       { CTL_DEBUG_MISC,       "misc=%x"       },
23528 +       { CTL_DEBUG_ERROR,      NULL            }
23529 +};
23530 +
23531 +#define        HANDLE_CASE(id, name, val)                              \
23532 +       case CTL_DEBUG_ ## id:                                  \
23533 +               vs_debug_ ## name = val;                        \
23534 +               printk("vs_debug_" #name "=0x%x\n", val);       \
23535 +               break
23536 +
23537 +
23538 +static int __init vs_debug_setup(char *str)
23539 +{
23540 +       char *p;
23541 +       int token;
23542 +
23543 +       printk("vs_debug_setup(%s)\n", str);
23544 +       while ((p = strsep(&str, ",")) != NULL) {
23545 +               substring_t args[MAX_OPT_ARGS];
23546 +               unsigned int value;
23547 +
23548 +               if (!*p)
23549 +                       continue;
23550 +
23551 +               token = match_token(p, tokens, args);
23552 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
23553 +
23554 +               switch (token) {
23555 +               HANDLE_CASE(SWITCH, switch, value);
23556 +               HANDLE_CASE(XID,    xid,    value);
23557 +               HANDLE_CASE(NID,    nid,    value);
23558 +               HANDLE_CASE(TAG,    tag,    value);
23559 +               HANDLE_CASE(NET,    net,    value);
23560 +               HANDLE_CASE(LIMIT,  limit,  value);
23561 +               HANDLE_CASE(CRES,   cres,   value);
23562 +               HANDLE_CASE(DLIM,   dlim,   value);
23563 +               HANDLE_CASE(QUOTA,  quota,  value);
23564 +               HANDLE_CASE(CVIRT,  cvirt,  value);
23565 +               HANDLE_CASE(SPACE,  space,  value);
23566 +               HANDLE_CASE(PERM,   perm,   value);
23567 +               HANDLE_CASE(MISC,   misc,   value);
23568 +               default:
23569 +                       return -EINVAL;
23570 +                       break;
23571 +               }
23572 +       }
23573 +       return 1;
23574 +}
23575 +
23576 +__setup("vsdebug=", vs_debug_setup);
23577 +
23578 +
23579 +
23580 +EXPORT_SYMBOL_GPL(vs_debug_switch);
23581 +EXPORT_SYMBOL_GPL(vs_debug_xid);
23582 +EXPORT_SYMBOL_GPL(vs_debug_nid);
23583 +EXPORT_SYMBOL_GPL(vs_debug_net);
23584 +EXPORT_SYMBOL_GPL(vs_debug_limit);
23585 +EXPORT_SYMBOL_GPL(vs_debug_cres);
23586 +EXPORT_SYMBOL_GPL(vs_debug_dlim);
23587 +EXPORT_SYMBOL_GPL(vs_debug_quota);
23588 +EXPORT_SYMBOL_GPL(vs_debug_cvirt);
23589 +EXPORT_SYMBOL_GPL(vs_debug_space);
23590 +EXPORT_SYMBOL_GPL(vs_debug_perm);
23591 +EXPORT_SYMBOL_GPL(vs_debug_misc);
23592 +
23593 diff -NurpP --minimal linux-3.9.4/kernel/vserver/tag.c linux-3.9.4-vs2.3.6.3/kernel/vserver/tag.c
23594 --- linux-3.9.4/kernel/vserver/tag.c    1970-01-01 00:00:00.000000000 +0000
23595 +++ linux-3.9.4-vs2.3.6.3/kernel/vserver/tag.c  2013-05-31 14:47:11.000000000 +0000
23596 @@ -0,0 +1,63 @@
23597 +/*
23598 + *  linux/kernel/vserver/tag.c
23599 + *
23600 + *  Virtual Server: Shallow Tag Space
23601 + *
23602 + *  Copyright (C) 2007  Herbert Pötzl
23603 + *
23604 + *  V0.01  basic implementation
23605 + *
23606 + */
23607 +
23608 +#include <linux/sched.h>
23609 +#include <linux/vserver/debug.h>
23610 +#include <linux/vs_pid.h>
23611 +#include <linux/vs_tag.h>
23612 +
23613 +#include <linux/vserver/tag_cmd.h>
23614 +
23615 +
23616 +int dx_migrate_task(struct task_struct *p, tag_t tag)
23617 +{
23618 +       if (!p)
23619 +               BUG();
23620 +
23621 +       vxdprintk(VXD_CBIT(tag, 5),
23622 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
23623 +
23624 +       task_lock(p);
23625 +       p->tag = tag;
23626 +       task_unlock(p);
23627 +
23628 +       vxdprintk(VXD_CBIT(tag, 5),
23629 +               "moved task %p into [#%d]", p, tag);
23630 +       return 0;
23631 +}
23632 +
23633 +/* vserver syscall commands below here */
23634 +
23635 +/* taks xid and vx_info functions */
23636 +
23637 +
23638 +int vc_task_tag(uint32_t id)
23639 +{
23640 +       tag_t tag;
23641 +
23642 +       if (id) {
23643 +               struct task_struct *tsk;
23644 +               rcu_read_lock();
23645 +               tsk = find_task_by_real_pid(id);
23646 +               tag = (tsk) ? tsk->tag : -ESRCH;
23647 +               rcu_read_unlock();
23648 +       } else
23649 +               tag = dx_current_tag();
23650 +       return tag;
23651 +}
23652 +
23653 +
23654 +int vc_tag_migrate(uint32_t tag)
23655 +{
23656 +       return dx_migrate_task(current, tag & 0xFFFF);
23657 +}
23658 +
23659 +
23660 diff -NurpP --minimal linux-3.9.4/kernel/vserver/vci_config.h linux-3.9.4-vs2.3.6.3/kernel/vserver/vci_config.h
23661 --- linux-3.9.4/kernel/vserver/vci_config.h     1970-01-01 00:00:00.000000000 +0000
23662 +++ linux-3.9.4-vs2.3.6.3/kernel/vserver/vci_config.h   2013-05-31 14:47:11.000000000 +0000
23663 @@ -0,0 +1,80 @@
23664 +
23665 +/*  interface version */
23666 +
23667 +#define VCI_VERSION            0x00020308
23668 +
23669 +
23670 +enum {
23671 +       VCI_KCBIT_NO_DYNAMIC = 0,
23672 +
23673 +       VCI_KCBIT_PROC_SECURE = 4,
23674 +       /* VCI_KCBIT_HARDCPU = 5, */
23675 +       /* VCI_KCBIT_IDLELIMIT = 6, */
23676 +       /* VCI_KCBIT_IDLETIME = 7, */
23677 +
23678 +       VCI_KCBIT_COWBL = 8,
23679 +       VCI_KCBIT_FULLCOWBL = 9,
23680 +       VCI_KCBIT_SPACES = 10,
23681 +       VCI_KCBIT_NETV2 = 11,
23682 +       VCI_KCBIT_MEMCG = 12,
23683 +       VCI_KCBIT_MEMCG_SWAP = 13,
23684 +
23685 +       VCI_KCBIT_DEBUG = 16,
23686 +       VCI_KCBIT_HISTORY = 20,
23687 +       VCI_KCBIT_TAGGED = 24,
23688 +       VCI_KCBIT_PPTAG = 28,
23689 +
23690 +       VCI_KCBIT_MORE = 31,
23691 +};
23692 +
23693 +
23694 +static inline uint32_t vci_kernel_config(void)
23695 +{
23696 +       return
23697 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
23698 +
23699 +       /* configured features */
23700 +#ifdef CONFIG_VSERVER_PROC_SECURE
23701 +       (1 << VCI_KCBIT_PROC_SECURE) |
23702 +#endif
23703 +#ifdef CONFIG_VSERVER_COWBL
23704 +       (1 << VCI_KCBIT_COWBL) |
23705 +       (1 << VCI_KCBIT_FULLCOWBL) |
23706 +#endif
23707 +       (1 << VCI_KCBIT_SPACES) |
23708 +       (1 << VCI_KCBIT_NETV2) |
23709 +#ifdef CONFIG_MEMCG
23710 +       (1 << VCI_KCBIT_MEMCG) |
23711 +#endif
23712 +#ifdef CONFIG_MEMCG_SWAP
23713 +       (1 << VCI_KCBIT_MEMCG_SWAP) |
23714 +#endif
23715 +
23716 +       /* debug options */
23717 +#ifdef CONFIG_VSERVER_DEBUG
23718 +       (1 << VCI_KCBIT_DEBUG) |
23719 +#endif
23720 +#ifdef CONFIG_VSERVER_HISTORY
23721 +       (1 << VCI_KCBIT_HISTORY) |
23722 +#endif
23723 +
23724 +       /* inode context tagging */
23725 +#if    defined(CONFIG_TAGGING_NONE)
23726 +       (0 << VCI_KCBIT_TAGGED) |
23727 +#elif  defined(CONFIG_TAGGING_UID16)
23728 +       (1 << VCI_KCBIT_TAGGED) |
23729 +#elif  defined(CONFIG_TAGGING_GID16)
23730 +       (2 << VCI_KCBIT_TAGGED) |
23731 +#elif  defined(CONFIG_TAGGING_ID24)
23732 +       (3 << VCI_KCBIT_TAGGED) |
23733 +#elif  defined(CONFIG_TAGGING_INTERN)
23734 +       (4 << VCI_KCBIT_TAGGED) |
23735 +#elif  defined(CONFIG_TAGGING_RUNTIME)
23736 +       (5 << VCI_KCBIT_TAGGED) |
23737 +#else
23738 +       (7 << VCI_KCBIT_TAGGED) |
23739 +#endif
23740 +       (1 << VCI_KCBIT_PPTAG) |
23741 +       0;
23742 +}
23743 +
23744 diff -NurpP --minimal linux-3.9.4/mm/memcontrol.c linux-3.9.4-vs2.3.6.3/mm/memcontrol.c
23745 --- linux-3.9.4/mm/memcontrol.c 2013-05-31 13:45:31.000000000 +0000
23746 +++ linux-3.9.4-vs2.3.6.3/mm/memcontrol.c       2013-05-31 14:47:11.000000000 +0000
23747 @@ -1046,6 +1046,31 @@ struct mem_cgroup *mem_cgroup_from_task(
23748         return mem_cgroup_from_css(task_subsys_state(p, mem_cgroup_subsys_id));
23749  }
23750  
23751 +u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member)
23752 +{
23753 +       return res_counter_read_u64(&mem->res, member);
23754 +}
23755 +
23756 +u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member)
23757 +{
23758 +       return res_counter_read_u64(&mem->memsw, member);
23759 +}
23760 +
23761 +s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem)
23762 +{
23763 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_CACHE);
23764 +}
23765 +
23766 +s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem)
23767 +{
23768 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_RSS);
23769 +}
23770 +
23771 +s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem)
23772 +{
23773 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_FILE_MAPPED);
23774 +}
23775 +
23776  struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
23777  {
23778         struct mem_cgroup *memcg = NULL;
23779 diff -NurpP --minimal linux-3.9.4/mm/oom_kill.c linux-3.9.4-vs2.3.6.3/mm/oom_kill.c
23780 --- linux-3.9.4/mm/oom_kill.c   2013-05-31 13:45:31.000000000 +0000
23781 +++ linux-3.9.4-vs2.3.6.3/mm/oom_kill.c 2013-05-31 14:47:11.000000000 +0000
23782 @@ -35,6 +35,8 @@
23783  #include <linux/freezer.h>
23784  #include <linux/ftrace.h>
23785  #include <linux/ratelimit.h>
23786 +#include <linux/reboot.h>
23787 +#include <linux/vs_context.h>
23788  
23789  #define CREATE_TRACE_POINTS
23790  #include <trace/events/oom.h>
23791 @@ -113,11 +115,18 @@ struct task_struct *find_lock_task_mm(st
23792  static bool oom_unkillable_task(struct task_struct *p,
23793                 const struct mem_cgroup *memcg, const nodemask_t *nodemask)
23794  {
23795 -       if (is_global_init(p))
23796 +       unsigned xid = vx_current_xid();
23797 +
23798 +       /* skip the init task, global and per guest */
23799 +       if (task_is_init(p))
23800                 return true;
23801         if (p->flags & PF_KTHREAD)
23802                 return true;
23803  
23804 +       /* skip other guest and host processes if oom in guest */
23805 +       if (xid && vx_task_xid(p) != xid)
23806 +               return true;
23807 +
23808         /* When mem_cgroup_out_of_memory() and p is not member of the group */
23809         if (memcg && !task_in_mem_cgroup(p, memcg))
23810                 return true;
23811 @@ -426,8 +435,8 @@ void oom_kill_process(struct task_struct
23812                 dump_header(p, gfp_mask, order, memcg, nodemask);
23813  
23814         task_lock(p);
23815 -       pr_err("%s: Kill process %d (%s) score %d or sacrifice child\n",
23816 -               message, task_pid_nr(p), p->comm, points);
23817 +       pr_err("%s: Kill process %d:#%u (%s) score %d or sacrifice child\n",
23818 +               message, task_pid_nr(p), p->xid, p->comm, points);
23819         task_unlock(p);
23820  
23821         /*
23822 @@ -472,8 +481,8 @@ void oom_kill_process(struct task_struct
23823  
23824         /* mm cannot safely be dereferenced after task_unlock(victim) */
23825         mm = victim->mm;
23826 -       pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23827 -               task_pid_nr(victim), victim->comm, K(victim->mm->total_vm),
23828 +       pr_err("Killed process %d:#%u (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23829 +               task_pid_nr(victim), victim->xid, victim->comm, K(victim->mm->total_vm),
23830                 K(get_mm_counter(victim->mm, MM_ANONPAGES)),
23831                 K(get_mm_counter(victim->mm, MM_FILEPAGES)));
23832         task_unlock(victim);
23833 @@ -543,6 +552,8 @@ int unregister_oom_notifier(struct notif
23834  }
23835  EXPORT_SYMBOL_GPL(unregister_oom_notifier);
23836  
23837 +long vs_oom_action(unsigned int);
23838 +
23839  /*
23840   * Try to acquire the OOM killer lock for the zones in zonelist.  Returns zero
23841   * if a parallel OOM killing is already taking place that includes a zone in
23842 @@ -655,7 +666,12 @@ void out_of_memory(struct zonelist *zone
23843         /* Found nothing?!?! Either we hang forever, or we panic. */
23844         if (!p) {
23845                 dump_header(NULL, gfp_mask, order, NULL, mpol_mask);
23846 -               panic("Out of memory and no killable processes...\n");
23847 +
23848 +               /* avoid panic for guest OOM */
23849 +               if (vx_current_xid())
23850 +                       vs_oom_action(LINUX_REBOOT_CMD_OOM);
23851 +               else
23852 +                       panic("Out of memory and no killable processes...\n");
23853         }
23854         if (PTR_ERR(p) != -1UL) {
23855                 oom_kill_process(p, gfp_mask, order, points, totalpages, NULL,
23856 diff -NurpP --minimal linux-3.9.4/mm/page_alloc.c linux-3.9.4-vs2.3.6.3/mm/page_alloc.c
23857 --- linux-3.9.4/mm/page_alloc.c 2013-05-31 13:45:31.000000000 +0000
23858 +++ linux-3.9.4-vs2.3.6.3/mm/page_alloc.c       2013-05-31 15:08:50.000000000 +0000
23859 @@ -59,6 +59,8 @@
23860  #include <linux/migrate.h>
23861  #include <linux/page-debug-flags.h>
23862  #include <linux/sched/rt.h>
23863 +#include <linux/vs_base.h>
23864 +#include <linux/vs_limit.h>
23865  
23866  #include <asm/tlbflush.h>
23867  #include <asm/div64.h>
23868 @@ -2873,6 +2875,9 @@ void si_meminfo(struct sysinfo *val)
23869         val->totalhigh = totalhigh_pages;
23870         val->freehigh = nr_free_highpages();
23871         val->mem_unit = PAGE_SIZE;
23872 +
23873 +       if (vx_flags(VXF_VIRT_MEM, 0))
23874 +               vx_vsi_meminfo(val);
23875  }
23876  
23877  EXPORT_SYMBOL(si_meminfo);
23878 @@ -2893,6 +2898,9 @@ void si_meminfo_node(struct sysinfo *val
23879         val->freehigh = 0;
23880  #endif
23881         val->mem_unit = PAGE_SIZE;
23882 +
23883 +       if (vx_flags(VXF_VIRT_MEM, 0))
23884 +               vx_vsi_meminfo(val);
23885  }
23886  #endif
23887  
23888 diff -NurpP --minimal linux-3.9.4/mm/pgtable-generic.c linux-3.9.4-vs2.3.6.3/mm/pgtable-generic.c
23889 --- linux-3.9.4/mm/pgtable-generic.c    2013-02-19 13:58:57.000000000 +0000
23890 +++ linux-3.9.4-vs2.3.6.3/mm/pgtable-generic.c  2013-05-31 14:47:11.000000000 +0000
23891 @@ -6,6 +6,8 @@
23892   *  Copyright (C) 2010  Linus Torvalds
23893   */
23894  
23895 +#include <linux/mm.h>
23896 +
23897  #include <linux/pagemap.h>
23898  #include <asm/tlb.h>
23899  #include <asm-generic/pgtable.h>
23900 diff -NurpP --minimal linux-3.9.4/mm/shmem.c linux-3.9.4-vs2.3.6.3/mm/shmem.c
23901 --- linux-3.9.4/mm/shmem.c      2013-05-31 13:45:31.000000000 +0000
23902 +++ linux-3.9.4-vs2.3.6.3/mm/shmem.c    2013-05-31 14:47:11.000000000 +0000
23903 @@ -1909,7 +1909,7 @@ static int shmem_statfs(struct dentry *d
23904  {
23905         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
23906  
23907 -       buf->f_type = TMPFS_MAGIC;
23908 +       buf->f_type = TMPFS_SUPER_MAGIC;
23909         buf->f_bsize = PAGE_CACHE_SIZE;
23910         buf->f_namelen = NAME_MAX;
23911         if (sbinfo->max_blocks) {
23912 @@ -2606,7 +2606,7 @@ int shmem_fill_super(struct super_block
23913         sb->s_maxbytes = MAX_LFS_FILESIZE;
23914         sb->s_blocksize = PAGE_CACHE_SIZE;
23915         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
23916 -       sb->s_magic = TMPFS_MAGIC;
23917 +       sb->s_magic = TMPFS_SUPER_MAGIC;
23918         sb->s_op = &shmem_ops;
23919         sb->s_time_gran = 1;
23920  #ifdef CONFIG_TMPFS_XATTR
23921 diff -NurpP --minimal linux-3.9.4/mm/slab.c linux-3.9.4-vs2.3.6.3/mm/slab.c
23922 --- linux-3.9.4/mm/slab.c       2013-05-31 13:45:31.000000000 +0000
23923 +++ linux-3.9.4-vs2.3.6.3/mm/slab.c     2013-05-31 14:47:11.000000000 +0000
23924 @@ -429,6 +429,8 @@ static void kmem_list3_init(struct kmem_
23925  #define STATS_INC_FREEMISS(x)  do { } while (0)
23926  #endif
23927  
23928 +#include "slab_vs.h"
23929 +
23930  #if DEBUG
23931  
23932  /*
23933 @@ -3438,6 +3440,7 @@ retry:
23934  
23935         obj = slab_get_obj(cachep, slabp, nodeid);
23936         check_slabp(cachep, slabp);
23937 +       vx_slab_alloc(cachep, flags);
23938         l3->free_objects--;
23939         /* move slabp to correct slabp list: */
23940         list_del(&slabp->list);
23941 @@ -3517,6 +3520,7 @@ slab_alloc_node(struct kmem_cache *cache
23942         /* ___cache_alloc_node can fall back to other nodes */
23943         ptr = ____cache_alloc_node(cachep, flags, nodeid);
23944    out:
23945 +       vx_slab_alloc(cachep, flags);
23946         local_irq_restore(save_flags);
23947         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
23948         kmemleak_alloc_recursive(ptr, cachep->object_size, 1, cachep->flags,
23949 @@ -3709,6 +3713,7 @@ static inline void __cache_free(struct k
23950         check_irq_off();
23951         kmemleak_free_recursive(objp, cachep->flags);
23952         objp = cache_free_debugcheck(cachep, objp, caller);
23953 +       vx_slab_free(cachep);
23954  
23955         kmemcheck_slab_free(cachep, objp, cachep->object_size);
23956  
23957 diff -NurpP --minimal linux-3.9.4/mm/slab_vs.h linux-3.9.4-vs2.3.6.3/mm/slab_vs.h
23958 --- linux-3.9.4/mm/slab_vs.h    1970-01-01 00:00:00.000000000 +0000
23959 +++ linux-3.9.4-vs2.3.6.3/mm/slab_vs.h  2013-05-31 14:47:11.000000000 +0000
23960 @@ -0,0 +1,29 @@
23961 +
23962 +#include <linux/vserver/context.h>
23963 +
23964 +#include <linux/vs_context.h>
23965 +
23966 +static inline
23967 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
23968 +{
23969 +       int what = gfp_zone(cachep->allocflags);
23970 +       struct vx_info *vxi = current_vx_info();
23971 +
23972 +       if (!vxi)
23973 +               return;
23974 +
23975 +       atomic_add(cachep->size, &vxi->cacct.slab[what]);
23976 +}
23977 +
23978 +static inline
23979 +void vx_slab_free(struct kmem_cache *cachep)
23980 +{
23981 +       int what = gfp_zone(cachep->allocflags);
23982 +       struct vx_info *vxi = current_vx_info();
23983 +
23984 +       if (!vxi)
23985 +               return;
23986 +
23987 +       atomic_sub(cachep->size, &vxi->cacct.slab[what]);
23988 +}
23989 +
23990 diff -NurpP --minimal linux-3.9.4/mm/swapfile.c linux-3.9.4-vs2.3.6.3/mm/swapfile.c
23991 --- linux-3.9.4/mm/swapfile.c   2013-05-31 13:45:31.000000000 +0000
23992 +++ linux-3.9.4-vs2.3.6.3/mm/swapfile.c 2013-05-31 14:47:11.000000000 +0000
23993 @@ -39,6 +39,7 @@
23994  #include <asm/tlbflush.h>
23995  #include <linux/swapops.h>
23996  #include <linux/page_cgroup.h>
23997 +#include <linux/vs_base.h>
23998  
23999  static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
24000                                  unsigned char);
24001 @@ -1767,6 +1768,16 @@ static int swap_show(struct seq_file *sw
24002  
24003         if (si == SEQ_START_TOKEN) {
24004                 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
24005 +               if (vx_flags(VXF_VIRT_MEM, 0)) {
24006 +                       struct sysinfo si;
24007 +
24008 +                       vx_vsi_swapinfo(&si);
24009 +                       if (si.totalswap < (1 << 10))
24010 +                               return 0;
24011 +                       seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
24012 +                               "hdv0", "partition", si.totalswap >> 10,
24013 +                               (si.totalswap - si.freeswap) >> 10, -1);
24014 +               }
24015                 return 0;
24016         }
24017  
24018 @@ -2195,6 +2206,8 @@ void si_swapinfo(struct sysinfo *val)
24019         val->freeswap = atomic_long_read(&nr_swap_pages) + nr_to_be_unused;
24020         val->totalswap = total_swap_pages + nr_to_be_unused;
24021         spin_unlock(&swap_lock);
24022 +       if (vx_flags(VXF_VIRT_MEM, 0))
24023 +               vx_vsi_swapinfo(val);
24024  }
24025  
24026  /*
24027 diff -NurpP --minimal linux-3.9.4/net/bridge/br_multicast.c linux-3.9.4-vs2.3.6.3/net/bridge/br_multicast.c
24028 --- linux-3.9.4/net/bridge/br_multicast.c       2013-05-31 13:45:31.000000000 +0000
24029 +++ linux-3.9.4-vs2.3.6.3/net/bridge/br_multicast.c     2013-05-31 17:17:53.000000000 +0000
24030 @@ -443,7 +443,7 @@ static struct sk_buff *br_ip6_multicast_
24031         ip6h->hop_limit = 1;
24032         ipv6_addr_set(&ip6h->daddr, htonl(0xff020000), 0, 0, htonl(1));
24033         if (ipv6_dev_get_saddr(dev_net(br->dev), br->dev, &ip6h->daddr, 0,
24034 -                              &ip6h->saddr)) {
24035 +                              &ip6h->saddr, NULL)) {
24036                 kfree_skb(skb);
24037                 return NULL;
24038         }
24039 diff -NurpP --minimal linux-3.9.4/net/core/dev.c linux-3.9.4-vs2.3.6.3/net/core/dev.c
24040 --- linux-3.9.4/net/core/dev.c  2013-05-31 14:22:27.000000000 +0000
24041 +++ linux-3.9.4-vs2.3.6.3/net/core/dev.c        2013-05-31 18:37:38.000000000 +0000
24042 @@ -122,6 +122,7 @@
24043  #include <linux/in.h>
24044  #include <linux/jhash.h>
24045  #include <linux/random.h>
24046 +#include <linux/vs_inet.h>
24047  #include <trace/events/napi.h>
24048  #include <trace/events/net.h>
24049  #include <trace/events/skb.h>
24050 @@ -662,7 +663,8 @@ struct net_device *__dev_get_by_name(str
24051         struct hlist_head *head = dev_name_hash(net, name);
24052  
24053         hlist_for_each_entry(dev, head, name_hlist)
24054 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24055 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24056 +                   nx_dev_visible(current_nx_info(), dev))
24057                         return dev;
24058  
24059         return NULL;
24060 @@ -687,7 +689,8 @@ struct net_device *dev_get_by_name_rcu(s
24061         struct hlist_head *head = dev_name_hash(net, name);
24062  
24063         hlist_for_each_entry_rcu(dev, head, name_hlist)
24064 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24065 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24066 +                   nx_dev_visible(current_nx_info(), dev))
24067                         return dev;
24068  
24069         return NULL;
24070 @@ -737,7 +740,8 @@ struct net_device *__dev_get_by_index(st
24071         struct hlist_head *head = dev_index_hash(net, ifindex);
24072  
24073         hlist_for_each_entry(dev, head, index_hlist)
24074 -               if (dev->ifindex == ifindex)
24075 +               if ((dev->ifindex == ifindex) &&
24076 +                   nx_dev_visible(current_nx_info(), dev))
24077                         return dev;
24078  
24079         return NULL;
24080 @@ -755,7 +759,7 @@ EXPORT_SYMBOL(__dev_get_by_index);
24081   *     about locking. The caller must hold RCU lock.
24082   */
24083  
24084 -struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
24085 +struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex)
24086  {
24087         struct net_device *dev;
24088         struct hlist_head *head = dev_index_hash(net, ifindex);
24089 @@ -766,6 +770,16 @@ struct net_device *dev_get_by_index_rcu(
24090  
24091         return NULL;
24092  }
24093 +EXPORT_SYMBOL(dev_get_by_index_real_rcu);
24094 +
24095 +struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
24096 +{
24097 +       struct net_device *dev = dev_get_by_index_real_rcu(net, ifindex);
24098 +
24099 +       if (nx_dev_visible(current_nx_info(), dev))
24100 +               return dev;
24101 +       return NULL;
24102 +}
24103  EXPORT_SYMBOL(dev_get_by_index_rcu);
24104  
24105  
24106 @@ -814,7 +828,8 @@ struct net_device *dev_getbyhwaddr_rcu(s
24107  
24108         for_each_netdev_rcu(net, dev)
24109                 if (dev->type == type &&
24110 -                   !memcmp(dev->dev_addr, ha, dev->addr_len))
24111 +                   !memcmp(dev->dev_addr, ha, dev->addr_len) &&
24112 +                   nx_dev_visible(current_nx_info(), dev))
24113                         return dev;
24114  
24115         return NULL;
24116 @@ -826,9 +841,11 @@ struct net_device *__dev_getfirstbyhwtyp
24117         struct net_device *dev;
24118  
24119         ASSERT_RTNL();
24120 -       for_each_netdev(net, dev)
24121 -               if (dev->type == type)
24122 +       for_each_netdev(net, dev) {
24123 +               if ((dev->type == type) &&
24124 +                   nx_dev_visible(current_nx_info(), dev))
24125                         return dev;
24126 +       }
24127  
24128         return NULL;
24129  }
24130 @@ -840,7 +857,8 @@ struct net_device *dev_getfirstbyhwtype(
24131  
24132         rcu_read_lock();
24133         for_each_netdev_rcu(net, dev)
24134 -               if (dev->type == type) {
24135 +               if ((dev->type == type) &&
24136 +                   nx_dev_visible(current_nx_info(), dev)) {
24137                         dev_hold(dev);
24138                         ret = dev;
24139                         break;
24140 @@ -868,7 +886,8 @@ struct net_device *dev_get_by_flags_rcu(
24141  
24142         ret = NULL;
24143         for_each_netdev_rcu(net, dev) {
24144 -               if (((dev->flags ^ if_flags) & mask) == 0) {
24145 +               if ((((dev->flags ^ if_flags) & mask) == 0) &&
24146 +                       nx_dev_visible(current_nx_info(), dev)) {
24147                         ret = dev;
24148                         break;
24149                 }
24150 @@ -946,6 +965,8 @@ static int __dev_alloc_name(struct net *
24151                                 continue;
24152                         if (i < 0 || i >= max_netdevices)
24153                                 continue;
24154 +                       if (!nx_dev_visible(current_nx_info(), d))
24155 +                               continue;
24156  
24157                         /*  avoid cases where sscanf is not exact inverse of printf */
24158                         snprintf(buf, IFNAMSIZ, name, i);
24159 diff -NurpP --minimal linux-3.9.4/net/core/net-procfs.c linux-3.9.4-vs2.3.6.3/net/core/net-procfs.c
24160 --- linux-3.9.4/net/core/net-procfs.c   2013-05-31 13:45:32.000000000 +0000
24161 +++ linux-3.9.4-vs2.3.6.3/net/core/net-procfs.c 2013-06-01 10:40:52.000000000 +0000
24162 @@ -1,6 +1,7 @@
24163  #include <linux/netdevice.h>
24164  #include <linux/proc_fs.h>
24165  #include <linux/seq_file.h>
24166 +#include <linux/vs_inet.h>
24167  #include <net/wext.h>
24168  
24169  #define BUCKET_SPACE (32 - NETDEV_HASHBITS - 1)
24170 @@ -77,8 +78,13 @@ static void dev_seq_stop(struct seq_file
24171  static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
24172  {
24173         struct rtnl_link_stats64 temp;
24174 -       const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
24175 +       const struct rtnl_link_stats64 *stats;
24176 +
24177 +       /* device visible inside network context? */
24178 +       if (!nx_dev_visible(current_nx_info(), dev))
24179 +               return;
24180  
24181 +       stats = dev_get_stats(dev, &temp);
24182         seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
24183                    "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
24184                    dev->name, stats->rx_bytes, stats->rx_packets,
24185 diff -NurpP --minimal linux-3.9.4/net/core/rtnetlink.c linux-3.9.4-vs2.3.6.3/net/core/rtnetlink.c
24186 --- linux-3.9.4/net/core/rtnetlink.c    2013-05-31 13:45:32.000000000 +0000
24187 +++ linux-3.9.4-vs2.3.6.3/net/core/rtnetlink.c  2013-05-31 17:17:54.000000000 +0000
24188 @@ -1085,6 +1085,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
24189                 hlist_for_each_entry_rcu(dev, head, index_hlist) {
24190                         if (idx < s_idx)
24191                                 goto cont;
24192 +                       if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
24193 +                               continue;
24194                         if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
24195                                              NETLINK_CB(cb->skb).portid,
24196                                              cb->nlh->nlmsg_seq, 0,
24197 @@ -1974,6 +1976,9 @@ void rtmsg_ifinfo(int type, struct net_d
24198         int err = -ENOBUFS;
24199         size_t if_info_size;
24200  
24201 +       if (!nx_dev_visible(current_nx_info(), dev))
24202 +               return;
24203 +
24204         skb = nlmsg_new((if_info_size = if_nlmsg_size(dev, 0)), GFP_KERNEL);
24205         if (skb == NULL)
24206                 goto errout;
24207 diff -NurpP --minimal linux-3.9.4/net/core/sock.c linux-3.9.4-vs2.3.6.3/net/core/sock.c
24208 --- linux-3.9.4/net/core/sock.c 2013-05-31 14:22:27.000000000 +0000
24209 +++ linux-3.9.4-vs2.3.6.3/net/core/sock.c       2013-05-31 17:17:54.000000000 +0000
24210 @@ -132,6 +132,10 @@
24211  #include <net/netprio_cgroup.h>
24212  
24213  #include <linux/filter.h>
24214 +#include <linux/vs_socket.h>
24215 +#include <linux/vs_limit.h>
24216 +#include <linux/vs_context.h>
24217 +#include <linux/vs_network.h>
24218  
24219  #include <trace/events/sock.h>
24220  
24221 @@ -1257,6 +1261,8 @@ static struct sock *sk_prot_alloc(struct
24222                         goto out_free_sec;
24223                 sk_tx_queue_clear(sk);
24224         }
24225 +               sock_vx_init(sk);
24226 +               sock_nx_init(sk);
24227  
24228         return sk;
24229  
24230 @@ -1367,6 +1373,11 @@ static void __sk_free(struct sock *sk)
24231                 put_cred(sk->sk_peer_cred);
24232         put_pid(sk->sk_peer_pid);
24233         put_net(sock_net(sk));
24234 +       vx_sock_dec(sk);
24235 +       clr_vx_info(&sk->sk_vx_info);
24236 +       sk->sk_xid = -1;
24237 +       clr_nx_info(&sk->sk_nx_info);
24238 +       sk->sk_nid = -1;
24239         sk_prot_free(sk->sk_prot_creator, sk);
24240  }
24241  
24242 @@ -1427,6 +1438,8 @@ struct sock *sk_clone_lock(const struct
24243  
24244                 /* SANITY */
24245                 get_net(sock_net(newsk));
24246 +               sock_vx_init(newsk);
24247 +               sock_nx_init(newsk);
24248                 sk_node_init(&newsk->sk_node);
24249                 sock_lock_init(newsk);
24250                 bh_lock_sock(newsk);
24251 @@ -1483,6 +1496,12 @@ struct sock *sk_clone_lock(const struct
24252                 smp_wmb();
24253                 atomic_set(&newsk->sk_refcnt, 2);
24254  
24255 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
24256 +               newsk->sk_xid = sk->sk_xid;
24257 +               vx_sock_inc(newsk);
24258 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
24259 +               newsk->sk_nid = sk->sk_nid;
24260 +
24261                 /*
24262                  * Increment the counter in the same struct proto as the master
24263                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
24264 @@ -2278,6 +2297,12 @@ void sock_init_data(struct socket *sock,
24265  
24266         sk->sk_stamp = ktime_set(-1L, 0);
24267  
24268 +       set_vx_info(&sk->sk_vx_info, current_vx_info());
24269 +       sk->sk_xid = vx_current_xid();
24270 +       vx_sock_inc(sk);
24271 +       set_nx_info(&sk->sk_nx_info, current_nx_info());
24272 +       sk->sk_nid = nx_current_nid();
24273 +
24274         /*
24275          * Before updating sk_refcnt, we must commit prior changes to memory
24276          * (Documentation/RCU/rculist_nulls.txt for details)
24277 diff -NurpP --minimal linux-3.9.4/net/ipv4/af_inet.c linux-3.9.4-vs2.3.6.3/net/ipv4/af_inet.c
24278 --- linux-3.9.4/net/ipv4/af_inet.c      2013-05-31 13:45:32.000000000 +0000
24279 +++ linux-3.9.4-vs2.3.6.3/net/ipv4/af_inet.c    2013-06-03 17:22:33.000000000 +0000
24280 @@ -118,6 +118,7 @@
24281  #ifdef CONFIG_IP_MROUTE
24282  #include <linux/mroute.h>
24283  #endif
24284 +#include <linux/vs_limit.h>
24285  
24286  
24287  /* The inetsw table contains everything that inet_create needs to
24288 @@ -336,10 +337,13 @@ lookup_protocol:
24289         }
24290  
24291         err = -EPERM;
24292 +       if ((protocol == IPPROTO_ICMP) &&
24293 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
24294 +               goto override;
24295         if (sock->type == SOCK_RAW && !kern &&
24296             !ns_capable(net->user_ns, CAP_NET_RAW))
24297                 goto out_rcu_unlock;
24298 -
24299 +override:
24300         sock->ops = answer->ops;
24301         answer_prot = answer->prot;
24302         answer_no_check = answer->no_check;
24303 @@ -460,6 +464,7 @@ int inet_bind(struct socket *sock, struc
24304         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
24305         struct sock *sk = sock->sk;
24306         struct inet_sock *inet = inet_sk(sk);
24307 +       struct nx_v4_sock_addr nsa;
24308         struct net *net = sock_net(sk);
24309         unsigned short snum;
24310         int chk_addr_ret;
24311 @@ -484,7 +489,11 @@ int inet_bind(struct socket *sock, struc
24312                         goto out;
24313         }
24314  
24315 -       chk_addr_ret = inet_addr_type(net, addr->sin_addr.s_addr);
24316 +       err = v4_map_sock_addr(inet, addr, &nsa);
24317 +       if (err)
24318 +               goto out;
24319 +
24320 +       chk_addr_ret = inet_addr_type(net, nsa.saddr);
24321  
24322         /* Not specified by any standard per-se, however it breaks too
24323          * many applications when removed.  It is unfortunate since
24324 @@ -496,7 +505,7 @@ int inet_bind(struct socket *sock, struc
24325         err = -EADDRNOTAVAIL;
24326         if (!sysctl_ip_nonlocal_bind &&
24327             !(inet->freebind || inet->transparent) &&
24328 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
24329 +           nsa.saddr != htonl(INADDR_ANY) &&
24330             chk_addr_ret != RTN_LOCAL &&
24331             chk_addr_ret != RTN_MULTICAST &&
24332             chk_addr_ret != RTN_BROADCAST)
24333 @@ -522,7 +531,7 @@ int inet_bind(struct socket *sock, struc
24334         if (sk->sk_state != TCP_CLOSE || inet->inet_num)
24335                 goto out_release_sock;
24336  
24337 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24338 +       v4_set_sock_addr(inet, &nsa);
24339         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24340                 inet->inet_saddr = 0;  /* Use device */
24341  
24342 @@ -741,11 +750,13 @@ int inet_getname(struct socket *sock, st
24343                      peer == 1))
24344                         return -ENOTCONN;
24345                 sin->sin_port = inet->inet_dport;
24346 -               sin->sin_addr.s_addr = inet->inet_daddr;
24347 +               sin->sin_addr.s_addr =
24348 +                       nx_map_sock_lback(sk->sk_nx_info, inet->inet_daddr);
24349         } else {
24350                 __be32 addr = inet->inet_rcv_saddr;
24351                 if (!addr)
24352                         addr = inet->inet_saddr;
24353 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
24354                 sin->sin_port = inet->inet_sport;
24355                 sin->sin_addr.s_addr = addr;
24356         }
24357 diff -NurpP --minimal linux-3.9.4/net/ipv4/arp.c linux-3.9.4-vs2.3.6.3/net/ipv4/arp.c
24358 --- linux-3.9.4/net/ipv4/arp.c  2013-05-31 13:45:32.000000000 +0000
24359 +++ linux-3.9.4-vs2.3.6.3/net/ipv4/arp.c        2013-05-31 17:17:54.000000000 +0000
24360 @@ -1317,6 +1317,7 @@ static void arp_format_neigh_entry(struc
24361         struct net_device *dev = n->dev;
24362         int hatype = dev->type;
24363  
24364 +       /* FIXME: check for network context */
24365         read_lock(&n->lock);
24366         /* Convert hardware address to XX:XX:XX:XX ... form. */
24367  #if IS_ENABLED(CONFIG_AX25)
24368 @@ -1348,6 +1349,7 @@ static void arp_format_pneigh_entry(stru
24369         int hatype = dev ? dev->type : 0;
24370         char tbuf[16];
24371  
24372 +       /* FIXME: check for network context */
24373         sprintf(tbuf, "%pI4", n->key);
24374         seq_printf(seq, "%-16s 0x%-10x0x%-10x%s     *        %s\n",
24375                    tbuf, hatype, ATF_PUBL | ATF_PERM, "00:00:00:00:00:00",
24376 diff -NurpP --minimal linux-3.9.4/net/ipv4/devinet.c linux-3.9.4-vs2.3.6.3/net/ipv4/devinet.c
24377 --- linux-3.9.4/net/ipv4/devinet.c      2013-05-31 13:45:32.000000000 +0000
24378 +++ linux-3.9.4-vs2.3.6.3/net/ipv4/devinet.c    2013-05-31 17:17:54.000000000 +0000
24379 @@ -522,6 +522,7 @@ struct in_device *inetdev_by_index(struc
24380  }
24381  EXPORT_SYMBOL(inetdev_by_index);
24382  
24383 +
24384  /* Called only from RTNL semaphored context. No locks. */
24385  
24386  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
24387 @@ -940,6 +941,8 @@ int devinet_ioctl(struct net *net, unsig
24388  
24389         in_dev = __in_dev_get_rtnl(dev);
24390         if (in_dev) {
24391 +               struct nx_info *nxi = current_nx_info();
24392 +
24393                 if (tryaddrmatch) {
24394                         /* Matthias Andree */
24395                         /* compare label and address (4.4BSD style) */
24396 @@ -948,6 +951,8 @@ int devinet_ioctl(struct net *net, unsig
24397                            This is checked above. */
24398                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
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                                     sin_orig.sin_addr.s_addr ==
24404                                                         ifa->ifa_local) {
24405 @@ -960,9 +965,12 @@ int devinet_ioctl(struct net *net, unsig
24406                    comparing just the label */
24407                 if (!ifa) {
24408                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24409 -                            ifap = &ifa->ifa_next)
24410 +                            ifap = &ifa->ifa_next) {
24411 +                               if (!nx_v4_ifa_visible(nxi, ifa))
24412 +                                       continue;
24413                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
24414                                         break;
24415 +                       }
24416                 }
24417         }
24418  
24419 @@ -1116,6 +1124,8 @@ static int inet_gifconf(struct net_devic
24420                 goto out;
24421  
24422         for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
24423 +               if (!nx_v4_ifa_visible(current_nx_info(), ifa))
24424 +                       continue;
24425                 if (!buf) {
24426                         done += sizeof(ifr);
24427                         continue;
24428 @@ -1519,6 +1529,7 @@ static int inet_dump_ifaddr(struct sk_bu
24429         struct net_device *dev;
24430         struct in_device *in_dev;
24431         struct in_ifaddr *ifa;
24432 +       struct sock *sk = skb->sk;
24433         struct hlist_head *head;
24434  
24435         s_h = cb->args[0];
24436 @@ -1540,6 +1551,8 @@ static int inet_dump_ifaddr(struct sk_bu
24437  
24438                         for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
24439                              ifa = ifa->ifa_next, ip_idx++) {
24440 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
24441 +                               continue;
24442                                 if (ip_idx < s_ip_idx)
24443                                         continue;
24444                                 if (inet_fill_ifaddr(skb, ifa,
24445 diff -NurpP --minimal linux-3.9.4/net/ipv4/fib_trie.c linux-3.9.4-vs2.3.6.3/net/ipv4/fib_trie.c
24446 --- linux-3.9.4/net/ipv4/fib_trie.c     2013-05-31 13:45:32.000000000 +0000
24447 +++ linux-3.9.4-vs2.3.6.3/net/ipv4/fib_trie.c   2013-05-31 17:17:54.000000000 +0000
24448 @@ -2548,6 +2548,7 @@ static int fib_route_seq_show(struct seq
24449                             || fa->fa_type == RTN_MULTICAST)
24450                                 continue;
24451  
24452 +                       /* FIXME: check for network context? */
24453                         if (fi)
24454                                 seq_printf(seq,
24455                                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t"
24456 diff -NurpP --minimal linux-3.9.4/net/ipv4/inet_connection_sock.c linux-3.9.4-vs2.3.6.3/net/ipv4/inet_connection_sock.c
24457 --- linux-3.9.4/net/ipv4/inet_connection_sock.c 2013-05-31 13:45:32.000000000 +0000
24458 +++ linux-3.9.4-vs2.3.6.3/net/ipv4/inet_connection_sock.c       2013-05-31 18:29:56.000000000 +0000
24459 @@ -53,6 +53,37 @@ void inet_get_local_port_range(int *low,
24460  }
24461  EXPORT_SYMBOL(inet_get_local_port_range);
24462  
24463 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24464 +{
24465 +       __be32  sk1_rcv_saddr = sk_rcv_saddr(sk1),
24466 +               sk2_rcv_saddr = sk_rcv_saddr(sk2);
24467 +
24468 +       if (inet_v6_ipv6only(sk2))
24469 +               return 0;
24470 +
24471 +       if (sk1_rcv_saddr &&
24472 +           sk2_rcv_saddr &&
24473 +           sk1_rcv_saddr == sk2_rcv_saddr)
24474 +               return 1;
24475 +
24476 +       if (sk1_rcv_saddr &&
24477 +           !sk2_rcv_saddr &&
24478 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
24479 +               return 1;
24480 +
24481 +       if (sk2_rcv_saddr &&
24482 +           !sk1_rcv_saddr &&
24483 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
24484 +               return 1;
24485 +
24486 +       if (!sk1_rcv_saddr &&
24487 +           !sk2_rcv_saddr &&
24488 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
24489 +               return 1;
24490 +
24491 +       return 0;
24492 +}
24493 +
24494  int inet_csk_bind_conflict(const struct sock *sk,
24495                            const struct inet_bind_bucket *tb, bool relax)
24496  {
24497 @@ -79,17 +110,12 @@ int inet_csk_bind_conflict(const struct
24498                             (!reuseport || !sk2->sk_reuseport ||
24499                             (sk2->sk_state != TCP_TIME_WAIT &&
24500                              !uid_eq(uid, sock_i_uid(sk2))))) {
24501 -                               const __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
24502 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr(sk) ||
24503 -                                   sk2_rcv_saddr == sk_rcv_saddr(sk))
24504 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
24505                                         break;
24506                         }
24507                         if (!relax && reuse && sk2->sk_reuse &&
24508                             sk2->sk_state != TCP_LISTEN) {
24509 -                               const __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
24510 -
24511 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr(sk) ||
24512 -                                   sk2_rcv_saddr == sk_rcv_saddr(sk))
24513 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
24514                                         break;
24515                         }
24516                 }
24517 diff -NurpP --minimal linux-3.9.4/net/ipv4/inet_diag.c linux-3.9.4-vs2.3.6.3/net/ipv4/inet_diag.c
24518 --- linux-3.9.4/net/ipv4/inet_diag.c    2013-02-19 13:58:58.000000000 +0000
24519 +++ linux-3.9.4-vs2.3.6.3/net/ipv4/inet_diag.c  2013-05-31 17:17:54.000000000 +0000
24520 @@ -31,6 +31,8 @@
24521  
24522  #include <linux/inet.h>
24523  #include <linux/stddef.h>
24524 +#include <linux/vs_network.h>
24525 +#include <linux/vs_inet.h>
24526  
24527  #include <linux/inet_diag.h>
24528  #include <linux/sock_diag.h>
24529 @@ -106,8 +108,10 @@ int inet_sk_diag_fill(struct sock *sk, s
24530  
24531         r->id.idiag_sport = inet->inet_sport;
24532         r->id.idiag_dport = inet->inet_dport;
24533 -       r->id.idiag_src[0] = inet->inet_rcv_saddr;
24534 -       r->id.idiag_dst[0] = inet->inet_daddr;
24535 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info,
24536 +               inet->inet_rcv_saddr);
24537 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info,
24538 +               inet->inet_daddr);
24539  
24540         if (nla_put_u8(skb, INET_DIAG_SHUTDOWN, sk->sk_shutdown))
24541                 goto errout;
24542 @@ -242,8 +246,8 @@ static int inet_twsk_diag_fill(struct in
24543         sock_diag_save_cookie(tw, r->id.idiag_cookie);
24544         r->id.idiag_sport     = tw->tw_sport;
24545         r->id.idiag_dport     = tw->tw_dport;
24546 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
24547 -       r->id.idiag_dst[0]    = tw->tw_daddr;
24548 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
24549 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
24550         r->idiag_state        = tw->tw_substate;
24551         r->idiag_timer        = 3;
24552         r->idiag_expires      = DIV_ROUND_UP(tmo * 1000, HZ);
24553 @@ -287,12 +291,14 @@ int inet_diag_dump_one_icsk(struct inet_
24554  
24555         err = -EINVAL;
24556         if (req->sdiag_family == AF_INET) {
24557 +               /* TODO: lback */
24558                 sk = inet_lookup(net, hashinfo, req->id.idiag_dst[0],
24559                                  req->id.idiag_dport, req->id.idiag_src[0],
24560                                  req->id.idiag_sport, req->id.idiag_if);
24561         }
24562  #if IS_ENABLED(CONFIG_IPV6)
24563         else if (req->sdiag_family == AF_INET6) {
24564 +               /* TODO: lback */
24565                 sk = inet6_lookup(net, hashinfo,
24566                                   (struct in6_addr *)req->id.idiag_dst,
24567                                   req->id.idiag_dport,
24568 @@ -494,6 +500,7 @@ int inet_diag_bc_sk(const struct nlattr
24569         } else
24570  #endif
24571         {
24572 +                       /* TODO: lback */
24573                 entry.saddr = &inet->inet_rcv_saddr;
24574                 entry.daddr = &inet->inet_daddr;
24575         }
24576 @@ -652,6 +659,7 @@ static int inet_twsk_diag_dump(struct in
24577                 } else
24578  #endif
24579                 {
24580 +                       /* TODO: lback */
24581                         entry.saddr = &tw->tw_rcv_saddr;
24582                         entry.daddr = &tw->tw_daddr;
24583                 }
24584 @@ -730,8 +738,8 @@ static int inet_diag_fill_req(struct sk_
24585  
24586         r->id.idiag_sport = inet->inet_sport;
24587         r->id.idiag_dport = ireq->rmt_port;
24588 -       r->id.idiag_src[0] = ireq->loc_addr;
24589 -       r->id.idiag_dst[0] = ireq->rmt_addr;
24590 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
24591 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
24592         r->idiag_expires = jiffies_to_msecs(tmo);
24593         r->idiag_rqueue = 0;
24594         r->idiag_wqueue = 0;
24595 @@ -794,6 +802,7 @@ static int inet_diag_dump_reqs(struct sk
24596                             r->id.idiag_dport)
24597                                 continue;
24598  
24599 +                       /* TODO: lback */
24600                         if (bc) {
24601                                 inet_diag_req_addrs(sk, req, &entry);
24602                                 entry.dport = ntohs(ireq->rmt_port);
24603 @@ -850,6 +859,8 @@ void inet_diag_dump_icsk(struct inet_has
24604                                 if (!net_eq(sock_net(sk), net))
24605                                         continue;
24606  
24607 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24608 +                                       continue;
24609                                 if (num < s_num) {
24610                                         num++;
24611                                         continue;
24612 @@ -922,6 +933,8 @@ skip_listen_ht:
24613  
24614                         if (!net_eq(sock_net(sk), net))
24615                                 continue;
24616 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24617 +                               continue;
24618                         if (num < s_num)
24619                                 goto next_normal;
24620                         if (!(r->idiag_states & (1 << sk->sk_state)))
24621 @@ -950,7 +963,8 @@ next_normal:
24622                                     &head->twchain) {
24623                                 if (!net_eq(twsk_net(tw), net))
24624                                         continue;
24625 -
24626 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
24627 +                                       continue;
24628                                 if (num < s_num)
24629                                         goto next_dying;
24630                                 if (r->sdiag_family != AF_UNSPEC &&
24631 diff -NurpP --minimal linux-3.9.4/net/ipv4/inet_hashtables.c linux-3.9.4-vs2.3.6.3/net/ipv4/inet_hashtables.c
24632 --- linux-3.9.4/net/ipv4/inet_hashtables.c      2013-05-31 13:45:32.000000000 +0000
24633 +++ linux-3.9.4-vs2.3.6.3/net/ipv4/inet_hashtables.c    2013-05-31 18:20:50.000000000 +0000
24634 @@ -22,6 +22,7 @@
24635  #include <net/inet_connection_sock.h>
24636  #include <net/inet_hashtables.h>
24637  #include <net/secure_seq.h>
24638 +#include <net/route.h>
24639  #include <net/ip.h>
24640  
24641  /*
24642 @@ -156,6 +157,11 @@ static inline int compute_score(struct s
24643                         if (rcv_saddr != daddr)
24644                                 return -1;
24645                         score += 4;
24646 +               } else {
24647 +                       /* block non nx_info ips */
24648 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
24649 +                               daddr, NXA_MASK_BIND))
24650 +                               return -1;
24651                 }
24652                 if (sk->sk_bound_dev_if) {
24653                         if (sk->sk_bound_dev_if != dif)
24654 @@ -173,7 +179,6 @@ static inline int compute_score(struct s
24655   * wildcarded during the search since they can never be otherwise.
24656   */
24657  
24658 -
24659  struct sock *__inet_lookup_listener(struct net *net,
24660                                     struct inet_hashinfo *hashinfo,
24661                                     const __be32 saddr, __be16 sport,
24662 @@ -209,6 +214,7 @@ begin:
24663                         phash = next_pseudo_random32(phash);
24664                 }
24665         }
24666 +
24667         /*
24668          * if the nulls value we got at the end of this lookup is
24669          * not the expected one, we must restart lookup.
24670 diff -NurpP --minimal linux-3.9.4/net/ipv4/netfilter.c linux-3.9.4-vs2.3.6.3/net/ipv4/netfilter.c
24671 --- linux-3.9.4/net/ipv4/netfilter.c    2012-12-11 03:30:57.000000000 +0000
24672 +++ linux-3.9.4-vs2.3.6.3/net/ipv4/netfilter.c  2013-05-31 17:17:54.000000000 +0000
24673 @@ -6,7 +6,7 @@
24674  #include <linux/skbuff.h>
24675  #include <linux/gfp.h>
24676  #include <linux/export.h>
24677 -#include <net/route.h>
24678 +// #include <net/route.h>
24679  #include <net/xfrm.h>
24680  #include <net/ip.h>
24681  #include <net/netfilter/nf_queue.h>
24682 diff -NurpP --minimal linux-3.9.4/net/ipv4/raw.c linux-3.9.4-vs2.3.6.3/net/ipv4/raw.c
24683 --- linux-3.9.4/net/ipv4/raw.c  2013-05-31 13:45:32.000000000 +0000
24684 +++ linux-3.9.4-vs2.3.6.3/net/ipv4/raw.c        2013-05-31 18:19:38.000000000 +0000
24685 @@ -116,7 +116,7 @@ static struct sock *__raw_v4_lookup(stru
24686  
24687                 if (net_eq(sock_net(sk), net) && inet->inet_num == num  &&
24688                     !(inet->inet_daddr && inet->inet_daddr != raddr)    &&
24689 -                   !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
24690 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
24691                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
24692                         goto found; /* gotcha */
24693         }
24694 @@ -395,6 +395,12 @@ static int raw_send_hdrinc(struct sock *
24695                 icmp_out_count(net, ((struct icmphdr *)
24696                         skb_transport_header(skb))->type);
24697  
24698 +       err = -EPERM;
24699 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
24700 +               sk->sk_nx_info &&
24701 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
24702 +               goto error_free;
24703 +
24704         err = NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT, skb, NULL,
24705                       rt->dst.dev, dst_output);
24706         if (err > 0)
24707 @@ -580,6 +586,16 @@ static int raw_sendmsg(struct kiocb *ioc
24708                         goto done;
24709         }
24710  
24711 +       if (sk->sk_nx_info) {
24712 +               rt = ip_v4_find_src(sock_net(sk), sk->sk_nx_info, &fl4);
24713 +               if (IS_ERR(rt)) {
24714 +                       err = PTR_ERR(rt);
24715 +                       rt = NULL;
24716 +                       goto done;
24717 +               }
24718 +               ip_rt_put(rt);
24719 +       }
24720 +
24721         security_sk_classify_flow(sk, flowi4_to_flowi(&fl4));
24722         rt = ip_route_output_flow(sock_net(sk), &fl4, sk);
24723         if (IS_ERR(rt)) {
24724 @@ -656,17 +672,19 @@ static int raw_bind(struct sock *sk, str
24725  {
24726         struct inet_sock *inet = inet_sk(sk);
24727         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
24728 +       struct nx_v4_sock_addr nsa = { 0 };
24729         int ret = -EINVAL;
24730         int chk_addr_ret;
24731  
24732         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
24733                 goto out;
24734 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
24735 +       v4_map_sock_addr(inet, addr, &nsa);
24736 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
24737         ret = -EADDRNOTAVAIL;
24738 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
24739 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
24740             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
24741                 goto out;
24742 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24743 +       v4_set_sock_addr(inet, &nsa);
24744         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24745                 inet->inet_saddr = 0;  /* Use device */
24746         sk_dst_reset(sk);
24747 @@ -718,7 +736,8 @@ static int raw_recvmsg(struct kiocb *ioc
24748         /* Copy the address. */
24749         if (sin) {
24750                 sin->sin_family = AF_INET;
24751 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
24752 +               sin->sin_addr.s_addr =
24753 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
24754                 sin->sin_port = 0;
24755                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
24756         }
24757 @@ -913,7 +932,8 @@ static struct sock *raw_get_first(struct
24758         for (state->bucket = 0; state->bucket < RAW_HTABLE_SIZE;
24759                         ++state->bucket) {
24760                 sk_for_each(sk, &state->h->ht[state->bucket])
24761 -                       if (sock_net(sk) == seq_file_net(seq))
24762 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
24763 +                           nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24764                                 goto found;
24765         }
24766         sk = NULL;
24767 @@ -929,7 +949,8 @@ static struct sock *raw_get_next(struct
24768                 sk = sk_next(sk);
24769  try_again:
24770                 ;
24771 -       } while (sk && sock_net(sk) != seq_file_net(seq));
24772 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
24773 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
24774  
24775         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
24776                 sk = sk_head(&state->h->ht[state->bucket]);
24777 diff -NurpP --minimal linux-3.9.4/net/ipv4/route.c linux-3.9.4-vs2.3.6.3/net/ipv4/route.c
24778 --- linux-3.9.4/net/ipv4/route.c        2013-05-31 13:45:32.000000000 +0000
24779 +++ linux-3.9.4-vs2.3.6.3/net/ipv4/route.c      2013-05-31 17:17:54.000000000 +0000
24780 @@ -1998,7 +1998,7 @@ struct rtable *__ip_route_output_key(str
24781  
24782  
24783         if (fl4->flowi4_oif) {
24784 -               dev_out = dev_get_by_index_rcu(net, fl4->flowi4_oif);
24785 +               dev_out = dev_get_by_index_real_rcu(net, fl4->flowi4_oif);
24786                 rth = ERR_PTR(-ENODEV);
24787                 if (dev_out == NULL)
24788                         goto out;
24789 diff -NurpP --minimal linux-3.9.4/net/ipv4/tcp.c linux-3.9.4-vs2.3.6.3/net/ipv4/tcp.c
24790 --- linux-3.9.4/net/ipv4/tcp.c  2013-05-31 13:45:32.000000000 +0000
24791 +++ linux-3.9.4-vs2.3.6.3/net/ipv4/tcp.c        2013-05-31 17:17:54.000000000 +0000
24792 @@ -268,6 +268,7 @@
24793  #include <linux/crypto.h>
24794  #include <linux/time.h>
24795  #include <linux/slab.h>
24796 +#include <linux/in.h>
24797  
24798  #include <net/icmp.h>
24799  #include <net/inet_common.h>
24800 diff -NurpP --minimal linux-3.9.4/net/ipv4/tcp_ipv4.c linux-3.9.4-vs2.3.6.3/net/ipv4/tcp_ipv4.c
24801 --- linux-3.9.4/net/ipv4/tcp_ipv4.c     2013-05-31 13:45:32.000000000 +0000
24802 +++ linux-3.9.4-vs2.3.6.3/net/ipv4/tcp_ipv4.c   2013-05-31 17:17:54.000000000 +0000
24803 @@ -2260,6 +2260,12 @@ static void *listening_get_next(struct s
24804                 req = req->dl_next;
24805                 while (1) {
24806                         while (req) {
24807 +                               vxdprintk(VXD_CBIT(net, 6),
24808 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
24809 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
24810 +                               if (req->sk &&
24811 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
24812 +                                       continue;
24813                                 if (req->rsk_ops->family == st->family) {
24814                                         cur = req;
24815                                         goto out;
24816 @@ -2284,6 +2290,10 @@ get_req:
24817         }
24818  get_sk:
24819         sk_nulls_for_each_from(sk, node) {
24820 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
24821 +                       sk, sk->sk_nid, nx_current_nid());
24822 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24823 +                       continue;
24824                 if (!net_eq(sock_net(sk), net))
24825                         continue;
24826                 if (sk->sk_family == st->family) {
24827 @@ -2360,6 +2370,11 @@ static void *established_get_first(struc
24828  
24829                 spin_lock_bh(lock);
24830                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
24831 +                       vxdprintk(VXD_CBIT(net, 6),
24832 +                               "sk,egf: %p [#%d] (from %d)",
24833 +                               sk, sk->sk_nid, nx_current_nid());
24834 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24835 +                               continue;
24836                         if (sk->sk_family != st->family ||
24837                             !net_eq(sock_net(sk), net)) {
24838                                 continue;
24839 @@ -2370,6 +2385,11 @@ static void *established_get_first(struc
24840                 st->state = TCP_SEQ_STATE_TIME_WAIT;
24841                 inet_twsk_for_each(tw, node,
24842                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
24843 +                       vxdprintk(VXD_CBIT(net, 6),
24844 +                               "tw: %p [#%d] (from %d)",
24845 +                               tw, tw->tw_nid, nx_current_nid());
24846 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
24847 +                               continue;
24848                         if (tw->tw_family != st->family ||
24849                             !net_eq(twsk_net(tw), net)) {
24850                                 continue;
24851 @@ -2399,7 +2419,9 @@ static void *established_get_next(struct
24852                 tw = cur;
24853                 tw = tw_next(tw);
24854  get_tw:
24855 -               while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
24856 +               while (tw && (tw->tw_family != st->family ||
24857 +                       !net_eq(twsk_net(tw), net) ||
24858 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
24859                         tw = tw_next(tw);
24860                 }
24861                 if (tw) {
24862 @@ -2423,6 +2445,11 @@ get_tw:
24863                 sk = sk_nulls_next(sk);
24864  
24865         sk_nulls_for_each_from(sk, node) {
24866 +               vxdprintk(VXD_CBIT(net, 6),
24867 +                       "sk,egn: %p [#%d] (from %d)",
24868 +                       sk, sk->sk_nid, nx_current_nid());
24869 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24870 +                       continue;
24871                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
24872                         goto found;
24873         }
24874 @@ -2628,9 +2655,9 @@ static void get_openreq4(const struct so
24875         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
24876                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %pK%n",
24877                 i,
24878 -               ireq->loc_addr,
24879 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
24880                 ntohs(inet_sk(sk)->inet_sport),
24881 -               ireq->rmt_addr,
24882 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
24883                 ntohs(ireq->rmt_port),
24884                 TCP_SYN_RECV,
24885                 0, 0, /* could print option size, but that is af dependent. */
24886 @@ -2653,8 +2680,8 @@ static void get_tcp4_sock(struct sock *s
24887         const struct inet_connection_sock *icsk = inet_csk(sk);
24888         const struct inet_sock *inet = inet_sk(sk);
24889         struct fastopen_queue *fastopenq = icsk->icsk_accept_queue.fastopenq;
24890 -       __be32 dest = inet->inet_daddr;
24891 -       __be32 src = inet->inet_rcv_saddr;
24892 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
24893 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
24894         __u16 destp = ntohs(inet->inet_dport);
24895         __u16 srcp = ntohs(inet->inet_sport);
24896         int rx_queue;
24897 @@ -2710,8 +2737,8 @@ static void get_timewait4_sock(const str
24898         __u16 destp, srcp;
24899         long delta = tw->tw_ttd - jiffies;
24900  
24901 -       dest  = tw->tw_daddr;
24902 -       src   = tw->tw_rcv_saddr;
24903 +       dest  = nx_map_sock_lback(current_nx_info(), tw->tw_daddr);
24904 +       src   = nx_map_sock_lback(current_nx_info(), tw->tw_rcv_saddr);
24905         destp = ntohs(tw->tw_dport);
24906         srcp  = ntohs(tw->tw_sport);
24907  
24908 diff -NurpP --minimal linux-3.9.4/net/ipv4/tcp_minisocks.c linux-3.9.4-vs2.3.6.3/net/ipv4/tcp_minisocks.c
24909 --- linux-3.9.4/net/ipv4/tcp_minisocks.c        2013-05-31 14:22:27.000000000 +0000
24910 +++ linux-3.9.4-vs2.3.6.3/net/ipv4/tcp_minisocks.c      2013-05-31 17:17:54.000000000 +0000
24911 @@ -23,6 +23,9 @@
24912  #include <linux/slab.h>
24913  #include <linux/sysctl.h>
24914  #include <linux/workqueue.h>
24915 +#include <linux/vs_limit.h>
24916 +#include <linux/vs_socket.h>
24917 +#include <linux/vs_context.h>
24918  #include <net/tcp.h>
24919  #include <net/inet_common.h>
24920  #include <net/xfrm.h>
24921 @@ -291,6 +294,11 @@ void tcp_time_wait(struct sock *sk, int
24922                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
24923                 tcptw->tw_ts_offset     = tp->tsoffset;
24924  
24925 +               tw->tw_xid              = sk->sk_xid;
24926 +               tw->tw_vx_info          = NULL;
24927 +               tw->tw_nid              = sk->sk_nid;
24928 +               tw->tw_nx_info          = NULL;
24929 +
24930  #if IS_ENABLED(CONFIG_IPV6)
24931                 if (tw->tw_family == PF_INET6) {
24932                         struct ipv6_pinfo *np = inet6_sk(sk);
24933 diff -NurpP --minimal linux-3.9.4/net/ipv4/udp.c linux-3.9.4-vs2.3.6.3/net/ipv4/udp.c
24934 --- linux-3.9.4/net/ipv4/udp.c  2013-05-31 13:45:32.000000000 +0000
24935 +++ linux-3.9.4-vs2.3.6.3/net/ipv4/udp.c        2013-05-31 18:26:00.000000000 +0000
24936 @@ -306,14 +306,7 @@ fail:
24937  }
24938  EXPORT_SYMBOL(udp_lib_get_port);
24939  
24940 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24941 -{
24942 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
24943 -
24944 -       return  (!ipv6_only_sock(sk2)  &&
24945 -                (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr ||
24946 -                  inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
24947 -}
24948 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
24949  
24950  static unsigned int udp4_portaddr_hash(struct net *net, __be32 saddr,
24951                                        unsigned int port)
24952 @@ -348,6 +341,11 @@ static inline int compute_score(struct s
24953                         if (inet->inet_rcv_saddr != daddr)
24954                                 return -1;
24955                         score += 4;
24956 +               } else {
24957 +                       /* block non nx_info ips */
24958 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
24959 +                               daddr, NXA_MASK_BIND))
24960 +                               return -1;
24961                 }
24962                 if (inet->inet_daddr) {
24963                         if (inet->inet_daddr != saddr)
24964 @@ -458,6 +456,7 @@ begin:
24965         return result;
24966  }
24967  
24968 +
24969  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
24970   * harder than this. -DaveM
24971   */
24972 @@ -504,6 +503,11 @@ begin:
24973         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
24974                 score = compute_score(sk, net, saddr, hnum, sport,
24975                                       daddr, dport, dif);
24976 +               /* FIXME: disabled?
24977 +               if (score == 9) {
24978 +                       result = sk;
24979 +                       break;
24980 +               } else */
24981                 if (score > badness) {
24982                         result = sk;
24983                         badness = score;
24984 @@ -528,6 +532,7 @@ begin:
24985         if (get_nulls_value(node) != slot)
24986                 goto begin;
24987  
24988 +
24989         if (result) {
24990                 if (unlikely(!atomic_inc_not_zero_hint(&result->sk_refcnt, 2)))
24991                         result = NULL;
24992 @@ -537,6 +542,7 @@ begin:
24993                         goto begin;
24994                 }
24995         }
24996 +
24997         rcu_read_unlock();
24998         return result;
24999  }
25000 @@ -580,8 +586,7 @@ static inline struct sock *udp_v4_mcast_
25001                     udp_sk(s)->udp_port_hash != hnum ||
25002                     (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
25003                     (inet->inet_dport != rmt_port && inet->inet_dport) ||
25004 -                   (inet->inet_rcv_saddr &&
25005 -                    inet->inet_rcv_saddr != loc_addr) ||
25006 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
25007                     ipv6_only_sock(s) ||
25008                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
25009                         continue;
25010 @@ -964,6 +969,16 @@ int udp_sendmsg(struct kiocb *iocb, stru
25011                                    inet_sk_flowi_flags(sk)|FLOWI_FLAG_CAN_SLEEP,
25012                                    faddr, saddr, dport, inet->inet_sport);
25013  
25014 +               if (sk->sk_nx_info) {
25015 +                       rt = ip_v4_find_src(net, sk->sk_nx_info, fl4);
25016 +                       if (IS_ERR(rt)) {
25017 +                               err = PTR_ERR(rt);
25018 +                               rt = NULL;
25019 +                               goto out;
25020 +                       }
25021 +                       ip_rt_put(rt);
25022 +               }
25023 +
25024                 security_sk_classify_flow(sk, flowi4_to_flowi(fl4));
25025                 rt = ip_route_output_flow(net, fl4, sk);
25026                 if (IS_ERR(rt)) {
25027 @@ -1269,7 +1284,8 @@ try_again:
25028         if (sin) {
25029                 sin->sin_family = AF_INET;
25030                 sin->sin_port = udp_hdr(skb)->source;
25031 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
25032 +               sin->sin_addr.s_addr = nx_map_sock_lback(
25033 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
25034                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
25035         }
25036         if (inet->cmsg_flags)
25037 @@ -2025,6 +2041,8 @@ static struct sock *udp_get_first(struct
25038                 sk_nulls_for_each(sk, node, &hslot->head) {
25039                         if (!net_eq(sock_net(sk), net))
25040                                 continue;
25041 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25042 +                               continue;
25043                         if (sk->sk_family == state->family)
25044                                 goto found;
25045                 }
25046 @@ -2042,7 +2060,9 @@ static struct sock *udp_get_next(struct
25047  
25048         do {
25049                 sk = sk_nulls_next(sk);
25050 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
25051 +       } while (sk && (!net_eq(sock_net(sk), net) ||
25052 +               sk->sk_family != state->family ||
25053 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
25054  
25055         if (!sk) {
25056                 if (state->bucket <= state->udp_table->mask)
25057 @@ -2138,8 +2158,8 @@ static void udp4_format_sock(struct sock
25058                 int bucket, int *len)
25059  {
25060         struct inet_sock *inet = inet_sk(sp);
25061 -       __be32 dest = inet->inet_daddr;
25062 -       __be32 src  = inet->inet_rcv_saddr;
25063 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
25064 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
25065         __u16 destp       = ntohs(inet->inet_dport);
25066         __u16 srcp        = ntohs(inet->inet_sport);
25067  
25068 diff -NurpP --minimal linux-3.9.4/net/ipv6/Kconfig linux-3.9.4-vs2.3.6.3/net/ipv6/Kconfig
25069 --- linux-3.9.4/net/ipv6/Kconfig        2013-05-31 13:45:32.000000000 +0000
25070 +++ linux-3.9.4-vs2.3.6.3/net/ipv6/Kconfig      2013-05-31 17:17:54.000000000 +0000
25071 @@ -4,8 +4,8 @@
25072  
25073  #   IPv6 as module will cause a CRASH if you try to unload it
25074  menuconfig IPV6
25075 -       tristate "The IPv6 protocol"
25076 -       default m
25077 +       bool "The IPv6 protocol"
25078 +       default n
25079         ---help---
25080           This is complemental support for the IP version 6.
25081           You will still be able to do traditional IPv4 networking as well.
25082 diff -NurpP --minimal linux-3.9.4/net/ipv6/addrconf.c linux-3.9.4-vs2.3.6.3/net/ipv6/addrconf.c
25083 --- linux-3.9.4/net/ipv6/addrconf.c     2013-05-31 13:45:32.000000000 +0000
25084 +++ linux-3.9.4-vs2.3.6.3/net/ipv6/addrconf.c   2013-05-31 20:07:39.000000000 +0000
25085 @@ -93,6 +93,8 @@
25086  #include <linux/proc_fs.h>
25087  #include <linux/seq_file.h>
25088  #include <linux/export.h>
25089 +#include <linux/vs_network.h>
25090 +#include <linux/vs_inet6.h>
25091  
25092  /* Set to 3 to get tracing... */
25093  #define ACONF_DEBUG 2
25094 @@ -1250,7 +1252,7 @@ out:
25095  
25096  int ipv6_dev_get_saddr(struct net *net, const struct net_device *dst_dev,
25097                        const struct in6_addr *daddr, unsigned int prefs,
25098 -                      struct in6_addr *saddr)
25099 +                      struct in6_addr *saddr, struct nx_info *nxi)
25100  {
25101         struct ipv6_saddr_score scores[2],
25102                                 *score = &scores[0], *hiscore = &scores[1];
25103 @@ -1322,6 +1324,8 @@ int ipv6_dev_get_saddr(struct net *net,
25104                                                dev->name);
25105                                 continue;
25106                         }
25107 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
25108 +                               continue;
25109  
25110                         score->rule = -1;
25111                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
25112 @@ -3311,7 +3315,10 @@ static void if6_seq_stop(struct seq_file
25113  static int if6_seq_show(struct seq_file *seq, void *v)
25114  {
25115         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
25116 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25117 +
25118 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
25119 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
25120 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25121                    &ifp->addr,
25122                    ifp->idev->dev->ifindex,
25123                    ifp->prefix_len,
25124 @@ -3815,6 +3822,11 @@ static int in6_dump_addrs(struct inet6_d
25125         struct ifacaddr6 *ifaca;
25126         int err = 1;
25127         int ip_idx = *p_ip_idx;
25128 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25129 +
25130 +       /* disable ipv6 on non v6 guests */
25131 +       if (nxi && !nx_info_has_v6(nxi))
25132 +               return skb->len;
25133  
25134         read_lock_bh(&idev->lock);
25135         switch (type) {
25136 @@ -3825,6 +3837,8 @@ static int in6_dump_addrs(struct inet6_d
25137                 list_for_each_entry(ifa, &idev->addr_list, if_list) {
25138                         if (++ip_idx < s_ip_idx)
25139                                 continue;
25140 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
25141 +                                       continue;
25142                         err = inet6_fill_ifaddr(skb, ifa,
25143                                                 NETLINK_CB(cb->skb).portid,
25144                                                 cb->nlh->nlmsg_seq,
25145 @@ -3841,6 +3855,8 @@ static int in6_dump_addrs(struct inet6_d
25146                      ifmca = ifmca->next, ip_idx++) {
25147                         if (ip_idx < s_ip_idx)
25148                                 continue;
25149 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
25150 +                                       continue;
25151                         err = inet6_fill_ifmcaddr(skb, ifmca,
25152                                                   NETLINK_CB(cb->skb).portid,
25153                                                   cb->nlh->nlmsg_seq,
25154 @@ -3856,6 +3872,8 @@ static int in6_dump_addrs(struct inet6_d
25155                      ifaca = ifaca->aca_next, ip_idx++) {
25156                         if (ip_idx < s_ip_idx)
25157                                 continue;
25158 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
25159 +                                       continue;
25160                         err = inet6_fill_ifacaddr(skb, ifaca,
25161                                                   NETLINK_CB(cb->skb).portid,
25162                                                   cb->nlh->nlmsg_seq,
25163 @@ -3884,6 +3902,10 @@ static int inet6_dump_addr(struct sk_buf
25164         struct inet6_dev *idev;
25165         struct hlist_head *head;
25166  
25167 +       /* FIXME: maybe disable ipv6 on non v6 guests?
25168 +       if (skb->sk && skb->sk->sk_vx_info)
25169 +               return skb->len; */
25170 +
25171         s_h = cb->args[0];
25172         s_idx = idx = cb->args[1];
25173         s_ip_idx = ip_idx = cb->args[2];
25174 @@ -4238,6 +4260,7 @@ static int inet6_dump_ifinfo(struct sk_b
25175         struct net_device *dev;
25176         struct inet6_dev *idev;
25177         struct hlist_head *head;
25178 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25179  
25180         s_h = cb->args[0];
25181         s_idx = cb->args[1];
25182 @@ -4249,6 +4272,8 @@ static int inet6_dump_ifinfo(struct sk_b
25183                 hlist_for_each_entry_rcu(dev, head, index_hlist) {
25184                         if (idx < s_idx)
25185                                 goto cont;
25186 +                       if (!v6_dev_in_nx_info(dev, nxi))
25187 +                               goto cont;
25188                         idev = __in6_dev_get(dev);
25189                         if (!idev)
25190                                 goto cont;
25191 diff -NurpP --minimal linux-3.9.4/net/ipv6/af_inet6.c linux-3.9.4-vs2.3.6.3/net/ipv6/af_inet6.c
25192 --- linux-3.9.4/net/ipv6/af_inet6.c     2013-05-31 13:45:32.000000000 +0000
25193 +++ linux-3.9.4-vs2.3.6.3/net/ipv6/af_inet6.c   2013-05-31 20:04:41.000000000 +0000
25194 @@ -43,6 +43,8 @@
25195  #include <linux/netdevice.h>
25196  #include <linux/icmpv6.h>
25197  #include <linux/netfilter_ipv6.h>
25198 +#include <linux/vs_inet.h>
25199 +#include <linux/vs_inet6.h>
25200  
25201  #include <net/ip.h>
25202  #include <net/ipv6.h>
25203 @@ -160,10 +162,13 @@ lookup_protocol:
25204         }
25205  
25206         err = -EPERM;
25207 +       if ((protocol == IPPROTO_ICMPV6) &&
25208 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
25209 +               goto override;
25210         if (sock->type == SOCK_RAW && !kern &&
25211             !ns_capable(net->user_ns, CAP_NET_RAW))
25212                 goto out_rcu_unlock;
25213 -
25214 +override:
25215         sock->ops = answer->ops;
25216         answer_prot = answer->prot;
25217         answer_no_check = answer->no_check;
25218 @@ -263,6 +268,7 @@ int inet6_bind(struct socket *sock, stru
25219         struct inet_sock *inet = inet_sk(sk);
25220         struct ipv6_pinfo *np = inet6_sk(sk);
25221         struct net *net = sock_net(sk);
25222 +       struct nx_v6_sock_addr nsa;
25223         __be32 v4addr = 0;
25224         unsigned short snum;
25225         int addr_type = 0;
25226 @@ -278,6 +284,10 @@ int inet6_bind(struct socket *sock, stru
25227         if (addr->sin6_family != AF_INET6)
25228                 return -EAFNOSUPPORT;
25229  
25230 +       err = v6_map_sock_addr(inet, addr, &nsa);
25231 +       if (err)
25232 +               return err;
25233 +
25234         addr_type = ipv6_addr_type(&addr->sin6_addr);
25235         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
25236                 return -EINVAL;
25237 @@ -309,6 +319,7 @@ int inet6_bind(struct socket *sock, stru
25238                 /* Reproduce AF_INET checks to make the bindings consistent */
25239                 v4addr = addr->sin6_addr.s6_addr32[3];
25240                 chk_addr_ret = inet_addr_type(net, v4addr);
25241 +
25242                 if (!sysctl_ip_nonlocal_bind &&
25243                     !(inet->freebind || inet->transparent) &&
25244                     v4addr != htonl(INADDR_ANY) &&
25245 @@ -318,6 +329,10 @@ int inet6_bind(struct socket *sock, stru
25246                         err = -EADDRNOTAVAIL;
25247                         goto out;
25248                 }
25249 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
25250 +                       err = -EADDRNOTAVAIL;
25251 +                       goto out;
25252 +               }
25253         } else {
25254                 if (addr_type != IPV6_ADDR_ANY) {
25255                         struct net_device *dev = NULL;
25256 @@ -344,6 +359,11 @@ int inet6_bind(struct socket *sock, stru
25257                                 }
25258                         }
25259  
25260 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25261 +                               err = -EADDRNOTAVAIL;
25262 +                               goto out_unlock;
25263 +                       }
25264 +
25265                         /* ipv4 addr of the socket is invalid.  Only the
25266                          * unspecified and mapped address have a v4 equivalent.
25267                          */
25268 @@ -360,6 +380,9 @@ int inet6_bind(struct socket *sock, stru
25269                 }
25270         }
25271  
25272 +       /* what's that for? */
25273 +       v6_set_sock_addr(inet, &nsa);
25274 +
25275         inet->inet_rcv_saddr = v4addr;
25276         inet->inet_saddr = v4addr;
25277  
25278 @@ -461,9 +484,11 @@ int inet6_getname(struct socket *sock, s
25279                         return -ENOTCONN;
25280                 sin->sin6_port = inet->inet_dport;
25281                 sin->sin6_addr = np->daddr;
25282 +               /* FIXME: remap lback? */
25283                 if (np->sndflow)
25284                         sin->sin6_flowinfo = np->flow_label;
25285         } else {
25286 +               /* FIXME: remap lback? */
25287                 if (ipv6_addr_any(&np->rcv_saddr))
25288                         sin->sin6_addr = np->saddr;
25289                 else
25290 diff -NurpP --minimal linux-3.9.4/net/ipv6/datagram.c linux-3.9.4-vs2.3.6.3/net/ipv6/datagram.c
25291 --- linux-3.9.4/net/ipv6/datagram.c     2013-05-31 13:45:32.000000000 +0000
25292 +++ linux-3.9.4-vs2.3.6.3/net/ipv6/datagram.c   2013-05-31 17:17:54.000000000 +0000
25293 @@ -648,7 +648,7 @@ int ip6_datagram_send_ctl(struct net *ne
25294  
25295                         rcu_read_lock();
25296                         if (fl6->flowi6_oif) {
25297 -                               dev = dev_get_by_index_rcu(net, fl6->flowi6_oif);
25298 +                               dev = dev_get_by_index_real_rcu(net, fl6->flowi6_oif);
25299                                 if (!dev) {
25300                                         rcu_read_unlock();
25301                                         return -ENODEV;
25302 diff -NurpP --minimal linux-3.9.4/net/ipv6/fib6_rules.c linux-3.9.4-vs2.3.6.3/net/ipv6/fib6_rules.c
25303 --- linux-3.9.4/net/ipv6/fib6_rules.c   2013-02-19 13:58:58.000000000 +0000
25304 +++ linux-3.9.4-vs2.3.6.3/net/ipv6/fib6_rules.c 2013-05-31 17:17:54.000000000 +0000
25305 @@ -90,7 +90,7 @@ static int fib6_rule_action(struct fib_r
25306                                                ip6_dst_idev(&rt->dst)->dev,
25307                                                &flp6->daddr,
25308                                                rt6_flags2srcprefs(flags),
25309 -                                              &saddr))
25310 +                                              &saddr, NULL))
25311                                 goto again;
25312                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
25313                                                r->src.plen))
25314 diff -NurpP --minimal linux-3.9.4/net/ipv6/inet6_hashtables.c linux-3.9.4-vs2.3.6.3/net/ipv6/inet6_hashtables.c
25315 --- linux-3.9.4/net/ipv6/inet6_hashtables.c     2013-05-31 13:45:32.000000000 +0000
25316 +++ linux-3.9.4-vs2.3.6.3/net/ipv6/inet6_hashtables.c   2013-05-31 17:17:54.000000000 +0000
25317 @@ -16,6 +16,7 @@
25318  
25319  #include <linux/module.h>
25320  #include <linux/random.h>
25321 +#include <linux/vs_inet6.h>
25322  
25323  #include <net/inet_connection_sock.h>
25324  #include <net/inet_hashtables.h>
25325 @@ -83,7 +84,6 @@ struct sock *__inet6_lookup_established(
25326         unsigned int slot = hash & hashinfo->ehash_mask;
25327         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
25328  
25329 -
25330         rcu_read_lock();
25331  begin:
25332         sk_nulls_for_each_rcu(sk, node, &head->chain) {
25333 @@ -97,7 +97,7 @@ begin:
25334                                 sock_put(sk);
25335                                 goto begin;
25336                         }
25337 -               goto out;
25338 +                       goto out;
25339                 }
25340         }
25341         if (get_nulls_value(node) != slot)
25342 @@ -147,6 +147,9 @@ static inline int compute_score(struct s
25343                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25344                                 return -1;
25345                         score++;
25346 +               } else {
25347 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25348 +                               return -1;
25349                 }
25350                 if (sk->sk_bound_dev_if) {
25351                         if (sk->sk_bound_dev_if != dif)
25352 diff -NurpP --minimal linux-3.9.4/net/ipv6/ip6_output.c linux-3.9.4-vs2.3.6.3/net/ipv6/ip6_output.c
25353 --- linux-3.9.4/net/ipv6/ip6_output.c   2013-05-31 13:45:32.000000000 +0000
25354 +++ linux-3.9.4-vs2.3.6.3/net/ipv6/ip6_output.c 2013-05-31 17:17:54.000000000 +0000
25355 @@ -877,7 +877,8 @@ static int ip6_dst_lookup_tail(struct so
25356                 struct rt6_info *rt = (struct rt6_info *) *dst;
25357                 err = ip6_route_get_saddr(net, rt, &fl6->daddr,
25358                                           sk ? inet6_sk(sk)->srcprefs : 0,
25359 -                                         &fl6->saddr);
25360 +                                         &fl6->saddr,
25361 +                                         sk ? sk->sk_nx_info : NULL);
25362                 if (err)
25363                         goto out_err_release;
25364         }
25365 diff -NurpP --minimal linux-3.9.4/net/ipv6/ndisc.c linux-3.9.4-vs2.3.6.3/net/ipv6/ndisc.c
25366 --- linux-3.9.4/net/ipv6/ndisc.c        2013-05-31 13:45:32.000000000 +0000
25367 +++ linux-3.9.4-vs2.3.6.3/net/ipv6/ndisc.c      2013-05-31 17:17:54.000000000 +0000
25368 @@ -485,7 +485,7 @@ static void ndisc_send_na(struct net_dev
25369         } else {
25370                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
25371                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
25372 -                                      &tmpaddr))
25373 +                                      &tmpaddr, NULL))
25374                         return;
25375                 src_addr = &tmpaddr;
25376         }
25377 diff -NurpP --minimal linux-3.9.4/net/ipv6/netfilter/ip6t_MASQUERADE.c linux-3.9.4-vs2.3.6.3/net/ipv6/netfilter/ip6t_MASQUERADE.c
25378 --- linux-3.9.4/net/ipv6/netfilter/ip6t_MASQUERADE.c    2012-12-11 03:30:57.000000000 +0000
25379 +++ linux-3.9.4-vs2.3.6.3/net/ipv6/netfilter/ip6t_MASQUERADE.c  2013-05-31 17:17:54.000000000 +0000
25380 @@ -34,7 +34,7 @@ masquerade_tg6(struct sk_buff *skb, cons
25381                             ctinfo == IP_CT_RELATED_REPLY));
25382  
25383         if (ipv6_dev_get_saddr(dev_net(par->out), par->out,
25384 -                              &ipv6_hdr(skb)->daddr, 0, &src) < 0)
25385 +                              &ipv6_hdr(skb)->daddr, 0, &src, NULL) < 0)
25386                 return NF_DROP;
25387  
25388         nfct_nat(ct)->masq_index = par->out->ifindex;
25389 diff -NurpP --minimal linux-3.9.4/net/ipv6/raw.c linux-3.9.4-vs2.3.6.3/net/ipv6/raw.c
25390 --- linux-3.9.4/net/ipv6/raw.c  2013-05-31 13:45:32.000000000 +0000
25391 +++ linux-3.9.4-vs2.3.6.3/net/ipv6/raw.c        2013-05-31 17:17:54.000000000 +0000
25392 @@ -30,6 +30,7 @@
25393  #include <linux/icmpv6.h>
25394  #include <linux/netfilter.h>
25395  #include <linux/netfilter_ipv6.h>
25396 +#include <linux/vs_inet6.h>
25397  #include <linux/skbuff.h>
25398  #include <linux/compat.h>
25399  #include <asm/uaccess.h>
25400 @@ -283,6 +284,13 @@ static int rawv6_bind(struct sock *sk, s
25401                                 goto out_unlock;
25402                 }
25403  
25404 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25405 +                       err = -EADDRNOTAVAIL;
25406 +                       if (dev)
25407 +                               dev_put(dev);
25408 +                       goto out;
25409 +               }
25410 +
25411                 /* ipv4 addr of the socket is invalid.  Only the
25412                  * unspecified and mapped address have a v4 equivalent.
25413                  */
25414 diff -NurpP --minimal linux-3.9.4/net/ipv6/route.c linux-3.9.4-vs2.3.6.3/net/ipv6/route.c
25415 --- linux-3.9.4/net/ipv6/route.c        2013-05-31 13:45:32.000000000 +0000
25416 +++ linux-3.9.4-vs2.3.6.3/net/ipv6/route.c      2013-05-31 18:10:38.000000000 +0000
25417 @@ -58,6 +58,7 @@
25418  #include <net/netevent.h>
25419  #include <net/netlink.h>
25420  #include <net/nexthop.h>
25421 +#include <linux/vs_inet6.h>
25422  
25423  #include <asm/uaccess.h>
25424  
25425 @@ -2079,15 +2080,17 @@ int ip6_route_get_saddr(struct net *net,
25426                         struct rt6_info *rt,
25427                         const struct in6_addr *daddr,
25428                         unsigned int prefs,
25429 -                       struct in6_addr *saddr)
25430 +                       struct in6_addr *saddr,
25431 +                       struct nx_info *nxi)
25432  {
25433         struct inet6_dev *idev = ip6_dst_idev((struct dst_entry*)rt);
25434         int err = 0;
25435 -       if (rt->rt6i_prefsrc.plen)
25436 +       if (rt->rt6i_prefsrc.plen && (!nxi ||
25437 +           v6_addr_in_nx_info(nxi, &rt->rt6i_prefsrc.addr, NXA_TYPE_ADDR)))
25438                 *saddr = rt->rt6i_prefsrc.addr;
25439         else
25440                 err = ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
25441 -                                        daddr, prefs, saddr);
25442 +                                        daddr, prefs, saddr, nxi);
25443         return err;
25444  }
25445  
25446 @@ -2507,7 +2510,8 @@ static int rt6_fill_node(struct net *net
25447                                 goto nla_put_failure;
25448         } else if (dst) {
25449                 struct in6_addr saddr_buf;
25450 -               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf) == 0 &&
25451 +               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf,
25452 +                   (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0 &&
25453                     nla_put(skb, RTA_PREFSRC, 16, &saddr_buf))
25454                         goto nla_put_failure;
25455         }
25456 @@ -2719,6 +2723,7 @@ static int rt6_info_route(struct rt6_inf
25457  {
25458         struct seq_file *m = p_arg;
25459  
25460 +       /* FIXME: check for network context? */
25461         seq_printf(m, "%pi6 %02x ", &rt->rt6i_dst.addr, rt->rt6i_dst.plen);
25462  
25463  #ifdef CONFIG_IPV6_SUBTREES
25464 diff -NurpP --minimal linux-3.9.4/net/ipv6/tcp_ipv6.c linux-3.9.4-vs2.3.6.3/net/ipv6/tcp_ipv6.c
25465 --- linux-3.9.4/net/ipv6/tcp_ipv6.c     2013-05-31 14:22:27.000000000 +0000
25466 +++ linux-3.9.4-vs2.3.6.3/net/ipv6/tcp_ipv6.c   2013-05-31 17:17:54.000000000 +0000
25467 @@ -71,6 +71,7 @@
25468  
25469  #include <linux/crypto.h>
25470  #include <linux/scatterlist.h>
25471 +#include <linux/vs_inet6.h>
25472  
25473  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
25474  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
25475 @@ -164,8 +165,15 @@ static int tcp_v6_connect(struct sock *s
25476          *      connect() to INADDR_ANY means loopback (BSD'ism).
25477          */
25478  
25479 -       if(ipv6_addr_any(&usin->sin6_addr))
25480 -               usin->sin6_addr.s6_addr[15] = 0x1;
25481 +       if(ipv6_addr_any(&usin->sin6_addr)) {
25482 +               struct nx_info *nxi =  sk->sk_nx_info;
25483 +
25484 +               if (nxi && nx_info_has_v6(nxi))
25485 +                       /* FIXME: remap lback? */
25486 +                       usin->sin6_addr = nxi->v6.ip;
25487 +               else
25488 +                       usin->sin6_addr.s6_addr[15] = 0x1;
25489 +       }
25490  
25491         addr_type = ipv6_addr_type(&usin->sin6_addr);
25492  
25493 diff -NurpP --minimal linux-3.9.4/net/ipv6/udp.c linux-3.9.4-vs2.3.6.3/net/ipv6/udp.c
25494 --- linux-3.9.4/net/ipv6/udp.c  2013-05-31 14:22:27.000000000 +0000
25495 +++ linux-3.9.4-vs2.3.6.3/net/ipv6/udp.c        2013-05-31 18:16:01.000000000 +0000
25496 @@ -46,42 +46,68 @@
25497  #include <net/ip6_checksum.h>
25498  #include <net/xfrm.h>
25499  #include <net/inet6_hashtables.h>
25500 +#include <linux/vs_inet6.h>
25501  
25502  #include <linux/proc_fs.h>
25503  #include <linux/seq_file.h>
25504  #include <trace/events/skb.h>
25505  #include "udp_impl.h"
25506  
25507 -int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
25508 +int ipv6_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25509  {
25510 -       const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
25511 +       const struct in6_addr *sk1_rcv_saddr6 = &inet6_sk(sk1)->rcv_saddr;
25512         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
25513 -       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk);
25514 +       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk1);
25515         __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
25516 -       int sk_ipv6only = ipv6_only_sock(sk);
25517 +       int sk1_ipv6only = ipv6_only_sock(sk1);
25518         int sk2_ipv6only = inet_v6_ipv6only(sk2);
25519 -       int addr_type = ipv6_addr_type(sk_rcv_saddr6);
25520 +       int addr_type = ipv6_addr_type(sk1_rcv_saddr6);
25521         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
25522  
25523         /* if both are mapped, treat as IPv4 */
25524 -       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
25525 -               return (!sk2_ipv6only &&
25526 +       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
25527 +               if (!sk2_ipv6only &&
25528                         (!sk1_rcv_saddr || !sk2_rcv_saddr ||
25529 -                         sk1_rcv_saddr == sk2_rcv_saddr));
25530 +                         sk1_rcv_saddr == sk2_rcv_saddr))
25531 +                       goto vs_v4;
25532 +               else
25533 +                       return 0;
25534 +       }
25535  
25536         if (addr_type2 == IPV6_ADDR_ANY &&
25537             !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
25538 -               return 1;
25539 +               goto vs;
25540  
25541         if (addr_type == IPV6_ADDR_ANY &&
25542 -           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
25543 -               return 1;
25544 +           !(sk1_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
25545 +               goto vs;
25546  
25547         if (sk2_rcv_saddr6 &&
25548 -           ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
25549 -               return 1;
25550 +           ipv6_addr_equal(sk1_rcv_saddr6, sk2_rcv_saddr6))
25551 +               goto vs;
25552  
25553         return 0;
25554 +
25555 +vs_v4:
25556 +       if (!sk1_rcv_saddr && !sk2_rcv_saddr)
25557 +               return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25558 +       if (!sk2_rcv_saddr)
25559 +               return v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, -1);
25560 +       if (!sk1_rcv_saddr)
25561 +               return v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, -1);
25562 +       return 1;
25563 +vs:
25564 +       if (addr_type2 == IPV6_ADDR_ANY && addr_type == IPV6_ADDR_ANY)
25565 +               return nx_v6_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25566 +       else if (addr_type2 == IPV6_ADDR_ANY)
25567 +               return v6_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr6, -1);
25568 +       else if (addr_type == IPV6_ADDR_ANY) {
25569 +               if (addr_type2 == IPV6_ADDR_MAPPED)
25570 +                       return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25571 +               else
25572 +                       return v6_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr6, -1);
25573 +       }
25574 +       return 1;
25575  }
25576  
25577  static unsigned int udp6_portaddr_hash(struct net *net,
25578 @@ -145,6 +171,10 @@ static inline int compute_score(struct s
25579                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25580                                 return -1;
25581                         score++;
25582 +               } else {
25583 +                       /* block non nx_info ips */
25584 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25585 +                               return -1;
25586                 }
25587                 if (!ipv6_addr_any(&np->daddr)) {
25588                         if (!ipv6_addr_equal(&np->daddr, saddr))
25589 diff -NurpP --minimal linux-3.9.4/net/ipv6/xfrm6_policy.c linux-3.9.4-vs2.3.6.3/net/ipv6/xfrm6_policy.c
25590 --- linux-3.9.4/net/ipv6/xfrm6_policy.c 2013-05-31 14:22:27.000000000 +0000
25591 +++ linux-3.9.4-vs2.3.6.3/net/ipv6/xfrm6_policy.c       2013-05-31 17:17:54.000000000 +0000
25592 @@ -63,7 +63,7 @@ static int xfrm6_get_saddr(struct net *n
25593         dev = ip6_dst_idev(dst)->dev;
25594         ipv6_dev_get_saddr(dev_net(dev), dev,
25595                            (struct in6_addr *)&daddr->a6, 0,
25596 -                          (struct in6_addr *)&saddr->a6);
25597 +                          (struct in6_addr *)&saddr->a6, NULL);
25598         dst_release(dst);
25599         return 0;
25600  }
25601 diff -NurpP --minimal linux-3.9.4/net/netfilter/ipvs/ip_vs_xmit.c linux-3.9.4-vs2.3.6.3/net/netfilter/ipvs/ip_vs_xmit.c
25602 --- linux-3.9.4/net/netfilter/ipvs/ip_vs_xmit.c 2013-02-19 13:58:59.000000000 +0000
25603 +++ linux-3.9.4-vs2.3.6.3/net/netfilter/ipvs/ip_vs_xmit.c       2013-05-31 17:17:54.000000000 +0000
25604 @@ -273,7 +273,7 @@ __ip_vs_route_output_v6(struct net *net,
25605                 return dst;
25606         if (ipv6_addr_any(&fl6.saddr) &&
25607             ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
25608 -                              &fl6.daddr, 0, &fl6.saddr) < 0)
25609 +                              &fl6.daddr, 0, &fl6.saddr, NULL) < 0)
25610                 goto out_err;
25611         if (do_xfrm) {
25612                 dst = xfrm_lookup(net, dst, flowi6_to_flowi(&fl6), NULL, 0);
25613 diff -NurpP --minimal linux-3.9.4/net/netlink/af_netlink.c linux-3.9.4-vs2.3.6.3/net/netlink/af_netlink.c
25614 --- linux-3.9.4/net/netlink/af_netlink.c        2013-05-31 13:45:33.000000000 +0000
25615 +++ linux-3.9.4-vs2.3.6.3/net/netlink/af_netlink.c      2013-05-31 17:17:54.000000000 +0000
25616 @@ -55,6 +55,9 @@
25617  #include <linux/types.h>
25618  #include <linux/audit.h>
25619  #include <linux/mutex.h>
25620 +#include <linux/vs_context.h>
25621 +#include <linux/vs_network.h>
25622 +#include <linux/vs_limit.h>
25623  
25624  #include <net/net_namespace.h>
25625  #include <net/sock.h>
25626 @@ -1976,6 +1979,8 @@ static struct sock *netlink_seq_socket_i
25627                         sk_for_each(s, &hash->table[j]) {
25628                                 if (sock_net(s) != seq_file_net(seq))
25629                                         continue;
25630 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25631 +                                       continue;
25632                                 if (off == pos) {
25633                                         iter->link = i;
25634                                         iter->hash_idx = j;
25635 @@ -2010,7 +2015,8 @@ static void *netlink_seq_next(struct seq
25636         s = v;
25637         do {
25638                 s = sk_next(s);
25639 -       } while (s && sock_net(s) != seq_file_net(seq));
25640 +       } while (s && (sock_net(s) != seq_file_net(seq) ||
25641 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
25642         if (s)
25643                 return s;
25644  
25645 @@ -2022,7 +2028,8 @@ static void *netlink_seq_next(struct seq
25646  
25647                 for (; j <= hash->mask; j++) {
25648                         s = sk_head(&hash->table[j]);
25649 -                       while (s && sock_net(s) != seq_file_net(seq))
25650 +                       while (s && (sock_net(s) != seq_file_net(seq) ||
25651 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
25652                                 s = sk_next(s);
25653                         if (s) {
25654                                 iter->link = i;
25655 diff -NurpP --minimal linux-3.9.4/net/socket.c linux-3.9.4-vs2.3.6.3/net/socket.c
25656 --- linux-3.9.4/net/socket.c    2013-05-31 13:45:33.000000000 +0000
25657 +++ linux-3.9.4-vs2.3.6.3/net/socket.c  2013-05-31 17:17:54.000000000 +0000
25658 @@ -98,6 +98,10 @@
25659  
25660  #include <net/sock.h>
25661  #include <linux/netfilter.h>
25662 +#include <linux/vs_base.h>
25663 +#include <linux/vs_socket.h>
25664 +#include <linux/vs_inet.h>
25665 +#include <linux/vs_inet6.h>
25666  
25667  #include <linux/if_tun.h>
25668  #include <linux/ipv6_route.h>
25669 @@ -617,13 +621,29 @@ static inline int __sock_sendmsg_nosec(s
25670                                        struct msghdr *msg, size_t size)
25671  {
25672         struct sock_iocb *si = kiocb_to_siocb(iocb);
25673 +       size_t len;
25674  
25675         si->sock = sock;
25676         si->scm = NULL;
25677         si->msg = msg;
25678         si->size = size;
25679  
25680 -       return sock->ops->sendmsg(iocb, sock, msg, size);
25681 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
25682 +       if (sock->sk) {
25683 +               if (len == size)
25684 +                       vx_sock_send(sock->sk, size);
25685 +               else
25686 +                       vx_sock_fail(sock->sk, size);
25687 +       }
25688 +       vxdprintk(VXD_CBIT(net, 7),
25689 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%zu",
25690 +               sock, sock->sk,
25691 +               (sock->sk)?sock->sk->sk_nx_info:0,
25692 +               (sock->sk)?sock->sk->sk_vx_info:0,
25693 +               (sock->sk)?sock->sk->sk_xid:0,
25694 +               (sock->sk)?sock->sk->sk_nid:0,
25695 +               (unsigned int)size, len);
25696 +       return len;
25697  }
25698  
25699  static inline int __sock_sendmsg(struct kiocb *iocb, struct socket *sock,
25700 @@ -779,6 +799,7 @@ static inline int __sock_recvmsg_nosec(s
25701                                        struct msghdr *msg, size_t size, int flags)
25702  {
25703         struct sock_iocb *si = kiocb_to_siocb(iocb);
25704 +       int len;
25705  
25706         si->sock = sock;
25707         si->scm = NULL;
25708 @@ -786,7 +807,18 @@ static inline int __sock_recvmsg_nosec(s
25709         si->size = size;
25710         si->flags = flags;
25711  
25712 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
25713 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
25714 +       if ((len >= 0) && sock->sk)
25715 +               vx_sock_recv(sock->sk, len);
25716 +       vxdprintk(VXD_CBIT(net, 7),
25717 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
25718 +               sock, sock->sk,
25719 +               (sock->sk)?sock->sk->sk_nx_info:0,
25720 +               (sock->sk)?sock->sk->sk_vx_info:0,
25721 +               (sock->sk)?sock->sk->sk_xid:0,
25722 +               (sock->sk)?sock->sk->sk_nid:0,
25723 +               (unsigned int)size, len);
25724 +       return len;
25725  }
25726  
25727  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
25728 @@ -1269,6 +1301,13 @@ int __sock_create(struct net *net, int f
25729         if (type < 0 || type >= SOCK_MAX)
25730                 return -EINVAL;
25731  
25732 +       if (!nx_check(0, VS_ADMIN)) {
25733 +               if (family == PF_INET && !current_nx_info_has_v4())
25734 +                       return -EAFNOSUPPORT;
25735 +               if (family == PF_INET6 && !current_nx_info_has_v6())
25736 +                       return -EAFNOSUPPORT;
25737 +       }
25738 +
25739         /* Compatibility.
25740  
25741            This uglymoron is moved from INET layer to here to avoid
25742 @@ -1403,6 +1442,7 @@ SYSCALL_DEFINE3(socket, int, family, int
25743         if (retval < 0)
25744                 goto out;
25745  
25746 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
25747         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
25748         if (retval < 0)
25749                 goto out_release;
25750 @@ -1444,10 +1484,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
25751         err = sock_create(family, type, protocol, &sock1);
25752         if (err < 0)
25753                 goto out;
25754 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
25755  
25756         err = sock_create(family, type, protocol, &sock2);
25757         if (err < 0)
25758                 goto out_release_1;
25759 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
25760  
25761         err = sock1->ops->socketpair(sock1, sock2);
25762         if (err < 0)
25763 diff -NurpP --minimal linux-3.9.4/net/sunrpc/auth.c linux-3.9.4-vs2.3.6.3/net/sunrpc/auth.c
25764 --- linux-3.9.4/net/sunrpc/auth.c       2013-05-31 13:45:33.000000000 +0000
25765 +++ linux-3.9.4-vs2.3.6.3/net/sunrpc/auth.c     2013-06-03 20:11:37.000000000 +0000
25766 @@ -15,6 +15,7 @@
25767  #include <linux/sunrpc/clnt.h>
25768  #include <linux/sunrpc/gss_api.h>
25769  #include <linux/spinlock.h>
25770 +#include <linux/vs_tag.h>
25771  
25772  #ifdef RPC_DEBUG
25773  # define RPCDBG_FACILITY       RPCDBG_AUTH
25774 @@ -480,6 +481,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
25775         memset(&acred, 0, sizeof(acred));
25776         acred.uid = cred->fsuid;
25777         acred.gid = cred->fsgid;
25778 +       acred.tag = make_ktag(&init_user_ns, dx_current_tag());
25779         acred.group_info = get_group_info(((struct cred *)cred)->group_info);
25780  
25781         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
25782 @@ -520,6 +522,7 @@ rpcauth_bind_root_cred(struct rpc_task *
25783         struct auth_cred acred = {
25784                 .uid = GLOBAL_ROOT_UID,
25785                 .gid = GLOBAL_ROOT_GID,
25786 +               .tag = KTAGT_INIT(dx_current_tag()),
25787         };
25788  
25789         dprintk("RPC: %5u looking up %s cred\n",
25790 diff -NurpP --minimal linux-3.9.4/net/sunrpc/auth_unix.c linux-3.9.4-vs2.3.6.3/net/sunrpc/auth_unix.c
25791 --- linux-3.9.4/net/sunrpc/auth_unix.c  2013-05-31 13:45:33.000000000 +0000
25792 +++ linux-3.9.4-vs2.3.6.3/net/sunrpc/auth_unix.c        2013-06-03 19:35:29.000000000 +0000
25793 @@ -13,11 +13,13 @@
25794  #include <linux/sunrpc/clnt.h>
25795  #include <linux/sunrpc/auth.h>
25796  #include <linux/user_namespace.h>
25797 +#include <linux/vs_tag.h>
25798  
25799  #define NFS_NGROUPS    16
25800  
25801  struct unx_cred {
25802         struct rpc_cred         uc_base;
25803 +       ktag_t                  uc_tag;
25804         kgid_t                  uc_gid;
25805         kgid_t                  uc_gids[NFS_NGROUPS];
25806  };
25807 @@ -80,6 +82,7 @@ unx_create_cred(struct rpc_auth *auth, s
25808                 groups = NFS_NGROUPS;
25809  
25810         cred->uc_gid = acred->gid;
25811 +       cred->uc_tag = acred->tag;
25812         for (i = 0; i < groups; i++)
25813                 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
25814         if (i < NFS_NGROUPS)
25815 @@ -121,7 +124,9 @@ unx_match(struct auth_cred *acred, struc
25816         unsigned int i;
25817  
25818  
25819 -       if (!uid_eq(cred->uc_uid, acred->uid) || !gid_eq(cred->uc_gid, acred->gid))
25820 +       if (!uid_eq(cred->uc_uid, acred->uid) ||
25821 +           !gid_eq(cred->uc_gid, acred->gid) ||
25822 +           !tag_eq(cred->uc_tag, acred->tag))
25823                 return 0;
25824  
25825         if (acred->group_info != NULL)
25826 @@ -146,7 +151,7 @@ unx_marshal(struct rpc_task *task, __be3
25827         struct rpc_clnt *clnt = task->tk_client;
25828         struct unx_cred *cred = container_of(task->tk_rqstp->rq_cred, struct unx_cred, uc_base);
25829         __be32          *base, *hold;
25830 -       int             i;
25831 +       int             i, tag;
25832  
25833         *p++ = htonl(RPC_AUTH_UNIX);
25834         base = p++;
25835 @@ -157,8 +162,11 @@ unx_marshal(struct rpc_task *task, __be3
25836          */
25837         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
25838  
25839 -       *p++ = htonl((u32) from_kuid(&init_user_ns, cred->uc_uid));
25840 -       *p++ = htonl((u32) from_kgid(&init_user_ns, cred->uc_gid));
25841 +       tag = task->tk_client->cl_tag;
25842 +       *p++ = htonl((u32) from_kuid(&init_user_ns,
25843 +               TAGINO_KUID(tag, cred->uc_uid, cred->uc_tag)));
25844 +       *p++ = htonl((u32) from_kgid(&init_user_ns,
25845 +               TAGINO_KGID(tag, cred->uc_gid, cred->uc_tag)));
25846         hold = p++;
25847         for (i = 0; i < 16 && gid_valid(cred->uc_gids[i]); i++)
25848                 *p++ = htonl((u32) from_kgid(&init_user_ns, cred->uc_gids[i]));
25849 diff -NurpP --minimal linux-3.9.4/net/sunrpc/clnt.c linux-3.9.4-vs2.3.6.3/net/sunrpc/clnt.c
25850 --- linux-3.9.4/net/sunrpc/clnt.c       2013-05-31 13:45:33.000000000 +0000
25851 +++ linux-3.9.4-vs2.3.6.3/net/sunrpc/clnt.c     2013-05-31 17:17:54.000000000 +0000
25852 @@ -31,6 +31,7 @@
25853  #include <linux/in6.h>
25854  #include <linux/un.h>
25855  #include <linux/rcupdate.h>
25856 +#include <linux/vs_cvirt.h>
25857  
25858  #include <linux/sunrpc/clnt.h>
25859  #include <linux/sunrpc/addr.h>
25860 @@ -482,6 +483,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
25861         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
25862                 clnt->cl_chatty = 1;
25863  
25864 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
25865 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
25866 +               clnt->cl_tag = 1; */
25867         return clnt;
25868  }
25869  EXPORT_SYMBOL_GPL(rpc_create);
25870 diff -NurpP --minimal linux-3.9.4/net/unix/af_unix.c linux-3.9.4-vs2.3.6.3/net/unix/af_unix.c
25871 --- linux-3.9.4/net/unix/af_unix.c      2013-05-31 13:45:33.000000000 +0000
25872 +++ linux-3.9.4-vs2.3.6.3/net/unix/af_unix.c    2013-05-31 17:17:54.000000000 +0000
25873 @@ -114,6 +114,8 @@
25874  #include <linux/mount.h>
25875  #include <net/checksum.h>
25876  #include <linux/security.h>
25877 +#include <linux/vs_context.h>
25878 +#include <linux/vs_limit.h>
25879  
25880  struct hlist_head unix_socket_table[2 * UNIX_HASH_SIZE];
25881  EXPORT_SYMBOL_GPL(unix_socket_table);
25882 @@ -270,6 +272,8 @@ static struct sock *__unix_find_socket_b
25883                 if (!net_eq(sock_net(s), net))
25884                         continue;
25885  
25886 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25887 +                       continue;
25888                 if (u->addr->len == len &&
25889                     !memcmp(u->addr->name, sunname, len))
25890                         goto found;
25891 @@ -2256,6 +2260,8 @@ static struct sock *unix_from_bucket(str
25892         for (sk = sk_head(&unix_socket_table[bucket]); sk; sk = sk_next(sk)) {
25893                 if (sock_net(sk) != seq_file_net(seq))
25894                         continue;
25895 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25896 +                       continue;
25897                 if (++count == offset)
25898                         break;
25899         }
25900 @@ -2273,6 +2279,8 @@ static struct sock *unix_next_socket(str
25901                 sk = sk_next(sk);
25902                 if (!sk)
25903                         goto next_bucket;
25904 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25905 +                       continue;
25906                 if (sock_net(sk) == seq_file_net(seq))
25907                         return sk;
25908         }
25909 diff -NurpP --minimal linux-3.9.4/scripts/checksyscalls.sh linux-3.9.4-vs2.3.6.3/scripts/checksyscalls.sh
25910 --- linux-3.9.4/scripts/checksyscalls.sh        2012-12-11 03:30:57.000000000 +0000
25911 +++ linux-3.9.4-vs2.3.6.3/scripts/checksyscalls.sh      2013-05-31 14:47:11.000000000 +0000
25912 @@ -193,7 +193,6 @@ cat << EOF
25913  #define __IGNORE_afs_syscall
25914  #define __IGNORE_getpmsg
25915  #define __IGNORE_putpmsg
25916 -#define __IGNORE_vserver
25917  EOF
25918  }
25919  
25920 diff -NurpP --minimal linux-3.9.4/security/commoncap.c linux-3.9.4-vs2.3.6.3/security/commoncap.c
25921 --- linux-3.9.4/security/commoncap.c    2013-05-31 13:45:34.000000000 +0000
25922 +++ linux-3.9.4-vs2.3.6.3/security/commoncap.c  2013-05-31 15:07:02.000000000 +0000
25923 @@ -76,6 +76,7 @@ int cap_netlink_send(struct sock *sk, st
25924  int cap_capable(const struct cred *cred, struct user_namespace *targ_ns,
25925                 int cap, int audit)
25926  {
25927 +       struct vx_info *vxi = current_vx_info(); /* FIXME: get vxi from cred? */
25928         struct user_namespace *ns = targ_ns;
25929  
25930         /* See if cred has the capability in the target user namespace
25931 @@ -84,8 +85,12 @@ int cap_capable(const struct cred *cred,
25932          */
25933         for (;;) {
25934                 /* Do we have the necessary capabilities? */
25935 -               if (ns == cred->user_ns)
25936 -                       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
25937 +               if (ns == cred->user_ns) {
25938 +                       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
25939 +                           cap_raised(cred->cap_effective, cap))
25940 +                               return 0;
25941 +                       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
25942 +               }
25943  
25944                 /* Have we tried all of the parent namespaces? */
25945                 if (ns == &init_user_ns)
25946 @@ -628,7 +633,7 @@ int cap_inode_setxattr(struct dentry *de
25947  
25948         if (!strncmp(name, XATTR_SECURITY_PREFIX,
25949                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
25950 -           !capable(CAP_SYS_ADMIN))
25951 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
25952                 return -EPERM;
25953         return 0;
25954  }
25955 @@ -654,7 +659,7 @@ int cap_inode_removexattr(struct dentry
25956  
25957         if (!strncmp(name, XATTR_SECURITY_PREFIX,
25958                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
25959 -           !capable(CAP_SYS_ADMIN))
25960 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
25961                 return -EPERM;
25962         return 0;
25963  }
25964 diff -NurpP --minimal linux-3.9.4/security/selinux/hooks.c linux-3.9.4-vs2.3.6.3/security/selinux/hooks.c
25965 --- linux-3.9.4/security/selinux/hooks.c        2013-05-31 13:45:34.000000000 +0000
25966 +++ linux-3.9.4-vs2.3.6.3/security/selinux/hooks.c      2013-05-31 14:47:11.000000000 +0000
25967 @@ -67,7 +67,6 @@
25968  #include <linux/dccp.h>
25969  #include <linux/quota.h>
25970  #include <linux/un.h>          /* for Unix socket types */
25971 -#include <net/af_unix.h>       /* for Unix socket types */
25972  #include <linux/parser.h>
25973  #include <linux/nfs_mount.h>
25974  #include <net/ipv6.h>
This page took 2.048631 seconds and 4 git commands to generate.