]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
- vserver patch patch-3.9.4-vs2.3.6.1.diff (early 3.9 version); builds with vs, too
[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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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/um/include/shared/kern_constants.h linux-3.9.4-vs2.3.6.1/arch/um/include/shared/kern_constants.h
742 --- linux-3.9.4/arch/um/include/shared/kern_constants.h 1970-01-01 00:00:00.000000000 +0000
743 +++ linux-3.9.4-vs2.3.6.1/arch/um/include/shared/kern_constants.h       2013-05-31 14:47:11.000000000 +0000
744 @@ -0,0 +1 @@
745 +#include "../../../../include/generated/asm-offsets.h"
746 diff -NurpP --minimal linux-3.9.4/arch/um/include/shared/user_constants.h linux-3.9.4-vs2.3.6.1/arch/um/include/shared/user_constants.h
747 --- linux-3.9.4/arch/um/include/shared/user_constants.h 1970-01-01 00:00:00.000000000 +0000
748 +++ linux-3.9.4-vs2.3.6.1/arch/um/include/shared/user_constants.h       2013-05-31 14:47:11.000000000 +0000
749 @@ -0,0 +1,40 @@
750 +/*
751 + * DO NOT MODIFY.
752 + *
753 + * This file was generated by arch/um/Makefile
754 + *
755 + */
756 +
757 +#define HOST_SC_CR2 176 /* offsetof(struct sigcontext, cr2)    # */
758 +#define HOST_SC_ERR 152 /* offsetof(struct sigcontext, err)    # */
759 +#define HOST_SC_TRAPNO 160 /* offsetof(struct sigcontext, trapno)      # */
760 +#define HOST_FP_SIZE 64 /* sizeof(struct _fpstate) / sizeof(unsigned long)     # */
761 +#define HOST_RBX 5 /* RBX      # */
762 +#define HOST_RCX 11 /* RCX     # */
763 +#define HOST_RDI 14 /* RDI     # */
764 +#define HOST_RSI 13 /* RSI     # */
765 +#define HOST_RDX 12 /* RDX     # */
766 +#define HOST_RBP 4 /* RBP      # */
767 +#define HOST_RAX 10 /* RAX     # */
768 +#define HOST_R8 9 /* R8        # */
769 +#define HOST_R9 8 /* R9        # */
770 +#define HOST_R10 7 /* R10      # */
771 +#define HOST_R11 6 /* R11      # */
772 +#define HOST_R12 3 /* R12      # */
773 +#define HOST_R13 2 /* R13      # */
774 +#define HOST_R14 1 /* R14      # */
775 +#define HOST_R15 0 /* R15      # */
776 +#define HOST_ORIG_RAX 15 /* ORIG_RAX   # */
777 +#define HOST_CS 17 /* CS       # */
778 +#define HOST_SS 20 /* SS       # */
779 +#define HOST_EFLAGS 18 /* EFLAGS       # */
780 +#define HOST_IP 16 /* RIP      # */
781 +#define HOST_SP 19 /* RSP      # */
782 +#define UM_FRAME_SIZE 216 /* sizeof(struct user_regs_struct)   # */
783 +#define UM_POLLIN 1 /* POLLIN  # */
784 +#define UM_POLLPRI 2 /* POLLPRI        # */
785 +#define UM_POLLOUT 4 /* POLLOUT        # */
786 +#define UM_PROT_READ 1 /* PROT_READ    # */
787 +#define UM_PROT_WRITE 2 /* PROT_WRITE  # */
788 +#define UM_PROT_EXEC 4 /* PROT_EXEC    # */
789 +
790 diff -NurpP --minimal linux-3.9.4/arch/x86/Kconfig linux-3.9.4-vs2.3.6.1/arch/x86/Kconfig
791 --- linux-3.9.4/arch/x86/Kconfig        2013-05-31 14:22:26.000000000 +0000
792 +++ linux-3.9.4-vs2.3.6.1/arch/x86/Kconfig      2013-05-31 14:47:11.000000000 +0000
793 @@ -2341,6 +2341,8 @@ source "fs/Kconfig"
794  
795  source "arch/x86/Kconfig.debug"
796  
797 +source "kernel/vserver/Kconfig"
798 +
799  source "security/Kconfig"
800  
801  source "crypto/Kconfig"
802 diff -NurpP --minimal linux-3.9.4/arch/x86/syscalls/syscall_32.tbl linux-3.9.4-vs2.3.6.1/arch/x86/syscalls/syscall_32.tbl
803 --- linux-3.9.4/arch/x86/syscalls/syscall_32.tbl        2013-05-31 13:44:50.000000000 +0000
804 +++ linux-3.9.4-vs2.3.6.1/arch/x86/syscalls/syscall_32.tbl      2013-05-31 14:47:11.000000000 +0000
805 @@ -279,7 +279,7 @@
806  270    i386    tgkill                  sys_tgkill
807  271    i386    utimes                  sys_utimes                      compat_sys_utimes
808  272    i386    fadvise64_64            sys_fadvise64_64                sys32_fadvise64_64
809 -273    i386    vserver
810 +273    i386    vserver                 sys_vserver                     sys32_vserver
811  274    i386    mbind                   sys_mbind
812  275    i386    get_mempolicy           sys_get_mempolicy               compat_sys_get_mempolicy
813  276    i386    set_mempolicy           sys_set_mempolicy
814 diff -NurpP --minimal linux-3.9.4/arch/x86/syscalls/syscall_64.tbl linux-3.9.4-vs2.3.6.1/arch/x86/syscalls/syscall_64.tbl
815 --- linux-3.9.4/arch/x86/syscalls/syscall_64.tbl        2013-05-31 13:44:50.000000000 +0000
816 +++ linux-3.9.4-vs2.3.6.1/arch/x86/syscalls/syscall_64.tbl      2013-05-31 14:47:11.000000000 +0000
817 @@ -242,7 +242,7 @@
818  233    common  epoll_ctl               sys_epoll_ctl
819  234    common  tgkill                  sys_tgkill
820  235    common  utimes                  sys_utimes
821 -236    64      vserver
822 +236    64      vserver                 sys_vserver
823  237    common  mbind                   sys_mbind
824  238    common  set_mempolicy           sys_set_mempolicy
825  239    common  get_mempolicy           sys_get_mempolicy
826 diff -NurpP --minimal linux-3.9.4/drivers/block/Kconfig linux-3.9.4-vs2.3.6.1/drivers/block/Kconfig
827 --- linux-3.9.4/drivers/block/Kconfig   2013-05-31 13:44:51.000000000 +0000
828 +++ linux-3.9.4-vs2.3.6.1/drivers/block/Kconfig 2013-05-31 14:47:11.000000000 +0000
829 @@ -278,6 +278,13 @@ config BLK_DEV_CRYPTOLOOP
830  
831  source "drivers/block/drbd/Kconfig"
832  
833 +config BLK_DEV_VROOT
834 +       tristate "Virtual Root device support"
835 +       depends on QUOTACTL
836 +       ---help---
837 +         Saying Y here will allow you to use quota/fs ioctls on a shared
838 +         partition within a virtual server without compromising security.
839 +
840  config BLK_DEV_NBD
841         tristate "Network block device support"
842         depends on NET
843 diff -NurpP --minimal linux-3.9.4/drivers/block/Makefile linux-3.9.4-vs2.3.6.1/drivers/block/Makefile
844 --- linux-3.9.4/drivers/block/Makefile  2013-05-31 13:44:51.000000000 +0000
845 +++ linux-3.9.4-vs2.3.6.1/drivers/block/Makefile        2013-05-31 14:47:11.000000000 +0000
846 @@ -33,6 +33,7 @@ obj-$(CONFIG_VIRTIO_BLK)      += virtio_blk.o
847  obj-$(CONFIG_VIODASD)          += viodasd.o
848  obj-$(CONFIG_BLK_DEV_SX8)      += sx8.o
849  obj-$(CONFIG_BLK_DEV_HD)       += hd.o
850 +obj-$(CONFIG_BLK_DEV_VROOT)    += vroot.o
851  
852  obj-$(CONFIG_XEN_BLKDEV_FRONTEND)      += xen-blkfront.o
853  obj-$(CONFIG_XEN_BLKDEV_BACKEND)       += xen-blkback/
854 diff -NurpP --minimal linux-3.9.4/drivers/block/loop.c linux-3.9.4-vs2.3.6.1/drivers/block/loop.c
855 --- linux-3.9.4/drivers/block/loop.c    2013-05-31 13:44:51.000000000 +0000
856 +++ linux-3.9.4-vs2.3.6.1/drivers/block/loop.c  2013-05-31 14:47:11.000000000 +0000
857 @@ -76,6 +76,7 @@
858  #include <linux/sysfs.h>
859  #include <linux/miscdevice.h>
860  #include <linux/falloc.h>
861 +#include <linux/vs_context.h>
862  
863  #include <asm/uaccess.h>
864  
865 @@ -882,6 +883,7 @@ static int loop_set_fd(struct loop_devic
866         lo->lo_blocksize = lo_blocksize;
867         lo->lo_device = bdev;
868         lo->lo_flags = lo_flags;
869 +       lo->lo_xid = vx_current_xid();
870         lo->lo_backing_file = file;
871         lo->transfer = transfer_none;
872         lo->ioctl = NULL;
873 @@ -1033,6 +1035,7 @@ static int loop_clr_fd(struct loop_devic
874         lo->lo_sizelimit = 0;
875         lo->lo_encrypt_key_size = 0;
876         lo->lo_thread = NULL;
877 +       lo->lo_xid = 0;
878         memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
879         memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
880         memset(lo->lo_file_name, 0, LO_NAME_SIZE);
881 @@ -1076,7 +1079,7 @@ loop_set_status(struct loop_device *lo,
882  
883         if (lo->lo_encrypt_key_size &&
884             !uid_eq(lo->lo_key_owner, uid) &&
885 -           !capable(CAP_SYS_ADMIN))
886 +           !vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP))
887                 return -EPERM;
888         if (lo->lo_state != Lo_bound)
889                 return -ENXIO;
890 @@ -1166,7 +1169,8 @@ loop_get_status(struct loop_device *lo,
891         memcpy(info->lo_crypt_name, lo->lo_crypt_name, LO_NAME_SIZE);
892         info->lo_encrypt_type =
893                 lo->lo_encryption ? lo->lo_encryption->number : 0;
894 -       if (lo->lo_encrypt_key_size && capable(CAP_SYS_ADMIN)) {
895 +       if (lo->lo_encrypt_key_size &&
896 +               vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP)) {
897                 info->lo_encrypt_key_size = lo->lo_encrypt_key_size;
898                 memcpy(info->lo_encrypt_key, lo->lo_encrypt_key,
899                        lo->lo_encrypt_key_size);
900 @@ -1508,6 +1512,11 @@ static int lo_open(struct block_device *
901                 goto out;
902         }
903  
904 +       if (!vx_check(lo->lo_xid, VS_IDENT|VS_HOSTID|VS_ADMIN_P)) {
905 +               err = -EACCES;
906 +               goto out;
907 +       }
908 +
909         mutex_lock(&lo->lo_ctl_mutex);
910         lo->lo_refcnt++;
911         mutex_unlock(&lo->lo_ctl_mutex);
912 diff -NurpP --minimal linux-3.9.4/drivers/block/vroot.c linux-3.9.4-vs2.3.6.1/drivers/block/vroot.c
913 --- linux-3.9.4/drivers/block/vroot.c   1970-01-01 00:00:00.000000000 +0000
914 +++ linux-3.9.4-vs2.3.6.1/drivers/block/vroot.c 2013-05-31 14:47:11.000000000 +0000
915 @@ -0,0 +1,291 @@
916 +/*
917 + *  linux/drivers/block/vroot.c
918 + *
919 + *  written by Herbert Pötzl, 9/11/2002
920 + *  ported to 2.6.10 by Herbert Pötzl, 30/12/2004
921 + *
922 + *  based on the loop.c code by Theodore Ts'o.
923 + *
924 + * Copyright (C) 2002-2007 by Herbert Pötzl.
925 + * Redistribution of this file is permitted under the
926 + * GNU General Public License.
927 + *
928 + */
929 +
930 +#include <linux/module.h>
931 +#include <linux/moduleparam.h>
932 +#include <linux/file.h>
933 +#include <linux/major.h>
934 +#include <linux/blkdev.h>
935 +#include <linux/slab.h>
936 +
937 +#include <linux/vroot.h>
938 +#include <linux/vs_context.h>
939 +
940 +
941 +static int max_vroot = 8;
942 +
943 +static struct vroot_device *vroot_dev;
944 +static struct gendisk **disks;
945 +
946 +
947 +static int vroot_set_dev(
948 +       struct vroot_device *vr,
949 +       struct block_device *bdev,
950 +       unsigned int arg)
951 +{
952 +       struct block_device *real_bdev;
953 +       struct file *file;
954 +       struct inode *inode;
955 +       int error;
956 +
957 +       error = -EBUSY;
958 +       if (vr->vr_state != Vr_unbound)
959 +               goto out;
960 +
961 +       error = -EBADF;
962 +       file = fget(arg);
963 +       if (!file)
964 +               goto out;
965 +
966 +       error = -EINVAL;
967 +       inode = file->f_dentry->d_inode;
968 +
969 +
970 +       if (S_ISBLK(inode->i_mode)) {
971 +               real_bdev = inode->i_bdev;
972 +               vr->vr_device = real_bdev;
973 +               __iget(real_bdev->bd_inode);
974 +       } else
975 +               goto out_fput;
976 +
977 +       vxdprintk(VXD_CBIT(misc, 0),
978 +               "vroot[%d]_set_dev: dev=" VXF_DEV,
979 +               vr->vr_number, VXD_DEV(real_bdev));
980 +
981 +       vr->vr_state = Vr_bound;
982 +       error = 0;
983 +
984 + out_fput:
985 +       fput(file);
986 + out:
987 +       return error;
988 +}
989 +
990 +static int vroot_clr_dev(
991 +       struct vroot_device *vr,
992 +       struct block_device *bdev)
993 +{
994 +       struct block_device *real_bdev;
995 +
996 +       if (vr->vr_state != Vr_bound)
997 +               return -ENXIO;
998 +       if (vr->vr_refcnt > 1)  /* we needed one fd for the ioctl */
999 +               return -EBUSY;
1000 +
1001 +       real_bdev = vr->vr_device;
1002 +
1003 +       vxdprintk(VXD_CBIT(misc, 0),
1004 +               "vroot[%d]_clr_dev: dev=" VXF_DEV,
1005 +               vr->vr_number, VXD_DEV(real_bdev));
1006 +
1007 +       bdput(real_bdev);
1008 +       vr->vr_state = Vr_unbound;
1009 +       vr->vr_device = NULL;
1010 +       return 0;
1011 +}
1012 +
1013 +
1014 +static int vr_ioctl(struct block_device *bdev, fmode_t mode,
1015 +       unsigned int cmd, unsigned long arg)
1016 +{
1017 +       struct vroot_device *vr = bdev->bd_disk->private_data;
1018 +       int err;
1019 +
1020 +       down(&vr->vr_ctl_mutex);
1021 +       switch (cmd) {
1022 +       case VROOT_SET_DEV:
1023 +               err = vroot_set_dev(vr, bdev, arg);
1024 +               break;
1025 +       case VROOT_CLR_DEV:
1026 +               err = vroot_clr_dev(vr, bdev);
1027 +               break;
1028 +       default:
1029 +               err = -EINVAL;
1030 +               break;
1031 +       }
1032 +       up(&vr->vr_ctl_mutex);
1033 +       return err;
1034 +}
1035 +
1036 +static int vr_open(struct block_device *bdev, fmode_t mode)
1037 +{
1038 +       struct vroot_device *vr = bdev->bd_disk->private_data;
1039 +
1040 +       down(&vr->vr_ctl_mutex);
1041 +       vr->vr_refcnt++;
1042 +       up(&vr->vr_ctl_mutex);
1043 +       return 0;
1044 +}
1045 +
1046 +static int vr_release(struct gendisk *disk, fmode_t mode)
1047 +{
1048 +       struct vroot_device *vr = disk->private_data;
1049 +
1050 +       down(&vr->vr_ctl_mutex);
1051 +       --vr->vr_refcnt;
1052 +       up(&vr->vr_ctl_mutex);
1053 +       return 0;
1054 +}
1055 +
1056 +static struct block_device_operations vr_fops = {
1057 +       .owner =        THIS_MODULE,
1058 +       .open =         vr_open,
1059 +       .release =      vr_release,
1060 +       .ioctl =        vr_ioctl,
1061 +};
1062 +
1063 +static void vroot_make_request(struct request_queue *q, struct bio *bio)
1064 +{
1065 +       printk("vroot_make_request %p, %p\n", q, bio);
1066 +       bio_io_error(bio);
1067 +}
1068 +
1069 +struct block_device *__vroot_get_real_bdev(struct block_device *bdev)
1070 +{
1071 +       struct inode *inode = bdev->bd_inode;
1072 +       struct vroot_device *vr;
1073 +       struct block_device *real_bdev;
1074 +       int minor = iminor(inode);
1075 +
1076 +       vr = &vroot_dev[minor];
1077 +       real_bdev = vr->vr_device;
1078 +
1079 +       vxdprintk(VXD_CBIT(misc, 0),
1080 +               "vroot[%d]_get_real_bdev: dev=" VXF_DEV,
1081 +               vr->vr_number, VXD_DEV(real_bdev));
1082 +
1083 +       if (vr->vr_state != Vr_bound)
1084 +               return ERR_PTR(-ENXIO);
1085 +
1086 +       __iget(real_bdev->bd_inode);
1087 +       return real_bdev;
1088 +}
1089 +
1090 +
1091 +
1092 +/*
1093 + * And now the modules code and kernel interface.
1094 + */
1095 +
1096 +module_param(max_vroot, int, 0);
1097 +
1098 +MODULE_PARM_DESC(max_vroot, "Maximum number of vroot devices (1-256)");
1099 +MODULE_LICENSE("GPL");
1100 +MODULE_ALIAS_BLOCKDEV_MAJOR(VROOT_MAJOR);
1101 +
1102 +MODULE_AUTHOR ("Herbert Pötzl");
1103 +MODULE_DESCRIPTION ("Virtual Root Device Mapper");
1104 +
1105 +
1106 +int __init vroot_init(void)
1107 +{
1108 +       int err, i;
1109 +
1110 +       if (max_vroot < 1 || max_vroot > 256) {
1111 +               max_vroot = MAX_VROOT_DEFAULT;
1112 +               printk(KERN_WARNING "vroot: invalid max_vroot "
1113 +                       "(must be between 1 and 256), "
1114 +                       "using default (%d)\n", max_vroot);
1115 +       }
1116 +
1117 +       if (register_blkdev(VROOT_MAJOR, "vroot"))
1118 +               return -EIO;
1119 +
1120 +       err = -ENOMEM;
1121 +       vroot_dev = kmalloc(max_vroot * sizeof(struct vroot_device), GFP_KERNEL);
1122 +       if (!vroot_dev)
1123 +               goto out_mem1;
1124 +       memset(vroot_dev, 0, max_vroot * sizeof(struct vroot_device));
1125 +
1126 +       disks = kmalloc(max_vroot * sizeof(struct gendisk *), GFP_KERNEL);
1127 +       if (!disks)
1128 +               goto out_mem2;
1129 +
1130 +       for (i = 0; i < max_vroot; i++) {
1131 +               disks[i] = alloc_disk(1);
1132 +               if (!disks[i])
1133 +                       goto out_mem3;
1134 +               disks[i]->queue = blk_alloc_queue(GFP_KERNEL);
1135 +               if (!disks[i]->queue)
1136 +                       goto out_mem3;
1137 +               blk_queue_make_request(disks[i]->queue, vroot_make_request);
1138 +       }
1139 +
1140 +       for (i = 0; i < max_vroot; i++) {
1141 +               struct vroot_device *vr = &vroot_dev[i];
1142 +               struct gendisk *disk = disks[i];
1143 +
1144 +               memset(vr, 0, sizeof(*vr));
1145 +               sema_init(&vr->vr_ctl_mutex, 1);
1146 +               vr->vr_number = i;
1147 +               disk->major = VROOT_MAJOR;
1148 +               disk->first_minor = i;
1149 +               disk->fops = &vr_fops;
1150 +               sprintf(disk->disk_name, "vroot%d", i);
1151 +               disk->private_data = vr;
1152 +       }
1153 +
1154 +       err = register_vroot_grb(&__vroot_get_real_bdev);
1155 +       if (err)
1156 +               goto out_mem3;
1157 +
1158 +       for (i = 0; i < max_vroot; i++)
1159 +               add_disk(disks[i]);
1160 +       printk(KERN_INFO "vroot: loaded (max %d devices)\n", max_vroot);
1161 +       return 0;
1162 +
1163 +out_mem3:
1164 +       while (i--)
1165 +               put_disk(disks[i]);
1166 +       kfree(disks);
1167 +out_mem2:
1168 +       kfree(vroot_dev);
1169 +out_mem1:
1170 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1171 +       printk(KERN_ERR "vroot: ran out of memory\n");
1172 +       return err;
1173 +}
1174 +
1175 +void vroot_exit(void)
1176 +{
1177 +       int i;
1178 +
1179 +       if (unregister_vroot_grb(&__vroot_get_real_bdev))
1180 +               printk(KERN_WARNING "vroot: cannot unregister grb\n");
1181 +
1182 +       for (i = 0; i < max_vroot; i++) {
1183 +               del_gendisk(disks[i]);
1184 +               put_disk(disks[i]);
1185 +       }
1186 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1187 +
1188 +       kfree(disks);
1189 +       kfree(vroot_dev);
1190 +}
1191 +
1192 +module_init(vroot_init);
1193 +module_exit(vroot_exit);
1194 +
1195 +#ifndef MODULE
1196 +
1197 +static int __init max_vroot_setup(char *str)
1198 +{
1199 +       max_vroot = simple_strtol(str, NULL, 0);
1200 +       return 1;
1201 +}
1202 +
1203 +__setup("max_vroot=", max_vroot_setup);
1204 +
1205 +#endif
1206 +
1207 diff -NurpP --minimal linux-3.9.4/drivers/infiniband/Kconfig linux-3.9.4-vs2.3.6.1/drivers/infiniband/Kconfig
1208 --- linux-3.9.4/drivers/infiniband/Kconfig      2012-12-11 03:30:57.000000000 +0000
1209 +++ linux-3.9.4-vs2.3.6.1/drivers/infiniband/Kconfig    2013-05-31 14:47:11.000000000 +0000
1210 @@ -39,7 +39,7 @@ config INFINIBAND_USER_MEM
1211  config INFINIBAND_ADDR_TRANS
1212         bool
1213         depends on INET
1214 -       depends on !(INFINIBAND = y && IPV6 = m)
1215 +       depends on !(INFINIBAND = y && IPV6 = y)
1216         default y
1217  
1218  source "drivers/infiniband/hw/mthca/Kconfig"
1219 diff -NurpP --minimal linux-3.9.4/drivers/infiniband/core/addr.c linux-3.9.4-vs2.3.6.1/drivers/infiniband/core/addr.c
1220 --- linux-3.9.4/drivers/infiniband/core/addr.c  2012-12-11 03:30:57.000000000 +0000
1221 +++ linux-3.9.4-vs2.3.6.1/drivers/infiniband/core/addr.c        2013-05-31 14:47:11.000000000 +0000
1222 @@ -261,7 +261,7 @@ static int addr6_resolve(struct sockaddr
1223  
1224         if (ipv6_addr_any(&fl6.saddr)) {
1225                 ret = ipv6_dev_get_saddr(&init_net, ip6_dst_idev(dst)->dev,
1226 -                                        &fl6.daddr, 0, &fl6.saddr);
1227 +                                        &fl6.daddr, 0, &fl6.saddr, NULL);
1228                 if (ret)
1229                         goto put;
1230  
1231 diff -NurpP --minimal linux-3.9.4/drivers/md/dm-ioctl.c linux-3.9.4-vs2.3.6.1/drivers/md/dm-ioctl.c
1232 --- linux-3.9.4/drivers/md/dm-ioctl.c   2013-05-31 13:44:59.000000000 +0000
1233 +++ linux-3.9.4-vs2.3.6.1/drivers/md/dm-ioctl.c 2013-05-31 14:47:11.000000000 +0000
1234 @@ -16,6 +16,7 @@
1235  #include <linux/dm-ioctl.h>
1236  #include <linux/hdreg.h>
1237  #include <linux/compat.h>
1238 +#include <linux/vs_context.h>
1239  
1240  #include <asm/uaccess.h>
1241  
1242 @@ -106,7 +107,8 @@ static struct hash_cell *__get_name_cell
1243         unsigned int h = hash_str(str);
1244  
1245         list_for_each_entry (hc, _name_buckets + h, name_list)
1246 -               if (!strcmp(hc->name, str)) {
1247 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1248 +                       !strcmp(hc->name, str)) {
1249                         dm_get(hc->md);
1250                         return hc;
1251                 }
1252 @@ -120,7 +122,8 @@ static struct hash_cell *__get_uuid_cell
1253         unsigned int h = hash_str(str);
1254  
1255         list_for_each_entry (hc, _uuid_buckets + h, uuid_list)
1256 -               if (!strcmp(hc->uuid, str)) {
1257 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1258 +                       !strcmp(hc->uuid, str)) {
1259                         dm_get(hc->md);
1260                         return hc;
1261                 }
1262 @@ -131,13 +134,15 @@ static struct hash_cell *__get_uuid_cell
1263  static struct hash_cell *__get_dev_cell(uint64_t dev)
1264  {
1265         struct mapped_device *md;
1266 -       struct hash_cell *hc;
1267 +       struct hash_cell *hc = NULL;
1268  
1269         md = dm_get_md(huge_decode_dev(dev));
1270         if (!md)
1271                 return NULL;
1272  
1273 -       hc = dm_get_mdptr(md);
1274 +       if (vx_check(dm_get_xid(md), VS_WATCH_P | VS_IDENT))
1275 +               hc = dm_get_mdptr(md);
1276 +
1277         if (!hc) {
1278                 dm_put(md);
1279                 return NULL;
1280 @@ -445,6 +450,9 @@ typedef int (*ioctl_fn)(struct dm_ioctl
1281  
1282  static int remove_all(struct dm_ioctl *param, size_t param_size)
1283  {
1284 +       if (!vx_check(0, VS_ADMIN))
1285 +               return -EPERM;
1286 +
1287         dm_hash_remove_all(1);
1288         param->data_size = 0;
1289         return 0;
1290 @@ -492,6 +500,8 @@ static int list_devices(struct dm_ioctl
1291          */
1292         for (i = 0; i < NUM_BUCKETS; i++) {
1293                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1294 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1295 +                               continue;
1296                         needed += sizeof(struct dm_name_list);
1297                         needed += strlen(hc->name) + 1;
1298                         needed += ALIGN_MASK;
1299 @@ -515,6 +525,8 @@ static int list_devices(struct dm_ioctl
1300          */
1301         for (i = 0; i < NUM_BUCKETS; i++) {
1302                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1303 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1304 +                               continue;
1305                         if (old_nl)
1306                                 old_nl->next = (uint32_t) ((void *) nl -
1307                                                            (void *) old_nl);
1308 @@ -1722,8 +1734,8 @@ static int ctl_ioctl(uint command, struc
1309         size_t input_param_size;
1310         struct dm_ioctl param_kernel;
1311  
1312 -       /* only root can play with this */
1313 -       if (!capable(CAP_SYS_ADMIN))
1314 +       /* only root and certain contexts can play with this */
1315 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_MAPPER))
1316                 return -EACCES;
1317  
1318         if (_IOC_TYPE(command) != DM_IOCTL)
1319 diff -NurpP --minimal linux-3.9.4/drivers/md/dm.c linux-3.9.4-vs2.3.6.1/drivers/md/dm.c
1320 --- linux-3.9.4/drivers/md/dm.c 2013-05-31 13:44:59.000000000 +0000
1321 +++ linux-3.9.4-vs2.3.6.1/drivers/md/dm.c       2013-05-31 14:47:11.000000000 +0000
1322 @@ -19,6 +19,7 @@
1323  #include <linux/idr.h>
1324  #include <linux/hdreg.h>
1325  #include <linux/delay.h>
1326 +#include <linux/vs_base.h>
1327  
1328  #include <trace/events/block.h>
1329  
1330 @@ -125,6 +126,7 @@ struct mapped_device {
1331         rwlock_t map_lock;
1332         atomic_t holders;
1333         atomic_t open_count;
1334 +       xid_t xid;
1335  
1336         unsigned long flags;
1337  
1338 @@ -317,6 +319,7 @@ int dm_deleting_md(struct mapped_device
1339  static int dm_blk_open(struct block_device *bdev, fmode_t mode)
1340  {
1341         struct mapped_device *md;
1342 +       int ret = -ENXIO;
1343  
1344         spin_lock(&_minor_lock);
1345  
1346 @@ -325,18 +328,19 @@ static int dm_blk_open(struct block_devi
1347                 goto out;
1348  
1349         if (test_bit(DMF_FREEING, &md->flags) ||
1350 -           dm_deleting_md(md)) {
1351 -               md = NULL;
1352 +           dm_deleting_md(md))
1353 +               goto out;
1354 +
1355 +       ret = -EACCES;
1356 +       if (!vx_check(md->xid, VS_IDENT|VS_HOSTID))
1357                 goto out;
1358 -       }
1359  
1360         dm_get(md);
1361         atomic_inc(&md->open_count);
1362 -
1363 +       ret = 0;
1364  out:
1365         spin_unlock(&_minor_lock);
1366 -
1367 -       return md ? 0 : -ENXIO;
1368 +       return ret;
1369  }
1370  
1371  static int dm_blk_close(struct gendisk *disk, fmode_t mode)
1372 @@ -547,6 +551,14 @@ int dm_set_geometry(struct mapped_device
1373         return 0;
1374  }
1375  
1376 +/*
1377 + * Get the xid associated with a dm device
1378 + */
1379 +xid_t dm_get_xid(struct mapped_device *md)
1380 +{
1381 +       return md->xid;
1382 +}
1383 +
1384  /*-----------------------------------------------------------------
1385   * CRUD START:
1386   *   A more elegant soln is in the works that uses the queue
1387 @@ -1884,6 +1896,7 @@ static struct mapped_device *alloc_dev(i
1388         INIT_LIST_HEAD(&md->uevent_list);
1389         spin_lock_init(&md->uevent_lock);
1390  
1391 +       md->xid = vx_current_xid();
1392         md->queue = blk_alloc_queue(GFP_KERNEL);
1393         if (!md->queue)
1394                 goto bad_queue;
1395 diff -NurpP --minimal linux-3.9.4/drivers/md/dm.h linux-3.9.4-vs2.3.6.1/drivers/md/dm.h
1396 --- linux-3.9.4/drivers/md/dm.h 2013-02-19 13:57:51.000000000 +0000
1397 +++ linux-3.9.4-vs2.3.6.1/drivers/md/dm.h       2013-05-31 14:47:11.000000000 +0000
1398 @@ -46,6 +46,8 @@ struct dm_dev_internal {
1399  struct dm_table;
1400  struct dm_md_mempools;
1401  
1402 +xid_t dm_get_xid(struct mapped_device *md);
1403 +
1404  /*-----------------------------------------------------------------
1405   * Internal table functions.
1406   *---------------------------------------------------------------*/
1407 diff -NurpP --minimal linux-3.9.4/drivers/net/tun.c linux-3.9.4-vs2.3.6.1/drivers/net/tun.c
1408 --- linux-3.9.4/drivers/net/tun.c       2013-05-31 14:22:27.000000000 +0000
1409 +++ linux-3.9.4-vs2.3.6.1/drivers/net/tun.c     2013-05-31 20:01:45.000000000 +0000
1410 @@ -64,6 +64,7 @@
1411  #include <linux/nsproxy.h>
1412  #include <linux/virtio_net.h>
1413  #include <linux/rcupdate.h>
1414 +#include <linux/vs_network.h>
1415  #include <net/net_namespace.h>
1416  #include <net/netns/generic.h>
1417  #include <net/rtnetlink.h>
1418 @@ -164,6 +165,7 @@ struct tun_struct {
1419         unsigned int            flags;
1420         kuid_t                  owner;
1421         kgid_t                  group;
1422 +       nid_t                   nid;
1423  
1424         struct net_device       *dev;
1425         netdev_features_t       set_features;
1426 @@ -380,6 +382,7 @@ static inline bool tun_not_capable(struc
1427         return ((uid_valid(tun->owner) && !uid_eq(cred->euid, tun->owner)) ||
1428                   (gid_valid(tun->group) && !in_egroup_p(tun->group))) &&
1429                 !ns_capable(net->user_ns, CAP_NET_ADMIN);
1430 +               /* !cap_raised(current_cap(), CAP_NET_ADMIN) */
1431  }
1432  
1433  static void tun_set_real_num_queues(struct tun_struct *tun)
1434 @@ -1404,6 +1407,7 @@ static void tun_setup(struct net_device
1435  
1436         tun->owner = INVALID_UID;
1437         tun->group = INVALID_GID;
1438 +       tun->nid = nx_current_nid();
1439  
1440         dev->ethtool_ops = &tun_ethtool_ops;
1441         dev->destructor = tun_free_netdev;
1442 @@ -1591,6 +1595,9 @@ static int tun_set_iff(struct net *net,
1443                 if (err < 0)
1444                         return err;
1445  
1446 +               if (!nx_check(tun->nid, VS_IDENT | VS_HOSTID | VS_ADMIN_P))
1447 +                       return -EPERM;
1448 +
1449                 err = tun_attach(tun, file);
1450                 if (err < 0)
1451                         return err;
1452 @@ -1605,7 +1612,7 @@ static int tun_set_iff(struct net *net,
1453                 int queues = ifr->ifr_flags & IFF_MULTI_QUEUE ?
1454                              MAX_TAP_QUEUES : 1;
1455  
1456 -               if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
1457 +               if (!vx_ns_capable(net->user_ns, CAP_NET_ADMIN, NXC_TUN_CREATE))
1458                         return -EPERM;
1459                 err = security_tun_dev_create();
1460                 if (err < 0)
1461 @@ -1950,6 +1957,16 @@ static long __tun_chr_ioctl(struct file
1462                           from_kgid(&init_user_ns, tun->group));
1463                 break;
1464  
1465 +       case TUNSETNID:
1466 +               if (!capable(CAP_CONTEXT))
1467 +                       return -EPERM;
1468 +
1469 +               /* Set nid owner of the device */
1470 +               tun->nid = (nid_t) arg;
1471 +
1472 +               tun_debug(KERN_INFO, tun, "nid owner set to %u\n", tun->nid);
1473 +               break;
1474 +
1475         case TUNSETLINK:
1476                 /* Only allow setting the type when the interface is down */
1477                 if (tun->dev->flags & IFF_UP) {
1478 diff -NurpP --minimal linux-3.9.4/drivers/staging/csr/csr_wifi_hip_xbv.c linux-3.9.4-vs2.3.6.1/drivers/staging/csr/csr_wifi_hip_xbv.c
1479 --- linux-3.9.4/drivers/staging/csr/csr_wifi_hip_xbv.c  2013-02-19 13:58:32.000000000 +0000
1480 +++ linux-3.9.4-vs2.3.6.1/drivers/staging/csr/csr_wifi_hip_xbv.c        2013-05-31 14:47:11.000000000 +0000
1481 @@ -55,7 +55,7 @@ typedef struct
1482  {
1483      char t_name[4];
1484      u32     t_len;
1485 -} tag_t;
1486 +} ctag_t;
1487  
1488  
1489  #define TAG_EQ(i, v)    (((i)[0] == (v)[0]) &&  \
1490 @@ -90,7 +90,7 @@ typedef struct
1491      u32 ptr;
1492  } xbv_stack_t;
1493  
1494 -static s32 read_tag(card_t *card, ct_t *ct, tag_t *tag);
1495 +static s32 read_tag(card_t *card, ct_t *ct, ctag_t *tag);
1496  static s32 read_bytes(card_t *card, ct_t *ct, void *buf, u32 len);
1497  static s32 read_uint(card_t *card, ct_t *ct, u32 *u, u32 len);
1498  static s32 xbv_check(xbv1_t *fwinfo, const xbv_stack_t *stack,
1499 @@ -160,7 +160,7 @@ static u32 write_fwdl_to_ptdl(void *buf,
1500  CsrResult xbv1_parse(card_t *card, fwreadfn_t readfn, void *dlpriv, xbv1_t *fwinfo)
1501  {
1502      ct_t ct;
1503 -    tag_t tag;
1504 +    ctag_t tag;
1505      xbv_stack_t stack;
1506  
1507      ct.dlpriv = dlpriv;
1508 @@ -505,7 +505,7 @@ static u32 xbv2uint(u8 *ptr, s32 len)
1509  }
1510  
1511  
1512 -static s32 read_tag(card_t *card, ct_t *ct, tag_t *tag)
1513 +static s32 read_tag(card_t *card, ct_t *ct, ctag_t *tag)
1514  {
1515      u8 buf[8];
1516      s32 n;
1517 diff -NurpP --minimal linux-3.9.4/drivers/tty/sysrq.c linux-3.9.4-vs2.3.6.1/drivers/tty/sysrq.c
1518 --- linux-3.9.4/drivers/tty/sysrq.c     2013-05-31 13:45:19.000000000 +0000
1519 +++ linux-3.9.4-vs2.3.6.1/drivers/tty/sysrq.c   2013-05-31 15:08:19.000000000 +0000
1520 @@ -43,6 +43,7 @@
1521  #include <linux/input.h>
1522  #include <linux/uaccess.h>
1523  #include <linux/moduleparam.h>
1524 +#include <linux/vserver/debug.h>
1525  
1526  #include <asm/ptrace.h>
1527  #include <asm/irq_regs.h>
1528 @@ -401,6 +402,21 @@ static struct sysrq_key_op sysrq_unrt_op
1529         .enable_mask    = SYSRQ_ENABLE_RTNICE,
1530  };
1531  
1532 +
1533 +#ifdef CONFIG_VSERVER_DEBUG
1534 +static void sysrq_handle_vxinfo(int key)
1535 +{
1536 +       dump_vx_info_inactive((key == 'x') ? 0 : 1);
1537 +}
1538 +
1539 +static struct sysrq_key_op sysrq_showvxinfo_op = {
1540 +       .handler        = sysrq_handle_vxinfo,
1541 +       .help_msg       = "conteXt",
1542 +       .action_msg     = "Show Context Info",
1543 +       .enable_mask    = SYSRQ_ENABLE_DUMP,
1544 +};
1545 +#endif
1546 +
1547  /* Key Operations table and lock */
1548  static DEFINE_SPINLOCK(sysrq_key_table_lock);
1549  
1550 @@ -456,7 +472,11 @@ static struct sysrq_key_op *sysrq_key_ta
1551         &sysrq_showstate_blocked_op,    /* w */
1552         /* x: May be registered on ppc/powerpc for xmon */
1553         /* x: May be registered on sparc64 for global PMU dump */
1554 +#ifdef CONFIG_VSERVER_DEBUG
1555 +       &sysrq_showvxinfo_op,           /* x */
1556 +#else
1557         NULL,                           /* x */
1558 +#endif
1559         /* y: May be registered on sparc64 for global register dump */
1560         NULL,                           /* y */
1561         &sysrq_ftrace_dump_op,          /* z */
1562 @@ -471,6 +491,8 @@ static int sysrq_key_table_key2index(int
1563                 retval = key - '0';
1564         else if ((key >= 'a') && (key <= 'z'))
1565                 retval = key + 10 - 'a';
1566 +       else if ((key >= 'A') && (key <= 'Z'))
1567 +               retval = key + 10 - 'A';
1568         else
1569                 retval = -1;
1570         return retval;
1571 diff -NurpP --minimal linux-3.9.4/drivers/tty/tty_io.c linux-3.9.4-vs2.3.6.1/drivers/tty/tty_io.c
1572 --- linux-3.9.4/drivers/tty/tty_io.c    2013-05-31 14:22:27.000000000 +0000
1573 +++ linux-3.9.4-vs2.3.6.1/drivers/tty/tty_io.c  2013-05-31 14:47:11.000000000 +0000
1574 @@ -104,6 +104,7 @@
1575  
1576  #include <linux/kmod.h>
1577  #include <linux/nsproxy.h>
1578 +#include <linux/vs_pid.h>
1579  
1580  #undef TTY_DEBUG_HANGUP
1581  
1582 @@ -2144,7 +2145,8 @@ static int tiocsti(struct tty_struct *tt
1583         char ch, mbz = 0;
1584         struct tty_ldisc *ld;
1585  
1586 -       if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN))
1587 +       if (((current->signal->tty != tty) &&
1588 +               !vx_capable(CAP_SYS_ADMIN, VXC_TIOCSTI)))
1589                 return -EPERM;
1590         if (get_user(ch, p))
1591                 return -EFAULT;
1592 @@ -2432,6 +2434,7 @@ static int tiocspgrp(struct tty_struct *
1593                 return -ENOTTY;
1594         if (get_user(pgrp_nr, p))
1595                 return -EFAULT;
1596 +       pgrp_nr = vx_rmap_pid(pgrp_nr);
1597         if (pgrp_nr < 0)
1598                 return -EINVAL;
1599         rcu_read_lock();
1600 diff -NurpP --minimal linux-3.9.4/fs/attr.c linux-3.9.4-vs2.3.6.1/fs/attr.c
1601 --- linux-3.9.4/fs/attr.c       2013-02-19 13:58:46.000000000 +0000
1602 +++ linux-3.9.4-vs2.3.6.1/fs/attr.c     2013-05-31 14:47:11.000000000 +0000
1603 @@ -15,6 +15,9 @@
1604  #include <linux/security.h>
1605  #include <linux/evm.h>
1606  #include <linux/ima.h>
1607 +#include <linux/proc_fs.h>
1608 +#include <linux/devpts_fs.h>
1609 +#include <linux/vs_tag.h>
1610  
1611  /**
1612   * inode_change_ok - check if attribute changes to an inode are allowed
1613 @@ -77,6 +80,10 @@ int inode_change_ok(const struct inode *
1614                         return -EPERM;
1615         }
1616  
1617 +       /* check for inode tag permission */
1618 +       if (dx_permission(inode, MAY_WRITE))
1619 +               return -EACCES;
1620 +
1621         return 0;
1622  }
1623  EXPORT_SYMBOL(inode_change_ok);
1624 @@ -147,6 +154,8 @@ void setattr_copy(struct inode *inode, c
1625                 inode->i_uid = attr->ia_uid;
1626         if (ia_valid & ATTR_GID)
1627                 inode->i_gid = attr->ia_gid;
1628 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
1629 +               inode->i_tag = attr->ia_tag;
1630         if (ia_valid & ATTR_ATIME)
1631                 inode->i_atime = timespec_trunc(attr->ia_atime,
1632                                                 inode->i_sb->s_time_gran);
1633 @@ -177,7 +186,8 @@ int notify_change(struct dentry * dentry
1634  
1635         WARN_ON_ONCE(!mutex_is_locked(&inode->i_mutex));
1636  
1637 -       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_TIMES_SET)) {
1638 +       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID |
1639 +               ATTR_TAG | ATTR_TIMES_SET)) {
1640                 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
1641                         return -EPERM;
1642         }
1643 diff -NurpP --minimal linux-3.9.4/fs/block_dev.c linux-3.9.4-vs2.3.6.1/fs/block_dev.c
1644 --- linux-3.9.4/fs/block_dev.c  2013-05-31 13:45:22.000000000 +0000
1645 +++ linux-3.9.4-vs2.3.6.1/fs/block_dev.c        2013-05-31 14:47:11.000000000 +0000
1646 @@ -27,6 +27,7 @@
1647  #include <linux/namei.h>
1648  #include <linux/log2.h>
1649  #include <linux/cleancache.h>
1650 +#include <linux/vs_device.h>
1651  #include <asm/uaccess.h>
1652  #include "internal.h"
1653  
1654 @@ -528,6 +529,7 @@ struct block_device *bdget(dev_t dev)
1655                 bdev->bd_invalidated = 0;
1656                 inode->i_mode = S_IFBLK;
1657                 inode->i_rdev = dev;
1658 +               inode->i_mdev = dev;
1659                 inode->i_bdev = bdev;
1660                 inode->i_data.a_ops = &def_blk_aops;
1661                 mapping_set_gfp_mask(&inode->i_data, GFP_USER);
1662 @@ -575,6 +577,11 @@ EXPORT_SYMBOL(bdput);
1663  static struct block_device *bd_acquire(struct inode *inode)
1664  {
1665         struct block_device *bdev;
1666 +       dev_t mdev;
1667 +
1668 +       if (!vs_map_blkdev(inode->i_rdev, &mdev, DATTR_OPEN))
1669 +               return NULL;
1670 +       inode->i_mdev = mdev;
1671  
1672         spin_lock(&bdev_lock);
1673         bdev = inode->i_bdev;
1674 @@ -585,7 +592,7 @@ static struct block_device *bd_acquire(s
1675         }
1676         spin_unlock(&bdev_lock);
1677  
1678 -       bdev = bdget(inode->i_rdev);
1679 +       bdev = bdget(mdev);
1680         if (bdev) {
1681                 spin_lock(&bdev_lock);
1682                 if (!inode->i_bdev) {
1683 diff -NurpP --minimal linux-3.9.4/fs/btrfs/ctree.h linux-3.9.4-vs2.3.6.1/fs/btrfs/ctree.h
1684 --- linux-3.9.4/fs/btrfs/ctree.h        2013-05-31 13:45:22.000000000 +0000
1685 +++ linux-3.9.4-vs2.3.6.1/fs/btrfs/ctree.h      2013-05-31 14:47:11.000000000 +0000
1686 @@ -705,11 +705,14 @@ struct btrfs_inode_item {
1687         /* modification sequence number for NFS */
1688         __le64 sequence;
1689  
1690 +       __le16 tag;
1691         /*
1692          * a little future expansion, for more than this we can
1693          * just grow the inode item and version it
1694          */
1695 -       __le64 reserved[4];
1696 +       __le16 reserved16;
1697 +       __le32 reserved32;
1698 +       __le64 reserved[3];
1699         struct btrfs_timespec atime;
1700         struct btrfs_timespec ctime;
1701         struct btrfs_timespec mtime;
1702 @@ -1901,6 +1904,8 @@ struct btrfs_ioctl_defrag_range_args {
1703  #define BTRFS_MOUNT_CHECK_INTEGRITY_INCLUDING_EXTENT_DATA (1 << 21)
1704  #define BTRFS_MOUNT_PANIC_ON_FATAL_ERROR       (1 << 22)
1705  
1706 +#define BTRFS_MOUNT_TAGGED             (1 << 24)
1707 +
1708  #define btrfs_clear_opt(o, opt)                ((o) &= ~BTRFS_MOUNT_##opt)
1709  #define btrfs_set_opt(o, opt)          ((o) |= BTRFS_MOUNT_##opt)
1710  #define btrfs_raw_test_opt(o, opt)     ((o) & BTRFS_MOUNT_##opt)
1711 @@ -2170,6 +2175,7 @@ BTRFS_SETGET_FUNCS(inode_block_group, st
1712  BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
1713  BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
1714  BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
1715 +BTRFS_SETGET_FUNCS(inode_tag, struct btrfs_inode_item, tag, 16);
1716  BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
1717  BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
1718  BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
1719 @@ -2223,6 +2229,10 @@ BTRFS_SETGET_FUNCS(extent_flags, struct
1720  
1721  BTRFS_SETGET_FUNCS(extent_refs_v0, struct btrfs_extent_item_v0, refs, 32);
1722  
1723 +#define BTRFS_INODE_IXUNLINK           (1 << 24)
1724 +#define BTRFS_INODE_BARRIER            (1 << 25)
1725 +#define BTRFS_INODE_COW                        (1 << 26)
1726 +
1727  
1728  BTRFS_SETGET_FUNCS(tree_block_level, struct btrfs_tree_block_info, level, 8);
1729  
1730 @@ -3581,6 +3591,7 @@ extern const struct dentry_operations bt
1731  long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
1732  void btrfs_update_iflags(struct inode *inode);
1733  void btrfs_inherit_iflags(struct inode *inode, struct inode *dir);
1734 +int btrfs_sync_flags(struct inode *inode, int, int);
1735  int btrfs_defrag_file(struct inode *inode, struct file *file,
1736                       struct btrfs_ioctl_defrag_range_args *range,
1737                       u64 newer_than, unsigned long max_pages);
1738 diff -NurpP --minimal linux-3.9.4/fs/btrfs/disk-io.c linux-3.9.4-vs2.3.6.1/fs/btrfs/disk-io.c
1739 --- linux-3.9.4/fs/btrfs/disk-io.c      2013-05-31 13:45:22.000000000 +0000
1740 +++ linux-3.9.4-vs2.3.6.1/fs/btrfs/disk-io.c    2013-05-31 14:47:11.000000000 +0000
1741 @@ -2258,6 +2258,9 @@ int open_ctree(struct super_block *sb,
1742                 goto fail_alloc;
1743         }
1744  
1745 +       if (btrfs_test_opt(tree_root, TAGGED))
1746 +               sb->s_flags |= MS_TAGGED;
1747 +
1748         features = btrfs_super_incompat_flags(disk_super) &
1749                 ~BTRFS_FEATURE_INCOMPAT_SUPP;
1750         if (features) {
1751 diff -NurpP --minimal linux-3.9.4/fs/btrfs/inode.c linux-3.9.4-vs2.3.6.1/fs/btrfs/inode.c
1752 --- linux-3.9.4/fs/btrfs/inode.c        2013-05-31 14:22:27.000000000 +0000
1753 +++ linux-3.9.4-vs2.3.6.1/fs/btrfs/inode.c      2013-05-31 20:42:33.000000000 +0000
1754 @@ -41,6 +41,7 @@
1755  #include <linux/mount.h>
1756  #include <linux/btrfs.h>
1757  #include <linux/blkdev.h>
1758 +#include <linux/vs_tag.h>
1759  #include "compat.h"
1760  #include "ctree.h"
1761  #include "disk-io.h"
1762 @@ -3312,6 +3313,8 @@ static void btrfs_read_locked_inode(stru
1763         struct btrfs_key location;
1764         int maybe_acls;
1765         u32 rdev;
1766 +       uid_t uid;
1767 +       gid_t gid;
1768         int ret;
1769         bool filled = false;
1770  
1771 @@ -3339,8 +3342,13 @@ static void btrfs_read_locked_inode(stru
1772                                     struct btrfs_inode_item);
1773         inode->i_mode = btrfs_inode_mode(leaf, inode_item);
1774         set_nlink(inode, btrfs_inode_nlink(leaf, inode_item));
1775 -       i_uid_write(inode, btrfs_inode_uid(leaf, inode_item));
1776 -       i_gid_write(inode, btrfs_inode_gid(leaf, inode_item));
1777 +
1778 +       uid = btrfs_inode_uid(leaf, inode_item);
1779 +       gid = btrfs_inode_gid(leaf, inode_item);
1780 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), uid, gid));
1781 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), uid, gid));
1782 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), uid, gid,
1783 +               btrfs_inode_tag(leaf, inode_item)));
1784         btrfs_i_size_write(inode, btrfs_inode_size(leaf, inode_item));
1785  
1786         tspec = btrfs_inode_atime(inode_item);
1787 @@ -3431,11 +3439,18 @@ static void fill_inode_item(struct btrfs
1788                             struct inode *inode)
1789  {
1790         struct btrfs_map_token token;
1791 +       uid_t uid = TAGINO_UID(DX_TAG(inode),
1792 +               i_uid_read(inode), i_tag_read(inode));
1793 +       gid_t gid = TAGINO_GID(DX_TAG(inode),
1794 +               i_gid_read(inode), i_tag_read(inode));
1795  
1796         btrfs_init_map_token(&token);
1797  
1798 -       btrfs_set_token_inode_uid(leaf, item, i_uid_read(inode), &token);
1799 -       btrfs_set_token_inode_gid(leaf, item, i_gid_read(inode), &token);
1800 +       btrfs_set_token_inode_uid(leaf, item, uid, &token);
1801 +       btrfs_set_token_inode_gid(leaf, item, gid, &token);
1802 +#ifdef CONFIG_TAGGING_INTERN
1803 +       btrfs_set_token_inode_tag(leaf, item, i_tag_read(inode), &token);
1804 +#endif
1805         btrfs_set_token_inode_size(leaf, item, BTRFS_I(inode)->disk_i_size,
1806                                    &token);
1807         btrfs_set_token_inode_mode(leaf, item, inode->i_mode, &token);
1808 @@ -8683,11 +8698,13 @@ static const struct inode_operations btr
1809         .listxattr      = btrfs_listxattr,
1810         .removexattr    = btrfs_removexattr,
1811         .permission     = btrfs_permission,
1812 +       .sync_flags     = btrfs_sync_flags,
1813         .get_acl        = btrfs_get_acl,
1814  };
1815  static const struct inode_operations btrfs_dir_ro_inode_operations = {
1816         .lookup         = btrfs_lookup,
1817         .permission     = btrfs_permission,
1818 +       .sync_flags     = btrfs_sync_flags,
1819         .get_acl        = btrfs_get_acl,
1820  };
1821  
1822 diff -NurpP --minimal linux-3.9.4/fs/btrfs/ioctl.c linux-3.9.4-vs2.3.6.1/fs/btrfs/ioctl.c
1823 --- linux-3.9.4/fs/btrfs/ioctl.c        2013-05-31 14:22:27.000000000 +0000
1824 +++ linux-3.9.4-vs2.3.6.1/fs/btrfs/ioctl.c      2013-05-31 14:47:11.000000000 +0000
1825 @@ -75,10 +75,13 @@ static unsigned int btrfs_flags_to_ioctl
1826  {
1827         unsigned int iflags = 0;
1828  
1829 -       if (flags & BTRFS_INODE_SYNC)
1830 -               iflags |= FS_SYNC_FL;
1831         if (flags & BTRFS_INODE_IMMUTABLE)
1832                 iflags |= FS_IMMUTABLE_FL;
1833 +       if (flags & BTRFS_INODE_IXUNLINK)
1834 +               iflags |= FS_IXUNLINK_FL;
1835 +
1836 +       if (flags & BTRFS_INODE_SYNC)
1837 +               iflags |= FS_SYNC_FL;
1838         if (flags & BTRFS_INODE_APPEND)
1839                 iflags |= FS_APPEND_FL;
1840         if (flags & BTRFS_INODE_NODUMP)
1841 @@ -95,28 +98,78 @@ static unsigned int btrfs_flags_to_ioctl
1842         else if (flags & BTRFS_INODE_NOCOMPRESS)
1843                 iflags |= FS_NOCOMP_FL;
1844  
1845 +       if (flags & BTRFS_INODE_BARRIER)
1846 +               iflags |= FS_BARRIER_FL;
1847 +       if (flags & BTRFS_INODE_COW)
1848 +               iflags |= FS_COW_FL;
1849         return iflags;
1850  }
1851  
1852  /*
1853 - * Update inode->i_flags based on the btrfs internal flags.
1854 + * Update inode->i_(v)flags based on the btrfs internal flags.
1855   */
1856  void btrfs_update_iflags(struct inode *inode)
1857  {
1858         struct btrfs_inode *ip = BTRFS_I(inode);
1859  
1860 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
1861 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
1862 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
1863  
1864 -       if (ip->flags & BTRFS_INODE_SYNC)
1865 -               inode->i_flags |= S_SYNC;
1866         if (ip->flags & BTRFS_INODE_IMMUTABLE)
1867                 inode->i_flags |= S_IMMUTABLE;
1868 +       if (ip->flags & BTRFS_INODE_IXUNLINK)
1869 +               inode->i_flags |= S_IXUNLINK;
1870 +
1871 +       if (ip->flags & BTRFS_INODE_SYNC)
1872 +               inode->i_flags |= S_SYNC;
1873         if (ip->flags & BTRFS_INODE_APPEND)
1874                 inode->i_flags |= S_APPEND;
1875         if (ip->flags & BTRFS_INODE_NOATIME)
1876                 inode->i_flags |= S_NOATIME;
1877         if (ip->flags & BTRFS_INODE_DIRSYNC)
1878                 inode->i_flags |= S_DIRSYNC;
1879 +
1880 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
1881 +
1882 +       if (ip->flags & BTRFS_INODE_BARRIER)
1883 +               inode->i_vflags |= V_BARRIER;
1884 +       if (ip->flags & BTRFS_INODE_COW)
1885 +               inode->i_vflags |= V_COW;
1886 +}
1887 +
1888 +/*
1889 + * Update btrfs internal flags from inode->i_(v)flags.
1890 + */
1891 +void btrfs_update_flags(struct inode *inode)
1892 +{
1893 +       struct btrfs_inode *ip = BTRFS_I(inode);
1894 +
1895 +       unsigned int flags = inode->i_flags;
1896 +       unsigned int vflags = inode->i_vflags;
1897 +
1898 +       ip->flags &= ~(BTRFS_INODE_SYNC | BTRFS_INODE_APPEND |
1899 +                       BTRFS_INODE_IMMUTABLE | BTRFS_INODE_IXUNLINK |
1900 +                       BTRFS_INODE_NOATIME | BTRFS_INODE_DIRSYNC |
1901 +                       BTRFS_INODE_BARRIER | BTRFS_INODE_COW);
1902 +
1903 +       if (flags & S_IMMUTABLE)
1904 +               ip->flags |= BTRFS_INODE_IMMUTABLE;
1905 +       if (flags & S_IXUNLINK)
1906 +               ip->flags |= BTRFS_INODE_IXUNLINK;
1907 +
1908 +       if (flags & S_SYNC)
1909 +               ip->flags |= BTRFS_INODE_SYNC;
1910 +       if (flags & S_APPEND)
1911 +               ip->flags |= BTRFS_INODE_APPEND;
1912 +       if (flags & S_NOATIME)
1913 +               ip->flags |= BTRFS_INODE_NOATIME;
1914 +       if (flags & S_DIRSYNC)
1915 +               ip->flags |= BTRFS_INODE_DIRSYNC;
1916 +
1917 +       if (vflags & V_BARRIER)
1918 +               ip->flags |= BTRFS_INODE_BARRIER;
1919 +       if (vflags & V_COW)
1920 +               ip->flags |= BTRFS_INODE_COW;
1921  }
1922  
1923  /*
1924 @@ -132,6 +185,7 @@ void btrfs_inherit_iflags(struct inode *
1925                 return;
1926  
1927         flags = BTRFS_I(dir)->flags;
1928 +       flags &= ~BTRFS_INODE_BARRIER;
1929  
1930         if (flags & BTRFS_INODE_NOCOMPRESS) {
1931                 BTRFS_I(inode)->flags &= ~BTRFS_INODE_COMPRESS;
1932 @@ -150,6 +204,30 @@ void btrfs_inherit_iflags(struct inode *
1933         btrfs_update_iflags(inode);
1934  }
1935  
1936 +int btrfs_sync_flags(struct inode *inode, int flags, int vflags)
1937 +{
1938 +       struct btrfs_inode *ip = BTRFS_I(inode);
1939 +       struct btrfs_root *root = ip->root;
1940 +       struct btrfs_trans_handle *trans;
1941 +       int ret;
1942 +
1943 +       trans = btrfs_join_transaction(root);
1944 +       BUG_ON(!trans);
1945 +
1946 +       inode->i_flags = flags;
1947 +       inode->i_vflags = vflags;
1948 +       btrfs_update_flags(inode);
1949 +
1950 +       ret = btrfs_update_inode(trans, root, inode);
1951 +       BUG_ON(ret);
1952 +
1953 +       btrfs_update_iflags(inode);
1954 +       inode->i_ctime = CURRENT_TIME;
1955 +       btrfs_end_transaction(trans, root);
1956 +
1957 +       return 0;
1958 +}
1959 +
1960  static int btrfs_ioctl_getflags(struct file *file, void __user *arg)
1961  {
1962         struct btrfs_inode *ip = BTRFS_I(file_inode(file));
1963 @@ -212,21 +290,27 @@ static int btrfs_ioctl_setflags(struct f
1964  
1965         flags = btrfs_mask_flags(inode->i_mode, flags);
1966         oldflags = btrfs_flags_to_ioctl(ip->flags);
1967 -       if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) {
1968 +       if ((flags ^ oldflags) & (FS_APPEND_FL |
1969 +               FS_IMMUTABLE_FL | FS_IXUNLINK_FL)) {
1970                 if (!capable(CAP_LINUX_IMMUTABLE)) {
1971                         ret = -EPERM;
1972                         goto out_unlock;
1973                 }
1974         }
1975  
1976 -       if (flags & FS_SYNC_FL)
1977 -               ip->flags |= BTRFS_INODE_SYNC;
1978 -       else
1979 -               ip->flags &= ~BTRFS_INODE_SYNC;
1980         if (flags & FS_IMMUTABLE_FL)
1981                 ip->flags |= BTRFS_INODE_IMMUTABLE;
1982         else
1983                 ip->flags &= ~BTRFS_INODE_IMMUTABLE;
1984 +       if (flags & FS_IXUNLINK_FL)
1985 +               ip->flags |= BTRFS_INODE_IXUNLINK;
1986 +       else
1987 +               ip->flags &= ~BTRFS_INODE_IXUNLINK;
1988 +
1989 +       if (flags & FS_SYNC_FL)
1990 +               ip->flags |= BTRFS_INODE_SYNC;
1991 +       else
1992 +               ip->flags &= ~BTRFS_INODE_SYNC;
1993         if (flags & FS_APPEND_FL)
1994                 ip->flags |= BTRFS_INODE_APPEND;
1995         else
1996 diff -NurpP --minimal linux-3.9.4/fs/btrfs/super.c linux-3.9.4-vs2.3.6.1/fs/btrfs/super.c
1997 --- linux-3.9.4/fs/btrfs/super.c        2013-05-31 13:45:22.000000000 +0000
1998 +++ linux-3.9.4-vs2.3.6.1/fs/btrfs/super.c      2013-05-31 14:47:11.000000000 +0000
1999 @@ -321,7 +321,7 @@ enum {
2000         Opt_no_space_cache, Opt_recovery, Opt_skip_balance,
2001         Opt_check_integrity, Opt_check_integrity_including_extent_data,
2002         Opt_check_integrity_print_mask, Opt_fatal_errors,
2003 -       Opt_err,
2004 +       Opt_tag, Opt_notag, Opt_tagid, Opt_err,
2005  };
2006  
2007  static match_table_t tokens = {
2008 @@ -361,6 +361,9 @@ static match_table_t tokens = {
2009         {Opt_check_integrity_including_extent_data, "check_int_data"},
2010         {Opt_check_integrity_print_mask, "check_int_print_mask=%d"},
2011         {Opt_fatal_errors, "fatal_errors=%s"},
2012 +       {Opt_tag, "tag"},
2013 +       {Opt_notag, "notag"},
2014 +       {Opt_tagid, "tagid=%u"},
2015         {Opt_err, NULL},
2016  };
2017  
2018 @@ -626,6 +629,22 @@ int btrfs_parse_options(struct btrfs_roo
2019                                 goto out;
2020                         }
2021                         break;
2022 +#ifndef CONFIG_TAGGING_NONE
2023 +               case Opt_tag:
2024 +                       printk(KERN_INFO "btrfs: use tagging\n");
2025 +                       btrfs_set_opt(info->mount_opt, TAGGED);
2026 +                       break;
2027 +               case Opt_notag:
2028 +                       printk(KERN_INFO "btrfs: disabled tagging\n");
2029 +                       btrfs_clear_opt(info->mount_opt, TAGGED);
2030 +                       break;
2031 +#endif
2032 +#ifdef CONFIG_PROPAGATE
2033 +               case Opt_tagid:
2034 +                       /* use args[0] */
2035 +                       btrfs_set_opt(info->mount_opt, TAGGED);
2036 +                       break;
2037 +#endif
2038                 case Opt_err:
2039                         printk(KERN_INFO "btrfs: unrecognized mount option "
2040                                "'%s'\n", p);
2041 @@ -1258,6 +1277,12 @@ static int btrfs_remount(struct super_bl
2042         btrfs_resize_thread_pool(fs_info,
2043                 fs_info->thread_pool_size, old_thread_pool_size);
2044  
2045 +       if (btrfs_test_opt(root, TAGGED) && !(sb->s_flags & MS_TAGGED)) {
2046 +               printk("btrfs: %s: tagging not permitted on remount.\n",
2047 +                       sb->s_id);
2048 +               return -EINVAL;
2049 +       }
2050 +
2051         if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
2052                 goto out;
2053  
2054 diff -NurpP --minimal linux-3.9.4/fs/char_dev.c linux-3.9.4-vs2.3.6.1/fs/char_dev.c
2055 --- linux-3.9.4/fs/char_dev.c   2012-12-11 03:30:57.000000000 +0000
2056 +++ linux-3.9.4-vs2.3.6.1/fs/char_dev.c 2013-05-31 14:47:11.000000000 +0000
2057 @@ -21,6 +21,8 @@
2058  #include <linux/mutex.h>
2059  #include <linux/backing-dev.h>
2060  #include <linux/tty.h>
2061 +#include <linux/vs_context.h>
2062 +#include <linux/vs_device.h>
2063  
2064  #include "internal.h"
2065  
2066 @@ -371,14 +373,21 @@ static int chrdev_open(struct inode *ino
2067         struct cdev *p;
2068         struct cdev *new = NULL;
2069         int ret = 0;
2070 +       dev_t mdev;
2071 +
2072 +       if (!vs_map_chrdev(inode->i_rdev, &mdev, DATTR_OPEN))
2073 +               return -EPERM;
2074 +       inode->i_mdev = mdev;
2075  
2076         spin_lock(&cdev_lock);
2077         p = inode->i_cdev;
2078         if (!p) {
2079                 struct kobject *kobj;
2080                 int idx;
2081 +
2082                 spin_unlock(&cdev_lock);
2083 -               kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
2084 +
2085 +               kobj = kobj_lookup(cdev_map, mdev, &idx);
2086                 if (!kobj)
2087                         return -ENXIO;
2088                 new = container_of(kobj, struct cdev, kobj);
2089 diff -NurpP --minimal linux-3.9.4/fs/dcache.c linux-3.9.4-vs2.3.6.1/fs/dcache.c
2090 --- linux-3.9.4/fs/dcache.c     2013-05-31 14:22:27.000000000 +0000
2091 +++ linux-3.9.4-vs2.3.6.1/fs/dcache.c   2013-05-31 14:47:11.000000000 +0000
2092 @@ -37,6 +37,7 @@
2093  #include <linux/rculist_bl.h>
2094  #include <linux/prefetch.h>
2095  #include <linux/ratelimit.h>
2096 +#include <linux/vs_limit.h>
2097  #include "internal.h"
2098  #include "mount.h"
2099  
2100 @@ -593,6 +594,8 @@ int d_invalidate(struct dentry * dentry)
2101                 spin_lock(&dentry->d_lock);
2102         }
2103  
2104 +       vx_dentry_dec(dentry);
2105 +
2106         /*
2107          * Somebody else still using it?
2108          *
2109 @@ -622,6 +625,7 @@ EXPORT_SYMBOL(d_invalidate);
2110  static inline void __dget_dlock(struct dentry *dentry)
2111  {
2112         dentry->d_count++;
2113 +       vx_dentry_inc(dentry);
2114  }
2115  
2116  static inline void __dget(struct dentry *dentry)
2117 @@ -1252,6 +1256,9 @@ struct dentry *__d_alloc(struct super_bl
2118         struct dentry *dentry;
2119         char *dname;
2120  
2121 +       if (!vx_dentry_avail(1))
2122 +               return NULL;
2123 +
2124         dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
2125         if (!dentry)
2126                 return NULL;
2127 @@ -1284,6 +1291,7 @@ struct dentry *__d_alloc(struct super_bl
2128  
2129         dentry->d_count = 1;
2130         dentry->d_flags = 0;
2131 +       vx_dentry_inc(dentry);
2132         spin_lock_init(&dentry->d_lock);
2133         seqcount_init(&dentry->d_seq);
2134         dentry->d_inode = NULL;
2135 @@ -1984,6 +1992,7 @@ struct dentry *__d_lookup(const struct d
2136                 }
2137  
2138                 dentry->d_count++;
2139 +               vx_dentry_inc(dentry);
2140                 found = dentry;
2141                 spin_unlock(&dentry->d_lock);
2142                 break;
2143 diff -NurpP --minimal linux-3.9.4/fs/devpts/inode.c linux-3.9.4-vs2.3.6.1/fs/devpts/inode.c
2144 --- linux-3.9.4/fs/devpts/inode.c       2013-05-31 13:45:23.000000000 +0000
2145 +++ linux-3.9.4-vs2.3.6.1/fs/devpts/inode.c     2013-05-31 15:42:25.000000000 +0000
2146 @@ -25,6 +25,7 @@
2147  #include <linux/parser.h>
2148  #include <linux/fsnotify.h>
2149  #include <linux/seq_file.h>
2150 +#include <linux/vs_base.h>
2151  
2152  #define DEVPTS_DEFAULT_MODE 0600
2153  /*
2154 @@ -36,6 +37,21 @@
2155  #define DEVPTS_DEFAULT_PTMX_MODE 0000
2156  #define PTMX_MINOR     2
2157  
2158 +static int devpts_permission(struct inode *inode, int mask)
2159 +{
2160 +       int ret = -EACCES;
2161 +
2162 +       /* devpts is xid tagged */
2163 +       if (vx_check((xid_t)i_tag_read(inode), VS_WATCH_P | VS_IDENT))
2164 +               ret = generic_permission(inode, mask);
2165 +       return ret;
2166 +}
2167 +
2168 +static struct inode_operations devpts_file_inode_operations = {
2169 +       .permission     = devpts_permission,
2170 +};
2171 +
2172 +
2173  /*
2174   * sysctl support for setting limits on the number of Unix98 ptys allocated.
2175   * Otherwise one can eat up all kernel memory by opening /dev/ptmx repeatedly.
2176 @@ -345,6 +361,34 @@ static int devpts_show_options(struct se
2177         return 0;
2178  }
2179  
2180 +static int devpts_filter(struct dentry *de)
2181 +{
2182 +       xid_t xid = 0;
2183 +
2184 +       /* devpts is xid tagged */
2185 +       if (de && de->d_inode)
2186 +               xid = (xid_t)i_tag_read(de->d_inode);
2187 +#ifdef CONFIG_VSERVER_WARN_DEVPTS
2188 +       else
2189 +               vxwprintk_task(1, "devpts " VS_Q("%.*s") " without inode.",
2190 +                       de->d_name.len, de->d_name.name);
2191 +#endif
2192 +       return vx_check(xid, VS_WATCH_P | VS_IDENT);
2193 +}
2194 +
2195 +static int devpts_readdir(struct file * filp, void * dirent, filldir_t filldir)
2196 +{
2197 +       return dcache_readdir_filter(filp, dirent, filldir, devpts_filter);
2198 +}
2199 +
2200 +static struct file_operations devpts_dir_operations = {
2201 +       .open           = dcache_dir_open,
2202 +       .release        = dcache_dir_close,
2203 +       .llseek         = dcache_dir_lseek,
2204 +       .read           = generic_read_dir,
2205 +       .readdir        = devpts_readdir,
2206 +};
2207 +
2208  static const struct super_operations devpts_sops = {
2209         .statfs         = simple_statfs,
2210         .remount_fs     = devpts_remount,
2211 @@ -388,8 +432,10 @@ devpts_fill_super(struct super_block *s,
2212         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2213         inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
2214         inode->i_op = &simple_dir_inode_operations;
2215 -       inode->i_fop = &simple_dir_operations;
2216 +       inode->i_fop = &devpts_dir_operations;
2217         set_nlink(inode, 2);
2218 +       /* devpts is xid tagged */
2219 +       i_tag_write(inode, (tag_t)vx_current_xid());
2220  
2221         s->s_root = d_make_root(inode);
2222         if (s->s_root)
2223 @@ -592,6 +638,9 @@ struct inode *devpts_pty_new(struct inod
2224         inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
2225         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2226         init_special_inode(inode, S_IFCHR|opts->mode, device);
2227 +       /* devpts is xid tagged */
2228 +       i_tag_write(inode, (tag_t)vx_current_xid());
2229 +       inode->i_op = &devpts_file_inode_operations;
2230         inode->i_private = priv;
2231  
2232         sprintf(s, "%d", index);
2233 diff -NurpP --minimal linux-3.9.4/fs/ext2/balloc.c linux-3.9.4-vs2.3.6.1/fs/ext2/balloc.c
2234 --- linux-3.9.4/fs/ext2/balloc.c        2013-05-31 13:45:23.000000000 +0000
2235 +++ linux-3.9.4-vs2.3.6.1/fs/ext2/balloc.c      2013-05-31 14:47:11.000000000 +0000
2236 @@ -693,7 +693,6 @@ ext2_try_to_allocate(struct super_block
2237                         start = 0;
2238                 end = EXT2_BLOCKS_PER_GROUP(sb);
2239         }
2240 -
2241         BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
2242  
2243  repeat:
2244 diff -NurpP --minimal linux-3.9.4/fs/ext2/ext2.h linux-3.9.4-vs2.3.6.1/fs/ext2/ext2.h
2245 --- linux-3.9.4/fs/ext2/ext2.h  2012-12-11 03:30:57.000000000 +0000
2246 +++ linux-3.9.4-vs2.3.6.1/fs/ext2/ext2.h        2013-05-31 14:47:11.000000000 +0000
2247 @@ -244,8 +244,12 @@ struct ext2_group_desc
2248  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
2249  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
2250  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
2251 +#define EXT2_IXUNLINK_FL               FS_IXUNLINK_FL  /* Immutable invert on unlink */
2252  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
2253  
2254 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
2255 +#define EXT2_COW_FL                    FS_COW_FL       /* Copy on Write marker */
2256 +
2257  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
2258  #define EXT2_FL_USER_MODIFIABLE                FS_FL_USER_MODIFIABLE   /* User modifiable flags */
2259  
2260 @@ -329,7 +333,8 @@ struct ext2_inode {
2261                         __u16   i_pad1;
2262                         __le16  l_i_uid_high;   /* these 2 fields    */
2263                         __le16  l_i_gid_high;   /* were reserved2[0] */
2264 -                       __u32   l_i_reserved2;
2265 +                       __le16  l_i_tag;        /* Context Tag */
2266 +                       __u16   l_i_reserved2;
2267                 } linux2;
2268                 struct {
2269                         __u8    h_i_frag;       /* Fragment number */
2270 @@ -357,6 +362,7 @@ struct ext2_inode {
2271  #define i_gid_low      i_gid
2272  #define i_uid_high     osd2.linux2.l_i_uid_high
2273  #define i_gid_high     osd2.linux2.l_i_gid_high
2274 +#define i_raw_tag      osd2.linux2.l_i_tag
2275  #define i_reserved2    osd2.linux2.l_i_reserved2
2276  
2277  /*
2278 @@ -384,6 +390,7 @@ struct ext2_inode {
2279  #define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
2280  #define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
2281  #define EXT2_MOUNT_RESERVATION         0x080000  /* Preallocation */
2282 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
2283  
2284  
2285  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
2286 @@ -757,6 +764,7 @@ extern void ext2_set_inode_flags(struct
2287  extern void ext2_get_inode_flags(struct ext2_inode_info *);
2288  extern int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2289                        u64 start, u64 len);
2290 +extern int ext2_sync_flags(struct inode *, int, int);
2291  
2292  /* ioctl.c */
2293  extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
2294 diff -NurpP --minimal linux-3.9.4/fs/ext2/file.c linux-3.9.4-vs2.3.6.1/fs/ext2/file.c
2295 --- linux-3.9.4/fs/ext2/file.c  2012-12-11 03:30:57.000000000 +0000
2296 +++ linux-3.9.4-vs2.3.6.1/fs/ext2/file.c        2013-05-31 14:47:11.000000000 +0000
2297 @@ -104,4 +104,5 @@ const struct inode_operations ext2_file_
2298         .setattr        = ext2_setattr,
2299         .get_acl        = ext2_get_acl,
2300         .fiemap         = ext2_fiemap,
2301 +       .sync_flags     = ext2_sync_flags,
2302  };
2303 diff -NurpP --minimal linux-3.9.4/fs/ext2/ialloc.c linux-3.9.4-vs2.3.6.1/fs/ext2/ialloc.c
2304 --- linux-3.9.4/fs/ext2/ialloc.c        2013-05-31 13:45:23.000000000 +0000
2305 +++ linux-3.9.4-vs2.3.6.1/fs/ext2/ialloc.c      2013-05-31 14:47:11.000000000 +0000
2306 @@ -17,6 +17,7 @@
2307  #include <linux/backing-dev.h>
2308  #include <linux/buffer_head.h>
2309  #include <linux/random.h>
2310 +#include <linux/vs_tag.h>
2311  #include "ext2.h"
2312  #include "xattr.h"
2313  #include "acl.h"
2314 @@ -546,6 +547,7 @@ got:
2315                 inode->i_mode = mode;
2316                 inode->i_uid = current_fsuid();
2317                 inode->i_gid = dir->i_gid;
2318 +               inode->i_tag = dx_current_fstag(sb);
2319         } else
2320                 inode_init_owner(inode, dir, mode);
2321  
2322 diff -NurpP --minimal linux-3.9.4/fs/ext2/inode.c linux-3.9.4-vs2.3.6.1/fs/ext2/inode.c
2323 --- linux-3.9.4/fs/ext2/inode.c 2013-05-31 13:45:23.000000000 +0000
2324 +++ linux-3.9.4-vs2.3.6.1/fs/ext2/inode.c       2013-05-31 14:47:11.000000000 +0000
2325 @@ -31,6 +31,7 @@
2326  #include <linux/mpage.h>
2327  #include <linux/fiemap.h>
2328  #include <linux/namei.h>
2329 +#include <linux/vs_tag.h>
2330  #include "ext2.h"
2331  #include "acl.h"
2332  #include "xip.h"
2333 @@ -1179,7 +1180,7 @@ static void ext2_truncate_blocks(struct
2334                 return;
2335         if (ext2_inode_is_fast_symlink(inode))
2336                 return;
2337 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2338 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2339                 return;
2340         __ext2_truncate_blocks(inode, offset);
2341  }
2342 @@ -1270,36 +1271,61 @@ void ext2_set_inode_flags(struct inode *
2343  {
2344         unsigned int flags = EXT2_I(inode)->i_flags;
2345  
2346 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2347 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2348 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2349 +
2350 +
2351 +       if (flags & EXT2_IMMUTABLE_FL)
2352 +               inode->i_flags |= S_IMMUTABLE;
2353 +       if (flags & EXT2_IXUNLINK_FL)
2354 +               inode->i_flags |= S_IXUNLINK;
2355 +
2356         if (flags & EXT2_SYNC_FL)
2357                 inode->i_flags |= S_SYNC;
2358         if (flags & EXT2_APPEND_FL)
2359                 inode->i_flags |= S_APPEND;
2360 -       if (flags & EXT2_IMMUTABLE_FL)
2361 -               inode->i_flags |= S_IMMUTABLE;
2362         if (flags & EXT2_NOATIME_FL)
2363                 inode->i_flags |= S_NOATIME;
2364         if (flags & EXT2_DIRSYNC_FL)
2365                 inode->i_flags |= S_DIRSYNC;
2366 +
2367 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2368 +
2369 +       if (flags & EXT2_BARRIER_FL)
2370 +               inode->i_vflags |= V_BARRIER;
2371 +       if (flags & EXT2_COW_FL)
2372 +               inode->i_vflags |= V_COW;
2373  }
2374  
2375  /* Propagate flags from i_flags to EXT2_I(inode)->i_flags */
2376  void ext2_get_inode_flags(struct ext2_inode_info *ei)
2377  {
2378         unsigned int flags = ei->vfs_inode.i_flags;
2379 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2380 +
2381 +       ei->i_flags &= ~(EXT2_SYNC_FL | EXT2_APPEND_FL |
2382 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL |
2383 +                       EXT2_NOATIME_FL | EXT2_DIRSYNC_FL |
2384 +                       EXT2_BARRIER_FL | EXT2_COW_FL);
2385 +
2386 +       if (flags & S_IMMUTABLE)
2387 +               ei->i_flags |= EXT2_IMMUTABLE_FL;
2388 +       if (flags & S_IXUNLINK)
2389 +               ei->i_flags |= EXT2_IXUNLINK_FL;
2390  
2391 -       ei->i_flags &= ~(EXT2_SYNC_FL|EXT2_APPEND_FL|
2392 -                       EXT2_IMMUTABLE_FL|EXT2_NOATIME_FL|EXT2_DIRSYNC_FL);
2393         if (flags & S_SYNC)
2394                 ei->i_flags |= EXT2_SYNC_FL;
2395         if (flags & S_APPEND)
2396                 ei->i_flags |= EXT2_APPEND_FL;
2397 -       if (flags & S_IMMUTABLE)
2398 -               ei->i_flags |= EXT2_IMMUTABLE_FL;
2399         if (flags & S_NOATIME)
2400                 ei->i_flags |= EXT2_NOATIME_FL;
2401         if (flags & S_DIRSYNC)
2402                 ei->i_flags |= EXT2_DIRSYNC_FL;
2403 +
2404 +       if (vflags & V_BARRIER)
2405 +               ei->i_flags |= EXT2_BARRIER_FL;
2406 +       if (vflags & V_COW)
2407 +               ei->i_flags |= EXT2_COW_FL;
2408  }
2409  
2410  struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
2411 @@ -1335,8 +1361,10 @@ struct inode *ext2_iget (struct super_bl
2412                 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2413                 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2414         }
2415 -       i_uid_write(inode, i_uid);
2416 -       i_gid_write(inode, i_gid);
2417 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
2418 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
2419 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
2420 +               le16_to_cpu(raw_inode->i_raw_tag)));
2421         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2422         inode->i_size = le32_to_cpu(raw_inode->i_size);
2423         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2424 @@ -1434,8 +1462,10 @@ static int __ext2_write_inode(struct ino
2425         struct ext2_inode_info *ei = EXT2_I(inode);
2426         struct super_block *sb = inode->i_sb;
2427         ino_t ino = inode->i_ino;
2428 -       uid_t uid = i_uid_read(inode);
2429 -       gid_t gid = i_gid_read(inode);
2430 +       uid_t uid = TAGINO_UID(DX_TAG(inode),
2431 +               i_uid_read(inode), i_tag_read(inode));
2432 +       gid_t gid = TAGINO_GID(DX_TAG(inode),
2433 +               i_gid_read(inode), i_tag_read(inode));
2434         struct buffer_head * bh;
2435         struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2436         int n;
2437 @@ -1471,6 +1501,9 @@ static int __ext2_write_inode(struct ino
2438                 raw_inode->i_uid_high = 0;
2439                 raw_inode->i_gid_high = 0;
2440         }
2441 +#ifdef CONFIG_TAGGING_INTERN
2442 +       raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
2443 +#endif
2444         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2445         raw_inode->i_size = cpu_to_le32(inode->i_size);
2446         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2447 @@ -1551,7 +1584,8 @@ int ext2_setattr(struct dentry *dentry,
2448         if (is_quota_modification(inode, iattr))
2449                 dquot_initialize(inode);
2450         if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
2451 -           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
2452 +           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid)) ||
2453 +           (iattr->ia_valid & ATTR_TAG && !tag_eq(iattr->ia_tag, inode->i_tag))) {
2454                 error = dquot_transfer(inode, iattr);
2455                 if (error)
2456                         return error;
2457 diff -NurpP --minimal linux-3.9.4/fs/ext2/ioctl.c linux-3.9.4-vs2.3.6.1/fs/ext2/ioctl.c
2458 --- linux-3.9.4/fs/ext2/ioctl.c 2013-05-31 13:45:23.000000000 +0000
2459 +++ linux-3.9.4-vs2.3.6.1/fs/ext2/ioctl.c       2013-05-31 14:47:11.000000000 +0000
2460 @@ -17,6 +17,16 @@
2461  #include <asm/uaccess.h>
2462  
2463  
2464 +int ext2_sync_flags(struct inode *inode, int flags, int vflags)
2465 +{
2466 +       inode->i_flags = flags;
2467 +       inode->i_vflags = vflags;
2468 +       ext2_get_inode_flags(EXT2_I(inode));
2469 +       inode->i_ctime = CURRENT_TIME_SEC;
2470 +       mark_inode_dirty(inode);
2471 +       return 0;
2472 +}
2473 +
2474  long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2475  {
2476         struct inode *inode = file_inode(filp);
2477 @@ -51,6 +61,11 @@ long ext2_ioctl(struct file *filp, unsig
2478  
2479                 flags = ext2_mask_flags(inode->i_mode, flags);
2480  
2481 +               if (IS_BARRIER(inode)) {
2482 +                       vxwprintk_task(1, "messing with the barrier.");
2483 +                       return -EACCES;
2484 +               }
2485 +
2486                 mutex_lock(&inode->i_mutex);
2487                 /* Is it quota file? Do not allow user to mess with it */
2488                 if (IS_NOQUOTA(inode)) {
2489 @@ -66,7 +81,9 @@ long ext2_ioctl(struct file *filp, unsig
2490                  *
2491                  * This test looks nicer. Thanks to Pauline Middelink
2492                  */
2493 -               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
2494 +               if ((oldflags & EXT2_IMMUTABLE_FL) ||
2495 +                       ((flags ^ oldflags) & (EXT2_APPEND_FL |
2496 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
2497                         if (!capable(CAP_LINUX_IMMUTABLE)) {
2498                                 mutex_unlock(&inode->i_mutex);
2499                                 ret = -EPERM;
2500 @@ -74,7 +91,7 @@ long ext2_ioctl(struct file *filp, unsig
2501                         }
2502                 }
2503  
2504 -               flags = flags & EXT2_FL_USER_MODIFIABLE;
2505 +               flags &= EXT2_FL_USER_MODIFIABLE;
2506                 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
2507                 ei->i_flags = flags;
2508  
2509 diff -NurpP --minimal linux-3.9.4/fs/ext2/namei.c linux-3.9.4-vs2.3.6.1/fs/ext2/namei.c
2510 --- linux-3.9.4/fs/ext2/namei.c 2012-12-11 03:30:57.000000000 +0000
2511 +++ linux-3.9.4-vs2.3.6.1/fs/ext2/namei.c       2013-05-31 14:47:11.000000000 +0000
2512 @@ -32,6 +32,7 @@
2513  
2514  #include <linux/pagemap.h>
2515  #include <linux/quotaops.h>
2516 +#include <linux/vs_tag.h>
2517  #include "ext2.h"
2518  #include "xattr.h"
2519  #include "acl.h"
2520 @@ -73,6 +74,7 @@ static struct dentry *ext2_lookup(struct
2521                                         (unsigned long) ino);
2522                         return ERR_PTR(-EIO);
2523                 }
2524 +               dx_propagate_tag(nd, inode);
2525         }
2526         return d_splice_alias(inode, dentry);
2527  }
2528 @@ -397,6 +399,7 @@ const struct inode_operations ext2_dir_i
2529         .removexattr    = generic_removexattr,
2530  #endif
2531         .setattr        = ext2_setattr,
2532 +       .sync_flags     = ext2_sync_flags,
2533         .get_acl        = ext2_get_acl,
2534  };
2535  
2536 diff -NurpP --minimal linux-3.9.4/fs/ext2/super.c linux-3.9.4-vs2.3.6.1/fs/ext2/super.c
2537 --- linux-3.9.4/fs/ext2/super.c 2013-05-31 13:45:23.000000000 +0000
2538 +++ linux-3.9.4-vs2.3.6.1/fs/ext2/super.c       2013-05-31 14:47:11.000000000 +0000
2539 @@ -395,7 +395,8 @@ enum {
2540         Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
2541         Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
2542         Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
2543 -       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
2544 +       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
2545 +       Opt_tag, Opt_notag, Opt_tagid
2546  };
2547  
2548  static const match_table_t tokens = {
2549 @@ -423,6 +424,9 @@ static const match_table_t tokens = {
2550         {Opt_acl, "acl"},
2551         {Opt_noacl, "noacl"},
2552         {Opt_xip, "xip"},
2553 +       {Opt_tag, "tag"},
2554 +       {Opt_notag, "notag"},
2555 +       {Opt_tagid, "tagid=%u"},
2556         {Opt_grpquota, "grpquota"},
2557         {Opt_ignore, "noquota"},
2558         {Opt_quota, "quota"},
2559 @@ -506,6 +510,20 @@ static int parse_options(char *options,
2560                 case Opt_nouid32:
2561                         set_opt (sbi->s_mount_opt, NO_UID32);
2562                         break;
2563 +#ifndef CONFIG_TAGGING_NONE
2564 +               case Opt_tag:
2565 +                       set_opt (sbi->s_mount_opt, TAGGED);
2566 +                       break;
2567 +               case Opt_notag:
2568 +                       clear_opt (sbi->s_mount_opt, TAGGED);
2569 +                       break;
2570 +#endif
2571 +#ifdef CONFIG_PROPAGATE
2572 +               case Opt_tagid:
2573 +                       /* use args[0] */
2574 +                       set_opt (sbi->s_mount_opt, TAGGED);
2575 +                       break;
2576 +#endif
2577                 case Opt_nocheck:
2578                         clear_opt (sbi->s_mount_opt, CHECK);
2579                         break;
2580 @@ -864,6 +882,8 @@ static int ext2_fill_super(struct super_
2581         if (!parse_options((char *) data, sb))
2582                 goto failed_mount;
2583  
2584 +       if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
2585 +               sb->s_flags |= MS_TAGGED;
2586         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2587                 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
2588                  MS_POSIXACL : 0);
2589 @@ -1269,6 +1289,14 @@ static int ext2_remount (struct super_bl
2590                 err = -EINVAL;
2591                 goto restore_opts;
2592         }
2593 +
2594 +       if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
2595 +               !(sb->s_flags & MS_TAGGED)) {
2596 +               printk("EXT2-fs: %s: tagging not permitted on remount.\n",
2597 +                      sb->s_id);
2598 +               err = -EINVAL;
2599 +               goto restore_opts;
2600 +       }
2601  
2602         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2603                 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
2604 diff -NurpP --minimal linux-3.9.4/fs/ext3/ext3.h linux-3.9.4-vs2.3.6.1/fs/ext3/ext3.h
2605 --- linux-3.9.4/fs/ext3/ext3.h  2012-12-11 03:30:57.000000000 +0000
2606 +++ linux-3.9.4-vs2.3.6.1/fs/ext3/ext3.h        2013-05-31 14:47:11.000000000 +0000
2607 @@ -151,10 +151,14 @@ struct ext3_group_desc
2608  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
2609  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
2610  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
2611 +#define EXT3_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
2612  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
2613  
2614 -#define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
2615 -#define EXT3_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
2616 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
2617 +#define EXT3_COW_FL                    0x20000000 /* Copy on Write marker */
2618 +
2619 +#define EXT3_FL_USER_VISIBLE           0x0103DFFF /* User visible flags */
2620 +#define EXT3_FL_USER_MODIFIABLE                0x010380FF /* User modifiable flags */
2621  
2622  /* Flags that should be inherited by new inodes from their parent. */
2623  #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
2624 @@ -290,7 +294,8 @@ struct ext3_inode {
2625                         __u16   i_pad1;
2626                         __le16  l_i_uid_high;   /* these 2 fields    */
2627                         __le16  l_i_gid_high;   /* were reserved2[0] */
2628 -                       __u32   l_i_reserved2;
2629 +                       __le16  l_i_tag;        /* Context Tag */
2630 +                       __u16   l_i_reserved2;
2631                 } linux2;
2632                 struct {
2633                         __u8    h_i_frag;       /* Fragment number */
2634 @@ -320,6 +325,7 @@ struct ext3_inode {
2635  #define i_gid_low      i_gid
2636  #define i_uid_high     osd2.linux2.l_i_uid_high
2637  #define i_gid_high     osd2.linux2.l_i_gid_high
2638 +#define i_raw_tag      osd2.linux2.l_i_tag
2639  #define i_reserved2    osd2.linux2.l_i_reserved2
2640  
2641  /*
2642 @@ -364,6 +370,7 @@ struct ext3_inode {
2643  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
2644  #define EXT3_MOUNT_DATA_ERR_ABORT      0x400000 /* Abort on file data write
2645                                                   * error in ordered mode */
2646 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
2647  
2648  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
2649  #ifndef _LINUX_EXT2_FS_H
2650 @@ -1061,6 +1068,7 @@ extern void ext3_get_inode_flags(struct
2651  extern void ext3_set_aops(struct inode *inode);
2652  extern int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2653                        u64 start, u64 len);
2654 +extern int ext3_sync_flags(struct inode *, int, int);
2655  
2656  /* ioctl.c */
2657  extern long ext3_ioctl(struct file *, unsigned int, unsigned long);
2658 diff -NurpP --minimal linux-3.9.4/fs/ext3/file.c linux-3.9.4-vs2.3.6.1/fs/ext3/file.c
2659 --- linux-3.9.4/fs/ext3/file.c  2012-12-11 03:30:57.000000000 +0000
2660 +++ linux-3.9.4-vs2.3.6.1/fs/ext3/file.c        2013-05-31 14:47:11.000000000 +0000
2661 @@ -76,5 +76,6 @@ const struct inode_operations ext3_file_
2662  #endif
2663         .get_acl        = ext3_get_acl,
2664         .fiemap         = ext3_fiemap,
2665 +       .sync_flags     = ext3_sync_flags,
2666  };
2667  
2668 diff -NurpP --minimal linux-3.9.4/fs/ext3/ialloc.c linux-3.9.4-vs2.3.6.1/fs/ext3/ialloc.c
2669 --- linux-3.9.4/fs/ext3/ialloc.c        2012-12-11 03:30:57.000000000 +0000
2670 +++ linux-3.9.4-vs2.3.6.1/fs/ext3/ialloc.c      2013-05-31 14:47:11.000000000 +0000
2671 @@ -14,6 +14,7 @@
2672  
2673  #include <linux/quotaops.h>
2674  #include <linux/random.h>
2675 +#include <linux/vs_tag.h>
2676  
2677  #include "ext3.h"
2678  #include "xattr.h"
2679 @@ -469,6 +470,7 @@ got:
2680                 inode->i_mode = mode;
2681                 inode->i_uid = current_fsuid();
2682                 inode->i_gid = dir->i_gid;
2683 +               inode->i_tag = dx_current_fstag(sb);
2684         } else
2685                 inode_init_owner(inode, dir, mode);
2686  
2687 diff -NurpP --minimal linux-3.9.4/fs/ext3/inode.c linux-3.9.4-vs2.3.6.1/fs/ext3/inode.c
2688 --- linux-3.9.4/fs/ext3/inode.c 2013-05-31 13:45:23.000000000 +0000
2689 +++ linux-3.9.4-vs2.3.6.1/fs/ext3/inode.c       2013-05-31 14:47:11.000000000 +0000
2690 @@ -27,6 +27,8 @@
2691  #include <linux/writeback.h>
2692  #include <linux/mpage.h>
2693  #include <linux/namei.h>
2694 +#include <linux/vs_tag.h>
2695 +
2696  #include "ext3.h"
2697  #include "xattr.h"
2698  #include "acl.h"
2699 @@ -2851,36 +2853,60 @@ void ext3_set_inode_flags(struct inode *
2700  {
2701         unsigned int flags = EXT3_I(inode)->i_flags;
2702  
2703 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2704 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2705 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2706 +
2707 +       if (flags & EXT3_IMMUTABLE_FL)
2708 +               inode->i_flags |= S_IMMUTABLE;
2709 +       if (flags & EXT3_IXUNLINK_FL)
2710 +               inode->i_flags |= S_IXUNLINK;
2711 +
2712         if (flags & EXT3_SYNC_FL)
2713                 inode->i_flags |= S_SYNC;
2714         if (flags & EXT3_APPEND_FL)
2715                 inode->i_flags |= S_APPEND;
2716 -       if (flags & EXT3_IMMUTABLE_FL)
2717 -               inode->i_flags |= S_IMMUTABLE;
2718         if (flags & EXT3_NOATIME_FL)
2719                 inode->i_flags |= S_NOATIME;
2720         if (flags & EXT3_DIRSYNC_FL)
2721                 inode->i_flags |= S_DIRSYNC;
2722 +
2723 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2724 +
2725 +       if (flags & EXT3_BARRIER_FL)
2726 +               inode->i_vflags |= V_BARRIER;
2727 +       if (flags & EXT3_COW_FL)
2728 +               inode->i_vflags |= V_COW;
2729  }
2730  
2731  /* Propagate flags from i_flags to EXT3_I(inode)->i_flags */
2732  void ext3_get_inode_flags(struct ext3_inode_info *ei)
2733  {
2734         unsigned int flags = ei->vfs_inode.i_flags;
2735 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2736 +
2737 +       ei->i_flags &= ~(EXT3_SYNC_FL | EXT3_APPEND_FL |
2738 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL |
2739 +                       EXT3_NOATIME_FL | EXT3_DIRSYNC_FL |
2740 +                       EXT3_BARRIER_FL | EXT3_COW_FL);
2741 +
2742 +       if (flags & S_IMMUTABLE)
2743 +               ei->i_flags |= EXT3_IMMUTABLE_FL;
2744 +       if (flags & S_IXUNLINK)
2745 +               ei->i_flags |= EXT3_IXUNLINK_FL;
2746  
2747 -       ei->i_flags &= ~(EXT3_SYNC_FL|EXT3_APPEND_FL|
2748 -                       EXT3_IMMUTABLE_FL|EXT3_NOATIME_FL|EXT3_DIRSYNC_FL);
2749         if (flags & S_SYNC)
2750                 ei->i_flags |= EXT3_SYNC_FL;
2751         if (flags & S_APPEND)
2752                 ei->i_flags |= EXT3_APPEND_FL;
2753 -       if (flags & S_IMMUTABLE)
2754 -               ei->i_flags |= EXT3_IMMUTABLE_FL;
2755         if (flags & S_NOATIME)
2756                 ei->i_flags |= EXT3_NOATIME_FL;
2757         if (flags & S_DIRSYNC)
2758                 ei->i_flags |= EXT3_DIRSYNC_FL;
2759 +
2760 +       if (vflags & V_BARRIER)
2761 +               ei->i_flags |= EXT3_BARRIER_FL;
2762 +       if (vflags & V_COW)
2763 +               ei->i_flags |= EXT3_COW_FL;
2764  }
2765  
2766  struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
2767 @@ -2918,8 +2944,10 @@ struct inode *ext3_iget(struct super_blo
2768                 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2769                 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2770         }
2771 -       i_uid_write(inode, i_uid);
2772 -       i_gid_write(inode, i_gid);
2773 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
2774 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
2775 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
2776 +               le16_to_cpu(raw_inode->i_raw_tag)));
2777         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2778         inode->i_size = le32_to_cpu(raw_inode->i_size);
2779         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2780 @@ -3091,8 +3119,10 @@ again:
2781  
2782         ext3_get_inode_flags(ei);
2783         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
2784 -       i_uid = i_uid_read(inode);
2785 -       i_gid = i_gid_read(inode);
2786 +       i_uid = TAGINO_UID(DX_TAG(inode),
2787 +               i_uid_read(inode), i_tag_read(inode));
2788 +       i_gid = TAGINO_GID(DX_TAG(inode),
2789 +               i_gid_read(inode), i_tag_read(inode));
2790         if(!(test_opt(inode->i_sb, NO_UID32))) {
2791                 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(i_uid));
2792                 raw_inode->i_gid_low = cpu_to_le16(low_16_bits(i_gid));
2793 @@ -3117,6 +3147,9 @@ again:
2794                 raw_inode->i_uid_high = 0;
2795                 raw_inode->i_gid_high = 0;
2796         }
2797 +#ifdef CONFIG_TAGGING_INTERN
2798 +       raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
2799 +#endif
2800         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2801         disksize = cpu_to_le32(ei->i_disksize);
2802         if (disksize != raw_inode->i_size) {
2803 @@ -3285,7 +3318,8 @@ int ext3_setattr(struct dentry *dentry,
2804         if (is_quota_modification(inode, attr))
2805                 dquot_initialize(inode);
2806         if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) ||
2807 -           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) {
2808 +           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid)) ||
2809 +           (ia_valid & ATTR_TAG && !tag_eq(attr->ia_tag, inode->i_tag))) {
2810                 handle_t *handle;
2811  
2812                 /* (user+group)*(old+new) structure, inode write (sb,
2813 @@ -3307,6 +3341,8 @@ int ext3_setattr(struct dentry *dentry,
2814                         inode->i_uid = attr->ia_uid;
2815                 if (attr->ia_valid & ATTR_GID)
2816                         inode->i_gid = attr->ia_gid;
2817 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2818 +                       inode->i_tag = attr->ia_tag;
2819                 error = ext3_mark_inode_dirty(handle, inode);
2820                 ext3_journal_stop(handle);
2821         }
2822 diff -NurpP --minimal linux-3.9.4/fs/ext3/ioctl.c linux-3.9.4-vs2.3.6.1/fs/ext3/ioctl.c
2823 --- linux-3.9.4/fs/ext3/ioctl.c 2013-05-31 13:45:23.000000000 +0000
2824 +++ linux-3.9.4-vs2.3.6.1/fs/ext3/ioctl.c       2013-05-31 14:47:11.000000000 +0000
2825 @@ -12,6 +12,34 @@
2826  #include <asm/uaccess.h>
2827  #include "ext3.h"
2828  
2829 +
2830 +int ext3_sync_flags(struct inode *inode, int flags, int vflags)
2831 +{
2832 +       handle_t *handle = NULL;
2833 +       struct ext3_iloc iloc;
2834 +       int err;
2835 +
2836 +       handle = ext3_journal_start(inode, 1);
2837 +       if (IS_ERR(handle))
2838 +               return PTR_ERR(handle);
2839 +
2840 +       if (IS_SYNC(inode))
2841 +               handle->h_sync = 1;
2842 +       err = ext3_reserve_inode_write(handle, inode, &iloc);
2843 +       if (err)
2844 +               goto flags_err;
2845 +
2846 +       inode->i_flags = flags;
2847 +       inode->i_vflags = vflags;
2848 +       ext3_get_inode_flags(EXT3_I(inode));
2849 +       inode->i_ctime = CURRENT_TIME_SEC;
2850 +
2851 +       err = ext3_mark_iloc_dirty(handle, inode, &iloc);
2852 +flags_err:
2853 +       ext3_journal_stop(handle);
2854 +       return err;
2855 +}
2856 +
2857  long ext3_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2858  {
2859         struct inode *inode = file_inode(filp);
2860 @@ -45,6 +73,11 @@ long ext3_ioctl(struct file *filp, unsig
2861  
2862                 flags = ext3_mask_flags(inode->i_mode, flags);
2863  
2864 +               if (IS_BARRIER(inode)) {
2865 +                       vxwprintk_task(1, "messing with the barrier.");
2866 +                       return -EACCES;
2867 +               }
2868 +
2869                 mutex_lock(&inode->i_mutex);
2870  
2871                 /* Is it quota file? Do not allow user to mess with it */
2872 @@ -63,7 +96,9 @@ long ext3_ioctl(struct file *filp, unsig
2873                  *
2874                  * This test looks nicer. Thanks to Pauline Middelink
2875                  */
2876 -               if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
2877 +               if ((oldflags & EXT3_IMMUTABLE_FL) ||
2878 +                       ((flags ^ oldflags) & (EXT3_APPEND_FL |
2879 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL))) {
2880                         if (!capable(CAP_LINUX_IMMUTABLE))
2881                                 goto flags_out;
2882                 }
2883 @@ -88,7 +123,7 @@ long ext3_ioctl(struct file *filp, unsig
2884                 if (err)
2885                         goto flags_err;
2886  
2887 -               flags = flags & EXT3_FL_USER_MODIFIABLE;
2888 +               flags &= EXT3_FL_USER_MODIFIABLE;
2889                 flags |= oldflags & ~EXT3_FL_USER_MODIFIABLE;
2890                 ei->i_flags = flags;
2891  
2892 diff -NurpP --minimal linux-3.9.4/fs/ext3/namei.c linux-3.9.4-vs2.3.6.1/fs/ext3/namei.c
2893 --- linux-3.9.4/fs/ext3/namei.c 2013-05-31 13:45:23.000000000 +0000
2894 +++ linux-3.9.4-vs2.3.6.1/fs/ext3/namei.c       2013-05-31 14:47:11.000000000 +0000
2895 @@ -25,6 +25,8 @@
2896   */
2897  
2898  #include <linux/quotaops.h>
2899 +#include <linux/vs_tag.h>
2900 +
2901  #include "ext3.h"
2902  #include "namei.h"
2903  #include "xattr.h"
2904 @@ -918,6 +920,7 @@ restart:
2905                                         submit_bh(READ | REQ_META | REQ_PRIO,
2906                                                   bh);
2907                                 }
2908 +               dx_propagate_tag(nd, inode);
2909                         }
2910                 }
2911                 if ((bh = bh_use[ra_ptr++]) == NULL)
2912 @@ -2527,6 +2530,7 @@ const struct inode_operations ext3_dir_i
2913         .listxattr      = ext3_listxattr,
2914         .removexattr    = generic_removexattr,
2915  #endif
2916 +       .sync_flags     = ext3_sync_flags,
2917         .get_acl        = ext3_get_acl,
2918  };
2919  
2920 diff -NurpP --minimal linux-3.9.4/fs/ext3/super.c linux-3.9.4-vs2.3.6.1/fs/ext3/super.c
2921 --- linux-3.9.4/fs/ext3/super.c 2013-05-31 13:45:23.000000000 +0000
2922 +++ linux-3.9.4-vs2.3.6.1/fs/ext3/super.c       2013-05-31 14:47:11.000000000 +0000
2923 @@ -816,7 +816,8 @@ enum {
2924         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
2925         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota,
2926         Opt_noquota, Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err,
2927 -       Opt_resize, Opt_usrquota, Opt_grpquota
2928 +       Opt_resize, Opt_usrquota, Opt_grpquota,
2929 +       Opt_tag, Opt_notag, Opt_tagid
2930  };
2931  
2932  static const match_table_t tokens = {
2933 @@ -873,6 +874,9 @@ static const match_table_t tokens = {
2934         {Opt_barrier, "barrier"},
2935         {Opt_nobarrier, "nobarrier"},
2936         {Opt_resize, "resize"},
2937 +       {Opt_tag, "tag"},
2938 +       {Opt_notag, "notag"},
2939 +       {Opt_tagid, "tagid=%u"},
2940         {Opt_err, NULL},
2941  };
2942  
2943 @@ -1040,6 +1044,20 @@ static int parse_options (char *options,
2944                 case Opt_nouid32:
2945                         set_opt (sbi->s_mount_opt, NO_UID32);
2946                         break;
2947 +#ifndef CONFIG_TAGGING_NONE
2948 +               case Opt_tag:
2949 +                       set_opt (sbi->s_mount_opt, TAGGED);
2950 +                       break;
2951 +               case Opt_notag:
2952 +                       clear_opt (sbi->s_mount_opt, TAGGED);
2953 +                       break;
2954 +#endif
2955 +#ifdef CONFIG_PROPAGATE
2956 +               case Opt_tagid:
2957 +                       /* use args[0] */
2958 +                       set_opt (sbi->s_mount_opt, TAGGED);
2959 +                       break;
2960 +#endif
2961                 case Opt_nocheck:
2962                         clear_opt (sbi->s_mount_opt, CHECK);
2963                         break;
2964 @@ -1737,6 +1755,9 @@ static int ext3_fill_super (struct super
2965                             NULL, 0))
2966                 goto failed_mount;
2967  
2968 +       if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
2969 +               sb->s_flags |= MS_TAGGED;
2970 +
2971         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2972                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2973  
2974 @@ -2633,6 +2654,14 @@ static int ext3_remount (struct super_bl
2975         if (test_opt(sb, ABORT))
2976                 ext3_abort(sb, __func__, "Abort forced by user");
2977  
2978 +       if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
2979 +               !(sb->s_flags & MS_TAGGED)) {
2980 +               printk("EXT3-fs: %s: tagging not permitted on remount.\n",
2981 +                       sb->s_id);
2982 +               err = -EINVAL;
2983 +               goto restore_opts;
2984 +       }
2985 +
2986         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2987                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2988  
2989 diff -NurpP --minimal linux-3.9.4/fs/ext4/ext4.h linux-3.9.4-vs2.3.6.1/fs/ext4/ext4.h
2990 --- linux-3.9.4/fs/ext4/ext4.h  2013-05-31 13:45:23.000000000 +0000
2991 +++ linux-3.9.4-vs2.3.6.1/fs/ext4/ext4.h        2013-05-31 16:22:49.000000000 +0000
2992 @@ -399,7 +399,10 @@ struct flex_groups {
2993  #define EXT4_EXTENTS_FL                        0x00080000 /* Inode uses extents */
2994  #define EXT4_EA_INODE_FL               0x00200000 /* Inode used for large EA */
2995  #define EXT4_EOFBLOCKS_FL              0x00400000 /* Blocks allocated beyond EOF */
2996 +#define EXT4_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
2997 +#define EXT4_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
2998  #define EXT4_INLINE_DATA_FL            0x10000000 /* Inode has inline data. */
2999 +#define EXT4_COW_FL                    0x20000000 /* Copy on Write marker */
3000  #define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
3001  
3002  #define EXT4_FL_USER_VISIBLE           0x004BDFFF /* User visible flags */
3003 @@ -674,7 +677,7 @@ struct ext4_inode {
3004                         __le16  l_i_uid_high;   /* these 2 fields */
3005                         __le16  l_i_gid_high;   /* were reserved2[0] */
3006                         __le16  l_i_checksum_lo;/* crc32c(uuid+inum+inode) LE */
3007 -                       __le16  l_i_reserved;
3008 +                       __le16  l_i_tag;        /* Context Tag */
3009                 } linux2;
3010                 struct {
3011                         __le16  h_i_reserved1;  /* Obsoleted fragment number/size which are removed in ext4 */
3012 @@ -792,6 +795,7 @@ do {                                                                               \
3013  #define i_gid_low      i_gid
3014  #define i_uid_high     osd2.linux2.l_i_uid_high
3015  #define i_gid_high     osd2.linux2.l_i_gid_high
3016 +#define i_raw_tag      osd2.linux2.l_i_tag
3017  #define i_checksum_lo  osd2.linux2.l_i_checksum_lo
3018  
3019  #elif defined(__GNU__)
3020 @@ -969,6 +973,7 @@ struct ext4_inode_info {
3021  #define EXT4_MOUNT_POSIX_ACL           0x08000 /* POSIX Access Control Lists */
3022  #define EXT4_MOUNT_NO_AUTO_DA_ALLOC    0x10000 /* No auto delalloc mapping */
3023  #define EXT4_MOUNT_BARRIER             0x20000 /* Use block barriers */
3024 +#define EXT4_MOUNT_TAGGED              0x40000 /* Enable Context Tags */
3025  #define EXT4_MOUNT_QUOTA               0x80000 /* Some quota option set */
3026  #define EXT4_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
3027  #define EXT4_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
3028 @@ -2527,6 +2532,7 @@ extern struct buffer_head *ext4_get_firs
3029  extern int ext4_inline_data_fiemap(struct inode *inode,
3030                                    struct fiemap_extent_info *fieinfo,
3031                                    int *has_inline);
3032 +extern int ext4_sync_flags(struct inode *, int, int);
3033  extern int ext4_try_to_evict_inline_data(handle_t *handle,
3034                                          struct inode *inode,
3035                                          int needed);
3036 diff -NurpP --minimal linux-3.9.4/fs/ext4/file.c linux-3.9.4-vs2.3.6.1/fs/ext4/file.c
3037 --- linux-3.9.4/fs/ext4/file.c  2013-05-31 13:45:23.000000000 +0000
3038 +++ linux-3.9.4-vs2.3.6.1/fs/ext4/file.c        2013-05-31 14:47:11.000000000 +0000
3039 @@ -650,5 +650,6 @@ const struct inode_operations ext4_file_
3040         .removexattr    = generic_removexattr,
3041         .get_acl        = ext4_get_acl,
3042         .fiemap         = ext4_fiemap,
3043 +       .sync_flags     = ext4_sync_flags,
3044  };
3045  
3046 diff -NurpP --minimal linux-3.9.4/fs/ext4/ialloc.c linux-3.9.4-vs2.3.6.1/fs/ext4/ialloc.c
3047 --- linux-3.9.4/fs/ext4/ialloc.c        2013-05-31 13:45:23.000000000 +0000
3048 +++ linux-3.9.4-vs2.3.6.1/fs/ext4/ialloc.c      2013-05-31 14:47:11.000000000 +0000
3049 @@ -22,6 +22,7 @@
3050  #include <linux/random.h>
3051  #include <linux/bitops.h>
3052  #include <linux/blkdev.h>
3053 +#include <linux/vs_tag.h>
3054  #include <asm/byteorder.h>
3055  
3056  #include "ext4.h"
3057 @@ -859,6 +860,7 @@ got:
3058                 inode->i_mode = mode;
3059                 inode->i_uid = current_fsuid();
3060                 inode->i_gid = dir->i_gid;
3061 +               inode->i_tag = dx_current_fstag(sb);
3062         } else
3063                 inode_init_owner(inode, dir, mode);
3064  
3065 diff -NurpP --minimal linux-3.9.4/fs/ext4/inode.c linux-3.9.4-vs2.3.6.1/fs/ext4/inode.c
3066 --- linux-3.9.4/fs/ext4/inode.c 2013-05-31 14:22:27.000000000 +0000
3067 +++ linux-3.9.4-vs2.3.6.1/fs/ext4/inode.c       2013-05-31 14:47:11.000000000 +0000
3068 @@ -37,6 +37,7 @@
3069  #include <linux/printk.h>
3070  #include <linux/slab.h>
3071  #include <linux/ratelimit.h>
3072 +#include <linux/vs_tag.h>
3073  
3074  #include "ext4_jbd2.h"
3075  #include "xattr.h"
3076 @@ -3870,41 +3871,64 @@ void ext4_set_inode_flags(struct inode *
3077  {
3078         unsigned int flags = EXT4_I(inode)->i_flags;
3079  
3080 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3081 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3082 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3083 +
3084 +       if (flags & EXT4_IMMUTABLE_FL)
3085 +               inode->i_flags |= S_IMMUTABLE;
3086 +       if (flags & EXT4_IXUNLINK_FL)
3087 +               inode->i_flags |= S_IXUNLINK;
3088 +
3089         if (flags & EXT4_SYNC_FL)
3090                 inode->i_flags |= S_SYNC;
3091         if (flags & EXT4_APPEND_FL)
3092                 inode->i_flags |= S_APPEND;
3093 -       if (flags & EXT4_IMMUTABLE_FL)
3094 -               inode->i_flags |= S_IMMUTABLE;
3095         if (flags & EXT4_NOATIME_FL)
3096                 inode->i_flags |= S_NOATIME;
3097         if (flags & EXT4_DIRSYNC_FL)
3098                 inode->i_flags |= S_DIRSYNC;
3099 +
3100 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3101 +
3102 +       if (flags & EXT4_BARRIER_FL)
3103 +               inode->i_vflags |= V_BARRIER;
3104 +       if (flags & EXT4_COW_FL)
3105 +               inode->i_vflags |= V_COW;
3106  }
3107  
3108  /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
3109  void ext4_get_inode_flags(struct ext4_inode_info *ei)
3110  {
3111 -       unsigned int vfs_fl;
3112 +       unsigned int vfs_fl, vfs_vf;
3113         unsigned long old_fl, new_fl;
3114  
3115         do {
3116                 vfs_fl = ei->vfs_inode.i_flags;
3117 +               vfs_vf = ei->vfs_inode.i_vflags;
3118                 old_fl = ei->i_flags;
3119                 new_fl = old_fl & ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
3120                                 EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|
3121 -                               EXT4_DIRSYNC_FL);
3122 +                               EXT4_DIRSYNC_FL|EXT4_BARRIER_FL|
3123 +                               EXT4_COW_FL);
3124 +
3125 +               if (vfs_fl & S_IMMUTABLE)
3126 +                       new_fl |= EXT4_IMMUTABLE_FL;
3127 +               if (vfs_fl & S_IXUNLINK)
3128 +                       new_fl |= EXT4_IXUNLINK_FL;
3129 +
3130                 if (vfs_fl & S_SYNC)
3131                         new_fl |= EXT4_SYNC_FL;
3132                 if (vfs_fl & S_APPEND)
3133                         new_fl |= EXT4_APPEND_FL;
3134 -               if (vfs_fl & S_IMMUTABLE)
3135 -                       new_fl |= EXT4_IMMUTABLE_FL;
3136                 if (vfs_fl & S_NOATIME)
3137                         new_fl |= EXT4_NOATIME_FL;
3138                 if (vfs_fl & S_DIRSYNC)
3139                         new_fl |= EXT4_DIRSYNC_FL;
3140 +
3141 +               if (vfs_vf & V_BARRIER)
3142 +                       new_fl |= EXT4_BARRIER_FL;
3143 +               if (vfs_vf & V_COW)
3144 +                       new_fl |= EXT4_COW_FL;
3145         } while (cmpxchg(&ei->i_flags, old_fl, new_fl) != old_fl);
3146  }
3147  
3148 @@ -4009,8 +4033,10 @@ struct inode *ext4_iget(struct super_blo
3149                 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3150                 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3151         }
3152 -       i_uid_write(inode, i_uid);
3153 -       i_gid_write(inode, i_gid);
3154 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
3155 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
3156 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
3157 +               le16_to_cpu(raw_inode->i_raw_tag)));
3158         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
3159  
3160         ext4_clear_state_flags(ei);     /* Only relevant on 32-bit archs */
3161 @@ -4233,8 +4259,10 @@ static int ext4_do_update_inode(handle_t
3162  
3163         ext4_get_inode_flags(ei);
3164         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3165 -       i_uid = i_uid_read(inode);
3166 -       i_gid = i_gid_read(inode);
3167 +       i_uid = TAGINO_UID(DX_TAG(inode),
3168 +               i_uid_read(inode), i_tag_read(inode));
3169 +       i_gid = TAGINO_GID(DX_TAG(inode),
3170 +               i_gid_read(inode), i_tag_read(inode));
3171         if (!(test_opt(inode->i_sb, NO_UID32))) {
3172                 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(i_uid));
3173                 raw_inode->i_gid_low = cpu_to_le16(low_16_bits(i_gid));
3174 @@ -4257,6 +4285,9 @@ static int ext4_do_update_inode(handle_t
3175                 raw_inode->i_uid_high = 0;
3176                 raw_inode->i_gid_high = 0;
3177         }
3178 +#ifdef CONFIG_TAGGING_INTERN
3179 +       raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
3180 +#endif
3181         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3182  
3183         EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
3184 @@ -4487,7 +4518,8 @@ int ext4_setattr(struct dentry *dentry,
3185         if (is_quota_modification(inode, attr))
3186                 dquot_initialize(inode);
3187         if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) ||
3188 -           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) {
3189 +           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid)) ||
3190 +           (ia_valid & ATTR_TAG && !tag_eq(attr->ia_tag, inode->i_tag))) {
3191                 handle_t *handle;
3192  
3193                 /* (user+group)*(old+new) structure, inode write (sb,
3194 @@ -4510,6 +4542,8 @@ int ext4_setattr(struct dentry *dentry,
3195                         inode->i_uid = attr->ia_uid;
3196                 if (attr->ia_valid & ATTR_GID)
3197                         inode->i_gid = attr->ia_gid;
3198 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3199 +                       inode->i_tag = attr->ia_tag;
3200                 error = ext4_mark_inode_dirty(handle, inode);
3201                 ext4_journal_stop(handle);
3202         }
3203 diff -NurpP --minimal linux-3.9.4/fs/ext4/ioctl.c linux-3.9.4-vs2.3.6.1/fs/ext4/ioctl.c
3204 --- linux-3.9.4/fs/ext4/ioctl.c 2013-05-31 13:45:23.000000000 +0000
3205 +++ linux-3.9.4-vs2.3.6.1/fs/ext4/ioctl.c       2013-05-31 19:50:08.000000000 +0000
3206 @@ -14,12 +14,40 @@
3207  #include <linux/compat.h>
3208  #include <linux/mount.h>
3209  #include <linux/file.h>
3210 +#include <linux/vs_tag.h>
3211  #include <asm/uaccess.h>
3212  #include "ext4_jbd2.h"
3213  #include "ext4.h"
3214  
3215  #define MAX_32_NUM ((((unsigned long long) 1) << 32) - 1)
3216  
3217 +int ext4_sync_flags(struct inode *inode, int flags, int vflags)
3218 +{
3219 +       handle_t *handle = NULL;
3220 +       struct ext4_iloc iloc;
3221 +       int err;
3222 +
3223 +       handle = ext4_journal_start(inode, EXT4_HT_INODE, 1);
3224 +       if (IS_ERR(handle))
3225 +               return PTR_ERR(handle);
3226 +
3227 +       if (IS_SYNC(inode))
3228 +               ext4_handle_sync(handle);
3229 +       err = ext4_reserve_inode_write(handle, inode, &iloc);
3230 +       if (err)
3231 +               goto flags_err;
3232 +
3233 +       inode->i_flags = flags;
3234 +       inode->i_vflags = vflags;
3235 +       ext4_get_inode_flags(EXT4_I(inode));
3236 +       inode->i_ctime = ext4_current_time(inode);
3237 +
3238 +       err = ext4_mark_iloc_dirty(handle, inode, &iloc);
3239 +flags_err:
3240 +       ext4_journal_stop(handle);
3241 +       return err;
3242 +}
3243 +
3244  long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3245  {
3246         struct inode *inode = file_inode(filp);
3247 @@ -53,6 +81,11 @@ long ext4_ioctl(struct file *filp, unsig
3248  
3249                 flags = ext4_mask_flags(inode->i_mode, flags);
3250  
3251 +               if (IS_BARRIER(inode)) {
3252 +                       vxwprintk_task(1, "messing with the barrier.");
3253 +                       return -EACCES;
3254 +               }
3255 +
3256                 err = -EPERM;
3257                 mutex_lock(&inode->i_mutex);
3258                 /* Is it quota file? Do not allow user to mess with it */
3259 @@ -70,7 +103,9 @@ long ext4_ioctl(struct file *filp, unsig
3260                  *
3261                  * This test looks nicer. Thanks to Pauline Middelink
3262                  */
3263 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
3264 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
3265 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
3266 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
3267                         if (!capable(CAP_LINUX_IMMUTABLE))
3268                                 goto flags_out;
3269                 }
3270 diff -NurpP --minimal linux-3.9.4/fs/ext4/namei.c linux-3.9.4-vs2.3.6.1/fs/ext4/namei.c
3271 --- linux-3.9.4/fs/ext4/namei.c 2013-05-31 13:45:23.000000000 +0000
3272 +++ linux-3.9.4-vs2.3.6.1/fs/ext4/namei.c       2013-05-31 14:47:11.000000000 +0000
3273 @@ -34,6 +34,7 @@
3274  #include <linux/quotaops.h>
3275  #include <linux/buffer_head.h>
3276  #include <linux/bio.h>
3277 +#include <linux/vs_tag.h>
3278  #include "ext4.h"
3279  #include "ext4_jbd2.h"
3280  
3281 @@ -1290,6 +1291,7 @@ restart:
3282                                         ll_rw_block(READ | REQ_META | REQ_PRIO,
3283                                                     1, &bh);
3284                         }
3285 +               dx_propagate_tag(nd, inode);
3286                 }
3287                 if ((bh = bh_use[ra_ptr++]) == NULL)
3288                         goto next;
3289 @@ -3190,6 +3192,7 @@ const struct inode_operations ext4_dir_i
3290         .removexattr    = generic_removexattr,
3291         .get_acl        = ext4_get_acl,
3292         .fiemap         = ext4_fiemap,
3293 +       .sync_flags     = ext4_sync_flags,
3294  };
3295  
3296  const struct inode_operations ext4_special_inode_operations = {
3297 diff -NurpP --minimal linux-3.9.4/fs/ext4/super.c linux-3.9.4-vs2.3.6.1/fs/ext4/super.c
3298 --- linux-3.9.4/fs/ext4/super.c 2013-05-31 14:22:27.000000000 +0000
3299 +++ linux-3.9.4-vs2.3.6.1/fs/ext4/super.c       2013-05-31 14:47:11.000000000 +0000
3300 @@ -1131,7 +1131,7 @@ enum {
3301         Opt_inode_readahead_blks, Opt_journal_ioprio,
3302         Opt_dioread_nolock, Opt_dioread_lock,
3303         Opt_discard, Opt_nodiscard, Opt_init_itable, Opt_noinit_itable,
3304 -       Opt_max_dir_size_kb,
3305 +       Opt_max_dir_size_kb, Opt_tag, Opt_notag, Opt_tagid
3306  };
3307  
3308  static const match_table_t tokens = {
3309 @@ -1211,6 +1211,9 @@ static const match_table_t tokens = {
3310         {Opt_removed, "reservation"},   /* mount option from ext2/3 */
3311         {Opt_removed, "noreservation"}, /* mount option from ext2/3 */
3312         {Opt_removed, "journal=%u"},    /* mount option from ext2/3 */
3313 +       {Opt_tag, "tag"},
3314 +       {Opt_notag, "notag"},
3315 +       {Opt_tagid, "tagid=%u"},
3316         {Opt_err, NULL},
3317  };
3318  
3319 @@ -1441,6 +1444,20 @@ static int handle_mount_opt(struct super
3320         case Opt_i_version:
3321                 sb->s_flags |= MS_I_VERSION;
3322                 return 1;
3323 +#ifndef CONFIG_TAGGING_NONE
3324 +       case Opt_tag:
3325 +               set_opt(sb, TAGGED);
3326 +               return 1;
3327 +       case Opt_notag:
3328 +               clear_opt(sb, TAGGED);
3329 +               return 1;
3330 +#endif
3331 +#ifdef CONFIG_PROPAGATE
3332 +       case Opt_tagid:
3333 +               /* use args[0] */
3334 +               set_opt(sb, TAGGED);
3335 +               return 1;
3336 +#endif
3337         }
3338  
3339         for (m = ext4_mount_opts; m->token != Opt_err; m++)
3340 @@ -3401,6 +3418,9 @@ static int ext4_fill_super(struct super_
3341                         clear_opt(sb, DELALLOC);
3342         }
3343  
3344 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
3345 +               sb->s_flags |= MS_TAGGED;
3346 +
3347         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3348                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3349  
3350 @@ -4587,6 +4607,14 @@ static int ext4_remount(struct super_blo
3351         if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
3352                 ext4_abort(sb, "Abort forced by user");
3353  
3354 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
3355 +               !(sb->s_flags & MS_TAGGED)) {
3356 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
3357 +                       sb->s_id);
3358 +               err = -EINVAL;
3359 +               goto restore_opts;
3360 +       }
3361 +
3362         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3363                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3364  
3365 diff -NurpP --minimal linux-3.9.4/fs/fcntl.c linux-3.9.4-vs2.3.6.1/fs/fcntl.c
3366 --- linux-3.9.4/fs/fcntl.c      2013-05-31 13:45:23.000000000 +0000
3367 +++ linux-3.9.4-vs2.3.6.1/fs/fcntl.c    2013-05-31 14:47:11.000000000 +0000
3368 @@ -21,6 +21,7 @@
3369  #include <linux/rcupdate.h>
3370  #include <linux/pid_namespace.h>
3371  #include <linux/user_namespace.h>
3372 +#include <linux/vs_limit.h>
3373  
3374  #include <asm/poll.h>
3375  #include <asm/siginfo.h>
3376 @@ -378,6 +379,8 @@ SYSCALL_DEFINE3(fcntl64, unsigned int, f
3377  
3378         if (!f.file)
3379                 goto out;
3380 +       if (!vx_files_avail(1))
3381 +               goto out;
3382  
3383         if (unlikely(f.file->f_mode & FMODE_PATH)) {
3384                 if (!check_fcntl_cmd(cmd))
3385 diff -NurpP --minimal linux-3.9.4/fs/file.c linux-3.9.4-vs2.3.6.1/fs/file.c
3386 --- linux-3.9.4/fs/file.c       2013-05-31 13:45:23.000000000 +0000
3387 +++ linux-3.9.4-vs2.3.6.1/fs/file.c     2013-05-31 14:47:11.000000000 +0000
3388 @@ -22,6 +22,7 @@
3389  #include <linux/spinlock.h>
3390  #include <linux/rcupdate.h>
3391  #include <linux/workqueue.h>
3392 +#include <linux/vs_limit.h>
3393  
3394  struct fdtable_defer {
3395         spinlock_t lock;
3396 @@ -364,6 +365,8 @@ struct files_struct *dup_fd(struct files
3397                 struct file *f = *old_fds++;
3398                 if (f) {
3399                         get_file(f);
3400 +                       /* TODO: sum it first for check and performance */
3401 +                       vx_openfd_inc(open_files - i);
3402                 } else {
3403                         /*
3404                          * The fd may be claimed in the fd bitmap but not yet
3405 @@ -429,9 +432,11 @@ static void close_files(struct files_str
3406                                         filp_close(file, files);
3407                                         cond_resched();
3408                                 }
3409 +                               vx_openfd_dec(i);
3410                         }
3411                         i++;
3412                         set >>= 1;
3413 +                       cond_resched();
3414                 }
3415         }
3416  }
3417 @@ -567,6 +572,7 @@ repeat:
3418         else
3419                 __clear_close_on_exec(fd, fdt);
3420         error = fd;
3421 +       vx_openfd_inc(fd);
3422  #if 1
3423         /* Sanity check */
3424         if (rcu_dereference_raw(fdt->fd[fd]) != NULL) {
3425 @@ -597,6 +603,7 @@ static void __put_unused_fd(struct files
3426         __clear_open_fd(fd, fdt);
3427         if (fd < files->next_fd)
3428                 files->next_fd = fd;
3429 +       vx_openfd_dec(fd);
3430  }
3431  
3432  void put_unused_fd(unsigned int fd)
3433 @@ -876,6 +883,8 @@ static int do_dup2(struct files_struct *
3434  
3435         if (tofree)
3436                 filp_close(tofree, files);
3437 +       else
3438 +               vx_openfd_inc(fd);      /* fd was unused */
3439  
3440         return fd;
3441  
3442 diff -NurpP --minimal linux-3.9.4/fs/file_table.c linux-3.9.4-vs2.3.6.1/fs/file_table.c
3443 --- linux-3.9.4/fs/file_table.c 2013-05-31 13:45:23.000000000 +0000
3444 +++ linux-3.9.4-vs2.3.6.1/fs/file_table.c       2013-05-31 14:47:11.000000000 +0000
3445 @@ -26,6 +26,8 @@
3446  #include <linux/hardirq.h>
3447  #include <linux/task_work.h>
3448  #include <linux/ima.h>
3449 +#include <linux/vs_limit.h>
3450 +#include <linux/vs_context.h>
3451  
3452  #include <linux/atomic.h>
3453  
3454 @@ -140,6 +142,8 @@ struct file *get_empty_filp(void)
3455         spin_lock_init(&f->f_lock);
3456         eventpoll_init_file(f);
3457         /* f->f_version: 0 */
3458 +       f->f_xid = vx_current_xid();
3459 +       vx_files_inc(f);
3460         return f;
3461  
3462  over:
3463 @@ -257,6 +261,8 @@ static void __fput(struct file *file)
3464                 i_readcount_dec(inode);
3465         if (file->f_mode & FMODE_WRITE)
3466                 drop_file_write_access(file);
3467 +       vx_files_dec(file);
3468 +       file->f_xid = 0;
3469         file->f_path.dentry = NULL;
3470         file->f_path.mnt = NULL;
3471         file->f_inode = NULL;
3472 @@ -344,6 +350,8 @@ void put_filp(struct file *file)
3473  {
3474         if (atomic_long_dec_and_test(&file->f_count)) {
3475                 security_file_free(file);
3476 +               vx_files_dec(file);
3477 +               file->f_xid = 0;
3478                 file_sb_list_del(file);
3479                 file_free(file);
3480         }
3481 diff -NurpP --minimal linux-3.9.4/fs/fs_struct.c linux-3.9.4-vs2.3.6.1/fs/fs_struct.c
3482 --- linux-3.9.4/fs/fs_struct.c  2013-05-31 13:45:23.000000000 +0000
3483 +++ linux-3.9.4-vs2.3.6.1/fs/fs_struct.c        2013-05-31 14:47:11.000000000 +0000
3484 @@ -4,6 +4,7 @@
3485  #include <linux/path.h>
3486  #include <linux/slab.h>
3487  #include <linux/fs_struct.h>
3488 +#include <linux/vserver/global.h>
3489  #include "internal.h"
3490  
3491  /*
3492 @@ -87,6 +88,7 @@ void free_fs_struct(struct fs_struct *fs
3493  {
3494         path_put(&fs->root);
3495         path_put(&fs->pwd);
3496 +       atomic_dec(&vs_global_fs);
3497         kmem_cache_free(fs_cachep, fs);
3498  }
3499  
3500 @@ -124,6 +126,7 @@ struct fs_struct *copy_fs_struct(struct
3501                 fs->pwd = old->pwd;
3502                 path_get(&fs->pwd);
3503                 spin_unlock(&old->lock);
3504 +               atomic_inc(&vs_global_fs);
3505         }
3506         return fs;
3507  }
3508 diff -NurpP --minimal linux-3.9.4/fs/gfs2/file.c linux-3.9.4-vs2.3.6.1/fs/gfs2/file.c
3509 --- linux-3.9.4/fs/gfs2/file.c  2013-05-31 13:45:23.000000000 +0000
3510 +++ linux-3.9.4-vs2.3.6.1/fs/gfs2/file.c        2013-05-31 19:54:27.000000000 +0000
3511 @@ -143,6 +143,9 @@ static const u32 fsflags_to_gfs2[32] = {
3512         [12] = GFS2_DIF_EXHASH,
3513         [14] = GFS2_DIF_INHERIT_JDATA,
3514         [17] = GFS2_DIF_TOPDIR,
3515 +       [27] = GFS2_DIF_IXUNLINK,
3516 +       [26] = GFS2_DIF_BARRIER,
3517 +       [29] = GFS2_DIF_COW,
3518  };
3519  
3520  static const u32 gfs2_to_fsflags[32] = {
3521 @@ -153,6 +156,9 @@ static const u32 gfs2_to_fsflags[32] = {
3522         [gfs2fl_ExHash] = FS_INDEX_FL,
3523         [gfs2fl_TopLevel] = FS_TOPDIR_FL,
3524         [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL,
3525 +       [gfs2fl_IXUnlink] = FS_IXUNLINK_FL,
3526 +       [gfs2fl_Barrier] = FS_BARRIER_FL,
3527 +       [gfs2fl_Cow] = FS_COW_FL,
3528  };
3529  
3530  static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
3531 @@ -183,12 +189,18 @@ void gfs2_set_inode_flags(struct inode *
3532  {
3533         struct gfs2_inode *ip = GFS2_I(inode);
3534         unsigned int flags = inode->i_flags;
3535 +       unsigned int vflags = inode->i_vflags;
3536 +
3537 +       flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3538 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC | S_NOSEC);
3539  
3540 -       flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC|S_NOSEC);
3541         if ((ip->i_eattr == 0) && !is_sxid(inode->i_mode))
3542                 inode->i_flags |= S_NOSEC;
3543         if (ip->i_diskflags & GFS2_DIF_IMMUTABLE)
3544                 flags |= S_IMMUTABLE;
3545 +       if (ip->i_diskflags & GFS2_DIF_IXUNLINK)
3546 +               flags |= S_IXUNLINK;
3547 +
3548         if (ip->i_diskflags & GFS2_DIF_APPENDONLY)
3549                 flags |= S_APPEND;
3550         if (ip->i_diskflags & GFS2_DIF_NOATIME)
3551 @@ -196,6 +208,43 @@ void gfs2_set_inode_flags(struct inode *
3552         if (ip->i_diskflags & GFS2_DIF_SYNC)
3553                 flags |= S_SYNC;
3554         inode->i_flags = flags;
3555 +
3556 +       vflags &= ~(V_BARRIER | V_COW);
3557 +
3558 +       if (ip->i_diskflags & GFS2_DIF_BARRIER)
3559 +               vflags |= V_BARRIER;
3560 +       if (ip->i_diskflags & GFS2_DIF_COW)
3561 +               vflags |= V_COW;
3562 +       inode->i_vflags = vflags;
3563 +}
3564 +
3565 +void gfs2_get_inode_flags(struct inode *inode)
3566 +{
3567 +       struct gfs2_inode *ip = GFS2_I(inode);
3568 +       unsigned int flags = inode->i_flags;
3569 +       unsigned int vflags = inode->i_vflags;
3570 +
3571 +       ip->i_diskflags &= ~(GFS2_DIF_APPENDONLY |
3572 +                       GFS2_DIF_NOATIME | GFS2_DIF_SYNC |
3573 +                       GFS2_DIF_IMMUTABLE | GFS2_DIF_IXUNLINK |
3574 +                       GFS2_DIF_BARRIER | GFS2_DIF_COW);
3575 +
3576 +       if (flags & S_IMMUTABLE)
3577 +               ip->i_diskflags |= GFS2_DIF_IMMUTABLE;
3578 +       if (flags & S_IXUNLINK)
3579 +               ip->i_diskflags |= GFS2_DIF_IXUNLINK;
3580 +
3581 +       if (flags & S_APPEND)
3582 +               ip->i_diskflags |= GFS2_DIF_APPENDONLY;
3583 +       if (flags & S_NOATIME)
3584 +               ip->i_diskflags |= GFS2_DIF_NOATIME;
3585 +       if (flags & S_SYNC)
3586 +               ip->i_diskflags |= GFS2_DIF_SYNC;
3587 +
3588 +       if (vflags & V_BARRIER)
3589 +               ip->i_diskflags |= GFS2_DIF_BARRIER;
3590 +       if (vflags & V_COW)
3591 +               ip->i_diskflags |= GFS2_DIF_COW;
3592  }
3593  
3594  /* Flags that can be set by user space */
3595 @@ -309,6 +358,37 @@ static int gfs2_set_flags(struct file *f
3596         return do_gfs2_set_flags(filp, gfsflags, ~GFS2_DIF_JDATA);
3597  }
3598  
3599 +int gfs2_sync_flags(struct inode *inode, int flags, int vflags)
3600 +{
3601 +       struct gfs2_inode *ip = GFS2_I(inode);
3602 +       struct gfs2_sbd *sdp = GFS2_SB(inode);
3603 +       struct buffer_head *bh;
3604 +       struct gfs2_holder gh;
3605 +       int error;
3606 +
3607 +       error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
3608 +       if (error)
3609 +               return error;
3610 +       error = gfs2_trans_begin(sdp, RES_DINODE, 0);
3611 +       if (error)
3612 +               goto out;
3613 +       error = gfs2_meta_inode_buffer(ip, &bh);
3614 +       if (error)
3615 +               goto out_trans_end;
3616 +       gfs2_trans_add_meta(ip->i_gl, bh);
3617 +       inode->i_flags = flags;
3618 +       inode->i_vflags = vflags;
3619 +       gfs2_get_inode_flags(inode);
3620 +       gfs2_dinode_out(ip, bh->b_data);
3621 +       brelse(bh);
3622 +       gfs2_set_aops(inode);
3623 +out_trans_end:
3624 +       gfs2_trans_end(sdp);
3625 +out:
3626 +       gfs2_glock_dq_uninit(&gh);
3627 +       return error;
3628 +}
3629 +
3630  static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3631  {
3632         switch(cmd) {
3633 diff -NurpP --minimal linux-3.9.4/fs/gfs2/inode.h linux-3.9.4-vs2.3.6.1/fs/gfs2/inode.h
3634 --- linux-3.9.4/fs/gfs2/inode.h 2012-12-11 03:30:57.000000000 +0000
3635 +++ linux-3.9.4-vs2.3.6.1/fs/gfs2/inode.h       2013-05-31 14:47:11.000000000 +0000
3636 @@ -117,6 +117,7 @@ extern const struct file_operations gfs2
3637  extern const struct file_operations gfs2_dir_fops_nolock;
3638  
3639  extern void gfs2_set_inode_flags(struct inode *inode);
3640 +extern int gfs2_sync_flags(struct inode *inode, int flags, int vflags);
3641   
3642  #ifdef CONFIG_GFS2_FS_LOCKING_DLM
3643  extern const struct file_operations gfs2_file_fops;
3644 diff -NurpP --minimal linux-3.9.4/fs/hostfs/hostfs.h linux-3.9.4-vs2.3.6.1/fs/hostfs/hostfs.h
3645 --- linux-3.9.4/fs/hostfs/hostfs.h      2012-12-11 03:30:57.000000000 +0000
3646 +++ linux-3.9.4-vs2.3.6.1/fs/hostfs/hostfs.h    2013-05-31 14:47:11.000000000 +0000
3647 @@ -42,6 +42,7 @@ struct hostfs_iattr {
3648         unsigned short  ia_mode;
3649         uid_t           ia_uid;
3650         gid_t           ia_gid;
3651 +       tag_t           ia_tag;
3652         loff_t          ia_size;
3653         struct timespec ia_atime;
3654         struct timespec ia_mtime;
3655 diff -NurpP --minimal linux-3.9.4/fs/inode.c linux-3.9.4-vs2.3.6.1/fs/inode.c
3656 --- linux-3.9.4/fs/inode.c      2013-05-31 13:45:24.000000000 +0000
3657 +++ linux-3.9.4-vs2.3.6.1/fs/inode.c    2013-05-31 14:47:11.000000000 +0000
3658 @@ -17,6 +17,7 @@
3659  #include <linux/prefetch.h>
3660  #include <linux/buffer_head.h> /* for inode_has_buffers */
3661  #include <linux/ratelimit.h>
3662 +#include <linux/vs_tag.h>
3663  #include "internal.h"
3664  
3665  /*
3666 @@ -128,6 +129,8 @@ int inode_init_always(struct super_block
3667         struct address_space *const mapping = &inode->i_data;
3668  
3669         inode->i_sb = sb;
3670 +
3671 +       /* essential because of inode slab reuse */
3672         inode->i_blkbits = sb->s_blocksize_bits;
3673         inode->i_flags = 0;
3674         atomic_set(&inode->i_count, 1);
3675 @@ -137,6 +140,7 @@ int inode_init_always(struct super_block
3676         inode->i_opflags = 0;
3677         i_uid_write(inode, 0);
3678         i_gid_write(inode, 0);
3679 +       i_tag_write(inode, 0);
3680         atomic_set(&inode->i_writecount, 0);
3681         inode->i_size = 0;
3682         inode->i_blocks = 0;
3683 @@ -149,6 +153,7 @@ int inode_init_always(struct super_block
3684         inode->i_bdev = NULL;
3685         inode->i_cdev = NULL;
3686         inode->i_rdev = 0;
3687 +       inode->i_mdev = 0;
3688         inode->dirtied_when = 0;
3689  
3690         if (security_inode_alloc(inode))
3691 @@ -483,6 +488,8 @@ void __insert_inode_hash(struct inode *i
3692  }
3693  EXPORT_SYMBOL(__insert_inode_hash);
3694  
3695 +EXPORT_SYMBOL_GPL(__iget);
3696 +
3697  /**
3698   *     __remove_inode_hash - remove an inode from the hash
3699   *     @inode: inode to unhash
3700 @@ -1799,9 +1806,11 @@ void init_special_inode(struct inode *in
3701         if (S_ISCHR(mode)) {
3702                 inode->i_fop = &def_chr_fops;
3703                 inode->i_rdev = rdev;
3704 +               inode->i_mdev = rdev;
3705         } else if (S_ISBLK(mode)) {
3706                 inode->i_fop = &def_blk_fops;
3707                 inode->i_rdev = rdev;
3708 +               inode->i_mdev = rdev;
3709         } else if (S_ISFIFO(mode))
3710                 inode->i_fop = &def_fifo_fops;
3711         else if (S_ISSOCK(mode))
3712 @@ -1830,6 +1839,7 @@ void inode_init_owner(struct inode *inod
3713         } else
3714                 inode->i_gid = current_fsgid();
3715         inode->i_mode = mode;
3716 +       inode->i_tag = dx_current_fstag(inode->i_sb);
3717  }
3718  EXPORT_SYMBOL(inode_init_owner);
3719  
3720 diff -NurpP --minimal linux-3.9.4/fs/ioctl.c linux-3.9.4-vs2.3.6.1/fs/ioctl.c
3721 --- linux-3.9.4/fs/ioctl.c      2013-05-31 13:45:24.000000000 +0000
3722 +++ linux-3.9.4-vs2.3.6.1/fs/ioctl.c    2013-05-31 14:47:11.000000000 +0000
3723 @@ -15,6 +15,9 @@
3724  #include <linux/writeback.h>
3725  #include <linux/buffer_head.h>
3726  #include <linux/falloc.h>
3727 +#include <linux/proc_fs.h>
3728 +#include <linux/vserver/inode.h>
3729 +#include <linux/vs_tag.h>
3730  
3731  #include <asm/ioctls.h>
3732  
3733 diff -NurpP --minimal linux-3.9.4/fs/ioprio.c linux-3.9.4-vs2.3.6.1/fs/ioprio.c
3734 --- linux-3.9.4/fs/ioprio.c     2012-12-11 03:30:57.000000000 +0000
3735 +++ linux-3.9.4-vs2.3.6.1/fs/ioprio.c   2013-05-31 14:47:11.000000000 +0000
3736 @@ -28,6 +28,7 @@
3737  #include <linux/syscalls.h>
3738  #include <linux/security.h>
3739  #include <linux/pid_namespace.h>
3740 +#include <linux/vs_base.h>
3741  
3742  int set_task_ioprio(struct task_struct *task, int ioprio)
3743  {
3744 @@ -105,6 +106,8 @@ SYSCALL_DEFINE3(ioprio_set, int, which,
3745                         else
3746                                 pgrp = find_vpid(who);
3747                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3748 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3749 +                                       continue;
3750                                 ret = set_task_ioprio(p, ioprio);
3751                                 if (ret)
3752                                         break;
3753 @@ -198,6 +201,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which,
3754                         else
3755                                 pgrp = find_vpid(who);
3756                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3757 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3758 +                                       continue;
3759                                 tmpio = get_task_ioprio(p);
3760                                 if (tmpio < 0)
3761                                         continue;
3762 diff -NurpP --minimal linux-3.9.4/fs/jfs/file.c linux-3.9.4-vs2.3.6.1/fs/jfs/file.c
3763 --- linux-3.9.4/fs/jfs/file.c   2013-02-19 13:58:48.000000000 +0000
3764 +++ linux-3.9.4-vs2.3.6.1/fs/jfs/file.c 2013-05-31 14:47:11.000000000 +0000
3765 @@ -109,7 +109,8 @@ int jfs_setattr(struct dentry *dentry, s
3766         if (is_quota_modification(inode, iattr))
3767                 dquot_initialize(inode);
3768         if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
3769 -           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
3770 +           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid)) ||
3771 +           (iattr->ia_valid & ATTR_TAG && !tag_eq(iattr->ia_tag, inode->i_tag))) {
3772                 rc = dquot_transfer(inode, iattr);
3773                 if (rc)
3774                         return rc;
3775 @@ -144,6 +145,7 @@ const struct inode_operations jfs_file_i
3776  #ifdef CONFIG_JFS_POSIX_ACL
3777         .get_acl        = jfs_get_acl,
3778  #endif
3779 +       .sync_flags     = jfs_sync_flags,
3780  };
3781  
3782  const struct file_operations jfs_file_operations = {
3783 diff -NurpP --minimal linux-3.9.4/fs/jfs/ioctl.c linux-3.9.4-vs2.3.6.1/fs/jfs/ioctl.c
3784 --- linux-3.9.4/fs/jfs/ioctl.c  2013-05-31 13:45:24.000000000 +0000
3785 +++ linux-3.9.4-vs2.3.6.1/fs/jfs/ioctl.c        2013-05-31 14:47:11.000000000 +0000
3786 @@ -12,6 +12,7 @@
3787  #include <linux/time.h>
3788  #include <linux/sched.h>
3789  #include <linux/blkdev.h>
3790 +#include <linux/mount.h>
3791  #include <asm/current.h>
3792  #include <asm/uaccess.h>
3793  
3794 @@ -56,6 +57,16 @@ static long jfs_map_ext2(unsigned long f
3795  }
3796  
3797  
3798 +int jfs_sync_flags(struct inode *inode, int flags, int vflags)
3799 +{
3800 +       inode->i_flags = flags;
3801 +       inode->i_vflags = vflags;
3802 +       jfs_get_inode_flags(JFS_IP(inode));
3803 +       inode->i_ctime = CURRENT_TIME_SEC;
3804 +       mark_inode_dirty(inode);
3805 +       return 0;
3806 +}
3807 +
3808  long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3809  {
3810         struct inode *inode = file_inode(filp);
3811 @@ -89,6 +100,11 @@ long jfs_ioctl(struct file *filp, unsign
3812                 if (!S_ISDIR(inode->i_mode))
3813                         flags &= ~JFS_DIRSYNC_FL;
3814  
3815 +               if (IS_BARRIER(inode)) {
3816 +                       vxwprintk_task(1, "messing with the barrier.");
3817 +                       return -EACCES;
3818 +               }
3819 +
3820                 /* Is it quota file? Do not allow user to mess with it */
3821                 if (IS_NOQUOTA(inode)) {
3822                         err = -EPERM;
3823 @@ -106,8 +122,8 @@ long jfs_ioctl(struct file *filp, unsign
3824                  * the relevant capability.
3825                  */
3826                 if ((oldflags & JFS_IMMUTABLE_FL) ||
3827 -                       ((flags ^ oldflags) &
3828 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
3829 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
3830 +                       JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
3831                         if (!capable(CAP_LINUX_IMMUTABLE)) {
3832                                 mutex_unlock(&inode->i_mutex);
3833                                 err = -EPERM;
3834 @@ -115,7 +131,7 @@ long jfs_ioctl(struct file *filp, unsign
3835                         }
3836                 }
3837  
3838 -               flags = flags & JFS_FL_USER_MODIFIABLE;
3839 +               flags &= JFS_FL_USER_MODIFIABLE;
3840                 flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
3841                 jfs_inode->mode2 = flags;
3842  
3843 diff -NurpP --minimal linux-3.9.4/fs/jfs/jfs_dinode.h linux-3.9.4-vs2.3.6.1/fs/jfs/jfs_dinode.h
3844 --- linux-3.9.4/fs/jfs/jfs_dinode.h     2012-12-11 03:30:57.000000000 +0000
3845 +++ linux-3.9.4-vs2.3.6.1/fs/jfs/jfs_dinode.h   2013-05-31 14:47:11.000000000 +0000
3846 @@ -161,9 +161,13 @@ struct dinode {
3847  
3848  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
3849  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
3850 +#define JFS_IXUNLINK_FL                0x08000000 /* Immutable invert on unlink */
3851  
3852 -#define JFS_FL_USER_VISIBLE    0x03F80000
3853 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
3854 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
3855 +#define JFS_COW_FL             0x20000000 /* Copy on Write marker */
3856 +
3857 +#define JFS_FL_USER_VISIBLE    0x07F80000
3858 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
3859  #define JFS_FL_INHERIT         0x03C80000
3860  
3861  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
3862 diff -NurpP --minimal linux-3.9.4/fs/jfs/jfs_filsys.h linux-3.9.4-vs2.3.6.1/fs/jfs/jfs_filsys.h
3863 --- linux-3.9.4/fs/jfs/jfs_filsys.h     2012-12-11 03:30:57.000000000 +0000
3864 +++ linux-3.9.4-vs2.3.6.1/fs/jfs/jfs_filsys.h   2013-05-31 14:47:11.000000000 +0000
3865 @@ -266,6 +266,7 @@
3866  #define JFS_NAME_MAX   255
3867  #define JFS_PATH_MAX   BPSIZE
3868  
3869 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
3870  
3871  /*
3872   *     file system state (superblock state)
3873 diff -NurpP --minimal linux-3.9.4/fs/jfs/jfs_imap.c linux-3.9.4-vs2.3.6.1/fs/jfs/jfs_imap.c
3874 --- linux-3.9.4/fs/jfs/jfs_imap.c       2012-12-11 03:30:57.000000000 +0000
3875 +++ linux-3.9.4-vs2.3.6.1/fs/jfs/jfs_imap.c     2013-05-31 14:47:11.000000000 +0000
3876 @@ -46,6 +46,7 @@
3877  #include <linux/pagemap.h>
3878  #include <linux/quotaops.h>
3879  #include <linux/slab.h>
3880 +#include <linux/vs_tag.h>
3881  
3882  #include "jfs_incore.h"
3883  #include "jfs_inode.h"
3884 @@ -3058,6 +3059,8 @@ static int copy_from_dinode(struct dinod
3885  {
3886         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
3887         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
3888 +       kuid_t uid;
3889 +       kgid_t gid;
3890  
3891         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
3892         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
3893 @@ -3078,14 +3081,19 @@ static int copy_from_dinode(struct dinod
3894         }
3895         set_nlink(ip, le32_to_cpu(dip->di_nlink));
3896  
3897 -       jfs_ip->saved_uid = make_kuid(&init_user_ns, le32_to_cpu(dip->di_uid));
3898 +       uid = make_kuid(&init_user_ns, le32_to_cpu(dip->di_uid));
3899 +       gid = make_kgid(&init_user_ns, le32_to_cpu(dip->di_gid));
3900 +       ip->i_tag = make_ktag(&init_user_ns,
3901 +               INOTAG_TAG(DX_TAG(ip), uid, gid, 0));
3902 +
3903 +       jfs_ip->saved_uid = INOTAG_UID(DX_TAG(ip), uid, gid);
3904         if (!uid_valid(sbi->uid))
3905                 ip->i_uid = jfs_ip->saved_uid;
3906         else {
3907                 ip->i_uid = sbi->uid;
3908         }
3909  
3910 -       jfs_ip->saved_gid = make_kgid(&init_user_ns, le32_to_cpu(dip->di_gid));
3911 +       jfs_ip->saved_gid = INOTAG_GID(DX_TAG(ip), uid, gid);
3912         if (!gid_valid(sbi->gid))
3913                 ip->i_gid = jfs_ip->saved_gid;
3914         else {
3915 @@ -3150,16 +3158,14 @@ static void copy_to_dinode(struct dinode
3916         dip->di_size = cpu_to_le64(ip->i_size);
3917         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
3918         dip->di_nlink = cpu_to_le32(ip->i_nlink);
3919 -       if (!uid_valid(sbi->uid))
3920 -               dip->di_uid = cpu_to_le32(i_uid_read(ip));
3921 -       else
3922 -               dip->di_uid =cpu_to_le32(from_kuid(&init_user_ns,
3923 -                                                  jfs_ip->saved_uid));
3924 -       if (!gid_valid(sbi->gid))
3925 -               dip->di_gid = cpu_to_le32(i_gid_read(ip));
3926 -       else
3927 -               dip->di_gid = cpu_to_le32(from_kgid(&init_user_ns,
3928 -                                                   jfs_ip->saved_gid));
3929 +       dip->di_uid = cpu_to_le32(from_kuid(&init_user_ns,
3930 +               TAGINO_UID(DX_TAG(ip),
3931 +               !uid_valid(sbi->uid) ? ip->i_uid : jfs_ip->saved_uid,
3932 +               ip->i_tag)));
3933 +       dip->di_gid = cpu_to_le32(from_kuid(&init_user_ns,
3934 +               TAGINO_GID(DX_TAG(ip),
3935 +               !gid_valid(sbi->gid) ? ip->i_gid : jfs_ip->saved_gid,
3936 +               ip->i_tag)));
3937         jfs_get_inode_flags(jfs_ip);
3938         /*
3939          * mode2 is only needed for storing the higher order bits.
3940 diff -NurpP --minimal linux-3.9.4/fs/jfs/jfs_inode.c linux-3.9.4-vs2.3.6.1/fs/jfs/jfs_inode.c
3941 --- linux-3.9.4/fs/jfs/jfs_inode.c      2012-12-11 03:30:57.000000000 +0000
3942 +++ linux-3.9.4-vs2.3.6.1/fs/jfs/jfs_inode.c    2013-05-31 14:47:11.000000000 +0000
3943 @@ -18,6 +18,7 @@
3944  
3945  #include <linux/fs.h>
3946  #include <linux/quotaops.h>
3947 +#include <linux/vs_tag.h>
3948  #include "jfs_incore.h"
3949  #include "jfs_inode.h"
3950  #include "jfs_filsys.h"
3951 @@ -30,29 +31,46 @@ void jfs_set_inode_flags(struct inode *i
3952  {
3953         unsigned int flags = JFS_IP(inode)->mode2;
3954  
3955 -       inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
3956 -               S_NOATIME | S_DIRSYNC | S_SYNC);
3957 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3958 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3959  
3960         if (flags & JFS_IMMUTABLE_FL)
3961                 inode->i_flags |= S_IMMUTABLE;
3962 +       if (flags & JFS_IXUNLINK_FL)
3963 +               inode->i_flags |= S_IXUNLINK;
3964 +
3965 +       if (flags & JFS_SYNC_FL)
3966 +               inode->i_flags |= S_SYNC;
3967         if (flags & JFS_APPEND_FL)
3968                 inode->i_flags |= S_APPEND;
3969         if (flags & JFS_NOATIME_FL)
3970                 inode->i_flags |= S_NOATIME;
3971         if (flags & JFS_DIRSYNC_FL)
3972                 inode->i_flags |= S_DIRSYNC;
3973 -       if (flags & JFS_SYNC_FL)
3974 -               inode->i_flags |= S_SYNC;
3975 +
3976 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3977 +
3978 +       if (flags & JFS_BARRIER_FL)
3979 +               inode->i_vflags |= V_BARRIER;
3980 +       if (flags & JFS_COW_FL)
3981 +               inode->i_vflags |= V_COW;
3982  }
3983  
3984  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
3985  {
3986         unsigned int flags = jfs_ip->vfs_inode.i_flags;
3987 +       unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
3988 +
3989 +       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
3990 +                          JFS_APPEND_FL | JFS_NOATIME_FL |
3991 +                          JFS_DIRSYNC_FL | JFS_SYNC_FL |
3992 +                          JFS_BARRIER_FL | JFS_COW_FL);
3993  
3994 -       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
3995 -                          JFS_DIRSYNC_FL | JFS_SYNC_FL);
3996         if (flags & S_IMMUTABLE)
3997                 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
3998 +       if (flags & S_IXUNLINK)
3999 +               jfs_ip->mode2 |= JFS_IXUNLINK_FL;
4000 +
4001         if (flags & S_APPEND)
4002                 jfs_ip->mode2 |= JFS_APPEND_FL;
4003         if (flags & S_NOATIME)
4004 @@ -61,6 +79,11 @@ void jfs_get_inode_flags(struct jfs_inod
4005                 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
4006         if (flags & S_SYNC)
4007                 jfs_ip->mode2 |= JFS_SYNC_FL;
4008 +
4009 +       if (vflags & V_BARRIER)
4010 +               jfs_ip->mode2 |= JFS_BARRIER_FL;
4011 +       if (vflags & V_COW)
4012 +               jfs_ip->mode2 |= JFS_COW_FL;
4013  }
4014  
4015  /*
4016 diff -NurpP --minimal linux-3.9.4/fs/jfs/jfs_inode.h linux-3.9.4-vs2.3.6.1/fs/jfs/jfs_inode.h
4017 --- linux-3.9.4/fs/jfs/jfs_inode.h      2012-12-11 03:30:57.000000000 +0000
4018 +++ linux-3.9.4-vs2.3.6.1/fs/jfs/jfs_inode.h    2013-05-31 14:47:11.000000000 +0000
4019 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
4020  extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
4021         int fh_len, int fh_type);
4022  extern void jfs_set_inode_flags(struct inode *);
4023 +extern int jfs_sync_flags(struct inode *, int, int);
4024  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
4025  extern int jfs_setattr(struct dentry *, struct iattr *);
4026  
4027 diff -NurpP --minimal linux-3.9.4/fs/jfs/namei.c linux-3.9.4-vs2.3.6.1/fs/jfs/namei.c
4028 --- linux-3.9.4/fs/jfs/namei.c  2012-12-11 03:30:57.000000000 +0000
4029 +++ linux-3.9.4-vs2.3.6.1/fs/jfs/namei.c        2013-05-31 14:47:11.000000000 +0000
4030 @@ -22,6 +22,7 @@
4031  #include <linux/ctype.h>
4032  #include <linux/quotaops.h>
4033  #include <linux/exportfs.h>
4034 +#include <linux/vs_tag.h>
4035  #include "jfs_incore.h"
4036  #include "jfs_superblock.h"
4037  #include "jfs_inode.h"
4038 @@ -1461,6 +1462,7 @@ static struct dentry *jfs_lookup(struct
4039                         jfs_err("jfs_lookup: iget failed on inum %d", (uint)inum);
4040         }
4041  
4042 +       dx_propagate_tag(nd, ip);
4043         return d_splice_alias(ip, dentry);
4044  }
4045  
4046 @@ -1525,6 +1527,7 @@ const struct inode_operations jfs_dir_in
4047  #ifdef CONFIG_JFS_POSIX_ACL
4048         .get_acl        = jfs_get_acl,
4049  #endif
4050 +       .sync_flags     = jfs_sync_flags,
4051  };
4052  
4053  const struct file_operations jfs_dir_operations = {
4054 diff -NurpP --minimal linux-3.9.4/fs/jfs/super.c linux-3.9.4-vs2.3.6.1/fs/jfs/super.c
4055 --- linux-3.9.4/fs/jfs/super.c  2013-05-31 13:45:24.000000000 +0000
4056 +++ linux-3.9.4-vs2.3.6.1/fs/jfs/super.c        2013-05-31 14:47:11.000000000 +0000
4057 @@ -199,7 +199,8 @@ enum {
4058         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
4059         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
4060         Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
4061 -       Opt_discard, Opt_nodiscard, Opt_discard_minblk
4062 +       Opt_discard, Opt_nodiscard, Opt_discard_minblk,
4063 +       Opt_tag, Opt_notag, Opt_tagid
4064  };
4065  
4066  static const match_table_t tokens = {
4067 @@ -209,6 +210,10 @@ static const match_table_t tokens = {
4068         {Opt_resize, "resize=%u"},
4069         {Opt_resize_nosize, "resize"},
4070         {Opt_errors, "errors=%s"},
4071 +       {Opt_tag, "tag"},
4072 +       {Opt_notag, "notag"},
4073 +       {Opt_tagid, "tagid=%u"},
4074 +       {Opt_tag, "tagxid"},
4075         {Opt_ignore, "noquota"},
4076         {Opt_ignore, "quota"},
4077         {Opt_usrquota, "usrquota"},
4078 @@ -385,7 +390,20 @@ static int parse_options(char *options,
4079                         }
4080                         break;
4081                 }
4082 -
4083 +#ifndef CONFIG_TAGGING_NONE
4084 +               case Opt_tag:
4085 +                       *flag |= JFS_TAGGED;
4086 +                       break;
4087 +               case Opt_notag:
4088 +                       *flag &= JFS_TAGGED;
4089 +                       break;
4090 +#endif
4091 +#ifdef CONFIG_PROPAGATE
4092 +               case Opt_tagid:
4093 +                       /* use args[0] */
4094 +                       *flag |= JFS_TAGGED;
4095 +                       break;
4096 +#endif
4097                 default:
4098                         printk("jfs: Unrecognized mount option \"%s\" "
4099                                         " or missing value\n", p);
4100 @@ -417,6 +435,12 @@ static int jfs_remount(struct super_bloc
4101                 return -EINVAL;
4102         }
4103  
4104 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
4105 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
4106 +                       sb->s_id);
4107 +               return -EINVAL;
4108 +       }
4109 +
4110         if (newLVSize) {
4111                 if (sb->s_flags & MS_RDONLY) {
4112                         pr_err("JFS: resize requires volume" \
4113 @@ -502,6 +526,9 @@ static int jfs_fill_super(struct super_b
4114  #ifdef CONFIG_JFS_POSIX_ACL
4115         sb->s_flags |= MS_POSIXACL;
4116  #endif
4117 +       /* map mount option tagxid */
4118 +       if (sbi->flag & JFS_TAGGED)
4119 +               sb->s_flags |= MS_TAGGED;
4120  
4121         if (newLVSize) {
4122                 pr_err("resize option for remount only\n");
4123 diff -NurpP --minimal linux-3.9.4/fs/libfs.c linux-3.9.4-vs2.3.6.1/fs/libfs.c
4124 --- linux-3.9.4/fs/libfs.c      2013-02-19 13:58:48.000000000 +0000
4125 +++ linux-3.9.4-vs2.3.6.1/fs/libfs.c    2013-05-31 14:47:11.000000000 +0000
4126 @@ -135,7 +135,8 @@ static inline unsigned char dt_type(stru
4127   * both impossible due to the lock on directory.
4128   */
4129  
4130 -int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
4131 +static inline int do_dcache_readdir_filter(struct file *filp,
4132 +       void *dirent, filldir_t filldir, int (*filter)(struct dentry *dentry))
4133  {
4134         struct dentry *dentry = filp->f_path.dentry;
4135         struct dentry *cursor = filp->private_data;
4136 @@ -166,6 +167,8 @@ int dcache_readdir(struct file * filp, v
4137                         for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
4138                                 struct dentry *next;
4139                                 next = list_entry(p, struct dentry, d_u.d_child);
4140 +                               if (filter && !filter(next))
4141 +                                       continue;
4142                                 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
4143                                 if (!simple_positive(next)) {
4144                                         spin_unlock(&next->d_lock);
4145 @@ -192,6 +195,17 @@ int dcache_readdir(struct file * filp, v
4146         return 0;
4147  }
4148  
4149 +int dcache_readdir(struct file *filp, void *dirent, filldir_t filldir)
4150 +{
4151 +       return do_dcache_readdir_filter(filp, dirent, filldir, NULL);
4152 +}
4153 +
4154 +int dcache_readdir_filter(struct file *filp, void *dirent, filldir_t filldir,
4155 +       int (*filter)(struct dentry *))
4156 +{
4157 +       return do_dcache_readdir_filter(filp, dirent, filldir, filter);
4158 +}
4159 +
4160  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
4161  {
4162         return -EISDIR;
4163 @@ -981,6 +995,7 @@ EXPORT_SYMBOL(dcache_dir_close);
4164  EXPORT_SYMBOL(dcache_dir_lseek);
4165  EXPORT_SYMBOL(dcache_dir_open);
4166  EXPORT_SYMBOL(dcache_readdir);
4167 +EXPORT_SYMBOL(dcache_readdir_filter);
4168  EXPORT_SYMBOL(generic_read_dir);
4169  EXPORT_SYMBOL(mount_pseudo);
4170  EXPORT_SYMBOL(simple_write_begin);
4171 diff -NurpP --minimal linux-3.9.4/fs/locks.c linux-3.9.4-vs2.3.6.1/fs/locks.c
4172 --- linux-3.9.4/fs/locks.c      2013-05-31 13:45:24.000000000 +0000
4173 +++ linux-3.9.4-vs2.3.6.1/fs/locks.c    2013-05-31 15:53:57.000000000 +0000
4174 @@ -126,6 +126,8 @@
4175  #include <linux/time.h>
4176  #include <linux/rcupdate.h>
4177  #include <linux/pid_namespace.h>
4178 +#include <linux/vs_base.h>
4179 +#include <linux/vs_limit.h>
4180  
4181  #include <asm/uaccess.h>
4182  
4183 @@ -184,11 +186,17 @@ static void locks_init_lock_heads(struct
4184  /* Allocate an empty lock structure. */
4185  struct file_lock *locks_alloc_lock(void)
4186  {
4187 -       struct file_lock *fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4188 +       struct file_lock *fl;
4189  
4190 -       if (fl)
4191 -               locks_init_lock_heads(fl);
4192 +       if (!vx_locks_avail(1))
4193 +               return NULL;
4194  
4195 +       fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4196 +
4197 +       if (fl) {
4198 +               locks_init_lock_heads(fl);
4199 +               fl->fl_xid = -1;
4200 +       }
4201         return fl;
4202  }
4203  EXPORT_SYMBOL_GPL(locks_alloc_lock);
4204 @@ -212,6 +220,7 @@ void locks_free_lock(struct file_lock *f
4205         BUG_ON(!list_empty(&fl->fl_block));
4206         BUG_ON(!list_empty(&fl->fl_link));
4207  
4208 +       vx_locks_dec(fl);
4209         locks_release_private(fl);
4210         kmem_cache_free(filelock_cache, fl);
4211  }
4212 @@ -221,6 +230,7 @@ void locks_init_lock(struct file_lock *f
4213  {
4214         memset(fl, 0, sizeof(struct file_lock));
4215         locks_init_lock_heads(fl);
4216 +       fl->fl_xid = -1;
4217  }
4218  
4219  EXPORT_SYMBOL(locks_init_lock);
4220 @@ -261,6 +271,7 @@ void locks_copy_lock(struct file_lock *n
4221         new->fl_file = fl->fl_file;
4222         new->fl_ops = fl->fl_ops;
4223         new->fl_lmops = fl->fl_lmops;
4224 +       new->fl_xid = fl->fl_xid;
4225  
4226         locks_copy_private(new, fl);
4227  }
4228 @@ -299,6 +310,11 @@ static int flock_make_lock(struct file *
4229         fl->fl_flags = FL_FLOCK;
4230         fl->fl_type = type;
4231         fl->fl_end = OFFSET_MAX;
4232 +
4233 +       vxd_assert(filp->f_xid == vx_current_xid(),
4234 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4235 +       fl->fl_xid = filp->f_xid;
4236 +       vx_locks_inc(fl);
4237         
4238         *lock = fl;
4239         return 0;
4240 @@ -438,6 +454,7 @@ static int lease_init(struct file *filp,
4241  
4242         fl->fl_owner = current->files;
4243         fl->fl_pid = current->tgid;
4244 +       fl->fl_xid = vx_current_xid();
4245  
4246         fl->fl_file = filp;
4247         fl->fl_flags = FL_LEASE;
4248 @@ -457,6 +474,11 @@ static struct file_lock *lease_alloc(str
4249         if (fl == NULL)
4250                 return ERR_PTR(error);
4251  
4252 +       fl->fl_xid = vx_current_xid();
4253 +       if (filp)
4254 +               vxd_assert(filp->f_xid == fl->fl_xid,
4255 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
4256 +       vx_locks_inc(fl);
4257         error = lease_init(filp, type, fl);
4258         if (error) {
4259                 locks_free_lock(fl);
4260 @@ -753,6 +775,7 @@ static int flock_lock_file(struct file *
4261                 lock_flocks();
4262         }
4263  
4264 +       new_fl->fl_xid = -1;
4265  find_conflict:
4266         for_each_lock(inode, before) {
4267                 struct file_lock *fl = *before;
4268 @@ -773,6 +796,7 @@ find_conflict:
4269                 goto out;
4270         locks_copy_lock(new_fl, request);
4271         locks_insert_lock(before, new_fl);
4272 +       vx_locks_inc(new_fl);
4273         new_fl = NULL;
4274         error = 0;
4275  
4276 @@ -783,7 +807,8 @@ out:
4277         return error;
4278  }
4279  
4280 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
4281 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
4282 +       struct file_lock *conflock, xid_t xid)
4283  {
4284         struct file_lock *fl;
4285         struct file_lock *new_fl = NULL;
4286 @@ -793,6 +818,8 @@ static int __posix_lock_file(struct inod
4287         struct file_lock **before;
4288         int error, added = 0;
4289  
4290 +       vxd_assert(xid == vx_current_xid(),
4291 +               "xid(%d) == current(%d)", xid, vx_current_xid());
4292         /*
4293          * We may need two file_lock structures for this operation,
4294          * so we get them in advance to avoid races.
4295 @@ -803,7 +830,11 @@ static int __posix_lock_file(struct inod
4296             (request->fl_type != F_UNLCK ||
4297              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
4298                 new_fl = locks_alloc_lock();
4299 +               new_fl->fl_xid = xid;
4300 +               vx_locks_inc(new_fl);
4301                 new_fl2 = locks_alloc_lock();
4302 +               new_fl2->fl_xid = xid;
4303 +               vx_locks_inc(new_fl2);
4304         }
4305  
4306         lock_flocks();
4307 @@ -1002,7 +1033,8 @@ static int __posix_lock_file(struct inod
4308  int posix_lock_file(struct file *filp, struct file_lock *fl,
4309                         struct file_lock *conflock)
4310  {
4311 -       return __posix_lock_file(file_inode(filp), fl, conflock);
4312 +       return __posix_lock_file(file_inode(filp),
4313 +               fl, conflock, filp->f_xid);
4314  }
4315  EXPORT_SYMBOL(posix_lock_file);
4316  
4317 @@ -1092,7 +1124,7 @@ int locks_mandatory_area(int read_write,
4318         fl.fl_end = offset + count - 1;
4319  
4320         for (;;) {
4321 -               error = __posix_lock_file(inode, &fl, NULL);
4322 +               error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
4323                 if (error != FILE_LOCK_DEFERRED)
4324                         break;
4325                 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
4326 @@ -1397,6 +1429,7 @@ int generic_add_lease(struct file *filp,
4327                 goto out;
4328  
4329         locks_insert_lock(before, lease);
4330 +       vx_locks_inc(lease);
4331         return 0;
4332  
4333  out:
4334 @@ -1836,6 +1869,11 @@ int fcntl_setlk(unsigned int fd, struct
4335         if (file_lock == NULL)
4336                 return -ENOLCK;
4337  
4338 +       vxd_assert(filp->f_xid == vx_current_xid(),
4339 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4340 +       file_lock->fl_xid = filp->f_xid;
4341 +       vx_locks_inc(file_lock);
4342 +
4343         /*
4344          * This might block, so we do it before checking the inode.
4345          */
4346 @@ -1954,6 +1992,11 @@ int fcntl_setlk64(unsigned int fd, struc
4347         if (file_lock == NULL)
4348                 return -ENOLCK;
4349  
4350 +       vxd_assert(filp->f_xid == vx_current_xid(),
4351 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4352 +       file_lock->fl_xid = filp->f_xid;
4353 +       vx_locks_inc(file_lock);
4354 +
4355         /*
4356          * This might block, so we do it before checking the inode.
4357          */
4358 @@ -2219,8 +2262,11 @@ static int locks_show(struct seq_file *f
4359  
4360         lock_get_status(f, fl, *((loff_t *)f->private), "");
4361  
4362 -       list_for_each_entry(bfl, &fl->fl_block, fl_block)
4363 +       list_for_each_entry(bfl, &fl->fl_block, fl_block) {
4364 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
4365 +                       continue;
4366                 lock_get_status(f, bfl, *((loff_t *)f->private), " ->");
4367 +       }
4368  
4369         return 0;
4370  }
4371 diff -NurpP --minimal linux-3.9.4/fs/mount.h linux-3.9.4-vs2.3.6.1/fs/mount.h
4372 --- linux-3.9.4/fs/mount.h      2013-02-19 13:58:48.000000000 +0000
4373 +++ linux-3.9.4-vs2.3.6.1/fs/mount.h    2013-05-31 14:47:11.000000000 +0000
4374 @@ -49,6 +49,7 @@ struct mount {
4375         int mnt_expiry_mark;            /* true if marked for expiry */
4376         int mnt_pinned;
4377         int mnt_ghosts;
4378 +       tag_t mnt_tag;                  /* tagging used for vfsmount */
4379  };
4380  
4381  #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
4382 diff -NurpP --minimal linux-3.9.4/fs/namei.c linux-3.9.4-vs2.3.6.1/fs/namei.c
4383 --- linux-3.9.4/fs/namei.c      2013-05-31 14:22:27.000000000 +0000
4384 +++ linux-3.9.4-vs2.3.6.1/fs/namei.c    2013-06-01 00:22:21.000000000 +0000
4385 @@ -34,6 +34,14 @@
4386  #include <linux/device_cgroup.h>
4387  #include <linux/fs_struct.h>
4388  #include <linux/posix_acl.h>
4389 +#include <linux/proc_fs.h>
4390 +#include <linux/vserver/inode.h>
4391 +#include <linux/vs_base.h>
4392 +#include <linux/vs_tag.h>
4393 +#include <linux/vs_cowbl.h>
4394 +#include <linux/vs_device.h>
4395 +#include <linux/vs_context.h>
4396 +#include <linux/pid_namespace.h>
4397  #include <asm/uaccess.h>
4398  
4399  #include "internal.h"
4400 @@ -266,6 +274,89 @@ static int check_acl(struct inode *inode
4401         return -EAGAIN;
4402  }
4403  
4404 +static inline int dx_barrier(const struct inode *inode)
4405 +{
4406 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
4407 +               vxwprintk_task(1, "did hit the barrier.");
4408 +               return 1;
4409 +       }
4410 +       return 0;
4411 +}
4412 +
4413 +static int __dx_permission(const struct inode *inode, int mask)
4414 +{
4415 +       if (dx_barrier(inode))
4416 +               return -EACCES;
4417 +
4418 +       if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
4419 +               /* devpts is xid tagged */
4420 +               if (S_ISDIR(inode->i_mode) ||
4421 +                   vx_check((xid_t)i_tag_read(inode), VS_IDENT | VS_WATCH_P))
4422 +                       return 0;
4423 +
4424 +               /* just pretend we didn't find anything */
4425 +               return -ENOENT;
4426 +       }
4427 +       else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
4428 +               struct proc_dir_entry *de = PDE(inode);
4429 +
4430 +               if (de && !vx_hide_check(0, de->vx_flags))
4431 +                       goto out;
4432 +
4433 +               if ((mask & (MAY_WRITE | MAY_APPEND))) {
4434 +                       struct pid *pid;
4435 +                       struct task_struct *tsk;
4436 +
4437 +                       if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
4438 +                           vx_flags(VXF_STATE_SETUP, 0))
4439 +                               return 0;
4440 +
4441 +                       pid = PROC_I(inode)->pid;
4442 +                       if (!pid)
4443 +                               goto out;
4444 +
4445 +                       rcu_read_lock();
4446 +                       tsk = pid_task(pid, PIDTYPE_PID);
4447 +                       vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
4448 +                                 tsk, (tsk ? vx_task_xid(tsk) : 0));
4449 +                       if (tsk &&
4450 +                               vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P)) {
4451 +                               rcu_read_unlock();
4452 +                               return 0;
4453 +                       }
4454 +                       rcu_read_unlock();
4455 +               }
4456 +               else {
4457 +                       /* FIXME: Should we block some entries here? */
4458 +                       return 0;
4459 +               }
4460 +       }
4461 +       else {
4462 +               if (dx_notagcheck(inode->i_sb) ||
4463 +                   dx_check((xid_t)i_tag_read(inode),
4464 +                       DX_HOSTID | DX_ADMIN | DX_WATCH | DX_IDENT))
4465 +                       return 0;
4466 +       }
4467 +
4468 +out:
4469 +       return -EACCES;
4470 +}
4471 +
4472 +int dx_permission(const struct inode *inode, int mask)
4473 +{
4474 +       int ret = __dx_permission(inode, mask);
4475 +       if (unlikely(ret)) {
4476 +#ifndef        CONFIG_VSERVER_WARN_DEVPTS
4477 +               if (inode->i_sb->s_magic != DEVPTS_SUPER_MAGIC)
4478 +#endif
4479 +                   vxwprintk_task(1,
4480 +                       "denied [0x%x] access to inode %s:%p[#%d,%lu]",
4481 +                       mask, inode->i_sb->s_id, inode, inode->i_tag,
4482 +                       inode->i_ino);
4483 +       }
4484 +       return ret;
4485 +}
4486 +
4487  /*
4488   * This does the basic permission checking
4489   */
4490 @@ -388,10 +479,14 @@ int __inode_permission(struct inode *ino
4491                 /*
4492                  * Nobody gets write access to an immutable file.
4493                  */
4494 -               if (IS_IMMUTABLE(inode))
4495 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
4496                         return -EACCES;
4497         }
4498  
4499 +       retval = dx_permission(inode, mask);
4500 +       if (retval)
4501 +               return retval;
4502 +
4503         retval = do_inode_permission(inode, mask);
4504         if (retval)
4505                 return retval;
4506 @@ -1238,7 +1333,8 @@ static void follow_dotdot(struct nameida
4507  
4508                 if (nd->path.dentry == nd->root.dentry &&
4509                     nd->path.mnt == nd->root.mnt) {
4510 -                       break;
4511 +                       /* for sane '/' avoid follow_mount() */
4512 +                       return;
4513                 }
4514                 if (nd->path.dentry != nd->path.mnt->mnt_root) {
4515                         /* rare case of legitimate dget_parent()... */
4516 @@ -1383,6 +1479,9 @@ static int lookup_fast(struct nameidata
4517                                 goto unlazy;
4518                         }
4519                 }
4520 +
4521 +               /* FIXME: check dx permission */
4522 +
4523                 path->mnt = mnt;
4524                 path->dentry = dentry;
4525                 if (unlikely(!__follow_mount_rcu(nd, path, inode)))
4526 @@ -1413,6 +1512,8 @@ unlazy:
4527                 }
4528         }
4529  
4530 +       /* FIXME: check dx permission */
4531 +
4532         path->mnt = mnt;
4533         path->dentry = dentry;
4534         err = follow_managed(path, nd->flags);
4535 @@ -2237,7 +2338,7 @@ static int may_delete(struct inode *dir,
4536         if (IS_APPEND(dir))
4537                 return -EPERM;
4538         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
4539 -           IS_IMMUTABLE(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4540 +               IS_IXORUNLINK(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4541                 return -EPERM;
4542         if (isdir) {
4543                 if (!S_ISDIR(victim->d_inode->i_mode))
4544 @@ -2316,19 +2417,25 @@ int vfs_create(struct inode *dir, struct
4545                 bool want_excl)
4546  {
4547         int error = may_create(dir, dentry);
4548 -       if (error)
4549 +       if (error) {
4550 +               vxdprintk(VXD_CBIT(misc, 3), "may_create failed with %d", error);
4551                 return error;
4552 +       }
4553  
4554         if (!dir->i_op->create)
4555                 return -EACCES; /* shouldn't it be ENOSYS? */
4556         mode &= S_IALLUGO;
4557         mode |= S_IFREG;
4558         error = security_inode_create(dir, dentry, mode);
4559 -       if (error)
4560 +       if (error) {
4561 +               vxdprintk(VXD_CBIT(misc, 3), "security_inode_create failed with %d", error);
4562                 return error;
4563 +       }
4564         error = dir->i_op->create(dir, dentry, mode, want_excl);
4565         if (!error)
4566                 fsnotify_create(dir, dentry);
4567 +       else
4568 +               vxdprintk(VXD_CBIT(misc, 3), "i_op->create failed with %d", error);
4569         return error;
4570  }
4571  
4572 @@ -2363,6 +2470,15 @@ static int may_open(struct path *path, i
4573                 break;
4574         }
4575  
4576 +#ifdef CONFIG_VSERVER_COWBL
4577 +       if (IS_COW(inode) &&
4578 +               ((flag & O_ACCMODE) != O_RDONLY)) {
4579 +               if (IS_COW_LINK(inode))
4580 +                       return -EMLINK;
4581 +               inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
4582 +               mark_inode_dirty(inode);
4583 +       }
4584 +#endif
4585         error = inode_permission(inode, acc_mode);
4586         if (error)
4587                 return error;
4588 @@ -2865,6 +2981,16 @@ finish_open:
4589         }
4590  finish_open_created:
4591         error = may_open(&nd->path, acc_mode, open_flag);
4592 +#ifdef CONFIG_VSERVER_COWBL
4593 +       if (error == -EMLINK) {
4594 +               struct dentry *dentry;
4595 +               dentry = cow_break_link(name->name);
4596 +               if (IS_ERR(dentry))
4597 +                       error = PTR_ERR(dentry);
4598 +               else
4599 +                       dput(dentry);
4600 +       }
4601 +#endif
4602         if (error)
4603                 goto out;
4604         file->f_path.mnt = nd->path.mnt;
4605 @@ -2929,6 +3055,7 @@ static struct file *path_openat(int dfd,
4606         int opened = 0;
4607         int error;
4608  
4609 +restart:
4610         file = get_empty_filp();
4611         if (IS_ERR(file))
4612                 return file;
4613 @@ -2965,6 +3092,16 @@ static struct file *path_openat(int dfd,
4614                 error = do_last(nd, &path, file, op, &opened, pathname);
4615                 put_link(nd, &link, cookie);
4616         }
4617 +
4618 +#ifdef CONFIG_VSERVER_COWBL
4619 +       if (error == -EMLINK) {
4620 +               if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4621 +                       path_put(&nd->root);
4622 +               if (base)
4623 +                       fput(base);
4624 +               goto restart;
4625 +       }
4626 +#endif
4627  out:
4628         if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4629                 path_put(&nd->root);
4630 @@ -3079,6 +3216,11 @@ struct dentry *kern_path_create(int dfd,
4631                 goto fail;
4632         }
4633         *path = nd.path;
4634 +       vxdprintk(VXD_CBIT(misc, 3), "kern_path_create path.dentry = %p (%.*s), dentry = %p (%.*s), d_inode = %p",
4635 +               path->dentry, path->dentry->d_name.len,
4636 +               path->dentry->d_name.name, dentry,
4637 +               dentry->d_name.len, dentry->d_name.name,
4638 +               path->dentry->d_inode);
4639         return dentry;
4640  fail:
4641         dput(dentry);
4642 @@ -3573,7 +3715,7 @@ int vfs_link(struct dentry *old_dentry,
4643         /*
4644          * A link to an append-only or immutable file cannot be created.
4645          */
4646 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
4647 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
4648                 return -EPERM;
4649         if (!dir->i_op->link)
4650                 return -EPERM;
4651 @@ -3976,6 +4118,286 @@ int vfs_follow_link(struct nameidata *nd
4652         return __vfs_follow_link(nd, link);
4653  }
4654  
4655 +
4656 +#ifdef CONFIG_VSERVER_COWBL
4657 +
4658 +static inline
4659 +long do_cow_splice(struct file *in, struct file *out, size_t len)
4660 +{
4661 +       loff_t ppos = 0;
4662 +
4663 +       return do_splice_direct(in, &ppos, out, len, 0);
4664 +}
4665 +
4666 +struct dentry *cow_break_link(const char *pathname)
4667 +{
4668 +       int ret, mode, pathlen, redo = 0, drop = 1;
4669 +       struct nameidata old_nd, dir_nd;
4670 +       struct path dir_path, *old_path, *new_path;
4671 +       struct dentry *dir, *old_dentry, *new_dentry = NULL;
4672 +       struct file *old_file;
4673 +       struct file *new_file;
4674 +       char *to, *path, pad='\251';
4675 +       loff_t size;
4676 +
4677 +       vxdprintk(VXD_CBIT(misc, 1),
4678 +               "cow_break_link(" VS_Q("%s") ")", pathname);
4679 +
4680 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
4681 +       ret = -ENOMEM;
4682 +       if (!path)
4683 +               goto out;
4684 +
4685 +       /* old_nd.path will have refs to dentry and mnt */
4686 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4687 +       vxdprintk(VXD_CBIT(misc, 2),
4688 +               "do_path_lookup(old): %d", ret);
4689 +       if (ret < 0)
4690 +               goto out_free_path;
4691 +
4692 +       /* dentry/mnt refs handed over to old_path */
4693 +       old_path = &old_nd.path;
4694 +       /* no explicit reference for old_dentry here */
4695 +       old_dentry = old_path->dentry;
4696 +
4697 +       mode = old_dentry->d_inode->i_mode;
4698 +       to = d_path(old_path, path, PATH_MAX-2);
4699 +       pathlen = strlen(to);
4700 +       vxdprintk(VXD_CBIT(misc, 2),
4701 +               "old path " VS_Q("%s") " [%p:" VS_Q("%.*s") ":%d]", to,
4702 +               old_dentry,
4703 +               old_dentry->d_name.len, old_dentry->d_name.name,
4704 +               old_dentry->d_name.len);
4705 +
4706 +       to[pathlen + 1] = 0;
4707 +retry:
4708 +       new_dentry = NULL;
4709 +       to[pathlen] = pad--;
4710 +       ret = -ELOOP;
4711 +       if (pad <= '\240')
4712 +               goto out_rel_old;
4713 +
4714 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy " VS_Q("%s"), to);
4715 +
4716 +       /* dir_nd.path will have refs to dentry and mnt */
4717 +       ret = do_path_lookup(AT_FDCWD, to,
4718 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
4719 +       vxdprintk(VXD_CBIT(misc, 2), "do_path_lookup(new): %d", ret);
4720 +       if (ret < 0)
4721 +               goto retry;
4722 +
4723 +       /* this puppy downs the dir inode mutex if successful.
4724 +          dir_path will hold refs to dentry and mnt and
4725 +          we'll have write access to the mnt */
4726 +       new_dentry = kern_path_create(AT_FDCWD, to, &dir_path, 0);
4727 +       if (!new_dentry || IS_ERR(new_dentry)) {
4728 +               path_put(&dir_nd.path);
4729 +               vxdprintk(VXD_CBIT(misc, 2),
4730 +                       "kern_path_create(new) failed with %ld",
4731 +                       PTR_ERR(new_dentry));
4732 +               goto retry;
4733 +       }
4734 +       vxdprintk(VXD_CBIT(misc, 2),
4735 +               "kern_path_create(new): %p [" VS_Q("%.*s") ":%d]",
4736 +               new_dentry,
4737 +               new_dentry->d_name.len, new_dentry->d_name.name,
4738 +               new_dentry->d_name.len);
4739 +
4740 +       /* take a reference on new_dentry */
4741 +       dget(new_dentry);
4742 +
4743 +       /* dentry/mnt refs handed over to new_path */
4744 +       new_path = &dir_path;
4745 +
4746 +       /* dentry for old/new dir */
4747 +       dir = dir_nd.path.dentry;
4748 +
4749 +       /* give up reference on dir */
4750 +       dput(new_path->dentry);
4751 +
4752 +       /* new_dentry already has a reference */
4753 +       new_path->dentry = new_dentry;
4754 +
4755 +       ret = vfs_create(dir->d_inode, new_dentry, mode, 1);
4756 +       vxdprintk(VXD_CBIT(misc, 2),
4757 +               "vfs_create(new): %d", ret);
4758 +       if (ret == -EEXIST) {
4759 +               path_put(&dir_nd.path);
4760 +               mutex_unlock(&dir->d_inode->i_mutex);
4761 +               mnt_drop_write(new_path->mnt);
4762 +               path_put(new_path);
4763 +               new_dentry = NULL;
4764 +               goto retry;
4765 +       }
4766 +       else if (ret < 0)
4767 +               goto out_unlock_new;
4768 +
4769 +       /* drop out early, ret passes ENOENT */
4770 +       ret = -ENOENT;
4771 +       if ((redo = d_unhashed(old_dentry)))
4772 +               goto out_unlock_new;
4773 +
4774 +       /* doesn't change refs for old_path */
4775 +       old_file = dentry_open(old_path, O_RDONLY, current_cred());
4776 +       vxdprintk(VXD_CBIT(misc, 2),
4777 +               "dentry_open(old): %p", old_file);
4778 +       if (IS_ERR(old_file)) {
4779 +               ret = PTR_ERR(old_file);
4780 +               goto out_unlock_new;
4781 +       }
4782 +
4783 +       /* doesn't change refs for new_path */
4784 +       new_file = dentry_open(new_path, O_WRONLY, current_cred());
4785 +       vxdprintk(VXD_CBIT(misc, 2),
4786 +               "dentry_open(new): %p", new_file);
4787 +       if (IS_ERR(new_file)) {
4788 +               ret = PTR_ERR(new_file);
4789 +               goto out_fput_old;
4790 +       }
4791 +
4792 +       /* unlock the inode mutex from kern_path_create() */
4793 +       mutex_unlock(&dir->d_inode->i_mutex);
4794 +
4795 +       /* drop write access to mnt */
4796 +       mnt_drop_write(new_path->mnt);
4797 +
4798 +       drop = 0;
4799 +
4800 +       size = i_size_read(old_file->f_dentry->d_inode);
4801 +       ret = do_cow_splice(old_file, new_file, size);
4802 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
4803 +       if (ret < 0) {
4804 +               goto out_fput_both;
4805 +       } else if (ret < size) {
4806 +               ret = -ENOSPC;
4807 +               goto out_fput_both;
4808 +       } else {
4809 +               struct inode *old_inode = old_dentry->d_inode;
4810 +               struct inode *new_inode = new_dentry->d_inode;
4811 +               struct iattr attr = {
4812 +                       .ia_uid = old_inode->i_uid,
4813 +                       .ia_gid = old_inode->i_gid,
4814 +                       .ia_valid = ATTR_UID | ATTR_GID
4815 +                       };
4816 +
4817 +               setattr_copy(new_inode, &attr);
4818 +               mark_inode_dirty(new_inode);
4819 +       }
4820 +
4821 +       /* lock rename mutex */
4822 +       mutex_lock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4823 +
4824 +       /* drop out late */
4825 +       ret = -ENOENT;
4826 +       if ((redo = d_unhashed(old_dentry)))
4827 +               goto out_unlock;
4828 +
4829 +       vxdprintk(VXD_CBIT(misc, 2),
4830 +               "vfs_rename: [" VS_Q("%*s") ":%d] -> [" VS_Q("%*s") ":%d]",
4831 +               new_dentry->d_name.len, new_dentry->d_name.name,
4832 +               new_dentry->d_name.len,
4833 +               old_dentry->d_name.len, old_dentry->d_name.name,
4834 +               old_dentry->d_name.len);
4835 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_dentry,
4836 +               old_dentry->d_parent->d_inode, old_dentry);
4837 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
4838 +
4839 +out_unlock:
4840 +       mutex_unlock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4841 +
4842 +out_fput_both:
4843 +       vxdprintk(VXD_CBIT(misc, 3),
4844 +               "fput(new_file=%p[#%ld])", new_file,
4845 +               atomic_long_read(&new_file->f_count));
4846 +       fput(new_file);
4847 +
4848 +out_fput_old:
4849 +       vxdprintk(VXD_CBIT(misc, 3),
4850 +               "fput(old_file=%p[#%ld])", old_file,
4851 +               atomic_long_read(&old_file->f_count));
4852 +       fput(old_file);
4853 +
4854 +out_unlock_new:
4855 +       /* drop references from dir_nd.path */
4856 +       path_put(&dir_nd.path);
4857 +
4858 +       if (drop) {
4859 +               /* unlock the inode mutex from kern_path_create() */
4860 +               mutex_unlock(&dir->d_inode->i_mutex);
4861 +
4862 +               /* drop write access to mnt */
4863 +               mnt_drop_write(new_path->mnt);
4864 +       }
4865 +
4866 +       if (!ret)
4867 +               goto out_redo;
4868 +
4869 +       /* error path cleanup */
4870 +       vfs_unlink(dir->d_inode, new_dentry);
4871 +
4872 +out_redo:
4873 +       if (!redo)
4874 +               goto out_rel_both;
4875 +
4876 +       /* lookup dentry once again
4877 +          old_nd.path will be freed as old_path in out_rel_old */
4878 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4879 +       if (ret)
4880 +               goto out_rel_both;
4881 +
4882 +       /* drop reference on new_dentry */
4883 +       dput(new_dentry);
4884 +       new_dentry = old_path->dentry;
4885 +       dget(new_dentry);
4886 +       vxdprintk(VXD_CBIT(misc, 2),
4887 +               "do_path_lookup(redo): %p [" VS_Q("%.*s") ":%d]",
4888 +               new_dentry,
4889 +               new_dentry->d_name.len, new_dentry->d_name.name,
4890 +               new_dentry->d_name.len);
4891 +
4892 +out_rel_both:
4893 +       if (new_path)
4894 +               path_put(new_path);
4895 +out_rel_old:
4896 +       path_put(old_path);
4897 +out_free_path:
4898 +       kfree(path);
4899 +out:
4900 +       if (ret) {
4901 +               dput(new_dentry);
4902 +               new_dentry = ERR_PTR(ret);
4903 +       }
4904 +       vxdprintk(VXD_CBIT(misc, 3),
4905 +               "cow_break_link returning with %p", new_dentry);
4906 +       return new_dentry;
4907 +}
4908 +
4909 +#endif
4910 +
4911 +int    vx_info_mnt_namespace(struct mnt_namespace *ns, char *buffer)
4912 +{
4913 +       struct path path;
4914 +       struct vfsmount *vmnt;
4915 +       char *pstr, *root;
4916 +       int length = 0;
4917 +
4918 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
4919 +       if (!pstr)
4920 +               return 0;
4921 +
4922 +       vmnt = &ns->root->mnt;
4923 +       path.mnt = vmnt;
4924 +       path.dentry = vmnt->mnt_root;
4925 +       root = d_path(&path, pstr, PATH_MAX - 2);
4926 +       length = sprintf(buffer + length,
4927 +               "Namespace:\t%p [#%u]\n"
4928 +               "RootPath:\t%s\n",
4929 +               ns, atomic_read(&ns->count),
4930 +               root);
4931 +       kfree(pstr);
4932 +       return length;
4933 +}
4934 +
4935  /* get the link contents into pagecache */
4936  static char *page_getlink(struct dentry * dentry, struct page **ppage)
4937  {
4938 @@ -4099,3 +4521,4 @@ EXPORT_SYMBOL(vfs_symlink);
4939  EXPORT_SYMBOL(vfs_unlink);
4940  EXPORT_SYMBOL(dentry_unhash);
4941  EXPORT_SYMBOL(generic_readlink);
4942 +EXPORT_SYMBOL(vx_info_mnt_namespace);
4943 diff -NurpP --minimal linux-3.9.4/fs/namespace.c linux-3.9.4-vs2.3.6.1/fs/namespace.c
4944 --- linux-3.9.4/fs/namespace.c  2013-05-31 14:22:27.000000000 +0000
4945 +++ linux-3.9.4-vs2.3.6.1/fs/namespace.c        2013-05-31 18:47:18.000000000 +0000
4946 @@ -22,6 +22,11 @@
4947  #include <linux/fsnotify.h>    /* fsnotify_vfsmount_delete */
4948  #include <linux/uaccess.h>
4949  #include <linux/proc_fs.h>
4950 +#include <linux/vs_base.h>
4951 +#include <linux/vs_context.h>
4952 +#include <linux/vs_tag.h>
4953 +#include <linux/vserver/space.h>
4954 +#include <linux/vserver/global.h>
4955  #include "pnode.h"
4956  #include "internal.h"
4957  
4958 @@ -751,6 +756,10 @@ vfs_kern_mount(struct file_system_type *
4959         if (!type)
4960                 return ERR_PTR(-ENODEV);
4961  
4962 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
4963 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
4964 +               return ERR_PTR(-EPERM);
4965 +
4966         mnt = alloc_vfsmnt(name);
4967         if (!mnt)
4968                 return ERR_PTR(-ENOMEM);
4969 @@ -807,6 +816,7 @@ static struct mount *clone_mnt(struct mo
4970         mnt->mnt.mnt_root = dget(root);
4971         mnt->mnt_mountpoint = mnt->mnt.mnt_root;
4972         mnt->mnt_parent = mnt;
4973 +               mnt->mnt_tag = old->mnt_tag;
4974         br_write_lock(&vfsmount_lock);
4975         list_add_tail(&mnt->mnt_instance, &sb->s_mounts);
4976         br_write_unlock(&vfsmount_lock);
4977 @@ -1639,6 +1649,7 @@ static int do_change_type(struct path *p
4978                 if (err)
4979                         goto out_unlock;
4980         }
4981 +       // mnt->mnt_flags = mnt_flags;
4982  
4983         br_write_lock(&vfsmount_lock);
4984         for (m = mnt; m; m = (recurse ? next_mnt(m, mnt) : NULL))
4985 @@ -1654,12 +1665,14 @@ static int do_change_type(struct path *p
4986   * do loopback mount.
4987   */
4988  static int do_loopback(struct path *path, const char *old_name,
4989 -                               int recurse)
4990 +       tag_t tag, unsigned long flags, int mnt_flags)
4991  {
4992         LIST_HEAD(umount_list);
4993         struct path old_path;
4994         struct mount *mnt = NULL, *old;
4995 +       int recurse = flags & MS_REC;
4996         int err;
4997 +
4998         if (!old_name || !*old_name)
4999                 return -EINVAL;
5000         err = kern_path(old_name, LOOKUP_FOLLOW|LOOKUP_AUTOMOUNT, &old_path);
5001 @@ -1733,7 +1746,7 @@ static int change_mount_flags(struct vfs
5002   * on it - tough luck.
5003   */
5004  static int do_remount(struct path *path, int flags, int mnt_flags,
5005 -                     void *data)
5006 +       void *data, xid_t xid)
5007  {
5008         int err;
5009         struct super_block *sb = path->mnt->mnt_sb;
5010 @@ -2046,7 +2059,6 @@ void mark_mounts_for_expiry(struct list_
5011         }
5012         br_write_unlock(&vfsmount_lock);
5013         up_write(&namespace_sem);
5014 -
5015         release_mounts(&umounts);
5016  }
5017  
5018 @@ -2218,6 +2230,7 @@ long do_mount(const char *dev_name, cons
5019         struct path path;
5020         int retval = 0;
5021         int mnt_flags = 0;
5022 +       tag_t tag = 0;
5023  
5024         /* Discard magic */
5025         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
5026 @@ -2247,6 +2260,12 @@ long do_mount(const char *dev_name, cons
5027         if (!(flags & MS_NOATIME))
5028                 mnt_flags |= MNT_RELATIME;
5029  
5030 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
5031 +               /* FIXME: bind and re-mounts get the tag flag? */
5032 +               if (flags & (MS_BIND|MS_REMOUNT))
5033 +                       flags |= MS_TAGID;
5034 +       }
5035 +
5036         /* Separate the per-mountpoint flags */
5037         if (flags & MS_NOSUID)
5038                 mnt_flags |= MNT_NOSUID;
5039 @@ -2263,15 +2282,17 @@ long do_mount(const char *dev_name, cons
5040         if (flags & MS_RDONLY)
5041                 mnt_flags |= MNT_READONLY;
5042  
5043 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_DEV_MOUNT))
5044 +               mnt_flags |= MNT_NODEV;
5045         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_BORN |
5046                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
5047                    MS_STRICTATIME);
5048  
5049         if (flags & MS_REMOUNT)
5050                 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
5051 -                                   data_page);
5052 +                                   data_page, tag);
5053         else if (flags & MS_BIND)
5054 -               retval = do_loopback(&path, dev_name, flags & MS_REC);
5055 +               retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
5056         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
5057                 retval = do_change_type(&path, flags);
5058         else if (flags & MS_MOVE)
5059 @@ -2380,6 +2401,7 @@ static struct mnt_namespace *dup_mnt_ns(
5060                 q = next_mnt(q, new);
5061         }
5062         up_write(&namespace_sem);
5063 +       atomic_inc(&vs_global_mnt_ns);
5064  
5065         if (rootmnt)
5066                 mntput(rootmnt);
5067 @@ -2575,9 +2597,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
5068         error = -EINVAL;
5069         new_mnt = real_mount(new.mnt);
5070         root_mnt = real_mount(root.mnt);
5071 -       if (IS_MNT_SHARED(real_mount(old.mnt)) ||
5072 +       if ((IS_MNT_SHARED(real_mount(old.mnt)) ||
5073                 IS_MNT_SHARED(new_mnt->mnt_parent) ||
5074 -               IS_MNT_SHARED(root_mnt->mnt_parent))
5075 +               IS_MNT_SHARED(root_mnt->mnt_parent)) &&
5076 +               !vx_flags(VXF_STATE_SETUP, 0))
5077                 goto out4;
5078         if (!check_mnt(root_mnt) || !check_mnt(new_mnt))
5079                 goto out4;
5080 @@ -2703,6 +2726,7 @@ void put_mnt_ns(struct mnt_namespace *ns
5081         br_write_unlock(&vfsmount_lock);
5082         up_write(&namespace_sem);
5083         release_mounts(&umount_list);
5084 +       atomic_dec(&vs_global_mnt_ns);
5085         free_mnt_ns(ns);
5086  }
5087  
5088 diff -NurpP --minimal linux-3.9.4/fs/nfs/client.c linux-3.9.4-vs2.3.6.1/fs/nfs/client.c
5089 --- linux-3.9.4/fs/nfs/client.c 2013-05-31 13:45:24.000000000 +0000
5090 +++ linux-3.9.4-vs2.3.6.1/fs/nfs/client.c       2013-05-31 14:47:11.000000000 +0000
5091 @@ -682,6 +682,9 @@ int nfs_init_server_rpcclient(struct nfs
5092         if (server->flags & NFS_MOUNT_SOFT)
5093                 server->client->cl_softrtry = 1;
5094  
5095 +       server->client->cl_tag = 0;
5096 +       if (server->flags & NFS_MOUNT_TAGGED)
5097 +               server->client->cl_tag = 1;
5098         return 0;
5099  }
5100  EXPORT_SYMBOL_GPL(nfs_init_server_rpcclient);
5101 @@ -861,6 +864,10 @@ static void nfs_server_set_fsinfo(struct
5102                 server->acdirmin = server->acdirmax = 0;
5103         }
5104  
5105 +       /* FIXME: needs fsinfo
5106 +       if (server->flags & NFS_MOUNT_TAGGED)
5107 +               sb->s_flags |= MS_TAGGED;       */
5108 +
5109         server->maxfilesize = fsinfo->maxfilesize;
5110  
5111         server->time_delta = fsinfo->time_delta;
5112 diff -NurpP --minimal linux-3.9.4/fs/nfs/dir.c linux-3.9.4-vs2.3.6.1/fs/nfs/dir.c
5113 --- linux-3.9.4/fs/nfs/dir.c    2013-05-31 13:45:24.000000000 +0000
5114 +++ linux-3.9.4-vs2.3.6.1/fs/nfs/dir.c  2013-05-31 14:47:11.000000000 +0000
5115 @@ -36,6 +36,7 @@
5116  #include <linux/sched.h>
5117  #include <linux/kmemleak.h>
5118  #include <linux/xattr.h>
5119 +#include <linux/vs_tag.h>
5120  
5121  #include "delegation.h"
5122  #include "iostat.h"
5123 @@ -1300,6 +1301,7 @@ struct dentry *nfs_lookup(struct inode *
5124         /* Success: notify readdir to use READDIRPLUS */
5125         nfs_advise_use_readdirplus(dir);
5126  
5127 +       dx_propagate_tag(nd, inode);
5128  no_entry:
5129         res = d_materialise_unique(dentry, inode);
5130         if (res != NULL) {
5131 diff -NurpP --minimal linux-3.9.4/fs/nfs/inode.c linux-3.9.4-vs2.3.6.1/fs/nfs/inode.c
5132 --- linux-3.9.4/fs/nfs/inode.c  2013-05-31 13:45:24.000000000 +0000
5133 +++ linux-3.9.4-vs2.3.6.1/fs/nfs/inode.c        2013-05-31 20:37:45.000000000 +0000
5134 @@ -39,6 +39,7 @@
5135  #include <linux/compat.h>
5136  #include <linux/freezer.h>
5137  #include <linux/crc32.h>
5138 +#include <linux/vs_tag.h>
5139  
5140  #include <asm/uaccess.h>
5141  
5142 @@ -290,6 +291,8 @@ nfs_fhget(struct super_block *sb, struct
5143         if (inode->i_state & I_NEW) {
5144                 struct nfs_inode *nfsi = NFS_I(inode);
5145                 unsigned long now = jiffies;
5146 +               uid_t uid;
5147 +               gid_t gid;
5148  
5149                 /* We set i_ino for the few things that still rely on it,
5150                  * such as stat(2) */
5151 @@ -334,8 +337,8 @@ nfs_fhget(struct super_block *sb, struct
5152                 inode->i_version = 0;
5153                 inode->i_size = 0;
5154                 clear_nlink(inode);
5155 -               inode->i_uid = make_kuid(&init_user_ns, -2);
5156 -               inode->i_gid = make_kgid(&init_user_ns, -2);
5157 +               uid = make_kuid(&init_user_ns, -2);
5158 +               gid = make_kgid(&init_user_ns, -2);
5159                 inode->i_blocks = 0;
5160                 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
5161                 nfsi->write_io = 0;
5162 @@ -369,11 +372,11 @@ nfs_fhget(struct super_block *sb, struct
5163                 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
5164                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5165                 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
5166 -                       inode->i_uid = fattr->uid;
5167 +                       uid = fattr->uid;
5168                 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
5169                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5170                 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
5171 -                       inode->i_gid = fattr->gid;
5172 +                       gid = fattr->gid;
5173                 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
5174                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5175                 if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED)
5176 @@ -384,6 +387,11 @@ nfs_fhget(struct super_block *sb, struct
5177                          */
5178                         inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
5179                 }
5180 +               inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5181 +               inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5182 +               inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
5183 +                               /* maybe fattr->xid someday */
5184 +
5185                 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
5186                 nfsi->attrtimeo_timestamp = now;
5187                 nfsi->access_cache = RB_ROOT;
5188 @@ -505,6 +513,8 @@ void nfs_setattr_update_inode(struct ino
5189                         inode->i_uid = attr->ia_uid;
5190                 if ((attr->ia_valid & ATTR_GID) != 0)
5191                         inode->i_gid = attr->ia_gid;
5192 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5193 +                       inode->i_tag = attr->ia_tag;
5194                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5195                 spin_unlock(&inode->i_lock);
5196         }
5197 @@ -980,6 +990,11 @@ static int nfs_check_inode_attributes(st
5198         struct nfs_inode *nfsi = NFS_I(inode);
5199         loff_t cur_size, new_isize;
5200         unsigned long invalid = 0;
5201 +       kuid_t kuid;
5202 +       kgid_t kgid;
5203 +       ktag_t ktag;
5204 +       uid_t uid;
5205 +       gid_t gid;
5206  
5207  
5208         if (nfs_have_delegated_attributes(inode))
5209 @@ -1005,13 +1020,21 @@ static int nfs_check_inode_attributes(st
5210                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5211         }
5212  
5213 +       uid = from_kuid(&init_user_ns, fattr->uid);
5214 +       gid = from_kgid(&init_user_ns, fattr->gid);
5215 +
5216 +       kuid = make_kuid(&init_user_ns, INOTAG_UID(DX_TAG(inode), uid, gid));
5217 +       kgid = make_kgid(&init_user_ns, INOTAG_GID(DX_TAG(inode), uid, gid));
5218 +       ktag = make_ktag(&init_user_ns, INOTAG_TAG(DX_TAG(inode), uid, gid, 0));
5219 +
5220         /* Have any file permissions changed? */
5221         if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
5222                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5223 -       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && !uid_eq(inode->i_uid, fattr->uid))
5224 +       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && !uid_eq(inode->i_uid, kuid))
5225                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5226 -       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && !gid_eq(inode->i_gid, fattr->gid))
5227 +       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && !gid_eq(inode->i_gid, kgid))
5228                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5229 +               /* maybe check for tag too? */
5230  
5231         /* Has the link count changed? */
5232         if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
5233 @@ -1317,6 +1340,9 @@ static int nfs_update_inode(struct inode
5234         unsigned long invalid = 0;
5235         unsigned long now = jiffies;
5236         unsigned long save_cache_validity;
5237 +       uid_t uid;
5238 +       gid_t gid;
5239 +       tag_t tag;
5240  
5241         dfprintk(VFS, "NFS: %s(%s/%ld fh_crc=0x%08x ct=%d info=0x%x)\n",
5242                         __func__, inode->i_sb->s_id, inode->i_ino,
5243 @@ -1418,6 +1444,9 @@ static int nfs_update_inode(struct inode
5244                                 | NFS_INO_REVAL_PAGECACHE
5245                                 | NFS_INO_REVAL_FORCED);
5246  
5247 +       uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
5248 +       gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
5249 +       tag = inode->i_tag;
5250  
5251         if (fattr->valid & NFS_ATTR_FATTR_ATIME)
5252                 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5253 @@ -1460,6 +1489,10 @@ static int nfs_update_inode(struct inode
5254                                 | NFS_INO_INVALID_ACL
5255                                 | NFS_INO_REVAL_FORCED);
5256  
5257 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5258 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5259 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, tag);
5260 +
5261         if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
5262                 if (inode->i_nlink != fattr->nlink) {
5263                         invalid |= NFS_INO_INVALID_ATTR;
5264 diff -NurpP --minimal linux-3.9.4/fs/nfs/nfs3xdr.c linux-3.9.4-vs2.3.6.1/fs/nfs/nfs3xdr.c
5265 --- linux-3.9.4/fs/nfs/nfs3xdr.c        2013-05-31 13:45:24.000000000 +0000
5266 +++ linux-3.9.4-vs2.3.6.1/fs/nfs/nfs3xdr.c      2013-05-31 15:33:48.000000000 +0000
5267 @@ -20,6 +20,7 @@
5268  #include <linux/nfs3.h>
5269  #include <linux/nfs_fs.h>
5270  #include <linux/nfsacl.h>
5271 +#include <linux/vs_tag.h>
5272  #include "internal.h"
5273  
5274  #define NFSDBG_FACILITY                NFSDBG_XDR
5275 @@ -558,7 +559,8 @@ static __be32 *xdr_decode_nfstime3(__be3
5276   *             set_mtime       mtime;
5277   *     };
5278   */
5279 -static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr)
5280 +static void encode_sattr3(struct xdr_stream *xdr,
5281 +       const struct iattr *attr, int tag)
5282  {
5283         u32 nbytes;
5284         __be32 *p;
5285 @@ -590,15 +592,19 @@ static void encode_sattr3(struct xdr_str
5286         } else
5287                 *p++ = xdr_zero;
5288  
5289 -       if (attr->ia_valid & ATTR_UID) {
5290 +       if (attr->ia_valid & ATTR_UID ||
5291 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5292                 *p++ = xdr_one;
5293 -               *p++ = cpu_to_be32(from_kuid(&init_user_ns, attr->ia_uid));
5294 +               *p++ = cpu_to_be32(TAGINO_UID(tag,
5295 +                       from_kuid(&init_user_ns, attr->ia_uid), attr->ia_tag));
5296         } else
5297                 *p++ = xdr_zero;
5298  
5299 -       if (attr->ia_valid & ATTR_GID) {
5300 +       if (attr->ia_valid & ATTR_GID ||
5301 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5302                 *p++ = xdr_one;
5303 -               *p++ = cpu_to_be32(from_kgid(&init_user_ns, attr->ia_gid));
5304 +               *p++ = cpu_to_be32(TAGINO_GID(tag,
5305 +                       from_kgid(&init_user_ns, attr->ia_gid), attr->ia_tag));
5306         } else
5307                 *p++ = xdr_zero;
5308  
5309 @@ -887,7 +893,7 @@ static void nfs3_xdr_enc_setattr3args(st
5310                                       const struct nfs3_sattrargs *args)
5311  {
5312         encode_nfs_fh3(xdr, args->fh);
5313 -       encode_sattr3(xdr, args->sattr);
5314 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5315         encode_sattrguard3(xdr, args);
5316  }
5317  
5318 @@ -1037,13 +1043,13 @@ static void nfs3_xdr_enc_write3args(stru
5319   *     };
5320   */
5321  static void encode_createhow3(struct xdr_stream *xdr,
5322 -                             const struct nfs3_createargs *args)
5323 +       const struct nfs3_createargs *args, int tag)
5324  {
5325         encode_uint32(xdr, args->createmode);
5326         switch (args->createmode) {
5327         case NFS3_CREATE_UNCHECKED:
5328         case NFS3_CREATE_GUARDED:
5329 -               encode_sattr3(xdr, args->sattr);
5330 +               encode_sattr3(xdr, args->sattr, tag);
5331                 break;
5332         case NFS3_CREATE_EXCLUSIVE:
5333                 encode_createverf3(xdr, args->verifier);
5334 @@ -1058,7 +1064,7 @@ static void nfs3_xdr_enc_create3args(str
5335                                      const struct nfs3_createargs *args)
5336  {
5337         encode_diropargs3(xdr, args->fh, args->name, args->len);
5338 -       encode_createhow3(xdr, args);
5339 +       encode_createhow3(xdr, args, req->rq_task->tk_client->cl_tag);
5340  }
5341  
5342  /*
5343 @@ -1074,7 +1080,7 @@ static void nfs3_xdr_enc_mkdir3args(stru
5344                                     const struct nfs3_mkdirargs *args)
5345  {
5346         encode_diropargs3(xdr, args->fh, args->name, args->len);
5347 -       encode_sattr3(xdr, args->sattr);
5348 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5349  }
5350  
5351  /*
5352 @@ -1091,9 +1097,9 @@ static void nfs3_xdr_enc_mkdir3args(stru
5353   *     };
5354   */
5355  static void encode_symlinkdata3(struct xdr_stream *xdr,
5356 -                               const struct nfs3_symlinkargs *args)
5357 +       const struct nfs3_symlinkargs *args, int tag)
5358  {
5359 -       encode_sattr3(xdr, args->sattr);
5360 +       encode_sattr3(xdr, args->sattr, tag);
5361         encode_nfspath3(xdr, args->pages, args->pathlen);
5362  }
5363  
5364 @@ -1102,7 +1108,7 @@ static void nfs3_xdr_enc_symlink3args(st
5365                                       const struct nfs3_symlinkargs *args)
5366  {
5367         encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen);
5368 -       encode_symlinkdata3(xdr, args);
5369 +       encode_symlinkdata3(xdr, args, req->rq_task->tk_client->cl_tag);
5370  }
5371  
5372  /*
5373 @@ -1130,24 +1136,24 @@ static void nfs3_xdr_enc_symlink3args(st
5374   *     };
5375   */
5376  static void encode_devicedata3(struct xdr_stream *xdr,
5377 -                              const struct nfs3_mknodargs *args)
5378 +       const struct nfs3_mknodargs *args, int tag)
5379  {
5380 -       encode_sattr3(xdr, args->sattr);
5381 +       encode_sattr3(xdr, args->sattr, tag);
5382         encode_specdata3(xdr, args->rdev);
5383  }
5384  
5385  static void encode_mknoddata3(struct xdr_stream *xdr,
5386 -                             const struct nfs3_mknodargs *args)
5387 +       const struct nfs3_mknodargs *args, int tag)
5388  {
5389         encode_ftype3(xdr, args->type);
5390         switch (args->type) {
5391         case NF3CHR:
5392         case NF3BLK:
5393 -               encode_devicedata3(xdr, args);
5394 +               encode_devicedata3(xdr, args, tag);
5395                 break;
5396         case NF3SOCK:
5397         case NF3FIFO:
5398 -               encode_sattr3(xdr, args->sattr);
5399 +               encode_sattr3(xdr, args->sattr, tag);
5400                 break;
5401         case NF3REG:
5402         case NF3DIR:
5403 @@ -1162,7 +1168,7 @@ static void nfs3_xdr_enc_mknod3args(stru
5404                                     const struct nfs3_mknodargs *args)
5405  {
5406         encode_diropargs3(xdr, args->fh, args->name, args->len);
5407 -       encode_mknoddata3(xdr, args);
5408 +       encode_mknoddata3(xdr, args, req->rq_task->tk_client->cl_tag);
5409  }
5410  
5411  /*
5412 diff -NurpP --minimal linux-3.9.4/fs/nfs/super.c linux-3.9.4-vs2.3.6.1/fs/nfs/super.c
5413 --- linux-3.9.4/fs/nfs/super.c  2013-05-31 13:45:24.000000000 +0000
5414 +++ linux-3.9.4-vs2.3.6.1/fs/nfs/super.c        2013-05-31 15:41:34.000000000 +0000
5415 @@ -55,6 +55,7 @@
5416  #include <linux/parser.h>
5417  #include <linux/nsproxy.h>
5418  #include <linux/rcupdate.h>
5419 +#include <linux/vs_tag.h>
5420  
5421  #include <asm/uaccess.h>
5422  
5423 @@ -103,6 +104,7 @@ enum {
5424         Opt_mountport,
5425         Opt_mountvers,
5426         Opt_minorversion,
5427 +       Opt_tagid,
5428  
5429         /* Mount options that take string arguments */
5430         Opt_nfsvers,
5431 @@ -115,6 +117,9 @@ enum {
5432         /* Special mount options */
5433         Opt_userspace, Opt_deprecated, Opt_sloppy,
5434  
5435 +       /* Linux-VServer tagging options */
5436 +       Opt_tag, Opt_notag,
5437 +
5438         Opt_err
5439  };
5440  
5441 @@ -184,6 +189,10 @@ static const match_table_t nfs_mount_opt
5442         { Opt_fscache_uniq, "fsc=%s" },
5443         { Opt_local_lock, "local_lock=%s" },
5444  
5445 +       { Opt_tag, "tag" },
5446 +       { Opt_notag, "notag" },
5447 +       { Opt_tagid, "tagid=%u" },
5448 +
5449         /* The following needs to be listed after all other options */
5450         { Opt_nfsvers, "v%s" },
5451  
5452 @@ -635,6 +644,7 @@ static void nfs_show_mount_options(struc
5453                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
5454                 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
5455                 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
5456 +               { NFS_MOUNT_TAGGED, ",tag", "" },
5457                 { 0, NULL, NULL }
5458         };
5459         const struct proc_nfs_info *nfs_infop;
5460 @@ -1261,6 +1271,14 @@ static int nfs_parse_mount_options(char
5461                 case Opt_nomigration:
5462                         mnt->options &= NFS_OPTION_MIGRATION;
5463                         break;
5464 +#ifndef CONFIG_TAGGING_NONE
5465 +               case Opt_tag:
5466 +                       mnt->flags |= NFS_MOUNT_TAGGED;
5467 +                       break;
5468 +               case Opt_notag:
5469 +                       mnt->flags &= ~NFS_MOUNT_TAGGED;
5470 +                       break;
5471 +#endif
5472  
5473                 /*
5474                  * options that take numeric values
5475 @@ -1347,6 +1365,12 @@ static int nfs_parse_mount_options(char
5476                                 goto out_invalid_value;
5477                         mnt->minorversion = option;
5478                         break;
5479 +#ifdef CONFIG_PROPAGATE
5480 +               case Opt_tagid:
5481 +                       /* use args[0] */
5482 +                       nfs_data.flags |= NFS_MOUNT_TAGGED;
5483 +                       break;
5484 +#endif
5485  
5486                 /*
5487                  * options that take text values
5488 diff -NurpP --minimal linux-3.9.4/fs/nfsd/auth.c linux-3.9.4-vs2.3.6.1/fs/nfsd/auth.c
5489 --- linux-3.9.4/fs/nfsd/auth.c  2013-05-31 13:45:24.000000000 +0000
5490 +++ linux-3.9.4-vs2.3.6.1/fs/nfsd/auth.c        2013-05-31 14:47:11.000000000 +0000
5491 @@ -2,6 +2,7 @@
5492  
5493  #include <linux/sched.h>
5494  #include <linux/user_namespace.h>
5495 +#include <linux/vs_tag.h>
5496  #include "nfsd.h"
5497  #include "auth.h"
5498  
5499 @@ -37,6 +38,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
5500  
5501         new->fsuid = rqstp->rq_cred.cr_uid;
5502         new->fsgid = rqstp->rq_cred.cr_gid;
5503 +       /* FIXME: this desperately needs a tag :)
5504 +       new->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
5505 +                       */
5506  
5507         rqgi = rqstp->rq_cred.cr_group_info;
5508  
5509 diff -NurpP --minimal linux-3.9.4/fs/nfsd/nfs3xdr.c linux-3.9.4-vs2.3.6.1/fs/nfsd/nfs3xdr.c
5510 --- linux-3.9.4/fs/nfsd/nfs3xdr.c       2013-05-31 13:45:24.000000000 +0000
5511 +++ linux-3.9.4-vs2.3.6.1/fs/nfsd/nfs3xdr.c     2013-05-31 16:17:38.000000000 +0000
5512 @@ -8,6 +8,7 @@
5513  
5514  #include <linux/namei.h>
5515  #include <linux/sunrpc/svc_xprt.h>
5516 +#include <linux/vs_tag.h>
5517  #include "xdr3.h"
5518  #include "auth.h"
5519  #include "netns.h"
5520 @@ -98,6 +99,8 @@ static __be32 *
5521  decode_sattr3(__be32 *p, struct iattr *iap)
5522  {
5523         u32     tmp;
5524 +       uid_t   uid = 0;
5525 +       gid_t   gid = 0;
5526  
5527         iap->ia_valid = 0;
5528  
5529 @@ -106,15 +109,18 @@ decode_sattr3(__be32 *p, struct iattr *i
5530                 iap->ia_mode = ntohl(*p++);
5531         }
5532         if (*p++) {
5533 -               iap->ia_uid = make_kuid(&init_user_ns, ntohl(*p++));
5534 +               uid = make_kuid(&init_user_ns, ntohl(*p++));
5535                 if (uid_valid(iap->ia_uid))
5536                         iap->ia_valid |= ATTR_UID;
5537         }
5538         if (*p++) {
5539 -               iap->ia_gid = make_kgid(&init_user_ns, ntohl(*p++));
5540 +               gid = make_kgid(&init_user_ns, ntohl(*p++));
5541                 if (gid_valid(iap->ia_gid))
5542                         iap->ia_valid |= ATTR_GID;
5543         }
5544 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
5545 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
5546 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
5547         if (*p++) {
5548                 u64     newsize;
5549  
5550 @@ -170,8 +176,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
5551         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
5552         *p++ = htonl((u32) stat->mode);
5553         *p++ = htonl((u32) stat->nlink);
5554 -       *p++ = htonl((u32) from_kuid(&init_user_ns, stat->uid));
5555 -       *p++ = htonl((u32) from_kgid(&init_user_ns, stat->gid));
5556 +       *p++ = htonl((u32) from_kuid(&init_user_ns,
5557 +               TAGINO_UID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5558 +               stat->uid, stat->tag)));
5559 +       *p++ = htonl((u32) from_kgid(&init_user_ns,
5560 +               TAGINO_GID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5561 +               stat->gid, stat->tag)));
5562         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
5563                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
5564         } else {
5565 diff -NurpP --minimal linux-3.9.4/fs/nfsd/nfs4xdr.c linux-3.9.4-vs2.3.6.1/fs/nfsd/nfs4xdr.c
5566 --- linux-3.9.4/fs/nfsd/nfs4xdr.c       2013-05-31 14:22:27.000000000 +0000
5567 +++ linux-3.9.4-vs2.3.6.1/fs/nfsd/nfs4xdr.c     2013-05-31 14:47:11.000000000 +0000
5568 @@ -46,6 +46,7 @@
5569  #include <linux/utsname.h>
5570  #include <linux/pagemap.h>
5571  #include <linux/sunrpc/svcauth_gss.h>
5572 +#include <linux/vs_tag.h>
5573  
5574  #include "idmap.h"
5575  #include "acl.h"
5576 @@ -2349,14 +2350,18 @@ out_acl:
5577                 WRITE32(stat.nlink);
5578         }
5579         if (bmval1 & FATTR4_WORD1_OWNER) {
5580 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
5581 +               status = nfsd4_encode_user(rqstp,
5582 +                       TAGINO_UID(DX_TAG(dentry->d_inode),
5583 +                       stat.uid, stat.tag), &p, &buflen);
5584                 if (status == nfserr_resource)
5585                         goto out_resource;
5586                 if (status)
5587                         goto out;
5588         }
5589         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
5590 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
5591 +               status = nfsd4_encode_group(rqstp,
5592 +                       TAGINO_GID(DX_TAG(dentry->d_inode),
5593 +                       stat.gid, stat.tag), &p, &buflen);
5594                 if (status == nfserr_resource)
5595                         goto out_resource;
5596                 if (status)
5597 diff -NurpP --minimal linux-3.9.4/fs/nfsd/nfsxdr.c linux-3.9.4-vs2.3.6.1/fs/nfsd/nfsxdr.c
5598 --- linux-3.9.4/fs/nfsd/nfsxdr.c        2013-05-31 13:45:24.000000000 +0000
5599 +++ linux-3.9.4-vs2.3.6.1/fs/nfsd/nfsxdr.c      2013-05-31 16:20:53.000000000 +0000
5600 @@ -7,6 +7,7 @@
5601  #include "vfs.h"
5602  #include "xdr.h"
5603  #include "auth.h"
5604 +#include <linux/vs_tag.h>
5605  
5606  #define NFSDDBG_FACILITY               NFSDDBG_XDR
5607  
5608 @@ -89,6 +90,8 @@ static __be32 *
5609  decode_sattr(__be32 *p, struct iattr *iap)
5610  {
5611         u32     tmp, tmp1;
5612 +       uid_t   uid = 0;
5613 +       gid_t   gid = 0;
5614  
5615         iap->ia_valid = 0;
5616  
5617 @@ -101,15 +104,18 @@ decode_sattr(__be32 *p, struct iattr *ia
5618                 iap->ia_mode = tmp;
5619         }
5620         if ((tmp = ntohl(*p++)) != (u32)-1) {
5621 -               iap->ia_uid = make_kuid(&init_user_ns, tmp);
5622 +               uid = make_kuid(&init_user_ns, tmp);
5623                 if (uid_valid(iap->ia_uid))
5624                         iap->ia_valid |= ATTR_UID;
5625         }
5626         if ((tmp = ntohl(*p++)) != (u32)-1) {
5627 -               iap->ia_gid = make_kgid(&init_user_ns, tmp);
5628 +               gid = make_kgid(&init_user_ns, tmp);
5629                 if (gid_valid(iap->ia_gid))
5630                         iap->ia_valid |= ATTR_GID;
5631         }
5632 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
5633 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
5634 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
5635         if ((tmp = ntohl(*p++)) != (u32)-1) {
5636                 iap->ia_valid |= ATTR_SIZE;
5637                 iap->ia_size = tmp;
5638 @@ -154,8 +160,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
5639         *p++ = htonl(nfs_ftypes[type >> 12]);
5640         *p++ = htonl((u32) stat->mode);
5641         *p++ = htonl((u32) stat->nlink);
5642 -       *p++ = htonl((u32) from_kuid(&init_user_ns, stat->uid));
5643 -       *p++ = htonl((u32) from_kgid(&init_user_ns, stat->gid));
5644 +       *p++ = htonl((u32) from_kuid(&init_user_ns,
5645 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
5646 +       *p++ = htonl((u32) from_kgid(&init_user_ns,
5647 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
5648  
5649         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
5650                 *p++ = htonl(NFS_MAXPATHLEN);
5651 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/dlmglue.c linux-3.9.4-vs2.3.6.1/fs/ocfs2/dlmglue.c
5652 --- linux-3.9.4/fs/ocfs2/dlmglue.c      2013-05-31 13:45:24.000000000 +0000
5653 +++ linux-3.9.4-vs2.3.6.1/fs/ocfs2/dlmglue.c    2013-05-31 15:47:29.000000000 +0000
5654 @@ -2047,6 +2047,7 @@ static void __ocfs2_stuff_meta_lvb(struc
5655         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
5656         lvb->lvb_iuid      = cpu_to_be32(i_uid_read(inode));
5657         lvb->lvb_igid      = cpu_to_be32(i_gid_read(inode));
5658 +       lvb->lvb_itag      = cpu_to_be16(inode->i_tag);
5659         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
5660         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
5661         lvb->lvb_iatime_packed  =
5662 @@ -2097,6 +2098,7 @@ static void ocfs2_refresh_inode_from_lvb
5663  
5664         i_uid_write(inode, be32_to_cpu(lvb->lvb_iuid));
5665         i_gid_write(inode, be32_to_cpu(lvb->lvb_igid));
5666 +       i_tag_write(inode, be16_to_cpu(lvb->lvb_itag));
5667         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
5668         set_nlink(inode, be16_to_cpu(lvb->lvb_inlink));
5669         ocfs2_unpack_timespec(&inode->i_atime,
5670 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/dlmglue.h linux-3.9.4-vs2.3.6.1/fs/ocfs2/dlmglue.h
5671 --- linux-3.9.4/fs/ocfs2/dlmglue.h      2012-12-11 03:30:57.000000000 +0000
5672 +++ linux-3.9.4-vs2.3.6.1/fs/ocfs2/dlmglue.h    2013-05-31 14:47:11.000000000 +0000
5673 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
5674         __be16       lvb_inlink;
5675         __be32       lvb_iattr;
5676         __be32       lvb_igeneration;
5677 -       __be32       lvb_reserved2;
5678 +       __be16       lvb_itag;
5679 +       __be16       lvb_reserved2;
5680  };
5681  
5682  #define OCFS2_QINFO_LVB_VERSION 1
5683 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/file.c linux-3.9.4-vs2.3.6.1/fs/ocfs2/file.c
5684 --- linux-3.9.4/fs/ocfs2/file.c 2013-05-31 13:45:24.000000000 +0000
5685 +++ linux-3.9.4-vs2.3.6.1/fs/ocfs2/file.c       2013-05-31 14:47:11.000000000 +0000
5686 @@ -1124,7 +1124,7 @@ int ocfs2_setattr(struct dentry *dentry,
5687                 attr->ia_valid &= ~ATTR_SIZE;
5688  
5689  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
5690 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
5691 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
5692         if (!(attr->ia_valid & OCFS2_VALID_ATTRS))
5693                 return 0;
5694  
5695 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/inode.c linux-3.9.4-vs2.3.6.1/fs/ocfs2/inode.c
5696 --- linux-3.9.4/fs/ocfs2/inode.c        2013-05-31 13:45:24.000000000 +0000
5697 +++ linux-3.9.4-vs2.3.6.1/fs/ocfs2/inode.c      2013-05-31 20:39:47.000000000 +0000
5698 @@ -28,6 +28,7 @@
5699  #include <linux/highmem.h>
5700  #include <linux/pagemap.h>
5701  #include <linux/quotaops.h>
5702 +#include <linux/vs_tag.h>
5703  
5704  #include <asm/byteorder.h>
5705  
5706 @@ -78,11 +79,13 @@ void ocfs2_set_inode_flags(struct inode
5707  {
5708         unsigned int flags = OCFS2_I(inode)->ip_attr;
5709  
5710 -       inode->i_flags &= ~(S_IMMUTABLE |
5711 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
5712                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
5713  
5714         if (flags & OCFS2_IMMUTABLE_FL)
5715                 inode->i_flags |= S_IMMUTABLE;
5716 +       if (flags & OCFS2_IXUNLINK_FL)
5717 +               inode->i_flags |= S_IXUNLINK;
5718  
5719         if (flags & OCFS2_SYNC_FL)
5720                 inode->i_flags |= S_SYNC;
5721 @@ -92,25 +95,44 @@ void ocfs2_set_inode_flags(struct inode
5722                 inode->i_flags |= S_NOATIME;
5723         if (flags & OCFS2_DIRSYNC_FL)
5724                 inode->i_flags |= S_DIRSYNC;
5725 +
5726 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
5727 +
5728 +       if (flags & OCFS2_BARRIER_FL)
5729 +               inode->i_vflags |= V_BARRIER;
5730 +       if (flags & OCFS2_COW_FL)
5731 +               inode->i_vflags |= V_COW;
5732  }
5733  
5734  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
5735  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
5736  {
5737         unsigned int flags = oi->vfs_inode.i_flags;
5738 +       unsigned int vflags = oi->vfs_inode.i_vflags;
5739 +
5740 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
5741 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
5742 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
5743 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
5744 +
5745 +       if (flags & S_IMMUTABLE)
5746 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5747 +       if (flags & S_IXUNLINK)
5748 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
5749  
5750 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
5751 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
5752         if (flags & S_SYNC)
5753                 oi->ip_attr |= OCFS2_SYNC_FL;
5754         if (flags & S_APPEND)
5755                 oi->ip_attr |= OCFS2_APPEND_FL;
5756 -       if (flags & S_IMMUTABLE)
5757 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5758         if (flags & S_NOATIME)
5759                 oi->ip_attr |= OCFS2_NOATIME_FL;
5760         if (flags & S_DIRSYNC)
5761                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
5762 +
5763 +       if (vflags & V_BARRIER)
5764 +               oi->ip_attr |= OCFS2_BARRIER_FL;
5765 +       if (vflags & V_COW)
5766 +               oi->ip_attr |= OCFS2_COW_FL;
5767  }
5768  
5769  struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
5770 @@ -241,6 +263,8 @@ void ocfs2_populate_inode(struct inode *
5771         struct super_block *sb;
5772         struct ocfs2_super *osb;
5773         int use_plocks = 1;
5774 +       uid_t uid;
5775 +       gid_t gid;
5776  
5777         sb = inode->i_sb;
5778         osb = OCFS2_SB(sb);
5779 @@ -269,8 +293,12 @@ void ocfs2_populate_inode(struct inode *
5780         inode->i_generation = le32_to_cpu(fe->i_generation);
5781         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
5782         inode->i_mode = le16_to_cpu(fe->i_mode);
5783 -       i_uid_write(inode, le32_to_cpu(fe->i_uid));
5784 -       i_gid_write(inode, le32_to_cpu(fe->i_gid));
5785 +       uid = le32_to_cpu(fe->i_uid);
5786 +       gid = le32_to_cpu(fe->i_gid);
5787 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), uid, gid));
5788 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), uid, gid));
5789 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), uid, gid,
5790 +               /* le16_to_cpu(raw_inode->i_raw_tag) */ 0));
5791  
5792         /* Fast symlinks will have i_size but no allocated clusters. */
5793         if (S_ISLNK(inode->i_mode) && !fe->i_clusters) {
5794 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/inode.h linux-3.9.4-vs2.3.6.1/fs/ocfs2/inode.h
5795 --- linux-3.9.4/fs/ocfs2/inode.h        2012-12-11 03:30:57.000000000 +0000
5796 +++ linux-3.9.4-vs2.3.6.1/fs/ocfs2/inode.h      2013-05-31 14:47:11.000000000 +0000
5797 @@ -154,6 +154,7 @@ struct buffer_head *ocfs2_bread(struct i
5798  
5799  void ocfs2_set_inode_flags(struct inode *inode);
5800  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
5801 +int ocfs2_sync_flags(struct inode *inode, int, int);
5802  
5803  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
5804  {
5805 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/ioctl.c linux-3.9.4-vs2.3.6.1/fs/ocfs2/ioctl.c
5806 --- linux-3.9.4/fs/ocfs2/ioctl.c        2013-05-31 13:45:24.000000000 +0000
5807 +++ linux-3.9.4-vs2.3.6.1/fs/ocfs2/ioctl.c      2013-05-31 14:47:11.000000000 +0000
5808 @@ -76,7 +76,41 @@ static int ocfs2_get_inode_attr(struct i
5809         return status;
5810  }
5811  
5812 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5813 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
5814 +{
5815 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
5816 +       struct buffer_head *bh = NULL;
5817 +       handle_t *handle = NULL;
5818 +       int status;
5819 +
5820 +       status = ocfs2_inode_lock(inode, &bh, 1);
5821 +       if (status < 0) {
5822 +               mlog_errno(status);
5823 +               return status;
5824 +       }
5825 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5826 +       if (IS_ERR(handle)) {
5827 +               status = PTR_ERR(handle);
5828 +               mlog_errno(status);
5829 +               goto bail_unlock;
5830 +       }
5831 +
5832 +       inode->i_flags = flags;
5833 +       inode->i_vflags = vflags;
5834 +       ocfs2_get_inode_flags(OCFS2_I(inode));
5835 +
5836 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
5837 +       if (status < 0)
5838 +               mlog_errno(status);
5839 +
5840 +       ocfs2_commit_trans(osb, handle);
5841 +bail_unlock:
5842 +       ocfs2_inode_unlock(inode, 1);
5843 +       brelse(bh);
5844 +       return status;
5845 +}
5846 +
5847 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5848                                 unsigned mask)
5849  {
5850         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
5851 @@ -101,6 +135,11 @@ static int ocfs2_set_inode_attr(struct i
5852         if (!S_ISDIR(inode->i_mode))
5853                 flags &= ~OCFS2_DIRSYNC_FL;
5854  
5855 +       if (IS_BARRIER(inode)) {
5856 +               vxwprintk_task(1, "messing with the barrier.");
5857 +               goto bail_unlock;
5858 +       }
5859 +
5860         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5861         if (IS_ERR(handle)) {
5862                 status = PTR_ERR(handle);
5863 @@ -879,6 +918,7 @@ bail:
5864         return status;
5865  }
5866  
5867 +
5868  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
5869  {
5870         struct inode *inode = file_inode(filp);
5871 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/namei.c linux-3.9.4-vs2.3.6.1/fs/ocfs2/namei.c
5872 --- linux-3.9.4/fs/ocfs2/namei.c        2013-05-31 13:45:24.000000000 +0000
5873 +++ linux-3.9.4-vs2.3.6.1/fs/ocfs2/namei.c      2013-05-31 15:52:25.000000000 +0000
5874 @@ -41,6 +41,7 @@
5875  #include <linux/slab.h>
5876  #include <linux/highmem.h>
5877  #include <linux/quotaops.h>
5878 +#include <linux/vs_tag.h>
5879  
5880  #include <cluster/masklog.h>
5881  
5882 @@ -475,6 +476,7 @@ static int __ocfs2_mknod_locked(struct i
5883         struct ocfs2_dinode *fe = NULL;
5884         struct ocfs2_extent_list *fel;
5885         u16 feat;
5886 +       tag_t tag;
5887  
5888         *new_fe_bh = NULL;
5889  
5890 @@ -512,8 +514,11 @@ static int __ocfs2_mknod_locked(struct i
5891         fe->i_suballoc_loc = cpu_to_le64(suballoc_loc);
5892         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
5893         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
5894 -       fe->i_uid = cpu_to_le32(i_uid_read(inode));
5895 -       fe->i_gid = cpu_to_le32(i_gid_read(inode));
5896 +
5897 +       tag = dx_current_fstag(osb->sb);
5898 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), i_uid_read(inode), tag));
5899 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), i_gid_read(inode), tag));
5900 +       inode->i_tag = tag; /* is this correct? */
5901         fe->i_mode = cpu_to_le16(inode->i_mode);
5902         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
5903                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
5904 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/ocfs2.h linux-3.9.4-vs2.3.6.1/fs/ocfs2/ocfs2.h
5905 --- linux-3.9.4/fs/ocfs2/ocfs2.h        2012-12-11 03:30:57.000000000 +0000
5906 +++ linux-3.9.4-vs2.3.6.1/fs/ocfs2/ocfs2.h      2013-05-31 14:47:11.000000000 +0000
5907 @@ -272,6 +272,7 @@ enum ocfs2_mount_options
5908                                                      writes */
5909         OCFS2_MOUNT_HB_NONE = 1 << 13, /* No heartbeat */
5910         OCFS2_MOUNT_HB_GLOBAL = 1 << 14, /* Global heartbeat */
5911 +       OCFS2_MOUNT_TAGGED = 1 << 15, /* use tagging */
5912  };
5913  
5914  #define OCFS2_OSB_SOFT_RO                      0x0001
5915 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/ocfs2_fs.h linux-3.9.4-vs2.3.6.1/fs/ocfs2/ocfs2_fs.h
5916 --- linux-3.9.4/fs/ocfs2/ocfs2_fs.h     2012-12-11 03:30:57.000000000 +0000
5917 +++ linux-3.9.4-vs2.3.6.1/fs/ocfs2/ocfs2_fs.h   2013-05-31 14:47:11.000000000 +0000
5918 @@ -266,6 +266,11 @@
5919  #define OCFS2_TOPDIR_FL                        FS_TOPDIR_FL    /* Top of directory hierarchies*/
5920  #define OCFS2_RESERVED_FL              FS_RESERVED_FL  /* reserved for ext2 lib */
5921  
5922 +#define OCFS2_IXUNLINK_FL              FS_IXUNLINK_FL  /* Immutable invert on unlink */
5923 +
5924 +#define OCFS2_BARRIER_FL               FS_BARRIER_FL   /* Barrier for chroot() */
5925 +#define OCFS2_COW_FL                   FS_COW_FL       /* Copy on Write marker */
5926 +
5927  #define OCFS2_FL_VISIBLE               FS_FL_USER_VISIBLE      /* User visible flags */
5928  #define OCFS2_FL_MODIFIABLE            FS_FL_USER_MODIFIABLE   /* User modifiable flags */
5929  
5930 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/super.c linux-3.9.4-vs2.3.6.1/fs/ocfs2/super.c
5931 --- linux-3.9.4/fs/ocfs2/super.c        2013-05-31 13:45:25.000000000 +0000
5932 +++ linux-3.9.4-vs2.3.6.1/fs/ocfs2/super.c      2013-05-31 14:47:11.000000000 +0000
5933 @@ -185,6 +185,7 @@ enum {
5934         Opt_coherency_full,
5935         Opt_resv_level,
5936         Opt_dir_resv_level,
5937 +       Opt_tag, Opt_notag, Opt_tagid,
5938         Opt_err,
5939  };
5940  
5941 @@ -216,6 +217,9 @@ static const match_table_t tokens = {
5942         {Opt_coherency_full, "coherency=full"},
5943         {Opt_resv_level, "resv_level=%u"},
5944         {Opt_dir_resv_level, "dir_resv_level=%u"},
5945 +       {Opt_tag, "tag"},
5946 +       {Opt_notag, "notag"},
5947 +       {Opt_tagid, "tagid=%u"},
5948         {Opt_err, NULL}
5949  };
5950  
5951 @@ -662,6 +666,13 @@ static int ocfs2_remount(struct super_bl
5952                 goto out;
5953         }
5954  
5955 +       if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
5956 +           (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
5957 +               ret = -EINVAL;
5958 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
5959 +               goto out;
5960 +       }
5961 +
5962         /* We're going to/from readonly mode. */
5963         if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
5964                 /* Disable quota accounting before remounting RO */
5965 @@ -1177,6 +1188,9 @@ static int ocfs2_fill_super(struct super
5966  
5967         ocfs2_complete_mount_recovery(osb);
5968  
5969 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
5970 +               sb->s_flags |= MS_TAGGED;
5971 +
5972         if (ocfs2_mount_local(osb))
5973                 snprintf(nodestr, sizeof(nodestr), "local");
5974         else
5975 @@ -1504,6 +1518,20 @@ static int ocfs2_parse_options(struct su
5976                             option < OCFS2_MAX_RESV_LEVEL)
5977                                 mopt->dir_resv_level = option;
5978                         break;
5979 +#ifndef CONFIG_TAGGING_NONE
5980 +               case Opt_tag:
5981 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5982 +                       break;
5983 +               case Opt_notag:
5984 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
5985 +                       break;
5986 +#endif
5987 +#ifdef CONFIG_PROPAGATE
5988 +               case Opt_tagid:
5989 +                       /* use args[0] */
5990 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5991 +                       break;
5992 +#endif
5993                 default:
5994                         mlog(ML_ERROR,
5995                              "Unrecognized mount option \"%s\" "
5996 diff -NurpP --minimal linux-3.9.4/fs/open.c linux-3.9.4-vs2.3.6.1/fs/open.c
5997 --- linux-3.9.4/fs/open.c       2013-05-31 13:45:25.000000000 +0000
5998 +++ linux-3.9.4-vs2.3.6.1/fs/open.c     2013-05-31 21:09:19.000000000 +0000
5999 @@ -31,6 +31,11 @@
6000  #include <linux/ima.h>
6001  #include <linux/dnotify.h>
6002  #include <linux/compat.h>
6003 +#include <linux/vs_base.h>
6004 +#include <linux/vs_limit.h>
6005 +#include <linux/vs_tag.h>
6006 +#include <linux/vs_cowbl.h>
6007 +#include <linux/vserver/dlimit.h>
6008  
6009  #include "internal.h"
6010  
6011 @@ -67,6 +72,11 @@ long vfs_truncate(struct path *path, lof
6012         struct inode *inode;
6013         long error;
6014  
6015 +#ifdef CONFIG_VSERVER_COWBL
6016 +       error = cow_check_and_break(path);
6017 +       if (error)
6018 +               goto out;
6019 +#endif
6020         inode = path->dentry->d_inode;
6021  
6022         /* For directories it's -EISDIR, for other non-regulars - -EINVAL */
6023 @@ -532,6 +542,13 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
6024         unsigned int lookup_flags = LOOKUP_FOLLOW;
6025  retry:
6026         error = user_path_at(dfd, filename, lookup_flags, &path);
6027 +#ifdef CONFIG_VSERVER_COWBL
6028 +       if (!error) {
6029 +               error = cow_check_and_break(&path);
6030 +               if (error)
6031 +                       path_put(&path);
6032 +       }
6033 +#endif
6034         if (!error) {
6035                 error = chmod_common(&path, mode);
6036                 path_put(&path);
6037 @@ -564,13 +581,13 @@ static int chown_common(struct path *pat
6038                 if (!uid_valid(uid))
6039                         return -EINVAL;
6040                 newattrs.ia_valid |= ATTR_UID;
6041 -               newattrs.ia_uid = uid;
6042 +               newattrs.ia_uid = dx_map_uid(user);
6043         }
6044         if (group != (gid_t) -1) {
6045                 if (!gid_valid(gid))
6046                         return -EINVAL;
6047                 newattrs.ia_valid |= ATTR_GID;
6048 -               newattrs.ia_gid = gid;
6049 +               newattrs.ia_gid = dx_map_gid(group);
6050         }
6051         if (!S_ISDIR(inode->i_mode))
6052                 newattrs.ia_valid |=
6053 @@ -604,6 +621,18 @@ retry:
6054         error = mnt_want_write(path.mnt);
6055         if (error)
6056                 goto out_release;
6057 +#ifdef CONFIG_VSERVER_COWBL
6058 +       error = cow_check_and_break(&path);
6059 +       if (!error)
6060 +#endif
6061 +#ifdef CONFIG_VSERVER_COWBL
6062 +       error = cow_check_and_break(&path);
6063 +       if (!error)
6064 +#endif
6065 +#ifdef CONFIG_VSERVER_COWBL
6066 +       error = cow_check_and_break(&path);
6067 +       if (!error)
6068 +#endif
6069         error = chown_common(&path, user, group);
6070         mnt_drop_write(path.mnt);
6071  out_release:
6072 diff -NurpP --minimal linux-3.9.4/fs/proc/array.c linux-3.9.4-vs2.3.6.1/fs/proc/array.c
6073 --- linux-3.9.4/fs/proc/array.c 2013-05-31 13:45:25.000000000 +0000
6074 +++ linux-3.9.4-vs2.3.6.1/fs/proc/array.c       2013-05-31 14:47:11.000000000 +0000
6075 @@ -82,6 +82,8 @@
6076  #include <linux/ptrace.h>
6077  #include <linux/tracehook.h>
6078  #include <linux/user_namespace.h>
6079 +#include <linux/vs_context.h>
6080 +#include <linux/vs_network.h>
6081  
6082  #include <asm/pgtable.h>
6083  #include <asm/processor.h>
6084 @@ -173,6 +175,9 @@ static inline void task_state(struct seq
6085         rcu_read_lock();
6086         ppid = pid_alive(p) ?
6087                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
6088 +       if (unlikely(vx_current_initpid(p->pid)))
6089 +               ppid = 0;
6090 +
6091         tpid = 0;
6092         if (pid_alive(p)) {
6093                 struct task_struct *tracer = ptrace_parent(p);
6094 @@ -297,7 +302,7 @@ static inline void task_sig(struct seq_f
6095  }
6096  
6097  static void render_cap_t(struct seq_file *m, const char *header,
6098 -                       kernel_cap_t *a)
6099 +                       struct vx_info *vxi, kernel_cap_t *a)
6100  {
6101         unsigned __capi;
6102  
6103 @@ -331,10 +336,11 @@ static inline void task_cap(struct seq_f
6104         NORM_CAPS(cap_effective);
6105         NORM_CAPS(cap_bset);
6106  
6107 -       render_cap_t(m, "CapInh:\t", &cap_inheritable);
6108 -       render_cap_t(m, "CapPrm:\t", &cap_permitted);
6109 -       render_cap_t(m, "CapEff:\t", &cap_effective);
6110 -       render_cap_t(m, "CapBnd:\t", &cap_bset);
6111 +       /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
6112 +       render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
6113 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
6114 +       render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
6115 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
6116  }
6117  
6118  static inline void task_seccomp(struct seq_file *m, struct task_struct *p)
6119 @@ -363,6 +369,42 @@ static void task_cpus_allowed(struct seq
6120         seq_putc(m, '\n');
6121  }
6122  
6123 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6124 +                       struct pid *pid, struct task_struct *task)
6125 +{
6126 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
6127 +                       "Count:\t%u\n"
6128 +                       "uts:\t%p(%c)\n"
6129 +                       "ipc:\t%p(%c)\n"
6130 +                       "mnt:\t%p(%c)\n"
6131 +                       "pid:\t%p(%c)\n"
6132 +                       "net:\t%p(%c)\n",
6133 +                       task->nsproxy,
6134 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6135 +                       atomic_read(&task->nsproxy->count),
6136 +                       task->nsproxy->uts_ns,
6137 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6138 +                       task->nsproxy->ipc_ns,
6139 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6140 +                       task->nsproxy->mnt_ns,
6141 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6142 +                       task->nsproxy->pid_ns,
6143 +                       (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
6144 +                       task->nsproxy->net_ns,
6145 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6146 +       return 0;
6147 +}
6148 +
6149 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6150 +{
6151 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6152 +               return;
6153 +
6154 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6155 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6156 +}
6157 +
6158 +
6159  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6160                         struct pid *pid, struct task_struct *task)
6161  {
6162 @@ -380,6 +422,7 @@ int proc_pid_status(struct seq_file *m,
6163         task_seccomp(m, task);
6164         task_cpus_allowed(m, task);
6165         cpuset_task_status_allowed(m, task);
6166 +       task_vs_id(m, task);
6167         task_context_switch_counts(m, task);
6168         return 0;
6169  }
6170 @@ -489,6 +532,17 @@ static int do_task_stat(struct seq_file
6171         /* convert nsec -> ticks */
6172         start_time = nsec_to_clock_t(start_time);
6173  
6174 +       /* fixup start time for virt uptime */
6175 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6176 +               unsigned long long bias =
6177 +                       current->vx_info->cvirt.bias_clock;
6178 +
6179 +               if (start_time > bias)
6180 +                       start_time -= bias;
6181 +               else
6182 +                       start_time = 0;
6183 +       }
6184 +
6185         seq_printf(m, "%d (%s) %c", pid_nr_ns(pid, ns), tcomm, state);
6186         seq_put_decimal_ll(m, ' ', ppid);
6187         seq_put_decimal_ll(m, ' ', pgid);
6188 diff -NurpP --minimal linux-3.9.4/fs/proc/base.c linux-3.9.4-vs2.3.6.1/fs/proc/base.c
6189 --- linux-3.9.4/fs/proc/base.c  2013-05-31 13:45:25.000000000 +0000
6190 +++ linux-3.9.4-vs2.3.6.1/fs/proc/base.c        2013-05-31 14:47:11.000000000 +0000
6191 @@ -86,6 +86,8 @@
6192  #include <linux/fs_struct.h>
6193  #include <linux/slab.h>
6194  #include <linux/flex_array.h>
6195 +#include <linux/vs_context.h>
6196 +#include <linux/vs_network.h>
6197  #ifdef CONFIG_HARDWALL
6198  #include <asm/hardwall.h>
6199  #endif
6200 @@ -944,11 +946,15 @@ static ssize_t oom_adj_write(struct file
6201                 oom_adj = (oom_adj * OOM_SCORE_ADJ_MAX) / -OOM_DISABLE;
6202  
6203         if (oom_adj < task->signal->oom_score_adj &&
6204 -           !capable(CAP_SYS_RESOURCE)) {
6205 +           !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
6206                 err = -EACCES;
6207                 goto err_sighand;
6208         }
6209  
6210 +       /* prevent guest processes from circumventing the oom killer */
6211 +       if (vx_current_xid() && (oom_adj == OOM_DISABLE))
6212 +               oom_adj = OOM_ADJUST_MIN;
6213 +
6214         /*
6215          * /proc/pid/oom_adj is provided for legacy purposes, ask users to use
6216          * /proc/pid/oom_score_adj instead.
6217 @@ -1528,6 +1534,8 @@ struct inode *proc_pid_make_inode(struct
6218                 inode->i_gid = cred->egid;
6219                 rcu_read_unlock();
6220         }
6221 +       /* procfs is xid tagged */
6222 +       i_tag_write(inode, (tag_t)vx_task_xid(task));
6223         security_task_to_inode(task, inode);
6224  
6225  out:
6226 @@ -1573,6 +1581,8 @@ int pid_getattr(struct vfsmount *mnt, st
6227  
6228  /* dentry stuff */
6229  
6230 +static unsigned name_to_int(struct dentry *dentry);
6231 +
6232  /*
6233   *     Exceptional case: normally we are not allowed to unhash a busy
6234   * directory. In this case, however, we can do it - no aliasing problems
6235 @@ -1601,6 +1611,12 @@ int pid_revalidate(struct dentry *dentry
6236         task = get_proc_task(inode);
6237  
6238         if (task) {
6239 +               unsigned pid = name_to_int(dentry);
6240 +
6241 +               if (pid != ~0U && pid != vx_map_pid(task->pid)) {
6242 +                       put_task_struct(task);
6243 +                       goto drop;
6244 +               }
6245                 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
6246                     task_dumpable(task)) {
6247                         rcu_read_lock();
6248 @@ -1617,6 +1633,7 @@ int pid_revalidate(struct dentry *dentry
6249                 put_task_struct(task);
6250                 return 1;
6251         }
6252 +drop:
6253         d_drop(dentry);
6254         return 0;
6255  }
6256 @@ -2059,6 +2076,13 @@ static struct dentry *proc_pident_lookup
6257         if (!task)
6258                 goto out_no_task;
6259  
6260 +       /* TODO: maybe we can come up with a generic approach? */
6261 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
6262 +               (dentry->d_name.len == 5) &&
6263 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
6264 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
6265 +               goto out;
6266 +
6267         /*
6268          * Yes, it does not scale. And it should not. Don't add
6269          * new entries into /proc/<tgid>/ without very good reasons.
6270 @@ -2493,6 +2517,9 @@ static int proc_pid_personality(struct s
6271  static const struct file_operations proc_task_operations;
6272  static const struct inode_operations proc_task_inode_operations;
6273  
6274 +extern int proc_pid_vx_info(struct task_struct *, char *);
6275 +extern int proc_pid_nx_info(struct task_struct *, char *);
6276 +
6277  static const struct pid_entry tgid_base_stuff[] = {
6278         DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
6279         DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
6280 @@ -2559,6 +2586,8 @@ static const struct pid_entry tgid_base_
6281  #ifdef CONFIG_CGROUPS
6282         REG("cgroup",  S_IRUGO, proc_cgroup_operations),
6283  #endif
6284 +       INF("vinfo",      S_IRUGO, proc_pid_vx_info),
6285 +       INF("ninfo",      S_IRUGO, proc_pid_nx_info),
6286         INF("oom_score",  S_IRUGO, proc_oom_score),
6287         REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adj_operations),
6288         REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations),
6289 @@ -2583,6 +2612,7 @@ static const struct pid_entry tgid_base_
6290         REG("gid_map",    S_IRUGO|S_IWUSR, proc_gid_map_operations),
6291         REG("projid_map", S_IRUGO|S_IWUSR, proc_projid_map_operations),
6292  #endif
6293 +       ONE("nsproxy",  S_IRUGO, proc_pid_nsproxy),
6294  };
6295  
6296  static int proc_tgid_base_readdir(struct file * filp,
6297 @@ -2770,7 +2800,7 @@ retry:
6298         iter.task = NULL;
6299         pid = find_ge_pid(iter.tgid, ns);
6300         if (pid) {
6301 -               iter.tgid = pid_nr_ns(pid, ns);
6302 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
6303                 iter.task = pid_task(pid, PIDTYPE_PID);
6304                 /* What we to know is if the pid we have find is the
6305                  * pid of a thread_group_leader.  Testing for task
6306 @@ -2800,7 +2830,7 @@ static int proc_pid_fill_cache(struct fi
6307         struct tgid_iter iter)
6308  {
6309         char name[PROC_NUMBUF];
6310 -       int len = snprintf(name, sizeof(name), "%d", iter.tgid);
6311 +       int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
6312         return proc_fill_cache(filp, dirent, filldir, name, len,
6313                                 proc_pid_instantiate, iter.task, NULL);
6314  }
6315 @@ -2833,6 +2863,8 @@ int proc_pid_readdir(struct file * filp,
6316                         __filldir = fake_filldir;
6317  
6318                 filp->f_pos = iter.tgid + TGID_OFFSET;
6319 +               if (!vx_proc_task_visible(iter.task))
6320 +                       continue;
6321                 if (proc_pid_fill_cache(filp, dirent, __filldir, iter) < 0) {
6322                         put_task_struct(iter.task);
6323                         goto out;
6324 @@ -2993,6 +3025,8 @@ static struct dentry *proc_task_lookup(s
6325         tid = name_to_int(dentry);
6326         if (tid == ~0U)
6327                 goto out;
6328 +       if (vx_current_initpid(tid))
6329 +               goto out;
6330  
6331         ns = dentry->d_sb->s_fs_info;
6332         rcu_read_lock();
6333 diff -NurpP --minimal linux-3.9.4/fs/proc/generic.c linux-3.9.4-vs2.3.6.1/fs/proc/generic.c
6334 --- linux-3.9.4/fs/proc/generic.c       2013-05-31 13:45:25.000000000 +0000
6335 +++ linux-3.9.4-vs2.3.6.1/fs/proc/generic.c     2013-05-31 16:13:42.000000000 +0000
6336 @@ -23,6 +23,7 @@
6337  #include <linux/bitops.h>
6338  #include <linux/spinlock.h>
6339  #include <linux/completion.h>
6340 +#include <linux/vserver/inode.h>
6341  #include <asm/uaccess.h>
6342  
6343  #include "internal.h"
6344 @@ -409,6 +410,8 @@ struct dentry *proc_lookup_de(struct pro
6345         for (de = de->subdir; de ; de = de->next) {
6346                 if (de->namelen != dentry->d_name.len)
6347                         continue;
6348 +               if (!vx_hide_check(0, de->vx_flags))
6349 +                       continue;
6350                 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
6351                         pde_get(de);
6352                         spin_unlock(&proc_subdir_lock);
6353 @@ -417,6 +420,8 @@ struct dentry *proc_lookup_de(struct pro
6354                                 return ERR_PTR(-ENOMEM);
6355                         d_set_d_op(dentry, &proc_dentry_operations);
6356                         d_add(dentry, inode);
6357 +                       /* generic proc entries belong to the host */
6358 +                       i_tag_write(inode, 0);
6359                         return NULL;
6360                 }
6361         }
6362 @@ -485,6 +490,8 @@ int proc_readdir_de(struct proc_dir_entr
6363  
6364                                 /* filldir passes info to user space */
6365                                 pde_get(de);
6366 +                               if (!vx_hide_check(0, de->vx_flags))
6367 +                                       goto skip;
6368                                 spin_unlock(&proc_subdir_lock);
6369                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
6370                                             de->low_ino, de->mode >> 12) < 0) {
6371 @@ -492,6 +499,7 @@ int proc_readdir_de(struct proc_dir_entr
6372                                         goto out;
6373                                 }
6374                                 spin_lock(&proc_subdir_lock);
6375 +                       skip:
6376                                 filp->f_pos++;
6377                                 next = de->next;
6378                                 pde_put(de);
6379 @@ -603,6 +611,7 @@ static struct proc_dir_entry *__proc_cre
6380         ent->namelen = len;
6381         ent->mode = mode;
6382         ent->nlink = nlink;
6383 +       ent->vx_flags = IATTR_PROC_DEFAULT;
6384         atomic_set(&ent->count, 1);
6385         spin_lock_init(&ent->pde_unload_lock);
6386         INIT_LIST_HEAD(&ent->pde_openers);
6387 @@ -626,7 +635,8 @@ struct proc_dir_entry *proc_symlink(cons
6388                                 kfree(ent->data);
6389                                 kfree(ent);
6390                                 ent = NULL;
6391 -                       }
6392 +                       } else
6393 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
6394                 } else {
6395                         kfree(ent);
6396                         ent = NULL;
6397 diff -NurpP --minimal linux-3.9.4/fs/proc/inode.c linux-3.9.4-vs2.3.6.1/fs/proc/inode.c
6398 --- linux-3.9.4/fs/proc/inode.c 2013-05-31 13:45:25.000000000 +0000
6399 +++ linux-3.9.4-vs2.3.6.1/fs/proc/inode.c       2013-05-31 14:47:11.000000000 +0000
6400 @@ -458,6 +458,8 @@ struct inode *proc_get_inode(struct supe
6401                         inode->i_uid = de->uid;
6402                         inode->i_gid = de->gid;
6403                 }
6404 +               if (de->vx_flags)
6405 +                       PROC_I(inode)->vx_flags = de->vx_flags;
6406                 if (de->size)
6407                         inode->i_size = de->size;
6408                 if (de->nlink)
6409 diff -NurpP --minimal linux-3.9.4/fs/proc/internal.h linux-3.9.4-vs2.3.6.1/fs/proc/internal.h
6410 --- linux-3.9.4/fs/proc/internal.h      2013-05-31 13:45:25.000000000 +0000
6411 +++ linux-3.9.4-vs2.3.6.1/fs/proc/internal.h    2013-05-31 16:04:34.000000000 +0000
6412 @@ -12,6 +12,8 @@
6413  #include <linux/sched.h>
6414  #include <linux/proc_fs.h>
6415  #include <linux/binfmts.h>
6416 +#include <linux/vs_pid.h>
6417 +
6418  struct  ctl_table_header;
6419  struct  mempolicy;
6420  
6421 @@ -56,6 +58,9 @@ extern int proc_pid_status(struct seq_fi
6422                                 struct pid *pid, struct task_struct *task);
6423  extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
6424                                 struct pid *pid, struct task_struct *task);
6425 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6426 +                               struct pid *pid, struct task_struct *task);
6427 +
6428  extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
6429  
6430  extern const struct file_operations proc_tid_children_operations;
6431 @@ -89,11 +94,16 @@ static inline struct pid *proc_pid(struc
6432         return PROC_I(inode)->pid;
6433  }
6434  
6435 -static inline struct task_struct *get_proc_task(struct inode *inode)
6436 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
6437  {
6438         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
6439  }
6440  
6441 +static inline struct task_struct *get_proc_task(struct inode *inode)
6442 +{
6443 +       return vx_get_proc_task(inode, proc_pid(inode));
6444 +}
6445 +
6446  static inline int proc_fd(struct inode *inode)
6447  {
6448         return PROC_I(inode)->fd;
6449 diff -NurpP --minimal linux-3.9.4/fs/proc/loadavg.c linux-3.9.4-vs2.3.6.1/fs/proc/loadavg.c
6450 --- linux-3.9.4/fs/proc/loadavg.c       2012-12-11 03:30:57.000000000 +0000
6451 +++ linux-3.9.4-vs2.3.6.1/fs/proc/loadavg.c     2013-05-31 14:47:11.000000000 +0000
6452 @@ -12,15 +12,27 @@
6453  
6454  static int loadavg_proc_show(struct seq_file *m, void *v)
6455  {
6456 +       unsigned long running;
6457 +       unsigned int threads;
6458         unsigned long avnrun[3];
6459  
6460         get_avenrun(avnrun, FIXED_1/200, 0);
6461  
6462 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
6463 +               struct vx_info *vxi = current_vx_info();
6464 +
6465 +               running = atomic_read(&vxi->cvirt.nr_running);
6466 +               threads = atomic_read(&vxi->cvirt.nr_threads);
6467 +       } else {
6468 +               running = nr_running();
6469 +               threads = nr_threads;
6470 +       }
6471 +
6472         seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
6473                 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
6474                 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
6475                 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
6476 -               nr_running(), nr_threads,
6477 +               running, threads,
6478                 task_active_pid_ns(current)->last_pid);
6479         return 0;
6480  }
6481 diff -NurpP --minimal linux-3.9.4/fs/proc/meminfo.c linux-3.9.4-vs2.3.6.1/fs/proc/meminfo.c
6482 --- linux-3.9.4/fs/proc/meminfo.c       2013-05-31 13:45:25.000000000 +0000
6483 +++ linux-3.9.4-vs2.3.6.1/fs/proc/meminfo.c     2013-05-31 16:05:39.000000000 +0000
6484 @@ -39,7 +39,8 @@ static int meminfo_proc_show(struct seq_
6485         allowed = ((totalram_pages - hugetlb_total_pages())
6486                 * sysctl_overcommit_ratio / 100) + total_swap_pages;
6487  
6488 -       cached = global_page_state(NR_FILE_PAGES) -
6489 +       cached = vx_flags(VXF_VIRT_MEM, 0) ?
6490 +               vx_vsi_cached(&i) : global_page_state(NR_FILE_PAGES) -
6491                         total_swapcache_pages() - i.bufferram;
6492         if (cached < 0)
6493                 cached = 0;
6494 diff -NurpP --minimal linux-3.9.4/fs/proc/root.c linux-3.9.4-vs2.3.6.1/fs/proc/root.c
6495 --- linux-3.9.4/fs/proc/root.c  2013-05-31 13:45:25.000000000 +0000
6496 +++ linux-3.9.4-vs2.3.6.1/fs/proc/root.c        2013-05-31 14:47:11.000000000 +0000
6497 @@ -20,9 +20,14 @@
6498  #include <linux/mount.h>
6499  #include <linux/pid_namespace.h>
6500  #include <linux/parser.h>
6501 +#include <linux/vserver/inode.h>
6502  
6503  #include "internal.h"
6504  
6505 +struct proc_dir_entry *proc_virtual;
6506 +
6507 +extern void proc_vx_init(void);
6508 +
6509  static int proc_test_super(struct super_block *sb, void *data)
6510  {
6511         return sb->s_fs_info == data;
6512 @@ -182,6 +187,7 @@ void __init proc_root_init(void)
6513  #endif
6514         proc_mkdir("bus", NULL);
6515         proc_sys_init();
6516 +       proc_vx_init();
6517  }
6518  
6519  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
6520 @@ -248,6 +254,7 @@ struct proc_dir_entry proc_root = {
6521         .proc_iops      = &proc_root_inode_operations, 
6522         .proc_fops      = &proc_root_operations,
6523         .parent         = &proc_root,
6524 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
6525         .name           = "/proc",
6526  };
6527  
6528 diff -NurpP --minimal linux-3.9.4/fs/proc/self.c linux-3.9.4-vs2.3.6.1/fs/proc/self.c
6529 --- linux-3.9.4/fs/proc/self.c  2013-02-19 13:58:49.000000000 +0000
6530 +++ linux-3.9.4-vs2.3.6.1/fs/proc/self.c        2013-05-31 20:57:54.000000000 +0000
6531 @@ -1,6 +1,7 @@
6532  #include <linux/proc_fs.h>
6533  #include <linux/sched.h>
6534  #include <linux/namei.h>
6535 +#include <linux/vserver/inode.h>
6536  
6537  /*
6538   * /proc/self:
6539 @@ -56,4 +57,5 @@ void __init proc_self_init(void)
6540         mode = S_IFLNK | S_IRWXUGO;
6541         proc_self_symlink = proc_create("self", mode, NULL, NULL );
6542         proc_self_symlink->proc_iops = &proc_self_inode_operations;
6543 +       proc_self_symlink->vx_flags = IATTR_PROC_SYMLINK;
6544  }
6545 diff -NurpP --minimal linux-3.9.4/fs/proc/stat.c linux-3.9.4-vs2.3.6.1/fs/proc/stat.c
6546 --- linux-3.9.4/fs/proc/stat.c  2012-12-11 03:30:57.000000000 +0000
6547 +++ linux-3.9.4-vs2.3.6.1/fs/proc/stat.c        2013-05-31 14:47:11.000000000 +0000
6548 @@ -9,8 +9,10 @@
6549  #include <linux/slab.h>
6550  #include <linux/time.h>
6551  #include <linux/irqnr.h>
6552 +#include <linux/vserver/cvirt.h>
6553  #include <asm/cputime.h>
6554  #include <linux/tick.h>
6555 +#include <linux/cpuset.h>
6556  
6557  #ifndef arch_irq_stat_cpu
6558  #define arch_irq_stat_cpu(cpu) 0
6559 @@ -87,14 +89,26 @@ static int show_stat(struct seq_file *p,
6560         u64 sum_softirq = 0;
6561         unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
6562         struct timespec boottime;
6563 +       cpumask_var_t cpus_allowed;
6564 +       bool virt_cpu = vx_flags(VXF_VIRT_CPU, 0);
6565  
6566         user = nice = system = idle = iowait =
6567                 irq = softirq = steal = 0;
6568         guest = guest_nice = 0;
6569         getboottime(&boottime);
6570 +
6571 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6572 +               vx_vsi_boottime(&boottime);
6573 +
6574 +       if (virt_cpu)
6575 +               cpuset_cpus_allowed(current, cpus_allowed);
6576 +
6577         jif = boottime.tv_sec;
6578  
6579         for_each_possible_cpu(i) {
6580 +               if (virt_cpu && !cpumask_test_cpu(i, cpus_allowed))
6581 +                       continue;
6582 +
6583                 user += kcpustat_cpu(i).cpustat[CPUTIME_USER];
6584                 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
6585                 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
6586 @@ -131,6 +145,9 @@ static int show_stat(struct seq_file *p,
6587         seq_putc(p, '\n');
6588  
6589         for_each_online_cpu(i) {
6590 +               if (virt_cpu && !cpumask_test_cpu(i, cpus_allowed))
6591 +                       continue;
6592 +
6593                 /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
6594                 user = kcpustat_cpu(i).cpustat[CPUTIME_USER];
6595                 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
6596 diff -NurpP --minimal linux-3.9.4/fs/proc/uptime.c linux-3.9.4-vs2.3.6.1/fs/proc/uptime.c
6597 --- linux-3.9.4/fs/proc/uptime.c        2012-12-11 03:30:57.000000000 +0000
6598 +++ linux-3.9.4-vs2.3.6.1/fs/proc/uptime.c      2013-05-31 14:47:11.000000000 +0000
6599 @@ -5,6 +5,7 @@
6600  #include <linux/seq_file.h>
6601  #include <linux/time.h>
6602  #include <linux/kernel_stat.h>
6603 +#include <linux/vserver/cvirt.h>
6604  #include <asm/cputime.h>
6605  
6606  static int uptime_proc_show(struct seq_file *m, void *v)
6607 @@ -25,6 +26,10 @@ static int uptime_proc_show(struct seq_f
6608         nsec = cputime64_to_jiffies64(idletime) * TICK_NSEC;
6609         idle.tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem);
6610         idle.tv_nsec = rem;
6611 +
6612 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6613 +               vx_vsi_uptime(&uptime, &idle);
6614 +
6615         seq_printf(m, "%lu.%02lu %lu.%02lu\n",
6616                         (unsigned long) uptime.tv_sec,
6617                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
6618 diff -NurpP --minimal linux-3.9.4/fs/proc_namespace.c linux-3.9.4-vs2.3.6.1/fs/proc_namespace.c
6619 --- linux-3.9.4/fs/proc_namespace.c     2012-12-11 03:30:57.000000000 +0000
6620 +++ linux-3.9.4-vs2.3.6.1/fs/proc_namespace.c   2013-05-31 17:17:53.000000000 +0000
6621 @@ -44,6 +44,8 @@ static int show_sb_opts(struct seq_file
6622                 { MS_SYNCHRONOUS, ",sync" },
6623                 { MS_DIRSYNC, ",dirsync" },
6624                 { MS_MANDLOCK, ",mand" },
6625 +               { MS_TAGGED, ",tag" },
6626 +               { MS_NOTAGCHECK, ",notagcheck" },
6627                 { 0, NULL }
6628         };
6629         const struct proc_fs_info *fs_infop;
6630 @@ -80,6 +82,40 @@ static inline void mangle(struct seq_fil
6631         seq_escape(m, s, " \t\n\\");
6632  }
6633  
6634 +#ifdef CONFIG_VSERVER_EXTRA_MNT_CHECK
6635 +
6636 +static int mnt_is_reachable(struct vfsmount *vfsmnt)
6637 +{
6638 +       struct path root;
6639 +       struct dentry *point;
6640 +       struct mount *mnt = real_mount(vfsmnt);
6641 +       struct mount *root_mnt;
6642 +       int ret;
6643 +
6644 +       if (mnt == mnt->mnt_ns->root)
6645 +               return 1;
6646 +
6647 +       br_read_lock(&vfsmount_lock);
6648 +       root = current->fs->root;
6649 +       root_mnt = real_mount(root.mnt);
6650 +       point = root.dentry;
6651 +
6652 +       while ((mnt != mnt->mnt_parent) && (mnt != root_mnt)) {
6653 +               point = mnt->mnt_mountpoint;
6654 +               mnt = mnt->mnt_parent;
6655 +       }
6656 +
6657 +       ret = (mnt == root_mnt) && is_subdir(point, root.dentry);
6658 +
6659 +       br_read_unlock(&vfsmount_lock);
6660 +
6661 +       return ret;
6662 +}
6663 +
6664 +#else
6665 +#define        mnt_is_reachable(v)     (1)
6666 +#endif
6667 +
6668  static void show_type(struct seq_file *m, struct super_block *sb)
6669  {
6670         mangle(m, sb->s_type->name);
6671 @@ -96,6 +132,17 @@ static int show_vfsmnt(struct seq_file *
6672         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
6673         struct super_block *sb = mnt_path.dentry->d_sb;
6674  
6675 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6676 +               return SEQ_SKIP;
6677 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6678 +               return SEQ_SKIP;
6679 +
6680 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6681 +               mnt == current->fs->root.mnt) {
6682 +               seq_puts(m, "/dev/root / ");
6683 +               goto type;
6684 +       }
6685 +
6686         if (sb->s_op->show_devname) {
6687                 err = sb->s_op->show_devname(m, mnt_path.dentry);
6688                 if (err)
6689 @@ -106,6 +153,7 @@ static int show_vfsmnt(struct seq_file *
6690         seq_putc(m, ' ');
6691         seq_path(m, &mnt_path, " \t\n\\");
6692         seq_putc(m, ' ');
6693 +type:
6694         show_type(m, sb);
6695         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
6696         err = show_sb_opts(m, sb);
6697 @@ -128,6 +176,11 @@ static int show_mountinfo(struct seq_fil
6698         struct path root = p->root;
6699         int err = 0;
6700  
6701 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6702 +               return SEQ_SKIP;
6703 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6704 +               return SEQ_SKIP;
6705 +
6706         seq_printf(m, "%i %i %u:%u ", r->mnt_id, r->mnt_parent->mnt_id,
6707                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
6708         if (sb->s_op->show_path)
6709 @@ -187,6 +240,17 @@ static int show_vfsstat(struct seq_file
6710         struct super_block *sb = mnt_path.dentry->d_sb;
6711         int err = 0;
6712  
6713 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6714 +               return SEQ_SKIP;
6715 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6716 +               return SEQ_SKIP;
6717 +
6718 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6719 +               mnt == current->fs->root.mnt) {
6720 +               seq_puts(m, "device /dev/root mounted on / ");
6721 +               goto type;
6722 +       }
6723 +
6724         /* device */
6725         if (sb->s_op->show_devname) {
6726                 seq_puts(m, "device ");
6727 @@ -203,7 +267,7 @@ static int show_vfsstat(struct seq_file
6728         seq_puts(m, " mounted on ");
6729         seq_path(m, &mnt_path, " \t\n\\");
6730         seq_putc(m, ' ');
6731 -
6732 +type:
6733         /* file system type */
6734         seq_puts(m, "with fstype ");
6735         show_type(m, sb);
6736 diff -NurpP --minimal linux-3.9.4/fs/quota/dquot.c linux-3.9.4-vs2.3.6.1/fs/quota/dquot.c
6737 --- linux-3.9.4/fs/quota/dquot.c        2013-05-31 13:45:25.000000000 +0000
6738 +++ linux-3.9.4-vs2.3.6.1/fs/quota/dquot.c      2013-05-31 14:47:11.000000000 +0000
6739 @@ -1585,6 +1585,9 @@ int __dquot_alloc_space(struct inode *in
6740         struct dquot **dquots = inode->i_dquot;
6741         int reserve = flags & DQUOT_SPACE_RESERVE;
6742  
6743 +       if ((ret = dl_alloc_space(inode, number)))
6744 +               return ret;
6745 +
6746         /*
6747          * First test before acquiring mutex - solves deadlocks when we
6748          * re-enter the quota code and are already holding the mutex
6749 @@ -1640,6 +1643,9 @@ int dquot_alloc_inode(const struct inode
6750         struct dquot_warn warn[MAXQUOTAS];
6751         struct dquot * const *dquots = inode->i_dquot;
6752  
6753 +       if ((ret = dl_alloc_inode(inode)))
6754 +               return ret;
6755 +
6756         /* First test before acquiring mutex - solves deadlocks when we
6757           * re-enter the quota code and are already holding the mutex */
6758         if (!dquot_active(inode))
6759 @@ -1711,6 +1717,8 @@ void __dquot_free_space(struct inode *in
6760         struct dquot **dquots = inode->i_dquot;
6761         int reserve = flags & DQUOT_SPACE_RESERVE;
6762  
6763 +       dl_free_space(inode, number);
6764 +
6765         /* First test before acquiring mutex - solves deadlocks when we
6766           * re-enter the quota code and are already holding the mutex */
6767         if (!dquot_active(inode)) {
6768 @@ -1755,6 +1763,8 @@ void dquot_free_inode(const struct inode
6769         struct dquot_warn warn[MAXQUOTAS];
6770         struct dquot * const *dquots = inode->i_dquot;
6771  
6772 +       dl_free_inode(inode);
6773 +
6774         /* First test before acquiring mutex - solves deadlocks when we
6775           * re-enter the quota code and are already holding the mutex */
6776         if (!dquot_active(inode))
6777 diff -NurpP --minimal linux-3.9.4/fs/quota/quota.c linux-3.9.4-vs2.3.6.1/fs/quota/quota.c
6778 --- linux-3.9.4/fs/quota/quota.c        2013-02-19 13:58:49.000000000 +0000
6779 +++ linux-3.9.4-vs2.3.6.1/fs/quota/quota.c      2013-05-31 14:47:11.000000000 +0000
6780 @@ -8,6 +8,7 @@
6781  #include <linux/fs.h>
6782  #include <linux/namei.h>
6783  #include <linux/slab.h>
6784 +#include <linux/vs_context.h>
6785  #include <asm/current.h>
6786  #include <linux/uaccess.h>
6787  #include <linux/kernel.h>
6788 @@ -37,7 +38,7 @@ static int check_quotactl_permission(str
6789                         break;
6790                 /*FALLTHROUGH*/
6791         default:
6792 -               if (!capable(CAP_SYS_ADMIN))
6793 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
6794                         return -EPERM;
6795         }
6796  
6797 @@ -309,6 +310,46 @@ static int do_quotactl(struct super_bloc
6798  
6799  #ifdef CONFIG_BLOCK
6800  
6801 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6802 +
6803 +#include <linux/vroot.h>
6804 +#include <linux/major.h>
6805 +#include <linux/module.h>
6806 +#include <linux/kallsyms.h>
6807 +#include <linux/vserver/debug.h>
6808 +
6809 +static vroot_grb_func *vroot_get_real_bdev = NULL;
6810 +
6811 +static DEFINE_SPINLOCK(vroot_grb_lock);
6812 +
6813 +int register_vroot_grb(vroot_grb_func *func) {
6814 +       int ret = -EBUSY;
6815 +
6816 +       spin_lock(&vroot_grb_lock);
6817 +       if (!vroot_get_real_bdev) {
6818 +               vroot_get_real_bdev = func;
6819 +               ret = 0;
6820 +       }
6821 +       spin_unlock(&vroot_grb_lock);
6822 +       return ret;
6823 +}
6824 +EXPORT_SYMBOL(register_vroot_grb);
6825 +
6826 +int unregister_vroot_grb(vroot_grb_func *func) {
6827 +       int ret = -EINVAL;
6828 +
6829 +       spin_lock(&vroot_grb_lock);
6830 +       if (vroot_get_real_bdev) {
6831 +               vroot_get_real_bdev = NULL;
6832 +               ret = 0;
6833 +       }
6834 +       spin_unlock(&vroot_grb_lock);
6835 +       return ret;
6836 +}
6837 +EXPORT_SYMBOL(unregister_vroot_grb);
6838 +
6839 +#endif
6840 +
6841  /* Return 1 if 'cmd' will block on frozen filesystem */
6842  static int quotactl_cmd_write(int cmd)
6843  {
6844 @@ -343,6 +384,22 @@ static struct super_block *quotactl_bloc
6845         putname(tmp);
6846         if (IS_ERR(bdev))
6847                 return ERR_CAST(bdev);
6848 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6849 +       if (bdev && bdev->bd_inode &&
6850 +               imajor(bdev->bd_inode) == VROOT_MAJOR) {
6851 +               struct block_device *bdnew = (void *)-EINVAL;
6852 +
6853 +               if (vroot_get_real_bdev)
6854 +                       bdnew = vroot_get_real_bdev(bdev);
6855 +               else
6856 +                       vxdprintk(VXD_CBIT(misc, 0),
6857 +                                       "vroot_get_real_bdev not set");
6858 +               bdput(bdev);
6859 +               if (IS_ERR(bdnew))
6860 +                       return ERR_PTR(PTR_ERR(bdnew));
6861 +               bdev = bdnew;
6862 +       }
6863 +#endif
6864         if (quotactl_cmd_write(cmd))
6865                 sb = get_super_thawed(bdev);
6866         else
6867 diff -NurpP --minimal linux-3.9.4/fs/stat.c linux-3.9.4-vs2.3.6.1/fs/stat.c
6868 --- linux-3.9.4/fs/stat.c       2013-05-31 13:45:25.000000000 +0000
6869 +++ linux-3.9.4-vs2.3.6.1/fs/stat.c     2013-05-31 14:47:11.000000000 +0000
6870 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
6871         stat->nlink = inode->i_nlink;
6872         stat->uid = inode->i_uid;
6873         stat->gid = inode->i_gid;
6874 +       stat->tag = inode->i_tag;
6875         stat->rdev = inode->i_rdev;
6876         stat->size = i_size_read(inode);
6877         stat->atime = inode->i_atime;
6878 diff -NurpP --minimal linux-3.9.4/fs/statfs.c linux-3.9.4-vs2.3.6.1/fs/statfs.c
6879 --- linux-3.9.4/fs/statfs.c     2013-02-19 13:58:49.000000000 +0000
6880 +++ linux-3.9.4-vs2.3.6.1/fs/statfs.c   2013-05-31 14:47:11.000000000 +0000
6881 @@ -7,6 +7,8 @@
6882  #include <linux/statfs.h>
6883  #include <linux/security.h>
6884  #include <linux/uaccess.h>
6885 +#include <linux/vs_base.h>
6886 +#include <linux/vs_dlimit.h>
6887  #include "internal.h"
6888  
6889  static int flags_by_mnt(int mnt_flags)
6890 @@ -60,6 +62,8 @@ static int statfs_by_dentry(struct dentr
6891         retval = dentry->d_sb->s_op->statfs(dentry, buf);
6892         if (retval == 0 && buf->f_frsize == 0)
6893                 buf->f_frsize = buf->f_bsize;
6894 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
6895 +               vx_vsi_statfs(dentry->d_sb, buf);
6896         return retval;
6897  }
6898  
6899 diff -NurpP --minimal linux-3.9.4/fs/super.c linux-3.9.4-vs2.3.6.1/fs/super.c
6900 --- linux-3.9.4/fs/super.c      2013-05-31 13:45:25.000000000 +0000
6901 +++ linux-3.9.4-vs2.3.6.1/fs/super.c    2013-05-31 14:47:11.000000000 +0000
6902 @@ -34,6 +34,8 @@
6903  #include <linux/cleancache.h>
6904  #include <linux/fsnotify.h>
6905  #include <linux/lockdep.h>
6906 +#include <linux/magic.h>
6907 +#include <linux/vs_context.h>
6908  #include "internal.h"
6909  
6910  
6911 @@ -1117,6 +1119,13 @@ mount_fs(struct file_system_type *type,
6912         WARN_ON(sb->s_bdi == &default_backing_dev_info);
6913         sb->s_flags |= MS_BORN;
6914  
6915 +       error = -EPERM;
6916 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) &&
6917 +               !sb->s_bdev &&
6918 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
6919 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
6920 +               goto out_sb;
6921 +
6922         error = security_sb_kern_mount(sb, flags, secdata);
6923         if (error)
6924                 goto out_sb;
6925 diff -NurpP --minimal linux-3.9.4/fs/sysfs/mount.c linux-3.9.4-vs2.3.6.1/fs/sysfs/mount.c
6926 --- linux-3.9.4/fs/sysfs/mount.c        2013-05-31 13:45:25.000000000 +0000
6927 +++ linux-3.9.4-vs2.3.6.1/fs/sysfs/mount.c      2013-05-31 14:47:11.000000000 +0000
6928 @@ -48,7 +48,7 @@ static int sysfs_fill_super(struct super
6929  
6930         sb->s_blocksize = PAGE_CACHE_SIZE;
6931         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
6932 -       sb->s_magic = SYSFS_MAGIC;
6933 +       sb->s_magic = SYSFS_SUPER_MAGIC;
6934         sb->s_op = &sysfs_ops;
6935         sb->s_time_gran = 1;
6936  
6937 diff -NurpP --minimal linux-3.9.4/fs/utimes.c linux-3.9.4-vs2.3.6.1/fs/utimes.c
6938 --- linux-3.9.4/fs/utimes.c     2013-02-19 13:58:49.000000000 +0000
6939 +++ linux-3.9.4-vs2.3.6.1/fs/utimes.c   2013-05-31 22:40:16.000000000 +0000
6940 @@ -8,6 +8,8 @@
6941  #include <linux/stat.h>
6942  #include <linux/utime.h>
6943  #include <linux/syscalls.h>
6944 +#include <linux/mount.h>
6945 +#include <linux/vs_cowbl.h>
6946  #include <asm/uaccess.h>
6947  #include <asm/unistd.h>
6948  
6949 @@ -52,12 +54,18 @@ static int utimes_common(struct path *pa
6950  {
6951         int error;
6952         struct iattr newattrs;
6953 -       struct inode *inode = path->dentry->d_inode;
6954 +       struct inode *inode;
6955 +
6956 +       error = cow_check_and_break(path);
6957 +       if (error)
6958 +               goto out;
6959  
6960         error = mnt_want_write(path->mnt);
6961         if (error)
6962                 goto out;
6963  
6964 +       inode = path->dentry->d_inode;
6965 +
6966         if (times && times[0].tv_nsec == UTIME_NOW &&
6967                      times[1].tv_nsec == UTIME_NOW)
6968                 times = NULL;
6969 diff -NurpP --minimal linux-3.9.4/fs/xattr.c linux-3.9.4-vs2.3.6.1/fs/xattr.c
6970 --- linux-3.9.4/fs/xattr.c      2013-02-19 13:58:49.000000000 +0000
6971 +++ linux-3.9.4-vs2.3.6.1/fs/xattr.c    2013-05-31 14:47:11.000000000 +0000
6972 @@ -21,6 +21,7 @@
6973  #include <linux/audit.h>
6974  #include <linux/vmalloc.h>
6975  #include <linux/posix_acl_xattr.h>
6976 +#include <linux/mount.h>
6977  
6978  #include <asm/uaccess.h>
6979  
6980 @@ -52,7 +53,7 @@ xattr_permission(struct inode *inode, co
6981          * The trusted.* namespace can only be accessed by privileged users.
6982          */
6983         if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN)) {
6984 -               if (!capable(CAP_SYS_ADMIN))
6985 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_FS_TRUSTED))
6986                         return (mask & MAY_WRITE) ? -EPERM : -ENODATA;
6987                 return 0;
6988         }
6989 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_dinode.h linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_dinode.h
6990 --- linux-3.9.4/fs/xfs/xfs_dinode.h     2012-12-11 03:30:57.000000000 +0000
6991 +++ linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_dinode.h   2013-05-31 14:47:11.000000000 +0000
6992 @@ -51,7 +51,9 @@ typedef struct xfs_dinode {
6993         __be32          di_nlink;       /* number of links to file */
6994         __be16          di_projid_lo;   /* lower part of owner's project id */
6995         __be16          di_projid_hi;   /* higher part owner's project id */
6996 -       __u8            di_pad[6];      /* unused, zeroed space */
6997 +       __u8            di_pad[2];      /* unused, zeroed space */
6998 +       __be16          di_tag;         /* context tagging */
6999 +       __be16          di_vflags;      /* vserver specific flags */
7000         __be16          di_flushiter;   /* incremented on flush */
7001         xfs_timestamp_t di_atime;       /* time last accessed */
7002         xfs_timestamp_t di_mtime;       /* time last modified */
7003 @@ -184,6 +186,8 @@ static inline void xfs_dinode_put_rdev(s
7004  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
7005  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
7006  #define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
7007 +#define XFS_DIFLAG_IXUNLINK_BIT     15 /* Immutable inver on unlink */
7008 +
7009  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
7010  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
7011  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
7012 @@ -199,6 +203,7 @@ static inline void xfs_dinode_put_rdev(s
7013  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
7014  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
7015  #define XFS_DIFLAG_FILESTREAM    (1 << XFS_DIFLAG_FILESTREAM_BIT)
7016 +#define XFS_DIFLAG_IXUNLINK      (1 << XFS_DIFLAG_IXUNLINK_BIT)
7017  
7018  #ifdef CONFIG_XFS_RT
7019  #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
7020 @@ -211,6 +216,10 @@ static inline void xfs_dinode_put_rdev(s
7021          XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
7022          XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
7023          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
7024 -        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
7025 +        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM | \
7026 +        XFS_DIFLAG_IXUNLINK)
7027 +
7028 +#define XFS_DIVFLAG_BARRIER    0x01
7029 +#define XFS_DIVFLAG_COW                0x02
7030  
7031  #endif /* __XFS_DINODE_H__ */
7032 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_fs.h linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_fs.h
7033 --- linux-3.9.4/fs/xfs/xfs_fs.h 2013-02-19 13:58:49.000000000 +0000
7034 +++ linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_fs.h       2013-05-31 14:47:11.000000000 +0000
7035 @@ -67,6 +67,9 @@ struct fsxattr {
7036  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
7037  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
7038  #define XFS_XFLAG_FILESTREAM   0x00004000      /* use filestream allocator */
7039 +#define XFS_XFLAG_IXUNLINK     0x00008000      /* immutable invert on unlink */
7040 +#define XFS_XFLAG_BARRIER      0x10000000      /* chroot() barrier */
7041 +#define XFS_XFLAG_COW          0x20000000      /* copy on write mark */
7042  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
7043  
7044  /*
7045 @@ -303,7 +306,8 @@ typedef struct xfs_bstat {
7046  #define        bs_projid       bs_projid_lo    /* (previously just bs_projid)  */
7047         __u16           bs_forkoff;     /* inode fork offset in bytes   */
7048         __u16           bs_projid_hi;   /* higher part of project id    */
7049 -       unsigned char   bs_pad[10];     /* pad space, unused            */
7050 +       unsigned char   bs_pad[8];      /* pad space, unused            */
7051 +       __u16           bs_tag;         /* context tagging              */
7052         __u32           bs_dmevmask;    /* DMIG event mask              */
7053         __u16           bs_dmstate;     /* DMIG state info              */
7054         __u16           bs_aextents;    /* attribute number of extents  */
7055 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_ialloc.c linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_ialloc.c
7056 --- linux-3.9.4/fs/xfs/xfs_ialloc.c     2013-05-31 13:45:25.000000000 +0000
7057 +++ linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_ialloc.c   2013-05-31 14:47:11.000000000 +0000
7058 @@ -37,7 +37,6 @@
7059  #include "xfs_error.h"
7060  #include "xfs_bmap.h"
7061  
7062 -
7063  /*
7064   * Allocation group level functions.
7065   */
7066 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_inode.c linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_inode.c
7067 --- linux-3.9.4/fs/xfs/xfs_inode.c      2013-05-31 13:45:25.000000000 +0000
7068 +++ linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_inode.c    2013-05-31 14:47:11.000000000 +0000
7069 @@ -16,6 +16,7 @@
7070   * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
7071   */
7072  #include <linux/log2.h>
7073 +#include <linux/vs_tag.h>
7074  
7075  #include "xfs.h"
7076  #include "xfs_fs.h"
7077 @@ -835,15 +836,25 @@ xfs_iformat_btree(
7078  STATIC void
7079  xfs_dinode_from_disk(
7080         xfs_icdinode_t          *to,
7081 -       xfs_dinode_t            *from)
7082 +       xfs_dinode_t            *from,
7083 +       int                     tagged)
7084  {
7085 +       uint32_t uid, gid, tag;
7086 +
7087         to->di_magic = be16_to_cpu(from->di_magic);
7088         to->di_mode = be16_to_cpu(from->di_mode);
7089         to->di_version = from ->di_version;
7090         to->di_format = from->di_format;
7091         to->di_onlink = be16_to_cpu(from->di_onlink);
7092 -       to->di_uid = be32_to_cpu(from->di_uid);
7093 -       to->di_gid = be32_to_cpu(from->di_gid);
7094 +
7095 +       uid = be32_to_cpu(from->di_uid);
7096 +       gid = be32_to_cpu(from->di_gid);
7097 +       tag = be16_to_cpu(from->di_tag);
7098 +
7099 +       to->di_uid = INOTAG_UID(tagged, uid, gid);
7100 +       to->di_gid = INOTAG_GID(tagged, uid, gid);
7101 +       to->di_tag = INOTAG_TAG(tagged, uid, gid, tag);
7102 +
7103         to->di_nlink = be32_to_cpu(from->di_nlink);
7104         to->di_projid_lo = be16_to_cpu(from->di_projid_lo);
7105         to->di_projid_hi = be16_to_cpu(from->di_projid_hi);
7106 @@ -865,21 +876,26 @@ xfs_dinode_from_disk(
7107         to->di_dmevmask = be32_to_cpu(from->di_dmevmask);
7108         to->di_dmstate  = be16_to_cpu(from->di_dmstate);
7109         to->di_flags    = be16_to_cpu(from->di_flags);
7110 +       to->di_vflags   = be16_to_cpu(from->di_vflags);
7111         to->di_gen      = be32_to_cpu(from->di_gen);
7112  }
7113  
7114  void
7115  xfs_dinode_to_disk(
7116         xfs_dinode_t            *to,
7117 -       xfs_icdinode_t          *from)
7118 +       xfs_icdinode_t          *from,
7119 +       int                     tagged)
7120  {
7121         to->di_magic = cpu_to_be16(from->di_magic);
7122         to->di_mode = cpu_to_be16(from->di_mode);
7123         to->di_version = from ->di_version;
7124         to->di_format = from->di_format;
7125         to->di_onlink = cpu_to_be16(from->di_onlink);
7126 -       to->di_uid = cpu_to_be32(from->di_uid);
7127 -       to->di_gid = cpu_to_be32(from->di_gid);
7128 +
7129 +       to->di_uid = cpu_to_be32(TAGINO_UID(tagged, from->di_uid, from->di_tag));
7130 +       to->di_gid = cpu_to_be32(TAGINO_GID(tagged, from->di_gid, from->di_tag));
7131 +       to->di_tag = cpu_to_be16(TAGINO_TAG(tagged, from->di_tag));
7132 +
7133         to->di_nlink = cpu_to_be32(from->di_nlink);
7134         to->di_projid_lo = cpu_to_be16(from->di_projid_lo);
7135         to->di_projid_hi = cpu_to_be16(from->di_projid_hi);
7136 @@ -901,12 +917,14 @@ xfs_dinode_to_disk(
7137         to->di_dmevmask = cpu_to_be32(from->di_dmevmask);
7138         to->di_dmstate = cpu_to_be16(from->di_dmstate);
7139         to->di_flags = cpu_to_be16(from->di_flags);
7140 +       to->di_vflags = cpu_to_be16(from->di_vflags);
7141         to->di_gen = cpu_to_be32(from->di_gen);
7142  }
7143  
7144  STATIC uint
7145  _xfs_dic2xflags(
7146 -       __uint16_t              di_flags)
7147 +       __uint16_t              di_flags,
7148 +       __uint16_t              di_vflags)
7149  {
7150         uint                    flags = 0;
7151  
7152 @@ -917,6 +935,8 @@ _xfs_dic2xflags(
7153                         flags |= XFS_XFLAG_PREALLOC;
7154                 if (di_flags & XFS_DIFLAG_IMMUTABLE)
7155                         flags |= XFS_XFLAG_IMMUTABLE;
7156 +               if (di_flags & XFS_DIFLAG_IXUNLINK)
7157 +                       flags |= XFS_XFLAG_IXUNLINK;
7158                 if (di_flags & XFS_DIFLAG_APPEND)
7159                         flags |= XFS_XFLAG_APPEND;
7160                 if (di_flags & XFS_DIFLAG_SYNC)
7161 @@ -941,6 +961,10 @@ _xfs_dic2xflags(
7162                         flags |= XFS_XFLAG_FILESTREAM;
7163         }
7164  
7165 +       if (di_vflags & XFS_DIVFLAG_BARRIER)
7166 +               flags |= FS_BARRIER_FL;
7167 +       if (di_vflags & XFS_DIVFLAG_COW)
7168 +               flags |= FS_COW_FL;
7169         return flags;
7170  }
7171  
7172 @@ -950,7 +974,7 @@ xfs_ip2xflags(
7173  {
7174         xfs_icdinode_t          *dic = &ip->i_d;
7175  
7176 -       return _xfs_dic2xflags(dic->di_flags) |
7177 +       return _xfs_dic2xflags(dic->di_flags, dic->di_vflags) |
7178                                 (XFS_IFORK_Q(ip) ? XFS_XFLAG_HASATTR : 0);
7179  }
7180  
7181 @@ -958,7 +982,8 @@ uint
7182  xfs_dic2xflags(
7183         xfs_dinode_t            *dip)
7184  {
7185 -       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags)) |
7186 +       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags),
7187 +                               be16_to_cpu(dip->di_vflags)) |
7188                                 (XFS_DFORK_Q(dip) ? XFS_XFLAG_HASATTR : 0);
7189  }
7190  
7191 @@ -1012,7 +1037,8 @@ xfs_iread(
7192          * Otherwise, just get the truly permanent information.
7193          */
7194         if (dip->di_mode) {
7195 -               xfs_dinode_from_disk(&ip->i_d, dip);
7196 +               xfs_dinode_from_disk(&ip->i_d, dip,
7197 +                       mp->m_flags & XFS_MOUNT_TAGGED);
7198                 error = xfs_iformat(ip, dip);
7199                 if (error)  {
7200  #ifdef DEBUG
7201 @@ -1199,6 +1225,7 @@ xfs_ialloc(
7202         ASSERT(ip->i_d.di_nlink == nlink);
7203         ip->i_d.di_uid = current_fsuid();
7204         ip->i_d.di_gid = current_fsgid();
7205 +       ip->i_d.di_tag = current_fstag(&ip->i_vnode);
7206         xfs_set_projid(ip, prid);
7207         memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
7208  
7209 @@ -1258,6 +1285,7 @@ xfs_ialloc(
7210         ip->i_d.di_dmevmask = 0;
7211         ip->i_d.di_dmstate = 0;
7212         ip->i_d.di_flags = 0;
7213 +       ip->i_d.di_vflags = 0;
7214         flags = XFS_ILOG_CORE;
7215         switch (mode & S_IFMT) {
7216         case S_IFIFO:
7217 @@ -1952,6 +1980,7 @@ xfs_ifree(
7218         }
7219         ip->i_d.di_mode = 0;            /* mark incore inode as free */
7220         ip->i_d.di_flags = 0;
7221 +       ip->i_d.di_vflags = 0;
7222         ip->i_d.di_dmevmask = 0;
7223         ip->i_d.di_forkoff = 0;         /* mark the attr fork not in use */
7224         ip->i_d.di_format = XFS_DINODE_FMT_EXTENTS;
7225 @@ -2118,7 +2147,6 @@ xfs_iroot_realloc(
7226         return;
7227  }
7228  
7229 -
7230  /*
7231   * This is called when the amount of space needed for if_data
7232   * is increased or decreased.  The change in size is indicated by
7233 @@ -2800,7 +2828,8 @@ xfs_iflush_int(
7234          * because if the inode is dirty at all the core must
7235          * be.
7236          */
7237 -       xfs_dinode_to_disk(dip, &ip->i_d);
7238 +       xfs_dinode_to_disk(dip, &ip->i_d,
7239 +               mp->m_flags & XFS_MOUNT_TAGGED);
7240  
7241         /* Wrap, we never let the log put out DI_MAX_FLUSH */
7242         if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
7243 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_inode.h linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_inode.h
7244 --- linux-3.9.4/fs/xfs/xfs_inode.h      2013-05-31 13:45:25.000000000 +0000
7245 +++ linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_inode.h    2013-05-31 14:47:11.000000000 +0000
7246 @@ -134,7 +134,9 @@ typedef struct xfs_icdinode {
7247         __uint32_t      di_nlink;       /* number of links to file */
7248         __uint16_t      di_projid_lo;   /* lower part of owner's project id */
7249         __uint16_t      di_projid_hi;   /* higher part of owner's project id */
7250 -       __uint8_t       di_pad[6];      /* unused, zeroed space */
7251 +       __uint8_t       di_pad[2];      /* unused, zeroed space */
7252 +       __uint16_t      di_tag;         /* context tagging */
7253 +       __uint16_t      di_vflags;      /* vserver specific flags */
7254         __uint16_t      di_flushiter;   /* incremented on flush */
7255         xfs_ictimestamp_t di_atime;     /* time last accessed */
7256         xfs_ictimestamp_t di_mtime;     /* time last modified */
7257 @@ -556,7 +558,7 @@ int         xfs_imap_to_bp(struct xfs_mount *,
7258  int            xfs_iread(struct xfs_mount *, struct xfs_trans *,
7259                           struct xfs_inode *, uint);
7260  void           xfs_dinode_to_disk(struct xfs_dinode *,
7261 -                                  struct xfs_icdinode *);
7262 +                                  struct xfs_icdinode *, int);
7263  void           xfs_idestroy_fork(struct xfs_inode *, int);
7264  void           xfs_idata_realloc(struct xfs_inode *, int, int);
7265  void           xfs_iroot_realloc(struct xfs_inode *, int, int);
7266 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_ioctl.c linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_ioctl.c
7267 --- linux-3.9.4/fs/xfs/xfs_ioctl.c      2013-05-31 13:45:25.000000000 +0000
7268 +++ linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_ioctl.c    2013-05-31 14:47:11.000000000 +0000
7269 @@ -26,7 +26,7 @@
7270  #include "xfs_bmap_btree.h"
7271  #include "xfs_dinode.h"
7272  #include "xfs_inode.h"
7273 -#include "xfs_ioctl.h"
7274 +// #include "xfs_ioctl.h"
7275  #include "xfs_rtalloc.h"
7276  #include "xfs_itable.h"
7277  #include "xfs_error.h"
7278 @@ -763,6 +763,10 @@ xfs_merge_ioc_xflags(
7279                 xflags |= XFS_XFLAG_IMMUTABLE;
7280         else
7281                 xflags &= ~XFS_XFLAG_IMMUTABLE;
7282 +       if (flags & FS_IXUNLINK_FL)
7283 +               xflags |= XFS_XFLAG_IXUNLINK;
7284 +       else
7285 +               xflags &= ~XFS_XFLAG_IXUNLINK;
7286         if (flags & FS_APPEND_FL)
7287                 xflags |= XFS_XFLAG_APPEND;
7288         else
7289 @@ -791,6 +795,8 @@ xfs_di2lxflags(
7290  
7291         if (di_flags & XFS_DIFLAG_IMMUTABLE)
7292                 flags |= FS_IMMUTABLE_FL;
7293 +       if (di_flags & XFS_DIFLAG_IXUNLINK)
7294 +               flags |= FS_IXUNLINK_FL;
7295         if (di_flags & XFS_DIFLAG_APPEND)
7296                 flags |= FS_APPEND_FL;
7297         if (di_flags & XFS_DIFLAG_SYNC)
7298 @@ -851,6 +857,8 @@ xfs_set_diflags(
7299         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
7300         if (xflags & XFS_XFLAG_IMMUTABLE)
7301                 di_flags |= XFS_DIFLAG_IMMUTABLE;
7302 +       if (xflags & XFS_XFLAG_IXUNLINK)
7303 +               di_flags |= XFS_DIFLAG_IXUNLINK;
7304         if (xflags & XFS_XFLAG_APPEND)
7305                 di_flags |= XFS_DIFLAG_APPEND;
7306         if (xflags & XFS_XFLAG_SYNC)
7307 @@ -893,6 +901,10 @@ xfs_diflags_to_linux(
7308                 inode->i_flags |= S_IMMUTABLE;
7309         else
7310                 inode->i_flags &= ~S_IMMUTABLE;
7311 +       if (xflags & XFS_XFLAG_IXUNLINK)
7312 +               inode->i_flags |= S_IXUNLINK;
7313 +       else
7314 +               inode->i_flags &= ~S_IXUNLINK;
7315         if (xflags & XFS_XFLAG_APPEND)
7316                 inode->i_flags |= S_APPEND;
7317         else
7318 @@ -1397,10 +1409,18 @@ xfs_file_ioctl(
7319         case XFS_IOC_FSGETXATTRA:
7320                 return xfs_ioc_fsgetxattr(ip, 1, arg);
7321         case XFS_IOC_FSSETXATTR:
7322 +               if (IS_BARRIER(inode)) {
7323 +                       vxwprintk_task(1, "messing with the barrier.");
7324 +                       return -XFS_ERROR(EACCES);
7325 +               }
7326                 return xfs_ioc_fssetxattr(ip, filp, arg);
7327         case XFS_IOC_GETXFLAGS:
7328                 return xfs_ioc_getxflags(ip, arg);
7329         case XFS_IOC_SETXFLAGS:
7330 +               if (IS_BARRIER(inode)) {
7331 +                       vxwprintk_task(1, "messing with the barrier.");
7332 +                       return -XFS_ERROR(EACCES);
7333 +               }
7334                 return xfs_ioc_setxflags(ip, filp, arg);
7335  
7336         case XFS_IOC_FSSETDM: {
7337 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_ioctl.h linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_ioctl.h
7338 --- linux-3.9.4/fs/xfs/xfs_ioctl.h      2012-12-11 03:30:57.000000000 +0000
7339 +++ linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_ioctl.h    2013-05-31 14:47:11.000000000 +0000
7340 @@ -70,6 +70,12 @@ xfs_handle_to_dentry(
7341         void __user             *uhandle,
7342         u32                     hlen);
7343  
7344 +extern int
7345 +xfs_sync_flags(
7346 +       struct inode            *inode,
7347 +       int                     flags,
7348 +       int                     vflags);
7349 +
7350  extern long
7351  xfs_file_ioctl(
7352         struct file             *filp,
7353 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_iops.c linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_iops.c
7354 --- linux-3.9.4/fs/xfs/xfs_iops.c       2013-02-19 13:58:49.000000000 +0000
7355 +++ linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_iops.c     2013-05-31 14:47:11.000000000 +0000
7356 @@ -28,6 +28,7 @@
7357  #include "xfs_bmap_btree.h"
7358  #include "xfs_dinode.h"
7359  #include "xfs_inode.h"
7360 +#include "xfs_ioctl.h"
7361  #include "xfs_bmap.h"
7362  #include "xfs_rtalloc.h"
7363  #include "xfs_error.h"
7364 @@ -47,6 +48,7 @@
7365  #include <linux/security.h>
7366  #include <linux/fiemap.h>
7367  #include <linux/slab.h>
7368 +#include <linux/vs_tag.h>
7369  
7370  static int
7371  xfs_initxattrs(
7372 @@ -422,6 +424,7 @@ xfs_vn_getattr(
7373         stat->nlink = ip->i_d.di_nlink;
7374         stat->uid = ip->i_d.di_uid;
7375         stat->gid = ip->i_d.di_gid;
7376 +       stat->tag = ip->i_d.di_tag;
7377         stat->ino = ip->i_ino;
7378         stat->atime = inode->i_atime;
7379         stat->mtime = inode->i_mtime;
7380 @@ -1037,6 +1040,7 @@ static const struct inode_operations xfs
7381         .listxattr              = xfs_vn_listxattr,
7382         .fiemap                 = xfs_vn_fiemap,
7383         .update_time            = xfs_vn_update_time,
7384 +       .sync_flags             = xfs_sync_flags,
7385  };
7386  
7387  static const struct inode_operations xfs_dir_inode_operations = {
7388 @@ -1063,6 +1067,7 @@ static const struct inode_operations xfs
7389         .removexattr            = generic_removexattr,
7390         .listxattr              = xfs_vn_listxattr,
7391         .update_time            = xfs_vn_update_time,
7392 +       .sync_flags             = xfs_sync_flags,
7393  };
7394  
7395  static const struct inode_operations xfs_dir_ci_inode_operations = {
7396 @@ -1114,6 +1119,10 @@ xfs_diflags_to_iflags(
7397                 inode->i_flags |= S_IMMUTABLE;
7398         else
7399                 inode->i_flags &= ~S_IMMUTABLE;
7400 +       if (ip->i_d.di_flags & XFS_DIFLAG_IXUNLINK)
7401 +               inode->i_flags |= S_IXUNLINK;
7402 +       else
7403 +               inode->i_flags &= ~S_IXUNLINK;
7404         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
7405                 inode->i_flags |= S_APPEND;
7406         else
7407 @@ -1126,6 +1135,15 @@ xfs_diflags_to_iflags(
7408                 inode->i_flags |= S_NOATIME;
7409         else
7410                 inode->i_flags &= ~S_NOATIME;
7411 +
7412 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_BARRIER)
7413 +               inode->i_vflags |= V_BARRIER;
7414 +       else
7415 +               inode->i_vflags &= ~V_BARRIER;
7416 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_COW)
7417 +               inode->i_vflags |= V_COW;
7418 +       else
7419 +               inode->i_vflags &= ~V_COW;
7420  }
7421  
7422  /*
7423 @@ -1157,6 +1175,7 @@ xfs_setup_inode(
7424         set_nlink(inode, ip->i_d.di_nlink);
7425         inode->i_uid    = ip->i_d.di_uid;
7426         inode->i_gid    = ip->i_d.di_gid;
7427 +       inode->i_tag    = ip->i_d.di_tag;
7428  
7429         switch (inode->i_mode & S_IFMT) {
7430         case S_IFBLK:
7431 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_itable.c linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_itable.c
7432 --- linux-3.9.4/fs/xfs/xfs_itable.c     2013-02-19 13:58:49.000000000 +0000
7433 +++ linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_itable.c   2013-05-31 14:47:11.000000000 +0000
7434 @@ -97,6 +97,7 @@ xfs_bulkstat_one_int(
7435         buf->bs_mode = dic->di_mode;
7436         buf->bs_uid = dic->di_uid;
7437         buf->bs_gid = dic->di_gid;
7438 +       buf->bs_tag = dic->di_tag;
7439         buf->bs_size = dic->di_size;
7440         buf->bs_atime.tv_sec = dic->di_atime.t_sec;
7441         buf->bs_atime.tv_nsec = dic->di_atime.t_nsec;
7442 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_linux.h linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_linux.h
7443 --- linux-3.9.4/fs/xfs/xfs_linux.h      2013-02-19 13:58:49.000000000 +0000
7444 +++ linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_linux.h    2013-05-31 14:47:11.000000000 +0000
7445 @@ -123,6 +123,7 @@
7446  
7447  #define current_cpu()          (raw_smp_processor_id())
7448  #define current_pid()          (current->pid)
7449 +#define current_fstag(vp)      (dx_current_fstag((vp)->i_sb))
7450  #define current_test_flags(f)  (current->flags & (f))
7451  #define current_set_flags_nested(sp, f)                \
7452                 (*(sp) = current->flags, current->flags |= (f))
7453 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_log_recover.c linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_log_recover.c
7454 --- linux-3.9.4/fs/xfs/xfs_log_recover.c        2013-05-31 13:45:25.000000000 +0000
7455 +++ linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_log_recover.c      2013-05-31 14:47:11.000000000 +0000
7456 @@ -2361,7 +2361,8 @@ xlog_recover_inode_pass2(
7457         }
7458  
7459         /* The core is in in-core format */
7460 -       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr);
7461 +       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr,
7462 +               mp->m_flags & XFS_MOUNT_TAGGED);
7463  
7464         /* the rest is in on-disk format */
7465         if (item->ri_buf[1].i_len > sizeof(struct xfs_icdinode)) {
7466 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_mount.h linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_mount.h
7467 --- linux-3.9.4/fs/xfs/xfs_mount.h      2013-05-31 13:45:25.000000000 +0000
7468 +++ linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_mount.h    2013-05-31 14:47:11.000000000 +0000
7469 @@ -254,6 +254,7 @@ typedef struct xfs_mount {
7470                                                    allocator */
7471  #define XFS_MOUNT_NOATTR2      (1ULL << 25)    /* disable use of attr2 format */
7472  
7473 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
7474  
7475  /*
7476   * Default minimum read and write sizes.
7477 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_super.c linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_super.c
7478 --- linux-3.9.4/fs/xfs/xfs_super.c      2013-05-31 13:45:25.000000000 +0000
7479 +++ linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_super.c    2013-05-31 14:47:11.000000000 +0000
7480 @@ -114,6 +114,9 @@ mempool_t *xfs_ioend_pool;
7481  #define MNTOPT_NODELAYLOG  "nodelaylog"        /* Delayed logging disabled */
7482  #define MNTOPT_DISCARD    "discard"    /* Discard unused blocks */
7483  #define MNTOPT_NODISCARD   "nodiscard" /* Do not discard unused blocks */
7484 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
7485 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
7486 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
7487  
7488  /*
7489   * Table driven mount option parser.
7490 @@ -126,6 +129,8 @@ enum {
7491         Opt_nobarrier,
7492         Opt_inode64,
7493         Opt_inode32,
7494 +       Opt_tag,
7495 +       Opt_notag,
7496         Opt_err
7497  };
7498  
7499 @@ -134,6 +139,9 @@ static const match_table_t tokens = {
7500         {Opt_nobarrier, "nobarrier"},
7501         {Opt_inode64, "inode64"},
7502         {Opt_inode32, "inode32"},
7503 +       {Opt_tag, "tagxid"},
7504 +       {Opt_tag, "tag"},
7505 +       {Opt_notag, "notag"},
7506         {Opt_err, NULL}
7507  };
7508  
7509 @@ -392,6 +400,19 @@ xfs_parseargs(
7510                 } else if (!strcmp(this_char, "irixsgid")) {
7511                         xfs_warn(mp,
7512         "irixsgid is now a sysctl(2) variable, option is deprecated.");
7513 +#ifndef CONFIG_TAGGING_NONE
7514 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7515 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7516 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
7517 +                       mp->m_flags &= ~XFS_MOUNT_TAGGED;
7518 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
7519 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7520 +#endif
7521 +#ifdef CONFIG_PROPAGATE
7522 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7523 +                       /* use value */
7524 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7525 +#endif
7526                 } else {
7527                         xfs_warn(mp, "unknown mount option [%s].", this_char);
7528                         return EINVAL;
7529 @@ -1238,6 +1259,16 @@ xfs_fs_remount(
7530                 case Opt_inode32:
7531                         mp->m_maxagi = xfs_set_inode32(mp);
7532                         break;
7533 +               case Opt_tag:
7534 +                       if (!(sb->s_flags & MS_TAGGED)) {
7535 +                               printk(KERN_INFO
7536 +                                       "XFS: %s: tagging not permitted on remount.\n",
7537 +                                       sb->s_id);
7538 +                               return -EINVAL;
7539 +                       }
7540 +                       break;
7541 +               case Opt_notag:
7542 +                       break;
7543                 default:
7544                         /*
7545                          * Logically we would return an error here to prevent
7546 @@ -1458,6 +1489,9 @@ xfs_fs_fill_super(
7547         if (error)
7548                 goto out_free_sb;
7549  
7550 +       if (mp->m_flags & XFS_MOUNT_TAGGED)
7551 +               sb->s_flags |= MS_TAGGED;
7552 +
7553         /*
7554          * we must configure the block size in the superblock before we run the
7555          * full mount process as the mount process can lookup and cache inodes.
7556 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_vnodeops.c linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_vnodeops.c
7557 --- linux-3.9.4/fs/xfs/xfs_vnodeops.c   2013-05-31 13:45:25.000000000 +0000
7558 +++ linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_vnodeops.c 2013-05-31 14:47:11.000000000 +0000
7559 @@ -104,6 +104,77 @@ xfs_readlink_bmap(
7560         return error;
7561  }
7562  
7563 +
7564 +STATIC void
7565 +xfs_get_inode_flags(
7566 +       xfs_inode_t     *ip)
7567 +{
7568 +       struct inode    *inode = VFS_I(ip);
7569 +       unsigned int    flags = inode->i_flags;
7570 +       unsigned int    vflags = inode->i_vflags;
7571 +
7572 +       if (flags & S_IMMUTABLE)
7573 +               ip->i_d.di_flags |= XFS_DIFLAG_IMMUTABLE;
7574 +       else
7575 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IMMUTABLE;
7576 +       if (flags & S_IXUNLINK)
7577 +               ip->i_d.di_flags |= XFS_DIFLAG_IXUNLINK;
7578 +       else
7579 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IXUNLINK;
7580 +
7581 +       if (vflags & V_BARRIER)
7582 +               ip->i_d.di_vflags |= XFS_DIVFLAG_BARRIER;
7583 +       else
7584 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_BARRIER;
7585 +       if (vflags & V_COW)
7586 +               ip->i_d.di_vflags |= XFS_DIVFLAG_COW;
7587 +       else
7588 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_COW;
7589 +}
7590 +
7591 +int
7592 +xfs_sync_flags(
7593 +       struct inode            *inode,
7594 +       int                     flags,
7595 +       int                     vflags)
7596 +{
7597 +       struct xfs_inode        *ip = XFS_I(inode);
7598 +       struct xfs_mount        *mp = ip->i_mount;
7599 +       struct xfs_trans        *tp;
7600 +       unsigned int            lock_flags = 0;
7601 +       int                     code;
7602 +
7603 +       tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
7604 +       code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
7605 +       if (code)
7606 +               goto error_out;
7607 +
7608 +       xfs_ilock(ip, XFS_ILOCK_EXCL);
7609 +       xfs_trans_ijoin(tp, ip, 0);
7610 +
7611 +       inode->i_flags = flags;
7612 +       inode->i_vflags = vflags;
7613 +       xfs_get_inode_flags(ip);
7614 +
7615 +       xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
7616 +       xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG);
7617 +
7618 +       XFS_STATS_INC(xs_ig_attrchg);
7619 +
7620 +       if (mp->m_flags & XFS_MOUNT_WSYNC)
7621 +               xfs_trans_set_sync(tp);
7622 +       code = xfs_trans_commit(tp, 0);
7623 +       xfs_iunlock(ip, XFS_ILOCK_EXCL);
7624 +       return code;
7625 +
7626 +error_out:
7627 +       xfs_trans_cancel(tp, 0);
7628 +       if (lock_flags)
7629 +               xfs_iunlock(ip, XFS_ILOCK_EXCL);
7630 +       return code;
7631 +}
7632 +
7633 +
7634  int
7635  xfs_readlink(
7636         xfs_inode_t     *ip,
7637 diff -NurpP --minimal linux-3.9.4/include/linux/cred.h linux-3.9.4-vs2.3.6.1/include/linux/cred.h
7638 --- linux-3.9.4/include/linux/cred.h    2013-02-19 13:58:50.000000000 +0000
7639 +++ linux-3.9.4-vs2.3.6.1/include/linux/cred.h  2013-05-31 14:47:11.000000000 +0000
7640 @@ -143,6 +143,7 @@ extern void exit_creds(struct task_struc
7641  extern int copy_creds(struct task_struct *, unsigned long);
7642  extern const struct cred *get_task_cred(struct task_struct *);
7643  extern struct cred *cred_alloc_blank(void);
7644 +extern struct cred *__prepare_creds(const struct cred *);
7645  extern struct cred *prepare_creds(void);
7646  extern struct cred *prepare_exec_creds(void);
7647  extern int commit_creds(struct cred *);
7648 @@ -196,6 +197,31 @@ static inline void validate_process_cred
7649  }
7650  #endif
7651  
7652 +static inline void set_cred_subscribers(struct cred *cred, int n)
7653 +{
7654 +#ifdef CONFIG_DEBUG_CREDENTIALS
7655 +       atomic_set(&cred->subscribers, n);
7656 +#endif
7657 +}
7658 +
7659 +static inline int read_cred_subscribers(const struct cred *cred)
7660 +{
7661 +#ifdef CONFIG_DEBUG_CREDENTIALS
7662 +       return atomic_read(&cred->subscribers);
7663 +#else
7664 +       return 0;
7665 +#endif
7666 +}
7667 +
7668 +static inline void alter_cred_subscribers(const struct cred *_cred, int n)
7669 +{
7670 +#ifdef CONFIG_DEBUG_CREDENTIALS
7671 +       struct cred *cred = (struct cred *) _cred;
7672 +
7673 +       atomic_add(n, &cred->subscribers);
7674 +#endif
7675 +}
7676 +
7677  /**
7678   * get_new_cred - Get a reference on a new set of credentials
7679   * @cred: The new credentials to reference
7680 diff -NurpP --minimal linux-3.9.4/include/linux/devpts_fs.h linux-3.9.4-vs2.3.6.1/include/linux/devpts_fs.h
7681 --- linux-3.9.4/include/linux/devpts_fs.h       2013-02-19 13:58:50.000000000 +0000
7682 +++ linux-3.9.4-vs2.3.6.1/include/linux/devpts_fs.h     2013-05-31 14:47:11.000000000 +0000
7683 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
7684  
7685  #endif
7686  
7687 -
7688  #endif /* _LINUX_DEVPTS_FS_H */
7689 diff -NurpP --minimal linux-3.9.4/include/linux/fs.h linux-3.9.4-vs2.3.6.1/include/linux/fs.h
7690 --- linux-3.9.4/include/linux/fs.h      2013-05-31 13:45:27.000000000 +0000
7691 +++ linux-3.9.4-vs2.3.6.1/include/linux/fs.h    2013-05-31 14:47:11.000000000 +0000
7692 @@ -211,6 +211,7 @@ typedef void (dio_iodone_t)(struct kiocb
7693  #define ATTR_KILL_PRIV (1 << 14)
7694  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
7695  #define ATTR_TIMES_SET (1 << 16)
7696 +#define ATTR_TAG       (1 << 17)
7697  
7698  /*
7699   * This is the Inode Attributes structure, used for notify_change().  It
7700 @@ -226,6 +227,7 @@ struct iattr {
7701         umode_t         ia_mode;
7702         kuid_t          ia_uid;
7703         kgid_t          ia_gid;
7704 +       ktag_t          ia_tag;
7705         loff_t          ia_size;
7706         struct timespec ia_atime;
7707         struct timespec ia_mtime;
7708 @@ -523,7 +525,9 @@ struct inode {
7709         unsigned short          i_opflags;
7710         kuid_t                  i_uid;
7711         kgid_t                  i_gid;
7712 -       unsigned int            i_flags;
7713 +       ktag_t                  i_tag;
7714 +       unsigned short          i_flags;
7715 +       unsigned short          i_vflags;
7716  
7717  #ifdef CONFIG_FS_POSIX_ACL
7718         struct posix_acl        *i_acl;
7719 @@ -552,6 +556,7 @@ struct inode {
7720                 unsigned int __i_nlink;
7721         };
7722         dev_t                   i_rdev;
7723 +       dev_t                   i_mdev;
7724         loff_t                  i_size;
7725         struct timespec         i_atime;
7726         struct timespec         i_mtime;
7727 @@ -702,6 +707,11 @@ static inline gid_t i_gid_read(const str
7728         return from_kgid(&init_user_ns, inode->i_gid);
7729  }
7730  
7731 +static inline tag_t i_tag_read(const struct inode *inode)
7732 +{
7733 +       return from_ktag(&init_user_ns, inode->i_tag);
7734 +}
7735 +
7736  static inline void i_uid_write(struct inode *inode, uid_t uid)
7737  {
7738         inode->i_uid = make_kuid(&init_user_ns, uid);
7739 @@ -712,14 +722,19 @@ static inline void i_gid_write(struct in
7740         inode->i_gid = make_kgid(&init_user_ns, gid);
7741  }
7742  
7743 +static inline void i_tag_write(struct inode *inode, tag_t tag)
7744 +{
7745 +       inode->i_tag = make_ktag(&init_user_ns, tag);
7746 +}
7747 +
7748  static inline unsigned iminor(const struct inode *inode)
7749  {
7750 -       return MINOR(inode->i_rdev);
7751 +       return MINOR(inode->i_mdev);
7752  }
7753  
7754  static inline unsigned imajor(const struct inode *inode)
7755  {
7756 -       return MAJOR(inode->i_rdev);
7757 +       return MAJOR(inode->i_mdev);
7758  }
7759  
7760  extern struct block_device *I_BDEV(struct inode *inode);
7761 @@ -786,6 +801,7 @@ struct file {
7762         loff_t                  f_pos;
7763         struct fown_struct      f_owner;
7764         const struct cred       *f_cred;
7765 +       xid_t                   f_xid;
7766         struct file_ra_state    f_ra;
7767  
7768         u64                     f_version;
7769 @@ -937,6 +953,7 @@ struct file_lock {
7770         struct file *fl_file;
7771         loff_t fl_start;
7772         loff_t fl_end;
7773 +       xid_t fl_xid;
7774  
7775         struct fasync_struct *  fl_fasync; /* for lease break notifications */
7776         /* for lease breaks: */
7777 @@ -1567,6 +1584,7 @@ struct inode_operations {
7778         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
7779         ssize_t (*listxattr) (struct dentry *, char *, size_t);
7780         int (*removexattr) (struct dentry *, const char *);
7781 +       int (*sync_flags) (struct inode *, int, int);
7782         int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
7783                       u64 len);
7784         int (*update_time)(struct inode *, struct timespec *, int);
7785 @@ -1579,6 +1597,7 @@ ssize_t rw_copy_check_uvector(int type,
7786                               unsigned long nr_segs, unsigned long fast_segs,
7787                               struct iovec *fast_pointer,
7788                               struct iovec **ret_pointer);
7789 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
7790  
7791  extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
7792  extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *);
7793 @@ -1632,6 +1651,14 @@ struct super_operations {
7794  #define S_IMA          1024    /* Inode has an associated IMA struct */
7795  #define S_AUTOMOUNT    2048    /* Automount/referral quasi-directory */
7796  #define S_NOSEC                4096    /* no suid or xattr security attributes */
7797 +#define S_IXUNLINK     8192    /* Immutable Invert on unlink */
7798 +
7799 +/* Linux-VServer related Inode flags */
7800 +
7801 +#define V_VALID                1
7802 +#define V_XATTR                2
7803 +#define V_BARRIER      4       /* Barrier for chroot() */
7804 +#define V_COW          8       /* Copy on Write */
7805  
7806  /*
7807   * Note that nosuid etc flags are inode-specific: setting some file-system
7808 @@ -1656,10 +1683,13 @@ struct super_operations {
7809  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
7810  #define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
7811  #define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
7812 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
7813  
7814  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
7815  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
7816  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
7817 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
7818 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
7819  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
7820  
7821  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
7822 @@ -1670,6 +1700,16 @@ struct super_operations {
7823  #define IS_AUTOMOUNT(inode)    ((inode)->i_flags & S_AUTOMOUNT)
7824  #define IS_NOSEC(inode)                ((inode)->i_flags & S_NOSEC)
7825  
7826 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
7827 +
7828 +#ifdef CONFIG_VSERVER_COWBL
7829 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
7830 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
7831 +#else
7832 +#  define IS_COW(inode)                (0)
7833 +#  define IS_COW_LINK(inode)   (0)
7834 +#endif
7835 +
7836  /*
7837   * Inode state bits.  Protected by inode->i_lock
7838   *
7839 @@ -1898,6 +1938,9 @@ extern int rw_verify_area(int, struct fi
7840  extern int locks_mandatory_locked(struct inode *);
7841  extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t);
7842  
7843 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
7844 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
7845 +
7846  /*
7847   * Candidates for mandatory locking have the setgid bit set
7848   * but no group execute bit -  an otherwise meaningless combination.
7849 @@ -2509,6 +2552,7 @@ extern int dcache_dir_open(struct inode
7850  extern int dcache_dir_close(struct inode *, struct file *);
7851  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
7852  extern int dcache_readdir(struct file *, void *, filldir_t);
7853 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
7854  extern int simple_setattr(struct dentry *, struct iattr *);
7855  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
7856  extern int simple_statfs(struct dentry *, struct kstatfs *);
7857 diff -NurpP --minimal linux-3.9.4/include/linux/init_task.h linux-3.9.4-vs2.3.6.1/include/linux/init_task.h
7858 --- linux-3.9.4/include/linux/init_task.h       2013-05-31 13:45:27.000000000 +0000
7859 +++ linux-3.9.4-vs2.3.6.1/include/linux/init_task.h     2013-05-31 14:53:41.000000000 +0000
7860 @@ -222,6 +222,10 @@ extern struct task_group root_task_group
7861         INIT_TASK_RCU_PREEMPT(tsk)                                      \
7862         INIT_CPUSET_SEQ                                                 \
7863         INIT_VTIME(tsk)                                                 \
7864 +       .xid            = 0,                                            \
7865 +       .vx_info        = NULL,                                         \
7866 +       .nid            = 0,                                            \
7867 +       .nx_info        = NULL,                                         \
7868  }
7869  
7870  
7871 diff -NurpP --minimal linux-3.9.4/include/linux/ipc.h linux-3.9.4-vs2.3.6.1/include/linux/ipc.h
7872 --- linux-3.9.4/include/linux/ipc.h     2012-12-11 03:30:57.000000000 +0000
7873 +++ linux-3.9.4-vs2.3.6.1/include/linux/ipc.h   2013-05-31 14:47:11.000000000 +0000
7874 @@ -16,6 +16,7 @@ struct kern_ipc_perm
7875         key_t           key;
7876         kuid_t          uid;
7877         kgid_t          gid;
7878 +       xid_t           xid;
7879         kuid_t          cuid;
7880         kgid_t          cgid;
7881         umode_t         mode; 
7882 diff -NurpP --minimal linux-3.9.4/include/linux/loop.h linux-3.9.4-vs2.3.6.1/include/linux/loop.h
7883 --- linux-3.9.4/include/linux/loop.h    2013-02-19 13:58:51.000000000 +0000
7884 +++ linux-3.9.4-vs2.3.6.1/include/linux/loop.h  2013-05-31 14:47:11.000000000 +0000
7885 @@ -41,6 +41,7 @@ struct loop_device {
7886         struct loop_func_table *lo_encryption;
7887         __u32           lo_init[2];
7888         kuid_t          lo_key_owner;   /* Who set the key */
7889 +       xid_t           lo_xid;
7890         int             (*ioctl)(struct loop_device *, int cmd, 
7891                                  unsigned long arg); 
7892  
7893 diff -NurpP --minimal linux-3.9.4/include/linux/memcontrol.h linux-3.9.4-vs2.3.6.1/include/linux/memcontrol.h
7894 --- linux-3.9.4/include/linux/memcontrol.h      2013-05-31 13:45:28.000000000 +0000
7895 +++ linux-3.9.4-vs2.3.6.1/include/linux/memcontrol.h    2013-05-31 14:47:11.000000000 +0000
7896 @@ -86,6 +86,13 @@ extern struct mem_cgroup *try_get_mem_cg
7897  extern struct mem_cgroup *parent_mem_cgroup(struct mem_cgroup *memcg);
7898  extern struct mem_cgroup *mem_cgroup_from_cont(struct cgroup *cont);
7899  
7900 +extern u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member);
7901 +extern u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member);
7902 +
7903 +extern s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem);
7904 +extern s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem);
7905 +extern s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem);
7906 +
7907  static inline
7908  bool mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *memcg)
7909  {
7910 diff -NurpP --minimal linux-3.9.4/include/linux/mm_types.h linux-3.9.4-vs2.3.6.1/include/linux/mm_types.h
7911 --- linux-3.9.4/include/linux/mm_types.h        2013-05-31 13:45:28.000000000 +0000
7912 +++ linux-3.9.4-vs2.3.6.1/include/linux/mm_types.h      2013-05-31 14:47:11.000000000 +0000
7913 @@ -380,6 +380,7 @@ struct mm_struct {
7914  
7915         /* Architecture-specific MM context */
7916         mm_context_t context;
7917 +       struct vx_info *mm_vx_info;
7918  
7919         unsigned long flags; /* Must use atomic bitops to access the bits */
7920  
7921 diff -NurpP --minimal linux-3.9.4/include/linux/mount.h linux-3.9.4-vs2.3.6.1/include/linux/mount.h
7922 --- linux-3.9.4/include/linux/mount.h   2013-05-31 13:45:28.000000000 +0000
7923 +++ linux-3.9.4-vs2.3.6.1/include/linux/mount.h 2013-05-31 14:47:11.000000000 +0000
7924 @@ -49,6 +49,9 @@ struct mnt_namespace;
7925  
7926  #define MNT_LOCK_READONLY      0x400000
7927  
7928 +#define MNT_TAGID      0x10000
7929 +#define MNT_NOTAG      0x20000
7930 +
7931  struct vfsmount {
7932         struct dentry *mnt_root;        /* root of the mounted tree */
7933         struct super_block *mnt_sb;     /* pointer to superblock */
7934 diff -NurpP --minimal linux-3.9.4/include/linux/net.h linux-3.9.4-vs2.3.6.1/include/linux/net.h
7935 --- linux-3.9.4/include/linux/net.h     2012-12-11 03:30:57.000000000 +0000
7936 +++ linux-3.9.4-vs2.3.6.1/include/linux/net.h   2013-05-31 14:47:11.000000000 +0000
7937 @@ -38,6 +38,7 @@ struct net;
7938  #define SOCK_PASSCRED          3
7939  #define SOCK_PASSSEC           4
7940  #define SOCK_EXTERNALLY_ALLOCATED 5
7941 +#define SOCK_USER_SOCKET       6
7942  
7943  #ifndef ARCH_HAS_SOCKET_TYPES
7944  /**
7945 diff -NurpP --minimal linux-3.9.4/include/linux/netdevice.h linux-3.9.4-vs2.3.6.1/include/linux/netdevice.h
7946 --- linux-3.9.4/include/linux/netdevice.h       2013-05-31 13:45:28.000000000 +0000
7947 +++ linux-3.9.4-vs2.3.6.1/include/linux/netdevice.h     2013-05-31 14:47:11.000000000 +0000
7948 @@ -1688,6 +1688,7 @@ extern void               netdev_resync_ops(struct ne
7949  
7950  extern struct net_device       *dev_get_by_index(struct net *net, int ifindex);
7951  extern struct net_device       *__dev_get_by_index(struct net *net, int ifindex);
7952 +extern struct net_device       *dev_get_by_index_real_rcu(struct net *net, int ifindex);
7953  extern struct net_device       *dev_get_by_index_rcu(struct net *net, int ifindex);
7954  extern int             dev_restart(struct net_device *dev);
7955  #ifdef CONFIG_NETPOLL_TRAP
7956 diff -NurpP --minimal linux-3.9.4/include/linux/nsproxy.h linux-3.9.4-vs2.3.6.1/include/linux/nsproxy.h
7957 --- linux-3.9.4/include/linux/nsproxy.h 2013-02-19 13:58:51.000000000 +0000
7958 +++ linux-3.9.4-vs2.3.6.1/include/linux/nsproxy.h       2013-05-31 17:17:53.000000000 +0000
7959 @@ -3,6 +3,7 @@
7960  
7961  #include <linux/spinlock.h>
7962  #include <linux/sched.h>
7963 +#include <linux/vserver/debug.h>
7964  
7965  struct mnt_namespace;
7966  struct uts_namespace;
7967 @@ -63,6 +64,7 @@ static inline struct nsproxy *task_nspro
7968  }
7969  
7970  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
7971 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
7972  void exit_task_namespaces(struct task_struct *tsk);
7973  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
7974  void free_nsproxy(struct nsproxy *ns);
7975 @@ -70,16 +72,26 @@ int unshare_nsproxy_namespaces(unsigned
7976         struct cred *, struct fs_struct *);
7977  int __init nsproxy_cache_init(void);
7978  
7979 -static inline void put_nsproxy(struct nsproxy *ns)
7980 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
7981 +
7982 +static inline void __get_nsproxy(struct nsproxy *ns,
7983 +       const char *_file, int _line)
7984  {
7985 -       if (atomic_dec_and_test(&ns->count)) {
7986 -               free_nsproxy(ns);
7987 -       }
7988 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
7989 +               ns, atomic_read(&ns->count), _file, _line);
7990 +       atomic_inc(&ns->count);
7991  }
7992  
7993 -static inline void get_nsproxy(struct nsproxy *ns)
7994 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
7995 +
7996 +static inline void __put_nsproxy(struct nsproxy *ns,
7997 +       const char *_file, int _line)
7998  {
7999 -       atomic_inc(&ns->count);
8000 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
8001 +               ns, atomic_read(&ns->count), _file, _line);
8002 +       if (atomic_dec_and_test(&ns->count)) {
8003 +               free_nsproxy(ns);
8004 +       }
8005  }
8006  
8007  #endif
8008 diff -NurpP --minimal linux-3.9.4/include/linux/pid.h linux-3.9.4-vs2.3.6.1/include/linux/pid.h
8009 --- linux-3.9.4/include/linux/pid.h     2013-05-31 13:45:28.000000000 +0000
8010 +++ linux-3.9.4-vs2.3.6.1/include/linux/pid.h   2013-05-31 14:47:11.000000000 +0000
8011 @@ -8,7 +8,8 @@ enum pid_type
8012         PIDTYPE_PID,
8013         PIDTYPE_PGID,
8014         PIDTYPE_SID,
8015 -       PIDTYPE_MAX
8016 +       PIDTYPE_MAX,
8017 +       PIDTYPE_REALPID
8018  };
8019  
8020  /*
8021 @@ -172,6 +173,7 @@ static inline pid_t pid_nr(struct pid *p
8022  }
8023  
8024  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
8025 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
8026  pid_t pid_vnr(struct pid *pid);
8027  
8028  #define do_each_pid_task(pid, type, task)                              \
8029 diff -NurpP --minimal linux-3.9.4/include/linux/proc_fs.h linux-3.9.4-vs2.3.6.1/include/linux/proc_fs.h
8030 --- linux-3.9.4/include/linux/proc_fs.h 2013-05-31 13:45:28.000000000 +0000
8031 +++ linux-3.9.4-vs2.3.6.1/include/linux/proc_fs.h       2013-05-31 14:47:11.000000000 +0000
8032 @@ -58,6 +58,7 @@ struct proc_dir_entry {
8033         nlink_t nlink;
8034         kuid_t uid;
8035         kgid_t gid;
8036 +       int vx_flags;
8037         loff_t size;
8038         const struct inode_operations *proc_iops;
8039         /*
8040 @@ -274,12 +275,18 @@ extern const struct proc_ns_operations p
8041  extern const struct proc_ns_operations userns_operations;
8042  extern const struct proc_ns_operations mntns_operations;
8043  
8044 +struct vx_info;
8045 +struct nx_info;
8046 +
8047  union proc_op {
8048         int (*proc_get_link)(struct dentry *, struct path *);
8049         int (*proc_read)(struct task_struct *task, char *page);
8050         int (*proc_show)(struct seq_file *m,
8051                 struct pid_namespace *ns, struct pid *pid,
8052                 struct task_struct *task);
8053 +       int (*proc_vs_read)(char *page);
8054 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
8055 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
8056  };
8057  
8058  struct ctl_table_header;
8059 @@ -287,6 +294,7 @@ struct ctl_table;
8060  
8061  struct proc_inode {
8062         struct pid *pid;
8063 +       int vx_flags;
8064         int fd;
8065         union proc_op op;
8066         struct proc_dir_entry *pde;
8067 diff -NurpP --minimal linux-3.9.4/include/linux/quotaops.h linux-3.9.4-vs2.3.6.1/include/linux/quotaops.h
8068 --- linux-3.9.4/include/linux/quotaops.h        2012-12-11 03:30:57.000000000 +0000
8069 +++ linux-3.9.4-vs2.3.6.1/include/linux/quotaops.h      2013-05-31 14:47:11.000000000 +0000
8070 @@ -8,6 +8,7 @@
8071  #define _LINUX_QUOTAOPS_
8072  
8073  #include <linux/fs.h>
8074 +#include <linux/vs_dlimit.h>
8075  
8076  #define DQUOT_SPACE_WARN       0x1
8077  #define DQUOT_SPACE_RESERVE    0x2
8078 @@ -205,11 +206,12 @@ static inline void dquot_drop(struct ino
8079  
8080  static inline int dquot_alloc_inode(const struct inode *inode)
8081  {
8082 -       return 0;
8083 +       return dl_alloc_inode(inode);
8084  }
8085  
8086  static inline void dquot_free_inode(const struct inode *inode)
8087  {
8088 +       dl_free_inode(inode);
8089  }
8090  
8091  static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
8092 @@ -220,6 +222,10 @@ static inline int dquot_transfer(struct
8093  static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
8094                 int flags)
8095  {
8096 +       int ret = 0;
8097 +
8098 +       if ((ret = dl_alloc_space(inode, number)))
8099 +               return ret;
8100         if (!(flags & DQUOT_SPACE_RESERVE))
8101                 inode_add_bytes(inode, number);
8102         return 0;
8103 @@ -230,6 +236,7 @@ static inline void __dquot_free_space(st
8104  {
8105         if (!(flags & DQUOT_SPACE_RESERVE))
8106                 inode_sub_bytes(inode, number);
8107 +       dl_free_space(inode, number);
8108  }
8109  
8110  static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
8111 diff -NurpP --minimal linux-3.9.4/include/linux/sched.h linux-3.9.4-vs2.3.6.1/include/linux/sched.h
8112 --- linux-3.9.4/include/linux/sched.h   2013-05-31 14:22:27.000000000 +0000
8113 +++ linux-3.9.4-vs2.3.6.1/include/linux/sched.h 2013-05-31 14:47:11.000000000 +0000
8114 @@ -1398,6 +1398,14 @@ struct task_struct {
8115  #endif
8116         struct seccomp seccomp;
8117  
8118 +/* vserver context data */
8119 +       struct vx_info *vx_info;
8120 +       struct nx_info *nx_info;
8121 +
8122 +       xid_t xid;
8123 +       nid_t nid;
8124 +       tag_t tag;
8125 +
8126  /* Thread group tracking */
8127         u32 parent_exec_id;
8128         u32 self_exec_id;
8129 @@ -1637,6 +1645,11 @@ struct pid_namespace;
8130  pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
8131                         struct pid_namespace *ns);
8132  
8133 +#include <linux/vserver/base.h>
8134 +#include <linux/vserver/context.h>
8135 +#include <linux/vserver/debug.h>
8136 +#include <linux/vserver/pid.h>
8137 +
8138  static inline pid_t task_pid_nr(struct task_struct *tsk)
8139  {
8140         return tsk->pid;
8141 @@ -1650,7 +1663,8 @@ static inline pid_t task_pid_nr_ns(struc
8142  
8143  static inline pid_t task_pid_vnr(struct task_struct *tsk)
8144  {
8145 -       return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
8146 +       // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
8147 +       return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
8148  }
8149  
8150  
8151 @@ -1663,7 +1677,7 @@ pid_t task_tgid_nr_ns(struct task_struct
8152  
8153  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
8154  {
8155 -       return pid_vnr(task_tgid(tsk));
8156 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
8157  }
8158  
8159  
8160 diff -NurpP --minimal linux-3.9.4/include/linux/shmem_fs.h linux-3.9.4-vs2.3.6.1/include/linux/shmem_fs.h
8161 --- linux-3.9.4/include/linux/shmem_fs.h        2012-12-11 03:30:57.000000000 +0000
8162 +++ linux-3.9.4-vs2.3.6.1/include/linux/shmem_fs.h      2013-05-31 14:47:11.000000000 +0000
8163 @@ -9,6 +9,9 @@
8164  
8165  /* inode in-kernel data */
8166  
8167 +#define TMPFS_SUPER_MAGIC      0x01021994
8168 +
8169 +
8170  struct shmem_inode_info {
8171         spinlock_t              lock;
8172         unsigned long           flags;
8173 diff -NurpP --minimal linux-3.9.4/include/linux/stat.h linux-3.9.4-vs2.3.6.1/include/linux/stat.h
8174 --- linux-3.9.4/include/linux/stat.h    2012-12-11 03:30:57.000000000 +0000
8175 +++ linux-3.9.4-vs2.3.6.1/include/linux/stat.h  2013-05-31 14:47:11.000000000 +0000
8176 @@ -25,6 +25,7 @@ struct kstat {
8177         unsigned int    nlink;
8178         kuid_t          uid;
8179         kgid_t          gid;
8180 +       tag_t           tag;
8181         dev_t           rdev;
8182         loff_t          size;
8183         struct timespec  atime;
8184 diff -NurpP --minimal linux-3.9.4/include/linux/sunrpc/auth.h linux-3.9.4-vs2.3.6.1/include/linux/sunrpc/auth.h
8185 --- linux-3.9.4/include/linux/sunrpc/auth.h     2013-05-31 13:45:28.000000000 +0000
8186 +++ linux-3.9.4-vs2.3.6.1/include/linux/sunrpc/auth.h   2013-05-31 14:52:57.000000000 +0000
8187 @@ -26,6 +26,7 @@
8188  struct auth_cred {
8189         kuid_t  uid;
8190         kgid_t  gid;
8191 +       ktag_t  tag;
8192         struct group_info *group_info;
8193         const char *principal;
8194         unsigned char machine_cred : 1;
8195 diff -NurpP --minimal linux-3.9.4/include/linux/sunrpc/clnt.h linux-3.9.4-vs2.3.6.1/include/linux/sunrpc/clnt.h
8196 --- linux-3.9.4/include/linux/sunrpc/clnt.h     2013-05-31 13:45:28.000000000 +0000
8197 +++ linux-3.9.4-vs2.3.6.1/include/linux/sunrpc/clnt.h   2013-05-31 14:47:11.000000000 +0000
8198 @@ -49,7 +49,8 @@ struct rpc_clnt {
8199         unsigned int            cl_softrtry : 1,/* soft timeouts */
8200                                 cl_discrtry : 1,/* disconnect before retry */
8201                                 cl_autobind : 1,/* use getport() */
8202 -                               cl_chatty   : 1;/* be verbose */
8203 +                               cl_chatty   : 1,/* be verbose */
8204 +                               cl_tag      : 1;/* context tagging */
8205  
8206         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
8207         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
8208 diff -NurpP --minimal linux-3.9.4/include/linux/sysfs.h linux-3.9.4-vs2.3.6.1/include/linux/sysfs.h
8209 --- linux-3.9.4/include/linux/sysfs.h   2013-05-31 13:45:28.000000000 +0000
8210 +++ linux-3.9.4-vs2.3.6.1/include/linux/sysfs.h 2013-05-31 14:47:11.000000000 +0000
8211 @@ -19,6 +19,8 @@
8212  #include <linux/kobject_ns.h>
8213  #include <linux/atomic.h>
8214  
8215 +#define SYSFS_SUPER_MAGIC      0x62656572
8216 +
8217  struct kobject;
8218  struct module;
8219  enum kobj_ns_type;
8220 diff -NurpP --minimal linux-3.9.4/include/linux/types.h linux-3.9.4-vs2.3.6.1/include/linux/types.h
8221 --- linux-3.9.4/include/linux/types.h   2013-02-19 13:58:52.000000000 +0000
8222 +++ linux-3.9.4-vs2.3.6.1/include/linux/types.h 2013-05-31 14:47:11.000000000 +0000
8223 @@ -32,6 +32,9 @@ typedef __kernel_uid32_t      uid_t;
8224  typedef __kernel_gid32_t       gid_t;
8225  typedef __kernel_uid16_t        uid16_t;
8226  typedef __kernel_gid16_t        gid16_t;
8227 +typedef unsigned int           xid_t;
8228 +typedef unsigned int           nid_t;
8229 +typedef unsigned int           tag_t;
8230  
8231  typedef unsigned long          uintptr_t;
8232  
8233 diff -NurpP --minimal linux-3.9.4/include/linux/uidgid.h linux-3.9.4-vs2.3.6.1/include/linux/uidgid.h
8234 --- linux-3.9.4/include/linux/uidgid.h  2012-12-11 03:30:57.000000000 +0000
8235 +++ linux-3.9.4-vs2.3.6.1/include/linux/uidgid.h        2013-05-31 14:47:11.000000000 +0000
8236 @@ -23,13 +23,17 @@ typedef struct {
8237         uid_t val;
8238  } kuid_t;
8239  
8240 -
8241  typedef struct {
8242         gid_t val;
8243  } kgid_t;
8244  
8245 +typedef struct {
8246 +       tag_t val;
8247 +} ktag_t;
8248 +
8249  #define KUIDT_INIT(value) (kuid_t){ value }
8250  #define KGIDT_INIT(value) (kgid_t){ value }
8251 +#define KTAGT_INIT(value) (ktag_t){ value }
8252  
8253  static inline uid_t __kuid_val(kuid_t uid)
8254  {
8255 @@ -41,10 +45,16 @@ static inline gid_t __kgid_val(kgid_t gi
8256         return gid.val;
8257  }
8258  
8259 +static inline tag_t __ktag_val(ktag_t tag)
8260 +{
8261 +       return tag.val;
8262 +}
8263 +
8264  #else
8265  
8266  typedef uid_t kuid_t;
8267  typedef gid_t kgid_t;
8268 +typedef tag_t ktag_t;
8269  
8270  static inline uid_t __kuid_val(kuid_t uid)
8271  {
8272 @@ -56,16 +66,24 @@ static inline gid_t __kgid_val(kgid_t gi
8273         return gid;
8274  }
8275  
8276 +static inline tag_t __ktag_val(ktag_t tag)
8277 +{
8278 +       return tag;
8279 +}
8280 +
8281  #define KUIDT_INIT(value) ((kuid_t) value )
8282  #define KGIDT_INIT(value) ((kgid_t) value )
8283 +#define KTAGT_INIT(value) ((ktag_t) value )
8284  
8285  #endif
8286  
8287  #define GLOBAL_ROOT_UID KUIDT_INIT(0)
8288  #define GLOBAL_ROOT_GID KGIDT_INIT(0)
8289 +#define GLOBAL_ROOT_TAG KTAGT_INIT(0)
8290  
8291  #define INVALID_UID KUIDT_INIT(-1)
8292  #define INVALID_GID KGIDT_INIT(-1)
8293 +#define INVALID_TAG KTAGT_INIT(-1)
8294  
8295  static inline bool uid_eq(kuid_t left, kuid_t right)
8296  {
8297 @@ -77,6 +95,11 @@ static inline bool gid_eq(kgid_t left, k
8298         return __kgid_val(left) == __kgid_val(right);
8299  }
8300  
8301 +static inline bool tag_eq(ktag_t left, ktag_t right)
8302 +{
8303 +       return __ktag_val(left) == __ktag_val(right);
8304 +}
8305 +
8306  static inline bool uid_gt(kuid_t left, kuid_t right)
8307  {
8308         return __kuid_val(left) > __kuid_val(right);
8309 @@ -127,13 +150,21 @@ static inline bool gid_valid(kgid_t gid)
8310         return !gid_eq(gid, INVALID_GID);
8311  }
8312  
8313 +static inline bool tag_valid(ktag_t tag)
8314 +{
8315 +       return !tag_eq(tag, INVALID_TAG);
8316 +}
8317 +
8318  #ifdef CONFIG_USER_NS
8319  
8320  extern kuid_t make_kuid(struct user_namespace *from, uid_t uid);
8321  extern kgid_t make_kgid(struct user_namespace *from, gid_t gid);
8322 +extern krag_t make_ktag(struct user_namespace *from, gid_t gid);
8323  
8324  extern uid_t from_kuid(struct user_namespace *to, kuid_t uid);
8325  extern gid_t from_kgid(struct user_namespace *to, kgid_t gid);
8326 +extern tag_t from_ktag(struct user_namespace *to, ktag_t tag);
8327 +
8328  extern uid_t from_kuid_munged(struct user_namespace *to, kuid_t uid);
8329  extern gid_t from_kgid_munged(struct user_namespace *to, kgid_t gid);
8330  
8331 @@ -159,6 +190,11 @@ static inline kgid_t make_kgid(struct us
8332         return KGIDT_INIT(gid);
8333  }
8334  
8335 +static inline ktag_t make_ktag(struct user_namespace *from, tag_t tag)
8336 +{
8337 +       return KTAGT_INIT(tag);
8338 +}
8339 +
8340  static inline uid_t from_kuid(struct user_namespace *to, kuid_t kuid)
8341  {
8342         return __kuid_val(kuid);
8343 @@ -169,6 +205,11 @@ static inline gid_t from_kgid(struct use
8344         return __kgid_val(kgid);
8345  }
8346  
8347 +static inline tag_t from_ktag(struct user_namespace *to, ktag_t ktag)
8348 +{
8349 +       return __ktag_val(ktag);
8350 +}
8351 +
8352  static inline uid_t from_kuid_munged(struct user_namespace *to, kuid_t kuid)
8353  {
8354         uid_t uid = from_kuid(to, kuid);
8355 diff -NurpP --minimal linux-3.9.4/include/linux/vroot.h linux-3.9.4-vs2.3.6.1/include/linux/vroot.h
8356 --- linux-3.9.4/include/linux/vroot.h   1970-01-01 00:00:00.000000000 +0000
8357 +++ linux-3.9.4-vs2.3.6.1/include/linux/vroot.h 2013-05-31 14:47:11.000000000 +0000
8358 @@ -0,0 +1,51 @@
8359 +
8360 +/*
8361 + * include/linux/vroot.h
8362 + *
8363 + * written by Herbert Pötzl, 9/11/2002
8364 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
8365 + *
8366 + * Copyright (C) 2002-2007 by Herbert Pötzl.
8367 + * Redistribution of this file is permitted under the
8368 + * GNU General Public License.
8369 + */
8370 +
8371 +#ifndef _LINUX_VROOT_H
8372 +#define _LINUX_VROOT_H
8373 +
8374 +
8375 +#ifdef __KERNEL__
8376 +
8377 +/* Possible states of device */
8378 +enum {
8379 +       Vr_unbound,
8380 +       Vr_bound,
8381 +};
8382 +
8383 +struct vroot_device {
8384 +       int             vr_number;
8385 +       int             vr_refcnt;
8386 +
8387 +       struct semaphore        vr_ctl_mutex;
8388 +       struct block_device    *vr_device;
8389 +       int                     vr_state;
8390 +};
8391 +
8392 +
8393 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
8394 +
8395 +extern int register_vroot_grb(vroot_grb_func *);
8396 +extern int unregister_vroot_grb(vroot_grb_func *);
8397 +
8398 +#endif /* __KERNEL__ */
8399 +
8400 +#define MAX_VROOT_DEFAULT      8
8401 +
8402 +/*
8403 + * IOCTL commands --- we will commandeer 0x56 ('V')
8404 + */
8405 +
8406 +#define VROOT_SET_DEV          0x5600
8407 +#define VROOT_CLR_DEV          0x5601
8408 +
8409 +#endif /* _LINUX_VROOT_H */
8410 diff -NurpP --minimal linux-3.9.4/include/linux/vs_base.h linux-3.9.4-vs2.3.6.1/include/linux/vs_base.h
8411 --- linux-3.9.4/include/linux/vs_base.h 1970-01-01 00:00:00.000000000 +0000
8412 +++ linux-3.9.4-vs2.3.6.1/include/linux/vs_base.h       2013-05-31 14:47:11.000000000 +0000
8413 @@ -0,0 +1,10 @@
8414 +#ifndef _VS_BASE_H
8415 +#define _VS_BASE_H
8416 +
8417 +#include "vserver/base.h"
8418 +#include "vserver/check.h"
8419 +#include "vserver/debug.h"
8420 +
8421 +#else
8422 +#warning duplicate inclusion
8423 +#endif
8424 diff -NurpP --minimal linux-3.9.4/include/linux/vs_context.h linux-3.9.4-vs2.3.6.1/include/linux/vs_context.h
8425 --- linux-3.9.4/include/linux/vs_context.h      1970-01-01 00:00:00.000000000 +0000
8426 +++ linux-3.9.4-vs2.3.6.1/include/linux/vs_context.h    2013-05-31 14:47:11.000000000 +0000
8427 @@ -0,0 +1,242 @@
8428 +#ifndef _VS_CONTEXT_H
8429 +#define _VS_CONTEXT_H
8430 +
8431 +#include "vserver/base.h"
8432 +#include "vserver/check.h"
8433 +#include "vserver/context.h"
8434 +#include "vserver/history.h"
8435 +#include "vserver/debug.h"
8436 +
8437 +#include <linux/sched.h>
8438 +
8439 +
8440 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
8441 +
8442 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
8443 +       const char *_file, int _line, void *_here)
8444 +{
8445 +       if (!vxi)
8446 +               return NULL;
8447 +
8448 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
8449 +               vxi, vxi ? vxi->vx_id : 0,
8450 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8451 +               _file, _line);
8452 +       __vxh_get_vx_info(vxi, _here);
8453 +
8454 +       atomic_inc(&vxi->vx_usecnt);
8455 +       return vxi;
8456 +}
8457 +
8458 +
8459 +extern void free_vx_info(struct vx_info *);
8460 +
8461 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
8462 +
8463 +static inline void __put_vx_info(struct vx_info *vxi,
8464 +       const char *_file, int _line, void *_here)
8465 +{
8466 +       if (!vxi)
8467 +               return;
8468 +
8469 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
8470 +               vxi, vxi ? vxi->vx_id : 0,
8471 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8472 +               _file, _line);
8473 +       __vxh_put_vx_info(vxi, _here);
8474 +
8475 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
8476 +               free_vx_info(vxi);
8477 +}
8478 +
8479 +
8480 +#define init_vx_info(p, i) \
8481 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
8482 +
8483 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
8484 +       const char *_file, int _line, void *_here)
8485 +{
8486 +       if (vxi) {
8487 +               vxlprintk(VXD_CBIT(xid, 3),
8488 +                       "init_vx_info(%p[#%d.%d])",
8489 +                       vxi, vxi ? vxi->vx_id : 0,
8490 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8491 +                       _file, _line);
8492 +               __vxh_init_vx_info(vxi, vxp, _here);
8493 +
8494 +               atomic_inc(&vxi->vx_usecnt);
8495 +       }
8496 +       *vxp = vxi;
8497 +}
8498 +
8499 +
8500 +#define set_vx_info(p, i) \
8501 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
8502 +
8503 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
8504 +       const char *_file, int _line, void *_here)
8505 +{
8506 +       struct vx_info *vxo;
8507 +
8508 +       if (!vxi)
8509 +               return;
8510 +
8511 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
8512 +               vxi, vxi ? vxi->vx_id : 0,
8513 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8514 +               _file, _line);
8515 +       __vxh_set_vx_info(vxi, vxp, _here);
8516 +
8517 +       atomic_inc(&vxi->vx_usecnt);
8518 +       vxo = xchg(vxp, vxi);
8519 +       BUG_ON(vxo);
8520 +}
8521 +
8522 +
8523 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
8524 +
8525 +static inline void __clr_vx_info(struct vx_info **vxp,
8526 +       const char *_file, int _line, void *_here)
8527 +{
8528 +       struct vx_info *vxo;
8529 +
8530 +       vxo = xchg(vxp, NULL);
8531 +       if (!vxo)
8532 +               return;
8533 +
8534 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
8535 +               vxo, vxo ? vxo->vx_id : 0,
8536 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
8537 +               _file, _line);
8538 +       __vxh_clr_vx_info(vxo, vxp, _here);
8539 +
8540 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
8541 +               free_vx_info(vxo);
8542 +}
8543 +
8544 +
8545 +#define claim_vx_info(v, p) \
8546 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
8547 +
8548 +static inline void __claim_vx_info(struct vx_info *vxi,
8549 +       struct task_struct *task,
8550 +       const char *_file, int _line, void *_here)
8551 +{
8552 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
8553 +               vxi, vxi ? vxi->vx_id : 0,
8554 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8555 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
8556 +               task, _file, _line);
8557 +       __vxh_claim_vx_info(vxi, task, _here);
8558 +
8559 +       atomic_inc(&vxi->vx_tasks);
8560 +}
8561 +
8562 +
8563 +extern void unhash_vx_info(struct vx_info *);
8564 +
8565 +#define release_vx_info(v, p) \
8566 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
8567 +
8568 +static inline void __release_vx_info(struct vx_info *vxi,
8569 +       struct task_struct *task,
8570 +       const char *_file, int _line, void *_here)
8571 +{
8572 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
8573 +               vxi, vxi ? vxi->vx_id : 0,
8574 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8575 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
8576 +               task, _file, _line);
8577 +       __vxh_release_vx_info(vxi, task, _here);
8578 +
8579 +       might_sleep();
8580 +
8581 +       if (atomic_dec_and_test(&vxi->vx_tasks))
8582 +               unhash_vx_info(vxi);
8583 +}
8584 +
8585 +
8586 +#define task_get_vx_info(p) \
8587 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
8588 +
8589 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
8590 +       const char *_file, int _line, void *_here)
8591 +{
8592 +       struct vx_info *vxi;
8593 +
8594 +       task_lock(p);
8595 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
8596 +               p, _file, _line);
8597 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
8598 +       task_unlock(p);
8599 +       return vxi;
8600 +}
8601 +
8602 +
8603 +static inline void __wakeup_vx_info(struct vx_info *vxi)
8604 +{
8605 +       if (waitqueue_active(&vxi->vx_wait))
8606 +               wake_up_interruptible(&vxi->vx_wait);
8607 +}
8608 +
8609 +
8610 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
8611 +
8612 +static inline void __enter_vx_info(struct vx_info *vxi,
8613 +       struct vx_info_save *vxis, const char *_file, int _line)
8614 +{
8615 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
8616 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
8617 +               current->xid, current->vx_info, _file, _line);
8618 +       vxis->vxi = xchg(&current->vx_info, vxi);
8619 +       vxis->xid = current->xid;
8620 +       current->xid = vxi ? vxi->vx_id : 0;
8621 +}
8622 +
8623 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
8624 +
8625 +static inline void __leave_vx_info(struct vx_info_save *vxis,
8626 +       const char *_file, int _line)
8627 +{
8628 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
8629 +               vxis, vxis->xid, vxis->vxi, current,
8630 +               current->xid, current->vx_info, _file, _line);
8631 +       (void)xchg(&current->vx_info, vxis->vxi);
8632 +       current->xid = vxis->xid;
8633 +}
8634 +
8635 +
8636 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
8637 +{
8638 +       vxis->vxi = xchg(&current->vx_info, NULL);
8639 +       vxis->xid = xchg(&current->xid, (xid_t)0);
8640 +}
8641 +
8642 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
8643 +{
8644 +       (void)xchg(&current->xid, vxis->xid);
8645 +       (void)xchg(&current->vx_info, vxis->vxi);
8646 +}
8647 +
8648 +#define task_is_init(p) \
8649 +       __task_is_init(p, __FILE__, __LINE__, __HERE__)
8650 +
8651 +static inline int __task_is_init(struct task_struct *p,
8652 +       const char *_file, int _line, void *_here)
8653 +{
8654 +       int is_init = is_global_init(p);
8655 +
8656 +       task_lock(p);
8657 +       if (p->vx_info)
8658 +               is_init = p->vx_info->vx_initpid == p->pid;
8659 +       task_unlock(p);
8660 +       return is_init;
8661 +}
8662 +
8663 +extern void exit_vx_info(struct task_struct *, int);
8664 +extern void exit_vx_info_early(struct task_struct *, int);
8665 +
8666 +
8667 +#else
8668 +#warning duplicate inclusion
8669 +#endif
8670 diff -NurpP --minimal linux-3.9.4/include/linux/vs_cowbl.h linux-3.9.4-vs2.3.6.1/include/linux/vs_cowbl.h
8671 --- linux-3.9.4/include/linux/vs_cowbl.h        1970-01-01 00:00:00.000000000 +0000
8672 +++ linux-3.9.4-vs2.3.6.1/include/linux/vs_cowbl.h      2013-05-31 14:47:11.000000000 +0000
8673 @@ -0,0 +1,48 @@
8674 +#ifndef _VS_COWBL_H
8675 +#define _VS_COWBL_H
8676 +
8677 +#include <linux/fs.h>
8678 +#include <linux/dcache.h>
8679 +#include <linux/namei.h>
8680 +#include <linux/slab.h>
8681 +
8682 +extern struct dentry *cow_break_link(const char *pathname);
8683 +
8684 +static inline int cow_check_and_break(struct path *path)
8685 +{
8686 +       struct inode *inode = path->dentry->d_inode;
8687 +       int error = 0;
8688 +
8689 +       /* do we need this check? */
8690 +       if (IS_RDONLY(inode))
8691 +               return -EROFS;
8692 +
8693 +       if (IS_COW(inode)) {
8694 +               if (IS_COW_LINK(inode)) {
8695 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
8696 +                       char *pp, *buf;
8697 +
8698 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
8699 +                       if (!buf) {
8700 +                               return -ENOMEM;
8701 +                       }
8702 +                       pp = d_path(path, buf, PATH_MAX);
8703 +                       new_dentry = cow_break_link(pp);
8704 +                       kfree(buf);
8705 +                       if (!IS_ERR(new_dentry)) {
8706 +                               path->dentry = new_dentry;
8707 +                               dput(old_dentry);
8708 +                       } else
8709 +                               error = PTR_ERR(new_dentry);
8710 +               } else {
8711 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
8712 +                       inode->i_ctime = CURRENT_TIME;
8713 +                       mark_inode_dirty(inode);
8714 +               }
8715 +       }
8716 +       return error;
8717 +}
8718 +
8719 +#else
8720 +#warning duplicate inclusion
8721 +#endif
8722 diff -NurpP --minimal linux-3.9.4/include/linux/vs_cvirt.h linux-3.9.4-vs2.3.6.1/include/linux/vs_cvirt.h
8723 --- linux-3.9.4/include/linux/vs_cvirt.h        1970-01-01 00:00:00.000000000 +0000
8724 +++ linux-3.9.4-vs2.3.6.1/include/linux/vs_cvirt.h      2013-05-31 14:47:11.000000000 +0000
8725 @@ -0,0 +1,50 @@
8726 +#ifndef _VS_CVIRT_H
8727 +#define _VS_CVIRT_H
8728 +
8729 +#include "vserver/cvirt.h"
8730 +#include "vserver/context.h"
8731 +#include "vserver/base.h"
8732 +#include "vserver/check.h"
8733 +#include "vserver/debug.h"
8734 +
8735 +
8736 +static inline void vx_activate_task(struct task_struct *p)
8737 +{
8738 +       struct vx_info *vxi;
8739 +
8740 +       if ((vxi = p->vx_info)) {
8741 +               vx_update_load(vxi);
8742 +               atomic_inc(&vxi->cvirt.nr_running);
8743 +       }
8744 +}
8745 +
8746 +static inline void vx_deactivate_task(struct task_struct *p)
8747 +{
8748 +       struct vx_info *vxi;
8749 +
8750 +       if ((vxi = p->vx_info)) {
8751 +               vx_update_load(vxi);
8752 +               atomic_dec(&vxi->cvirt.nr_running);
8753 +       }
8754 +}
8755 +
8756 +static inline void vx_uninterruptible_inc(struct task_struct *p)
8757 +{
8758 +       struct vx_info *vxi;
8759 +
8760 +       if ((vxi = p->vx_info))
8761 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
8762 +}
8763 +
8764 +static inline void vx_uninterruptible_dec(struct task_struct *p)
8765 +{
8766 +       struct vx_info *vxi;
8767 +
8768 +       if ((vxi = p->vx_info))
8769 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
8770 +}
8771 +
8772 +
8773 +#else
8774 +#warning duplicate inclusion
8775 +#endif
8776 diff -NurpP --minimal linux-3.9.4/include/linux/vs_device.h linux-3.9.4-vs2.3.6.1/include/linux/vs_device.h
8777 --- linux-3.9.4/include/linux/vs_device.h       1970-01-01 00:00:00.000000000 +0000
8778 +++ linux-3.9.4-vs2.3.6.1/include/linux/vs_device.h     2013-05-31 14:47:11.000000000 +0000
8779 @@ -0,0 +1,45 @@
8780 +#ifndef _VS_DEVICE_H
8781 +#define _VS_DEVICE_H
8782 +
8783 +#include "vserver/base.h"
8784 +#include "vserver/device.h"
8785 +#include "vserver/debug.h"
8786 +
8787 +
8788 +#ifdef CONFIG_VSERVER_DEVICE
8789 +
8790 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
8791 +
8792 +#define vs_device_perm(v, d, m, p) \
8793 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
8794 +
8795 +#else
8796 +
8797 +static inline
8798 +int vs_map_device(struct vx_info *vxi,
8799 +       dev_t device, dev_t *target, umode_t mode)
8800 +{
8801 +       if (target)
8802 +               *target = device;
8803 +       return ~0;
8804 +}
8805 +
8806 +#define vs_device_perm(v, d, m, p) ((p) == (p))
8807 +
8808 +#endif
8809 +
8810 +
8811 +#define vs_map_chrdev(d, t, p) \
8812 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
8813 +#define vs_map_blkdev(d, t, p) \
8814 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
8815 +
8816 +#define vs_chrdev_perm(d, p) \
8817 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
8818 +#define vs_blkdev_perm(d, p) \
8819 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
8820 +
8821 +
8822 +#else
8823 +#warning duplicate inclusion
8824 +#endif
8825 diff -NurpP --minimal linux-3.9.4/include/linux/vs_dlimit.h linux-3.9.4-vs2.3.6.1/include/linux/vs_dlimit.h
8826 --- linux-3.9.4/include/linux/vs_dlimit.h       1970-01-01 00:00:00.000000000 +0000
8827 +++ linux-3.9.4-vs2.3.6.1/include/linux/vs_dlimit.h     2013-05-31 14:47:11.000000000 +0000
8828 @@ -0,0 +1,215 @@
8829 +#ifndef _VS_DLIMIT_H
8830 +#define _VS_DLIMIT_H
8831 +
8832 +#include <linux/fs.h>
8833 +
8834 +#include "vserver/dlimit.h"
8835 +#include "vserver/base.h"
8836 +#include "vserver/debug.h"
8837 +
8838 +
8839 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
8840 +
8841 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
8842 +       const char *_file, int _line)
8843 +{
8844 +       if (!dli)
8845 +               return NULL;
8846 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
8847 +               dli, dli ? dli->dl_tag : 0,
8848 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
8849 +               _file, _line);
8850 +       atomic_inc(&dli->dl_usecnt);
8851 +       return dli;
8852 +}
8853 +
8854 +
8855 +#define free_dl_info(i) \
8856 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
8857 +
8858 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
8859 +
8860 +static inline void __put_dl_info(struct dl_info *dli,
8861 +       const char *_file, int _line)
8862 +{
8863 +       if (!dli)
8864 +               return;
8865 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
8866 +               dli, dli ? dli->dl_tag : 0,
8867 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
8868 +               _file, _line);
8869 +       if (atomic_dec_and_test(&dli->dl_usecnt))
8870 +               free_dl_info(dli);
8871 +}
8872 +
8873 +
8874 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
8875 +
8876 +static inline int __dl_alloc_space(struct super_block *sb,
8877 +       tag_t tag, dlsize_t nr, const char *file, int line)
8878 +{
8879 +       struct dl_info *dli = NULL;
8880 +       int ret = 0;
8881 +
8882 +       if (nr == 0)
8883 +               goto out;
8884 +       dli = locate_dl_info(sb, tag);
8885 +       if (!dli)
8886 +               goto out;
8887 +
8888 +       spin_lock(&dli->dl_lock);
8889 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
8890 +       if (!ret)
8891 +               dli->dl_space_used += nr;
8892 +       spin_unlock(&dli->dl_lock);
8893 +       put_dl_info(dli);
8894 +out:
8895 +       vxlprintk(VXD_CBIT(dlim, 1),
8896 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
8897 +               sb, tag, __dlimit_char(dli), (long long)nr,
8898 +               ret, file, line);
8899 +       return ret ? -ENOSPC : 0;
8900 +}
8901 +
8902 +static inline void __dl_free_space(struct super_block *sb,
8903 +       tag_t tag, dlsize_t nr, const char *_file, int _line)
8904 +{
8905 +       struct dl_info *dli = NULL;
8906 +
8907 +       if (nr == 0)
8908 +               goto out;
8909 +       dli = locate_dl_info(sb, tag);
8910 +       if (!dli)
8911 +               goto out;
8912 +
8913 +       spin_lock(&dli->dl_lock);
8914 +       if (dli->dl_space_used > nr)
8915 +               dli->dl_space_used -= nr;
8916 +       else
8917 +               dli->dl_space_used = 0;
8918 +       spin_unlock(&dli->dl_lock);
8919 +       put_dl_info(dli);
8920 +out:
8921 +       vxlprintk(VXD_CBIT(dlim, 1),
8922 +               "FREE  (%p,#%d)%c %lld bytes",
8923 +               sb, tag, __dlimit_char(dli), (long long)nr,
8924 +               _file, _line);
8925 +}
8926 +
8927 +static inline int __dl_alloc_inode(struct super_block *sb,
8928 +       tag_t tag, const char *_file, int _line)
8929 +{
8930 +       struct dl_info *dli;
8931 +       int ret = 0;
8932 +
8933 +       dli = locate_dl_info(sb, tag);
8934 +       if (!dli)
8935 +               goto out;
8936 +
8937 +       spin_lock(&dli->dl_lock);
8938 +       dli->dl_inodes_used++;
8939 +       ret = (dli->dl_inodes_used > dli->dl_inodes_total);
8940 +       spin_unlock(&dli->dl_lock);
8941 +       put_dl_info(dli);
8942 +out:
8943 +       vxlprintk(VXD_CBIT(dlim, 0),
8944 +               "ALLOC (%p,#%d)%c inode (%d)",
8945 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
8946 +       return ret ? -ENOSPC : 0;
8947 +}
8948 +
8949 +static inline void __dl_free_inode(struct super_block *sb,
8950 +       tag_t tag, const char *_file, int _line)
8951 +{
8952 +       struct dl_info *dli;
8953 +
8954 +       dli = locate_dl_info(sb, tag);
8955 +       if (!dli)
8956 +               goto out;
8957 +
8958 +       spin_lock(&dli->dl_lock);
8959 +       if (dli->dl_inodes_used > 1)
8960 +               dli->dl_inodes_used--;
8961 +       else
8962 +               dli->dl_inodes_used = 0;
8963 +       spin_unlock(&dli->dl_lock);
8964 +       put_dl_info(dli);
8965 +out:
8966 +       vxlprintk(VXD_CBIT(dlim, 0),
8967 +               "FREE  (%p,#%d)%c inode",
8968 +               sb, tag, __dlimit_char(dli), _file, _line);
8969 +}
8970 +
8971 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
8972 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
8973 +       const char *_file, int _line)
8974 +{
8975 +       struct dl_info *dli;
8976 +       uint64_t broot, bfree;
8977 +
8978 +       dli = locate_dl_info(sb, tag);
8979 +       if (!dli)
8980 +               return;
8981 +
8982 +       spin_lock(&dli->dl_lock);
8983 +       broot = (dli->dl_space_total -
8984 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
8985 +               >> sb->s_blocksize_bits;
8986 +       bfree = (dli->dl_space_total - dli->dl_space_used)
8987 +                       >> sb->s_blocksize_bits;
8988 +       spin_unlock(&dli->dl_lock);
8989 +
8990 +       vxlprintk(VXD_CBIT(dlim, 2),
8991 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
8992 +               (long long)bfree, (long long)broot,
8993 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
8994 +               _file, _line);
8995 +       if (free_blocks) {
8996 +               if (*free_blocks > bfree)
8997 +                       *free_blocks = bfree;
8998 +       }
8999 +       if (root_blocks) {
9000 +               if (*root_blocks > broot)
9001 +                       *root_blocks = broot;
9002 +       }
9003 +       put_dl_info(dli);
9004 +}
9005 +
9006 +#define dl_prealloc_space(in, bytes) \
9007 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
9008 +               __FILE__, __LINE__ )
9009 +
9010 +#define dl_alloc_space(in, bytes) \
9011 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
9012 +               __FILE__, __LINE__ )
9013 +
9014 +#define dl_reserve_space(in, bytes) \
9015 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
9016 +               __FILE__, __LINE__ )
9017 +
9018 +#define dl_claim_space(in, bytes) (0)
9019 +
9020 +#define dl_release_space(in, bytes) \
9021 +       __dl_free_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
9022 +               __FILE__, __LINE__ )
9023 +
9024 +#define dl_free_space(in, bytes) \
9025 +       __dl_free_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
9026 +               __FILE__, __LINE__ )
9027 +
9028 +
9029 +
9030 +#define dl_alloc_inode(in) \
9031 +       __dl_alloc_inode((in)->i_sb, i_tag_read(in), __FILE__, __LINE__ )
9032 +
9033 +#define dl_free_inode(in) \
9034 +       __dl_free_inode((in)->i_sb, i_tag_read(in), __FILE__, __LINE__ )
9035 +
9036 +
9037 +#define dl_adjust_block(sb, tag, fb, rb) \
9038 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
9039 +
9040 +
9041 +#else
9042 +#warning duplicate inclusion
9043 +#endif
9044 diff -NurpP --minimal linux-3.9.4/include/linux/vs_inet.h linux-3.9.4-vs2.3.6.1/include/linux/vs_inet.h
9045 --- linux-3.9.4/include/linux/vs_inet.h 1970-01-01 00:00:00.000000000 +0000
9046 +++ linux-3.9.4-vs2.3.6.1/include/linux/vs_inet.h       2013-05-31 14:47:11.000000000 +0000
9047 @@ -0,0 +1,364 @@
9048 +#ifndef _VS_INET_H
9049 +#define _VS_INET_H
9050 +
9051 +#include "vserver/base.h"
9052 +#include "vserver/network.h"
9053 +#include "vserver/debug.h"
9054 +
9055 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
9056 +
9057 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
9058 +                       NIPQUAD((a)->mask), (a)->type
9059 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
9060 +
9061 +#define NIPQUAD(addr) \
9062 +       ((unsigned char *)&addr)[0], \
9063 +       ((unsigned char *)&addr)[1], \
9064 +       ((unsigned char *)&addr)[2], \
9065 +       ((unsigned char *)&addr)[3]
9066 +
9067 +#define NIPQUAD_FMT "%u.%u.%u.%u"
9068 +
9069 +
9070 +static inline
9071 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
9072 +{
9073 +       __be32 ip = nxa->ip[0].s_addr;
9074 +       __be32 mask = nxa->mask.s_addr;
9075 +       __be32 bcast = ip | ~mask;
9076 +       int ret = 0;
9077 +
9078 +       switch (nxa->type & tmask) {
9079 +       case NXA_TYPE_MASK:
9080 +               ret = (ip == (addr & mask));
9081 +               break;
9082 +       case NXA_TYPE_ADDR:
9083 +               ret = 3;
9084 +               if (addr == ip)
9085 +                       break;
9086 +               /* fall through to broadcast */
9087 +       case NXA_MOD_BCAST:
9088 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
9089 +               break;
9090 +       case NXA_TYPE_RANGE:
9091 +               ret = ((nxa->ip[0].s_addr <= addr) &&
9092 +                       (nxa->ip[1].s_addr > addr));
9093 +               break;
9094 +       case NXA_TYPE_ANY:
9095 +               ret = 2;
9096 +               break;
9097 +       }
9098 +
9099 +       vxdprintk(VXD_CBIT(net, 0),
9100 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
9101 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
9102 +       return ret;
9103 +}
9104 +
9105 +static inline
9106 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
9107 +{
9108 +       struct nx_addr_v4 *nxa;
9109 +       unsigned long irqflags;
9110 +       int ret = 1;
9111 +
9112 +       if (!nxi)
9113 +               goto out;
9114 +
9115 +       ret = 2;
9116 +       /* allow 127.0.0.1 when remapping lback */
9117 +       if ((tmask & NXA_LOOPBACK) &&
9118 +               (addr == IPI_LOOPBACK) &&
9119 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9120 +               goto out;
9121 +       ret = 3;
9122 +       /* check for lback address */
9123 +       if ((tmask & NXA_MOD_LBACK) &&
9124 +               (nxi->v4_lback.s_addr == addr))
9125 +               goto out;
9126 +       ret = 4;
9127 +       /* check for broadcast address */
9128 +       if ((tmask & NXA_MOD_BCAST) &&
9129 +               (nxi->v4_bcast.s_addr == addr))
9130 +               goto out;
9131 +       ret = 5;
9132 +
9133 +       /* check for v4 addresses */
9134 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
9135 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
9136 +               if (v4_addr_match(nxa, addr, tmask))
9137 +                       goto out_unlock;
9138 +       ret = 0;
9139 +out_unlock:
9140 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
9141 +out:
9142 +       vxdprintk(VXD_CBIT(net, 0),
9143 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
9144 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
9145 +       return ret;
9146 +}
9147 +
9148 +static inline
9149 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
9150 +{
9151 +       /* FIXME: needs full range checks */
9152 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
9153 +}
9154 +
9155 +static inline
9156 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
9157 +{
9158 +       struct nx_addr_v4 *ptr;
9159 +       unsigned long irqflags;
9160 +       int ret = 1;
9161 +
9162 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
9163 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
9164 +               if (v4_nx_addr_match(ptr, nxa, mask))
9165 +                       goto out_unlock;
9166 +       ret = 0;
9167 +out_unlock:
9168 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
9169 +       return ret;
9170 +}
9171 +
9172 +#include <net/inet_sock.h>
9173 +
9174 +/*
9175 + *     Check if a given address matches for a socket
9176 + *
9177 + *     nxi:            the socket's nx_info if any
9178 + *     addr:           to be verified address
9179 + */
9180 +static inline
9181 +int v4_sock_addr_match (
9182 +       struct nx_info *nxi,
9183 +       struct inet_sock *inet,
9184 +       __be32 addr)
9185 +{
9186 +       __be32 saddr = inet->inet_rcv_saddr;
9187 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
9188 +
9189 +       if (addr && (saddr == addr || bcast == addr))
9190 +               return 1;
9191 +       if (!saddr)
9192 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
9193 +       return 0;
9194 +}
9195 +
9196 +
9197 +/* inet related checks and helpers */
9198 +
9199 +
9200 +struct in_ifaddr;
9201 +struct net_device;
9202 +struct sock;
9203 +
9204 +#ifdef CONFIG_INET
9205 +
9206 +#include <linux/netdevice.h>
9207 +#include <linux/inetdevice.h>
9208 +#include <net/inet_sock.h>
9209 +#include <net/inet_timewait_sock.h>
9210 +
9211 +
9212 +int dev_in_nx_info(struct net_device *, struct nx_info *);
9213 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
9214 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
9215 +
9216 +
9217 +/*
9218 + *     check if address is covered by socket
9219 + *
9220 + *     sk:     the socket to check against
9221 + *     addr:   the address in question (must be != 0)
9222 + */
9223 +
9224 +static inline
9225 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
9226 +{
9227 +       struct nx_info *nxi = sk->sk_nx_info;
9228 +       __be32 saddr = sk_rcv_saddr(sk);
9229 +
9230 +       vxdprintk(VXD_CBIT(net, 5),
9231 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
9232 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
9233 +               (sk->sk_socket?sk->sk_socket->flags:0));
9234 +
9235 +       if (saddr) {            /* direct address match */
9236 +               return v4_addr_match(nxa, saddr, -1);
9237 +       } else if (nxi) {       /* match against nx_info */
9238 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
9239 +       } else {                /* unrestricted any socket */
9240 +               return 1;
9241 +       }
9242 +}
9243 +
9244 +
9245 +
9246 +static inline
9247 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
9248 +{
9249 +       vxdprintk(VXD_CBIT(net, 1),
9250 +               "nx_dev_visible(%p[#%u],%p " VS_Q("%s") ") %d",
9251 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
9252 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
9253 +
9254 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9255 +               return 1;
9256 +       if (dev_in_nx_info(dev, nxi))
9257 +               return 1;
9258 +       return 0;
9259 +}
9260 +
9261 +
9262 +static inline
9263 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
9264 +{
9265 +       if (!nxi)
9266 +               return 1;
9267 +       if (!ifa)
9268 +               return 0;
9269 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
9270 +}
9271 +
9272 +static inline
9273 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
9274 +{
9275 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
9276 +               nxi, nxi ? nxi->nx_id : 0, ifa,
9277 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
9278 +
9279 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9280 +               return 1;
9281 +       if (v4_ifa_in_nx_info(ifa, nxi))
9282 +               return 1;
9283 +       return 0;
9284 +}
9285 +
9286 +
9287 +struct nx_v4_sock_addr {
9288 +       __be32 saddr;   /* Address used for validation */
9289 +       __be32 baddr;   /* Address used for socket bind */
9290 +};
9291 +
9292 +static inline
9293 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
9294 +       struct nx_v4_sock_addr *nsa)
9295 +{
9296 +       struct sock *sk = &inet->sk;
9297 +       struct nx_info *nxi = sk->sk_nx_info;
9298 +       __be32 saddr = addr->sin_addr.s_addr;
9299 +       __be32 baddr = saddr;
9300 +
9301 +       vxdprintk(VXD_CBIT(net, 3),
9302 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
9303 +               sk, sk->sk_nx_info, sk->sk_socket,
9304 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
9305 +               NIPQUAD(saddr));
9306 +
9307 +       if (nxi) {
9308 +               if (saddr == INADDR_ANY) {
9309 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
9310 +                               baddr = nxi->v4.ip[0].s_addr;
9311 +               } else if (saddr == IPI_LOOPBACK) {
9312 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9313 +                               baddr = nxi->v4_lback.s_addr;
9314 +               } else if (!ipv4_is_multicast(saddr) ||
9315 +                       !nx_info_ncaps(nxi, NXC_MULTICAST)) {
9316 +                       /* normal address bind */
9317 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
9318 +                               return -EADDRNOTAVAIL;
9319 +               }
9320 +       }
9321 +
9322 +       vxdprintk(VXD_CBIT(net, 3),
9323 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
9324 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
9325 +
9326 +       nsa->saddr = saddr;
9327 +       nsa->baddr = baddr;
9328 +       return 0;
9329 +}
9330 +
9331 +static inline
9332 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
9333 +{
9334 +       inet->inet_saddr = nsa->baddr;
9335 +       inet->inet_rcv_saddr = nsa->baddr;
9336 +}
9337 +
9338 +
9339 +/*
9340 + *      helper to simplify inet_lookup_listener
9341 + *
9342 + *      nxi:   the socket's nx_info if any
9343 + *      addr:  to be verified address
9344 + *      saddr: socket address
9345 + */
9346 +static inline int v4_inet_addr_match (
9347 +       struct nx_info *nxi,
9348 +       __be32 addr,
9349 +       __be32 saddr)
9350 +{
9351 +       if (addr && (saddr == addr))
9352 +               return 1;
9353 +       if (!saddr)
9354 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
9355 +       return 0;
9356 +}
9357 +
9358 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
9359 +{
9360 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
9361 +               (addr == nxi->v4_lback.s_addr))
9362 +               return IPI_LOOPBACK;
9363 +       return addr;
9364 +}
9365 +
9366 +static inline
9367 +int nx_info_has_v4(struct nx_info *nxi)
9368 +{
9369 +       if (!nxi)
9370 +               return 1;
9371 +       if (NX_IPV4(nxi))
9372 +               return 1;
9373 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9374 +               return 1;
9375 +       return 0;
9376 +}
9377 +
9378 +#else /* CONFIG_INET */
9379 +
9380 +static inline
9381 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
9382 +{
9383 +       return 1;
9384 +}
9385 +
9386 +static inline
9387 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
9388 +{
9389 +       return 1;
9390 +}
9391 +
9392 +static inline
9393 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
9394 +{
9395 +       return 1;
9396 +}
9397 +
9398 +static inline
9399 +int nx_info_has_v4(struct nx_info *nxi)
9400 +{
9401 +       return 0;
9402 +}
9403 +
9404 +#endif /* CONFIG_INET */
9405 +
9406 +#define current_nx_info_has_v4() \
9407 +       nx_info_has_v4(current_nx_info())
9408 +
9409 +#else
9410 +// #warning duplicate inclusion
9411 +#endif
9412 diff -NurpP --minimal linux-3.9.4/include/linux/vs_inet6.h linux-3.9.4-vs2.3.6.1/include/linux/vs_inet6.h
9413 --- linux-3.9.4/include/linux/vs_inet6.h        1970-01-01 00:00:00.000000000 +0000
9414 +++ linux-3.9.4-vs2.3.6.1/include/linux/vs_inet6.h      2013-05-31 14:47:11.000000000 +0000
9415 @@ -0,0 +1,257 @@
9416 +#ifndef _VS_INET6_H
9417 +#define _VS_INET6_H
9418 +
9419 +#include "vserver/base.h"
9420 +#include "vserver/network.h"
9421 +#include "vserver/debug.h"
9422 +
9423 +#include <net/ipv6.h>
9424 +
9425 +#define NXAV6(a)       &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
9426 +#define NXAV6_FMT      "[%pI6/%pI6/%d:%04x]"
9427 +
9428 +
9429 +#ifdef CONFIG_IPV6
9430 +
9431 +static inline
9432 +int v6_addr_match(struct nx_addr_v6 *nxa,
9433 +       const struct in6_addr *addr, uint16_t mask)
9434 +{
9435 +       int ret = 0;
9436 +
9437 +       switch (nxa->type & mask) {
9438 +       case NXA_TYPE_MASK:
9439 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
9440 +               break;
9441 +       case NXA_TYPE_ADDR:
9442 +               ret = ipv6_addr_equal(&nxa->ip, addr);
9443 +               break;
9444 +       case NXA_TYPE_ANY:
9445 +               ret = 1;
9446 +               break;
9447 +       }
9448 +       vxdprintk(VXD_CBIT(net, 0),
9449 +               "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
9450 +               nxa, NXAV6(nxa), addr, mask, ret);
9451 +       return ret;
9452 +}
9453 +
9454 +static inline
9455 +int v6_addr_in_nx_info(struct nx_info *nxi,
9456 +       const struct in6_addr *addr, uint16_t mask)
9457 +{
9458 +       struct nx_addr_v6 *nxa;
9459 +       unsigned long irqflags;
9460 +       int ret = 1;
9461 +
9462 +       if (!nxi)
9463 +               goto out;
9464 +
9465 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
9466 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
9467 +               if (v6_addr_match(nxa, addr, mask))
9468 +                       goto out_unlock;
9469 +       ret = 0;
9470 +out_unlock:
9471 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
9472 +out:
9473 +       vxdprintk(VXD_CBIT(net, 0),
9474 +               "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
9475 +               nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
9476 +       return ret;
9477 +}
9478 +
9479 +static inline
9480 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
9481 +{
9482 +       /* FIXME: needs full range checks */
9483 +       return v6_addr_match(nxa, &addr->ip, mask);
9484 +}
9485 +
9486 +static inline
9487 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
9488 +{
9489 +       struct nx_addr_v6 *ptr;
9490 +       unsigned long irqflags;
9491 +       int ret = 1;
9492 +
9493 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
9494 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
9495 +               if (v6_nx_addr_match(ptr, nxa, mask))
9496 +                       goto out_unlock;
9497 +       ret = 0;
9498 +out_unlock:
9499 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
9500 +       return ret;
9501 +}
9502 +
9503 +
9504 +/*
9505 + *     Check if a given address matches for a socket
9506 + *
9507 + *     nxi:            the socket's nx_info if any
9508 + *     addr:           to be verified address
9509 + */
9510 +static inline
9511 +int v6_sock_addr_match (
9512 +       struct nx_info *nxi,
9513 +       struct inet_sock *inet,
9514 +       struct in6_addr *addr)
9515 +{
9516 +       struct sock *sk = &inet->sk;
9517 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
9518 +
9519 +       if (!ipv6_addr_any(addr) &&
9520 +               ipv6_addr_equal(saddr, addr))
9521 +               return 1;
9522 +       if (ipv6_addr_any(saddr))
9523 +               return v6_addr_in_nx_info(nxi, addr, -1);
9524 +       return 0;
9525 +}
9526 +
9527 +/*
9528 + *     check if address is covered by socket
9529 + *
9530 + *     sk:     the socket to check against
9531 + *     addr:   the address in question (must be != 0)
9532 + */
9533 +
9534 +static inline
9535 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
9536 +{
9537 +       struct nx_info *nxi = sk->sk_nx_info;
9538 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
9539 +
9540 +       vxdprintk(VXD_CBIT(net, 5),
9541 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
9542 +               sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
9543 +               (sk->sk_socket?sk->sk_socket->flags:0));
9544 +
9545 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
9546 +               return v6_addr_match(nxa, saddr, -1);
9547 +       } else if (nxi) {               /* match against nx_info */
9548 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
9549 +       } else {                        /* unrestricted any socket */
9550 +               return 1;
9551 +       }
9552 +}
9553 +
9554 +
9555 +/* inet related checks and helpers */
9556 +
9557 +
9558 +struct in_ifaddr;
9559 +struct net_device;
9560 +struct sock;
9561 +
9562 +
9563 +#include <linux/netdevice.h>
9564 +#include <linux/inetdevice.h>
9565 +#include <net/inet_timewait_sock.h>
9566 +
9567 +
9568 +int dev_in_nx_info(struct net_device *, struct nx_info *);
9569 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
9570 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
9571 +
9572 +
9573 +
9574 +static inline
9575 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
9576 +{
9577 +       if (!nxi)
9578 +               return 1;
9579 +       if (!ifa)
9580 +               return 0;
9581 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
9582 +}
9583 +
9584 +static inline
9585 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
9586 +{
9587 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
9588 +               nxi, nxi ? nxi->nx_id : 0, ifa,
9589 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
9590 +
9591 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9592 +               return 1;
9593 +       if (v6_ifa_in_nx_info(ifa, nxi))
9594 +               return 1;
9595 +       return 0;
9596 +}
9597 +
9598 +
9599 +struct nx_v6_sock_addr {
9600 +       struct in6_addr saddr;  /* Address used for validation */
9601 +       struct in6_addr baddr;  /* Address used for socket bind */
9602 +};
9603 +
9604 +static inline
9605 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
9606 +       struct nx_v6_sock_addr *nsa)
9607 +{
9608 +       // struct sock *sk = &inet->sk;
9609 +       // struct nx_info *nxi = sk->sk_nx_info;
9610 +       struct in6_addr saddr = addr->sin6_addr;
9611 +       struct in6_addr baddr = saddr;
9612 +
9613 +       nsa->saddr = saddr;
9614 +       nsa->baddr = baddr;
9615 +       return 0;
9616 +}
9617 +
9618 +static inline
9619 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
9620 +{
9621 +       // struct sock *sk = &inet->sk;
9622 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
9623 +
9624 +       // *saddr = nsa->baddr;
9625 +       // inet->inet_saddr = nsa->baddr;
9626 +}
9627 +
9628 +static inline
9629 +int nx_info_has_v6(struct nx_info *nxi)
9630 +{
9631 +       if (!nxi)
9632 +               return 1;
9633 +       if (NX_IPV6(nxi))
9634 +               return 1;
9635 +       return 0;
9636 +}
9637 +
9638 +#else /* CONFIG_IPV6 */
9639 +
9640 +static inline
9641 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
9642 +{
9643 +       return 1;
9644 +}
9645 +
9646 +
9647 +static inline
9648 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
9649 +{
9650 +       return 1;
9651 +}
9652 +
9653 +static inline
9654 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
9655 +{
9656 +       return 1;
9657 +}
9658 +
9659 +static inline
9660 +int nx_info_has_v6(struct nx_info *nxi)
9661 +{
9662 +       return 0;
9663 +}
9664 +
9665 +#endif /* CONFIG_IPV6 */
9666 +
9667 +#define current_nx_info_has_v6() \
9668 +       nx_info_has_v6(current_nx_info())
9669 +
9670 +#else
9671 +#warning duplicate inclusion
9672 +#endif
9673 diff -NurpP --minimal linux-3.9.4/include/linux/vs_limit.h linux-3.9.4-vs2.3.6.1/include/linux/vs_limit.h
9674 --- linux-3.9.4/include/linux/vs_limit.h        1970-01-01 00:00:00.000000000 +0000
9675 +++ linux-3.9.4-vs2.3.6.1/include/linux/vs_limit.h      2013-05-31 14:47:11.000000000 +0000
9676 @@ -0,0 +1,140 @@
9677 +#ifndef _VS_LIMIT_H
9678 +#define _VS_LIMIT_H
9679 +
9680 +#include "vserver/limit.h"
9681 +#include "vserver/base.h"
9682 +#include "vserver/context.h"
9683 +#include "vserver/debug.h"
9684 +#include "vserver/context.h"
9685 +#include "vserver/limit_int.h"
9686 +
9687 +
9688 +#define vx_acc_cres(v, d, p, r) \
9689 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
9690 +
9691 +#define vx_acc_cres_cond(x, d, p, r) \
9692 +       __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
9693 +       r, d, p, __FILE__, __LINE__)
9694 +
9695 +
9696 +#define vx_add_cres(v, a, p, r) \
9697 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
9698 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
9699 +
9700 +#define vx_add_cres_cond(x, a, p, r) \
9701 +       __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
9702 +       r, a, p, __FILE__, __LINE__)
9703 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
9704 +
9705 +
9706 +/* process and file limits */
9707 +
9708 +#define vx_nproc_inc(p) \
9709 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
9710 +
9711 +#define vx_nproc_dec(p) \
9712 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
9713 +
9714 +#define vx_files_inc(f) \
9715 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
9716 +
9717 +#define vx_files_dec(f) \
9718 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
9719 +
9720 +#define vx_locks_inc(l) \
9721 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
9722 +
9723 +#define vx_locks_dec(l) \
9724 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
9725 +
9726 +#define vx_openfd_inc(f) \
9727 +       vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
9728 +
9729 +#define vx_openfd_dec(f) \
9730 +       vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
9731 +
9732 +
9733 +#define vx_cres_avail(v, n, r) \
9734 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
9735 +
9736 +
9737 +#define vx_nproc_avail(n) \
9738 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
9739 +
9740 +#define vx_files_avail(n) \
9741 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
9742 +
9743 +#define vx_locks_avail(n) \
9744 +       vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
9745 +
9746 +#define vx_openfd_avail(n) \
9747 +       vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
9748 +
9749 +
9750 +/* dentry limits */
9751 +
9752 +#define vx_dentry_inc(d) do {                                          \
9753 +       if ((d)->d_count == 1)                                          \
9754 +               vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY);    \
9755 +       } while (0)
9756 +
9757 +#define vx_dentry_dec(d) do {                                          \
9758 +       if ((d)->d_count == 0)                                          \
9759 +               vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY);    \
9760 +       } while (0)
9761 +
9762 +#define vx_dentry_avail(n) \
9763 +       vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
9764 +
9765 +
9766 +/* socket limits */
9767 +
9768 +#define vx_sock_inc(s) \
9769 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
9770 +
9771 +#define vx_sock_dec(s) \
9772 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
9773 +
9774 +#define vx_sock_avail(n) \
9775 +       vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
9776 +
9777 +
9778 +/* ipc resource limits */
9779 +
9780 +#define vx_ipcmsg_add(v, u, a) \
9781 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
9782 +
9783 +#define vx_ipcmsg_sub(v, u, a) \
9784 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
9785 +
9786 +#define vx_ipcmsg_avail(v, a) \
9787 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
9788 +
9789 +
9790 +#define vx_ipcshm_add(v, k, a) \
9791 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
9792 +
9793 +#define vx_ipcshm_sub(v, k, a) \
9794 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
9795 +
9796 +#define vx_ipcshm_avail(v, a) \
9797 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
9798 +
9799 +
9800 +#define vx_semary_inc(a) \
9801 +       vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
9802 +
9803 +#define vx_semary_dec(a) \
9804 +       vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
9805 +
9806 +
9807 +#define vx_nsems_add(a,n) \
9808 +       vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
9809 +
9810 +#define vx_nsems_sub(a,n) \
9811 +       vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
9812 +
9813 +
9814 +#else
9815 +#warning duplicate inclusion
9816 +#endif
9817 diff -NurpP --minimal linux-3.9.4/include/linux/vs_network.h linux-3.9.4-vs2.3.6.1/include/linux/vs_network.h
9818 --- linux-3.9.4/include/linux/vs_network.h      1970-01-01 00:00:00.000000000 +0000
9819 +++ linux-3.9.4-vs2.3.6.1/include/linux/vs_network.h    2013-05-31 14:47:11.000000000 +0000
9820 @@ -0,0 +1,169 @@
9821 +#ifndef _NX_VS_NETWORK_H
9822 +#define _NX_VS_NETWORK_H
9823 +
9824 +#include "vserver/context.h"
9825 +#include "vserver/network.h"
9826 +#include "vserver/base.h"
9827 +#include "vserver/check.h"
9828 +#include "vserver/debug.h"
9829 +
9830 +#include <linux/sched.h>
9831 +
9832 +
9833 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
9834 +
9835 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
9836 +       const char *_file, int _line)
9837 +{
9838 +       if (!nxi)
9839 +               return NULL;
9840 +
9841 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
9842 +               nxi, nxi ? nxi->nx_id : 0,
9843 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9844 +               _file, _line);
9845 +
9846 +       atomic_inc(&nxi->nx_usecnt);
9847 +       return nxi;
9848 +}
9849 +
9850 +
9851 +extern void free_nx_info(struct nx_info *);
9852 +
9853 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
9854 +
9855 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
9856 +{
9857 +       if (!nxi)
9858 +               return;
9859 +
9860 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
9861 +               nxi, nxi ? nxi->nx_id : 0,
9862 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9863 +               _file, _line);
9864 +
9865 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
9866 +               free_nx_info(nxi);
9867 +}
9868 +
9869 +
9870 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
9871 +
9872 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
9873 +               const char *_file, int _line)
9874 +{
9875 +       if (nxi) {
9876 +               vxlprintk(VXD_CBIT(nid, 3),
9877 +                       "init_nx_info(%p[#%d.%d])",
9878 +                       nxi, nxi ? nxi->nx_id : 0,
9879 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9880 +                       _file, _line);
9881 +
9882 +               atomic_inc(&nxi->nx_usecnt);
9883 +       }
9884 +       *nxp = nxi;
9885 +}
9886 +
9887 +
9888 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
9889 +
9890 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
9891 +       const char *_file, int _line)
9892 +{
9893 +       struct nx_info *nxo;
9894 +
9895 +       if (!nxi)
9896 +               return;
9897 +
9898 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
9899 +               nxi, nxi ? nxi->nx_id : 0,
9900 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9901 +               _file, _line);
9902 +
9903 +       atomic_inc(&nxi->nx_usecnt);
9904 +       nxo = xchg(nxp, nxi);
9905 +       BUG_ON(nxo);
9906 +}
9907 +
9908 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
9909 +
9910 +static inline void __clr_nx_info(struct nx_info **nxp,
9911 +       const char *_file, int _line)
9912 +{
9913 +       struct nx_info *nxo;
9914 +
9915 +       nxo = xchg(nxp, NULL);
9916 +       if (!nxo)
9917 +               return;
9918 +
9919 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
9920 +               nxo, nxo ? nxo->nx_id : 0,
9921 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
9922 +               _file, _line);
9923 +
9924 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
9925 +               free_nx_info(nxo);
9926 +}
9927 +
9928 +
9929 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
9930 +
9931 +static inline void __claim_nx_info(struct nx_info *nxi,
9932 +       struct task_struct *task, const char *_file, int _line)
9933 +{
9934 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
9935 +               nxi, nxi ? nxi->nx_id : 0,
9936 +               nxi?atomic_read(&nxi->nx_usecnt):0,
9937 +               nxi?atomic_read(&nxi->nx_tasks):0,
9938 +               task, _file, _line);
9939 +
9940 +       atomic_inc(&nxi->nx_tasks);
9941 +}
9942 +
9943 +
9944 +extern void unhash_nx_info(struct nx_info *);
9945 +
9946 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
9947 +
9948 +static inline void __release_nx_info(struct nx_info *nxi,
9949 +       struct task_struct *task, const char *_file, int _line)
9950 +{
9951 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
9952 +               nxi, nxi ? nxi->nx_id : 0,
9953 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9954 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
9955 +               task, _file, _line);
9956 +
9957 +       might_sleep();
9958 +
9959 +       if (atomic_dec_and_test(&nxi->nx_tasks))
9960 +               unhash_nx_info(nxi);
9961 +}
9962 +
9963 +
9964 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
9965 +
9966 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
9967 +       const char *_file, int _line)
9968 +{
9969 +       struct nx_info *nxi;
9970 +
9971 +       task_lock(p);
9972 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
9973 +               p, _file, _line);
9974 +       nxi = __get_nx_info(p->nx_info, _file, _line);
9975 +       task_unlock(p);
9976 +       return nxi;
9977 +}
9978 +
9979 +
9980 +static inline void exit_nx_info(struct task_struct *p)
9981 +{
9982 +       if (p->nx_info)
9983 +               release_nx_info(p->nx_info, p);
9984 +}
9985 +
9986 +
9987 +#else
9988 +#warning duplicate inclusion
9989 +#endif
9990 diff -NurpP --minimal linux-3.9.4/include/linux/vs_pid.h linux-3.9.4-vs2.3.6.1/include/linux/vs_pid.h
9991 --- linux-3.9.4/include/linux/vs_pid.h  1970-01-01 00:00:00.000000000 +0000
9992 +++ linux-3.9.4-vs2.3.6.1/include/linux/vs_pid.h        2013-05-31 14:47:11.000000000 +0000
9993 @@ -0,0 +1,50 @@
9994 +#ifndef _VS_PID_H
9995 +#define _VS_PID_H
9996 +
9997 +#include "vserver/base.h"
9998 +#include "vserver/check.h"
9999 +#include "vserver/context.h"
10000 +#include "vserver/debug.h"
10001 +#include "vserver/pid.h"
10002 +#include <linux/pid_namespace.h>
10003 +
10004 +
10005 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
10006 +
10007 +static inline
10008 +int vx_proc_task_visible(struct task_struct *task)
10009 +{
10010 +       if ((task->pid == 1) &&
10011 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
10012 +               /* show a blend through init */
10013 +               goto visible;
10014 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
10015 +               goto visible;
10016 +       return 0;
10017 +visible:
10018 +       return 1;
10019 +}
10020 +
10021 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
10022 +
10023 +
10024 +static inline
10025 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
10026 +{
10027 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
10028 +
10029 +       if (task && !vx_proc_task_visible(task)) {
10030 +               vxdprintk(VXD_CBIT(misc, 6),
10031 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
10032 +                       task, task->xid, task->pid,
10033 +                       current, current->xid, current->pid);
10034 +               put_task_struct(task);
10035 +               task = NULL;
10036 +       }
10037 +       return task;
10038 +}
10039 +
10040 +
10041 +#else
10042 +#warning duplicate inclusion
10043 +#endif
10044 diff -NurpP --minimal linux-3.9.4/include/linux/vs_sched.h linux-3.9.4-vs2.3.6.1/include/linux/vs_sched.h
10045 --- linux-3.9.4/include/linux/vs_sched.h        1970-01-01 00:00:00.000000000 +0000
10046 +++ linux-3.9.4-vs2.3.6.1/include/linux/vs_sched.h      2013-05-31 14:47:11.000000000 +0000
10047 @@ -0,0 +1,40 @@
10048 +#ifndef _VS_SCHED_H
10049 +#define _VS_SCHED_H
10050 +
10051 +#include "vserver/base.h"
10052 +#include "vserver/context.h"
10053 +#include "vserver/sched.h"
10054 +
10055 +
10056 +#define MAX_PRIO_BIAS           20
10057 +#define MIN_PRIO_BIAS          -20
10058 +
10059 +static inline
10060 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
10061 +{
10062 +       struct vx_info *vxi = p->vx_info;
10063 +
10064 +       if (vxi)
10065 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
10066 +       return prio;
10067 +}
10068 +
10069 +static inline void vx_account_user(struct vx_info *vxi,
10070 +       cputime_t cputime, int nice)
10071 +{
10072 +       if (!vxi)
10073 +               return;
10074 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
10075 +}
10076 +
10077 +static inline void vx_account_system(struct vx_info *vxi,
10078 +       cputime_t cputime, int idle)
10079 +{
10080 +       if (!vxi)
10081 +               return;
10082 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
10083 +}
10084 +
10085 +#else
10086 +#warning duplicate inclusion
10087 +#endif
10088 diff -NurpP --minimal linux-3.9.4/include/linux/vs_socket.h linux-3.9.4-vs2.3.6.1/include/linux/vs_socket.h
10089 --- linux-3.9.4/include/linux/vs_socket.h       1970-01-01 00:00:00.000000000 +0000
10090 +++ linux-3.9.4-vs2.3.6.1/include/linux/vs_socket.h     2013-05-31 14:47:11.000000000 +0000
10091 @@ -0,0 +1,67 @@
10092 +#ifndef _VS_SOCKET_H
10093 +#define _VS_SOCKET_H
10094 +
10095 +#include "vserver/debug.h"
10096 +#include "vserver/base.h"
10097 +#include "vserver/cacct.h"
10098 +#include "vserver/context.h"
10099 +#include "vserver/tag.h"
10100 +
10101 +
10102 +/* socket accounting */
10103 +
10104 +#include <linux/socket.h>
10105 +
10106 +static inline int vx_sock_type(int family)
10107 +{
10108 +       switch (family) {
10109 +       case PF_UNSPEC:
10110 +               return VXA_SOCK_UNSPEC;
10111 +       case PF_UNIX:
10112 +               return VXA_SOCK_UNIX;
10113 +       case PF_INET:
10114 +               return VXA_SOCK_INET;
10115 +       case PF_INET6:
10116 +               return VXA_SOCK_INET6;
10117 +       case PF_PACKET:
10118 +               return VXA_SOCK_PACKET;
10119 +       default:
10120 +               return VXA_SOCK_OTHER;
10121 +       }
10122 +}
10123 +
10124 +#define vx_acc_sock(v, f, p, s) \
10125 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
10126 +
10127 +static inline void __vx_acc_sock(struct vx_info *vxi,
10128 +       int family, int pos, int size, char *file, int line)
10129 +{
10130 +       if (vxi) {
10131 +               int type = vx_sock_type(family);
10132 +
10133 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
10134 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
10135 +       }
10136 +}
10137 +
10138 +#define vx_sock_recv(sk, s) \
10139 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
10140 +#define vx_sock_send(sk, s) \
10141 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
10142 +#define vx_sock_fail(sk, s) \
10143 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
10144 +
10145 +
10146 +#define sock_vx_init(s) do {           \
10147 +       (s)->sk_xid = 0;                \
10148 +       (s)->sk_vx_info = NULL;         \
10149 +       } while (0)
10150 +
10151 +#define sock_nx_init(s) do {           \
10152 +       (s)->sk_nid = 0;                \
10153 +       (s)->sk_nx_info = NULL;         \
10154 +       } while (0)
10155 +
10156 +#else
10157 +#warning duplicate inclusion
10158 +#endif
10159 diff -NurpP --minimal linux-3.9.4/include/linux/vs_tag.h linux-3.9.4-vs2.3.6.1/include/linux/vs_tag.h
10160 --- linux-3.9.4/include/linux/vs_tag.h  1970-01-01 00:00:00.000000000 +0000
10161 +++ linux-3.9.4-vs2.3.6.1/include/linux/vs_tag.h        2013-05-31 14:47:11.000000000 +0000
10162 @@ -0,0 +1,47 @@
10163 +#ifndef _VS_TAG_H
10164 +#define _VS_TAG_H
10165 +
10166 +#include <linux/vserver/tag.h>
10167 +
10168 +/* check conditions */
10169 +
10170 +#define DX_ADMIN       0x0001
10171 +#define DX_WATCH       0x0002
10172 +#define DX_HOSTID      0x0008
10173 +
10174 +#define DX_IDENT       0x0010
10175 +
10176 +#define DX_ARG_MASK    0x0010
10177 +
10178 +
10179 +#define dx_task_tag(t) ((t)->tag)
10180 +
10181 +#define dx_current_tag() dx_task_tag(current)
10182 +
10183 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
10184 +
10185 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
10186 +
10187 +
10188 +/*
10189 + * check current context for ADMIN/WATCH and
10190 + * optionally against supplied argument
10191 + */
10192 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
10193 +{
10194 +       if (mode & DX_ARG_MASK) {
10195 +               if ((mode & DX_IDENT) && (id == cid))
10196 +                       return 1;
10197 +       }
10198 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
10199 +               ((mode & DX_WATCH) && (cid == 1)) ||
10200 +               ((mode & DX_HOSTID) && (id == 0)));
10201 +}
10202 +
10203 +struct inode;
10204 +int dx_permission(const struct inode *inode, int mask);
10205 +
10206 +
10207 +#else
10208 +#warning duplicate inclusion
10209 +#endif
10210 diff -NurpP --minimal linux-3.9.4/include/linux/vs_time.h linux-3.9.4-vs2.3.6.1/include/linux/vs_time.h
10211 --- linux-3.9.4/include/linux/vs_time.h 1970-01-01 00:00:00.000000000 +0000
10212 +++ linux-3.9.4-vs2.3.6.1/include/linux/vs_time.h       2013-05-31 14:47:11.000000000 +0000
10213 @@ -0,0 +1,19 @@
10214 +#ifndef _VS_TIME_H
10215 +#define _VS_TIME_H
10216 +
10217 +
10218 +/* time faking stuff */
10219 +
10220 +#ifdef CONFIG_VSERVER_VTIME
10221 +
10222 +extern void vx_adjust_timespec(struct timespec *ts);
10223 +extern int vx_settimeofday(const struct timespec *ts);
10224 +
10225 +#else
10226 +#define        vx_adjust_timespec(t)   do { } while (0)
10227 +#define        vx_settimeofday(t)      do_settimeofday(t)
10228 +#endif
10229 +
10230 +#else
10231 +#warning duplicate inclusion
10232 +#endif
10233 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/base.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/base.h
10234 --- linux-3.9.4/include/linux/vserver/base.h    1970-01-01 00:00:00.000000000 +0000
10235 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/base.h  2013-05-31 17:55:09.000000000 +0000
10236 @@ -0,0 +1,181 @@
10237 +#ifndef _VSERVER_BASE_H
10238 +#define _VSERVER_BASE_H
10239 +
10240 +
10241 +/* context state changes */
10242 +
10243 +enum {
10244 +       VSC_STARTUP = 1,
10245 +       VSC_SHUTDOWN,
10246 +
10247 +       VSC_NETUP,
10248 +       VSC_NETDOWN,
10249 +};
10250 +
10251 +
10252 +
10253 +#define vx_task_xid(t) ((t)->xid)
10254 +
10255 +#define vx_current_xid() vx_task_xid(current)
10256 +
10257 +#define current_vx_info() (current->vx_info)
10258 +
10259 +
10260 +#define nx_task_nid(t) ((t)->nid)
10261 +
10262 +#define nx_current_nid() nx_task_nid(current)
10263 +
10264 +#define current_nx_info() (current->nx_info)
10265 +
10266 +
10267 +/* generic flag merging */
10268 +
10269 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
10270 +
10271 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
10272 +
10273 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
10274 +
10275 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
10276 +
10277 +
10278 +/* context flags */
10279 +
10280 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
10281 +
10282 +#define vx_current_flags()     __vx_flags(current_vx_info())
10283 +
10284 +#define vx_info_flags(v, m, f) \
10285 +       vs_check_flags(__vx_flags(v), m, f)
10286 +
10287 +#define task_vx_flags(t, m, f) \
10288 +       ((t) && vx_info_flags((t)->vx_info, m, f))
10289 +
10290 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
10291 +
10292 +
10293 +/* context caps */
10294 +
10295 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
10296 +
10297 +#define vx_current_ccaps()     __vx_ccaps(current_vx_info())
10298 +
10299 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
10300 +
10301 +#define vx_ccaps(c)    vx_info_ccaps(current_vx_info(), (c))
10302 +
10303 +
10304 +
10305 +/* network flags */
10306 +
10307 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
10308 +
10309 +#define nx_current_flags()     __nx_flags(current_nx_info())
10310 +
10311 +#define nx_info_flags(n, m, f) \
10312 +       vs_check_flags(__nx_flags(n), m, f)
10313 +
10314 +#define task_nx_flags(t, m, f) \
10315 +       ((t) && nx_info_flags((t)->nx_info, m, f))
10316 +
10317 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
10318 +
10319 +
10320 +/* network caps */
10321 +
10322 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
10323 +
10324 +#define nx_current_ncaps()     __nx_ncaps(current_nx_info())
10325 +
10326 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
10327 +
10328 +#define nx_ncaps(c)    nx_info_ncaps(current_nx_info(), c)
10329 +
10330 +
10331 +/* context mask capabilities */
10332 +
10333 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
10334 +
10335 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
10336 +
10337 +#define vx_mcaps(c)    vx_info_mcaps(current_vx_info(), c)
10338 +
10339 +
10340 +/* context bcap mask */
10341 +
10342 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
10343 +
10344 +#define vx_current_bcaps()     __vx_bcaps(current_vx_info())
10345 +
10346 +
10347 +/* mask given bcaps */
10348 +
10349 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
10350 +
10351 +#define vx_mbcaps(c)           vx_info_mbcaps(current_vx_info(), c)
10352 +
10353 +
10354 +/* masked cap_bset */
10355 +
10356 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
10357 +
10358 +#define vx_current_cap_bset()  vx_info_cap_bset(current_vx_info())
10359 +
10360 +#if 0
10361 +#define vx_info_mbcap(v, b) \
10362 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
10363 +       vx_info_bcaps(v, b) : (b))
10364 +
10365 +#define task_vx_mbcap(t, b) \
10366 +       vx_info_mbcap((t)->vx_info, (t)->b)
10367 +
10368 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
10369 +#endif
10370 +
10371 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
10372 +
10373 +#define vx_capable(b, c) (capable(b) || \
10374 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10375 +
10376 +#define vx_ns_capable(n, b, c) (ns_capable(n, b) || \
10377 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10378 +
10379 +#define nx_capable(b, c) (capable(b) || \
10380 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
10381 +
10382 +#define vx_task_initpid(t, n) \
10383 +       ((t)->vx_info && \
10384 +       ((t)->vx_info->vx_initpid == (n)))
10385 +
10386 +#define vx_current_initpid(n)  vx_task_initpid(current, n)
10387 +
10388 +
10389 +/* context unshare mask */
10390 +
10391 +#define __vx_umask(v)          ((v)->vx_umask)
10392 +
10393 +#define vx_current_umask()     __vx_umask(current_vx_info())
10394 +
10395 +#define vx_can_unshare(b, f) (capable(b) || \
10396 +       (cap_raised(current_cap(), b) && \
10397 +       !((f) & ~vx_current_umask())))
10398 +
10399 +#define vx_ns_can_unshare(n, b, f) (ns_capable(n, b) || \
10400 +       (cap_raised(current_cap(), b) && \
10401 +       !((f) & ~vx_current_umask())))
10402 +
10403 +#define __vx_wmask(v)          ((v)->vx_wmask)
10404 +
10405 +#define vx_current_wmask()     __vx_wmask(current_vx_info())
10406 +
10407 +
10408 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
10409 +
10410 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
10411 +
10412 +
10413 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
10414 +
10415 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
10416 +
10417 +#endif
10418 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/cacct.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/cacct.h
10419 --- linux-3.9.4/include/linux/vserver/cacct.h   1970-01-01 00:00:00.000000000 +0000
10420 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/cacct.h 2013-05-31 14:47:11.000000000 +0000
10421 @@ -0,0 +1,15 @@
10422 +#ifndef _VSERVER_CACCT_H
10423 +#define _VSERVER_CACCT_H
10424 +
10425 +
10426 +enum sock_acc_field {
10427 +       VXA_SOCK_UNSPEC = 0,
10428 +       VXA_SOCK_UNIX,
10429 +       VXA_SOCK_INET,
10430 +       VXA_SOCK_INET6,
10431 +       VXA_SOCK_PACKET,
10432 +       VXA_SOCK_OTHER,
10433 +       VXA_SOCK_SIZE   /* array size */
10434 +};
10435 +
10436 +#endif /* _VSERVER_CACCT_H */
10437 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/cacct_cmd.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/cacct_cmd.h
10438 --- linux-3.9.4/include/linux/vserver/cacct_cmd.h       1970-01-01 00:00:00.000000000 +0000
10439 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/cacct_cmd.h     2013-05-31 14:47:11.000000000 +0000
10440 @@ -0,0 +1,10 @@
10441 +#ifndef _VSERVER_CACCT_CMD_H
10442 +#define _VSERVER_CACCT_CMD_H
10443 +
10444 +
10445 +#include <linux/compiler.h>
10446 +#include <uapi/vserver/cacct_cmd.h>
10447 +
10448 +extern int vc_sock_stat(struct vx_info *, void __user *);
10449 +
10450 +#endif /* _VSERVER_CACCT_CMD_H */
10451 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/cacct_def.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/cacct_def.h
10452 --- linux-3.9.4/include/linux/vserver/cacct_def.h       1970-01-01 00:00:00.000000000 +0000
10453 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/cacct_def.h     2013-05-31 14:47:11.000000000 +0000
10454 @@ -0,0 +1,43 @@
10455 +#ifndef _VSERVER_CACCT_DEF_H
10456 +#define _VSERVER_CACCT_DEF_H
10457 +
10458 +#include <asm/atomic.h>
10459 +#include <linux/vserver/cacct.h>
10460 +
10461 +
10462 +struct _vx_sock_acc {
10463 +       atomic_long_t count;
10464 +       atomic_long_t total;
10465 +};
10466 +
10467 +/* context sub struct */
10468 +
10469 +struct _vx_cacct {
10470 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
10471 +       atomic_t slab[8];
10472 +       atomic_t page[6][8];
10473 +};
10474 +
10475 +#ifdef CONFIG_VSERVER_DEBUG
10476 +
10477 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
10478 +{
10479 +       int i, j;
10480 +
10481 +       printk("\t_vx_cacct:");
10482 +       for (i = 0; i < 6; i++) {
10483 +               struct _vx_sock_acc *ptr = cacct->sock[i];
10484 +
10485 +               printk("\t [%d] =", i);
10486 +               for (j = 0; j < 3; j++) {
10487 +                       printk(" [%d] = %8lu, %8lu", j,
10488 +                               atomic_long_read(&ptr[j].count),
10489 +                               atomic_long_read(&ptr[j].total));
10490 +               }
10491 +               printk("\n");
10492 +       }
10493 +}
10494 +
10495 +#endif
10496 +
10497 +#endif /* _VSERVER_CACCT_DEF_H */
10498 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/cacct_int.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/cacct_int.h
10499 --- linux-3.9.4/include/linux/vserver/cacct_int.h       1970-01-01 00:00:00.000000000 +0000
10500 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/cacct_int.h     2013-05-31 14:47:11.000000000 +0000
10501 @@ -0,0 +1,17 @@
10502 +#ifndef _VSERVER_CACCT_INT_H
10503 +#define _VSERVER_CACCT_INT_H
10504 +
10505 +static inline
10506 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
10507 +{
10508 +       return atomic_long_read(&cacct->sock[type][pos].count);
10509 +}
10510 +
10511 +
10512 +static inline
10513 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
10514 +{
10515 +       return atomic_long_read(&cacct->sock[type][pos].total);
10516 +}
10517 +
10518 +#endif /* _VSERVER_CACCT_INT_H */
10519 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/check.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/check.h
10520 --- linux-3.9.4/include/linux/vserver/check.h   1970-01-01 00:00:00.000000000 +0000
10521 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/check.h 2013-05-31 14:47:11.000000000 +0000
10522 @@ -0,0 +1,89 @@
10523 +#ifndef _VSERVER_CHECK_H
10524 +#define _VSERVER_CHECK_H
10525 +
10526 +
10527 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
10528 +
10529 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
10530 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
10531 +#else
10532 +#define MIN_D_CONTEXT  65536
10533 +#endif
10534 +
10535 +/* check conditions */
10536 +
10537 +#define VS_ADMIN       0x0001
10538 +#define VS_WATCH       0x0002
10539 +#define VS_HIDE                0x0004
10540 +#define VS_HOSTID      0x0008
10541 +
10542 +#define VS_IDENT       0x0010
10543 +#define VS_EQUIV       0x0020
10544 +#define VS_PARENT      0x0040
10545 +#define VS_CHILD       0x0080
10546 +
10547 +#define VS_ARG_MASK    0x00F0
10548 +
10549 +#define VS_DYNAMIC     0x0100
10550 +#define VS_STATIC      0x0200
10551 +
10552 +#define VS_ATR_MASK    0x0F00
10553 +
10554 +#ifdef CONFIG_VSERVER_PRIVACY
10555 +#define VS_ADMIN_P     (0)
10556 +#define VS_WATCH_P     (0)
10557 +#else
10558 +#define VS_ADMIN_P     VS_ADMIN
10559 +#define VS_WATCH_P     VS_WATCH
10560 +#endif
10561 +
10562 +#define VS_HARDIRQ     0x1000
10563 +#define VS_SOFTIRQ     0x2000
10564 +#define VS_IRQ         0x4000
10565 +
10566 +#define VS_IRQ_MASK    0xF000
10567 +
10568 +#include <linux/hardirq.h>
10569 +
10570 +/*
10571 + * check current context for ADMIN/WATCH and
10572 + * optionally against supplied argument
10573 + */
10574 +static inline int __vs_check(int cid, int id, unsigned int mode)
10575 +{
10576 +       if (mode & VS_ARG_MASK) {
10577 +               if ((mode & VS_IDENT) && (id == cid))
10578 +                       return 1;
10579 +       }
10580 +       if (mode & VS_ATR_MASK) {
10581 +               if ((mode & VS_DYNAMIC) &&
10582 +                       (id >= MIN_D_CONTEXT) &&
10583 +                       (id <= MAX_S_CONTEXT))
10584 +                       return 1;
10585 +               if ((mode & VS_STATIC) &&
10586 +                       (id > 1) && (id < MIN_D_CONTEXT))
10587 +                       return 1;
10588 +       }
10589 +       if (mode & VS_IRQ_MASK) {
10590 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
10591 +                       return 1;
10592 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
10593 +                       return 1;
10594 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
10595 +                       return 1;
10596 +       }
10597 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
10598 +               ((mode & VS_WATCH) && (cid == 1)) ||
10599 +               ((mode & VS_HOSTID) && (id == 0)));
10600 +}
10601 +
10602 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
10603 +
10604 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
10605 +
10606 +
10607 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
10608 +
10609 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
10610 +
10611 +#endif
10612 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/context.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/context.h
10613 --- linux-3.9.4/include/linux/vserver/context.h 1970-01-01 00:00:00.000000000 +0000
10614 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/context.h       2013-05-31 14:47:11.000000000 +0000
10615 @@ -0,0 +1,110 @@
10616 +#ifndef _VSERVER_CONTEXT_H
10617 +#define _VSERVER_CONTEXT_H
10618 +
10619 +
10620 +#include <linux/list.h>
10621 +#include <linux/spinlock.h>
10622 +#include <linux/rcupdate.h>
10623 +#include <uapi/vserver/context.h>
10624 +
10625 +#include "limit_def.h"
10626 +#include "sched_def.h"
10627 +#include "cvirt_def.h"
10628 +#include "cacct_def.h"
10629 +#include "device_def.h"
10630 +
10631 +#define VX_SPACES      2
10632 +
10633 +struct _vx_info_pc {
10634 +       struct _vx_sched_pc sched_pc;
10635 +       struct _vx_cvirt_pc cvirt_pc;
10636 +};
10637 +
10638 +struct _vx_space {
10639 +       unsigned long vx_nsmask;                /* assignment mask */
10640 +       struct nsproxy *vx_nsproxy;             /* private namespaces */
10641 +       struct fs_struct *vx_fs;                /* private namespace fs */
10642 +       const struct cred *vx_cred;             /* task credentials */
10643 +};
10644 +
10645 +struct vx_info {
10646 +       struct hlist_node vx_hlist;             /* linked list of contexts */
10647 +       xid_t vx_id;                            /* context id */
10648 +       atomic_t vx_usecnt;                     /* usage count */
10649 +       atomic_t vx_tasks;                      /* tasks count */
10650 +       struct vx_info *vx_parent;              /* parent context */
10651 +       int vx_state;                           /* context state */
10652 +
10653 +       struct _vx_space space[VX_SPACES];      /* namespace store */
10654 +
10655 +       uint64_t vx_flags;                      /* context flags */
10656 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
10657 +       uint64_t vx_umask;                      /* unshare mask (guest) */
10658 +       uint64_t vx_wmask;                      /* warn mask (guest) */
10659 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
10660 +
10661 +       struct task_struct *vx_reaper;          /* guest reaper process */
10662 +       pid_t vx_initpid;                       /* PID of guest init */
10663 +       int64_t vx_badness_bias;                /* OOM points bias */
10664 +
10665 +       struct _vx_limit limit;                 /* vserver limits */
10666 +       struct _vx_sched sched;                 /* vserver scheduler */
10667 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
10668 +       struct _vx_cacct cacct;                 /* context accounting */
10669 +
10670 +       struct _vx_device dmap;                 /* default device map targets */
10671 +
10672 +#ifndef CONFIG_SMP
10673 +       struct _vx_info_pc info_pc;             /* per cpu data */
10674 +#else
10675 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
10676 +#endif
10677 +
10678 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
10679 +       int reboot_cmd;                         /* last sys_reboot() cmd */
10680 +       int exit_code;                          /* last process exit code */
10681 +
10682 +       char vx_name[65];                       /* vserver name */
10683 +};
10684 +
10685 +#ifndef CONFIG_SMP
10686 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
10687 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
10688 +#else
10689 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
10690 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
10691 +#endif
10692 +
10693 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
10694 +
10695 +
10696 +struct vx_info_save {
10697 +       struct vx_info *vxi;
10698 +       xid_t xid;
10699 +};
10700 +
10701 +
10702 +/* status flags */
10703 +
10704 +#define VXS_HASHED     0x0001
10705 +#define VXS_PAUSED     0x0010
10706 +#define VXS_SHUTDOWN   0x0100
10707 +#define VXS_HELPER     0x1000
10708 +#define VXS_RELEASED   0x8000
10709 +
10710 +
10711 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
10712 +extern void release_vx_info(struct vx_info *, struct task_struct *);
10713 +
10714 +extern struct vx_info *lookup_vx_info(int);
10715 +extern struct vx_info *lookup_or_create_vx_info(int);
10716 +
10717 +extern int get_xid_list(int, unsigned int *, int);
10718 +extern int xid_is_hashed(xid_t);
10719 +
10720 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
10721 +
10722 +extern long vs_state_change(struct vx_info *, unsigned int);
10723 +
10724 +
10725 +#endif /* _VSERVER_CONTEXT_H */
10726 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/context_cmd.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/context_cmd.h
10727 --- linux-3.9.4/include/linux/vserver/context_cmd.h     1970-01-01 00:00:00.000000000 +0000
10728 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/context_cmd.h   2013-05-31 14:47:11.000000000 +0000
10729 @@ -0,0 +1,33 @@
10730 +#ifndef _VSERVER_CONTEXT_CMD_H
10731 +#define _VSERVER_CONTEXT_CMD_H
10732 +
10733 +#include <uapi/vserver/context_cmd.h>
10734 +
10735 +extern int vc_task_xid(uint32_t);
10736 +
10737 +extern int vc_vx_info(struct vx_info *, void __user *);
10738 +
10739 +extern int vc_ctx_stat(struct vx_info *, void __user *);
10740 +
10741 +extern int vc_ctx_create(uint32_t, void __user *);
10742 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
10743 +
10744 +extern int vc_get_cflags(struct vx_info *, void __user *);
10745 +extern int vc_set_cflags(struct vx_info *, void __user *);
10746 +
10747 +extern int vc_get_ccaps(struct vx_info *, void __user *);
10748 +extern int vc_set_ccaps(struct vx_info *, void __user *);
10749 +
10750 +extern int vc_get_bcaps(struct vx_info *, void __user *);
10751 +extern int vc_set_bcaps(struct vx_info *, void __user *);
10752 +
10753 +extern int vc_get_umask(struct vx_info *, void __user *);
10754 +extern int vc_set_umask(struct vx_info *, void __user *);
10755 +
10756 +extern int vc_get_wmask(struct vx_info *, void __user *);
10757 +extern int vc_set_wmask(struct vx_info *, void __user *);
10758 +
10759 +extern int vc_get_badness(struct vx_info *, void __user *);
10760 +extern int vc_set_badness(struct vx_info *, void __user *);
10761 +
10762 +#endif /* _VSERVER_CONTEXT_CMD_H */
10763 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/cvirt.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/cvirt.h
10764 --- linux-3.9.4/include/linux/vserver/cvirt.h   1970-01-01 00:00:00.000000000 +0000
10765 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/cvirt.h 2013-05-31 14:47:11.000000000 +0000
10766 @@ -0,0 +1,18 @@
10767 +#ifndef _VSERVER_CVIRT_H
10768 +#define _VSERVER_CVIRT_H
10769 +
10770 +struct timespec;
10771 +
10772 +void vx_vsi_boottime(struct timespec *);
10773 +
10774 +void vx_vsi_uptime(struct timespec *, struct timespec *);
10775 +
10776 +
10777 +struct vx_info;
10778 +
10779 +void vx_update_load(struct vx_info *);
10780 +
10781 +
10782 +int vx_do_syslog(int, char __user *, int);
10783 +
10784 +#endif /* _VSERVER_CVIRT_H */
10785 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/cvirt_cmd.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/cvirt_cmd.h
10786 --- linux-3.9.4/include/linux/vserver/cvirt_cmd.h       1970-01-01 00:00:00.000000000 +0000
10787 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/cvirt_cmd.h     2013-05-31 14:47:11.000000000 +0000
10788 @@ -0,0 +1,13 @@
10789 +#ifndef _VSERVER_CVIRT_CMD_H
10790 +#define _VSERVER_CVIRT_CMD_H
10791 +
10792 +
10793 +#include <linux/compiler.h>
10794 +#include <uapi/vserver/cvirt_cmd.h>
10795 +
10796 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
10797 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
10798 +
10799 +extern int vc_virt_stat(struct vx_info *, void __user *);
10800 +
10801 +#endif /* _VSERVER_CVIRT_CMD_H */
10802 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/cvirt_def.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/cvirt_def.h
10803 --- linux-3.9.4/include/linux/vserver/cvirt_def.h       1970-01-01 00:00:00.000000000 +0000
10804 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/cvirt_def.h     2013-05-31 14:47:11.000000000 +0000
10805 @@ -0,0 +1,80 @@
10806 +#ifndef _VSERVER_CVIRT_DEF_H
10807 +#define _VSERVER_CVIRT_DEF_H
10808 +
10809 +#include <linux/jiffies.h>
10810 +#include <linux/spinlock.h>
10811 +#include <linux/wait.h>
10812 +#include <linux/time.h>
10813 +#include <asm/atomic.h>
10814 +
10815 +
10816 +struct _vx_usage_stat {
10817 +       uint64_t user;
10818 +       uint64_t nice;
10819 +       uint64_t system;
10820 +       uint64_t softirq;
10821 +       uint64_t irq;
10822 +       uint64_t idle;
10823 +       uint64_t iowait;
10824 +};
10825 +
10826 +struct _vx_syslog {
10827 +       wait_queue_head_t log_wait;
10828 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
10829 +
10830 +       unsigned long log_start;        /* next char to be read by syslog() */
10831 +       unsigned long con_start;        /* next char to be sent to consoles */
10832 +       unsigned long log_end;  /* most-recently-written-char + 1 */
10833 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
10834 +
10835 +       char log_buf[1024];
10836 +};
10837 +
10838 +
10839 +/* context sub struct */
10840 +
10841 +struct _vx_cvirt {
10842 +       atomic_t nr_threads;            /* number of current threads */
10843 +       atomic_t nr_running;            /* number of running threads */
10844 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
10845 +
10846 +       atomic_t nr_onhold;             /* processes on hold */
10847 +       uint32_t onhold_last;           /* jiffies when put on hold */
10848 +
10849 +       struct timespec bias_ts;        /* time offset to the host */
10850 +       struct timespec bias_idle;
10851 +       struct timespec bias_uptime;    /* context creation point */
10852 +       uint64_t bias_clock;            /* offset in clock_t */
10853 +
10854 +       spinlock_t load_lock;           /* lock for the load averages */
10855 +       atomic_t load_updates;          /* nr of load updates done so far */
10856 +       uint32_t load_last;             /* last time load was calculated */
10857 +       uint32_t load[3];               /* load averages 1,5,15 */
10858 +
10859 +       atomic_t total_forks;           /* number of forks so far */
10860 +
10861 +       struct _vx_syslog syslog;
10862 +};
10863 +
10864 +struct _vx_cvirt_pc {
10865 +       struct _vx_usage_stat cpustat;
10866 +};
10867 +
10868 +
10869 +#ifdef CONFIG_VSERVER_DEBUG
10870 +
10871 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
10872 +{
10873 +       printk("\t_vx_cvirt:\n");
10874 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
10875 +               atomic_read(&cvirt->nr_threads),
10876 +               atomic_read(&cvirt->nr_running),
10877 +               atomic_read(&cvirt->nr_uninterruptible),
10878 +               atomic_read(&cvirt->nr_onhold));
10879 +       /* add rest here */
10880 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
10881 +}
10882 +
10883 +#endif
10884 +
10885 +#endif /* _VSERVER_CVIRT_DEF_H */
10886 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/debug.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/debug.h
10887 --- linux-3.9.4/include/linux/vserver/debug.h   1970-01-01 00:00:00.000000000 +0000
10888 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/debug.h 2013-05-31 14:47:11.000000000 +0000
10889 @@ -0,0 +1,145 @@
10890 +#ifndef _VSERVER_DEBUG_H
10891 +#define _VSERVER_DEBUG_H
10892 +
10893 +
10894 +#define VXD_CBIT(n, m) (vs_debug_ ## n & (1 << (m)))
10895 +#define VXD_CMIN(n, m) (vs_debug_ ## n > (m))
10896 +#define VXD_MASK(n, m) (vs_debug_ ## n & (m))
10897 +
10898 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
10899 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
10900 +#define VXF_DEV                "%p[%lu,%d:%d]"
10901 +
10902 +#if    defined(CONFIG_QUOTES_UTF8)
10903 +#define        VS_Q_LQM        "\xc2\xbb"
10904 +#define        VS_Q_RQM        "\xc2\xab"
10905 +#elif  defined(CONFIG_QUOTES_ASCII)
10906 +#define        VS_Q_LQM        "\x27"
10907 +#define        VS_Q_RQM        "\x27"
10908 +#else
10909 +#define        VS_Q_LQM        "\xbb"
10910 +#define        VS_Q_RQM        "\xab"
10911 +#endif
10912 +
10913 +#define        VS_Q(f)         VS_Q_LQM f VS_Q_RQM
10914 +
10915 +
10916 +#define vxd_path(p)                                            \
10917 +       ({ static char _buffer[PATH_MAX];                       \
10918 +          d_path(p, _buffer, sizeof(_buffer)); })
10919 +
10920 +#define vxd_cond_path(n)                                       \
10921 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
10922 +
10923 +
10924 +#ifdef CONFIG_VSERVER_DEBUG
10925 +
10926 +extern unsigned int vs_debug_switch;
10927 +extern unsigned int vs_debug_xid;
10928 +extern unsigned int vs_debug_nid;
10929 +extern unsigned int vs_debug_tag;
10930 +extern unsigned int vs_debug_net;
10931 +extern unsigned int vs_debug_limit;
10932 +extern unsigned int vs_debug_cres;
10933 +extern unsigned int vs_debug_dlim;
10934 +extern unsigned int vs_debug_quota;
10935 +extern unsigned int vs_debug_cvirt;
10936 +extern unsigned int vs_debug_space;
10937 +extern unsigned int vs_debug_perm;
10938 +extern unsigned int vs_debug_misc;
10939 +
10940 +
10941 +#define VX_LOGLEVEL    "vxD: "
10942 +#define VX_PROC_FMT    "%p: "
10943 +#define VX_PROCESS     current
10944 +
10945 +#define vxdprintk(c, f, x...)                                  \
10946 +       do {                                                    \
10947 +               if (c)                                          \
10948 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
10949 +                               VX_PROCESS , ##x);              \
10950 +       } while (0)
10951 +
10952 +#define vxlprintk(c, f, x...)                                  \
10953 +       do {                                                    \
10954 +               if (c)                                          \
10955 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
10956 +       } while (0)
10957 +
10958 +#define vxfprintk(c, f, x...)                                  \
10959 +       do {                                                    \
10960 +               if (c)                                          \
10961 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
10962 +       } while (0)
10963 +
10964 +
10965 +struct vx_info;
10966 +
10967 +void dump_vx_info(struct vx_info *, int);
10968 +void dump_vx_info_inactive(int);
10969 +
10970 +#else  /* CONFIG_VSERVER_DEBUG */
10971 +
10972 +#define vs_debug_switch        0
10973 +#define vs_debug_xid   0
10974 +#define vs_debug_nid   0
10975 +#define vs_debug_tag   0
10976 +#define vs_debug_net   0
10977 +#define vs_debug_limit 0
10978 +#define vs_debug_cres  0
10979 +#define vs_debug_dlim  0
10980 +#define vs_debug_quota 0
10981 +#define vs_debug_cvirt 0
10982 +#define vs_debug_space 0
10983 +#define vs_debug_perm  0
10984 +#define vs_debug_misc  0
10985 +
10986 +#define vxdprintk(x...) do { } while (0)
10987 +#define vxlprintk(x...) do { } while (0)
10988 +#define vxfprintk(x...) do { } while (0)
10989 +
10990 +#endif /* CONFIG_VSERVER_DEBUG */
10991 +
10992 +
10993 +#ifdef CONFIG_VSERVER_WARN
10994 +
10995 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
10996 +#define VX_WARN_TASK   "[" VS_Q("%s") ",%u:#%u|%u|%u] "
10997 +#define VX_WARN_XID    "[xid #%u] "
10998 +#define VX_WARN_NID    "[nid #%u] "
10999 +#define VX_WARN_TAG    "[tag #%u] "
11000 +
11001 +#define vxwprintk(c, f, x...)                                  \
11002 +       do {                                                    \
11003 +               if (c)                                          \
11004 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
11005 +       } while (0)
11006 +
11007 +#else  /* CONFIG_VSERVER_WARN */
11008 +
11009 +#define vxwprintk(x...) do { } while (0)
11010 +
11011 +#endif /* CONFIG_VSERVER_WARN */
11012 +
11013 +#define vxwprintk_task(c, f, x...)                             \
11014 +       vxwprintk(c, VX_WARN_TASK f,                            \
11015 +               current->comm, current->pid,                    \
11016 +               current->xid, current->nid, current->tag, ##x)
11017 +#define vxwprintk_xid(c, f, x...)                              \
11018 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
11019 +#define vxwprintk_nid(c, f, x...)                              \
11020 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
11021 +#define vxwprintk_tag(c, f, x...)                              \
11022 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
11023 +
11024 +#ifdef CONFIG_VSERVER_DEBUG
11025 +#define vxd_assert_lock(l)     assert_spin_locked(l)
11026 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
11027 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
11028 +#else
11029 +#define vxd_assert_lock(l)     do { } while (0)
11030 +#define vxd_assert(c, f, x...) do { } while (0)
11031 +#endif
11032 +
11033 +
11034 +#endif /* _VSERVER_DEBUG_H */
11035 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/debug_cmd.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/debug_cmd.h
11036 --- linux-3.9.4/include/linux/vserver/debug_cmd.h       1970-01-01 00:00:00.000000000 +0000
11037 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/debug_cmd.h     2013-05-31 14:47:11.000000000 +0000
11038 @@ -0,0 +1,37 @@
11039 +#ifndef _VSERVER_DEBUG_CMD_H
11040 +#define _VSERVER_DEBUG_CMD_H
11041 +
11042 +#include <uapi/vserver/debug_cmd.h>
11043 +
11044 +
11045 +#ifdef CONFIG_COMPAT
11046 +
11047 +#include <asm/compat.h>
11048 +
11049 +struct vcmd_read_history_v0_x32 {
11050 +       uint32_t index;
11051 +       uint32_t count;
11052 +       compat_uptr_t data_ptr;
11053 +};
11054 +
11055 +struct vcmd_read_monitor_v0_x32 {
11056 +       uint32_t index;
11057 +       uint32_t count;
11058 +       compat_uptr_t data_ptr;
11059 +};
11060 +
11061 +#endif  /* CONFIG_COMPAT */
11062 +
11063 +extern int vc_dump_history(uint32_t);
11064 +
11065 +extern int vc_read_history(uint32_t, void __user *);
11066 +extern int vc_read_monitor(uint32_t, void __user *);
11067 +
11068 +#ifdef CONFIG_COMPAT
11069 +
11070 +extern int vc_read_history_x32(uint32_t, void __user *);
11071 +extern int vc_read_monitor_x32(uint32_t, void __user *);
11072 +
11073 +#endif  /* CONFIG_COMPAT */
11074 +
11075 +#endif /* _VSERVER_DEBUG_CMD_H */
11076 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/device.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/device.h
11077 --- linux-3.9.4/include/linux/vserver/device.h  1970-01-01 00:00:00.000000000 +0000
11078 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/device.h        2013-05-31 14:47:11.000000000 +0000
11079 @@ -0,0 +1,9 @@
11080 +#ifndef _VSERVER_DEVICE_H
11081 +#define _VSERVER_DEVICE_H
11082 +
11083 +
11084 +#include <uapi/vserver/device.h>
11085 +
11086 +#else  /* _VSERVER_DEVICE_H */
11087 +#warning duplicate inclusion
11088 +#endif /* _VSERVER_DEVICE_H */
11089 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/device_cmd.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/device_cmd.h
11090 --- linux-3.9.4/include/linux/vserver/device_cmd.h      1970-01-01 00:00:00.000000000 +0000
11091 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/device_cmd.h    2013-05-31 14:47:11.000000000 +0000
11092 @@ -0,0 +1,31 @@
11093 +#ifndef _VSERVER_DEVICE_CMD_H
11094 +#define _VSERVER_DEVICE_CMD_H
11095 +
11096 +#include <uapi/vserver/device_cmd.h>
11097 +
11098 +
11099 +#ifdef CONFIG_COMPAT
11100 +
11101 +#include <asm/compat.h>
11102 +
11103 +struct vcmd_set_mapping_v0_x32 {
11104 +       compat_uptr_t device_ptr;
11105 +       compat_uptr_t target_ptr;
11106 +       uint32_t flags;
11107 +};
11108 +
11109 +#endif /* CONFIG_COMPAT */
11110 +
11111 +#include <linux/compiler.h>
11112 +
11113 +extern int vc_set_mapping(struct vx_info *, void __user *);
11114 +extern int vc_unset_mapping(struct vx_info *, void __user *);
11115 +
11116 +#ifdef CONFIG_COMPAT
11117 +
11118 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
11119 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
11120 +
11121 +#endif /* CONFIG_COMPAT */
11122 +
11123 +#endif /* _VSERVER_DEVICE_CMD_H */
11124 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/device_def.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/device_def.h
11125 --- linux-3.9.4/include/linux/vserver/device_def.h      1970-01-01 00:00:00.000000000 +0000
11126 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/device_def.h    2013-05-31 14:47:11.000000000 +0000
11127 @@ -0,0 +1,17 @@
11128 +#ifndef _VSERVER_DEVICE_DEF_H
11129 +#define _VSERVER_DEVICE_DEF_H
11130 +
11131 +#include <linux/types.h>
11132 +
11133 +struct vx_dmap_target {
11134 +       dev_t target;
11135 +       uint32_t flags;
11136 +};
11137 +
11138 +struct _vx_device {
11139 +#ifdef CONFIG_VSERVER_DEVICE
11140 +       struct vx_dmap_target targets[2];
11141 +#endif
11142 +};
11143 +
11144 +#endif /* _VSERVER_DEVICE_DEF_H */
11145 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/dlimit.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/dlimit.h
11146 --- linux-3.9.4/include/linux/vserver/dlimit.h  1970-01-01 00:00:00.000000000 +0000
11147 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/dlimit.h        2013-05-31 14:47:11.000000000 +0000
11148 @@ -0,0 +1,54 @@
11149 +#ifndef _VSERVER_DLIMIT_H
11150 +#define _VSERVER_DLIMIT_H
11151 +
11152 +#include "switch.h"
11153 +
11154 +
11155 +#ifdef __KERNEL__
11156 +
11157 +/*      keep in sync with CDLIM_INFINITY       */
11158 +
11159 +#define DLIM_INFINITY          (~0ULL)
11160 +
11161 +#include <linux/spinlock.h>
11162 +#include <linux/rcupdate.h>
11163 +
11164 +struct super_block;
11165 +
11166 +struct dl_info {
11167 +       struct hlist_node dl_hlist;             /* linked list of contexts */
11168 +       struct rcu_head dl_rcu;                 /* the rcu head */
11169 +       tag_t dl_tag;                           /* context tag */
11170 +       atomic_t dl_usecnt;                     /* usage count */
11171 +       atomic_t dl_refcnt;                     /* reference count */
11172 +
11173 +       struct super_block *dl_sb;              /* associated superblock */
11174 +
11175 +       spinlock_t dl_lock;                     /* protect the values */
11176 +
11177 +       unsigned long long dl_space_used;       /* used space in bytes */
11178 +       unsigned long long dl_space_total;      /* maximum space in bytes */
11179 +       unsigned long dl_inodes_used;           /* used inodes */
11180 +       unsigned long dl_inodes_total;          /* maximum inodes */
11181 +
11182 +       unsigned int dl_nrlmult;                /* non root limit mult */
11183 +};
11184 +
11185 +struct rcu_head;
11186 +
11187 +extern void rcu_free_dl_info(struct rcu_head *);
11188 +extern void unhash_dl_info(struct dl_info *);
11189 +
11190 +extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
11191 +
11192 +
11193 +struct kstatfs;
11194 +
11195 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
11196 +
11197 +typedef uint64_t dlsize_t;
11198 +
11199 +#endif /* __KERNEL__ */
11200 +#else  /* _VSERVER_DLIMIT_H */
11201 +#warning duplicate inclusion
11202 +#endif /* _VSERVER_DLIMIT_H */
11203 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/dlimit_cmd.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/dlimit_cmd.h
11204 --- linux-3.9.4/include/linux/vserver/dlimit_cmd.h      1970-01-01 00:00:00.000000000 +0000
11205 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/dlimit_cmd.h    2013-05-31 14:47:11.000000000 +0000
11206 @@ -0,0 +1,46 @@
11207 +#ifndef _VSERVER_DLIMIT_CMD_H
11208 +#define _VSERVER_DLIMIT_CMD_H
11209 +
11210 +#include <uapi/vserver/dlimit_cmd.h>
11211 +
11212 +
11213 +#ifdef CONFIG_COMPAT
11214 +
11215 +#include <asm/compat.h>
11216 +
11217 +struct vcmd_ctx_dlimit_base_v0_x32 {
11218 +       compat_uptr_t name_ptr;
11219 +       uint32_t flags;
11220 +};
11221 +
11222 +struct vcmd_ctx_dlimit_v0_x32 {
11223 +       compat_uptr_t name_ptr;
11224 +       uint32_t space_used;                    /* used space in kbytes */
11225 +       uint32_t space_total;                   /* maximum space in kbytes */
11226 +       uint32_t inodes_used;                   /* used inodes */
11227 +       uint32_t inodes_total;                  /* maximum inodes */
11228 +       uint32_t reserved;                      /* reserved for root in % */
11229 +       uint32_t flags;
11230 +};
11231 +
11232 +#endif /* CONFIG_COMPAT */
11233 +
11234 +#include <linux/compiler.h>
11235 +
11236 +extern int vc_add_dlimit(uint32_t, void __user *);
11237 +extern int vc_rem_dlimit(uint32_t, void __user *);
11238 +
11239 +extern int vc_set_dlimit(uint32_t, void __user *);
11240 +extern int vc_get_dlimit(uint32_t, void __user *);
11241 +
11242 +#ifdef CONFIG_COMPAT
11243 +
11244 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
11245 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
11246 +
11247 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
11248 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
11249 +
11250 +#endif /* CONFIG_COMPAT */
11251 +
11252 +#endif /* _VSERVER_DLIMIT_CMD_H */
11253 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/global.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/global.h
11254 --- linux-3.9.4/include/linux/vserver/global.h  1970-01-01 00:00:00.000000000 +0000
11255 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/global.h        2013-05-31 14:47:11.000000000 +0000
11256 @@ -0,0 +1,19 @@
11257 +#ifndef _VSERVER_GLOBAL_H
11258 +#define _VSERVER_GLOBAL_H
11259 +
11260 +
11261 +extern atomic_t vx_global_ctotal;
11262 +extern atomic_t vx_global_cactive;
11263 +
11264 +extern atomic_t nx_global_ctotal;
11265 +extern atomic_t nx_global_cactive;
11266 +
11267 +extern atomic_t vs_global_nsproxy;
11268 +extern atomic_t vs_global_fs;
11269 +extern atomic_t vs_global_mnt_ns;
11270 +extern atomic_t vs_global_uts_ns;
11271 +extern atomic_t vs_global_user_ns;
11272 +extern atomic_t vs_global_pid_ns;
11273 +
11274 +
11275 +#endif /* _VSERVER_GLOBAL_H */
11276 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/history.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/history.h
11277 --- linux-3.9.4/include/linux/vserver/history.h 1970-01-01 00:00:00.000000000 +0000
11278 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/history.h       2013-05-31 14:47:11.000000000 +0000
11279 @@ -0,0 +1,197 @@
11280 +#ifndef _VSERVER_HISTORY_H
11281 +#define _VSERVER_HISTORY_H
11282 +
11283 +
11284 +enum {
11285 +       VXH_UNUSED = 0,
11286 +       VXH_THROW_OOPS = 1,
11287 +
11288 +       VXH_GET_VX_INFO,
11289 +       VXH_PUT_VX_INFO,
11290 +       VXH_INIT_VX_INFO,
11291 +       VXH_SET_VX_INFO,
11292 +       VXH_CLR_VX_INFO,
11293 +       VXH_CLAIM_VX_INFO,
11294 +       VXH_RELEASE_VX_INFO,
11295 +       VXH_ALLOC_VX_INFO,
11296 +       VXH_DEALLOC_VX_INFO,
11297 +       VXH_HASH_VX_INFO,
11298 +       VXH_UNHASH_VX_INFO,
11299 +       VXH_LOC_VX_INFO,
11300 +       VXH_LOOKUP_VX_INFO,
11301 +       VXH_CREATE_VX_INFO,
11302 +};
11303 +
11304 +struct _vxhe_vxi {
11305 +       struct vx_info *ptr;
11306 +       unsigned xid;
11307 +       unsigned usecnt;
11308 +       unsigned tasks;
11309 +};
11310 +
11311 +struct _vxhe_set_clr {
11312 +       void *data;
11313 +};
11314 +
11315 +struct _vxhe_loc_lookup {
11316 +       unsigned arg;
11317 +};
11318 +
11319 +struct _vx_hist_entry {
11320 +       void *loc;
11321 +       unsigned short seq;
11322 +       unsigned short type;
11323 +       struct _vxhe_vxi vxi;
11324 +       union {
11325 +               struct _vxhe_set_clr sc;
11326 +               struct _vxhe_loc_lookup ll;
11327 +       };
11328 +};
11329 +
11330 +#ifdef CONFIG_VSERVER_HISTORY
11331 +
11332 +extern unsigned volatile int vxh_active;
11333 +
11334 +struct _vx_hist_entry *vxh_advance(void *loc);
11335 +
11336 +
11337 +static inline
11338 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
11339 +{
11340 +       entry->vxi.ptr = vxi;
11341 +       if (vxi) {
11342 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
11343 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
11344 +               entry->vxi.xid = vxi->vx_id;
11345 +       }
11346 +}
11347 +
11348 +
11349 +#define        __HERE__ current_text_addr()
11350 +
11351 +#define __VXH_BODY(__type, __data, __here)     \
11352 +       struct _vx_hist_entry *entry;           \
11353 +                                               \
11354 +       preempt_disable();                      \
11355 +       entry = vxh_advance(__here);            \
11356 +       __data;                                 \
11357 +       entry->type = __type;                   \
11358 +       preempt_enable();
11359 +
11360 +
11361 +       /* pass vxi only */
11362 +
11363 +#define __VXH_SMPL                             \
11364 +       __vxh_copy_vxi(entry, vxi)
11365 +
11366 +static inline
11367 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
11368 +{
11369 +       __VXH_BODY(__type, __VXH_SMPL, __here)
11370 +}
11371 +
11372 +       /* pass vxi and data (void *) */
11373 +
11374 +#define __VXH_DATA                             \
11375 +       __vxh_copy_vxi(entry, vxi);             \
11376 +       entry->sc.data = data
11377 +
11378 +static inline
11379 +void   __vxh_data(struct vx_info *vxi, void *data,
11380 +                       int __type, void *__here)
11381 +{
11382 +       __VXH_BODY(__type, __VXH_DATA, __here)
11383 +}
11384 +
11385 +       /* pass vxi and arg (long) */
11386 +
11387 +#define __VXH_LONG                             \
11388 +       __vxh_copy_vxi(entry, vxi);             \
11389 +       entry->ll.arg = arg
11390 +
11391 +static inline
11392 +void   __vxh_long(struct vx_info *vxi, long arg,
11393 +                       int __type, void *__here)
11394 +{
11395 +       __VXH_BODY(__type, __VXH_LONG, __here)
11396 +}
11397 +
11398 +
11399 +static inline
11400 +void   __vxh_throw_oops(void *__here)
11401 +{
11402 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
11403 +       /* prevent further acquisition */
11404 +       vxh_active = 0;
11405 +}
11406 +
11407 +
11408 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
11409 +
11410 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
11411 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
11412 +
11413 +#define __vxh_init_vx_info(v, d, h) \
11414 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
11415 +#define __vxh_set_vx_info(v, d, h) \
11416 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
11417 +#define __vxh_clr_vx_info(v, d, h) \
11418 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
11419 +
11420 +#define __vxh_claim_vx_info(v, d, h) \
11421 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
11422 +#define __vxh_release_vx_info(v, d, h) \
11423 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
11424 +
11425 +#define vxh_alloc_vx_info(v) \
11426 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
11427 +#define vxh_dealloc_vx_info(v) \
11428 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
11429 +
11430 +#define vxh_hash_vx_info(v) \
11431 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
11432 +#define vxh_unhash_vx_info(v) \
11433 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
11434 +
11435 +#define vxh_loc_vx_info(v, l) \
11436 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
11437 +#define vxh_lookup_vx_info(v, l) \
11438 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
11439 +#define vxh_create_vx_info(v, l) \
11440 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
11441 +
11442 +extern void vxh_dump_history(void);
11443 +
11444 +
11445 +#else  /* CONFIG_VSERVER_HISTORY */
11446 +
11447 +#define        __HERE__        0
11448 +
11449 +#define vxh_throw_oops()               do { } while (0)
11450 +
11451 +#define __vxh_get_vx_info(v, h)                do { } while (0)
11452 +#define __vxh_put_vx_info(v, h)                do { } while (0)
11453 +
11454 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
11455 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
11456 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
11457 +
11458 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
11459 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
11460 +
11461 +#define vxh_alloc_vx_info(v)           do { } while (0)
11462 +#define vxh_dealloc_vx_info(v)         do { } while (0)
11463 +
11464 +#define vxh_hash_vx_info(v)            do { } while (0)
11465 +#define vxh_unhash_vx_info(v)          do { } while (0)
11466 +
11467 +#define vxh_loc_vx_info(v, l)          do { } while (0)
11468 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
11469 +#define vxh_create_vx_info(v, l)       do { } while (0)
11470 +
11471 +#define vxh_dump_history()             do { } while (0)
11472 +
11473 +
11474 +#endif /* CONFIG_VSERVER_HISTORY */
11475 +
11476 +#endif /* _VSERVER_HISTORY_H */
11477 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/inode.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/inode.h
11478 --- linux-3.9.4/include/linux/vserver/inode.h   1970-01-01 00:00:00.000000000 +0000
11479 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/inode.h 2013-05-31 14:47:11.000000000 +0000
11480 @@ -0,0 +1,19 @@
11481 +#ifndef _VSERVER_INODE_H
11482 +#define _VSERVER_INODE_H
11483 +
11484 +#include <uapi/vserver/inode.h>
11485 +
11486 +
11487 +#ifdef CONFIG_VSERVER_PROC_SECURE
11488 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
11489 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11490 +#else
11491 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
11492 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11493 +#endif
11494 +
11495 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
11496 +
11497 +#else  /* _VSERVER_INODE_H */
11498 +#warning duplicate inclusion
11499 +#endif /* _VSERVER_INODE_H */
11500 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/inode_cmd.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/inode_cmd.h
11501 --- linux-3.9.4/include/linux/vserver/inode_cmd.h       1970-01-01 00:00:00.000000000 +0000
11502 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/inode_cmd.h     2013-05-31 14:47:11.000000000 +0000
11503 @@ -0,0 +1,36 @@
11504 +#ifndef _VSERVER_INODE_CMD_H
11505 +#define _VSERVER_INODE_CMD_H
11506 +
11507 +#include <uapi/vserver/inode_cmd.h>
11508 +
11509 +
11510 +
11511 +#ifdef CONFIG_COMPAT
11512 +
11513 +#include <asm/compat.h>
11514 +
11515 +struct vcmd_ctx_iattr_v1_x32 {
11516 +       compat_uptr_t name_ptr;
11517 +       uint32_t tag;
11518 +       uint32_t flags;
11519 +       uint32_t mask;
11520 +};
11521 +
11522 +#endif /* CONFIG_COMPAT */
11523 +
11524 +#include <linux/compiler.h>
11525 +
11526 +extern int vc_get_iattr(void __user *);
11527 +extern int vc_set_iattr(void __user *);
11528 +
11529 +extern int vc_fget_iattr(uint32_t, void __user *);
11530 +extern int vc_fset_iattr(uint32_t, void __user *);
11531 +
11532 +#ifdef CONFIG_COMPAT
11533 +
11534 +extern int vc_get_iattr_x32(void __user *);
11535 +extern int vc_set_iattr_x32(void __user *);
11536 +
11537 +#endif /* CONFIG_COMPAT */
11538 +
11539 +#endif /* _VSERVER_INODE_CMD_H */
11540 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/limit.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/limit.h
11541 --- linux-3.9.4/include/linux/vserver/limit.h   1970-01-01 00:00:00.000000000 +0000
11542 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/limit.h 2013-05-31 14:47:11.000000000 +0000
11543 @@ -0,0 +1,61 @@
11544 +#ifndef _VSERVER_LIMIT_H
11545 +#define _VSERVER_LIMIT_H
11546 +
11547 +#include <uapi/vserver/limit.h>
11548 +
11549 +
11550 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
11551 +
11552 +/*     keep in sync with CRLIM_INFINITY */
11553 +
11554 +#define        VLIM_INFINITY   (~0ULL)
11555 +
11556 +#include <asm/atomic.h>
11557 +#include <asm/resource.h>
11558 +
11559 +#ifndef RLIM_INFINITY
11560 +#warning RLIM_INFINITY is undefined
11561 +#endif
11562 +
11563 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
11564 +
11565 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
11566 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
11567 +
11568 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
11569 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
11570 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
11571 +
11572 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
11573 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
11574 +
11575 +typedef atomic_long_t rlim_atomic_t;
11576 +typedef unsigned long rlim_t;
11577 +
11578 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
11579 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
11580 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
11581 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
11582 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
11583 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
11584 +
11585 +
11586 +#if    (RLIM_INFINITY == VLIM_INFINITY)
11587 +#define        VX_VLIM(r) ((long long)(long)(r))
11588 +#define        VX_RLIM(v) ((rlim_t)(v))
11589 +#else
11590 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
11591 +               ? VLIM_INFINITY : (long long)(r))
11592 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
11593 +               ? RLIM_INFINITY : (rlim_t)(v))
11594 +#endif
11595 +
11596 +struct sysinfo;
11597 +
11598 +void vx_vsi_meminfo(struct sysinfo *);
11599 +void vx_vsi_swapinfo(struct sysinfo *);
11600 +long vx_vsi_cached(struct sysinfo *);
11601 +
11602 +#define NUM_LIMITS     24
11603 +
11604 +#endif /* _VSERVER_LIMIT_H */
11605 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/limit_cmd.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/limit_cmd.h
11606 --- linux-3.9.4/include/linux/vserver/limit_cmd.h       1970-01-01 00:00:00.000000000 +0000
11607 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/limit_cmd.h     2013-05-31 14:47:11.000000000 +0000
11608 @@ -0,0 +1,35 @@
11609 +#ifndef _VSERVER_LIMIT_CMD_H
11610 +#define _VSERVER_LIMIT_CMD_H
11611 +
11612 +#include <uapi/vserver/limit_cmd.h>
11613 +
11614 +
11615 +#ifdef CONFIG_IA32_EMULATION
11616 +
11617 +struct vcmd_ctx_rlimit_v0_x32 {
11618 +       uint32_t id;
11619 +       uint64_t minimum;
11620 +       uint64_t softlimit;
11621 +       uint64_t maximum;
11622 +} __attribute__ ((packed));
11623 +
11624 +#endif /* CONFIG_IA32_EMULATION */
11625 +
11626 +#include <linux/compiler.h>
11627 +
11628 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
11629 +extern int vc_get_rlimit(struct vx_info *, void __user *);
11630 +extern int vc_set_rlimit(struct vx_info *, void __user *);
11631 +extern int vc_reset_hits(struct vx_info *, void __user *);
11632 +extern int vc_reset_minmax(struct vx_info *, void __user *);
11633 +
11634 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
11635 +
11636 +#ifdef CONFIG_IA32_EMULATION
11637 +
11638 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
11639 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
11640 +
11641 +#endif /* CONFIG_IA32_EMULATION */
11642 +
11643 +#endif /* _VSERVER_LIMIT_CMD_H */
11644 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/limit_def.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/limit_def.h
11645 --- linux-3.9.4/include/linux/vserver/limit_def.h       1970-01-01 00:00:00.000000000 +0000
11646 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/limit_def.h     2013-05-31 14:47:11.000000000 +0000
11647 @@ -0,0 +1,47 @@
11648 +#ifndef _VSERVER_LIMIT_DEF_H
11649 +#define _VSERVER_LIMIT_DEF_H
11650 +
11651 +#include <asm/atomic.h>
11652 +#include <asm/resource.h>
11653 +
11654 +#include "limit.h"
11655 +
11656 +
11657 +struct _vx_res_limit {
11658 +       rlim_t soft;            /* Context soft limit */
11659 +       rlim_t hard;            /* Context hard limit */
11660 +
11661 +       rlim_atomic_t rcur;     /* Current value */
11662 +       rlim_t rmin;            /* Context minimum */
11663 +       rlim_t rmax;            /* Context maximum */
11664 +
11665 +       atomic_t lhit;          /* Limit hits */
11666 +};
11667 +
11668 +/* context sub struct */
11669 +
11670 +struct _vx_limit {
11671 +       struct _vx_res_limit res[NUM_LIMITS];
11672 +};
11673 +
11674 +#ifdef CONFIG_VSERVER_DEBUG
11675 +
11676 +static inline void __dump_vx_limit(struct _vx_limit *limit)
11677 +{
11678 +       int i;
11679 +
11680 +       printk("\t_vx_limit:");
11681 +       for (i = 0; i < NUM_LIMITS; i++) {
11682 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
11683 +                       i, (unsigned long)__rlim_get(limit, i),
11684 +                       (unsigned long)__rlim_rmin(limit, i),
11685 +                       (unsigned long)__rlim_rmax(limit, i),
11686 +                       (long)__rlim_soft(limit, i),
11687 +                       (long)__rlim_hard(limit, i),
11688 +                       atomic_read(&__rlim_lhit(limit, i)));
11689 +       }
11690 +}
11691 +
11692 +#endif
11693 +
11694 +#endif /* _VSERVER_LIMIT_DEF_H */
11695 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/limit_int.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/limit_int.h
11696 --- linux-3.9.4/include/linux/vserver/limit_int.h       1970-01-01 00:00:00.000000000 +0000
11697 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/limit_int.h     2013-05-31 14:47:11.000000000 +0000
11698 @@ -0,0 +1,193 @@
11699 +#ifndef _VSERVER_LIMIT_INT_H
11700 +#define _VSERVER_LIMIT_INT_H
11701 +
11702 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
11703 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
11704 +
11705 +extern const char *vlimit_name[NUM_LIMITS];
11706 +
11707 +static inline void __vx_acc_cres(struct vx_info *vxi,
11708 +       int res, int dir, void *_data, char *_file, int _line)
11709 +{
11710 +       if (VXD_RCRES_COND(res))
11711 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
11712 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11713 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11714 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
11715 +       if (!vxi)
11716 +               return;
11717 +
11718 +       if (dir > 0)
11719 +               __rlim_inc(&vxi->limit, res);
11720 +       else
11721 +               __rlim_dec(&vxi->limit, res);
11722 +}
11723 +
11724 +static inline void __vx_add_cres(struct vx_info *vxi,
11725 +       int res, int amount, void *_data, char *_file, int _line)
11726 +{
11727 +       if (VXD_RCRES_COND(res))
11728 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
11729 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11730 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11731 +                       amount, _data, _file, _line);
11732 +       if (amount == 0)
11733 +               return;
11734 +       if (!vxi)
11735 +               return;
11736 +       __rlim_add(&vxi->limit, res, amount);
11737 +}
11738 +
11739 +static inline
11740 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
11741 +{
11742 +       int cond = (value > __rlim_rmax(limit, res));
11743 +
11744 +       if (cond)
11745 +               __rlim_rmax(limit, res) = value;
11746 +       return cond;
11747 +}
11748 +
11749 +static inline
11750 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
11751 +{
11752 +       int cond = (value < __rlim_rmin(limit, res));
11753 +
11754 +       if (cond)
11755 +               __rlim_rmin(limit, res) = value;
11756 +       return cond;
11757 +}
11758 +
11759 +static inline
11760 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
11761 +{
11762 +       if (!__vx_cres_adjust_max(limit, res, value))
11763 +               __vx_cres_adjust_min(limit, res, value);
11764 +}
11765 +
11766 +
11767 +/*     return values:
11768 +        +1 ... no limit hit
11769 +        -1 ... over soft limit
11770 +         0 ... over hard limit         */
11771 +
11772 +static inline int __vx_cres_avail(struct vx_info *vxi,
11773 +       int res, int num, char *_file, int _line)
11774 +{
11775 +       struct _vx_limit *limit;
11776 +       rlim_t value;
11777 +
11778 +       if (VXD_RLIMIT_COND(res))
11779 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
11780 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11781 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
11782 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
11783 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11784 +                       num, _file, _line);
11785 +       if (!vxi)
11786 +               return 1;
11787 +
11788 +       limit = &vxi->limit;
11789 +       value = __rlim_get(limit, res);
11790 +
11791 +       if (!__vx_cres_adjust_max(limit, res, value))
11792 +               __vx_cres_adjust_min(limit, res, value);
11793 +
11794 +       if (num == 0)
11795 +               return 1;
11796 +
11797 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
11798 +               return -1;
11799 +       if (value + num <= __rlim_soft(limit, res))
11800 +               return -1;
11801 +
11802 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
11803 +               return 1;
11804 +       if (value + num <= __rlim_hard(limit, res))
11805 +               return 1;
11806 +
11807 +       __rlim_hit(limit, res);
11808 +       return 0;
11809 +}
11810 +
11811 +
11812 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
11813 +
11814 +static inline
11815 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
11816 +{
11817 +       rlim_t value, sum = 0;
11818 +       int res;
11819 +
11820 +       while ((res = *array++)) {
11821 +               value = __rlim_get(limit, res);
11822 +               __vx_cres_fixup(limit, res, value);
11823 +               sum += value;
11824 +       }
11825 +       return sum;
11826 +}
11827 +
11828 +static inline
11829 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
11830 +{
11831 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
11832 +       int res = *array;
11833 +
11834 +       if (value == __rlim_get(limit, res))
11835 +               return value;
11836 +
11837 +       __rlim_set(limit, res, value);
11838 +       /* now adjust min/max */
11839 +       if (!__vx_cres_adjust_max(limit, res, value))
11840 +               __vx_cres_adjust_min(limit, res, value);
11841 +
11842 +       return value;
11843 +}
11844 +
11845 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
11846 +       const int *array, int num, char *_file, int _line)
11847 +{
11848 +       struct _vx_limit *limit;
11849 +       rlim_t value = 0;
11850 +       int res;
11851 +
11852 +       if (num == 0)
11853 +               return 1;
11854 +       if (!vxi)
11855 +               return 1;
11856 +
11857 +       limit = &vxi->limit;
11858 +       res = *array;
11859 +       value = __vx_cres_array_sum(limit, array + 1);
11860 +
11861 +       __rlim_set(limit, res, value);
11862 +       __vx_cres_fixup(limit, res, value);
11863 +
11864 +       return __vx_cres_avail(vxi, res, num, _file, _line);
11865 +}
11866 +
11867 +
11868 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
11869 +{
11870 +       rlim_t value;
11871 +       int res;
11872 +
11873 +       /* complex resources first */
11874 +       if ((id < 0) || (id == RLIMIT_RSS))
11875 +               __vx_cres_array_fixup(limit, VLA_RSS);
11876 +
11877 +       for (res = 0; res < NUM_LIMITS; res++) {
11878 +               if ((id > 0) && (res != id))
11879 +                       continue;
11880 +
11881 +               value = __rlim_get(limit, res);
11882 +               __vx_cres_fixup(limit, res, value);
11883 +
11884 +               /* not supposed to happen, maybe warn? */
11885 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
11886 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
11887 +       }
11888 +}
11889 +
11890 +
11891 +#endif /* _VSERVER_LIMIT_INT_H */
11892 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/monitor.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/monitor.h
11893 --- linux-3.9.4/include/linux/vserver/monitor.h 1970-01-01 00:00:00.000000000 +0000
11894 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/monitor.h       2013-05-31 14:47:11.000000000 +0000
11895 @@ -0,0 +1,6 @@
11896 +#ifndef _VSERVER_MONITOR_H
11897 +#define _VSERVER_MONITOR_H
11898 +
11899 +#include <uapi/vserver/monitor.h>
11900 +
11901 +#endif /* _VSERVER_MONITOR_H */
11902 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/network.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/network.h
11903 --- linux-3.9.4/include/linux/vserver/network.h 1970-01-01 00:00:00.000000000 +0000
11904 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/network.h       2013-05-31 14:47:11.000000000 +0000
11905 @@ -0,0 +1,76 @@
11906 +#ifndef _VSERVER_NETWORK_H
11907 +#define _VSERVER_NETWORK_H
11908 +
11909 +
11910 +#include <linux/list.h>
11911 +#include <linux/spinlock.h>
11912 +#include <linux/rcupdate.h>
11913 +#include <linux/in.h>
11914 +#include <linux/in6.h>
11915 +#include <asm/atomic.h>
11916 +#include <uapi/vserver/network.h>
11917 +
11918 +struct nx_addr_v4 {
11919 +       struct nx_addr_v4 *next;
11920 +       struct in_addr ip[2];
11921 +       struct in_addr mask;
11922 +       uint16_t type;
11923 +       uint16_t flags;
11924 +};
11925 +
11926 +struct nx_addr_v6 {
11927 +       struct nx_addr_v6 *next;
11928 +       struct in6_addr ip;
11929 +       struct in6_addr mask;
11930 +       uint32_t prefix;
11931 +       uint16_t type;
11932 +       uint16_t flags;
11933 +};
11934 +
11935 +struct nx_info {
11936 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
11937 +       nid_t nx_id;                    /* vnet id */
11938 +       atomic_t nx_usecnt;             /* usage count */
11939 +       atomic_t nx_tasks;              /* tasks count */
11940 +       int nx_state;                   /* context state */
11941 +
11942 +       uint64_t nx_flags;              /* network flag word */
11943 +       uint64_t nx_ncaps;              /* network capabilities */
11944 +
11945 +       spinlock_t addr_lock;           /* protect address changes */
11946 +       struct in_addr v4_lback;        /* Loopback address */
11947 +       struct in_addr v4_bcast;        /* Broadcast address */
11948 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
11949 +#ifdef CONFIG_IPV6
11950 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
11951 +#endif
11952 +       char nx_name[65];               /* network context name */
11953 +};
11954 +
11955 +
11956 +/* status flags */
11957 +
11958 +#define NXS_HASHED      0x0001
11959 +#define NXS_SHUTDOWN    0x0100
11960 +#define NXS_RELEASED    0x8000
11961 +
11962 +extern struct nx_info *lookup_nx_info(int);
11963 +
11964 +extern int get_nid_list(int, unsigned int *, int);
11965 +extern int nid_is_hashed(nid_t);
11966 +
11967 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
11968 +
11969 +extern long vs_net_change(struct nx_info *, unsigned int);
11970 +
11971 +struct sock;
11972 +
11973 +
11974 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
11975 +#ifdef  CONFIG_IPV6
11976 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
11977 +#else
11978 +#define NX_IPV6(n)     (0)
11979 +#endif
11980 +
11981 +#endif /* _VSERVER_NETWORK_H */
11982 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/network_cmd.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/network_cmd.h
11983 --- linux-3.9.4/include/linux/vserver/network_cmd.h     1970-01-01 00:00:00.000000000 +0000
11984 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/network_cmd.h   2013-05-31 14:47:11.000000000 +0000
11985 @@ -0,0 +1,37 @@
11986 +#ifndef _VSERVER_NETWORK_CMD_H
11987 +#define _VSERVER_NETWORK_CMD_H
11988 +
11989 +#include <uapi/vserver/network_cmd.h>
11990 +
11991 +extern int vc_task_nid(uint32_t);
11992 +
11993 +extern int vc_nx_info(struct nx_info *, void __user *);
11994 +
11995 +extern int vc_net_create(uint32_t, void __user *);
11996 +extern int vc_net_migrate(struct nx_info *, void __user *);
11997 +
11998 +extern int vc_net_add(struct nx_info *, void __user *);
11999 +extern int vc_net_remove(struct nx_info *, void __user *);
12000 +
12001 +extern int vc_net_add_ipv4_v1(struct nx_info *, void __user *);
12002 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
12003 +
12004 +extern int vc_net_rem_ipv4_v1(struct nx_info *, void __user *);
12005 +extern int vc_net_rem_ipv4(struct nx_info *, void __user *);
12006 +
12007 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
12008 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
12009 +
12010 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
12011 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
12012 +
12013 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
12014 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
12015 +
12016 +extern int vc_get_nflags(struct nx_info *, void __user *);
12017 +extern int vc_set_nflags(struct nx_info *, void __user *);
12018 +
12019 +extern int vc_get_ncaps(struct nx_info *, void __user *);
12020 +extern int vc_set_ncaps(struct nx_info *, void __user *);
12021 +
12022 +#endif /* _VSERVER_CONTEXT_CMD_H */
12023 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/percpu.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/percpu.h
12024 --- linux-3.9.4/include/linux/vserver/percpu.h  1970-01-01 00:00:00.000000000 +0000
12025 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/percpu.h        2013-05-31 14:47:11.000000000 +0000
12026 @@ -0,0 +1,14 @@
12027 +#ifndef _VSERVER_PERCPU_H
12028 +#define _VSERVER_PERCPU_H
12029 +
12030 +#include "cvirt_def.h"
12031 +#include "sched_def.h"
12032 +
12033 +struct _vx_percpu {
12034 +       struct _vx_cvirt_pc cvirt;
12035 +       struct _vx_sched_pc sched;
12036 +};
12037 +
12038 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
12039 +
12040 +#endif /* _VSERVER_PERCPU_H */
12041 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/pid.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/pid.h
12042 --- linux-3.9.4/include/linux/vserver/pid.h     1970-01-01 00:00:00.000000000 +0000
12043 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/pid.h   2013-05-31 14:47:11.000000000 +0000
12044 @@ -0,0 +1,51 @@
12045 +#ifndef _VSERVER_PID_H
12046 +#define _VSERVER_PID_H
12047 +
12048 +/* pid faking stuff */
12049 +
12050 +#define vx_info_map_pid(v, p) \
12051 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
12052 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
12053 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
12054 +#define vx_map_tgid(p) vx_map_pid(p)
12055 +
12056 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
12057 +       const char *func, const char *file, int line)
12058 +{
12059 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12060 +               vxfprintk(VXD_CBIT(cvirt, 2),
12061 +                       "vx_map_tgid: %p/%llx: %d -> %d",
12062 +                       vxi, (long long)vxi->vx_flags, pid,
12063 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
12064 +                       func, file, line);
12065 +               if (pid == 0)
12066 +                       return 0;
12067 +               if (pid == vxi->vx_initpid)
12068 +                       return 1;
12069 +       }
12070 +       return pid;
12071 +}
12072 +
12073 +#define vx_info_rmap_pid(v, p) \
12074 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
12075 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
12076 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
12077 +
12078 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
12079 +       const char *func, const char *file, int line)
12080 +{
12081 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12082 +               vxfprintk(VXD_CBIT(cvirt, 2),
12083 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
12084 +                       vxi, (long long)vxi->vx_flags, pid,
12085 +                       (pid == 1) ? vxi->vx_initpid : pid,
12086 +                       func, file, line);
12087 +               if ((pid == 1) && vxi->vx_initpid)
12088 +                       return vxi->vx_initpid;
12089 +               if (pid == vxi->vx_initpid)
12090 +                       return ~0U;
12091 +       }
12092 +       return pid;
12093 +}
12094 +
12095 +#endif
12096 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/sched.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/sched.h
12097 --- linux-3.9.4/include/linux/vserver/sched.h   1970-01-01 00:00:00.000000000 +0000
12098 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/sched.h 2013-05-31 14:47:11.000000000 +0000
12099 @@ -0,0 +1,23 @@
12100 +#ifndef _VSERVER_SCHED_H
12101 +#define _VSERVER_SCHED_H
12102 +
12103 +
12104 +#ifdef __KERNEL__
12105 +
12106 +struct timespec;
12107 +
12108 +void vx_vsi_uptime(struct timespec *, struct timespec *);
12109 +
12110 +
12111 +struct vx_info;
12112 +
12113 +void vx_update_load(struct vx_info *);
12114 +
12115 +
12116 +void vx_update_sched_param(struct _vx_sched *sched,
12117 +       struct _vx_sched_pc *sched_pc);
12118 +
12119 +#endif /* __KERNEL__ */
12120 +#else  /* _VSERVER_SCHED_H */
12121 +#warning duplicate inclusion
12122 +#endif /* _VSERVER_SCHED_H */
12123 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/sched_cmd.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/sched_cmd.h
12124 --- linux-3.9.4/include/linux/vserver/sched_cmd.h       1970-01-01 00:00:00.000000000 +0000
12125 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/sched_cmd.h     2013-05-31 14:47:11.000000000 +0000
12126 @@ -0,0 +1,11 @@
12127 +#ifndef _VSERVER_SCHED_CMD_H
12128 +#define _VSERVER_SCHED_CMD_H
12129 +
12130 +
12131 +#include <linux/compiler.h>
12132 +#include <uapi/vserver/sched_cmd.h>
12133 +
12134 +extern int vc_set_prio_bias(struct vx_info *, void __user *);
12135 +extern int vc_get_prio_bias(struct vx_info *, void __user *);
12136 +
12137 +#endif /* _VSERVER_SCHED_CMD_H */
12138 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/sched_def.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/sched_def.h
12139 --- linux-3.9.4/include/linux/vserver/sched_def.h       1970-01-01 00:00:00.000000000 +0000
12140 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/sched_def.h     2013-05-31 14:47:11.000000000 +0000
12141 @@ -0,0 +1,38 @@
12142 +#ifndef _VSERVER_SCHED_DEF_H
12143 +#define _VSERVER_SCHED_DEF_H
12144 +
12145 +#include <linux/spinlock.h>
12146 +#include <linux/jiffies.h>
12147 +#include <linux/cpumask.h>
12148 +#include <asm/atomic.h>
12149 +#include <asm/param.h>
12150 +
12151 +
12152 +/* context sub struct */
12153 +
12154 +struct _vx_sched {
12155 +       int prio_bias;                  /* bias offset for priority */
12156 +
12157 +       cpumask_t update;               /* CPUs which should update */
12158 +};
12159 +
12160 +struct _vx_sched_pc {
12161 +       int prio_bias;                  /* bias offset for priority */
12162 +
12163 +       uint64_t user_ticks;            /* token tick events */
12164 +       uint64_t sys_ticks;             /* token tick events */
12165 +       uint64_t hold_ticks;            /* token ticks paused */
12166 +};
12167 +
12168 +
12169 +#ifdef CONFIG_VSERVER_DEBUG
12170 +
12171 +static inline void __dump_vx_sched(struct _vx_sched *sched)
12172 +{
12173 +       printk("\t_vx_sched:\n");
12174 +       printk("\t priority = %4d\n", sched->prio_bias);
12175 +}
12176 +
12177 +#endif
12178 +
12179 +#endif /* _VSERVER_SCHED_DEF_H */
12180 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/signal.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/signal.h
12181 --- linux-3.9.4/include/linux/vserver/signal.h  1970-01-01 00:00:00.000000000 +0000
12182 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/signal.h        2013-05-31 14:47:11.000000000 +0000
12183 @@ -0,0 +1,14 @@
12184 +#ifndef _VSERVER_SIGNAL_H
12185 +#define _VSERVER_SIGNAL_H
12186 +
12187 +
12188 +#ifdef __KERNEL__
12189 +
12190 +struct vx_info;
12191 +
12192 +int vx_info_kill(struct vx_info *, int, int);
12193 +
12194 +#endif /* __KERNEL__ */
12195 +#else  /* _VSERVER_SIGNAL_H */
12196 +#warning duplicate inclusion
12197 +#endif /* _VSERVER_SIGNAL_H */
12198 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/signal_cmd.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/signal_cmd.h
12199 --- linux-3.9.4/include/linux/vserver/signal_cmd.h      1970-01-01 00:00:00.000000000 +0000
12200 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/signal_cmd.h    2013-05-31 14:47:11.000000000 +0000
12201 @@ -0,0 +1,14 @@
12202 +#ifndef _VSERVER_SIGNAL_CMD_H
12203 +#define _VSERVER_SIGNAL_CMD_H
12204 +
12205 +#include <uapi/vserver/signal_cmd.h>
12206 +
12207 +
12208 +extern int vc_ctx_kill(struct vx_info *, void __user *);
12209 +extern int vc_wait_exit(struct vx_info *, void __user *);
12210 +
12211 +
12212 +extern int vc_get_pflags(uint32_t pid, void __user *);
12213 +extern int vc_set_pflags(uint32_t pid, void __user *);
12214 +
12215 +#endif /* _VSERVER_SIGNAL_CMD_H */
12216 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/space.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/space.h
12217 --- linux-3.9.4/include/linux/vserver/space.h   1970-01-01 00:00:00.000000000 +0000
12218 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/space.h 2013-05-31 14:47:11.000000000 +0000
12219 @@ -0,0 +1,12 @@
12220 +#ifndef _VSERVER_SPACE_H
12221 +#define _VSERVER_SPACE_H
12222 +
12223 +#include <linux/types.h>
12224 +
12225 +struct vx_info;
12226 +
12227 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
12228 +
12229 +#else  /* _VSERVER_SPACE_H */
12230 +#warning duplicate inclusion
12231 +#endif /* _VSERVER_SPACE_H */
12232 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/space_cmd.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/space_cmd.h
12233 --- linux-3.9.4/include/linux/vserver/space_cmd.h       1970-01-01 00:00:00.000000000 +0000
12234 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/space_cmd.h     2013-05-31 14:47:11.000000000 +0000
12235 @@ -0,0 +1,13 @@
12236 +#ifndef _VSERVER_SPACE_CMD_H
12237 +#define _VSERVER_SPACE_CMD_H
12238 +
12239 +#include <uapi/vserver/space_cmd.h>
12240 +
12241 +
12242 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
12243 +extern int vc_set_space_v1(struct vx_info *, void __user *);
12244 +extern int vc_enter_space(struct vx_info *, void __user *);
12245 +extern int vc_set_space(struct vx_info *, void __user *);
12246 +extern int vc_get_space_mask(void __user *, int);
12247 +
12248 +#endif /* _VSERVER_SPACE_CMD_H */
12249 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/switch.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/switch.h
12250 --- linux-3.9.4/include/linux/vserver/switch.h  1970-01-01 00:00:00.000000000 +0000
12251 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/switch.h        2013-05-31 14:47:11.000000000 +0000
12252 @@ -0,0 +1,8 @@
12253 +#ifndef _VSERVER_SWITCH_H
12254 +#define _VSERVER_SWITCH_H
12255 +
12256 +
12257 +#include <linux/errno.h>
12258 +#include <uapi/vserver/switch.h>
12259 +
12260 +#endif /* _VSERVER_SWITCH_H */
12261 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/tag.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/tag.h
12262 --- linux-3.9.4/include/linux/vserver/tag.h     1970-01-01 00:00:00.000000000 +0000
12263 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/tag.h   2013-05-31 14:47:11.000000000 +0000
12264 @@ -0,0 +1,143 @@
12265 +#ifndef _DX_TAG_H
12266 +#define _DX_TAG_H
12267 +
12268 +#include <linux/types.h>
12269 +
12270 +
12271 +#define DX_TAG(in)     (IS_TAGGED(in))
12272 +
12273 +
12274 +#ifdef CONFIG_TAG_NFSD
12275 +#define DX_TAG_NFSD    1
12276 +#else
12277 +#define DX_TAG_NFSD    0
12278 +#endif
12279 +
12280 +
12281 +#ifdef CONFIG_TAGGING_NONE
12282 +
12283 +#define MAX_UID                0xFFFFFFFF
12284 +#define MAX_GID                0xFFFFFFFF
12285 +
12286 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
12287 +
12288 +#define TAGINO_UID(cond, uid, tag)     (uid)
12289 +#define TAGINO_GID(cond, gid, tag)     (gid)
12290 +
12291 +#endif
12292 +
12293 +
12294 +#ifdef CONFIG_TAGGING_GID16
12295 +
12296 +#define MAX_UID                0xFFFFFFFF
12297 +#define MAX_GID                0x0000FFFF
12298 +
12299 +#define INOTAG_TAG(cond, uid, gid, tag)        \
12300 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
12301 +
12302 +#define TAGINO_UID(cond, uid, tag)     (uid)
12303 +#define TAGINO_GID(cond, gid, tag)     \
12304 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
12305 +
12306 +#endif
12307 +
12308 +
12309 +#ifdef CONFIG_TAGGING_ID24
12310 +
12311 +#define MAX_UID                0x00FFFFFF
12312 +#define MAX_GID                0x00FFFFFF
12313 +
12314 +#define INOTAG_TAG(cond, uid, gid, tag)        \
12315 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
12316 +
12317 +#define TAGINO_UID(cond, uid, tag)     \
12318 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
12319 +#define TAGINO_GID(cond, gid, tag)     \
12320 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
12321 +
12322 +#endif
12323 +
12324 +
12325 +#ifdef CONFIG_TAGGING_UID16
12326 +
12327 +#define MAX_UID                0x0000FFFF
12328 +#define MAX_GID                0xFFFFFFFF
12329 +
12330 +#define INOTAG_TAG(cond, uid, gid, tag)        \
12331 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
12332 +
12333 +#define TAGINO_UID(cond, uid, tag)     \
12334 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
12335 +#define TAGINO_GID(cond, gid, tag)     (gid)
12336 +
12337 +#endif
12338 +
12339 +
12340 +#ifdef CONFIG_TAGGING_INTERN
12341 +
12342 +#define MAX_UID                0xFFFFFFFF
12343 +#define MAX_GID                0xFFFFFFFF
12344 +
12345 +#define INOTAG_TAG(cond, uid, gid, tag)        \
12346 +       ((cond) ? (tag) : 0)
12347 +
12348 +#define TAGINO_UID(cond, uid, tag)     (uid)
12349 +#define TAGINO_GID(cond, gid, tag)     (gid)
12350 +
12351 +#endif
12352 +
12353 +
12354 +#ifndef CONFIG_TAGGING_NONE
12355 +#define dx_current_fstag(sb)   \
12356 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
12357 +#else
12358 +#define dx_current_fstag(sb)   (0)
12359 +#endif
12360 +
12361 +#ifndef CONFIG_TAGGING_INTERN
12362 +#define TAGINO_TAG(cond, tag)  (0)
12363 +#else
12364 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
12365 +#endif
12366 +
12367 +#define INOTAG_UID(cond, uid, gid)     \
12368 +       ((cond) ? ((uid) & MAX_UID) : (uid))
12369 +#define INOTAG_GID(cond, uid, gid)     \
12370 +       ((cond) ? ((gid) & MAX_GID) : (gid))
12371 +
12372 +
12373 +static inline uid_t dx_map_uid(uid_t uid)
12374 +{
12375 +       if ((uid > MAX_UID) && (uid != -1))
12376 +               uid = -2;
12377 +       return (uid & MAX_UID);
12378 +}
12379 +
12380 +static inline gid_t dx_map_gid(gid_t gid)
12381 +{
12382 +       if ((gid > MAX_GID) && (gid != -1))
12383 +               gid = -2;
12384 +       return (gid & MAX_GID);
12385 +}
12386 +
12387 +struct peer_tag {
12388 +       int32_t xid;
12389 +       int32_t nid;
12390 +};
12391 +
12392 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
12393 +
12394 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
12395 +                unsigned long *flags);
12396 +
12397 +#ifdef CONFIG_PROPAGATE
12398 +
12399 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
12400 +
12401 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
12402 +
12403 +#else
12404 +#define dx_propagate_tag(n, i) do { } while (0)
12405 +#endif
12406 +
12407 +#endif /* _DX_TAG_H */
12408 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/tag_cmd.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/tag_cmd.h
12409 --- linux-3.9.4/include/linux/vserver/tag_cmd.h 1970-01-01 00:00:00.000000000 +0000
12410 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/tag_cmd.h       2013-05-31 14:47:11.000000000 +0000
12411 @@ -0,0 +1,10 @@
12412 +#ifndef _VSERVER_TAG_CMD_H
12413 +#define _VSERVER_TAG_CMD_H
12414 +
12415 +#include <uapi/vserver/tag_cmd.h>
12416 +
12417 +extern int vc_task_tag(uint32_t);
12418 +
12419 +extern int vc_tag_migrate(uint32_t);
12420 +
12421 +#endif /* _VSERVER_TAG_CMD_H */
12422 diff -NurpP --minimal linux-3.9.4/include/net/addrconf.h linux-3.9.4-vs2.3.6.1/include/net/addrconf.h
12423 --- linux-3.9.4/include/net/addrconf.h  2013-05-31 13:45:28.000000000 +0000
12424 +++ linux-3.9.4-vs2.3.6.1/include/net/addrconf.h        2013-05-31 17:17:53.000000000 +0000
12425 @@ -85,7 +85,8 @@ extern int                    ipv6_dev_get_saddr(struct n
12426                                                const struct net_device *dev,
12427                                                const struct in6_addr *daddr,
12428                                                unsigned int srcprefs,
12429 -                                              struct in6_addr *saddr);
12430 +                                              struct in6_addr *saddr,
12431 +                                              struct nx_info *nxi);
12432  extern int                     ipv6_get_lladdr(struct net_device *dev,
12433                                                 struct in6_addr *addr,
12434                                                 unsigned char banned_flags);
12435 diff -NurpP --minimal linux-3.9.4/include/net/af_unix.h linux-3.9.4-vs2.3.6.1/include/net/af_unix.h
12436 --- linux-3.9.4/include/net/af_unix.h   2013-02-19 13:58:52.000000000 +0000
12437 +++ linux-3.9.4-vs2.3.6.1/include/net/af_unix.h 2013-05-31 17:17:53.000000000 +0000
12438 @@ -4,6 +4,7 @@
12439  #include <linux/socket.h>
12440  #include <linux/un.h>
12441  #include <linux/mutex.h>
12442 +#include <linux/vs_base.h>
12443  #include <net/sock.h>
12444  
12445  extern void unix_inflight(struct file *fp);
12446 diff -NurpP --minimal linux-3.9.4/include/net/inet_timewait_sock.h linux-3.9.4-vs2.3.6.1/include/net/inet_timewait_sock.h
12447 --- linux-3.9.4/include/net/inet_timewait_sock.h        2013-05-31 13:45:28.000000000 +0000
12448 +++ linux-3.9.4-vs2.3.6.1/include/net/inet_timewait_sock.h      2013-05-31 17:18:34.000000000 +0000
12449 @@ -116,6 +116,10 @@ struct inet_timewait_sock {
12450  #define tw_dport               __tw_common.skc_dport
12451  #define tw_num                 __tw_common.skc_num
12452  #define tw_portpair            __tw_common.skc_portpair
12453 +#define tw_xid                 __tw_common.skc_xid
12454 +#define tw_vx_info             __tw_common.skc_vx_info
12455 +#define tw_nid                 __tw_common.skc_nid
12456 +#define tw_nx_info             __tw_common.skc_nx_info
12457  
12458         int                     tw_timeout;
12459         volatile unsigned char  tw_substate;
12460 diff -NurpP --minimal linux-3.9.4/include/net/ip6_route.h linux-3.9.4-vs2.3.6.1/include/net/ip6_route.h
12461 --- linux-3.9.4/include/net/ip6_route.h 2013-05-31 13:45:28.000000000 +0000
12462 +++ linux-3.9.4-vs2.3.6.1/include/net/ip6_route.h       2013-05-31 17:17:53.000000000 +0000
12463 @@ -95,7 +95,8 @@ extern int                    ip6_route_get_saddr(struct
12464                                                     struct rt6_info *rt,
12465                                                     const struct in6_addr *daddr,
12466                                                     unsigned int prefs,
12467 -                                                   struct in6_addr *saddr);
12468 +                                                   struct in6_addr *saddr,
12469 +                                                   struct nx_info *nxi);
12470  
12471  extern struct rt6_info         *rt6_lookup(struct net *net,
12472                                             const struct in6_addr *daddr,
12473 diff -NurpP --minimal linux-3.9.4/include/net/route.h linux-3.9.4-vs2.3.6.1/include/net/route.h
12474 --- linux-3.9.4/include/net/route.h     2013-02-19 13:58:52.000000000 +0000
12475 +++ linux-3.9.4-vs2.3.6.1/include/net/route.h   2013-05-31 17:17:53.000000000 +0000
12476 @@ -207,6 +207,9 @@ static inline void ip_rt_put(struct rtab
12477         dst_release(&rt->dst);
12478  }
12479  
12480 +#include <linux/vs_base.h>
12481 +#include <linux/vs_inet.h>
12482 +
12483  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
12484  
12485  extern const __u8 ip_tos2prio[16];
12486 @@ -256,6 +259,9 @@ static inline void ip_route_connect_init
12487                            protocol, flow_flags, dst, src, dport, sport);
12488  }
12489  
12490 +extern struct rtable *ip_v4_find_src(struct net *net, struct nx_info *,
12491 +       struct flowi4 *);
12492 +
12493  static inline struct rtable *ip_route_connect(struct flowi4 *fl4,
12494                                               __be32 dst, __be32 src, u32 tos,
12495                                               int oif, u8 protocol,
12496 @@ -264,11 +270,25 @@ static inline struct rtable *ip_route_co
12497  {
12498         struct net *net = sock_net(sk);
12499         struct rtable *rt;
12500 +       struct nx_info *nx_info = current_nx_info();
12501  
12502         ip_route_connect_init(fl4, dst, src, tos, oif, protocol,
12503                               sport, dport, sk, can_sleep);
12504  
12505 -       if (!dst || !src) {
12506 +       if (sk)
12507 +               nx_info = sk->sk_nx_info;
12508 +
12509 +       vxdprintk(VXD_CBIT(net, 4),
12510 +               "ip_route_connect(%p) %p,%p;%lx",
12511 +               sk, nx_info, sk->sk_socket,
12512 +               (sk->sk_socket?sk->sk_socket->flags:0));
12513 +
12514 +       rt = ip_v4_find_src(net, nx_info, fl4);
12515 +       if (IS_ERR(rt))
12516 +               return rt;
12517 +       ip_rt_put(rt);
12518 +
12519 +       if (!fl4->daddr || !fl4->saddr) {
12520                 rt = __ip_route_output_key(net, fl4);
12521                 if (IS_ERR(rt))
12522                         return rt;
12523 diff -NurpP --minimal linux-3.9.4/include/net/sock.h linux-3.9.4-vs2.3.6.1/include/net/sock.h
12524 --- linux-3.9.4/include/net/sock.h      2013-05-31 14:22:27.000000000 +0000
12525 +++ linux-3.9.4-vs2.3.6.1/include/net/sock.h    2013-05-31 17:17:53.000000000 +0000
12526 @@ -191,6 +191,10 @@ struct sock_common {
12527  #ifdef CONFIG_NET_NS
12528         struct net              *skc_net;
12529  #endif
12530 +       xid_t                   skc_xid;
12531 +       struct vx_info          *skc_vx_info;
12532 +       nid_t                   skc_nid;
12533 +       struct nx_info          *skc_nx_info;
12534         /*
12535          * fields between dontcopy_begin/dontcopy_end
12536          * are not copied in sock_copy()
12537 @@ -304,6 +308,10 @@ struct sock {
12538  #define sk_bind_node           __sk_common.skc_bind_node
12539  #define sk_prot                        __sk_common.skc_prot
12540  #define sk_net                 __sk_common.skc_net
12541 +#define sk_xid                 __sk_common.skc_xid
12542 +#define sk_vx_info             __sk_common.skc_vx_info
12543 +#define sk_nid                 __sk_common.skc_nid
12544 +#define sk_nx_info             __sk_common.skc_nx_info
12545         socket_lock_t           sk_lock;
12546         struct sk_buff_head     sk_receive_queue;
12547         /*
12548 diff -NurpP --minimal linux-3.9.4/include/uapi/Kbuild linux-3.9.4-vs2.3.6.1/include/uapi/Kbuild
12549 --- linux-3.9.4/include/uapi/Kbuild     2012-12-11 03:30:57.000000000 +0000
12550 +++ linux-3.9.4-vs2.3.6.1/include/uapi/Kbuild   2013-05-31 14:47:11.000000000 +0000
12551 @@ -12,3 +12,4 @@ header-y += video/
12552  header-y += drm/
12553  header-y += xen/
12554  header-y += scsi/
12555 +header-y += vserver/
12556 diff -NurpP --minimal linux-3.9.4/include/uapi/linux/capability.h linux-3.9.4-vs2.3.6.1/include/uapi/linux/capability.h
12557 --- linux-3.9.4/include/uapi/linux/capability.h 2012-12-11 03:30:57.000000000 +0000
12558 +++ linux-3.9.4-vs2.3.6.1/include/uapi/linux/capability.h       2013-05-31 14:47:11.000000000 +0000
12559 @@ -259,6 +259,7 @@ struct vfs_cap_data {
12560     arbitrary SCSI commands */
12561  /* Allow setting encryption key on loopback filesystem */
12562  /* Allow setting zone reclaim policy */
12563 +/* Allow the selection of a security context */
12564  
12565  #define CAP_SYS_ADMIN        21
12566  
12567 @@ -345,7 +346,12 @@ struct vfs_cap_data {
12568  
12569  #define CAP_LAST_CAP         CAP_BLOCK_SUSPEND
12570  
12571 -#define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
12572 +/* Allow context manipulations */
12573 +/* Allow changing context info on files */
12574 +
12575 +#define CAP_CONTEXT         63
12576 +
12577 +#define cap_valid(x) ((x) >= 0 && ((x) <= CAP_LAST_CAP || (x) == CAP_CONTEXT))
12578  
12579  /*
12580   * Bit location of each capability (used by user-space library and kernel)
12581 diff -NurpP --minimal linux-3.9.4/include/uapi/linux/fs.h linux-3.9.4-vs2.3.6.1/include/uapi/linux/fs.h
12582 --- linux-3.9.4/include/uapi/linux/fs.h 2013-05-31 13:45:29.000000000 +0000
12583 +++ linux-3.9.4-vs2.3.6.1/include/uapi/linux/fs.h       2013-05-31 23:07:43.000000000 +0000
12584 @@ -86,6 +86,9 @@ struct inodes_stat_t {
12585  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
12586  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
12587  #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
12588 +#define MS_TAGGED      (1<<8)  /* use generic inode tagging */
12589 +#define MS_NOTAGCHECK  (1<<9)  /* don't check tags */
12590 +#define MS_TAGID       (1<<25) /* use specific tag for this mount */
12591  
12592  /* These sb flags are internal to the kernel */
12593  #define MS_SNAP_STABLE (1<<27) /* Snapshot pages during writeback, if needed */
12594 @@ -192,11 +195,14 @@ struct inodes_stat_t {
12595  #define FS_EXTENT_FL                   0x00080000 /* Extents */
12596  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
12597  #define FS_NOCOW_FL                    0x00800000 /* Do not cow file */
12598 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
12599  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
12600  
12601 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
12602 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
12603 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
12604 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
12605  
12606 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
12607 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
12608  
12609  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
12610  #define SYNC_FILE_RANGE_WRITE          2
12611 diff -NurpP --minimal linux-3.9.4/include/uapi/linux/gfs2_ondisk.h linux-3.9.4-vs2.3.6.1/include/uapi/linux/gfs2_ondisk.h
12612 --- linux-3.9.4/include/uapi/linux/gfs2_ondisk.h        2012-12-11 03:30:57.000000000 +0000
12613 +++ linux-3.9.4-vs2.3.6.1/include/uapi/linux/gfs2_ondisk.h      2013-05-31 14:47:11.000000000 +0000
12614 @@ -225,6 +225,9 @@ enum {
12615         gfs2fl_Sync             = 8,
12616         gfs2fl_System           = 9,
12617         gfs2fl_TopLevel         = 10,
12618 +       gfs2fl_IXUnlink         = 16,
12619 +       gfs2fl_Barrier          = 17,
12620 +       gfs2fl_Cow              = 18,
12621         gfs2fl_TruncInProg      = 29,
12622         gfs2fl_InheritDirectio  = 30,
12623         gfs2fl_InheritJdata     = 31,
12624 @@ -242,6 +245,9 @@ enum {
12625  #define GFS2_DIF_SYNC                  0x00000100
12626  #define GFS2_DIF_SYSTEM                        0x00000200 /* New in gfs2 */
12627  #define GFS2_DIF_TOPDIR                        0x00000400 /* New in gfs2 */
12628 +#define GFS2_DIF_IXUNLINK               0x00010000
12629 +#define GFS2_DIF_BARRIER                0x00020000
12630 +#define GFS2_DIF_COW                    0x00040000
12631  #define GFS2_DIF_TRUNC_IN_PROG         0x20000000 /* New in gfs2 */
12632  #define GFS2_DIF_INHERIT_DIRECTIO      0x40000000 /* only in gfs1 */
12633  #define GFS2_DIF_INHERIT_JDATA         0x80000000
12634 diff -NurpP --minimal linux-3.9.4/include/uapi/linux/if_tun.h linux-3.9.4-vs2.3.6.1/include/uapi/linux/if_tun.h
12635 --- linux-3.9.4/include/uapi/linux/if_tun.h     2013-02-19 13:58:55.000000000 +0000
12636 +++ linux-3.9.4-vs2.3.6.1/include/uapi/linux/if_tun.h   2013-05-31 15:00:16.000000000 +0000
12637 @@ -56,6 +56,7 @@
12638  #define TUNGETVNETHDRSZ _IOR('T', 215, int)
12639  #define TUNSETVNETHDRSZ _IOW('T', 216, int)
12640  #define TUNSETQUEUE  _IOW('T', 217, int)
12641 +#define TUNSETNID     _IOW('T', 218, int)
12642  
12643  /* TUNSETIFF ifr flags */
12644  #define IFF_TUN                0x0001
12645 diff -NurpP --minimal linux-3.9.4/include/uapi/linux/major.h linux-3.9.4-vs2.3.6.1/include/uapi/linux/major.h
12646 --- linux-3.9.4/include/uapi/linux/major.h      2012-12-11 03:30:57.000000000 +0000
12647 +++ linux-3.9.4-vs2.3.6.1/include/uapi/linux/major.h    2013-05-31 14:47:11.000000000 +0000
12648 @@ -15,6 +15,7 @@
12649  #define HD_MAJOR               IDE0_MAJOR
12650  #define PTY_SLAVE_MAJOR                3
12651  #define TTY_MAJOR              4
12652 +#define VROOT_MAJOR            4
12653  #define TTYAUX_MAJOR           5
12654  #define LP_MAJOR               6
12655  #define VCS_MAJOR              7
12656 diff -NurpP --minimal linux-3.9.4/include/uapi/linux/nfs_mount.h linux-3.9.4-vs2.3.6.1/include/uapi/linux/nfs_mount.h
12657 --- linux-3.9.4/include/uapi/linux/nfs_mount.h  2012-12-11 03:30:57.000000000 +0000
12658 +++ linux-3.9.4-vs2.3.6.1/include/uapi/linux/nfs_mount.h        2013-05-31 14:47:11.000000000 +0000
12659 @@ -63,7 +63,8 @@ struct nfs_mount_data {
12660  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
12661  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
12662  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
12663 -#define NFS_MOUNT_FLAGMASK     0xFFFF
12664 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
12665 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
12666  
12667  /* The following are for internal use only */
12668  #define NFS_MOUNT_LOOKUP_CACHE_NONEG   0x10000
12669 diff -NurpP --minimal linux-3.9.4/include/uapi/linux/reboot.h linux-3.9.4-vs2.3.6.1/include/uapi/linux/reboot.h
12670 --- linux-3.9.4/include/uapi/linux/reboot.h     2012-12-11 03:30:57.000000000 +0000
12671 +++ linux-3.9.4-vs2.3.6.1/include/uapi/linux/reboot.h   2013-05-31 14:47:11.000000000 +0000
12672 @@ -33,7 +33,7 @@
12673  #define        LINUX_REBOOT_CMD_RESTART2       0xA1B2C3D4
12674  #define        LINUX_REBOOT_CMD_SW_SUSPEND     0xD000FCE2
12675  #define        LINUX_REBOOT_CMD_KEXEC          0x45584543
12676 -
12677 +#define        LINUX_REBOOT_CMD_OOM            0xDEADBEEF
12678  
12679  
12680  #endif /* _UAPI_LINUX_REBOOT_H */
12681 diff -NurpP --minimal linux-3.9.4/include/uapi/linux/sysctl.h linux-3.9.4-vs2.3.6.1/include/uapi/linux/sysctl.h
12682 --- linux-3.9.4/include/uapi/linux/sysctl.h     2012-12-11 03:30:57.000000000 +0000
12683 +++ linux-3.9.4-vs2.3.6.1/include/uapi/linux/sysctl.h   2013-05-31 14:47:11.000000000 +0000
12684 @@ -60,6 +60,7 @@ enum
12685         CTL_ABI=9,              /* Binary emulation */
12686         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
12687         CTL_ARLAN=254,          /* arlan wireless driver */
12688 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
12689         CTL_S390DBF=5677,       /* s390 debug */
12690         CTL_SUNRPC=7249,        /* sunrpc debug */
12691         CTL_PM=9899,            /* frv power management */
12692 @@ -94,6 +95,7 @@ enum
12693  
12694         KERN_PANIC=15,          /* int: panic timeout */
12695         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
12696 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
12697  
12698         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
12699         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
12700 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/Kbuild linux-3.9.4-vs2.3.6.1/include/uapi/vserver/Kbuild
12701 --- linux-3.9.4/include/uapi/vserver/Kbuild     1970-01-01 00:00:00.000000000 +0000
12702 +++ linux-3.9.4-vs2.3.6.1/include/uapi/vserver/Kbuild   2013-05-31 14:47:11.000000000 +0000
12703 @@ -0,0 +1,9 @@
12704 +
12705 +header-y += context_cmd.h network_cmd.h space_cmd.h \
12706 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
12707 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
12708 +       debug_cmd.h device_cmd.h
12709 +
12710 +header-y += switch.h context.h network.h monitor.h \
12711 +       limit.h inode.h device.h
12712 +
12713 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/cacct_cmd.h linux-3.9.4-vs2.3.6.1/include/uapi/vserver/cacct_cmd.h
12714 --- linux-3.9.4/include/uapi/vserver/cacct_cmd.h        1970-01-01 00:00:00.000000000 +0000
12715 +++ linux-3.9.4-vs2.3.6.1/include/uapi/vserver/cacct_cmd.h      2013-05-31 14:47:11.000000000 +0000
12716 @@ -0,0 +1,15 @@
12717 +#ifndef _UAPI_VS_CACCT_CMD_H
12718 +#define _UAPI_VS_CACCT_CMD_H
12719 +
12720 +
12721 +/* virtual host info name commands */
12722 +
12723 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
12724 +
12725 +struct vcmd_sock_stat_v0 {
12726 +       uint32_t field;
12727 +       uint32_t count[3];
12728 +       uint64_t total[3];
12729 +};
12730 +
12731 +#endif /* _UAPI_VS_CACCT_CMD_H */
12732 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/context.h linux-3.9.4-vs2.3.6.1/include/uapi/vserver/context.h
12733 --- linux-3.9.4/include/uapi/vserver/context.h  1970-01-01 00:00:00.000000000 +0000
12734 +++ linux-3.9.4-vs2.3.6.1/include/uapi/vserver/context.h        2013-05-31 19:44:13.000000000 +0000
12735 @@ -0,0 +1,81 @@
12736 +#ifndef _UAPI_VS_CONTEXT_H
12737 +#define _UAPI_VS_CONTEXT_H
12738 +
12739 +#include <linux/types.h>
12740 +#include <linux/capability.h>
12741 +
12742 +
12743 +/* context flags */
12744 +
12745 +#define VXF_INFO_SCHED         0x00000002
12746 +#define VXF_INFO_NPROC         0x00000004
12747 +#define VXF_INFO_PRIVATE       0x00000008
12748 +
12749 +#define VXF_INFO_INIT          0x00000010
12750 +#define VXF_INFO_HIDE          0x00000020
12751 +#define VXF_INFO_ULIMIT                0x00000040
12752 +#define VXF_INFO_NSPACE                0x00000080
12753 +
12754 +#define VXF_SCHED_HARD         0x00000100
12755 +#define VXF_SCHED_PRIO         0x00000200
12756 +#define VXF_SCHED_PAUSE                0x00000400
12757 +
12758 +#define VXF_VIRT_MEM           0x00010000
12759 +#define VXF_VIRT_UPTIME                0x00020000
12760 +#define VXF_VIRT_CPU           0x00040000
12761 +#define VXF_VIRT_LOAD          0x00080000
12762 +#define VXF_VIRT_TIME          0x00100000
12763 +
12764 +#define VXF_HIDE_MOUNT         0x01000000
12765 +/* was VXF_HIDE_NETIF          0x02000000 */
12766 +#define VXF_HIDE_VINFO         0x04000000
12767 +
12768 +#define VXF_STATE_SETUP                (1ULL << 32)
12769 +#define VXF_STATE_INIT         (1ULL << 33)
12770 +#define VXF_STATE_ADMIN                (1ULL << 34)
12771 +
12772 +#define VXF_SC_HELPER          (1ULL << 36)
12773 +#define VXF_REBOOT_KILL                (1ULL << 37)
12774 +#define VXF_PERSISTENT         (1ULL << 38)
12775 +
12776 +#define VXF_FORK_RSS           (1ULL << 48)
12777 +#define VXF_PROLIFIC           (1ULL << 49)
12778 +
12779 +#define VXF_IGNEG_NICE         (1ULL << 52)
12780 +
12781 +#define VXF_ONE_TIME           (0x0007ULL << 32)
12782 +
12783 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
12784 +
12785 +
12786 +/* context migration */
12787 +
12788 +#define VXM_SET_INIT           0x00000001
12789 +#define VXM_SET_REAPER         0x00000002
12790 +
12791 +/* context caps */
12792 +
12793 +#define VXC_SET_UTSNAME                0x00000001
12794 +#define VXC_SET_RLIMIT         0x00000002
12795 +#define VXC_FS_SECURITY                0x00000004
12796 +#define VXC_FS_TRUSTED         0x00000008
12797 +#define VXC_TIOCSTI            0x00000010
12798 +
12799 +/* was VXC_RAW_ICMP            0x00000100 */
12800 +#define VXC_SYSLOG             0x00001000
12801 +#define VXC_OOM_ADJUST         0x00002000
12802 +#define VXC_AUDIT_CONTROL      0x00004000
12803 +
12804 +/* #define VXC_SECURE_MOUNT    0x00010000
12805 +#define VXC_SECURE_REMOUNT     0x00020000 */
12806 +#define VXC_BINARY_MOUNT       0x00040000
12807 +#define VXC_DEV_MOUNT          0x00080000
12808 +
12809 +#define VXC_QUOTA_CTL          0x00100000
12810 +#define VXC_ADMIN_MAPPER       0x00200000
12811 +#define VXC_ADMIN_CLOOP                0x00400000
12812 +
12813 +#define VXC_KTHREAD            0x01000000
12814 +#define VXC_NAMESPACE          0x02000000
12815 +
12816 +#endif /* _UAPI_VS_CONTEXT_H */
12817 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/context_cmd.h linux-3.9.4-vs2.3.6.1/include/uapi/vserver/context_cmd.h
12818 --- linux-3.9.4/include/uapi/vserver/context_cmd.h      1970-01-01 00:00:00.000000000 +0000
12819 +++ linux-3.9.4-vs2.3.6.1/include/uapi/vserver/context_cmd.h    2013-05-31 14:47:11.000000000 +0000
12820 @@ -0,0 +1,115 @@
12821 +#ifndef _UAPI_VS_CONTEXT_CMD_H
12822 +#define _UAPI_VS_CONTEXT_CMD_H
12823 +
12824 +
12825 +/* vinfo commands */
12826 +
12827 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
12828 +
12829 +
12830 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
12831 +
12832 +struct vcmd_vx_info_v0 {
12833 +       uint32_t xid;
12834 +       uint32_t initpid;
12835 +       /* more to come */
12836 +};
12837 +
12838 +
12839 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
12840 +
12841 +struct vcmd_ctx_stat_v0 {
12842 +       uint32_t usecnt;
12843 +       uint32_t tasks;
12844 +       /* more to come */
12845 +};
12846 +
12847 +
12848 +/* context commands */
12849 +
12850 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
12851 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
12852 +
12853 +struct vcmd_ctx_create {
12854 +       uint64_t flagword;
12855 +};
12856 +
12857 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
12858 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
12859 +
12860 +struct vcmd_ctx_migrate {
12861 +       uint64_t flagword;
12862 +};
12863 +
12864 +
12865 +
12866 +/* flag commands */
12867 +
12868 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
12869 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
12870 +
12871 +struct vcmd_ctx_flags_v0 {
12872 +       uint64_t flagword;
12873 +       uint64_t mask;
12874 +};
12875 +
12876 +
12877 +
12878 +/* context caps commands */
12879 +
12880 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
12881 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
12882 +
12883 +struct vcmd_ctx_caps_v1 {
12884 +       uint64_t ccaps;
12885 +       uint64_t cmask;
12886 +};
12887 +
12888 +
12889 +
12890 +/* bcaps commands */
12891 +
12892 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
12893 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
12894 +
12895 +struct vcmd_bcaps {
12896 +       uint64_t bcaps;
12897 +       uint64_t bmask;
12898 +};
12899 +
12900 +
12901 +
12902 +/* umask commands */
12903 +
12904 +#define VCMD_get_umask         VC_CMD(FLAGS, 13, 0)
12905 +#define VCMD_set_umask         VC_CMD(FLAGS, 14, 0)
12906 +
12907 +struct vcmd_umask {
12908 +       uint64_t umask;
12909 +       uint64_t mask;
12910 +};
12911 +
12912 +
12913 +
12914 +/* wmask commands */
12915 +
12916 +#define VCMD_get_wmask         VC_CMD(FLAGS, 15, 0)
12917 +#define VCMD_set_wmask         VC_CMD(FLAGS, 16, 0)
12918 +
12919 +struct vcmd_wmask {
12920 +       uint64_t wmask;
12921 +       uint64_t mask;
12922 +};
12923 +
12924 +
12925 +
12926 +/* OOM badness */
12927 +
12928 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
12929 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
12930 +
12931 +struct vcmd_badness_v0 {
12932 +       int64_t bias;
12933 +};
12934 +
12935 +#endif /* _UAPI_VS_CONTEXT_CMD_H */
12936 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/cvirt_cmd.h linux-3.9.4-vs2.3.6.1/include/uapi/vserver/cvirt_cmd.h
12937 --- linux-3.9.4/include/uapi/vserver/cvirt_cmd.h        1970-01-01 00:00:00.000000000 +0000
12938 +++ linux-3.9.4-vs2.3.6.1/include/uapi/vserver/cvirt_cmd.h      2013-05-31 14:47:11.000000000 +0000
12939 @@ -0,0 +1,41 @@
12940 +#ifndef _UAPI_VS_CVIRT_CMD_H
12941 +#define _UAPI_VS_CVIRT_CMD_H
12942 +
12943 +
12944 +/* virtual host info name commands */
12945 +
12946 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
12947 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
12948 +
12949 +struct vcmd_vhi_name_v0 {
12950 +       uint32_t field;
12951 +       char name[65];
12952 +};
12953 +
12954 +
12955 +enum vhi_name_field {
12956 +       VHIN_CONTEXT = 0,
12957 +       VHIN_SYSNAME,
12958 +       VHIN_NODENAME,
12959 +       VHIN_RELEASE,
12960 +       VHIN_VERSION,
12961 +       VHIN_MACHINE,
12962 +       VHIN_DOMAINNAME,
12963 +};
12964 +
12965 +
12966 +
12967 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
12968 +
12969 +struct vcmd_virt_stat_v0 {
12970 +       uint64_t offset;
12971 +       uint64_t uptime;
12972 +       uint32_t nr_threads;
12973 +       uint32_t nr_running;
12974 +       uint32_t nr_uninterruptible;
12975 +       uint32_t nr_onhold;
12976 +       uint32_t nr_forks;
12977 +       uint32_t load[3];
12978 +};
12979 +
12980 +#endif /* _UAPI_VS_CVIRT_CMD_H */
12981 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/debug_cmd.h linux-3.9.4-vs2.3.6.1/include/uapi/vserver/debug_cmd.h
12982 --- linux-3.9.4/include/uapi/vserver/debug_cmd.h        1970-01-01 00:00:00.000000000 +0000
12983 +++ linux-3.9.4-vs2.3.6.1/include/uapi/vserver/debug_cmd.h      2013-05-31 14:47:11.000000000 +0000
12984 @@ -0,0 +1,24 @@
12985 +#ifndef _UAPI_VS_DEBUG_CMD_H
12986 +#define _UAPI_VS_DEBUG_CMD_H
12987 +
12988 +
12989 +/* debug commands */
12990 +
12991 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
12992 +
12993 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
12994 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
12995 +
12996 +struct  vcmd_read_history_v0 {
12997 +       uint32_t index;
12998 +       uint32_t count;
12999 +       char __user *data;
13000 +};
13001 +
13002 +struct  vcmd_read_monitor_v0 {
13003 +       uint32_t index;
13004 +       uint32_t count;
13005 +       char __user *data;
13006 +};
13007 +
13008 +#endif /* _UAPI_VS_DEBUG_CMD_H */
13009 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/device.h linux-3.9.4-vs2.3.6.1/include/uapi/vserver/device.h
13010 --- linux-3.9.4/include/uapi/vserver/device.h   1970-01-01 00:00:00.000000000 +0000
13011 +++ linux-3.9.4-vs2.3.6.1/include/uapi/vserver/device.h 2013-05-31 14:47:11.000000000 +0000
13012 @@ -0,0 +1,12 @@
13013 +#ifndef _UAPI_VS_DEVICE_H
13014 +#define _UAPI_VS_DEVICE_H
13015 +
13016 +
13017 +#define DATTR_CREATE   0x00000001
13018 +#define DATTR_OPEN     0x00000002
13019 +
13020 +#define DATTR_REMAP    0x00000010
13021 +
13022 +#define DATTR_MASK     0x00000013
13023 +
13024 +#endif /* _UAPI_VS_DEVICE_H */
13025 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/device_cmd.h linux-3.9.4-vs2.3.6.1/include/uapi/vserver/device_cmd.h
13026 --- linux-3.9.4/include/uapi/vserver/device_cmd.h       1970-01-01 00:00:00.000000000 +0000
13027 +++ linux-3.9.4-vs2.3.6.1/include/uapi/vserver/device_cmd.h     2013-05-31 14:47:11.000000000 +0000
13028 @@ -0,0 +1,16 @@
13029 +#ifndef _UAPI_VS_DEVICE_CMD_H
13030 +#define _UAPI_VS_DEVICE_CMD_H
13031 +
13032 +
13033 +/*  device vserver commands */
13034 +
13035 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
13036 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
13037 +
13038 +struct vcmd_set_mapping_v0 {
13039 +       const char __user *device;
13040 +       const char __user *target;
13041 +       uint32_t flags;
13042 +};
13043 +
13044 +#endif /* _UAPI_VS_DEVICE_CMD_H */
13045 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/dlimit_cmd.h linux-3.9.4-vs2.3.6.1/include/uapi/vserver/dlimit_cmd.h
13046 --- linux-3.9.4/include/uapi/vserver/dlimit_cmd.h       1970-01-01 00:00:00.000000000 +0000
13047 +++ linux-3.9.4-vs2.3.6.1/include/uapi/vserver/dlimit_cmd.h     2013-05-31 14:47:11.000000000 +0000
13048 @@ -0,0 +1,67 @@
13049 +#ifndef _UAPI_VS_DLIMIT_CMD_H
13050 +#define _UAPI_VS_DLIMIT_CMD_H
13051 +
13052 +
13053 +/*  dlimit vserver commands */
13054 +
13055 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
13056 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
13057 +
13058 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
13059 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
13060 +
13061 +struct vcmd_ctx_dlimit_base_v0 {
13062 +       const char __user *name;
13063 +       uint32_t flags;
13064 +};
13065 +
13066 +struct vcmd_ctx_dlimit_v0 {
13067 +       const char __user *name;
13068 +       uint32_t space_used;                    /* used space in kbytes */
13069 +       uint32_t space_total;                   /* maximum space in kbytes */
13070 +       uint32_t inodes_used;                   /* used inodes */
13071 +       uint32_t inodes_total;                  /* maximum inodes */
13072 +       uint32_t reserved;                      /* reserved for root in % */
13073 +       uint32_t flags;
13074 +};
13075 +
13076 +#define CDLIM_UNSET            ((uint32_t)0UL)
13077 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
13078 +#define CDLIM_KEEP             ((uint32_t)~1UL)
13079 +
13080 +#define DLIME_UNIT     0
13081 +#define DLIME_KILO     1
13082 +#define DLIME_MEGA     2
13083 +#define DLIME_GIGA     3
13084 +
13085 +#define DLIMF_SHIFT    0x10
13086 +
13087 +#define DLIMS_USED     0
13088 +#define DLIMS_TOTAL    2
13089 +
13090 +static inline
13091 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
13092 +{
13093 +       int exp = (flags & DLIMF_SHIFT) ?
13094 +               (flags >> shift) & DLIME_GIGA : DLIME_KILO;
13095 +       return ((uint64_t)val) << (10 * exp);
13096 +}
13097 +
13098 +static inline
13099 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
13100 +{
13101 +       int exp = 0;
13102 +
13103 +       if (*flags & DLIMF_SHIFT) {
13104 +               while (val > (1LL << 32) && (exp < 3)) {
13105 +                       val >>= 10;
13106 +                       exp++;
13107 +               }
13108 +               *flags &= ~(DLIME_GIGA << shift);
13109 +               *flags |= exp << shift;
13110 +       } else
13111 +               val >>= 10;
13112 +       return val;
13113 +}
13114 +
13115 +#endif /* _UAPI_VS_DLIMIT_CMD_H */
13116 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/inode.h linux-3.9.4-vs2.3.6.1/include/uapi/vserver/inode.h
13117 --- linux-3.9.4/include/uapi/vserver/inode.h    1970-01-01 00:00:00.000000000 +0000
13118 +++ linux-3.9.4-vs2.3.6.1/include/uapi/vserver/inode.h  2013-05-31 14:47:11.000000000 +0000
13119 @@ -0,0 +1,23 @@
13120 +#ifndef _UAPI_VS_INODE_H
13121 +#define _UAPI_VS_INODE_H
13122 +
13123 +
13124 +#define IATTR_TAG      0x01000000
13125 +
13126 +#define IATTR_ADMIN    0x00000001
13127 +#define IATTR_WATCH    0x00000002
13128 +#define IATTR_HIDE     0x00000004
13129 +#define IATTR_FLAGS    0x00000007
13130 +
13131 +#define IATTR_BARRIER  0x00010000
13132 +#define IATTR_IXUNLINK 0x00020000
13133 +#define IATTR_IMMUTABLE 0x00040000
13134 +#define IATTR_COW      0x00080000
13135 +
13136 +
13137 +/* inode ioctls */
13138 +
13139 +#define FIOC_GETXFLG   _IOR('x', 5, long)
13140 +#define FIOC_SETXFLG   _IOW('x', 6, long)
13141 +
13142 +#endif /* _UAPI_VS_INODE_H */
13143 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/inode_cmd.h linux-3.9.4-vs2.3.6.1/include/uapi/vserver/inode_cmd.h
13144 --- linux-3.9.4/include/uapi/vserver/inode_cmd.h        1970-01-01 00:00:00.000000000 +0000
13145 +++ linux-3.9.4-vs2.3.6.1/include/uapi/vserver/inode_cmd.h      2013-05-31 14:47:11.000000000 +0000
13146 @@ -0,0 +1,26 @@
13147 +#ifndef _UAPI_VS_INODE_CMD_H
13148 +#define _UAPI_VS_INODE_CMD_H
13149 +
13150 +
13151 +/*  inode vserver commands */
13152 +
13153 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
13154 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
13155 +
13156 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
13157 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
13158 +
13159 +struct vcmd_ctx_iattr_v1 {
13160 +       const char __user *name;
13161 +       uint32_t tag;
13162 +       uint32_t flags;
13163 +       uint32_t mask;
13164 +};
13165 +
13166 +struct vcmd_ctx_fiattr_v0 {
13167 +       uint32_t tag;
13168 +       uint32_t flags;
13169 +       uint32_t mask;
13170 +};
13171 +
13172 +#endif /* _UAPI_VS_INODE_CMD_H */
13173 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/limit.h linux-3.9.4-vs2.3.6.1/include/uapi/vserver/limit.h
13174 --- linux-3.9.4/include/uapi/vserver/limit.h    1970-01-01 00:00:00.000000000 +0000
13175 +++ linux-3.9.4-vs2.3.6.1/include/uapi/vserver/limit.h  2013-05-31 14:47:11.000000000 +0000
13176 @@ -0,0 +1,14 @@
13177 +#ifndef _UAPI_VS_LIMIT_H
13178 +#define _UAPI_VS_LIMIT_H
13179 +
13180 +
13181 +#define VLIMIT_NSOCK   16
13182 +#define VLIMIT_OPENFD  17
13183 +#define VLIMIT_ANON    18
13184 +#define VLIMIT_SHMEM   19
13185 +#define VLIMIT_SEMARY  20
13186 +#define VLIMIT_NSEMS   21
13187 +#define VLIMIT_DENTRY  22
13188 +#define VLIMIT_MAPPED  23
13189 +
13190 +#endif /* _UAPI_VS_LIMIT_H */
13191 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/limit_cmd.h linux-3.9.4-vs2.3.6.1/include/uapi/vserver/limit_cmd.h
13192 --- linux-3.9.4/include/uapi/vserver/limit_cmd.h        1970-01-01 00:00:00.000000000 +0000
13193 +++ linux-3.9.4-vs2.3.6.1/include/uapi/vserver/limit_cmd.h      2013-05-31 14:47:11.000000000 +0000
13194 @@ -0,0 +1,40 @@
13195 +#ifndef _UAPI_VS_LIMIT_CMD_H
13196 +#define _UAPI_VS_LIMIT_CMD_H
13197 +
13198 +
13199 +/*  rlimit vserver commands */
13200 +
13201 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
13202 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
13203 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
13204 +#define VCMD_reset_hits                VC_CMD(RLIMIT, 7, 0)
13205 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
13206 +
13207 +struct vcmd_ctx_rlimit_v0 {
13208 +       uint32_t id;
13209 +       uint64_t minimum;
13210 +       uint64_t softlimit;
13211 +       uint64_t maximum;
13212 +};
13213 +
13214 +struct vcmd_ctx_rlimit_mask_v0 {
13215 +       uint32_t minimum;
13216 +       uint32_t softlimit;
13217 +       uint32_t maximum;
13218 +};
13219 +
13220 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
13221 +
13222 +struct vcmd_rlimit_stat_v0 {
13223 +       uint32_t id;
13224 +       uint32_t hits;
13225 +       uint64_t value;
13226 +       uint64_t minimum;
13227 +       uint64_t maximum;
13228 +};
13229 +
13230 +#define CRLIM_UNSET            (0ULL)
13231 +#define CRLIM_INFINITY         (~0ULL)
13232 +#define CRLIM_KEEP             (~1ULL)
13233 +
13234 +#endif /* _UAPI_VS_LIMIT_CMD_H */
13235 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/monitor.h linux-3.9.4-vs2.3.6.1/include/uapi/vserver/monitor.h
13236 --- linux-3.9.4/include/uapi/vserver/monitor.h  1970-01-01 00:00:00.000000000 +0000
13237 +++ linux-3.9.4-vs2.3.6.1/include/uapi/vserver/monitor.h        2013-05-31 14:47:11.000000000 +0000
13238 @@ -0,0 +1,96 @@
13239 +#ifndef _UAPI_VS_MONITOR_H
13240 +#define _UAPI_VS_MONITOR_H
13241 +
13242 +#include <linux/types.h>
13243 +
13244 +
13245 +enum {
13246 +       VXM_UNUSED = 0,
13247 +
13248 +       VXM_SYNC = 0x10,
13249 +
13250 +       VXM_UPDATE = 0x20,
13251 +       VXM_UPDATE_1,
13252 +       VXM_UPDATE_2,
13253 +
13254 +       VXM_RQINFO_1 = 0x24,
13255 +       VXM_RQINFO_2,
13256 +
13257 +       VXM_ACTIVATE = 0x40,
13258 +       VXM_DEACTIVATE,
13259 +       VXM_IDLE,
13260 +
13261 +       VXM_HOLD = 0x44,
13262 +       VXM_UNHOLD,
13263 +
13264 +       VXM_MIGRATE = 0x48,
13265 +       VXM_RESCHED,
13266 +
13267 +       /* all other bits are flags */
13268 +       VXM_SCHED = 0x80,
13269 +};
13270 +
13271 +struct _vxm_update_1 {
13272 +       uint32_t tokens_max;
13273 +       uint32_t fill_rate;
13274 +       uint32_t interval;
13275 +};
13276 +
13277 +struct _vxm_update_2 {
13278 +       uint32_t tokens_min;
13279 +       uint32_t fill_rate;
13280 +       uint32_t interval;
13281 +};
13282 +
13283 +struct _vxm_rqinfo_1 {
13284 +       uint16_t running;
13285 +       uint16_t onhold;
13286 +       uint16_t iowait;
13287 +       uint16_t uintr;
13288 +       uint32_t idle_tokens;
13289 +};
13290 +
13291 +struct _vxm_rqinfo_2 {
13292 +       uint32_t norm_time;
13293 +       uint32_t idle_time;
13294 +       uint32_t idle_skip;
13295 +};
13296 +
13297 +struct _vxm_sched {
13298 +       uint32_t tokens;
13299 +       uint32_t norm_time;
13300 +       uint32_t idle_time;
13301 +};
13302 +
13303 +struct _vxm_task {
13304 +       uint16_t pid;
13305 +       uint16_t state;
13306 +};
13307 +
13308 +struct _vxm_event {
13309 +       uint32_t jif;
13310 +       union {
13311 +               uint32_t seq;
13312 +               uint32_t sec;
13313 +       };
13314 +       union {
13315 +               uint32_t tokens;
13316 +               uint32_t nsec;
13317 +               struct _vxm_task tsk;
13318 +       };
13319 +};
13320 +
13321 +struct _vx_mon_entry {
13322 +       uint16_t type;
13323 +       uint16_t xid;
13324 +       union {
13325 +               struct _vxm_event ev;
13326 +               struct _vxm_sched sd;
13327 +               struct _vxm_update_1 u1;
13328 +               struct _vxm_update_2 u2;
13329 +               struct _vxm_rqinfo_1 q1;
13330 +               struct _vxm_rqinfo_2 q2;
13331 +       };
13332 +};
13333 +
13334 +#endif /* _UAPI_VS_MONITOR_H */
13335 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/network.h linux-3.9.4-vs2.3.6.1/include/uapi/vserver/network.h
13336 --- linux-3.9.4/include/uapi/vserver/network.h  1970-01-01 00:00:00.000000000 +0000
13337 +++ linux-3.9.4-vs2.3.6.1/include/uapi/vserver/network.h        2013-05-31 14:47:11.000000000 +0000
13338 @@ -0,0 +1,76 @@
13339 +#ifndef _UAPI_VS_NETWORK_H
13340 +#define _UAPI_VS_NETWORK_H
13341 +
13342 +#include <linux/types.h>
13343 +
13344 +
13345 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
13346 +
13347 +
13348 +/* network flags */
13349 +
13350 +#define NXF_INFO_PRIVATE       0x00000008
13351 +
13352 +#define NXF_SINGLE_IP          0x00000100
13353 +#define NXF_LBACK_REMAP                0x00000200
13354 +#define NXF_LBACK_ALLOW                0x00000400
13355 +
13356 +#define NXF_HIDE_NETIF         0x02000000
13357 +#define NXF_HIDE_LBACK         0x04000000
13358 +
13359 +#define NXF_STATE_SETUP                (1ULL << 32)
13360 +#define NXF_STATE_ADMIN                (1ULL << 34)
13361 +
13362 +#define NXF_SC_HELPER          (1ULL << 36)
13363 +#define NXF_PERSISTENT         (1ULL << 38)
13364 +
13365 +#define NXF_ONE_TIME           (0x0005ULL << 32)
13366 +
13367 +
13368 +#define        NXF_INIT_SET            (__nxf_init_set())
13369 +
13370 +static inline uint64_t __nxf_init_set(void) {
13371 +       return    NXF_STATE_ADMIN
13372 +#ifdef CONFIG_VSERVER_AUTO_LBACK
13373 +               | NXF_LBACK_REMAP
13374 +               | NXF_HIDE_LBACK
13375 +#endif
13376 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
13377 +               | NXF_SINGLE_IP
13378 +#endif
13379 +               | NXF_HIDE_NETIF;
13380 +}
13381 +
13382 +
13383 +/* network caps */
13384 +
13385 +#define NXC_TUN_CREATE         0x00000001
13386 +
13387 +#define NXC_RAW_ICMP           0x00000100
13388 +
13389 +#define NXC_MULTICAST          0x00001000
13390 +
13391 +
13392 +/* address types */
13393 +
13394 +#define NXA_TYPE_IPV4          0x0001
13395 +#define NXA_TYPE_IPV6          0x0002
13396 +
13397 +#define NXA_TYPE_NONE          0x0000
13398 +#define NXA_TYPE_ANY           0x00FF
13399 +
13400 +#define NXA_TYPE_ADDR          0x0010
13401 +#define NXA_TYPE_MASK          0x0020
13402 +#define NXA_TYPE_RANGE         0x0040
13403 +
13404 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
13405 +
13406 +#define NXA_MOD_BCAST          0x0100
13407 +#define NXA_MOD_LBACK          0x0200
13408 +
13409 +#define NXA_LOOPBACK           0x1000
13410 +
13411 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
13412 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
13413 +
13414 +#endif /* _UAPI_VS_NETWORK_H */
13415 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/network_cmd.h linux-3.9.4-vs2.3.6.1/include/uapi/vserver/network_cmd.h
13416 --- linux-3.9.4/include/uapi/vserver/network_cmd.h      1970-01-01 00:00:00.000000000 +0000
13417 +++ linux-3.9.4-vs2.3.6.1/include/uapi/vserver/network_cmd.h    2013-05-31 14:47:11.000000000 +0000
13418 @@ -0,0 +1,123 @@
13419 +#ifndef _UAPI_VS_NETWORK_CMD_H
13420 +#define _UAPI_VS_NETWORK_CMD_H
13421 +
13422 +
13423 +/* vinfo commands */
13424 +
13425 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
13426 +
13427 +
13428 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
13429 +
13430 +struct vcmd_nx_info_v0 {
13431 +       uint32_t nid;
13432 +       /* more to come */
13433 +};
13434 +
13435 +
13436 +#include <linux/in.h>
13437 +#include <linux/in6.h>
13438 +
13439 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
13440 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
13441 +
13442 +struct  vcmd_net_create {
13443 +       uint64_t flagword;
13444 +};
13445 +
13446 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
13447 +
13448 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
13449 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
13450 +
13451 +struct vcmd_net_addr_v0 {
13452 +       uint16_t type;
13453 +       uint16_t count;
13454 +       struct in_addr ip[4];
13455 +       struct in_addr mask[4];
13456 +};
13457 +
13458 +#define VCMD_net_add_ipv4_v1   VC_CMD(NETALT, 1, 1)
13459 +#define VCMD_net_rem_ipv4_v1   VC_CMD(NETALT, 2, 1)
13460 +
13461 +struct vcmd_net_addr_ipv4_v1 {
13462 +       uint16_t type;
13463 +       uint16_t flags;
13464 +       struct in_addr ip;
13465 +       struct in_addr mask;
13466 +};
13467 +
13468 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 2)
13469 +#define VCMD_net_rem_ipv4      VC_CMD(NETALT, 2, 2)
13470 +
13471 +struct vcmd_net_addr_ipv4_v2 {
13472 +       uint16_t type;
13473 +       uint16_t flags;
13474 +       struct in_addr ip;
13475 +       struct in_addr ip2;
13476 +       struct in_addr mask;
13477 +};
13478 +
13479 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
13480 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
13481 +
13482 +struct vcmd_net_addr_ipv6_v1 {
13483 +       uint16_t type;
13484 +       uint16_t flags;
13485 +       uint32_t prefix;
13486 +       struct in6_addr ip;
13487 +       struct in6_addr mask;
13488 +};
13489 +
13490 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
13491 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
13492 +
13493 +struct vcmd_match_ipv4_v0 {
13494 +       uint16_t type;
13495 +       uint16_t flags;
13496 +       uint16_t parent;
13497 +       uint16_t prefix;
13498 +       struct in_addr ip;
13499 +       struct in_addr ip2;
13500 +       struct in_addr mask;
13501 +};
13502 +
13503 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
13504 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
13505 +
13506 +struct vcmd_match_ipv6_v0 {
13507 +       uint16_t type;
13508 +       uint16_t flags;
13509 +       uint16_t parent;
13510 +       uint16_t prefix;
13511 +       struct in6_addr ip;
13512 +       struct in6_addr ip2;
13513 +       struct in6_addr mask;
13514 +};
13515 +
13516 +
13517 +
13518 +
13519 +/* flag commands */
13520 +
13521 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
13522 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
13523 +
13524 +struct vcmd_net_flags_v0 {
13525 +       uint64_t flagword;
13526 +       uint64_t mask;
13527 +};
13528 +
13529 +
13530 +
13531 +/* network caps commands */
13532 +
13533 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
13534 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
13535 +
13536 +struct vcmd_net_caps_v0 {
13537 +       uint64_t ncaps;
13538 +       uint64_t cmask;
13539 +};
13540 +
13541 +#endif /* _UAPI_VS_NETWORK_CMD_H */
13542 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/sched_cmd.h linux-3.9.4-vs2.3.6.1/include/uapi/vserver/sched_cmd.h
13543 --- linux-3.9.4/include/uapi/vserver/sched_cmd.h        1970-01-01 00:00:00.000000000 +0000
13544 +++ linux-3.9.4-vs2.3.6.1/include/uapi/vserver/sched_cmd.h      2013-05-31 14:47:11.000000000 +0000
13545 @@ -0,0 +1,13 @@
13546 +#ifndef _UAPI_VS_SCHED_CMD_H
13547 +#define _UAPI_VS_SCHED_CMD_H
13548 +
13549 +
13550 +struct vcmd_prio_bias {
13551 +       int32_t cpu_id;
13552 +       int32_t prio_bias;
13553 +};
13554 +
13555 +#define VCMD_set_prio_bias     VC_CMD(SCHED, 4, 0)
13556 +#define VCMD_get_prio_bias     VC_CMD(SCHED, 5, 0)
13557 +
13558 +#endif /* _UAPI_VS_SCHED_CMD_H */
13559 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/signal_cmd.h linux-3.9.4-vs2.3.6.1/include/uapi/vserver/signal_cmd.h
13560 --- linux-3.9.4/include/uapi/vserver/signal_cmd.h       1970-01-01 00:00:00.000000000 +0000
13561 +++ linux-3.9.4-vs2.3.6.1/include/uapi/vserver/signal_cmd.h     2013-05-31 14:47:11.000000000 +0000
13562 @@ -0,0 +1,31 @@
13563 +#ifndef _UAPI_VS_SIGNAL_CMD_H
13564 +#define _UAPI_VS_SIGNAL_CMD_H
13565 +
13566 +
13567 +/*  signalling vserver commands */
13568 +
13569 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
13570 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
13571 +
13572 +struct vcmd_ctx_kill_v0 {
13573 +       int32_t pid;
13574 +       int32_t sig;
13575 +};
13576 +
13577 +struct vcmd_wait_exit_v0 {
13578 +       int32_t reboot_cmd;
13579 +       int32_t exit_code;
13580 +};
13581 +
13582 +
13583 +/*  process alteration commands */
13584 +
13585 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
13586 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
13587 +
13588 +struct vcmd_pflags_v0 {
13589 +       uint32_t flagword;
13590 +       uint32_t mask;
13591 +};
13592 +
13593 +#endif /* _UAPI_VS_SIGNAL_CMD_H */
13594 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/space_cmd.h linux-3.9.4-vs2.3.6.1/include/uapi/vserver/space_cmd.h
13595 --- linux-3.9.4/include/uapi/vserver/space_cmd.h        1970-01-01 00:00:00.000000000 +0000
13596 +++ linux-3.9.4-vs2.3.6.1/include/uapi/vserver/space_cmd.h      2013-05-31 14:47:11.000000000 +0000
13597 @@ -0,0 +1,28 @@
13598 +#ifndef _UAPI_VS_SPACE_CMD_H
13599 +#define _UAPI_VS_SPACE_CMD_H
13600 +
13601 +
13602 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
13603 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
13604 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
13605 +
13606 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
13607 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
13608 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
13609 +
13610 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
13611 +
13612 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
13613 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
13614 +
13615 +
13616 +struct vcmd_space_mask_v1 {
13617 +       uint64_t mask;
13618 +};
13619 +
13620 +struct vcmd_space_mask_v2 {
13621 +       uint64_t mask;
13622 +       uint32_t index;
13623 +};
13624 +
13625 +#endif /* _UAPI_VS_SPACE_CMD_H */
13626 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/switch.h linux-3.9.4-vs2.3.6.1/include/uapi/vserver/switch.h
13627 --- linux-3.9.4/include/uapi/vserver/switch.h   1970-01-01 00:00:00.000000000 +0000
13628 +++ linux-3.9.4-vs2.3.6.1/include/uapi/vserver/switch.h 2013-05-31 14:47:11.000000000 +0000
13629 @@ -0,0 +1,90 @@
13630 +#ifndef _UAPI_VS_SWITCH_H
13631 +#define _UAPI_VS_SWITCH_H
13632 +
13633 +#include <linux/types.h>
13634 +
13635 +
13636 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
13637 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
13638 +#define VC_VERSION(c)          ((c) & 0xFFF)
13639 +
13640 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
13641 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
13642 +
13643 +/*
13644 +
13645 +  Syscall Matrix V2.8
13646 +
13647 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
13648 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
13649 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
13650 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13651 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
13652 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
13653 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13654 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
13655 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
13656 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13657 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
13658 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
13659 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13660 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
13661 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
13662 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13663 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
13664 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
13665 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13666 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
13667 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
13668 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
13669 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
13670 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
13671 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13672 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
13673 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
13674 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13675 +
13676 +*/
13677 +
13678 +#define VC_CAT_VERSION         0
13679 +
13680 +#define VC_CAT_VSETUP          1
13681 +#define VC_CAT_VHOST           2
13682 +
13683 +#define VC_CAT_DEVICE          6
13684 +
13685 +#define VC_CAT_VPROC           9
13686 +#define VC_CAT_PROCALT         10
13687 +#define VC_CAT_PROCMIG         11
13688 +#define VC_CAT_PROCTRL         12
13689 +
13690 +#define VC_CAT_SCHED           14
13691 +#define VC_CAT_MEMCTRL         20
13692 +
13693 +#define VC_CAT_VNET            25
13694 +#define VC_CAT_NETALT          26
13695 +#define VC_CAT_NETMIG          27
13696 +#define VC_CAT_NETCTRL         28
13697 +
13698 +#define VC_CAT_TAGMIG          35
13699 +#define VC_CAT_DLIMIT          36
13700 +#define VC_CAT_INODE           38
13701 +
13702 +#define VC_CAT_VSTAT           40
13703 +#define VC_CAT_VINFO           46
13704 +#define VC_CAT_EVENT           48
13705 +
13706 +#define VC_CAT_FLAGS           52
13707 +#define VC_CAT_VSPACE          54
13708 +#define VC_CAT_DEBUG           56
13709 +#define VC_CAT_RLIMIT          60
13710 +
13711 +#define VC_CAT_SYSTEST         61
13712 +#define VC_CAT_COMPAT          63
13713 +
13714 +/*  query version */
13715 +
13716 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
13717 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
13718 +
13719 +#endif /* _UAPI_VS_SWITCH_H */
13720 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/tag_cmd.h linux-3.9.4-vs2.3.6.1/include/uapi/vserver/tag_cmd.h
13721 --- linux-3.9.4/include/uapi/vserver/tag_cmd.h  1970-01-01 00:00:00.000000000 +0000
13722 +++ linux-3.9.4-vs2.3.6.1/include/uapi/vserver/tag_cmd.h        2013-05-31 14:47:11.000000000 +0000
13723 @@ -0,0 +1,14 @@
13724 +#ifndef _UAPI_VS_TAG_CMD_H
13725 +#define _UAPI_VS_TAG_CMD_H
13726 +
13727 +
13728 +/* vinfo commands */
13729 +
13730 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
13731 +
13732 +
13733 +/* context commands */
13734 +
13735 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
13736 +
13737 +#endif /* _UAPI_VS_TAG_CMD_H */
13738 diff -NurpP --minimal linux-3.9.4/init/Kconfig linux-3.9.4-vs2.3.6.1/init/Kconfig
13739 --- linux-3.9.4/init/Kconfig    2013-05-31 13:45:29.000000000 +0000
13740 +++ linux-3.9.4-vs2.3.6.1/init/Kconfig  2013-05-31 14:47:11.000000000 +0000
13741 @@ -760,6 +760,7 @@ config NUMA_BALANCING
13742  menuconfig CGROUPS
13743         boolean "Control Group support"
13744         depends on EVENTFD
13745 +       default y
13746         help
13747           This option adds support for grouping sets of processes together, for
13748           use with process control subsystems such as Cpusets, CFS, memory
13749 @@ -1022,6 +1023,7 @@ config IPC_NS
13750  config USER_NS
13751         bool "User namespace"
13752         depends on UIDGID_CONVERTED
13753 +       depends on VSERVER_DISABLED
13754         select UIDGID_STRICT_TYPE_CHECKS
13755  
13756         default n
13757 diff -NurpP --minimal linux-3.9.4/init/main.c linux-3.9.4-vs2.3.6.1/init/main.c
13758 --- linux-3.9.4/init/main.c     2013-05-31 13:45:29.000000000 +0000
13759 +++ linux-3.9.4-vs2.3.6.1/init/main.c   2013-05-31 15:09:17.000000000 +0000
13760 @@ -72,6 +72,7 @@
13761  #include <linux/ptrace.h>
13762  #include <linux/blkdev.h>
13763  #include <linux/elevator.h>
13764 +#include <linux/vserver/percpu.h>
13765  
13766  #include <asm/io.h>
13767  #include <asm/bugs.h>
13768 diff -NurpP --minimal linux-3.9.4/ipc/mqueue.c linux-3.9.4-vs2.3.6.1/ipc/mqueue.c
13769 --- linux-3.9.4/ipc/mqueue.c    2013-05-31 13:45:29.000000000 +0000
13770 +++ linux-3.9.4-vs2.3.6.1/ipc/mqueue.c  2013-05-31 14:47:11.000000000 +0000
13771 @@ -35,6 +35,8 @@
13772  #include <linux/ipc_namespace.h>
13773  #include <linux/user_namespace.h>
13774  #include <linux/slab.h>
13775 +#include <linux/vs_context.h>
13776 +#include <linux/vs_limit.h>
13777  
13778  #include <net/sock.h>
13779  #include "util.h"
13780 @@ -76,6 +78,7 @@ struct mqueue_inode_info {
13781         struct pid* notify_owner;
13782         struct user_namespace *notify_user_ns;
13783         struct user_struct *user;       /* user who created, for accounting */
13784 +       struct vx_info *vxi;
13785         struct sock *notify_sock;
13786         struct sk_buff *notify_cookie;
13787  
13788 @@ -234,6 +237,7 @@ static struct inode *mqueue_get_inode(st
13789         if (S_ISREG(mode)) {
13790                 struct mqueue_inode_info *info;
13791                 unsigned long mq_bytes, mq_treesize;
13792 +               struct vx_info *vxi = current_vx_info();
13793  
13794                 inode->i_fop = &mqueue_file_operations;
13795                 inode->i_size = FILENT_SIZE;
13796 @@ -247,6 +251,7 @@ static struct inode *mqueue_get_inode(st
13797                 info->notify_user_ns = NULL;
13798                 info->qsize = 0;
13799                 info->user = NULL;      /* set when all is ok */
13800 +               info->vxi = NULL;
13801                 info->msg_tree = RB_ROOT;
13802                 info->node_cache = NULL;
13803                 memset(&info->attr, 0, sizeof(info->attr));
13804 @@ -280,17 +285,20 @@ static struct inode *mqueue_get_inode(st
13805  
13806                 spin_lock(&mq_lock);
13807                 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
13808 -                   u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
13809 +                   u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE) ||
13810 +                   !vx_ipcmsg_avail(vxi, mq_bytes)) {
13811                         spin_unlock(&mq_lock);
13812                         /* mqueue_evict_inode() releases info->messages */
13813                         ret = -EMFILE;
13814                         goto out_inode;
13815                 }
13816                 u->mq_bytes += mq_bytes;
13817 +               vx_ipcmsg_add(vxi, u, mq_bytes);
13818                 spin_unlock(&mq_lock);
13819  
13820                 /* all is ok */
13821                 info->user = get_uid(u);
13822 +               info->vxi = get_vx_info(vxi);
13823         } else if (S_ISDIR(mode)) {
13824                 inc_nlink(inode);
13825                 /* Some things misbehave if size == 0 on a directory */
13826 @@ -402,8 +410,11 @@ static void mqueue_evict_inode(struct in
13827  
13828         user = info->user;
13829         if (user) {
13830 +               struct vx_info *vxi = info->vxi;
13831 +
13832                 spin_lock(&mq_lock);
13833                 user->mq_bytes -= mq_bytes;
13834 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
13835                 /*
13836                  * get_ns_from_inode() ensures that the
13837                  * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
13838 @@ -413,6 +424,7 @@ static void mqueue_evict_inode(struct in
13839                 if (ipc_ns)
13840                         ipc_ns->mq_queues_count--;
13841                 spin_unlock(&mq_lock);
13842 +               put_vx_info(vxi);
13843                 free_uid(user);
13844         }
13845         if (ipc_ns)
13846 diff -NurpP --minimal linux-3.9.4/ipc/msg.c linux-3.9.4-vs2.3.6.1/ipc/msg.c
13847 --- linux-3.9.4/ipc/msg.c       2013-05-31 13:45:29.000000000 +0000
13848 +++ linux-3.9.4-vs2.3.6.1/ipc/msg.c     2013-05-31 14:47:11.000000000 +0000
13849 @@ -37,6 +37,7 @@
13850  #include <linux/rwsem.h>
13851  #include <linux/nsproxy.h>
13852  #include <linux/ipc_namespace.h>
13853 +#include <linux/vs_base.h>
13854  
13855  #include <asm/current.h>
13856  #include <asm/uaccess.h>
13857 @@ -190,6 +191,7 @@ static int newque(struct ipc_namespace *
13858  
13859         msq->q_perm.mode = msgflg & S_IRWXUGO;
13860         msq->q_perm.key = key;
13861 +       msq->q_perm.xid = vx_current_xid();
13862  
13863         msq->q_perm.security = NULL;
13864         retval = security_msg_queue_alloc(msq);
13865 diff -NurpP --minimal linux-3.9.4/ipc/sem.c linux-3.9.4-vs2.3.6.1/ipc/sem.c
13866 --- linux-3.9.4/ipc/sem.c       2012-12-11 03:30:57.000000000 +0000
13867 +++ linux-3.9.4-vs2.3.6.1/ipc/sem.c     2013-05-31 14:47:11.000000000 +0000
13868 @@ -86,6 +86,8 @@
13869  #include <linux/rwsem.h>
13870  #include <linux/nsproxy.h>
13871  #include <linux/ipc_namespace.h>
13872 +#include <linux/vs_base.h>
13873 +#include <linux/vs_limit.h>
13874  
13875  #include <asm/uaccess.h>
13876  #include "util.h"
13877 @@ -306,6 +308,7 @@ static int newary(struct ipc_namespace *
13878  
13879         sma->sem_perm.mode = (semflg & S_IRWXUGO);
13880         sma->sem_perm.key = key;
13881 +       sma->sem_perm.xid = vx_current_xid();
13882  
13883         sma->sem_perm.security = NULL;
13884         retval = security_sem_alloc(sma);
13885 @@ -321,6 +324,9 @@ static int newary(struct ipc_namespace *
13886                 return id;
13887         }
13888         ns->used_sems += nsems;
13889 +       /* FIXME: obsoleted? */
13890 +       vx_semary_inc(sma);
13891 +       vx_nsems_add(sma, nsems);
13892  
13893         sma->sem_base = (struct sem *) &sma[1];
13894  
13895 @@ -770,6 +776,9 @@ static void freeary(struct ipc_namespace
13896  
13897         wake_up_sem_queue_do(&tasks);
13898         ns->used_sems -= sma->sem_nsems;
13899 +       /* FIXME: obsoleted? */
13900 +       vx_nsems_sub(sma, sma->sem_nsems);
13901 +       vx_semary_dec(sma);
13902         security_sem_free(sma);
13903         ipc_rcu_putref(sma);
13904  }
13905 diff -NurpP --minimal linux-3.9.4/ipc/shm.c linux-3.9.4-vs2.3.6.1/ipc/shm.c
13906 --- linux-3.9.4/ipc/shm.c       2013-05-31 14:22:27.000000000 +0000
13907 +++ linux-3.9.4-vs2.3.6.1/ipc/shm.c     2013-05-31 14:47:11.000000000 +0000
13908 @@ -39,6 +39,8 @@
13909  #include <linux/nsproxy.h>
13910  #include <linux/mount.h>
13911  #include <linux/ipc_namespace.h>
13912 +#include <linux/vs_context.h>
13913 +#include <linux/vs_limit.h>
13914  
13915  #include <asm/uaccess.h>
13916  
13917 @@ -187,7 +189,12 @@ static void shm_open(struct vm_area_stru
13918   */
13919  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
13920  {
13921 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
13922 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
13923 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
13924 +
13925 +       vx_ipcshm_sub(vxi, shp, numpages);
13926 +       ns->shm_tot -= numpages;
13927 +
13928         shm_rmid(ns, shp);
13929         shm_unlock(shp);
13930         if (!is_file_hugepages(shp->shm_file))
13931 @@ -197,6 +204,7 @@ static void shm_destroy(struct ipc_names
13932                                                 shp->mlock_user);
13933         fput (shp->shm_file);
13934         security_shm_free(shp);
13935 +       put_vx_info(vxi);
13936         ipc_rcu_putref(shp);
13937  }
13938  
13939 @@ -474,11 +482,15 @@ static int newseg(struct ipc_namespace *
13940         if (ns->shm_tot + numpages > ns->shm_ctlall)
13941                 return -ENOSPC;
13942  
13943 +       if (!vx_ipcshm_avail(current_vx_info(), numpages))
13944 +               return -ENOSPC;
13945 +
13946         shp = ipc_rcu_alloc(sizeof(*shp));
13947         if (!shp)
13948                 return -ENOMEM;
13949  
13950         shp->shm_perm.key = key;
13951 +       shp->shm_perm.xid = vx_current_xid();
13952         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
13953         shp->mlock_user = NULL;
13954  
13955 @@ -544,6 +556,7 @@ static int newseg(struct ipc_namespace *
13956         ns->shm_tot += numpages;
13957         error = shp->shm_perm.id;
13958         shm_unlock(shp);
13959 +       vx_ipcshm_add(current_vx_info(), key, numpages);
13960         return error;
13961  
13962  no_id:
13963 diff -NurpP --minimal linux-3.9.4/kernel/Makefile linux-3.9.4-vs2.3.6.1/kernel/Makefile
13964 --- linux-3.9.4/kernel/Makefile 2013-05-31 14:22:27.000000000 +0000
13965 +++ linux-3.9.4-vs2.3.6.1/kernel/Makefile       2013-05-31 14:47:11.000000000 +0000
13966 @@ -24,6 +24,7 @@ endif
13967  
13968  obj-y += sched/
13969  obj-y += power/
13970 +obj-y += vserver/
13971  
13972  obj-$(CONFIG_CHECKPOINT_RESTORE) += kcmp.o
13973  obj-$(CONFIG_FREEZER) += freezer.o
13974 diff -NurpP --minimal linux-3.9.4/kernel/auditsc.c linux-3.9.4-vs2.3.6.1/kernel/auditsc.c
13975 --- linux-3.9.4/kernel/auditsc.c        2013-05-31 14:22:27.000000000 +0000
13976 +++ linux-3.9.4-vs2.3.6.1/kernel/auditsc.c      2013-05-31 14:47:11.000000000 +0000
13977 @@ -2315,7 +2315,7 @@ int audit_set_loginuid(kuid_t loginuid)
13978         if (audit_loginuid_set(task))
13979                 return -EPERM;
13980  #else /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
13981 -       if (!capable(CAP_AUDIT_CONTROL))
13982 +       if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
13983                 return -EPERM;
13984  #endif  /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
13985  
13986 diff -NurpP --minimal linux-3.9.4/kernel/capability.c linux-3.9.4-vs2.3.6.1/kernel/capability.c
13987 --- linux-3.9.4/kernel/capability.c     2013-05-31 13:45:29.000000000 +0000
13988 +++ linux-3.9.4-vs2.3.6.1/kernel/capability.c   2013-05-31 14:47:11.000000000 +0000
13989 @@ -15,6 +15,7 @@
13990  #include <linux/syscalls.h>
13991  #include <linux/pid_namespace.h>
13992  #include <linux/user_namespace.h>
13993 +#include <linux/vs_context.h>
13994  #include <asm/uaccess.h>
13995  
13996  /*
13997 @@ -116,6 +117,7 @@ static int cap_validate_magic(cap_user_h
13998         return 0;
13999  }
14000  
14001 +
14002  /*
14003   * The only thing that can change the capabilities of the current
14004   * process is the current process. As such, we can't be in this code
14005 @@ -349,6 +351,8 @@ bool has_ns_capability_noaudit(struct ta
14006         return (ret == 0);
14007  }
14008  
14009 +#include <linux/vserver/base.h>
14010 +
14011  /**
14012   * has_capability_noaudit - Does a task have a capability (unaudited) in the
14013   * initial user ns
14014 diff -NurpP --minimal linux-3.9.4/kernel/compat.c linux-3.9.4-vs2.3.6.1/kernel/compat.c
14015 --- linux-3.9.4/kernel/compat.c 2013-05-31 13:45:29.000000000 +0000
14016 +++ linux-3.9.4-vs2.3.6.1/kernel/compat.c       2013-05-31 14:47:11.000000000 +0000
14017 @@ -27,6 +27,7 @@
14018  #include <linux/times.h>
14019  #include <linux/ptrace.h>
14020  #include <linux/gfp.h>
14021 +#include <linux/vs_time.h>
14022  
14023  #include <asm/uaccess.h>
14024  
14025 @@ -1059,7 +1060,7 @@ asmlinkage long compat_sys_stime(compat_
14026         if (err)
14027                 return err;
14028  
14029 -       do_settimeofday(&tv);
14030 +       vx_settimeofday(&tv);
14031         return 0;
14032  }
14033  
14034 diff -NurpP --minimal linux-3.9.4/kernel/cred.c linux-3.9.4-vs2.3.6.1/kernel/cred.c
14035 --- linux-3.9.4/kernel/cred.c   2013-02-19 13:58:56.000000000 +0000
14036 +++ linux-3.9.4-vs2.3.6.1/kernel/cred.c 2013-05-31 14:47:11.000000000 +0000
14037 @@ -56,31 +56,6 @@ struct cred init_cred = {
14038         .group_info             = &init_groups,
14039  };
14040  
14041 -static inline void set_cred_subscribers(struct cred *cred, int n)
14042 -{
14043 -#ifdef CONFIG_DEBUG_CREDENTIALS
14044 -       atomic_set(&cred->subscribers, n);
14045 -#endif
14046 -}
14047 -
14048 -static inline int read_cred_subscribers(const struct cred *cred)
14049 -{
14050 -#ifdef CONFIG_DEBUG_CREDENTIALS
14051 -       return atomic_read(&cred->subscribers);
14052 -#else
14053 -       return 0;
14054 -#endif
14055 -}
14056 -
14057 -static inline void alter_cred_subscribers(const struct cred *_cred, int n)
14058 -{
14059 -#ifdef CONFIG_DEBUG_CREDENTIALS
14060 -       struct cred *cred = (struct cred *) _cred;
14061 -
14062 -       atomic_add(n, &cred->subscribers);
14063 -#endif
14064 -}
14065 -
14066  /*
14067   * The RCU callback to actually dispose of a set of credentials
14068   */
14069 @@ -232,21 +207,16 @@ error:
14070   *
14071   * Call commit_creds() or abort_creds() to clean up.
14072   */
14073 -struct cred *prepare_creds(void)
14074 +struct cred *__prepare_creds(const struct cred *old)
14075  {
14076 -       struct task_struct *task = current;
14077 -       const struct cred *old;
14078         struct cred *new;
14079  
14080 -       validate_process_creds();
14081 -
14082         new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
14083         if (!new)
14084                 return NULL;
14085  
14086         kdebug("prepare_creds() alloc %p", new);
14087  
14088 -       old = task->cred;
14089         memcpy(new, old, sizeof(struct cred));
14090  
14091         atomic_set(&new->usage, 1);
14092 @@ -275,6 +245,13 @@ error:
14093         abort_creds(new);
14094         return NULL;
14095  }
14096 +
14097 +struct cred *prepare_creds(void)
14098 +{
14099 +       validate_process_creds();
14100 +
14101 +       return __prepare_creds(current->cred);
14102 +}
14103  EXPORT_SYMBOL(prepare_creds);
14104  
14105  /*
14106 diff -NurpP --minimal linux-3.9.4/kernel/exit.c linux-3.9.4-vs2.3.6.1/kernel/exit.c
14107 --- linux-3.9.4/kernel/exit.c   2013-05-31 13:45:29.000000000 +0000
14108 +++ linux-3.9.4-vs2.3.6.1/kernel/exit.c 2013-05-31 14:47:11.000000000 +0000
14109 @@ -48,6 +48,10 @@
14110  #include <linux/fs_struct.h>
14111  #include <linux/init_task.h>
14112  #include <linux/perf_event.h>
14113 +#include <linux/vs_limit.h>
14114 +#include <linux/vs_context.h>
14115 +#include <linux/vs_network.h>
14116 +#include <linux/vs_pid.h>
14117  #include <trace/events/sched.h>
14118  #include <linux/hw_breakpoint.h>
14119  #include <linux/oom.h>
14120 @@ -514,15 +518,25 @@ static struct task_struct *find_new_reap
14121         __acquires(&tasklist_lock)
14122  {
14123         struct pid_namespace *pid_ns = task_active_pid_ns(father);
14124 -       struct task_struct *thread;
14125 +       struct vx_info *vxi = task_get_vx_info(father);
14126 +       struct task_struct *thread = father;
14127 +       struct task_struct *reaper;
14128  
14129 -       thread = father;
14130         while_each_thread(father, thread) {
14131                 if (thread->flags & PF_EXITING)
14132                         continue;
14133                 if (unlikely(pid_ns->child_reaper == father))
14134                         pid_ns->child_reaper = thread;
14135 -               return thread;
14136 +               reaper = thread;
14137 +               goto out_put;
14138 +       }
14139 +
14140 +       reaper = pid_ns->child_reaper;
14141 +       if (vxi) {
14142 +               BUG_ON(!vxi->vx_reaper);
14143 +               if (vxi->vx_reaper != init_pid_ns.child_reaper &&
14144 +                   vxi->vx_reaper != father)
14145 +                       reaper = vxi->vx_reaper;
14146         }
14147  
14148         if (unlikely(pid_ns->child_reaper == father)) {
14149 @@ -560,7 +574,9 @@ static struct task_struct *find_new_reap
14150                 }
14151         }
14152  
14153 -       return pid_ns->child_reaper;
14154 +out_put:
14155 +       put_vx_info(vxi);
14156 +       return reaper;
14157  }
14158  
14159  /*
14160 @@ -611,10 +627,15 @@ static void forget_original_parent(struc
14161         list_for_each_entry_safe(p, n, &father->children, sibling) {
14162                 struct task_struct *t = p;
14163                 do {
14164 -                       t->real_parent = reaper;
14165 +                       struct task_struct *new_parent = reaper;
14166 +
14167 +                       if (unlikely(p == reaper))
14168 +                               new_parent = task_active_pid_ns(p)->child_reaper;
14169 +
14170 +                       t->real_parent = new_parent;
14171                         if (t->parent == father) {
14172                                 BUG_ON(t->ptrace);
14173 -                               t->parent = t->real_parent;
14174 +                               t->parent = new_parent;
14175                         }
14176                         if (t->pdeath_signal)
14177                                 group_send_sig_info(t->pdeath_signal,
14178 @@ -821,6 +842,9 @@ void do_exit(long code)
14179          */
14180         ptrace_put_breakpoints(tsk);
14181  
14182 +       /* needs to stay before exit_notify() */
14183 +       exit_vx_info_early(tsk, code);
14184 +
14185         exit_notify(tsk, group_dead);
14186  #ifdef CONFIG_NUMA
14187         task_lock(tsk);
14188 @@ -874,10 +898,15 @@ void do_exit(long code)
14189         smp_mb();
14190         raw_spin_unlock_wait(&tsk->pi_lock);
14191  
14192 +       /* needs to stay after exit_notify() */
14193 +       exit_vx_info(tsk, code);
14194 +       exit_nx_info(tsk);
14195 +
14196         /* causes final put_task_struct in finish_task_switch(). */
14197         tsk->state = TASK_DEAD;
14198         tsk->flags |= PF_NOFREEZE;      /* tell freezer to ignore us */
14199         schedule();
14200 +       printk("bad task: %p [%lx]\n", current, current->state);
14201         BUG();
14202         /* Avoid "noreturn function does return".  */
14203         for (;;)
14204 diff -NurpP --minimal linux-3.9.4/kernel/fork.c linux-3.9.4-vs2.3.6.1/kernel/fork.c
14205 --- linux-3.9.4/kernel/fork.c   2013-05-31 13:45:29.000000000 +0000
14206 +++ linux-3.9.4-vs2.3.6.1/kernel/fork.c 2013-05-31 14:47:11.000000000 +0000
14207 @@ -70,6 +70,9 @@
14208  #include <linux/khugepaged.h>
14209  #include <linux/signalfd.h>
14210  #include <linux/uprobes.h>
14211 +#include <linux/vs_context.h>
14212 +#include <linux/vs_network.h>
14213 +#include <linux/vs_limit.h>
14214  
14215  #include <asm/pgtable.h>
14216  #include <asm/pgalloc.h>
14217 @@ -210,6 +213,8 @@ void free_task(struct task_struct *tsk)
14218         arch_release_thread_info(tsk->stack);
14219         free_thread_info(tsk->stack);
14220         rt_mutex_debug_task_free(tsk);
14221 +       clr_vx_info(&tsk->vx_info);
14222 +       clr_nx_info(&tsk->nx_info);
14223         ftrace_graph_exit_task(tsk);
14224         put_seccomp_filter(tsk);
14225         arch_release_task_struct(tsk);
14226 @@ -547,6 +552,7 @@ static struct mm_struct *mm_init(struct
14227         if (likely(!mm_alloc_pgd(mm))) {
14228                 mm->def_flags = 0;
14229                 mmu_notifier_mm_init(mm);
14230 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
14231                 return mm;
14232         }
14233  
14234 @@ -599,6 +605,7 @@ void __mmdrop(struct mm_struct *mm)
14235         destroy_context(mm);
14236         mmu_notifier_mm_destroy(mm);
14237         check_mm(mm);
14238 +       clr_vx_info(&mm->mm_vx_info);
14239         free_mm(mm);
14240  }
14241  EXPORT_SYMBOL_GPL(__mmdrop);
14242 @@ -818,6 +825,7 @@ struct mm_struct *dup_mm(struct task_str
14243                 goto fail_nomem;
14244  
14245         memcpy(mm, oldmm, sizeof(*mm));
14246 +       mm->mm_vx_info = NULL;
14247         mm_init_cpumask(mm);
14248  
14249  #ifdef CONFIG_TRANSPARENT_HUGEPAGE
14250 @@ -859,6 +867,7 @@ fail_nocontext:
14251          * If init_new_context() failed, we cannot use mmput() to free the mm
14252          * because it calls destroy_context()
14253          */
14254 +       clr_vx_info(&mm->mm_vx_info);
14255         mm_free_pgd(mm);
14256         free_mm(mm);
14257         return NULL;
14258 @@ -1137,6 +1146,8 @@ static struct task_struct *copy_process(
14259  {
14260         int retval;
14261         struct task_struct *p;
14262 +       struct vx_info *vxi;
14263 +       struct nx_info *nxi;
14264  
14265         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
14266                 return ERR_PTR(-EINVAL);
14267 @@ -1195,7 +1206,12 @@ static struct task_struct *copy_process(
14268         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
14269         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
14270  #endif
14271 +       init_vx_info(&p->vx_info, current_vx_info());
14272 +       init_nx_info(&p->nx_info, current_nx_info());
14273 +
14274         retval = -EAGAIN;
14275 +       if (!vx_nproc_avail(1))
14276 +               goto bad_fork_free;
14277         if (atomic_read(&p->real_cred->user->processes) >=
14278                         task_rlimit(p, RLIMIT_NPROC)) {
14279                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
14280 @@ -1472,6 +1488,18 @@ static struct task_struct *copy_process(
14281  
14282         total_forks++;
14283         spin_unlock(&current->sighand->siglock);
14284 +
14285 +       /* p is copy of current */
14286 +       vxi = p->vx_info;
14287 +       if (vxi) {
14288 +               claim_vx_info(vxi, p);
14289 +               atomic_inc(&vxi->cvirt.nr_threads);
14290 +               atomic_inc(&vxi->cvirt.total_forks);
14291 +               vx_nproc_inc(p);
14292 +       }
14293 +       nxi = p->nx_info;
14294 +       if (nxi)
14295 +               claim_nx_info(nxi, p);
14296         write_unlock_irq(&tasklist_lock);
14297         proc_fork_connector(p);
14298         cgroup_post_fork(p);
14299 diff -NurpP --minimal linux-3.9.4/kernel/kthread.c linux-3.9.4-vs2.3.6.1/kernel/kthread.c
14300 --- linux-3.9.4/kernel/kthread.c        2013-05-31 13:45:30.000000000 +0000
14301 +++ linux-3.9.4-vs2.3.6.1/kernel/kthread.c      2013-05-31 14:47:11.000000000 +0000
14302 @@ -17,6 +17,7 @@
14303  #include <linux/slab.h>
14304  #include <linux/freezer.h>
14305  #include <linux/ptrace.h>
14306 +#include <linux/vs_pid.h>
14307  #include <trace/events/sched.h>
14308  
14309  static DEFINE_SPINLOCK(kthread_create_lock);
14310 diff -NurpP --minimal linux-3.9.4/kernel/nsproxy.c linux-3.9.4-vs2.3.6.1/kernel/nsproxy.c
14311 --- linux-3.9.4/kernel/nsproxy.c        2013-05-31 13:45:30.000000000 +0000
14312 +++ linux-3.9.4-vs2.3.6.1/kernel/nsproxy.c      2013-05-31 19:28:43.000000000 +0000
14313 @@ -20,11 +20,14 @@
14314  #include <linux/mnt_namespace.h>
14315  #include <linux/utsname.h>
14316  #include <linux/pid_namespace.h>
14317 +#include <linux/vserver/global.h>
14318 +#include <linux/vserver/debug.h>
14319  #include <net/net_namespace.h>
14320  #include <linux/ipc_namespace.h>
14321  #include <linux/proc_fs.h>
14322  #include <linux/file.h>
14323  #include <linux/syscalls.h>
14324 +#include "../fs/mount.h"
14325  
14326  static struct kmem_cache *nsproxy_cachep;
14327  
14328 @@ -46,8 +49,11 @@ static inline struct nsproxy *create_nsp
14329         struct nsproxy *nsproxy;
14330  
14331         nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
14332 -       if (nsproxy)
14333 +       if (nsproxy) {
14334                 atomic_set(&nsproxy->count, 1);
14335 +               atomic_inc(&vs_global_nsproxy);
14336 +       }
14337 +       vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
14338         return nsproxy;
14339  }
14340  
14341 @@ -56,9 +62,12 @@ static inline struct nsproxy *create_nsp
14342   * Return the newly created nsproxy.  Do not attach this to the task,
14343   * leave it to the caller to do proper locking and attach it to task.
14344   */
14345 -static struct nsproxy *create_new_namespaces(unsigned long flags,
14346 -       struct task_struct *tsk, struct user_namespace *user_ns,
14347 -       struct fs_struct *new_fs)
14348 +static struct nsproxy *unshare_namespaces(
14349 +       unsigned long flags,
14350 +       struct nsproxy *orig,
14351 +       struct fs_struct *new_fs,
14352 +       struct user_namespace *new_user,
14353 +       struct pid_namespace *new_pid)
14354  {
14355         struct nsproxy *new_nsp;
14356         int err;
14357 @@ -67,31 +76,31 @@ static struct nsproxy *create_new_namesp
14358         if (!new_nsp)
14359                 return ERR_PTR(-ENOMEM);
14360  
14361 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, user_ns, new_fs);
14362 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_user, new_fs);
14363         if (IS_ERR(new_nsp->mnt_ns)) {
14364                 err = PTR_ERR(new_nsp->mnt_ns);
14365                 goto out_ns;
14366         }
14367  
14368 -       new_nsp->uts_ns = copy_utsname(flags, user_ns, tsk->nsproxy->uts_ns);
14369 +       new_nsp->uts_ns = copy_utsname(flags, new_user, orig->uts_ns);
14370         if (IS_ERR(new_nsp->uts_ns)) {
14371                 err = PTR_ERR(new_nsp->uts_ns);
14372                 goto out_uts;
14373         }
14374  
14375 -       new_nsp->ipc_ns = copy_ipcs(flags, user_ns, tsk->nsproxy->ipc_ns);
14376 +       new_nsp->ipc_ns = copy_ipcs(flags, new_user, orig->ipc_ns);
14377         if (IS_ERR(new_nsp->ipc_ns)) {
14378                 err = PTR_ERR(new_nsp->ipc_ns);
14379                 goto out_ipc;
14380         }
14381  
14382 -       new_nsp->pid_ns = copy_pid_ns(flags, user_ns, tsk->nsproxy->pid_ns);
14383 +       new_nsp->pid_ns = copy_pid_ns(flags, new_user, new_pid);
14384         if (IS_ERR(new_nsp->pid_ns)) {
14385                 err = PTR_ERR(new_nsp->pid_ns);
14386                 goto out_pid;
14387         }
14388  
14389 -       new_nsp->net_ns = copy_net_ns(flags, user_ns, tsk->nsproxy->net_ns);
14390 +       new_nsp->net_ns = copy_net_ns(flags, new_user, orig->net_ns);
14391         if (IS_ERR(new_nsp->net_ns)) {
14392                 err = PTR_ERR(new_nsp->net_ns);
14393                 goto out_net;
14394 @@ -116,6 +125,41 @@ out_ns:
14395         return ERR_PTR(err);
14396  }
14397  
14398 +static struct nsproxy *create_new_namespaces(unsigned long flags,
14399 +       struct task_struct *tsk, struct user_namespace *user_ns,
14400 +       struct fs_struct *new_fs)
14401 +
14402 +{
14403 +       return unshare_namespaces(flags, tsk->nsproxy,
14404 +               new_fs, user_ns, task_active_pid_ns(tsk));
14405 +}
14406 +
14407 +/*
14408 + * copies the nsproxy, setting refcount to 1, and grabbing a
14409 + * reference to all contained namespaces.
14410 + */
14411 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
14412 +{
14413 +       struct nsproxy *ns = create_nsproxy();
14414 +
14415 +       if (ns) {
14416 +               memcpy(ns, orig, sizeof(struct nsproxy));
14417 +               atomic_set(&ns->count, 1);
14418 +
14419 +               if (ns->mnt_ns)
14420 +                       get_mnt_ns(ns->mnt_ns);
14421 +               if (ns->uts_ns)
14422 +                       get_uts_ns(ns->uts_ns);
14423 +               if (ns->ipc_ns)
14424 +                       get_ipc_ns(ns->ipc_ns);
14425 +               if (ns->pid_ns)
14426 +                       get_pid_ns(ns->pid_ns);
14427 +               if (ns->net_ns)
14428 +                       get_net(ns->net_ns);
14429 +       }
14430 +       return ns;
14431 +}
14432 +
14433  /*
14434   * called from clone.  This now handles copy for nsproxy and all
14435   * namespaces therein.
14436 @@ -124,9 +168,12 @@ int copy_namespaces(unsigned long flags,
14437  {
14438         struct nsproxy *old_ns = tsk->nsproxy;
14439         struct user_namespace *user_ns = task_cred_xxx(tsk, user_ns);
14440 -       struct nsproxy *new_ns;
14441 +       struct nsproxy *new_ns = NULL;
14442         int err = 0;
14443  
14444 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
14445 +               flags, tsk, old_ns);
14446 +
14447         if (!old_ns)
14448                 return 0;
14449  
14450 @@ -136,7 +183,7 @@ int copy_namespaces(unsigned long flags,
14451                                 CLONE_NEWPID | CLONE_NEWNET)))
14452                 return 0;
14453  
14454 -       if (!ns_capable(user_ns, CAP_SYS_ADMIN)) {
14455 +       if (!vx_ns_can_unshare(user_ns, CAP_SYS_ADMIN, flags)) {
14456                 err = -EPERM;
14457                 goto out;
14458         }
14459 @@ -163,6 +210,9 @@ int copy_namespaces(unsigned long flags,
14460  
14461  out:
14462         put_nsproxy(old_ns);
14463 +       vxdprintk(VXD_CBIT(space, 3),
14464 +               "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
14465 +               flags, tsk, old_ns, err, new_ns);
14466         return err;
14467  }
14468  
14469 @@ -176,7 +226,9 @@ void free_nsproxy(struct nsproxy *ns)
14470                 put_ipc_ns(ns->ipc_ns);
14471         if (ns->pid_ns)
14472                 put_pid_ns(ns->pid_ns);
14473 -       put_net(ns->net_ns);
14474 +       if (ns->net_ns)
14475 +               put_net(ns->net_ns);
14476 +       atomic_dec(&vs_global_nsproxy);
14477         kmem_cache_free(nsproxy_cachep, ns);
14478  }
14479  
14480 @@ -190,12 +242,16 @@ int unshare_nsproxy_namespaces(unsigned
14481         struct user_namespace *user_ns;
14482         int err = 0;
14483  
14484 +       vxdprintk(VXD_CBIT(space, 4),
14485 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
14486 +               unshare_flags, current->nsproxy);
14487 +
14488         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
14489                                CLONE_NEWNET | CLONE_NEWPID)))
14490                 return 0;
14491  
14492         user_ns = new_cred ? new_cred->user_ns : current_user_ns();
14493 -       if (!ns_capable(user_ns, CAP_SYS_ADMIN))
14494 +       if (!vx_ns_can_unshare(user_ns, CAP_SYS_ADMIN, unshare_flags))
14495                 return -EPERM;
14496  
14497         *new_nsp = create_new_namespaces(unshare_flags, current, user_ns,
14498 diff -NurpP --minimal linux-3.9.4/kernel/pid.c linux-3.9.4-vs2.3.6.1/kernel/pid.c
14499 --- linux-3.9.4/kernel/pid.c    2013-05-31 13:45:30.000000000 +0000
14500 +++ linux-3.9.4-vs2.3.6.1/kernel/pid.c  2013-05-31 15:24:34.000000000 +0000
14501 @@ -37,6 +37,7 @@
14502  #include <linux/init_task.h>
14503  #include <linux/syscalls.h>
14504  #include <linux/proc_fs.h>
14505 +#include <linux/vs_pid.h>
14506  
14507  #define pid_hashfn(nr, ns)     \
14508         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
14509 @@ -364,7 +365,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
14510  
14511  struct pid *find_vpid(int nr)
14512  {
14513 -       return find_pid_ns(nr, task_active_pid_ns(current));
14514 +       return find_pid_ns(vx_rmap_pid(nr), task_active_pid_ns(current));
14515  }
14516  EXPORT_SYMBOL_GPL(find_vpid);
14517  
14518 @@ -424,6 +425,9 @@ void transfer_pid(struct task_struct *ol
14519  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
14520  {
14521         struct task_struct *result = NULL;
14522 +
14523 +       if (type == PIDTYPE_REALPID)
14524 +               type = PIDTYPE_PID;
14525         if (pid) {
14526                 struct hlist_node *first;
14527                 first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]),
14528 @@ -443,7 +447,7 @@ struct task_struct *find_task_by_pid_ns(
14529         rcu_lockdep_assert(rcu_read_lock_held(),
14530                            "find_task_by_pid_ns() needs rcu_read_lock()"
14531                            " protection");
14532 -       return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
14533 +       return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
14534  }
14535  
14536  struct task_struct *find_task_by_vpid(pid_t vnr)
14537 @@ -487,7 +491,7 @@ struct pid *find_get_pid(pid_t nr)
14538  }
14539  EXPORT_SYMBOL_GPL(find_get_pid);
14540  
14541 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
14542 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
14543  {
14544         struct upid *upid;
14545         pid_t nr = 0;
14546 @@ -501,6 +505,11 @@ pid_t pid_nr_ns(struct pid *pid, struct
14547  }
14548  EXPORT_SYMBOL_GPL(pid_nr_ns);
14549  
14550 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
14551 +{
14552 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
14553 +}
14554 +
14555  pid_t pid_vnr(struct pid *pid)
14556  {
14557         return pid_nr_ns(pid, task_active_pid_ns(current));
14558 diff -NurpP --minimal linux-3.9.4/kernel/pid_namespace.c linux-3.9.4-vs2.3.6.1/kernel/pid_namespace.c
14559 --- linux-3.9.4/kernel/pid_namespace.c  2013-05-31 13:45:30.000000000 +0000
14560 +++ linux-3.9.4-vs2.3.6.1/kernel/pid_namespace.c        2013-05-31 17:59:48.000000000 +0000
14561 @@ -18,6 +18,7 @@
14562  #include <linux/proc_fs.h>
14563  #include <linux/reboot.h>
14564  #include <linux/export.h>
14565 +#include <linux/vserver/global.h>
14566  
14567  #define BITS_PER_PAGE          (PAGE_SIZE*8)
14568  
14569 @@ -112,6 +113,7 @@ static struct pid_namespace *create_pid_
14570                 goto out_free_map;
14571  
14572         kref_init(&ns->kref);
14573 +       atomic_inc(&vs_global_pid_ns);
14574         ns->level = level;
14575         ns->parent = get_pid_ns(parent_pid_ns);
14576         ns->user_ns = get_user_ns(user_ns);
14577 @@ -142,6 +144,7 @@ static void destroy_pid_namespace(struct
14578         for (i = 0; i < PIDMAP_ENTRIES; i++)
14579                 kfree(ns->pidmap[i].page);
14580         put_user_ns(ns->user_ns);
14581 +       atomic_dec(&vs_global_pid_ns);
14582         kmem_cache_free(pid_ns_cachep, ns);
14583  }
14584  
14585 diff -NurpP --minimal linux-3.9.4/kernel/posix-timers.c linux-3.9.4-vs2.3.6.1/kernel/posix-timers.c
14586 --- linux-3.9.4/kernel/posix-timers.c   2013-05-31 13:45:30.000000000 +0000
14587 +++ linux-3.9.4-vs2.3.6.1/kernel/posix-timers.c 2013-05-31 14:47:11.000000000 +0000
14588 @@ -47,6 +47,7 @@
14589  #include <linux/wait.h>
14590  #include <linux/workqueue.h>
14591  #include <linux/export.h>
14592 +#include <linux/vs_context.h>
14593  
14594  /*
14595   * Management arrays for POSIX timers.  Timers are kept in slab memory
14596 @@ -340,6 +341,7 @@ int posix_timer_event(struct k_itimer *t
14597  {
14598         struct task_struct *task;
14599         int shared, ret = -1;
14600 +
14601         /*
14602          * FIXME: if ->sigq is queued we can race with
14603          * dequeue_signal()->do_schedule_next_timer().
14604 @@ -356,10 +358,18 @@ int posix_timer_event(struct k_itimer *t
14605         rcu_read_lock();
14606         task = pid_task(timr->it_pid, PIDTYPE_PID);
14607         if (task) {
14608 +               struct vx_info_save vxis;
14609 +               struct vx_info *vxi;
14610 +
14611 +               vxi = get_vx_info(task->vx_info);
14612 +               enter_vx_info(vxi, &vxis);
14613                 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
14614                 ret = send_sigqueue(timr->sigq, task, shared);
14615 +               leave_vx_info(&vxis);
14616 +               put_vx_info(vxi);
14617         }
14618         rcu_read_unlock();
14619 +
14620         /* If we failed to send the signal the timer stops. */
14621         return ret > 0;
14622  }
14623 diff -NurpP --minimal linux-3.9.4/kernel/printk.c linux-3.9.4-vs2.3.6.1/kernel/printk.c
14624 --- linux-3.9.4/kernel/printk.c 2013-05-31 13:45:30.000000000 +0000
14625 +++ linux-3.9.4-vs2.3.6.1/kernel/printk.c       2013-05-31 15:23:35.000000000 +0000
14626 @@ -43,6 +43,7 @@
14627  #include <linux/rculist.h>
14628  #include <linux/poll.h>
14629  #include <linux/irq_work.h>
14630 +#include <linux/vs_cvirt.h>
14631  
14632  #include <asm/uaccess.h>
14633  
14634 @@ -841,7 +842,7 @@ static int check_syslog_permissions(int
14635                 return 0;
14636  
14637         if (syslog_action_restricted(type)) {
14638 -               if (capable(CAP_SYSLOG))
14639 +               if (vx_capable(CAP_SYSLOG, VXC_SYSLOG))
14640                         return 0;
14641                 /* For historical reasons, accept CAP_SYS_ADMIN too, with a warning */
14642                 if (capable(CAP_SYS_ADMIN)) {
14643 @@ -1135,12 +1136,9 @@ int do_syslog(int type, char __user *buf
14644         if (error)
14645                 return error;
14646  
14647 -       switch (type) {
14648 -       case SYSLOG_ACTION_CLOSE:       /* Close log */
14649 -               break;
14650 -       case SYSLOG_ACTION_OPEN:        /* Open log */
14651 -               break;
14652 -       case SYSLOG_ACTION_READ:        /* Read from log */
14653 +       if ((type == SYSLOG_ACTION_READ) ||
14654 +           (type == SYSLOG_ACTION_READ_ALL) ||
14655 +           (type == SYSLOG_ACTION_READ_CLEAR)) {
14656                 error = -EINVAL;
14657                 if (!buf || len < 0)
14658                         goto out;
14659 @@ -1151,6 +1149,16 @@ int do_syslog(int type, char __user *buf
14660                         error = -EFAULT;
14661                         goto out;
14662                 }
14663 +       }
14664 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
14665 +               return vx_do_syslog(type, buf, len);
14666 +
14667 +       switch (type) {
14668 +       case SYSLOG_ACTION_CLOSE:       /* Close log */
14669 +               break;
14670 +       case SYSLOG_ACTION_OPEN:        /* Open log */
14671 +               break;
14672 +       case SYSLOG_ACTION_READ:        /* Read from log */
14673                 error = wait_event_interruptible(log_wait,
14674                                                  syslog_seq != log_next_seq);
14675                 if (error)
14676 @@ -1163,16 +1171,6 @@ int do_syslog(int type, char __user *buf
14677                 /* FALL THRU */
14678         /* Read last kernel messages */
14679         case SYSLOG_ACTION_READ_ALL:
14680 -               error = -EINVAL;
14681 -               if (!buf || len < 0)
14682 -                       goto out;
14683 -               error = 0;
14684 -               if (!len)
14685 -                       goto out;
14686 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
14687 -                       error = -EFAULT;
14688 -                       goto out;
14689 -               }
14690                 error = syslog_print_all(buf, len, clear);
14691                 break;
14692         /* Clear ring buffer */
14693 diff -NurpP --minimal linux-3.9.4/kernel/ptrace.c linux-3.9.4-vs2.3.6.1/kernel/ptrace.c
14694 --- linux-3.9.4/kernel/ptrace.c 2013-05-31 13:45:30.000000000 +0000
14695 +++ linux-3.9.4-vs2.3.6.1/kernel/ptrace.c       2013-05-31 15:22:34.000000000 +0000
14696 @@ -22,6 +22,7 @@
14697  #include <linux/syscalls.h>
14698  #include <linux/uaccess.h>
14699  #include <linux/regset.h>
14700 +#include <linux/vs_context.h>
14701  #include <linux/hw_breakpoint.h>
14702  #include <linux/cn_proc.h>
14703  
14704 @@ -261,6 +262,11 @@ ok:
14705         }
14706         rcu_read_unlock();
14707  
14708 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_WATCH_P|VS_IDENT))
14709 +               return -EPERM;
14710 +       if (!vx_check(task->xid, VS_IDENT) &&
14711 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
14712 +               return -EACCES;
14713         return security_ptrace_access_check(task, mode);
14714  }
14715  
14716 diff -NurpP --minimal linux-3.9.4/kernel/sched/core.c linux-3.9.4-vs2.3.6.1/kernel/sched/core.c
14717 --- linux-3.9.4/kernel/sched/core.c     2013-05-31 13:45:30.000000000 +0000
14718 +++ linux-3.9.4-vs2.3.6.1/kernel/sched/core.c   2013-05-31 15:17:22.000000000 +0000
14719 @@ -73,6 +73,8 @@
14720  #include <linux/init_task.h>
14721  #include <linux/binfmts.h>
14722  #include <linux/context_tracking.h>
14723 +#include <linux/vs_sched.h>
14724 +#include <linux/vs_cvirt.h>
14725  
14726  #include <asm/switch_to.h>
14727  #include <asm/tlb.h>
14728 @@ -2091,9 +2093,17 @@ EXPORT_SYMBOL(avenrun); /* should be rem
14729   */
14730  void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
14731  {
14732 -       loads[0] = (avenrun[0] + offset) << shift;
14733 -       loads[1] = (avenrun[1] + offset) << shift;
14734 -       loads[2] = (avenrun[2] + offset) << shift;
14735 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
14736 +               struct vx_info *vxi = current_vx_info();
14737 +
14738 +               loads[0] = (vxi->cvirt.load[0] + offset) << shift;
14739 +               loads[1] = (vxi->cvirt.load[1] + offset) << shift;
14740 +               loads[2] = (vxi->cvirt.load[2] + offset) << shift;
14741 +       } else {
14742 +               loads[0] = (avenrun[0] + offset) << shift;
14743 +               loads[1] = (avenrun[1] + offset) << shift;
14744 +               loads[2] = (avenrun[2] + offset) << shift;
14745 +       }
14746  }
14747  
14748  static long calc_load_fold_active(struct rq *this_rq)
14749 @@ -3704,7 +3714,7 @@ SYSCALL_DEFINE1(nice, int, increment)
14750                 nice = 19;
14751  
14752         if (increment < 0 && !can_nice(current, nice))
14753 -               return -EPERM;
14754 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
14755  
14756         retval = security_task_setnice(current, nice);
14757         if (retval)
14758 diff -NurpP --minimal linux-3.9.4/kernel/sched/cputime.c linux-3.9.4-vs2.3.6.1/kernel/sched/cputime.c
14759 --- linux-3.9.4/kernel/sched/cputime.c  2013-05-31 14:22:27.000000000 +0000
14760 +++ linux-3.9.4-vs2.3.6.1/kernel/sched/cputime.c        2013-05-31 15:17:55.000000000 +0000
14761 @@ -4,6 +4,7 @@
14762  #include <linux/kernel_stat.h>
14763  #include <linux/static_key.h>
14764  #include <linux/context_tracking.h>
14765 +#include <linux/vs_sched.h>
14766  #include "sched.h"
14767  
14768  
14769 @@ -151,14 +152,17 @@ static inline void task_group_account_fi
14770  void account_user_time(struct task_struct *p, cputime_t cputime,
14771                        cputime_t cputime_scaled)
14772  {
14773 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
14774 +       int nice = (TASK_NICE(p) > 0);
14775         int index;
14776  
14777         /* Add user time to process. */
14778         p->utime += cputime;
14779         p->utimescaled += cputime_scaled;
14780 +       vx_account_user(vxi, cputime, nice);
14781         account_group_user_time(p, cputime);
14782  
14783 -       index = (TASK_NICE(p) > 0) ? CPUTIME_NICE : CPUTIME_USER;
14784 +       index = (nice) ? CPUTIME_NICE : CPUTIME_USER;
14785  
14786         /* Add user time to cpustat. */
14787         task_group_account_field(p, index, (__force u64) cputime);
14788 @@ -205,9 +209,12 @@ static inline
14789  void __account_system_time(struct task_struct *p, cputime_t cputime,
14790                         cputime_t cputime_scaled, int index)
14791  {
14792 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
14793 +
14794         /* Add system time to process. */
14795         p->stime += cputime;
14796         p->stimescaled += cputime_scaled;
14797 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
14798         account_group_system_time(p, cputime);
14799  
14800         /* Add system time to cpustat. */
14801 diff -NurpP --minimal linux-3.9.4/kernel/sched/fair.c linux-3.9.4-vs2.3.6.1/kernel/sched/fair.c
14802 --- linux-3.9.4/kernel/sched/fair.c     2013-05-31 13:45:30.000000000 +0000
14803 +++ linux-3.9.4-vs2.3.6.1/kernel/sched/fair.c   2013-05-31 15:19:37.000000000 +0000
14804 @@ -29,6 +29,7 @@
14805  #include <linux/mempolicy.h>
14806  #include <linux/migrate.h>
14807  #include <linux/task_work.h>
14808 +#include <linux/vs_cvirt.h>
14809  
14810  #include <trace/events/sched.h>
14811  
14812 @@ -1714,6 +1715,8 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
14813                 __enqueue_entity(cfs_rq, se);
14814         se->on_rq = 1;
14815  
14816 +       if (entity_is_task(se))
14817 +               vx_activate_task(task_of(se));
14818         if (cfs_rq->nr_running == 1) {
14819                 list_add_leaf_cfs_rq(cfs_rq);
14820                 check_enqueue_throttle(cfs_rq);
14821 @@ -1795,6 +1798,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
14822         if (se != cfs_rq->curr)
14823                 __dequeue_entity(cfs_rq, se);
14824         se->on_rq = 0;
14825 +       if (entity_is_task(se))
14826 +               vx_deactivate_task(task_of(se));
14827         account_entity_dequeue(cfs_rq, se);
14828  
14829         /*
14830 diff -NurpP --minimal linux-3.9.4/kernel/signal.c linux-3.9.4-vs2.3.6.1/kernel/signal.c
14831 --- linux-3.9.4/kernel/signal.c 2013-05-31 13:45:30.000000000 +0000
14832 +++ linux-3.9.4-vs2.3.6.1/kernel/signal.c       2013-05-31 15:20:05.000000000 +0000
14833 @@ -32,6 +32,8 @@
14834  #include <linux/user_namespace.h>
14835  #include <linux/uprobes.h>
14836  #include <linux/compat.h>
14837 +#include <linux/vs_context.h>
14838 +#include <linux/vs_pid.h>
14839  #define CREATE_TRACE_POINTS
14840  #include <trace/events/signal.h>
14841  
14842 @@ -789,9 +791,18 @@ static int check_kill_permission(int sig
14843         struct pid *sid;
14844         int error;
14845  
14846 +       vxdprintk(VXD_CBIT(misc, 7),
14847 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
14848 +               sig, info, t, vx_task_xid(t), t->pid);
14849 +
14850         if (!valid_signal(sig))
14851                 return -EINVAL;
14852  
14853 +/*     FIXME: needed? if so, why?
14854 +       if ((info != SEND_SIG_NOINFO) &&
14855 +               (is_si_special(info) || !si_fromuser(info)))
14856 +               goto skip;      */
14857 +
14858         if (!si_fromuser(info))
14859                 return 0;
14860  
14861 @@ -815,6 +826,20 @@ static int check_kill_permission(int sig
14862                 }
14863         }
14864  
14865 +       error = -EPERM;
14866 +       if (t->pid == 1 && current->xid)
14867 +               return error;
14868 +
14869 +       error = -ESRCH;
14870 +       /* FIXME: we shouldn't return ESRCH ever, to avoid
14871 +                 loops, maybe ENOENT or EACCES? */
14872 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
14873 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
14874 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
14875 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
14876 +               return error;
14877 +       }
14878 +/* skip: */
14879         return security_task_kill(t, info, sig, 0);
14880  }
14881  
14882 @@ -1351,7 +1376,7 @@ int kill_pid_info(int sig, struct siginf
14883         rcu_read_lock();
14884  retry:
14885         p = pid_task(pid, PIDTYPE_PID);
14886 -       if (p) {
14887 +       if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
14888                 error = group_send_sig_info(sig, info, p);
14889                 if (unlikely(error == -ESRCH))
14890                         /*
14891 @@ -1399,7 +1424,7 @@ int kill_pid_info_as_cred(int sig, struc
14892  
14893         rcu_read_lock();
14894         p = pid_task(pid, PIDTYPE_PID);
14895 -       if (!p) {
14896 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
14897                 ret = -ESRCH;
14898                 goto out_unlock;
14899         }
14900 @@ -1451,8 +1476,10 @@ static int kill_something_info(int sig,
14901                 struct task_struct * p;
14902  
14903                 for_each_process(p) {
14904 -                       if (task_pid_vnr(p) > 1 &&
14905 -                                       !same_thread_group(p, current)) {
14906 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
14907 +                               task_pid_vnr(p) > 1 &&
14908 +                               !same_thread_group(p, current) &&
14909 +                               !vx_current_initpid(p->pid)) {
14910                                 int err = group_send_sig_info(sig, info, p);
14911                                 ++count;
14912                                 if (err != -EPERM)
14913 @@ -2306,6 +2333,11 @@ relock:
14914                                 !sig_kernel_only(signr))
14915                         continue;
14916  
14917 +               /* virtual init is protected against user signals */
14918 +               if ((info->si_code == SI_USER) &&
14919 +                       vx_current_initpid(current->pid))
14920 +                       continue;
14921 +
14922                 if (sig_kernel_stop(signr)) {
14923                         /*
14924                          * The default action is to stop all threads in
14925 diff -NurpP --minimal linux-3.9.4/kernel/softirq.c linux-3.9.4-vs2.3.6.1/kernel/softirq.c
14926 --- linux-3.9.4/kernel/softirq.c        2013-05-31 13:45:30.000000000 +0000
14927 +++ linux-3.9.4-vs2.3.6.1/kernel/softirq.c      2013-05-31 14:47:11.000000000 +0000
14928 @@ -25,6 +25,7 @@
14929  #include <linux/smp.h>
14930  #include <linux/smpboot.h>
14931  #include <linux/tick.h>
14932 +#include <linux/vs_context.h>
14933  
14934  #define CREATE_TRACE_POINTS
14935  #include <trace/events/irq.h>
14936 diff -NurpP --minimal linux-3.9.4/kernel/sys.c linux-3.9.4-vs2.3.6.1/kernel/sys.c
14937 --- linux-3.9.4/kernel/sys.c    2013-05-31 13:45:30.000000000 +0000
14938 +++ linux-3.9.4-vs2.3.6.1/kernel/sys.c  2013-05-31 15:23:14.000000000 +0000
14939 @@ -50,6 +50,7 @@
14940  #include <linux/binfmts.h>
14941  
14942  #include <linux/kmsg_dump.h>
14943 +#include <linux/vs_pid.h>
14944  /* Move somewhere else to avoid recompiling? */
14945  #include <generated/utsrelease.h>
14946  
14947 @@ -155,7 +156,10 @@ static int set_one_prio(struct task_stru
14948                 goto out;
14949         }
14950         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
14951 -               error = -EACCES;
14952 +               if (vx_flags(VXF_IGNEG_NICE, 0))
14953 +                       error = 0;
14954 +               else
14955 +                       error = -EACCES;
14956                 goto out;
14957         }
14958         no_nice = security_task_setnice(p, niceval);
14959 @@ -206,6 +210,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
14960                         else
14961                                 pgrp = task_pgrp(current);
14962                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
14963 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
14964 +                                       continue;
14965                                 error = set_one_prio(p, niceval, error);
14966                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
14967                         break;
14968 @@ -271,6 +277,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
14969                         else
14970                                 pgrp = task_pgrp(current);
14971                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
14972 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
14973 +                                       continue;
14974                                 niceval = 20 - task_nice(p);
14975                                 if (niceval > retval)
14976                                         retval = niceval;
14977 @@ -424,6 +432,8 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
14978  
14979  static DEFINE_MUTEX(reboot_mutex);
14980  
14981 +long vs_reboot(unsigned int, void __user *);
14982 +
14983  /*
14984   * Reboot system call: for obvious reasons only root may call it,
14985   * and even root needs to set up some magic numbers in the registers
14986 @@ -466,6 +476,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
14987         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
14988                 cmd = LINUX_REBOOT_CMD_HALT;
14989  
14990 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
14991 +               return vs_reboot(cmd, arg);
14992 +
14993         mutex_lock(&reboot_mutex);
14994         switch (cmd) {
14995         case LINUX_REBOOT_CMD_RESTART:
14996 @@ -1373,7 +1386,8 @@ SYSCALL_DEFINE2(sethostname, char __user
14997         int errno;
14998         char tmp[__NEW_UTS_LEN];
14999  
15000 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
15001 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
15002 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
15003                 return -EPERM;
15004  
15005         if (len < 0 || len > __NEW_UTS_LEN)
15006 @@ -1424,7 +1438,8 @@ SYSCALL_DEFINE2(setdomainname, char __us
15007         int errno;
15008         char tmp[__NEW_UTS_LEN];
15009  
15010 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
15011 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
15012 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
15013                 return -EPERM;
15014         if (len < 0 || len > __NEW_UTS_LEN)
15015                 return -EINVAL;
15016 @@ -1543,7 +1558,7 @@ int do_prlimit(struct task_struct *tsk,
15017                 /* Keep the capable check against init_user_ns until
15018                    cgroups can contain all limits */
15019                 if (new_rlim->rlim_max > rlim->rlim_max &&
15020 -                               !capable(CAP_SYS_RESOURCE))
15021 +                       !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
15022                         retval = -EPERM;
15023                 if (!retval)
15024                         retval = security_task_setrlimit(tsk->group_leader,
15025 @@ -1596,7 +1611,8 @@ static int check_prlimit_permission(stru
15026             gid_eq(cred->gid, tcred->sgid) &&
15027             gid_eq(cred->gid, tcred->gid))
15028                 return 0;
15029 -       if (ns_capable(tcred->user_ns, CAP_SYS_RESOURCE))
15030 +       if (vx_ns_capable(tcred->user_ns,
15031 +               CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
15032                 return 0;
15033  
15034         return -EPERM;
15035 diff -NurpP --minimal linux-3.9.4/kernel/sysctl.c linux-3.9.4-vs2.3.6.1/kernel/sysctl.c
15036 --- linux-3.9.4/kernel/sysctl.c 2013-05-31 13:45:30.000000000 +0000
15037 +++ linux-3.9.4-vs2.3.6.1/kernel/sysctl.c       2013-05-31 15:28:39.000000000 +0000
15038 @@ -83,6 +83,7 @@
15039  #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
15040  #include <linux/lockdep.h>
15041  #endif
15042 +extern char vshelper_path[];
15043  #ifdef CONFIG_CHR_DEV_SG
15044  #include <scsi/sg.h>
15045  #endif
15046 @@ -629,6 +630,13 @@ static struct ctl_table kern_table[] = {
15047                 .mode           = 0644,
15048                 .proc_handler   = proc_dostring,
15049         },
15050 +       {
15051 +               .procname       = "vshelper",
15052 +               .data           = &vshelper_path,
15053 +               .maxlen         = 256,
15054 +               .mode           = 0644,
15055 +               .proc_handler   = &proc_dostring,
15056 +       },
15057  
15058  #ifdef CONFIG_CHR_DEV_SG
15059         {
15060 diff -NurpP --minimal linux-3.9.4/kernel/sysctl_binary.c linux-3.9.4-vs2.3.6.1/kernel/sysctl_binary.c
15061 --- linux-3.9.4/kernel/sysctl_binary.c  2013-05-31 13:45:30.000000000 +0000
15062 +++ linux-3.9.4-vs2.3.6.1/kernel/sysctl_binary.c        2013-05-31 14:47:11.000000000 +0000
15063 @@ -73,6 +73,7 @@ static const struct bin_table bin_kern_t
15064  
15065         { CTL_INT,      KERN_PANIC,                     "panic" },
15066         { CTL_INT,      KERN_REALROOTDEV,               "real-root-dev" },
15067 +       { CTL_STR,      KERN_VSHELPER,                  "vshelper" },
15068  
15069         { CTL_STR,      KERN_SPARC_REBOOT,              "reboot-cmd" },
15070         { CTL_INT,      KERN_CTLALTDEL,                 "ctrl-alt-del" },
15071 diff -NurpP --minimal linux-3.9.4/kernel/time/timekeeping.c linux-3.9.4-vs2.3.6.1/kernel/time/timekeeping.c
15072 --- linux-3.9.4/kernel/time/timekeeping.c       2013-05-31 13:45:30.000000000 +0000
15073 +++ linux-3.9.4-vs2.3.6.1/kernel/time/timekeeping.c     2013-05-31 15:24:55.000000000 +0000
15074 @@ -22,6 +22,7 @@
15075  #include <linux/tick.h>
15076  #include <linux/stop_machine.h>
15077  #include <linux/pvclock_gtod.h>
15078 +#include <linux/vs_time.h>
15079  
15080  
15081  static struct timekeeper timekeeper;
15082 @@ -594,6 +595,7 @@ void getrawmonotonic(struct timespec *ts
15083         } while (read_seqretry(&tk->lock, seq));
15084  
15085         timespec_add_ns(ts, nsecs);
15086 +       vx_adjust_timespec(ts);
15087  }
15088  EXPORT_SYMBOL(getrawmonotonic);
15089  
15090 diff -NurpP --minimal linux-3.9.4/kernel/time.c linux-3.9.4-vs2.3.6.1/kernel/time.c
15091 --- linux-3.9.4/kernel/time.c   2013-05-31 13:45:30.000000000 +0000
15092 +++ linux-3.9.4-vs2.3.6.1/kernel/time.c 2013-05-31 14:47:11.000000000 +0000
15093 @@ -37,6 +37,7 @@
15094  #include <linux/fs.h>
15095  #include <linux/math64.h>
15096  #include <linux/ptrace.h>
15097 +#include <linux/vs_time.h>
15098  
15099  #include <asm/uaccess.h>
15100  #include <asm/unistd.h>
15101 @@ -92,7 +93,7 @@ SYSCALL_DEFINE1(stime, time_t __user *,
15102         if (err)
15103                 return err;
15104  
15105 -       do_settimeofday(&tv);
15106 +       vx_settimeofday(&tv);
15107         return 0;
15108  }
15109  
15110 @@ -180,7 +181,7 @@ int do_sys_settimeofday(const struct tim
15111                 }
15112         }
15113         if (tv)
15114 -               return do_settimeofday(tv);
15115 +               return vx_settimeofday(tv);
15116         return 0;
15117  }
15118  
15119 diff -NurpP --minimal linux-3.9.4/kernel/timer.c linux-3.9.4-vs2.3.6.1/kernel/timer.c
15120 --- linux-3.9.4/kernel/timer.c  2013-05-31 14:22:27.000000000 +0000
15121 +++ linux-3.9.4-vs2.3.6.1/kernel/timer.c        2013-05-31 14:47:11.000000000 +0000
15122 @@ -41,6 +41,10 @@
15123  #include <linux/sched.h>
15124  #include <linux/sched/sysctl.h>
15125  #include <linux/slab.h>
15126 +#include <linux/vs_base.h>
15127 +#include <linux/vs_cvirt.h>
15128 +#include <linux/vs_pid.h>
15129 +#include <linux/vserver/sched.h>
15130  
15131  #include <asm/uaccess.h>
15132  #include <asm/unistd.h>
15133 diff -NurpP --minimal linux-3.9.4/kernel/user_namespace.c linux-3.9.4-vs2.3.6.1/kernel/user_namespace.c
15134 --- linux-3.9.4/kernel/user_namespace.c 2013-05-31 13:45:30.000000000 +0000
15135 +++ linux-3.9.4-vs2.3.6.1/kernel/user_namespace.c       2013-05-31 17:44:56.000000000 +0000
15136 @@ -22,6 +22,7 @@
15137  #include <linux/ctype.h>
15138  #include <linux/projid.h>
15139  #include <linux/fs_struct.h>
15140 +#include <linux/vserver/global.h>
15141  
15142  static struct kmem_cache *user_ns_cachep __read_mostly;
15143  
15144 @@ -91,6 +92,7 @@ int create_user_ns(struct cred *new)
15145  
15146         atomic_set(&ns->count, 1);
15147         /* Leave the new->user_ns reference with the new user namespace. */
15148 +       atomic_inc(&vs_global_user_ns);
15149         ns->parent = parent_ns;
15150         ns->owner = owner;
15151         ns->group = group;
15152 @@ -835,6 +837,8 @@ static void *userns_get(struct task_stru
15153  
15154  static void userns_put(void *ns)
15155  {
15156 +       /* FIXME: maybe move into destroyer? */
15157 +       atomic_dec(&vs_global_user_ns);
15158         put_user_ns(ns);
15159  }
15160  
15161 diff -NurpP --minimal linux-3.9.4/kernel/utsname.c linux-3.9.4-vs2.3.6.1/kernel/utsname.c
15162 --- linux-3.9.4/kernel/utsname.c        2013-05-31 13:45:30.000000000 +0000
15163 +++ linux-3.9.4-vs2.3.6.1/kernel/utsname.c      2013-05-31 15:15:55.000000000 +0000
15164 @@ -16,14 +16,17 @@
15165  #include <linux/slab.h>
15166  #include <linux/user_namespace.h>
15167  #include <linux/proc_fs.h>
15168 +#include <linux/vserver/global.h>
15169  
15170  static struct uts_namespace *create_uts_ns(void)
15171  {
15172         struct uts_namespace *uts_ns;
15173  
15174         uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
15175 -       if (uts_ns)
15176 +       if (uts_ns) {
15177                 kref_init(&uts_ns->kref);
15178 +               atomic_inc(&vs_global_uts_ns);
15179 +       }
15180         return uts_ns;
15181  }
15182  
15183 @@ -85,6 +88,7 @@ void free_uts_ns(struct kref *kref)
15184         ns = container_of(kref, struct uts_namespace, kref);
15185         put_user_ns(ns->user_ns);
15186         proc_free_inum(ns->proc_inum);
15187 +       atomic_dec(&vs_global_uts_ns);
15188         kfree(ns);
15189  }
15190  
15191 diff -NurpP --minimal linux-3.9.4/kernel/vserver/Kconfig linux-3.9.4-vs2.3.6.1/kernel/vserver/Kconfig
15192 --- linux-3.9.4/kernel/vserver/Kconfig  1970-01-01 00:00:00.000000000 +0000
15193 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/Kconfig        2013-05-31 14:47:11.000000000 +0000
15194 @@ -0,0 +1,233 @@
15195 +#
15196 +# Linux VServer configuration
15197 +#
15198 +
15199 +menu "Linux VServer"
15200 +
15201 +config VSERVER_AUTO_LBACK
15202 +       bool    "Automatically Assign Loopback IP"
15203 +       default y
15204 +       help
15205 +         Automatically assign a guest specific loopback
15206 +         IP and add it to the kernel network stack on
15207 +         startup.
15208 +
15209 +config VSERVER_AUTO_SINGLE
15210 +       bool    "Automatic Single IP Special Casing"
15211 +       depends on EXPERIMENTAL
15212 +       default y
15213 +       help
15214 +         This allows network contexts with a single IP to
15215 +         automatically remap 0.0.0.0 bindings to that IP,
15216 +         avoiding further network checks and improving
15217 +         performance.
15218 +
15219 +         (note: such guests do not allow to change the ip
15220 +          on the fly and do not show loopback addresses)
15221 +
15222 +config VSERVER_COWBL
15223 +       bool    "Enable COW Immutable Link Breaking"
15224 +       default y
15225 +       help
15226 +         This enables the COW (Copy-On-Write) link break code.
15227 +         It allows you to treat unified files like normal files
15228 +         when writing to them (which will implicitely break the
15229 +         link and create a copy of the unified file)
15230 +
15231 +config VSERVER_VTIME
15232 +       bool    "Enable Virtualized Guest Time"
15233 +       depends on EXPERIMENTAL
15234 +       default n
15235 +       help
15236 +         This enables per guest time offsets to allow for
15237 +         adjusting the system clock individually per guest.
15238 +         this adds some overhead to the time functions and
15239 +         therefore should not be enabled without good reason.
15240 +
15241 +config VSERVER_DEVICE
15242 +       bool    "Enable Guest Device Mapping"
15243 +       depends on EXPERIMENTAL
15244 +       default n
15245 +       help
15246 +         This enables generic device remapping.
15247 +
15248 +config VSERVER_PROC_SECURE
15249 +       bool    "Enable Proc Security"
15250 +       depends on PROC_FS
15251 +       default y
15252 +       help
15253 +         This configures ProcFS security to initially hide
15254 +         non-process entries for all contexts except the main and
15255 +         spectator context (i.e. for all guests), which is a secure
15256 +         default.
15257 +
15258 +         (note: on 1.2x the entries were visible by default)
15259 +
15260 +choice
15261 +       prompt  "Persistent Inode Tagging"
15262 +       default TAGGING_ID24
15263 +       help
15264 +         This adds persistent context information to filesystems
15265 +         mounted with the tagxid option. Tagging is a requirement
15266 +         for per-context disk limits and per-context quota.
15267 +
15268 +
15269 +config TAGGING_NONE
15270 +       bool    "Disabled"
15271 +       help
15272 +         do not store per-context information in inodes.
15273 +
15274 +config TAGGING_UID16
15275 +       bool    "UID16/GID32"
15276 +       help
15277 +         reduces UID to 16 bit, but leaves GID at 32 bit.
15278 +
15279 +config TAGGING_GID16
15280 +       bool    "UID32/GID16"
15281 +       help
15282 +         reduces GID to 16 bit, but leaves UID at 32 bit.
15283 +
15284 +config TAGGING_ID24
15285 +       bool    "UID24/GID24"
15286 +       help
15287 +         uses the upper 8bit from UID and GID for XID tagging
15288 +         which leaves 24bit for UID/GID each, which should be
15289 +         more than sufficient for normal use.
15290 +
15291 +config TAGGING_INTERN
15292 +       bool    "UID32/GID32"
15293 +       help
15294 +         this uses otherwise reserved inode fields in the on
15295 +         disk representation, which limits the use to a few
15296 +         filesystems (currently ext2 and ext3)
15297 +
15298 +endchoice
15299 +
15300 +config TAG_NFSD
15301 +       bool    "Tag NFSD User Auth and Files"
15302 +       default n
15303 +       help
15304 +         Enable this if you do want the in-kernel NFS
15305 +         Server to use the tagging specified above.
15306 +         (will require patched clients too)
15307 +
15308 +config VSERVER_PRIVACY
15309 +       bool    "Honor Privacy Aspects of Guests"
15310 +       default n
15311 +       help
15312 +         When enabled, most context checks will disallow
15313 +         access to structures assigned to a specific context,
15314 +         like ptys or loop devices.
15315 +
15316 +config VSERVER_CONTEXTS
15317 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
15318 +       range 1 65533
15319 +       default "768"   if 64BIT
15320 +       default "256"
15321 +       help
15322 +         This setting will optimize certain data structures
15323 +         and memory allocations according to the expected
15324 +         maximum.
15325 +
15326 +         note: this is not a strict upper limit.
15327 +
15328 +config VSERVER_WARN
15329 +       bool    "VServer Warnings"
15330 +       default y
15331 +       help
15332 +         This enables various runtime warnings, which will
15333 +         notify about potential manipulation attempts or
15334 +         resource shortage. It is generally considered to
15335 +         be a good idea to have that enabled.
15336 +
15337 +config VSERVER_WARN_DEVPTS
15338 +       bool    "VServer DevPTS Warnings"
15339 +       depends on VSERVER_WARN
15340 +       default y
15341 +       help
15342 +         This enables DevPTS related warnings, issued when a
15343 +         process inside a context tries to lookup or access
15344 +         a dynamic pts from the host or a different context.
15345 +
15346 +config VSERVER_DEBUG
15347 +       bool    "VServer Debugging Code"
15348 +       default n
15349 +       help
15350 +         Set this to yes if you want to be able to activate
15351 +         debugging output at runtime. It adds a very small
15352 +         overhead to all vserver related functions and
15353 +         increases the kernel size by about 20k.
15354 +
15355 +config VSERVER_HISTORY
15356 +       bool    "VServer History Tracing"
15357 +       depends on VSERVER_DEBUG
15358 +       default n
15359 +       help
15360 +         Set this to yes if you want to record the history of
15361 +         linux-vserver activities, so they can be replayed in
15362 +         the event of a kernel panic or oops.
15363 +
15364 +config VSERVER_HISTORY_SIZE
15365 +       int     "Per-CPU History Size (32-65536)"
15366 +       depends on VSERVER_HISTORY
15367 +       range 32 65536
15368 +       default 64
15369 +       help
15370 +         This allows you to specify the number of entries in
15371 +         the per-CPU history buffer.
15372 +
15373 +config VSERVER_EXTRA_MNT_CHECK
15374 +       bool    "Extra Checks for Reachability"
15375 +       default n
15376 +       help
15377 +         Set this to yes if you want to do extra checks for
15378 +         vfsmount reachability in the proc filesystem code.
15379 +         This shouldn't be required on any setup utilizing
15380 +         mnt namespaces.
15381 +
15382 +choice
15383 +       prompt  "Quotes used in debug and warn messages"
15384 +       default QUOTES_ISO8859
15385 +
15386 +config QUOTES_ISO8859
15387 +       bool    "Extended ASCII (ISO 8859) angle quotes"
15388 +       help
15389 +         This uses the extended ASCII characters \xbb
15390 +         and \xab for quoting file and process names.
15391 +
15392 +config QUOTES_UTF8
15393 +       bool    "UTF-8 angle quotes"
15394 +       help
15395 +         This uses the the UTF-8 sequences for angle
15396 +         quotes to quote file and process names.
15397 +
15398 +config QUOTES_ASCII
15399 +       bool    "ASCII single quotes"
15400 +       help
15401 +         This uses the ASCII single quote character
15402 +         (\x27) to quote file and process names.
15403 +
15404 +endchoice
15405 +
15406 +endmenu
15407 +
15408 +
15409 +config VSERVER
15410 +       bool
15411 +       default y
15412 +       select NAMESPACES
15413 +       select UTS_NS
15414 +       select IPC_NS
15415 +#      select USER_NS
15416 +       select SYSVIPC
15417 +
15418 +config VSERVER_SECURITY
15419 +       bool
15420 +       depends on SECURITY
15421 +       default y
15422 +       select SECURITY_CAPABILITIES
15423 +
15424 +config VSERVER_DISABLED
15425 +       bool
15426 +       default n
15427 +
15428 diff -NurpP --minimal linux-3.9.4/kernel/vserver/Makefile linux-3.9.4-vs2.3.6.1/kernel/vserver/Makefile
15429 --- linux-3.9.4/kernel/vserver/Makefile 1970-01-01 00:00:00.000000000 +0000
15430 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/Makefile       2013-05-31 14:47:11.000000000 +0000
15431 @@ -0,0 +1,18 @@
15432 +#
15433 +# Makefile for the Linux vserver routines.
15434 +#
15435 +
15436 +
15437 +obj-y          += vserver.o
15438 +
15439 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
15440 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
15441 +                  dlimit.o tag.o
15442 +
15443 +vserver-$(CONFIG_INET) += inet.o
15444 +vserver-$(CONFIG_PROC_FS) += proc.o
15445 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
15446 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
15447 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
15448 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
15449 +
15450 diff -NurpP --minimal linux-3.9.4/kernel/vserver/cacct.c linux-3.9.4-vs2.3.6.1/kernel/vserver/cacct.c
15451 --- linux-3.9.4/kernel/vserver/cacct.c  1970-01-01 00:00:00.000000000 +0000
15452 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/cacct.c        2013-05-31 14:47:11.000000000 +0000
15453 @@ -0,0 +1,42 @@
15454 +/*
15455 + *  linux/kernel/vserver/cacct.c
15456 + *
15457 + *  Virtual Server: Context Accounting
15458 + *
15459 + *  Copyright (C) 2006-2007 Herbert Pötzl
15460 + *
15461 + *  V0.01  added accounting stats
15462 + *
15463 + */
15464 +
15465 +#include <linux/types.h>
15466 +#include <linux/vs_context.h>
15467 +#include <linux/vserver/cacct_cmd.h>
15468 +#include <linux/vserver/cacct_int.h>
15469 +
15470 +#include <asm/errno.h>
15471 +#include <asm/uaccess.h>
15472 +
15473 +
15474 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
15475 +{
15476 +       struct vcmd_sock_stat_v0 vc_data;
15477 +       int j, field;
15478 +
15479 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15480 +               return -EFAULT;
15481 +
15482 +       field = vc_data.field;
15483 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
15484 +               return -EINVAL;
15485 +
15486 +       for (j = 0; j < 3; j++) {
15487 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
15488 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
15489 +       }
15490 +
15491 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15492 +               return -EFAULT;
15493 +       return 0;
15494 +}
15495 +
15496 diff -NurpP --minimal linux-3.9.4/kernel/vserver/cacct_init.h linux-3.9.4-vs2.3.6.1/kernel/vserver/cacct_init.h
15497 --- linux-3.9.4/kernel/vserver/cacct_init.h     1970-01-01 00:00:00.000000000 +0000
15498 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/cacct_init.h   2013-05-31 14:47:11.000000000 +0000
15499 @@ -0,0 +1,25 @@
15500 +
15501 +
15502 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
15503 +{
15504 +       int i, j;
15505 +
15506 +
15507 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
15508 +               for (j = 0; j < 3; j++) {
15509 +                       atomic_long_set(&cacct->sock[i][j].count, 0);
15510 +                       atomic_long_set(&cacct->sock[i][j].total, 0);
15511 +               }
15512 +       }
15513 +       for (i = 0; i < 8; i++)
15514 +               atomic_set(&cacct->slab[i], 0);
15515 +       for (i = 0; i < 5; i++)
15516 +               for (j = 0; j < 4; j++)
15517 +                       atomic_set(&cacct->page[i][j], 0);
15518 +}
15519 +
15520 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
15521 +{
15522 +       return;
15523 +}
15524 +
15525 diff -NurpP --minimal linux-3.9.4/kernel/vserver/cacct_proc.h linux-3.9.4-vs2.3.6.1/kernel/vserver/cacct_proc.h
15526 --- linux-3.9.4/kernel/vserver/cacct_proc.h     1970-01-01 00:00:00.000000000 +0000
15527 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/cacct_proc.h   2013-05-31 14:47:11.000000000 +0000
15528 @@ -0,0 +1,53 @@
15529 +#ifndef _VX_CACCT_PROC_H
15530 +#define _VX_CACCT_PROC_H
15531 +
15532 +#include <linux/vserver/cacct_int.h>
15533 +
15534 +
15535 +#define VX_SOCKA_TOP   \
15536 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
15537 +
15538 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
15539 +{
15540 +       int i, j, length = 0;
15541 +       static char *type[VXA_SOCK_SIZE] = {
15542 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
15543 +       };
15544 +
15545 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
15546 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
15547 +               length += sprintf(buffer + length, "%s:", type[i]);
15548 +               for (j = 0; j < 3; j++) {
15549 +                       length += sprintf(buffer + length,
15550 +                               "\t%10lu/%-10lu",
15551 +                               vx_sock_count(cacct, i, j),
15552 +                               vx_sock_total(cacct, i, j));
15553 +               }
15554 +               buffer[length++] = '\n';
15555 +       }
15556 +
15557 +       length += sprintf(buffer + length, "\n");
15558 +       length += sprintf(buffer + length,
15559 +               "slab:\t %8u %8u %8u %8u\n",
15560 +               atomic_read(&cacct->slab[1]),
15561 +               atomic_read(&cacct->slab[4]),
15562 +               atomic_read(&cacct->slab[0]),
15563 +               atomic_read(&cacct->slab[2]));
15564 +
15565 +       length += sprintf(buffer + length, "\n");
15566 +       for (i = 0; i < 5; i++) {
15567 +               length += sprintf(buffer + length,
15568 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
15569 +                       atomic_read(&cacct->page[i][0]),
15570 +                       atomic_read(&cacct->page[i][1]),
15571 +                       atomic_read(&cacct->page[i][2]),
15572 +                       atomic_read(&cacct->page[i][3]),
15573 +                       atomic_read(&cacct->page[i][4]),
15574 +                       atomic_read(&cacct->page[i][5]),
15575 +                       atomic_read(&cacct->page[i][6]),
15576 +                       atomic_read(&cacct->page[i][7]));
15577 +       }
15578 +       return length;
15579 +}
15580 +
15581 +#endif /* _VX_CACCT_PROC_H */
15582 diff -NurpP --minimal linux-3.9.4/kernel/vserver/context.c linux-3.9.4-vs2.3.6.1/kernel/vserver/context.c
15583 --- linux-3.9.4/kernel/vserver/context.c        1970-01-01 00:00:00.000000000 +0000
15584 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/context.c      2013-05-31 19:34:32.000000000 +0000
15585 @@ -0,0 +1,1119 @@
15586 +/*
15587 + *  linux/kernel/vserver/context.c
15588 + *
15589 + *  Virtual Server: Context Support
15590 + *
15591 + *  Copyright (C) 2003-2011  Herbert Pötzl
15592 + *
15593 + *  V0.01  context helper
15594 + *  V0.02  vx_ctx_kill syscall command
15595 + *  V0.03  replaced context_info calls
15596 + *  V0.04  redesign of struct (de)alloc
15597 + *  V0.05  rlimit basic implementation
15598 + *  V0.06  task_xid and info commands
15599 + *  V0.07  context flags and caps
15600 + *  V0.08  switch to RCU based hash
15601 + *  V0.09  revert to non RCU for now
15602 + *  V0.10  and back to working RCU hash
15603 + *  V0.11  and back to locking again
15604 + *  V0.12  referenced context store
15605 + *  V0.13  separate per cpu data
15606 + *  V0.14  changed vcmds to vxi arg
15607 + *  V0.15  added context stat
15608 + *  V0.16  have __create claim() the vxi
15609 + *  V0.17  removed older and legacy stuff
15610 + *  V0.18  added user credentials
15611 + *  V0.19  added warn mask
15612 + *
15613 + */
15614 +
15615 +#include <linux/slab.h>
15616 +#include <linux/types.h>
15617 +#include <linux/security.h>
15618 +#include <linux/pid_namespace.h>
15619 +#include <linux/capability.h>
15620 +
15621 +#include <linux/vserver/context.h>
15622 +#include <linux/vserver/network.h>
15623 +#include <linux/vserver/debug.h>
15624 +#include <linux/vserver/limit.h>
15625 +#include <linux/vserver/limit_int.h>
15626 +#include <linux/vserver/space.h>
15627 +#include <linux/init_task.h>
15628 +#include <linux/fs_struct.h>
15629 +#include <linux/cred.h>
15630 +
15631 +#include <linux/vs_context.h>
15632 +#include <linux/vs_limit.h>
15633 +#include <linux/vs_pid.h>
15634 +#include <linux/vserver/context_cmd.h>
15635 +
15636 +#include "cvirt_init.h"
15637 +#include "cacct_init.h"
15638 +#include "limit_init.h"
15639 +#include "sched_init.h"
15640 +
15641 +
15642 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
15643 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
15644 +
15645 +
15646 +/*     now inactive context structures */
15647 +
15648 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
15649 +
15650 +static DEFINE_SPINLOCK(vx_info_inactive_lock);
15651 +
15652 +
15653 +/*     __alloc_vx_info()
15654 +
15655 +       * allocate an initialized vx_info struct
15656 +       * doesn't make it visible (hash)                        */
15657 +
15658 +static struct vx_info *__alloc_vx_info(xid_t xid)
15659 +{
15660 +       struct vx_info *new = NULL;
15661 +       int cpu, index;
15662 +
15663 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
15664 +
15665 +       /* would this benefit from a slab cache? */
15666 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
15667 +       if (!new)
15668 +               return 0;
15669 +
15670 +       memset(new, 0, sizeof(struct vx_info));
15671 +#ifdef CONFIG_SMP
15672 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
15673 +       if (!new->ptr_pc)
15674 +               goto error;
15675 +#endif
15676 +       new->vx_id = xid;
15677 +       INIT_HLIST_NODE(&new->vx_hlist);
15678 +       atomic_set(&new->vx_usecnt, 0);
15679 +       atomic_set(&new->vx_tasks, 0);
15680 +       new->vx_parent = NULL;
15681 +       new->vx_state = 0;
15682 +       init_waitqueue_head(&new->vx_wait);
15683 +
15684 +       /* prepare reaper */
15685 +       get_task_struct(init_pid_ns.child_reaper);
15686 +       new->vx_reaper = init_pid_ns.child_reaper;
15687 +       new->vx_badness_bias = 0;
15688 +
15689 +       /* rest of init goes here */
15690 +       vx_info_init_limit(&new->limit);
15691 +       vx_info_init_sched(&new->sched);
15692 +       vx_info_init_cvirt(&new->cvirt);
15693 +       vx_info_init_cacct(&new->cacct);
15694 +
15695 +       /* per cpu data structures */
15696 +       for_each_possible_cpu(cpu) {
15697 +               vx_info_init_sched_pc(
15698 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
15699 +               vx_info_init_cvirt_pc(
15700 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
15701 +       }
15702 +
15703 +       new->vx_flags = VXF_INIT_SET;
15704 +       new->vx_bcaps = CAP_FULL_SET;   // maybe ~CAP_SETPCAP
15705 +       new->vx_ccaps = 0;
15706 +       new->vx_umask = 0;
15707 +       new->vx_wmask = 0;
15708 +
15709 +       new->reboot_cmd = 0;
15710 +       new->exit_code = 0;
15711 +
15712 +       // preconfig spaces
15713 +       for (index = 0; index < VX_SPACES; index++) {
15714 +               struct _vx_space *space = &new->space[index];
15715 +
15716 +               // filesystem
15717 +               spin_lock(&init_fs.lock);
15718 +               init_fs.users++;
15719 +               spin_unlock(&init_fs.lock);
15720 +               space->vx_fs = &init_fs;
15721 +
15722 +               /* FIXME: do we want defaults? */
15723 +               // space->vx_real_cred = 0;
15724 +               // space->vx_cred = 0;
15725 +       }
15726 +
15727 +
15728 +       vxdprintk(VXD_CBIT(xid, 0),
15729 +               "alloc_vx_info(%d) = %p", xid, new);
15730 +       vxh_alloc_vx_info(new);
15731 +       atomic_inc(&vx_global_ctotal);
15732 +       return new;
15733 +#ifdef CONFIG_SMP
15734 +error:
15735 +       kfree(new);
15736 +       return 0;
15737 +#endif
15738 +}
15739 +
15740 +/*     __dealloc_vx_info()
15741 +
15742 +       * final disposal of vx_info                             */
15743 +
15744 +static void __dealloc_vx_info(struct vx_info *vxi)
15745 +{
15746 +#ifdef CONFIG_VSERVER_WARN
15747 +       struct vx_info_save vxis;
15748 +       int cpu;
15749 +#endif
15750 +       vxdprintk(VXD_CBIT(xid, 0),
15751 +               "dealloc_vx_info(%p)", vxi);
15752 +       vxh_dealloc_vx_info(vxi);
15753 +
15754 +#ifdef CONFIG_VSERVER_WARN
15755 +       enter_vx_info(vxi, &vxis);
15756 +       vx_info_exit_limit(&vxi->limit);
15757 +       vx_info_exit_sched(&vxi->sched);
15758 +       vx_info_exit_cvirt(&vxi->cvirt);
15759 +       vx_info_exit_cacct(&vxi->cacct);
15760 +
15761 +       for_each_possible_cpu(cpu) {
15762 +               vx_info_exit_sched_pc(
15763 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
15764 +               vx_info_exit_cvirt_pc(
15765 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
15766 +       }
15767 +       leave_vx_info(&vxis);
15768 +#endif
15769 +
15770 +       vxi->vx_id = -1;
15771 +       vxi->vx_state |= VXS_RELEASED;
15772 +
15773 +#ifdef CONFIG_SMP
15774 +       free_percpu(vxi->ptr_pc);
15775 +#endif
15776 +       kfree(vxi);
15777 +       atomic_dec(&vx_global_ctotal);
15778 +}
15779 +
15780 +static void __shutdown_vx_info(struct vx_info *vxi)
15781 +{
15782 +       struct nsproxy *nsproxy;
15783 +       struct fs_struct *fs;
15784 +       struct cred *cred;
15785 +       int index, kill;
15786 +
15787 +       might_sleep();
15788 +
15789 +       vxi->vx_state |= VXS_SHUTDOWN;
15790 +       vs_state_change(vxi, VSC_SHUTDOWN);
15791 +
15792 +       for (index = 0; index < VX_SPACES; index++) {
15793 +               struct _vx_space *space = &vxi->space[index];
15794 +
15795 +               nsproxy = xchg(&space->vx_nsproxy, NULL);
15796 +               if (nsproxy)
15797 +                       put_nsproxy(nsproxy);
15798 +
15799 +               fs = xchg(&space->vx_fs, NULL);
15800 +               spin_lock(&fs->lock);
15801 +               kill = !--fs->users;
15802 +               spin_unlock(&fs->lock);
15803 +               if (kill)
15804 +                       free_fs_struct(fs);
15805 +
15806 +               cred = (struct cred *)xchg(&space->vx_cred, NULL);
15807 +               if (cred)
15808 +                       abort_creds(cred);
15809 +       }
15810 +}
15811 +
15812 +/* exported stuff */
15813 +
15814 +void free_vx_info(struct vx_info *vxi)
15815 +{
15816 +       unsigned long flags;
15817 +       unsigned index;
15818 +
15819 +       /* check for reference counts first */
15820 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
15821 +       BUG_ON(atomic_read(&vxi->vx_tasks));
15822 +
15823 +       /* context must not be hashed */
15824 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
15825 +
15826 +       /* context shutdown is mandatory */
15827 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
15828 +
15829 +       /* spaces check */
15830 +       for (index = 0; index < VX_SPACES; index++) {
15831 +               struct _vx_space *space = &vxi->space[index];
15832 +
15833 +               BUG_ON(space->vx_nsproxy);
15834 +               BUG_ON(space->vx_fs);
15835 +               // BUG_ON(space->vx_real_cred);
15836 +               // BUG_ON(space->vx_cred);
15837 +       }
15838 +
15839 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
15840 +       hlist_del(&vxi->vx_hlist);
15841 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
15842 +
15843 +       __dealloc_vx_info(vxi);
15844 +}
15845 +
15846 +
15847 +/*     hash table for vx_info hash */
15848 +
15849 +#define VX_HASH_SIZE   13
15850 +
15851 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
15852 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
15853 +
15854 +static DEFINE_SPINLOCK(vx_info_hash_lock);
15855 +
15856 +
15857 +static inline unsigned int __hashval(xid_t xid)
15858 +{
15859 +       return (xid % VX_HASH_SIZE);
15860 +}
15861 +
15862 +
15863 +
15864 +/*     __hash_vx_info()
15865 +
15866 +       * add the vxi to the global hash table
15867 +       * requires the hash_lock to be held                     */
15868 +
15869 +static inline void __hash_vx_info(struct vx_info *vxi)
15870 +{
15871 +       struct hlist_head *head;
15872 +
15873 +       vxd_assert_lock(&vx_info_hash_lock);
15874 +       vxdprintk(VXD_CBIT(xid, 4),
15875 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
15876 +       vxh_hash_vx_info(vxi);
15877 +
15878 +       /* context must not be hashed */
15879 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
15880 +
15881 +       vxi->vx_state |= VXS_HASHED;
15882 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
15883 +       hlist_add_head(&vxi->vx_hlist, head);
15884 +       atomic_inc(&vx_global_cactive);
15885 +}
15886 +
15887 +/*     __unhash_vx_info()
15888 +
15889 +       * remove the vxi from the global hash table
15890 +       * requires the hash_lock to be held                     */
15891 +
15892 +static inline void __unhash_vx_info(struct vx_info *vxi)
15893 +{
15894 +       unsigned long flags;
15895 +
15896 +       vxd_assert_lock(&vx_info_hash_lock);
15897 +       vxdprintk(VXD_CBIT(xid, 4),
15898 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
15899 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
15900 +       vxh_unhash_vx_info(vxi);
15901 +
15902 +       /* context must be hashed */
15903 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
15904 +       /* but without tasks */
15905 +       BUG_ON(atomic_read(&vxi->vx_tasks));
15906 +
15907 +       vxi->vx_state &= ~VXS_HASHED;
15908 +       hlist_del_init(&vxi->vx_hlist);
15909 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
15910 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
15911 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
15912 +       atomic_dec(&vx_global_cactive);
15913 +}
15914 +
15915 +
15916 +/*     __lookup_vx_info()
15917 +
15918 +       * requires the hash_lock to be held
15919 +       * doesn't increment the vx_refcnt                       */
15920 +
15921 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
15922 +{
15923 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
15924 +       struct hlist_node *pos;
15925 +       struct vx_info *vxi;
15926 +
15927 +       vxd_assert_lock(&vx_info_hash_lock);
15928 +       hlist_for_each(pos, head) {
15929 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
15930 +
15931 +               if (vxi->vx_id == xid)
15932 +                       goto found;
15933 +       }
15934 +       vxi = NULL;
15935 +found:
15936 +       vxdprintk(VXD_CBIT(xid, 0),
15937 +               "__lookup_vx_info(#%u): %p[#%u]",
15938 +               xid, vxi, vxi ? vxi->vx_id : 0);
15939 +       vxh_lookup_vx_info(vxi, xid);
15940 +       return vxi;
15941 +}
15942 +
15943 +
15944 +/*     __create_vx_info()
15945 +
15946 +       * create the requested context
15947 +       * get(), claim() and hash it                            */
15948 +
15949 +static struct vx_info *__create_vx_info(int id)
15950 +{
15951 +       struct vx_info *new, *vxi = NULL;
15952 +
15953 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
15954 +
15955 +       if (!(new = __alloc_vx_info(id)))
15956 +               return ERR_PTR(-ENOMEM);
15957 +
15958 +       /* required to make dynamic xids unique */
15959 +       spin_lock(&vx_info_hash_lock);
15960 +
15961 +       /* static context requested */
15962 +       if ((vxi = __lookup_vx_info(id))) {
15963 +               vxdprintk(VXD_CBIT(xid, 0),
15964 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
15965 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
15966 +                       vxi = ERR_PTR(-EBUSY);
15967 +               else
15968 +                       vxi = ERR_PTR(-EEXIST);
15969 +               goto out_unlock;
15970 +       }
15971 +       /* new context */
15972 +       vxdprintk(VXD_CBIT(xid, 0),
15973 +               "create_vx_info(%d) = %p (new)", id, new);
15974 +       claim_vx_info(new, NULL);
15975 +       __hash_vx_info(get_vx_info(new));
15976 +       vxi = new, new = NULL;
15977 +
15978 +out_unlock:
15979 +       spin_unlock(&vx_info_hash_lock);
15980 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
15981 +       if (new)
15982 +               __dealloc_vx_info(new);
15983 +       return vxi;
15984 +}
15985 +
15986 +
15987 +/*     exported stuff                                          */
15988 +
15989 +
15990 +void unhash_vx_info(struct vx_info *vxi)
15991 +{
15992 +       spin_lock(&vx_info_hash_lock);
15993 +       __unhash_vx_info(vxi);
15994 +       spin_unlock(&vx_info_hash_lock);
15995 +       __shutdown_vx_info(vxi);
15996 +       __wakeup_vx_info(vxi);
15997 +}
15998 +
15999 +
16000 +/*     lookup_vx_info()
16001 +
16002 +       * search for a vx_info and get() it
16003 +       * negative id means current                             */
16004 +
16005 +struct vx_info *lookup_vx_info(int id)
16006 +{
16007 +       struct vx_info *vxi = NULL;
16008 +
16009 +       if (id < 0) {
16010 +               vxi = get_vx_info(current_vx_info());
16011 +       } else if (id > 1) {
16012 +               spin_lock(&vx_info_hash_lock);
16013 +               vxi = get_vx_info(__lookup_vx_info(id));
16014 +               spin_unlock(&vx_info_hash_lock);
16015 +       }
16016 +       return vxi;
16017 +}
16018 +
16019 +/*     xid_is_hashed()
16020 +
16021 +       * verify that xid is still hashed                       */
16022 +
16023 +int xid_is_hashed(xid_t xid)
16024 +{
16025 +       int hashed;
16026 +
16027 +       spin_lock(&vx_info_hash_lock);
16028 +       hashed = (__lookup_vx_info(xid) != NULL);
16029 +       spin_unlock(&vx_info_hash_lock);
16030 +       return hashed;
16031 +}
16032 +
16033 +#ifdef CONFIG_PROC_FS
16034 +
16035 +/*     get_xid_list()
16036 +
16037 +       * get a subset of hashed xids for proc
16038 +       * assumes size is at least one                          */
16039 +
16040 +int get_xid_list(int index, unsigned int *xids, int size)
16041 +{
16042 +       int hindex, nr_xids = 0;
16043 +
16044 +       /* only show current and children */
16045 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
16046 +               if (index > 0)
16047 +                       return 0;
16048 +               xids[nr_xids] = vx_current_xid();
16049 +               return 1;
16050 +       }
16051 +
16052 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
16053 +               struct hlist_head *head = &vx_info_hash[hindex];
16054 +               struct hlist_node *pos;
16055 +
16056 +               spin_lock(&vx_info_hash_lock);
16057 +               hlist_for_each(pos, head) {
16058 +                       struct vx_info *vxi;
16059 +
16060 +                       if (--index > 0)
16061 +                               continue;
16062 +
16063 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16064 +                       xids[nr_xids] = vxi->vx_id;
16065 +                       if (++nr_xids >= size) {
16066 +                               spin_unlock(&vx_info_hash_lock);
16067 +                               goto out;
16068 +                       }
16069 +               }
16070 +               /* keep the lock time short */
16071 +               spin_unlock(&vx_info_hash_lock);
16072 +       }
16073 +out:
16074 +       return nr_xids;
16075 +}
16076 +#endif
16077 +
16078 +#ifdef CONFIG_VSERVER_DEBUG
16079 +
16080 +void   dump_vx_info_inactive(int level)
16081 +{
16082 +       struct hlist_node *entry, *next;
16083 +
16084 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
16085 +               struct vx_info *vxi =
16086 +                       list_entry(entry, struct vx_info, vx_hlist);
16087 +
16088 +               dump_vx_info(vxi, level);
16089 +       }
16090 +}
16091 +
16092 +#endif
16093 +
16094 +#if 0
16095 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
16096 +{
16097 +       struct user_struct *new_user, *old_user;
16098 +
16099 +       if (!p || !vxi)
16100 +               BUG();
16101 +
16102 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
16103 +               return -EACCES;
16104 +
16105 +       new_user = alloc_uid(vxi->vx_id, p->uid);
16106 +       if (!new_user)
16107 +               return -ENOMEM;
16108 +
16109 +       old_user = p->user;
16110 +       if (new_user != old_user) {
16111 +               atomic_inc(&new_user->processes);
16112 +               atomic_dec(&old_user->processes);
16113 +               p->user = new_user;
16114 +       }
16115 +       free_uid(old_user);
16116 +       return 0;
16117 +}
16118 +#endif
16119 +
16120 +#if 0
16121 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
16122 +{
16123 +       // p->cap_effective &= vxi->vx_cap_bset;
16124 +       p->cap_effective =
16125 +               cap_intersect(p->cap_effective, vxi->cap_bset);
16126 +       // p->cap_inheritable &= vxi->vx_cap_bset;
16127 +       p->cap_inheritable =
16128 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
16129 +       // p->cap_permitted &= vxi->vx_cap_bset;
16130 +       p->cap_permitted =
16131 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
16132 +}
16133 +#endif
16134 +
16135 +
16136 +#include <linux/file.h>
16137 +#include <linux/fdtable.h>
16138 +
16139 +static int vx_openfd_task(struct task_struct *tsk)
16140 +{
16141 +       struct files_struct *files = tsk->files;
16142 +       struct fdtable *fdt;
16143 +       const unsigned long *bptr;
16144 +       int count, total;
16145 +
16146 +       /* no rcu_read_lock() because of spin_lock() */
16147 +       spin_lock(&files->file_lock);
16148 +       fdt = files_fdtable(files);
16149 +       bptr = fdt->open_fds;
16150 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
16151 +       for (total = 0; count > 0; count--) {
16152 +               if (*bptr)
16153 +                       total += hweight_long(*bptr);
16154 +               bptr++;
16155 +       }
16156 +       spin_unlock(&files->file_lock);
16157 +       return total;
16158 +}
16159 +
16160 +
16161 +/*     for *space compatibility */
16162 +
16163 +asmlinkage long sys_unshare(unsigned long);
16164 +
16165 +/*
16166 + *     migrate task to new context
16167 + *     gets vxi, puts old_vxi on change
16168 + *     optionally unshares namespaces (hack)
16169 + */
16170 +
16171 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
16172 +{
16173 +       struct vx_info *old_vxi;
16174 +       int ret = 0;
16175 +
16176 +       if (!p || !vxi)
16177 +               BUG();
16178 +
16179 +       vxdprintk(VXD_CBIT(xid, 5),
16180 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
16181 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
16182 +
16183 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
16184 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16185 +               return -EACCES;
16186 +
16187 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
16188 +               return -EFAULT;
16189 +
16190 +       old_vxi = task_get_vx_info(p);
16191 +       if (old_vxi == vxi)
16192 +               goto out;
16193 +
16194 +//     if (!(ret = vx_migrate_user(p, vxi))) {
16195 +       {
16196 +               int openfd;
16197 +
16198 +               task_lock(p);
16199 +               openfd = vx_openfd_task(p);
16200 +
16201 +               if (old_vxi) {
16202 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
16203 +                       atomic_dec(&old_vxi->cvirt.nr_running);
16204 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
16205 +                       /* FIXME: what about the struct files here? */
16206 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
16207 +                       /* account for the executable */
16208 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
16209 +               }
16210 +               atomic_inc(&vxi->cvirt.nr_threads);
16211 +               atomic_inc(&vxi->cvirt.nr_running);
16212 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
16213 +               /* FIXME: what about the struct files here? */
16214 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
16215 +               /* account for the executable */
16216 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
16217 +
16218 +               if (old_vxi) {
16219 +                       release_vx_info(old_vxi, p);
16220 +                       clr_vx_info(&p->vx_info);
16221 +               }
16222 +               claim_vx_info(vxi, p);
16223 +               set_vx_info(&p->vx_info, vxi);
16224 +               p->xid = vxi->vx_id;
16225 +
16226 +               vxdprintk(VXD_CBIT(xid, 5),
16227 +                       "moved task %p into vxi:%p[#%d]",
16228 +                       p, vxi, vxi->vx_id);
16229 +
16230 +               // vx_mask_cap_bset(vxi, p);
16231 +               task_unlock(p);
16232 +
16233 +               /* hack for *spaces to provide compatibility */
16234 +               if (unshare) {
16235 +                       struct nsproxy *old_nsp, *new_nsp;
16236 +
16237 +                       ret = unshare_nsproxy_namespaces(
16238 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
16239 +                               &new_nsp, NULL, NULL);
16240 +                       if (ret)
16241 +                               goto out;
16242 +
16243 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
16244 +                       vx_set_space(vxi,
16245 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
16246 +                       put_nsproxy(old_nsp);
16247 +               }
16248 +       }
16249 +out:
16250 +       put_vx_info(old_vxi);
16251 +       return ret;
16252 +}
16253 +
16254 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
16255 +{
16256 +       struct task_struct *old_reaper;
16257 +       struct vx_info *reaper_vxi;
16258 +
16259 +       if (!vxi)
16260 +               return -EINVAL;
16261 +
16262 +       vxdprintk(VXD_CBIT(xid, 6),
16263 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
16264 +               vxi, vxi->vx_id, p, p->xid, p->pid);
16265 +
16266 +       old_reaper = vxi->vx_reaper;
16267 +       if (old_reaper == p)
16268 +               return 0;
16269 +
16270 +       reaper_vxi = task_get_vx_info(p);
16271 +       if (reaper_vxi && reaper_vxi != vxi) {
16272 +               vxwprintk(1,
16273 +                       "Unsuitable reaper [" VS_Q("%s") ",%u:#%u] "
16274 +                       "for [xid #%u]",
16275 +                       p->comm, p->pid, p->xid, vx_current_xid());
16276 +               goto out;
16277 +       }
16278 +
16279 +       /* set new child reaper */
16280 +       get_task_struct(p);
16281 +       vxi->vx_reaper = p;
16282 +       put_task_struct(old_reaper);
16283 +out:
16284 +       put_vx_info(reaper_vxi);
16285 +       return 0;
16286 +}
16287 +
16288 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
16289 +{
16290 +       if (!vxi)
16291 +               return -EINVAL;
16292 +
16293 +       vxdprintk(VXD_CBIT(xid, 6),
16294 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
16295 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16296 +
16297 +       vxi->vx_flags &= ~VXF_STATE_INIT;
16298 +       // vxi->vx_initpid = p->tgid;
16299 +       vxi->vx_initpid = p->pid;
16300 +       return 0;
16301 +}
16302 +
16303 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
16304 +{
16305 +       vxdprintk(VXD_CBIT(xid, 6),
16306 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
16307 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16308 +
16309 +       vxi->exit_code = code;
16310 +       vxi->vx_initpid = 0;
16311 +}
16312 +
16313 +
16314 +void vx_set_persistent(struct vx_info *vxi)
16315 +{
16316 +       vxdprintk(VXD_CBIT(xid, 6),
16317 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
16318 +
16319 +       get_vx_info(vxi);
16320 +       claim_vx_info(vxi, NULL);
16321 +}
16322 +
16323 +void vx_clear_persistent(struct vx_info *vxi)
16324 +{
16325 +       vxdprintk(VXD_CBIT(xid, 6),
16326 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
16327 +
16328 +       release_vx_info(vxi, NULL);
16329 +       put_vx_info(vxi);
16330 +}
16331 +
16332 +void vx_update_persistent(struct vx_info *vxi)
16333 +{
16334 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
16335 +               vx_set_persistent(vxi);
16336 +       else
16337 +               vx_clear_persistent(vxi);
16338 +}
16339 +
16340 +
16341 +/*     task must be current or locked          */
16342 +
16343 +void   exit_vx_info(struct task_struct *p, int code)
16344 +{
16345 +       struct vx_info *vxi = p->vx_info;
16346 +
16347 +       if (vxi) {
16348 +               atomic_dec(&vxi->cvirt.nr_threads);
16349 +               vx_nproc_dec(p);
16350 +
16351 +               vxi->exit_code = code;
16352 +               release_vx_info(vxi, p);
16353 +       }
16354 +}
16355 +
16356 +void   exit_vx_info_early(struct task_struct *p, int code)
16357 +{
16358 +       struct vx_info *vxi = p->vx_info;
16359 +
16360 +       if (vxi) {
16361 +               if (vxi->vx_initpid == p->pid)
16362 +                       vx_exit_init(vxi, p, code);
16363 +               if (vxi->vx_reaper == p)
16364 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
16365 +       }
16366 +}
16367 +
16368 +
16369 +/* vserver syscall commands below here */
16370 +
16371 +/* taks xid and vx_info functions */
16372 +
16373 +#include <asm/uaccess.h>
16374 +
16375 +
16376 +int vc_task_xid(uint32_t id)
16377 +{
16378 +       xid_t xid;
16379 +
16380 +       if (id) {
16381 +               struct task_struct *tsk;
16382 +
16383 +               rcu_read_lock();
16384 +               tsk = find_task_by_real_pid(id);
16385 +               xid = (tsk) ? tsk->xid : -ESRCH;
16386 +               rcu_read_unlock();
16387 +       } else
16388 +               xid = vx_current_xid();
16389 +       return xid;
16390 +}
16391 +
16392 +
16393 +int vc_vx_info(struct vx_info *vxi, void __user *data)
16394 +{
16395 +       struct vcmd_vx_info_v0 vc_data;
16396 +
16397 +       vc_data.xid = vxi->vx_id;
16398 +       vc_data.initpid = vxi->vx_initpid;
16399 +
16400 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16401 +               return -EFAULT;
16402 +       return 0;
16403 +}
16404 +
16405 +
16406 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
16407 +{
16408 +       struct vcmd_ctx_stat_v0 vc_data;
16409 +
16410 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
16411 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
16412 +
16413 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16414 +               return -EFAULT;
16415 +       return 0;
16416 +}
16417 +
16418 +
16419 +/* context functions */
16420 +
16421 +int vc_ctx_create(uint32_t xid, void __user *data)
16422 +{
16423 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
16424 +       struct vx_info *new_vxi;
16425 +       int ret;
16426 +
16427 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16428 +               return -EFAULT;
16429 +
16430 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
16431 +               return -EINVAL;
16432 +
16433 +       new_vxi = __create_vx_info(xid);
16434 +       if (IS_ERR(new_vxi))
16435 +               return PTR_ERR(new_vxi);
16436 +
16437 +       /* initial flags */
16438 +       new_vxi->vx_flags = vc_data.flagword;
16439 +
16440 +       ret = -ENOEXEC;
16441 +       if (vs_state_change(new_vxi, VSC_STARTUP))
16442 +               goto out;
16443 +
16444 +       ret = vx_migrate_task(current, new_vxi, (!data));
16445 +       if (ret)
16446 +               goto out;
16447 +
16448 +       /* return context id on success */
16449 +       ret = new_vxi->vx_id;
16450 +
16451 +       /* get a reference for persistent contexts */
16452 +       if ((vc_data.flagword & VXF_PERSISTENT))
16453 +               vx_set_persistent(new_vxi);
16454 +out:
16455 +       release_vx_info(new_vxi, NULL);
16456 +       put_vx_info(new_vxi);
16457 +       return ret;
16458 +}
16459 +
16460 +
16461 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
16462 +{
16463 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
16464 +       int ret;
16465 +
16466 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16467 +               return -EFAULT;
16468 +
16469 +       ret = vx_migrate_task(current, vxi, 0);
16470 +       if (ret)
16471 +               return ret;
16472 +       if (vc_data.flagword & VXM_SET_INIT)
16473 +               ret = vx_set_init(vxi, current);
16474 +       if (ret)
16475 +               return ret;
16476 +       if (vc_data.flagword & VXM_SET_REAPER)
16477 +               ret = vx_set_reaper(vxi, current);
16478 +       return ret;
16479 +}
16480 +
16481 +
16482 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
16483 +{
16484 +       struct vcmd_ctx_flags_v0 vc_data;
16485 +
16486 +       vc_data.flagword = vxi->vx_flags;
16487 +
16488 +       /* special STATE flag handling */
16489 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
16490 +
16491 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16492 +               return -EFAULT;
16493 +       return 0;
16494 +}
16495 +
16496 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
16497 +{
16498 +       struct vcmd_ctx_flags_v0 vc_data;
16499 +       uint64_t mask, trigger;
16500 +
16501 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16502 +               return -EFAULT;
16503 +
16504 +       /* special STATE flag handling */
16505 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
16506 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
16507 +
16508 +       if (vxi == current_vx_info()) {
16509 +               /* if (trigger & VXF_STATE_SETUP)
16510 +                       vx_mask_cap_bset(vxi, current); */
16511 +               if (trigger & VXF_STATE_INIT) {
16512 +                       int ret;
16513 +
16514 +                       ret = vx_set_init(vxi, current);
16515 +                       if (ret)
16516 +                               return ret;
16517 +                       ret = vx_set_reaper(vxi, current);
16518 +                       if (ret)
16519 +                               return ret;
16520 +               }
16521 +       }
16522 +
16523 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
16524 +               vc_data.flagword, mask);
16525 +       if (trigger & VXF_PERSISTENT)
16526 +               vx_update_persistent(vxi);
16527 +
16528 +       return 0;
16529 +}
16530 +
16531 +
16532 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
16533 +{
16534 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
16535 +
16536 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
16537 +       return v;
16538 +}
16539 +
16540 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
16541 +{
16542 +       kernel_cap_t c = __cap_empty_set;
16543 +
16544 +       c.cap[0] = v & 0xFFFFFFFF;
16545 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
16546 +
16547 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
16548 +       return c;
16549 +}
16550 +
16551 +
16552 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
16553 +{
16554 +       if (bcaps)
16555 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
16556 +       if (ccaps)
16557 +               *ccaps = vxi->vx_ccaps;
16558 +
16559 +       return 0;
16560 +}
16561 +
16562 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
16563 +{
16564 +       struct vcmd_ctx_caps_v1 vc_data;
16565 +       int ret;
16566 +
16567 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
16568 +       if (ret)
16569 +               return ret;
16570 +       vc_data.cmask = ~0ULL;
16571 +
16572 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16573 +               return -EFAULT;
16574 +       return 0;
16575 +}
16576 +
16577 +static int do_set_caps(struct vx_info *vxi,
16578 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
16579 +{
16580 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
16581 +
16582 +#if 0
16583 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
16584 +               bcaps, bmask, ccaps, cmask);
16585 +#endif
16586 +       vxi->vx_bcaps = cap_t_from_caps(
16587 +               vs_mask_flags(bcold, bcaps, bmask));
16588 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
16589 +
16590 +       return 0;
16591 +}
16592 +
16593 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
16594 +{
16595 +       struct vcmd_ctx_caps_v1 vc_data;
16596 +
16597 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16598 +               return -EFAULT;
16599 +
16600 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
16601 +}
16602 +
16603 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
16604 +{
16605 +       struct vcmd_bcaps vc_data;
16606 +       int ret;
16607 +
16608 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
16609 +       if (ret)
16610 +               return ret;
16611 +       vc_data.bmask = ~0ULL;
16612 +
16613 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16614 +               return -EFAULT;
16615 +       return 0;
16616 +}
16617 +
16618 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
16619 +{
16620 +       struct vcmd_bcaps vc_data;
16621 +
16622 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16623 +               return -EFAULT;
16624 +
16625 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
16626 +}
16627 +
16628 +
16629 +int vc_get_umask(struct vx_info *vxi, void __user *data)
16630 +{
16631 +       struct vcmd_umask vc_data;
16632 +
16633 +       vc_data.umask = vxi->vx_umask;
16634 +       vc_data.mask = ~0ULL;
16635 +
16636 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16637 +               return -EFAULT;
16638 +       return 0;
16639 +}
16640 +
16641 +int vc_set_umask(struct vx_info *vxi, void __user *data)
16642 +{
16643 +       struct vcmd_umask vc_data;
16644 +
16645 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16646 +               return -EFAULT;
16647 +
16648 +       vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
16649 +               vc_data.umask, vc_data.mask);
16650 +       return 0;
16651 +}
16652 +
16653 +
16654 +int vc_get_wmask(struct vx_info *vxi, void __user *data)
16655 +{
16656 +       struct vcmd_wmask vc_data;
16657 +
16658 +       vc_data.wmask = vxi->vx_wmask;
16659 +       vc_data.mask = ~0ULL;
16660 +
16661 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16662 +               return -EFAULT;
16663 +       return 0;
16664 +}
16665 +
16666 +int vc_set_wmask(struct vx_info *vxi, void __user *data)
16667 +{
16668 +       struct vcmd_wmask vc_data;
16669 +
16670 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16671 +               return -EFAULT;
16672 +
16673 +       vxi->vx_wmask = vs_mask_flags(vxi->vx_wmask,
16674 +               vc_data.wmask, vc_data.mask);
16675 +       return 0;
16676 +}
16677 +
16678 +
16679 +int vc_get_badness(struct vx_info *vxi, void __user *data)
16680 +{
16681 +       struct vcmd_badness_v0 vc_data;
16682 +
16683 +       vc_data.bias = vxi->vx_badness_bias;
16684 +
16685 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16686 +               return -EFAULT;
16687 +       return 0;
16688 +}
16689 +
16690 +int vc_set_badness(struct vx_info *vxi, void __user *data)
16691 +{
16692 +       struct vcmd_badness_v0 vc_data;
16693 +
16694 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16695 +               return -EFAULT;
16696 +
16697 +       vxi->vx_badness_bias = vc_data.bias;
16698 +       return 0;
16699 +}
16700 +
16701 +#include <linux/module.h>
16702 +
16703 +EXPORT_SYMBOL_GPL(free_vx_info);
16704 +
16705 diff -NurpP --minimal linux-3.9.4/kernel/vserver/cvirt.c linux-3.9.4-vs2.3.6.1/kernel/vserver/cvirt.c
16706 --- linux-3.9.4/kernel/vserver/cvirt.c  1970-01-01 00:00:00.000000000 +0000
16707 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/cvirt.c        2013-05-31 14:47:11.000000000 +0000
16708 @@ -0,0 +1,313 @@
16709 +/*
16710 + *  linux/kernel/vserver/cvirt.c
16711 + *
16712 + *  Virtual Server: Context Virtualization
16713 + *
16714 + *  Copyright (C) 2004-2007  Herbert Pötzl
16715 + *
16716 + *  V0.01  broken out from limit.c
16717 + *  V0.02  added utsname stuff
16718 + *  V0.03  changed vcmds to vxi arg
16719 + *
16720 + */
16721 +
16722 +#include <linux/types.h>
16723 +#include <linux/utsname.h>
16724 +#include <linux/vs_cvirt.h>
16725 +#include <linux/vserver/switch.h>
16726 +#include <linux/vserver/cvirt_cmd.h>
16727 +
16728 +#include <asm/uaccess.h>
16729 +
16730 +
16731 +void vx_vsi_boottime(struct timespec *boottime)
16732 +{
16733 +       struct vx_info *vxi = current_vx_info();
16734 +
16735 +       set_normalized_timespec(boottime,
16736 +               boottime->tv_sec + vxi->cvirt.bias_uptime.tv_sec,
16737 +               boottime->tv_nsec + vxi->cvirt.bias_uptime.tv_nsec);
16738 +       return;
16739 +}
16740 +
16741 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
16742 +{
16743 +       struct vx_info *vxi = current_vx_info();
16744 +
16745 +       set_normalized_timespec(uptime,
16746 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
16747 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
16748 +       if (!idle)
16749 +               return;
16750 +       set_normalized_timespec(idle,
16751 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
16752 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
16753 +       return;
16754 +}
16755 +
16756 +uint64_t vx_idle_jiffies(void)
16757 +{
16758 +       return init_task.utime + init_task.stime;
16759 +}
16760 +
16761 +
16762 +
16763 +static inline uint32_t __update_loadavg(uint32_t load,
16764 +       int wsize, int delta, int n)
16765 +{
16766 +       unsigned long long calc, prev;
16767 +
16768 +       /* just set it to n */
16769 +       if (unlikely(delta >= wsize))
16770 +               return (n << FSHIFT);
16771 +
16772 +       calc = delta * n;
16773 +       calc <<= FSHIFT;
16774 +       prev = (wsize - delta);
16775 +       prev *= load;
16776 +       calc += prev;
16777 +       do_div(calc, wsize);
16778 +       return calc;
16779 +}
16780 +
16781 +
16782 +void vx_update_load(struct vx_info *vxi)
16783 +{
16784 +       uint32_t now, last, delta;
16785 +       unsigned int nr_running, nr_uninterruptible;
16786 +       unsigned int total;
16787 +       unsigned long flags;
16788 +
16789 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
16790 +
16791 +       now = jiffies;
16792 +       last = vxi->cvirt.load_last;
16793 +       delta = now - last;
16794 +
16795 +       if (delta < 5*HZ)
16796 +               goto out;
16797 +
16798 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
16799 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
16800 +       total = nr_running + nr_uninterruptible;
16801 +
16802 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
16803 +               60*HZ, delta, total);
16804 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
16805 +               5*60*HZ, delta, total);
16806 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
16807 +               15*60*HZ, delta, total);
16808 +
16809 +       vxi->cvirt.load_last = now;
16810 +out:
16811 +       atomic_inc(&vxi->cvirt.load_updates);
16812 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
16813 +}
16814 +
16815 +
16816 +/*
16817 + * Commands to do_syslog:
16818 + *
16819 + *      0 -- Close the log.  Currently a NOP.
16820 + *      1 -- Open the log. Currently a NOP.
16821 + *      2 -- Read from the log.
16822 + *      3 -- Read all messages remaining in the ring buffer.
16823 + *      4 -- Read and clear all messages remaining in the ring buffer
16824 + *      5 -- Clear ring buffer.
16825 + *      6 -- Disable printk's to console
16826 + *      7 -- Enable printk's to console
16827 + *      8 -- Set level of messages printed to console
16828 + *      9 -- Return number of unread characters in the log buffer
16829 + *     10 -- Return size of the log buffer
16830 + */
16831 +int vx_do_syslog(int type, char __user *buf, int len)
16832 +{
16833 +       int error = 0;
16834 +       int do_clear = 0;
16835 +       struct vx_info *vxi = current_vx_info();
16836 +       struct _vx_syslog *log;
16837 +
16838 +       if (!vxi)
16839 +               return -EINVAL;
16840 +       log = &vxi->cvirt.syslog;
16841 +
16842 +       switch (type) {
16843 +       case 0:         /* Close log */
16844 +       case 1:         /* Open log */
16845 +               break;
16846 +       case 2:         /* Read from log */
16847 +               error = wait_event_interruptible(log->log_wait,
16848 +                       (log->log_start - log->log_end));
16849 +               if (error)
16850 +                       break;
16851 +               spin_lock_irq(&log->logbuf_lock);
16852 +               spin_unlock_irq(&log->logbuf_lock);
16853 +               break;
16854 +       case 4:         /* Read/clear last kernel messages */
16855 +               do_clear = 1;
16856 +               /* fall through */
16857 +       case 3:         /* Read last kernel messages */
16858 +               return 0;
16859 +
16860 +       case 5:         /* Clear ring buffer */
16861 +               return 0;
16862 +
16863 +       case 6:         /* Disable logging to console */
16864 +       case 7:         /* Enable logging to console */
16865 +       case 8:         /* Set level of messages printed to console */
16866 +               break;
16867 +
16868 +       case 9:         /* Number of chars in the log buffer */
16869 +               return 0;
16870 +       case 10:        /* Size of the log buffer */
16871 +               return 0;
16872 +       default:
16873 +               error = -EINVAL;
16874 +               break;
16875 +       }
16876 +       return error;
16877 +}
16878 +
16879 +
16880 +/* virtual host info names */
16881 +
16882 +static char *vx_vhi_name(struct vx_info *vxi, int id)
16883 +{
16884 +       struct nsproxy *nsproxy;
16885 +       struct uts_namespace *uts;
16886 +
16887 +       if (id == VHIN_CONTEXT)
16888 +               return vxi->vx_name;
16889 +
16890 +       nsproxy = vxi->space[0].vx_nsproxy;
16891 +       if (!nsproxy)
16892 +               return NULL;
16893 +
16894 +       uts = nsproxy->uts_ns;
16895 +       if (!uts)
16896 +               return NULL;
16897 +
16898 +       switch (id) {
16899 +       case VHIN_SYSNAME:
16900 +               return uts->name.sysname;
16901 +       case VHIN_NODENAME:
16902 +               return uts->name.nodename;
16903 +       case VHIN_RELEASE:
16904 +               return uts->name.release;
16905 +       case VHIN_VERSION:
16906 +               return uts->name.version;
16907 +       case VHIN_MACHINE:
16908 +               return uts->name.machine;
16909 +       case VHIN_DOMAINNAME:
16910 +               return uts->name.domainname;
16911 +       default:
16912 +               return NULL;
16913 +       }
16914 +       return NULL;
16915 +}
16916 +
16917 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
16918 +{
16919 +       struct vcmd_vhi_name_v0 vc_data;
16920 +       char *name;
16921 +
16922 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16923 +               return -EFAULT;
16924 +
16925 +       name = vx_vhi_name(vxi, vc_data.field);
16926 +       if (!name)
16927 +               return -EINVAL;
16928 +
16929 +       memcpy(name, vc_data.name, 65);
16930 +       return 0;
16931 +}
16932 +
16933 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
16934 +{
16935 +       struct vcmd_vhi_name_v0 vc_data;
16936 +       char *name;
16937 +
16938 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16939 +               return -EFAULT;
16940 +
16941 +       name = vx_vhi_name(vxi, vc_data.field);
16942 +       if (!name)
16943 +               return -EINVAL;
16944 +
16945 +       memcpy(vc_data.name, name, 65);
16946 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16947 +               return -EFAULT;
16948 +       return 0;
16949 +}
16950 +
16951 +
16952 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
16953 +{
16954 +       struct vcmd_virt_stat_v0 vc_data;
16955 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
16956 +       struct timespec uptime;
16957 +
16958 +       do_posix_clock_monotonic_gettime(&uptime);
16959 +       set_normalized_timespec(&uptime,
16960 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
16961 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
16962 +
16963 +       vc_data.offset = timespec_to_ns(&cvirt->bias_ts);
16964 +       vc_data.uptime = timespec_to_ns(&uptime);
16965 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
16966 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
16967 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
16968 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
16969 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
16970 +       vc_data.load[0] = cvirt->load[0];
16971 +       vc_data.load[1] = cvirt->load[1];
16972 +       vc_data.load[2] = cvirt->load[2];
16973 +
16974 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16975 +               return -EFAULT;
16976 +       return 0;
16977 +}
16978 +
16979 +
16980 +#ifdef CONFIG_VSERVER_VTIME
16981 +
16982 +/* virtualized time base */
16983 +
16984 +void vx_adjust_timespec(struct timespec *ts)
16985 +{
16986 +       struct vx_info *vxi;
16987 +
16988 +       if (!vx_flags(VXF_VIRT_TIME, 0))
16989 +               return;
16990 +
16991 +       vxi = current_vx_info();
16992 +       ts->tv_sec += vxi->cvirt.bias_ts.tv_sec;
16993 +       ts->tv_nsec += vxi->cvirt.bias_ts.tv_nsec;
16994 +
16995 +       if (ts->tv_nsec >= NSEC_PER_SEC) {
16996 +               ts->tv_sec++;
16997 +               ts->tv_nsec -= NSEC_PER_SEC;
16998 +       } else if (ts->tv_nsec < 0) {
16999 +               ts->tv_sec--;
17000 +               ts->tv_nsec += NSEC_PER_SEC;
17001 +       }
17002 +}
17003 +
17004 +int vx_settimeofday(const struct timespec *ts)
17005 +{
17006 +       struct timespec ats, delta;
17007 +       struct vx_info *vxi;
17008 +
17009 +       if (!vx_flags(VXF_VIRT_TIME, 0))
17010 +               return do_settimeofday(ts);
17011 +
17012 +       getnstimeofday(&ats);
17013 +       delta = timespec_sub(*ts, ats);
17014 +
17015 +       vxi = current_vx_info();
17016 +       vxi->cvirt.bias_ts = timespec_add(vxi->cvirt.bias_ts, delta);
17017 +       return 0;
17018 +}
17019 +
17020 +#endif
17021 +
17022 diff -NurpP --minimal linux-3.9.4/kernel/vserver/cvirt_init.h linux-3.9.4-vs2.3.6.1/kernel/vserver/cvirt_init.h
17023 --- linux-3.9.4/kernel/vserver/cvirt_init.h     1970-01-01 00:00:00.000000000 +0000
17024 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/cvirt_init.h   2013-05-31 14:47:11.000000000 +0000
17025 @@ -0,0 +1,70 @@
17026 +
17027 +
17028 +extern uint64_t vx_idle_jiffies(void);
17029 +
17030 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
17031 +{
17032 +       uint64_t idle_jiffies = vx_idle_jiffies();
17033 +       uint64_t nsuptime;
17034 +
17035 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
17036 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
17037 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
17038 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
17039 +       cvirt->bias_ts.tv_sec = 0;
17040 +       cvirt->bias_ts.tv_nsec = 0;
17041 +
17042 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
17043 +       atomic_set(&cvirt->nr_threads, 0);
17044 +       atomic_set(&cvirt->nr_running, 0);
17045 +       atomic_set(&cvirt->nr_uninterruptible, 0);
17046 +       atomic_set(&cvirt->nr_onhold, 0);
17047 +
17048 +       spin_lock_init(&cvirt->load_lock);
17049 +       cvirt->load_last = jiffies;
17050 +       atomic_set(&cvirt->load_updates, 0);
17051 +       cvirt->load[0] = 0;
17052 +       cvirt->load[1] = 0;
17053 +       cvirt->load[2] = 0;
17054 +       atomic_set(&cvirt->total_forks, 0);
17055 +
17056 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
17057 +       init_waitqueue_head(&cvirt->syslog.log_wait);
17058 +       cvirt->syslog.log_start = 0;
17059 +       cvirt->syslog.log_end = 0;
17060 +       cvirt->syslog.con_start = 0;
17061 +       cvirt->syslog.logged_chars = 0;
17062 +}
17063 +
17064 +static inline
17065 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17066 +{
17067 +       // cvirt_pc->cpustat = { 0 };
17068 +}
17069 +
17070 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
17071 +{
17072 +#ifdef CONFIG_VSERVER_WARN
17073 +       int value;
17074 +#endif
17075 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
17076 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
17077 +               cvirt, value);
17078 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
17079 +               "!!! cvirt: %p[nr_running] = %d on exit.",
17080 +               cvirt, value);
17081 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
17082 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
17083 +               cvirt, value);
17084 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
17085 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
17086 +               cvirt, value);
17087 +       return;
17088 +}
17089 +
17090 +static inline
17091 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17092 +{
17093 +       return;
17094 +}
17095 +
17096 diff -NurpP --minimal linux-3.9.4/kernel/vserver/cvirt_proc.h linux-3.9.4-vs2.3.6.1/kernel/vserver/cvirt_proc.h
17097 --- linux-3.9.4/kernel/vserver/cvirt_proc.h     1970-01-01 00:00:00.000000000 +0000
17098 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/cvirt_proc.h   2013-05-31 19:38:26.000000000 +0000
17099 @@ -0,0 +1,123 @@
17100 +#ifndef _VX_CVIRT_PROC_H
17101 +#define _VX_CVIRT_PROC_H
17102 +
17103 +#include <linux/nsproxy.h>
17104 +#include <linux/mnt_namespace.h>
17105 +#include <linux/ipc_namespace.h>
17106 +#include <linux/utsname.h>
17107 +#include <linux/ipc.h>
17108 +
17109 +extern int vx_info_mnt_namespace(struct mnt_namespace *, char *);
17110 +
17111 +static inline
17112 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
17113 +{
17114 +       struct mnt_namespace *ns;
17115 +       struct uts_namespace *uts;
17116 +       struct ipc_namespace *ipc;
17117 +       int length = 0;
17118 +
17119 +       if (!nsproxy)
17120 +               goto out;
17121 +
17122 +       length += sprintf(buffer + length,
17123 +               "NSProxy:\t%p [%p,%p,%p]\n",
17124 +               nsproxy, nsproxy->mnt_ns,
17125 +               nsproxy->uts_ns, nsproxy->ipc_ns);
17126 +
17127 +       ns = nsproxy->mnt_ns;
17128 +       if (!ns)
17129 +               goto skip_ns;
17130 +
17131 +       length += vx_info_mnt_namespace(ns, buffer + length);
17132 +
17133 +skip_ns:
17134 +
17135 +       uts = nsproxy->uts_ns;
17136 +       if (!uts)
17137 +               goto skip_uts;
17138 +
17139 +       length += sprintf(buffer + length,
17140 +               "SysName:\t%.*s\n"
17141 +               "NodeName:\t%.*s\n"
17142 +               "Release:\t%.*s\n"
17143 +               "Version:\t%.*s\n"
17144 +               "Machine:\t%.*s\n"
17145 +               "DomainName:\t%.*s\n",
17146 +               __NEW_UTS_LEN, uts->name.sysname,
17147 +               __NEW_UTS_LEN, uts->name.nodename,
17148 +               __NEW_UTS_LEN, uts->name.release,
17149 +               __NEW_UTS_LEN, uts->name.version,
17150 +               __NEW_UTS_LEN, uts->name.machine,
17151 +               __NEW_UTS_LEN, uts->name.domainname);
17152 +skip_uts:
17153 +
17154 +       ipc = nsproxy->ipc_ns;
17155 +       if (!ipc)
17156 +               goto skip_ipc;
17157 +
17158 +       length += sprintf(buffer + length,
17159 +               "SEMS:\t\t%d %d %d %d  %d\n"
17160 +               "MSG:\t\t%d %d %d\n"
17161 +               "SHM:\t\t%lu %lu  %d %ld\n",
17162 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
17163 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
17164 +               ipc->used_sems,
17165 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
17166 +               (unsigned long)ipc->shm_ctlmax,
17167 +               (unsigned long)ipc->shm_ctlall,
17168 +               ipc->shm_ctlmni, ipc->shm_tot);
17169 +skip_ipc:
17170 +out:
17171 +       return length;
17172 +}
17173 +
17174 +
17175 +#include <linux/sched.h>
17176 +
17177 +#define LOAD_INT(x) ((x) >> FSHIFT)
17178 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
17179 +
17180 +static inline
17181 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
17182 +{
17183 +       int length = 0;
17184 +       int a, b, c;
17185 +
17186 +       length += sprintf(buffer + length,
17187 +               "BiasUptime:\t%lu.%02lu\n",
17188 +               (unsigned long)cvirt->bias_uptime.tv_sec,
17189 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
17190 +
17191 +       a = cvirt->load[0] + (FIXED_1 / 200);
17192 +       b = cvirt->load[1] + (FIXED_1 / 200);
17193 +       c = cvirt->load[2] + (FIXED_1 / 200);
17194 +       length += sprintf(buffer + length,
17195 +               "nr_threads:\t%d\n"
17196 +               "nr_running:\t%d\n"
17197 +               "nr_unintr:\t%d\n"
17198 +               "nr_onhold:\t%d\n"
17199 +               "load_updates:\t%d\n"
17200 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
17201 +               "total_forks:\t%d\n",
17202 +               atomic_read(&cvirt->nr_threads),
17203 +               atomic_read(&cvirt->nr_running),
17204 +               atomic_read(&cvirt->nr_uninterruptible),
17205 +               atomic_read(&cvirt->nr_onhold),
17206 +               atomic_read(&cvirt->load_updates),
17207 +               LOAD_INT(a), LOAD_FRAC(a),
17208 +               LOAD_INT(b), LOAD_FRAC(b),
17209 +               LOAD_INT(c), LOAD_FRAC(c),
17210 +               atomic_read(&cvirt->total_forks));
17211 +       return length;
17212 +}
17213 +
17214 +static inline
17215 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
17216 +       char *buffer, int cpu)
17217 +{
17218 +       int length = 0;
17219 +       return length;
17220 +}
17221 +
17222 +#endif /* _VX_CVIRT_PROC_H */
17223 diff -NurpP --minimal linux-3.9.4/kernel/vserver/debug.c linux-3.9.4-vs2.3.6.1/kernel/vserver/debug.c
17224 --- linux-3.9.4/kernel/vserver/debug.c  1970-01-01 00:00:00.000000000 +0000
17225 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/debug.c        2013-05-31 14:47:11.000000000 +0000
17226 @@ -0,0 +1,32 @@
17227 +/*
17228 + *  kernel/vserver/debug.c
17229 + *
17230 + *  Copyright (C) 2005-2007 Herbert Pötzl
17231 + *
17232 + *  V0.01  vx_info dump support
17233 + *
17234 + */
17235 +
17236 +#include <linux/module.h>
17237 +
17238 +#include <linux/vserver/context.h>
17239 +
17240 +
17241 +void   dump_vx_info(struct vx_info *vxi, int level)
17242 +{
17243 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
17244 +               atomic_read(&vxi->vx_usecnt),
17245 +               atomic_read(&vxi->vx_tasks),
17246 +               vxi->vx_state);
17247 +       if (level > 0) {
17248 +               __dump_vx_limit(&vxi->limit);
17249 +               __dump_vx_sched(&vxi->sched);
17250 +               __dump_vx_cvirt(&vxi->cvirt);
17251 +               __dump_vx_cacct(&vxi->cacct);
17252 +       }
17253 +       printk("---\n");
17254 +}
17255 +
17256 +
17257 +EXPORT_SYMBOL_GPL(dump_vx_info);
17258 +
17259 diff -NurpP --minimal linux-3.9.4/kernel/vserver/device.c linux-3.9.4-vs2.3.6.1/kernel/vserver/device.c
17260 --- linux-3.9.4/kernel/vserver/device.c 1970-01-01 00:00:00.000000000 +0000
17261 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/device.c       2013-05-31 14:47:11.000000000 +0000
17262 @@ -0,0 +1,443 @@
17263 +/*
17264 + *  linux/kernel/vserver/device.c
17265 + *
17266 + *  Linux-VServer: Device Support
17267 + *
17268 + *  Copyright (C) 2006  Herbert Pötzl
17269 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
17270 + *
17271 + *  V0.01  device mapping basics
17272 + *  V0.02  added defaults
17273 + *
17274 + */
17275 +
17276 +#include <linux/slab.h>
17277 +#include <linux/rcupdate.h>
17278 +#include <linux/fs.h>
17279 +#include <linux/namei.h>
17280 +#include <linux/hash.h>
17281 +
17282 +#include <asm/errno.h>
17283 +#include <asm/uaccess.h>
17284 +#include <linux/vserver/base.h>
17285 +#include <linux/vserver/debug.h>
17286 +#include <linux/vserver/context.h>
17287 +#include <linux/vserver/device.h>
17288 +#include <linux/vserver/device_cmd.h>
17289 +
17290 +
17291 +#define DMAP_HASH_BITS 4
17292 +
17293 +
17294 +struct vs_mapping {
17295 +       union {
17296 +               struct hlist_node hlist;
17297 +               struct list_head list;
17298 +       } u;
17299 +#define dm_hlist       u.hlist
17300 +#define dm_list                u.list
17301 +       xid_t xid;
17302 +       dev_t device;
17303 +       struct vx_dmap_target target;
17304 +};
17305 +
17306 +
17307 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
17308 +
17309 +static DEFINE_SPINLOCK(dmap_main_hash_lock);
17310 +
17311 +static struct vx_dmap_target dmap_defaults[2] = {
17312 +       { .flags = DATTR_OPEN },
17313 +       { .flags = DATTR_OPEN },
17314 +};
17315 +
17316 +
17317 +struct kmem_cache *dmap_cachep __read_mostly;
17318 +
17319 +int __init dmap_cache_init(void)
17320 +{
17321 +       dmap_cachep = kmem_cache_create("dmap_cache",
17322 +               sizeof(struct vs_mapping), 0,
17323 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
17324 +       return 0;
17325 +}
17326 +
17327 +__initcall(dmap_cache_init);
17328 +
17329 +
17330 +static inline unsigned int __hashval(dev_t dev, int bits)
17331 +{
17332 +       return hash_long((unsigned long)dev, bits);
17333 +}
17334 +
17335 +
17336 +/*     __hash_mapping()
17337 + *     add the mapping to the hash table
17338 + */
17339 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
17340 +{
17341 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17342 +       struct hlist_head *head, *hash = dmap_main_hash;
17343 +       int device = vdm->device;
17344 +
17345 +       spin_lock(hash_lock);
17346 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
17347 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
17348 +
17349 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
17350 +       hlist_add_head(&vdm->dm_hlist, head);
17351 +       spin_unlock(hash_lock);
17352 +}
17353 +
17354 +
17355 +static inline int __mode_to_default(umode_t mode)
17356 +{
17357 +       switch (mode) {
17358 +       case S_IFBLK:
17359 +               return 0;
17360 +       case S_IFCHR:
17361 +               return 1;
17362 +       default:
17363 +               BUG();
17364 +       }
17365 +}
17366 +
17367 +
17368 +/*     __set_default()
17369 + *     set a default
17370 + */
17371 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
17372 +       struct vx_dmap_target *vdmt)
17373 +{
17374 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17375 +       spin_lock(hash_lock);
17376 +
17377 +       if (vxi)
17378 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
17379 +       else
17380 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
17381 +
17382 +
17383 +       spin_unlock(hash_lock);
17384 +
17385 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
17386 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
17387 +}
17388 +
17389 +
17390 +/*     __remove_default()
17391 + *     remove a default
17392 + */
17393 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
17394 +{
17395 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17396 +       spin_lock(hash_lock);
17397 +
17398 +       if (vxi)
17399 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
17400 +       else    /* remove == reset */
17401 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
17402 +
17403 +       spin_unlock(hash_lock);
17404 +       return 0;
17405 +}
17406 +
17407 +
17408 +/*     __find_mapping()
17409 + *     find a mapping in the hash table
17410 + *
17411 + *     caller must hold hash_lock
17412 + */
17413 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
17414 +       struct vs_mapping **local, struct vs_mapping **global)
17415 +{
17416 +       struct hlist_head *hash = dmap_main_hash;
17417 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
17418 +       struct hlist_node *pos;
17419 +       struct vs_mapping *vdm;
17420 +
17421 +       *local = NULL;
17422 +       if (global)
17423 +               *global = NULL;
17424 +
17425 +       hlist_for_each(pos, head) {
17426 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
17427 +
17428 +               if ((vdm->device == device) &&
17429 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
17430 +                       if (vdm->xid == xid) {
17431 +                               *local = vdm;
17432 +                               return 1;
17433 +                       } else if (global && vdm->xid == 0)
17434 +                               *global = vdm;
17435 +               }
17436 +       }
17437 +
17438 +       if (global && *global)
17439 +               return 0;
17440 +       else
17441 +               return -ENOENT;
17442 +}
17443 +
17444 +
17445 +/*     __lookup_mapping()
17446 + *     find a mapping and store the result in target and flags
17447 + */
17448 +static inline int __lookup_mapping(struct vx_info *vxi,
17449 +       dev_t device, dev_t *target, int *flags, umode_t mode)
17450 +{
17451 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17452 +       struct vs_mapping *vdm, *global;
17453 +       struct vx_dmap_target *vdmt;
17454 +       int ret = 0;
17455 +       xid_t xid = vxi->vx_id;
17456 +       int index;
17457 +
17458 +       spin_lock(hash_lock);
17459 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
17460 +               ret = 1;
17461 +               vdmt = &vdm->target;
17462 +               goto found;
17463 +       }
17464 +
17465 +       index = __mode_to_default(mode);
17466 +       if (vxi && vxi->dmap.targets[index].flags) {
17467 +               ret = 2;
17468 +               vdmt = &vxi->dmap.targets[index];
17469 +       } else if (global) {
17470 +               ret = 3;
17471 +               vdmt = &global->target;
17472 +               goto found;
17473 +       } else {
17474 +               ret = 4;
17475 +               vdmt = &dmap_defaults[index];
17476 +       }
17477 +
17478 +found:
17479 +       if (target && (vdmt->flags & DATTR_REMAP))
17480 +               *target = vdmt->target;
17481 +       else if (target)
17482 +               *target = device;
17483 +       if (flags)
17484 +               *flags = vdmt->flags;
17485 +
17486 +       spin_unlock(hash_lock);
17487 +
17488 +       return ret;
17489 +}
17490 +
17491 +
17492 +/*     __remove_mapping()
17493 + *     remove a mapping from the hash table
17494 + */
17495 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
17496 +       umode_t mode)
17497 +{
17498 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17499 +       struct vs_mapping *vdm = NULL;
17500 +       int ret = 0;
17501 +
17502 +       spin_lock(hash_lock);
17503 +
17504 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
17505 +               NULL);
17506 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
17507 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
17508 +       if (ret < 0)
17509 +               goto out;
17510 +       hlist_del(&vdm->dm_hlist);
17511 +
17512 +out:
17513 +       spin_unlock(hash_lock);
17514 +       if (vdm)
17515 +               kmem_cache_free(dmap_cachep, vdm);
17516 +       return ret;
17517 +}
17518 +
17519 +
17520 +
17521 +int vs_map_device(struct vx_info *vxi,
17522 +       dev_t device, dev_t *target, umode_t mode)
17523 +{
17524 +       int ret, flags = DATTR_MASK;
17525 +
17526 +       if (!vxi) {
17527 +               if (target)
17528 +                       *target = device;
17529 +               goto out;
17530 +       }
17531 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
17532 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
17533 +               device, target ? *target : 0, flags, mode, ret);
17534 +out:
17535 +       return (flags & DATTR_MASK);
17536 +}
17537 +
17538 +
17539 +
17540 +static int do_set_mapping(struct vx_info *vxi,
17541 +       dev_t device, dev_t target, int flags, umode_t mode)
17542 +{
17543 +       if (device) {
17544 +               struct vs_mapping *new;
17545 +
17546 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
17547 +               if (!new)
17548 +                       return -ENOMEM;
17549 +
17550 +               INIT_HLIST_NODE(&new->dm_hlist);
17551 +               new->device = device;
17552 +               new->target.target = target;
17553 +               new->target.flags = flags | mode;
17554 +               new->xid = (vxi ? vxi->vx_id : 0);
17555 +
17556 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
17557 +               __hash_mapping(vxi, new);
17558 +       } else {
17559 +               struct vx_dmap_target new = {
17560 +                       .target = target,
17561 +                       .flags = flags | mode,
17562 +               };
17563 +               __set_default(vxi, mode, &new);
17564 +       }
17565 +       return 0;
17566 +}
17567 +
17568 +
17569 +static int do_unset_mapping(struct vx_info *vxi,
17570 +       dev_t device, dev_t target, int flags, umode_t mode)
17571 +{
17572 +       int ret = -EINVAL;
17573 +
17574 +       if (device) {
17575 +               ret = __remove_mapping(vxi, device, mode);
17576 +               if (ret < 0)
17577 +                       goto out;
17578 +       } else {
17579 +               ret = __remove_default(vxi, mode);
17580 +               if (ret < 0)
17581 +                       goto out;
17582 +       }
17583 +
17584 +out:
17585 +       return ret;
17586 +}
17587 +
17588 +
17589 +static inline int __user_device(const char __user *name, dev_t *dev,
17590 +       umode_t *mode)
17591 +{
17592 +       struct nameidata nd;
17593 +       int ret;
17594 +
17595 +       if (!name) {
17596 +               *dev = 0;
17597 +               return 0;
17598 +       }
17599 +       ret = user_lpath(name, &nd.path);
17600 +       if (ret)
17601 +               return ret;
17602 +       if (nd.path.dentry->d_inode) {
17603 +               *dev = nd.path.dentry->d_inode->i_rdev;
17604 +               *mode = nd.path.dentry->d_inode->i_mode;
17605 +       }
17606 +       path_put(&nd.path);
17607 +       return 0;
17608 +}
17609 +
17610 +static inline int __mapping_mode(dev_t device, dev_t target,
17611 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
17612 +{
17613 +       if (device)
17614 +               *mode = device_mode & S_IFMT;
17615 +       else if (target)
17616 +               *mode = target_mode & S_IFMT;
17617 +       else
17618 +               return -EINVAL;
17619 +
17620 +       /* if both given, device and target mode have to match */
17621 +       if (device && target &&
17622 +               ((device_mode ^ target_mode) & S_IFMT))
17623 +               return -EINVAL;
17624 +       return 0;
17625 +}
17626 +
17627 +
17628 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
17629 +       const char __user *target_path, int flags, int set)
17630 +{
17631 +       dev_t device = ~0, target = ~0;
17632 +       umode_t device_mode = 0, target_mode = 0, mode;
17633 +       int ret;
17634 +
17635 +       ret = __user_device(device_path, &device, &device_mode);
17636 +       if (ret)
17637 +               return ret;
17638 +       ret = __user_device(target_path, &target, &target_mode);
17639 +       if (ret)
17640 +               return ret;
17641 +
17642 +       ret = __mapping_mode(device, target,
17643 +               device_mode, target_mode, &mode);
17644 +       if (ret)
17645 +               return ret;
17646 +
17647 +       if (set)
17648 +               return do_set_mapping(vxi, device, target,
17649 +                       flags, mode);
17650 +       else
17651 +               return do_unset_mapping(vxi, device, target,
17652 +                       flags, mode);
17653 +}
17654 +
17655 +
17656 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
17657 +{
17658 +       struct vcmd_set_mapping_v0 vc_data;
17659 +
17660 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17661 +               return -EFAULT;
17662 +
17663 +       return do_mapping(vxi, vc_data.device, vc_data.target,
17664 +               vc_data.flags, 1);
17665 +}
17666 +
17667 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
17668 +{
17669 +       struct vcmd_set_mapping_v0 vc_data;
17670 +
17671 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17672 +               return -EFAULT;
17673 +
17674 +       return do_mapping(vxi, vc_data.device, vc_data.target,
17675 +               vc_data.flags, 0);
17676 +}
17677 +
17678 +
17679 +#ifdef CONFIG_COMPAT
17680 +
17681 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
17682 +{
17683 +       struct vcmd_set_mapping_v0_x32 vc_data;
17684 +
17685 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17686 +               return -EFAULT;
17687 +
17688 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
17689 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
17690 +}
17691 +
17692 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
17693 +{
17694 +       struct vcmd_set_mapping_v0_x32 vc_data;
17695 +
17696 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17697 +               return -EFAULT;
17698 +
17699 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
17700 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
17701 +}
17702 +
17703 +#endif /* CONFIG_COMPAT */
17704 +
17705 +
17706 diff -NurpP --minimal linux-3.9.4/kernel/vserver/dlimit.c linux-3.9.4-vs2.3.6.1/kernel/vserver/dlimit.c
17707 --- linux-3.9.4/kernel/vserver/dlimit.c 1970-01-01 00:00:00.000000000 +0000
17708 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/dlimit.c       2013-05-31 19:37:39.000000000 +0000
17709 @@ -0,0 +1,528 @@
17710 +/*
17711 + *  linux/kernel/vserver/dlimit.c
17712 + *
17713 + *  Virtual Server: Context Disk Limits
17714 + *
17715 + *  Copyright (C) 2004-2009  Herbert Pötzl
17716 + *
17717 + *  V0.01  initial version
17718 + *  V0.02  compat32 splitup
17719 + *  V0.03  extended interface
17720 + *
17721 + */
17722 +
17723 +#include <linux/statfs.h>
17724 +#include <linux/sched.h>
17725 +#include <linux/namei.h>
17726 +#include <linux/vs_tag.h>
17727 +#include <linux/vs_dlimit.h>
17728 +#include <linux/vserver/dlimit_cmd.h>
17729 +#include <linux/slab.h>
17730 +// #include <linux/gfp.h>
17731 +
17732 +#include <asm/uaccess.h>
17733 +
17734 +/*     __alloc_dl_info()
17735 +
17736 +       * allocate an initialized dl_info struct
17737 +       * doesn't make it visible (hash)                        */
17738 +
17739 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
17740 +{
17741 +       struct dl_info *new = NULL;
17742 +
17743 +       vxdprintk(VXD_CBIT(dlim, 5),
17744 +               "alloc_dl_info(%p,%d)*", sb, tag);
17745 +
17746 +       /* would this benefit from a slab cache? */
17747 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
17748 +       if (!new)
17749 +               return 0;
17750 +
17751 +       memset(new, 0, sizeof(struct dl_info));
17752 +       new->dl_tag = tag;
17753 +       new->dl_sb = sb;
17754 +       // INIT_RCU_HEAD(&new->dl_rcu);
17755 +       INIT_HLIST_NODE(&new->dl_hlist);
17756 +       spin_lock_init(&new->dl_lock);
17757 +       atomic_set(&new->dl_refcnt, 0);
17758 +       atomic_set(&new->dl_usecnt, 0);
17759 +
17760 +       /* rest of init goes here */
17761 +
17762 +       vxdprintk(VXD_CBIT(dlim, 4),
17763 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
17764 +       return new;
17765 +}
17766 +
17767 +/*     __dealloc_dl_info()
17768 +
17769 +       * final disposal of dl_info                             */
17770 +
17771 +static void __dealloc_dl_info(struct dl_info *dli)
17772 +{
17773 +       vxdprintk(VXD_CBIT(dlim, 4),
17774 +               "dealloc_dl_info(%p)", dli);
17775 +
17776 +       dli->dl_hlist.next = LIST_POISON1;
17777 +       dli->dl_tag = -1;
17778 +       dli->dl_sb = 0;
17779 +
17780 +       BUG_ON(atomic_read(&dli->dl_usecnt));
17781 +       BUG_ON(atomic_read(&dli->dl_refcnt));
17782 +
17783 +       kfree(dli);
17784 +}
17785 +
17786 +
17787 +/*     hash table for dl_info hash */
17788 +
17789 +#define DL_HASH_SIZE   13
17790 +
17791 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
17792 +
17793 +static DEFINE_SPINLOCK(dl_info_hash_lock);
17794 +
17795 +
17796 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
17797 +{
17798 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
17799 +}
17800 +
17801 +
17802 +
17803 +/*     __hash_dl_info()
17804 +
17805 +       * add the dli to the global hash table
17806 +       * requires the hash_lock to be held                     */
17807 +
17808 +static inline void __hash_dl_info(struct dl_info *dli)
17809 +{
17810 +       struct hlist_head *head;
17811 +
17812 +       vxdprintk(VXD_CBIT(dlim, 6),
17813 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
17814 +       get_dl_info(dli);
17815 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
17816 +       hlist_add_head_rcu(&dli->dl_hlist, head);
17817 +}
17818 +
17819 +/*     __unhash_dl_info()
17820 +
17821 +       * remove the dli from the global hash table
17822 +       * requires the hash_lock to be held                     */
17823 +
17824 +static inline void __unhash_dl_info(struct dl_info *dli)
17825 +{
17826 +       vxdprintk(VXD_CBIT(dlim, 6),
17827 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
17828 +       hlist_del_rcu(&dli->dl_hlist);
17829 +       put_dl_info(dli);
17830 +}
17831 +
17832 +
17833 +/*     __lookup_dl_info()
17834 +
17835 +       * requires the rcu_read_lock()
17836 +       * doesn't increment the dl_refcnt                       */
17837 +
17838 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
17839 +{
17840 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
17841 +       struct dl_info *dli;
17842 +
17843 +       hlist_for_each_entry_rcu(dli, head, dl_hlist) {
17844 +               if (dli->dl_tag == tag && dli->dl_sb == sb)
17845 +                       return dli;
17846 +       }
17847 +       return NULL;
17848 +}
17849 +
17850 +
17851 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
17852 +{
17853 +       struct dl_info *dli;
17854 +
17855 +       rcu_read_lock();
17856 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
17857 +       vxdprintk(VXD_CBIT(dlim, 7),
17858 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
17859 +       rcu_read_unlock();
17860 +       return dli;
17861 +}
17862 +
17863 +void rcu_free_dl_info(struct rcu_head *head)
17864 +{
17865 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
17866 +       int usecnt, refcnt;
17867 +
17868 +       BUG_ON(!dli || !head);
17869 +
17870 +       usecnt = atomic_read(&dli->dl_usecnt);
17871 +       BUG_ON(usecnt < 0);
17872 +
17873 +       refcnt = atomic_read(&dli->dl_refcnt);
17874 +       BUG_ON(refcnt < 0);
17875 +
17876 +       vxdprintk(VXD_CBIT(dlim, 3),
17877 +               "rcu_free_dl_info(%p)", dli);
17878 +       if (!usecnt)
17879 +               __dealloc_dl_info(dli);
17880 +       else
17881 +               printk("!!! rcu didn't free\n");
17882 +}
17883 +
17884 +
17885 +
17886 +
17887 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
17888 +       uint32_t flags, int add)
17889 +{
17890 +       struct path path;
17891 +       int ret;
17892 +
17893 +       ret = user_lpath(name, &path);
17894 +       if (!ret) {
17895 +               struct super_block *sb;
17896 +               struct dl_info *dli;
17897 +
17898 +               ret = -EINVAL;
17899 +               if (!path.dentry->d_inode)
17900 +                       goto out_release;
17901 +               if (!(sb = path.dentry->d_inode->i_sb))
17902 +                       goto out_release;
17903 +
17904 +               if (add) {
17905 +                       dli = __alloc_dl_info(sb, id);
17906 +                       spin_lock(&dl_info_hash_lock);
17907 +
17908 +                       ret = -EEXIST;
17909 +                       if (__lookup_dl_info(sb, id))
17910 +                               goto out_unlock;
17911 +                       __hash_dl_info(dli);
17912 +                       dli = NULL;
17913 +               } else {
17914 +                       spin_lock(&dl_info_hash_lock);
17915 +                       dli = __lookup_dl_info(sb, id);
17916 +
17917 +                       ret = -ESRCH;
17918 +                       if (!dli)
17919 +                               goto out_unlock;
17920 +                       __unhash_dl_info(dli);
17921 +               }
17922 +               ret = 0;
17923 +       out_unlock:
17924 +               spin_unlock(&dl_info_hash_lock);
17925 +               if (add && dli)
17926 +                       __dealloc_dl_info(dli);
17927 +       out_release:
17928 +               path_put(&path);
17929 +       }
17930 +       return ret;
17931 +}
17932 +
17933 +int vc_add_dlimit(uint32_t id, void __user *data)
17934 +{
17935 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
17936 +
17937 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17938 +               return -EFAULT;
17939 +
17940 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
17941 +}
17942 +
17943 +int vc_rem_dlimit(uint32_t id, void __user *data)
17944 +{
17945 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
17946 +
17947 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17948 +               return -EFAULT;
17949 +
17950 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
17951 +}
17952 +
17953 +#ifdef CONFIG_COMPAT
17954 +
17955 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
17956 +{
17957 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
17958 +
17959 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17960 +               return -EFAULT;
17961 +
17962 +       return do_addrem_dlimit(id,
17963 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
17964 +}
17965 +
17966 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
17967 +{
17968 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
17969 +
17970 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17971 +               return -EFAULT;
17972 +
17973 +       return do_addrem_dlimit(id,
17974 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
17975 +}
17976 +
17977 +#endif /* CONFIG_COMPAT */
17978 +
17979 +
17980 +static inline
17981 +int do_set_dlimit(uint32_t id, const char __user *name,
17982 +       uint32_t space_used, uint32_t space_total,
17983 +       uint32_t inodes_used, uint32_t inodes_total,
17984 +       uint32_t reserved, uint32_t flags)
17985 +{
17986 +       struct path path;
17987 +       int ret;
17988 +
17989 +       ret = user_lpath(name, &path);
17990 +       if (!ret) {
17991 +               struct super_block *sb;
17992 +               struct dl_info *dli;
17993 +
17994 +               ret = -EINVAL;
17995 +               if (!path.dentry->d_inode)
17996 +                       goto out_release;
17997 +               if (!(sb = path.dentry->d_inode->i_sb))
17998 +                       goto out_release;
17999 +
18000 +               /* sanity checks */
18001 +               if ((reserved != CDLIM_KEEP &&
18002 +                       reserved > 100) ||
18003 +                       (inodes_used != CDLIM_KEEP &&
18004 +                       inodes_used > inodes_total) ||
18005 +                       (space_used != CDLIM_KEEP &&
18006 +                       space_used > space_total))
18007 +                       goto out_release;
18008 +
18009 +               ret = -ESRCH;
18010 +               dli = locate_dl_info(sb, id);
18011 +               if (!dli)
18012 +                       goto out_release;
18013 +
18014 +               spin_lock(&dli->dl_lock);
18015 +
18016 +               if (inodes_used != CDLIM_KEEP)
18017 +                       dli->dl_inodes_used = inodes_used;
18018 +               if (inodes_total != CDLIM_KEEP)
18019 +                       dli->dl_inodes_total = inodes_total;
18020 +               if (space_used != CDLIM_KEEP)
18021 +                       dli->dl_space_used = dlimit_space_32to64(
18022 +                               space_used, flags, DLIMS_USED);
18023 +
18024 +               if (space_total == CDLIM_INFINITY)
18025 +                       dli->dl_space_total = DLIM_INFINITY;
18026 +               else if (space_total != CDLIM_KEEP)
18027 +                       dli->dl_space_total = dlimit_space_32to64(
18028 +                               space_total, flags, DLIMS_TOTAL);
18029 +
18030 +               if (reserved != CDLIM_KEEP)
18031 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
18032 +
18033 +               spin_unlock(&dli->dl_lock);
18034 +
18035 +               put_dl_info(dli);
18036 +               ret = 0;
18037 +
18038 +       out_release:
18039 +               path_put(&path);
18040 +       }
18041 +       return ret;
18042 +}
18043 +
18044 +int vc_set_dlimit(uint32_t id, void __user *data)
18045 +{
18046 +       struct vcmd_ctx_dlimit_v0 vc_data;
18047 +
18048 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18049 +               return -EFAULT;
18050 +
18051 +       return do_set_dlimit(id, vc_data.name,
18052 +               vc_data.space_used, vc_data.space_total,
18053 +               vc_data.inodes_used, vc_data.inodes_total,
18054 +               vc_data.reserved, vc_data.flags);
18055 +}
18056 +
18057 +#ifdef CONFIG_COMPAT
18058 +
18059 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
18060 +{
18061 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18062 +
18063 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18064 +               return -EFAULT;
18065 +
18066 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
18067 +               vc_data.space_used, vc_data.space_total,
18068 +               vc_data.inodes_used, vc_data.inodes_total,
18069 +               vc_data.reserved, vc_data.flags);
18070 +}
18071 +
18072 +#endif /* CONFIG_COMPAT */
18073 +
18074 +
18075 +static inline
18076 +int do_get_dlimit(uint32_t id, const char __user *name,
18077 +       uint32_t *space_used, uint32_t *space_total,
18078 +       uint32_t *inodes_used, uint32_t *inodes_total,
18079 +       uint32_t *reserved, uint32_t *flags)
18080 +{
18081 +       struct path path;
18082 +       int ret;
18083 +
18084 +       ret = user_lpath(name, &path);
18085 +       if (!ret) {
18086 +               struct super_block *sb;
18087 +               struct dl_info *dli;
18088 +
18089 +               ret = -EINVAL;
18090 +               if (!path.dentry->d_inode)
18091 +                       goto out_release;
18092 +               if (!(sb = path.dentry->d_inode->i_sb))
18093 +                       goto out_release;
18094 +
18095 +               ret = -ESRCH;
18096 +               dli = locate_dl_info(sb, id);
18097 +               if (!dli)
18098 +                       goto out_release;
18099 +
18100 +               spin_lock(&dli->dl_lock);
18101 +               *inodes_used = dli->dl_inodes_used;
18102 +               *inodes_total = dli->dl_inodes_total;
18103 +
18104 +               *space_used = dlimit_space_64to32(
18105 +                       dli->dl_space_used, flags, DLIMS_USED);
18106 +
18107 +               if (dli->dl_space_total == DLIM_INFINITY)
18108 +                       *space_total = CDLIM_INFINITY;
18109 +               else
18110 +                       *space_total = dlimit_space_64to32(
18111 +                               dli->dl_space_total, flags, DLIMS_TOTAL);
18112 +
18113 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
18114 +               spin_unlock(&dli->dl_lock);
18115 +
18116 +               put_dl_info(dli);
18117 +               ret = -EFAULT;
18118 +
18119 +               ret = 0;
18120 +       out_release:
18121 +               path_put(&path);
18122 +       }
18123 +       return ret;
18124 +}
18125 +
18126 +
18127 +int vc_get_dlimit(uint32_t id, void __user *data)
18128 +{
18129 +       struct vcmd_ctx_dlimit_v0 vc_data;
18130 +       int ret;
18131 +
18132 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18133 +               return -EFAULT;
18134 +
18135 +       ret = do_get_dlimit(id, vc_data.name,
18136 +               &vc_data.space_used, &vc_data.space_total,
18137 +               &vc_data.inodes_used, &vc_data.inodes_total,
18138 +               &vc_data.reserved, &vc_data.flags);
18139 +       if (ret)
18140 +               return ret;
18141 +
18142 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18143 +               return -EFAULT;
18144 +       return 0;
18145 +}
18146 +
18147 +#ifdef CONFIG_COMPAT
18148 +
18149 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
18150 +{
18151 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18152 +       int ret;
18153 +
18154 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18155 +               return -EFAULT;
18156 +
18157 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
18158 +               &vc_data.space_used, &vc_data.space_total,
18159 +               &vc_data.inodes_used, &vc_data.inodes_total,
18160 +               &vc_data.reserved, &vc_data.flags);
18161 +       if (ret)
18162 +               return ret;
18163 +
18164 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18165 +               return -EFAULT;
18166 +       return 0;
18167 +}
18168 +
18169 +#endif /* CONFIG_COMPAT */
18170 +
18171 +
18172 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
18173 +{
18174 +       struct dl_info *dli;
18175 +       __u64 blimit, bfree, bavail;
18176 +       __u32 ifree;
18177 +
18178 +       dli = locate_dl_info(sb, dx_current_tag());
18179 +       if (!dli)
18180 +               return;
18181 +
18182 +       spin_lock(&dli->dl_lock);
18183 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
18184 +               goto no_ilim;
18185 +
18186 +       /* reduce max inodes available to limit */
18187 +       if (buf->f_files > dli->dl_inodes_total)
18188 +               buf->f_files = dli->dl_inodes_total;
18189 +
18190 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
18191 +       /* reduce free inodes to min */
18192 +       if (ifree < buf->f_ffree)
18193 +               buf->f_ffree = ifree;
18194 +
18195 +no_ilim:
18196 +       if (dli->dl_space_total == DLIM_INFINITY)
18197 +               goto no_blim;
18198 +
18199 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
18200 +
18201 +       if (dli->dl_space_total < dli->dl_space_used)
18202 +               bfree = 0;
18203 +       else
18204 +               bfree = (dli->dl_space_total - dli->dl_space_used)
18205 +                       >> sb->s_blocksize_bits;
18206 +
18207 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
18208 +       if (bavail < dli->dl_space_used)
18209 +               bavail = 0;
18210 +       else
18211 +               bavail = (bavail - dli->dl_space_used)
18212 +                       >> sb->s_blocksize_bits;
18213 +
18214 +       /* reduce max space available to limit */
18215 +       if (buf->f_blocks > blimit)
18216 +               buf->f_blocks = blimit;
18217 +
18218 +       /* reduce free space to min */
18219 +       if (bfree < buf->f_bfree)
18220 +               buf->f_bfree = bfree;
18221 +
18222 +       /* reduce avail space to min */
18223 +       if (bavail < buf->f_bavail)
18224 +               buf->f_bavail = bavail;
18225 +
18226 +no_blim:
18227 +       spin_unlock(&dli->dl_lock);
18228 +       put_dl_info(dli);
18229 +
18230 +       return;
18231 +}
18232 +
18233 +#include <linux/module.h>
18234 +
18235 +EXPORT_SYMBOL_GPL(locate_dl_info);
18236 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
18237 +
18238 diff -NurpP --minimal linux-3.9.4/kernel/vserver/helper.c linux-3.9.4-vs2.3.6.1/kernel/vserver/helper.c
18239 --- linux-3.9.4/kernel/vserver/helper.c 1970-01-01 00:00:00.000000000 +0000
18240 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/helper.c       2013-05-31 14:47:11.000000000 +0000
18241 @@ -0,0 +1,229 @@
18242 +/*
18243 + *  linux/kernel/vserver/helper.c
18244 + *
18245 + *  Virtual Context Support
18246 + *
18247 + *  Copyright (C) 2004-2007  Herbert Pötzl
18248 + *
18249 + *  V0.01  basic helper
18250 + *
18251 + */
18252 +
18253 +#include <linux/kmod.h>
18254 +#include <linux/reboot.h>
18255 +#include <linux/vs_context.h>
18256 +#include <linux/vs_network.h>
18257 +#include <linux/vserver/signal.h>
18258 +
18259 +
18260 +char vshelper_path[255] = "/sbin/vshelper";
18261 +
18262 +static int vshelper_init(struct subprocess_info *info, struct cred *new_cred)
18263 +{
18264 +       current->flags &= ~PF_THREAD_BOUND;
18265 +       return 0;
18266 +}
18267 +
18268 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
18269 +{
18270 +       int ret;
18271 +
18272 +       if ((ret = call_usermodehelper_fns(name, argv, envp,
18273 +               sync ? UMH_WAIT_PROC : UMH_WAIT_EXEC,
18274 +               vshelper_init, NULL, NULL))) {
18275 +               printk(KERN_WARNING "%s: (%s %s) returned %s with %d\n",
18276 +                       name, argv[1], argv[2],
18277 +                       sync ? "sync" : "async", ret);
18278 +       }
18279 +       vxdprintk(VXD_CBIT(switch, 4),
18280 +               "%s: (%s %s) returned %s with %d",
18281 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
18282 +       return ret;
18283 +}
18284 +
18285 +/*
18286 + *      vshelper path is set via /proc/sys
18287 + *      invoked by vserver sys_reboot(), with
18288 + *      the following arguments
18289 + *
18290 + *      argv [0] = vshelper_path;
18291 + *      argv [1] = action: "restart", "halt", "poweroff", ...
18292 + *      argv [2] = context identifier
18293 + *
18294 + *      envp [*] = type-specific parameters
18295 + */
18296 +
18297 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
18298 +{
18299 +       char id_buf[8], cmd_buf[16];
18300 +       char uid_buf[16], pid_buf[16];
18301 +       int ret;
18302 +
18303 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18304 +       char *envp[] = {"HOME=/", "TERM=linux",
18305 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
18306 +                       uid_buf, pid_buf, cmd_buf, 0};
18307 +
18308 +       if (vx_info_state(vxi, VXS_HELPER))
18309 +               return -EAGAIN;
18310 +       vxi->vx_state |= VXS_HELPER;
18311 +
18312 +       snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
18313 +
18314 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18315 +       snprintf(uid_buf, sizeof(uid_buf), "VS_UID=%d", current_uid());
18316 +       snprintf(pid_buf, sizeof(pid_buf), "VS_PID=%d", current->pid);
18317 +
18318 +       switch (cmd) {
18319 +       case LINUX_REBOOT_CMD_RESTART:
18320 +               argv[1] = "restart";
18321 +               break;
18322 +
18323 +       case LINUX_REBOOT_CMD_HALT:
18324 +               argv[1] = "halt";
18325 +               break;
18326 +
18327 +       case LINUX_REBOOT_CMD_POWER_OFF:
18328 +               argv[1] = "poweroff";
18329 +               break;
18330 +
18331 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
18332 +               argv[1] = "swsusp";
18333 +               break;
18334 +
18335 +       case LINUX_REBOOT_CMD_OOM:
18336 +               argv[1] = "oom";
18337 +               break;
18338 +
18339 +       default:
18340 +               vxi->vx_state &= ~VXS_HELPER;
18341 +               return 0;
18342 +       }
18343 +
18344 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
18345 +       vxi->vx_state &= ~VXS_HELPER;
18346 +       __wakeup_vx_info(vxi);
18347 +       return (ret) ? -EPERM : 0;
18348 +}
18349 +
18350 +
18351 +long vs_reboot(unsigned int cmd, void __user *arg)
18352 +{
18353 +       struct vx_info *vxi = current_vx_info();
18354 +       long ret = 0;
18355 +
18356 +       vxdprintk(VXD_CBIT(misc, 5),
18357 +               "vs_reboot(%p[#%d],%u)",
18358 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18359 +
18360 +       ret = vs_reboot_helper(vxi, cmd, arg);
18361 +       if (ret)
18362 +               return ret;
18363 +
18364 +       vxi->reboot_cmd = cmd;
18365 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18366 +               switch (cmd) {
18367 +               case LINUX_REBOOT_CMD_RESTART:
18368 +               case LINUX_REBOOT_CMD_HALT:
18369 +               case LINUX_REBOOT_CMD_POWER_OFF:
18370 +                       vx_info_kill(vxi, 0, SIGKILL);
18371 +                       vx_info_kill(vxi, 1, SIGKILL);
18372 +               default:
18373 +                       break;
18374 +               }
18375 +       }
18376 +       return 0;
18377 +}
18378 +
18379 +long vs_oom_action(unsigned int cmd)
18380 +{
18381 +       struct vx_info *vxi = current_vx_info();
18382 +       long ret = 0;
18383 +
18384 +       vxdprintk(VXD_CBIT(misc, 5),
18385 +               "vs_oom_action(%p[#%d],%u)",
18386 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18387 +
18388 +       ret = vs_reboot_helper(vxi, cmd, NULL);
18389 +       if (ret)
18390 +               return ret;
18391 +
18392 +       vxi->reboot_cmd = cmd;
18393 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18394 +               vx_info_kill(vxi, 0, SIGKILL);
18395 +               vx_info_kill(vxi, 1, SIGKILL);
18396 +       }
18397 +       return 0;
18398 +}
18399 +
18400 +/*
18401 + *      argv [0] = vshelper_path;
18402 + *      argv [1] = action: "startup", "shutdown"
18403 + *      argv [2] = context identifier
18404 + *
18405 + *      envp [*] = type-specific parameters
18406 + */
18407 +
18408 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
18409 +{
18410 +       char id_buf[8], cmd_buf[16];
18411 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18412 +       char *envp[] = {"HOME=/", "TERM=linux",
18413 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18414 +
18415 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
18416 +               return 0;
18417 +
18418 +       snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
18419 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18420 +
18421 +       switch (cmd) {
18422 +       case VSC_STARTUP:
18423 +               argv[1] = "startup";
18424 +               break;
18425 +       case VSC_SHUTDOWN:
18426 +               argv[1] = "shutdown";
18427 +               break;
18428 +       default:
18429 +               return 0;
18430 +       }
18431 +
18432 +       return do_vshelper(vshelper_path, argv, envp, 1);
18433 +}
18434 +
18435 +
18436 +/*
18437 + *      argv [0] = vshelper_path;
18438 + *      argv [1] = action: "netup", "netdown"
18439 + *      argv [2] = context identifier
18440 + *
18441 + *      envp [*] = type-specific parameters
18442 + */
18443 +
18444 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
18445 +{
18446 +       char id_buf[8], cmd_buf[16];
18447 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18448 +       char *envp[] = {"HOME=/", "TERM=linux",
18449 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18450 +
18451 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
18452 +               return 0;
18453 +
18454 +       snprintf(id_buf, sizeof(id_buf), "%d", nxi->nx_id);
18455 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18456 +
18457 +       switch (cmd) {
18458 +       case VSC_NETUP:
18459 +               argv[1] = "netup";
18460 +               break;
18461 +       case VSC_NETDOWN:
18462 +               argv[1] = "netdown";
18463 +               break;
18464 +       default:
18465 +               return 0;
18466 +       }
18467 +
18468 +       return do_vshelper(vshelper_path, argv, envp, 1);
18469 +}
18470 +
18471 diff -NurpP --minimal linux-3.9.4/kernel/vserver/history.c linux-3.9.4-vs2.3.6.1/kernel/vserver/history.c
18472 --- linux-3.9.4/kernel/vserver/history.c        1970-01-01 00:00:00.000000000 +0000
18473 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/history.c      2013-05-31 14:47:11.000000000 +0000
18474 @@ -0,0 +1,258 @@
18475 +/*
18476 + *  kernel/vserver/history.c
18477 + *
18478 + *  Virtual Context History Backtrace
18479 + *
18480 + *  Copyright (C) 2004-2007  Herbert Pötzl
18481 + *
18482 + *  V0.01  basic structure
18483 + *  V0.02  hash/unhash and trace
18484 + *  V0.03  preemption fixes
18485 + *
18486 + */
18487 +
18488 +#include <linux/module.h>
18489 +#include <asm/uaccess.h>
18490 +
18491 +#include <linux/vserver/context.h>
18492 +#include <linux/vserver/debug.h>
18493 +#include <linux/vserver/debug_cmd.h>
18494 +#include <linux/vserver/history.h>
18495 +
18496 +
18497 +#ifdef CONFIG_VSERVER_HISTORY
18498 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
18499 +#else
18500 +#define VXH_SIZE       64
18501 +#endif
18502 +
18503 +struct _vx_history {
18504 +       unsigned int counter;
18505 +
18506 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
18507 +};
18508 +
18509 +
18510 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
18511 +
18512 +unsigned volatile int vxh_active = 1;
18513 +
18514 +static atomic_t sequence = ATOMIC_INIT(0);
18515 +
18516 +
18517 +/*     vxh_advance()
18518 +
18519 +       * requires disabled preemption                          */
18520 +
18521 +struct _vx_hist_entry *vxh_advance(void *loc)
18522 +{
18523 +       unsigned int cpu = smp_processor_id();
18524 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
18525 +       struct _vx_hist_entry *entry;
18526 +       unsigned int index;
18527 +
18528 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
18529 +       entry = &hist->entry[index];
18530 +
18531 +       entry->seq = atomic_inc_return(&sequence);
18532 +       entry->loc = loc;
18533 +       return entry;
18534 +}
18535 +
18536 +EXPORT_SYMBOL_GPL(vxh_advance);
18537 +
18538 +
18539 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
18540 +
18541 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
18542 +
18543 +
18544 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
18545 +
18546 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
18547 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
18548 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
18549 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
18550 +
18551 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
18552 +{
18553 +       switch (e->type) {
18554 +       case VXH_THROW_OOPS:
18555 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
18556 +               break;
18557 +
18558 +       case VXH_GET_VX_INFO:
18559 +       case VXH_PUT_VX_INFO:
18560 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
18561 +                       VXH_LOC_ARGS(e),
18562 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
18563 +                       VXH_VXI_ARGS(e));
18564 +               break;
18565 +
18566 +       case VXH_INIT_VX_INFO:
18567 +       case VXH_SET_VX_INFO:
18568 +       case VXH_CLR_VX_INFO:
18569 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
18570 +                       VXH_LOC_ARGS(e),
18571 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
18572 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
18573 +                       VXH_VXI_ARGS(e), e->sc.data);
18574 +               break;
18575 +
18576 +       case VXH_CLAIM_VX_INFO:
18577 +       case VXH_RELEASE_VX_INFO:
18578 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
18579 +                       VXH_LOC_ARGS(e),
18580 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
18581 +                       VXH_VXI_ARGS(e), e->sc.data);
18582 +               break;
18583 +
18584 +       case VXH_ALLOC_VX_INFO:
18585 +       case VXH_DEALLOC_VX_INFO:
18586 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
18587 +                       VXH_LOC_ARGS(e),
18588 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
18589 +                       VXH_VXI_ARGS(e));
18590 +               break;
18591 +
18592 +       case VXH_HASH_VX_INFO:
18593 +       case VXH_UNHASH_VX_INFO:
18594 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
18595 +                       VXH_LOC_ARGS(e),
18596 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
18597 +                       VXH_VXI_ARGS(e));
18598 +               break;
18599 +
18600 +       case VXH_LOC_VX_INFO:
18601 +       case VXH_LOOKUP_VX_INFO:
18602 +       case VXH_CREATE_VX_INFO:
18603 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
18604 +                       VXH_LOC_ARGS(e),
18605 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
18606 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
18607 +                       e->ll.arg, VXH_VXI_ARGS(e));
18608 +               break;
18609 +       }
18610 +}
18611 +
18612 +static void __vxh_dump_history(void)
18613 +{
18614 +       unsigned int i, cpu;
18615 +
18616 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
18617 +               atomic_read(&sequence), NR_CPUS);
18618 +
18619 +       for (i = 0; i < VXH_SIZE; i++) {
18620 +               for_each_online_cpu(cpu) {
18621 +                       struct _vx_history *hist =
18622 +                               &per_cpu(vx_history_buffer, cpu);
18623 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
18624 +                       struct _vx_hist_entry *entry = &hist->entry[index];
18625 +
18626 +                       vxh_dump_entry(entry, cpu);
18627 +               }
18628 +       }
18629 +}
18630 +
18631 +void   vxh_dump_history(void)
18632 +{
18633 +       vxh_active = 0;
18634 +#ifdef CONFIG_SMP
18635 +       local_irq_enable();
18636 +       smp_send_stop();
18637 +       local_irq_disable();
18638 +#endif
18639 +       __vxh_dump_history();
18640 +}
18641 +
18642 +
18643 +/* vserver syscall commands below here */
18644 +
18645 +
18646 +int vc_dump_history(uint32_t id)
18647 +{
18648 +       vxh_active = 0;
18649 +       __vxh_dump_history();
18650 +       vxh_active = 1;
18651 +
18652 +       return 0;
18653 +}
18654 +
18655 +
18656 +int do_read_history(struct __user _vx_hist_entry *data,
18657 +       int cpu, uint32_t *index, uint32_t *count)
18658 +{
18659 +       int pos, ret = 0;
18660 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
18661 +       int end = hist->counter;
18662 +       int start = end - VXH_SIZE + 2;
18663 +       int idx = *index;
18664 +
18665 +       /* special case: get current pos */
18666 +       if (!*count) {
18667 +               *index = end;
18668 +               return 0;
18669 +       }
18670 +
18671 +       /* have we lost some data? */
18672 +       if (idx < start)
18673 +               idx = start;
18674 +
18675 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
18676 +               struct _vx_hist_entry *entry =
18677 +                       &hist->entry[idx % VXH_SIZE];
18678 +
18679 +               /* send entry to userspace */
18680 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
18681 +               if (ret)
18682 +                       break;
18683 +       }
18684 +       /* save new index and count */
18685 +       *index = idx;
18686 +       *count = pos;
18687 +       return ret ? ret : (*index < end);
18688 +}
18689 +
18690 +int vc_read_history(uint32_t id, void __user *data)
18691 +{
18692 +       struct vcmd_read_history_v0 vc_data;
18693 +       int ret;
18694 +
18695 +       if (id >= NR_CPUS)
18696 +               return -EINVAL;
18697 +
18698 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18699 +               return -EFAULT;
18700 +
18701 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
18702 +               id, &vc_data.index, &vc_data.count);
18703 +
18704 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18705 +               return -EFAULT;
18706 +       return ret;
18707 +}
18708 +
18709 +#ifdef CONFIG_COMPAT
18710 +
18711 +int vc_read_history_x32(uint32_t id, void __user *data)
18712 +{
18713 +       struct vcmd_read_history_v0_x32 vc_data;
18714 +       int ret;
18715 +
18716 +       if (id >= NR_CPUS)
18717 +               return -EINVAL;
18718 +
18719 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18720 +               return -EFAULT;
18721 +
18722 +       ret = do_read_history((struct __user _vx_hist_entry *)
18723 +               compat_ptr(vc_data.data_ptr),
18724 +               id, &vc_data.index, &vc_data.count);
18725 +
18726 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18727 +               return -EFAULT;
18728 +       return ret;
18729 +}
18730 +
18731 +#endif /* CONFIG_COMPAT */
18732 +
18733 diff -NurpP --minimal linux-3.9.4/kernel/vserver/inet.c linux-3.9.4-vs2.3.6.1/kernel/vserver/inet.c
18734 --- linux-3.9.4/kernel/vserver/inet.c   1970-01-01 00:00:00.000000000 +0000
18735 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/inet.c 2013-05-31 22:43:05.000000000 +0000
18736 @@ -0,0 +1,236 @@
18737 +
18738 +#include <linux/in.h>
18739 +#include <linux/inetdevice.h>
18740 +#include <linux/export.h>
18741 +#include <linux/vs_inet.h>
18742 +#include <linux/vs_inet6.h>
18743 +#include <linux/vserver/debug.h>
18744 +#include <net/route.h>
18745 +#include <net/addrconf.h>
18746 +
18747 +
18748 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
18749 +{
18750 +       int ret = 0;
18751 +
18752 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
18753 +               ret = 1;
18754 +       else {
18755 +               struct nx_addr_v4 *ptr;
18756 +               unsigned long irqflags;
18757 +
18758 +               spin_lock_irqsave(&nxi1->addr_lock, irqflags);
18759 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
18760 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
18761 +                               ret = 1;
18762 +                               break;
18763 +                       }
18764 +               }
18765 +               spin_unlock_irqrestore(&nxi1->addr_lock, irqflags);
18766 +       }
18767 +
18768 +       vxdprintk(VXD_CBIT(net, 2),
18769 +               "nx_v4_addr_conflict(%p,%p): %d",
18770 +               nxi1, nxi2, ret);
18771 +
18772 +       return ret;
18773 +}
18774 +
18775 +
18776 +#ifdef CONFIG_IPV6
18777 +
18778 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
18779 +{
18780 +       int ret = 0;
18781 +
18782 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
18783 +               ret = 1;
18784 +       else {
18785 +               struct nx_addr_v6 *ptr;
18786 +               unsigned long irqflags;
18787 +
18788 +               spin_lock_irqsave(&nxi1->addr_lock, irqflags);
18789 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
18790 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
18791 +                               ret = 1;
18792 +                               break;
18793 +                       }
18794 +               }
18795 +               spin_unlock_irqrestore(&nxi1->addr_lock, irqflags);
18796 +       }
18797 +
18798 +       vxdprintk(VXD_CBIT(net, 2),
18799 +               "nx_v6_addr_conflict(%p,%p): %d",
18800 +               nxi1, nxi2, ret);
18801 +
18802 +       return ret;
18803 +}
18804 +
18805 +#endif
18806 +
18807 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18808 +{
18809 +       struct in_device *in_dev;
18810 +       struct in_ifaddr **ifap;
18811 +       struct in_ifaddr *ifa;
18812 +       int ret = 0;
18813 +
18814 +       if (!dev)
18815 +               goto out;
18816 +       in_dev = in_dev_get(dev);
18817 +       if (!in_dev)
18818 +               goto out;
18819 +
18820 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
18821 +               ifap = &ifa->ifa_next) {
18822 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
18823 +                       ret = 1;
18824 +                       break;
18825 +               }
18826 +       }
18827 +       in_dev_put(in_dev);
18828 +out:
18829 +       return ret;
18830 +}
18831 +
18832 +
18833 +#ifdef CONFIG_IPV6
18834 +
18835 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18836 +{
18837 +       struct inet6_dev *in_dev;
18838 +       struct inet6_ifaddr *ifa;
18839 +       int ret = 0;
18840 +
18841 +       if (!dev)
18842 +               goto out;
18843 +       in_dev = in6_dev_get(dev);
18844 +       if (!in_dev)
18845 +               goto out;
18846 +
18847 +       // for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
18848 +       list_for_each_entry(ifa, &in_dev->addr_list, if_list) {
18849 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
18850 +                       ret = 1;
18851 +                       break;
18852 +               }
18853 +       }
18854 +       in6_dev_put(in_dev);
18855 +out:
18856 +       return ret;
18857 +}
18858 +
18859 +#endif
18860 +
18861 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18862 +{
18863 +       int ret = 1;
18864 +
18865 +       if (!nxi)
18866 +               goto out;
18867 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
18868 +               goto out;
18869 +#ifdef CONFIG_IPV6
18870 +       ret = 2;
18871 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
18872 +               goto out;
18873 +#endif
18874 +       ret = 0;
18875 +out:
18876 +       vxdprintk(VXD_CBIT(net, 3),
18877 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
18878 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
18879 +       return ret;
18880 +}
18881 +
18882 +struct rtable *ip_v4_find_src(struct net *net, struct nx_info *nxi,
18883 +       struct flowi4 *fl4)
18884 +{
18885 +       struct rtable *rt;
18886 +
18887 +       if (!nxi)
18888 +               return NULL;
18889 +
18890 +       /* FIXME: handle lback only case */
18891 +       if (!NX_IPV4(nxi))
18892 +               return ERR_PTR(-EPERM);
18893 +
18894 +       vxdprintk(VXD_CBIT(net, 4),
18895 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
18896 +               nxi, nxi ? nxi->nx_id : 0,
18897 +               NIPQUAD(fl4->saddr), NIPQUAD(fl4->daddr));
18898 +
18899 +       /* single IP is unconditional */
18900 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
18901 +               (fl4->saddr == INADDR_ANY))
18902 +               fl4->saddr = nxi->v4.ip[0].s_addr;
18903 +
18904 +       if (fl4->saddr == INADDR_ANY) {
18905 +               struct nx_addr_v4 *ptr;
18906 +               __be32 found = 0;
18907 +
18908 +               rt = __ip_route_output_key(net, fl4);
18909 +               if (!IS_ERR(rt)) {
18910 +                       found = fl4->saddr;
18911 +                       ip_rt_put(rt);
18912 +                       vxdprintk(VXD_CBIT(net, 4),
18913 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
18914 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(found));
18915 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
18916 +                               goto found;
18917 +               }
18918 +
18919 +               WARN_ON_ONCE(in_irq());
18920 +               spin_lock_bh(&nxi->addr_lock);
18921 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
18922 +                       __be32 primary = ptr->ip[0].s_addr;
18923 +                       __be32 mask = ptr->mask.s_addr;
18924 +                       __be32 neta = primary & mask;
18925 +
18926 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
18927 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
18928 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
18929 +                               NIPQUAD(mask), NIPQUAD(neta));
18930 +                       if ((found & mask) != neta)
18931 +                               continue;
18932 +
18933 +                       fl4->saddr = primary;
18934 +                       rt = __ip_route_output_key(net, fl4);
18935 +                       vxdprintk(VXD_CBIT(net, 4),
18936 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
18937 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(primary));
18938 +                       if (!IS_ERR(rt)) {
18939 +                               found = fl4->saddr;
18940 +                               ip_rt_put(rt);
18941 +                               if (found == primary)
18942 +                                       goto found_unlock;
18943 +                       }
18944 +               }
18945 +               /* still no source ip? */
18946 +               found = ipv4_is_loopback(fl4->daddr)
18947 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
18948 +       found_unlock:
18949 +               spin_unlock_bh(&nxi->addr_lock);
18950 +       found:
18951 +               /* assign src ip to flow */
18952 +               fl4->saddr = found;
18953 +
18954 +       } else {
18955 +               if (!v4_addr_in_nx_info(nxi, fl4->saddr, NXA_MASK_BIND))
18956 +                       return ERR_PTR(-EPERM);
18957 +       }
18958 +
18959 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
18960 +               if (ipv4_is_loopback(fl4->daddr))
18961 +                       fl4->daddr = nxi->v4_lback.s_addr;
18962 +               if (ipv4_is_loopback(fl4->saddr))
18963 +                       fl4->saddr = nxi->v4_lback.s_addr;
18964 +       } else if (ipv4_is_loopback(fl4->daddr) &&
18965 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
18966 +               return ERR_PTR(-EPERM);
18967 +
18968 +       return NULL;
18969 +}
18970 +
18971 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
18972 +
18973 diff -NurpP --minimal linux-3.9.4/kernel/vserver/init.c linux-3.9.4-vs2.3.6.1/kernel/vserver/init.c
18974 --- linux-3.9.4/kernel/vserver/init.c   1970-01-01 00:00:00.000000000 +0000
18975 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/init.c 2013-05-31 14:47:11.000000000 +0000
18976 @@ -0,0 +1,45 @@
18977 +/*
18978 + *  linux/kernel/init.c
18979 + *
18980 + *  Virtual Server Init
18981 + *
18982 + *  Copyright (C) 2004-2007  Herbert Pötzl
18983 + *
18984 + *  V0.01  basic structure
18985 + *
18986 + */
18987 +
18988 +#include <linux/init.h>
18989 +
18990 +int    vserver_register_sysctl(void);
18991 +void   vserver_unregister_sysctl(void);
18992 +
18993 +
18994 +static int __init init_vserver(void)
18995 +{
18996 +       int ret = 0;
18997 +
18998 +#ifdef CONFIG_VSERVER_DEBUG
18999 +       vserver_register_sysctl();
19000 +#endif
19001 +       return ret;
19002 +}
19003 +
19004 +
19005 +static void __exit exit_vserver(void)
19006 +{
19007 +
19008 +#ifdef CONFIG_VSERVER_DEBUG
19009 +       vserver_unregister_sysctl();
19010 +#endif
19011 +       return;
19012 +}
19013 +
19014 +/* FIXME: GFP_ZONETYPES gone
19015 +long vx_slab[GFP_ZONETYPES]; */
19016 +long vx_area;
19017 +
19018 +
19019 +module_init(init_vserver);
19020 +module_exit(exit_vserver);
19021 +
19022 diff -NurpP --minimal linux-3.9.4/kernel/vserver/inode.c linux-3.9.4-vs2.3.6.1/kernel/vserver/inode.c
19023 --- linux-3.9.4/kernel/vserver/inode.c  1970-01-01 00:00:00.000000000 +0000
19024 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/inode.c        2013-05-31 14:47:11.000000000 +0000
19025 @@ -0,0 +1,437 @@
19026 +/*
19027 + *  linux/kernel/vserver/inode.c
19028 + *
19029 + *  Virtual Server: File System Support
19030 + *
19031 + *  Copyright (C) 2004-2007  Herbert Pötzl
19032 + *
19033 + *  V0.01  separated from vcontext V0.05
19034 + *  V0.02  moved to tag (instead of xid)
19035 + *
19036 + */
19037 +
19038 +#include <linux/tty.h>
19039 +#include <linux/proc_fs.h>
19040 +#include <linux/devpts_fs.h>
19041 +#include <linux/fs.h>
19042 +#include <linux/file.h>
19043 +#include <linux/mount.h>
19044 +#include <linux/parser.h>
19045 +#include <linux/namei.h>
19046 +#include <linux/vserver/inode.h>
19047 +#include <linux/vserver/inode_cmd.h>
19048 +#include <linux/vs_base.h>
19049 +#include <linux/vs_tag.h>
19050 +
19051 +#include <asm/uaccess.h>
19052 +
19053 +
19054 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19055 +{
19056 +       struct proc_dir_entry *entry;
19057 +
19058 +       if (!in || !in->i_sb)
19059 +               return -ESRCH;
19060 +
19061 +       *flags = IATTR_TAG
19062 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
19063 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
19064 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
19065 +               | (IS_COW(in) ? IATTR_COW : 0);
19066 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
19067 +
19068 +       if (S_ISDIR(in->i_mode))
19069 +               *mask |= IATTR_BARRIER;
19070 +
19071 +       if (IS_TAGGED(in)) {
19072 +               *tag = i_tag_read(in);
19073 +               *mask |= IATTR_TAG;
19074 +       }
19075 +
19076 +       switch (in->i_sb->s_magic) {
19077 +       case PROC_SUPER_MAGIC:
19078 +               entry = PROC_I(in)->pde;
19079 +
19080 +               /* check for specific inodes? */
19081 +               if (entry)
19082 +                       *mask |= IATTR_FLAGS;
19083 +               if (entry)
19084 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
19085 +               else
19086 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
19087 +               break;
19088 +
19089 +       case DEVPTS_SUPER_MAGIC:
19090 +               *tag = i_tag_read(in);
19091 +               *mask |= IATTR_TAG;
19092 +               break;
19093 +
19094 +       default:
19095 +               break;
19096 +       }
19097 +       return 0;
19098 +}
19099 +
19100 +int vc_get_iattr(void __user *data)
19101 +{
19102 +       struct path path;
19103 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
19104 +       int ret;
19105 +
19106 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19107 +               return -EFAULT;
19108 +
19109 +       ret = user_lpath(vc_data.name, &path);
19110 +       if (!ret) {
19111 +               ret = __vc_get_iattr(path.dentry->d_inode,
19112 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19113 +               path_put(&path);
19114 +       }
19115 +       if (ret)
19116 +               return ret;
19117 +
19118 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19119 +               ret = -EFAULT;
19120 +       return ret;
19121 +}
19122 +
19123 +#ifdef CONFIG_COMPAT
19124 +
19125 +int vc_get_iattr_x32(void __user *data)
19126 +{
19127 +       struct path path;
19128 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
19129 +       int ret;
19130 +
19131 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19132 +               return -EFAULT;
19133 +
19134 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19135 +       if (!ret) {
19136 +               ret = __vc_get_iattr(path.dentry->d_inode,
19137 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19138 +               path_put(&path);
19139 +       }
19140 +       if (ret)
19141 +               return ret;
19142 +
19143 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19144 +               ret = -EFAULT;
19145 +       return ret;
19146 +}
19147 +
19148 +#endif /* CONFIG_COMPAT */
19149 +
19150 +
19151 +int vc_fget_iattr(uint32_t fd, void __user *data)
19152 +{
19153 +       struct file *filp;
19154 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
19155 +       int ret;
19156 +
19157 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19158 +               return -EFAULT;
19159 +
19160 +       filp = fget(fd);
19161 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19162 +               return -EBADF;
19163 +
19164 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
19165 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
19166 +
19167 +       fput(filp);
19168 +
19169 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19170 +               ret = -EFAULT;
19171 +       return ret;
19172 +}
19173 +
19174 +
19175 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19176 +{
19177 +       struct inode *in = de->d_inode;
19178 +       int error = 0, is_proc = 0, has_tag = 0;
19179 +       struct iattr attr = { 0 };
19180 +
19181 +       if (!in || !in->i_sb)
19182 +               return -ESRCH;
19183 +
19184 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
19185 +       if ((*mask & IATTR_FLAGS) && !is_proc)
19186 +               return -EINVAL;
19187 +
19188 +       has_tag = IS_TAGGED(in) ||
19189 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
19190 +       if ((*mask & IATTR_TAG) && !has_tag)
19191 +               return -EINVAL;
19192 +
19193 +       mutex_lock(&in->i_mutex);
19194 +       if (*mask & IATTR_TAG) {
19195 +               attr.ia_tag = *tag;
19196 +               attr.ia_valid |= ATTR_TAG;
19197 +       }
19198 +
19199 +       if (*mask & IATTR_FLAGS) {
19200 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
19201 +               unsigned int iflags = PROC_I(in)->vx_flags;
19202 +
19203 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
19204 +                       | (*flags & IATTR_FLAGS);
19205 +               PROC_I(in)->vx_flags = iflags;
19206 +               if (entry)
19207 +                       entry->vx_flags = iflags;
19208 +       }
19209 +
19210 +       if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
19211 +               IATTR_BARRIER | IATTR_COW)) {
19212 +               int iflags = in->i_flags;
19213 +               int vflags = in->i_vflags;
19214 +
19215 +               if (*mask & IATTR_IMMUTABLE) {
19216 +                       if (*flags & IATTR_IMMUTABLE)
19217 +                               iflags |= S_IMMUTABLE;
19218 +                       else
19219 +                               iflags &= ~S_IMMUTABLE;
19220 +               }
19221 +               if (*mask & IATTR_IXUNLINK) {
19222 +                       if (*flags & IATTR_IXUNLINK)
19223 +                               iflags |= S_IXUNLINK;
19224 +                       else
19225 +                               iflags &= ~S_IXUNLINK;
19226 +               }
19227 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
19228 +                       if (*flags & IATTR_BARRIER)
19229 +                               vflags |= V_BARRIER;
19230 +                       else
19231 +                               vflags &= ~V_BARRIER;
19232 +               }
19233 +               if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
19234 +                       if (*flags & IATTR_COW)
19235 +                               vflags |= V_COW;
19236 +                       else
19237 +                               vflags &= ~V_COW;
19238 +               }
19239 +               if (in->i_op && in->i_op->sync_flags) {
19240 +                       error = in->i_op->sync_flags(in, iflags, vflags);
19241 +                       if (error)
19242 +                               goto out;
19243 +               }
19244 +       }
19245 +
19246 +       if (attr.ia_valid) {
19247 +               if (in->i_op && in->i_op->setattr)
19248 +                       error = in->i_op->setattr(de, &attr);
19249 +               else {
19250 +                       error = inode_change_ok(in, &attr);
19251 +                       if (!error) {
19252 +                               setattr_copy(in, &attr);
19253 +                               mark_inode_dirty(in);
19254 +                       }
19255 +               }
19256 +       }
19257 +
19258 +out:
19259 +       mutex_unlock(&in->i_mutex);
19260 +       return error;
19261 +}
19262 +
19263 +int vc_set_iattr(void __user *data)
19264 +{
19265 +       struct path path;
19266 +       struct vcmd_ctx_iattr_v1 vc_data;
19267 +       int ret;
19268 +
19269 +       if (!capable(CAP_LINUX_IMMUTABLE))
19270 +               return -EPERM;
19271 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19272 +               return -EFAULT;
19273 +
19274 +       ret = user_lpath(vc_data.name, &path);
19275 +       if (!ret) {
19276 +               ret = __vc_set_iattr(path.dentry,
19277 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19278 +               path_put(&path);
19279 +       }
19280 +
19281 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19282 +               ret = -EFAULT;
19283 +       return ret;
19284 +}
19285 +
19286 +#ifdef CONFIG_COMPAT
19287 +
19288 +int vc_set_iattr_x32(void __user *data)
19289 +{
19290 +       struct path path;
19291 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
19292 +       int ret;
19293 +
19294 +       if (!capable(CAP_LINUX_IMMUTABLE))
19295 +               return -EPERM;
19296 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19297 +               return -EFAULT;
19298 +
19299 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19300 +       if (!ret) {
19301 +               ret = __vc_set_iattr(path.dentry,
19302 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19303 +               path_put(&path);
19304 +       }
19305 +
19306 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19307 +               ret = -EFAULT;
19308 +       return ret;
19309 +}
19310 +
19311 +#endif /* CONFIG_COMPAT */
19312 +
19313 +int vc_fset_iattr(uint32_t fd, void __user *data)
19314 +{
19315 +       struct file *filp;
19316 +       struct vcmd_ctx_fiattr_v0 vc_data;
19317 +       int ret;
19318 +
19319 +       if (!capable(CAP_LINUX_IMMUTABLE))
19320 +               return -EPERM;
19321 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19322 +               return -EFAULT;
19323 +
19324 +       filp = fget(fd);
19325 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19326 +               return -EBADF;
19327 +
19328 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
19329 +               &vc_data.flags, &vc_data.mask);
19330 +
19331 +       fput(filp);
19332 +
19333 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19334 +               return -EFAULT;
19335 +       return ret;
19336 +}
19337 +
19338 +
19339 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
19340 +
19341 +static match_table_t tokens = {
19342 +       {Opt_notagcheck, "notagcheck"},
19343 +#ifdef CONFIG_PROPAGATE
19344 +       {Opt_notag, "notag"},
19345 +       {Opt_tag, "tag"},
19346 +       {Opt_tagid, "tagid=%u"},
19347 +#endif
19348 +       {Opt_err, NULL}
19349 +};
19350 +
19351 +
19352 +static void __dx_parse_remove(char *string, char *opt)
19353 +{
19354 +       char *p = strstr(string, opt);
19355 +       char *q = p;
19356 +
19357 +       if (p) {
19358 +               while (*q != '\0' && *q != ',')
19359 +                       q++;
19360 +               while (*q)
19361 +                       *p++ = *q++;
19362 +               while (*p)
19363 +                       *p++ = '\0';
19364 +       }
19365 +}
19366 +
19367 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
19368 +                unsigned long *flags)
19369 +{
19370 +       int set = 0;
19371 +       substring_t args[MAX_OPT_ARGS];
19372 +       int token;
19373 +       char *s, *p, *opts;
19374 +#if defined(CONFIG_PROPAGATE) || defined(CONFIG_VSERVER_DEBUG)
19375 +       int option = 0;
19376 +#endif
19377 +
19378 +       if (!string)
19379 +               return 0;
19380 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
19381 +       if (!s)
19382 +               return 0;
19383 +
19384 +       opts = s;
19385 +       while ((p = strsep(&opts, ",")) != NULL) {
19386 +               token = match_token(p, tokens, args);
19387 +
19388 +               switch (token) {
19389 +#ifdef CONFIG_PROPAGATE
19390 +               case Opt_tag:
19391 +                       if (tag)
19392 +                               *tag = 0;
19393 +                       if (remove)
19394 +                               __dx_parse_remove(s, "tag");
19395 +                       *mnt_flags |= MNT_TAGID;
19396 +                       set |= MNT_TAGID;
19397 +                       break;
19398 +               case Opt_notag:
19399 +                       if (remove)
19400 +                               __dx_parse_remove(s, "notag");
19401 +                       *mnt_flags |= MNT_NOTAG;
19402 +                       set |= MNT_NOTAG;
19403 +                       break;
19404 +               case Opt_tagid:
19405 +                       if (tag && !match_int(args, &option))
19406 +                               *tag = option;
19407 +                       if (remove)
19408 +                               __dx_parse_remove(s, "tagid");
19409 +                       *mnt_flags |= MNT_TAGID;
19410 +                       set |= MNT_TAGID;
19411 +                       break;
19412 +#endif /* CONFIG_PROPAGATE */
19413 +               case Opt_notagcheck:
19414 +                       if (remove)
19415 +                               __dx_parse_remove(s, "notagcheck");
19416 +                       *flags |= MS_NOTAGCHECK;
19417 +                       set |= MS_NOTAGCHECK;
19418 +                       break;
19419 +               }
19420 +               vxdprintk(VXD_CBIT(tag, 7),
19421 +                       "dx_parse_tag(" VS_Q("%s") "): %d:#%d",
19422 +                       p, token, option);
19423 +       }
19424 +       if (set)
19425 +               strcpy(string, s);
19426 +       kfree(s);
19427 +       return set;
19428 +}
19429 +
19430 +#ifdef CONFIG_PROPAGATE
19431 +
19432 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
19433 +{
19434 +       tag_t new_tag = 0;
19435 +       struct vfsmount *mnt;
19436 +       int propagate;
19437 +
19438 +       if (!nd)
19439 +               return;
19440 +       mnt = nd->path.mnt;
19441 +       if (!mnt)
19442 +               return;
19443 +
19444 +       propagate = (mnt->mnt_flags & MNT_TAGID);
19445 +       if (propagate)
19446 +               new_tag = mnt->mnt_tag;
19447 +
19448 +       vxdprintk(VXD_CBIT(tag, 7),
19449 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
19450 +               inode, inode->i_ino, inode->i_tag,
19451 +               new_tag, (propagate) ? 1 : 0);
19452 +
19453 +       if (propagate)
19454 +               i_tag_write(inode, new_tag);
19455 +}
19456 +
19457 +#include <linux/module.h>
19458 +
19459 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
19460 +
19461 +#endif /* CONFIG_PROPAGATE */
19462 +
19463 diff -NurpP --minimal linux-3.9.4/kernel/vserver/limit.c linux-3.9.4-vs2.3.6.1/kernel/vserver/limit.c
19464 --- linux-3.9.4/kernel/vserver/limit.c  1970-01-01 00:00:00.000000000 +0000
19465 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/limit.c        2013-05-31 14:47:11.000000000 +0000
19466 @@ -0,0 +1,345 @@
19467 +/*
19468 + *  linux/kernel/vserver/limit.c
19469 + *
19470 + *  Virtual Server: Context Limits
19471 + *
19472 + *  Copyright (C) 2004-2010  Herbert Pötzl
19473 + *
19474 + *  V0.01  broken out from vcontext V0.05
19475 + *  V0.02  changed vcmds to vxi arg
19476 + *  V0.03  added memory cgroup support
19477 + *
19478 + */
19479 +
19480 +#include <linux/sched.h>
19481 +#include <linux/module.h>
19482 +#include <linux/memcontrol.h>
19483 +#include <linux/res_counter.h>
19484 +#include <linux/vs_limit.h>
19485 +#include <linux/vserver/limit.h>
19486 +#include <linux/vserver/limit_cmd.h>
19487 +
19488 +#include <asm/uaccess.h>
19489 +
19490 +
19491 +const char *vlimit_name[NUM_LIMITS] = {
19492 +       [RLIMIT_CPU]            = "CPU",
19493 +       [RLIMIT_NPROC]          = "NPROC",
19494 +       [RLIMIT_NOFILE]         = "NOFILE",
19495 +       [RLIMIT_LOCKS]          = "LOCKS",
19496 +       [RLIMIT_SIGPENDING]     = "SIGP",
19497 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
19498 +
19499 +       [VLIMIT_NSOCK]          = "NSOCK",
19500 +       [VLIMIT_OPENFD]         = "OPENFD",
19501 +       [VLIMIT_SHMEM]          = "SHMEM",
19502 +       [VLIMIT_DENTRY]         = "DENTRY",
19503 +};
19504 +
19505 +EXPORT_SYMBOL_GPL(vlimit_name);
19506 +
19507 +#define MASK_ENTRY(x)  (1 << (x))
19508 +
19509 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
19510 +               /* minimum */
19511 +       0
19512 +       ,       /* softlimit */
19513 +       0
19514 +       ,       /* maximum */
19515 +       MASK_ENTRY( RLIMIT_NPROC        ) |
19516 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
19517 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
19518 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
19519 +
19520 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
19521 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
19522 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
19523 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
19524 +       0
19525 +};
19526 +               /* accounting only */
19527 +uint32_t account_mask =
19528 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
19529 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
19530 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
19531 +       0;
19532 +
19533 +
19534 +static int is_valid_vlimit(int id)
19535 +{
19536 +       uint32_t mask = vlimit_mask.minimum |
19537 +               vlimit_mask.softlimit | vlimit_mask.maximum;
19538 +       return mask & (1 << id);
19539 +}
19540 +
19541 +static int is_accounted_vlimit(int id)
19542 +{
19543 +       if (is_valid_vlimit(id))
19544 +               return 1;
19545 +       return account_mask & (1 << id);
19546 +}
19547 +
19548 +
19549 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
19550 +{
19551 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
19552 +       return VX_VLIM(limit);
19553 +}
19554 +
19555 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
19556 +{
19557 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
19558 +       return VX_VLIM(limit);
19559 +}
19560 +
19561 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
19562 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
19563 +{
19564 +       if (!is_valid_vlimit(id))
19565 +               return -EINVAL;
19566 +
19567 +       if (minimum)
19568 +               *minimum = CRLIM_UNSET;
19569 +       if (softlimit)
19570 +               *softlimit = vc_get_soft(vxi, id);
19571 +       if (maximum)
19572 +               *maximum = vc_get_hard(vxi, id);
19573 +       return 0;
19574 +}
19575 +
19576 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
19577 +{
19578 +       struct vcmd_ctx_rlimit_v0 vc_data;
19579 +       int ret;
19580 +
19581 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19582 +               return -EFAULT;
19583 +
19584 +       ret = do_get_rlimit(vxi, vc_data.id,
19585 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
19586 +       if (ret)
19587 +               return ret;
19588 +
19589 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19590 +               return -EFAULT;
19591 +       return 0;
19592 +}
19593 +
19594 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
19595 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
19596 +{
19597 +       if (!is_valid_vlimit(id))
19598 +               return -EINVAL;
19599 +
19600 +       if (maximum != CRLIM_KEEP)
19601 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
19602 +       if (softlimit != CRLIM_KEEP)
19603 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
19604 +
19605 +       /* clamp soft limit */
19606 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
19607 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
19608 +
19609 +       return 0;
19610 +}
19611 +
19612 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
19613 +{
19614 +       struct vcmd_ctx_rlimit_v0 vc_data;
19615 +
19616 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19617 +               return -EFAULT;
19618 +
19619 +       return do_set_rlimit(vxi, vc_data.id,
19620 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
19621 +}
19622 +
19623 +#ifdef CONFIG_IA32_EMULATION
19624 +
19625 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
19626 +{
19627 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
19628 +
19629 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19630 +               return -EFAULT;
19631 +
19632 +       return do_set_rlimit(vxi, vc_data.id,
19633 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
19634 +}
19635 +
19636 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
19637 +{
19638 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
19639 +       int ret;
19640 +
19641 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19642 +               return -EFAULT;
19643 +
19644 +       ret = do_get_rlimit(vxi, vc_data.id,
19645 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
19646 +       if (ret)
19647 +               return ret;
19648 +
19649 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19650 +               return -EFAULT;
19651 +       return 0;
19652 +}
19653 +
19654 +#endif /* CONFIG_IA32_EMULATION */
19655 +
19656 +
19657 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
19658 +{
19659 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
19660 +               return -EFAULT;
19661 +       return 0;
19662 +}
19663 +
19664 +
19665 +static inline void vx_reset_hits(struct _vx_limit *limit)
19666 +{
19667 +       int lim;
19668 +
19669 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19670 +               atomic_set(&__rlim_lhit(limit, lim), 0);
19671 +       }
19672 +}
19673 +
19674 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
19675 +{
19676 +       vx_reset_hits(&vxi->limit);
19677 +       return 0;
19678 +}
19679 +
19680 +static inline void vx_reset_minmax(struct _vx_limit *limit)
19681 +{
19682 +       rlim_t value;
19683 +       int lim;
19684 +
19685 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19686 +               value = __rlim_get(limit, lim);
19687 +               __rlim_rmax(limit, lim) = value;
19688 +               __rlim_rmin(limit, lim) = value;
19689 +       }
19690 +}
19691 +
19692 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
19693 +{
19694 +       vx_reset_minmax(&vxi->limit);
19695 +       return 0;
19696 +}
19697 +
19698 +
19699 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
19700 +{
19701 +       struct vcmd_rlimit_stat_v0 vc_data;
19702 +       struct _vx_limit *limit = &vxi->limit;
19703 +       int id;
19704 +
19705 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19706 +               return -EFAULT;
19707 +
19708 +       id = vc_data.id;
19709 +       if (!is_accounted_vlimit(id))
19710 +               return -EINVAL;
19711 +
19712 +       vx_limit_fixup(limit, id);
19713 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
19714 +       vc_data.value = __rlim_get(limit, id);
19715 +       vc_data.minimum = __rlim_rmin(limit, id);
19716 +       vc_data.maximum = __rlim_rmax(limit, id);
19717 +
19718 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19719 +               return -EFAULT;
19720 +       return 0;
19721 +}
19722 +
19723 +
19724 +void vx_vsi_meminfo(struct sysinfo *val)
19725 +{
19726 +#ifdef CONFIG_MEMCG
19727 +       struct mem_cgroup *mcg;
19728 +       u64 res_limit, res_usage;
19729 +
19730 +       rcu_read_lock();
19731 +       mcg = mem_cgroup_from_task(current);
19732 +       rcu_read_unlock();
19733 +       if (!mcg)
19734 +               goto out;
19735 +
19736 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
19737 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
19738 +
19739 +       if (res_limit != RESOURCE_MAX)
19740 +               val->totalram = (res_limit >> PAGE_SHIFT);
19741 +       val->freeram = val->totalram - (res_usage >> PAGE_SHIFT);
19742 +       val->bufferram = 0;
19743 +       val->totalhigh = 0;
19744 +       val->freehigh = 0;
19745 +out:
19746 +#endif /* CONFIG_MEMCG */
19747 +       return;
19748 +}
19749 +
19750 +void vx_vsi_swapinfo(struct sysinfo *val)
19751 +{
19752 +#ifdef CONFIG_MEMCG
19753 +#ifdef CONFIG_MEMCG_SWAP
19754 +       struct mem_cgroup *mcg;
19755 +       u64 res_limit, res_usage, memsw_limit, memsw_usage;
19756 +       s64 swap_limit, swap_usage;
19757 +
19758 +       rcu_read_lock();
19759 +       mcg = mem_cgroup_from_task(current);
19760 +       rcu_read_unlock();
19761 +       if (!mcg)
19762 +               goto out;
19763 +
19764 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
19765 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
19766 +       memsw_limit = mem_cgroup_memsw_read_u64(mcg, RES_LIMIT);
19767 +       memsw_usage = mem_cgroup_memsw_read_u64(mcg, RES_USAGE);
19768 +
19769 +       /* memory unlimited */
19770 +       if (res_limit == RESOURCE_MAX)
19771 +               goto out;
19772 +
19773 +       swap_limit = memsw_limit - res_limit;
19774 +       /* we have a swap limit? */
19775 +       if (memsw_limit != RESOURCE_MAX)
19776 +               val->totalswap = swap_limit >> PAGE_SHIFT;
19777 +
19778 +       /* calculate swap part */
19779 +       swap_usage = (memsw_usage > res_usage) ?
19780 +               memsw_usage - res_usage : 0;
19781 +
19782 +       /* total shown minus usage gives free swap */
19783 +       val->freeswap = (swap_usage < swap_limit) ?
19784 +               val->totalswap - (swap_usage >> PAGE_SHIFT) : 0;
19785 +out:
19786 +#else  /* !CONFIG_MEMCG_SWAP */
19787 +       val->totalswap = 0;
19788 +       val->freeswap = 0;
19789 +#endif /* !CONFIG_MEMCG_SWAP */
19790 +#endif /* CONFIG_MEMCG */
19791 +       return;
19792 +}
19793 +
19794 +long vx_vsi_cached(struct sysinfo *val)
19795 +{
19796 +       long cache = 0;
19797 +#ifdef CONFIG_MEMCG
19798 +       struct mem_cgroup *mcg;
19799 +
19800 +       rcu_read_lock();
19801 +       mcg = mem_cgroup_from_task(current);
19802 +       rcu_read_unlock();
19803 +       if (!mcg)
19804 +               goto out;
19805 +
19806 +       cache = mem_cgroup_stat_read_cache(mcg);
19807 +out:
19808 +#endif
19809 +       return cache;
19810 +}
19811 +
19812 diff -NurpP --minimal linux-3.9.4/kernel/vserver/limit_init.h linux-3.9.4-vs2.3.6.1/kernel/vserver/limit_init.h
19813 --- linux-3.9.4/kernel/vserver/limit_init.h     1970-01-01 00:00:00.000000000 +0000
19814 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/limit_init.h   2013-05-31 14:47:11.000000000 +0000
19815 @@ -0,0 +1,31 @@
19816 +
19817 +
19818 +static inline void vx_info_init_limit(struct _vx_limit *limit)
19819 +{
19820 +       int lim;
19821 +
19822 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19823 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
19824 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
19825 +               __rlim_set(limit, lim, 0);
19826 +               atomic_set(&__rlim_lhit(limit, lim), 0);
19827 +               __rlim_rmin(limit, lim) = 0;
19828 +               __rlim_rmax(limit, lim) = 0;
19829 +       }
19830 +}
19831 +
19832 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
19833 +{
19834 +       rlim_t value;
19835 +       int lim;
19836 +
19837 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19838 +               if ((1 << lim) & VLIM_NOCHECK)
19839 +                       continue;
19840 +               value = __rlim_get(limit, lim);
19841 +               vxwprintk_xid(value,
19842 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
19843 +                       limit, vlimit_name[lim], lim, (long)value);
19844 +       }
19845 +}
19846 +
19847 diff -NurpP --minimal linux-3.9.4/kernel/vserver/limit_proc.h linux-3.9.4-vs2.3.6.1/kernel/vserver/limit_proc.h
19848 --- linux-3.9.4/kernel/vserver/limit_proc.h     1970-01-01 00:00:00.000000000 +0000
19849 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/limit_proc.h   2013-05-31 14:47:11.000000000 +0000
19850 @@ -0,0 +1,57 @@
19851 +#ifndef _VX_LIMIT_PROC_H
19852 +#define _VX_LIMIT_PROC_H
19853 +
19854 +#include <linux/vserver/limit_int.h>
19855 +
19856 +
19857 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
19858 +#define VX_LIMIT_TOP   \
19859 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
19860 +
19861 +#define VX_LIMIT_ARG(r)                                \
19862 +       (unsigned long)__rlim_get(limit, r),    \
19863 +       (unsigned long)__rlim_rmin(limit, r),   \
19864 +       (unsigned long)__rlim_rmax(limit, r),   \
19865 +       VX_VLIM(__rlim_soft(limit, r)),         \
19866 +       VX_VLIM(__rlim_hard(limit, r)),         \
19867 +       atomic_read(&__rlim_lhit(limit, r))
19868 +
19869 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
19870 +{
19871 +       vx_limit_fixup(limit, -1);
19872 +       return sprintf(buffer, VX_LIMIT_TOP
19873 +               "PROC"  VX_LIMIT_FMT
19874 +               "VM"    VX_LIMIT_FMT
19875 +               "VML"   VX_LIMIT_FMT
19876 +               "RSS"   VX_LIMIT_FMT
19877 +               "ANON"  VX_LIMIT_FMT
19878 +               "RMAP"  VX_LIMIT_FMT
19879 +               "FILES" VX_LIMIT_FMT
19880 +               "OFD"   VX_LIMIT_FMT
19881 +               "LOCKS" VX_LIMIT_FMT
19882 +               "SOCK"  VX_LIMIT_FMT
19883 +               "MSGQ"  VX_LIMIT_FMT
19884 +               "SHM"   VX_LIMIT_FMT
19885 +               "SEMA"  VX_LIMIT_FMT
19886 +               "SEMS"  VX_LIMIT_FMT
19887 +               "DENT"  VX_LIMIT_FMT,
19888 +               VX_LIMIT_ARG(RLIMIT_NPROC),
19889 +               VX_LIMIT_ARG(RLIMIT_AS),
19890 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
19891 +               VX_LIMIT_ARG(RLIMIT_RSS),
19892 +               VX_LIMIT_ARG(VLIMIT_ANON),
19893 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
19894 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
19895 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
19896 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
19897 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
19898 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
19899 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
19900 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
19901 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
19902 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
19903 +}
19904 +
19905 +#endif /* _VX_LIMIT_PROC_H */
19906 +
19907 +
19908 diff -NurpP --minimal linux-3.9.4/kernel/vserver/network.c linux-3.9.4-vs2.3.6.1/kernel/vserver/network.c
19909 --- linux-3.9.4/kernel/vserver/network.c        1970-01-01 00:00:00.000000000 +0000
19910 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/network.c      2013-05-31 14:47:11.000000000 +0000
19911 @@ -0,0 +1,1053 @@
19912 +/*
19913 + *  linux/kernel/vserver/network.c
19914 + *
19915 + *  Virtual Server: Network Support
19916 + *
19917 + *  Copyright (C) 2003-2007  Herbert Pötzl
19918 + *
19919 + *  V0.01  broken out from vcontext V0.05
19920 + *  V0.02  cleaned up implementation
19921 + *  V0.03  added equiv nx commands
19922 + *  V0.04  switch to RCU based hash
19923 + *  V0.05  and back to locking again
19924 + *  V0.06  changed vcmds to nxi arg
19925 + *  V0.07  have __create claim() the nxi
19926 + *
19927 + */
19928 +
19929 +#include <linux/err.h>
19930 +#include <linux/slab.h>
19931 +#include <linux/rcupdate.h>
19932 +#include <net/ipv6.h>
19933 +
19934 +#include <linux/vs_network.h>
19935 +#include <linux/vs_pid.h>
19936 +#include <linux/vserver/network_cmd.h>
19937 +
19938 +
19939 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
19940 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
19941 +
19942 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
19943 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
19944 +
19945 +
19946 +static int __init init_network(void)
19947 +{
19948 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
19949 +               sizeof(struct nx_addr_v4), 0,
19950 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19951 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
19952 +               sizeof(struct nx_addr_v6), 0,
19953 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19954 +       return 0;
19955 +}
19956 +
19957 +
19958 +/*     __alloc_nx_addr_v4()                                    */
19959 +
19960 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
19961 +{
19962 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
19963 +               nx_addr_v4_cachep, GFP_KERNEL);
19964 +
19965 +       if (!IS_ERR(nxa))
19966 +               memset(nxa, 0, sizeof(*nxa));
19967 +       return nxa;
19968 +}
19969 +
19970 +/*     __dealloc_nx_addr_v4()                                  */
19971 +
19972 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
19973 +{
19974 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
19975 +}
19976 +
19977 +/*     __dealloc_nx_addr_v4_all()                              */
19978 +
19979 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
19980 +{
19981 +       while (nxa) {
19982 +               struct nx_addr_v4 *next = nxa->next;
19983 +
19984 +               __dealloc_nx_addr_v4(nxa);
19985 +               nxa = next;
19986 +       }
19987 +}
19988 +
19989 +
19990 +#ifdef CONFIG_IPV6
19991 +
19992 +/*     __alloc_nx_addr_v6()                                    */
19993 +
19994 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
19995 +{
19996 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
19997 +               nx_addr_v6_cachep, GFP_KERNEL);
19998 +
19999 +       if (!IS_ERR(nxa))
20000 +               memset(nxa, 0, sizeof(*nxa));
20001 +       return nxa;
20002 +}
20003 +
20004 +/*     __dealloc_nx_addr_v6()                                  */
20005 +
20006 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
20007 +{
20008 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
20009 +}
20010 +
20011 +/*     __dealloc_nx_addr_v6_all()                              */
20012 +
20013 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
20014 +{
20015 +       while (nxa) {
20016 +               struct nx_addr_v6 *next = nxa->next;
20017 +
20018 +               __dealloc_nx_addr_v6(nxa);
20019 +               nxa = next;
20020 +       }
20021 +}
20022 +
20023 +#endif /* CONFIG_IPV6 */
20024 +
20025 +/*     __alloc_nx_info()
20026 +
20027 +       * allocate an initialized nx_info struct
20028 +       * doesn't make it visible (hash)                        */
20029 +
20030 +static struct nx_info *__alloc_nx_info(nid_t nid)
20031 +{
20032 +       struct nx_info *new = NULL;
20033 +
20034 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
20035 +
20036 +       /* would this benefit from a slab cache? */
20037 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
20038 +       if (!new)
20039 +               return 0;
20040 +
20041 +       memset(new, 0, sizeof(struct nx_info));
20042 +       new->nx_id = nid;
20043 +       INIT_HLIST_NODE(&new->nx_hlist);
20044 +       atomic_set(&new->nx_usecnt, 0);
20045 +       atomic_set(&new->nx_tasks, 0);
20046 +       spin_lock_init(&new->addr_lock);
20047 +       new->nx_state = 0;
20048 +
20049 +       new->nx_flags = NXF_INIT_SET;
20050 +
20051 +       /* rest of init goes here */
20052 +
20053 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
20054 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
20055 +
20056 +       vxdprintk(VXD_CBIT(nid, 0),
20057 +               "alloc_nx_info(%d) = %p", nid, new);
20058 +       atomic_inc(&nx_global_ctotal);
20059 +       return new;
20060 +}
20061 +
20062 +/*     __dealloc_nx_info()
20063 +
20064 +       * final disposal of nx_info                             */
20065 +
20066 +static void __dealloc_nx_info(struct nx_info *nxi)
20067 +{
20068 +       vxdprintk(VXD_CBIT(nid, 0),
20069 +               "dealloc_nx_info(%p)", nxi);
20070 +
20071 +       nxi->nx_hlist.next = LIST_POISON1;
20072 +       nxi->nx_id = -1;
20073 +
20074 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20075 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20076 +
20077 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
20078 +#ifdef CONFIG_IPV6
20079 +       __dealloc_nx_addr_v6_all(nxi->v6.next);
20080 +#endif
20081 +
20082 +       nxi->nx_state |= NXS_RELEASED;
20083 +       kfree(nxi);
20084 +       atomic_dec(&nx_global_ctotal);
20085 +}
20086 +
20087 +static void __shutdown_nx_info(struct nx_info *nxi)
20088 +{
20089 +       nxi->nx_state |= NXS_SHUTDOWN;
20090 +       vs_net_change(nxi, VSC_NETDOWN);
20091 +}
20092 +
20093 +/*     exported stuff                                          */
20094 +
20095 +void free_nx_info(struct nx_info *nxi)
20096 +{
20097 +       /* context shutdown is mandatory */
20098 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
20099 +
20100 +       /* context must not be hashed */
20101 +       BUG_ON(nxi->nx_state & NXS_HASHED);
20102 +
20103 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20104 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20105 +
20106 +       __dealloc_nx_info(nxi);
20107 +}
20108 +
20109 +
20110 +void __nx_set_lback(struct nx_info *nxi)
20111 +{
20112 +       int nid = nxi->nx_id;
20113 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
20114 +
20115 +       nxi->v4_lback.s_addr = lback;
20116 +}
20117 +
20118 +extern int __nx_inet_add_lback(__be32 addr);
20119 +extern int __nx_inet_del_lback(__be32 addr);
20120 +
20121 +
20122 +/*     hash table for nx_info hash */
20123 +
20124 +#define NX_HASH_SIZE   13
20125 +
20126 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
20127 +
20128 +static DEFINE_SPINLOCK(nx_info_hash_lock);
20129 +
20130 +
20131 +static inline unsigned int __hashval(nid_t nid)
20132 +{
20133 +       return (nid % NX_HASH_SIZE);
20134 +}
20135 +
20136 +
20137 +
20138 +/*     __hash_nx_info()
20139 +
20140 +       * add the nxi to the global hash table
20141 +       * requires the hash_lock to be held                     */
20142 +
20143 +static inline void __hash_nx_info(struct nx_info *nxi)
20144 +{
20145 +       struct hlist_head *head;
20146 +
20147 +       vxd_assert_lock(&nx_info_hash_lock);
20148 +       vxdprintk(VXD_CBIT(nid, 4),
20149 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
20150 +
20151 +       /* context must not be hashed */
20152 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
20153 +
20154 +       nxi->nx_state |= NXS_HASHED;
20155 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
20156 +       hlist_add_head(&nxi->nx_hlist, head);
20157 +       atomic_inc(&nx_global_cactive);
20158 +}
20159 +
20160 +/*     __unhash_nx_info()
20161 +
20162 +       * remove the nxi from the global hash table
20163 +       * requires the hash_lock to be held                     */
20164 +
20165 +static inline void __unhash_nx_info(struct nx_info *nxi)
20166 +{
20167 +       vxd_assert_lock(&nx_info_hash_lock);
20168 +       vxdprintk(VXD_CBIT(nid, 4),
20169 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
20170 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
20171 +
20172 +       /* context must be hashed */
20173 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
20174 +       /* but without tasks */
20175 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20176 +
20177 +       nxi->nx_state &= ~NXS_HASHED;
20178 +       hlist_del(&nxi->nx_hlist);
20179 +       atomic_dec(&nx_global_cactive);
20180 +}
20181 +
20182 +
20183 +/*     __lookup_nx_info()
20184 +
20185 +       * requires the hash_lock to be held
20186 +       * doesn't increment the nx_refcnt                       */
20187 +
20188 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
20189 +{
20190 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
20191 +       struct hlist_node *pos;
20192 +       struct nx_info *nxi;
20193 +
20194 +       vxd_assert_lock(&nx_info_hash_lock);
20195 +       hlist_for_each(pos, head) {
20196 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20197 +
20198 +               if (nxi->nx_id == nid)
20199 +                       goto found;
20200 +       }
20201 +       nxi = NULL;
20202 +found:
20203 +       vxdprintk(VXD_CBIT(nid, 0),
20204 +               "__lookup_nx_info(#%u): %p[#%u]",
20205 +               nid, nxi, nxi ? nxi->nx_id : 0);
20206 +       return nxi;
20207 +}
20208 +
20209 +
20210 +/*     __create_nx_info()
20211 +
20212 +       * create the requested context
20213 +       * get(), claim() and hash it                            */
20214 +
20215 +static struct nx_info *__create_nx_info(int id)
20216 +{
20217 +       struct nx_info *new, *nxi = NULL;
20218 +
20219 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
20220 +
20221 +       if (!(new = __alloc_nx_info(id)))
20222 +               return ERR_PTR(-ENOMEM);
20223 +
20224 +       /* required to make dynamic xids unique */
20225 +       spin_lock(&nx_info_hash_lock);
20226 +
20227 +       /* static context requested */
20228 +       if ((nxi = __lookup_nx_info(id))) {
20229 +               vxdprintk(VXD_CBIT(nid, 0),
20230 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
20231 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20232 +                       nxi = ERR_PTR(-EBUSY);
20233 +               else
20234 +                       nxi = ERR_PTR(-EEXIST);
20235 +               goto out_unlock;
20236 +       }
20237 +       /* new context */
20238 +       vxdprintk(VXD_CBIT(nid, 0),
20239 +               "create_nx_info(%d) = %p (new)", id, new);
20240 +       claim_nx_info(new, NULL);
20241 +       __nx_set_lback(new);
20242 +       __hash_nx_info(get_nx_info(new));
20243 +       nxi = new, new = NULL;
20244 +
20245 +out_unlock:
20246 +       spin_unlock(&nx_info_hash_lock);
20247 +       if (new)
20248 +               __dealloc_nx_info(new);
20249 +       return nxi;
20250 +}
20251 +
20252 +
20253 +
20254 +/*     exported stuff                                          */
20255 +
20256 +
20257 +void unhash_nx_info(struct nx_info *nxi)
20258 +{
20259 +       __shutdown_nx_info(nxi);
20260 +       spin_lock(&nx_info_hash_lock);
20261 +       __unhash_nx_info(nxi);
20262 +       spin_unlock(&nx_info_hash_lock);
20263 +}
20264 +
20265 +/*     lookup_nx_info()
20266 +
20267 +       * search for a nx_info and get() it
20268 +       * negative id means current                             */
20269 +
20270 +struct nx_info *lookup_nx_info(int id)
20271 +{
20272 +       struct nx_info *nxi = NULL;
20273 +
20274 +       if (id < 0) {
20275 +               nxi = get_nx_info(current_nx_info());
20276 +       } else if (id > 1) {
20277 +               spin_lock(&nx_info_hash_lock);
20278 +               nxi = get_nx_info(__lookup_nx_info(id));
20279 +               spin_unlock(&nx_info_hash_lock);
20280 +       }
20281 +       return nxi;
20282 +}
20283 +
20284 +/*     nid_is_hashed()
20285 +
20286 +       * verify that nid is still hashed                       */
20287 +
20288 +int nid_is_hashed(nid_t nid)
20289 +{
20290 +       int hashed;
20291 +
20292 +       spin_lock(&nx_info_hash_lock);
20293 +       hashed = (__lookup_nx_info(nid) != NULL);
20294 +       spin_unlock(&nx_info_hash_lock);
20295 +       return hashed;
20296 +}
20297 +
20298 +
20299 +#ifdef CONFIG_PROC_FS
20300 +
20301 +/*     get_nid_list()
20302 +
20303 +       * get a subset of hashed nids for proc
20304 +       * assumes size is at least one                          */
20305 +
20306 +int get_nid_list(int index, unsigned int *nids, int size)
20307 +{
20308 +       int hindex, nr_nids = 0;
20309 +
20310 +       /* only show current and children */
20311 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
20312 +               if (index > 0)
20313 +                       return 0;
20314 +               nids[nr_nids] = nx_current_nid();
20315 +               return 1;
20316 +       }
20317 +
20318 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
20319 +               struct hlist_head *head = &nx_info_hash[hindex];
20320 +               struct hlist_node *pos;
20321 +
20322 +               spin_lock(&nx_info_hash_lock);
20323 +               hlist_for_each(pos, head) {
20324 +                       struct nx_info *nxi;
20325 +
20326 +                       if (--index > 0)
20327 +                               continue;
20328 +
20329 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20330 +                       nids[nr_nids] = nxi->nx_id;
20331 +                       if (++nr_nids >= size) {
20332 +                               spin_unlock(&nx_info_hash_lock);
20333 +                               goto out;
20334 +                       }
20335 +               }
20336 +               /* keep the lock time short */
20337 +               spin_unlock(&nx_info_hash_lock);
20338 +       }
20339 +out:
20340 +       return nr_nids;
20341 +}
20342 +#endif
20343 +
20344 +
20345 +/*
20346 + *     migrate task to new network
20347 + *     gets nxi, puts old_nxi on change
20348 + */
20349 +
20350 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
20351 +{
20352 +       struct nx_info *old_nxi;
20353 +       int ret = 0;
20354 +
20355 +       if (!p || !nxi)
20356 +               BUG();
20357 +
20358 +       vxdprintk(VXD_CBIT(nid, 5),
20359 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
20360 +               p, nxi, nxi->nx_id,
20361 +               atomic_read(&nxi->nx_usecnt),
20362 +               atomic_read(&nxi->nx_tasks));
20363 +
20364 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
20365 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20366 +               return -EACCES;
20367 +
20368 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
20369 +               return -EFAULT;
20370 +
20371 +       /* maybe disallow this completely? */
20372 +       old_nxi = task_get_nx_info(p);
20373 +       if (old_nxi == nxi)
20374 +               goto out;
20375 +
20376 +       task_lock(p);
20377 +       if (old_nxi)
20378 +               clr_nx_info(&p->nx_info);
20379 +       claim_nx_info(nxi, p);
20380 +       set_nx_info(&p->nx_info, nxi);
20381 +       p->nid = nxi->nx_id;
20382 +       task_unlock(p);
20383 +
20384 +       vxdprintk(VXD_CBIT(nid, 5),
20385 +               "moved task %p into nxi:%p[#%d]",
20386 +               p, nxi, nxi->nx_id);
20387 +
20388 +       if (old_nxi)
20389 +               release_nx_info(old_nxi, p);
20390 +       ret = 0;
20391 +out:
20392 +       put_nx_info(old_nxi);
20393 +       return ret;
20394 +}
20395 +
20396 +
20397 +void nx_set_persistent(struct nx_info *nxi)
20398 +{
20399 +       vxdprintk(VXD_CBIT(nid, 6),
20400 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
20401 +
20402 +       get_nx_info(nxi);
20403 +       claim_nx_info(nxi, NULL);
20404 +}
20405 +
20406 +void nx_clear_persistent(struct nx_info *nxi)
20407 +{
20408 +       vxdprintk(VXD_CBIT(nid, 6),
20409 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
20410 +
20411 +       release_nx_info(nxi, NULL);
20412 +       put_nx_info(nxi);
20413 +}
20414 +
20415 +void nx_update_persistent(struct nx_info *nxi)
20416 +{
20417 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
20418 +               nx_set_persistent(nxi);
20419 +       else
20420 +               nx_clear_persistent(nxi);
20421 +}
20422 +
20423 +/* vserver syscall commands below here */
20424 +
20425 +/* taks nid and nx_info functions */
20426 +
20427 +#include <asm/uaccess.h>
20428 +
20429 +
20430 +int vc_task_nid(uint32_t id)
20431 +{
20432 +       nid_t nid;
20433 +
20434 +       if (id) {
20435 +               struct task_struct *tsk;
20436 +
20437 +               rcu_read_lock();
20438 +               tsk = find_task_by_real_pid(id);
20439 +               nid = (tsk) ? tsk->nid : -ESRCH;
20440 +               rcu_read_unlock();
20441 +       } else
20442 +               nid = nx_current_nid();
20443 +       return nid;
20444 +}
20445 +
20446 +
20447 +int vc_nx_info(struct nx_info *nxi, void __user *data)
20448 +{
20449 +       struct vcmd_nx_info_v0 vc_data;
20450 +
20451 +       vc_data.nid = nxi->nx_id;
20452 +
20453 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20454 +               return -EFAULT;
20455 +       return 0;
20456 +}
20457 +
20458 +
20459 +/* network functions */
20460 +
20461 +int vc_net_create(uint32_t nid, void __user *data)
20462 +{
20463 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
20464 +       struct nx_info *new_nxi;
20465 +       int ret;
20466 +
20467 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20468 +               return -EFAULT;
20469 +
20470 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
20471 +               return -EINVAL;
20472 +
20473 +       new_nxi = __create_nx_info(nid);
20474 +       if (IS_ERR(new_nxi))
20475 +               return PTR_ERR(new_nxi);
20476 +
20477 +       /* initial flags */
20478 +       new_nxi->nx_flags = vc_data.flagword;
20479 +
20480 +       ret = -ENOEXEC;
20481 +       if (vs_net_change(new_nxi, VSC_NETUP))
20482 +               goto out;
20483 +
20484 +       ret = nx_migrate_task(current, new_nxi);
20485 +       if (ret)
20486 +               goto out;
20487 +
20488 +       /* return context id on success */
20489 +       ret = new_nxi->nx_id;
20490 +
20491 +       /* get a reference for persistent contexts */
20492 +       if ((vc_data.flagword & NXF_PERSISTENT))
20493 +               nx_set_persistent(new_nxi);
20494 +out:
20495 +       release_nx_info(new_nxi, NULL);
20496 +       put_nx_info(new_nxi);
20497 +       return ret;
20498 +}
20499 +
20500 +
20501 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
20502 +{
20503 +       return nx_migrate_task(current, nxi);
20504 +}
20505 +
20506 +
20507 +static inline
20508 +struct nx_addr_v4 *__find_v4_addr(struct nx_info *nxi,
20509 +       __be32 ip, __be32 ip2, __be32 mask, uint16_t type, uint16_t flags,
20510 +       struct nx_addr_v4 **prev)
20511 +{
20512 +       struct nx_addr_v4 *nxa = &nxi->v4;
20513 +
20514 +       for (; nxa; nxa = nxa->next) {
20515 +               if ((nxa->ip[0].s_addr == ip) &&
20516 +                   (nxa->ip[1].s_addr == ip2) &&
20517 +                   (nxa->mask.s_addr == mask) &&
20518 +                   (nxa->type == type) &&
20519 +                   (nxa->flags == flags))
20520 +                   return nxa;
20521 +
20522 +               /* save previous entry */
20523 +               if (prev)
20524 +                       *prev = nxa;
20525 +       }
20526 +       return NULL;
20527 +}
20528 +
20529 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
20530 +       uint16_t type, uint16_t flags)
20531 +{
20532 +       struct nx_addr_v4 *nxa = NULL;
20533 +       struct nx_addr_v4 *new = __alloc_nx_addr_v4();
20534 +       unsigned long irqflags;
20535 +       int ret = -EEXIST;
20536 +
20537 +       if (IS_ERR(new))
20538 +               return PTR_ERR(new);
20539 +
20540 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
20541 +       if (__find_v4_addr(nxi, ip, ip2, mask, type, flags, &nxa))
20542 +               goto out_unlock;
20543 +
20544 +       if (NX_IPV4(nxi)) {
20545 +               nxa->next = new;
20546 +               nxa = new;
20547 +               new = NULL;
20548 +
20549 +               /* remove single ip for ip list */
20550 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
20551 +       }
20552 +
20553 +       nxa->ip[0].s_addr = ip;
20554 +       nxa->ip[1].s_addr = ip2;
20555 +       nxa->mask.s_addr = mask;
20556 +       nxa->type = type;
20557 +       nxa->flags = flags;
20558 +       ret = 0;
20559 +out_unlock:
20560 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20561 +       if (new)
20562 +               __dealloc_nx_addr_v4(new);
20563 +       return ret;
20564 +}
20565 +
20566 +int do_remove_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
20567 +       uint16_t type, uint16_t flags)
20568 +{
20569 +       struct nx_addr_v4 *nxa = NULL;
20570 +       struct nx_addr_v4 *old = NULL;
20571 +       unsigned long irqflags;
20572 +       int ret = 0;
20573 +
20574 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
20575 +       switch (type) {
20576 +       case NXA_TYPE_ADDR:
20577 +               old = __find_v4_addr(nxi, ip, ip2, mask, type, flags, &nxa);
20578 +               if (old) {
20579 +                       if (nxa) {
20580 +                               nxa->next = old->next;
20581 +                               old->next = NULL;
20582 +                       } else {
20583 +                               if (old->next) {
20584 +                                       nxa = old;
20585 +                                       old = old->next;
20586 +                                       *nxa = *old;
20587 +                                       old->next = NULL;
20588 +                               } else {
20589 +                                       memset(old, 0, sizeof(*old));
20590 +                                       old = NULL;
20591 +                               }
20592 +                       }
20593 +               } else
20594 +                       ret = -ESRCH;
20595 +               break;
20596 +
20597 +       case NXA_TYPE_ANY:
20598 +               nxa = &nxi->v4;
20599 +               old = nxa->next;
20600 +               memset(nxa, 0, sizeof(*nxa));
20601 +               break;
20602 +
20603 +       default:
20604 +               ret = -EINVAL;
20605 +       }
20606 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20607 +       __dealloc_nx_addr_v4_all(old);
20608 +       return ret;
20609 +}
20610 +
20611 +
20612 +int vc_net_add(struct nx_info *nxi, void __user *data)
20613 +{
20614 +       struct vcmd_net_addr_v0 vc_data;
20615 +       int index, ret = 0;
20616 +
20617 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20618 +               return -EFAULT;
20619 +
20620 +       switch (vc_data.type) {
20621 +       case NXA_TYPE_IPV4:
20622 +               if ((vc_data.count < 1) || (vc_data.count > 4))
20623 +                       return -EINVAL;
20624 +
20625 +               index = 0;
20626 +               while (index < vc_data.count) {
20627 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
20628 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
20629 +                       if (ret)
20630 +                               return ret;
20631 +                       index++;
20632 +               }
20633 +               ret = index;
20634 +               break;
20635 +
20636 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
20637 +               nxi->v4_bcast = vc_data.ip[0];
20638 +               ret = 1;
20639 +               break;
20640 +
20641 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
20642 +               nxi->v4_lback = vc_data.ip[0];
20643 +               ret = 1;
20644 +               break;
20645 +
20646 +       default:
20647 +               ret = -EINVAL;
20648 +               break;
20649 +       }
20650 +       return ret;
20651 +}
20652 +
20653 +int vc_net_remove(struct nx_info *nxi, void __user *data)
20654 +{
20655 +       struct vcmd_net_addr_v0 vc_data;
20656 +
20657 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20658 +               return -EFAULT;
20659 +
20660 +       switch (vc_data.type) {
20661 +       case NXA_TYPE_ANY:
20662 +               return do_remove_v4_addr(nxi, 0, 0, 0, vc_data.type, 0);
20663 +       default:
20664 +               return -EINVAL;
20665 +       }
20666 +       return 0;
20667 +}
20668 +
20669 +
20670 +int vc_net_add_ipv4_v1(struct nx_info *nxi, void __user *data)
20671 +{
20672 +       struct vcmd_net_addr_ipv4_v1 vc_data;
20673 +
20674 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20675 +               return -EFAULT;
20676 +
20677 +       switch (vc_data.type) {
20678 +       case NXA_TYPE_ADDR:
20679 +       case NXA_TYPE_MASK:
20680 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
20681 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20682 +
20683 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
20684 +               nxi->v4_bcast = vc_data.ip;
20685 +               break;
20686 +
20687 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
20688 +               nxi->v4_lback = vc_data.ip;
20689 +               break;
20690 +
20691 +       default:
20692 +               return -EINVAL;
20693 +       }
20694 +       return 0;
20695 +}
20696 +
20697 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
20698 +{
20699 +       struct vcmd_net_addr_ipv4_v2 vc_data;
20700 +
20701 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20702 +               return -EFAULT;
20703 +
20704 +       switch (vc_data.type) {
20705 +       case NXA_TYPE_ADDR:
20706 +       case NXA_TYPE_MASK:
20707 +       case NXA_TYPE_RANGE:
20708 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
20709 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20710 +
20711 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
20712 +               nxi->v4_bcast = vc_data.ip;
20713 +               break;
20714 +
20715 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
20716 +               nxi->v4_lback = vc_data.ip;
20717 +               break;
20718 +
20719 +       default:
20720 +               return -EINVAL;
20721 +       }
20722 +       return 0;
20723 +}
20724 +
20725 +int vc_net_rem_ipv4_v1(struct nx_info *nxi, void __user *data)
20726 +{
20727 +       struct vcmd_net_addr_ipv4_v1 vc_data;
20728 +
20729 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20730 +               return -EFAULT;
20731 +
20732 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, 0,
20733 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20734 +}
20735 +
20736 +int vc_net_rem_ipv4(struct nx_info *nxi, void __user *data)
20737 +{
20738 +       struct vcmd_net_addr_ipv4_v2 vc_data;
20739 +
20740 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20741 +               return -EFAULT;
20742 +
20743 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
20744 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20745 +}
20746 +
20747 +#ifdef CONFIG_IPV6
20748 +
20749 +static inline
20750 +struct nx_addr_v6 *__find_v6_addr(struct nx_info *nxi,
20751 +       struct in6_addr *ip, struct in6_addr *mask,
20752 +       uint32_t prefix, uint16_t type, uint16_t flags,
20753 +       struct nx_addr_v6 **prev)
20754 +{
20755 +       struct nx_addr_v6 *nxa = &nxi->v6;
20756 +
20757 +       for (; nxa; nxa = nxa->next) {
20758 +               if (ipv6_addr_equal(&nxa->ip, ip) &&
20759 +                   ipv6_addr_equal(&nxa->mask, mask) &&
20760 +                   (nxa->prefix == prefix) &&
20761 +                   (nxa->type == type) &&
20762 +                   (nxa->flags == flags))
20763 +                   return nxa;
20764 +
20765 +               /* save previous entry */
20766 +               if (prev)
20767 +                       *prev = nxa;
20768 +       }
20769 +       return NULL;
20770 +}
20771 +
20772 +
20773 +int do_add_v6_addr(struct nx_info *nxi,
20774 +       struct in6_addr *ip, struct in6_addr *mask,
20775 +       uint32_t prefix, uint16_t type, uint16_t flags)
20776 +{
20777 +       struct nx_addr_v6 *nxa = NULL;
20778 +       struct nx_addr_v6 *new = __alloc_nx_addr_v6();
20779 +       unsigned long irqflags;
20780 +       int ret = -EEXIST;
20781 +
20782 +       if (IS_ERR(new))
20783 +               return PTR_ERR(new);
20784 +
20785 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
20786 +       if (__find_v6_addr(nxi, ip, mask, prefix, type, flags, &nxa))
20787 +               goto out_unlock;
20788 +
20789 +       if (NX_IPV6(nxi)) {
20790 +               nxa->next = new;
20791 +               nxa = new;
20792 +               new = NULL;
20793 +       }
20794 +
20795 +       nxa->ip = *ip;
20796 +       nxa->mask = *mask;
20797 +       nxa->prefix = prefix;
20798 +       nxa->type = type;
20799 +       nxa->flags = flags;
20800 +       ret = 0;
20801 +out_unlock:
20802 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20803 +       if (new)
20804 +               __dealloc_nx_addr_v6(new);
20805 +       return ret;
20806 +}
20807 +
20808 +int do_remove_v6_addr(struct nx_info *nxi,
20809 +       struct in6_addr *ip, struct in6_addr *mask,
20810 +       uint32_t prefix, uint16_t type, uint16_t flags)
20811 +{
20812 +       struct nx_addr_v6 *nxa = NULL;
20813 +       struct nx_addr_v6 *old = NULL;
20814 +       unsigned long irqflags;
20815 +       int ret = 0;
20816 +
20817 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
20818 +       switch (type) {
20819 +       case NXA_TYPE_ADDR:
20820 +               old = __find_v6_addr(nxi, ip, mask, prefix, type, flags, &nxa);
20821 +               if (old) {
20822 +                       if (nxa) {
20823 +                               nxa->next = old->next;
20824 +                               old->next = NULL;
20825 +                       } else {
20826 +                               if (old->next) {
20827 +                                       nxa = old;
20828 +                                       old = old->next;
20829 +                                       *nxa = *old;
20830 +                                       old->next = NULL;
20831 +                               } else {
20832 +                                       memset(old, 0, sizeof(*old));
20833 +                                       old = NULL;
20834 +                               }
20835 +                       }
20836 +               } else
20837 +                       ret = -ESRCH;
20838 +               break;
20839 +
20840 +       case NXA_TYPE_ANY:
20841 +               nxa = &nxi->v6;
20842 +               old = nxa->next;
20843 +               memset(nxa, 0, sizeof(*nxa));
20844 +               break;
20845 +
20846 +       default:
20847 +               ret = -EINVAL;
20848 +       }
20849 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20850 +       __dealloc_nx_addr_v6_all(old);
20851 +       return ret;
20852 +}
20853 +
20854 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
20855 +{
20856 +       struct vcmd_net_addr_ipv6_v1 vc_data;
20857 +
20858 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20859 +               return -EFAULT;
20860 +
20861 +       switch (vc_data.type) {
20862 +       case NXA_TYPE_ADDR:
20863 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
20864 +               /* fallthrough */
20865 +       case NXA_TYPE_MASK:
20866 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
20867 +                       vc_data.prefix, vc_data.type, vc_data.flags);
20868 +       default:
20869 +               return -EINVAL;
20870 +       }
20871 +       return 0;
20872 +}
20873 +
20874 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
20875 +{
20876 +       struct vcmd_net_addr_ipv6_v1 vc_data;
20877 +
20878 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20879 +               return -EFAULT;
20880 +
20881 +       switch (vc_data.type) {
20882 +       case NXA_TYPE_ADDR:
20883 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
20884 +               /* fallthrough */
20885 +       case NXA_TYPE_MASK:
20886 +               return do_remove_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
20887 +                       vc_data.prefix, vc_data.type, vc_data.flags);
20888 +       case NXA_TYPE_ANY:
20889 +               return do_remove_v6_addr(nxi, NULL, NULL, 0, vc_data.type, 0);
20890 +       default:
20891 +               return -EINVAL;
20892 +       }
20893 +       return 0;
20894 +}
20895 +
20896 +#endif /* CONFIG_IPV6 */
20897 +
20898 +
20899 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
20900 +{
20901 +       struct vcmd_net_flags_v0 vc_data;
20902 +
20903 +       vc_data.flagword = nxi->nx_flags;
20904 +
20905 +       /* special STATE flag handling */
20906 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
20907 +
20908 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20909 +               return -EFAULT;
20910 +       return 0;
20911 +}
20912 +
20913 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
20914 +{
20915 +       struct vcmd_net_flags_v0 vc_data;
20916 +       uint64_t mask, trigger;
20917 +
20918 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20919 +               return -EFAULT;
20920 +
20921 +       /* special STATE flag handling */
20922 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
20923 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
20924 +
20925 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
20926 +               vc_data.flagword, mask);
20927 +       if (trigger & NXF_PERSISTENT)
20928 +               nx_update_persistent(nxi);
20929 +
20930 +       return 0;
20931 +}
20932 +
20933 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
20934 +{
20935 +       struct vcmd_net_caps_v0 vc_data;
20936 +
20937 +       vc_data.ncaps = nxi->nx_ncaps;
20938 +       vc_data.cmask = ~0ULL;
20939 +
20940 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20941 +               return -EFAULT;
20942 +       return 0;
20943 +}
20944 +
20945 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
20946 +{
20947 +       struct vcmd_net_caps_v0 vc_data;
20948 +
20949 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20950 +               return -EFAULT;
20951 +
20952 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
20953 +               vc_data.ncaps, vc_data.cmask);
20954 +       return 0;
20955 +}
20956 +
20957 +
20958 +#include <linux/module.h>
20959 +
20960 +module_init(init_network);
20961 +
20962 +EXPORT_SYMBOL_GPL(free_nx_info);
20963 +EXPORT_SYMBOL_GPL(unhash_nx_info);
20964 +
20965 diff -NurpP --minimal linux-3.9.4/kernel/vserver/proc.c linux-3.9.4-vs2.3.6.1/kernel/vserver/proc.c
20966 --- linux-3.9.4/kernel/vserver/proc.c   1970-01-01 00:00:00.000000000 +0000
20967 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/proc.c 2013-05-31 14:47:11.000000000 +0000
20968 @@ -0,0 +1,1110 @@
20969 +/*
20970 + *  linux/kernel/vserver/proc.c
20971 + *
20972 + *  Virtual Context Support
20973 + *
20974 + *  Copyright (C) 2003-2011  Herbert Pötzl
20975 + *
20976 + *  V0.01  basic structure
20977 + *  V0.02  adaptation vs1.3.0
20978 + *  V0.03  proc permissions
20979 + *  V0.04  locking/generic
20980 + *  V0.05  next generation procfs
20981 + *  V0.06  inode validation
20982 + *  V0.07  generic rewrite vid
20983 + *  V0.08  remove inode type
20984 + *  V0.09  added u/wmask info
20985 + *
20986 + */
20987 +
20988 +#include <linux/proc_fs.h>
20989 +#include <linux/fs_struct.h>
20990 +#include <linux/mount.h>
20991 +#include <linux/namei.h>
20992 +#include <asm/unistd.h>
20993 +
20994 +#include <linux/vs_context.h>
20995 +#include <linux/vs_network.h>
20996 +#include <linux/vs_cvirt.h>
20997 +
20998 +#include <linux/in.h>
20999 +#include <linux/inetdevice.h>
21000 +#include <linux/vs_inet.h>
21001 +#include <linux/vs_inet6.h>
21002 +
21003 +#include <linux/vserver/global.h>
21004 +
21005 +#include "cvirt_proc.h"
21006 +#include "cacct_proc.h"
21007 +#include "limit_proc.h"
21008 +#include "sched_proc.h"
21009 +#include "vci_config.h"
21010 +
21011 +
21012 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
21013 +{
21014 +       unsigned __capi;
21015 +
21016 +       CAP_FOR_EACH_U32(__capi) {
21017 +               buffer += sprintf(buffer, "%08x",
21018 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
21019 +       }
21020 +       return buffer;
21021 +}
21022 +
21023 +
21024 +static struct proc_dir_entry *proc_virtual;
21025 +
21026 +static struct proc_dir_entry *proc_virtnet;
21027 +
21028 +
21029 +/* first the actual feeds */
21030 +
21031 +
21032 +static int proc_vci(char *buffer)
21033 +{
21034 +       return sprintf(buffer,
21035 +               "VCIVersion:\t%04x:%04x\n"
21036 +               "VCISyscall:\t%d\n"
21037 +               "VCIKernel:\t%08x\n",
21038 +               VCI_VERSION >> 16,
21039 +               VCI_VERSION & 0xFFFF,
21040 +               __NR_vserver,
21041 +               vci_kernel_config());
21042 +}
21043 +
21044 +static int proc_virtual_info(char *buffer)
21045 +{
21046 +       return proc_vci(buffer);
21047 +}
21048 +
21049 +static int proc_virtual_status(char *buffer)
21050 +{
21051 +       return sprintf(buffer,
21052 +               "#CTotal:\t%d\n"
21053 +               "#CActive:\t%d\n"
21054 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
21055 +               "#InitTask:\t%d\t%d %d\n",
21056 +               atomic_read(&vx_global_ctotal),
21057 +               atomic_read(&vx_global_cactive),
21058 +               atomic_read(&vs_global_nsproxy),
21059 +               atomic_read(&vs_global_fs),
21060 +               atomic_read(&vs_global_mnt_ns),
21061 +               atomic_read(&vs_global_uts_ns),
21062 +               atomic_read(&nr_ipc_ns),
21063 +               atomic_read(&vs_global_user_ns),
21064 +               atomic_read(&vs_global_pid_ns),
21065 +               atomic_read(&init_task.usage),
21066 +               atomic_read(&init_task.nsproxy->count),
21067 +               init_task.fs->users);
21068 +}
21069 +
21070 +
21071 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
21072 +{
21073 +       int length;
21074 +
21075 +       length = sprintf(buffer,
21076 +               "ID:\t%d\n"
21077 +               "Info:\t%p\n"
21078 +               "Init:\t%d\n"
21079 +               "OOM:\t%lld\n",
21080 +               vxi->vx_id,
21081 +               vxi,
21082 +               vxi->vx_initpid,
21083 +               vxi->vx_badness_bias);
21084 +       return length;
21085 +}
21086 +
21087 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
21088 +{
21089 +       char *orig = buffer;
21090 +
21091 +       buffer += sprintf(buffer,
21092 +               "UseCnt:\t%d\n"
21093 +               "Tasks:\t%d\n"
21094 +               "Flags:\t%016llx\n",
21095 +               atomic_read(&vxi->vx_usecnt),
21096 +               atomic_read(&vxi->vx_tasks),
21097 +               (unsigned long long)vxi->vx_flags);
21098 +
21099 +       buffer += sprintf(buffer, "BCaps:\t");
21100 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
21101 +       buffer += sprintf(buffer, "\n");
21102 +
21103 +       buffer += sprintf(buffer,
21104 +               "CCaps:\t%016llx\n"
21105 +               "Umask:\t%16llx\n"
21106 +               "Wmask:\t%16llx\n"
21107 +               "Spaces:\t%08lx %08lx\n",
21108 +               (unsigned long long)vxi->vx_ccaps,
21109 +               (unsigned long long)vxi->vx_umask,
21110 +               (unsigned long long)vxi->vx_wmask,
21111 +               vxi->space[0].vx_nsmask, vxi->space[1].vx_nsmask);
21112 +       return buffer - orig;
21113 +}
21114 +
21115 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
21116 +{
21117 +       return vx_info_proc_limit(&vxi->limit, buffer);
21118 +}
21119 +
21120 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
21121 +{
21122 +       int cpu, length;
21123 +
21124 +       length = vx_info_proc_sched(&vxi->sched, buffer);
21125 +       for_each_online_cpu(cpu) {
21126 +               length += vx_info_proc_sched_pc(
21127 +                       &vx_per_cpu(vxi, sched_pc, cpu),
21128 +                       buffer + length, cpu);
21129 +       }
21130 +       return length;
21131 +}
21132 +
21133 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
21134 +{
21135 +       return vx_info_proc_nsproxy(vxi->space[0].vx_nsproxy, buffer);
21136 +}
21137 +
21138 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
21139 +{
21140 +       return vx_info_proc_nsproxy(vxi->space[1].vx_nsproxy, buffer);
21141 +}
21142 +
21143 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
21144 +{
21145 +       int cpu, length;
21146 +
21147 +       vx_update_load(vxi);
21148 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
21149 +       for_each_online_cpu(cpu) {
21150 +               length += vx_info_proc_cvirt_pc(
21151 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
21152 +                       buffer + length, cpu);
21153 +       }
21154 +       return length;
21155 +}
21156 +
21157 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
21158 +{
21159 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
21160 +}
21161 +
21162 +
21163 +static int proc_virtnet_info(char *buffer)
21164 +{
21165 +       return proc_vci(buffer);
21166 +}
21167 +
21168 +static int proc_virtnet_status(char *buffer)
21169 +{
21170 +       return sprintf(buffer,
21171 +               "#CTotal:\t%d\n"
21172 +               "#CActive:\t%d\n",
21173 +               atomic_read(&nx_global_ctotal),
21174 +               atomic_read(&nx_global_cactive));
21175 +}
21176 +
21177 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
21178 +{
21179 +       struct nx_addr_v4 *v4a;
21180 +#ifdef CONFIG_IPV6
21181 +       struct nx_addr_v6 *v6a;
21182 +#endif
21183 +       int length, i;
21184 +
21185 +       length = sprintf(buffer,
21186 +               "ID:\t%d\n"
21187 +               "Info:\t%p\n"
21188 +               "Bcast:\t" NIPQUAD_FMT "\n"
21189 +               "Lback:\t" NIPQUAD_FMT "\n",
21190 +               nxi->nx_id,
21191 +               nxi,
21192 +               NIPQUAD(nxi->v4_bcast.s_addr),
21193 +               NIPQUAD(nxi->v4_lback.s_addr));
21194 +
21195 +       if (!NX_IPV4(nxi))
21196 +               goto skip_v4;
21197 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
21198 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
21199 +                       i, NXAV4(v4a));
21200 +skip_v4:
21201 +#ifdef CONFIG_IPV6
21202 +       if (!NX_IPV6(nxi))
21203 +               goto skip_v6;
21204 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
21205 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
21206 +                       i, NXAV6(v6a));
21207 +skip_v6:
21208 +#endif
21209 +       return length;
21210 +}
21211 +
21212 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
21213 +{
21214 +       int length;
21215 +
21216 +       length = sprintf(buffer,
21217 +               "UseCnt:\t%d\n"
21218 +               "Tasks:\t%d\n"
21219 +               "Flags:\t%016llx\n"
21220 +               "NCaps:\t%016llx\n",
21221 +               atomic_read(&nxi->nx_usecnt),
21222 +               atomic_read(&nxi->nx_tasks),
21223 +               (unsigned long long)nxi->nx_flags,
21224 +               (unsigned long long)nxi->nx_ncaps);
21225 +       return length;
21226 +}
21227 +
21228 +
21229 +
21230 +/* here the inode helpers */
21231 +
21232 +struct vs_entry {
21233 +       int len;
21234 +       char *name;
21235 +       mode_t mode;
21236 +       struct inode_operations *iop;
21237 +       struct file_operations *fop;
21238 +       union proc_op op;
21239 +};
21240 +
21241 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
21242 +{
21243 +       struct inode *inode = new_inode(sb);
21244 +
21245 +       if (!inode)
21246 +               goto out;
21247 +
21248 +       inode->i_mode = p->mode;
21249 +       if (p->iop)
21250 +               inode->i_op = p->iop;
21251 +       if (p->fop)
21252 +               inode->i_fop = p->fop;
21253 +
21254 +       set_nlink(inode, (p->mode & S_IFDIR) ? 2 : 1);
21255 +       inode->i_flags |= S_IMMUTABLE;
21256 +
21257 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
21258 +
21259 +       inode->i_uid = 0;
21260 +       inode->i_gid = 0;
21261 +       inode->i_tag = 0;
21262 +out:
21263 +       return inode;
21264 +}
21265 +
21266 +static struct dentry *vs_proc_instantiate(struct inode *dir,
21267 +       struct dentry *dentry, int id, void *ptr)
21268 +{
21269 +       struct vs_entry *p = ptr;
21270 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
21271 +       struct dentry *error = ERR_PTR(-EINVAL);
21272 +
21273 +       if (!inode)
21274 +               goto out;
21275 +
21276 +       PROC_I(inode)->op = p->op;
21277 +       PROC_I(inode)->fd = id;
21278 +       d_add(dentry, inode);
21279 +       error = NULL;
21280 +out:
21281 +       return error;
21282 +}
21283 +
21284 +/* Lookups */
21285 +
21286 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
21287 +
21288 +/*
21289 + * Fill a directory entry.
21290 + *
21291 + * If possible create the dcache entry and derive our inode number and
21292 + * file type from dcache entry.
21293 + *
21294 + * Since all of the proc inode numbers are dynamically generated, the inode
21295 + * numbers do not exist until the inode is cache.  This means creating the
21296 + * the dcache entry in readdir is necessary to keep the inode numbers
21297 + * reported by readdir in sync with the inode numbers reported
21298 + * by stat.
21299 + */
21300 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
21301 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
21302 +{
21303 +       struct dentry *child, *dir = filp->f_dentry;
21304 +       struct inode *inode;
21305 +       struct qstr qname;
21306 +       ino_t ino = 0;
21307 +       unsigned type = DT_UNKNOWN;
21308 +
21309 +       qname.name = name;
21310 +       qname.len  = len;
21311 +       qname.hash = full_name_hash(name, len);
21312 +
21313 +       child = d_lookup(dir, &qname);
21314 +       if (!child) {
21315 +               struct dentry *new;
21316 +               new = d_alloc(dir, &qname);
21317 +               if (new) {
21318 +                       child = instantiate(dir->d_inode, new, id, ptr);
21319 +                       if (child)
21320 +                               dput(new);
21321 +                       else
21322 +                               child = new;
21323 +               }
21324 +       }
21325 +       if (!child || IS_ERR(child) || !child->d_inode)
21326 +               goto end_instantiate;
21327 +       inode = child->d_inode;
21328 +       if (inode) {
21329 +               ino = inode->i_ino;
21330 +               type = inode->i_mode >> 12;
21331 +       }
21332 +       dput(child);
21333 +end_instantiate:
21334 +       if (!ino)
21335 +               ino = find_inode_number(dir, &qname);
21336 +       if (!ino)
21337 +               ino = 1;
21338 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
21339 +}
21340 +
21341 +
21342 +
21343 +/* get and revalidate vx_info/xid */
21344 +
21345 +static inline
21346 +struct vx_info *get_proc_vx_info(struct inode *inode)
21347 +{
21348 +       return lookup_vx_info(PROC_I(inode)->fd);
21349 +}
21350 +
21351 +static int proc_xid_revalidate(struct dentry *dentry, unsigned int flags)
21352 +{
21353 +       struct inode *inode = dentry->d_inode;
21354 +       xid_t xid = PROC_I(inode)->fd;
21355 +
21356 +       if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
21357 +               return -ECHILD;
21358 +
21359 +       if (!xid || xid_is_hashed(xid))
21360 +               return 1;
21361 +       d_drop(dentry);
21362 +       return 0;
21363 +}
21364 +
21365 +
21366 +/* get and revalidate nx_info/nid */
21367 +
21368 +static int proc_nid_revalidate(struct dentry *dentry, unsigned int flags)
21369 +{
21370 +       struct inode *inode = dentry->d_inode;
21371 +       nid_t nid = PROC_I(inode)->fd;
21372 +
21373 +       if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
21374 +               return -ECHILD;
21375 +
21376 +       if (!nid || nid_is_hashed(nid))
21377 +               return 1;
21378 +       d_drop(dentry);
21379 +       return 0;
21380 +}
21381 +
21382 +
21383 +
21384 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
21385 +
21386 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
21387 +                         size_t count, loff_t *ppos)
21388 +{
21389 +       struct inode *inode = file->f_dentry->d_inode;
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(PROC_I(inode)->fd);
21398 +
21399 +       if (!(page = __get_free_page(GFP_KERNEL)))
21400 +               return -ENOMEM;
21401 +
21402 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
21403 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
21404 +
21405 +       if (length >= 0)
21406 +               length = simple_read_from_buffer(buf, count, ppos,
21407 +                       (char *)page, length);
21408 +
21409 +       free_page(page);
21410 +       return length;
21411 +}
21412 +
21413 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
21414 +                         size_t count, loff_t *ppos)
21415 +{
21416 +       struct inode *inode = file->f_dentry->d_inode;
21417 +       struct vx_info *vxi = NULL;
21418 +       xid_t xid = PROC_I(inode)->fd;
21419 +       unsigned long page;
21420 +       ssize_t length = 0;
21421 +
21422 +       if (count > PROC_BLOCK_SIZE)
21423 +               count = PROC_BLOCK_SIZE;
21424 +
21425 +       /* fade that out as soon as stable */
21426 +       WARN_ON(!xid);
21427 +       vxi = lookup_vx_info(xid);
21428 +       if (!vxi)
21429 +               goto out;
21430 +
21431 +       length = -ENOMEM;
21432 +       if (!(page = __get_free_page(GFP_KERNEL)))
21433 +               goto out_put;
21434 +
21435 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
21436 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
21437 +
21438 +       if (length >= 0)
21439 +               length = simple_read_from_buffer(buf, count, ppos,
21440 +                       (char *)page, length);
21441 +
21442 +       free_page(page);
21443 +out_put:
21444 +       put_vx_info(vxi);
21445 +out:
21446 +       return length;
21447 +}
21448 +
21449 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
21450 +                         size_t count, loff_t *ppos)
21451 +{
21452 +       struct inode *inode = file->f_dentry->d_inode;
21453 +       struct nx_info *nxi = NULL;
21454 +       nid_t nid = PROC_I(inode)->fd;
21455 +       unsigned long page;
21456 +       ssize_t length = 0;
21457 +
21458 +       if (count > PROC_BLOCK_SIZE)
21459 +               count = PROC_BLOCK_SIZE;
21460 +
21461 +       /* fade that out as soon as stable */
21462 +       WARN_ON(!nid);
21463 +       nxi = lookup_nx_info(nid);
21464 +       if (!nxi)
21465 +               goto out;
21466 +
21467 +       length = -ENOMEM;
21468 +       if (!(page = __get_free_page(GFP_KERNEL)))
21469 +               goto out_put;
21470 +
21471 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
21472 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
21473 +
21474 +       if (length >= 0)
21475 +               length = simple_read_from_buffer(buf, count, ppos,
21476 +                       (char *)page, length);
21477 +
21478 +       free_page(page);
21479 +out_put:
21480 +       put_nx_info(nxi);
21481 +out:
21482 +       return length;
21483 +}
21484 +
21485 +
21486 +
21487 +/* here comes the lower level */
21488 +
21489 +
21490 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
21491 +       .len  = sizeof(NAME) - 1,       \
21492 +       .name = (NAME),                 \
21493 +       .mode = MODE,                   \
21494 +       .iop  = IOP,                    \
21495 +       .fop  = FOP,                    \
21496 +       .op   = OP,                     \
21497 +}
21498 +
21499 +
21500 +#define DIR(NAME, MODE, OTYPE)                         \
21501 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
21502 +               &proc_ ## OTYPE ## _inode_operations,   \
21503 +               &proc_ ## OTYPE ## _file_operations, { } )
21504 +
21505 +#define INF(NAME, MODE, OTYPE)                         \
21506 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21507 +               &proc_vs_info_file_operations,          \
21508 +               { .proc_vs_read = &proc_##OTYPE } )
21509 +
21510 +#define VINF(NAME, MODE, OTYPE)                                \
21511 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21512 +               &proc_vx_info_file_operations,          \
21513 +               { .proc_vxi_read = &proc_##OTYPE } )
21514 +
21515 +#define NINF(NAME, MODE, OTYPE)                                \
21516 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21517 +               &proc_nx_info_file_operations,          \
21518 +               { .proc_nxi_read = &proc_##OTYPE } )
21519 +
21520 +
21521 +static struct file_operations proc_vs_info_file_operations = {
21522 +       .read =         proc_vs_info_read,
21523 +};
21524 +
21525 +static struct file_operations proc_vx_info_file_operations = {
21526 +       .read =         proc_vx_info_read,
21527 +};
21528 +
21529 +static struct dentry_operations proc_xid_dentry_operations = {
21530 +       .d_revalidate = proc_xid_revalidate,
21531 +};
21532 +
21533 +static struct vs_entry vx_base_stuff[] = {
21534 +       VINF("info",    S_IRUGO, vxi_info),
21535 +       VINF("status",  S_IRUGO, vxi_status),
21536 +       VINF("limit",   S_IRUGO, vxi_limit),
21537 +       VINF("sched",   S_IRUGO, vxi_sched),
21538 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
21539 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
21540 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
21541 +       VINF("cacct",   S_IRUGO, vxi_cacct),
21542 +       {}
21543 +};
21544 +
21545 +
21546 +
21547 +
21548 +static struct dentry *proc_xid_instantiate(struct inode *dir,
21549 +       struct dentry *dentry, int id, void *ptr)
21550 +{
21551 +       dentry->d_op = &proc_xid_dentry_operations;
21552 +       return vs_proc_instantiate(dir, dentry, id, ptr);
21553 +}
21554 +
21555 +static struct dentry *proc_xid_lookup(struct inode *dir,
21556 +       struct dentry *dentry, unsigned int flags)
21557 +{
21558 +       struct vs_entry *p = vx_base_stuff;
21559 +       struct dentry *error = ERR_PTR(-ENOENT);
21560 +
21561 +       for (; p->name; p++) {
21562 +               if (p->len != dentry->d_name.len)
21563 +                       continue;
21564 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21565 +                       break;
21566 +       }
21567 +       if (!p->name)
21568 +               goto out;
21569 +
21570 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
21571 +out:
21572 +       return error;
21573 +}
21574 +
21575 +static int proc_xid_readdir(struct file *filp,
21576 +       void *dirent, filldir_t filldir)
21577 +{
21578 +       struct dentry *dentry = filp->f_dentry;
21579 +       struct inode *inode = dentry->d_inode;
21580 +       struct vs_entry *p = vx_base_stuff;
21581 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
21582 +       int pos, index;
21583 +       u64 ino;
21584 +
21585 +       pos = filp->f_pos;
21586 +       switch (pos) {
21587 +       case 0:
21588 +               ino = inode->i_ino;
21589 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21590 +                       goto out;
21591 +               pos++;
21592 +               /* fall through */
21593 +       case 1:
21594 +               ino = parent_ino(dentry);
21595 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21596 +                       goto out;
21597 +               pos++;
21598 +               /* fall through */
21599 +       default:
21600 +               index = pos - 2;
21601 +               if (index >= size)
21602 +                       goto out;
21603 +               for (p += index; p->name; p++) {
21604 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21605 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
21606 +                               goto out;
21607 +                       pos++;
21608 +               }
21609 +       }
21610 +out:
21611 +       filp->f_pos = pos;
21612 +       return 1;
21613 +}
21614 +
21615 +
21616 +
21617 +static struct file_operations proc_nx_info_file_operations = {
21618 +       .read =         proc_nx_info_read,
21619 +};
21620 +
21621 +static struct dentry_operations proc_nid_dentry_operations = {
21622 +       .d_revalidate = proc_nid_revalidate,
21623 +};
21624 +
21625 +static struct vs_entry nx_base_stuff[] = {
21626 +       NINF("info",    S_IRUGO, nxi_info),
21627 +       NINF("status",  S_IRUGO, nxi_status),
21628 +       {}
21629 +};
21630 +
21631 +
21632 +static struct dentry *proc_nid_instantiate(struct inode *dir,
21633 +       struct dentry *dentry, int id, void *ptr)
21634 +{
21635 +       dentry->d_op = &proc_nid_dentry_operations;
21636 +       return vs_proc_instantiate(dir, dentry, id, ptr);
21637 +}
21638 +
21639 +static struct dentry *proc_nid_lookup(struct inode *dir,
21640 +       struct dentry *dentry, unsigned int flags)
21641 +{
21642 +       struct vs_entry *p = nx_base_stuff;
21643 +       struct dentry *error = ERR_PTR(-ENOENT);
21644 +
21645 +       for (; p->name; p++) {
21646 +               if (p->len != dentry->d_name.len)
21647 +                       continue;
21648 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21649 +                       break;
21650 +       }
21651 +       if (!p->name)
21652 +               goto out;
21653 +
21654 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
21655 +out:
21656 +       return error;
21657 +}
21658 +
21659 +static int proc_nid_readdir(struct file *filp,
21660 +       void *dirent, filldir_t filldir)
21661 +{
21662 +       struct dentry *dentry = filp->f_dentry;
21663 +       struct inode *inode = dentry->d_inode;
21664 +       struct vs_entry *p = nx_base_stuff;
21665 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
21666 +       int pos, index;
21667 +       u64 ino;
21668 +
21669 +       pos = filp->f_pos;
21670 +       switch (pos) {
21671 +       case 0:
21672 +               ino = inode->i_ino;
21673 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21674 +                       goto out;
21675 +               pos++;
21676 +               /* fall through */
21677 +       case 1:
21678 +               ino = parent_ino(dentry);
21679 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21680 +                       goto out;
21681 +               pos++;
21682 +               /* fall through */
21683 +       default:
21684 +               index = pos - 2;
21685 +               if (index >= size)
21686 +                       goto out;
21687 +               for (p += index; p->name; p++) {
21688 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21689 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
21690 +                               goto out;
21691 +                       pos++;
21692 +               }
21693 +       }
21694 +out:
21695 +       filp->f_pos = pos;
21696 +       return 1;
21697 +}
21698 +
21699 +
21700 +#define MAX_MULBY10    ((~0U - 9) / 10)
21701 +
21702 +static inline int atovid(const char *str, int len)
21703 +{
21704 +       int vid, c;
21705 +
21706 +       vid = 0;
21707 +       while (len-- > 0) {
21708 +               c = *str - '0';
21709 +               str++;
21710 +               if (c > 9)
21711 +                       return -1;
21712 +               if (vid >= MAX_MULBY10)
21713 +                       return -1;
21714 +               vid *= 10;
21715 +               vid += c;
21716 +               if (!vid)
21717 +                       return -1;
21718 +       }
21719 +       return vid;
21720 +}
21721 +
21722 +/* now the upper level (virtual) */
21723 +
21724 +
21725 +static struct file_operations proc_xid_file_operations = {
21726 +       .read =         generic_read_dir,
21727 +       .readdir =      proc_xid_readdir,
21728 +};
21729 +
21730 +static struct inode_operations proc_xid_inode_operations = {
21731 +       .lookup =       proc_xid_lookup,
21732 +};
21733 +
21734 +static struct vs_entry vx_virtual_stuff[] = {
21735 +       INF("info",     S_IRUGO, virtual_info),
21736 +       INF("status",   S_IRUGO, virtual_status),
21737 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
21738 +};
21739 +
21740 +
21741 +static struct dentry *proc_virtual_lookup(struct inode *dir,
21742 +       struct dentry *dentry, unsigned int flags)
21743 +{
21744 +       struct vs_entry *p = vx_virtual_stuff;
21745 +       struct dentry *error = ERR_PTR(-ENOENT);
21746 +       int id = 0;
21747 +
21748 +       for (; p->name; p++) {
21749 +               if (p->len != dentry->d_name.len)
21750 +                       continue;
21751 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21752 +                       break;
21753 +       }
21754 +       if (p->name)
21755 +               goto instantiate;
21756 +
21757 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
21758 +       if ((id < 0) || !xid_is_hashed(id))
21759 +               goto out;
21760 +
21761 +instantiate:
21762 +       error = proc_xid_instantiate(dir, dentry, id, p);
21763 +out:
21764 +       return error;
21765 +}
21766 +
21767 +static struct file_operations proc_nid_file_operations = {
21768 +       .read =         generic_read_dir,
21769 +       .readdir =      proc_nid_readdir,
21770 +};
21771 +
21772 +static struct inode_operations proc_nid_inode_operations = {
21773 +       .lookup =       proc_nid_lookup,
21774 +};
21775 +
21776 +static struct vs_entry nx_virtnet_stuff[] = {
21777 +       INF("info",     S_IRUGO, virtnet_info),
21778 +       INF("status",   S_IRUGO, virtnet_status),
21779 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
21780 +};
21781 +
21782 +
21783 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
21784 +       struct dentry *dentry, unsigned int flags)
21785 +{
21786 +       struct vs_entry *p = nx_virtnet_stuff;
21787 +       struct dentry *error = ERR_PTR(-ENOENT);
21788 +       int id = 0;
21789 +
21790 +       for (; p->name; p++) {
21791 +               if (p->len != dentry->d_name.len)
21792 +                       continue;
21793 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21794 +                       break;
21795 +       }
21796 +       if (p->name)
21797 +               goto instantiate;
21798 +
21799 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
21800 +       if ((id < 0) || !nid_is_hashed(id))
21801 +               goto out;
21802 +
21803 +instantiate:
21804 +       error = proc_nid_instantiate(dir, dentry, id, p);
21805 +out:
21806 +       return error;
21807 +}
21808 +
21809 +
21810 +#define PROC_MAXVIDS 32
21811 +
21812 +int proc_virtual_readdir(struct file *filp,
21813 +       void *dirent, filldir_t filldir)
21814 +{
21815 +       struct dentry *dentry = filp->f_dentry;
21816 +       struct inode *inode = dentry->d_inode;
21817 +       struct vs_entry *p = vx_virtual_stuff;
21818 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
21819 +       int pos, index;
21820 +       unsigned int xid_array[PROC_MAXVIDS];
21821 +       char buf[PROC_NUMBUF];
21822 +       unsigned int nr_xids, i;
21823 +       u64 ino;
21824 +
21825 +       pos = filp->f_pos;
21826 +       switch (pos) {
21827 +       case 0:
21828 +               ino = inode->i_ino;
21829 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21830 +                       goto out;
21831 +               pos++;
21832 +               /* fall through */
21833 +       case 1:
21834 +               ino = parent_ino(dentry);
21835 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21836 +                       goto out;
21837 +               pos++;
21838 +               /* fall through */
21839 +       default:
21840 +               index = pos - 2;
21841 +               if (index >= size)
21842 +                       goto entries;
21843 +               for (p += index; p->name; p++) {
21844 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21845 +                               vs_proc_instantiate, 0, p))
21846 +                               goto out;
21847 +                       pos++;
21848 +               }
21849 +       entries:
21850 +               index = pos - size;
21851 +               p = &vx_virtual_stuff[size - 1];
21852 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
21853 +               for (i = 0; i < nr_xids; i++) {
21854 +                       int n, xid = xid_array[i];
21855 +                       unsigned int j = PROC_NUMBUF;
21856 +
21857 +                       n = xid;
21858 +                       do
21859 +                               buf[--j] = '0' + (n % 10);
21860 +                       while (n /= 10);
21861 +
21862 +                       if (proc_fill_cache(filp, dirent, filldir,
21863 +                               buf + j, PROC_NUMBUF - j,
21864 +                               vs_proc_instantiate, xid, p))
21865 +                               goto out;
21866 +                       pos++;
21867 +               }
21868 +       }
21869 +out:
21870 +       filp->f_pos = pos;
21871 +       return 0;
21872 +}
21873 +
21874 +static int proc_virtual_getattr(struct vfsmount *mnt,
21875 +       struct dentry *dentry, struct kstat *stat)
21876 +{
21877 +       struct inode *inode = dentry->d_inode;
21878 +
21879 +       generic_fillattr(inode, stat);
21880 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
21881 +       return 0;
21882 +}
21883 +
21884 +static struct file_operations proc_virtual_dir_operations = {
21885 +       .read =         generic_read_dir,
21886 +       .readdir =      proc_virtual_readdir,
21887 +};
21888 +
21889 +static struct inode_operations proc_virtual_dir_inode_operations = {
21890 +       .getattr =      proc_virtual_getattr,
21891 +       .lookup =       proc_virtual_lookup,
21892 +};
21893 +
21894 +
21895 +
21896 +
21897 +
21898 +int proc_virtnet_readdir(struct file *filp,
21899 +       void *dirent, filldir_t filldir)
21900 +{
21901 +       struct dentry *dentry = filp->f_dentry;
21902 +       struct inode *inode = dentry->d_inode;
21903 +       struct vs_entry *p = nx_virtnet_stuff;
21904 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
21905 +       int pos, index;
21906 +       unsigned int nid_array[PROC_MAXVIDS];
21907 +       char buf[PROC_NUMBUF];
21908 +       unsigned int nr_nids, i;
21909 +       u64 ino;
21910 +
21911 +       pos = filp->f_pos;
21912 +       switch (pos) {
21913 +       case 0:
21914 +               ino = inode->i_ino;
21915 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21916 +                       goto out;
21917 +               pos++;
21918 +               /* fall through */
21919 +       case 1:
21920 +               ino = parent_ino(dentry);
21921 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21922 +                       goto out;
21923 +               pos++;
21924 +               /* fall through */
21925 +       default:
21926 +               index = pos - 2;
21927 +               if (index >= size)
21928 +                       goto entries;
21929 +               for (p += index; p->name; p++) {
21930 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21931 +                               vs_proc_instantiate, 0, p))
21932 +                               goto out;
21933 +                       pos++;
21934 +               }
21935 +       entries:
21936 +               index = pos - size;
21937 +               p = &nx_virtnet_stuff[size - 1];
21938 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
21939 +               for (i = 0; i < nr_nids; i++) {
21940 +                       int n, nid = nid_array[i];
21941 +                       unsigned int j = PROC_NUMBUF;
21942 +
21943 +                       n = nid;
21944 +                       do
21945 +                               buf[--j] = '0' + (n % 10);
21946 +                       while (n /= 10);
21947 +
21948 +                       if (proc_fill_cache(filp, dirent, filldir,
21949 +                               buf + j, PROC_NUMBUF - j,
21950 +                               vs_proc_instantiate, nid, p))
21951 +                               goto out;
21952 +                       pos++;
21953 +               }
21954 +       }
21955 +out:
21956 +       filp->f_pos = pos;
21957 +       return 0;
21958 +}
21959 +
21960 +static int proc_virtnet_getattr(struct vfsmount *mnt,
21961 +       struct dentry *dentry, struct kstat *stat)
21962 +{
21963 +       struct inode *inode = dentry->d_inode;
21964 +
21965 +       generic_fillattr(inode, stat);
21966 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
21967 +       return 0;
21968 +}
21969 +
21970 +static struct file_operations proc_virtnet_dir_operations = {
21971 +       .read =         generic_read_dir,
21972 +       .readdir =      proc_virtnet_readdir,
21973 +};
21974 +
21975 +static struct inode_operations proc_virtnet_dir_inode_operations = {
21976 +       .getattr =      proc_virtnet_getattr,
21977 +       .lookup =       proc_virtnet_lookup,
21978 +};
21979 +
21980 +
21981 +
21982 +void proc_vx_init(void)
21983 +{
21984 +       struct proc_dir_entry *ent;
21985 +
21986 +       ent = proc_mkdir("virtual", 0);
21987 +       if (ent) {
21988 +               ent->proc_fops = &proc_virtual_dir_operations;
21989 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
21990 +       }
21991 +       proc_virtual = ent;
21992 +
21993 +       ent = proc_mkdir("virtnet", 0);
21994 +       if (ent) {
21995 +               ent->proc_fops = &proc_virtnet_dir_operations;
21996 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
21997 +       }
21998 +       proc_virtnet = ent;
21999 +}
22000 +
22001 +
22002 +
22003 +
22004 +/* per pid info */
22005 +
22006 +
22007 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
22008 +{
22009 +       struct vx_info *vxi;
22010 +       char *orig = buffer;
22011 +
22012 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
22013 +
22014 +       vxi = task_get_vx_info(p);
22015 +       if (!vxi)
22016 +               goto out;
22017 +
22018 +       buffer += sprintf(buffer, "BCaps:\t");
22019 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
22020 +       buffer += sprintf(buffer, "\n");
22021 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
22022 +               (unsigned long long)vxi->vx_ccaps);
22023 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
22024 +               (unsigned long long)vxi->vx_flags);
22025 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
22026 +
22027 +       put_vx_info(vxi);
22028 +out:
22029 +       return buffer - orig;
22030 +}
22031 +
22032 +
22033 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
22034 +{
22035 +       struct nx_info *nxi;
22036 +       struct nx_addr_v4 *v4a;
22037 +#ifdef CONFIG_IPV6
22038 +       struct nx_addr_v6 *v6a;
22039 +#endif
22040 +       char *orig = buffer;
22041 +       int i;
22042 +
22043 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
22044 +
22045 +       nxi = task_get_nx_info(p);
22046 +       if (!nxi)
22047 +               goto out;
22048 +
22049 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
22050 +               (unsigned long long)nxi->nx_ncaps);
22051 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
22052 +               (unsigned long long)nxi->nx_flags);
22053 +
22054 +       buffer += sprintf(buffer,
22055 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
22056 +               NIPQUAD(nxi->v4_bcast.s_addr));
22057 +       buffer += sprintf (buffer,
22058 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
22059 +               NIPQUAD(nxi->v4_lback.s_addr));
22060 +       if (!NX_IPV4(nxi))
22061 +               goto skip_v4;
22062 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
22063 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
22064 +                       i, NXAV4(v4a));
22065 +skip_v4:
22066 +#ifdef CONFIG_IPV6
22067 +       if (!NX_IPV6(nxi))
22068 +               goto skip_v6;
22069 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
22070 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
22071 +                       i, NXAV6(v6a));
22072 +skip_v6:
22073 +#endif
22074 +       put_nx_info(nxi);
22075 +out:
22076 +       return buffer - orig;
22077 +}
22078 +
22079 diff -NurpP --minimal linux-3.9.4/kernel/vserver/sched.c linux-3.9.4-vs2.3.6.1/kernel/vserver/sched.c
22080 --- linux-3.9.4/kernel/vserver/sched.c  1970-01-01 00:00:00.000000000 +0000
22081 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/sched.c        2013-05-31 14:47:11.000000000 +0000
22082 @@ -0,0 +1,83 @@
22083 +/*
22084 + *  linux/kernel/vserver/sched.c
22085 + *
22086 + *  Virtual Server: Scheduler Support
22087 + *
22088 + *  Copyright (C) 2004-2010  Herbert Pötzl
22089 + *
22090 + *  V0.01  adapted Sam Vilains version to 2.6.3
22091 + *  V0.02  removed legacy interface
22092 + *  V0.03  changed vcmds to vxi arg
22093 + *  V0.04  removed older and legacy interfaces
22094 + *  V0.05  removed scheduler code/commands
22095 + *
22096 + */
22097 +
22098 +#include <linux/vs_context.h>
22099 +#include <linux/vs_sched.h>
22100 +#include <linux/cpumask.h>
22101 +#include <linux/vserver/sched_cmd.h>
22102 +
22103 +#include <asm/uaccess.h>
22104 +
22105 +
22106 +void vx_update_sched_param(struct _vx_sched *sched,
22107 +       struct _vx_sched_pc *sched_pc)
22108 +{
22109 +       sched_pc->prio_bias = sched->prio_bias;
22110 +}
22111 +
22112 +static int do_set_prio_bias(struct vx_info *vxi, struct vcmd_prio_bias *data)
22113 +{
22114 +       int cpu;
22115 +
22116 +       if (data->prio_bias > MAX_PRIO_BIAS)
22117 +               data->prio_bias = MAX_PRIO_BIAS;
22118 +       if (data->prio_bias < MIN_PRIO_BIAS)
22119 +               data->prio_bias = MIN_PRIO_BIAS;
22120 +
22121 +       if (data->cpu_id != ~0) {
22122 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
22123 +               cpumask_and(&vxi->sched.update, &vxi->sched.update,
22124 +                       cpu_online_mask);
22125 +       } else
22126 +               cpumask_copy(&vxi->sched.update, cpu_online_mask);
22127 +
22128 +       for_each_cpu_mask(cpu, vxi->sched.update)
22129 +               vx_update_sched_param(&vxi->sched,
22130 +                       &vx_per_cpu(vxi, sched_pc, cpu));
22131 +       return 0;
22132 +}
22133 +
22134 +int vc_set_prio_bias(struct vx_info *vxi, void __user *data)
22135 +{
22136 +       struct vcmd_prio_bias vc_data;
22137 +
22138 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22139 +               return -EFAULT;
22140 +
22141 +       return do_set_prio_bias(vxi, &vc_data);
22142 +}
22143 +
22144 +int vc_get_prio_bias(struct vx_info *vxi, void __user *data)
22145 +{
22146 +       struct vcmd_prio_bias vc_data;
22147 +       struct _vx_sched_pc *pcd;
22148 +       int cpu;
22149 +
22150 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22151 +               return -EFAULT;
22152 +
22153 +       cpu = vc_data.cpu_id;
22154 +
22155 +       if (!cpu_possible(cpu))
22156 +               return -EINVAL;
22157 +
22158 +       pcd = &vx_per_cpu(vxi, sched_pc, cpu);
22159 +       vc_data.prio_bias = pcd->prio_bias;
22160 +
22161 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22162 +               return -EFAULT;
22163 +       return 0;
22164 +}
22165 +
22166 diff -NurpP --minimal linux-3.9.4/kernel/vserver/sched_init.h linux-3.9.4-vs2.3.6.1/kernel/vserver/sched_init.h
22167 --- linux-3.9.4/kernel/vserver/sched_init.h     1970-01-01 00:00:00.000000000 +0000
22168 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/sched_init.h   2013-05-31 14:47:11.000000000 +0000
22169 @@ -0,0 +1,27 @@
22170 +
22171 +static inline void vx_info_init_sched(struct _vx_sched *sched)
22172 +{
22173 +       /* scheduling; hard code starting values as constants */
22174 +       sched->prio_bias = 0;
22175 +}
22176 +
22177 +static inline
22178 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22179 +{
22180 +       sched_pc->prio_bias = 0;
22181 +
22182 +       sched_pc->user_ticks = 0;
22183 +       sched_pc->sys_ticks = 0;
22184 +       sched_pc->hold_ticks = 0;
22185 +}
22186 +
22187 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
22188 +{
22189 +       return;
22190 +}
22191 +
22192 +static inline
22193 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22194 +{
22195 +       return;
22196 +}
22197 diff -NurpP --minimal linux-3.9.4/kernel/vserver/sched_proc.h linux-3.9.4-vs2.3.6.1/kernel/vserver/sched_proc.h
22198 --- linux-3.9.4/kernel/vserver/sched_proc.h     1970-01-01 00:00:00.000000000 +0000
22199 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/sched_proc.h   2013-05-31 14:47:11.000000000 +0000
22200 @@ -0,0 +1,32 @@
22201 +#ifndef _VX_SCHED_PROC_H
22202 +#define _VX_SCHED_PROC_H
22203 +
22204 +
22205 +static inline
22206 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
22207 +{
22208 +       int length = 0;
22209 +
22210 +       length += sprintf(buffer,
22211 +               "PrioBias:\t%8d\n",
22212 +               sched->prio_bias);
22213 +       return length;
22214 +}
22215 +
22216 +static inline
22217 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
22218 +       char *buffer, int cpu)
22219 +{
22220 +       int length = 0;
22221 +
22222 +       length += sprintf(buffer + length,
22223 +               "cpu %d: %lld %lld %lld", cpu,
22224 +               (unsigned long long)sched_pc->user_ticks,
22225 +               (unsigned long long)sched_pc->sys_ticks,
22226 +               (unsigned long long)sched_pc->hold_ticks);
22227 +       length += sprintf(buffer + length,
22228 +               " %d\n", sched_pc->prio_bias);
22229 +       return length;
22230 +}
22231 +
22232 +#endif /* _VX_SCHED_PROC_H */
22233 diff -NurpP --minimal linux-3.9.4/kernel/vserver/signal.c linux-3.9.4-vs2.3.6.1/kernel/vserver/signal.c
22234 --- linux-3.9.4/kernel/vserver/signal.c 1970-01-01 00:00:00.000000000 +0000
22235 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/signal.c       2013-05-31 14:47:11.000000000 +0000
22236 @@ -0,0 +1,134 @@
22237 +/*
22238 + *  linux/kernel/vserver/signal.c
22239 + *
22240 + *  Virtual Server: Signal Support
22241 + *
22242 + *  Copyright (C) 2003-2007  Herbert Pötzl
22243 + *
22244 + *  V0.01  broken out from vcontext V0.05
22245 + *  V0.02  changed vcmds to vxi arg
22246 + *  V0.03  adjusted siginfo for kill
22247 + *
22248 + */
22249 +
22250 +#include <asm/uaccess.h>
22251 +
22252 +#include <linux/vs_context.h>
22253 +#include <linux/vs_pid.h>
22254 +#include <linux/vserver/signal_cmd.h>
22255 +
22256 +
22257 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
22258 +{
22259 +       int retval, count = 0;
22260 +       struct task_struct *p;
22261 +       struct siginfo *sip = SEND_SIG_PRIV;
22262 +
22263 +       retval = -ESRCH;
22264 +       vxdprintk(VXD_CBIT(misc, 4),
22265 +               "vx_info_kill(%p[#%d],%d,%d)*",
22266 +               vxi, vxi->vx_id, pid, sig);
22267 +       read_lock(&tasklist_lock);
22268 +       switch (pid) {
22269 +       case  0:
22270 +       case -1:
22271 +               for_each_process(p) {
22272 +                       int err = 0;
22273 +
22274 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
22275 +                               (pid && vxi->vx_initpid == p->pid))
22276 +                               continue;
22277 +
22278 +                       err = group_send_sig_info(sig, sip, p);
22279 +                       ++count;
22280 +                       if (err != -EPERM)
22281 +                               retval = err;
22282 +               }
22283 +               break;
22284 +
22285 +       case 1:
22286 +               if (vxi->vx_initpid) {
22287 +                       pid = vxi->vx_initpid;
22288 +                       /* for now, only SIGINT to private init ... */
22289 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22290 +                               /* ... as long as there are tasks left */
22291 +                               (atomic_read(&vxi->vx_tasks) > 1))
22292 +                               sig = SIGINT;
22293 +               }
22294 +               /* fallthrough */
22295 +       default:
22296 +               rcu_read_lock();
22297 +               p = find_task_by_real_pid(pid);
22298 +               rcu_read_unlock();
22299 +               if (p) {
22300 +                       if (vx_task_xid(p) == vxi->vx_id)
22301 +                               retval = group_send_sig_info(sig, sip, p);
22302 +               }
22303 +               break;
22304 +       }
22305 +       read_unlock(&tasklist_lock);
22306 +       vxdprintk(VXD_CBIT(misc, 4),
22307 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
22308 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
22309 +       return retval;
22310 +}
22311 +
22312 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
22313 +{
22314 +       struct vcmd_ctx_kill_v0 vc_data;
22315 +
22316 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22317 +               return -EFAULT;
22318 +
22319 +       /* special check to allow guest shutdown */
22320 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22321 +               /* forbid killall pid=0 when init is present */
22322 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
22323 +               (vc_data.pid > 1)))
22324 +               return -EACCES;
22325 +
22326 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
22327 +}
22328 +
22329 +
22330 +static int __wait_exit(struct vx_info *vxi)
22331 +{
22332 +       DECLARE_WAITQUEUE(wait, current);
22333 +       int ret = 0;
22334 +
22335 +       add_wait_queue(&vxi->vx_wait, &wait);
22336 +       set_current_state(TASK_INTERRUPTIBLE);
22337 +
22338 +wait:
22339 +       if (vx_info_state(vxi,
22340 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
22341 +               goto out;
22342 +       if (signal_pending(current)) {
22343 +               ret = -ERESTARTSYS;
22344 +               goto out;
22345 +       }
22346 +       schedule();
22347 +       goto wait;
22348 +
22349 +out:
22350 +       set_current_state(TASK_RUNNING);
22351 +       remove_wait_queue(&vxi->vx_wait, &wait);
22352 +       return ret;
22353 +}
22354 +
22355 +
22356 +
22357 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
22358 +{
22359 +       struct vcmd_wait_exit_v0 vc_data;
22360 +       int ret;
22361 +
22362 +       ret = __wait_exit(vxi);
22363 +       vc_data.reboot_cmd = vxi->reboot_cmd;
22364 +       vc_data.exit_code = vxi->exit_code;
22365 +
22366 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22367 +               ret = -EFAULT;
22368 +       return ret;
22369 +}
22370 +
22371 diff -NurpP --minimal linux-3.9.4/kernel/vserver/space.c linux-3.9.4-vs2.3.6.1/kernel/vserver/space.c
22372 --- linux-3.9.4/kernel/vserver/space.c  1970-01-01 00:00:00.000000000 +0000
22373 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/space.c        2013-05-31 14:47:11.000000000 +0000
22374 @@ -0,0 +1,436 @@
22375 +/*
22376 + *  linux/kernel/vserver/space.c
22377 + *
22378 + *  Virtual Server: Context Space Support
22379 + *
22380 + *  Copyright (C) 2003-2010  Herbert Pötzl
22381 + *
22382 + *  V0.01  broken out from context.c 0.07
22383 + *  V0.02  added task locking for namespace
22384 + *  V0.03  broken out vx_enter_namespace
22385 + *  V0.04  added *space support and commands
22386 + *  V0.05  added credential support
22387 + *
22388 + */
22389 +
22390 +#include <linux/utsname.h>
22391 +#include <linux/nsproxy.h>
22392 +#include <linux/err.h>
22393 +#include <linux/fs_struct.h>
22394 +#include <linux/cred.h>
22395 +#include <asm/uaccess.h>
22396 +
22397 +#include <linux/vs_context.h>
22398 +#include <linux/vserver/space.h>
22399 +#include <linux/vserver/space_cmd.h>
22400 +
22401 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
22402 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
22403 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
22404 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
22405 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
22406 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
22407 +
22408 +
22409 +/* namespace functions */
22410 +
22411 +#include <linux/mnt_namespace.h>
22412 +#include <linux/user_namespace.h>
22413 +#include <linux/pid_namespace.h>
22414 +#include <linux/ipc_namespace.h>
22415 +#include <net/net_namespace.h>
22416 +#include "../fs/mount.h"
22417 +
22418 +
22419 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
22420 +       .mask = CLONE_FS |
22421 +               CLONE_NEWNS |
22422 +#ifdef CONFIG_UTS_NS
22423 +               CLONE_NEWUTS |
22424 +#endif
22425 +#ifdef CONFIG_IPC_NS
22426 +               CLONE_NEWIPC |
22427 +#endif
22428 +#ifdef CONFIG_USER_NS
22429 +               CLONE_NEWUSER |
22430 +#endif
22431 +               0
22432 +};
22433 +
22434 +static const struct vcmd_space_mask_v1 space_mask = {
22435 +       .mask = CLONE_FS |
22436 +               CLONE_NEWNS |
22437 +#ifdef CONFIG_UTS_NS
22438 +               CLONE_NEWUTS |
22439 +#endif
22440 +#ifdef CONFIG_IPC_NS
22441 +               CLONE_NEWIPC |
22442 +#endif
22443 +#ifdef CONFIG_USER_NS
22444 +               CLONE_NEWUSER |
22445 +#endif
22446 +#ifdef CONFIG_PID_NS
22447 +               CLONE_NEWPID |
22448 +#endif
22449 +#ifdef CONFIG_NET_NS
22450 +               CLONE_NEWNET |
22451 +#endif
22452 +               0
22453 +};
22454 +
22455 +static const struct vcmd_space_mask_v1 default_space_mask = {
22456 +       .mask = CLONE_FS |
22457 +               CLONE_NEWNS |
22458 +#ifdef CONFIG_UTS_NS
22459 +               CLONE_NEWUTS |
22460 +#endif
22461 +#ifdef CONFIG_IPC_NS
22462 +               CLONE_NEWIPC |
22463 +#endif
22464 +#ifdef CONFIG_USER_NS
22465 +               CLONE_NEWUSER |
22466 +#endif
22467 +#ifdef CONFIG_PID_NS
22468 +//             CLONE_NEWPID |
22469 +#endif
22470 +               0
22471 +};
22472 +
22473 +/*
22474 + *     build a new nsproxy mix
22475 + *      assumes that both proxies are 'const'
22476 + *     does not touch nsproxy refcounts
22477 + *     will hold a reference on the result.
22478 + */
22479 +
22480 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
22481 +       struct nsproxy *new_nsproxy, unsigned long mask)
22482 +{
22483 +       struct mnt_namespace *old_ns;
22484 +       struct uts_namespace *old_uts;
22485 +       struct ipc_namespace *old_ipc;
22486 +#ifdef CONFIG_PID_NS
22487 +       struct pid_namespace *old_pid;
22488 +#endif
22489 +#ifdef CONFIG_NET_NS
22490 +       struct net *old_net;
22491 +#endif
22492 +       struct nsproxy *nsproxy;
22493 +
22494 +       nsproxy = copy_nsproxy(old_nsproxy);
22495 +       if (!nsproxy)
22496 +               goto out;
22497 +
22498 +       if (mask & CLONE_NEWNS) {
22499 +               old_ns = nsproxy->mnt_ns;
22500 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
22501 +               if (nsproxy->mnt_ns)
22502 +                       get_mnt_ns(nsproxy->mnt_ns);
22503 +       } else
22504 +               old_ns = NULL;
22505 +
22506 +       if (mask & CLONE_NEWUTS) {
22507 +               old_uts = nsproxy->uts_ns;
22508 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
22509 +               if (nsproxy->uts_ns)
22510 +                       get_uts_ns(nsproxy->uts_ns);
22511 +       } else
22512 +               old_uts = NULL;
22513 +
22514 +       if (mask & CLONE_NEWIPC) {
22515 +               old_ipc = nsproxy->ipc_ns;
22516 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
22517 +               if (nsproxy->ipc_ns)
22518 +                       get_ipc_ns(nsproxy->ipc_ns);
22519 +       } else
22520 +               old_ipc = NULL;
22521 +
22522 +#ifdef CONFIG_PID_NS
22523 +       if (mask & CLONE_NEWPID) {
22524 +               old_pid = nsproxy->pid_ns;
22525 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
22526 +               if (nsproxy->pid_ns)
22527 +                       get_pid_ns(nsproxy->pid_ns);
22528 +       } else
22529 +               old_pid = NULL;
22530 +#endif
22531 +#ifdef CONFIG_NET_NS
22532 +       if (mask & CLONE_NEWNET) {
22533 +               old_net = nsproxy->net_ns;
22534 +               nsproxy->net_ns = new_nsproxy->net_ns;
22535 +               if (nsproxy->net_ns)
22536 +                       get_net(nsproxy->net_ns);
22537 +       } else
22538 +               old_net = NULL;
22539 +#endif
22540 +       if (old_ns)
22541 +               put_mnt_ns(old_ns);
22542 +       if (old_uts)
22543 +               put_uts_ns(old_uts);
22544 +       if (old_ipc)
22545 +               put_ipc_ns(old_ipc);
22546 +#ifdef CONFIG_PID_NS
22547 +       if (old_pid)
22548 +               put_pid_ns(old_pid);
22549 +#endif
22550 +#ifdef CONFIG_NET_NS
22551 +       if (old_net)
22552 +               put_net(old_net);
22553 +#endif
22554 +out:
22555 +       return nsproxy;
22556 +}
22557 +
22558 +
22559 +/*
22560 + *     merge two nsproxy structs into a new one.
22561 + *     will hold a reference on the result.
22562 + */
22563 +
22564 +static inline
22565 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
22566 +       struct nsproxy *proxy, unsigned long mask)
22567 +{
22568 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
22569 +
22570 +       if (!proxy)
22571 +               return NULL;
22572 +
22573 +       if (mask) {
22574 +               /* vs_mix_nsproxy returns with reference */
22575 +               return vs_mix_nsproxy(old ? old : &null_proxy,
22576 +                       proxy, mask);
22577 +       }
22578 +       get_nsproxy(proxy);
22579 +       return proxy;
22580 +}
22581 +
22582 +
22583 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
22584 +{
22585 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
22586 +       struct fs_struct *fs_cur, *fs = NULL;
22587 +       struct _vx_space *space;
22588 +       int ret, kill = 0;
22589 +
22590 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
22591 +               vxi, vxi->vx_id, mask, index);
22592 +
22593 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
22594 +               return -EACCES;
22595 +
22596 +       if (index >= VX_SPACES)
22597 +               return -EINVAL;
22598 +
22599 +       space = &vxi->space[index];
22600 +
22601 +       if (!mask)
22602 +               mask = space->vx_nsmask;
22603 +
22604 +       if ((mask & space->vx_nsmask) != mask)
22605 +               return -EINVAL;
22606 +
22607 +       if (mask & CLONE_FS) {
22608 +               fs = copy_fs_struct(space->vx_fs);
22609 +               if (!fs)
22610 +                       return -ENOMEM;
22611 +       }
22612 +       proxy = space->vx_nsproxy;
22613 +
22614 +       vxdprintk(VXD_CBIT(space, 9),
22615 +               "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
22616 +               vxi, vxi->vx_id, mask, index, proxy, fs);
22617 +
22618 +       task_lock(current);
22619 +       fs_cur = current->fs;
22620 +
22621 +       if (mask & CLONE_FS) {
22622 +               spin_lock(&fs_cur->lock);
22623 +               current->fs = fs;
22624 +               kill = !--fs_cur->users;
22625 +               spin_unlock(&fs_cur->lock);
22626 +       }
22627 +
22628 +       proxy_cur = current->nsproxy;
22629 +       get_nsproxy(proxy_cur);
22630 +       task_unlock(current);
22631 +
22632 +       if (kill)
22633 +               free_fs_struct(fs_cur);
22634 +
22635 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
22636 +       if (IS_ERR(proxy_new)) {
22637 +               ret = PTR_ERR(proxy_new);
22638 +               goto out_put;
22639 +       }
22640 +
22641 +       proxy_new = xchg(&current->nsproxy, proxy_new);
22642 +
22643 +       if (mask & CLONE_NEWUSER) {
22644 +               struct cred *cred;
22645 +
22646 +               vxdprintk(VXD_CBIT(space, 10),
22647 +                       "vx_enter_space(%p[#%u],%p) cred (%p,%p)",
22648 +                       vxi, vxi->vx_id, space->vx_cred,
22649 +                       current->real_cred, current->cred);
22650 +
22651 +               if (space->vx_cred) {
22652 +                       cred = __prepare_creds(space->vx_cred);
22653 +                       if (cred)
22654 +                               commit_creds(cred);
22655 +               }
22656 +       }
22657 +
22658 +       ret = 0;
22659 +
22660 +       if (proxy_new)
22661 +               put_nsproxy(proxy_new);
22662 +out_put:
22663 +       if (proxy_cur)
22664 +               put_nsproxy(proxy_cur);
22665 +       return ret;
22666 +}
22667 +
22668 +
22669 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
22670 +{
22671 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
22672 +       struct fs_struct *fs_vxi, *fs = NULL;
22673 +       struct _vx_space *space;
22674 +       int ret, kill = 0;
22675 +
22676 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
22677 +               vxi, vxi->vx_id, mask, index);
22678 +
22679 +       if ((mask & space_mask.mask) != mask)
22680 +               return -EINVAL;
22681 +
22682 +       if (index >= VX_SPACES)
22683 +               return -EINVAL;
22684 +
22685 +       space = &vxi->space[index];
22686 +
22687 +       proxy_vxi = space->vx_nsproxy;
22688 +       fs_vxi = space->vx_fs;
22689 +
22690 +       if (mask & CLONE_FS) {
22691 +               fs = copy_fs_struct(current->fs);
22692 +               if (!fs)
22693 +                       return -ENOMEM;
22694 +       }
22695 +
22696 +       task_lock(current);
22697 +
22698 +       if (mask & CLONE_FS) {
22699 +               spin_lock(&fs_vxi->lock);
22700 +               space->vx_fs = fs;
22701 +               kill = !--fs_vxi->users;
22702 +               spin_unlock(&fs_vxi->lock);
22703 +       }
22704 +
22705 +       proxy_cur = current->nsproxy;
22706 +       get_nsproxy(proxy_cur);
22707 +       task_unlock(current);
22708 +
22709 +       if (kill)
22710 +               free_fs_struct(fs_vxi);
22711 +
22712 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
22713 +       if (IS_ERR(proxy_new)) {
22714 +               ret = PTR_ERR(proxy_new);
22715 +               goto out_put;
22716 +       }
22717 +
22718 +       proxy_new = xchg(&space->vx_nsproxy, proxy_new);
22719 +       space->vx_nsmask |= mask;
22720 +
22721 +       if (mask & CLONE_NEWUSER) {
22722 +               struct cred *cred;
22723 +
22724 +               vxdprintk(VXD_CBIT(space, 10),
22725 +                       "vx_set_space(%p[#%u],%p) cred (%p,%p)",
22726 +                       vxi, vxi->vx_id, space->vx_cred,
22727 +                       current->real_cred, current->cred);
22728 +
22729 +               cred = prepare_creds();
22730 +               cred = (struct cred *)xchg(&space->vx_cred, cred);
22731 +               if (cred)
22732 +                       abort_creds(cred);
22733 +       }
22734 +
22735 +       ret = 0;
22736 +
22737 +       if (proxy_new)
22738 +               put_nsproxy(proxy_new);
22739 +out_put:
22740 +       if (proxy_cur)
22741 +               put_nsproxy(proxy_cur);
22742 +       return ret;
22743 +}
22744 +
22745 +
22746 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
22747 +{
22748 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22749 +
22750 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22751 +               return -EFAULT;
22752 +
22753 +       return vx_enter_space(vxi, vc_data.mask, 0);
22754 +}
22755 +
22756 +int vc_enter_space(struct vx_info *vxi, void __user *data)
22757 +{
22758 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22759 +
22760 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22761 +               return -EFAULT;
22762 +
22763 +       if (vc_data.index >= VX_SPACES)
22764 +               return -EINVAL;
22765 +
22766 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
22767 +}
22768 +
22769 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
22770 +{
22771 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22772 +
22773 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22774 +               return -EFAULT;
22775 +
22776 +       return vx_set_space(vxi, vc_data.mask, 0);
22777 +}
22778 +
22779 +int vc_set_space(struct vx_info *vxi, void __user *data)
22780 +{
22781 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22782 +
22783 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22784 +               return -EFAULT;
22785 +
22786 +       if (vc_data.index >= VX_SPACES)
22787 +               return -EINVAL;
22788 +
22789 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
22790 +}
22791 +
22792 +int vc_get_space_mask(void __user *data, int type)
22793 +{
22794 +       const struct vcmd_space_mask_v1 *mask;
22795 +
22796 +       if (type == 0)
22797 +               mask = &space_mask_v0;
22798 +       else if (type == 1)
22799 +               mask = &space_mask;
22800 +       else
22801 +               mask = &default_space_mask;
22802 +
22803 +       vxdprintk(VXD_CBIT(space, 10),
22804 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
22805 +
22806 +       if (copy_to_user(data, mask, sizeof(*mask)))
22807 +               return -EFAULT;
22808 +       return 0;
22809 +}
22810 +
22811 diff -NurpP --minimal linux-3.9.4/kernel/vserver/switch.c linux-3.9.4-vs2.3.6.1/kernel/vserver/switch.c
22812 --- linux-3.9.4/kernel/vserver/switch.c 1970-01-01 00:00:00.000000000 +0000
22813 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/switch.c       2013-05-31 14:47:11.000000000 +0000
22814 @@ -0,0 +1,556 @@
22815 +/*
22816 + *  linux/kernel/vserver/switch.c
22817 + *
22818 + *  Virtual Server: Syscall Switch
22819 + *
22820 + *  Copyright (C) 2003-2011  Herbert Pötzl
22821 + *
22822 + *  V0.01  syscall switch
22823 + *  V0.02  added signal to context
22824 + *  V0.03  added rlimit functions
22825 + *  V0.04  added iattr, task/xid functions
22826 + *  V0.05  added debug/history stuff
22827 + *  V0.06  added compat32 layer
22828 + *  V0.07  vcmd args and perms
22829 + *  V0.08  added status commands
22830 + *  V0.09  added tag commands
22831 + *  V0.10  added oom bias
22832 + *  V0.11  added device commands
22833 + *  V0.12  added warn mask
22834 + *
22835 + */
22836 +
22837 +#include <linux/vs_context.h>
22838 +#include <linux/vs_network.h>
22839 +#include <linux/vserver/switch.h>
22840 +
22841 +#include "vci_config.h"
22842 +
22843 +
22844 +static inline
22845 +int vc_get_version(uint32_t id)
22846 +{
22847 +       return VCI_VERSION;
22848 +}
22849 +
22850 +static inline
22851 +int vc_get_vci(uint32_t id)
22852 +{
22853 +       return vci_kernel_config();
22854 +}
22855 +
22856 +#include <linux/vserver/context_cmd.h>
22857 +#include <linux/vserver/cvirt_cmd.h>
22858 +#include <linux/vserver/cacct_cmd.h>
22859 +#include <linux/vserver/limit_cmd.h>
22860 +#include <linux/vserver/network_cmd.h>
22861 +#include <linux/vserver/sched_cmd.h>
22862 +#include <linux/vserver/debug_cmd.h>
22863 +#include <linux/vserver/inode_cmd.h>
22864 +#include <linux/vserver/dlimit_cmd.h>
22865 +#include <linux/vserver/signal_cmd.h>
22866 +#include <linux/vserver/space_cmd.h>
22867 +#include <linux/vserver/tag_cmd.h>
22868 +#include <linux/vserver/device_cmd.h>
22869 +
22870 +#include <linux/vserver/inode.h>
22871 +#include <linux/vserver/dlimit.h>
22872 +
22873 +
22874 +#ifdef CONFIG_COMPAT
22875 +#define __COMPAT(name, id, data, compat)       \
22876 +       (compat) ? name ## _x32(id, data) : name(id, data)
22877 +#define __COMPAT_NO_ID(name, data, compat)     \
22878 +       (compat) ? name ## _x32(data) : name(data)
22879 +#else
22880 +#define __COMPAT(name, id, data, compat)       \
22881 +       name(id, data)
22882 +#define __COMPAT_NO_ID(name, data, compat)     \
22883 +       name(data)
22884 +#endif
22885 +
22886 +
22887 +static inline
22888 +long do_vcmd(uint32_t cmd, uint32_t id,
22889 +       struct vx_info *vxi, struct nx_info *nxi,
22890 +       void __user *data, int compat)
22891 +{
22892 +       switch (cmd) {
22893 +
22894 +       case VCMD_get_version:
22895 +               return vc_get_version(id);
22896 +       case VCMD_get_vci:
22897 +               return vc_get_vci(id);
22898 +
22899 +       case VCMD_task_xid:
22900 +               return vc_task_xid(id);
22901 +       case VCMD_vx_info:
22902 +               return vc_vx_info(vxi, data);
22903 +
22904 +       case VCMD_task_nid:
22905 +               return vc_task_nid(id);
22906 +       case VCMD_nx_info:
22907 +               return vc_nx_info(nxi, data);
22908 +
22909 +       case VCMD_task_tag:
22910 +               return vc_task_tag(id);
22911 +
22912 +       case VCMD_set_space_v1:
22913 +               return vc_set_space_v1(vxi, data);
22914 +       /* this is version 2 */
22915 +       case VCMD_set_space:
22916 +               return vc_set_space(vxi, data);
22917 +
22918 +       case VCMD_get_space_mask_v0:
22919 +               return vc_get_space_mask(data, 0);
22920 +       /* this is version 1 */
22921 +       case VCMD_get_space_mask:
22922 +               return vc_get_space_mask(data, 1);
22923 +
22924 +       case VCMD_get_space_default:
22925 +               return vc_get_space_mask(data, -1);
22926 +
22927 +       case VCMD_set_umask:
22928 +               return vc_set_umask(vxi, data);
22929 +
22930 +       case VCMD_get_umask:
22931 +               return vc_get_umask(vxi, data);
22932 +
22933 +       case VCMD_set_wmask:
22934 +               return vc_set_wmask(vxi, data);
22935 +
22936 +       case VCMD_get_wmask:
22937 +               return vc_get_wmask(vxi, data);
22938 +#ifdef CONFIG_IA32_EMULATION
22939 +       case VCMD_get_rlimit:
22940 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
22941 +       case VCMD_set_rlimit:
22942 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
22943 +#else
22944 +       case VCMD_get_rlimit:
22945 +               return vc_get_rlimit(vxi, data);
22946 +       case VCMD_set_rlimit:
22947 +               return vc_set_rlimit(vxi, data);
22948 +#endif
22949 +       case VCMD_get_rlimit_mask:
22950 +               return vc_get_rlimit_mask(id, data);
22951 +       case VCMD_reset_hits:
22952 +               return vc_reset_hits(vxi, data);
22953 +       case VCMD_reset_minmax:
22954 +               return vc_reset_minmax(vxi, data);
22955 +
22956 +       case VCMD_get_vhi_name:
22957 +               return vc_get_vhi_name(vxi, data);
22958 +       case VCMD_set_vhi_name:
22959 +               return vc_set_vhi_name(vxi, data);
22960 +
22961 +       case VCMD_ctx_stat:
22962 +               return vc_ctx_stat(vxi, data);
22963 +       case VCMD_virt_stat:
22964 +               return vc_virt_stat(vxi, data);
22965 +       case VCMD_sock_stat:
22966 +               return vc_sock_stat(vxi, data);
22967 +       case VCMD_rlimit_stat:
22968 +               return vc_rlimit_stat(vxi, data);
22969 +
22970 +       case VCMD_set_cflags:
22971 +               return vc_set_cflags(vxi, data);
22972 +       case VCMD_get_cflags:
22973 +               return vc_get_cflags(vxi, data);
22974 +
22975 +       /* this is version 1 */
22976 +       case VCMD_set_ccaps:
22977 +               return vc_set_ccaps(vxi, data);
22978 +       /* this is version 1 */
22979 +       case VCMD_get_ccaps:
22980 +               return vc_get_ccaps(vxi, data);
22981 +       case VCMD_set_bcaps:
22982 +               return vc_set_bcaps(vxi, data);
22983 +       case VCMD_get_bcaps:
22984 +               return vc_get_bcaps(vxi, data);
22985 +
22986 +       case VCMD_set_badness:
22987 +               return vc_set_badness(vxi, data);
22988 +       case VCMD_get_badness:
22989 +               return vc_get_badness(vxi, data);
22990 +
22991 +       case VCMD_set_nflags:
22992 +               return vc_set_nflags(nxi, data);
22993 +       case VCMD_get_nflags:
22994 +               return vc_get_nflags(nxi, data);
22995 +
22996 +       case VCMD_set_ncaps:
22997 +               return vc_set_ncaps(nxi, data);
22998 +       case VCMD_get_ncaps:
22999 +               return vc_get_ncaps(nxi, data);
23000 +
23001 +       case VCMD_set_prio_bias:
23002 +               return vc_set_prio_bias(vxi, data);
23003 +       case VCMD_get_prio_bias:
23004 +               return vc_get_prio_bias(vxi, data);
23005 +       case VCMD_add_dlimit:
23006 +               return __COMPAT(vc_add_dlimit, id, data, compat);
23007 +       case VCMD_rem_dlimit:
23008 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
23009 +       case VCMD_set_dlimit:
23010 +               return __COMPAT(vc_set_dlimit, id, data, compat);
23011 +       case VCMD_get_dlimit:
23012 +               return __COMPAT(vc_get_dlimit, id, data, compat);
23013 +
23014 +       case VCMD_ctx_kill:
23015 +               return vc_ctx_kill(vxi, data);
23016 +
23017 +       case VCMD_wait_exit:
23018 +               return vc_wait_exit(vxi, data);
23019 +
23020 +       case VCMD_get_iattr:
23021 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
23022 +       case VCMD_set_iattr:
23023 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
23024 +
23025 +       case VCMD_fget_iattr:
23026 +               return vc_fget_iattr(id, data);
23027 +       case VCMD_fset_iattr:
23028 +               return vc_fset_iattr(id, data);
23029 +
23030 +       case VCMD_enter_space_v0:
23031 +               return vc_enter_space_v1(vxi, NULL);
23032 +       case VCMD_enter_space_v1:
23033 +               return vc_enter_space_v1(vxi, data);
23034 +       /* this is version 2 */
23035 +       case VCMD_enter_space:
23036 +               return vc_enter_space(vxi, data);
23037 +
23038 +       case VCMD_ctx_create_v0:
23039 +               return vc_ctx_create(id, NULL);
23040 +       case VCMD_ctx_create:
23041 +               return vc_ctx_create(id, data);
23042 +       case VCMD_ctx_migrate_v0:
23043 +               return vc_ctx_migrate(vxi, NULL);
23044 +       case VCMD_ctx_migrate:
23045 +               return vc_ctx_migrate(vxi, data);
23046 +
23047 +       case VCMD_net_create_v0:
23048 +               return vc_net_create(id, NULL);
23049 +       case VCMD_net_create:
23050 +               return vc_net_create(id, data);
23051 +       case VCMD_net_migrate:
23052 +               return vc_net_migrate(nxi, data);
23053 +
23054 +       case VCMD_tag_migrate:
23055 +               return vc_tag_migrate(id);
23056 +
23057 +       case VCMD_net_add:
23058 +               return vc_net_add(nxi, data);
23059 +       case VCMD_net_remove:
23060 +               return vc_net_remove(nxi, data);
23061 +
23062 +       case VCMD_net_add_ipv4_v1:
23063 +               return vc_net_add_ipv4_v1(nxi, data);
23064 +       /* this is version 2 */
23065 +       case VCMD_net_add_ipv4:
23066 +               return vc_net_add_ipv4(nxi, data);
23067 +
23068 +       case VCMD_net_rem_ipv4_v1:
23069 +               return vc_net_rem_ipv4_v1(nxi, data);
23070 +       /* this is version 2 */
23071 +       case VCMD_net_rem_ipv4:
23072 +               return vc_net_rem_ipv4(nxi, data);
23073 +#ifdef CONFIG_IPV6
23074 +       case VCMD_net_add_ipv6:
23075 +               return vc_net_add_ipv6(nxi, data);
23076 +       case VCMD_net_remove_ipv6:
23077 +               return vc_net_remove_ipv6(nxi, data);
23078 +#endif
23079 +/*     case VCMD_add_match_ipv4:
23080 +               return vc_add_match_ipv4(nxi, data);
23081 +       case VCMD_get_match_ipv4:
23082 +               return vc_get_match_ipv4(nxi, data);
23083 +#ifdef CONFIG_IPV6
23084 +       case VCMD_add_match_ipv6:
23085 +               return vc_add_match_ipv6(nxi, data);
23086 +       case VCMD_get_match_ipv6:
23087 +               return vc_get_match_ipv6(nxi, data);
23088 +#endif */
23089 +
23090 +#ifdef CONFIG_VSERVER_DEVICE
23091 +       case VCMD_set_mapping:
23092 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
23093 +       case VCMD_unset_mapping:
23094 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
23095 +#endif
23096 +#ifdef CONFIG_VSERVER_HISTORY
23097 +       case VCMD_dump_history:
23098 +               return vc_dump_history(id);
23099 +       case VCMD_read_history:
23100 +               return __COMPAT(vc_read_history, id, data, compat);
23101 +#endif
23102 +       default:
23103 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
23104 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
23105 +       }
23106 +       return -ENOSYS;
23107 +}
23108 +
23109 +
23110 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
23111 +       case VCMD_ ## vcmd: perm = _perm;               \
23112 +               args = _args; flags = _flags; break
23113 +
23114 +
23115 +#define VCA_NONE       0x00
23116 +#define VCA_VXI                0x01
23117 +#define VCA_NXI                0x02
23118 +
23119 +#define VCF_NONE       0x00
23120 +#define VCF_INFO       0x01
23121 +#define VCF_ADMIN      0x02
23122 +#define VCF_ARES       0x06    /* includes admin */
23123 +#define VCF_SETUP      0x08
23124 +
23125 +#define VCF_ZIDOK      0x10    /* zero id okay */
23126 +
23127 +
23128 +static inline
23129 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
23130 +{
23131 +       long ret;
23132 +       int permit = -1, state = 0;
23133 +       int perm = -1, args = 0, flags = 0;
23134 +       struct vx_info *vxi = NULL;
23135 +       struct nx_info *nxi = NULL;
23136 +
23137 +       switch (cmd) {
23138 +       /* unpriviledged commands */
23139 +       __VCMD(get_version,      0, VCA_NONE,   0);
23140 +       __VCMD(get_vci,          0, VCA_NONE,   0);
23141 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
23142 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
23143 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
23144 +       __VCMD(get_space_default,0, VCA_NONE,   0);
23145 +
23146 +       /* info commands */
23147 +       __VCMD(task_xid,         2, VCA_NONE,   0);
23148 +       __VCMD(reset_hits,       2, VCA_VXI,    0);
23149 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
23150 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
23151 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
23152 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
23153 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
23154 +       __VCMD(get_umask,        3, VCA_VXI,    VCF_INFO);
23155 +       __VCMD(get_wmask,        3, VCA_VXI,    VCF_INFO);
23156 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
23157 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
23158 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
23159 +
23160 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
23161 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
23162 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
23163 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
23164 +
23165 +       __VCMD(task_nid,         2, VCA_NONE,   0);
23166 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
23167 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
23168 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
23169 +
23170 +       __VCMD(task_tag,         2, VCA_NONE,   0);
23171 +
23172 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
23173 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
23174 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
23175 +       __VCMD(get_prio_bias,    3, VCA_VXI,    VCF_INFO);
23176 +
23177 +       /* lower admin commands */
23178 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
23179 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
23180 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
23181 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
23182 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
23183 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
23184 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
23185 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
23186 +
23187 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
23188 +       __VCMD(net_create,       5, VCA_NONE,   0);
23189 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
23190 +
23191 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
23192 +
23193 +       /* higher admin commands */
23194 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
23195 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23196 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23197 +
23198 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23199 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23200 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23201 +       __VCMD(set_umask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23202 +       __VCMD(set_wmask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23203 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23204 +
23205 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23206 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23207 +       __VCMD(set_prio_bias,    7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23208 +
23209 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23210 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23211 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23212 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23213 +       __VCMD(net_add_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23214 +       __VCMD(net_rem_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23215 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23216 +       __VCMD(net_rem_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23217 +#ifdef CONFIG_IPV6
23218 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23219 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23220 +#endif
23221 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
23222 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
23223 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
23224 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
23225 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
23226 +
23227 +#ifdef CONFIG_VSERVER_DEVICE
23228 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23229 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23230 +#endif
23231 +       /* debug level admin commands */
23232 +#ifdef CONFIG_VSERVER_HISTORY
23233 +       __VCMD(dump_history,     9, VCA_NONE,   0);
23234 +       __VCMD(read_history,     9, VCA_NONE,   0);
23235 +#endif
23236 +
23237 +       default:
23238 +               perm = -1;
23239 +       }
23240 +
23241 +       vxdprintk(VXD_CBIT(switch, 0),
23242 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
23243 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23244 +               VC_VERSION(cmd), id, data, compat,
23245 +               perm, args, flags);
23246 +
23247 +       ret = -ENOSYS;
23248 +       if (perm < 0)
23249 +               goto out;
23250 +
23251 +       state = 1;
23252 +       if (!capable(CAP_CONTEXT))
23253 +               goto out;
23254 +
23255 +       state = 2;
23256 +       /* moved here from the individual commands */
23257 +       ret = -EPERM;
23258 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
23259 +               goto out;
23260 +
23261 +       state = 3;
23262 +       /* vcmd involves resource management  */
23263 +       ret = -EPERM;
23264 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
23265 +               goto out;
23266 +
23267 +       state = 4;
23268 +       /* various legacy exceptions */
23269 +       switch (cmd) {
23270 +       /* will go away when spectator is a cap */
23271 +       case VCMD_ctx_migrate_v0:
23272 +       case VCMD_ctx_migrate:
23273 +               if (id == 1) {
23274 +                       current->xid = 1;
23275 +                       ret = 1;
23276 +                       goto out;
23277 +               }
23278 +               break;
23279 +
23280 +       /* will go away when spectator is a cap */
23281 +       case VCMD_net_migrate:
23282 +               if (id == 1) {
23283 +                       current->nid = 1;
23284 +                       ret = 1;
23285 +                       goto out;
23286 +               }
23287 +               break;
23288 +       }
23289 +
23290 +       /* vcmds are fine by default */
23291 +       permit = 1;
23292 +
23293 +       /* admin type vcmds require admin ... */
23294 +       if (flags & VCF_ADMIN)
23295 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
23296 +
23297 +       /* ... but setup type vcmds override that */
23298 +       if (!permit && (flags & VCF_SETUP))
23299 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
23300 +
23301 +       state = 5;
23302 +       ret = -EPERM;
23303 +       if (!permit)
23304 +               goto out;
23305 +
23306 +       state = 6;
23307 +       if (!id && (flags & VCF_ZIDOK))
23308 +               goto skip_id;
23309 +
23310 +       ret = -ESRCH;
23311 +       if (args & VCA_VXI) {
23312 +               vxi = lookup_vx_info(id);
23313 +               if (!vxi)
23314 +                       goto out;
23315 +
23316 +               if ((flags & VCF_ADMIN) &&
23317 +                       /* special case kill for shutdown */
23318 +                       (cmd != VCMD_ctx_kill) &&
23319 +                       /* can context be administrated? */
23320 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
23321 +                       ret = -EACCES;
23322 +                       goto out_vxi;
23323 +               }
23324 +       }
23325 +       state = 7;
23326 +       if (args & VCA_NXI) {
23327 +               nxi = lookup_nx_info(id);
23328 +               if (!nxi)
23329 +                       goto out_vxi;
23330 +
23331 +               if ((flags & VCF_ADMIN) &&
23332 +                       /* can context be administrated? */
23333 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
23334 +                       ret = -EACCES;
23335 +                       goto out_nxi;
23336 +               }
23337 +       }
23338 +skip_id:
23339 +       state = 8;
23340 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
23341 +
23342 +out_nxi:
23343 +       if ((args & VCA_NXI) && nxi)
23344 +               put_nx_info(nxi);
23345 +out_vxi:
23346 +       if ((args & VCA_VXI) && vxi)
23347 +               put_vx_info(vxi);
23348 +out:
23349 +       vxdprintk(VXD_CBIT(switch, 1),
23350 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
23351 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23352 +               VC_VERSION(cmd), ret, ret, state, permit);
23353 +       return ret;
23354 +}
23355 +
23356 +asmlinkage long
23357 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
23358 +{
23359 +       return do_vserver(cmd, id, data, 0);
23360 +}
23361 +
23362 +#ifdef CONFIG_COMPAT
23363 +
23364 +asmlinkage long
23365 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
23366 +{
23367 +       return do_vserver(cmd, id, data, 1);
23368 +}
23369 +
23370 +#endif /* CONFIG_COMPAT */
23371 diff -NurpP --minimal linux-3.9.4/kernel/vserver/sysctl.c linux-3.9.4-vs2.3.6.1/kernel/vserver/sysctl.c
23372 --- linux-3.9.4/kernel/vserver/sysctl.c 1970-01-01 00:00:00.000000000 +0000
23373 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/sysctl.c       2013-05-31 14:47:11.000000000 +0000
23374 @@ -0,0 +1,247 @@
23375 +/*
23376 + *  kernel/vserver/sysctl.c
23377 + *
23378 + *  Virtual Context Support
23379 + *
23380 + *  Copyright (C) 2004-2007  Herbert Pötzl
23381 + *
23382 + *  V0.01  basic structure
23383 + *
23384 + */
23385 +
23386 +#include <linux/module.h>
23387 +#include <linux/ctype.h>
23388 +#include <linux/sysctl.h>
23389 +#include <linux/parser.h>
23390 +#include <asm/uaccess.h>
23391 +
23392 +enum {
23393 +       CTL_DEBUG_ERROR         = 0,
23394 +       CTL_DEBUG_SWITCH        = 1,
23395 +       CTL_DEBUG_XID,
23396 +       CTL_DEBUG_NID,
23397 +       CTL_DEBUG_TAG,
23398 +       CTL_DEBUG_NET,
23399 +       CTL_DEBUG_LIMIT,
23400 +       CTL_DEBUG_CRES,
23401 +       CTL_DEBUG_DLIM,
23402 +       CTL_DEBUG_QUOTA,
23403 +       CTL_DEBUG_CVIRT,
23404 +       CTL_DEBUG_SPACE,
23405 +       CTL_DEBUG_PERM,
23406 +       CTL_DEBUG_MISC,
23407 +};
23408 +
23409 +
23410 +unsigned int vs_debug_switch   = 0;
23411 +unsigned int vs_debug_xid      = 0;
23412 +unsigned int vs_debug_nid      = 0;
23413 +unsigned int vs_debug_tag      = 0;
23414 +unsigned int vs_debug_net      = 0;
23415 +unsigned int vs_debug_limit    = 0;
23416 +unsigned int vs_debug_cres     = 0;
23417 +unsigned int vs_debug_dlim     = 0;
23418 +unsigned int vs_debug_quota    = 0;
23419 +unsigned int vs_debug_cvirt    = 0;
23420 +unsigned int vs_debug_space    = 0;
23421 +unsigned int vs_debug_perm     = 0;
23422 +unsigned int vs_debug_misc     = 0;
23423 +
23424 +
23425 +static struct ctl_table_header *vserver_table_header;
23426 +static ctl_table vserver_root_table[];
23427 +
23428 +
23429 +void vserver_register_sysctl(void)
23430 +{
23431 +       if (!vserver_table_header) {
23432 +               vserver_table_header = register_sysctl_table(vserver_root_table);
23433 +       }
23434 +
23435 +}
23436 +
23437 +void vserver_unregister_sysctl(void)
23438 +{
23439 +       if (vserver_table_header) {
23440 +               unregister_sysctl_table(vserver_table_header);
23441 +               vserver_table_header = NULL;
23442 +       }
23443 +}
23444 +
23445 +
23446 +static int proc_dodebug(ctl_table *table, int write,
23447 +       void __user *buffer, size_t *lenp, loff_t *ppos)
23448 +{
23449 +       char            tmpbuf[20], *p, c;
23450 +       unsigned int    value;
23451 +       size_t          left, len;
23452 +
23453 +       if ((*ppos && !write) || !*lenp) {
23454 +               *lenp = 0;
23455 +               return 0;
23456 +       }
23457 +
23458 +       left = *lenp;
23459 +
23460 +       if (write) {
23461 +               if (!access_ok(VERIFY_READ, buffer, left))
23462 +                       return -EFAULT;
23463 +               p = (char *)buffer;
23464 +               while (left && __get_user(c, p) >= 0 && isspace(c))
23465 +                       left--, p++;
23466 +               if (!left)
23467 +                       goto done;
23468 +
23469 +               if (left > sizeof(tmpbuf) - 1)
23470 +                       return -EINVAL;
23471 +               if (copy_from_user(tmpbuf, p, left))
23472 +                       return -EFAULT;
23473 +               tmpbuf[left] = '\0';
23474 +
23475 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
23476 +                       value = 10 * value + (*p - '0');
23477 +               if (*p && !isspace(*p))
23478 +                       return -EINVAL;
23479 +               while (left && isspace(*p))
23480 +                       left--, p++;
23481 +               *(unsigned int *)table->data = value;
23482 +       } else {
23483 +               if (!access_ok(VERIFY_WRITE, buffer, left))
23484 +                       return -EFAULT;
23485 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
23486 +               if (len > left)
23487 +                       len = left;
23488 +               if (__copy_to_user(buffer, tmpbuf, len))
23489 +                       return -EFAULT;
23490 +               if ((left -= len) > 0) {
23491 +                       if (put_user('\n', (char *)buffer + len))
23492 +                               return -EFAULT;
23493 +                       left--;
23494 +               }
23495 +       }
23496 +
23497 +done:
23498 +       *lenp -= left;
23499 +       *ppos += *lenp;
23500 +       return 0;
23501 +}
23502 +
23503 +static int zero;
23504 +
23505 +#define        CTL_ENTRY(ctl, name)                            \
23506 +       {                                               \
23507 +               .procname       = #name,                \
23508 +               .data           = &vs_ ## name,         \
23509 +               .maxlen         = sizeof(int),          \
23510 +               .mode           = 0644,                 \
23511 +               .proc_handler   = &proc_dodebug,        \
23512 +               .extra1         = &zero,                \
23513 +               .extra2         = &zero,                \
23514 +       }
23515 +
23516 +static ctl_table vserver_debug_table[] = {
23517 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
23518 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
23519 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
23520 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
23521 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
23522 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
23523 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
23524 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
23525 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
23526 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
23527 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
23528 +       CTL_ENTRY(CTL_DEBUG_PERM,       debug_perm),
23529 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
23530 +       { 0 }
23531 +};
23532 +
23533 +static ctl_table vserver_root_table[] = {
23534 +       {
23535 +               .procname       = "vserver",
23536 +               .mode           = 0555,
23537 +               .child          = vserver_debug_table
23538 +       },
23539 +       { 0 }
23540 +};
23541 +
23542 +
23543 +static match_table_t tokens = {
23544 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
23545 +       { CTL_DEBUG_XID,        "xid=%x"        },
23546 +       { CTL_DEBUG_NID,        "nid=%x"        },
23547 +       { CTL_DEBUG_TAG,        "tag=%x"        },
23548 +       { CTL_DEBUG_NET,        "net=%x"        },
23549 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
23550 +       { CTL_DEBUG_CRES,       "cres=%x"       },
23551 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
23552 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
23553 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
23554 +       { CTL_DEBUG_SPACE,      "space=%x"      },
23555 +       { CTL_DEBUG_PERM,       "perm=%x"       },
23556 +       { CTL_DEBUG_MISC,       "misc=%x"       },
23557 +       { CTL_DEBUG_ERROR,      NULL            }
23558 +};
23559 +
23560 +#define        HANDLE_CASE(id, name, val)                              \
23561 +       case CTL_DEBUG_ ## id:                                  \
23562 +               vs_debug_ ## name = val;                        \
23563 +               printk("vs_debug_" #name "=0x%x\n", val);       \
23564 +               break
23565 +
23566 +
23567 +static int __init vs_debug_setup(char *str)
23568 +{
23569 +       char *p;
23570 +       int token;
23571 +
23572 +       printk("vs_debug_setup(%s)\n", str);
23573 +       while ((p = strsep(&str, ",")) != NULL) {
23574 +               substring_t args[MAX_OPT_ARGS];
23575 +               unsigned int value;
23576 +
23577 +               if (!*p)
23578 +                       continue;
23579 +
23580 +               token = match_token(p, tokens, args);
23581 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
23582 +
23583 +               switch (token) {
23584 +               HANDLE_CASE(SWITCH, switch, value);
23585 +               HANDLE_CASE(XID,    xid,    value);
23586 +               HANDLE_CASE(NID,    nid,    value);
23587 +               HANDLE_CASE(TAG,    tag,    value);
23588 +               HANDLE_CASE(NET,    net,    value);
23589 +               HANDLE_CASE(LIMIT,  limit,  value);
23590 +               HANDLE_CASE(CRES,   cres,   value);
23591 +               HANDLE_CASE(DLIM,   dlim,   value);
23592 +               HANDLE_CASE(QUOTA,  quota,  value);
23593 +               HANDLE_CASE(CVIRT,  cvirt,  value);
23594 +               HANDLE_CASE(SPACE,  space,  value);
23595 +               HANDLE_CASE(PERM,   perm,   value);
23596 +               HANDLE_CASE(MISC,   misc,   value);
23597 +               default:
23598 +                       return -EINVAL;
23599 +                       break;
23600 +               }
23601 +       }
23602 +       return 1;
23603 +}
23604 +
23605 +__setup("vsdebug=", vs_debug_setup);
23606 +
23607 +
23608 +
23609 +EXPORT_SYMBOL_GPL(vs_debug_switch);
23610 +EXPORT_SYMBOL_GPL(vs_debug_xid);
23611 +EXPORT_SYMBOL_GPL(vs_debug_nid);
23612 +EXPORT_SYMBOL_GPL(vs_debug_net);
23613 +EXPORT_SYMBOL_GPL(vs_debug_limit);
23614 +EXPORT_SYMBOL_GPL(vs_debug_cres);
23615 +EXPORT_SYMBOL_GPL(vs_debug_dlim);
23616 +EXPORT_SYMBOL_GPL(vs_debug_quota);
23617 +EXPORT_SYMBOL_GPL(vs_debug_cvirt);
23618 +EXPORT_SYMBOL_GPL(vs_debug_space);
23619 +EXPORT_SYMBOL_GPL(vs_debug_perm);
23620 +EXPORT_SYMBOL_GPL(vs_debug_misc);
23621 +
23622 diff -NurpP --minimal linux-3.9.4/kernel/vserver/tag.c linux-3.9.4-vs2.3.6.1/kernel/vserver/tag.c
23623 --- linux-3.9.4/kernel/vserver/tag.c    1970-01-01 00:00:00.000000000 +0000
23624 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/tag.c  2013-05-31 14:47:11.000000000 +0000
23625 @@ -0,0 +1,63 @@
23626 +/*
23627 + *  linux/kernel/vserver/tag.c
23628 + *
23629 + *  Virtual Server: Shallow Tag Space
23630 + *
23631 + *  Copyright (C) 2007  Herbert Pötzl
23632 + *
23633 + *  V0.01  basic implementation
23634 + *
23635 + */
23636 +
23637 +#include <linux/sched.h>
23638 +#include <linux/vserver/debug.h>
23639 +#include <linux/vs_pid.h>
23640 +#include <linux/vs_tag.h>
23641 +
23642 +#include <linux/vserver/tag_cmd.h>
23643 +
23644 +
23645 +int dx_migrate_task(struct task_struct *p, tag_t tag)
23646 +{
23647 +       if (!p)
23648 +               BUG();
23649 +
23650 +       vxdprintk(VXD_CBIT(tag, 5),
23651 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
23652 +
23653 +       task_lock(p);
23654 +       p->tag = tag;
23655 +       task_unlock(p);
23656 +
23657 +       vxdprintk(VXD_CBIT(tag, 5),
23658 +               "moved task %p into [#%d]", p, tag);
23659 +       return 0;
23660 +}
23661 +
23662 +/* vserver syscall commands below here */
23663 +
23664 +/* taks xid and vx_info functions */
23665 +
23666 +
23667 +int vc_task_tag(uint32_t id)
23668 +{
23669 +       tag_t tag;
23670 +
23671 +       if (id) {
23672 +               struct task_struct *tsk;
23673 +               rcu_read_lock();
23674 +               tsk = find_task_by_real_pid(id);
23675 +               tag = (tsk) ? tsk->tag : -ESRCH;
23676 +               rcu_read_unlock();
23677 +       } else
23678 +               tag = dx_current_tag();
23679 +       return tag;
23680 +}
23681 +
23682 +
23683 +int vc_tag_migrate(uint32_t tag)
23684 +{
23685 +       return dx_migrate_task(current, tag & 0xFFFF);
23686 +}
23687 +
23688 +
23689 diff -NurpP --minimal linux-3.9.4/kernel/vserver/vci_config.h linux-3.9.4-vs2.3.6.1/kernel/vserver/vci_config.h
23690 --- linux-3.9.4/kernel/vserver/vci_config.h     1970-01-01 00:00:00.000000000 +0000
23691 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/vci_config.h   2013-05-31 14:47:11.000000000 +0000
23692 @@ -0,0 +1,80 @@
23693 +
23694 +/*  interface version */
23695 +
23696 +#define VCI_VERSION            0x00020308
23697 +
23698 +
23699 +enum {
23700 +       VCI_KCBIT_NO_DYNAMIC = 0,
23701 +
23702 +       VCI_KCBIT_PROC_SECURE = 4,
23703 +       /* VCI_KCBIT_HARDCPU = 5, */
23704 +       /* VCI_KCBIT_IDLELIMIT = 6, */
23705 +       /* VCI_KCBIT_IDLETIME = 7, */
23706 +
23707 +       VCI_KCBIT_COWBL = 8,
23708 +       VCI_KCBIT_FULLCOWBL = 9,
23709 +       VCI_KCBIT_SPACES = 10,
23710 +       VCI_KCBIT_NETV2 = 11,
23711 +       VCI_KCBIT_MEMCG = 12,
23712 +       VCI_KCBIT_MEMCG_SWAP = 13,
23713 +
23714 +       VCI_KCBIT_DEBUG = 16,
23715 +       VCI_KCBIT_HISTORY = 20,
23716 +       VCI_KCBIT_TAGGED = 24,
23717 +       VCI_KCBIT_PPTAG = 28,
23718 +
23719 +       VCI_KCBIT_MORE = 31,
23720 +};
23721 +
23722 +
23723 +static inline uint32_t vci_kernel_config(void)
23724 +{
23725 +       return
23726 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
23727 +
23728 +       /* configured features */
23729 +#ifdef CONFIG_VSERVER_PROC_SECURE
23730 +       (1 << VCI_KCBIT_PROC_SECURE) |
23731 +#endif
23732 +#ifdef CONFIG_VSERVER_COWBL
23733 +       (1 << VCI_KCBIT_COWBL) |
23734 +       (1 << VCI_KCBIT_FULLCOWBL) |
23735 +#endif
23736 +       (1 << VCI_KCBIT_SPACES) |
23737 +       (1 << VCI_KCBIT_NETV2) |
23738 +#ifdef CONFIG_MEMCG
23739 +       (1 << VCI_KCBIT_MEMCG) |
23740 +#endif
23741 +#ifdef CONFIG_MEMCG_SWAP
23742 +       (1 << VCI_KCBIT_MEMCG_SWAP) |
23743 +#endif
23744 +
23745 +       /* debug options */
23746 +#ifdef CONFIG_VSERVER_DEBUG
23747 +       (1 << VCI_KCBIT_DEBUG) |
23748 +#endif
23749 +#ifdef CONFIG_VSERVER_HISTORY
23750 +       (1 << VCI_KCBIT_HISTORY) |
23751 +#endif
23752 +
23753 +       /* inode context tagging */
23754 +#if    defined(CONFIG_TAGGING_NONE)
23755 +       (0 << VCI_KCBIT_TAGGED) |
23756 +#elif  defined(CONFIG_TAGGING_UID16)
23757 +       (1 << VCI_KCBIT_TAGGED) |
23758 +#elif  defined(CONFIG_TAGGING_GID16)
23759 +       (2 << VCI_KCBIT_TAGGED) |
23760 +#elif  defined(CONFIG_TAGGING_ID24)
23761 +       (3 << VCI_KCBIT_TAGGED) |
23762 +#elif  defined(CONFIG_TAGGING_INTERN)
23763 +       (4 << VCI_KCBIT_TAGGED) |
23764 +#elif  defined(CONFIG_TAGGING_RUNTIME)
23765 +       (5 << VCI_KCBIT_TAGGED) |
23766 +#else
23767 +       (7 << VCI_KCBIT_TAGGED) |
23768 +#endif
23769 +       (1 << VCI_KCBIT_PPTAG) |
23770 +       0;
23771 +}
23772 +
23773 diff -NurpP --minimal linux-3.9.4/mm/memcontrol.c linux-3.9.4-vs2.3.6.1/mm/memcontrol.c
23774 --- linux-3.9.4/mm/memcontrol.c 2013-05-31 13:45:31.000000000 +0000
23775 +++ linux-3.9.4-vs2.3.6.1/mm/memcontrol.c       2013-05-31 14:47:11.000000000 +0000
23776 @@ -1046,6 +1046,31 @@ struct mem_cgroup *mem_cgroup_from_task(
23777         return mem_cgroup_from_css(task_subsys_state(p, mem_cgroup_subsys_id));
23778  }
23779  
23780 +u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member)
23781 +{
23782 +       return res_counter_read_u64(&mem->res, member);
23783 +}
23784 +
23785 +u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member)
23786 +{
23787 +       return res_counter_read_u64(&mem->memsw, member);
23788 +}
23789 +
23790 +s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem)
23791 +{
23792 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_CACHE);
23793 +}
23794 +
23795 +s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem)
23796 +{
23797 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_RSS);
23798 +}
23799 +
23800 +s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem)
23801 +{
23802 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_FILE_MAPPED);
23803 +}
23804 +
23805  struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
23806  {
23807         struct mem_cgroup *memcg = NULL;
23808 diff -NurpP --minimal linux-3.9.4/mm/oom_kill.c linux-3.9.4-vs2.3.6.1/mm/oom_kill.c
23809 --- linux-3.9.4/mm/oom_kill.c   2013-05-31 13:45:31.000000000 +0000
23810 +++ linux-3.9.4-vs2.3.6.1/mm/oom_kill.c 2013-05-31 14:47:11.000000000 +0000
23811 @@ -35,6 +35,8 @@
23812  #include <linux/freezer.h>
23813  #include <linux/ftrace.h>
23814  #include <linux/ratelimit.h>
23815 +#include <linux/reboot.h>
23816 +#include <linux/vs_context.h>
23817  
23818  #define CREATE_TRACE_POINTS
23819  #include <trace/events/oom.h>
23820 @@ -113,11 +115,18 @@ struct task_struct *find_lock_task_mm(st
23821  static bool oom_unkillable_task(struct task_struct *p,
23822                 const struct mem_cgroup *memcg, const nodemask_t *nodemask)
23823  {
23824 -       if (is_global_init(p))
23825 +       unsigned xid = vx_current_xid();
23826 +
23827 +       /* skip the init task, global and per guest */
23828 +       if (task_is_init(p))
23829                 return true;
23830         if (p->flags & PF_KTHREAD)
23831                 return true;
23832  
23833 +       /* skip other guest and host processes if oom in guest */
23834 +       if (xid && vx_task_xid(p) != xid)
23835 +               return true;
23836 +
23837         /* When mem_cgroup_out_of_memory() and p is not member of the group */
23838         if (memcg && !task_in_mem_cgroup(p, memcg))
23839                 return true;
23840 @@ -426,8 +435,8 @@ void oom_kill_process(struct task_struct
23841                 dump_header(p, gfp_mask, order, memcg, nodemask);
23842  
23843         task_lock(p);
23844 -       pr_err("%s: Kill process %d (%s) score %d or sacrifice child\n",
23845 -               message, task_pid_nr(p), p->comm, points);
23846 +       pr_err("%s: Kill process %d:#%u (%s) score %d or sacrifice child\n",
23847 +               message, task_pid_nr(p), p->xid, p->comm, points);
23848         task_unlock(p);
23849  
23850         /*
23851 @@ -472,8 +481,8 @@ void oom_kill_process(struct task_struct
23852  
23853         /* mm cannot safely be dereferenced after task_unlock(victim) */
23854         mm = victim->mm;
23855 -       pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23856 -               task_pid_nr(victim), victim->comm, K(victim->mm->total_vm),
23857 +       pr_err("Killed process %d:#%u (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23858 +               task_pid_nr(victim), victim->xid, victim->comm, K(victim->mm->total_vm),
23859                 K(get_mm_counter(victim->mm, MM_ANONPAGES)),
23860                 K(get_mm_counter(victim->mm, MM_FILEPAGES)));
23861         task_unlock(victim);
23862 @@ -543,6 +552,8 @@ int unregister_oom_notifier(struct notif
23863  }
23864  EXPORT_SYMBOL_GPL(unregister_oom_notifier);
23865  
23866 +long vs_oom_action(unsigned int);
23867 +
23868  /*
23869   * Try to acquire the OOM killer lock for the zones in zonelist.  Returns zero
23870   * if a parallel OOM killing is already taking place that includes a zone in
23871 @@ -655,7 +666,12 @@ void out_of_memory(struct zonelist *zone
23872         /* Found nothing?!?! Either we hang forever, or we panic. */
23873         if (!p) {
23874                 dump_header(NULL, gfp_mask, order, NULL, mpol_mask);
23875 -               panic("Out of memory and no killable processes...\n");
23876 +
23877 +               /* avoid panic for guest OOM */
23878 +               if (vx_current_xid())
23879 +                       vs_oom_action(LINUX_REBOOT_CMD_OOM);
23880 +               else
23881 +                       panic("Out of memory and no killable processes...\n");
23882         }
23883         if (PTR_ERR(p) != -1UL) {
23884                 oom_kill_process(p, gfp_mask, order, points, totalpages, NULL,
23885 diff -NurpP --minimal linux-3.9.4/mm/page_alloc.c linux-3.9.4-vs2.3.6.1/mm/page_alloc.c
23886 --- linux-3.9.4/mm/page_alloc.c 2013-05-31 13:45:31.000000000 +0000
23887 +++ linux-3.9.4-vs2.3.6.1/mm/page_alloc.c       2013-05-31 15:08:50.000000000 +0000
23888 @@ -59,6 +59,8 @@
23889  #include <linux/migrate.h>
23890  #include <linux/page-debug-flags.h>
23891  #include <linux/sched/rt.h>
23892 +#include <linux/vs_base.h>
23893 +#include <linux/vs_limit.h>
23894  
23895  #include <asm/tlbflush.h>
23896  #include <asm/div64.h>
23897 @@ -2873,6 +2875,9 @@ void si_meminfo(struct sysinfo *val)
23898         val->totalhigh = totalhigh_pages;
23899         val->freehigh = nr_free_highpages();
23900         val->mem_unit = PAGE_SIZE;
23901 +
23902 +       if (vx_flags(VXF_VIRT_MEM, 0))
23903 +               vx_vsi_meminfo(val);
23904  }
23905  
23906  EXPORT_SYMBOL(si_meminfo);
23907 @@ -2893,6 +2898,9 @@ void si_meminfo_node(struct sysinfo *val
23908         val->freehigh = 0;
23909  #endif
23910         val->mem_unit = PAGE_SIZE;
23911 +
23912 +       if (vx_flags(VXF_VIRT_MEM, 0))
23913 +               vx_vsi_meminfo(val);
23914  }
23915  #endif
23916  
23917 diff -NurpP --minimal linux-3.9.4/mm/pgtable-generic.c linux-3.9.4-vs2.3.6.1/mm/pgtable-generic.c
23918 --- linux-3.9.4/mm/pgtable-generic.c    2013-02-19 13:58:57.000000000 +0000
23919 +++ linux-3.9.4-vs2.3.6.1/mm/pgtable-generic.c  2013-05-31 14:47:11.000000000 +0000
23920 @@ -6,6 +6,8 @@
23921   *  Copyright (C) 2010  Linus Torvalds
23922   */
23923  
23924 +#include <linux/mm.h>
23925 +
23926  #include <linux/pagemap.h>
23927  #include <asm/tlb.h>
23928  #include <asm-generic/pgtable.h>
23929 diff -NurpP --minimal linux-3.9.4/mm/shmem.c linux-3.9.4-vs2.3.6.1/mm/shmem.c
23930 --- linux-3.9.4/mm/shmem.c      2013-05-31 13:45:31.000000000 +0000
23931 +++ linux-3.9.4-vs2.3.6.1/mm/shmem.c    2013-05-31 14:47:11.000000000 +0000
23932 @@ -1909,7 +1909,7 @@ static int shmem_statfs(struct dentry *d
23933  {
23934         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
23935  
23936 -       buf->f_type = TMPFS_MAGIC;
23937 +       buf->f_type = TMPFS_SUPER_MAGIC;
23938         buf->f_bsize = PAGE_CACHE_SIZE;
23939         buf->f_namelen = NAME_MAX;
23940         if (sbinfo->max_blocks) {
23941 @@ -2606,7 +2606,7 @@ int shmem_fill_super(struct super_block
23942         sb->s_maxbytes = MAX_LFS_FILESIZE;
23943         sb->s_blocksize = PAGE_CACHE_SIZE;
23944         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
23945 -       sb->s_magic = TMPFS_MAGIC;
23946 +       sb->s_magic = TMPFS_SUPER_MAGIC;
23947         sb->s_op = &shmem_ops;
23948         sb->s_time_gran = 1;
23949  #ifdef CONFIG_TMPFS_XATTR
23950 diff -NurpP --minimal linux-3.9.4/mm/slab.c linux-3.9.4-vs2.3.6.1/mm/slab.c
23951 --- linux-3.9.4/mm/slab.c       2013-05-31 13:45:31.000000000 +0000
23952 +++ linux-3.9.4-vs2.3.6.1/mm/slab.c     2013-05-31 14:47:11.000000000 +0000
23953 @@ -429,6 +429,8 @@ static void kmem_list3_init(struct kmem_
23954  #define STATS_INC_FREEMISS(x)  do { } while (0)
23955  #endif
23956  
23957 +#include "slab_vs.h"
23958 +
23959  #if DEBUG
23960  
23961  /*
23962 @@ -3438,6 +3440,7 @@ retry:
23963  
23964         obj = slab_get_obj(cachep, slabp, nodeid);
23965         check_slabp(cachep, slabp);
23966 +       vx_slab_alloc(cachep, flags);
23967         l3->free_objects--;
23968         /* move slabp to correct slabp list: */
23969         list_del(&slabp->list);
23970 @@ -3517,6 +3520,7 @@ slab_alloc_node(struct kmem_cache *cache
23971         /* ___cache_alloc_node can fall back to other nodes */
23972         ptr = ____cache_alloc_node(cachep, flags, nodeid);
23973    out:
23974 +       vx_slab_alloc(cachep, flags);
23975         local_irq_restore(save_flags);
23976         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
23977         kmemleak_alloc_recursive(ptr, cachep->object_size, 1, cachep->flags,
23978 @@ -3709,6 +3713,7 @@ static inline void __cache_free(struct k
23979         check_irq_off();
23980         kmemleak_free_recursive(objp, cachep->flags);
23981         objp = cache_free_debugcheck(cachep, objp, caller);
23982 +       vx_slab_free(cachep);
23983  
23984         kmemcheck_slab_free(cachep, objp, cachep->object_size);
23985  
23986 diff -NurpP --minimal linux-3.9.4/mm/slab_vs.h linux-3.9.4-vs2.3.6.1/mm/slab_vs.h
23987 --- linux-3.9.4/mm/slab_vs.h    1970-01-01 00:00:00.000000000 +0000
23988 +++ linux-3.9.4-vs2.3.6.1/mm/slab_vs.h  2013-05-31 14:47:11.000000000 +0000
23989 @@ -0,0 +1,29 @@
23990 +
23991 +#include <linux/vserver/context.h>
23992 +
23993 +#include <linux/vs_context.h>
23994 +
23995 +static inline
23996 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
23997 +{
23998 +       int what = gfp_zone(cachep->allocflags);
23999 +       struct vx_info *vxi = current_vx_info();
24000 +
24001 +       if (!vxi)
24002 +               return;
24003 +
24004 +       atomic_add(cachep->size, &vxi->cacct.slab[what]);
24005 +}
24006 +
24007 +static inline
24008 +void vx_slab_free(struct kmem_cache *cachep)
24009 +{
24010 +       int what = gfp_zone(cachep->allocflags);
24011 +       struct vx_info *vxi = current_vx_info();
24012 +
24013 +       if (!vxi)
24014 +               return;
24015 +
24016 +       atomic_sub(cachep->size, &vxi->cacct.slab[what]);
24017 +}
24018 +
24019 diff -NurpP --minimal linux-3.9.4/mm/swapfile.c linux-3.9.4-vs2.3.6.1/mm/swapfile.c
24020 --- linux-3.9.4/mm/swapfile.c   2013-05-31 13:45:31.000000000 +0000
24021 +++ linux-3.9.4-vs2.3.6.1/mm/swapfile.c 2013-05-31 14:47:11.000000000 +0000
24022 @@ -39,6 +39,7 @@
24023  #include <asm/tlbflush.h>
24024  #include <linux/swapops.h>
24025  #include <linux/page_cgroup.h>
24026 +#include <linux/vs_base.h>
24027  
24028  static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
24029                                  unsigned char);
24030 @@ -1767,6 +1768,16 @@ static int swap_show(struct seq_file *sw
24031  
24032         if (si == SEQ_START_TOKEN) {
24033                 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
24034 +               if (vx_flags(VXF_VIRT_MEM, 0)) {
24035 +                       struct sysinfo si;
24036 +
24037 +                       vx_vsi_swapinfo(&si);
24038 +                       if (si.totalswap < (1 << 10))
24039 +                               return 0;
24040 +                       seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
24041 +                               "hdv0", "partition", si.totalswap >> 10,
24042 +                               (si.totalswap - si.freeswap) >> 10, -1);
24043 +               }
24044                 return 0;
24045         }
24046  
24047 @@ -2195,6 +2206,8 @@ void si_swapinfo(struct sysinfo *val)
24048         val->freeswap = atomic_long_read(&nr_swap_pages) + nr_to_be_unused;
24049         val->totalswap = total_swap_pages + nr_to_be_unused;
24050         spin_unlock(&swap_lock);
24051 +       if (vx_flags(VXF_VIRT_MEM, 0))
24052 +               vx_vsi_swapinfo(val);
24053  }
24054  
24055  /*
24056 diff -NurpP --minimal linux-3.9.4/net/bridge/br_multicast.c linux-3.9.4-vs2.3.6.1/net/bridge/br_multicast.c
24057 --- linux-3.9.4/net/bridge/br_multicast.c       2013-05-31 13:45:31.000000000 +0000
24058 +++ linux-3.9.4-vs2.3.6.1/net/bridge/br_multicast.c     2013-05-31 17:17:53.000000000 +0000
24059 @@ -443,7 +443,7 @@ static struct sk_buff *br_ip6_multicast_
24060         ip6h->hop_limit = 1;
24061         ipv6_addr_set(&ip6h->daddr, htonl(0xff020000), 0, 0, htonl(1));
24062         if (ipv6_dev_get_saddr(dev_net(br->dev), br->dev, &ip6h->daddr, 0,
24063 -                              &ip6h->saddr)) {
24064 +                              &ip6h->saddr, NULL)) {
24065                 kfree_skb(skb);
24066                 return NULL;
24067         }
24068 diff -NurpP --minimal linux-3.9.4/net/core/dev.c linux-3.9.4-vs2.3.6.1/net/core/dev.c
24069 --- linux-3.9.4/net/core/dev.c  2013-05-31 14:22:27.000000000 +0000
24070 +++ linux-3.9.4-vs2.3.6.1/net/core/dev.c        2013-05-31 18:37:38.000000000 +0000
24071 @@ -122,6 +122,7 @@
24072  #include <linux/in.h>
24073  #include <linux/jhash.h>
24074  #include <linux/random.h>
24075 +#include <linux/vs_inet.h>
24076  #include <trace/events/napi.h>
24077  #include <trace/events/net.h>
24078  #include <trace/events/skb.h>
24079 @@ -662,7 +663,8 @@ struct net_device *__dev_get_by_name(str
24080         struct hlist_head *head = dev_name_hash(net, name);
24081  
24082         hlist_for_each_entry(dev, head, name_hlist)
24083 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24084 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24085 +                   nx_dev_visible(current_nx_info(), dev))
24086                         return dev;
24087  
24088         return NULL;
24089 @@ -687,7 +689,8 @@ struct net_device *dev_get_by_name_rcu(s
24090         struct hlist_head *head = dev_name_hash(net, name);
24091  
24092         hlist_for_each_entry_rcu(dev, head, name_hlist)
24093 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24094 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24095 +                   nx_dev_visible(current_nx_info(), dev))
24096                         return dev;
24097  
24098         return NULL;
24099 @@ -737,7 +740,8 @@ struct net_device *__dev_get_by_index(st
24100         struct hlist_head *head = dev_index_hash(net, ifindex);
24101  
24102         hlist_for_each_entry(dev, head, index_hlist)
24103 -               if (dev->ifindex == ifindex)
24104 +               if ((dev->ifindex == ifindex) &&
24105 +                   nx_dev_visible(current_nx_info(), dev))
24106                         return dev;
24107  
24108         return NULL;
24109 @@ -755,7 +759,7 @@ EXPORT_SYMBOL(__dev_get_by_index);
24110   *     about locking. The caller must hold RCU lock.
24111   */
24112  
24113 -struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
24114 +struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex)
24115  {
24116         struct net_device *dev;
24117         struct hlist_head *head = dev_index_hash(net, ifindex);
24118 @@ -766,6 +770,16 @@ struct net_device *dev_get_by_index_rcu(
24119  
24120         return NULL;
24121  }
24122 +EXPORT_SYMBOL(dev_get_by_index_real_rcu);
24123 +
24124 +struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
24125 +{
24126 +       struct net_device *dev = dev_get_by_index_real_rcu(net, ifindex);
24127 +
24128 +       if (nx_dev_visible(current_nx_info(), dev))
24129 +               return dev;
24130 +       return NULL;
24131 +}
24132  EXPORT_SYMBOL(dev_get_by_index_rcu);
24133  
24134  
24135 @@ -814,7 +828,8 @@ struct net_device *dev_getbyhwaddr_rcu(s
24136  
24137         for_each_netdev_rcu(net, dev)
24138                 if (dev->type == type &&
24139 -                   !memcmp(dev->dev_addr, ha, dev->addr_len))
24140 +                   !memcmp(dev->dev_addr, ha, dev->addr_len) &&
24141 +                   nx_dev_visible(current_nx_info(), dev))
24142                         return dev;
24143  
24144         return NULL;
24145 @@ -826,9 +841,11 @@ struct net_device *__dev_getfirstbyhwtyp
24146         struct net_device *dev;
24147  
24148         ASSERT_RTNL();
24149 -       for_each_netdev(net, dev)
24150 -               if (dev->type == type)
24151 +       for_each_netdev(net, dev) {
24152 +               if ((dev->type == type) &&
24153 +                   nx_dev_visible(current_nx_info(), dev))
24154                         return dev;
24155 +       }
24156  
24157         return NULL;
24158  }
24159 @@ -840,7 +857,8 @@ struct net_device *dev_getfirstbyhwtype(
24160  
24161         rcu_read_lock();
24162         for_each_netdev_rcu(net, dev)
24163 -               if (dev->type == type) {
24164 +               if ((dev->type == type) &&
24165 +                   nx_dev_visible(current_nx_info(), dev)) {
24166                         dev_hold(dev);
24167                         ret = dev;
24168                         break;
24169 @@ -868,7 +886,8 @@ struct net_device *dev_get_by_flags_rcu(
24170  
24171         ret = NULL;
24172         for_each_netdev_rcu(net, dev) {
24173 -               if (((dev->flags ^ if_flags) & mask) == 0) {
24174 +               if ((((dev->flags ^ if_flags) & mask) == 0) &&
24175 +                       nx_dev_visible(current_nx_info(), dev)) {
24176                         ret = dev;
24177                         break;
24178                 }
24179 @@ -946,6 +965,8 @@ static int __dev_alloc_name(struct net *
24180                                 continue;
24181                         if (i < 0 || i >= max_netdevices)
24182                                 continue;
24183 +                       if (!nx_dev_visible(current_nx_info(), d))
24184 +                               continue;
24185  
24186                         /*  avoid cases where sscanf is not exact inverse of printf */
24187                         snprintf(buf, IFNAMSIZ, name, i);
24188 diff -NurpP --minimal linux-3.9.4/net/core/rtnetlink.c linux-3.9.4-vs2.3.6.1/net/core/rtnetlink.c
24189 --- linux-3.9.4/net/core/rtnetlink.c    2013-05-31 13:45:32.000000000 +0000
24190 +++ linux-3.9.4-vs2.3.6.1/net/core/rtnetlink.c  2013-05-31 17:17:54.000000000 +0000
24191 @@ -1085,6 +1085,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
24192                 hlist_for_each_entry_rcu(dev, head, index_hlist) {
24193                         if (idx < s_idx)
24194                                 goto cont;
24195 +                       if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
24196 +                               continue;
24197                         if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
24198                                              NETLINK_CB(cb->skb).portid,
24199                                              cb->nlh->nlmsg_seq, 0,
24200 @@ -1974,6 +1976,9 @@ void rtmsg_ifinfo(int type, struct net_d
24201         int err = -ENOBUFS;
24202         size_t if_info_size;
24203  
24204 +       if (!nx_dev_visible(current_nx_info(), dev))
24205 +               return;
24206 +
24207         skb = nlmsg_new((if_info_size = if_nlmsg_size(dev, 0)), GFP_KERNEL);
24208         if (skb == NULL)
24209                 goto errout;
24210 diff -NurpP --minimal linux-3.9.4/net/core/sock.c linux-3.9.4-vs2.3.6.1/net/core/sock.c
24211 --- linux-3.9.4/net/core/sock.c 2013-05-31 14:22:27.000000000 +0000
24212 +++ linux-3.9.4-vs2.3.6.1/net/core/sock.c       2013-05-31 17:17:54.000000000 +0000
24213 @@ -132,6 +132,10 @@
24214  #include <net/netprio_cgroup.h>
24215  
24216  #include <linux/filter.h>
24217 +#include <linux/vs_socket.h>
24218 +#include <linux/vs_limit.h>
24219 +#include <linux/vs_context.h>
24220 +#include <linux/vs_network.h>
24221  
24222  #include <trace/events/sock.h>
24223  
24224 @@ -1257,6 +1261,8 @@ static struct sock *sk_prot_alloc(struct
24225                         goto out_free_sec;
24226                 sk_tx_queue_clear(sk);
24227         }
24228 +               sock_vx_init(sk);
24229 +               sock_nx_init(sk);
24230  
24231         return sk;
24232  
24233 @@ -1367,6 +1373,11 @@ static void __sk_free(struct sock *sk)
24234                 put_cred(sk->sk_peer_cred);
24235         put_pid(sk->sk_peer_pid);
24236         put_net(sock_net(sk));
24237 +       vx_sock_dec(sk);
24238 +       clr_vx_info(&sk->sk_vx_info);
24239 +       sk->sk_xid = -1;
24240 +       clr_nx_info(&sk->sk_nx_info);
24241 +       sk->sk_nid = -1;
24242         sk_prot_free(sk->sk_prot_creator, sk);
24243  }
24244  
24245 @@ -1427,6 +1438,8 @@ struct sock *sk_clone_lock(const struct
24246  
24247                 /* SANITY */
24248                 get_net(sock_net(newsk));
24249 +               sock_vx_init(newsk);
24250 +               sock_nx_init(newsk);
24251                 sk_node_init(&newsk->sk_node);
24252                 sock_lock_init(newsk);
24253                 bh_lock_sock(newsk);
24254 @@ -1483,6 +1496,12 @@ struct sock *sk_clone_lock(const struct
24255                 smp_wmb();
24256                 atomic_set(&newsk->sk_refcnt, 2);
24257  
24258 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
24259 +               newsk->sk_xid = sk->sk_xid;
24260 +               vx_sock_inc(newsk);
24261 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
24262 +               newsk->sk_nid = sk->sk_nid;
24263 +
24264                 /*
24265                  * Increment the counter in the same struct proto as the master
24266                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
24267 @@ -2278,6 +2297,12 @@ void sock_init_data(struct socket *sock,
24268  
24269         sk->sk_stamp = ktime_set(-1L, 0);
24270  
24271 +       set_vx_info(&sk->sk_vx_info, current_vx_info());
24272 +       sk->sk_xid = vx_current_xid();
24273 +       vx_sock_inc(sk);
24274 +       set_nx_info(&sk->sk_nx_info, current_nx_info());
24275 +       sk->sk_nid = nx_current_nid();
24276 +
24277         /*
24278          * Before updating sk_refcnt, we must commit prior changes to memory
24279          * (Documentation/RCU/rculist_nulls.txt for details)
24280 diff -NurpP --minimal linux-3.9.4/net/ipv4/af_inet.c linux-3.9.4-vs2.3.6.1/net/ipv4/af_inet.c
24281 --- linux-3.9.4/net/ipv4/af_inet.c      2013-05-31 13:45:32.000000000 +0000
24282 +++ linux-3.9.4-vs2.3.6.1/net/ipv4/af_inet.c    2013-05-31 18:24:05.000000000 +0000
24283 @@ -118,6 +118,7 @@
24284  #ifdef CONFIG_IP_MROUTE
24285  #include <linux/mroute.h>
24286  #endif
24287 +#include <linux/vs_limit.h>
24288  
24289  
24290  /* The inetsw table contains everything that inet_create needs to
24291 @@ -336,6 +337,10 @@ lookup_protocol:
24292         }
24293  
24294         err = -EPERM;
24295 +       if ((protocol == IPPROTO_ICMP) &&
24296 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
24297 +               goto override;
24298 +override:
24299         if (sock->type == SOCK_RAW && !kern &&
24300             !ns_capable(net->user_ns, CAP_NET_RAW))
24301                 goto out_rcu_unlock;
24302 @@ -460,6 +465,7 @@ int inet_bind(struct socket *sock, struc
24303         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
24304         struct sock *sk = sock->sk;
24305         struct inet_sock *inet = inet_sk(sk);
24306 +       struct nx_v4_sock_addr nsa;
24307         struct net *net = sock_net(sk);
24308         unsigned short snum;
24309         int chk_addr_ret;
24310 @@ -484,7 +490,11 @@ int inet_bind(struct socket *sock, struc
24311                         goto out;
24312         }
24313  
24314 -       chk_addr_ret = inet_addr_type(net, addr->sin_addr.s_addr);
24315 +       err = v4_map_sock_addr(inet, addr, &nsa);
24316 +       if (err)
24317 +               goto out;
24318 +
24319 +       chk_addr_ret = inet_addr_type(net, nsa.saddr);
24320  
24321         /* Not specified by any standard per-se, however it breaks too
24322          * many applications when removed.  It is unfortunate since
24323 @@ -496,7 +506,7 @@ int inet_bind(struct socket *sock, struc
24324         err = -EADDRNOTAVAIL;
24325         if (!sysctl_ip_nonlocal_bind &&
24326             !(inet->freebind || inet->transparent) &&
24327 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
24328 +           nsa.saddr != htonl(INADDR_ANY) &&
24329             chk_addr_ret != RTN_LOCAL &&
24330             chk_addr_ret != RTN_MULTICAST &&
24331             chk_addr_ret != RTN_BROADCAST)
24332 @@ -522,7 +532,7 @@ int inet_bind(struct socket *sock, struc
24333         if (sk->sk_state != TCP_CLOSE || inet->inet_num)
24334                 goto out_release_sock;
24335  
24336 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24337 +       v4_set_sock_addr(inet, &nsa);
24338         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24339                 inet->inet_saddr = 0;  /* Use device */
24340  
24341 @@ -741,11 +751,13 @@ int inet_getname(struct socket *sock, st
24342                      peer == 1))
24343                         return -ENOTCONN;
24344                 sin->sin_port = inet->inet_dport;
24345 -               sin->sin_addr.s_addr = inet->inet_daddr;
24346 +               sin->sin_addr.s_addr =
24347 +                       nx_map_sock_lback(sk->sk_nx_info, inet->inet_daddr);
24348         } else {
24349                 __be32 addr = inet->inet_rcv_saddr;
24350                 if (!addr)
24351                         addr = inet->inet_saddr;
24352 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
24353                 sin->sin_port = inet->inet_sport;
24354                 sin->sin_addr.s_addr = addr;
24355         }
24356 diff -NurpP --minimal linux-3.9.4/net/ipv4/arp.c linux-3.9.4-vs2.3.6.1/net/ipv4/arp.c
24357 --- linux-3.9.4/net/ipv4/arp.c  2013-05-31 13:45:32.000000000 +0000
24358 +++ linux-3.9.4-vs2.3.6.1/net/ipv4/arp.c        2013-05-31 17:17:54.000000000 +0000
24359 @@ -1317,6 +1317,7 @@ static void arp_format_neigh_entry(struc
24360         struct net_device *dev = n->dev;
24361         int hatype = dev->type;
24362  
24363 +       /* FIXME: check for network context */
24364         read_lock(&n->lock);
24365         /* Convert hardware address to XX:XX:XX:XX ... form. */
24366  #if IS_ENABLED(CONFIG_AX25)
24367 @@ -1348,6 +1349,7 @@ static void arp_format_pneigh_entry(stru
24368         int hatype = dev ? dev->type : 0;
24369         char tbuf[16];
24370  
24371 +       /* FIXME: check for network context */
24372         sprintf(tbuf, "%pI4", n->key);
24373         seq_printf(seq, "%-16s 0x%-10x0x%-10x%s     *        %s\n",
24374                    tbuf, hatype, ATF_PUBL | ATF_PERM, "00:00:00:00:00:00",
24375 diff -NurpP --minimal linux-3.9.4/net/ipv4/devinet.c linux-3.9.4-vs2.3.6.1/net/ipv4/devinet.c
24376 --- linux-3.9.4/net/ipv4/devinet.c      2013-05-31 13:45:32.000000000 +0000
24377 +++ linux-3.9.4-vs2.3.6.1/net/ipv4/devinet.c    2013-05-31 17:17:54.000000000 +0000
24378 @@ -522,6 +522,7 @@ struct in_device *inetdev_by_index(struc
24379  }
24380  EXPORT_SYMBOL(inetdev_by_index);
24381  
24382 +
24383  /* Called only from RTNL semaphored context. No locks. */
24384  
24385  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
24386 @@ -940,6 +941,8 @@ int devinet_ioctl(struct net *net, unsig
24387  
24388         in_dev = __in_dev_get_rtnl(dev);
24389         if (in_dev) {
24390 +               struct nx_info *nxi = current_nx_info();
24391 +
24392                 if (tryaddrmatch) {
24393                         /* Matthias Andree */
24394                         /* compare label and address (4.4BSD style) */
24395 @@ -948,6 +951,8 @@ int devinet_ioctl(struct net *net, unsig
24396                            This is checked above. */
24397                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24398                              ifap = &ifa->ifa_next) {
24399 +                               if (!nx_v4_ifa_visible(nxi, ifa))
24400 +                                       continue;
24401                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
24402                                     sin_orig.sin_addr.s_addr ==
24403                                                         ifa->ifa_local) {
24404 @@ -960,9 +965,12 @@ int devinet_ioctl(struct net *net, unsig
24405                    comparing just the label */
24406                 if (!ifa) {
24407                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24408 -                            ifap = &ifa->ifa_next)
24409 +                            ifap = &ifa->ifa_next) {
24410 +                               if (!nx_v4_ifa_visible(nxi, ifa))
24411 +                                       continue;
24412                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
24413                                         break;
24414 +                       }
24415                 }
24416         }
24417  
24418 @@ -1116,6 +1124,8 @@ static int inet_gifconf(struct net_devic
24419                 goto out;
24420  
24421         for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
24422 +               if (!nx_v4_ifa_visible(current_nx_info(), ifa))
24423 +                       continue;
24424                 if (!buf) {
24425                         done += sizeof(ifr);
24426                         continue;
24427 @@ -1519,6 +1529,7 @@ static int inet_dump_ifaddr(struct sk_bu
24428         struct net_device *dev;
24429         struct in_device *in_dev;
24430         struct in_ifaddr *ifa;
24431 +       struct sock *sk = skb->sk;
24432         struct hlist_head *head;
24433  
24434         s_h = cb->args[0];
24435 @@ -1540,6 +1551,8 @@ static int inet_dump_ifaddr(struct sk_bu
24436  
24437                         for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
24438                              ifa = ifa->ifa_next, ip_idx++) {
24439 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
24440 +                               continue;
24441                                 if (ip_idx < s_ip_idx)
24442                                         continue;
24443                                 if (inet_fill_ifaddr(skb, ifa,
24444 diff -NurpP --minimal linux-3.9.4/net/ipv4/fib_trie.c linux-3.9.4-vs2.3.6.1/net/ipv4/fib_trie.c
24445 --- linux-3.9.4/net/ipv4/fib_trie.c     2013-05-31 13:45:32.000000000 +0000
24446 +++ linux-3.9.4-vs2.3.6.1/net/ipv4/fib_trie.c   2013-05-31 17:17:54.000000000 +0000
24447 @@ -2548,6 +2548,7 @@ static int fib_route_seq_show(struct seq
24448                             || fa->fa_type == RTN_MULTICAST)
24449                                 continue;
24450  
24451 +                       /* FIXME: check for network context? */
24452                         if (fi)
24453                                 seq_printf(seq,
24454                                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t"
24455 diff -NurpP --minimal linux-3.9.4/net/ipv4/inet_connection_sock.c linux-3.9.4-vs2.3.6.1/net/ipv4/inet_connection_sock.c
24456 --- linux-3.9.4/net/ipv4/inet_connection_sock.c 2013-05-31 13:45:32.000000000 +0000
24457 +++ linux-3.9.4-vs2.3.6.1/net/ipv4/inet_connection_sock.c       2013-05-31 18:29:56.000000000 +0000
24458 @@ -53,6 +53,37 @@ void inet_get_local_port_range(int *low,
24459  }
24460  EXPORT_SYMBOL(inet_get_local_port_range);
24461  
24462 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24463 +{
24464 +       __be32  sk1_rcv_saddr = sk_rcv_saddr(sk1),
24465 +               sk2_rcv_saddr = sk_rcv_saddr(sk2);
24466 +
24467 +       if (inet_v6_ipv6only(sk2))
24468 +               return 0;
24469 +
24470 +       if (sk1_rcv_saddr &&
24471 +           sk2_rcv_saddr &&
24472 +           sk1_rcv_saddr == sk2_rcv_saddr)
24473 +               return 1;
24474 +
24475 +       if (sk1_rcv_saddr &&
24476 +           !sk2_rcv_saddr &&
24477 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
24478 +               return 1;
24479 +
24480 +       if (sk2_rcv_saddr &&
24481 +           !sk1_rcv_saddr &&
24482 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
24483 +               return 1;
24484 +
24485 +       if (!sk1_rcv_saddr &&
24486 +           !sk2_rcv_saddr &&
24487 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
24488 +               return 1;
24489 +
24490 +       return 0;
24491 +}
24492 +
24493  int inet_csk_bind_conflict(const struct sock *sk,
24494                            const struct inet_bind_bucket *tb, bool relax)
24495  {
24496 @@ -79,17 +110,12 @@ int inet_csk_bind_conflict(const struct
24497                             (!reuseport || !sk2->sk_reuseport ||
24498                             (sk2->sk_state != TCP_TIME_WAIT &&
24499                              !uid_eq(uid, sock_i_uid(sk2))))) {
24500 -                               const __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
24501 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr(sk) ||
24502 -                                   sk2_rcv_saddr == sk_rcv_saddr(sk))
24503 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
24504                                         break;
24505                         }
24506                         if (!relax && reuse && sk2->sk_reuse &&
24507                             sk2->sk_state != TCP_LISTEN) {
24508 -                               const __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
24509 -
24510 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr(sk) ||
24511 -                                   sk2_rcv_saddr == sk_rcv_saddr(sk))
24512 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
24513                                         break;
24514                         }
24515                 }
24516 diff -NurpP --minimal linux-3.9.4/net/ipv4/inet_diag.c linux-3.9.4-vs2.3.6.1/net/ipv4/inet_diag.c
24517 --- linux-3.9.4/net/ipv4/inet_diag.c    2013-02-19 13:58:58.000000000 +0000
24518 +++ linux-3.9.4-vs2.3.6.1/net/ipv4/inet_diag.c  2013-05-31 17:17:54.000000000 +0000
24519 @@ -31,6 +31,8 @@
24520  
24521  #include <linux/inet.h>
24522  #include <linux/stddef.h>
24523 +#include <linux/vs_network.h>
24524 +#include <linux/vs_inet.h>
24525  
24526  #include <linux/inet_diag.h>
24527  #include <linux/sock_diag.h>
24528 @@ -106,8 +108,10 @@ int inet_sk_diag_fill(struct sock *sk, s
24529  
24530         r->id.idiag_sport = inet->inet_sport;
24531         r->id.idiag_dport = inet->inet_dport;
24532 -       r->id.idiag_src[0] = inet->inet_rcv_saddr;
24533 -       r->id.idiag_dst[0] = inet->inet_daddr;
24534 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info,
24535 +               inet->inet_rcv_saddr);
24536 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info,
24537 +               inet->inet_daddr);
24538  
24539         if (nla_put_u8(skb, INET_DIAG_SHUTDOWN, sk->sk_shutdown))
24540                 goto errout;
24541 @@ -242,8 +246,8 @@ static int inet_twsk_diag_fill(struct in
24542         sock_diag_save_cookie(tw, r->id.idiag_cookie);
24543         r->id.idiag_sport     = tw->tw_sport;
24544         r->id.idiag_dport     = tw->tw_dport;
24545 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
24546 -       r->id.idiag_dst[0]    = tw->tw_daddr;
24547 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
24548 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
24549         r->idiag_state        = tw->tw_substate;
24550         r->idiag_timer        = 3;
24551         r->idiag_expires      = DIV_ROUND_UP(tmo * 1000, HZ);
24552 @@ -287,12 +291,14 @@ int inet_diag_dump_one_icsk(struct inet_
24553  
24554         err = -EINVAL;
24555         if (req->sdiag_family == AF_INET) {
24556 +               /* TODO: lback */
24557                 sk = inet_lookup(net, hashinfo, req->id.idiag_dst[0],
24558                                  req->id.idiag_dport, req->id.idiag_src[0],
24559                                  req->id.idiag_sport, req->id.idiag_if);
24560         }
24561  #if IS_ENABLED(CONFIG_IPV6)
24562         else if (req->sdiag_family == AF_INET6) {
24563 +               /* TODO: lback */
24564                 sk = inet6_lookup(net, hashinfo,
24565                                   (struct in6_addr *)req->id.idiag_dst,
24566                                   req->id.idiag_dport,
24567 @@ -494,6 +500,7 @@ int inet_diag_bc_sk(const struct nlattr
24568         } else
24569  #endif
24570         {
24571 +                       /* TODO: lback */
24572                 entry.saddr = &inet->inet_rcv_saddr;
24573                 entry.daddr = &inet->inet_daddr;
24574         }
24575 @@ -652,6 +659,7 @@ static int inet_twsk_diag_dump(struct in
24576                 } else
24577  #endif
24578                 {
24579 +                       /* TODO: lback */
24580                         entry.saddr = &tw->tw_rcv_saddr;
24581                         entry.daddr = &tw->tw_daddr;
24582                 }
24583 @@ -730,8 +738,8 @@ static int inet_diag_fill_req(struct sk_
24584  
24585         r->id.idiag_sport = inet->inet_sport;
24586         r->id.idiag_dport = ireq->rmt_port;
24587 -       r->id.idiag_src[0] = ireq->loc_addr;
24588 -       r->id.idiag_dst[0] = ireq->rmt_addr;
24589 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
24590 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
24591         r->idiag_expires = jiffies_to_msecs(tmo);
24592         r->idiag_rqueue = 0;
24593         r->idiag_wqueue = 0;
24594 @@ -794,6 +802,7 @@ static int inet_diag_dump_reqs(struct sk
24595                             r->id.idiag_dport)
24596                                 continue;
24597  
24598 +                       /* TODO: lback */
24599                         if (bc) {
24600                                 inet_diag_req_addrs(sk, req, &entry);
24601                                 entry.dport = ntohs(ireq->rmt_port);
24602 @@ -850,6 +859,8 @@ void inet_diag_dump_icsk(struct inet_has
24603                                 if (!net_eq(sock_net(sk), net))
24604                                         continue;
24605  
24606 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24607 +                                       continue;
24608                                 if (num < s_num) {
24609                                         num++;
24610                                         continue;
24611 @@ -922,6 +933,8 @@ skip_listen_ht:
24612  
24613                         if (!net_eq(sock_net(sk), net))
24614                                 continue;
24615 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24616 +                               continue;
24617                         if (num < s_num)
24618                                 goto next_normal;
24619                         if (!(r->idiag_states & (1 << sk->sk_state)))
24620 @@ -950,7 +963,8 @@ next_normal:
24621                                     &head->twchain) {
24622                                 if (!net_eq(twsk_net(tw), net))
24623                                         continue;
24624 -
24625 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
24626 +                                       continue;
24627                                 if (num < s_num)
24628                                         goto next_dying;
24629                                 if (r->sdiag_family != AF_UNSPEC &&
24630 diff -NurpP --minimal linux-3.9.4/net/ipv4/inet_hashtables.c linux-3.9.4-vs2.3.6.1/net/ipv4/inet_hashtables.c
24631 --- linux-3.9.4/net/ipv4/inet_hashtables.c      2013-05-31 13:45:32.000000000 +0000
24632 +++ linux-3.9.4-vs2.3.6.1/net/ipv4/inet_hashtables.c    2013-05-31 18:20:50.000000000 +0000
24633 @@ -22,6 +22,7 @@
24634  #include <net/inet_connection_sock.h>
24635  #include <net/inet_hashtables.h>
24636  #include <net/secure_seq.h>
24637 +#include <net/route.h>
24638  #include <net/ip.h>
24639  
24640  /*
24641 @@ -156,6 +157,11 @@ static inline int compute_score(struct s
24642                         if (rcv_saddr != daddr)
24643                                 return -1;
24644                         score += 4;
24645 +               } else {
24646 +                       /* block non nx_info ips */
24647 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
24648 +                               daddr, NXA_MASK_BIND))
24649 +                               return -1;
24650                 }
24651                 if (sk->sk_bound_dev_if) {
24652                         if (sk->sk_bound_dev_if != dif)
24653 @@ -173,7 +179,6 @@ static inline int compute_score(struct s
24654   * wildcarded during the search since they can never be otherwise.
24655   */
24656  
24657 -
24658  struct sock *__inet_lookup_listener(struct net *net,
24659                                     struct inet_hashinfo *hashinfo,
24660                                     const __be32 saddr, __be16 sport,
24661 @@ -209,6 +214,7 @@ begin:
24662                         phash = next_pseudo_random32(phash);
24663                 }
24664         }
24665 +
24666         /*
24667          * if the nulls value we got at the end of this lookup is
24668          * not the expected one, we must restart lookup.
24669 diff -NurpP --minimal linux-3.9.4/net/ipv4/netfilter.c linux-3.9.4-vs2.3.6.1/net/ipv4/netfilter.c
24670 --- linux-3.9.4/net/ipv4/netfilter.c    2012-12-11 03:30:57.000000000 +0000
24671 +++ linux-3.9.4-vs2.3.6.1/net/ipv4/netfilter.c  2013-05-31 17:17:54.000000000 +0000
24672 @@ -6,7 +6,7 @@
24673  #include <linux/skbuff.h>
24674  #include <linux/gfp.h>
24675  #include <linux/export.h>
24676 -#include <net/route.h>
24677 +// #include <net/route.h>
24678  #include <net/xfrm.h>
24679  #include <net/ip.h>
24680  #include <net/netfilter/nf_queue.h>
24681 diff -NurpP --minimal linux-3.9.4/net/ipv4/raw.c linux-3.9.4-vs2.3.6.1/net/ipv4/raw.c
24682 --- linux-3.9.4/net/ipv4/raw.c  2013-05-31 13:45:32.000000000 +0000
24683 +++ linux-3.9.4-vs2.3.6.1/net/ipv4/raw.c        2013-05-31 18:19:38.000000000 +0000
24684 @@ -116,7 +116,7 @@ static struct sock *__raw_v4_lookup(stru
24685  
24686                 if (net_eq(sock_net(sk), net) && inet->inet_num == num  &&
24687                     !(inet->inet_daddr && inet->inet_daddr != raddr)    &&
24688 -                   !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
24689 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
24690                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
24691                         goto found; /* gotcha */
24692         }
24693 @@ -395,6 +395,12 @@ static int raw_send_hdrinc(struct sock *
24694                 icmp_out_count(net, ((struct icmphdr *)
24695                         skb_transport_header(skb))->type);
24696  
24697 +       err = -EPERM;
24698 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
24699 +               sk->sk_nx_info &&
24700 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
24701 +               goto error_free;
24702 +
24703         err = NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT, skb, NULL,
24704                       rt->dst.dev, dst_output);
24705         if (err > 0)
24706 @@ -580,6 +586,16 @@ static int raw_sendmsg(struct kiocb *ioc
24707                         goto done;
24708         }
24709  
24710 +       if (sk->sk_nx_info) {
24711 +               rt = ip_v4_find_src(sock_net(sk), sk->sk_nx_info, &fl4);
24712 +               if (IS_ERR(rt)) {
24713 +                       err = PTR_ERR(rt);
24714 +                       rt = NULL;
24715 +                       goto done;
24716 +               }
24717 +               ip_rt_put(rt);
24718 +       }
24719 +
24720         security_sk_classify_flow(sk, flowi4_to_flowi(&fl4));
24721         rt = ip_route_output_flow(sock_net(sk), &fl4, sk);
24722         if (IS_ERR(rt)) {
24723 @@ -656,17 +672,19 @@ static int raw_bind(struct sock *sk, str
24724  {
24725         struct inet_sock *inet = inet_sk(sk);
24726         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
24727 +       struct nx_v4_sock_addr nsa = { 0 };
24728         int ret = -EINVAL;
24729         int chk_addr_ret;
24730  
24731         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
24732                 goto out;
24733 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
24734 +       v4_map_sock_addr(inet, addr, &nsa);
24735 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
24736         ret = -EADDRNOTAVAIL;
24737 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
24738 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
24739             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
24740                 goto out;
24741 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24742 +       v4_set_sock_addr(inet, &nsa);
24743         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24744                 inet->inet_saddr = 0;  /* Use device */
24745         sk_dst_reset(sk);
24746 @@ -718,7 +736,8 @@ static int raw_recvmsg(struct kiocb *ioc
24747         /* Copy the address. */
24748         if (sin) {
24749                 sin->sin_family = AF_INET;
24750 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
24751 +               sin->sin_addr.s_addr =
24752 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
24753                 sin->sin_port = 0;
24754                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
24755         }
24756 @@ -913,7 +932,8 @@ static struct sock *raw_get_first(struct
24757         for (state->bucket = 0; state->bucket < RAW_HTABLE_SIZE;
24758                         ++state->bucket) {
24759                 sk_for_each(sk, &state->h->ht[state->bucket])
24760 -                       if (sock_net(sk) == seq_file_net(seq))
24761 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
24762 +                           nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24763                                 goto found;
24764         }
24765         sk = NULL;
24766 @@ -929,7 +949,8 @@ static struct sock *raw_get_next(struct
24767                 sk = sk_next(sk);
24768  try_again:
24769                 ;
24770 -       } while (sk && sock_net(sk) != seq_file_net(seq));
24771 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
24772 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
24773  
24774         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
24775                 sk = sk_head(&state->h->ht[state->bucket]);
24776 diff -NurpP --minimal linux-3.9.4/net/ipv4/route.c linux-3.9.4-vs2.3.6.1/net/ipv4/route.c
24777 --- linux-3.9.4/net/ipv4/route.c        2013-05-31 13:45:32.000000000 +0000
24778 +++ linux-3.9.4-vs2.3.6.1/net/ipv4/route.c      2013-05-31 17:17:54.000000000 +0000
24779 @@ -1998,7 +1998,7 @@ struct rtable *__ip_route_output_key(str
24780  
24781  
24782         if (fl4->flowi4_oif) {
24783 -               dev_out = dev_get_by_index_rcu(net, fl4->flowi4_oif);
24784 +               dev_out = dev_get_by_index_real_rcu(net, fl4->flowi4_oif);
24785                 rth = ERR_PTR(-ENODEV);
24786                 if (dev_out == NULL)
24787                         goto out;
24788 diff -NurpP --minimal linux-3.9.4/net/ipv4/tcp.c linux-3.9.4-vs2.3.6.1/net/ipv4/tcp.c
24789 --- linux-3.9.4/net/ipv4/tcp.c  2013-05-31 13:45:32.000000000 +0000
24790 +++ linux-3.9.4-vs2.3.6.1/net/ipv4/tcp.c        2013-05-31 17:17:54.000000000 +0000
24791 @@ -268,6 +268,7 @@
24792  #include <linux/crypto.h>
24793  #include <linux/time.h>
24794  #include <linux/slab.h>
24795 +#include <linux/in.h>
24796  
24797  #include <net/icmp.h>
24798  #include <net/inet_common.h>
24799 diff -NurpP --minimal linux-3.9.4/net/ipv4/tcp_ipv4.c linux-3.9.4-vs2.3.6.1/net/ipv4/tcp_ipv4.c
24800 --- linux-3.9.4/net/ipv4/tcp_ipv4.c     2013-05-31 13:45:32.000000000 +0000
24801 +++ linux-3.9.4-vs2.3.6.1/net/ipv4/tcp_ipv4.c   2013-05-31 17:17:54.000000000 +0000
24802 @@ -2260,6 +2260,12 @@ static void *listening_get_next(struct s
24803                 req = req->dl_next;
24804                 while (1) {
24805                         while (req) {
24806 +                               vxdprintk(VXD_CBIT(net, 6),
24807 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
24808 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
24809 +                               if (req->sk &&
24810 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
24811 +                                       continue;
24812                                 if (req->rsk_ops->family == st->family) {
24813                                         cur = req;
24814                                         goto out;
24815 @@ -2284,6 +2290,10 @@ get_req:
24816         }
24817  get_sk:
24818         sk_nulls_for_each_from(sk, node) {
24819 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
24820 +                       sk, sk->sk_nid, nx_current_nid());
24821 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24822 +                       continue;
24823                 if (!net_eq(sock_net(sk), net))
24824                         continue;
24825                 if (sk->sk_family == st->family) {
24826 @@ -2360,6 +2370,11 @@ static void *established_get_first(struc
24827  
24828                 spin_lock_bh(lock);
24829                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
24830 +                       vxdprintk(VXD_CBIT(net, 6),
24831 +                               "sk,egf: %p [#%d] (from %d)",
24832 +                               sk, sk->sk_nid, nx_current_nid());
24833 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24834 +                               continue;
24835                         if (sk->sk_family != st->family ||
24836                             !net_eq(sock_net(sk), net)) {
24837                                 continue;
24838 @@ -2370,6 +2385,11 @@ static void *established_get_first(struc
24839                 st->state = TCP_SEQ_STATE_TIME_WAIT;
24840                 inet_twsk_for_each(tw, node,
24841                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
24842 +                       vxdprintk(VXD_CBIT(net, 6),
24843 +                               "tw: %p [#%d] (from %d)",
24844 +                               tw, tw->tw_nid, nx_current_nid());
24845 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
24846 +                               continue;
24847                         if (tw->tw_family != st->family ||
24848                             !net_eq(twsk_net(tw), net)) {
24849                                 continue;
24850 @@ -2399,7 +2419,9 @@ static void *established_get_next(struct
24851                 tw = cur;
24852                 tw = tw_next(tw);
24853  get_tw:
24854 -               while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
24855 +               while (tw && (tw->tw_family != st->family ||
24856 +                       !net_eq(twsk_net(tw), net) ||
24857 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
24858                         tw = tw_next(tw);
24859                 }
24860                 if (tw) {
24861 @@ -2423,6 +2445,11 @@ get_tw:
24862                 sk = sk_nulls_next(sk);
24863  
24864         sk_nulls_for_each_from(sk, node) {
24865 +               vxdprintk(VXD_CBIT(net, 6),
24866 +                       "sk,egn: %p [#%d] (from %d)",
24867 +                       sk, sk->sk_nid, nx_current_nid());
24868 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24869 +                       continue;
24870                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
24871                         goto found;
24872         }
24873 @@ -2628,9 +2655,9 @@ static void get_openreq4(const struct so
24874         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
24875                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %pK%n",
24876                 i,
24877 -               ireq->loc_addr,
24878 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
24879                 ntohs(inet_sk(sk)->inet_sport),
24880 -               ireq->rmt_addr,
24881 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
24882                 ntohs(ireq->rmt_port),
24883                 TCP_SYN_RECV,
24884                 0, 0, /* could print option size, but that is af dependent. */
24885 @@ -2653,8 +2680,8 @@ static void get_tcp4_sock(struct sock *s
24886         const struct inet_connection_sock *icsk = inet_csk(sk);
24887         const struct inet_sock *inet = inet_sk(sk);
24888         struct fastopen_queue *fastopenq = icsk->icsk_accept_queue.fastopenq;
24889 -       __be32 dest = inet->inet_daddr;
24890 -       __be32 src = inet->inet_rcv_saddr;
24891 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
24892 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
24893         __u16 destp = ntohs(inet->inet_dport);
24894         __u16 srcp = ntohs(inet->inet_sport);
24895         int rx_queue;
24896 @@ -2710,8 +2737,8 @@ static void get_timewait4_sock(const str
24897         __u16 destp, srcp;
24898         long delta = tw->tw_ttd - jiffies;
24899  
24900 -       dest  = tw->tw_daddr;
24901 -       src   = tw->tw_rcv_saddr;
24902 +       dest  = nx_map_sock_lback(current_nx_info(), tw->tw_daddr);
24903 +       src   = nx_map_sock_lback(current_nx_info(), tw->tw_rcv_saddr);
24904         destp = ntohs(tw->tw_dport);
24905         srcp  = ntohs(tw->tw_sport);
24906  
24907 diff -NurpP --minimal linux-3.9.4/net/ipv4/tcp_minisocks.c linux-3.9.4-vs2.3.6.1/net/ipv4/tcp_minisocks.c
24908 --- linux-3.9.4/net/ipv4/tcp_minisocks.c        2013-05-31 14:22:27.000000000 +0000
24909 +++ linux-3.9.4-vs2.3.6.1/net/ipv4/tcp_minisocks.c      2013-05-31 17:17:54.000000000 +0000
24910 @@ -23,6 +23,9 @@
24911  #include <linux/slab.h>
24912  #include <linux/sysctl.h>
24913  #include <linux/workqueue.h>
24914 +#include <linux/vs_limit.h>
24915 +#include <linux/vs_socket.h>
24916 +#include <linux/vs_context.h>
24917  #include <net/tcp.h>
24918  #include <net/inet_common.h>
24919  #include <net/xfrm.h>
24920 @@ -291,6 +294,11 @@ void tcp_time_wait(struct sock *sk, int
24921                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
24922                 tcptw->tw_ts_offset     = tp->tsoffset;
24923  
24924 +               tw->tw_xid              = sk->sk_xid;
24925 +               tw->tw_vx_info          = NULL;
24926 +               tw->tw_nid              = sk->sk_nid;
24927 +               tw->tw_nx_info          = NULL;
24928 +
24929  #if IS_ENABLED(CONFIG_IPV6)
24930                 if (tw->tw_family == PF_INET6) {
24931                         struct ipv6_pinfo *np = inet6_sk(sk);
24932 diff -NurpP --minimal linux-3.9.4/net/ipv4/udp.c linux-3.9.4-vs2.3.6.1/net/ipv4/udp.c
24933 --- linux-3.9.4/net/ipv4/udp.c  2013-05-31 13:45:32.000000000 +0000
24934 +++ linux-3.9.4-vs2.3.6.1/net/ipv4/udp.c        2013-05-31 18:26:00.000000000 +0000
24935 @@ -306,14 +306,7 @@ fail:
24936  }
24937  EXPORT_SYMBOL(udp_lib_get_port);
24938  
24939 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24940 -{
24941 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
24942 -
24943 -       return  (!ipv6_only_sock(sk2)  &&
24944 -                (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr ||
24945 -                  inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
24946 -}
24947 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
24948  
24949  static unsigned int udp4_portaddr_hash(struct net *net, __be32 saddr,
24950                                        unsigned int port)
24951 @@ -348,6 +341,11 @@ static inline int compute_score(struct s
24952                         if (inet->inet_rcv_saddr != daddr)
24953                                 return -1;
24954                         score += 4;
24955 +               } else {
24956 +                       /* block non nx_info ips */
24957 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
24958 +                               daddr, NXA_MASK_BIND))
24959 +                               return -1;
24960                 }
24961                 if (inet->inet_daddr) {
24962                         if (inet->inet_daddr != saddr)
24963 @@ -458,6 +456,7 @@ begin:
24964         return result;
24965  }
24966  
24967 +
24968  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
24969   * harder than this. -DaveM
24970   */
24971 @@ -504,6 +503,11 @@ begin:
24972         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
24973                 score = compute_score(sk, net, saddr, hnum, sport,
24974                                       daddr, dport, dif);
24975 +               /* FIXME: disabled?
24976 +               if (score == 9) {
24977 +                       result = sk;
24978 +                       break;
24979 +               } else */
24980                 if (score > badness) {
24981                         result = sk;
24982                         badness = score;
24983 @@ -528,6 +532,7 @@ begin:
24984         if (get_nulls_value(node) != slot)
24985                 goto begin;
24986  
24987 +
24988         if (result) {
24989                 if (unlikely(!atomic_inc_not_zero_hint(&result->sk_refcnt, 2)))
24990                         result = NULL;
24991 @@ -537,6 +542,7 @@ begin:
24992                         goto begin;
24993                 }
24994         }
24995 +
24996         rcu_read_unlock();
24997         return result;
24998  }
24999 @@ -580,8 +586,7 @@ static inline struct sock *udp_v4_mcast_
25000                     udp_sk(s)->udp_port_hash != hnum ||
25001                     (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
25002                     (inet->inet_dport != rmt_port && inet->inet_dport) ||
25003 -                   (inet->inet_rcv_saddr &&
25004 -                    inet->inet_rcv_saddr != loc_addr) ||
25005 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
25006                     ipv6_only_sock(s) ||
25007                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
25008                         continue;
25009 @@ -964,6 +969,16 @@ int udp_sendmsg(struct kiocb *iocb, stru
25010                                    inet_sk_flowi_flags(sk)|FLOWI_FLAG_CAN_SLEEP,
25011                                    faddr, saddr, dport, inet->inet_sport);
25012  
25013 +               if (sk->sk_nx_info) {
25014 +                       rt = ip_v4_find_src(net, sk->sk_nx_info, fl4);
25015 +                       if (IS_ERR(rt)) {
25016 +                               err = PTR_ERR(rt);
25017 +                               rt = NULL;
25018 +                               goto out;
25019 +                       }
25020 +                       ip_rt_put(rt);
25021 +               }
25022 +
25023                 security_sk_classify_flow(sk, flowi4_to_flowi(fl4));
25024                 rt = ip_route_output_flow(net, fl4, sk);
25025                 if (IS_ERR(rt)) {
25026 @@ -1269,7 +1284,8 @@ try_again:
25027         if (sin) {
25028                 sin->sin_family = AF_INET;
25029                 sin->sin_port = udp_hdr(skb)->source;
25030 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
25031 +               sin->sin_addr.s_addr = nx_map_sock_lback(
25032 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
25033                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
25034         }
25035         if (inet->cmsg_flags)
25036 @@ -2025,6 +2041,8 @@ static struct sock *udp_get_first(struct
25037                 sk_nulls_for_each(sk, node, &hslot->head) {
25038                         if (!net_eq(sock_net(sk), net))
25039                                 continue;
25040 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25041 +                               continue;
25042                         if (sk->sk_family == state->family)
25043                                 goto found;
25044                 }
25045 @@ -2042,7 +2060,9 @@ static struct sock *udp_get_next(struct
25046  
25047         do {
25048                 sk = sk_nulls_next(sk);
25049 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
25050 +       } while (sk && (!net_eq(sock_net(sk), net) ||
25051 +               sk->sk_family != state->family ||
25052 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
25053  
25054         if (!sk) {
25055                 if (state->bucket <= state->udp_table->mask)
25056 @@ -2138,8 +2158,8 @@ static void udp4_format_sock(struct sock
25057                 int bucket, int *len)
25058  {
25059         struct inet_sock *inet = inet_sk(sp);
25060 -       __be32 dest = inet->inet_daddr;
25061 -       __be32 src  = inet->inet_rcv_saddr;
25062 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
25063 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
25064         __u16 destp       = ntohs(inet->inet_dport);
25065         __u16 srcp        = ntohs(inet->inet_sport);
25066  
25067 diff -NurpP --minimal linux-3.9.4/net/ipv6/Kconfig linux-3.9.4-vs2.3.6.1/net/ipv6/Kconfig
25068 --- linux-3.9.4/net/ipv6/Kconfig        2013-05-31 13:45:32.000000000 +0000
25069 +++ linux-3.9.4-vs2.3.6.1/net/ipv6/Kconfig      2013-05-31 17:17:54.000000000 +0000
25070 @@ -4,8 +4,8 @@
25071  
25072  #   IPv6 as module will cause a CRASH if you try to unload it
25073  menuconfig IPV6
25074 -       tristate "The IPv6 protocol"
25075 -       default m
25076 +       bool "The IPv6 protocol"
25077 +       default n
25078         ---help---
25079           This is complemental support for the IP version 6.
25080           You will still be able to do traditional IPv4 networking as well.
25081 diff -NurpP --minimal linux-3.9.4/net/ipv6/addrconf.c linux-3.9.4-vs2.3.6.1/net/ipv6/addrconf.c
25082 --- linux-3.9.4/net/ipv6/addrconf.c     2013-05-31 13:45:32.000000000 +0000
25083 +++ linux-3.9.4-vs2.3.6.1/net/ipv6/addrconf.c   2013-05-31 20:07:39.000000000 +0000
25084 @@ -93,6 +93,8 @@
25085  #include <linux/proc_fs.h>
25086  #include <linux/seq_file.h>
25087  #include <linux/export.h>
25088 +#include <linux/vs_network.h>
25089 +#include <linux/vs_inet6.h>
25090  
25091  /* Set to 3 to get tracing... */
25092  #define ACONF_DEBUG 2
25093 @@ -1250,7 +1252,7 @@ out:
25094  
25095  int ipv6_dev_get_saddr(struct net *net, const struct net_device *dst_dev,
25096                        const struct in6_addr *daddr, unsigned int prefs,
25097 -                      struct in6_addr *saddr)
25098 +                      struct in6_addr *saddr, struct nx_info *nxi)
25099  {
25100         struct ipv6_saddr_score scores[2],
25101                                 *score = &scores[0], *hiscore = &scores[1];
25102 @@ -1322,6 +1324,8 @@ int ipv6_dev_get_saddr(struct net *net,
25103                                                dev->name);
25104                                 continue;
25105                         }
25106 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
25107 +                               continue;
25108  
25109                         score->rule = -1;
25110                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
25111 @@ -3311,7 +3315,10 @@ static void if6_seq_stop(struct seq_file
25112  static int if6_seq_show(struct seq_file *seq, void *v)
25113  {
25114         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
25115 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25116 +
25117 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
25118 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
25119 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25120                    &ifp->addr,
25121                    ifp->idev->dev->ifindex,
25122                    ifp->prefix_len,
25123 @@ -3815,6 +3822,11 @@ static int in6_dump_addrs(struct inet6_d
25124         struct ifacaddr6 *ifaca;
25125         int err = 1;
25126         int ip_idx = *p_ip_idx;
25127 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25128 +
25129 +       /* disable ipv6 on non v6 guests */
25130 +       if (nxi && !nx_info_has_v6(nxi))
25131 +               return skb->len;
25132  
25133         read_lock_bh(&idev->lock);
25134         switch (type) {
25135 @@ -3825,6 +3837,8 @@ static int in6_dump_addrs(struct inet6_d
25136                 list_for_each_entry(ifa, &idev->addr_list, if_list) {
25137                         if (++ip_idx < s_ip_idx)
25138                                 continue;
25139 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
25140 +                                       continue;
25141                         err = inet6_fill_ifaddr(skb, ifa,
25142                                                 NETLINK_CB(cb->skb).portid,
25143                                                 cb->nlh->nlmsg_seq,
25144 @@ -3841,6 +3855,8 @@ static int in6_dump_addrs(struct inet6_d
25145                      ifmca = ifmca->next, ip_idx++) {
25146                         if (ip_idx < s_ip_idx)
25147                                 continue;
25148 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
25149 +                                       continue;
25150                         err = inet6_fill_ifmcaddr(skb, ifmca,
25151                                                   NETLINK_CB(cb->skb).portid,
25152                                                   cb->nlh->nlmsg_seq,
25153 @@ -3856,6 +3872,8 @@ static int in6_dump_addrs(struct inet6_d
25154                      ifaca = ifaca->aca_next, ip_idx++) {
25155                         if (ip_idx < s_ip_idx)
25156                                 continue;
25157 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
25158 +                                       continue;
25159                         err = inet6_fill_ifacaddr(skb, ifaca,
25160                                                   NETLINK_CB(cb->skb).portid,
25161                                                   cb->nlh->nlmsg_seq,
25162 @@ -3884,6 +3902,10 @@ static int inet6_dump_addr(struct sk_buf
25163         struct inet6_dev *idev;
25164         struct hlist_head *head;
25165  
25166 +       /* FIXME: maybe disable ipv6 on non v6 guests?
25167 +       if (skb->sk && skb->sk->sk_vx_info)
25168 +               return skb->len; */
25169 +
25170         s_h = cb->args[0];
25171         s_idx = idx = cb->args[1];
25172         s_ip_idx = ip_idx = cb->args[2];
25173 @@ -4238,6 +4260,7 @@ static int inet6_dump_ifinfo(struct sk_b
25174         struct net_device *dev;
25175         struct inet6_dev *idev;
25176         struct hlist_head *head;
25177 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25178  
25179         s_h = cb->args[0];
25180         s_idx = cb->args[1];
25181 @@ -4249,6 +4272,8 @@ static int inet6_dump_ifinfo(struct sk_b
25182                 hlist_for_each_entry_rcu(dev, head, index_hlist) {
25183                         if (idx < s_idx)
25184                                 goto cont;
25185 +                       if (!v6_dev_in_nx_info(dev, nxi))
25186 +                               goto cont;
25187                         idev = __in6_dev_get(dev);
25188                         if (!idev)
25189                                 goto cont;
25190 diff -NurpP --minimal linux-3.9.4/net/ipv6/af_inet6.c linux-3.9.4-vs2.3.6.1/net/ipv6/af_inet6.c
25191 --- linux-3.9.4/net/ipv6/af_inet6.c     2013-05-31 13:45:32.000000000 +0000
25192 +++ linux-3.9.4-vs2.3.6.1/net/ipv6/af_inet6.c   2013-05-31 20:04:41.000000000 +0000
25193 @@ -43,6 +43,8 @@
25194  #include <linux/netdevice.h>
25195  #include <linux/icmpv6.h>
25196  #include <linux/netfilter_ipv6.h>
25197 +#include <linux/vs_inet.h>
25198 +#include <linux/vs_inet6.h>
25199  
25200  #include <net/ip.h>
25201  #include <net/ipv6.h>
25202 @@ -160,10 +162,13 @@ lookup_protocol:
25203         }
25204  
25205         err = -EPERM;
25206 +       if ((protocol == IPPROTO_ICMPV6) &&
25207 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
25208 +               goto override;
25209         if (sock->type == SOCK_RAW && !kern &&
25210             !ns_capable(net->user_ns, CAP_NET_RAW))
25211                 goto out_rcu_unlock;
25212 -
25213 +override:
25214         sock->ops = answer->ops;
25215         answer_prot = answer->prot;
25216         answer_no_check = answer->no_check;
25217 @@ -263,6 +268,7 @@ int inet6_bind(struct socket *sock, stru
25218         struct inet_sock *inet = inet_sk(sk);
25219         struct ipv6_pinfo *np = inet6_sk(sk);
25220         struct net *net = sock_net(sk);
25221 +       struct nx_v6_sock_addr nsa;
25222         __be32 v4addr = 0;
25223         unsigned short snum;
25224         int addr_type = 0;
25225 @@ -278,6 +284,10 @@ int inet6_bind(struct socket *sock, stru
25226         if (addr->sin6_family != AF_INET6)
25227                 return -EAFNOSUPPORT;
25228  
25229 +       err = v6_map_sock_addr(inet, addr, &nsa);
25230 +       if (err)
25231 +               return err;
25232 +
25233         addr_type = ipv6_addr_type(&addr->sin6_addr);
25234         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
25235                 return -EINVAL;
25236 @@ -309,6 +319,7 @@ int inet6_bind(struct socket *sock, stru
25237                 /* Reproduce AF_INET checks to make the bindings consistent */
25238                 v4addr = addr->sin6_addr.s6_addr32[3];
25239                 chk_addr_ret = inet_addr_type(net, v4addr);
25240 +
25241                 if (!sysctl_ip_nonlocal_bind &&
25242                     !(inet->freebind || inet->transparent) &&
25243                     v4addr != htonl(INADDR_ANY) &&
25244 @@ -318,6 +329,10 @@ int inet6_bind(struct socket *sock, stru
25245                         err = -EADDRNOTAVAIL;
25246                         goto out;
25247                 }
25248 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
25249 +                       err = -EADDRNOTAVAIL;
25250 +                       goto out;
25251 +               }
25252         } else {
25253                 if (addr_type != IPV6_ADDR_ANY) {
25254                         struct net_device *dev = NULL;
25255 @@ -344,6 +359,11 @@ int inet6_bind(struct socket *sock, stru
25256                                 }
25257                         }
25258  
25259 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25260 +                               err = -EADDRNOTAVAIL;
25261 +                               goto out_unlock;
25262 +                       }
25263 +
25264                         /* ipv4 addr of the socket is invalid.  Only the
25265                          * unspecified and mapped address have a v4 equivalent.
25266                          */
25267 @@ -360,6 +380,9 @@ int inet6_bind(struct socket *sock, stru
25268                 }
25269         }
25270  
25271 +       /* what's that for? */
25272 +       v6_set_sock_addr(inet, &nsa);
25273 +
25274         inet->inet_rcv_saddr = v4addr;
25275         inet->inet_saddr = v4addr;
25276  
25277 @@ -461,9 +484,11 @@ int inet6_getname(struct socket *sock, s
25278                         return -ENOTCONN;
25279                 sin->sin6_port = inet->inet_dport;
25280                 sin->sin6_addr = np->daddr;
25281 +               /* FIXME: remap lback? */
25282                 if (np->sndflow)
25283                         sin->sin6_flowinfo = np->flow_label;
25284         } else {
25285 +               /* FIXME: remap lback? */
25286                 if (ipv6_addr_any(&np->rcv_saddr))
25287                         sin->sin6_addr = np->saddr;
25288                 else
25289 diff -NurpP --minimal linux-3.9.4/net/ipv6/datagram.c linux-3.9.4-vs2.3.6.1/net/ipv6/datagram.c
25290 --- linux-3.9.4/net/ipv6/datagram.c     2013-05-31 13:45:32.000000000 +0000
25291 +++ linux-3.9.4-vs2.3.6.1/net/ipv6/datagram.c   2013-05-31 17:17:54.000000000 +0000
25292 @@ -648,7 +648,7 @@ int ip6_datagram_send_ctl(struct net *ne
25293  
25294                         rcu_read_lock();
25295                         if (fl6->flowi6_oif) {
25296 -                               dev = dev_get_by_index_rcu(net, fl6->flowi6_oif);
25297 +                               dev = dev_get_by_index_real_rcu(net, fl6->flowi6_oif);
25298                                 if (!dev) {
25299                                         rcu_read_unlock();
25300                                         return -ENODEV;
25301 diff -NurpP --minimal linux-3.9.4/net/ipv6/fib6_rules.c linux-3.9.4-vs2.3.6.1/net/ipv6/fib6_rules.c
25302 --- linux-3.9.4/net/ipv6/fib6_rules.c   2013-02-19 13:58:58.000000000 +0000
25303 +++ linux-3.9.4-vs2.3.6.1/net/ipv6/fib6_rules.c 2013-05-31 17:17:54.000000000 +0000
25304 @@ -90,7 +90,7 @@ static int fib6_rule_action(struct fib_r
25305                                                ip6_dst_idev(&rt->dst)->dev,
25306                                                &flp6->daddr,
25307                                                rt6_flags2srcprefs(flags),
25308 -                                              &saddr))
25309 +                                              &saddr, NULL))
25310                                 goto again;
25311                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
25312                                                r->src.plen))
25313 diff -NurpP --minimal linux-3.9.4/net/ipv6/inet6_hashtables.c linux-3.9.4-vs2.3.6.1/net/ipv6/inet6_hashtables.c
25314 --- linux-3.9.4/net/ipv6/inet6_hashtables.c     2013-05-31 13:45:32.000000000 +0000
25315 +++ linux-3.9.4-vs2.3.6.1/net/ipv6/inet6_hashtables.c   2013-05-31 17:17:54.000000000 +0000
25316 @@ -16,6 +16,7 @@
25317  
25318  #include <linux/module.h>
25319  #include <linux/random.h>
25320 +#include <linux/vs_inet6.h>
25321  
25322  #include <net/inet_connection_sock.h>
25323  #include <net/inet_hashtables.h>
25324 @@ -83,7 +84,6 @@ struct sock *__inet6_lookup_established(
25325         unsigned int slot = hash & hashinfo->ehash_mask;
25326         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
25327  
25328 -
25329         rcu_read_lock();
25330  begin:
25331         sk_nulls_for_each_rcu(sk, node, &head->chain) {
25332 @@ -97,7 +97,7 @@ begin:
25333                                 sock_put(sk);
25334                                 goto begin;
25335                         }
25336 -               goto out;
25337 +                       goto out;
25338                 }
25339         }
25340         if (get_nulls_value(node) != slot)
25341 @@ -147,6 +147,9 @@ static inline int compute_score(struct s
25342                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25343                                 return -1;
25344                         score++;
25345 +               } else {
25346 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25347 +                               return -1;
25348                 }
25349                 if (sk->sk_bound_dev_if) {
25350                         if (sk->sk_bound_dev_if != dif)
25351 diff -NurpP --minimal linux-3.9.4/net/ipv6/ip6_output.c linux-3.9.4-vs2.3.6.1/net/ipv6/ip6_output.c
25352 --- linux-3.9.4/net/ipv6/ip6_output.c   2013-05-31 13:45:32.000000000 +0000
25353 +++ linux-3.9.4-vs2.3.6.1/net/ipv6/ip6_output.c 2013-05-31 17:17:54.000000000 +0000
25354 @@ -877,7 +877,8 @@ static int ip6_dst_lookup_tail(struct so
25355                 struct rt6_info *rt = (struct rt6_info *) *dst;
25356                 err = ip6_route_get_saddr(net, rt, &fl6->daddr,
25357                                           sk ? inet6_sk(sk)->srcprefs : 0,
25358 -                                         &fl6->saddr);
25359 +                                         &fl6->saddr,
25360 +                                         sk ? sk->sk_nx_info : NULL);
25361                 if (err)
25362                         goto out_err_release;
25363         }
25364 diff -NurpP --minimal linux-3.9.4/net/ipv6/ndisc.c linux-3.9.4-vs2.3.6.1/net/ipv6/ndisc.c
25365 --- linux-3.9.4/net/ipv6/ndisc.c        2013-05-31 13:45:32.000000000 +0000
25366 +++ linux-3.9.4-vs2.3.6.1/net/ipv6/ndisc.c      2013-05-31 17:17:54.000000000 +0000
25367 @@ -485,7 +485,7 @@ static void ndisc_send_na(struct net_dev
25368         } else {
25369                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
25370                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
25371 -                                      &tmpaddr))
25372 +                                      &tmpaddr, NULL))
25373                         return;
25374                 src_addr = &tmpaddr;
25375         }
25376 diff -NurpP --minimal linux-3.9.4/net/ipv6/netfilter/ip6t_MASQUERADE.c linux-3.9.4-vs2.3.6.1/net/ipv6/netfilter/ip6t_MASQUERADE.c
25377 --- linux-3.9.4/net/ipv6/netfilter/ip6t_MASQUERADE.c    2012-12-11 03:30:57.000000000 +0000
25378 +++ linux-3.9.4-vs2.3.6.1/net/ipv6/netfilter/ip6t_MASQUERADE.c  2013-05-31 17:17:54.000000000 +0000
25379 @@ -34,7 +34,7 @@ masquerade_tg6(struct sk_buff *skb, cons
25380                             ctinfo == IP_CT_RELATED_REPLY));
25381  
25382         if (ipv6_dev_get_saddr(dev_net(par->out), par->out,
25383 -                              &ipv6_hdr(skb)->daddr, 0, &src) < 0)
25384 +                              &ipv6_hdr(skb)->daddr, 0, &src, NULL) < 0)
25385                 return NF_DROP;
25386  
25387         nfct_nat(ct)->masq_index = par->out->ifindex;
25388 diff -NurpP --minimal linux-3.9.4/net/ipv6/raw.c linux-3.9.4-vs2.3.6.1/net/ipv6/raw.c
25389 --- linux-3.9.4/net/ipv6/raw.c  2013-05-31 13:45:32.000000000 +0000
25390 +++ linux-3.9.4-vs2.3.6.1/net/ipv6/raw.c        2013-05-31 17:17:54.000000000 +0000
25391 @@ -30,6 +30,7 @@
25392  #include <linux/icmpv6.h>
25393  #include <linux/netfilter.h>
25394  #include <linux/netfilter_ipv6.h>
25395 +#include <linux/vs_inet6.h>
25396  #include <linux/skbuff.h>
25397  #include <linux/compat.h>
25398  #include <asm/uaccess.h>
25399 @@ -283,6 +284,13 @@ static int rawv6_bind(struct sock *sk, s
25400                                 goto out_unlock;
25401                 }
25402  
25403 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25404 +                       err = -EADDRNOTAVAIL;
25405 +                       if (dev)
25406 +                               dev_put(dev);
25407 +                       goto out;
25408 +               }
25409 +
25410                 /* ipv4 addr of the socket is invalid.  Only the
25411                  * unspecified and mapped address have a v4 equivalent.
25412                  */
25413 diff -NurpP --minimal linux-3.9.4/net/ipv6/route.c linux-3.9.4-vs2.3.6.1/net/ipv6/route.c
25414 --- linux-3.9.4/net/ipv6/route.c        2013-05-31 13:45:32.000000000 +0000
25415 +++ linux-3.9.4-vs2.3.6.1/net/ipv6/route.c      2013-05-31 18:10:38.000000000 +0000
25416 @@ -58,6 +58,7 @@
25417  #include <net/netevent.h>
25418  #include <net/netlink.h>
25419  #include <net/nexthop.h>
25420 +#include <linux/vs_inet6.h>
25421  
25422  #include <asm/uaccess.h>
25423  
25424 @@ -2079,15 +2080,17 @@ int ip6_route_get_saddr(struct net *net,
25425                         struct rt6_info *rt,
25426                         const struct in6_addr *daddr,
25427                         unsigned int prefs,
25428 -                       struct in6_addr *saddr)
25429 +                       struct in6_addr *saddr,
25430 +                       struct nx_info *nxi)
25431  {
25432         struct inet6_dev *idev = ip6_dst_idev((struct dst_entry*)rt);
25433         int err = 0;
25434 -       if (rt->rt6i_prefsrc.plen)
25435 +       if (rt->rt6i_prefsrc.plen && (!nxi ||
25436 +           v6_addr_in_nx_info(nxi, &rt->rt6i_prefsrc.addr, NXA_TYPE_ADDR)))
25437                 *saddr = rt->rt6i_prefsrc.addr;
25438         else
25439                 err = ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
25440 -                                        daddr, prefs, saddr);
25441 +                                        daddr, prefs, saddr, nxi);
25442         return err;
25443  }
25444  
25445 @@ -2507,7 +2510,8 @@ static int rt6_fill_node(struct net *net
25446                                 goto nla_put_failure;
25447         } else if (dst) {
25448                 struct in6_addr saddr_buf;
25449 -               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf) == 0 &&
25450 +               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf,
25451 +                   (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0 &&
25452                     nla_put(skb, RTA_PREFSRC, 16, &saddr_buf))
25453                         goto nla_put_failure;
25454         }
25455 @@ -2719,6 +2723,7 @@ static int rt6_info_route(struct rt6_inf
25456  {
25457         struct seq_file *m = p_arg;
25458  
25459 +       /* FIXME: check for network context? */
25460         seq_printf(m, "%pi6 %02x ", &rt->rt6i_dst.addr, rt->rt6i_dst.plen);
25461  
25462  #ifdef CONFIG_IPV6_SUBTREES
25463 diff -NurpP --minimal linux-3.9.4/net/ipv6/tcp_ipv6.c linux-3.9.4-vs2.3.6.1/net/ipv6/tcp_ipv6.c
25464 --- linux-3.9.4/net/ipv6/tcp_ipv6.c     2013-05-31 14:22:27.000000000 +0000
25465 +++ linux-3.9.4-vs2.3.6.1/net/ipv6/tcp_ipv6.c   2013-05-31 17:17:54.000000000 +0000
25466 @@ -71,6 +71,7 @@
25467  
25468  #include <linux/crypto.h>
25469  #include <linux/scatterlist.h>
25470 +#include <linux/vs_inet6.h>
25471  
25472  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
25473  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
25474 @@ -164,8 +165,15 @@ static int tcp_v6_connect(struct sock *s
25475          *      connect() to INADDR_ANY means loopback (BSD'ism).
25476          */
25477  
25478 -       if(ipv6_addr_any(&usin->sin6_addr))
25479 -               usin->sin6_addr.s6_addr[15] = 0x1;
25480 +       if(ipv6_addr_any(&usin->sin6_addr)) {
25481 +               struct nx_info *nxi =  sk->sk_nx_info;
25482 +
25483 +               if (nxi && nx_info_has_v6(nxi))
25484 +                       /* FIXME: remap lback? */
25485 +                       usin->sin6_addr = nxi->v6.ip;
25486 +               else
25487 +                       usin->sin6_addr.s6_addr[15] = 0x1;
25488 +       }
25489  
25490         addr_type = ipv6_addr_type(&usin->sin6_addr);
25491  
25492 diff -NurpP --minimal linux-3.9.4/net/ipv6/udp.c linux-3.9.4-vs2.3.6.1/net/ipv6/udp.c
25493 --- linux-3.9.4/net/ipv6/udp.c  2013-05-31 14:22:27.000000000 +0000
25494 +++ linux-3.9.4-vs2.3.6.1/net/ipv6/udp.c        2013-05-31 18:16:01.000000000 +0000
25495 @@ -46,42 +46,68 @@
25496  #include <net/ip6_checksum.h>
25497  #include <net/xfrm.h>
25498  #include <net/inet6_hashtables.h>
25499 +#include <linux/vs_inet6.h>
25500  
25501  #include <linux/proc_fs.h>
25502  #include <linux/seq_file.h>
25503  #include <trace/events/skb.h>
25504  #include "udp_impl.h"
25505  
25506 -int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
25507 +int ipv6_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25508  {
25509 -       const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
25510 +       const struct in6_addr *sk1_rcv_saddr6 = &inet6_sk(sk1)->rcv_saddr;
25511         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
25512 -       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk);
25513 +       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk1);
25514         __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
25515 -       int sk_ipv6only = ipv6_only_sock(sk);
25516 +       int sk1_ipv6only = ipv6_only_sock(sk1);
25517         int sk2_ipv6only = inet_v6_ipv6only(sk2);
25518 -       int addr_type = ipv6_addr_type(sk_rcv_saddr6);
25519 +       int addr_type = ipv6_addr_type(sk1_rcv_saddr6);
25520         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
25521  
25522         /* if both are mapped, treat as IPv4 */
25523 -       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
25524 -               return (!sk2_ipv6only &&
25525 +       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
25526 +               if (!sk2_ipv6only &&
25527                         (!sk1_rcv_saddr || !sk2_rcv_saddr ||
25528 -                         sk1_rcv_saddr == sk2_rcv_saddr));
25529 +                         sk1_rcv_saddr == sk2_rcv_saddr))
25530 +                       goto vs_v4;
25531 +               else
25532 +                       return 0;
25533 +       }
25534  
25535         if (addr_type2 == IPV6_ADDR_ANY &&
25536             !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
25537 -               return 1;
25538 +               goto vs;
25539  
25540         if (addr_type == IPV6_ADDR_ANY &&
25541 -           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
25542 -               return 1;
25543 +           !(sk1_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
25544 +               goto vs;
25545  
25546         if (sk2_rcv_saddr6 &&
25547 -           ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
25548 -               return 1;
25549 +           ipv6_addr_equal(sk1_rcv_saddr6, sk2_rcv_saddr6))
25550 +               goto vs;
25551  
25552         return 0;
25553 +
25554 +vs_v4:
25555 +       if (!sk1_rcv_saddr && !sk2_rcv_saddr)
25556 +               return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25557 +       if (!sk2_rcv_saddr)
25558 +               return v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, -1);
25559 +       if (!sk1_rcv_saddr)
25560 +               return v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, -1);
25561 +       return 1;
25562 +vs:
25563 +       if (addr_type2 == IPV6_ADDR_ANY && addr_type == IPV6_ADDR_ANY)
25564 +               return nx_v6_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25565 +       else if (addr_type2 == IPV6_ADDR_ANY)
25566 +               return v6_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr6, -1);
25567 +       else if (addr_type == IPV6_ADDR_ANY) {
25568 +               if (addr_type2 == IPV6_ADDR_MAPPED)
25569 +                       return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25570 +               else
25571 +                       return v6_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr6, -1);
25572 +       }
25573 +       return 1;
25574  }
25575  
25576  static unsigned int udp6_portaddr_hash(struct net *net,
25577 @@ -145,6 +171,10 @@ static inline int compute_score(struct s
25578                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25579                                 return -1;
25580                         score++;
25581 +               } else {
25582 +                       /* block non nx_info ips */
25583 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25584 +                               return -1;
25585                 }
25586                 if (!ipv6_addr_any(&np->daddr)) {
25587                         if (!ipv6_addr_equal(&np->daddr, saddr))
25588 diff -NurpP --minimal linux-3.9.4/net/ipv6/xfrm6_policy.c linux-3.9.4-vs2.3.6.1/net/ipv6/xfrm6_policy.c
25589 --- linux-3.9.4/net/ipv6/xfrm6_policy.c 2013-05-31 14:22:27.000000000 +0000
25590 +++ linux-3.9.4-vs2.3.6.1/net/ipv6/xfrm6_policy.c       2013-05-31 17:17:54.000000000 +0000
25591 @@ -63,7 +63,7 @@ static int xfrm6_get_saddr(struct net *n
25592         dev = ip6_dst_idev(dst)->dev;
25593         ipv6_dev_get_saddr(dev_net(dev), dev,
25594                            (struct in6_addr *)&daddr->a6, 0,
25595 -                          (struct in6_addr *)&saddr->a6);
25596 +                          (struct in6_addr *)&saddr->a6, NULL);
25597         dst_release(dst);
25598         return 0;
25599  }
25600 diff -NurpP --minimal linux-3.9.4/net/netfilter/ipvs/ip_vs_xmit.c linux-3.9.4-vs2.3.6.1/net/netfilter/ipvs/ip_vs_xmit.c
25601 --- linux-3.9.4/net/netfilter/ipvs/ip_vs_xmit.c 2013-02-19 13:58:59.000000000 +0000
25602 +++ linux-3.9.4-vs2.3.6.1/net/netfilter/ipvs/ip_vs_xmit.c       2013-05-31 17:17:54.000000000 +0000
25603 @@ -273,7 +273,7 @@ __ip_vs_route_output_v6(struct net *net,
25604                 return dst;
25605         if (ipv6_addr_any(&fl6.saddr) &&
25606             ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
25607 -                              &fl6.daddr, 0, &fl6.saddr) < 0)
25608 +                              &fl6.daddr, 0, &fl6.saddr, NULL) < 0)
25609                 goto out_err;
25610         if (do_xfrm) {
25611                 dst = xfrm_lookup(net, dst, flowi6_to_flowi(&fl6), NULL, 0);
25612 diff -NurpP --minimal linux-3.9.4/net/netlink/af_netlink.c linux-3.9.4-vs2.3.6.1/net/netlink/af_netlink.c
25613 --- linux-3.9.4/net/netlink/af_netlink.c        2013-05-31 13:45:33.000000000 +0000
25614 +++ linux-3.9.4-vs2.3.6.1/net/netlink/af_netlink.c      2013-05-31 17:17:54.000000000 +0000
25615 @@ -55,6 +55,9 @@
25616  #include <linux/types.h>
25617  #include <linux/audit.h>
25618  #include <linux/mutex.h>
25619 +#include <linux/vs_context.h>
25620 +#include <linux/vs_network.h>
25621 +#include <linux/vs_limit.h>
25622  
25623  #include <net/net_namespace.h>
25624  #include <net/sock.h>
25625 @@ -1976,6 +1979,8 @@ static struct sock *netlink_seq_socket_i
25626                         sk_for_each(s, &hash->table[j]) {
25627                                 if (sock_net(s) != seq_file_net(seq))
25628                                         continue;
25629 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25630 +                                       continue;
25631                                 if (off == pos) {
25632                                         iter->link = i;
25633                                         iter->hash_idx = j;
25634 @@ -2010,7 +2015,8 @@ static void *netlink_seq_next(struct seq
25635         s = v;
25636         do {
25637                 s = sk_next(s);
25638 -       } while (s && sock_net(s) != seq_file_net(seq));
25639 +       } while (s && (sock_net(s) != seq_file_net(seq) ||
25640 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
25641         if (s)
25642                 return s;
25643  
25644 @@ -2022,7 +2028,8 @@ static void *netlink_seq_next(struct seq
25645  
25646                 for (; j <= hash->mask; j++) {
25647                         s = sk_head(&hash->table[j]);
25648 -                       while (s && sock_net(s) != seq_file_net(seq))
25649 +                       while (s && (sock_net(s) != seq_file_net(seq) ||
25650 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
25651                                 s = sk_next(s);
25652                         if (s) {
25653                                 iter->link = i;
25654 diff -NurpP --minimal linux-3.9.4/net/socket.c linux-3.9.4-vs2.3.6.1/net/socket.c
25655 --- linux-3.9.4/net/socket.c    2013-05-31 13:45:33.000000000 +0000
25656 +++ linux-3.9.4-vs2.3.6.1/net/socket.c  2013-05-31 17:17:54.000000000 +0000
25657 @@ -98,6 +98,10 @@
25658  
25659  #include <net/sock.h>
25660  #include <linux/netfilter.h>
25661 +#include <linux/vs_base.h>
25662 +#include <linux/vs_socket.h>
25663 +#include <linux/vs_inet.h>
25664 +#include <linux/vs_inet6.h>
25665  
25666  #include <linux/if_tun.h>
25667  #include <linux/ipv6_route.h>
25668 @@ -617,13 +621,29 @@ static inline int __sock_sendmsg_nosec(s
25669                                        struct msghdr *msg, size_t size)
25670  {
25671         struct sock_iocb *si = kiocb_to_siocb(iocb);
25672 +       size_t len;
25673  
25674         si->sock = sock;
25675         si->scm = NULL;
25676         si->msg = msg;
25677         si->size = size;
25678  
25679 -       return sock->ops->sendmsg(iocb, sock, msg, size);
25680 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
25681 +       if (sock->sk) {
25682 +               if (len == size)
25683 +                       vx_sock_send(sock->sk, size);
25684 +               else
25685 +                       vx_sock_fail(sock->sk, size);
25686 +       }
25687 +       vxdprintk(VXD_CBIT(net, 7),
25688 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%zu",
25689 +               sock, sock->sk,
25690 +               (sock->sk)?sock->sk->sk_nx_info:0,
25691 +               (sock->sk)?sock->sk->sk_vx_info:0,
25692 +               (sock->sk)?sock->sk->sk_xid:0,
25693 +               (sock->sk)?sock->sk->sk_nid:0,
25694 +               (unsigned int)size, len);
25695 +       return len;
25696  }
25697  
25698  static inline int __sock_sendmsg(struct kiocb *iocb, struct socket *sock,
25699 @@ -779,6 +799,7 @@ static inline int __sock_recvmsg_nosec(s
25700                                        struct msghdr *msg, size_t size, int flags)
25701  {
25702         struct sock_iocb *si = kiocb_to_siocb(iocb);
25703 +       int len;
25704  
25705         si->sock = sock;
25706         si->scm = NULL;
25707 @@ -786,7 +807,18 @@ static inline int __sock_recvmsg_nosec(s
25708         si->size = size;
25709         si->flags = flags;
25710  
25711 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
25712 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
25713 +       if ((len >= 0) && sock->sk)
25714 +               vx_sock_recv(sock->sk, len);
25715 +       vxdprintk(VXD_CBIT(net, 7),
25716 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
25717 +               sock, sock->sk,
25718 +               (sock->sk)?sock->sk->sk_nx_info:0,
25719 +               (sock->sk)?sock->sk->sk_vx_info:0,
25720 +               (sock->sk)?sock->sk->sk_xid:0,
25721 +               (sock->sk)?sock->sk->sk_nid:0,
25722 +               (unsigned int)size, len);
25723 +       return len;
25724  }
25725  
25726  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
25727 @@ -1269,6 +1301,13 @@ int __sock_create(struct net *net, int f
25728         if (type < 0 || type >= SOCK_MAX)
25729                 return -EINVAL;
25730  
25731 +       if (!nx_check(0, VS_ADMIN)) {
25732 +               if (family == PF_INET && !current_nx_info_has_v4())
25733 +                       return -EAFNOSUPPORT;
25734 +               if (family == PF_INET6 && !current_nx_info_has_v6())
25735 +                       return -EAFNOSUPPORT;
25736 +       }
25737 +
25738         /* Compatibility.
25739  
25740            This uglymoron is moved from INET layer to here to avoid
25741 @@ -1403,6 +1442,7 @@ SYSCALL_DEFINE3(socket, int, family, int
25742         if (retval < 0)
25743                 goto out;
25744  
25745 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
25746         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
25747         if (retval < 0)
25748                 goto out_release;
25749 @@ -1444,10 +1484,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
25750         err = sock_create(family, type, protocol, &sock1);
25751         if (err < 0)
25752                 goto out;
25753 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
25754  
25755         err = sock_create(family, type, protocol, &sock2);
25756         if (err < 0)
25757                 goto out_release_1;
25758 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
25759  
25760         err = sock1->ops->socketpair(sock1, sock2);
25761         if (err < 0)
25762 diff -NurpP --minimal linux-3.9.4/net/sunrpc/auth.c linux-3.9.4-vs2.3.6.1/net/sunrpc/auth.c
25763 --- linux-3.9.4/net/sunrpc/auth.c       2013-05-31 13:45:33.000000000 +0000
25764 +++ linux-3.9.4-vs2.3.6.1/net/sunrpc/auth.c     2013-05-31 18:01:00.000000000 +0000
25765 @@ -15,6 +15,7 @@
25766  #include <linux/sunrpc/clnt.h>
25767  #include <linux/sunrpc/gss_api.h>
25768  #include <linux/spinlock.h>
25769 +#include <linux/vs_tag.h>
25770  
25771  #ifdef RPC_DEBUG
25772  # define RPCDBG_FACILITY       RPCDBG_AUTH
25773 @@ -480,6 +481,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
25774         memset(&acred, 0, sizeof(acred));
25775         acred.uid = cred->fsuid;
25776         acred.gid = cred->fsgid;
25777 +       acred.tag = dx_current_tag();
25778         acred.group_info = get_group_info(((struct cred *)cred)->group_info);
25779  
25780         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
25781 @@ -520,6 +522,7 @@ rpcauth_bind_root_cred(struct rpc_task *
25782         struct auth_cred acred = {
25783                 .uid = GLOBAL_ROOT_UID,
25784                 .gid = GLOBAL_ROOT_GID,
25785 +               .tag = dx_current_tag(),
25786         };
25787  
25788         dprintk("RPC: %5u looking up %s cred\n",
25789 diff -NurpP --minimal linux-3.9.4/net/sunrpc/auth_unix.c linux-3.9.4-vs2.3.6.1/net/sunrpc/auth_unix.c
25790 --- linux-3.9.4/net/sunrpc/auth_unix.c  2013-05-31 13:45:33.000000000 +0000
25791 +++ linux-3.9.4-vs2.3.6.1/net/sunrpc/auth_unix.c        2013-05-31 18:05:54.000000000 +0000
25792 @@ -13,11 +13,13 @@
25793  #include <linux/sunrpc/clnt.h>
25794  #include <linux/sunrpc/auth.h>
25795  #include <linux/user_namespace.h>
25796 +#include <linux/vs_tag.h>
25797  
25798  #define NFS_NGROUPS    16
25799  
25800  struct unx_cred {
25801         struct rpc_cred         uc_base;
25802 +       ktag_t                  uc_tag;
25803         kgid_t                  uc_gid;
25804         kgid_t                  uc_gids[NFS_NGROUPS];
25805  };
25806 @@ -80,6 +82,7 @@ unx_create_cred(struct rpc_auth *auth, s
25807                 groups = NFS_NGROUPS;
25808  
25809         cred->uc_gid = acred->gid;
25810 +       cred->uc_tag = acred->tag;
25811         for (i = 0; i < groups; i++)
25812                 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
25813         if (i < NFS_NGROUPS)
25814 @@ -121,7 +124,9 @@ unx_match(struct auth_cred *acred, struc
25815         unsigned int i;
25816  
25817  
25818 -       if (!uid_eq(cred->uc_uid, acred->uid) || !gid_eq(cred->uc_gid, acred->gid))
25819 +       if (!uid_eq(cred->uc_uid, acred->uid) ||
25820 +           !gid_eq(cred->uc_gid, acred->gid) ||
25821 +           !tag_eq(cred->uc_tag, acred->tag))
25822                 return 0;
25823  
25824         if (acred->group_info != NULL)
25825 @@ -146,7 +151,7 @@ unx_marshal(struct rpc_task *task, __be3
25826         struct rpc_clnt *clnt = task->tk_client;
25827         struct unx_cred *cred = container_of(task->tk_rqstp->rq_cred, struct unx_cred, uc_base);
25828         __be32          *base, *hold;
25829 -       int             i;
25830 +       int             i, tag;
25831  
25832         *p++ = htonl(RPC_AUTH_UNIX);
25833         base = p++;
25834 @@ -157,8 +162,13 @@ unx_marshal(struct rpc_task *task, __be3
25835          */
25836         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
25837  
25838 -       *p++ = htonl((u32) from_kuid(&init_user_ns, cred->uc_uid));
25839 -       *p++ = htonl((u32) from_kgid(&init_user_ns, cred->uc_gid));
25840 +       tag = task->tk_client->cl_tag;
25841 +       *p++ = htonl((u32) TAGINO_UID(tag,
25842 +               from_kuid(&init_user_ns, cred->uc_uid),
25843 +               from_ktag(&init_user_ns, cred->uc_tag)));
25844 +       *p++ = htonl((u32) TAGINO_GID(tag,
25845 +               from_kgid(&init_user_ns, cred->uc_gid),
25846 +               from_ktag(&init_user_ns, cred->uc_tag)));
25847         hold = p++;
25848         for (i = 0; i < 16 && gid_valid(cred->uc_gids[i]); i++)
25849                 *p++ = htonl((u32) from_kgid(&init_user_ns, cred->uc_gids[i]));
25850 diff -NurpP --minimal linux-3.9.4/net/sunrpc/clnt.c linux-3.9.4-vs2.3.6.1/net/sunrpc/clnt.c
25851 --- linux-3.9.4/net/sunrpc/clnt.c       2013-05-31 13:45:33.000000000 +0000
25852 +++ linux-3.9.4-vs2.3.6.1/net/sunrpc/clnt.c     2013-05-31 17:17:54.000000000 +0000
25853 @@ -31,6 +31,7 @@
25854  #include <linux/in6.h>
25855  #include <linux/un.h>
25856  #include <linux/rcupdate.h>
25857 +#include <linux/vs_cvirt.h>
25858  
25859  #include <linux/sunrpc/clnt.h>
25860  #include <linux/sunrpc/addr.h>
25861 @@ -482,6 +483,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
25862         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
25863                 clnt->cl_chatty = 1;
25864  
25865 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
25866 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
25867 +               clnt->cl_tag = 1; */
25868         return clnt;
25869  }
25870  EXPORT_SYMBOL_GPL(rpc_create);
25871 diff -NurpP --minimal linux-3.9.4/net/unix/af_unix.c linux-3.9.4-vs2.3.6.1/net/unix/af_unix.c
25872 --- linux-3.9.4/net/unix/af_unix.c      2013-05-31 13:45:33.000000000 +0000
25873 +++ linux-3.9.4-vs2.3.6.1/net/unix/af_unix.c    2013-05-31 17:17:54.000000000 +0000
25874 @@ -114,6 +114,8 @@
25875  #include <linux/mount.h>
25876  #include <net/checksum.h>
25877  #include <linux/security.h>
25878 +#include <linux/vs_context.h>
25879 +#include <linux/vs_limit.h>
25880  
25881  struct hlist_head unix_socket_table[2 * UNIX_HASH_SIZE];
25882  EXPORT_SYMBOL_GPL(unix_socket_table);
25883 @@ -270,6 +272,8 @@ static struct sock *__unix_find_socket_b
25884                 if (!net_eq(sock_net(s), net))
25885                         continue;
25886  
25887 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25888 +                       continue;
25889                 if (u->addr->len == len &&
25890                     !memcmp(u->addr->name, sunname, len))
25891                         goto found;
25892 @@ -2256,6 +2260,8 @@ static struct sock *unix_from_bucket(str
25893         for (sk = sk_head(&unix_socket_table[bucket]); sk; sk = sk_next(sk)) {
25894                 if (sock_net(sk) != seq_file_net(seq))
25895                         continue;
25896 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25897 +                       continue;
25898                 if (++count == offset)
25899                         break;
25900         }
25901 @@ -2273,6 +2279,8 @@ static struct sock *unix_next_socket(str
25902                 sk = sk_next(sk);
25903                 if (!sk)
25904                         goto next_bucket;
25905 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25906 +                       continue;
25907                 if (sock_net(sk) == seq_file_net(seq))
25908                         return sk;
25909         }
25910 diff -NurpP --minimal linux-3.9.4/scripts/checksyscalls.sh linux-3.9.4-vs2.3.6.1/scripts/checksyscalls.sh
25911 --- linux-3.9.4/scripts/checksyscalls.sh        2012-12-11 03:30:57.000000000 +0000
25912 +++ linux-3.9.4-vs2.3.6.1/scripts/checksyscalls.sh      2013-05-31 14:47:11.000000000 +0000
25913 @@ -193,7 +193,6 @@ cat << EOF
25914  #define __IGNORE_afs_syscall
25915  #define __IGNORE_getpmsg
25916  #define __IGNORE_putpmsg
25917 -#define __IGNORE_vserver
25918  EOF
25919  }
25920  
25921 diff -NurpP --minimal linux-3.9.4/scripts/mod/devicetable-offsets.h linux-3.9.4-vs2.3.6.1/scripts/mod/devicetable-offsets.h
25922 --- linux-3.9.4/scripts/mod/devicetable-offsets.h       1970-01-01 00:00:00.000000000 +0000
25923 +++ linux-3.9.4-vs2.3.6.1/scripts/mod/devicetable-offsets.h     2013-06-01 00:22:25.000000000 +0000
25924 @@ -0,0 +1,146 @@
25925 +#ifndef __DEVICEVTABLE_OFFSETS_H__
25926 +#define __DEVICEVTABLE_OFFSETS_H__
25927 +/*
25928 + * DO NOT MODIFY.
25929 + *
25930 + * This file was generated by Kbuild
25931 + *
25932 + */
25933 +
25934 +#define SIZE_usb_device_id 32 /* sizeof(struct usb_device_id)  # */
25935 +#define OFF_usb_device_id_match_flags 0 /* offsetof(struct usb_device_id, match_flags) # */
25936 +#define OFF_usb_device_id_idVendor 2 /* offsetof(struct usb_device_id, idVendor)       # */
25937 +#define OFF_usb_device_id_idProduct 4 /* offsetof(struct usb_device_id, idProduct)     # */
25938 +#define OFF_usb_device_id_bcdDevice_lo 6 /* offsetof(struct usb_device_id, bcdDevice_lo)       # */
25939 +#define OFF_usb_device_id_bcdDevice_hi 8 /* offsetof(struct usb_device_id, bcdDevice_hi)       # */
25940 +#define OFF_usb_device_id_bDeviceClass 10 /* offsetof(struct usb_device_id, bDeviceClass)      # */
25941 +#define OFF_usb_device_id_bDeviceSubClass 11 /* offsetof(struct usb_device_id, bDeviceSubClass)        # */
25942 +#define OFF_usb_device_id_bDeviceProtocol 12 /* offsetof(struct usb_device_id, bDeviceProtocol)        # */
25943 +#define OFF_usb_device_id_bInterfaceClass 13 /* offsetof(struct usb_device_id, bInterfaceClass)        # */
25944 +#define OFF_usb_device_id_bInterfaceSubClass 14 /* offsetof(struct usb_device_id, bInterfaceSubClass)  # */
25945 +#define OFF_usb_device_id_bInterfaceProtocol 15 /* offsetof(struct usb_device_id, bInterfaceProtocol)  # */
25946 +#define OFF_usb_device_id_bInterfaceNumber 16 /* offsetof(struct usb_device_id, bInterfaceNumber)      # */
25947 +#define SIZE_hid_device_id 24 /* sizeof(struct hid_device_id)  # */
25948 +#define OFF_hid_device_id_bus 0 /* offsetof(struct hid_device_id, bus) # */
25949 +#define OFF_hid_device_id_group 2 /* offsetof(struct hid_device_id, group)     # */
25950 +#define OFF_hid_device_id_vendor 4 /* offsetof(struct hid_device_id, vendor)   # */
25951 +#define OFF_hid_device_id_product 8 /* offsetof(struct hid_device_id, product) # */
25952 +#define SIZE_ieee1394_device_id 32 /* sizeof(struct ieee1394_device_id)        # */
25953 +#define OFF_ieee1394_device_id_match_flags 0 /* offsetof(struct ieee1394_device_id, match_flags)       # */
25954 +#define OFF_ieee1394_device_id_vendor_id 4 /* offsetof(struct ieee1394_device_id, vendor_id)   # */
25955 +#define OFF_ieee1394_device_id_model_id 8 /* offsetof(struct ieee1394_device_id, model_id)     # */
25956 +#define OFF_ieee1394_device_id_specifier_id 12 /* offsetof(struct ieee1394_device_id, specifier_id)    # */
25957 +#define OFF_ieee1394_device_id_version 16 /* offsetof(struct ieee1394_device_id, version)      # */
25958 +#define SIZE_pci_device_id 32 /* sizeof(struct pci_device_id)  # */
25959 +#define OFF_pci_device_id_vendor 0 /* offsetof(struct pci_device_id, vendor)   # */
25960 +#define OFF_pci_device_id_device 4 /* offsetof(struct pci_device_id, device)   # */
25961 +#define OFF_pci_device_id_subvendor 8 /* offsetof(struct pci_device_id, subvendor)     # */
25962 +#define OFF_pci_device_id_subdevice 12 /* offsetof(struct pci_device_id, subdevice)    # */
25963 +#define OFF_pci_device_id_class 16 /* offsetof(struct pci_device_id, class)    # */
25964 +#define OFF_pci_device_id_class_mask 20 /* offsetof(struct pci_device_id, class_mask)  # */
25965 +#define SIZE_ccw_device_id 16 /* sizeof(struct ccw_device_id)  # */
25966 +#define OFF_ccw_device_id_match_flags 0 /* offsetof(struct ccw_device_id, match_flags) # */
25967 +#define OFF_ccw_device_id_cu_type 2 /* offsetof(struct ccw_device_id, cu_type) # */
25968 +#define OFF_ccw_device_id_cu_model 6 /* offsetof(struct ccw_device_id, cu_model)       # */
25969 +#define OFF_ccw_device_id_dev_type 4 /* offsetof(struct ccw_device_id, dev_type)       # */
25970 +#define OFF_ccw_device_id_dev_model 7 /* offsetof(struct ccw_device_id, dev_model)     # */
25971 +#define SIZE_ap_device_id 16 /* sizeof(struct ap_device_id)    # */
25972 +#define OFF_ap_device_id_dev_type 2 /* offsetof(struct ap_device_id, dev_type) # */
25973 +#define SIZE_css_device_id 16 /* sizeof(struct css_device_id)  # */
25974 +#define OFF_css_device_id_type 1 /* offsetof(struct css_device_id, type)       # */
25975 +#define SIZE_serio_device_id 4 /* sizeof(struct serio_device_id)       # */
25976 +#define OFF_serio_device_id_type 0 /* offsetof(struct serio_device_id, type)   # */
25977 +#define OFF_serio_device_id_proto 3 /* offsetof(struct serio_device_id, proto) # */
25978 +#define OFF_serio_device_id_id 2 /* offsetof(struct serio_device_id, id)       # */
25979 +#define OFF_serio_device_id_extra 1 /* offsetof(struct serio_device_id, extra) # */
25980 +#define SIZE_acpi_device_id 24 /* sizeof(struct acpi_device_id)        # */
25981 +#define OFF_acpi_device_id_id 0 /* offsetof(struct acpi_device_id, id) # */
25982 +#define SIZE_pnp_device_id 16 /* sizeof(struct pnp_device_id)  # */
25983 +#define OFF_pnp_device_id_id 0 /* offsetof(struct pnp_device_id, id)   # */
25984 +#define SIZE_pnp_card_device_id 80 /* sizeof(struct pnp_card_device_id)        # */
25985 +#define OFF_pnp_card_device_id_devs 16 /* offsetof(struct pnp_card_device_id, devs)    # */
25986 +#define SIZE_pcmcia_device_id 80 /* sizeof(struct pcmcia_device_id)    # */
25987 +#define OFF_pcmcia_device_id_match_flags 0 /* offsetof(struct pcmcia_device_id, match_flags)   # */
25988 +#define OFF_pcmcia_device_id_manf_id 2 /* offsetof(struct pcmcia_device_id, manf_id)   # */
25989 +#define OFF_pcmcia_device_id_card_id 4 /* offsetof(struct pcmcia_device_id, card_id)   # */
25990 +#define OFF_pcmcia_device_id_func_id 6 /* offsetof(struct pcmcia_device_id, func_id)   # */
25991 +#define OFF_pcmcia_device_id_function 7 /* offsetof(struct pcmcia_device_id, function) # */
25992 +#define OFF_pcmcia_device_id_device_no 8 /* offsetof(struct pcmcia_device_id, device_no)       # */
25993 +#define OFF_pcmcia_device_id_prod_id_hash 12 /* offsetof(struct pcmcia_device_id, prod_id_hash)        # */
25994 +#define SIZE_of_device_id 200 /* sizeof(struct of_device_id)   # */
25995 +#define OFF_of_device_id_name 0 /* offsetof(struct of_device_id, name) # */
25996 +#define OFF_of_device_id_type 32 /* offsetof(struct of_device_id, type)        # */
25997 +#define OFF_of_device_id_compatible 64 /* offsetof(struct of_device_id, compatible)    # */
25998 +#define SIZE_vio_device_id 64 /* sizeof(struct vio_device_id)  # */
25999 +#define OFF_vio_device_id_type 0 /* offsetof(struct vio_device_id, type)       # */
26000 +#define OFF_vio_device_id_compat 32 /* offsetof(struct vio_device_id, compat)  # */
26001 +#define SIZE_input_device_id 192 /* sizeof(struct input_device_id)     # */
26002 +#define OFF_input_device_id_flags 0 /* offsetof(struct input_device_id, flags) # */
26003 +#define OFF_input_device_id_bustype 8 /* offsetof(struct input_device_id, bustype)     # */
26004 +#define OFF_input_device_id_vendor 10 /* offsetof(struct input_device_id, vendor)      # */
26005 +#define OFF_input_device_id_product 12 /* offsetof(struct input_device_id, product)    # */
26006 +#define OFF_input_device_id_version 14 /* offsetof(struct input_device_id, version)    # */
26007 +#define OFF_input_device_id_evbit 16 /* offsetof(struct input_device_id, evbit)        # */
26008 +#define OFF_input_device_id_keybit 24 /* offsetof(struct input_device_id, keybit)      # */
26009 +#define OFF_input_device_id_relbit 120 /* offsetof(struct input_device_id, relbit)     # */
26010 +#define OFF_input_device_id_absbit 128 /* offsetof(struct input_device_id, absbit)     # */
26011 +#define OFF_input_device_id_mscbit 136 /* offsetof(struct input_device_id, mscbit)     # */
26012 +#define OFF_input_device_id_ledbit 144 /* offsetof(struct input_device_id, ledbit)     # */
26013 +#define OFF_input_device_id_sndbit 152 /* offsetof(struct input_device_id, sndbit)     # */
26014 +#define OFF_input_device_id_ffbit 160 /* offsetof(struct input_device_id, ffbit)       # */
26015 +#define OFF_input_device_id_swbit 176 /* offsetof(struct input_device_id, swbit)       # */
26016 +#define SIZE_eisa_device_id 16 /* sizeof(struct eisa_device_id)        # */
26017 +#define OFF_eisa_device_id_sig 0 /* offsetof(struct eisa_device_id, sig)       # */
26018 +#define SIZE_parisc_device_id 8 /* sizeof(struct parisc_device_id)     # */
26019 +#define OFF_parisc_device_id_hw_type 0 /* offsetof(struct parisc_device_id, hw_type)   # */
26020 +#define OFF_parisc_device_id_hversion 2 /* offsetof(struct parisc_device_id, hversion) # */
26021 +#define OFF_parisc_device_id_hversion_rev 1 /* offsetof(struct parisc_device_id, hversion_rev) # */
26022 +#define OFF_parisc_device_id_sversion 4 /* offsetof(struct parisc_device_id, sversion) # */
26023 +#define SIZE_sdio_device_id 16 /* sizeof(struct sdio_device_id)        # */
26024 +#define OFF_sdio_device_id_class 0 /* offsetof(struct sdio_device_id, class)   # */
26025 +#define OFF_sdio_device_id_vendor 2 /* offsetof(struct sdio_device_id, vendor) # */
26026 +#define OFF_sdio_device_id_device 4 /* offsetof(struct sdio_device_id, device) # */
26027 +#define SIZE_ssb_device_id 6 /* sizeof(struct ssb_device_id)   # */
26028 +#define OFF_ssb_device_id_vendor 0 /* offsetof(struct ssb_device_id, vendor)   # */
26029 +#define OFF_ssb_device_id_coreid 2 /* offsetof(struct ssb_device_id, coreid)   # */
26030 +#define OFF_ssb_device_id_revision 4 /* offsetof(struct ssb_device_id, revision)       # */
26031 +#define SIZE_bcma_device_id 6 /* sizeof(struct bcma_device_id) # */
26032 +#define OFF_bcma_device_id_manuf 0 /* offsetof(struct bcma_device_id, manuf)   # */
26033 +#define OFF_bcma_device_id_id 2 /* offsetof(struct bcma_device_id, id) # */
26034 +#define OFF_bcma_device_id_rev 4 /* offsetof(struct bcma_device_id, rev)       # */
26035 +#define OFF_bcma_device_id_class 5 /* offsetof(struct bcma_device_id, class)   # */
26036 +#define SIZE_virtio_device_id 8 /* sizeof(struct virtio_device_id)     # */
26037 +#define OFF_virtio_device_id_device 0 /* offsetof(struct virtio_device_id, device)     # */
26038 +#define OFF_virtio_device_id_vendor 4 /* offsetof(struct virtio_device_id, vendor)     # */
26039 +#define SIZE_hv_vmbus_device_id 24 /* sizeof(struct hv_vmbus_device_id)        # */
26040 +#define OFF_hv_vmbus_device_id_guid 0 /* offsetof(struct hv_vmbus_device_id, guid)     # */
26041 +#define SIZE_i2c_device_id 32 /* sizeof(struct i2c_device_id)  # */
26042 +#define OFF_i2c_device_id_name 0 /* offsetof(struct i2c_device_id, name)       # */
26043 +#define SIZE_spi_device_id 40 /* sizeof(struct spi_device_id)  # */
26044 +#define OFF_spi_device_id_name 0 /* offsetof(struct spi_device_id, name)       # */
26045 +#define SIZE_dmi_system_id 344 /* sizeof(struct dmi_system_id) # */
26046 +#define OFF_dmi_system_id_matches 16 /* offsetof(struct dmi_system_id, matches)        # */
26047 +#define SIZE_platform_device_id 32 /* sizeof(struct platform_device_id)        # */
26048 +#define OFF_platform_device_id_name 0 /* offsetof(struct platform_device_id, name)     # */
26049 +#define SIZE_mdio_device_id 8 /* sizeof(struct mdio_device_id) # */
26050 +#define OFF_mdio_device_id_phy_id 0 /* offsetof(struct mdio_device_id, phy_id) # */
26051 +#define OFF_mdio_device_id_phy_id_mask 4 /* offsetof(struct mdio_device_id, phy_id_mask)       # */
26052 +#define SIZE_zorro_device_id 16 /* sizeof(struct zorro_device_id)      # */
26053 +#define OFF_zorro_device_id_id 0 /* offsetof(struct zorro_device_id, id)       # */
26054 +#define SIZE_isapnp_device_id 16 /* sizeof(struct isapnp_device_id)    # */
26055 +#define OFF_isapnp_device_id_vendor 4 /* offsetof(struct isapnp_device_id, vendor)     # */
26056 +#define OFF_isapnp_device_id_function 6 /* offsetof(struct isapnp_device_id, function) # */
26057 +#define SIZE_ipack_device_id 12 /* sizeof(struct ipack_device_id)      # */
26058 +#define OFF_ipack_device_id_format 0 /* offsetof(struct ipack_device_id, format)       # */
26059 +#define OFF_ipack_device_id_vendor 4 /* offsetof(struct ipack_device_id, vendor)       # */
26060 +#define OFF_ipack_device_id_device 8 /* offsetof(struct ipack_device_id, device)       # */
26061 +#define SIZE_amba_id 16 /* sizeof(struct amba_id)      # */
26062 +#define OFF_amba_id_id 0 /* offsetof(struct amba_id, id)       # */
26063 +#define OFF_amba_id_mask 4 /* offsetof(struct amba_id, mask)   # */
26064 +#define SIZE_x86_cpu_id 16 /* sizeof(struct x86_cpu_id)        # */
26065 +#define OFF_x86_cpu_id_feature 6 /* offsetof(struct x86_cpu_id, feature)       # */
26066 +#define OFF_x86_cpu_id_family 2 /* offsetof(struct x86_cpu_id, family) # */
26067 +#define OFF_x86_cpu_id_model 4 /* offsetof(struct x86_cpu_id, model)   # */
26068 +#define OFF_x86_cpu_id_vendor 0 /* offsetof(struct x86_cpu_id, vendor) # */
26069 +
26070 +#endif
26071 diff -NurpP --minimal linux-3.9.4/security/commoncap.c linux-3.9.4-vs2.3.6.1/security/commoncap.c
26072 --- linux-3.9.4/security/commoncap.c    2013-05-31 13:45:34.000000000 +0000
26073 +++ linux-3.9.4-vs2.3.6.1/security/commoncap.c  2013-05-31 15:07:02.000000000 +0000
26074 @@ -76,6 +76,7 @@ int cap_netlink_send(struct sock *sk, st
26075  int cap_capable(const struct cred *cred, struct user_namespace *targ_ns,
26076                 int cap, int audit)
26077  {
26078 +       struct vx_info *vxi = current_vx_info(); /* FIXME: get vxi from cred? */
26079         struct user_namespace *ns = targ_ns;
26080  
26081         /* See if cred has the capability in the target user namespace
26082 @@ -84,8 +85,12 @@ int cap_capable(const struct cred *cred,
26083          */
26084         for (;;) {
26085                 /* Do we have the necessary capabilities? */
26086 -               if (ns == cred->user_ns)
26087 -                       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
26088 +               if (ns == cred->user_ns) {
26089 +                       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
26090 +                           cap_raised(cred->cap_effective, cap))
26091 +                               return 0;
26092 +                       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
26093 +               }
26094  
26095                 /* Have we tried all of the parent namespaces? */
26096                 if (ns == &init_user_ns)
26097 @@ -628,7 +633,7 @@ int cap_inode_setxattr(struct dentry *de
26098  
26099         if (!strncmp(name, XATTR_SECURITY_PREFIX,
26100                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
26101 -           !capable(CAP_SYS_ADMIN))
26102 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
26103                 return -EPERM;
26104         return 0;
26105  }
26106 @@ -654,7 +659,7 @@ int cap_inode_removexattr(struct dentry
26107  
26108         if (!strncmp(name, XATTR_SECURITY_PREFIX,
26109                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
26110 -           !capable(CAP_SYS_ADMIN))
26111 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
26112                 return -EPERM;
26113         return 0;
26114  }
26115 diff -NurpP --minimal linux-3.9.4/security/selinux/hooks.c linux-3.9.4-vs2.3.6.1/security/selinux/hooks.c
26116 --- linux-3.9.4/security/selinux/hooks.c        2013-05-31 13:45:34.000000000 +0000
26117 +++ linux-3.9.4-vs2.3.6.1/security/selinux/hooks.c      2013-05-31 14:47:11.000000000 +0000
26118 @@ -67,7 +67,6 @@
26119  #include <linux/dccp.h>
26120  #include <linux/quota.h>
26121  #include <linux/un.h>          /* for Unix socket types */
26122 -#include <net/af_unix.h>       /* for Unix socket types */
26123  #include <linux/parser.h>
26124  #include <linux/nfs_mount.h>
26125  #include <net/ipv6.h>
This page took 1.929223 seconds and 4 git commands to generate.